mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
WG Manager now lives in WG Utils class, fixing the runtime errors for WG
hooks in mcMMO during start up
This commit is contained in:
parent
c0bfdd34b7
commit
8e1f002808
@ -77,7 +77,6 @@ public class mcMMO extends JavaPlugin {
|
|||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
private CommandRegistrationManager commandRegistrationManager;
|
private CommandRegistrationManager commandRegistrationManager;
|
||||||
// private NBTManager nbtManager;
|
// private NBTManager nbtManager;
|
||||||
private WorldGuardManager worldGuardManager;
|
|
||||||
private PartyManager partyManager;
|
private PartyManager partyManager;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
private ChatManager chatManager;
|
private ChatManager chatManager;
|
||||||
@ -284,9 +283,6 @@ public class mcMMO extends JavaPlugin {
|
|||||||
//Init Item Tools
|
//Init Item Tools
|
||||||
itemTools = new ItemTools(this);
|
itemTools = new ItemTools(this);
|
||||||
|
|
||||||
//Init World Guard Utils (Not sure about the order of this one, might need to be loaded earlier)
|
|
||||||
worldGuardUtils = new WorldGuardUtils(this);
|
|
||||||
|
|
||||||
//Init MOTD Utils
|
//Init MOTD Utils
|
||||||
messageOfTheDayUtils = new MessageOfTheDayUtils(this);
|
messageOfTheDayUtils = new MessageOfTheDayUtils(this);
|
||||||
|
|
||||||
@ -306,10 +302,14 @@ public class mcMMO extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onLoad()
|
public void onLoad()
|
||||||
{
|
{
|
||||||
worldGuardManager = new WorldGuardManager();
|
|
||||||
|
|
||||||
if(getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
if(getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
||||||
worldGuardManager.registerFlags();
|
worldGuardUtils = new WorldGuardUtils(); //Init WGU
|
||||||
|
|
||||||
|
if(worldGuardUtils.isWorldGuardLoaded()) {
|
||||||
|
//Register flags
|
||||||
|
System.out.println("[mcMMO - Registering World Guard Flags...]");
|
||||||
|
worldGuardUtils.getWorldGuardManager().registerFlags();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,7 +755,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WorldGuardManager getWorldGuardManager() {
|
public WorldGuardManager getWorldGuardManager() {
|
||||||
return worldGuardManager;
|
return worldGuardUtils.getWorldGuardManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PartyManager getPartyManager() {
|
public PartyManager getPartyManager() {
|
||||||
|
@ -21,8 +21,8 @@ import com.gmail.nossr50.events.hardcore.McMMOPlayerVampirismEvent;
|
|||||||
import com.gmail.nossr50.events.party.McMMOPartyLevelUpEvent;
|
import com.gmail.nossr50.events.party.McMMOPartyLevelUpEvent;
|
||||||
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
|
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
|
||||||
import com.gmail.nossr50.events.party.McMMOPartyXpGainEvent;
|
import com.gmail.nossr50.events.party.McMMOPartyXpGainEvent;
|
||||||
import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent;
|
|
||||||
import com.gmail.nossr50.events.players.McMMOPlayerProfileLoadEvent;
|
import com.gmail.nossr50.events.players.McMMOPlayerProfileLoadEvent;
|
||||||
|
import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent;
|
||||||
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
|
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
|
||||||
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
|
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
|
||||||
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
||||||
|
@ -8,7 +8,6 @@ import com.gmail.nossr50.events.scoreboard.McMMOScoreboardMakeboardEvent;
|
|||||||
import com.gmail.nossr50.events.scoreboard.ScoreboardEventReason;
|
import com.gmail.nossr50.events.scoreboard.ScoreboardEventReason;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.DisplaySlot;
|
import org.bukkit.scoreboard.DisplaySlot;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.gmail.nossr50.worldguard;
|
package com.gmail.nossr50.worldguard;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
@ -9,12 +8,8 @@ import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
|
|||||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import static org.bukkit.Bukkit.getServer;
|
|
||||||
|
|
||||||
public class WorldGuardManager {
|
public class WorldGuardManager {
|
||||||
private WorldGuardPlugin worldGuardPluginRef;
|
|
||||||
|
|
||||||
public boolean hasMainFlag(Player player)
|
public boolean hasMainFlag(Player player)
|
||||||
{
|
{
|
||||||
@ -63,18 +58,6 @@ public class WorldGuardManager {
|
|||||||
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_HARDCORE_WG_FLAG);
|
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_HARDCORE_WG_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WorldGuardPlugin getWorldGuard() {
|
|
||||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
|
||||||
|
|
||||||
// WorldGuard may not be loaded
|
|
||||||
if (!(plugin instanceof WorldGuardPlugin)) {
|
|
||||||
return null; // Maybe you want throw an exception instead
|
|
||||||
}
|
|
||||||
|
|
||||||
worldGuardPluginRef = (WorldGuardPlugin) plugin;
|
|
||||||
return worldGuardPluginRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerFlags()
|
public void registerFlags()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package com.gmail.nossr50.worldguard;
|
package com.gmail.nossr50.worldguard;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -15,10 +12,9 @@ public class WorldGuardUtils {
|
|||||||
private boolean isLoaded = false;
|
private boolean isLoaded = false;
|
||||||
private boolean detectedIncompatibleWG = false;
|
private boolean detectedIncompatibleWG = false;
|
||||||
private static final ArrayList<String> WGClassList;
|
private static final ArrayList<String> WGClassList;
|
||||||
private final mcMMO pluginRef;
|
private WorldGuardManager worldGuardManager;
|
||||||
|
|
||||||
public WorldGuardUtils(mcMMO pluginRef) {
|
public WorldGuardUtils() {
|
||||||
this.pluginRef = pluginRef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -72,7 +68,7 @@ public class WorldGuardUtils {
|
|||||||
if(plugin == null) {
|
if(plugin == null) {
|
||||||
//WG is not present
|
//WG is not present
|
||||||
detectedIncompatibleWG = true;
|
detectedIncompatibleWG = true;
|
||||||
pluginRef.getLogger().info("WorldGuard was not detected.");
|
System.out.println("[mcMMO WorldGuardUtils Debug] WorldGuard was not detected.");
|
||||||
} else {
|
} else {
|
||||||
//Check that its actually of class WorldGuardPlugin
|
//Check that its actually of class WorldGuardPlugin
|
||||||
if(plugin instanceof WorldGuardPlugin)
|
if(plugin instanceof WorldGuardPlugin)
|
||||||
@ -81,6 +77,9 @@ public class WorldGuardUtils {
|
|||||||
{
|
{
|
||||||
worldGuardPluginRef = (WorldGuardPlugin) plugin;
|
worldGuardPluginRef = (WorldGuardPlugin) plugin;
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
|
|
||||||
|
//Init WG Manager
|
||||||
|
worldGuardManager = new WorldGuardManager();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Plugin is not of the expected type
|
//Plugin is not of the expected type
|
||||||
@ -88,7 +87,6 @@ public class WorldGuardUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return worldGuardPluginRef;
|
return worldGuardPluginRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +98,7 @@ public class WorldGuardUtils {
|
|||||||
*/
|
*/
|
||||||
private boolean isCompatibleVersion(Plugin plugin) {
|
private boolean isCompatibleVersion(Plugin plugin) {
|
||||||
//Check that the version of WG is at least version 7.xx
|
//Check that the version of WG is at least version 7.xx
|
||||||
boolean allClassesFound = true;
|
// boolean allClassesFound = true;
|
||||||
|
|
||||||
if (!plugin.getDescription().getVersion().startsWith("7")) {
|
if (!plugin.getDescription().getVersion().startsWith("7")) {
|
||||||
markWGIncompatible();
|
markWGIncompatible();
|
||||||
@ -111,8 +109,8 @@ public class WorldGuardUtils {
|
|||||||
Class<?> checkForClass = Class.forName(classString);
|
Class<?> checkForClass = Class.forName(classString);
|
||||||
detectedIncompatibleWG = false; //In case this was set to true previously
|
detectedIncompatibleWG = false; //In case this was set to true previously
|
||||||
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
||||||
allClassesFound = false;
|
// allClassesFound = false;
|
||||||
pluginRef.getLogger().severe("Missing WorldGuard class - "+classString);
|
System.out.println("[mcMMO WorldGuardUtils Debug] Missing WorldGuard class - "+classString);
|
||||||
markWGIncompatible();
|
markWGIncompatible();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,17 +118,17 @@ public class WorldGuardUtils {
|
|||||||
/*
|
/*
|
||||||
* If WG appears to have all of its classes we can then check to see if its been initialized properly
|
* If WG appears to have all of its classes we can then check to see if its been initialized properly
|
||||||
*/
|
*/
|
||||||
try {
|
// try {
|
||||||
if(allClassesFound) {
|
// if(allClassesFound) {
|
||||||
if(!((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).isInitialized()) {
|
// if(!((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).isInitialized()) {
|
||||||
markWGIncompatible();
|
// markWGIncompatible();
|
||||||
pluginRef.getLogger().severe("WG did not initialize properly, this can cause errors with mcMMO so mcMMO is disabling certain features.");
|
// System.out.println("[mcMMO WorldGuardUtils Debug] WG did not initialize properly, this can cause errors with mcMMO so mcMMO is disabling certain features.");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
markWGIncompatible();
|
// markWGIncompatible();
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return !detectedIncompatibleWG;
|
return !detectedIncompatibleWG;
|
||||||
@ -140,10 +138,14 @@ public class WorldGuardUtils {
|
|||||||
* Mark WG as being incompatible to avoid unnecessary operations
|
* Mark WG as being incompatible to avoid unnecessary operations
|
||||||
*/
|
*/
|
||||||
private void markWGIncompatible() {
|
private void markWGIncompatible() {
|
||||||
pluginRef.getLogger().severe("You are using a version of WG that is not compatible with mcMMO, " +
|
System.out.println("[mcMMO WorldGuardUtils Debug] You are using a version of WG that is not compatible with mcMMO, " +
|
||||||
"WG features for mcMMO will be disabled. mcMMO requires you to be using a new version of WG7 " +
|
"WG features for mcMMO will be disabled. mcMMO requires you to be using a new version of WG7 " +
|
||||||
"in order for it to use WG features. Not all versions of WG7 are compatible.");
|
"in order for it to use WG features. Not all versions of WG7 are compatible.");
|
||||||
pluginRef.getLogger().severe("mcMMO will continue to function normally, but if you wish to use WG support you must use a compatible version.");
|
System.out.println("[mcMMO WorldGuardUtils Debug] mcMMO will continue to function normally, but if you wish to use WG support you must use a compatible version.");
|
||||||
detectedIncompatibleWG = true;
|
detectedIncompatibleWG = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WorldGuardManager getWorldGuardManager() {
|
||||||
|
return worldGuardManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ author: nossr50
|
|||||||
authors: [GJ, NuclearW, bm01, Glitchfinder, TfT_02, t00thpick1, Riking, electronicboy, kashike]
|
authors: [GJ, NuclearW, bm01, Glitchfinder, TfT_02, t00thpick1, Riking, electronicboy, kashike]
|
||||||
website: https://www.mcmmo.org
|
website: https://www.mcmmo.org
|
||||||
main: com.gmail.nossr50.mcMMO
|
main: com.gmail.nossr50.mcMMO
|
||||||
softdepend: [WorldGuard, CombatTag, HealthBar]
|
softdepend: [WorldGuard, WorldEdit, CombatTag, HealthBar]
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user