From e0a87dd2ac87d7d23f4bfd5360c623fd2de07a36 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 23 Dec 2015 21:39:05 +0100 Subject: [PATCH] Made Vault soft dependency only --- .../github/dre2n/dungeonsxl/DungeonsXL.java | 101 +++++++++++------- .../dungeonsxl/dungeon/game/GameWorld.java | 2 +- .../dungeonsxl/listener/PlayerListener.java | 2 +- .../dre2n/dungeonsxl/player/DGroup.java | 6 +- .../dre2n/dungeonsxl/player/DPlayer.java | 20 +++- 5 files changed, 83 insertions(+), 48 deletions(-) diff --git a/src/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/io/github/dre2n/dungeonsxl/DungeonsXL.java index af94c916..b5e0d3f9 100644 --- a/src/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -42,6 +42,8 @@ import org.bukkit.plugin.java.JavaPlugin; public class DungeonsXL extends JavaPlugin { private static DungeonsXL plugin; + private Economy economyProvider; + private Permission permissionProvider; private MainConfig mainConfig; private DMessages dMessages; @@ -80,10 +82,10 @@ public class DungeonsXL extends JavaPlugin { initFolders(); // Setup Permissions - setupPermissions(); + loadPermissionProvider(); // Setup Economy - setupEconomy(); + loadEconomyProvider(); getCommand("dungeonsxl").setExecutor(new CommandListener()); Bukkit.getServer().getPluginManager().registerEvents(new EntityListener(), this); @@ -195,43 +197,6 @@ public class DungeonsXL extends JavaPlugin { }, 0L, 2L); } - // Permissions - public Permission permission = null; - - private Boolean setupPermissions() { - RegisteredServiceProvider permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); - if (permissionProvider != null) { - permission = permissionProvider.getProvider(); - } - return permission != null; - } - - public Boolean GroupEnabled(String group) { - - for (String agroup : permission.getGroups()) { - if (agroup.equalsIgnoreCase(group)) { - return true; - } - } - - return false; - } - - // Economy - public Economy economy = null; - - private Boolean setupEconomy() { - if (mainConfig.enableEconomy()) { - RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); - if (economyProvider != null) { - economy = economyProvider.getProvider(); - } - return economy != null; - } else { - return false; - } - } - // Save and Load public void saveData() { File file = new File(getDataFolder(), "data.yml"); @@ -293,6 +258,64 @@ public class DungeonsXL extends JavaPlugin { return plugin; } + /** + * @return the loaded instance of Economy + */ + public Economy getEconomyProvider() { + return economyProvider; + } + + /** + * load / reload a new instance of Permission + */ + public void loadEconomyProvider() { + try { + if (mainConfig.enableEconomy()) { + RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(Economy.class); + if (economyProvider != null) { + this.economyProvider = economyProvider.getProvider(); + } + } + } catch (NoClassDefFoundError error) { + getLogger().info("Could not hook into Vault to register an economy provider!"); + } + } + + /** + * @return the loaded instance of Permission + */ + public Permission getPermissionProvider() { + return permissionProvider; + } + + /** + * load / reload a new instance of Permission + */ + public void loadPermissionProvider() { + try { + RegisteredServiceProvider permissionProvider = getServer().getServicesManager().getRegistration(Permission.class); + if (permissionProvider != null) { + this.permissionProvider = permissionProvider.getProvider(); + } + } catch (NoClassDefFoundError error) { + getLogger().info("Could not hook into Vault to register a permission provider!"); + } + } + + /** + * @param group + * the group to be checked + */ + public boolean isGroupEnabled(String group) { + for (String agroup : permissionProvider.getGroups()) { + if (agroup.equalsIgnoreCase(group)) { + return true; + } + } + + return false; + } + /** * @return the loaded instance of MainConfig */ diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java b/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java index be0fa051..1b6147ae 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java @@ -198,7 +198,7 @@ public class GameWorld { WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + dungeon, "config.yml")); if (plugin.getMainConfig().enableEconomy()) { - if ( !(DungeonsXL.getPlugin().economy.getBalance(player) >= worldConfig.getFee())) { + if ( !(DungeonsXL.getPlugin().getEconomyProvider().getBalance(player) >= worldConfig.getFee())) { return false; } } diff --git a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index b70edf8e..7c78f86a 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -413,7 +413,7 @@ public class PlayerListener implements Listener { if (plugin.getMainConfig().isTutorialActivated()) { if (DPlayer.get(player) == null) { if (plugin.getMainConfig().getTutorialDungeon() != null && plugin.getMainConfig().getTutorialStartGroup() != null && plugin.getMainConfig().getTutorialEndGroup() != null) { - for (String group : plugin.permission.getPlayerGroups(player)) { + for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) { if (plugin.getMainConfig().getTutorialStartGroup().equalsIgnoreCase(group)) { DGroup dgroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false); diff --git a/src/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/io/github/dre2n/dungeonsxl/player/DGroup.java index b80a0585..5fc93f4c 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -233,8 +233,8 @@ public class DGroup { continue; } - if (plugin.economy != null) { - DungeonsXL.getPlugin().economy.withdrawPlayer(player, fee); + if (plugin.getEconomyProvider() != null) { + plugin.getEconomyProvider().withdrawPlayer(player, fee); } } @@ -249,6 +249,7 @@ public class DGroup { return dgroup; } } + return null; } @@ -258,6 +259,7 @@ public class DGroup { return dgroup; } } + return null; } diff --git a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java index b9897141..910cef69 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java @@ -145,8 +145,8 @@ public class DPlayer { if ( !isinTestMode) {// Nur wenn man nicht am Testen ist if (isFinished) { addTreasure(); - if (plugin.economy != null) { - plugin.economy.depositPlayer(player, treasureMoney); + if (plugin.getEconomyProvider() != null) { + plugin.getEconomyProvider().depositPlayer(player, treasureMoney); } // Set Time @@ -172,8 +172,15 @@ public class DPlayer { // Tutorial Permissions if (gWorld.isTutorial) { - plugin.permission.playerAddGroup(player, plugin.getMainConfig().getTutorialEndGroup()); - plugin.permission.playerRemoveGroup(player, plugin.getMainConfig().getTutorialStartGroup()); + String endGroup = plugin.getMainConfig().getTutorialEndGroup(); + if (plugin.isGroupEnabled(endGroup)) { + plugin.getPermissionProvider().playerAddGroup(player, endGroup); + } + + String startGroup = plugin.getMainConfig().getTutorialStartGroup(); + if (plugin.isGroupEnabled(startGroup)) { + plugin.getPermissionProvider().playerRemoveGroup(player, startGroup); + } } } } @@ -235,7 +242,6 @@ public class DPlayer { // Respawn Items if (GameWorld.get(world).getConfig().getKeepInventoryOnDeath()) { - org.bukkit.Bukkit.broadcastMessage("deactivated code triggered"); if (respawnInventory != null || respawnArmor != null) { player.getInventory().setContents(respawnInventory); player.getInventory().setArmorContents(respawnArmor); @@ -300,6 +306,10 @@ public class DPlayer { dGroup.removeUnplayedFloor(dGroup.getMapName()); dGroup.setMapName(newFloor); dGroup.setGWorld(GameWorld.load(newFloor)); + for (Player player : dGroup.getPlayers()) { + DPlayer dPlayer = get(player); + dPlayer.checkpoint = dGroup.getGWorld().locStart; + } dGroup.startGame(); }