2019-01-22 23:11:59 +01:00
|
|
|
package com.gmail.nossr50;
|
|
|
|
|
2019-01-23 01:40:54 +01:00
|
|
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
|
|
|
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
|
|
|
import com.sk89q.worldguard.WorldGuard;
|
2019-01-22 23:11:59 +01:00
|
|
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
2019-01-23 01:40:54 +01:00
|
|
|
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
|
|
|
|
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
|
|
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
|
|
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
|
|
|
import static org.bukkit.Bukkit.getServer;
|
2019-01-22 23:11:59 +01:00
|
|
|
|
|
|
|
public class WorldGuardManager {
|
2019-01-23 01:40:54 +01:00
|
|
|
private static WorldGuardManager instance;
|
2019-01-23 02:59:45 +01:00
|
|
|
private WorldGuardPlugin worldGuardPluginRef;
|
2019-01-23 01:40:54 +01:00
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
public static WorldGuardManager getInstance() {
|
|
|
|
if(instance == null)
|
|
|
|
instance = new WorldGuardManager();
|
2019-01-23 01:40:54 +01:00
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
return instance;
|
2019-01-23 01:40:54 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
public WorldGuardManager()
|
2019-01-23 01:40:54 +01:00
|
|
|
{
|
2019-01-23 02:59:45 +01:00
|
|
|
|
2019-01-23 01:40:54 +01:00
|
|
|
}
|
2019-01-22 23:11:59 +01:00
|
|
|
|
2019-01-23 01:40:54 +01:00
|
|
|
public boolean hasMainFlag(Player player)
|
2019-01-22 23:11:59 +01:00
|
|
|
{
|
2019-01-23 02:59:45 +01:00
|
|
|
if(player == null)
|
|
|
|
return false;
|
2019-01-23 01:54:43 +01:00
|
|
|
|
2019-01-23 01:40:54 +01:00
|
|
|
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
|
|
|
|
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
|
|
|
|
|
2019-01-22 23:11:59 +01:00
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
//WorldGuardPlugin worldGuard = getWorldGuard();
|
|
|
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
|
|
|
RegionQuery query = container.createQuery();
|
2019-01-22 23:11:59 +01:00
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
//ApplicableRegionSet set = query.getApplicableRegions(loc);
|
|
|
|
|
|
|
|
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
2019-01-22 23:11:59 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 01:40:54 +01:00
|
|
|
public boolean hasXPFlag(Player player)
|
|
|
|
{
|
2019-01-23 02:59:45 +01:00
|
|
|
if(player == null)
|
|
|
|
return false;
|
2019-01-23 01:54:43 +01:00
|
|
|
|
2019-01-23 01:40:54 +01:00
|
|
|
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
|
|
|
|
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
|
2019-01-22 23:11:59 +01:00
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
//WorldGuardPlugin worldGuard = getWorldGuard();
|
|
|
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
|
|
|
RegionQuery query = container.createQuery();
|
2019-01-23 01:40:54 +01:00
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
//ApplicableRegionSet set = query.getApplicableRegions(loc);
|
2019-01-23 01:40:54 +01:00
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_XP_WG_FLAG);
|
2019-01-23 01:40:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private WorldGuardPlugin getWorldGuard() {
|
2019-01-22 23:11:59 +01:00
|
|
|
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
|
|
|
|
|
|
|
// WorldGuard may not be loaded
|
|
|
|
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
|
|
|
|
return null; // Maybe you want throw an exception instead
|
|
|
|
}
|
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
worldGuardPluginRef = (WorldGuardPlugin) plugin;
|
|
|
|
return worldGuardPluginRef;
|
2019-01-22 23:11:59 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
public void registerFlags()
|
2019-01-22 23:11:59 +01:00
|
|
|
{
|
|
|
|
if(getWorldGuard() == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
|
|
|
try {
|
|
|
|
// register our flag with the registry
|
2019-01-23 02:59:45 +01:00
|
|
|
/*registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
|
|
|
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);*/
|
2019-01-23 01:40:54 +01:00
|
|
|
registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
|
|
|
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
|
2019-01-23 02:59:45 +01:00
|
|
|
System.out.println("mcMMO has registered WG flags successfully!");
|
2019-01-22 23:11:59 +01:00
|
|
|
} catch (FlagConflictException e) {
|
|
|
|
e.printStackTrace();
|
2019-01-23 02:59:45 +01:00
|
|
|
System.out.println("mcMMO has failed to register WG flags!");
|
2019-01-22 23:11:59 +01:00
|
|
|
// some other plugin registered a flag by the same name already.
|
|
|
|
// you may want to re-register with a different name, but this
|
|
|
|
// could cause issues with saved flags in region files. it's better
|
|
|
|
// to print a message to let the server admin know of the conflict
|
|
|
|
}
|
2019-01-23 01:40:54 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 02:59:45 +01:00
|
|
|
|
2019-01-22 23:11:59 +01:00
|
|
|
}
|