mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Fixing some errors related to WG
This commit is contained in:
parent
cbb726e020
commit
cf0b60d165
@ -14,40 +14,30 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import static org.bukkit.Bukkit.getServer;
|
import static org.bukkit.Bukkit.getServer;
|
||||||
|
|
||||||
public class WorldGuardManager {
|
public class WorldGuardManager {
|
||||||
|
|
||||||
private static WorldGuardManager instance;
|
private static WorldGuardManager instance;
|
||||||
private Plugin worldGuardPluginRef;
|
private WorldGuardPlugin worldGuardPluginRef;
|
||||||
private boolean flagsRegistered = false;
|
|
||||||
|
public static WorldGuardManager getInstance() {
|
||||||
|
if(instance == null)
|
||||||
|
instance = new WorldGuardManager();
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
public WorldGuardManager()
|
public WorldGuardManager()
|
||||||
{
|
{
|
||||||
instance = this;
|
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init()
|
|
||||||
{
|
|
||||||
if(getWorldGuard() != null)
|
|
||||||
{
|
|
||||||
worldGuardPluginRef = getWorldGuard();
|
|
||||||
registerFlags();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMainFlag(Player player)
|
public boolean hasMainFlag(Player player)
|
||||||
{
|
{
|
||||||
//Not sure when we're supposed to know when WorldGuard is loaded
|
if(player == null)
|
||||||
if(!flagsRegistered)
|
return false;
|
||||||
registerFlags();
|
|
||||||
|
|
||||||
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
|
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
|
||||||
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
|
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
|
||||||
|
|
||||||
if(flagsRegistered)
|
|
||||||
{
|
|
||||||
if(getWorldGuard() != null)
|
|
||||||
{
|
|
||||||
//WorldGuardPlugin worldGuard = getWorldGuard();
|
//WorldGuardPlugin worldGuard = getWorldGuard();
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
@ -56,25 +46,15 @@ public class WorldGuardManager {
|
|||||||
|
|
||||||
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//Return False if these fail
|
|
||||||
mcMMO.p.getLogger().severe("Failed to detect WG flags, is WG running properly?");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasXPFlag(Player player)
|
public boolean hasXPFlag(Player player)
|
||||||
{
|
{
|
||||||
//Not sure when we're supposed to know when WorldGuard is loaded
|
if(player == null)
|
||||||
if(!flagsRegistered)
|
return false;
|
||||||
registerFlags();
|
|
||||||
|
|
||||||
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
|
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
|
||||||
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
|
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
|
||||||
|
|
||||||
if(flagsRegistered)
|
|
||||||
{
|
|
||||||
if(getWorldGuard() != null)
|
|
||||||
{
|
|
||||||
//WorldGuardPlugin worldGuard = getWorldGuard();
|
//WorldGuardPlugin worldGuard = getWorldGuard();
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
@ -83,11 +63,6 @@ public class WorldGuardManager {
|
|||||||
|
|
||||||
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_XP_WG_FLAG);
|
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_XP_WG_FLAG);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//Return False if these fail
|
|
||||||
mcMMO.p.getLogger().severe("Failed to detect WG flags, is WG running properly?");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WorldGuardPlugin getWorldGuard() {
|
private WorldGuardPlugin getWorldGuard() {
|
||||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
||||||
@ -97,10 +72,11 @@ public class WorldGuardManager {
|
|||||||
return null; // Maybe you want throw an exception instead
|
return null; // Maybe you want throw an exception instead
|
||||||
}
|
}
|
||||||
|
|
||||||
return (WorldGuardPlugin) plugin;
|
worldGuardPluginRef = (WorldGuardPlugin) plugin;
|
||||||
|
return worldGuardPluginRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerFlags()
|
public void registerFlags()
|
||||||
{
|
{
|
||||||
if(getWorldGuard() == null)
|
if(getWorldGuard() == null)
|
||||||
return;
|
return;
|
||||||
@ -108,11 +84,14 @@ public class WorldGuardManager {
|
|||||||
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
||||||
try {
|
try {
|
||||||
// register our flag with the registry
|
// register our flag with the registry
|
||||||
|
/*registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
||||||
|
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);*/
|
||||||
registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
||||||
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
|
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
|
||||||
flagsRegistered = true;
|
System.out.println("mcMMO has registered WG flags successfully!");
|
||||||
} catch (FlagConflictException e) {
|
} catch (FlagConflictException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
System.out.println("mcMMO has failed to register WG flags!");
|
||||||
// some other plugin registered a flag by the same name already.
|
// some other plugin registered a flag by the same name already.
|
||||||
// you may want to re-register with a different name, but this
|
// you may want to re-register with a different name, but this
|
||||||
// could cause issues with saved flags in region files. it's better
|
// could cause issues with saved flags in region files. it's better
|
||||||
@ -120,7 +99,5 @@ public class WorldGuardManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WorldGuardManager getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,10 @@ public class WorldGuardUtils {
|
|||||||
return false; // Maybe you want throw an exception instead
|
return false; // Maybe you want throw an exception instead
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
//Silently Fail
|
//Silently Fail
|
||||||
mcMMO.p.getLogger().severe("Failed to detect worldguard.");
|
//mcMMO.p.getLogger().severe("Failed to detect worldguard.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -219,6 +219,13 @@ public class mcMMO extends JavaPlugin {
|
|||||||
worldBlacklist = new WorldBlacklist(this);
|
worldBlacklist = new WorldBlacklist(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad()
|
||||||
|
{
|
||||||
|
if(getServer().getPluginManager().getPlugin("WorldGuard") != null)
|
||||||
|
WorldGuardManager.getInstance().registerFlags();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Things to be run when the plugin is disabled.
|
* Things to be run when the plugin is disabled.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user