diff --git a/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java b/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java index ca90f6f0..907da7fa 100644 --- a/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java +++ b/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java @@ -23,15 +23,19 @@ import de.erethon.commons.config.MessageConfig; import de.erethon.commons.javaplugin.DREPlugin; import de.erethon.commons.javaplugin.DREPluginSettings; import de.erethon.commons.misc.FileUtil; +import de.erethon.dungeonsxl.announcer.Announcer; import de.erethon.dungeonsxl.announcer.AnnouncerCache; +import de.erethon.dungeonsxl.announcer.AnnouncerListener; +import de.erethon.dungeonsxl.announcer.AnnouncerTask; import de.erethon.dungeonsxl.command.DCommandCache; import de.erethon.dungeonsxl.config.DMessage; -import de.erethon.dungeonsxl.config.GlobalData; import de.erethon.dungeonsxl.config.MainConfig; import de.erethon.dungeonsxl.dungeon.DungeonCache; import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.game.GameTypeCache; +import de.erethon.dungeonsxl.global.GlobalData; import de.erethon.dungeonsxl.global.GlobalProtectionCache; +import de.erethon.dungeonsxl.global.GlobalProtectionListener; import de.erethon.dungeonsxl.mob.DMobListener; import de.erethon.dungeonsxl.mob.DMobType; import de.erethon.dungeonsxl.mob.ExternalMobProviderCache; @@ -40,9 +44,11 @@ import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPlayerCache; import de.erethon.dungeonsxl.requirement.RequirementTypeCache; +import de.erethon.dungeonsxl.reward.RewardListener; import de.erethon.dungeonsxl.reward.RewardTypeCache; import de.erethon.dungeonsxl.sign.DSignTypeCache; import de.erethon.dungeonsxl.sign.SignScriptCache; +import de.erethon.dungeonsxl.trigger.TriggerListener; import de.erethon.dungeonsxl.trigger.TriggerTypeCache; import de.erethon.dungeonsxl.util.NoReload; import de.erethon.dungeonsxl.world.DWorldCache; @@ -121,30 +127,23 @@ public class DungeonsXL extends DREPlugin { public void onEnable() { super.onEnable(); instance = this; - - DPermission.register(); initFolders(); - loadCore(); + loadCaliburnAPI(); + DPermission.register(); + loadConfig(); + createCaches(); + initCaches(); loadData(); - new NoReload(this); } @Override public void onDisable() { - // Save saveData(); messageConfig.save(); - dGroups.clear(); - - // Delete DWorlds dWorlds.deleteAllInstances(); - - // Disable listeners HandlerList.unregisterAll(this); - - // Stop shedulers getServer().getScheduler().cancelTasks(this); } @@ -210,31 +209,46 @@ public class DungeonsXL extends DREPlugin { } } - public void loadCore() { - loadCaliburnAPI(); - // Load Language - loadMessageConfig(new File(LANGUAGES, "english.yml")); - // Load Config - loadGlobalData(new File(getDataFolder(), "data.yml")); - loadMainConfig(new File(getDataFolder(), "config.yml")); - // Load Language 2 - loadMessageConfig(new File(LANGUAGES, mainConfig.getLanguage() + ".yml")); - loadGameTypes(); - loadRequirementTypes(); - loadRewardTypes(); - loadTriggers(); - loadDSigns(); - loadDWorlds(MAPS); - loadDungeons(DUNGEONS); - loadGlobalProtections(); - loadExternalMobProviders(); - loadDPlayers(); - loadAnnouncers(ANNOUNCERS); - loadDClasses(CLASSES); - loadLootTables(LOOT_TABLES); - loadMobs(MOBS); - loadSignScripts(SIGNS); - loadDCommandCache(); + public void loadConfig() { + messageConfig = new MessageConfig(DMessage.class, new File(LANGUAGES, "english.yml")); + globalData = new GlobalData(new File(getDataFolder(), "data.yml")); + mainConfig = new MainConfig(this, new File(getDataFolder(), "config.yml")); + messageConfig = new MessageConfig(DMessage.class, new File(LANGUAGES, mainConfig.getLanguage() + ".yml")); + } + + public void createCaches() { + gameTypes = new GameTypeCache(); + requirementTypes = new RequirementTypeCache(); + rewardTypes = new RewardTypeCache(); + triggers = new TriggerTypeCache(); + dSigns = new DSignTypeCache(this); + dWorlds = new DWorldCache(this); + dungeons = new DungeonCache(this); + protections = new GlobalProtectionCache(this); + dMobProviders = new ExternalMobProviderCache(this); + dPlayers = new DPlayerCache(this); + announcers = new AnnouncerCache(); + dClasses = new DClassCache(this); + signScripts = new SignScriptCache(); + dCommands = new DCommandCache(this); + } + + public void initCaches() { + // Game types + // Requirements + Bukkit.getPluginManager().registerEvents(new RewardListener(this), this); + Bukkit.getPluginManager().registerEvents(new TriggerListener(this), this); + dSigns.init(); + dWorlds.init(MAPS); + dungeons.init(DUNGEONS); + Bukkit.getPluginManager().registerEvents(new GlobalProtectionListener(this), this); + dMobProviders.init(); + dPlayers.init(); + initAnnouncerCache(ANNOUNCERS); + dClasses.init(CLASSES); + Bukkit.getPluginManager().registerEvents(new DMobListener(), this); + signScripts.init(SIGNS); + dCommands.register(this); } // Save and load @@ -264,11 +278,14 @@ public class DungeonsXL extends DREPlugin { return caliburn; } - /** - * load / reload a new instance of CaliburnAPI if none exists - */ private void loadCaliburnAPI() { caliburn = CaliburnAPI.getInstance() == null ? new CaliburnAPI(this) : CaliburnAPI.getInstance(); + if (LOOT_TABLES.isDirectory()) { + FileUtil.getFilesForFolder(LOOT_TABLES).forEach(s -> new LootTable(caliburn, s)); + } + if (MOBS.isDirectory()) { + FileUtil.getFilesForFolder(MOBS).forEach(s -> caliburn.getExMobs().add(new DMobType(this, s))); + } } /** @@ -278,13 +295,9 @@ public class DungeonsXL extends DREPlugin { return globalData; } - /** - * load / reload a new instance of GlobalData - * - * @param file the file to load from - */ - public void loadGlobalData(File file) { - globalData = new GlobalData(file); + @Override + public DCommandCache getCommandCache() { + return dCommands; } /** @@ -294,268 +307,120 @@ public class DungeonsXL extends DREPlugin { return mainConfig; } - /** - * load / reload a new instance of MainConfig - * - * @param file the file to load from - */ - public void loadMainConfig(File file) { - mainConfig = new MainConfig(file); - } - - /** - * load / reload a new instance of MessageConfig - * - * @param file the file to load from - */ - public void loadMessageConfig(File file) { - messageConfig = new MessageConfig(DMessage.class, file); - } - - /** - * @return the loaded instance of DCommandCache - */ - @Override - public DCommandCache getCommandCache() { - return dCommands; - } - - /** - * load / reload a new instance of DCommandCache - */ - public void loadDCommandCache() { - dCommands = new DCommandCache(this); - dCommands.register(this); - } - /** * @return the dSigns */ - public DSignTypeCache getDSigns() { + public DSignTypeCache getDSignCache() { return dSigns; } - /** - * load / reload a new instance of DSignTypeCache - */ - public void loadDSigns() { - dSigns = new DSignTypeCache(); - } - /** * @return the game types */ - public GameTypeCache getGameTypes() { + public GameTypeCache getGameTypeCache() { return gameTypes; } - /** - * load / reload a new instance of GameTypeCache - */ - public void loadGameTypes() { - gameTypes = new GameTypeCache(); - } - /** * @return the requirement types */ - public RequirementTypeCache getRequirementTypes() { + public RequirementTypeCache getRequirementTypeCache() { return requirementTypes; } - /** - * load / reload a new instance of RequirementTypeCache - */ - public void loadRequirementTypes() { - requirementTypes = new RequirementTypeCache(); - } - /** * @return the reward types */ - public RewardTypeCache getRewardTypes() { + public RewardTypeCache getRewardTypeCache() { return rewardTypes; } - /** - * load / reload a new instance of RewardTypeCache - */ - public void loadRewardTypes() { - rewardTypes = new RewardTypeCache(); - } - /** * @return the triggers */ - public TriggerTypeCache getTriggers() { + public TriggerTypeCache getTriggerCache() { return triggers; } - /** - * load / reload a new instance of TriggerTypeCache - */ - public void loadTriggers() { - triggers = new TriggerTypeCache(); - } - /** * @return the loaded instance of DungeonCache */ - public DungeonCache getDungeons() { + public DungeonCache getDungeonCache() { return dungeons; } - /** - * load / reload a new instance of DungeonCache - * - * @param folder the folder to load from - */ - public void loadDungeons(File folder) { - dungeons = new DungeonCache(folder); - } - /** * @return the loaded instance of GlobalProtectionCache */ - public GlobalProtectionCache getGlobalProtections() { + public GlobalProtectionCache getGlobalProtectionCache() { return protections; } - /** - * load / reload a new instance of GlobalProtectionCache - */ - public void loadGlobalProtections() { - protections = new GlobalProtectionCache(); - } - /** * @return the loaded instance of ExternalMobProviderCache */ - public ExternalMobProviderCache getExternalMobProviders() { + public ExternalMobProviderCache getExternalMobProviderCache() { return dMobProviders; } - /** - * load / reload a new instance of ExternalMobProviderCache - */ - public void loadExternalMobProviders() { - dMobProviders = new ExternalMobProviderCache(); - } - /** * @return the loaded instance of DPlayerCache */ - public DPlayerCache getDPlayers() { + public DPlayerCache getDPlayerCache() { return dPlayers; } - /** - * load / reload a new instance of DPlayerCache - */ - public void loadDPlayers() { - dPlayers = new DPlayerCache(); - } - /** * @return the loaded instance of AnnouncerCache */ - public AnnouncerCache getAnnouncers() { + public AnnouncerCache getAnnouncerCache() { return announcers; } - /** - * load / reload a new instance of AnnouncerCache - * - * @param folder the folder to load from - */ - public void loadAnnouncers(File folder) { - announcers = new AnnouncerCache(folder); - } - - /** - * @return the loaded instance of DClasseCache - */ - public DClassCache getDClasses() { - return dClasses; - } - - /** - * load / reload a new instance of DClasseCache - * - * @param folder the folder to load from - */ - public void loadDClasses(File folder) { - dClasses = new DClassCache(folder); - } - - /** - * load / reload loot tables - * - * @param folder the folder to load from - */ - public void loadLootTables(File folder) { - for (File script : FileUtil.getFilesForFolder(folder)) { - new LootTable(caliburn, script); - } - } - - /** - * load / reload DMob types - * - * @param folder the folder to load from - */ - public void loadMobs(File folder) { - if (folder.isDirectory()) { - for (File script : FileUtil.getFilesForFolder(folder)) { - caliburn.getExMobs().add(new DMobType(script)); + private void initAnnouncerCache(File file) { + if (file.isDirectory()) { + for (File script : FileUtil.getFilesForFolder(file)) { + announcers.addAnnouncer(new Announcer(this, script)); } } - Bukkit.getPluginManager().registerEvents(new DMobListener(), this); + if (!announcers.getAnnouncers().isEmpty()) { + announcers.setAnnouncerTask(new AnnouncerTask(this).runTaskTimer(this, mainConfig.getAnnouncmentInterval(), mainConfig.getAnnouncmentInterval())); + } + Bukkit.getPluginManager().registerEvents(new AnnouncerListener(this), this); + } + + /** + * @return the loaded instance of DClassCache + */ + public DClassCache getDClassCache() { + return dClasses; } /** * @return the loaded instance of SignScriptCache */ - public SignScriptCache getSignScripts() { + public SignScriptCache getSignScriptCache() { return signScripts; } - /** - * load / reload a new instance of SignScriptCache - * - * @param folder the folder to load from - */ - public void loadSignScripts(File folder) { - signScripts = new SignScriptCache(folder); - } - /** * @return the loaded instance of DWorldCache */ - public DWorldCache getDWorlds() { + public DWorldCache getDWorldCache() { return dWorlds; } - /** - * load / reload a new instance of DWorldCache - * - * @param folder the folder to load from - */ - public void loadDWorlds(File folder) { - dWorlds = new DWorldCache(MAPS); - } - /** * @return the games */ - public List getGames() { + public List getGameCache() { return games; } /** * @return the dGroups */ - public List getDGroups() { + public List getDGroupCache() { return dGroups; } diff --git a/src/main/java/de/erethon/dungeonsxl/announcer/Announcer.java b/src/main/java/de/erethon/dungeonsxl/announcer/Announcer.java index 66817a20..8ce1c17b 100644 --- a/src/main/java/de/erethon/dungeonsxl/announcer/Announcer.java +++ b/src/main/java/de/erethon/dungeonsxl/announcer/Announcer.java @@ -51,7 +51,7 @@ import org.bukkit.material.Wool; */ public class Announcer { - DungeonsXL plugin = DungeonsXL.getInstance(); + private DungeonsXL plugin; private String name; @@ -73,17 +73,21 @@ public class Announcer { private AnnouncerStartGameTask startTask; /** - * @param file the script file + * @param plugin the plugin instance + * @param file the script file */ - public Announcer(File file) { - this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file)); + public Announcer(DungeonsXL plugin, File file) { + this(plugin, file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file)); } /** + * @param plugin the plugin instance * @param name the name of the Announcer * @param config the config that stores the information */ - public Announcer(String name, FileConfiguration config) { + public Announcer(DungeonsXL plugin, String name, FileConfiguration config) { + this.plugin = plugin; + this.name = name; description = config.getStringList("description"); @@ -94,7 +98,7 @@ public class Announcer { if (multiFloor) { dungeonName = identifier; - Dungeon dungeon = plugin.getDungeons().getByName(identifier); + Dungeon dungeon = plugin.getDungeonCache().getByName(identifier); if (dungeon != null) { mapName = dungeon.getConfig().getStartFloor().getName(); } @@ -128,7 +132,7 @@ public class Announcer { if (multiFloor) { dungeonName = identifier; - Dungeon dungeon = plugin.getDungeons().getByName(identifier); + Dungeon dungeon = plugin.getDungeonCache().getByName(identifier); if (dungeon != null) { mapName = dungeon.getConfig().getStartFloor().getName(); } @@ -374,7 +378,7 @@ public class Announcer { DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.ANNOUNCER); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { - dGroups.set(buttons.indexOf(button), new DGroup(player, color)); + dGroups.set(buttons.indexOf(button), new DGroup(plugin, player, color)); } } else if (dGroup == null && pGroup != null) { @@ -391,7 +395,7 @@ public class Announcer { if (areRequirementsFulfilled()) { if (startTask == null) { - startTask = new AnnouncerStartGameTask(this); + startTask = new AnnouncerStartGameTask(plugin, this); startTask.runTaskLater(plugin, 20 * 30L); } else { startTask.getProgressBar().addPlayer(player); @@ -412,7 +416,7 @@ public class Announcer { List lore = new ArrayList<>(); DGroup dGroup = dGroups.get(groupCount); - if (!plugin.getDGroups().contains(dGroup)) { + if (!plugin.getDGroupCache().contains(dGroup)) { dGroups.set(groupCount, null); } else if (dGroup != null) { diff --git a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerCache.java b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerCache.java index 74ebe3fb..0a108e94 100644 --- a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerCache.java +++ b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerCache.java @@ -16,14 +16,11 @@ */ package de.erethon.dungeonsxl.announcer; -import de.erethon.commons.misc.FileUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import java.io.File; import java.util.ArrayList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitTask; /** @@ -33,22 +30,10 @@ import org.bukkit.scheduler.BukkitTask; */ public class AnnouncerCache { - DungeonsXL plugin = DungeonsXL.getInstance(); - private BukkitTask announcerTask; private List announcers = new ArrayList<>(); - public AnnouncerCache(File file) { - if (file.isDirectory()) { - for (File script : FileUtil.getFilesForFolder(file)) { - announcers.add(new Announcer(script)); - } - } - startAnnouncerTask(plugin.getMainConfig().getAnnouncmentInterval()); - Bukkit.getPluginManager().registerEvents(new AnnouncerListener(), plugin); - } - /** * @param name the name * @return the announcer that has the name @@ -106,14 +91,10 @@ public class AnnouncerCache { } /** - * start a new AnnouncerTask - * - * @param period the period ticks + * @param announcerTask the AnnouncerTask to set */ - public void startAnnouncerTask(long period) { - if (!announcers.isEmpty()) { - announcerTask = new AnnouncerTask(this).runTaskTimer(plugin, period, period); - } + public void setAnnouncerTask(BukkitTask announcerTask) { + this.announcerTask = announcerTask; } } diff --git a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerListener.java b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerListener.java index 5a160896..7f98e04d 100644 --- a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerListener.java +++ b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerListener.java @@ -30,6 +30,12 @@ import org.bukkit.material.Wool; */ public class AnnouncerListener implements Listener { + private AnnouncerCache announcers; + + public AnnouncerListener(DungeonsXL plugin) { + announcers = plugin.getAnnouncerCache(); + } + @EventHandler public void onButtonClick(InventoryClickEvent event) { if (!(event.getWhoClicked() instanceof Player)) { @@ -39,7 +45,7 @@ public class AnnouncerListener implements Listener { Inventory gui = event.getInventory(); ItemStack button = event.getCurrentItem(); - Announcer announcer = DungeonsXL.getInstance().getAnnouncers().getByGUI(gui); + Announcer announcer = announcers.getByGUI(gui); if (announcer != null && button != null && button.getData() instanceof Wool) { announcer.clickGroupButton(player, button); } diff --git a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerStartGameTask.java b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerStartGameTask.java index 94350d64..859605d8 100644 --- a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerStartGameTask.java +++ b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerStartGameTask.java @@ -33,12 +33,15 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class AnnouncerStartGameTask extends BukkitRunnable { + private DungeonsXL plugin; + private Announcer announcer; private ProgressBar bar; - public AnnouncerStartGameTask(Announcer announcer) { - this.announcer = announcer; + public AnnouncerStartGameTask(DungeonsXL plugin, Announcer announcer) { + this.plugin = plugin; + this.announcer = announcer; HashSet players = new HashSet<>(); for (DGroup dGroup : announcer.getDGroups()) { if (dGroup == null) { @@ -49,7 +52,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable { } } bar = new ProgressBar(players, 30); - bar.runTaskTimer(DungeonsXL.getInstance(), 0L, 20L); + bar.send(plugin); } /** @@ -74,7 +77,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable { } if (game == null) { - DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(announcer.getMapName()); + DResourceWorld resource = plugin.getDWorldCache().getResourceByName(announcer.getMapName()); if (resource == null) { dGroup.sendMessage(DMessage.ERROR_NO_SUCH_MAP.getMessage(announcer.getMapName())); cancel(); @@ -86,7 +89,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable { cancel(); return; } - game = new Game(dGroup, gameWorld); + game = new Game(plugin, dGroup, gameWorld); } else { game.getDGroups().add(dGroup); } @@ -101,7 +104,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable { } for (Player player : game.getPlayers()) { - new DGamePlayer(player, game.getWorld()); + new DGamePlayer(plugin, player, game.getWorld()); } announcer.endStartTask(); diff --git a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerTask.java b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerTask.java index 383c0c4f..5ed8445d 100644 --- a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerTask.java +++ b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerTask.java @@ -29,11 +29,15 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class AnnouncerTask extends BukkitRunnable { + private DungeonsXL plugin; + private List announcers; private int index; - public AnnouncerTask(AnnouncerCache announcers) { - this.announcers = announcers.getAnnouncers(); + public AnnouncerTask(DungeonsXL plugin) { + this.plugin = plugin; + + this.announcers = plugin.getAnnouncerCache().getAnnouncers(); index = 0; } @@ -42,7 +46,7 @@ public class AnnouncerTask extends BukkitRunnable { Announcer announcer = announcers.get(index); List worlds = announcer.getWorlds(); for (Player player : Bukkit.getOnlinePlayers()) { - DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = plugin.getDPlayerCache().getByPlayer(player); if (!(dPlayer instanceof DInstancePlayer) && dPlayer.isAnnouncerEnabled()) { if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) { announcer.send(player); diff --git a/src/main/java/de/erethon/dungeonsxl/command/BreakCommand.java b/src/main/java/de/erethon/dungeonsxl/command/BreakCommand.java index 05ceafb8..823b7d50 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/BreakCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/BreakCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGlobalPlayer; @@ -28,9 +27,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class BreakCommand extends DRECommand { +public class BreakCommand extends DCommand { - public BreakCommand() { + public BreakCommand(DungeonsXL plugin) { + super(plugin); setCommand("break"); setMinArgs(0); setMaxArgs(0); @@ -42,7 +42,7 @@ public class BreakCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dGlobalPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player); if (dGlobalPlayer.isInBreakMode()) { dGlobalPlayer.setInBreakMode(false); diff --git a/src/main/java/de/erethon/dungeonsxl/command/ChatCommand.java b/src/main/java/de/erethon/dungeonsxl/command/ChatCommand.java index 726690cc..b10b470c 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/ChatCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/ChatCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DEditPlayer; @@ -30,9 +29,10 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class ChatCommand extends DRECommand { +public class ChatCommand extends DCommand { - public ChatCommand() { + public ChatCommand(DungeonsXL plugin) { + super(plugin); setCommand("chat"); setMinArgs(0); setMaxArgs(0); @@ -44,7 +44,7 @@ public class ChatCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); if (DGroup.getByPlayer(player) == null && !(dPlayer instanceof DEditPlayer)) { MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage()); diff --git a/src/main/java/de/erethon/dungeonsxl/command/ChatSpyCommand.java b/src/main/java/de/erethon/dungeonsxl/command/ChatSpyCommand.java index cb350662..f85d546b 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/ChatSpyCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/ChatSpyCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGlobalPlayer; @@ -28,9 +27,10 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class ChatSpyCommand extends DRECommand { +public class ChatSpyCommand extends DCommand { - public ChatSpyCommand() { + public ChatSpyCommand(DungeonsXL plugin) { + super(plugin); setCommand("chatSpy"); setMinArgs(0); setMaxArgs(0); @@ -42,7 +42,7 @@ public class ChatSpyCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); dPlayer.setInChatSpyMode(!dPlayer.isInChatSpyMode()); MessageUtil.sendMessage(player, (dPlayer.isInChatSpyMode() ? DMessage.CMD_CHATSPY_START : DMessage.CMD_CHATSPY_STOPPED).getMessage()); diff --git a/src/main/java/de/erethon/dungeonsxl/command/CreateCommand.java b/src/main/java/de/erethon/dungeonsxl/command/CreateCommand.java index 48a60b8e..5e0ef3fe 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/CreateCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/CreateCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DEditPlayer; @@ -33,11 +32,10 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class CreateCommand extends DRECommand { +public class CreateCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - - public CreateCommand() { + public CreateCommand(DungeonsXL plugin) { + super(plugin); setMinArgs(1); setMaxArgs(1); setCommand("create"); @@ -67,8 +65,8 @@ public class CreateCommand extends DRECommand { MessageUtil.log(plugin, DMessage.LOG_GENERATE_NEW_WORLD.getMessage()); // Create World - DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), name); - plugin.getDWorlds().addResource(resource); + DResourceWorld resource = new DResourceWorld(plugin, name); + instances.addResource(resource); DEditWorld editWorld = resource.generate(); editWorld.save(); editWorld.delete(); @@ -89,15 +87,15 @@ public class CreateCommand extends DRECommand { MessageUtil.log(plugin, DMessage.LOG_GENERATE_NEW_WORLD.getMessage()); // Create World - DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), name); - plugin.getDWorlds().addResource(resource); + DResourceWorld resource = new DResourceWorld(plugin, name); + instances.addResource(resource); DEditWorld editWorld = resource.generate(); // MSG Done MessageUtil.log(plugin, DMessage.LOG_WORLD_GENERATION_FINISHED.getMessage()); // Tp Player - new DEditPlayer(player, editWorld); + new DEditPlayer(plugin, player, editWorld); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/DCommand.java b/src/main/java/de/erethon/dungeonsxl/command/DCommand.java new file mode 100644 index 00000000..7b7656b1 --- /dev/null +++ b/src/main/java/de/erethon/dungeonsxl/command/DCommand.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2012-2018 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.command; + +import de.erethon.commons.command.DRECommand; +import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.config.MainConfig; +import de.erethon.dungeonsxl.player.DPlayerCache; +import de.erethon.dungeonsxl.world.DWorldCache; + +/** + * @author Daniel Saukel + */ +public abstract class DCommand extends DRECommand { + + protected DungeonsXL plugin; + protected MainConfig config; + protected DPlayerCache dPlayers; + protected DWorldCache instances; + + protected DCommand(DungeonsXL plugin) { + this.plugin = plugin; + config = plugin.getMainConfig(); + dPlayers = plugin.getDPlayerCache(); + instances = plugin.getDWorldCache(); + } + +} diff --git a/src/main/java/de/erethon/dungeonsxl/command/DCommandCache.java b/src/main/java/de/erethon/dungeonsxl/command/DCommandCache.java index 8808cd9b..31c3e9ff 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/DCommandCache.java +++ b/src/main/java/de/erethon/dungeonsxl/command/DCommandCache.java @@ -19,7 +19,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.command.DRECommand; import de.erethon.commons.command.DRECommandCache; import de.erethon.commons.compatibility.CompatibilityHandler; -import de.erethon.commons.javaplugin.DREPlugin; import de.erethon.dungeonsxl.DungeonsXL; /** @@ -29,72 +28,104 @@ import de.erethon.dungeonsxl.DungeonsXL; */ public class DCommandCache extends DRECommandCache { - public static BreakCommand BREAK = new BreakCommand(); - public static ChatCommand CHAT = new ChatCommand(); - public static ChatSpyCommand CHAT_SPY = new ChatSpyCommand(); - public static CreateCommand CREATE = new CreateCommand(); - public static EditCommand EDIT = new EditCommand(); - public static EnterCommand ENTER = new EnterCommand(); - public static EscapeCommand ESCAPE = new EscapeCommand(); - public static DeleteCommand DELETE = new DeleteCommand(); - public static DungeonItemCommand DUNGEON_ITEM = new DungeonItemCommand(); - public static GameCommand GAME = new GameCommand(); - public static GroupCommand GROUP = new GroupCommand(); - public static HelpCommand HELP = new HelpCommand(); - public static ImportCommand IMPORT = new ImportCommand(); - public static InviteCommand INVITE = new InviteCommand(); - public static JoinCommand JOIN = new JoinCommand(); - public static KickCommand KICK = new KickCommand(); - public static LeaveCommand LEAVE = new LeaveCommand(); - public static ListCommand LIST = new ListCommand(); - public static LivesCommand LIVES = new LivesCommand(); - public static MainCommand MAIN = new MainCommand(); - public static MsgCommand MESSAGE = new MsgCommand(); - public static PlayCommand PLAY = new PlayCommand(); - public static PortalCommand PORTAL = new PortalCommand(); - public static DRECommand RELOAD = CompatibilityHandler.getInstance().isSpigot() ? new ReloadCommand() : new ReloadCommandNoSpigot(); - public static RenameCommand RENAME = new RenameCommand(); - public static ResourcePackCommand RESOURCE_PACK = new ResourcePackCommand(); - public static SaveCommand SAVE = new SaveCommand(); - public static StatusCommand STATUS = new StatusCommand(); - public static TestCommand TEST = new TestCommand(); - public static UninviteCommand UNINVITE = new UninviteCommand(); + public static final String LABEL = "dungeonsxl"; - public DCommandCache(DREPlugin plugin) { - super("dungeonsxl", plugin, - BREAK, - CREATE, - DELETE, - DUNGEON_ITEM, - EDIT, - ENTER, - ESCAPE, - GAME, - GROUP, - HELP, - IMPORT, - INVITE, - JOIN, - KICK, - LEAVE, - LIST, - LIVES, - MAIN, - MESSAGE, - PLAY, - PORTAL, - RELOAD, - RENAME, - RESOURCE_PACK, - SAVE, - STATUS, - TEST, - UNINVITE, - new DeletePortalCommand() - ); - if (DungeonsXL.getInstance().getMainConfig().isChatEnabled()) { - addCommand(CHAT); - addCommand(CHAT_SPY); + public BreakCommand breakCmd; + public ChatCommand chat; + public ChatSpyCommand chatSpy; + public CreateCommand create; + public EditCommand edit; + public EnterCommand enter; + public EscapeCommand escape; + public DeleteCommand delete; + public DungeonItemCommand dungeonItem; + public GameCommand game; + public GroupCommand group; + public HelpCommand help; + public ImportCommand importCmd; + public InviteCommand invite; + public JoinCommand join; + public KickCommand kick; + public LeaveCommand leave; + public ListCommand list; + public LivesCommand lives; + public MainCommand main; + public MsgCommand message; + public PlayCommand play; + public PortalCommand portal; + public DRECommand reload; + public RenameCommand rename; + public ResourcePackCommand resourcePack; + public SaveCommand save; + public StatusCommand status; + public TestCommand test; + public UninviteCommand uninvite; + + public DCommandCache(DungeonsXL plugin) { + super(LABEL, plugin); + + breakCmd = new BreakCommand(plugin); + chat = new ChatCommand(plugin); + chatSpy = new ChatSpyCommand(plugin); + create = new CreateCommand(plugin); + edit = new EditCommand(plugin); + enter = new EnterCommand(plugin); + escape = new EscapeCommand(plugin); + delete = new DeleteCommand(plugin); + dungeonItem = new DungeonItemCommand(plugin); + game = new GameCommand(plugin); + group = new GroupCommand(plugin); + help = new HelpCommand(plugin); + importCmd = new ImportCommand(plugin); + invite = new InviteCommand(plugin); + join = new JoinCommand(plugin); + kick = new KickCommand(plugin); + leave = new LeaveCommand(plugin); + list = new ListCommand(plugin); + lives = new LivesCommand(plugin); + main = new MainCommand(plugin); + message = new MsgCommand(plugin); + play = new PlayCommand(plugin); + portal = new PortalCommand(plugin); + reload = CompatibilityHandler.getInstance().isSpigot() ? new ReloadCommand(plugin) : new ReloadCommandNoSpigot(plugin); + rename = new RenameCommand(plugin); + resourcePack = new ResourcePackCommand(plugin); + save = new SaveCommand(plugin); + status = new StatusCommand(plugin); + test = new TestCommand(plugin); + uninvite = new UninviteCommand(plugin); + + addCommand(breakCmd); + addCommand(create); + addCommand(delete); + addCommand(dungeonItem); + addCommand(edit); + addCommand(enter); + addCommand(escape); + addCommand(game); + addCommand(group); + addCommand(help); + addCommand(importCmd); + addCommand(invite); + addCommand(join); + addCommand(kick); + addCommand(leave); + addCommand(list); + addCommand(lives); + addCommand(main); + addCommand(message); + addCommand(play); + addCommand(portal); + addCommand(reload); + addCommand(rename); + addCommand(resourcePack); + addCommand(save); + addCommand(status); + addCommand(test); + addCommand(uninvite); + if (plugin.getMainConfig().isChatEnabled()) { + addCommand(chat); + addCommand(chatSpy); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/DeleteCommand.java b/src/main/java/de/erethon/dungeonsxl/command/DeleteCommand.java index 74f3033f..9fe03aa3 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/DeleteCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/DeleteCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.misc.FileUtil; import de.erethon.dungeonsxl.DungeonsXL; @@ -25,7 +24,6 @@ import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DResourceWorld; -import de.erethon.dungeonsxl.world.DWorldCache; import java.io.File; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; @@ -35,9 +33,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class DeleteCommand extends DRECommand { +public class DeleteCommand extends DCommand { - public DeleteCommand() { + public DeleteCommand(DungeonsXL plugin) { + super(plugin); setCommand("delete"); setMinArgs(1); setMaxArgs(2); @@ -49,9 +48,7 @@ public class DeleteCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { - DWorldCache dWorlds = DungeonsXL.getInstance().getDWorlds(); - - DResourceWorld resource = dWorlds.getResourceByName(args[1]); + DResourceWorld resource = instances.getResourceByName(args[1]); if (resource == null) { MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1])); return; @@ -72,12 +69,12 @@ public class DeleteCommand extends DRECommand { return; } - for (DEditWorld editWorld : dWorlds.getEditWorlds()) { + for (DEditWorld editWorld : instances.getEditWorlds()) { if (editWorld.getResource().equals(resource)) { editWorld.delete(false); } } - dWorlds.removeResource(resource); + instances.removeResource(resource); FileUtil.removeDir(resource.getFolder()); if (args[2].equalsIgnoreCase("true")) { diff --git a/src/main/java/de/erethon/dungeonsxl/command/DeletePortalCommand.java b/src/main/java/de/erethon/dungeonsxl/command/DeletePortalCommand.java deleted file mode 100644 index 3d04a9ce..00000000 --- a/src/main/java/de/erethon/dungeonsxl/command/DeletePortalCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2012-2018 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.command; - -import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; -import de.erethon.dungeonsxl.config.DMessage; -import de.erethon.dungeonsxl.global.DPortal; -import java.util.Set; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * @author Frank Baumann, Daniel Saukel - * @deprecated Use BreakCommand instead. - */ -@Deprecated -public class DeletePortalCommand extends DRECommand { - - public DeletePortalCommand() { - setCommand("deleteportal"); - setMinArgs(0); - setMaxArgs(0); - setHelp("/dxl deleteportal - Deletes the portal you are looking at"); - setPermission("dxl.portal"); - setPlayerCommand(true); - } - - @Override - public void onExecute(String[] args, CommandSender sender) { - Player player = (Player) sender; - DPortal dPortal = DPortal.getByLocation(player.getTargetBlock((Set) null, 20).getLocation()); - - if (dPortal != null) { - dPortal.delete(); - MessageUtil.sendMessage(player, DMessage.PLAYER_PROTECTED_BLOCK_DELETED.getMessage()); - - } else { - MessageUtil.sendMessage(player, DMessage.ERROR_NO_PROTECTED_BLOCK.getMessage()); - } - } - -} diff --git a/src/main/java/de/erethon/dungeonsxl/command/DungeonItemCommand.java b/src/main/java/de/erethon/dungeonsxl/command/DungeonItemCommand.java index d0135ab7..683fad06 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/DungeonItemCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/DungeonItemCommand.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.util.NBTUtil; @@ -29,9 +29,10 @@ import org.bukkit.inventory.PlayerInventory; /** * @author Frank Baumann, Daniel Saukel */ -public class DungeonItemCommand extends DRECommand { +public class DungeonItemCommand extends DCommand { - public DungeonItemCommand() { + public DungeonItemCommand(DungeonsXL plugin) { + super(plugin); setCommand("dungeonItem"); setAliases("di"); setMinArgs(0); diff --git a/src/main/java/de/erethon/dungeonsxl/command/EditCommand.java b/src/main/java/de/erethon/dungeonsxl/command/EditCommand.java index ec079319..f76ea85e 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/EditCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/EditCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DEditPlayer; @@ -27,18 +26,16 @@ import de.erethon.dungeonsxl.player.DInstancePlayer; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DResourceWorld; -import de.erethon.dungeonsxl.world.DWorldCache; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ -public class EditCommand extends DRECommand { +public class EditCommand extends DCommand { - DWorldCache worlds = DungeonsXL.getInstance().getDWorlds(); - - public EditCommand() { + public EditCommand(DungeonsXL plugin) { + super(plugin); setCommand("edit"); setMinArgs(1); setMaxArgs(1); @@ -51,12 +48,12 @@ public class EditCommand extends DRECommand { Player player = (Player) sender; String mapName = args[1]; - if (!worlds.exists(mapName)) { + if (!instances.exists(mapName)) { MessageUtil.sendMessage(player, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(mapName)); return; } - DResourceWorld resource = worlds.getResourceByName(mapName); + DResourceWorld resource = instances.getResourceByName(mapName); if (resource == null) { MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(mapName)); return; @@ -74,7 +71,7 @@ public class EditCommand extends DRECommand { } DGroup dGroup = DGroup.getByPlayer(player); - DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); if (dPlayer instanceof DInstancePlayer) { MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage()); @@ -86,7 +83,7 @@ public class EditCommand extends DRECommand { return; } - new DEditPlayer(player, editWorld); + new DEditPlayer(plugin, player, editWorld); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java b/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java index 0ad6ecab..063a1dd8 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.player.DGamePlayer; @@ -30,9 +30,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class EnterCommand extends DRECommand { +public class EnterCommand extends DCommand { - public EnterCommand() { + public EnterCommand(DungeonsXL plugin) { + super(plugin); setMinArgs(1); setMaxArgs(2); setCommand("enter"); @@ -73,7 +74,7 @@ public class EnterCommand extends DRECommand { } if (joining == null) { - joining = new DGroup(captain, game.getDungeon()); + joining = new DGroup(plugin, captain, game.getDungeon()); } if (joining.getCaptain() != captain && !DPermission.hasPermission(sender, DPermission.BYPASS)) { @@ -86,7 +87,7 @@ public class EnterCommand extends DRECommand { joining.sendMessage(DMessage.CMD_ENTER_SUCCESS.getMessage(joining.getName(), target.getName())); for (Player player : joining.getPlayers().getOnlinePlayers()) { - new DGamePlayer(player, game.getWorld(), game.getType()); + new DGamePlayer(plugin, player, game.getWorld(), game.getType()); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/EscapeCommand.java b/src/main/java/de/erethon/dungeonsxl/command/EscapeCommand.java index e31c2b05..4612ac76 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/EscapeCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/EscapeCommand.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DEditPlayer; import de.erethon.dungeonsxl.player.DGamePlayer; @@ -30,9 +30,10 @@ import org.bukkit.entity.Player; /** * @author Milan Albrecht, Daniel Saukel */ -public class EscapeCommand extends DRECommand { +public class EscapeCommand extends DCommand { - public EscapeCommand() { + public EscapeCommand(DungeonsXL plugin) { + super(plugin); setCommand("escape"); setMinArgs(0); setMaxArgs(0); diff --git a/src/main/java/de/erethon/dungeonsxl/command/GameCommand.java b/src/main/java/de/erethon/dungeonsxl/command/GameCommand.java index 324fc304..1d74288b 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/GameCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/GameCommand.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.player.DGroup; @@ -29,9 +29,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class GameCommand extends DRECommand { +public class GameCommand extends DCommand { - public GameCommand() { + public GameCommand(DungeonsXL plugin) { + super(plugin); setCommand("game"); setMinArgs(0); setMaxArgs(0); diff --git a/src/main/java/de/erethon/dungeonsxl/command/GroupCommand.java b/src/main/java/de/erethon/dungeonsxl/command/GroupCommand.java index 7c224fc9..604b9985 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/GroupCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/GroupCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.event.dgroup.DGroupCreateEvent; @@ -33,9 +32,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class GroupCommand extends DRECommand { +public class GroupCommand extends DCommand { - public GroupCommand() { + public GroupCommand(DungeonsXL plugin) { + super(plugin); setCommand("group"); setMinArgs(0); setMaxArgs(2); @@ -122,7 +122,7 @@ public class GroupCommand extends DRECommand { return; } - DGroup dGroup = new DGroup(args[2], player); + DGroup dGroup = new DGroup(plugin, args[2], player); DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); Bukkit.getPluginManager().callEvent(event); @@ -266,7 +266,7 @@ public class GroupCommand extends DRECommand { } public void showHelp(String page) { - MessageUtil.sendPluginTag(sender, DungeonsXL.getInstance()); + MessageUtil.sendPluginTag(sender, plugin); switch (page) { default: MessageUtil.sendCenteredMessage(sender, "&4&l[ &61-5 &4/ &67 &4| &61 &4&l]"); diff --git a/src/main/java/de/erethon/dungeonsxl/command/HelpCommand.java b/src/main/java/de/erethon/dungeonsxl/command/HelpCommand.java index c09d78a8..a6e7cfbe 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/HelpCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/HelpCommand.java @@ -29,11 +29,10 @@ import org.bukkit.command.CommandSender; /** * @author Frank Baumann, Daniel Saukel */ -public class HelpCommand extends DRECommand { +public class HelpCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - - public HelpCommand() { + public HelpCommand(DungeonsXL plugin) { + super(plugin); setCommand("help"); setMinArgs(0); setMaxArgs(1); diff --git a/src/main/java/de/erethon/dungeonsxl/command/ImportCommand.java b/src/main/java/de/erethon/dungeonsxl/command/ImportCommand.java index 4b79e5c1..de5ff678 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/ImportCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/ImportCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.commons.misc.FileUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; @@ -32,11 +31,10 @@ import org.bukkit.command.CommandSender; /** * @author Frank Baumann, Daniel Saukel */ -public class ImportCommand extends DRECommand { +public class ImportCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - - public ImportCommand() { + public ImportCommand(DungeonsXL plugin) { + super(plugin); setMinArgs(1); setMaxArgs(1); setCommand("import"); @@ -71,12 +69,12 @@ public class ImportCommand extends DRECommand { FileUtil.copyDir(source, target, "playerdata", "stats"); - DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), args[1]); + DResourceWorld resource = new DResourceWorld(plugin, args[1]); if (world.getEnvironment() != Environment.NORMAL) { resource.getConfig(true).setWorldEnvironment(world.getEnvironment()); resource.getConfig().save(); } - plugin.getDWorlds().addResource(resource); + instances.addResource(resource); MessageUtil.sendMessage(sender, DMessage.CMD_IMPORT_SUCCESS.getMessage(args[1])); } diff --git a/src/main/java/de/erethon/dungeonsxl/command/InviteCommand.java b/src/main/java/de/erethon/dungeonsxl/command/InviteCommand.java index 3042ea21..3f2b1fa7 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/InviteCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/InviteCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DPermission; @@ -29,9 +28,10 @@ import org.bukkit.command.CommandSender; /** * @author Frank Baumann, Daniel Saukel */ -public class InviteCommand extends DRECommand { +public class InviteCommand extends DCommand { - public InviteCommand() { + public InviteCommand(DungeonsXL plugin) { + super(plugin); setMinArgs(2); setMaxArgs(2); setCommand("invite"); @@ -43,7 +43,7 @@ public class InviteCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { - DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(args[2]); + DResourceWorld resource = instances.getResourceByName(args[2]); OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); if (resource != null) { diff --git a/src/main/java/de/erethon/dungeonsxl/command/JoinCommand.java b/src/main/java/de/erethon/dungeonsxl/command/JoinCommand.java index daaf701f..87906da1 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/JoinCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/JoinCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.announcer.Announcer; import de.erethon.dungeonsxl.config.DMessage; @@ -30,9 +29,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class JoinCommand extends DRECommand { +public class JoinCommand extends DCommand { - public JoinCommand() { + public JoinCommand(DungeonsXL plugin) { + super(plugin); setCommand("join"); setMinArgs(1); setMaxArgs(1); @@ -43,13 +43,13 @@ public class JoinCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { - DGlobalPlayer player = DungeonsXL.getInstance().getDPlayers().getByPlayer((Player) sender); + DGlobalPlayer player = dPlayers.getByPlayer((Player) sender); if (player instanceof DInstancePlayer) { MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GAME.getMessage()); return; } - Announcer announcer = DungeonsXL.getInstance().getAnnouncers().getByName(args[1]); + Announcer announcer = plugin.getAnnouncerCache().getByName(args[1]); if (announcer != null) { announcer.showGUI((Player) sender); } diff --git a/src/main/java/de/erethon/dungeonsxl/command/KickCommand.java b/src/main/java/de/erethon/dungeonsxl/command/KickCommand.java index b46ee92c..8fc949d3 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/KickCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/KickCommand.java @@ -17,8 +17,7 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; -import static de.erethon.dungeonsxl.command.DCommandCache.LEAVE; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DPermission; import org.bukkit.Bukkit; @@ -28,9 +27,10 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class KickCommand extends DRECommand { +public class KickCommand extends DCommand { - public KickCommand() { + public KickCommand(DungeonsXL plugin) { + super(plugin); setCommand("kick"); setMinArgs(1); setMaxArgs(1); @@ -45,7 +45,7 @@ public class KickCommand extends DRECommand { Player player = Bukkit.getPlayer(args[1]); if (player != null) { - LEAVE.onExecute(new String[]{LEAVE.getCommand()}, player); + plugin.getCommandCache().leave.onExecute(new String[]{plugin.getCommandCache().leave.getCommand()}, player); MessageUtil.sendMessage(sender, DMessage.CMD_KICK_SUCCESS.getMessage(player.getName())); } else { diff --git a/src/main/java/de/erethon/dungeonsxl/command/LeaveCommand.java b/src/main/java/de/erethon/dungeonsxl/command/LeaveCommand.java index 1ef466a7..7efc0e43 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/LeaveCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/LeaveCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent; @@ -36,9 +35,10 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class LeaveCommand extends DRECommand { +public class LeaveCommand extends DCommand { - public LeaveCommand() { + public LeaveCommand(DungeonsXL plugin) { + super(plugin); setCommand("leave"); setMinArgs(0); setMaxArgs(0); @@ -50,7 +50,7 @@ public class LeaveCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); Game game = Game.getByPlayer(player); if (game != null && game.isTutorial()) { diff --git a/src/main/java/de/erethon/dungeonsxl/command/ListCommand.java b/src/main/java/de/erethon/dungeonsxl/command/ListCommand.java index 322c9059..39771984 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/ListCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/ListCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.commons.misc.NumberUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; @@ -36,12 +35,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class ListCommand extends DRECommand { +public class ListCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - DWorldCache worlds = plugin.getDWorlds(); - - public ListCommand() { + public ListCommand(DungeonsXL plugin) { + super(plugin); setCommand("list"); setMinArgs(0); setMaxArgs(3); @@ -54,7 +51,7 @@ public class ListCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { ArrayList dungeonList = new ArrayList<>(); - for (Dungeon dungeon : plugin.getDungeons().getDungeons()) { + for (Dungeon dungeon : plugin.getDungeonCache().getDungeons()) { dungeonList.add(dungeon.getName()); } ArrayList mapList = new ArrayList<>(); @@ -64,10 +61,10 @@ public class ListCommand extends DRECommand { } } ArrayList loadedList = new ArrayList<>(); - for (DEditWorld editWorld : worlds.getEditWorlds()) { + for (DEditWorld editWorld : instances.getEditWorlds()) { loadedList.add(editWorld.getWorld().getWorldFolder().getName() + " / " + editWorld.getName()); } - for (DGameWorld gameWorld : worlds.getGameWorlds()) { + for (DGameWorld gameWorld : instances.getGameWorlds()) { loadedList.add(gameWorld.getWorld().getWorldFolder().getName() + " / " + gameWorld.getName()); } ArrayList toSend = new ArrayList<>(); @@ -78,7 +75,7 @@ public class ListCommand extends DRECommand { if (args.length >= 2) { if (args[1].equalsIgnoreCase("dungeons") || args[1].equalsIgnoreCase("d")) { if (args.length >= 3) { - Dungeon dungeon = plugin.getDungeons().getByName(args[2]); + Dungeon dungeon = plugin.getDungeonCache().getByName(args[2]); if (dungeon != null) { MessageUtil.sendPluginTag(sender, plugin); MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dungeon.getName() + " &4&l]"); @@ -133,7 +130,7 @@ public class ListCommand extends DRECommand { for (String map : toSend) { boolean invited = false; if (sender instanceof Player) { - DResourceWorld resource = worlds.getResourceByName(map); + DResourceWorld resource = instances.getResourceByName(map); if (resource != null) { invited = resource.isInvitedPlayer((Player) sender); } @@ -145,7 +142,7 @@ public class ListCommand extends DRECommand { case 1: MessageUtil.sendMessage(sender, "&4Dungeon&7 | &eMap count"); for (String dungeon : toSend) { - DungeonConfig dungeonConfig = new DungeonConfig(new File(DungeonsXL.DUNGEONS, dungeon + ".yml")); + DungeonConfig dungeonConfig = new DungeonConfig(plugin, new File(DungeonsXL.DUNGEONS, dungeon + ".yml")); int count = dungeonConfig.getFloors().size() + 2; MessageUtil.sendMessage(sender, "&b" + dungeon + "&7 | &e" + count); } diff --git a/src/main/java/de/erethon/dungeonsxl/command/LivesCommand.java b/src/main/java/de/erethon/dungeonsxl/command/LivesCommand.java index cfc3bc06..a8112721 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/LivesCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/LivesCommand.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGroup; @@ -29,9 +29,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class LivesCommand extends DRECommand { +public class LivesCommand extends DCommand { - public LivesCommand() { + public LivesCommand(DungeonsXL plugin) { + super(plugin); setCommand("lives"); setMinArgs(0); setMaxArgs(1); diff --git a/src/main/java/de/erethon/dungeonsxl/command/MainCommand.java b/src/main/java/de/erethon/dungeonsxl/command/MainCommand.java index b9a20c17..d6cfdd79 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/MainCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/MainCommand.java @@ -18,7 +18,6 @@ package de.erethon.dungeonsxl.command; import static de.erethon.commons.chat.FatLetter.*; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.Internals; import de.erethon.dungeonsxl.DungeonsXL; @@ -31,11 +30,10 @@ import org.bukkit.plugin.PluginManager; /** * @author Daniel Saukel */ -public class MainCommand extends DRECommand { +public class MainCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - - public MainCommand() { + public MainCommand(DungeonsXL plugin) { + super(plugin); setCommand("main"); setHelp(DMessage.HELP_CMD_MAIN.getMessage()); setPermission(DPermission.MAIN.getNode()); @@ -49,8 +47,8 @@ public class MainCommand extends DRECommand { int maps = DungeonsXL.MAPS.listFiles().length; int dungeons = DungeonsXL.DUNGEONS.listFiles().length; - int loaded = plugin.getDWorlds().getEditWorlds().size() + plugin.getDWorlds().getGameWorlds().size(); - int players = plugin.getDPlayers().getDGamePlayers().size(); + int loaded = instances.getEditWorlds().size() + instances.getGameWorlds().size(); + int players = dPlayers.getDGamePlayers().size(); Internals internals = CompatibilityHandler.getInstance().getInternals(); String vault = ""; if (plugins.getPlugin("Vault") != null) { diff --git a/src/main/java/de/erethon/dungeonsxl/command/MsgCommand.java b/src/main/java/de/erethon/dungeonsxl/command/MsgCommand.java index 5ee0e7a7..339f039b 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/MsgCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/MsgCommand.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.world.DEditWorld; @@ -29,9 +29,10 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class MsgCommand extends DRECommand { +public class MsgCommand extends DCommand { - public MsgCommand() { + public MsgCommand(DungeonsXL plugin) { + super(plugin); setMinArgs(-1); setMaxArgs(-1); setCommand("msg"); diff --git a/src/main/java/de/erethon/dungeonsxl/command/PlayCommand.java b/src/main/java/de/erethon/dungeonsxl/command/PlayCommand.java index d8665ce8..18884c93 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/PlayCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/PlayCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.dungeon.Dungeon; @@ -37,11 +36,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class PlayCommand extends DRECommand { +public class PlayCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - - public PlayCommand() { + public PlayCommand(DungeonsXL plugin) { + super(plugin); setCommand("play"); setMinArgs(1); setMaxArgs(1); @@ -54,17 +52,17 @@ public class PlayCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); if (dPlayer instanceof DInstancePlayer) { MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage()); return; } - Dungeon dungeon = plugin.getDungeons().getByName(args[1]); + Dungeon dungeon = plugin.getDungeonCache().getByName(args[1]); if (dungeon == null) { - DResourceWorld resource = plugin.getDWorlds().getResourceByName(args[1]); + DResourceWorld resource = instances.getResourceByName(args[1]); if (resource != null) { - dungeon = new Dungeon(resource); + dungeon = new Dungeon(plugin, resource); } else { MessageUtil.sendMessage(player, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(args[1])); return; @@ -76,11 +74,11 @@ public class PlayCommand extends DRECommand { MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage()); return; } else if (dGroup == null) { - dGroup = new DGroup(player, dungeon); + dGroup = new DGroup(plugin, player, dungeon); DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - plugin.getDGroups().remove(dGroup); + plugin.getDGroupCache().remove(dGroup); dGroup = null; } } @@ -95,9 +93,9 @@ public class PlayCommand extends DRECommand { MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage()); return; } - new Game(dGroup, gameWorld); + new Game(plugin, dGroup, gameWorld); for (Player groupPlayer : dGroup.getPlayers().getOnlinePlayers()) { - new DGamePlayer(groupPlayer, dGroup.getGameWorld()); + new DGamePlayer(plugin, groupPlayer, dGroup.getGameWorld()); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/PortalCommand.java b/src/main/java/de/erethon/dungeonsxl/command/PortalCommand.java index 5c73e79d..2b12aef8 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/PortalCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/PortalCommand.java @@ -20,7 +20,6 @@ import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.global.DPortal; @@ -33,12 +32,12 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class PortalCommand extends DRECommand { +public class PortalCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); CaliburnAPI caliburn = plugin.getCaliburn(); - public PortalCommand() { + public PortalCommand(DungeonsXL plugin) { + super(plugin); setCommand("portal"); setMinArgs(0); setMaxArgs(1); @@ -50,7 +49,7 @@ public class PortalCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dGlobalPlayer = plugin.getDPlayers().getByPlayer(player); + DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player); if (dGlobalPlayer instanceof DGamePlayer) { MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage()); @@ -70,7 +69,7 @@ public class PortalCommand extends DRECommand { DPortal dPortal = dGlobalPlayer.getPortal(); if (dPortal == null) { - dPortal = new DPortal(plugin.getGlobalProtections().generateId(DPortal.class, player.getWorld()), player.getWorld(), material, false); + dPortal = new DPortal(plugin, plugin.getGlobalProtectionCache().generateId(DPortal.class, player.getWorld()), player.getWorld(), material, false); dGlobalPlayer.setCreatingPortal(dPortal); dPortal.setWorld(player.getWorld()); dGlobalPlayer.setCachedItem(player.getItemInHand()); diff --git a/src/main/java/de/erethon/dungeonsxl/command/ReloadCommand.java b/src/main/java/de/erethon/dungeonsxl/command/ReloadCommand.java index ae387d5f..6328d0c5 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/ReloadCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/ReloadCommand.java @@ -18,7 +18,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.DefaultFontInfo; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.Internals; import de.erethon.dungeonsxl.DungeonsXL; @@ -37,11 +36,10 @@ import org.bukkit.plugin.PluginManager; /** * @author Frank Baumann, Daniel Saukel */ -public class ReloadCommand extends DRECommand { +public class ReloadCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - - public ReloadCommand() { + public ReloadCommand(DungeonsXL plugin) { + super(plugin); setCommand("reload"); setMinArgs(0); setMaxArgs(1); @@ -53,8 +51,8 @@ public class ReloadCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { - List dPlayers = plugin.getDPlayers().getDInstancePlayers(); - if (!dPlayers.isEmpty() && args.length == 1 && CompatibilityHandler.getInstance().isSpigot() && sender instanceof Player) { + List dPlayers = this.dPlayers.getDInstancePlayers(); + if (!dPlayers.isEmpty() && args.length == 1 && sender instanceof Player) { MessageUtil.sendMessage(sender, DMessage.CMD_RELOAD_PLAYERS.getMessage()); ClickEvent onClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl reload -force"); String message = DefaultFontInfo.center(DMessage.MISC_OKAY.getMessage()); @@ -78,8 +76,8 @@ public class ReloadCommand extends DRECommand { int maps = DungeonsXL.MAPS.listFiles().length; int dungeons = DungeonsXL.DUNGEONS.listFiles().length; - int loaded = plugin.getDWorlds().getEditWorlds().size() + plugin.getDWorlds().getGameWorlds().size(); - int players = plugin.getDPlayers().getDGamePlayers().size(); + int loaded = instances.getEditWorlds().size() + instances.getGameWorlds().size(); + int players = this.dPlayers.getDGamePlayers().size(); Internals internals = CompatibilityHandler.getInstance().getInternals(); String vault = ""; if (plugins.getPlugin("Vault") != null) { @@ -91,7 +89,9 @@ public class ReloadCommand extends DRECommand { } plugin.onDisable(); - plugin.loadCore(); + plugin.initFolders(); + plugin.createCaches(); + plugin.initCaches(); plugin.loadData(); MessageUtil.sendPluginTag(sender, plugin); diff --git a/src/main/java/de/erethon/dungeonsxl/command/ReloadCommandNoSpigot.java b/src/main/java/de/erethon/dungeonsxl/command/ReloadCommandNoSpigot.java index 74aa6dcc..e9fcc836 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/ReloadCommandNoSpigot.java +++ b/src/main/java/de/erethon/dungeonsxl/command/ReloadCommandNoSpigot.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.Internals; import de.erethon.dungeonsxl.DungeonsXL; @@ -33,11 +32,10 @@ import org.bukkit.plugin.PluginManager; /** * @author Frank Baumann, Daniel Saukel */ -public class ReloadCommandNoSpigot extends DRECommand { +public class ReloadCommandNoSpigot extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - - public ReloadCommandNoSpigot() { + public ReloadCommandNoSpigot(DungeonsXL plugin) { + super(plugin); setCommand("reload"); setMinArgs(0); setMaxArgs(1); @@ -49,7 +47,7 @@ public class ReloadCommandNoSpigot extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { - List dPlayers = plugin.getDPlayers().getDInstancePlayers(); + List dPlayers = this.dPlayers.getDInstancePlayers(); PluginManager plugins = Bukkit.getPluginManager(); @@ -65,8 +63,8 @@ public class ReloadCommandNoSpigot extends DRECommand { int maps = DungeonsXL.MAPS.listFiles().length; int dungeons = DungeonsXL.DUNGEONS.listFiles().length; - int loaded = plugin.getDWorlds().getEditWorlds().size() + plugin.getDWorlds().getGameWorlds().size(); - int players = plugin.getDPlayers().getDGamePlayers().size(); + int loaded = instances.getEditWorlds().size() + instances.getGameWorlds().size(); + int players = this.dPlayers.getDGamePlayers().size(); Internals internals = CompatibilityHandler.getInstance().getInternals(); String vault = ""; if (plugins.getPlugin("Vault") != null) { @@ -78,7 +76,9 @@ public class ReloadCommandNoSpigot extends DRECommand { } plugin.onDisable(); - plugin.loadCore(); + plugin.initFolders(); + plugin.createCaches(); + plugin.initCaches(); plugin.loadData(); MessageUtil.sendPluginTag(sender, plugin); diff --git a/src/main/java/de/erethon/dungeonsxl/command/RenameCommand.java b/src/main/java/de/erethon/dungeonsxl/command/RenameCommand.java index 1a010f28..125e6c18 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/RenameCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/RenameCommand.java @@ -17,14 +17,11 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.dungeon.Dungeon; import de.erethon.dungeonsxl.dungeon.DungeonConfig; -import de.erethon.dungeonsxl.global.GameSign; import de.erethon.dungeonsxl.global.GlobalProtection; -import de.erethon.dungeonsxl.global.GroupSign; import de.erethon.dungeonsxl.global.JoinSign; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.world.DEditWorld; @@ -38,11 +35,10 @@ import org.bukkit.configuration.file.FileConfiguration; /** * @author Daniel Saukel */ -public class RenameCommand extends DRECommand { +public class RenameCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - - public RenameCommand() { + public RenameCommand(DungeonsXL plugin) { + super(plugin); setCommand("rename"); setMinArgs(2); setMaxArgs(2); @@ -54,7 +50,7 @@ public class RenameCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { - DResourceWorld resource = plugin.getDWorlds().getResourceByName(args[1]); + DResourceWorld resource = instances.getResourceByName(args[1]); if (resource == null) { MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1])); return; @@ -64,13 +60,13 @@ public class RenameCommand extends DRECommand { resource.getFolder().renameTo(new File(DungeonsXL.MAPS, args[2])); resource.getSignData().updateFile(resource); - for (DEditWorld editWorld : plugin.getDWorlds().getEditWorlds()) { + for (DEditWorld editWorld : instances.getEditWorlds()) { if (editWorld.getResource() == resource) { editWorld.delete(true); } } - for (Dungeon dungeon : plugin.getDungeons().getDungeons()) { + for (Dungeon dungeon : plugin.getDungeonCache().getDungeons()) { DungeonConfig dConfig = dungeon.getConfig(); FileConfiguration config = dConfig.getConfig(); File file = dConfig.getFile(); @@ -100,7 +96,7 @@ public class RenameCommand extends DRECommand { } boolean changed = false; - for (GlobalProtection protection : plugin.getGlobalProtections().getProtections().toArray(new GlobalProtection[]{})) { + for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections().toArray(new GlobalProtection[]{})) { if (!(protection instanceof JoinSign)) { continue; } @@ -116,7 +112,7 @@ public class RenameCommand extends DRECommand { } if (changed) { - plugin.getGlobalProtections().saveAll(); + plugin.getGlobalProtectionCache().saveAll(); } MessageUtil.sendMessage(sender, DMessage.CMD_RENAME_SUCCESS.getMessage(args[1], args[2])); diff --git a/src/main/java/de/erethon/dungeonsxl/command/ResourcePackCommand.java b/src/main/java/de/erethon/dungeonsxl/command/ResourcePackCommand.java index 2af529e9..3c76176d 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/ResourcePackCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/ResourcePackCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DPermission; @@ -27,9 +26,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class ResourcePackCommand extends DRECommand { +public class ResourcePackCommand extends DCommand { - public ResourcePackCommand() { + public ResourcePackCommand(DungeonsXL plugin) { + super(plugin); setCommand("resourcepack"); setMinArgs(1); setMaxArgs(1); @@ -48,7 +48,7 @@ public class ResourcePackCommand extends DRECommand { return; } - String url = (String) DungeonsXL.getInstance().getMainConfig().getResourcePacks().get(args[1]); + String url = (String) config.getResourcePacks().get(args[1]); if (url == null) { MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_RESOURCE_PACK.getMessage(args[1])); return; diff --git a/src/main/java/de/erethon/dungeonsxl/command/SaveCommand.java b/src/main/java/de/erethon/dungeonsxl/command/SaveCommand.java index 22d55752..30cb3624 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/SaveCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/SaveCommand.java @@ -17,10 +17,8 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; -import de.erethon.dungeonsxl.config.MainConfig; import de.erethon.dungeonsxl.config.MainConfig.BackupMode; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.world.DEditWorld; @@ -30,11 +28,10 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class SaveCommand extends DRECommand { +public class SaveCommand extends DCommand { - MainConfig mainConfig = DungeonsXL.getInstance().getMainConfig(); - - public SaveCommand() { + public SaveCommand(DungeonsXL plugin) { + super(plugin); setCommand("save"); setMinArgs(0); setMaxArgs(0); @@ -48,7 +45,7 @@ public class SaveCommand extends DRECommand { Player player = (Player) sender; DEditWorld editWorld = DEditWorld.getByWorld(player.getWorld()); if (editWorld != null) { - BackupMode backupMode = mainConfig.getBackupMode(); + BackupMode backupMode = config.getBackupMode(); if (backupMode == BackupMode.ON_SAVE || backupMode == BackupMode.ON_DISABLE_AND_SAVE) { editWorld.getResource().backup(); } diff --git a/src/main/java/de/erethon/dungeonsxl/command/StatusCommand.java b/src/main/java/de/erethon/dungeonsxl/command/StatusCommand.java index 61ccbe36..bbd545b8 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/StatusCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/StatusCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; @@ -31,16 +30,16 @@ import org.bukkit.plugin.PluginManager; /** * @author Daniel Saukel */ -public class StatusCommand extends DRECommand { +public class StatusCommand extends DCommand { - DungeonsXL plugin = DungeonsXL.getInstance(); - CompatibilityHandler compat = CompatibilityHandler.getInstance(); - PluginManager manager = Bukkit.getPluginManager(); + private CompatibilityHandler compat = CompatibilityHandler.getInstance(); + private PluginManager manager = Bukkit.getPluginManager(); public static final String TRUE = ChatColor.GREEN + "\u2714"; public static final String FALSE = ChatColor.DARK_RED + "\u2718"; - public StatusCommand() { + public StatusCommand(DungeonsXL plugin) { + super(plugin); setCommand("status"); setMinArgs(0); setMaxArgs(0); diff --git a/src/main/java/de/erethon/dungeonsxl/command/TestCommand.java b/src/main/java/de/erethon/dungeonsxl/command/TestCommand.java index 3f2dd6d5..91fafac7 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/TestCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/TestCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.dungeon.Dungeon; @@ -36,9 +35,10 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class TestCommand extends DRECommand { +public class TestCommand extends DCommand { - public TestCommand() { + public TestCommand(DungeonsXL plugin) { + super(plugin); setCommand("test"); setMinArgs(0); setMaxArgs(0); @@ -51,7 +51,7 @@ public class TestCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); if (!(dPlayer instanceof DEditPlayer)) { DGroup dGroup = DGroup.getByPlayer(player); @@ -85,14 +85,14 @@ public class TestCommand extends DRECommand { DEditPlayer editPlayer = (DEditPlayer) dPlayer; editPlayer.leave(); DResourceWorld resource = editPlayer.getEditWorld().getResource(); - Dungeon dungeon = new Dungeon(resource); + Dungeon dungeon = new Dungeon(plugin, resource); DGameWorld instance = resource.instantiateAsGameWorld(false); if (instance == null) { MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage()); return; } - Game game = new Game(new DGroup(player, dungeon), GameTypeDefault.TEST, instance); - new DGamePlayer(player, game.getWorld(), GameTypeDefault.TEST); + Game game = new Game(plugin, new DGroup(plugin, player, dungeon), GameTypeDefault.TEST, instance); + new DGamePlayer(plugin, player, game.getWorld(), GameTypeDefault.TEST); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/UninviteCommand.java b/src/main/java/de/erethon/dungeonsxl/command/UninviteCommand.java index 11ce69e5..bc282913 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/UninviteCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/UninviteCommand.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DPermission; @@ -29,9 +28,10 @@ import org.bukkit.command.CommandSender; /** * @author Frank Baumann, Daniel Saukel */ -public class UninviteCommand extends DRECommand { +public class UninviteCommand extends DCommand { - public UninviteCommand() { + public UninviteCommand(DungeonsXL plugin) { + super(plugin); setCommand("uninvite"); setMinArgs(2); setMaxArgs(2); @@ -43,7 +43,7 @@ public class UninviteCommand extends DRECommand { @Override public void onExecute(String[] args, CommandSender sender) { - DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(args[2]); + DResourceWorld resource = instances.getResourceByName(args[2]); if (resource == null) { MessageUtil.sendMessage(sender, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(args[2])); return; diff --git a/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java b/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java index 258a5fb4..c4e818b2 100644 --- a/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java +++ b/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java @@ -39,6 +39,8 @@ import org.bukkit.configuration.ConfigurationSection; */ public class MainConfig extends DREConfig { + private DungeonsXL plugin; + public enum BackupMode { ON_DISABLE, ON_DISABLE_AND_SAVE, @@ -108,9 +110,11 @@ public class MainConfig extends DREConfig { /* Default Dungeon Settings */ private WorldConfig defaultWorldConfig; - public MainConfig(File file) { + public MainConfig(DungeonsXL plugin, File file) { super(file, CONFIG_VERSION); + this.plugin = plugin; + if (initialize) { initialize(); } @@ -234,7 +238,7 @@ public class MainConfig extends DREConfig { */ public Dungeon getTutorialDungeon() { if (tutorialDungeon == null) { - tutorialDungeon = DungeonsXL.getInstance().getDungeons().getByName(tutorialDungeonName, true); + tutorialDungeon = plugin.getDungeonCache().getByName(tutorialDungeonName, true); } return tutorialDungeon; } @@ -695,7 +699,7 @@ public class MainConfig extends DREConfig { /* Default Dungeon Config */ ConfigurationSection configSection = config.getConfigurationSection("default"); if (configSection != null) { - defaultWorldConfig = new WorldConfig(configSection); + defaultWorldConfig = new WorldConfig(plugin, configSection); } } diff --git a/src/main/java/de/erethon/dungeonsxl/dungeon/Dungeon.java b/src/main/java/de/erethon/dungeonsxl/dungeon/Dungeon.java index c9bf9738..aaac269f 100644 --- a/src/main/java/de/erethon/dungeonsxl/dungeon/Dungeon.java +++ b/src/main/java/de/erethon/dungeonsxl/dungeon/Dungeon.java @@ -31,6 +31,8 @@ import java.util.List; */ public class Dungeon { + private DungeonsXL plugin; + private String name; private DungeonConfig config; private DResourceWorld map; @@ -38,20 +40,26 @@ public class Dungeon { /** * Real dungeon * - * @param file the file to load from + * @param plugin the plugin instance + * @param file the file to load from */ - public Dungeon(File file) { + public Dungeon(DungeonsXL plugin, File file) { + this.plugin = plugin; + name = file.getName().replaceAll(".yml", ""); - config = new DungeonConfig(file); + config = new DungeonConfig(plugin, file); map = config.getStartFloor(); } /** * Artificial dungeon * + * @param plugin the plugin instance * @param resource the only resource world */ - public Dungeon(DResourceWorld resource) { + public Dungeon(DungeonsXL plugin, DResourceWorld resource) { + this.plugin = plugin; + name = resource.getName(); map = resource; } @@ -113,7 +121,7 @@ public class Dungeon { * @return false if there are setup errors */ public boolean isSetupCorrect() { - for (DResourceWorld resource : DungeonsXL.getInstance().getDWorlds().getResources()) { + for (DResourceWorld resource : plugin.getDWorldCache().getResources()) { if (resource.getName().equals(name)) { return false; } diff --git a/src/main/java/de/erethon/dungeonsxl/dungeon/DungeonCache.java b/src/main/java/de/erethon/dungeonsxl/dungeon/DungeonCache.java index b96df86f..aa46405d 100644 --- a/src/main/java/de/erethon/dungeonsxl/dungeon/DungeonCache.java +++ b/src/main/java/de/erethon/dungeonsxl/dungeon/DungeonCache.java @@ -31,17 +31,21 @@ import java.util.List; */ public class DungeonCache { - DungeonsXL plugin = DungeonsXL.getInstance(); + private DungeonsXL plugin; private List dungeons = new ArrayList<>(); - public DungeonCache(File folder) { + public DungeonCache(DungeonsXL plugin) { + this.plugin = plugin; + } + + public void init(File folder) { if (!folder.exists()) { folder.mkdir(); } for (File file : folder.listFiles()) { - Dungeon dungeon = new Dungeon(file); + Dungeon dungeon = new Dungeon(plugin, file); if (dungeon.isSetupCorrect()) { dungeons.add(dungeon); @@ -73,9 +77,9 @@ public class DungeonCache { } if (artificial) { - DResourceWorld resource = plugin.getDWorlds().getResourceByName(name); + DResourceWorld resource = plugin.getDWorldCache().getResourceByName(name); if (resource != null) { - return new Dungeon(resource); + return new Dungeon(plugin, resource); } } @@ -94,7 +98,7 @@ public class DungeonCache { * @return the Dungeon that has the name */ public Dungeon loadDungeon(String name) { - Dungeon dungeon = new Dungeon(Dungeon.getFileFromName(name)); + Dungeon dungeon = new Dungeon(plugin, Dungeon.getFileFromName(name)); dungeons.add(dungeon); return dungeon; } diff --git a/src/main/java/de/erethon/dungeonsxl/dungeon/DungeonConfig.java b/src/main/java/de/erethon/dungeonsxl/dungeon/DungeonConfig.java index e0bbe47b..b42611fa 100644 --- a/src/main/java/de/erethon/dungeonsxl/dungeon/DungeonConfig.java +++ b/src/main/java/de/erethon/dungeonsxl/dungeon/DungeonConfig.java @@ -19,7 +19,6 @@ package de.erethon.dungeonsxl.dungeon; import de.erethon.commons.config.DREConfig; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DResourceWorld; -import de.erethon.dungeonsxl.world.DWorldCache; import de.erethon.dungeonsxl.world.WorldConfig; import java.io.File; import java.util.ArrayList; @@ -32,7 +31,7 @@ import java.util.List; */ public class DungeonConfig extends DREConfig { - DWorldCache worlds = DungeonsXL.getInstance().getDWorlds(); + private DungeonsXL plugin; public static final int CONFIG_VERSION = 1; @@ -44,9 +43,11 @@ public class DungeonConfig extends DREConfig { private WorldConfig overrideValues; private WorldConfig defaultValues; - public DungeonConfig(File file) { + public DungeonConfig(DungeonsXL plugin, File file) { super(file, CONFIG_VERSION); + this.plugin = plugin; + if (initialize) { initialize(); } @@ -176,14 +177,14 @@ public class DungeonConfig extends DREConfig { * @return true if the floor is either in the list or the start / end floor. */ public boolean containsFloor(String mapName) { - return containsFloor(worlds.getResourceByName(mapName)); + return containsFloor(plugin.getDWorldCache().getResourceByName(mapName)); } @Override public void load() { if (config.contains("floors")) { for (String floor : config.getStringList("floors")) { - DResourceWorld resource = worlds.getResourceByName(floor); + DResourceWorld resource = plugin.getDWorldCache().getResourceByName(floor); if (resource != null) { floors.add(resource); } @@ -191,11 +192,11 @@ public class DungeonConfig extends DREConfig { } if (config.contains("startFloor")) { - startFloor = worlds.getResourceByName(config.getString("startFloor")); + startFloor = plugin.getDWorldCache().getResourceByName(config.getString("startFloor")); } if (config.contains("endFloor")) { - endFloor = worlds.getResourceByName(config.getString("endFloor")); + endFloor = plugin.getDWorldCache().getResourceByName(config.getString("endFloor")); } if (config.contains("floorCount")) { @@ -207,11 +208,11 @@ public class DungeonConfig extends DREConfig { } if (config.contains("overrideValues")) { - overrideValues = new WorldConfig(config.getConfigurationSection("overrideValues")); + overrideValues = new WorldConfig(plugin, config.getConfigurationSection("overrideValues")); } if (config.contains("defaultValues")) { - defaultValues = new WorldConfig(config.getConfigurationSection("defaultValues")); + defaultValues = new WorldConfig(plugin, config.getConfigurationSection("defaultValues")); } } diff --git a/src/main/java/de/erethon/dungeonsxl/game/Game.java b/src/main/java/de/erethon/dungeonsxl/game/Game.java index d363146f..940769fa 100644 --- a/src/main/java/de/erethon/dungeonsxl/game/Game.java +++ b/src/main/java/de/erethon/dungeonsxl/game/Game.java @@ -47,7 +47,7 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class Game { - DungeonsXL plugin = DungeonsXL.getInstance(); + private DungeonsXL plugin; private boolean tutorial; private List dGroups = new ArrayList<>(); @@ -59,8 +59,9 @@ public class Game { private Map gameKills = new HashMap<>(); private Map waveKills = new HashMap<>(); - public Game(DGroup dGroup) { - DungeonsXL.getInstance().getGames().add(this); + public Game(DungeonsXL plugin, DGroup dGroup) { + this.plugin = plugin; + plugin.getGameCache().add(this); tutorial = false; started = false; @@ -73,8 +74,9 @@ public class Game { dGroup.setScore(rules.getInitialScore()); } - public Game(DGroup dGroup, DGameWorld world) { - plugin.getGames().add(this); + public Game(DungeonsXL plugin, DGroup dGroup, DGameWorld world) { + this.plugin = plugin; + plugin.getGameCache().add(this); tutorial = false; started = false; @@ -88,12 +90,13 @@ public class Game { dGroup.setScore(rules.getInitialScore()); } - public Game(DGroup dGroup, GameType type, DGameWorld world) { - this(new ArrayList<>(Arrays.asList(dGroup)), type, world); + public Game(DungeonsXL plugin, DGroup dGroup, GameType type, DGameWorld world) { + this(plugin, new ArrayList<>(Arrays.asList(dGroup)), type, world); } - public Game(List dGroups, GameType type, DGameWorld world) { - plugin.getGames().add(this); + public Game(DungeonsXL plugin, List dGroups, GameType type, DGameWorld world) { + this.plugin = plugin; + plugin.getGameCache().add(this); this.dGroups = dGroups; this.type = type; @@ -368,9 +371,9 @@ public class Game { * Remove the Game from the List */ public void delete() { - GameSign gameSign = GameSign.getByGame(this); + GameSign gameSign = GameSign.getByGame(plugin, this); - plugin.getGames().remove(this); + plugin.getGameCache().remove(this); if (gameSign != null) { gameSign.update(); @@ -431,7 +434,7 @@ public class Game { /* Statics */ public static Game getByDGroup(DGroup dGroup) { - for (Game game : DungeonsXL.getInstance().getGames()) { + for (Game game : DungeonsXL.getInstance().getGameCache()) { if (game.getDGroups().contains(dGroup)) { return game; } @@ -445,7 +448,7 @@ public class Game { } public static Game getByGameWorld(DGameWorld gameWorld) { - for (Game game : DungeonsXL.getInstance().getGames()) { + for (Game game : DungeonsXL.getInstance().getGameCache()) { if (gameWorld.equals(game.getWorld())) { return game; } diff --git a/src/main/java/de/erethon/dungeonsxl/global/DPortal.java b/src/main/java/de/erethon/dungeonsxl/global/DPortal.java index 38663bf1..3c66b4b8 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/DPortal.java +++ b/src/main/java/de/erethon/dungeonsxl/global/DPortal.java @@ -52,19 +52,19 @@ public class DPortal extends GlobalProtection { private boolean active; private Set blocks; - public DPortal(int id, World world, boolean active) { - this(id, world, VanillaItem.NETHER_PORTAL, active); + public DPortal(DungeonsXL plugin, int id, World world, boolean active) { + this(plugin, id, world, VanillaItem.NETHER_PORTAL, active); } - public DPortal(int id, World world, ExItem material, boolean active) { - super(world, id); + public DPortal(DungeonsXL plugin, int id, World world, ExItem material, boolean active) { + super(plugin, world, id); this.material = material; this.active = active; } - public DPortal(int id, Block block1, Block block2, ExItem material, byte axis, boolean active) { - super(block1.getWorld(), id); + public DPortal(DungeonsXL plugin, int id, Block block1, Block block2, ExItem material, byte axis, boolean active) { + super(plugin, block1.getWorld(), id); this.block1 = block1; this.block2 = block2; @@ -233,14 +233,14 @@ public class DPortal extends GlobalProtection { } if (game == null) { - game = new Game(dGroup, target); + game = new Game(plugin, dGroup, target); } else { game.setWorld(target); dGroup.setGameWorld(target); } - new DGamePlayer(player, target); + new DGamePlayer(plugin, player, target); } @Override @@ -332,19 +332,21 @@ public class DPortal extends GlobalProtection { /* Statics */ /** + * @param plugin the plugin instance * @param location a location covered by the returned portal * @return the portal at the location, null if there is none */ - public static DPortal getByLocation(Location location) { - return getByBlock(location.getBlock()); + public static DPortal getByLocation(DungeonsXL plugin, Location location) { + return getByBlock(plugin, location.getBlock()); } /** - * @param block a block covered by the returned portal + * @param plugin the plugin instance + * @param block a block covered by the returned portal * @return the portal that the block belongs to, null if it belongs to none */ - public static DPortal getByBlock(Block block) { - for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(DPortal.class)) { + public static DPortal getByBlock(DungeonsXL plugin, Block block) { + for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(DPortal.class)) { DPortal portal = (DPortal) protection; if (portal.getBlock1() == null || portal.getBlock2() == null) { continue; diff --git a/src/main/java/de/erethon/dungeonsxl/global/GameSign.java b/src/main/java/de/erethon/dungeonsxl/global/GameSign.java index a47cdfb4..57dc1570 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/GameSign.java +++ b/src/main/java/de/erethon/dungeonsxl/global/GameSign.java @@ -45,8 +45,8 @@ public class GameSign extends JoinSign { private Game game; - public GameSign(int id, Block startSign, String identifier, int maxGroupsPerGame) { - super(id, startSign, identifier, maxGroupsPerGame); + public GameSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxGroupsPerGame) { + super(plugin, id, startSign, identifier, maxGroupsPerGame); } /** @@ -153,7 +153,7 @@ public class GameSign extends JoinSign { return; } - game = new Game(dGroup); + game = new Game(plugin, dGroup); dGroup.setDungeon(dungeon); update(); @@ -165,15 +165,16 @@ public class GameSign extends JoinSign { /* Statics */ /** - * @param block a block which is protected by the returned GameSign + * @param plugin the plugin instance + * @param block a block which is protected by the returned GameSign * @return the game sign the block belongs to, null if it belongs to none */ - public static GameSign getByBlock(Block block) { + public static GameSign getByBlock(DungeonsXL plugin, Block block) { if (!Category.SIGNS.containsBlock(block)) { return null; } - for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(GameSign.class)) { + for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GameSign.class)) { GameSign gameSign = (GameSign) protection; Block start = gameSign.startSign; if (start == block || (start.getX() == block.getX() && start.getZ() == block.getZ() && (start.getY() >= block.getY() && start.getY() - gameSign.verticalSigns <= block.getY()))) { @@ -185,11 +186,12 @@ public class GameSign extends JoinSign { } /** - * @param game the game to check + * @param plugin the plugin instance + * @param game the game to check * @return the game that this sign creates */ - public static GameSign getByGame(Game game) { - for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(GameSign.class)) { + public static GameSign getByGame(DungeonsXL plugin, Game game) { + for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GameSign.class)) { GameSign gameSign = (GameSign) protection; if (gameSign.game == game) { return gameSign; @@ -198,7 +200,7 @@ public class GameSign extends JoinSign { return null; } - public static GameSign tryToCreate(SignChangeEvent event) { + public static GameSign tryToCreate(DungeonsXL plugin, SignChangeEvent event) { if (!event.getLine(0).equalsIgnoreCase(SIGN_TAG)) { return null; } @@ -209,10 +211,10 @@ public class GameSign extends JoinSign { String identifier = event.getLine(2); int maxGroupsPerGame = NumberUtil.parseInt(event.getLine(3), 1); - return tryToCreate(event.getBlock(), identifier, maxGroupsPerGame); + return tryToCreate(plugin, event.getBlock(), identifier, maxGroupsPerGame); } - public static GameSign tryToCreate(Block startSign, String identifier, int maxGroupsPerGame) { + public static GameSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxGroupsPerGame) { World world = startSign.getWorld(); BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace(); int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ(); @@ -229,7 +231,7 @@ public class GameSign extends JoinSign { verticalSigns--; } - GameSign sign = new GameSign(DungeonsXL.getInstance().getGlobalProtections().generateId(GameSign.class, world), startSign, identifier, maxGroupsPerGame); + GameSign sign = new GameSign(plugin, plugin.getGlobalProtectionCache().generateId(GameSign.class, world), startSign, identifier, maxGroupsPerGame); LWCUtil.removeProtection(startSign); diff --git a/src/main/java/de/erethon/dungeonsxl/config/GlobalData.java b/src/main/java/de/erethon/dungeonsxl/global/GlobalData.java similarity index 96% rename from src/main/java/de/erethon/dungeonsxl/config/GlobalData.java rename to src/main/java/de/erethon/dungeonsxl/global/GlobalData.java index 0c049439..a30e3771 100644 --- a/src/main/java/de/erethon/dungeonsxl/config/GlobalData.java +++ b/src/main/java/de/erethon/dungeonsxl/global/GlobalData.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.config; +package de.erethon.dungeonsxl.global; import de.erethon.commons.config.DREConfig; import java.io.File; diff --git a/src/main/java/de/erethon/dungeonsxl/global/GlobalProtection.java b/src/main/java/de/erethon/dungeonsxl/global/GlobalProtection.java index ec32cb95..b8a0e7a8 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/GlobalProtection.java +++ b/src/main/java/de/erethon/dungeonsxl/global/GlobalProtection.java @@ -32,15 +32,20 @@ import org.bukkit.configuration.file.YamlConfiguration; */ public abstract class GlobalProtection { - public static final String SIGN_TAG = "[DXL]"; + protected DungeonsXL plugin; + protected GlobalProtectionCache protections; + private FileConfiguration config; - FileConfiguration config = DungeonsXL.getInstance().getGlobalData().getConfig(); - GlobalProtectionCache protections = DungeonsXL.getInstance().getGlobalProtections(); + public static final String SIGN_TAG = "[DXL]"; private World world; private int id; - protected GlobalProtection(World world, int id) { + protected GlobalProtection(DungeonsXL plugin, World world, int id) { + this.plugin = plugin; + protections = plugin.getGlobalProtectionCache(); + config = plugin.getGlobalData().getConfig(); + this.world = world; this.id = id; diff --git a/src/main/java/de/erethon/dungeonsxl/global/GlobalProtectionCache.java b/src/main/java/de/erethon/dungeonsxl/global/GlobalProtectionCache.java index 893058a0..04a3266f 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/GlobalProtectionCache.java +++ b/src/main/java/de/erethon/dungeonsxl/global/GlobalProtectionCache.java @@ -36,12 +36,12 @@ import org.bukkit.configuration.file.YamlConfiguration; */ public class GlobalProtectionCache { - DungeonsXL plugin = DungeonsXL.getInstance(); + private DungeonsXL plugin; private Set protections = new HashSet<>(); - public GlobalProtectionCache() { - Bukkit.getPluginManager().registerEvents(new GlobalProtectionListener(), plugin); + public GlobalProtectionCache(DungeonsXL plugin) { + this.plugin = plugin; } /** @@ -187,7 +187,7 @@ public class GlobalProtectionCache { int maxGroupsPerGame = data.getInt(preString + ".maxGroupsPerGame"); Block startSign = world.getBlockAt(data.getInt(preString + ".x"), data.getInt(preString + ".y"), data.getInt(preString + ".z")); - new GameSign(id, startSign, mapName, maxGroupsPerGame); + new GameSign(plugin, id, startSign, mapName, maxGroupsPerGame); } } while (data.contains(preString)); @@ -207,7 +207,7 @@ public class GlobalProtectionCache { int maxPlayersPerGroup = data.getInt(preString + ".maxPlayersPerGroup"); Block startSign = world.getBlockAt(data.getInt(preString + ".x"), data.getInt(preString + ".y"), data.getInt(preString + ".z")); - new GroupSign(id, startSign, mapName, maxPlayersPerGroup, groupName); + new GroupSign(plugin, id, startSign, mapName, maxPlayersPerGroup, groupName); } } while (data.contains(preString)); } @@ -224,7 +224,7 @@ public class GlobalProtectionCache { Block block = world.getBlockAt(data.getInt(preString + ".x"), data.getInt(preString + ".y"), data.getInt(preString + ".z")); if (block.getState() instanceof Sign) { Sign sign = (Sign) block.getState(); - new LeaveSign(id, sign); + new LeaveSign(plugin, id, sign); } } @@ -245,7 +245,7 @@ public class GlobalProtectionCache { Block block2 = world.getBlockAt(data.getInt(preString + "loc2.x"), data.getInt(preString + "loc2.y"), data.getInt(preString + "loc2.z")); ExItem material = plugin.getCaliburn().getExItem(data.getString(preString + "material")); String axis = data.getString(preString + "axis"); - DPortal dPortal = new DPortal(id, block1, block2, material != null ? material : VanillaItem.NETHER_PORTAL, (byte) (axis != null && axis.equals("z") ? 2 : 1), true); + DPortal dPortal = new DPortal(plugin, id, block1, block2, material != null ? material : VanillaItem.NETHER_PORTAL, (byte) (axis != null && axis.equals("z") ? 2 : 1), true); dPortal.create(null); } diff --git a/src/main/java/de/erethon/dungeonsxl/global/GlobalProtectionListener.java b/src/main/java/de/erethon/dungeonsxl/global/GlobalProtectionListener.java index 187cc655..decd1eb5 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/GlobalProtectionListener.java +++ b/src/main/java/de/erethon/dungeonsxl/global/GlobalProtectionListener.java @@ -49,7 +49,11 @@ import org.bukkit.inventory.ItemStack; */ public class GlobalProtectionListener implements Listener { - DungeonsXL plugin = DungeonsXL.getInstance(); + private DungeonsXL plugin; + + public GlobalProtectionListener(DungeonsXL plugin) { + this.plugin = plugin; + } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockBreakWithSignOnIt(BlockBreakEvent event) { @@ -79,9 +83,9 @@ public class GlobalProtectionListener implements Listener { public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); Player player = event.getPlayer(); - DGlobalPlayer dGlobalPlayer = plugin.getDPlayers().getByPlayer(player); + DGlobalPlayer dGlobalPlayer = plugin.getDPlayerCache().getByPlayer(player); - GlobalProtection protection = plugin.getGlobalProtections().getByBlock(block); + GlobalProtection protection = plugin.getGlobalProtectionCache().getByBlock(block); if (protection != null) { if (protection.onBreak(dGlobalPlayer)) { event.setCancelled(true); @@ -91,7 +95,7 @@ public class GlobalProtectionListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockPlace(BlockPlaceEvent event) { - if (DPortal.getByBlock(event.getBlock()) != null) { + if (DPortal.getByBlock(plugin, event.getBlock()) != null) { event.setCancelled(true); } } @@ -99,7 +103,7 @@ public class GlobalProtectionListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPlayerBucketFill(PlayerBucketFillEvent event) { Block block = event.getBlockClicked(); - if (DPortal.getByBlock(block) != null) { + if (DPortal.getByBlock(plugin, block) != null) { event.setCancelled(true); // Workaround for a bug of Bukkit event.getPlayer().sendBlockChange(block.getLocation(), block.getType(), (byte) 0); @@ -108,14 +112,14 @@ public class GlobalProtectionListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockSpread(BlockSpreadEvent event) { - if (DPortal.getByBlock(event.getBlock()) != null) { + if (DPortal.getByBlock(plugin, event.getBlock()) != null) { event.setCancelled(true); } } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockPhysics(BlockPhysicsEvent event) { - if (DPortal.getByBlock(event.getBlock()) != null) { + if (DPortal.getByBlock(plugin, event.getBlock()) != null) { event.setCancelled(true); } } @@ -124,7 +128,7 @@ public class GlobalProtectionListener implements Listener { public void onEntityExplode(EntityExplodeEvent event) { List blocklist = event.blockList(); for (Block block : blocklist) { - if (plugin.getGlobalProtections().isProtectedBlock(block)) { + if (plugin.getGlobalProtectionCache().isProtectedBlock(block)) { event.setCancelled(true); } } @@ -133,7 +137,7 @@ public class GlobalProtectionListener implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - DPortal dPortal = DPortal.getByLocation(player.getEyeLocation()); + DPortal dPortal = DPortal.getByLocation(plugin, player.getEyeLocation()); if (dPortal == null) { return; } @@ -167,14 +171,14 @@ public class GlobalProtectionListener implements Listener { Block block7 = block2.getRelative(BlockFace.SOUTH); Block block8 = block4.getRelative(BlockFace.NORTH); Block block9 = block4.getRelative(BlockFace.SOUTH); - return (DPortal.getByBlock(block1) != null || DPortal.getByBlock(block2) != null || DPortal.getByBlock(block3) != null - || DPortal.getByBlock(block4) != null || DPortal.getByBlock(block5) != null || DPortal.getByBlock(block6) != null - || DPortal.getByBlock(block7) != null || DPortal.getByBlock(block8) != null || DPortal.getByBlock(block9) != null); + return (DPortal.getByBlock(plugin, block1) != null || DPortal.getByBlock(plugin, block2) != null || DPortal.getByBlock(plugin, block3) != null + || DPortal.getByBlock(plugin, block4) != null || DPortal.getByBlock(plugin, block5) != null || DPortal.getByBlock(plugin, block6) != null + || DPortal.getByBlock(plugin, block7) != null || DPortal.getByBlock(plugin, block8) != null || DPortal.getByBlock(plugin, block9) != null); } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPortalCreation(PlayerInteractEvent event) { - DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(event.getPlayer()); + DGlobalPlayer dPlayer = plugin.getDPlayerCache().getByPlayer(event.getPlayer()); if (!dPlayer.isCreatingPortal()) { return; } @@ -184,7 +188,7 @@ public class GlobalProtectionListener implements Listener { return; } - for (GlobalProtection protection : plugin.getGlobalProtections().getProtections(DPortal.class)) { + for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(DPortal.class)) { DPortal dPortal = (DPortal) protection; if (dPortal.isActive() || dPortal != dPlayer.getPortal()) { continue; @@ -209,7 +213,7 @@ public class GlobalProtectionListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - if (plugin.getDPlayers().getByPlayer(player).isInBreakMode()) { + if (plugin.getDPlayerCache().getByPlayer(player).isInBreakMode()) { return; } Block clickedBlock = event.getClickedBlock(); @@ -218,19 +222,19 @@ public class GlobalProtectionListener implements Listener { } if (Category.SIGNS.containsBlock(clickedBlock)) { - GroupSign groupSign = GroupSign.getByBlock(clickedBlock); + GroupSign groupSign = GroupSign.getByBlock(plugin, clickedBlock); if (groupSign != null) { groupSign.onPlayerInteract(clickedBlock, player); event.setCancelled(true); } - GameSign gameSign = GameSign.getByBlock(clickedBlock); + GameSign gameSign = GameSign.getByBlock(plugin, clickedBlock); if (gameSign != null) { gameSign.onPlayerInteract(clickedBlock, player); event.setCancelled(true); } - LeaveSign leaveSign = LeaveSign.getByBlock(clickedBlock); + LeaveSign leaveSign = LeaveSign.getByBlock(plugin, clickedBlock); if (leaveSign != null) { leaveSign.onPlayerInteract(player); event.setCancelled(true); @@ -260,18 +264,18 @@ public class GlobalProtectionListener implements Listener { } if (lines[1].equalsIgnoreCase(GroupSign.GROUP_SIGN_TAG)) { - if (GroupSign.tryToCreate(event) != null) { + if (GroupSign.tryToCreate(plugin, event) != null) { event.setCancelled(true); } } else if (lines[1].equalsIgnoreCase(GameSign.GAME_SIGN_TAG)) { - if (GameSign.tryToCreate(event) != null) { + if (GameSign.tryToCreate(plugin, event) != null) { event.setCancelled(true); } } else if (lines[1].equalsIgnoreCase(LeaveSign.LEAVE_SIGN_TAG)) { Sign sign = (Sign) state; - new LeaveSign(plugin.getGlobalProtections().generateId(LeaveSign.class, sign.getWorld()), sign); + new LeaveSign(plugin, plugin.getGlobalProtectionCache().generateId(LeaveSign.class, sign.getWorld()), sign); event.setCancelled(true); } } diff --git a/src/main/java/de/erethon/dungeonsxl/global/GroupSign.java b/src/main/java/de/erethon/dungeonsxl/global/GroupSign.java index 1ec3d8e1..5142fc49 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/GroupSign.java +++ b/src/main/java/de/erethon/dungeonsxl/global/GroupSign.java @@ -45,8 +45,8 @@ public class GroupSign extends JoinSign { private String groupName; private DGroup group; - public GroupSign(int id, Block startSign, String identifier, int maxPlayersPerGroup, String groupName) { - super(id, startSign, identifier, maxPlayersPerGroup); + public GroupSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxPlayersPerGroup, String groupName) { + super(plugin, id, startSign, identifier, maxPlayersPerGroup); this.groupName = groupName; } @@ -146,9 +146,9 @@ public class GroupSign extends JoinSign { } if (groupName != null) { - group = new DGroup(groupName, player, dungeon); + group = new DGroup(plugin, groupName, player, dungeon); } else { - group = new DGroup(player, dungeon); + group = new DGroup(plugin, player, dungeon); } update(); @@ -160,15 +160,16 @@ public class GroupSign extends JoinSign { /* Statics */ /** - * @param block a block which is protected by the returned GroupSign + * @param plugin the plugin instance + * @param block a block which is protected by the returned GroupSign * @return the group sign the block belongs to, null if it belongs to none */ - public static GroupSign getByBlock(Block block) { + public static GroupSign getByBlock(DungeonsXL plugin, Block block) { if (!Category.SIGNS.containsBlock(block)) { return null; } - for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(GroupSign.class)) { + for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GroupSign.class)) { GroupSign groupSign = (GroupSign) protection; Block start = groupSign.startSign; if (start == block || (start.getX() == block.getX() && start.getZ() == block.getZ() && (start.getY() >= block.getY() && start.getY() - groupSign.verticalSigns <= block.getY()))) { @@ -179,7 +180,7 @@ public class GroupSign extends JoinSign { return null; } - public static GroupSign tryToCreate(SignChangeEvent event) { + public static GroupSign tryToCreate(DungeonsXL plugin, SignChangeEvent event) { if (!event.getLine(0).equalsIgnoreCase(SIGN_TAG)) { return null; } @@ -199,10 +200,10 @@ public class GroupSign extends JoinSign { groupName = data[1]; } - return tryToCreate(event.getBlock(), identifier, maxPlayersPerGroup, groupName); + return tryToCreate(plugin, event.getBlock(), identifier, maxPlayersPerGroup, groupName); } - public static GroupSign tryToCreate(Block startSign, String identifier, int maxPlayersPerGroup, String groupName) { + public static GroupSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxPlayersPerGroup, String groupName) { World world = startSign.getWorld(); BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace(); int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ(); @@ -219,7 +220,7 @@ public class GroupSign extends JoinSign { verticalSigns--; } - GroupSign sign = new GroupSign(DungeonsXL.getInstance().getGlobalProtections().generateId(GroupSign.class, world), startSign, identifier, maxPlayersPerGroup, groupName); + GroupSign sign = new GroupSign(plugin, plugin.getGlobalProtectionCache().generateId(GroupSign.class, world), startSign, identifier, maxPlayersPerGroup, groupName); LWCUtil.removeProtection(startSign); diff --git a/src/main/java/de/erethon/dungeonsxl/global/JoinSign.java b/src/main/java/de/erethon/dungeonsxl/global/JoinSign.java index 2d94ade7..1e8f3b8e 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/JoinSign.java +++ b/src/main/java/de/erethon/dungeonsxl/global/JoinSign.java @@ -37,15 +37,15 @@ public class JoinSign extends GlobalProtection { protected int verticalSigns; protected Set blocks; - protected JoinSign(int id, Block startSign, String identifier, int maxElements) { - super(startSign.getWorld(), id); + protected JoinSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxElements) { + super(plugin, startSign.getWorld(), id); this.startSign = startSign; - dungeon = DungeonsXL.getInstance().getDungeons().getByName(identifier); + dungeon = plugin.getDungeonCache().getByName(identifier); if (dungeon == null) { - DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(identifier); + DResourceWorld resource = plugin.getDWorldCache().getResourceByName(identifier); if (resource != null) { - dungeon = new Dungeon(resource); + dungeon = new Dungeon(plugin, resource); } } diff --git a/src/main/java/de/erethon/dungeonsxl/global/LeaveSign.java b/src/main/java/de/erethon/dungeonsxl/global/LeaveSign.java index fe003773..54355cd1 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/LeaveSign.java +++ b/src/main/java/de/erethon/dungeonsxl/global/LeaveSign.java @@ -43,8 +43,8 @@ public class LeaveSign extends GlobalProtection { private Sign sign; private Set blocks; - public LeaveSign(int id, Sign sign) { - super(sign.getWorld(), id); + public LeaveSign(DungeonsXL plugin, int id, Sign sign) { + super(plugin, sign.getWorld(), id); this.sign = sign; setText(); @@ -99,11 +99,12 @@ public class LeaveSign extends GlobalProtection { /* Statics */ /** - * @param block a block which is protected by the returned LeaveSign + * @param plugin the plugin instance + * @param block a block which is protected by the returned LeaveSign * @return the leave sign the block belongs to, null if it belongs to none */ - public static LeaveSign getByBlock(Block block) { - for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(LeaveSign.class)) { + public static LeaveSign getByBlock(DungeonsXL plugin, Block block) { + for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(LeaveSign.class)) { LeaveSign leaveSign = (LeaveSign) protection; if (leaveSign.getBlocks().contains(block)) { diff --git a/src/main/java/de/erethon/dungeonsxl/mob/DMobType.java b/src/main/java/de/erethon/dungeonsxl/mob/DMobType.java index a50802e3..895d5978 100644 --- a/src/main/java/de/erethon/dungeonsxl/mob/DMobType.java +++ b/src/main/java/de/erethon/dungeonsxl/mob/DMobType.java @@ -22,6 +22,7 @@ import de.erethon.caliburn.mob.ExMob; import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.misc.EnumUtil; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.world.DGameWorld; import java.io.File; @@ -50,7 +51,7 @@ import org.bukkit.inventory.meta.ItemMeta; @Deprecated public class DMobType extends ExMob { - CaliburnAPI caliburn = CaliburnAPI.getInstance(); + private CaliburnAPI caliburn; private String name; private EntityType type; @@ -70,17 +71,21 @@ public class DMobType extends ExMob { private String ocelotType = null; /** - * @param file the script file + * @param plugin the plugin instance + * @param file the script file */ - public DMobType(File file) { - this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file)); + public DMobType(DungeonsXL plugin, File file) { + this(plugin, file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file)); } /** + * @param plugin the plugin instance * @param name the name of the DMobType * @param config the config that stores the information */ - public DMobType(String name, FileConfiguration config) { + public DMobType(DungeonsXL plugin, String name, FileConfiguration config) { + caliburn = plugin.getCaliburn(); + this.name = name; // Read Mobs @@ -196,9 +201,7 @@ public class DMobType extends ExMob { } /* Getters and setters */ - /** - * @return the name - */ + @Override public String getName() { return name; } diff --git a/src/main/java/de/erethon/dungeonsxl/mob/ExternalMobProviderCache.java b/src/main/java/de/erethon/dungeonsxl/mob/ExternalMobProviderCache.java index af6f75ba..c1a70ce5 100644 --- a/src/main/java/de/erethon/dungeonsxl/mob/ExternalMobProviderCache.java +++ b/src/main/java/de/erethon/dungeonsxl/mob/ExternalMobProviderCache.java @@ -31,12 +31,16 @@ import org.bukkit.Bukkit; */ public class ExternalMobProviderCache { - DungeonsXL plugin = DungeonsXL.getInstance(); + private DungeonsXL plugin; private Set providers = new HashSet<>(); private CitizensMobProvider citizensMobProvider; - public ExternalMobProviderCache() { + public ExternalMobProviderCache(DungeonsXL plugin) { + this.plugin = plugin; + } + + public void init() { // Supported providers providers.addAll(Arrays.asList(ExternalMobPlugin.values())); diff --git a/src/main/java/de/erethon/dungeonsxl/player/DClass.java b/src/main/java/de/erethon/dungeonsxl/player/DClass.java index e144600a..3bb83709 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DClass.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DClass.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.player; import de.erethon.caliburn.CaliburnAPI; -import de.erethon.commons.compatibility.CompatibilityHandler; +import de.erethon.dungeonsxl.DungeonsXL; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -32,19 +32,20 @@ import org.bukkit.inventory.ItemStack; */ public class DClass { - CaliburnAPI caliburn = CaliburnAPI.getInstance(); - CompatibilityHandler compat = CompatibilityHandler.getInstance(); + private CaliburnAPI caliburn; private String name; private List items = new ArrayList<>(); private boolean dog; - public DClass(File file) { - this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file)); + public DClass(DungeonsXL plugin, File file) { + this(plugin, file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file)); } - public DClass(String name, FileConfiguration config) { + public DClass(DungeonsXL plugin, String name, FileConfiguration config) { + caliburn = plugin.getCaliburn(); + this.name = name; if (config.contains("items")) { diff --git a/src/main/java/de/erethon/dungeonsxl/player/DClassCache.java b/src/main/java/de/erethon/dungeonsxl/player/DClassCache.java index 4e4fb739..64821643 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DClassCache.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DClassCache.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.player; import de.erethon.commons.misc.FileUtil; +import de.erethon.dungeonsxl.DungeonsXL; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -28,12 +29,18 @@ import java.util.List; */ public class DClassCache { + private DungeonsXL plugin; + private List dClasses = new ArrayList<>(); - public DClassCache(File file) { + public DClassCache(DungeonsXL plugin) { + this.plugin = plugin; + } + + public void init(File file) { if (file.isDirectory()) { for (File script : FileUtil.getFilesForFolder(file)) { - dClasses.add(new DClass(script)); + dClasses.add(new DClass(plugin, script)); } } } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java index 4b8e85ba..c75ac131 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java @@ -43,8 +43,8 @@ public class DEditPlayer extends DInstancePlayer { private String[] linesCopy; private DEditWorld editWorld; - public DEditPlayer(Player player, DEditWorld world) { - super(player, world.getWorld()); + public DEditPlayer(DungeonsXL plugin, Player player, DEditWorld world) { + super(plugin, player, world.getWorld()); editWorld = world; // Set gamemode a few ticks later to avoid incompatibilities with plugins that force a gamemode @@ -190,7 +190,7 @@ public class DEditPlayer extends DInstancePlayer { /* Statics */ public static DEditPlayer getByPlayer(Player player) { - for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDEditPlayers()) { + for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDEditPlayers()) { if (dPlayer.getPlayer().equals(player)) { return dPlayer; } @@ -199,7 +199,7 @@ public class DEditPlayer extends DInstancePlayer { } public static DEditPlayer getByName(String name) { - for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDEditPlayers()) { + for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDEditPlayers()) { if (dPlayer.getName().equalsIgnoreCase(name)) { return dPlayer; } @@ -210,7 +210,7 @@ public class DEditPlayer extends DInstancePlayer { public static CopyOnWriteArrayList getByWorld(World world) { CopyOnWriteArrayList dPlayers = new CopyOnWriteArrayList<>(); - for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDEditPlayers()) { + for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDEditPlayers()) { if (dPlayer.getWorld() == world) { dPlayers.add(dPlayer); } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java index 97600315..a35a6b9c 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java @@ -81,12 +81,12 @@ public class DGamePlayer extends DInstancePlayer { private DGroupTag groupTag; - public DGamePlayer(Player player, DGameWorld world) { - super(player, world.getWorld()); + public DGamePlayer(DungeonsXL plugin, Player player, DGameWorld world) { + super(plugin, player, world.getWorld()); Game game = Game.getByGameWorld(world); if (game == null) { - game = new Game(DGroup.getByPlayer(player)); + game = new Game(plugin, DGroup.getByPlayer(player)); } GameRuleProvider rules = game.getRules(); @@ -111,8 +111,8 @@ public class DGamePlayer extends DInstancePlayer { } } - public DGamePlayer(Player player, DGameWorld world, GameType ready) { - this(player, world); + public DGamePlayer(DungeonsXL plugin, Player player, DGameWorld world, GameType ready) { + this(plugin, player, world); if (ready != null) { ready(ready); } @@ -215,7 +215,7 @@ public class DGamePlayer extends DInstancePlayer { return; } - DClass dClass = plugin.getDClasses().getByName(className); + DClass dClass = plugin.getDClassCache().getByName(className); if (dClass == null || this.dClass == dClass) { return; } @@ -396,7 +396,7 @@ public class DGamePlayer extends DInstancePlayer { * Creates a new group tag for the player. */ public void initDGroupTag() { - groupTag = new DGroupTag(this); + groupTag = new DGroupTag(plugin, this); } /* Actions */ @@ -679,7 +679,7 @@ public class DGamePlayer extends DInstancePlayer { Game game = Game.getByGameWorld(dGroup.getGameWorld()); if (game == null) { - game = new Game(dGroup, gameType, dGroup.getGameWorld()); + game = new Game(plugin, dGroup, gameType, dGroup.getGameWorld()); } else { game.setType(gameType); @@ -978,7 +978,7 @@ public class DGamePlayer extends DInstancePlayer { /* Statics */ public static DGamePlayer getByPlayer(Player player) { - for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) { + for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDGamePlayers()) { if (dPlayer.getPlayer().equals(player)) { return dPlayer; } @@ -987,7 +987,7 @@ public class DGamePlayer extends DInstancePlayer { } public static DGamePlayer getByName(String name) { - for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) { + for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDGamePlayers()) { if (dPlayer.getPlayer().getName().equalsIgnoreCase(name) || dPlayer.getName().equalsIgnoreCase(name)) { return dPlayer; } @@ -999,7 +999,7 @@ public class DGamePlayer extends DInstancePlayer { public static List getByWorld(World world) { List dPlayers = new ArrayList<>(); - for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) { + for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDGamePlayers()) { if (dPlayer.getWorld() == world) { dPlayers.add(dPlayer); } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java index 9d2a6c41..aa890ac4 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java @@ -46,9 +46,9 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class DGlobalPlayer implements PlayerWrapper { - DungeonsXL plugin = DungeonsXL.getInstance(); + protected DungeonsXL plugin; - boolean is1_9 = Internals.isAtLeast(Internals.v1_9_R1); + protected boolean is1_9 = Internals.isAtLeast(Internals.v1_9_R1); protected Player player; @@ -65,11 +65,13 @@ public class DGlobalPlayer implements PlayerWrapper { private ItemStack[] respawnArmor; private List rewardItems; - public DGlobalPlayer(Player player) { - this(player, false); + public DGlobalPlayer(DungeonsXL plugin, Player player) { + this(plugin, player, false); } - public DGlobalPlayer(Player player, boolean reset) { + public DGlobalPlayer(DungeonsXL plugin, Player player, boolean reset) { + this.plugin = plugin; + this.player = player; loadPlayerData(new File(DungeonsXL.PLAYERS, player.getUniqueId().toString() + ".yml")); @@ -77,11 +79,13 @@ public class DGlobalPlayer implements PlayerWrapper { reset(false); } - plugin.getDPlayers().addPlayer(this); + plugin.getDPlayerCache().addPlayer(this); } public DGlobalPlayer(DGlobalPlayer dPlayer) { + plugin = dPlayer.plugin; player = dPlayer.getPlayer(); + data = dPlayer.getData(); breakMode = dPlayer.isInBreakMode(); chatSpyMode = dPlayer.isInChatSpyMode(); creatingPortal = dPlayer.getPortal(); @@ -89,7 +93,7 @@ public class DGlobalPlayer implements PlayerWrapper { respawnInventory = dPlayer.getRespawnInventory(); respawnArmor = dPlayer.getRespawnArmor(); - plugin.getDPlayers().addPlayer(this); + plugin.getDPlayerCache().addPlayer(this); } /* Getters and setters */ @@ -397,7 +401,7 @@ public class DGlobalPlayer implements PlayerWrapper { } } - DGroup dGroup = new DGroup("Tutorial", player, dungeon); + DGroup dGroup = new DGroup(plugin, "Tutorial", player, dungeon); DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN); Bukkit.getPluginManager().callEvent(createEvent); @@ -409,8 +413,8 @@ public class DGlobalPlayer implements PlayerWrapper { // The maxInstances check is already done in the listener DGameWorld gameWorld = dungeon.getMap().instantiateAsGameWorld(true); dGroup.setGameWorld(gameWorld); - new Game(dGroup, gameWorld).setTutorial(true); - new DGamePlayer(player, gameWorld); + new Game(plugin, dGroup, gameWorld).setTutorial(true); + new DGamePlayer(plugin, player, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGroup.java b/src/main/java/de/erethon/dungeonsxl/player/DGroup.java index bd646da9..b30b2d8a 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGroup.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGroup.java @@ -55,8 +55,8 @@ import org.bukkit.scheduler.BukkitTask; */ public class DGroup { - DungeonsXL plugin = DungeonsXL.getInstance(); - DPlayerCache dPlayers = plugin.getDPlayers(); + DungeonsXL plugin; + DPlayerCache dPlayers; private String name; private Player captain; @@ -75,16 +75,19 @@ public class DGroup { private int initialLives = -1; private int lives = -1; - public DGroup(Player player) { - this("Group " + DungeonsXL.getInstance().getDGroups().size(), player); + public DGroup(DungeonsXL plugin, Player player) { + this(plugin, "Group " + plugin.getDGroupCache().size(), player); } - public DGroup(Player player, DColor color) { - this(color.toString().replace("_", " "), player); + public DGroup(DungeonsXL plugin, Player player, DColor color) { + this(plugin, color.toString().replace("_", " "), player); } - public DGroup(String name, Player player) { - plugin.getDGroups().add(this); + public DGroup(DungeonsXL plugin, String name, Player player) { + this.plugin = plugin; + dPlayers = plugin.getDPlayerCache(); + + plugin.getDGroupCache().add(this); this.name = name; setCaptain(player); @@ -94,19 +97,22 @@ public class DGroup { floorCount = 0; } - public DGroup(Player player, Dungeon dungeon) { - this(DungeonsXL.getInstance().getMainConfig().getGroupColorPriority().get(DungeonsXL.getInstance().getDGroups().size()).toString(), player, dungeon); + public DGroup(DungeonsXL plugin, Player player, Dungeon dungeon) { + this(plugin, plugin.getMainConfig().getGroupColorPriority().get(plugin.getDGroupCache().size()).toString(), player, dungeon); } - public DGroup(String name, Player player, Dungeon dungeon) { - this(name, player, new ArrayList(), dungeon); + public DGroup(DungeonsXL plugin, String name, Player player, Dungeon dungeon) { + this(plugin, name, player, new ArrayList(), dungeon); } - public DGroup(String name, Player captain, List players, Dungeon dungeon) { - plugin.getDGroups().add(this); + public DGroup(DungeonsXL plugin, String name, Player captain, List players, Dungeon dungeon) { + this.plugin = plugin; + dPlayers = plugin.getDPlayerCache(); + + plugin.getDGroupCache().add(this); this.name = name; - DPlayerJoinDGroupEvent event = new DPlayerJoinDGroupEvent(plugin.getDPlayers().getByPlayer(captain), true, this); + DPlayerJoinDGroupEvent event = new DPlayerJoinDGroupEvent(plugin.getDPlayerCache().getByPlayer(captain), true, this); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { @@ -242,7 +248,7 @@ public class DGroup { */ public void removePlayer(Player player, boolean message) { players.remove(player.getUniqueId()); - plugin.getGlobalProtections().updateGroupSigns(this); + plugin.getGlobalProtectionCache().updateGroupSigns(this); if (message) { sendMessage(DMessage.PLAYER_LEFT_GROUP.getMessage(player.getName())); @@ -377,15 +383,15 @@ public class DGroup { * @return if the action was successful */ public boolean setDungeon(String name) { - dungeon = plugin.getDungeons().getByName(name); + dungeon = plugin.getDungeonCache().getByName(name); if (dungeon != null) { unplayedFloors = dungeon.getConfig().getFloors(); return true; } else { - DResourceWorld resource = plugin.getDWorlds().getResourceByName(name); + DResourceWorld resource = plugin.getDWorldCache().getResourceByName(name); if (resource != null) { - dungeon = new Dungeon(resource); + dungeon = new Dungeon(plugin, resource); return true; } return false; @@ -682,7 +688,7 @@ public class DGroup { public void delete() { Game game = Game.getByDGroup(this); - plugin.getDGroups().remove(this); + plugin.getDGroupCache().remove(this); if (game != null) { game.removeDGroup(this); @@ -699,7 +705,7 @@ public class DGroup { timeIsRunningTask.cancel(); } - plugin.getGlobalProtections().updateGroupSigns(this); + plugin.getGlobalProtectionCache().updateGroupSigns(this); } public void startGame(Game game) { @@ -721,7 +727,7 @@ public class DGroup { for (Player player : dGroup.getPlayers().getOnlinePlayers()) { DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); if (dPlayer == null) { - dPlayer = new DGamePlayer(player, gameWorld); + dPlayer = new DGamePlayer(plugin, player, gameWorld); } if (rules.isGroupTagEnabled()) { dPlayer.initDGroupTag(); @@ -812,7 +818,7 @@ public class DGroup { } } - plugin.getGlobalProtections().updateGroupSigns(this); + plugin.getGlobalProtectionCache().updateGroupSigns(this); nextFloor = null; initialLives = rules.getInitialGroupLives(); lives = initialLives; @@ -885,7 +891,7 @@ public class DGroup { /* Statics */ public static DGroup getByName(String name) { - for (DGroup dGroup : DungeonsXL.getInstance().getDGroups()) { + for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) { if (dGroup.getName().equalsIgnoreCase(name) || dGroup.getRawName().equalsIgnoreCase(name)) { return dGroup; } @@ -895,7 +901,7 @@ public class DGroup { } public static DGroup getByPlayer(Player player) { - for (DGroup dGroup : DungeonsXL.getInstance().getDGroups()) { + for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) { if (dGroup.getPlayers().contains(player)) { return dGroup; } @@ -905,7 +911,7 @@ public class DGroup { } public static void leaveGroup(Player player) { - for (DGroup dGroup : DungeonsXL.getInstance().getDGroups()) { + for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) { if (dGroup.getPlayers().contains(player)) { dGroup.getPlayers().remove(player); } @@ -918,7 +924,7 @@ public class DGroup { */ public static List getByGameWorld(DGameWorld gameWorld) { List dGroups = new ArrayList<>(); - for (DGroup dGroup : DungeonsXL.getInstance().getDGroups()) { + for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) { if (dGroup.getGameWorld().equals(gameWorld)) { dGroups.add(dGroup); } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGroupTag.java b/src/main/java/de/erethon/dungeonsxl/player/DGroupTag.java index 21583098..5b2785df 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGroupTag.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGroupTag.java @@ -28,11 +28,11 @@ public class DGroupTag { private DGamePlayer player; private Hologram hologram; - public DGroupTag(DGamePlayer player) { + public DGroupTag(DungeonsXL plugin, DGamePlayer player) { this.player = player; DGroup group = player.getDGroup(); if (group != null) { - hologram = HologramsAPI.createHologram(DungeonsXL.getInstance(), player.getPlayer().getLocation().clone().add(0, 3.5, 0)); + hologram = HologramsAPI.createHologram(plugin, player.getPlayer().getLocation().clone().add(0, 3.5, 0)); hologram.appendItemLine(group.getDColor().getWoolMaterial().toItemStack()); hologram.appendTextLine(group.getName()); } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DInstancePlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DInstancePlayer.java index b4335281..ada31031 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DInstancePlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DInstancePlayer.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.player; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.MainConfig; import de.erethon.dungeonsxl.util.ParsingUtil; import de.erethon.dungeonsxl.world.DGameWorld; @@ -31,12 +32,15 @@ import org.bukkit.potion.PotionEffect; */ public abstract class DInstancePlayer extends DGlobalPlayer { - MainConfig config = plugin.getMainConfig(); + MainConfig config; private World world; - DInstancePlayer(Player player, World world) { - super(player, false); + DInstancePlayer(DungeonsXL plugin, Player player, World world) { + super(plugin, player, false); + + config = plugin.getMainConfig(); + this.world = world; getData().savePlayerState(player); } @@ -88,7 +92,7 @@ public abstract class DInstancePlayer extends DGlobalPlayer { new DGlobalPlayer(this); } else { - plugin.getDPlayers().removePlayer(this); + plugin.getDPlayerCache().removePlayer(this); } } @@ -98,14 +102,14 @@ public abstract class DInstancePlayer extends DGlobalPlayer { * @param message the message to send */ public void chat(String message) { - DInstanceWorld instance = plugin.getDWorlds().getInstanceByWorld(world); + DInstanceWorld instance = plugin.getDWorldCache().getInstanceByWorld(world); if (instance == null) { return; } String chatFormat = instance instanceof DGameWorld ? config.getChatFormatGame() : config.getChatFormatEdit(); instance.sendMessage(ParsingUtil.replaceChatPlaceholders(chatFormat, this) + message); - for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) { + for (DGlobalPlayer player : plugin.getDPlayerCache().getDGlobalPlayers()) { if (player.isInChatSpyMode()) { if (!instance.getWorld().getPlayers().contains(player.getPlayer())) { player.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatSpy(), this) + message); diff --git a/src/main/java/de/erethon/dungeonsxl/player/DPlayerCache.java b/src/main/java/de/erethon/dungeonsxl/player/DPlayerCache.java index 9fad6fb0..22c319c5 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DPlayerCache.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DPlayerCache.java @@ -35,8 +35,8 @@ import org.bukkit.scheduler.BukkitTask; */ public class DPlayerCache { - DungeonsXL plugin = DungeonsXL.getInstance(); - MainConfig mainConfig = plugin.getMainConfig(); + private DungeonsXL plugin; + private MainConfig config; private BukkitTask secureModeTask; private BukkitTask updateTask; @@ -44,14 +44,20 @@ public class DPlayerCache { private CopyOnWriteArrayList dGlobalPlayers = new CopyOnWriteArrayList<>(); - public DPlayerCache() { - if (mainConfig.isSecureModeEnabled()) { - startSecureModeTask(mainConfig.getSecureModeCheckInterval()); + public DPlayerCache(DungeonsXL plugin) { + this.plugin = plugin; + } + + public void init() { + config = plugin.getMainConfig(); + + if (config.isSecureModeEnabled()) { + startSecureModeTask(config.getSecureModeCheckInterval()); } startUpdateTask(2L); startLazyUpdateTask(20L); - Bukkit.getPluginManager().registerEvents(new DPlayerListener(this), plugin); + Bukkit.getPluginManager().registerEvents(new DPlayerListener(plugin), plugin); } /** @@ -64,7 +70,7 @@ public class DPlayerCache { return dGlobalPlayer; } } - return new DGlobalPlayer(player); + return new DGlobalPlayer(plugin, player); } /** @@ -86,7 +92,7 @@ public class DPlayerCache { */ public Collection getByInstance(DInstanceWorld instance) { Collection players = new ArrayList<>(); - plugin.getDWorlds().getInstances().forEach(i -> i.getPlayers().forEach(p -> players.add(p))); + plugin.getDWorldCache().getInstances().forEach(i -> i.getPlayers().forEach(p -> players.add(p))); return players; } @@ -160,7 +166,7 @@ public class DPlayerCache { */ public void loadAll() { for (Player player : Bukkit.getOnlinePlayers()) { - new DGlobalPlayer(player); + new DGlobalPlayer(plugin, player); } } @@ -195,7 +201,7 @@ public class DPlayerCache { * @param period the period in ticks */ public void startSecureModeTask(long period) { - secureModeTask = new SecureModeTask().runTaskTimer(plugin, period, period); + secureModeTask = new SecureModeTask(plugin).runTaskTimer(plugin, period, period); } /** @@ -211,7 +217,7 @@ public class DPlayerCache { * @param period the period in ticks */ public void startUpdateTask(long period) { - updateTask = new UpdateTask().runTaskTimer(plugin, period, period); + updateTask = new UpdateTask(plugin).runTaskTimer(plugin, period, period); } /** @@ -227,7 +233,7 @@ public class DPlayerCache { * @param period the period in ticks */ public void startLazyUpdateTask(long period) { - lazyUpdateTask = new LazyUpdateTask().runTaskTimer(plugin, period, period); + lazyUpdateTask = new LazyUpdateTask(plugin).runTaskTimer(plugin, period, period); } } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DPlayerData.java b/src/main/java/de/erethon/dungeonsxl/player/DPlayerData.java index 9600e570..b781925a 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DPlayerData.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DPlayerData.java @@ -19,8 +19,8 @@ package de.erethon.dungeonsxl.player; import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.compatibility.Internals; import de.erethon.commons.config.DREConfig; +import de.erethon.commons.javaplugin.DREPlugin; import de.erethon.commons.misc.EnumUtil; -import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import java.io.File; import java.io.IOException; @@ -45,7 +45,7 @@ import org.bukkit.potion.PotionEffect; */ public class DPlayerData extends DREConfig { - boolean is1_9 = Internals.isAtLeast(Internals.v1_9_R1); + protected boolean is1_9 = Internals.isAtLeast(Internals.v1_9_R1); public static final int CONFIG_VERSION = 4; @@ -383,7 +383,7 @@ public class DPlayerData extends DREConfig { if (!file.exists()) { try { file.createNewFile(); - MessageUtil.log(DungeonsXL.getInstance(), DMessage.LOG_NEW_PLAYER_DATA.getMessage(file.getName())); + MessageUtil.log(DREPlugin.getInstance(), DMessage.LOG_NEW_PLAYER_DATA.getMessage(file.getName())); } catch (IOException exception) { } } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DPlayerListener.java b/src/main/java/de/erethon/dungeonsxl/player/DPlayerListener.java index 30c4b73d..405b60fb 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DPlayerListener.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DPlayerListener.java @@ -65,15 +65,18 @@ import org.bukkit.inventory.meta.BookMeta; */ public class DPlayerListener implements Listener { - DungeonsXL plugin = DungeonsXL.getInstance(); - MainConfig config = plugin.getMainConfig(); - DWorldCache worlds = plugin.getDWorlds(); - DPlayerCache dPlayers; + private DungeonsXL plugin; + private MainConfig config; + private DWorldCache worlds; + private DPlayerCache dPlayers; public static final String ALL = "@all "; - public DPlayerListener(DPlayerCache dPlayers) { - this.dPlayers = dPlayers; + public DPlayerListener(DungeonsXL plugin) { + this.plugin = plugin; + config = plugin.getMainConfig(); + worlds = plugin.getDWorldCache(); + dPlayers = plugin.getDPlayerCache(); } @EventHandler @@ -372,7 +375,7 @@ public class DPlayerListener implements Listener { return; } - DGlobalPlayer dPlayer = new DGlobalPlayer(player); + DGlobalPlayer dPlayer = new DGlobalPlayer(plugin, player); if (dPlayer.getData().wasInGame()) { dPlayer.reset(dPlayer.getData().getKeepInventoryAfterLogout()); } @@ -447,7 +450,7 @@ public class DPlayerListener implements Listener { if (isCitizensNPC(player)) { return; } - plugin.getDPlayers().getByPlayer(player).applyRespawnInventory(); + plugin.getDPlayerCache().getByPlayer(player).applyRespawnInventory(); DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player); if (dPlayer == null) { @@ -485,7 +488,7 @@ public class DPlayerListener implements Listener { } // Because some plugins set another respawn point, DXL teleports a few ticks later. - new RespawnTask(player, respawn).runTaskLater(plugin, 10); + new RespawnTask(plugin, player, respawn).runTaskLater(plugin, 10); // Don't forget Doge! if (gamePlayer.getWolf() != null) { diff --git a/src/main/java/de/erethon/dungeonsxl/player/LazyUpdateTask.java b/src/main/java/de/erethon/dungeonsxl/player/LazyUpdateTask.java index 48619913..2145df8b 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/LazyUpdateTask.java +++ b/src/main/java/de/erethon/dungeonsxl/player/LazyUpdateTask.java @@ -24,9 +24,15 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class LazyUpdateTask extends BukkitRunnable { + private DungeonsXL plugin; + + public LazyUpdateTask(DungeonsXL plugin) { + this.plugin = plugin; + } + @Override public void run() { - for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) { + for (DGamePlayer dPlayer : plugin.getDPlayerCache().getDGamePlayers()) { dPlayer.update(true); } } diff --git a/src/main/java/de/erethon/dungeonsxl/player/RespawnTask.java b/src/main/java/de/erethon/dungeonsxl/player/RespawnTask.java index 70934919..028e02ec 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/RespawnTask.java +++ b/src/main/java/de/erethon/dungeonsxl/player/RespawnTask.java @@ -27,10 +27,14 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class RespawnTask extends BukkitRunnable { + private DPlayerCache dPlayers; + private Player player; private Location location; - public RespawnTask(Player player, Location location) { + public RespawnTask(DungeonsXL plugin, Player player, Location location) { + dPlayers = plugin.getDPlayerCache(); + this.location = location; this.player = player; } @@ -41,7 +45,7 @@ public class RespawnTask extends BukkitRunnable { PlayerUtil.secureTeleport(player, location); } - DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); if (dPlayer == null) { return; diff --git a/src/main/java/de/erethon/dungeonsxl/player/SecureModeTask.java b/src/main/java/de/erethon/dungeonsxl/player/SecureModeTask.java index a31d500a..7a26d64d 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/SecureModeTask.java +++ b/src/main/java/de/erethon/dungeonsxl/player/SecureModeTask.java @@ -26,12 +26,18 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class SecureModeTask extends BukkitRunnable { + private DungeonsXL plugin; + + public SecureModeTask(DungeonsXL plugin) { + this.plugin = plugin; + } + @Override public void run() { for (Player player : Bukkit.getOnlinePlayers()) { - DGlobalPlayer dGlobalPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); + DGlobalPlayer dGlobalPlayer = plugin.getDPlayerCache().getByPlayer(player); if (dGlobalPlayer == null) { - dGlobalPlayer = new DGlobalPlayer(player); + dGlobalPlayer = new DGlobalPlayer(plugin, player); } if (!(dGlobalPlayer instanceof DGamePlayer || dGlobalPlayer instanceof DEditPlayer)) { diff --git a/src/main/java/de/erethon/dungeonsxl/player/TimeIsRunningTask.java b/src/main/java/de/erethon/dungeonsxl/player/TimeIsRunningTask.java index bbbadc3b..34c8731d 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/TimeIsRunningTask.java +++ b/src/main/java/de/erethon/dungeonsxl/player/TimeIsRunningTask.java @@ -17,8 +17,6 @@ package de.erethon.dungeonsxl.player; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.config.MessageConfig; -import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.event.dplayer.DPlayerKickEvent; import de.erethon.dungeonsxl.game.Game; @@ -32,8 +30,6 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class TimeIsRunningTask extends BukkitRunnable { - MessageConfig messageConfig = DungeonsXL.getInstance().getMessageConfig(); - private DGroup dGroup; private int time; private int timeLeft; diff --git a/src/main/java/de/erethon/dungeonsxl/player/UpdateTask.java b/src/main/java/de/erethon/dungeonsxl/player/UpdateTask.java index 9f2f48e2..5559e453 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/UpdateTask.java +++ b/src/main/java/de/erethon/dungeonsxl/player/UpdateTask.java @@ -24,9 +24,15 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class UpdateTask extends BukkitRunnable { + private DungeonsXL plugin; + + public UpdateTask(DungeonsXL plugin) { + this.plugin = plugin; + } + @Override public void run() { - for (DInstancePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDInstancePlayers()) { + for (DInstancePlayer dPlayer : plugin.getDPlayerCache().getDInstancePlayers()) { dPlayer.update(false); } } diff --git a/src/main/java/de/erethon/dungeonsxl/requirement/FeeLevelRequirement.java b/src/main/java/de/erethon/dungeonsxl/requirement/FeeLevelRequirement.java index f359e52c..8ebb25ac 100644 --- a/src/main/java/de/erethon/dungeonsxl/requirement/FeeLevelRequirement.java +++ b/src/main/java/de/erethon/dungeonsxl/requirement/FeeLevelRequirement.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.requirement; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.game.GameRuleProvider; @@ -35,6 +36,10 @@ public class FeeLevelRequirement extends Requirement { private int fee; private Boolean keepInventory; + public FeeLevelRequirement(DungeonsXL plugin) { + super(plugin); + } + /* Getters and setters */ /** * @return the fee diff --git a/src/main/java/de/erethon/dungeonsxl/requirement/FeeMoneyRequirement.java b/src/main/java/de/erethon/dungeonsxl/requirement/FeeMoneyRequirement.java index c3081dd4..7b57b59d 100644 --- a/src/main/java/de/erethon/dungeonsxl/requirement/FeeMoneyRequirement.java +++ b/src/main/java/de/erethon/dungeonsxl/requirement/FeeMoneyRequirement.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.requirement; import de.erethon.commons.chat.MessageUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; +import net.milkbowl.vault.economy.Economy; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -27,12 +28,17 @@ import org.bukkit.entity.Player; */ public class FeeMoneyRequirement extends Requirement { - DungeonsXL plugin = DungeonsXL.getInstance(); + private Economy econ; private RequirementType type = RequirementTypeDefault.FEE_MONEY; private double fee; + public FeeMoneyRequirement(DungeonsXL plugin) { + super(plugin); + econ = plugin.getEconomyProvider(); + } + /* Getters and setters */ /** * @return the fee @@ -61,21 +67,21 @@ public class FeeMoneyRequirement extends Requirement { @Override public boolean check(Player player) { - if (plugin.getEconomyProvider() == null) { + if (econ == null) { return true; } - return plugin.getEconomyProvider().getBalance(player) >= fee; + return econ.getBalance(player) >= fee; } @Override public void demand(Player player) { - if (plugin.getEconomyProvider() == null) { + if (econ == null) { return; } - plugin.getEconomyProvider().withdrawPlayer(player, fee); - MessageUtil.sendMessage(player, DMessage.REQUIREMENT_FEE.getMessage(plugin.getEconomyProvider().format(fee))); + econ.withdrawPlayer(player, fee); + MessageUtil.sendMessage(player, DMessage.REQUIREMENT_FEE.getMessage(econ.format(fee))); } } diff --git a/src/main/java/de/erethon/dungeonsxl/requirement/ForbiddenItemsRequirement.java b/src/main/java/de/erethon/dungeonsxl/requirement/ForbiddenItemsRequirement.java index a74e2635..560d565a 100644 --- a/src/main/java/de/erethon/dungeonsxl/requirement/ForbiddenItemsRequirement.java +++ b/src/main/java/de/erethon/dungeonsxl/requirement/ForbiddenItemsRequirement.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.requirement; import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.item.ExItem; +import de.erethon.dungeonsxl.DungeonsXL; import java.util.List; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -28,12 +29,17 @@ import org.bukkit.inventory.ItemStack; */ public class ForbiddenItemsRequirement extends Requirement { - CaliburnAPI caliburn = CaliburnAPI.getInstance(); + private CaliburnAPI caliburn; private RequirementType type = RequirementTypeDefault.FORBIDDEN_ITEMS; private List forbiddenItems; + public ForbiddenItemsRequirement(DungeonsXL plugin) { + super(plugin); + caliburn = plugin.getCaliburn(); + } + /* Getters and setters */ /** * @return the forbidden items diff --git a/src/main/java/de/erethon/dungeonsxl/requirement/GroupSizeRequirement.java b/src/main/java/de/erethon/dungeonsxl/requirement/GroupSizeRequirement.java index 78b623ae..3e5bd677 100644 --- a/src/main/java/de/erethon/dungeonsxl/requirement/GroupSizeRequirement.java +++ b/src/main/java/de/erethon/dungeonsxl/requirement/GroupSizeRequirement.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.requirement; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.player.DGroup; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -30,6 +31,10 @@ public class GroupSizeRequirement extends Requirement { private int minimum; private int maximum; + public GroupSizeRequirement(DungeonsXL plugin) { + super(plugin); + } + /** * @return the group minimum */ diff --git a/src/main/java/de/erethon/dungeonsxl/requirement/KeyItemsRequirement.java b/src/main/java/de/erethon/dungeonsxl/requirement/KeyItemsRequirement.java index 3c72014d..f7564b8e 100644 --- a/src/main/java/de/erethon/dungeonsxl/requirement/KeyItemsRequirement.java +++ b/src/main/java/de/erethon/dungeonsxl/requirement/KeyItemsRequirement.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.requirement; import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.item.ExItem; +import de.erethon.dungeonsxl.DungeonsXL; import java.util.ArrayList; import java.util.List; import org.bukkit.configuration.ConfigurationSection; @@ -29,12 +30,17 @@ import org.bukkit.inventory.ItemStack; */ public class KeyItemsRequirement extends Requirement { - CaliburnAPI caliburn = CaliburnAPI.getInstance(); + private CaliburnAPI caliburn; private RequirementType type = RequirementTypeDefault.KEY_ITEMS; private List keyItems; + public KeyItemsRequirement(DungeonsXL plugin) { + super(plugin); + caliburn = plugin.getCaliburn(); + } + /* Getters and setters */ /** * @return the forbidden items diff --git a/src/main/java/de/erethon/dungeonsxl/requirement/PermissionRequirement.java b/src/main/java/de/erethon/dungeonsxl/requirement/PermissionRequirement.java index e73fd4f3..5e4a5cc6 100644 --- a/src/main/java/de/erethon/dungeonsxl/requirement/PermissionRequirement.java +++ b/src/main/java/de/erethon/dungeonsxl/requirement/PermissionRequirement.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.requirement; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.player.DPermission; import java.util.ArrayList; import java.util.List; @@ -31,6 +32,10 @@ public class PermissionRequirement extends Requirement { private List permissions = new ArrayList<>(); + public PermissionRequirement(DungeonsXL plugin) { + super(plugin); + } + /* Getters and setters */ /** * @return the permission the player must have to play the dungeon diff --git a/src/main/java/de/erethon/dungeonsxl/requirement/Requirement.java b/src/main/java/de/erethon/dungeonsxl/requirement/Requirement.java index e6d6392f..a3f02fa3 100644 --- a/src/main/java/de/erethon/dungeonsxl/requirement/Requirement.java +++ b/src/main/java/de/erethon/dungeonsxl/requirement/Requirement.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.requirement; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.event.requirement.RequirementRegistrationEvent; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -31,12 +32,18 @@ import org.bukkit.entity.Player; */ public abstract class Requirement { - public static Requirement create(RequirementType type) { + protected DungeonsXL plugin; + + protected Requirement(DungeonsXL plugin) { + this.plugin = plugin; + } + + public static Requirement create(DungeonsXL plugin, RequirementType type) { Requirement requirement = null; try { - Constructor constructor = type.getHandler().getConstructor(); - requirement = constructor.newInstance(); + Constructor constructor = type.getHandler().getConstructor(DungeonsXL.class); + requirement = constructor.newInstance(plugin); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { MessageUtil.log("An error occurred while accessing the handler class of the requirement " + type.getIdentifier() + ": " + exception.getClass().getSimpleName()); diff --git a/src/main/java/de/erethon/dungeonsxl/reward/ItemReward.java b/src/main/java/de/erethon/dungeonsxl/reward/ItemReward.java index 5c24643c..1c5816f8 100644 --- a/src/main/java/de/erethon/dungeonsxl/reward/ItemReward.java +++ b/src/main/java/de/erethon/dungeonsxl/reward/ItemReward.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.reward; +import de.erethon.dungeonsxl.DungeonsXL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -31,6 +32,10 @@ public class ItemReward extends Reward { private List items = new ArrayList<>(); + public ItemReward(DungeonsXL plugin) { + super(plugin); + } + /* Getters and setters */ /** * @return the reward items @@ -68,7 +73,7 @@ public class ItemReward extends Reward { /* Actions */ @Override public void giveTo(Player player) { - plugin.getDPlayers().getByPlayer(player).setRewardItems(items); + plugin.getDPlayerCache().getByPlayer(player).setRewardItems(items); } } diff --git a/src/main/java/de/erethon/dungeonsxl/reward/LevelReward.java b/src/main/java/de/erethon/dungeonsxl/reward/LevelReward.java index 1dc72605..27178125 100644 --- a/src/main/java/de/erethon/dungeonsxl/reward/LevelReward.java +++ b/src/main/java/de/erethon/dungeonsxl/reward/LevelReward.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.reward; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import org.bukkit.entity.Player; @@ -29,6 +30,10 @@ public class LevelReward extends Reward { private int levels; + public LevelReward(DungeonsXL plugin) { + super(plugin); + } + /** * @return the levels */ diff --git a/src/main/java/de/erethon/dungeonsxl/reward/MoneyReward.java b/src/main/java/de/erethon/dungeonsxl/reward/MoneyReward.java index f79a5ad1..fd9cf560 100644 --- a/src/main/java/de/erethon/dungeonsxl/reward/MoneyReward.java +++ b/src/main/java/de/erethon/dungeonsxl/reward/MoneyReward.java @@ -17,7 +17,9 @@ package de.erethon.dungeonsxl.reward; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; +import net.milkbowl.vault.economy.Economy; import org.bukkit.entity.Player; /** @@ -25,10 +27,17 @@ import org.bukkit.entity.Player; */ public class MoneyReward extends Reward { + private Economy econ; + private RewardType type = RewardTypeDefault.MONEY; private double money; + public MoneyReward(DungeonsXL plugin) { + super(plugin); + econ = plugin.getEconomyProvider(); + } + /** * @return the money */ @@ -52,11 +61,11 @@ public class MoneyReward extends Reward { @Override public void giveTo(Player player) { - if (plugin.getEconomyProvider() == null || money == 0) { + if (econ == null || money == 0) { return; } - plugin.getEconomyProvider().depositPlayer(player, money); + econ.depositPlayer(player, money); MessageUtil.sendMessage(player, DMessage.REWARD_GENERAL.getMessage(plugin.getEconomyProvider().format(money))); } diff --git a/src/main/java/de/erethon/dungeonsxl/reward/Reward.java b/src/main/java/de/erethon/dungeonsxl/reward/Reward.java index 37b426a7..a53884a6 100644 --- a/src/main/java/de/erethon/dungeonsxl/reward/Reward.java +++ b/src/main/java/de/erethon/dungeonsxl/reward/Reward.java @@ -31,14 +31,18 @@ import org.bukkit.entity.Player; */ public abstract class Reward { - DungeonsXL plugin = DungeonsXL.getInstance(); + protected DungeonsXL plugin; - public static Reward create(RewardType type) { + protected Reward(DungeonsXL plugin) { + this.plugin = plugin; + } + + public static Reward create(DungeonsXL plugin, RewardType type) { Reward reward = null; try { - Constructor constructor = type.getHandler().getConstructor(); - reward = constructor.newInstance(); + Constructor constructor = type.getHandler().getConstructor(DungeonsXL.class); + reward = constructor.newInstance(plugin); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { MessageUtil.log("An error occurred while accessing the handler class of the reward " + type.getIdentifier() + ": " + exception.getClass().getSimpleName()); diff --git a/src/main/java/de/erethon/dungeonsxl/reward/RewardListener.java b/src/main/java/de/erethon/dungeonsxl/reward/RewardListener.java index 8b700e28..176661f1 100644 --- a/src/main/java/de/erethon/dungeonsxl/reward/RewardListener.java +++ b/src/main/java/de/erethon/dungeonsxl/reward/RewardListener.java @@ -42,7 +42,11 @@ import org.bukkit.inventory.ItemStack; */ public class RewardListener implements Listener { - DungeonsXL plugin = DungeonsXL.getInstance(); + private DungeonsXL plugin; + + public RewardListener(DungeonsXL plugin) { + this.plugin = plugin; + } /*@EventHandler public void onInventoryClose(InventoryCloseEvent event) { @@ -109,8 +113,8 @@ public class RewardListener implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); - if (plugin.getDWorlds().getInstanceByWorld(player.getWorld()) != null) { + DGlobalPlayer dPlayer = plugin.getDPlayerCache().getByPlayer(player); + if (plugin.getDWorldCache().getInstanceByWorld(player.getWorld()) != null) { return; } Block block = player.getLocation().getBlock(); diff --git a/src/main/java/de/erethon/dungeonsxl/reward/RewardTypeCache.java b/src/main/java/de/erethon/dungeonsxl/reward/RewardTypeCache.java index 3359e662..6e48b68d 100644 --- a/src/main/java/de/erethon/dungeonsxl/reward/RewardTypeCache.java +++ b/src/main/java/de/erethon/dungeonsxl/reward/RewardTypeCache.java @@ -16,11 +16,9 @@ */ package de.erethon.dungeonsxl.reward; -import de.erethon.dungeonsxl.DungeonsXL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.bukkit.Bukkit; /** * RewardType instance manager. @@ -33,7 +31,6 @@ public class RewardTypeCache { public RewardTypeCache() { types.addAll(Arrays.asList(RewardTypeDefault.values())); - Bukkit.getPluginManager().registerEvents(new RewardListener(), DungeonsXL.getInstance()); } /** diff --git a/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java b/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java index 68ab3a5f..86e3ee17 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java @@ -20,6 +20,7 @@ import de.erethon.caliburn.category.Category; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.BlockUtil; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.TeamBed; import org.bukkit.block.Block; @@ -34,8 +35,8 @@ public class BedSign extends DSign { private int team; - public BedSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public BedSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ @@ -57,7 +58,7 @@ public class BedSign extends DSign { if (Category.BEDS.containsBlock(block)) { if (getGame().getDGroups().size() > team) { - getGameWorld().addGameBlock(new TeamBed(block, getGame().getDGroups().get(team))); + getGameWorld().addGameBlock(new TeamBed(plugin, block, getGame().getDGroups().get(team))); } getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } else { diff --git a/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java b/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java index 13e75d3a..d38dac48 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.util.MagicValueUtil; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.block.Sign; @@ -38,8 +39,8 @@ public class BlockSign extends DSign { private byte offBlockData = 0x0; private byte onBlockData = 0x0; - public BlockSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public BlockSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java b/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java index 64141cbc..edc7a2ed 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; @@ -39,8 +40,8 @@ public class BossShopSign extends DSign { private String shopName; - public BossShopSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public BossShopSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters*/ diff --git a/src/main/java/de/erethon/dungeonsxl/sign/CheckpointSign.java b/src/main/java/de/erethon/dungeonsxl/sign/CheckpointSign.java index b21dbec4..059edb85 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/CheckpointSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/CheckpointSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.world.DGameWorld; @@ -36,8 +37,8 @@ public class CheckpointSign extends DSign { private boolean initialized; private CopyOnWriteArrayList done = new CopyOnWriteArrayList<>(); - public CheckpointSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public CheckpointSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java b/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java index d1397ca9..1b93d04b 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java @@ -20,6 +20,7 @@ import de.erethon.caliburn.category.Category; import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.loottable.LootTable; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.RewardChest; import java.util.Arrays; @@ -44,8 +45,8 @@ public class ChestSign extends DSign { private ItemStack[] chestContent; private LootTable lootTable; - public ChestSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public ChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ @@ -178,7 +179,7 @@ public class ChestSign extends DSign { itemReward = list.toArray(new ItemStack[list.size()]); } - getGameWorld().addGameBlock(new RewardChest(chest, moneyReward, levelReward, itemReward)); + getGameWorld().addGameBlock(new RewardChest(plugin, chest, moneyReward, levelReward, itemReward)); getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } else { diff --git a/src/main/java/de/erethon/dungeonsxl/sign/ChunkUpdaterSign.java b/src/main/java/de/erethon/dungeonsxl/sign/ChunkUpdaterSign.java index a3a2b1d9..9349624e 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/ChunkUpdaterSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/ChunkUpdaterSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.Chunk; import org.bukkit.block.Sign; @@ -29,8 +30,8 @@ public class ChunkUpdaterSign extends DSign { private DSignType type = DSignTypeDefault.CHUNK_UPDATER; - public ChunkUpdaterSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public ChunkUpdaterSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/CommandSign.java b/src/main/java/de/erethon/dungeonsxl/sign/CommandSign.java index 6c97482f..a8353df2 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/CommandSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/CommandSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; import io.github.dre2n.commandsxl.CommandsXL; @@ -44,8 +45,8 @@ public class CommandSign extends DSign { private String executor; private boolean initialized; - public CommandSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public CommandSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/DSign.java b/src/main/java/de/erethon/dungeonsxl/sign/DSign.java index 9627e620..3f11b3b6 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/DSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/DSign.java @@ -39,7 +39,7 @@ import org.bukkit.entity.Player; */ public abstract class DSign { - protected DungeonsXL plugin = DungeonsXL.getInstance(); + protected DungeonsXL plugin; public static final String ERROR_0 = ChatColor.DARK_RED + "## ERROR ##"; public static final String ERROR_1 = ChatColor.WHITE + "Please"; @@ -55,7 +55,9 @@ public abstract class DSign { private boolean erroneous; - public DSign(Sign sign, String[] lines, DGameWorld gameWorld) { + protected DSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + this.plugin = plugin; + this.sign = sign; this.lines = lines; this.gameWorld = gameWorld; @@ -79,7 +81,7 @@ public abstract class DSign { value = triggerString.substring(1); } - Trigger trigger = Trigger.getOrCreate(type, value, this); + Trigger trigger = Trigger.getOrCreate(plugin, type, value, this); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); @@ -221,21 +223,21 @@ public abstract class DSign { } /* Statics */ - public static DSign create(Sign sign, DGameWorld gameWorld) { - return create(sign, sign.getLines(), gameWorld); + public static DSign create(DungeonsXL plugin, Sign sign, DGameWorld gameWorld) { + return create(plugin, sign, sign.getLines(), gameWorld); } - public static DSign create(Sign sign, String[] lines, DGameWorld gameWorld) { + public static DSign create(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { DSign dSign = null; - for (DSignType type : DungeonsXL.getInstance().getDSigns().getDSigns()) { + for (DSignType type : plugin.getDSignCache().getDSigns()) { if (!lines[0].equalsIgnoreCase("[" + type.getName() + "]")) { continue; } try { - Constructor constructor = type.getHandler().getConstructor(Sign.class, String[].class, DGameWorld.class); - dSign = constructor.newInstance(sign, lines, gameWorld); + Constructor constructor = type.getHandler().getConstructor(DungeonsXL.class, Sign.class, String[].class, DGameWorld.class); + dSign = constructor.newInstance(plugin, sign, lines, gameWorld); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { MessageUtil.log("An error occurred while accessing the handler class of the sign " + type.getName() + ": " + exception.getClass().getSimpleName()); diff --git a/src/main/java/de/erethon/dungeonsxl/sign/DSignListener.java b/src/main/java/de/erethon/dungeonsxl/sign/DSignListener.java index 41750f15..7175beed 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/DSignListener.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/DSignListener.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DPermission; @@ -39,6 +40,12 @@ import org.bukkit.event.player.PlayerInteractEvent; */ public class DSignListener implements Listener { + private DungeonsXL plugin; + + public DSignListener(DungeonsXL plugin) { + this.plugin = plugin; + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); @@ -97,7 +104,7 @@ public class DSignListener implements Listener { sign.setLine(2, lines[2]); sign.setLine(3, lines[3]); - DSign dsign = DSign.create(sign, null); + DSign dsign = DSign.create(plugin, sign, null); if (dsign == null) { return; diff --git a/src/main/java/de/erethon/dungeonsxl/sign/DSignTypeCache.java b/src/main/java/de/erethon/dungeonsxl/sign/DSignTypeCache.java index 0ff9d6ca..8a012b03 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/DSignTypeCache.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/DSignTypeCache.java @@ -29,11 +29,17 @@ import org.bukkit.Bukkit; */ public class DSignTypeCache { + private DungeonsXL plugin; + private List types = new ArrayList<>(); - public DSignTypeCache() { + public DSignTypeCache(DungeonsXL plugin) { + this.plugin = plugin; + } + + public void init() { types.addAll(Arrays.asList(DSignTypeDefault.values())); - Bukkit.getPluginManager().registerEvents(new DSignListener(), DungeonsXL.getInstance()); + Bukkit.getPluginManager().registerEvents(new DSignListener(plugin), plugin); } /** diff --git a/src/main/java/de/erethon/dungeonsxl/sign/DropSign.java b/src/main/java/de/erethon/dungeonsxl/sign/DropSign.java index 5617cbac..76cbe272 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/DropSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/DropSign.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.Location; import org.bukkit.block.Sign; @@ -35,8 +36,8 @@ public class DropSign extends DSign { private ItemStack item; private double interval = -1; - public DropSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public DropSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ diff --git a/src/main/java/de/erethon/dungeonsxl/sign/EndSign.java b/src/main/java/de/erethon/dungeonsxl/sign/EndSign.java index a7ef3780..1e77717b 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/EndSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/EndSign.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.dungeon.Dungeon; import de.erethon.dungeonsxl.player.DGamePlayer; @@ -36,8 +37,8 @@ public class EndSign extends DSign { private DResourceWorld floor; - public EndSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public EndSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /** @@ -62,7 +63,7 @@ public class EndSign extends DSign { @Override public void onInit() { if (!lines[1].isEmpty()) { - floor = plugin.getDWorlds().getResourceByName(lines[1]); + floor = plugin.getDWorldCache().getResourceByName(lines[1]); } if (!getTriggers().isEmpty()) { diff --git a/src/main/java/de/erethon/dungeonsxl/sign/FlagSign.java b/src/main/java/de/erethon/dungeonsxl/sign/FlagSign.java index 5137a5e2..7f4767de 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/FlagSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/FlagSign.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.TeamFlag; import org.bukkit.block.Sign; @@ -30,8 +31,8 @@ public class FlagSign extends DSign { private int team; - public FlagSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public FlagSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ @@ -50,7 +51,7 @@ public class FlagSign extends DSign { public void onInit() { this.team = NumberUtil.parseInt(lines[1]); if (getGame().getDGroups().size() > team) { - getGameWorld().addGameBlock(new TeamFlag(getSign().getBlock(), getGame().getDGroups().get(team))); + getGameWorld().addGameBlock(new TeamFlag(plugin, getSign().getBlock(), getGame().getDGroups().get(team))); } } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/InteractSign.java b/src/main/java/de/erethon/dungeonsxl/sign/InteractSign.java index 784abbbe..e97e1290 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/InteractSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/InteractSign.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DGameWorld; @@ -34,8 +35,8 @@ public class InteractSign extends DSign { private DSignType type = DSignTypeDefault.INTERACT; - public InteractSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public InteractSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/LeaveSign.java b/src/main/java/de/erethon/dungeonsxl/sign/LeaveSign.java index 0cc01fcd..b89da6b1 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/LeaveSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/LeaveSign.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; import de.erethon.dungeonsxl.player.DGamePlayer; @@ -34,8 +35,8 @@ public class LeaveSign extends DSign { private DSignType type = DSignTypeDefault.LEAVE; - public LeaveSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public LeaveSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override @@ -81,7 +82,7 @@ public class LeaveSign extends DSign { @Override public void onTrigger() { - for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) { + for (DGamePlayer dPlayer : plugin.getDPlayerCache().getDGamePlayers()) { DGamePlayerEscapeEvent event = new DGamePlayerEscapeEvent(dPlayer); Bukkit.getPluginManager().callEvent(event); diff --git a/src/main/java/de/erethon/dungeonsxl/sign/LivesModifierSign.java b/src/main/java/de/erethon/dungeonsxl/sign/LivesModifierSign.java index 04632c07..7b620c51 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/LivesModifierSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/LivesModifierSign.java @@ -20,6 +20,7 @@ import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.misc.EnumUtil; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.player.DGamePlayer; @@ -44,8 +45,8 @@ public class LivesModifierSign extends DSign { private int lives; private Target target; - public LivesModifierSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public LivesModifierSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ diff --git a/src/main/java/de/erethon/dungeonsxl/sign/LocationSign.java b/src/main/java/de/erethon/dungeonsxl/sign/LocationSign.java index 9f40a547..dad86d57 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/LocationSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/LocationSign.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.sign; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.Location; import org.bukkit.block.Sign; @@ -27,8 +28,8 @@ public abstract class LocationSign extends DSign { protected Location location; - public LocationSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public LocationSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/MobSign.java b/src/main/java/de/erethon/dungeonsxl/sign/MobSign.java index b330b4ac..72837c79 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/MobSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/MobSign.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.mob.ExMob; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.mob.ExternalMobProvider; import de.erethon.dungeonsxl.mob.ExternalMobProviderCache; import de.erethon.dungeonsxl.world.DGameWorld; @@ -36,7 +37,7 @@ import org.bukkit.scheduler.BukkitTask; */ public class MobSign extends DSign { - ExternalMobProviderCache providers = plugin.getExternalMobProviders(); + private ExternalMobProviderCache providers; private DSignType type = DSignTypeDefault.MOB; @@ -51,8 +52,9 @@ public class MobSign extends DSign { private BukkitTask task; private Collection spawnedMobs = new ArrayList<>(); - public MobSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public MobSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); + providers = plugin.getExternalMobProviderCache(); } /** diff --git a/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java b/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java index e9726d6c..550ac995 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.BlockUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.LockedDoor; import org.bukkit.block.Block; @@ -35,8 +36,8 @@ public class OpenDoorSign extends DSign { private LockedDoor door; private boolean active = true; - public OpenDoorSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public OpenDoorSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ @@ -84,9 +85,9 @@ public class OpenDoorSign extends DSign { Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); if (block.getState().getData() instanceof Door) { if (block.getRelative(BlockFace.DOWN).getType() == block.getType()) { - door = new LockedDoor(block.getRelative(BlockFace.DOWN)); + door = new LockedDoor(plugin, block.getRelative(BlockFace.DOWN)); } else { - door = new LockedDoor(block); + door = new LockedDoor(plugin, block); } getGameWorld().addGameBlock(door); diff --git a/src/main/java/de/erethon/dungeonsxl/sign/PerPlayerSign.java b/src/main/java/de/erethon/dungeonsxl/sign/PerPlayerSign.java index 501b27ec..26250f07 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/PerPlayerSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/PerPlayerSign.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.sign; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import java.util.HashSet; import java.util.Set; @@ -30,8 +31,8 @@ public abstract class PerPlayerSign extends DSign { private Set triggered = new HashSet<>(); - public PerPlayerSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public PerPlayerSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/PlaceSign.java b/src/main/java/de/erethon/dungeonsxl/sign/PlaceSign.java index 8c552217..96a0fd52 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/PlaceSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/PlaceSign.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.PlaceableBlock; import org.bukkit.block.Sign; @@ -28,8 +29,8 @@ public class PlaceSign extends DSign { private DSignType type = DSignTypeDefault.PLACE; - public PlaceSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public PlaceSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override @@ -39,7 +40,7 @@ public class PlaceSign extends DSign { @Override public void onInit() { - getGameWorld().addGameBlock(new PlaceableBlock(getSign().getBlock(), lines[1], lines[2])); + getGameWorld().addGameBlock(new PlaceableBlock(plugin, getSign().getBlock(), lines[1], lines[2])); getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/ProtectionSign.java b/src/main/java/de/erethon/dungeonsxl/sign/ProtectionSign.java index 4f69bcb5..2c6af492 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/ProtectionSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/ProtectionSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.BlockUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.ProtectedBlock; import org.bukkit.block.Sign; @@ -29,8 +30,8 @@ public class ProtectionSign extends DSign { private DSignType type = DSignTypeDefault.PROTECTION; - public ProtectionSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public ProtectionSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ @@ -47,7 +48,7 @@ public class ProtectionSign extends DSign { @Override public void onInit() { - getGameWorld().addGameBlock(new ProtectedBlock(BlockUtil.getAttachedBlock(getSign().getBlock()))); + getGameWorld().addGameBlock(new ProtectedBlock(plugin, BlockUtil.getAttachedBlock(getSign().getBlock()))); getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/RedstoneSign.java b/src/main/java/de/erethon/dungeonsxl/sign/RedstoneSign.java index 4b6870ff..befa8e6e 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/RedstoneSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/RedstoneSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -41,8 +42,8 @@ public class RedstoneSign extends DSign { private int repeat = 1; private int repeatsToDo = 1; - public RedstoneSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public RedstoneSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /** diff --git a/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java b/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java index c9a0300c..ad508c75 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; @@ -33,8 +34,8 @@ public class ResourcePackSign extends DSign { private String resourcePack; - public ResourcePackSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public ResourcePackSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ diff --git a/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java b/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java index ce99744e..e3a177df 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.sign; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.block.Sign; @@ -28,8 +29,8 @@ public class ScriptSign extends DSign { private String name; - public ScriptSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public ScriptSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); name = lines[1]; } @@ -42,14 +43,14 @@ public class ScriptSign extends DSign { @Override public boolean check() { - return plugin.getSignScripts().getByName(lines[1]) != null; + return plugin.getSignScriptCache().getByName(lines[1]) != null; } @Override public void onInit() { - SignScript script = plugin.getSignScripts().getByName(name); + SignScript script = plugin.getSignScriptCache().getByName(name); for (String[] lines : script.getSigns()) { - DSign dSign = DSign.create(getSign(), lines, getGameWorld()); + DSign dSign = DSign.create(plugin, getSign(), lines, getGameWorld()); if (dSign.isErroneous()) { continue; } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/SignScriptCache.java b/src/main/java/de/erethon/dungeonsxl/sign/SignScriptCache.java index c3a5af25..9fb5747f 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/SignScriptCache.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/SignScriptCache.java @@ -30,7 +30,7 @@ public class SignScriptCache { private List scripts = new ArrayList<>(); - public SignScriptCache(File file) { + public void init(File file) { if (file.isDirectory()) { for (File script : FileUtil.getFilesForFolder(file)) { scripts.add(new SignScript(script)); diff --git a/src/main/java/de/erethon/dungeonsxl/sign/TeleportSign.java b/src/main/java/de/erethon/dungeonsxl/sign/TeleportSign.java index 205b3f42..d057fbf4 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/TeleportSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/TeleportSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -29,8 +30,8 @@ public class TeleportSign extends LocationSign { private DSignType type = DSignTypeDefault.TELEPORT; - public TeleportSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public TeleportSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/TriggerSign.java b/src/main/java/de/erethon/dungeonsxl/sign/TriggerSign.java index 999c3b77..7b409703 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/TriggerSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/TriggerSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.trigger.SignTrigger; import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DGameWorld; @@ -37,8 +38,8 @@ public class TriggerSign extends DSign { private int triggerId; private boolean initialized; - public TriggerSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public TriggerSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/WaveSign.java b/src/main/java/de/erethon/dungeonsxl/sign/WaveSign.java index 3672eb24..4d8e0d01 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/WaveSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/WaveSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; @@ -35,8 +36,8 @@ public class WaveSign extends DSign { private double mobCountIncreaseRate; private boolean teleport; - public WaveSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public WaveSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /** diff --git a/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java b/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java index b6102a01..ae3bc3c7 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.sign.lobby; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.player.DClass; import de.erethon.dungeonsxl.sign.DSign; import de.erethon.dungeonsxl.sign.DSignType; @@ -33,9 +34,9 @@ public class ClassesSign extends DSign { private DClass dClass; - public ClassesSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); - dClass = plugin.getDClasses().getByName(sign.getLine(1)); + public ClassesSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); + dClass = plugin.getDClassCache().getByName(sign.getLine(1)); } /* Getters and setters */ @@ -56,7 +57,7 @@ public class ClassesSign extends DSign { /* Actions */ @Override public boolean check() { - return plugin.getDClasses().getByName(lines[1]) != null; + return plugin.getDClassCache().getByName(lines[1]) != null; } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/lobby/LobbySign.java b/src/main/java/de/erethon/dungeonsxl/sign/lobby/LobbySign.java index 10a49f13..8d9252fa 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/lobby/LobbySign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/lobby/LobbySign.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.sign.lobby; import de.erethon.caliburn.item.VanillaItem; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.sign.DSignType; import de.erethon.dungeonsxl.sign.DSignTypeDefault; import de.erethon.dungeonsxl.sign.LocationSign; @@ -30,8 +31,8 @@ public class LobbySign extends LocationSign { private DSignType type = DSignTypeDefault.LOBBY; - public LobbySign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public LobbySign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java b/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java index ba0e70d4..66d75531 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.sign.lobby; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.game.GameType; import de.erethon.dungeonsxl.game.GameTypeDefault; @@ -39,15 +40,15 @@ import org.bukkit.scheduler.BukkitRunnable; * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ public class ReadySign extends DSign { - + private DSignType type = DSignTypeDefault.READY; - + private GameType gameType; private double autoStart = -1; private boolean triggered = false; - - public ReadySign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + + public ReadySign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /** @@ -77,85 +78,85 @@ public class ReadySign extends DSign { public void setTimeToAutoStart(double time) { autoStart = time; } - + @Override public boolean check() { return true; } - + @Override public void onInit() { - if (plugin.getGameTypes().getBySign(this) != null) { - gameType = plugin.getGameTypes().getBySign(this); - + if (plugin.getGameTypeCache().getBySign(this) != null) { + gameType = plugin.getGameTypeCache().getBySign(this); + } else { gameType = GameTypeDefault.CUSTOM; } - + if (!lines[2].isEmpty()) { autoStart = NumberUtil.parseDouble(lines[2], -1); } - + if (!getTriggers().isEmpty()) { getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); return; } - + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); } - + getSign().setLine(0, ChatColor.DARK_BLUE + "############"); getSign().setLine(1, DMessage.SIGN_READY.getMessage()); getSign().setLine(2, ChatColor.DARK_RED + gameType.getSignName()); getSign().setLine(3, ChatColor.DARK_BLUE + "############"); getSign().update(); } - + @Override public boolean onPlayerTrigger(Player player) { ready(DGamePlayer.getByPlayer(player)); - + if (!triggered && autoStart >= 0) { triggered = true; - + new BukkitRunnable() { @Override public void run() { onTrigger(); } }.runTaskLater(plugin, (long) (autoStart * 20)); - + if (!DGroup.getByPlayer(player).isPlaying()) { - ProgressBar.sendProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)); + new ProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)).send(plugin); } } - + return true; } - + @Override public void onTrigger() { if (getGame() == null) { return; } - + for (Player player : getGame().getPlayers()) { ready(DGamePlayer.getByPlayer(player)); } } - + private void ready(DGamePlayer dPlayer) { if (dPlayer == null) { return; } - + if (dPlayer.isReady()) { return; } - + if (getGameWorld().getClassesSigns().isEmpty() || dPlayer.getDClass() != null) { GameType forced = null; if (getGameWorld().getConfig() != null) { @@ -163,15 +164,15 @@ public class ReadySign extends DSign { } dPlayer.ready(forced == null ? gameType : forced); } - + if (dPlayer.isReady()) { MessageUtil.sendMessage(dPlayer.getPlayer(), (dPlayer.isReady() ? DMessage.PLAYER_READY : DMessage.ERROR_READY).getMessage()); } } - + @Override public DSignType getType() { return type; } - + } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/lobby/StartSign.java b/src/main/java/de/erethon/dungeonsxl/sign/lobby/StartSign.java index 008ba117..99fb240c 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/lobby/StartSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/lobby/StartSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign.lobby; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.sign.DSignType; import de.erethon.dungeonsxl.sign.DSignTypeDefault; import de.erethon.dungeonsxl.sign.LocationSign; @@ -33,8 +34,8 @@ public class StartSign extends LocationSign { private int id; - public StartSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public StartSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters */ diff --git a/src/main/java/de/erethon/dungeonsxl/sign/message/ActionBarSign.java b/src/main/java/de/erethon/dungeonsxl/sign/message/ActionBarSign.java index 42d0eb79..aa09fcdf 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/message/ActionBarSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/message/ActionBarSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign.message; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.sign.DSignType; import de.erethon.dungeonsxl.sign.DSignTypeDefault; import de.erethon.dungeonsxl.sign.PerPlayerSign; @@ -34,8 +35,8 @@ public class ActionBarSign extends PerPlayerSign { private String text; - public ActionBarSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public ActionBarSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters*/ diff --git a/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java b/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java index 6daec383..7eb92759 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java @@ -21,6 +21,7 @@ import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.sign.DSign; import de.erethon.dungeonsxl.sign.DSignType; import de.erethon.dungeonsxl.sign.DSignTypeDefault; @@ -40,8 +41,8 @@ public class HologramSign extends DSign { private Hologram hologram; - public HologramSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public HologramSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/message/MessageSign.java b/src/main/java/de/erethon/dungeonsxl/sign/message/MessageSign.java index 9f84ee64..823eff13 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/message/MessageSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/message/MessageSign.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.sign.message; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.sign.DSign; import de.erethon.dungeonsxl.sign.DSignType; import de.erethon.dungeonsxl.sign.DSignTypeDefault; @@ -39,8 +40,8 @@ public class MessageSign extends DSign { private boolean initialized; private CopyOnWriteArrayList done = new CopyOnWriteArrayList<>(); - public MessageSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public MessageSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java b/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java index 1addddc3..bdcb7f8e 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java @@ -20,6 +20,7 @@ import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.compatibility.Internals; import de.erethon.commons.misc.EnumUtil; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.sign.DSign; import de.erethon.dungeonsxl.sign.DSignType; import de.erethon.dungeonsxl.sign.DSignTypeDefault; @@ -44,8 +45,8 @@ public class SoundMessageSign extends DSign { private float pitch; private CopyOnWriteArrayList done = new CopyOnWriteArrayList<>(); - public SoundMessageSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public SoundMessageSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/sign/message/TitleSign.java b/src/main/java/de/erethon/dungeonsxl/sign/message/TitleSign.java index bdb7df78..18c7f69b 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/message/TitleSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/message/TitleSign.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign.message; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.sign.DSignType; import de.erethon.dungeonsxl.sign.DSignTypeDefault; import de.erethon.dungeonsxl.sign.PerPlayerSign; @@ -35,8 +36,8 @@ public class TitleSign extends PerPlayerSign { private String title; private String subtitle; - public TitleSign(Sign sign, String[] lines, DGameWorld gameWorld) { - super(sign, lines, gameWorld); + public TitleSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { + super(plugin, sign, lines, gameWorld); } /* Getters and setters*/ diff --git a/src/main/java/de/erethon/dungeonsxl/trigger/ProgressTrigger.java b/src/main/java/de/erethon/dungeonsxl/trigger/ProgressTrigger.java index 53f59618..9466c1d2 100644 --- a/src/main/java/de/erethon/dungeonsxl/trigger/ProgressTrigger.java +++ b/src/main/java/de/erethon/dungeonsxl/trigger/ProgressTrigger.java @@ -113,8 +113,8 @@ public class ProgressTrigger extends Trigger { return new ProgressTrigger(floorCount, waveCount); } - public static ProgressTrigger getOrCreate(String floor, DGameWorld gameWorld) { - DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(floor); + public static ProgressTrigger getOrCreate(DungeonsXL plugin, String floor, DGameWorld gameWorld) { + DResourceWorld resource = plugin.getDWorldCache().getResourceByName(floor); if (resource != null) { return new ProgressTrigger(resource); diff --git a/src/main/java/de/erethon/dungeonsxl/trigger/Trigger.java b/src/main/java/de/erethon/dungeonsxl/trigger/Trigger.java index 10baf8a3..e874e172 100644 --- a/src/main/java/de/erethon/dungeonsxl/trigger/Trigger.java +++ b/src/main/java/de/erethon/dungeonsxl/trigger/Trigger.java @@ -118,8 +118,8 @@ public abstract class Trigger { gameWorld.removeTrigger(this); } - public static Trigger getOrCreate(String identifier, String value, DSign dSign) { - TriggerType type = DungeonsXL.getInstance().getTriggers().getByIdentifier(identifier); + public static Trigger getOrCreate(DungeonsXL plugin, String identifier, String value, DSign dSign) { + TriggerType type = plugin.getTriggerCache().getByIdentifier(identifier); Trigger trigger = null; if (type == TriggerTypeDefault.REDSTONE) { @@ -168,14 +168,14 @@ public abstract class Trigger { trigger = ProgressTrigger.getOrCreate(floorCount, waveCount, dSign.getGameWorld()); } else { - trigger = ProgressTrigger.getOrCreate(value, dSign.getGameWorld()); + trigger = ProgressTrigger.getOrCreate(plugin, value, dSign.getGameWorld()); } } } else if (type == TriggerTypeDefault.USE_ITEM) { if (value != null) { - trigger = UseItemTrigger.getOrCreate(value, dSign.getGameWorld()); + trigger = UseItemTrigger.getOrCreate(plugin, value, dSign.getGameWorld()); } } else if (type == TriggerTypeDefault.WAVE) { diff --git a/src/main/java/de/erethon/dungeonsxl/trigger/TriggerListener.java b/src/main/java/de/erethon/dungeonsxl/trigger/TriggerListener.java index f7dc55bd..138934af 100644 --- a/src/main/java/de/erethon/dungeonsxl/trigger/TriggerListener.java +++ b/src/main/java/de/erethon/dungeonsxl/trigger/TriggerListener.java @@ -28,18 +28,24 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class TriggerListener implements Listener { + private DungeonsXL plugin; + + public TriggerListener(DungeonsXL plugin) { + this.plugin = plugin; + } + @EventHandler public void onRedstoneEvent(final BlockRedstoneEvent event) { new BukkitRunnable() { @Override public void run() { - for (DGameWorld gameWorld : DungeonsXL.getInstance().getDWorlds().getGameWorlds()) { + for (DGameWorld gameWorld : plugin.getDWorldCache().getGameWorlds()) { if (event.getBlock().getWorld() == gameWorld.getWorld()) { RedstoneTrigger.updateAll(gameWorld); } } } - }.runTaskLater(DungeonsXL.getInstance(), 1); + }.runTaskLater(plugin, 1); } } diff --git a/src/main/java/de/erethon/dungeonsxl/trigger/TriggerTypeCache.java b/src/main/java/de/erethon/dungeonsxl/trigger/TriggerTypeCache.java index 6630a40f..0a0e48b5 100644 --- a/src/main/java/de/erethon/dungeonsxl/trigger/TriggerTypeCache.java +++ b/src/main/java/de/erethon/dungeonsxl/trigger/TriggerTypeCache.java @@ -16,11 +16,9 @@ */ package de.erethon.dungeonsxl.trigger; -import de.erethon.dungeonsxl.DungeonsXL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.bukkit.Bukkit; /** * TriggerType instance manager. @@ -33,7 +31,6 @@ public class TriggerTypeCache { public TriggerTypeCache() { types.addAll(Arrays.asList(TriggerTypeDefault.values())); - Bukkit.getPluginManager().registerEvents(new TriggerListener(), DungeonsXL.getInstance()); } /** diff --git a/src/main/java/de/erethon/dungeonsxl/trigger/UseItemTrigger.java b/src/main/java/de/erethon/dungeonsxl/trigger/UseItemTrigger.java index 6eba0d67..7555e956 100644 --- a/src/main/java/de/erethon/dungeonsxl/trigger/UseItemTrigger.java +++ b/src/main/java/de/erethon/dungeonsxl/trigger/UseItemTrigger.java @@ -16,8 +16,8 @@ */ package de.erethon.dungeonsxl.trigger; -import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.item.ExItem; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.event.trigger.TriggerActionEvent; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.Bukkit; @@ -33,9 +33,9 @@ public class UseItemTrigger extends Trigger { private String name; private String matchedName; - public UseItemTrigger(String name) { + public UseItemTrigger(DungeonsXL plugin, String name) { this.name = name; - ExItem item = CaliburnAPI.getInstance().getExItem(name); + ExItem item = plugin.getCaliburn().getExItem(name); if (item != null) { matchedName = item.toString(); } @@ -60,12 +60,12 @@ public class UseItemTrigger extends Trigger { } /* Statics */ - public static UseItemTrigger getOrCreate(String name, DGameWorld gameWorld) { + public static UseItemTrigger getOrCreate(DungeonsXL plugin, String name, DGameWorld gameWorld) { UseItemTrigger trigger = getByName(name, gameWorld); if (trigger != null) { return trigger; } - return new UseItemTrigger(name); + return new UseItemTrigger(plugin, name); } public static UseItemTrigger getByName(String name, DGameWorld gameWorld) { diff --git a/src/main/java/de/erethon/dungeonsxl/util/ProgressBar.java b/src/main/java/de/erethon/dungeonsxl/util/ProgressBar.java index 7523a4ee..7bd730e2 100644 --- a/src/main/java/de/erethon/dungeonsxl/util/ProgressBar.java +++ b/src/main/java/de/erethon/dungeonsxl/util/ProgressBar.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.util; import de.erethon.commons.chat.MessageUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.commons.javaplugin.DREPlugin; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -25,6 +25,7 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; @@ -89,25 +90,13 @@ public class ProgressBar extends BukkitRunnable { } /** - * Send the progress bar to a player + * Sends the progress bar to a player * - * @param player the player - * @param seconds the total time in seconds + * @param plugin the plugin instance * @return the scheduled BukkitTask */ - public static BukkitTask sendProgressBar(Player player, int seconds) { - return new ProgressBar(player, seconds).runTaskTimer(DungeonsXL.getInstance(), 0L, 20L); - } - - /** - * Send the progress bar to multiple players - * - * @param players a Collection of the players who shall see this progress bar - * @param seconds the total time in seconds - * @return the scheduled BukkitTask - */ - public static BukkitTask sendProgressBar(Collection players, int seconds) { - return new ProgressBar(players, seconds).runTaskTimer(DungeonsXL.getInstance(), 0L, 20L); + public BukkitTask send(Plugin plugin) { + return runTaskTimer(plugin, 0L, 20L); } } diff --git a/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java index 1eac48d6..2a1efbfb 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java @@ -35,19 +35,17 @@ import org.bukkit.block.Sign; */ public class DEditWorld extends DInstanceWorld { - DWorldCache worlds = plugin.getDWorlds(); - public static String ID_FILE_PREFIX = ".id_"; private File idFile; private CopyOnWriteArrayList signs = new CopyOnWriteArrayList<>(); - DEditWorld(DResourceWorld resourceWorld, File folder, World world, int id) { - super(resourceWorld, folder, world, id); + DEditWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, World world, int id) { + super(plugin, resourceWorld, folder, world, id); } - DEditWorld(DResourceWorld resourceWorld, File folder, int id) { - this(resourceWorld, folder, null, id); + DEditWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, int id) { + this(plugin, resourceWorld, folder, null, id); } /* Getters and setters */ @@ -168,7 +166,7 @@ public class DEditWorld extends DInstanceWorld { * @return the DEditWorld that represents the world */ public static DEditWorld getByName(String name) { - DInstanceWorld instance = DungeonsXL.getInstance().getDWorlds().getInstanceByName(name); + DInstanceWorld instance = DungeonsXL.getInstance().getDWorldCache().getInstanceByName(name); if (instance instanceof DEditWorld) { return (DEditWorld) instance; diff --git a/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java index bf10e9a6..9cb43386 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java @@ -83,8 +83,8 @@ public class DGameWorld extends DInstanceWorld { DEFAULT } - CaliburnAPI caliburn = plugin.getCaliburn(); - Game game; + private CaliburnAPI caliburn; + private Game game; // Variables private Type type = Type.DEFAULT; @@ -108,12 +108,14 @@ public class DGameWorld extends DInstanceWorld { private CopyOnWriteArrayList dSigns = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList triggers = new CopyOnWriteArrayList<>(); - DGameWorld(DResourceWorld resourceWorld, File folder, World world, int id) { - super(resourceWorld, folder, world, id); + DGameWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, World world, int id) { + super(plugin, resourceWorld, folder, world, id); + caliburn = plugin.getCaliburn(); } - DGameWorld(DResourceWorld resourceWorld, File folder, int id) { - this(resourceWorld, folder, null, id); + DGameWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, int id) { + this(plugin, resourceWorld, folder, null, id); + caliburn = plugin.getCaliburn(); } /** @@ -121,7 +123,7 @@ public class DGameWorld extends DInstanceWorld { */ public Game getGame() { if (game == null) { - for (Game game : plugin.getGames()) { + for (Game game : plugin.getGameCache()) { if (game.getWorld() == this) { this.game = game; } @@ -428,7 +430,7 @@ public class DGameWorld extends DInstanceWorld { * @return the Dungeon that contains the DGameWorld */ public Dungeon getDungeon() { - for (Dungeon dungeon : plugin.getDungeons().getDungeons()) { + for (Dungeon dungeon : plugin.getDungeonCache().getDungeons()) { if (dungeon.getConfig().containsFloor(getResource())) { return dungeon; } @@ -569,7 +571,7 @@ public class DGameWorld extends DInstanceWorld { } if (entity.getLocation().getBlock().getRelative(((Hanging) entity).getAttachedFace()).equals(block)) { Hanging hanging = (Hanging) entity; - if (rules.getDamageProtectedEntities().contains(CaliburnAPI.getInstance().getExMob(hanging))) { + if (rules.getDamageProtectedEntities().contains(caliburn.getExMob(hanging))) { event.setCancelled(true); break; } @@ -646,7 +648,7 @@ public class DGameWorld extends DInstanceWorld { * @return the EditWorld that represents the world */ public static DGameWorld getByWorld(World world) { - DInstanceWorld instance = DungeonsXL.getInstance().getDWorlds().getInstanceByName(world.getName()); + DInstanceWorld instance = DungeonsXL.getInstance().getDWorldCache().getInstanceByName(world.getName()); if (instance instanceof DGameWorld) { return (DGameWorld) instance; diff --git a/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java index 95eb4d57..3b23fe39 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java @@ -36,9 +36,9 @@ import org.bukkit.World; */ public abstract class DInstanceWorld { - DungeonsXL plugin = DungeonsXL.getInstance(); - DWorldCache worlds = plugin.getDWorlds(); - DPlayerCache dPlayers = plugin.getDPlayers(); + protected DungeonsXL plugin; + protected DWorldCache worlds; + protected DPlayerCache dPlayers; private DResourceWorld resourceWorld; private File folder; @@ -46,7 +46,11 @@ public abstract class DInstanceWorld { private int id; private Location lobby; - DInstanceWorld(DResourceWorld resourceWorld, File folder, World world, int id) { + DInstanceWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, World world, int id) { + this.plugin = plugin; + worlds = plugin.getDWorldCache(); + dPlayers = plugin.getDPlayerCache(); + this.resourceWorld = resourceWorld; this.folder = folder; this.world = world; @@ -124,7 +128,7 @@ public abstract class DInstanceWorld { */ public Collection getPlayers() { Collection players = new ArrayList<>(); - for (DInstancePlayer player : plugin.getDPlayers().getDInstancePlayers()) { + for (DInstancePlayer player : plugin.getDPlayerCache().getDInstancePlayers()) { if (player.getWorld().equals(world)) { players.add(player); } diff --git a/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java index 0db20ac3..dde4463d 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java @@ -38,15 +38,16 @@ import org.bukkit.WorldType; */ public class DResourceWorld { - DungeonsXL plugin = DungeonsXL.getInstance(); - DWorldCache worlds; + private DungeonsXL plugin; + private DWorldCache worlds; private File folder; private WorldConfig config; private SignData signData; - public DResourceWorld(DWorldCache worlds, String name) { - this.worlds = worlds; + public DResourceWorld(DungeonsXL plugin, String name) { + this.plugin = plugin; + worlds = plugin.getDWorldCache(); folder = new File(DungeonsXL.MAPS, name); if (!folder.exists()) { @@ -55,25 +56,26 @@ public class DResourceWorld { File configFile = new File(folder, "config.yml"); if (configFile.exists()) { - config = new WorldConfig(configFile); + config = new WorldConfig(plugin, configFile); } File signDataFile = new File(folder, "DXLData.data"); - signData = new SignData(signDataFile); + signData = new SignData(plugin, signDataFile); } - public DResourceWorld(DWorldCache worlds, File folder) { - this.worlds = worlds; + public DResourceWorld(DungeonsXL plugin, File folder) { + this.plugin = plugin; + worlds = plugin.getDWorldCache(); this.folder = folder; File configFile = new File(folder, "config.yml"); if (configFile.exists()) { - config = new WorldConfig(configFile); + config = new WorldConfig(plugin, configFile); } File signDataFile = new File(folder, "DXLData.data"); - signData = new SignData(signDataFile); + signData = new SignData(plugin, signDataFile); } /* Getters and setters */ @@ -120,7 +122,7 @@ public class DResourceWorld { exception.printStackTrace(); } } - config = new WorldConfig(file); + config = new WorldConfig(plugin, file); } return config; @@ -142,7 +144,7 @@ public class DResourceWorld { */ public void addInvitedPlayer(OfflinePlayer player) { if (config == null) { - config = new WorldConfig(); + config = new WorldConfig(plugin); } config.addInvitedPlayer(player.getUniqueId().toString()); @@ -218,7 +220,7 @@ public class DResourceWorld { } } - DInstanceWorld instance = game ? new DGameWorld(this, instanceFolder, id) : new DEditWorld(this, instanceFolder, id); + DInstanceWorld instance = game ? new DGameWorld(plugin, this, instanceFolder, id) : new DEditWorld(plugin, this, instanceFolder, id); FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES); instance.world = Bukkit.createWorld(WorldCreator.name(name).environment(getWorldEnvironment())); @@ -275,7 +277,7 @@ public class DResourceWorld { creator.type(WorldType.FLAT); creator.generateStructures(false); - final DEditWorld editWorld = new DEditWorld(this, folder, id); + final DEditWorld editWorld = new DEditWorld(plugin, this, folder, id); EditWorldGenerateEvent event = new EditWorldGenerateEvent(editWorld); Bukkit.getPluginManager().callEvent(event); diff --git a/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java b/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java index 264c0c52..c96e2f1e 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java @@ -38,8 +38,8 @@ import org.bukkit.scheduler.BukkitTask; */ public class DWorldCache { - DungeonsXL plugin = DungeonsXL.getInstance(); - MainConfig mainConfig = plugin.getMainConfig(); + private DungeonsXL plugin; + private MainConfig config; public static final File RAW = new File(DungeonsXL.MAPS, ".raw"); @@ -48,10 +48,16 @@ public class DWorldCache { private Set resources = new HashSet<>(); private Set instances = new HashSet<>(); - public DWorldCache(File folder) { + public DWorldCache(DungeonsXL plugin) { + this.plugin = plugin; + } + + public void init(File folder) { + config = plugin.getMainConfig(); + for (File file : folder.listFiles()) { if (file.isDirectory() && !file.getName().equals(".raw")) { - resources.add(new DResourceWorld(this, file)); + resources.add(new DResourceWorld(plugin, file)); } } @@ -60,7 +66,7 @@ public class DWorldCache { } startWorldUnloadTask(1200L); - Bukkit.getPluginManager().registerEvents(new DWorldListener(this), plugin); + Bukkit.getPluginManager().registerEvents(new DWorldListener(plugin), plugin); if (LWCUtil.isLWCLoaded()) { new LWCIntegration(plugin); } @@ -247,7 +253,7 @@ public class DWorldCache { * Clean up all instances. */ public void deleteAllInstances() { - BackupMode backupMode = mainConfig.getBackupMode(); + BackupMode backupMode = config.getBackupMode(); HashSet instances = new HashSet<>(this.instances); for (DInstanceWorld instance : instances) { if (backupMode == BackupMode.ON_DISABLE | backupMode == BackupMode.ON_DISABLE_AND_SAVE && instance instanceof DEditWorld) { @@ -325,7 +331,7 @@ public class DWorldCache { * @param period the period in ticks */ public void startWorldUnloadTask(long period) { - worldUnloadTask = new WorldUnloadTask().runTaskTimer(plugin, period, period); + worldUnloadTask = new WorldUnloadTask(plugin).runTaskTimer(plugin, period, period); } /* Util */ diff --git a/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java b/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java index 5da0dc4f..ca63df5c 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.world; import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.mob.ExMob; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.game.Game; import java.util.Set; import org.bukkit.block.Block; @@ -46,10 +47,12 @@ import org.bukkit.event.world.ChunkUnloadEvent; */ public class DWorldListener implements Listener { - DWorldCache dWorlds; + private CaliburnAPI caliburn; + private DWorldCache dWorlds; - public DWorldListener(DWorldCache dWorlds) { - this.dWorlds = dWorlds; + public DWorldListener(DungeonsXL plugin) { + caliburn = plugin.getCaliburn(); + dWorlds = plugin.getDWorldCache(); } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @@ -163,7 +166,7 @@ public class DWorldListener implements Listener { } Game game = Game.getByGameWorld(gameWorld); Set prot = interact ? game.getRules().getInteractionProtectedEntities() : game.getRules().getDamageProtectedEntities(); - if (prot.contains(CaliburnAPI.getInstance().getExMob(entity))) { + if (prot.contains(caliburn.getExMob(entity))) { event.setCancelled(true); } } diff --git a/src/main/java/de/erethon/dungeonsxl/world/LWCIntegration.java b/src/main/java/de/erethon/dungeonsxl/world/LWCIntegration.java index 532c60dd..2b73da8e 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/LWCIntegration.java +++ b/src/main/java/de/erethon/dungeonsxl/world/LWCIntegration.java @@ -26,7 +26,7 @@ import de.erethon.dungeonsxl.DungeonsXL; */ public class LWCIntegration extends JavaModule { - DungeonsXL plugin; + private DungeonsXL plugin; public LWCIntegration(DungeonsXL plugin) { this.plugin = plugin; @@ -35,7 +35,7 @@ public class LWCIntegration extends JavaModule { @Override public void onRegisterProtection(LWCProtectionRegisterEvent event) { - DInstanceWorld instance = plugin.getDWorlds().getInstanceByWorld(event.getBlock().getWorld()); + DInstanceWorld instance = plugin.getDWorldCache().getInstanceByWorld(event.getBlock().getWorld()); if (instance != null) { event.setCancelled(true); } diff --git a/src/main/java/de/erethon/dungeonsxl/world/SignData.java b/src/main/java/de/erethon/dungeonsxl/world/SignData.java index b0b043ec..51f79f1e 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/SignData.java +++ b/src/main/java/de/erethon/dungeonsxl/world/SignData.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.world; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.sign.DSign; import java.io.File; import java.io.FileInputStream; @@ -34,9 +35,13 @@ import org.bukkit.block.Sign; */ public class SignData { + private DungeonsXL plugin; + private File file; - public SignData(File file) { + public SignData(DungeonsXL plugin, File file) { + this.plugin = plugin; + if (!file.exists()) { try { file.createNewFile(); @@ -111,7 +116,7 @@ public class SignData { Block block = gameWorld.getWorld().getBlockAt(x, y, z); if (block.getState() instanceof Sign) { - DSign dSign = DSign.create((Sign) block.getState(), gameWorld); + DSign dSign = DSign.create(plugin, (Sign) block.getState(), gameWorld); gameWorld.getDSigns().add(dSign); } } diff --git a/src/main/java/de/erethon/dungeonsxl/world/WorldConfig.java b/src/main/java/de/erethon/dungeonsxl/world/WorldConfig.java index c615e1ae..c791432c 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/WorldConfig.java +++ b/src/main/java/de/erethon/dungeonsxl/world/WorldConfig.java @@ -48,8 +48,9 @@ import org.bukkit.configuration.file.YamlConfiguration; */ public class WorldConfig extends GameRuleProvider { - CaliburnAPI caliburn = CaliburnAPI.getInstance(); - CompatibilityHandler compat = CompatibilityHandler.getInstance(); + private DungeonsXL plugin; + private CaliburnAPI caliburn; + private CompatibilityHandler compat = CompatibilityHandler.getInstance(); private File file; @@ -57,16 +58,22 @@ public class WorldConfig extends GameRuleProvider { private GameType forcedGameType; private Environment worldEnvironment; - public WorldConfig() { + public WorldConfig(DungeonsXL plugin) { + this.plugin = plugin; + caliburn = plugin.getCaliburn(); } - public WorldConfig(File file) { + public WorldConfig(DungeonsXL plugin, File file) { + this(plugin); + this.file = file; FileConfiguration configFile = YamlConfiguration.loadConfiguration(file); load(configFile); } - public WorldConfig(ConfigurationSection configFile) { + public WorldConfig(DungeonsXL plugin, ConfigurationSection configFile) { + this(plugin); + load(configFile); } @@ -261,7 +268,7 @@ public class WorldConfig extends GameRuleProvider { ConfigurationSection requirementSection = configFile.getConfigurationSection("requirements"); for (String identifier : configFile.getConfigurationSection("requirements").getKeys(false)) { - Requirement requirement = Requirement.create(DungeonsXL.getInstance().getRequirementTypes().getByIdentifier(identifier)); + Requirement requirement = Requirement.create(plugin, plugin.getRequirementTypeCache().getByIdentifier(identifier)); requirement.setup(requirementSection); requirements.add(requirement); } @@ -292,7 +299,7 @@ public class WorldConfig extends GameRuleProvider { } if (configFile.contains("forcedGameType")) { - forcedGameType = DungeonsXL.getInstance().getGameTypes().getByName(configFile.getString("forcedGameType")); + forcedGameType = plugin.getGameTypeCache().getByName(configFile.getString("forcedGameType")); } if (configFile.contains("title.title")) { diff --git a/src/main/java/de/erethon/dungeonsxl/world/WorldUnloadTask.java b/src/main/java/de/erethon/dungeonsxl/world/WorldUnloadTask.java index fa2e2666..5c143e1a 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/WorldUnloadTask.java +++ b/src/main/java/de/erethon/dungeonsxl/world/WorldUnloadTask.java @@ -25,9 +25,15 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class WorldUnloadTask extends BukkitRunnable { + private DungeonsXL plugin; + + public WorldUnloadTask(DungeonsXL plugin) { + this.plugin = plugin; + } + @Override public void run() { - for (DGameWorld gameWorld : DungeonsXL.getInstance().getDWorlds().getGameWorlds()) { + for (DGameWorld gameWorld : plugin.getDWorldCache().getGameWorlds()) { if (gameWorld.exists()) { if (gameWorld.getWorld().getPlayers().isEmpty()) { if (DGamePlayer.getByWorld(gameWorld.getWorld()).isEmpty()) { @@ -37,7 +43,7 @@ public class WorldUnloadTask extends BukkitRunnable { } } - for (DEditWorld editWorld : DungeonsXL.getInstance().getDWorlds().getEditWorlds()) { + for (DEditWorld editWorld : plugin.getDWorldCache().getEditWorlds()) { if (editWorld.exists()) { if (editWorld.getWorld().getPlayers().isEmpty()) { editWorld.delete(true); diff --git a/src/main/java/de/erethon/dungeonsxl/world/WorldUpdateTask.java b/src/main/java/de/erethon/dungeonsxl/world/WorldUpdateTask.java index 9137d536..35545a62 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/WorldUpdateTask.java +++ b/src/main/java/de/erethon/dungeonsxl/world/WorldUpdateTask.java @@ -25,9 +25,15 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class WorldUpdateTask extends BukkitRunnable { + private DungeonsXL plugin; + + public WorldUpdateTask(DungeonsXL plugin) { + this.plugin = plugin; + } + @Override public void run() { - for (DGameWorld gameWorld : DungeonsXL.getInstance().getDWorlds().getGameWorlds()) { + for (DGameWorld gameWorld : plugin.getDWorldCache().getGameWorlds()) { gameWorld.update(); } } diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/GameBlock.java b/src/main/java/de/erethon/dungeonsxl/world/block/GameBlock.java index 726205b5..f6e9e467 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/GameBlock.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/GameBlock.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.world.block; +import de.erethon.dungeonsxl.DungeonsXL; import org.bukkit.block.Block; import org.bukkit.event.block.BlockBreakEvent; @@ -26,9 +27,12 @@ import org.bukkit.event.block.BlockBreakEvent; */ public abstract class GameBlock { + protected DungeonsXL plugin; + protected Block block; - public GameBlock(Block block) { + public GameBlock(DungeonsXL plugin, Block block) { + this.plugin = plugin; this.block = block; } diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/LockedDoor.java b/src/main/java/de/erethon/dungeonsxl/world/block/LockedDoor.java index 7cd37927..11d1484b 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/LockedDoor.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/LockedDoor.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.world.block; +import de.erethon.dungeonsxl.DungeonsXL; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; @@ -31,8 +32,8 @@ public class LockedDoor extends GameBlock implements MultiBlock { private Block attachedBlock; - public LockedDoor(Block block) { - super(block); + public LockedDoor(DungeonsXL plugin, Block block) { + super(plugin, block); attachedBlock = getAttachedBlock(); } diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/PlaceableBlock.java b/src/main/java/de/erethon/dungeonsxl/world/block/PlaceableBlock.java index b300ed59..1b794fd6 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/PlaceableBlock.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/PlaceableBlock.java @@ -16,8 +16,8 @@ */ package de.erethon.dungeonsxl.world.block; -import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.item.ExItem; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import java.util.HashSet; import java.util.Set; @@ -41,14 +41,14 @@ public class PlaceableBlock extends GameBlock { private boolean onEast = false; private boolean onWest = false; - public PlaceableBlock(Block block, String ids, String directions) { - super(block); + public PlaceableBlock(DungeonsXL plugin, Block block, String ids, String directions) { + super(plugin, block); // Split ids if (!ids.isEmpty()) { String[] splittedIds = ids.split(","); for (String id : splittedIds) { - ExItem item = CaliburnAPI.getInstance().getExItem(id); + ExItem item = plugin.getCaliburn().getExItem(id); if (item != null) { materials.add(item); } diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/ProtectedBlock.java b/src/main/java/de/erethon/dungeonsxl/world/block/ProtectedBlock.java index b348971c..82234f8e 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/ProtectedBlock.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/ProtectedBlock.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.world.block; +import de.erethon.dungeonsxl.DungeonsXL; import org.bukkit.block.Block; import org.bukkit.event.block.BlockBreakEvent; @@ -24,8 +25,8 @@ import org.bukkit.event.block.BlockBreakEvent; */ public class ProtectedBlock extends GameBlock { - public ProtectedBlock(Block block) { - super(block); + public ProtectedBlock(DungeonsXL plugin, Block block) { + super(plugin, block); } /* Actions */ diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java b/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java index 28079319..04ce18db 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java @@ -43,8 +43,6 @@ import org.bukkit.inventory.ItemStack; */ public class RewardChest extends GameBlock { - DungeonsXL plugin = DungeonsXL.getInstance(); - // Variables private boolean used = false; private Chest chest; @@ -52,8 +50,8 @@ public class RewardChest extends GameBlock { private int levelReward; private ItemStack[] itemReward; - public RewardChest(Block chest, double moneyReward, int levelReward, ItemStack[] itemReward) { - super(chest); + public RewardChest(DungeonsXL plugin, Block chest, double moneyReward, int levelReward, ItemStack[] itemReward) { + super(plugin, chest); if (!(chest.getState() instanceof Chest)) { return; @@ -169,19 +167,19 @@ public class RewardChest extends GameBlock { Game game = Game.getByDGroup(dGroup); if (game == null || game.getType() == GameTypeDefault.CUSTOM || game.getType().hasRewards()) { if (!hasMoneyReward) { - Reward reward = Reward.create(RewardTypeDefault.MONEY); + Reward reward = Reward.create(plugin, RewardTypeDefault.MONEY); ((MoneyReward) reward).addMoney(moneyReward); dGroup.addReward(reward); } if (!hasLevelReward) { - Reward reward = Reward.create(RewardTypeDefault.LEVEL); + Reward reward = Reward.create(plugin, RewardTypeDefault.LEVEL); ((LevelReward) reward).addLevels(levelReward); dGroup.addReward(reward); } if (!hasItemReward) { - Reward reward = Reward.create(RewardTypeDefault.ITEM); + Reward reward = Reward.create(plugin, RewardTypeDefault.ITEM); ((ItemReward) reward).addItems(itemReward); dGroup.addReward(reward); } diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/TeamBed.java b/src/main/java/de/erethon/dungeonsxl/world/block/TeamBed.java index 0a4cce43..d26a879e 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/TeamBed.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/TeamBed.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.world.block; import de.erethon.caliburn.category.Category; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGroup; @@ -35,8 +36,8 @@ public class TeamBed extends TeamBlock implements MultiBlock { private Block attachedBlock; - public TeamBed(Block block, DGroup owner) { - super(block, owner); + public TeamBed(DungeonsXL plugin, Block block, DGroup owner) { + super(plugin, block, owner); attachedBlock = getAttachedBlock(); } diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/TeamBlock.java b/src/main/java/de/erethon/dungeonsxl/world/block/TeamBlock.java index 350721b3..f6a2e2ff 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/TeamBlock.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/TeamBlock.java @@ -16,6 +16,7 @@ */ package de.erethon.dungeonsxl.world.block; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.player.DGroup; import org.bukkit.block.Block; @@ -26,8 +27,8 @@ public abstract class TeamBlock extends GameBlock { protected DGroup owner; - public TeamBlock(Block block, DGroup owner) { - super(block); + public TeamBlock(DungeonsXL plugin, Block block, DGroup owner) { + super(plugin, block); this.owner = owner; } diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java b/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java index f8f4d2f9..0eac5f69 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.world.block; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.compatibility.CompatibilityHandler; +import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGroup; @@ -33,8 +34,8 @@ import org.bukkit.event.block.BlockBreakEvent; */ public class TeamFlag extends TeamBlock { - public TeamFlag(Block block, DGroup owner) { - super(block, owner); + public TeamFlag(DungeonsXL plugin, Block block, DGroup owner) { + super(plugin, block, owner); reset(); }