Dependency injection

This commit is contained in:
Daniel Saukel 2018-08-18 16:52:51 +02:00
parent 4cf0c393cd
commit 9a9fee8deb
148 changed files with 1175 additions and 1075 deletions

View File

@ -23,15 +23,19 @@ import de.erethon.commons.config.MessageConfig;
import de.erethon.commons.javaplugin.DREPlugin; import de.erethon.commons.javaplugin.DREPlugin;
import de.erethon.commons.javaplugin.DREPluginSettings; import de.erethon.commons.javaplugin.DREPluginSettings;
import de.erethon.commons.misc.FileUtil; import de.erethon.commons.misc.FileUtil;
import de.erethon.dungeonsxl.announcer.Announcer;
import de.erethon.dungeonsxl.announcer.AnnouncerCache; 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.command.DCommandCache;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.config.GlobalData;
import de.erethon.dungeonsxl.config.MainConfig; import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.dungeon.DungeonCache; import de.erethon.dungeonsxl.dungeon.DungeonCache;
import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.game.Game;
import de.erethon.dungeonsxl.game.GameTypeCache; import de.erethon.dungeonsxl.game.GameTypeCache;
import de.erethon.dungeonsxl.global.GlobalData;
import de.erethon.dungeonsxl.global.GlobalProtectionCache; import de.erethon.dungeonsxl.global.GlobalProtectionCache;
import de.erethon.dungeonsxl.global.GlobalProtectionListener;
import de.erethon.dungeonsxl.mob.DMobListener; import de.erethon.dungeonsxl.mob.DMobListener;
import de.erethon.dungeonsxl.mob.DMobType; import de.erethon.dungeonsxl.mob.DMobType;
import de.erethon.dungeonsxl.mob.ExternalMobProviderCache; 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.DPermission;
import de.erethon.dungeonsxl.player.DPlayerCache; import de.erethon.dungeonsxl.player.DPlayerCache;
import de.erethon.dungeonsxl.requirement.RequirementTypeCache; import de.erethon.dungeonsxl.requirement.RequirementTypeCache;
import de.erethon.dungeonsxl.reward.RewardListener;
import de.erethon.dungeonsxl.reward.RewardTypeCache; import de.erethon.dungeonsxl.reward.RewardTypeCache;
import de.erethon.dungeonsxl.sign.DSignTypeCache; import de.erethon.dungeonsxl.sign.DSignTypeCache;
import de.erethon.dungeonsxl.sign.SignScriptCache; import de.erethon.dungeonsxl.sign.SignScriptCache;
import de.erethon.dungeonsxl.trigger.TriggerListener;
import de.erethon.dungeonsxl.trigger.TriggerTypeCache; import de.erethon.dungeonsxl.trigger.TriggerTypeCache;
import de.erethon.dungeonsxl.util.NoReload; import de.erethon.dungeonsxl.util.NoReload;
import de.erethon.dungeonsxl.world.DWorldCache; import de.erethon.dungeonsxl.world.DWorldCache;
@ -121,30 +127,23 @@ public class DungeonsXL extends DREPlugin {
public void onEnable() { public void onEnable() {
super.onEnable(); super.onEnable();
instance = this; instance = this;
DPermission.register();
initFolders(); initFolders();
loadCore(); loadCaliburnAPI();
DPermission.register();
loadConfig();
createCaches();
initCaches();
loadData(); loadData();
new NoReload(this); new NoReload(this);
} }
@Override @Override
public void onDisable() { public void onDisable() {
// Save
saveData(); saveData();
messageConfig.save(); messageConfig.save();
dGroups.clear(); dGroups.clear();
// Delete DWorlds
dWorlds.deleteAllInstances(); dWorlds.deleteAllInstances();
// Disable listeners
HandlerList.unregisterAll(this); HandlerList.unregisterAll(this);
// Stop shedulers
getServer().getScheduler().cancelTasks(this); getServer().getScheduler().cancelTasks(this);
} }
@ -210,31 +209,46 @@ public class DungeonsXL extends DREPlugin {
} }
} }
public void loadCore() { public void loadConfig() {
loadCaliburnAPI(); messageConfig = new MessageConfig(DMessage.class, new File(LANGUAGES, "english.yml"));
// Load Language globalData = new GlobalData(new File(getDataFolder(), "data.yml"));
loadMessageConfig(new File(LANGUAGES, "english.yml")); mainConfig = new MainConfig(this, new File(getDataFolder(), "config.yml"));
// Load Config messageConfig = new MessageConfig(DMessage.class, new File(LANGUAGES, mainConfig.getLanguage() + ".yml"));
loadGlobalData(new File(getDataFolder(), "data.yml")); }
loadMainConfig(new File(getDataFolder(), "config.yml"));
// Load Language 2 public void createCaches() {
loadMessageConfig(new File(LANGUAGES, mainConfig.getLanguage() + ".yml")); gameTypes = new GameTypeCache();
loadGameTypes(); requirementTypes = new RequirementTypeCache();
loadRequirementTypes(); rewardTypes = new RewardTypeCache();
loadRewardTypes(); triggers = new TriggerTypeCache();
loadTriggers(); dSigns = new DSignTypeCache(this);
loadDSigns(); dWorlds = new DWorldCache(this);
loadDWorlds(MAPS); dungeons = new DungeonCache(this);
loadDungeons(DUNGEONS); protections = new GlobalProtectionCache(this);
loadGlobalProtections(); dMobProviders = new ExternalMobProviderCache(this);
loadExternalMobProviders(); dPlayers = new DPlayerCache(this);
loadDPlayers(); announcers = new AnnouncerCache();
loadAnnouncers(ANNOUNCERS); dClasses = new DClassCache(this);
loadDClasses(CLASSES); signScripts = new SignScriptCache();
loadLootTables(LOOT_TABLES); dCommands = new DCommandCache(this);
loadMobs(MOBS); }
loadSignScripts(SIGNS);
loadDCommandCache(); 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 // Save and load
@ -264,11 +278,14 @@ public class DungeonsXL extends DREPlugin {
return caliburn; return caliburn;
} }
/**
* load / reload a new instance of CaliburnAPI if none exists
*/
private void loadCaliburnAPI() { private void loadCaliburnAPI() {
caliburn = CaliburnAPI.getInstance() == null ? new CaliburnAPI(this) : CaliburnAPI.getInstance(); 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; return globalData;
} }
/** @Override
* load / reload a new instance of GlobalData public DCommandCache getCommandCache() {
* return dCommands;
* @param file the file to load from
*/
public void loadGlobalData(File file) {
globalData = new GlobalData(file);
} }
/** /**
@ -294,268 +307,120 @@ public class DungeonsXL extends DREPlugin {
return mainConfig; 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 * @return the dSigns
*/ */
public DSignTypeCache getDSigns() { public DSignTypeCache getDSignCache() {
return dSigns; return dSigns;
} }
/**
* load / reload a new instance of DSignTypeCache
*/
public void loadDSigns() {
dSigns = new DSignTypeCache();
}
/** /**
* @return the game types * @return the game types
*/ */
public GameTypeCache getGameTypes() { public GameTypeCache getGameTypeCache() {
return gameTypes; return gameTypes;
} }
/**
* load / reload a new instance of GameTypeCache
*/
public void loadGameTypes() {
gameTypes = new GameTypeCache();
}
/** /**
* @return the requirement types * @return the requirement types
*/ */
public RequirementTypeCache getRequirementTypes() { public RequirementTypeCache getRequirementTypeCache() {
return requirementTypes; return requirementTypes;
} }
/**
* load / reload a new instance of RequirementTypeCache
*/
public void loadRequirementTypes() {
requirementTypes = new RequirementTypeCache();
}
/** /**
* @return the reward types * @return the reward types
*/ */
public RewardTypeCache getRewardTypes() { public RewardTypeCache getRewardTypeCache() {
return rewardTypes; return rewardTypes;
} }
/**
* load / reload a new instance of RewardTypeCache
*/
public void loadRewardTypes() {
rewardTypes = new RewardTypeCache();
}
/** /**
* @return the triggers * @return the triggers
*/ */
public TriggerTypeCache getTriggers() { public TriggerTypeCache getTriggerCache() {
return triggers; return triggers;
} }
/**
* load / reload a new instance of TriggerTypeCache
*/
public void loadTriggers() {
triggers = new TriggerTypeCache();
}
/** /**
* @return the loaded instance of DungeonCache * @return the loaded instance of DungeonCache
*/ */
public DungeonCache getDungeons() { public DungeonCache getDungeonCache() {
return dungeons; 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 * @return the loaded instance of GlobalProtectionCache
*/ */
public GlobalProtectionCache getGlobalProtections() { public GlobalProtectionCache getGlobalProtectionCache() {
return protections; return protections;
} }
/**
* load / reload a new instance of GlobalProtectionCache
*/
public void loadGlobalProtections() {
protections = new GlobalProtectionCache();
}
/** /**
* @return the loaded instance of ExternalMobProviderCache * @return the loaded instance of ExternalMobProviderCache
*/ */
public ExternalMobProviderCache getExternalMobProviders() { public ExternalMobProviderCache getExternalMobProviderCache() {
return dMobProviders; return dMobProviders;
} }
/**
* load / reload a new instance of ExternalMobProviderCache
*/
public void loadExternalMobProviders() {
dMobProviders = new ExternalMobProviderCache();
}
/** /**
* @return the loaded instance of DPlayerCache * @return the loaded instance of DPlayerCache
*/ */
public DPlayerCache getDPlayers() { public DPlayerCache getDPlayerCache() {
return dPlayers; return dPlayers;
} }
/**
* load / reload a new instance of DPlayerCache
*/
public void loadDPlayers() {
dPlayers = new DPlayerCache();
}
/** /**
* @return the loaded instance of AnnouncerCache * @return the loaded instance of AnnouncerCache
*/ */
public AnnouncerCache getAnnouncers() { public AnnouncerCache getAnnouncerCache() {
return announcers; return announcers;
} }
/** private void initAnnouncerCache(File file) {
* load / reload a new instance of AnnouncerCache if (file.isDirectory()) {
* for (File script : FileUtil.getFilesForFolder(file)) {
* @param folder the folder to load from announcers.addAnnouncer(new Announcer(this, script));
*/
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));
} }
} }
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 * @return the loaded instance of SignScriptCache
*/ */
public SignScriptCache getSignScripts() { public SignScriptCache getSignScriptCache() {
return signScripts; 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 * @return the loaded instance of DWorldCache
*/ */
public DWorldCache getDWorlds() { public DWorldCache getDWorldCache() {
return dWorlds; 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 * @return the games
*/ */
public List<Game> getGames() { public List<Game> getGameCache() {
return games; return games;
} }
/** /**
* @return the dGroups * @return the dGroups
*/ */
public List<DGroup> getDGroups() { public List<DGroup> getDGroupCache() {
return dGroups; return dGroups;
} }

View File

@ -51,7 +51,7 @@ import org.bukkit.material.Wool;
*/ */
public class Announcer { public class Announcer {
DungeonsXL plugin = DungeonsXL.getInstance(); private DungeonsXL plugin;
private String name; private String name;
@ -73,17 +73,21 @@ public class Announcer {
private AnnouncerStartGameTask startTask; private AnnouncerStartGameTask startTask;
/** /**
* @param file the script file * @param plugin the plugin instance
* @param file the script file
*/ */
public Announcer(File file) { public Announcer(DungeonsXL plugin, File file) {
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(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 name the name of the Announcer
* @param config the config that stores the information * @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; this.name = name;
description = config.getStringList("description"); description = config.getStringList("description");
@ -94,7 +98,7 @@ public class Announcer {
if (multiFloor) { if (multiFloor) {
dungeonName = identifier; dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getByName(identifier); Dungeon dungeon = plugin.getDungeonCache().getByName(identifier);
if (dungeon != null) { if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor().getName(); mapName = dungeon.getConfig().getStartFloor().getName();
} }
@ -128,7 +132,7 @@ public class Announcer {
if (multiFloor) { if (multiFloor) {
dungeonName = identifier; dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getByName(identifier); Dungeon dungeon = plugin.getDungeonCache().getByName(identifier);
if (dungeon != null) { if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor().getName(); mapName = dungeon.getConfig().getStartFloor().getName();
} }
@ -374,7 +378,7 @@ public class Announcer {
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.ANNOUNCER); DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.ANNOUNCER);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) { 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) { } else if (dGroup == null && pGroup != null) {
@ -391,7 +395,7 @@ public class Announcer {
if (areRequirementsFulfilled()) { if (areRequirementsFulfilled()) {
if (startTask == null) { if (startTask == null) {
startTask = new AnnouncerStartGameTask(this); startTask = new AnnouncerStartGameTask(plugin, this);
startTask.runTaskLater(plugin, 20 * 30L); startTask.runTaskLater(plugin, 20 * 30L);
} else { } else {
startTask.getProgressBar().addPlayer(player); startTask.getProgressBar().addPlayer(player);
@ -412,7 +416,7 @@ public class Announcer {
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
DGroup dGroup = dGroups.get(groupCount); DGroup dGroup = dGroups.get(groupCount);
if (!plugin.getDGroups().contains(dGroup)) { if (!plugin.getDGroupCache().contains(dGroup)) {
dGroups.set(groupCount, null); dGroups.set(groupCount, null);
} else if (dGroup != null) { } else if (dGroup != null) {

View File

@ -16,14 +16,11 @@
*/ */
package de.erethon.dungeonsxl.announcer; 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.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
/** /**
@ -33,22 +30,10 @@ import org.bukkit.scheduler.BukkitTask;
*/ */
public class AnnouncerCache { public class AnnouncerCache {
DungeonsXL plugin = DungeonsXL.getInstance();
private BukkitTask announcerTask; private BukkitTask announcerTask;
private List<Announcer> announcers = new ArrayList<>(); private List<Announcer> 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 * @param name the name
* @return the announcer that has the name * @return the announcer that has the name
@ -106,14 +91,10 @@ public class AnnouncerCache {
} }
/** /**
* start a new AnnouncerTask * @param announcerTask the AnnouncerTask to set
*
* @param period the period ticks
*/ */
public void startAnnouncerTask(long period) { public void setAnnouncerTask(BukkitTask announcerTask) {
if (!announcers.isEmpty()) { this.announcerTask = announcerTask;
announcerTask = new AnnouncerTask(this).runTaskTimer(plugin, period, period);
}
} }
} }

View File

@ -30,6 +30,12 @@ import org.bukkit.material.Wool;
*/ */
public class AnnouncerListener implements Listener { public class AnnouncerListener implements Listener {
private AnnouncerCache announcers;
public AnnouncerListener(DungeonsXL plugin) {
announcers = plugin.getAnnouncerCache();
}
@EventHandler @EventHandler
public void onButtonClick(InventoryClickEvent event) { public void onButtonClick(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player)) { if (!(event.getWhoClicked() instanceof Player)) {
@ -39,7 +45,7 @@ public class AnnouncerListener implements Listener {
Inventory gui = event.getInventory(); Inventory gui = event.getInventory();
ItemStack button = event.getCurrentItem(); 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) { if (announcer != null && button != null && button.getData() instanceof Wool) {
announcer.clickGroupButton(player, button); announcer.clickGroupButton(player, button);
} }

View File

@ -33,12 +33,15 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class AnnouncerStartGameTask extends BukkitRunnable { public class AnnouncerStartGameTask extends BukkitRunnable {
private DungeonsXL plugin;
private Announcer announcer; private Announcer announcer;
private ProgressBar bar; private ProgressBar bar;
public AnnouncerStartGameTask(Announcer announcer) { public AnnouncerStartGameTask(DungeonsXL plugin, Announcer announcer) {
this.announcer = announcer; this.plugin = plugin;
this.announcer = announcer;
HashSet<Player> players = new HashSet<>(); HashSet<Player> players = new HashSet<>();
for (DGroup dGroup : announcer.getDGroups()) { for (DGroup dGroup : announcer.getDGroups()) {
if (dGroup == null) { if (dGroup == null) {
@ -49,7 +52,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
} }
} }
bar = new ProgressBar(players, 30); 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) { if (game == null) {
DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(announcer.getMapName()); DResourceWorld resource = plugin.getDWorldCache().getResourceByName(announcer.getMapName());
if (resource == null) { if (resource == null) {
dGroup.sendMessage(DMessage.ERROR_NO_SUCH_MAP.getMessage(announcer.getMapName())); dGroup.sendMessage(DMessage.ERROR_NO_SUCH_MAP.getMessage(announcer.getMapName()));
cancel(); cancel();
@ -86,7 +89,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
cancel(); cancel();
return; return;
} }
game = new Game(dGroup, gameWorld); game = new Game(plugin, dGroup, gameWorld);
} else { } else {
game.getDGroups().add(dGroup); game.getDGroups().add(dGroup);
} }
@ -101,7 +104,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
} }
for (Player player : game.getPlayers()) { for (Player player : game.getPlayers()) {
new DGamePlayer(player, game.getWorld()); new DGamePlayer(plugin, player, game.getWorld());
} }
announcer.endStartTask(); announcer.endStartTask();

View File

@ -29,11 +29,15 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class AnnouncerTask extends BukkitRunnable { public class AnnouncerTask extends BukkitRunnable {
private DungeonsXL plugin;
private List<Announcer> announcers; private List<Announcer> announcers;
private int index; private int index;
public AnnouncerTask(AnnouncerCache announcers) { public AnnouncerTask(DungeonsXL plugin) {
this.announcers = announcers.getAnnouncers(); this.plugin = plugin;
this.announcers = plugin.getAnnouncerCache().getAnnouncers();
index = 0; index = 0;
} }
@ -42,7 +46,7 @@ public class AnnouncerTask extends BukkitRunnable {
Announcer announcer = announcers.get(index); Announcer announcer = announcers.get(index);
List<String> worlds = announcer.getWorlds(); List<String> worlds = announcer.getWorlds();
for (Player player : Bukkit.getOnlinePlayers()) { 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 (!(dPlayer instanceof DInstancePlayer) && dPlayer.isAnnouncerEnabled()) {
if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) { if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) {
announcer.send(player); announcer.send(player);

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGlobalPlayer; import de.erethon.dungeonsxl.player.DGlobalPlayer;
@ -28,9 +27,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class BreakCommand extends DRECommand { public class BreakCommand extends DCommand {
public BreakCommand() { public BreakCommand(DungeonsXL plugin) {
super(plugin);
setCommand("break"); setCommand("break");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);
@ -42,7 +42,7 @@ public class BreakCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
DGlobalPlayer dGlobalPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player);
if (dGlobalPlayer.isInBreakMode()) { if (dGlobalPlayer.isInBreakMode()) {
dGlobalPlayer.setInBreakMode(false); dGlobalPlayer.setInBreakMode(false);

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DEditPlayer; import de.erethon.dungeonsxl.player.DEditPlayer;
@ -30,9 +29,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Daniel Saukel * @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"); setCommand("chat");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);
@ -44,7 +44,7 @@ public class ChatCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) 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)) { if (DGroup.getByPlayer(player) == null && !(dPlayer instanceof DEditPlayer)) {
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage()); MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGlobalPlayer; import de.erethon.dungeonsxl.player.DGlobalPlayer;
@ -28,9 +27,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Daniel Saukel * @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"); setCommand("chatSpy");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);
@ -42,7 +42,7 @@ public class ChatSpyCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
dPlayer.setInChatSpyMode(!dPlayer.isInChatSpyMode()); dPlayer.setInChatSpyMode(!dPlayer.isInChatSpyMode());
MessageUtil.sendMessage(player, (dPlayer.isInChatSpyMode() ? DMessage.CMD_CHATSPY_START : DMessage.CMD_CHATSPY_STOPPED).getMessage()); MessageUtil.sendMessage(player, (dPlayer.isInChatSpyMode() ? DMessage.CMD_CHATSPY_START : DMessage.CMD_CHATSPY_STOPPED).getMessage());

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DEditPlayer; import de.erethon.dungeonsxl.player.DEditPlayer;
@ -33,11 +32,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
public class CreateCommand extends DRECommand { public class CreateCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public CreateCommand(DungeonsXL plugin) {
super(plugin);
public CreateCommand() {
setMinArgs(1); setMinArgs(1);
setMaxArgs(1); setMaxArgs(1);
setCommand("create"); setCommand("create");
@ -67,8 +65,8 @@ public class CreateCommand extends DRECommand {
MessageUtil.log(plugin, DMessage.LOG_GENERATE_NEW_WORLD.getMessage()); MessageUtil.log(plugin, DMessage.LOG_GENERATE_NEW_WORLD.getMessage());
// Create World // Create World
DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), name); DResourceWorld resource = new DResourceWorld(plugin, name);
plugin.getDWorlds().addResource(resource); instances.addResource(resource);
DEditWorld editWorld = resource.generate(); DEditWorld editWorld = resource.generate();
editWorld.save(); editWorld.save();
editWorld.delete(); editWorld.delete();
@ -89,15 +87,15 @@ public class CreateCommand extends DRECommand {
MessageUtil.log(plugin, DMessage.LOG_GENERATE_NEW_WORLD.getMessage()); MessageUtil.log(plugin, DMessage.LOG_GENERATE_NEW_WORLD.getMessage());
// Create World // Create World
DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), name); DResourceWorld resource = new DResourceWorld(plugin, name);
plugin.getDWorlds().addResource(resource); instances.addResource(resource);
DEditWorld editWorld = resource.generate(); DEditWorld editWorld = resource.generate();
// MSG Done // MSG Done
MessageUtil.log(plugin, DMessage.LOG_WORLD_GENERATION_FINISHED.getMessage()); MessageUtil.log(plugin, DMessage.LOG_WORLD_GENERATION_FINISHED.getMessage());
// Tp Player // Tp Player
new DEditPlayer(player, editWorld); new DEditPlayer(plugin, player, editWorld);
} }
} }

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -19,7 +19,6 @@ package de.erethon.dungeonsxl.command;
import de.erethon.commons.command.DRECommand; import de.erethon.commons.command.DRECommand;
import de.erethon.commons.command.DRECommandCache; import de.erethon.commons.command.DRECommandCache;
import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.CompatibilityHandler;
import de.erethon.commons.javaplugin.DREPlugin;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
/** /**
@ -29,72 +28,104 @@ import de.erethon.dungeonsxl.DungeonsXL;
*/ */
public class DCommandCache extends DRECommandCache { public class DCommandCache extends DRECommandCache {
public static BreakCommand BREAK = new BreakCommand(); public static final String LABEL = "dungeonsxl";
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 DCommandCache(DREPlugin plugin) { public BreakCommand breakCmd;
super("dungeonsxl", plugin, public ChatCommand chat;
BREAK, public ChatSpyCommand chatSpy;
CREATE, public CreateCommand create;
DELETE, public EditCommand edit;
DUNGEON_ITEM, public EnterCommand enter;
EDIT, public EscapeCommand escape;
ENTER, public DeleteCommand delete;
ESCAPE, public DungeonItemCommand dungeonItem;
GAME, public GameCommand game;
GROUP, public GroupCommand group;
HELP, public HelpCommand help;
IMPORT, public ImportCommand importCmd;
INVITE, public InviteCommand invite;
JOIN, public JoinCommand join;
KICK, public KickCommand kick;
LEAVE, public LeaveCommand leave;
LIST, public ListCommand list;
LIVES, public LivesCommand lives;
MAIN, public MainCommand main;
MESSAGE, public MsgCommand message;
PLAY, public PlayCommand play;
PORTAL, public PortalCommand portal;
RELOAD, public DRECommand reload;
RENAME, public RenameCommand rename;
RESOURCE_PACK, public ResourcePackCommand resourcePack;
SAVE, public SaveCommand save;
STATUS, public StatusCommand status;
TEST, public TestCommand test;
UNINVITE, public UninviteCommand uninvite;
new DeletePortalCommand()
); public DCommandCache(DungeonsXL plugin) {
if (DungeonsXL.getInstance().getMainConfig().isChatEnabled()) { super(LABEL, plugin);
addCommand(CHAT);
addCommand(CHAT_SPY); 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);
} }
} }

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.CompatibilityHandler;
import de.erethon.commons.misc.FileUtil; import de.erethon.commons.misc.FileUtil;
import de.erethon.dungeonsxl.DungeonsXL; 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.player.DPermission;
import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DEditWorld;
import de.erethon.dungeonsxl.world.DResourceWorld; import de.erethon.dungeonsxl.world.DResourceWorld;
import de.erethon.dungeonsxl.world.DWorldCache;
import java.io.File; import java.io.File;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
@ -35,9 +33,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class DeleteCommand extends DRECommand { public class DeleteCommand extends DCommand {
public DeleteCommand() { public DeleteCommand(DungeonsXL plugin) {
super(plugin);
setCommand("delete"); setCommand("delete");
setMinArgs(1); setMinArgs(1);
setMaxArgs(2); setMaxArgs(2);
@ -49,9 +48,7 @@ public class DeleteCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
DWorldCache dWorlds = DungeonsXL.getInstance().getDWorlds(); DResourceWorld resource = instances.getResourceByName(args[1]);
DResourceWorld resource = dWorlds.getResourceByName(args[1]);
if (resource == null) { if (resource == null) {
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1])); MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));
return; return;
@ -72,12 +69,12 @@ public class DeleteCommand extends DRECommand {
return; return;
} }
for (DEditWorld editWorld : dWorlds.getEditWorlds()) { for (DEditWorld editWorld : instances.getEditWorlds()) {
if (editWorld.getResource().equals(resource)) { if (editWorld.getResource().equals(resource)) {
editWorld.delete(false); editWorld.delete(false);
} }
} }
dWorlds.removeResource(resource); instances.removeResource(resource);
FileUtil.removeDir(resource.getFolder()); FileUtil.removeDir(resource.getFolder());
if (args[2].equalsIgnoreCase("true")) { if (args[2].equalsIgnoreCase("true")) {

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Material>) 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());
}
}
}

View File

@ -17,7 +17,7 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; 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.DMessage;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.util.NBTUtil; import de.erethon.dungeonsxl.util.NBTUtil;
@ -29,9 +29,10 @@ import org.bukkit.inventory.PlayerInventory;
/** /**
* @author Frank Baumann, Daniel Saukel * @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"); setCommand("dungeonItem");
setAliases("di"); setAliases("di");
setMinArgs(0); setMinArgs(0);

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DEditPlayer; 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.player.DPermission;
import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DEditWorld;
import de.erethon.dungeonsxl.world.DResourceWorld; import de.erethon.dungeonsxl.world.DResourceWorld;
import de.erethon.dungeonsxl.world.DWorldCache;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel * @author Frank Baumann, Milan Albrecht, Daniel Saukel
*/ */
public class EditCommand extends DRECommand { public class EditCommand extends DCommand {
DWorldCache worlds = DungeonsXL.getInstance().getDWorlds(); public EditCommand(DungeonsXL plugin) {
super(plugin);
public EditCommand() {
setCommand("edit"); setCommand("edit");
setMinArgs(1); setMinArgs(1);
setMaxArgs(1); setMaxArgs(1);
@ -51,12 +48,12 @@ public class EditCommand extends DRECommand {
Player player = (Player) sender; Player player = (Player) sender;
String mapName = args[1]; String mapName = args[1];
if (!worlds.exists(mapName)) { if (!instances.exists(mapName)) {
MessageUtil.sendMessage(player, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(mapName)); MessageUtil.sendMessage(player, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(mapName));
return; return;
} }
DResourceWorld resource = worlds.getResourceByName(mapName); DResourceWorld resource = instances.getResourceByName(mapName);
if (resource == null) { if (resource == null) {
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(mapName)); MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(mapName));
return; return;
@ -74,7 +71,7 @@ public class EditCommand extends DRECommand {
} }
DGroup dGroup = DGroup.getByPlayer(player); DGroup dGroup = DGroup.getByPlayer(player);
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
if (dPlayer instanceof DInstancePlayer) { if (dPlayer instanceof DInstancePlayer) {
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage()); MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
@ -86,7 +83,7 @@ public class EditCommand extends DRECommand {
return; return;
} }
new DEditPlayer(player, editWorld); new DEditPlayer(plugin, player, editWorld);
} }
} }

View File

@ -17,7 +17,7 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; 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.DMessage;
import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.game.Game;
import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGamePlayer;
@ -30,9 +30,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class EnterCommand extends DRECommand { public class EnterCommand extends DCommand {
public EnterCommand() { public EnterCommand(DungeonsXL plugin) {
super(plugin);
setMinArgs(1); setMinArgs(1);
setMaxArgs(2); setMaxArgs(2);
setCommand("enter"); setCommand("enter");
@ -73,7 +74,7 @@ public class EnterCommand extends DRECommand {
} }
if (joining == null) { 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)) { 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())); joining.sendMessage(DMessage.CMD_ENTER_SUCCESS.getMessage(joining.getName(), target.getName()));
for (Player player : joining.getPlayers().getOnlinePlayers()) { for (Player player : joining.getPlayers().getOnlinePlayers()) {
new DGamePlayer(player, game.getWorld(), game.getType()); new DGamePlayer(plugin, player, game.getWorld(), game.getType());
} }
} }

View File

@ -17,7 +17,7 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; 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.DMessage;
import de.erethon.dungeonsxl.player.DEditPlayer; import de.erethon.dungeonsxl.player.DEditPlayer;
import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGamePlayer;
@ -30,9 +30,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Milan Albrecht, Daniel Saukel * @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"); setCommand("escape");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);

View File

@ -17,7 +17,7 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; 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.DMessage;
import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.game.Game;
import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.player.DGroup;
@ -29,9 +29,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class GameCommand extends DRECommand { public class GameCommand extends DCommand {
public GameCommand() { public GameCommand(DungeonsXL plugin) {
super(plugin);
setCommand("game"); setCommand("game");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.event.dgroup.DGroupCreateEvent; import de.erethon.dungeonsxl.event.dgroup.DGroupCreateEvent;
@ -33,9 +32,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class GroupCommand extends DRECommand { public class GroupCommand extends DCommand {
public GroupCommand() { public GroupCommand(DungeonsXL plugin) {
super(plugin);
setCommand("group"); setCommand("group");
setMinArgs(0); setMinArgs(0);
setMaxArgs(2); setMaxArgs(2);
@ -122,7 +122,7 @@ public class GroupCommand extends DRECommand {
return; 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); DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@ -266,7 +266,7 @@ public class GroupCommand extends DRECommand {
} }
public void showHelp(String page) { public void showHelp(String page) {
MessageUtil.sendPluginTag(sender, DungeonsXL.getInstance()); MessageUtil.sendPluginTag(sender, plugin);
switch (page) { switch (page) {
default: default:
MessageUtil.sendCenteredMessage(sender, "&4&l[ &61-5 &4/ &67 &4| &61 &4&l]"); MessageUtil.sendCenteredMessage(sender, "&4&l[ &61-5 &4/ &67 &4| &61 &4&l]");

View File

@ -29,11 +29,10 @@ import org.bukkit.command.CommandSender;
/** /**
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
public class HelpCommand extends DRECommand { public class HelpCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public HelpCommand(DungeonsXL plugin) {
super(plugin);
public HelpCommand() {
setCommand("help"); setCommand("help");
setMinArgs(0); setMinArgs(0);
setMaxArgs(1); setMaxArgs(1);

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.commons.misc.FileUtil; import de.erethon.commons.misc.FileUtil;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
@ -32,11 +31,10 @@ import org.bukkit.command.CommandSender;
/** /**
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
public class ImportCommand extends DRECommand { public class ImportCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public ImportCommand(DungeonsXL plugin) {
super(plugin);
public ImportCommand() {
setMinArgs(1); setMinArgs(1);
setMaxArgs(1); setMaxArgs(1);
setCommand("import"); setCommand("import");
@ -71,12 +69,12 @@ public class ImportCommand extends DRECommand {
FileUtil.copyDir(source, target, "playerdata", "stats"); 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) { if (world.getEnvironment() != Environment.NORMAL) {
resource.getConfig(true).setWorldEnvironment(world.getEnvironment()); resource.getConfig(true).setWorldEnvironment(world.getEnvironment());
resource.getConfig().save(); resource.getConfig().save();
} }
plugin.getDWorlds().addResource(resource); instances.addResource(resource);
MessageUtil.sendMessage(sender, DMessage.CMD_IMPORT_SUCCESS.getMessage(args[1])); MessageUtil.sendMessage(sender, DMessage.CMD_IMPORT_SUCCESS.getMessage(args[1]));
} }

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
@ -29,9 +28,10 @@ import org.bukkit.command.CommandSender;
/** /**
* @author Frank Baumann, Daniel Saukel * @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); setMinArgs(2);
setMaxArgs(2); setMaxArgs(2);
setCommand("invite"); setCommand("invite");
@ -43,7 +43,7 @@ public class InviteCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { 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]); OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
if (resource != null) { if (resource != null) {

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.announcer.Announcer; import de.erethon.dungeonsxl.announcer.Announcer;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
@ -30,9 +29,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class JoinCommand extends DRECommand { public class JoinCommand extends DCommand {
public JoinCommand() { public JoinCommand(DungeonsXL plugin) {
super(plugin);
setCommand("join"); setCommand("join");
setMinArgs(1); setMinArgs(1);
setMaxArgs(1); setMaxArgs(1);
@ -43,13 +43,13 @@ public class JoinCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { 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) { if (player instanceof DInstancePlayer) {
MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GAME.getMessage()); MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GAME.getMessage());
return; return;
} }
Announcer announcer = DungeonsXL.getInstance().getAnnouncers().getByName(args[1]); Announcer announcer = plugin.getAnnouncerCache().getByName(args[1]);
if (announcer != null) { if (announcer != null) {
announcer.showGUI((Player) sender); announcer.showGUI((Player) sender);
} }

View File

@ -17,8 +17,7 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand; import de.erethon.dungeonsxl.DungeonsXL;
import static de.erethon.dungeonsxl.command.DCommandCache.LEAVE;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -28,9 +27,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Daniel Saukel * @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"); setCommand("kick");
setMinArgs(1); setMinArgs(1);
setMaxArgs(1); setMaxArgs(1);
@ -45,7 +45,7 @@ public class KickCommand extends DRECommand {
Player player = Bukkit.getPlayer(args[1]); Player player = Bukkit.getPlayer(args[1]);
if (player != null) { 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())); MessageUtil.sendMessage(sender, DMessage.CMD_KICK_SUCCESS.getMessage(player.getName()));
} else { } else {

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent; import de.erethon.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent;
@ -36,9 +35,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Daniel Saukel * @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"); setCommand("leave");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);
@ -50,7 +50,7 @@ public class LeaveCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
Game game = Game.getByPlayer(player); Game game = Game.getByPlayer(player);
if (game != null && game.isTutorial()) { if (game != null && game.isTutorial()) {

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
@ -36,12 +35,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class ListCommand extends DRECommand { public class ListCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public ListCommand(DungeonsXL plugin) {
DWorldCache worlds = plugin.getDWorlds(); super(plugin);
public ListCommand() {
setCommand("list"); setCommand("list");
setMinArgs(0); setMinArgs(0);
setMaxArgs(3); setMaxArgs(3);
@ -54,7 +51,7 @@ public class ListCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
ArrayList<String> dungeonList = new ArrayList<>(); ArrayList<String> dungeonList = new ArrayList<>();
for (Dungeon dungeon : plugin.getDungeons().getDungeons()) { for (Dungeon dungeon : plugin.getDungeonCache().getDungeons()) {
dungeonList.add(dungeon.getName()); dungeonList.add(dungeon.getName());
} }
ArrayList<String> mapList = new ArrayList<>(); ArrayList<String> mapList = new ArrayList<>();
@ -64,10 +61,10 @@ public class ListCommand extends DRECommand {
} }
} }
ArrayList<String> loadedList = new ArrayList<>(); ArrayList<String> loadedList = new ArrayList<>();
for (DEditWorld editWorld : worlds.getEditWorlds()) { for (DEditWorld editWorld : instances.getEditWorlds()) {
loadedList.add(editWorld.getWorld().getWorldFolder().getName() + " / " + editWorld.getName()); 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()); loadedList.add(gameWorld.getWorld().getWorldFolder().getName() + " / " + gameWorld.getName());
} }
ArrayList<String> toSend = new ArrayList<>(); ArrayList<String> toSend = new ArrayList<>();
@ -78,7 +75,7 @@ public class ListCommand extends DRECommand {
if (args.length >= 2) { if (args.length >= 2) {
if (args[1].equalsIgnoreCase("dungeons") || args[1].equalsIgnoreCase("d")) { if (args[1].equalsIgnoreCase("dungeons") || args[1].equalsIgnoreCase("d")) {
if (args.length >= 3) { if (args.length >= 3) {
Dungeon dungeon = plugin.getDungeons().getByName(args[2]); Dungeon dungeon = plugin.getDungeonCache().getByName(args[2]);
if (dungeon != null) { if (dungeon != null) {
MessageUtil.sendPluginTag(sender, plugin); MessageUtil.sendPluginTag(sender, plugin);
MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dungeon.getName() + " &4&l]"); MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dungeon.getName() + " &4&l]");
@ -133,7 +130,7 @@ public class ListCommand extends DRECommand {
for (String map : toSend) { for (String map : toSend) {
boolean invited = false; boolean invited = false;
if (sender instanceof Player) { if (sender instanceof Player) {
DResourceWorld resource = worlds.getResourceByName(map); DResourceWorld resource = instances.getResourceByName(map);
if (resource != null) { if (resource != null) {
invited = resource.isInvitedPlayer((Player) sender); invited = resource.isInvitedPlayer((Player) sender);
} }
@ -145,7 +142,7 @@ public class ListCommand extends DRECommand {
case 1: case 1:
MessageUtil.sendMessage(sender, "&4Dungeon&7 | &eMap count"); MessageUtil.sendMessage(sender, "&4Dungeon&7 | &eMap count");
for (String dungeon : toSend) { 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; int count = dungeonConfig.getFloors().size() + 2;
MessageUtil.sendMessage(sender, "&b" + dungeon + "&7 | &e" + count); MessageUtil.sendMessage(sender, "&b" + dungeon + "&7 | &e" + count);
} }

View File

@ -17,7 +17,7 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; 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.DMessage;
import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGamePlayer;
import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.player.DGroup;
@ -29,9 +29,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class LivesCommand extends DRECommand { public class LivesCommand extends DCommand {
public LivesCommand() { public LivesCommand(DungeonsXL plugin) {
super(plugin);
setCommand("lives"); setCommand("lives");
setMinArgs(0); setMinArgs(0);
setMaxArgs(1); setMaxArgs(1);

View File

@ -18,7 +18,6 @@ package de.erethon.dungeonsxl.command;
import static de.erethon.commons.chat.FatLetter.*; import static de.erethon.commons.chat.FatLetter.*;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.CompatibilityHandler;
import de.erethon.commons.compatibility.Internals; import de.erethon.commons.compatibility.Internals;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
@ -31,11 +30,10 @@ import org.bukkit.plugin.PluginManager;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class MainCommand extends DRECommand { public class MainCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public MainCommand(DungeonsXL plugin) {
super(plugin);
public MainCommand() {
setCommand("main"); setCommand("main");
setHelp(DMessage.HELP_CMD_MAIN.getMessage()); setHelp(DMessage.HELP_CMD_MAIN.getMessage());
setPermission(DPermission.MAIN.getNode()); setPermission(DPermission.MAIN.getNode());
@ -49,8 +47,8 @@ public class MainCommand extends DRECommand {
int maps = DungeonsXL.MAPS.listFiles().length; int maps = DungeonsXL.MAPS.listFiles().length;
int dungeons = DungeonsXL.DUNGEONS.listFiles().length; int dungeons = DungeonsXL.DUNGEONS.listFiles().length;
int loaded = plugin.getDWorlds().getEditWorlds().size() + plugin.getDWorlds().getGameWorlds().size(); int loaded = instances.getEditWorlds().size() + instances.getGameWorlds().size();
int players = plugin.getDPlayers().getDGamePlayers().size(); int players = dPlayers.getDGamePlayers().size();
Internals internals = CompatibilityHandler.getInstance().getInternals(); Internals internals = CompatibilityHandler.getInstance().getInternals();
String vault = ""; String vault = "";
if (plugins.getPlugin("Vault") != null) { if (plugins.getPlugin("Vault") != null) {

View File

@ -17,7 +17,7 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; 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.DMessage;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DEditWorld;
@ -29,9 +29,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Daniel Saukel * @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); setMinArgs(-1);
setMaxArgs(-1); setMaxArgs(-1);
setCommand("msg"); setCommand("msg");

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.dungeon.Dungeon; import de.erethon.dungeonsxl.dungeon.Dungeon;
@ -37,11 +36,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class PlayCommand extends DRECommand { public class PlayCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public PlayCommand(DungeonsXL plugin) {
super(plugin);
public PlayCommand() {
setCommand("play"); setCommand("play");
setMinArgs(1); setMinArgs(1);
setMaxArgs(1); setMaxArgs(1);
@ -54,17 +52,17 @@ public class PlayCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
if (dPlayer instanceof DInstancePlayer) { if (dPlayer instanceof DInstancePlayer) {
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage()); MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
return; return;
} }
Dungeon dungeon = plugin.getDungeons().getByName(args[1]); Dungeon dungeon = plugin.getDungeonCache().getByName(args[1]);
if (dungeon == null) { if (dungeon == null) {
DResourceWorld resource = plugin.getDWorlds().getResourceByName(args[1]); DResourceWorld resource = instances.getResourceByName(args[1]);
if (resource != null) { if (resource != null) {
dungeon = new Dungeon(resource); dungeon = new Dungeon(plugin, resource);
} else { } else {
MessageUtil.sendMessage(player, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(args[1])); MessageUtil.sendMessage(player, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(args[1]));
return; return;
@ -76,11 +74,11 @@ public class PlayCommand extends DRECommand {
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage()); MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage());
return; return;
} else if (dGroup == null) { } else if (dGroup == null) {
dGroup = new DGroup(player, dungeon); dGroup = new DGroup(plugin, player, dungeon);
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
plugin.getDGroups().remove(dGroup); plugin.getDGroupCache().remove(dGroup);
dGroup = null; dGroup = null;
} }
} }
@ -95,9 +93,9 @@ public class PlayCommand extends DRECommand {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage()); MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
return; return;
} }
new Game(dGroup, gameWorld); new Game(plugin, dGroup, gameWorld);
for (Player groupPlayer : dGroup.getPlayers().getOnlinePlayers()) { for (Player groupPlayer : dGroup.getPlayers().getOnlinePlayers()) {
new DGamePlayer(groupPlayer, dGroup.getGameWorld()); new DGamePlayer(plugin, groupPlayer, dGroup.getGameWorld());
} }
} }

View File

@ -20,7 +20,6 @@ import de.erethon.caliburn.CaliburnAPI;
import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.ExItem;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.global.DPortal; import de.erethon.dungeonsxl.global.DPortal;
@ -33,12 +32,12 @@ import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
public class PortalCommand extends DRECommand { public class PortalCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance();
CaliburnAPI caliburn = plugin.getCaliburn(); CaliburnAPI caliburn = plugin.getCaliburn();
public PortalCommand() { public PortalCommand(DungeonsXL plugin) {
super(plugin);
setCommand("portal"); setCommand("portal");
setMinArgs(0); setMinArgs(0);
setMaxArgs(1); setMaxArgs(1);
@ -50,7 +49,7 @@ public class PortalCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
DGlobalPlayer dGlobalPlayer = plugin.getDPlayers().getByPlayer(player); DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player);
if (dGlobalPlayer instanceof DGamePlayer) { if (dGlobalPlayer instanceof DGamePlayer) {
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage()); MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
@ -70,7 +69,7 @@ public class PortalCommand extends DRECommand {
DPortal dPortal = dGlobalPlayer.getPortal(); DPortal dPortal = dGlobalPlayer.getPortal();
if (dPortal == null) { 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); dGlobalPlayer.setCreatingPortal(dPortal);
dPortal.setWorld(player.getWorld()); dPortal.setWorld(player.getWorld());
dGlobalPlayer.setCachedItem(player.getItemInHand()); dGlobalPlayer.setCachedItem(player.getItemInHand());

View File

@ -18,7 +18,6 @@ package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.DefaultFontInfo; import de.erethon.commons.chat.DefaultFontInfo;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.CompatibilityHandler;
import de.erethon.commons.compatibility.Internals; import de.erethon.commons.compatibility.Internals;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
@ -37,11 +36,10 @@ import org.bukkit.plugin.PluginManager;
/** /**
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
public class ReloadCommand extends DRECommand { public class ReloadCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public ReloadCommand(DungeonsXL plugin) {
super(plugin);
public ReloadCommand() {
setCommand("reload"); setCommand("reload");
setMinArgs(0); setMinArgs(0);
setMaxArgs(1); setMaxArgs(1);
@ -53,8 +51,8 @@ public class ReloadCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
List<DInstancePlayer> dPlayers = plugin.getDPlayers().getDInstancePlayers(); List<DInstancePlayer> dPlayers = this.dPlayers.getDInstancePlayers();
if (!dPlayers.isEmpty() && args.length == 1 && CompatibilityHandler.getInstance().isSpigot() && sender instanceof Player) { if (!dPlayers.isEmpty() && args.length == 1 && sender instanceof Player) {
MessageUtil.sendMessage(sender, DMessage.CMD_RELOAD_PLAYERS.getMessage()); MessageUtil.sendMessage(sender, DMessage.CMD_RELOAD_PLAYERS.getMessage());
ClickEvent onClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl reload -force"); ClickEvent onClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl reload -force");
String message = DefaultFontInfo.center(DMessage.MISC_OKAY.getMessage()); String message = DefaultFontInfo.center(DMessage.MISC_OKAY.getMessage());
@ -78,8 +76,8 @@ public class ReloadCommand extends DRECommand {
int maps = DungeonsXL.MAPS.listFiles().length; int maps = DungeonsXL.MAPS.listFiles().length;
int dungeons = DungeonsXL.DUNGEONS.listFiles().length; int dungeons = DungeonsXL.DUNGEONS.listFiles().length;
int loaded = plugin.getDWorlds().getEditWorlds().size() + plugin.getDWorlds().getGameWorlds().size(); int loaded = instances.getEditWorlds().size() + instances.getGameWorlds().size();
int players = plugin.getDPlayers().getDGamePlayers().size(); int players = this.dPlayers.getDGamePlayers().size();
Internals internals = CompatibilityHandler.getInstance().getInternals(); Internals internals = CompatibilityHandler.getInstance().getInternals();
String vault = ""; String vault = "";
if (plugins.getPlugin("Vault") != null) { if (plugins.getPlugin("Vault") != null) {
@ -91,7 +89,9 @@ public class ReloadCommand extends DRECommand {
} }
plugin.onDisable(); plugin.onDisable();
plugin.loadCore(); plugin.initFolders();
plugin.createCaches();
plugin.initCaches();
plugin.loadData(); plugin.loadData();
MessageUtil.sendPluginTag(sender, plugin); MessageUtil.sendPluginTag(sender, plugin);

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.CompatibilityHandler;
import de.erethon.commons.compatibility.Internals; import de.erethon.commons.compatibility.Internals;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
@ -33,11 +32,10 @@ import org.bukkit.plugin.PluginManager;
/** /**
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
public class ReloadCommandNoSpigot extends DRECommand { public class ReloadCommandNoSpigot extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public ReloadCommandNoSpigot(DungeonsXL plugin) {
super(plugin);
public ReloadCommandNoSpigot() {
setCommand("reload"); setCommand("reload");
setMinArgs(0); setMinArgs(0);
setMaxArgs(1); setMaxArgs(1);
@ -49,7 +47,7 @@ public class ReloadCommandNoSpigot extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
List<DInstancePlayer> dPlayers = plugin.getDPlayers().getDInstancePlayers(); List<DInstancePlayer> dPlayers = this.dPlayers.getDInstancePlayers();
PluginManager plugins = Bukkit.getPluginManager(); PluginManager plugins = Bukkit.getPluginManager();
@ -65,8 +63,8 @@ public class ReloadCommandNoSpigot extends DRECommand {
int maps = DungeonsXL.MAPS.listFiles().length; int maps = DungeonsXL.MAPS.listFiles().length;
int dungeons = DungeonsXL.DUNGEONS.listFiles().length; int dungeons = DungeonsXL.DUNGEONS.listFiles().length;
int loaded = plugin.getDWorlds().getEditWorlds().size() + plugin.getDWorlds().getGameWorlds().size(); int loaded = instances.getEditWorlds().size() + instances.getGameWorlds().size();
int players = plugin.getDPlayers().getDGamePlayers().size(); int players = this.dPlayers.getDGamePlayers().size();
Internals internals = CompatibilityHandler.getInstance().getInternals(); Internals internals = CompatibilityHandler.getInstance().getInternals();
String vault = ""; String vault = "";
if (plugins.getPlugin("Vault") != null) { if (plugins.getPlugin("Vault") != null) {
@ -78,7 +76,9 @@ public class ReloadCommandNoSpigot extends DRECommand {
} }
plugin.onDisable(); plugin.onDisable();
plugin.loadCore(); plugin.initFolders();
plugin.createCaches();
plugin.initCaches();
plugin.loadData(); plugin.loadData();
MessageUtil.sendPluginTag(sender, plugin); MessageUtil.sendPluginTag(sender, plugin);

View File

@ -17,14 +17,11 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.dungeon.Dungeon; import de.erethon.dungeonsxl.dungeon.Dungeon;
import de.erethon.dungeonsxl.dungeon.DungeonConfig; import de.erethon.dungeonsxl.dungeon.DungeonConfig;
import de.erethon.dungeonsxl.global.GameSign;
import de.erethon.dungeonsxl.global.GlobalProtection; import de.erethon.dungeonsxl.global.GlobalProtection;
import de.erethon.dungeonsxl.global.GroupSign;
import de.erethon.dungeonsxl.global.JoinSign; import de.erethon.dungeonsxl.global.JoinSign;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DEditWorld;
@ -38,11 +35,10 @@ import org.bukkit.configuration.file.FileConfiguration;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class RenameCommand extends DRECommand { public class RenameCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); public RenameCommand(DungeonsXL plugin) {
super(plugin);
public RenameCommand() {
setCommand("rename"); setCommand("rename");
setMinArgs(2); setMinArgs(2);
setMaxArgs(2); setMaxArgs(2);
@ -54,7 +50,7 @@ public class RenameCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
DResourceWorld resource = plugin.getDWorlds().getResourceByName(args[1]); DResourceWorld resource = instances.getResourceByName(args[1]);
if (resource == null) { if (resource == null) {
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1])); MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));
return; return;
@ -64,13 +60,13 @@ public class RenameCommand extends DRECommand {
resource.getFolder().renameTo(new File(DungeonsXL.MAPS, args[2])); resource.getFolder().renameTo(new File(DungeonsXL.MAPS, args[2]));
resource.getSignData().updateFile(resource); resource.getSignData().updateFile(resource);
for (DEditWorld editWorld : plugin.getDWorlds().getEditWorlds()) { for (DEditWorld editWorld : instances.getEditWorlds()) {
if (editWorld.getResource() == resource) { if (editWorld.getResource() == resource) {
editWorld.delete(true); editWorld.delete(true);
} }
} }
for (Dungeon dungeon : plugin.getDungeons().getDungeons()) { for (Dungeon dungeon : plugin.getDungeonCache().getDungeons()) {
DungeonConfig dConfig = dungeon.getConfig(); DungeonConfig dConfig = dungeon.getConfig();
FileConfiguration config = dConfig.getConfig(); FileConfiguration config = dConfig.getConfig();
File file = dConfig.getFile(); File file = dConfig.getFile();
@ -100,7 +96,7 @@ public class RenameCommand extends DRECommand {
} }
boolean changed = false; 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)) { if (!(protection instanceof JoinSign)) {
continue; continue;
} }
@ -116,7 +112,7 @@ public class RenameCommand extends DRECommand {
} }
if (changed) { if (changed) {
plugin.getGlobalProtections().saveAll(); plugin.getGlobalProtectionCache().saveAll();
} }
MessageUtil.sendMessage(sender, DMessage.CMD_RENAME_SUCCESS.getMessage(args[1], args[2])); MessageUtil.sendMessage(sender, DMessage.CMD_RENAME_SUCCESS.getMessage(args[1], args[2]));

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
@ -27,9 +26,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class ResourcePackCommand extends DRECommand { public class ResourcePackCommand extends DCommand {
public ResourcePackCommand() { public ResourcePackCommand(DungeonsXL plugin) {
super(plugin);
setCommand("resourcepack"); setCommand("resourcepack");
setMinArgs(1); setMinArgs(1);
setMaxArgs(1); setMaxArgs(1);
@ -48,7 +48,7 @@ public class ResourcePackCommand extends DRECommand {
return; return;
} }
String url = (String) DungeonsXL.getInstance().getMainConfig().getResourcePacks().get(args[1]); String url = (String) config.getResourcePacks().get(args[1]);
if (url == null) { if (url == null) {
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_RESOURCE_PACK.getMessage(args[1])); MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_RESOURCE_PACK.getMessage(args[1]));
return; return;

View File

@ -17,10 +17,8 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.config.MainConfig.BackupMode; import de.erethon.dungeonsxl.config.MainConfig.BackupMode;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DEditWorld;
@ -30,11 +28,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
public class SaveCommand extends DRECommand { public class SaveCommand extends DCommand {
MainConfig mainConfig = DungeonsXL.getInstance().getMainConfig(); public SaveCommand(DungeonsXL plugin) {
super(plugin);
public SaveCommand() {
setCommand("save"); setCommand("save");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);
@ -48,7 +45,7 @@ public class SaveCommand extends DRECommand {
Player player = (Player) sender; Player player = (Player) sender;
DEditWorld editWorld = DEditWorld.getByWorld(player.getWorld()); DEditWorld editWorld = DEditWorld.getByWorld(player.getWorld());
if (editWorld != null) { if (editWorld != null) {
BackupMode backupMode = mainConfig.getBackupMode(); BackupMode backupMode = config.getBackupMode();
if (backupMode == BackupMode.ON_SAVE || backupMode == BackupMode.ON_DISABLE_AND_SAVE) { if (backupMode == BackupMode.ON_SAVE || backupMode == BackupMode.ON_DISABLE_AND_SAVE) {
editWorld.getResource().backup(); editWorld.getResource().backup();
} }

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.CompatibilityHandler;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
@ -31,16 +30,16 @@ import org.bukkit.plugin.PluginManager;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class StatusCommand extends DRECommand { public class StatusCommand extends DCommand {
DungeonsXL plugin = DungeonsXL.getInstance(); private CompatibilityHandler compat = CompatibilityHandler.getInstance();
CompatibilityHandler compat = CompatibilityHandler.getInstance(); private PluginManager manager = Bukkit.getPluginManager();
PluginManager manager = Bukkit.getPluginManager();
public static final String TRUE = ChatColor.GREEN + "\u2714"; public static final String TRUE = ChatColor.GREEN + "\u2714";
public static final String FALSE = ChatColor.DARK_RED + "\u2718"; public static final String FALSE = ChatColor.DARK_RED + "\u2718";
public StatusCommand() { public StatusCommand(DungeonsXL plugin) {
super(plugin);
setCommand("status"); setCommand("status");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.dungeon.Dungeon; import de.erethon.dungeonsxl.dungeon.Dungeon;
@ -36,9 +35,10 @@ import org.bukkit.entity.Player;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
*/ */
public class TestCommand extends DRECommand { public class TestCommand extends DCommand {
public TestCommand() { public TestCommand(DungeonsXL plugin) {
super(plugin);
setCommand("test"); setCommand("test");
setMinArgs(0); setMinArgs(0);
setMaxArgs(0); setMaxArgs(0);
@ -51,7 +51,7 @@ public class TestCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
if (!(dPlayer instanceof DEditPlayer)) { if (!(dPlayer instanceof DEditPlayer)) {
DGroup dGroup = DGroup.getByPlayer(player); DGroup dGroup = DGroup.getByPlayer(player);
@ -85,14 +85,14 @@ public class TestCommand extends DRECommand {
DEditPlayer editPlayer = (DEditPlayer) dPlayer; DEditPlayer editPlayer = (DEditPlayer) dPlayer;
editPlayer.leave(); editPlayer.leave();
DResourceWorld resource = editPlayer.getEditWorld().getResource(); DResourceWorld resource = editPlayer.getEditWorld().getResource();
Dungeon dungeon = new Dungeon(resource); Dungeon dungeon = new Dungeon(plugin, resource);
DGameWorld instance = resource.instantiateAsGameWorld(false); DGameWorld instance = resource.instantiateAsGameWorld(false);
if (instance == null) { if (instance == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage()); MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
return; return;
} }
Game game = new Game(new DGroup(player, dungeon), GameTypeDefault.TEST, instance); Game game = new Game(plugin, new DGroup(plugin, player, dungeon), GameTypeDefault.TEST, instance);
new DGamePlayer(player, game.getWorld(), GameTypeDefault.TEST); new DGamePlayer(plugin, player, game.getWorld(), GameTypeDefault.TEST);
} }
} }

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.command; package de.erethon.dungeonsxl.command;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
@ -29,9 +28,10 @@ import org.bukkit.command.CommandSender;
/** /**
* @author Frank Baumann, Daniel Saukel * @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"); setCommand("uninvite");
setMinArgs(2); setMinArgs(2);
setMaxArgs(2); setMaxArgs(2);
@ -43,7 +43,7 @@ public class UninviteCommand extends DRECommand {
@Override @Override
public void onExecute(String[] args, CommandSender sender) { public void onExecute(String[] args, CommandSender sender) {
DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(args[2]); DResourceWorld resource = instances.getResourceByName(args[2]);
if (resource == null) { if (resource == null) {
MessageUtil.sendMessage(sender, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(args[2])); MessageUtil.sendMessage(sender, DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage(args[2]));
return; return;

View File

@ -39,6 +39,8 @@ import org.bukkit.configuration.ConfigurationSection;
*/ */
public class MainConfig extends DREConfig { public class MainConfig extends DREConfig {
private DungeonsXL plugin;
public enum BackupMode { public enum BackupMode {
ON_DISABLE, ON_DISABLE,
ON_DISABLE_AND_SAVE, ON_DISABLE_AND_SAVE,
@ -108,9 +110,11 @@ public class MainConfig extends DREConfig {
/* Default Dungeon Settings */ /* Default Dungeon Settings */
private WorldConfig defaultWorldConfig; private WorldConfig defaultWorldConfig;
public MainConfig(File file) { public MainConfig(DungeonsXL plugin, File file) {
super(file, CONFIG_VERSION); super(file, CONFIG_VERSION);
this.plugin = plugin;
if (initialize) { if (initialize) {
initialize(); initialize();
} }
@ -234,7 +238,7 @@ public class MainConfig extends DREConfig {
*/ */
public Dungeon getTutorialDungeon() { public Dungeon getTutorialDungeon() {
if (tutorialDungeon == null) { if (tutorialDungeon == null) {
tutorialDungeon = DungeonsXL.getInstance().getDungeons().getByName(tutorialDungeonName, true); tutorialDungeon = plugin.getDungeonCache().getByName(tutorialDungeonName, true);
} }
return tutorialDungeon; return tutorialDungeon;
} }
@ -695,7 +699,7 @@ public class MainConfig extends DREConfig {
/* Default Dungeon Config */ /* Default Dungeon Config */
ConfigurationSection configSection = config.getConfigurationSection("default"); ConfigurationSection configSection = config.getConfigurationSection("default");
if (configSection != null) { if (configSection != null) {
defaultWorldConfig = new WorldConfig(configSection); defaultWorldConfig = new WorldConfig(plugin, configSection);
} }
} }

View File

@ -31,6 +31,8 @@ import java.util.List;
*/ */
public class Dungeon { public class Dungeon {
private DungeonsXL plugin;
private String name; private String name;
private DungeonConfig config; private DungeonConfig config;
private DResourceWorld map; private DResourceWorld map;
@ -38,20 +40,26 @@ public class Dungeon {
/** /**
* Real 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", ""); name = file.getName().replaceAll(".yml", "");
config = new DungeonConfig(file); config = new DungeonConfig(plugin, file);
map = config.getStartFloor(); map = config.getStartFloor();
} }
/** /**
* Artificial dungeon * Artificial dungeon
* *
* @param plugin the plugin instance
* @param resource the only resource world * @param resource the only resource world
*/ */
public Dungeon(DResourceWorld resource) { public Dungeon(DungeonsXL plugin, DResourceWorld resource) {
this.plugin = plugin;
name = resource.getName(); name = resource.getName();
map = resource; map = resource;
} }
@ -113,7 +121,7 @@ public class Dungeon {
* @return false if there are setup errors * @return false if there are setup errors
*/ */
public boolean isSetupCorrect() { public boolean isSetupCorrect() {
for (DResourceWorld resource : DungeonsXL.getInstance().getDWorlds().getResources()) { for (DResourceWorld resource : plugin.getDWorldCache().getResources()) {
if (resource.getName().equals(name)) { if (resource.getName().equals(name)) {
return false; return false;
} }

View File

@ -31,17 +31,21 @@ import java.util.List;
*/ */
public class DungeonCache { public class DungeonCache {
DungeonsXL plugin = DungeonsXL.getInstance(); private DungeonsXL plugin;
private List<Dungeon> dungeons = new ArrayList<>(); private List<Dungeon> dungeons = new ArrayList<>();
public DungeonCache(File folder) { public DungeonCache(DungeonsXL plugin) {
this.plugin = plugin;
}
public void init(File folder) {
if (!folder.exists()) { if (!folder.exists()) {
folder.mkdir(); folder.mkdir();
} }
for (File file : folder.listFiles()) { for (File file : folder.listFiles()) {
Dungeon dungeon = new Dungeon(file); Dungeon dungeon = new Dungeon(plugin, file);
if (dungeon.isSetupCorrect()) { if (dungeon.isSetupCorrect()) {
dungeons.add(dungeon); dungeons.add(dungeon);
@ -73,9 +77,9 @@ public class DungeonCache {
} }
if (artificial) { if (artificial) {
DResourceWorld resource = plugin.getDWorlds().getResourceByName(name); DResourceWorld resource = plugin.getDWorldCache().getResourceByName(name);
if (resource != null) { 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 * @return the Dungeon that has the name
*/ */
public Dungeon loadDungeon(String name) { public Dungeon loadDungeon(String name) {
Dungeon dungeon = new Dungeon(Dungeon.getFileFromName(name)); Dungeon dungeon = new Dungeon(plugin, Dungeon.getFileFromName(name));
dungeons.add(dungeon); dungeons.add(dungeon);
return dungeon; return dungeon;
} }

View File

@ -19,7 +19,6 @@ package de.erethon.dungeonsxl.dungeon;
import de.erethon.commons.config.DREConfig; import de.erethon.commons.config.DREConfig;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.world.DResourceWorld; import de.erethon.dungeonsxl.world.DResourceWorld;
import de.erethon.dungeonsxl.world.DWorldCache;
import de.erethon.dungeonsxl.world.WorldConfig; import de.erethon.dungeonsxl.world.WorldConfig;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,7 +31,7 @@ import java.util.List;
*/ */
public class DungeonConfig extends DREConfig { public class DungeonConfig extends DREConfig {
DWorldCache worlds = DungeonsXL.getInstance().getDWorlds(); private DungeonsXL plugin;
public static final int CONFIG_VERSION = 1; public static final int CONFIG_VERSION = 1;
@ -44,9 +43,11 @@ public class DungeonConfig extends DREConfig {
private WorldConfig overrideValues; private WorldConfig overrideValues;
private WorldConfig defaultValues; private WorldConfig defaultValues;
public DungeonConfig(File file) { public DungeonConfig(DungeonsXL plugin, File file) {
super(file, CONFIG_VERSION); super(file, CONFIG_VERSION);
this.plugin = plugin;
if (initialize) { if (initialize) {
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. * @return true if the floor is either in the list or the start / end floor.
*/ */
public boolean containsFloor(String mapName) { public boolean containsFloor(String mapName) {
return containsFloor(worlds.getResourceByName(mapName)); return containsFloor(plugin.getDWorldCache().getResourceByName(mapName));
} }
@Override @Override
public void load() { public void load() {
if (config.contains("floors")) { if (config.contains("floors")) {
for (String floor : config.getStringList("floors")) { for (String floor : config.getStringList("floors")) {
DResourceWorld resource = worlds.getResourceByName(floor); DResourceWorld resource = plugin.getDWorldCache().getResourceByName(floor);
if (resource != null) { if (resource != null) {
floors.add(resource); floors.add(resource);
} }
@ -191,11 +192,11 @@ public class DungeonConfig extends DREConfig {
} }
if (config.contains("startFloor")) { if (config.contains("startFloor")) {
startFloor = worlds.getResourceByName(config.getString("startFloor")); startFloor = plugin.getDWorldCache().getResourceByName(config.getString("startFloor"));
} }
if (config.contains("endFloor")) { if (config.contains("endFloor")) {
endFloor = worlds.getResourceByName(config.getString("endFloor")); endFloor = plugin.getDWorldCache().getResourceByName(config.getString("endFloor"));
} }
if (config.contains("floorCount")) { if (config.contains("floorCount")) {
@ -207,11 +208,11 @@ public class DungeonConfig extends DREConfig {
} }
if (config.contains("overrideValues")) { if (config.contains("overrideValues")) {
overrideValues = new WorldConfig(config.getConfigurationSection("overrideValues")); overrideValues = new WorldConfig(plugin, config.getConfigurationSection("overrideValues"));
} }
if (config.contains("defaultValues")) { if (config.contains("defaultValues")) {
defaultValues = new WorldConfig(config.getConfigurationSection("defaultValues")); defaultValues = new WorldConfig(plugin, config.getConfigurationSection("defaultValues"));
} }
} }

View File

@ -47,7 +47,7 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class Game { public class Game {
DungeonsXL plugin = DungeonsXL.getInstance(); private DungeonsXL plugin;
private boolean tutorial; private boolean tutorial;
private List<DGroup> dGroups = new ArrayList<>(); private List<DGroup> dGroups = new ArrayList<>();
@ -59,8 +59,9 @@ public class Game {
private Map<String, Integer> gameKills = new HashMap<>(); private Map<String, Integer> gameKills = new HashMap<>();
private Map<String, Integer> waveKills = new HashMap<>(); private Map<String, Integer> waveKills = new HashMap<>();
public Game(DGroup dGroup) { public Game(DungeonsXL plugin, DGroup dGroup) {
DungeonsXL.getInstance().getGames().add(this); this.plugin = plugin;
plugin.getGameCache().add(this);
tutorial = false; tutorial = false;
started = false; started = false;
@ -73,8 +74,9 @@ public class Game {
dGroup.setScore(rules.getInitialScore()); dGroup.setScore(rules.getInitialScore());
} }
public Game(DGroup dGroup, DGameWorld world) { public Game(DungeonsXL plugin, DGroup dGroup, DGameWorld world) {
plugin.getGames().add(this); this.plugin = plugin;
plugin.getGameCache().add(this);
tutorial = false; tutorial = false;
started = false; started = false;
@ -88,12 +90,13 @@ public class Game {
dGroup.setScore(rules.getInitialScore()); dGroup.setScore(rules.getInitialScore());
} }
public Game(DGroup dGroup, GameType type, DGameWorld world) { public Game(DungeonsXL plugin, DGroup dGroup, GameType type, DGameWorld world) {
this(new ArrayList<>(Arrays.asList(dGroup)), type, world); this(plugin, new ArrayList<>(Arrays.asList(dGroup)), type, world);
} }
public Game(List<DGroup> dGroups, GameType type, DGameWorld world) { public Game(DungeonsXL plugin, List<DGroup> dGroups, GameType type, DGameWorld world) {
plugin.getGames().add(this); this.plugin = plugin;
plugin.getGameCache().add(this);
this.dGroups = dGroups; this.dGroups = dGroups;
this.type = type; this.type = type;
@ -368,9 +371,9 @@ public class Game {
* Remove the Game from the List * Remove the Game from the List
*/ */
public void delete() { 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) { if (gameSign != null) {
gameSign.update(); gameSign.update();
@ -431,7 +434,7 @@ public class Game {
/* Statics */ /* Statics */
public static Game getByDGroup(DGroup dGroup) { public static Game getByDGroup(DGroup dGroup) {
for (Game game : DungeonsXL.getInstance().getGames()) { for (Game game : DungeonsXL.getInstance().getGameCache()) {
if (game.getDGroups().contains(dGroup)) { if (game.getDGroups().contains(dGroup)) {
return game; return game;
} }
@ -445,7 +448,7 @@ public class Game {
} }
public static Game getByGameWorld(DGameWorld gameWorld) { public static Game getByGameWorld(DGameWorld gameWorld) {
for (Game game : DungeonsXL.getInstance().getGames()) { for (Game game : DungeonsXL.getInstance().getGameCache()) {
if (gameWorld.equals(game.getWorld())) { if (gameWorld.equals(game.getWorld())) {
return game; return game;
} }

View File

@ -52,19 +52,19 @@ public class DPortal extends GlobalProtection {
private boolean active; private boolean active;
private Set<Block> blocks; private Set<Block> blocks;
public DPortal(int id, World world, boolean active) { public DPortal(DungeonsXL plugin, int id, World world, boolean active) {
this(id, world, VanillaItem.NETHER_PORTAL, active); this(plugin, id, world, VanillaItem.NETHER_PORTAL, active);
} }
public DPortal(int id, World world, ExItem material, boolean active) { public DPortal(DungeonsXL plugin, int id, World world, ExItem material, boolean active) {
super(world, id); super(plugin, world, id);
this.material = material; this.material = material;
this.active = active; this.active = active;
} }
public DPortal(int id, Block block1, Block block2, ExItem material, byte axis, boolean active) { public DPortal(DungeonsXL plugin, int id, Block block1, Block block2, ExItem material, byte axis, boolean active) {
super(block1.getWorld(), id); super(plugin, block1.getWorld(), id);
this.block1 = block1; this.block1 = block1;
this.block2 = block2; this.block2 = block2;
@ -233,14 +233,14 @@ public class DPortal extends GlobalProtection {
} }
if (game == null) { if (game == null) {
game = new Game(dGroup, target); game = new Game(plugin, dGroup, target);
} else { } else {
game.setWorld(target); game.setWorld(target);
dGroup.setGameWorld(target); dGroup.setGameWorld(target);
} }
new DGamePlayer(player, target); new DGamePlayer(plugin, player, target);
} }
@Override @Override
@ -332,19 +332,21 @@ public class DPortal extends GlobalProtection {
/* Statics */ /* Statics */
/** /**
* @param plugin the plugin instance
* @param location a location covered by the returned portal * @param location a location covered by the returned portal
* @return the portal at the location, null if there is none * @return the portal at the location, null if there is none
*/ */
public static DPortal getByLocation(Location location) { public static DPortal getByLocation(DungeonsXL plugin, Location location) {
return getByBlock(location.getBlock()); 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 * @return the portal that the block belongs to, null if it belongs to none
*/ */
public static DPortal getByBlock(Block block) { public static DPortal getByBlock(DungeonsXL plugin, Block block) {
for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(DPortal.class)) { for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(DPortal.class)) {
DPortal portal = (DPortal) protection; DPortal portal = (DPortal) protection;
if (portal.getBlock1() == null || portal.getBlock2() == null) { if (portal.getBlock1() == null || portal.getBlock2() == null) {
continue; continue;

View File

@ -45,8 +45,8 @@ public class GameSign extends JoinSign {
private Game game; private Game game;
public GameSign(int id, Block startSign, String identifier, int maxGroupsPerGame) { public GameSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxGroupsPerGame) {
super(id, startSign, identifier, maxGroupsPerGame); super(plugin, id, startSign, identifier, maxGroupsPerGame);
} }
/** /**
@ -153,7 +153,7 @@ public class GameSign extends JoinSign {
return; return;
} }
game = new Game(dGroup); game = new Game(plugin, dGroup);
dGroup.setDungeon(dungeon); dGroup.setDungeon(dungeon);
update(); update();
@ -165,15 +165,16 @@ public class GameSign extends JoinSign {
/* Statics */ /* 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 * @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)) { if (!Category.SIGNS.containsBlock(block)) {
return null; return null;
} }
for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(GameSign.class)) { for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GameSign.class)) {
GameSign gameSign = (GameSign) protection; GameSign gameSign = (GameSign) protection;
Block start = gameSign.startSign; 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()))) { 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 * @return the game that this sign creates
*/ */
public static GameSign getByGame(Game game) { public static GameSign getByGame(DungeonsXL plugin, Game game) {
for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(GameSign.class)) { for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GameSign.class)) {
GameSign gameSign = (GameSign) protection; GameSign gameSign = (GameSign) protection;
if (gameSign.game == game) { if (gameSign.game == game) {
return gameSign; return gameSign;
@ -198,7 +200,7 @@ public class GameSign extends JoinSign {
return null; return null;
} }
public static GameSign tryToCreate(SignChangeEvent event) { public static GameSign tryToCreate(DungeonsXL plugin, SignChangeEvent event) {
if (!event.getLine(0).equalsIgnoreCase(SIGN_TAG)) { if (!event.getLine(0).equalsIgnoreCase(SIGN_TAG)) {
return null; return null;
} }
@ -209,10 +211,10 @@ public class GameSign extends JoinSign {
String identifier = event.getLine(2); String identifier = event.getLine(2);
int maxGroupsPerGame = NumberUtil.parseInt(event.getLine(3), 1); 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(); World world = startSign.getWorld();
BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace(); BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace();
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ(); int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
@ -229,7 +231,7 @@ public class GameSign extends JoinSign {
verticalSigns--; 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); LWCUtil.removeProtection(startSign);

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package de.erethon.dungeonsxl.config; package de.erethon.dungeonsxl.global;
import de.erethon.commons.config.DREConfig; import de.erethon.commons.config.DREConfig;
import java.io.File; import java.io.File;

View File

@ -32,15 +32,20 @@ import org.bukkit.configuration.file.YamlConfiguration;
*/ */
public abstract class GlobalProtection { 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(); public static final String SIGN_TAG = "[DXL]";
GlobalProtectionCache protections = DungeonsXL.getInstance().getGlobalProtections();
private World world; private World world;
private int id; 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.world = world;
this.id = id; this.id = id;

View File

@ -36,12 +36,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
*/ */
public class GlobalProtectionCache { public class GlobalProtectionCache {
DungeonsXL plugin = DungeonsXL.getInstance(); private DungeonsXL plugin;
private Set<GlobalProtection> protections = new HashSet<>(); private Set<GlobalProtection> protections = new HashSet<>();
public GlobalProtectionCache() { public GlobalProtectionCache(DungeonsXL plugin) {
Bukkit.getPluginManager().registerEvents(new GlobalProtectionListener(), plugin); this.plugin = plugin;
} }
/** /**
@ -187,7 +187,7 @@ public class GlobalProtectionCache {
int maxGroupsPerGame = data.getInt(preString + ".maxGroupsPerGame"); int maxGroupsPerGame = data.getInt(preString + ".maxGroupsPerGame");
Block startSign = world.getBlockAt(data.getInt(preString + ".x"), data.getInt(preString + ".y"), data.getInt(preString + ".z")); 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)); } while (data.contains(preString));
@ -207,7 +207,7 @@ public class GlobalProtectionCache {
int maxPlayersPerGroup = data.getInt(preString + ".maxPlayersPerGroup"); int maxPlayersPerGroup = data.getInt(preString + ".maxPlayersPerGroup");
Block startSign = world.getBlockAt(data.getInt(preString + ".x"), data.getInt(preString + ".y"), data.getInt(preString + ".z")); 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)); } 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")); Block block = world.getBlockAt(data.getInt(preString + ".x"), data.getInt(preString + ".y"), data.getInt(preString + ".z"));
if (block.getState() instanceof Sign) { if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState(); 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")); 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")); ExItem material = plugin.getCaliburn().getExItem(data.getString(preString + "material"));
String axis = data.getString(preString + "axis"); 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); dPortal.create(null);
} }

View File

@ -49,7 +49,11 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class GlobalProtectionListener implements Listener { 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) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreakWithSignOnIt(BlockBreakEvent event) { public void onBlockBreakWithSignOnIt(BlockBreakEvent event) {
@ -79,9 +83,9 @@ public class GlobalProtectionListener implements Listener {
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
Player player = event.getPlayer(); 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 != null) {
if (protection.onBreak(dGlobalPlayer)) { if (protection.onBreak(dGlobalPlayer)) {
event.setCancelled(true); event.setCancelled(true);
@ -91,7 +95,7 @@ public class GlobalProtectionListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if (DPortal.getByBlock(event.getBlock()) != null) { if (DPortal.getByBlock(plugin, event.getBlock()) != null) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -99,7 +103,7 @@ public class GlobalProtectionListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerBucketFill(PlayerBucketFillEvent event) { public void onPlayerBucketFill(PlayerBucketFillEvent event) {
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
if (DPortal.getByBlock(block) != null) { if (DPortal.getByBlock(plugin, block) != null) {
event.setCancelled(true); event.setCancelled(true);
// Workaround for a bug of Bukkit // Workaround for a bug of Bukkit
event.getPlayer().sendBlockChange(block.getLocation(), block.getType(), (byte) 0); event.getPlayer().sendBlockChange(block.getLocation(), block.getType(), (byte) 0);
@ -108,14 +112,14 @@ public class GlobalProtectionListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockSpread(BlockSpreadEvent event) { public void onBlockSpread(BlockSpreadEvent event) {
if (DPortal.getByBlock(event.getBlock()) != null) { if (DPortal.getByBlock(plugin, event.getBlock()) != null) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) { public void onBlockPhysics(BlockPhysicsEvent event) {
if (DPortal.getByBlock(event.getBlock()) != null) { if (DPortal.getByBlock(plugin, event.getBlock()) != null) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -124,7 +128,7 @@ public class GlobalProtectionListener implements Listener {
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
List<Block> blocklist = event.blockList(); List<Block> blocklist = event.blockList();
for (Block block : blocklist) { for (Block block : blocklist) {
if (plugin.getGlobalProtections().isProtectedBlock(block)) { if (plugin.getGlobalProtectionCache().isProtectedBlock(block)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -133,7 +137,7 @@ public class GlobalProtectionListener implements Listener {
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
DPortal dPortal = DPortal.getByLocation(player.getEyeLocation()); DPortal dPortal = DPortal.getByLocation(plugin, player.getEyeLocation());
if (dPortal == null) { if (dPortal == null) {
return; return;
} }
@ -167,14 +171,14 @@ public class GlobalProtectionListener implements Listener {
Block block7 = block2.getRelative(BlockFace.SOUTH); Block block7 = block2.getRelative(BlockFace.SOUTH);
Block block8 = block4.getRelative(BlockFace.NORTH); Block block8 = block4.getRelative(BlockFace.NORTH);
Block block9 = block4.getRelative(BlockFace.SOUTH); Block block9 = block4.getRelative(BlockFace.SOUTH);
return (DPortal.getByBlock(block1) != null || DPortal.getByBlock(block2) != null || DPortal.getByBlock(block3) != null return (DPortal.getByBlock(plugin, block1) != null || DPortal.getByBlock(plugin, block2) != null || DPortal.getByBlock(plugin, block3) != null
|| DPortal.getByBlock(block4) != null || DPortal.getByBlock(block5) != null || DPortal.getByBlock(block6) != null || DPortal.getByBlock(plugin, block4) != null || DPortal.getByBlock(plugin, block5) != null || DPortal.getByBlock(plugin, block6) != null
|| DPortal.getByBlock(block7) != null || DPortal.getByBlock(block8) != null || DPortal.getByBlock(block9) != null); || DPortal.getByBlock(plugin, block7) != null || DPortal.getByBlock(plugin, block8) != null || DPortal.getByBlock(plugin, block9) != null);
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPortalCreation(PlayerInteractEvent event) { public void onPortalCreation(PlayerInteractEvent event) {
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(event.getPlayer()); DGlobalPlayer dPlayer = plugin.getDPlayerCache().getByPlayer(event.getPlayer());
if (!dPlayer.isCreatingPortal()) { if (!dPlayer.isCreatingPortal()) {
return; return;
} }
@ -184,7 +188,7 @@ public class GlobalProtectionListener implements Listener {
return; return;
} }
for (GlobalProtection protection : plugin.getGlobalProtections().getProtections(DPortal.class)) { for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(DPortal.class)) {
DPortal dPortal = (DPortal) protection; DPortal dPortal = (DPortal) protection;
if (dPortal.isActive() || dPortal != dPlayer.getPortal()) { if (dPortal.isActive() || dPortal != dPlayer.getPortal()) {
continue; continue;
@ -209,7 +213,7 @@ public class GlobalProtectionListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent event) { public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (plugin.getDPlayers().getByPlayer(player).isInBreakMode()) { if (plugin.getDPlayerCache().getByPlayer(player).isInBreakMode()) {
return; return;
} }
Block clickedBlock = event.getClickedBlock(); Block clickedBlock = event.getClickedBlock();
@ -218,19 +222,19 @@ public class GlobalProtectionListener implements Listener {
} }
if (Category.SIGNS.containsBlock(clickedBlock)) { if (Category.SIGNS.containsBlock(clickedBlock)) {
GroupSign groupSign = GroupSign.getByBlock(clickedBlock); GroupSign groupSign = GroupSign.getByBlock(plugin, clickedBlock);
if (groupSign != null) { if (groupSign != null) {
groupSign.onPlayerInteract(clickedBlock, player); groupSign.onPlayerInteract(clickedBlock, player);
event.setCancelled(true); event.setCancelled(true);
} }
GameSign gameSign = GameSign.getByBlock(clickedBlock); GameSign gameSign = GameSign.getByBlock(plugin, clickedBlock);
if (gameSign != null) { if (gameSign != null) {
gameSign.onPlayerInteract(clickedBlock, player); gameSign.onPlayerInteract(clickedBlock, player);
event.setCancelled(true); event.setCancelled(true);
} }
LeaveSign leaveSign = LeaveSign.getByBlock(clickedBlock); LeaveSign leaveSign = LeaveSign.getByBlock(plugin, clickedBlock);
if (leaveSign != null) { if (leaveSign != null) {
leaveSign.onPlayerInteract(player); leaveSign.onPlayerInteract(player);
event.setCancelled(true); event.setCancelled(true);
@ -260,18 +264,18 @@ public class GlobalProtectionListener implements Listener {
} }
if (lines[1].equalsIgnoreCase(GroupSign.GROUP_SIGN_TAG)) { if (lines[1].equalsIgnoreCase(GroupSign.GROUP_SIGN_TAG)) {
if (GroupSign.tryToCreate(event) != null) { if (GroupSign.tryToCreate(plugin, event) != null) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (lines[1].equalsIgnoreCase(GameSign.GAME_SIGN_TAG)) { } else if (lines[1].equalsIgnoreCase(GameSign.GAME_SIGN_TAG)) {
if (GameSign.tryToCreate(event) != null) { if (GameSign.tryToCreate(plugin, event) != null) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (lines[1].equalsIgnoreCase(LeaveSign.LEAVE_SIGN_TAG)) { } else if (lines[1].equalsIgnoreCase(LeaveSign.LEAVE_SIGN_TAG)) {
Sign sign = (Sign) state; 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); event.setCancelled(true);
} }
} }

View File

@ -45,8 +45,8 @@ public class GroupSign extends JoinSign {
private String groupName; private String groupName;
private DGroup group; private DGroup group;
public GroupSign(int id, Block startSign, String identifier, int maxPlayersPerGroup, String groupName) { public GroupSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxPlayersPerGroup, String groupName) {
super(id, startSign, identifier, maxPlayersPerGroup); super(plugin, id, startSign, identifier, maxPlayersPerGroup);
this.groupName = groupName; this.groupName = groupName;
} }
@ -146,9 +146,9 @@ public class GroupSign extends JoinSign {
} }
if (groupName != null) { if (groupName != null) {
group = new DGroup(groupName, player, dungeon); group = new DGroup(plugin, groupName, player, dungeon);
} else { } else {
group = new DGroup(player, dungeon); group = new DGroup(plugin, player, dungeon);
} }
update(); update();
@ -160,15 +160,16 @@ public class GroupSign extends JoinSign {
/* Statics */ /* 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 * @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)) { if (!Category.SIGNS.containsBlock(block)) {
return null; return null;
} }
for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(GroupSign.class)) { for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GroupSign.class)) {
GroupSign groupSign = (GroupSign) protection; GroupSign groupSign = (GroupSign) protection;
Block start = groupSign.startSign; 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()))) { 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; return null;
} }
public static GroupSign tryToCreate(SignChangeEvent event) { public static GroupSign tryToCreate(DungeonsXL plugin, SignChangeEvent event) {
if (!event.getLine(0).equalsIgnoreCase(SIGN_TAG)) { if (!event.getLine(0).equalsIgnoreCase(SIGN_TAG)) {
return null; return null;
} }
@ -199,10 +200,10 @@ public class GroupSign extends JoinSign {
groupName = data[1]; 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(); World world = startSign.getWorld();
BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace(); BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace();
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ(); int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
@ -219,7 +220,7 @@ public class GroupSign extends JoinSign {
verticalSigns--; 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); LWCUtil.removeProtection(startSign);

View File

@ -37,15 +37,15 @@ public class JoinSign extends GlobalProtection {
protected int verticalSigns; protected int verticalSigns;
protected Set<Block> blocks; protected Set<Block> blocks;
protected JoinSign(int id, Block startSign, String identifier, int maxElements) { protected JoinSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxElements) {
super(startSign.getWorld(), id); super(plugin, startSign.getWorld(), id);
this.startSign = startSign; this.startSign = startSign;
dungeon = DungeonsXL.getInstance().getDungeons().getByName(identifier); dungeon = plugin.getDungeonCache().getByName(identifier);
if (dungeon == null) { if (dungeon == null) {
DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(identifier); DResourceWorld resource = plugin.getDWorldCache().getResourceByName(identifier);
if (resource != null) { if (resource != null) {
dungeon = new Dungeon(resource); dungeon = new Dungeon(plugin, resource);
} }
} }

View File

@ -43,8 +43,8 @@ public class LeaveSign extends GlobalProtection {
private Sign sign; private Sign sign;
private Set<Block> blocks; private Set<Block> blocks;
public LeaveSign(int id, Sign sign) { public LeaveSign(DungeonsXL plugin, int id, Sign sign) {
super(sign.getWorld(), id); super(plugin, sign.getWorld(), id);
this.sign = sign; this.sign = sign;
setText(); setText();
@ -99,11 +99,12 @@ public class LeaveSign extends GlobalProtection {
/* Statics */ /* 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 * @return the leave sign the block belongs to, null if it belongs to none
*/ */
public static LeaveSign getByBlock(Block block) { public static LeaveSign getByBlock(DungeonsXL plugin, Block block) {
for (GlobalProtection protection : DungeonsXL.getInstance().getGlobalProtections().getProtections(LeaveSign.class)) { for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(LeaveSign.class)) {
LeaveSign leaveSign = (LeaveSign) protection; LeaveSign leaveSign = (LeaveSign) protection;
if (leaveSign.getBlocks().contains(block)) { if (leaveSign.getBlocks().contains(block)) {

View File

@ -22,6 +22,7 @@ import de.erethon.caliburn.mob.ExMob;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.misc.EnumUtil; import de.erethon.commons.misc.EnumUtil;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import java.io.File; import java.io.File;
@ -50,7 +51,7 @@ import org.bukkit.inventory.meta.ItemMeta;
@Deprecated @Deprecated
public class DMobType extends ExMob { public class DMobType extends ExMob {
CaliburnAPI caliburn = CaliburnAPI.getInstance(); private CaliburnAPI caliburn;
private String name; private String name;
private EntityType type; private EntityType type;
@ -70,17 +71,21 @@ public class DMobType extends ExMob {
private String ocelotType = null; private String ocelotType = null;
/** /**
* @param file the script file * @param plugin the plugin instance
* @param file the script file
*/ */
public DMobType(File file) { public DMobType(DungeonsXL plugin, File file) {
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(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 name the name of the DMobType
* @param config the config that stores the information * @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; this.name = name;
// Read Mobs // Read Mobs
@ -196,9 +201,7 @@ public class DMobType extends ExMob {
} }
/* Getters and setters */ /* Getters and setters */
/** @Override
* @return the name
*/
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -31,12 +31,16 @@ import org.bukkit.Bukkit;
*/ */
public class ExternalMobProviderCache { public class ExternalMobProviderCache {
DungeonsXL plugin = DungeonsXL.getInstance(); private DungeonsXL plugin;
private Set<ExternalMobProvider> providers = new HashSet<>(); private Set<ExternalMobProvider> providers = new HashSet<>();
private CitizensMobProvider citizensMobProvider; private CitizensMobProvider citizensMobProvider;
public ExternalMobProviderCache() { public ExternalMobProviderCache(DungeonsXL plugin) {
this.plugin = plugin;
}
public void init() {
// Supported providers // Supported providers
providers.addAll(Arrays.asList(ExternalMobPlugin.values())); providers.addAll(Arrays.asList(ExternalMobPlugin.values()));

View File

@ -17,7 +17,7 @@
package de.erethon.dungeonsxl.player; package de.erethon.dungeonsxl.player;
import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.CaliburnAPI;
import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.dungeonsxl.DungeonsXL;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -32,19 +32,20 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class DClass { public class DClass {
CaliburnAPI caliburn = CaliburnAPI.getInstance(); private CaliburnAPI caliburn;
CompatibilityHandler compat = CompatibilityHandler.getInstance();
private String name; private String name;
private List<ItemStack> items = new ArrayList<>(); private List<ItemStack> items = new ArrayList<>();
private boolean dog; private boolean dog;
public DClass(File file) { public DClass(DungeonsXL plugin, File file) {
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(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; this.name = name;
if (config.contains("items")) { if (config.contains("items")) {

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.player; package de.erethon.dungeonsxl.player;
import de.erethon.commons.misc.FileUtil; import de.erethon.commons.misc.FileUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,12 +29,18 @@ import java.util.List;
*/ */
public class DClassCache { public class DClassCache {
private DungeonsXL plugin;
private List<DClass> dClasses = new ArrayList<>(); private List<DClass> dClasses = new ArrayList<>();
public DClassCache(File file) { public DClassCache(DungeonsXL plugin) {
this.plugin = plugin;
}
public void init(File file) {
if (file.isDirectory()) { if (file.isDirectory()) {
for (File script : FileUtil.getFilesForFolder(file)) { for (File script : FileUtil.getFilesForFolder(file)) {
dClasses.add(new DClass(script)); dClasses.add(new DClass(plugin, script));
} }
} }
} }

View File

@ -43,8 +43,8 @@ public class DEditPlayer extends DInstancePlayer {
private String[] linesCopy; private String[] linesCopy;
private DEditWorld editWorld; private DEditWorld editWorld;
public DEditPlayer(Player player, DEditWorld world) { public DEditPlayer(DungeonsXL plugin, Player player, DEditWorld world) {
super(player, world.getWorld()); super(plugin, player, world.getWorld());
editWorld = world; editWorld = world;
// Set gamemode a few ticks later to avoid incompatibilities with plugins that force a gamemode // 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 */ /* Statics */
public static DEditPlayer getByPlayer(Player player) { 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)) { if (dPlayer.getPlayer().equals(player)) {
return dPlayer; return dPlayer;
} }
@ -199,7 +199,7 @@ public class DEditPlayer extends DInstancePlayer {
} }
public static DEditPlayer getByName(String name) { 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)) { if (dPlayer.getName().equalsIgnoreCase(name)) {
return dPlayer; return dPlayer;
} }
@ -210,7 +210,7 @@ public class DEditPlayer extends DInstancePlayer {
public static CopyOnWriteArrayList<DEditPlayer> getByWorld(World world) { public static CopyOnWriteArrayList<DEditPlayer> getByWorld(World world) {
CopyOnWriteArrayList<DEditPlayer> dPlayers = new CopyOnWriteArrayList<>(); CopyOnWriteArrayList<DEditPlayer> dPlayers = new CopyOnWriteArrayList<>();
for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDEditPlayers()) { for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDEditPlayers()) {
if (dPlayer.getWorld() == world) { if (dPlayer.getWorld() == world) {
dPlayers.add(dPlayer); dPlayers.add(dPlayer);
} }

View File

@ -81,12 +81,12 @@ public class DGamePlayer extends DInstancePlayer {
private DGroupTag groupTag; private DGroupTag groupTag;
public DGamePlayer(Player player, DGameWorld world) { public DGamePlayer(DungeonsXL plugin, Player player, DGameWorld world) {
super(player, world.getWorld()); super(plugin, player, world.getWorld());
Game game = Game.getByGameWorld(world); Game game = Game.getByGameWorld(world);
if (game == null) { if (game == null) {
game = new Game(DGroup.getByPlayer(player)); game = new Game(plugin, DGroup.getByPlayer(player));
} }
GameRuleProvider rules = game.getRules(); GameRuleProvider rules = game.getRules();
@ -111,8 +111,8 @@ public class DGamePlayer extends DInstancePlayer {
} }
} }
public DGamePlayer(Player player, DGameWorld world, GameType ready) { public DGamePlayer(DungeonsXL plugin, Player player, DGameWorld world, GameType ready) {
this(player, world); this(plugin, player, world);
if (ready != null) { if (ready != null) {
ready(ready); ready(ready);
} }
@ -215,7 +215,7 @@ public class DGamePlayer extends DInstancePlayer {
return; return;
} }
DClass dClass = plugin.getDClasses().getByName(className); DClass dClass = plugin.getDClassCache().getByName(className);
if (dClass == null || this.dClass == dClass) { if (dClass == null || this.dClass == dClass) {
return; return;
} }
@ -396,7 +396,7 @@ public class DGamePlayer extends DInstancePlayer {
* Creates a new group tag for the player. * Creates a new group tag for the player.
*/ */
public void initDGroupTag() { public void initDGroupTag() {
groupTag = new DGroupTag(this); groupTag = new DGroupTag(plugin, this);
} }
/* Actions */ /* Actions */
@ -679,7 +679,7 @@ public class DGamePlayer extends DInstancePlayer {
Game game = Game.getByGameWorld(dGroup.getGameWorld()); Game game = Game.getByGameWorld(dGroup.getGameWorld());
if (game == null) { if (game == null) {
game = new Game(dGroup, gameType, dGroup.getGameWorld()); game = new Game(plugin, dGroup, gameType, dGroup.getGameWorld());
} else { } else {
game.setType(gameType); game.setType(gameType);
@ -978,7 +978,7 @@ public class DGamePlayer extends DInstancePlayer {
/* Statics */ /* Statics */
public static DGamePlayer getByPlayer(Player player) { 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)) { if (dPlayer.getPlayer().equals(player)) {
return dPlayer; return dPlayer;
} }
@ -987,7 +987,7 @@ public class DGamePlayer extends DInstancePlayer {
} }
public static DGamePlayer getByName(String name) { 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)) { if (dPlayer.getPlayer().getName().equalsIgnoreCase(name) || dPlayer.getName().equalsIgnoreCase(name)) {
return dPlayer; return dPlayer;
} }
@ -999,7 +999,7 @@ public class DGamePlayer extends DInstancePlayer {
public static List<DGamePlayer> getByWorld(World world) { public static List<DGamePlayer> getByWorld(World world) {
List<DGamePlayer> dPlayers = new ArrayList<>(); List<DGamePlayer> dPlayers = new ArrayList<>();
for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) { for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDGamePlayers()) {
if (dPlayer.getWorld() == world) { if (dPlayer.getWorld() == world) {
dPlayers.add(dPlayer); dPlayers.add(dPlayer);
} }

View File

@ -46,9 +46,9 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class DGlobalPlayer implements PlayerWrapper { 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; protected Player player;
@ -65,11 +65,13 @@ public class DGlobalPlayer implements PlayerWrapper {
private ItemStack[] respawnArmor; private ItemStack[] respawnArmor;
private List<ItemStack> rewardItems; private List<ItemStack> rewardItems;
public DGlobalPlayer(Player player) { public DGlobalPlayer(DungeonsXL plugin, Player player) {
this(player, false); this(plugin, player, false);
} }
public DGlobalPlayer(Player player, boolean reset) { public DGlobalPlayer(DungeonsXL plugin, Player player, boolean reset) {
this.plugin = plugin;
this.player = player; this.player = player;
loadPlayerData(new File(DungeonsXL.PLAYERS, player.getUniqueId().toString() + ".yml")); loadPlayerData(new File(DungeonsXL.PLAYERS, player.getUniqueId().toString() + ".yml"));
@ -77,11 +79,13 @@ public class DGlobalPlayer implements PlayerWrapper {
reset(false); reset(false);
} }
plugin.getDPlayers().addPlayer(this); plugin.getDPlayerCache().addPlayer(this);
} }
public DGlobalPlayer(DGlobalPlayer dPlayer) { public DGlobalPlayer(DGlobalPlayer dPlayer) {
plugin = dPlayer.plugin;
player = dPlayer.getPlayer(); player = dPlayer.getPlayer();
data = dPlayer.getData();
breakMode = dPlayer.isInBreakMode(); breakMode = dPlayer.isInBreakMode();
chatSpyMode = dPlayer.isInChatSpyMode(); chatSpyMode = dPlayer.isInChatSpyMode();
creatingPortal = dPlayer.getPortal(); creatingPortal = dPlayer.getPortal();
@ -89,7 +93,7 @@ public class DGlobalPlayer implements PlayerWrapper {
respawnInventory = dPlayer.getRespawnInventory(); respawnInventory = dPlayer.getRespawnInventory();
respawnArmor = dPlayer.getRespawnArmor(); respawnArmor = dPlayer.getRespawnArmor();
plugin.getDPlayers().addPlayer(this); plugin.getDPlayerCache().addPlayer(this);
} }
/* Getters and setters */ /* 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); DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN);
Bukkit.getPluginManager().callEvent(createEvent); Bukkit.getPluginManager().callEvent(createEvent);
@ -409,8 +413,8 @@ public class DGlobalPlayer implements PlayerWrapper {
// The maxInstances check is already done in the listener // The maxInstances check is already done in the listener
DGameWorld gameWorld = dungeon.getMap().instantiateAsGameWorld(true); DGameWorld gameWorld = dungeon.getMap().instantiateAsGameWorld(true);
dGroup.setGameWorld(gameWorld); dGroup.setGameWorld(gameWorld);
new Game(dGroup, gameWorld).setTutorial(true); new Game(plugin, dGroup, gameWorld).setTutorial(true);
new DGamePlayer(player, gameWorld); new DGamePlayer(plugin, player, gameWorld);
} }
@Override @Override

View File

@ -55,8 +55,8 @@ import org.bukkit.scheduler.BukkitTask;
*/ */
public class DGroup { public class DGroup {
DungeonsXL plugin = DungeonsXL.getInstance(); DungeonsXL plugin;
DPlayerCache dPlayers = plugin.getDPlayers(); DPlayerCache dPlayers;
private String name; private String name;
private Player captain; private Player captain;
@ -75,16 +75,19 @@ public class DGroup {
private int initialLives = -1; private int initialLives = -1;
private int lives = -1; private int lives = -1;
public DGroup(Player player) { public DGroup(DungeonsXL plugin, Player player) {
this("Group " + DungeonsXL.getInstance().getDGroups().size(), player); this(plugin, "Group " + plugin.getDGroupCache().size(), player);
} }
public DGroup(Player player, DColor color) { public DGroup(DungeonsXL plugin, Player player, DColor color) {
this(color.toString().replace("_", " "), player); this(plugin, color.toString().replace("_", " "), player);
} }
public DGroup(String name, Player player) { public DGroup(DungeonsXL plugin, String name, Player player) {
plugin.getDGroups().add(this); this.plugin = plugin;
dPlayers = plugin.getDPlayerCache();
plugin.getDGroupCache().add(this);
this.name = name; this.name = name;
setCaptain(player); setCaptain(player);
@ -94,19 +97,22 @@ public class DGroup {
floorCount = 0; floorCount = 0;
} }
public DGroup(Player player, Dungeon dungeon) { public DGroup(DungeonsXL plugin, Player player, Dungeon dungeon) {
this(DungeonsXL.getInstance().getMainConfig().getGroupColorPriority().get(DungeonsXL.getInstance().getDGroups().size()).toString(), player, dungeon); this(plugin, plugin.getMainConfig().getGroupColorPriority().get(plugin.getDGroupCache().size()).toString(), player, dungeon);
} }
public DGroup(String name, Player player, Dungeon dungeon) { public DGroup(DungeonsXL plugin, String name, Player player, Dungeon dungeon) {
this(name, player, new ArrayList<Player>(), dungeon); this(plugin, name, player, new ArrayList<Player>(), dungeon);
} }
public DGroup(String name, Player captain, List<Player> players, Dungeon dungeon) { public DGroup(DungeonsXL plugin, String name, Player captain, List<Player> players, Dungeon dungeon) {
plugin.getDGroups().add(this); this.plugin = plugin;
dPlayers = plugin.getDPlayerCache();
plugin.getDGroupCache().add(this);
this.name = name; 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); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
@ -242,7 +248,7 @@ public class DGroup {
*/ */
public void removePlayer(Player player, boolean message) { public void removePlayer(Player player, boolean message) {
players.remove(player.getUniqueId()); players.remove(player.getUniqueId());
plugin.getGlobalProtections().updateGroupSigns(this); plugin.getGlobalProtectionCache().updateGroupSigns(this);
if (message) { if (message) {
sendMessage(DMessage.PLAYER_LEFT_GROUP.getMessage(player.getName())); sendMessage(DMessage.PLAYER_LEFT_GROUP.getMessage(player.getName()));
@ -377,15 +383,15 @@ public class DGroup {
* @return if the action was successful * @return if the action was successful
*/ */
public boolean setDungeon(String name) { public boolean setDungeon(String name) {
dungeon = plugin.getDungeons().getByName(name); dungeon = plugin.getDungeonCache().getByName(name);
if (dungeon != null) { if (dungeon != null) {
unplayedFloors = dungeon.getConfig().getFloors(); unplayedFloors = dungeon.getConfig().getFloors();
return true; return true;
} else { } else {
DResourceWorld resource = plugin.getDWorlds().getResourceByName(name); DResourceWorld resource = plugin.getDWorldCache().getResourceByName(name);
if (resource != null) { if (resource != null) {
dungeon = new Dungeon(resource); dungeon = new Dungeon(plugin, resource);
return true; return true;
} }
return false; return false;
@ -682,7 +688,7 @@ public class DGroup {
public void delete() { public void delete() {
Game game = Game.getByDGroup(this); Game game = Game.getByDGroup(this);
plugin.getDGroups().remove(this); plugin.getDGroupCache().remove(this);
if (game != null) { if (game != null) {
game.removeDGroup(this); game.removeDGroup(this);
@ -699,7 +705,7 @@ public class DGroup {
timeIsRunningTask.cancel(); timeIsRunningTask.cancel();
} }
plugin.getGlobalProtections().updateGroupSigns(this); plugin.getGlobalProtectionCache().updateGroupSigns(this);
} }
public void startGame(Game game) { public void startGame(Game game) {
@ -721,7 +727,7 @@ public class DGroup {
for (Player player : dGroup.getPlayers().getOnlinePlayers()) { for (Player player : dGroup.getPlayers().getOnlinePlayers()) {
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
if (dPlayer == null) { if (dPlayer == null) {
dPlayer = new DGamePlayer(player, gameWorld); dPlayer = new DGamePlayer(plugin, player, gameWorld);
} }
if (rules.isGroupTagEnabled()) { if (rules.isGroupTagEnabled()) {
dPlayer.initDGroupTag(); dPlayer.initDGroupTag();
@ -812,7 +818,7 @@ public class DGroup {
} }
} }
plugin.getGlobalProtections().updateGroupSigns(this); plugin.getGlobalProtectionCache().updateGroupSigns(this);
nextFloor = null; nextFloor = null;
initialLives = rules.getInitialGroupLives(); initialLives = rules.getInitialGroupLives();
lives = initialLives; lives = initialLives;
@ -885,7 +891,7 @@ public class DGroup {
/* Statics */ /* Statics */
public static DGroup getByName(String name) { 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)) { if (dGroup.getName().equalsIgnoreCase(name) || dGroup.getRawName().equalsIgnoreCase(name)) {
return dGroup; return dGroup;
} }
@ -895,7 +901,7 @@ public class DGroup {
} }
public static DGroup getByPlayer(Player player) { public static DGroup getByPlayer(Player player) {
for (DGroup dGroup : DungeonsXL.getInstance().getDGroups()) { for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) {
if (dGroup.getPlayers().contains(player)) { if (dGroup.getPlayers().contains(player)) {
return dGroup; return dGroup;
} }
@ -905,7 +911,7 @@ public class DGroup {
} }
public static void leaveGroup(Player player) { public static void leaveGroup(Player player) {
for (DGroup dGroup : DungeonsXL.getInstance().getDGroups()) { for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) {
if (dGroup.getPlayers().contains(player)) { if (dGroup.getPlayers().contains(player)) {
dGroup.getPlayers().remove(player); dGroup.getPlayers().remove(player);
} }
@ -918,7 +924,7 @@ public class DGroup {
*/ */
public static List<DGroup> getByGameWorld(DGameWorld gameWorld) { public static List<DGroup> getByGameWorld(DGameWorld gameWorld) {
List<DGroup> dGroups = new ArrayList<>(); List<DGroup> dGroups = new ArrayList<>();
for (DGroup dGroup : DungeonsXL.getInstance().getDGroups()) { for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) {
if (dGroup.getGameWorld().equals(gameWorld)) { if (dGroup.getGameWorld().equals(gameWorld)) {
dGroups.add(dGroup); dGroups.add(dGroup);
} }

View File

@ -28,11 +28,11 @@ public class DGroupTag {
private DGamePlayer player; private DGamePlayer player;
private Hologram hologram; private Hologram hologram;
public DGroupTag(DGamePlayer player) { public DGroupTag(DungeonsXL plugin, DGamePlayer player) {
this.player = player; this.player = player;
DGroup group = player.getDGroup(); DGroup group = player.getDGroup();
if (group != null) { 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.appendItemLine(group.getDColor().getWoolMaterial().toItemStack());
hologram.appendTextLine(group.getName()); hologram.appendTextLine(group.getName());
} }

View File

@ -16,6 +16,7 @@
*/ */
package de.erethon.dungeonsxl.player; package de.erethon.dungeonsxl.player;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.MainConfig; import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.util.ParsingUtil; import de.erethon.dungeonsxl.util.ParsingUtil;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
@ -31,12 +32,15 @@ import org.bukkit.potion.PotionEffect;
*/ */
public abstract class DInstancePlayer extends DGlobalPlayer { public abstract class DInstancePlayer extends DGlobalPlayer {
MainConfig config = plugin.getMainConfig(); MainConfig config;
private World world; private World world;
DInstancePlayer(Player player, World world) { DInstancePlayer(DungeonsXL plugin, Player player, World world) {
super(player, false); super(plugin, player, false);
config = plugin.getMainConfig();
this.world = world; this.world = world;
getData().savePlayerState(player); getData().savePlayerState(player);
} }
@ -88,7 +92,7 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
new DGlobalPlayer(this); new DGlobalPlayer(this);
} else { } 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 * @param message the message to send
*/ */
public void chat(String message) { public void chat(String message) {
DInstanceWorld instance = plugin.getDWorlds().getInstanceByWorld(world); DInstanceWorld instance = plugin.getDWorldCache().getInstanceByWorld(world);
if (instance == null) { if (instance == null) {
return; return;
} }
String chatFormat = instance instanceof DGameWorld ? config.getChatFormatGame() : config.getChatFormatEdit(); String chatFormat = instance instanceof DGameWorld ? config.getChatFormatGame() : config.getChatFormatEdit();
instance.sendMessage(ParsingUtil.replaceChatPlaceholders(chatFormat, this) + message); instance.sendMessage(ParsingUtil.replaceChatPlaceholders(chatFormat, this) + message);
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) { for (DGlobalPlayer player : plugin.getDPlayerCache().getDGlobalPlayers()) {
if (player.isInChatSpyMode()) { if (player.isInChatSpyMode()) {
if (!instance.getWorld().getPlayers().contains(player.getPlayer())) { if (!instance.getWorld().getPlayers().contains(player.getPlayer())) {
player.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatSpy(), this) + message); player.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatSpy(), this) + message);

View File

@ -35,8 +35,8 @@ import org.bukkit.scheduler.BukkitTask;
*/ */
public class DPlayerCache { public class DPlayerCache {
DungeonsXL plugin = DungeonsXL.getInstance(); private DungeonsXL plugin;
MainConfig mainConfig = plugin.getMainConfig(); private MainConfig config;
private BukkitTask secureModeTask; private BukkitTask secureModeTask;
private BukkitTask updateTask; private BukkitTask updateTask;
@ -44,14 +44,20 @@ public class DPlayerCache {
private CopyOnWriteArrayList<DGlobalPlayer> dGlobalPlayers = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList<DGlobalPlayer> dGlobalPlayers = new CopyOnWriteArrayList<>();
public DPlayerCache() { public DPlayerCache(DungeonsXL plugin) {
if (mainConfig.isSecureModeEnabled()) { this.plugin = plugin;
startSecureModeTask(mainConfig.getSecureModeCheckInterval()); }
public void init() {
config = plugin.getMainConfig();
if (config.isSecureModeEnabled()) {
startSecureModeTask(config.getSecureModeCheckInterval());
} }
startUpdateTask(2L); startUpdateTask(2L);
startLazyUpdateTask(20L); 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 dGlobalPlayer;
} }
} }
return new DGlobalPlayer(player); return new DGlobalPlayer(plugin, player);
} }
/** /**
@ -86,7 +92,7 @@ public class DPlayerCache {
*/ */
public Collection<DInstancePlayer> getByInstance(DInstanceWorld instance) { public Collection<DInstancePlayer> getByInstance(DInstanceWorld instance) {
Collection<DInstancePlayer> players = new ArrayList<>(); Collection<DInstancePlayer> 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; return players;
} }
@ -160,7 +166,7 @@ public class DPlayerCache {
*/ */
public void loadAll() { public void loadAll() {
for (Player player : Bukkit.getOnlinePlayers()) { 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 * @param period the period in ticks
*/ */
public void startSecureModeTask(long period) { 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 * @param period the period in ticks
*/ */
public void startUpdateTask(long period) { 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 * @param period the period in ticks
*/ */
public void startLazyUpdateTask(long period) { public void startLazyUpdateTask(long period) {
lazyUpdateTask = new LazyUpdateTask().runTaskTimer(plugin, period, period); lazyUpdateTask = new LazyUpdateTask(plugin).runTaskTimer(plugin, period, period);
} }
} }

View File

@ -19,8 +19,8 @@ package de.erethon.dungeonsxl.player;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.compatibility.Internals; import de.erethon.commons.compatibility.Internals;
import de.erethon.commons.config.DREConfig; import de.erethon.commons.config.DREConfig;
import de.erethon.commons.javaplugin.DREPlugin;
import de.erethon.commons.misc.EnumUtil; import de.erethon.commons.misc.EnumUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -45,7 +45,7 @@ import org.bukkit.potion.PotionEffect;
*/ */
public class DPlayerData extends DREConfig { 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; public static final int CONFIG_VERSION = 4;
@ -383,7 +383,7 @@ public class DPlayerData extends DREConfig {
if (!file.exists()) { if (!file.exists()) {
try { try {
file.createNewFile(); 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) { } catch (IOException exception) {
} }
} }

View File

@ -65,15 +65,18 @@ import org.bukkit.inventory.meta.BookMeta;
*/ */
public class DPlayerListener implements Listener { public class DPlayerListener implements Listener {
DungeonsXL plugin = DungeonsXL.getInstance(); private DungeonsXL plugin;
MainConfig config = plugin.getMainConfig(); private MainConfig config;
DWorldCache worlds = plugin.getDWorlds(); private DWorldCache worlds;
DPlayerCache dPlayers; private DPlayerCache dPlayers;
public static final String ALL = "@all "; public static final String ALL = "@all ";
public DPlayerListener(DPlayerCache dPlayers) { public DPlayerListener(DungeonsXL plugin) {
this.dPlayers = dPlayers; this.plugin = plugin;
config = plugin.getMainConfig();
worlds = plugin.getDWorldCache();
dPlayers = plugin.getDPlayerCache();
} }
@EventHandler @EventHandler
@ -372,7 +375,7 @@ public class DPlayerListener implements Listener {
return; return;
} }
DGlobalPlayer dPlayer = new DGlobalPlayer(player); DGlobalPlayer dPlayer = new DGlobalPlayer(plugin, player);
if (dPlayer.getData().wasInGame()) { if (dPlayer.getData().wasInGame()) {
dPlayer.reset(dPlayer.getData().getKeepInventoryAfterLogout()); dPlayer.reset(dPlayer.getData().getKeepInventoryAfterLogout());
} }
@ -447,7 +450,7 @@ public class DPlayerListener implements Listener {
if (isCitizensNPC(player)) { if (isCitizensNPC(player)) {
return; return;
} }
plugin.getDPlayers().getByPlayer(player).applyRespawnInventory(); plugin.getDPlayerCache().getByPlayer(player).applyRespawnInventory();
DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player); DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player);
if (dPlayer == null) { 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. // 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! // Don't forget Doge!
if (gamePlayer.getWolf() != null) { if (gamePlayer.getWolf() != null) {

View File

@ -24,9 +24,15 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class LazyUpdateTask extends BukkitRunnable { public class LazyUpdateTask extends BukkitRunnable {
private DungeonsXL plugin;
public LazyUpdateTask(DungeonsXL plugin) {
this.plugin = plugin;
}
@Override @Override
public void run() { public void run() {
for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) { for (DGamePlayer dPlayer : plugin.getDPlayerCache().getDGamePlayers()) {
dPlayer.update(true); dPlayer.update(true);
} }
} }

View File

@ -27,10 +27,14 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class RespawnTask extends BukkitRunnable { public class RespawnTask extends BukkitRunnable {
private DPlayerCache dPlayers;
private Player player; private Player player;
private Location location; private Location location;
public RespawnTask(Player player, Location location) { public RespawnTask(DungeonsXL plugin, Player player, Location location) {
dPlayers = plugin.getDPlayerCache();
this.location = location; this.location = location;
this.player = player; this.player = player;
} }
@ -41,7 +45,7 @@ public class RespawnTask extends BukkitRunnable {
PlayerUtil.secureTeleport(player, location); PlayerUtil.secureTeleport(player, location);
} }
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
if (dPlayer == null) { if (dPlayer == null) {
return; return;

View File

@ -26,12 +26,18 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class SecureModeTask extends BukkitRunnable { public class SecureModeTask extends BukkitRunnable {
private DungeonsXL plugin;
public SecureModeTask(DungeonsXL plugin) {
this.plugin = plugin;
}
@Override @Override
public void run() { public void run() {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
DGlobalPlayer dGlobalPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player); DGlobalPlayer dGlobalPlayer = plugin.getDPlayerCache().getByPlayer(player);
if (dGlobalPlayer == null) { if (dGlobalPlayer == null) {
dGlobalPlayer = new DGlobalPlayer(player); dGlobalPlayer = new DGlobalPlayer(plugin, player);
} }
if (!(dGlobalPlayer instanceof DGamePlayer || dGlobalPlayer instanceof DEditPlayer)) { if (!(dGlobalPlayer instanceof DGamePlayer || dGlobalPlayer instanceof DEditPlayer)) {

View File

@ -17,8 +17,6 @@
package de.erethon.dungeonsxl.player; package de.erethon.dungeonsxl.player;
import de.erethon.commons.chat.MessageUtil; 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.config.DMessage;
import de.erethon.dungeonsxl.event.dplayer.DPlayerKickEvent; import de.erethon.dungeonsxl.event.dplayer.DPlayerKickEvent;
import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.game.Game;
@ -32,8 +30,6 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class TimeIsRunningTask extends BukkitRunnable { public class TimeIsRunningTask extends BukkitRunnable {
MessageConfig messageConfig = DungeonsXL.getInstance().getMessageConfig();
private DGroup dGroup; private DGroup dGroup;
private int time; private int time;
private int timeLeft; private int timeLeft;

View File

@ -24,9 +24,15 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class UpdateTask extends BukkitRunnable { public class UpdateTask extends BukkitRunnable {
private DungeonsXL plugin;
public UpdateTask(DungeonsXL plugin) {
this.plugin = plugin;
}
@Override @Override
public void run() { public void run() {
for (DInstancePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDInstancePlayers()) { for (DInstancePlayer dPlayer : plugin.getDPlayerCache().getDInstancePlayers()) {
dPlayer.update(false); dPlayer.update(false);
} }
} }

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.requirement; package de.erethon.dungeonsxl.requirement;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.game.Game;
import de.erethon.dungeonsxl.game.GameRuleProvider; import de.erethon.dungeonsxl.game.GameRuleProvider;
@ -35,6 +36,10 @@ public class FeeLevelRequirement extends Requirement {
private int fee; private int fee;
private Boolean keepInventory; private Boolean keepInventory;
public FeeLevelRequirement(DungeonsXL plugin) {
super(plugin);
}
/* Getters and setters */ /* Getters and setters */
/** /**
* @return the fee * @return the fee

View File

@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.requirement;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -27,12 +28,17 @@ import org.bukkit.entity.Player;
*/ */
public class FeeMoneyRequirement extends Requirement { public class FeeMoneyRequirement extends Requirement {
DungeonsXL plugin = DungeonsXL.getInstance(); private Economy econ;
private RequirementType type = RequirementTypeDefault.FEE_MONEY; private RequirementType type = RequirementTypeDefault.FEE_MONEY;
private double fee; private double fee;
public FeeMoneyRequirement(DungeonsXL plugin) {
super(plugin);
econ = plugin.getEconomyProvider();
}
/* Getters and setters */ /* Getters and setters */
/** /**
* @return the fee * @return the fee
@ -61,21 +67,21 @@ public class FeeMoneyRequirement extends Requirement {
@Override @Override
public boolean check(Player player) { public boolean check(Player player) {
if (plugin.getEconomyProvider() == null) { if (econ == null) {
return true; return true;
} }
return plugin.getEconomyProvider().getBalance(player) >= fee; return econ.getBalance(player) >= fee;
} }
@Override @Override
public void demand(Player player) { public void demand(Player player) {
if (plugin.getEconomyProvider() == null) { if (econ == null) {
return; return;
} }
plugin.getEconomyProvider().withdrawPlayer(player, fee); econ.withdrawPlayer(player, fee);
MessageUtil.sendMessage(player, DMessage.REQUIREMENT_FEE.getMessage(plugin.getEconomyProvider().format(fee))); MessageUtil.sendMessage(player, DMessage.REQUIREMENT_FEE.getMessage(econ.format(fee)));
} }
} }

View File

@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.requirement;
import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.CaliburnAPI;
import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.ExItem;
import de.erethon.dungeonsxl.DungeonsXL;
import java.util.List; import java.util.List;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -28,12 +29,17 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class ForbiddenItemsRequirement extends Requirement { public class ForbiddenItemsRequirement extends Requirement {
CaliburnAPI caliburn = CaliburnAPI.getInstance(); private CaliburnAPI caliburn;
private RequirementType type = RequirementTypeDefault.FORBIDDEN_ITEMS; private RequirementType type = RequirementTypeDefault.FORBIDDEN_ITEMS;
private List<ExItem> forbiddenItems; private List<ExItem> forbiddenItems;
public ForbiddenItemsRequirement(DungeonsXL plugin) {
super(plugin);
caliburn = plugin.getCaliburn();
}
/* Getters and setters */ /* Getters and setters */
/** /**
* @return the forbidden items * @return the forbidden items

View File

@ -16,6 +16,7 @@
*/ */
package de.erethon.dungeonsxl.requirement; package de.erethon.dungeonsxl.requirement;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.player.DGroup;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -30,6 +31,10 @@ public class GroupSizeRequirement extends Requirement {
private int minimum; private int minimum;
private int maximum; private int maximum;
public GroupSizeRequirement(DungeonsXL plugin) {
super(plugin);
}
/** /**
* @return the group minimum * @return the group minimum
*/ */

View File

@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.requirement;
import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.CaliburnAPI;
import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.ExItem;
import de.erethon.dungeonsxl.DungeonsXL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -29,12 +30,17 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class KeyItemsRequirement extends Requirement { public class KeyItemsRequirement extends Requirement {
CaliburnAPI caliburn = CaliburnAPI.getInstance(); private CaliburnAPI caliburn;
private RequirementType type = RequirementTypeDefault.KEY_ITEMS; private RequirementType type = RequirementTypeDefault.KEY_ITEMS;
private List<ExItem> keyItems; private List<ExItem> keyItems;
public KeyItemsRequirement(DungeonsXL plugin) {
super(plugin);
caliburn = plugin.getCaliburn();
}
/* Getters and setters */ /* Getters and setters */
/** /**
* @return the forbidden items * @return the forbidden items

View File

@ -16,6 +16,7 @@
*/ */
package de.erethon.dungeonsxl.requirement; package de.erethon.dungeonsxl.requirement;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -31,6 +32,10 @@ public class PermissionRequirement extends Requirement {
private List<String> permissions = new ArrayList<>(); private List<String> permissions = new ArrayList<>();
public PermissionRequirement(DungeonsXL plugin) {
super(plugin);
}
/* Getters and setters */ /* Getters and setters */
/** /**
* @return the permission the player must have to play the dungeon * @return the permission the player must have to play the dungeon

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.requirement; package de.erethon.dungeonsxl.requirement;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.event.requirement.RequirementRegistrationEvent; import de.erethon.dungeonsxl.event.requirement.RequirementRegistrationEvent;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -31,12 +32,18 @@ import org.bukkit.entity.Player;
*/ */
public abstract class Requirement { 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; Requirement requirement = null;
try { try {
Constructor<? extends Requirement> constructor = type.getHandler().getConstructor(); Constructor<? extends Requirement> constructor = type.getHandler().getConstructor(DungeonsXL.class);
requirement = constructor.newInstance(); requirement = constructor.newInstance(plugin);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { } 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()); MessageUtil.log("An error occurred while accessing the handler class of the requirement " + type.getIdentifier() + ": " + exception.getClass().getSimpleName());

View File

@ -16,6 +16,7 @@
*/ */
package de.erethon.dungeonsxl.reward; package de.erethon.dungeonsxl.reward;
import de.erethon.dungeonsxl.DungeonsXL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -31,6 +32,10 @@ public class ItemReward extends Reward {
private List<ItemStack> items = new ArrayList<>(); private List<ItemStack> items = new ArrayList<>();
public ItemReward(DungeonsXL plugin) {
super(plugin);
}
/* Getters and setters */ /* Getters and setters */
/** /**
* @return the reward items * @return the reward items
@ -68,7 +73,7 @@ public class ItemReward extends Reward {
/* Actions */ /* Actions */
@Override @Override
public void giveTo(Player player) { public void giveTo(Player player) {
plugin.getDPlayers().getByPlayer(player).setRewardItems(items); plugin.getDPlayerCache().getByPlayer(player).setRewardItems(items);
} }
} }

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.reward; package de.erethon.dungeonsxl.reward;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -29,6 +30,10 @@ public class LevelReward extends Reward {
private int levels; private int levels;
public LevelReward(DungeonsXL plugin) {
super(plugin);
}
/** /**
* @return the levels * @return the levels
*/ */

View File

@ -17,7 +17,9 @@
package de.erethon.dungeonsxl.reward; package de.erethon.dungeonsxl.reward;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
@ -25,10 +27,17 @@ import org.bukkit.entity.Player;
*/ */
public class MoneyReward extends Reward { public class MoneyReward extends Reward {
private Economy econ;
private RewardType type = RewardTypeDefault.MONEY; private RewardType type = RewardTypeDefault.MONEY;
private double money; private double money;
public MoneyReward(DungeonsXL plugin) {
super(plugin);
econ = plugin.getEconomyProvider();
}
/** /**
* @return the money * @return the money
*/ */
@ -52,11 +61,11 @@ public class MoneyReward extends Reward {
@Override @Override
public void giveTo(Player player) { public void giveTo(Player player) {
if (plugin.getEconomyProvider() == null || money == 0) { if (econ == null || money == 0) {
return; return;
} }
plugin.getEconomyProvider().depositPlayer(player, money); econ.depositPlayer(player, money);
MessageUtil.sendMessage(player, DMessage.REWARD_GENERAL.getMessage(plugin.getEconomyProvider().format(money))); MessageUtil.sendMessage(player, DMessage.REWARD_GENERAL.getMessage(plugin.getEconomyProvider().format(money)));
} }

View File

@ -31,14 +31,18 @@ import org.bukkit.entity.Player;
*/ */
public abstract class Reward { 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; Reward reward = null;
try { try {
Constructor<? extends Reward> constructor = type.getHandler().getConstructor(); Constructor<? extends Reward> constructor = type.getHandler().getConstructor(DungeonsXL.class);
reward = constructor.newInstance(); reward = constructor.newInstance(plugin);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { } 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()); MessageUtil.log("An error occurred while accessing the handler class of the reward " + type.getIdentifier() + ": " + exception.getClass().getSimpleName());

View File

@ -42,7 +42,11 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class RewardListener implements Listener { public class RewardListener implements Listener {
DungeonsXL plugin = DungeonsXL.getInstance(); private DungeonsXL plugin;
public RewardListener(DungeonsXL plugin) {
this.plugin = plugin;
}
/*@EventHandler /*@EventHandler
public void onInventoryClose(InventoryCloseEvent event) { public void onInventoryClose(InventoryCloseEvent event) {
@ -109,8 +113,8 @@ public class RewardListener implements Listener {
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); DGlobalPlayer dPlayer = plugin.getDPlayerCache().getByPlayer(player);
if (plugin.getDWorlds().getInstanceByWorld(player.getWorld()) != null) { if (plugin.getDWorldCache().getInstanceByWorld(player.getWorld()) != null) {
return; return;
} }
Block block = player.getLocation().getBlock(); Block block = player.getLocation().getBlock();

View File

@ -16,11 +16,9 @@
*/ */
package de.erethon.dungeonsxl.reward; package de.erethon.dungeonsxl.reward;
import de.erethon.dungeonsxl.DungeonsXL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
/** /**
* RewardType instance manager. * RewardType instance manager.
@ -33,7 +31,6 @@ public class RewardTypeCache {
public RewardTypeCache() { public RewardTypeCache() {
types.addAll(Arrays.asList(RewardTypeDefault.values())); types.addAll(Arrays.asList(RewardTypeDefault.values()));
Bukkit.getPluginManager().registerEvents(new RewardListener(), DungeonsXL.getInstance());
} }
/** /**

View File

@ -20,6 +20,7 @@ import de.erethon.caliburn.category.Category;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.misc.BlockUtil; import de.erethon.commons.misc.BlockUtil;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.block.TeamBed; import de.erethon.dungeonsxl.world.block.TeamBed;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -34,8 +35,8 @@ public class BedSign extends DSign {
private int team; private int team;
public BedSign(Sign sign, String[] lines, DGameWorld gameWorld) { public BedSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
/* Getters and setters */ /* Getters and setters */
@ -57,7 +58,7 @@ public class BedSign extends DSign {
if (Category.BEDS.containsBlock(block)) { if (Category.BEDS.containsBlock(block)) {
if (getGame().getDGroups().size() > team) { 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()); getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
} else { } else {

View File

@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.sign;
import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.ExItem;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.util.MagicValueUtil; import de.erethon.dungeonsxl.util.MagicValueUtil;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -38,8 +39,8 @@ public class BlockSign extends DSign {
private byte offBlockData = 0x0; private byte offBlockData = 0x0;
private byte onBlockData = 0x0; private byte onBlockData = 0x0;
public BlockSign(Sign sign, String[] lines, DGameWorld gameWorld) { public BlockSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
@Override @Override

View File

@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.trigger.InteractTrigger;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
@ -39,8 +40,8 @@ public class BossShopSign extends DSign {
private String shopName; private String shopName;
public BossShopSign(Sign sign, String[] lines, DGameWorld gameWorld) { public BossShopSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
/* Getters and setters*/ /* Getters and setters*/

View File

@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGamePlayer;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
@ -36,8 +37,8 @@ public class CheckpointSign extends DSign {
private boolean initialized; private boolean initialized;
private CopyOnWriteArrayList<DGamePlayer> done = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList<DGamePlayer> done = new CopyOnWriteArrayList<>();
public CheckpointSign(Sign sign, String[] lines, DGameWorld gameWorld) { public CheckpointSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
@Override @Override

View File

@ -20,6 +20,7 @@ import de.erethon.caliburn.category.Category;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.caliburn.loottable.LootTable; import de.erethon.caliburn.loottable.LootTable;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.block.RewardChest; import de.erethon.dungeonsxl.world.block.RewardChest;
import java.util.Arrays; import java.util.Arrays;
@ -44,8 +45,8 @@ public class ChestSign extends DSign {
private ItemStack[] chestContent; private ItemStack[] chestContent;
private LootTable lootTable; private LootTable lootTable;
public ChestSign(Sign sign, String[] lines, DGameWorld gameWorld) { public ChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
/* Getters and setters */ /* Getters and setters */
@ -178,7 +179,7 @@ public class ChestSign extends DSign {
itemReward = list.toArray(new ItemStack[list.size()]); 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()); getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
} else { } else {

View File

@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -29,8 +30,8 @@ public class ChunkUpdaterSign extends DSign {
private DSignType type = DSignTypeDefault.CHUNK_UPDATER; private DSignType type = DSignTypeDefault.CHUNK_UPDATER;
public ChunkUpdaterSign(Sign sign, String[] lines, DGameWorld gameWorld) { public ChunkUpdaterSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
@Override @Override

View File

@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.sign;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.trigger.InteractTrigger;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import io.github.dre2n.commandsxl.CommandsXL; import io.github.dre2n.commandsxl.CommandsXL;
@ -44,8 +45,8 @@ public class CommandSign extends DSign {
private String executor; private String executor;
private boolean initialized; private boolean initialized;
public CommandSign(Sign sign, String[] lines, DGameWorld gameWorld) { public CommandSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
@Override @Override

View File

@ -39,7 +39,7 @@ import org.bukkit.entity.Player;
*/ */
public abstract class DSign { 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_0 = ChatColor.DARK_RED + "## ERROR ##";
public static final String ERROR_1 = ChatColor.WHITE + "Please"; public static final String ERROR_1 = ChatColor.WHITE + "Please";
@ -55,7 +55,9 @@ public abstract class DSign {
private boolean erroneous; 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.sign = sign;
this.lines = lines; this.lines = lines;
this.gameWorld = gameWorld; this.gameWorld = gameWorld;
@ -79,7 +81,7 @@ public abstract class DSign {
value = triggerString.substring(1); value = triggerString.substring(1);
} }
Trigger trigger = Trigger.getOrCreate(type, value, this); Trigger trigger = Trigger.getOrCreate(plugin, type, value, this);
if (trigger != null) { if (trigger != null) {
trigger.addListener(this); trigger.addListener(this);
addTrigger(trigger); addTrigger(trigger);
@ -221,21 +223,21 @@ public abstract class DSign {
} }
/* Statics */ /* Statics */
public static DSign create(Sign sign, DGameWorld gameWorld) { public static DSign create(DungeonsXL plugin, Sign sign, DGameWorld gameWorld) {
return create(sign, sign.getLines(), 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; DSign dSign = null;
for (DSignType type : DungeonsXL.getInstance().getDSigns().getDSigns()) { for (DSignType type : plugin.getDSignCache().getDSigns()) {
if (!lines[0].equalsIgnoreCase("[" + type.getName() + "]")) { if (!lines[0].equalsIgnoreCase("[" + type.getName() + "]")) {
continue; continue;
} }
try { try {
Constructor<? extends DSign> constructor = type.getHandler().getConstructor(Sign.class, String[].class, DGameWorld.class); Constructor<? extends DSign> constructor = type.getHandler().getConstructor(DungeonsXL.class, Sign.class, String[].class, DGameWorld.class);
dSign = constructor.newInstance(sign, lines, gameWorld); dSign = constructor.newInstance(plugin, sign, lines, gameWorld);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { } 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()); MessageUtil.log("An error occurred while accessing the handler class of the sign " + type.getName() + ": " + exception.getClass().getSimpleName());

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.sign; package de.erethon.dungeonsxl.sign;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGamePlayer;
import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.player.DPermission;
@ -39,6 +40,12 @@ import org.bukkit.event.player.PlayerInteractEvent;
*/ */
public class DSignListener implements Listener { public class DSignListener implements Listener {
private DungeonsXL plugin;
public DSignListener(DungeonsXL plugin) {
this.plugin = plugin;
}
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -97,7 +104,7 @@ public class DSignListener implements Listener {
sign.setLine(2, lines[2]); sign.setLine(2, lines[2]);
sign.setLine(3, lines[3]); sign.setLine(3, lines[3]);
DSign dsign = DSign.create(sign, null); DSign dsign = DSign.create(plugin, sign, null);
if (dsign == null) { if (dsign == null) {
return; return;

View File

@ -29,11 +29,17 @@ import org.bukkit.Bukkit;
*/ */
public class DSignTypeCache { public class DSignTypeCache {
private DungeonsXL plugin;
private List<DSignType> types = new ArrayList<>(); private List<DSignType> types = new ArrayList<>();
public DSignTypeCache() { public DSignTypeCache(DungeonsXL plugin) {
this.plugin = plugin;
}
public void init() {
types.addAll(Arrays.asList(DSignTypeDefault.values())); types.addAll(Arrays.asList(DSignTypeDefault.values()));
Bukkit.getPluginManager().registerEvents(new DSignListener(), DungeonsXL.getInstance()); Bukkit.getPluginManager().registerEvents(new DSignListener(plugin), plugin);
} }
/** /**

View File

@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.sign;
import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.ExItem;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -35,8 +36,8 @@ public class DropSign extends DSign {
private ItemStack item; private ItemStack item;
private double interval = -1; private double interval = -1;
public DropSign(Sign sign, String[] lines, DGameWorld gameWorld) { public DropSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
/* Getters and setters */ /* Getters and setters */

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.sign; package de.erethon.dungeonsxl.sign;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.dungeon.Dungeon; import de.erethon.dungeonsxl.dungeon.Dungeon;
import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGamePlayer;
@ -36,8 +37,8 @@ public class EndSign extends DSign {
private DResourceWorld floor; private DResourceWorld floor;
public EndSign(Sign sign, String[] lines, DGameWorld gameWorld) { public EndSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
/** /**
@ -62,7 +63,7 @@ public class EndSign extends DSign {
@Override @Override
public void onInit() { public void onInit() {
if (!lines[1].isEmpty()) { if (!lines[1].isEmpty()) {
floor = plugin.getDWorlds().getResourceByName(lines[1]); floor = plugin.getDWorldCache().getResourceByName(lines[1]);
} }
if (!getTriggers().isEmpty()) { if (!getTriggers().isEmpty()) {

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.sign; package de.erethon.dungeonsxl.sign;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.block.TeamFlag; import de.erethon.dungeonsxl.world.block.TeamFlag;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -30,8 +31,8 @@ public class FlagSign extends DSign {
private int team; private int team;
public FlagSign(Sign sign, String[] lines, DGameWorld gameWorld) { public FlagSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
/* Getters and setters */ /* Getters and setters */
@ -50,7 +51,7 @@ public class FlagSign extends DSign {
public void onInit() { public void onInit() {
this.team = NumberUtil.parseInt(lines[1]); this.team = NumberUtil.parseInt(lines[1]);
if (getGame().getDGroups().size() > team) { 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)));
} }
} }

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.sign; package de.erethon.dungeonsxl.sign;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.trigger.InteractTrigger;
import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DEditWorld;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
@ -34,8 +35,8 @@ public class InteractSign extends DSign {
private DSignType type = DSignTypeDefault.INTERACT; private DSignType type = DSignTypeDefault.INTERACT;
public InteractSign(Sign sign, String[] lines, DGameWorld gameWorld) { public InteractSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
@Override @Override

View File

@ -17,6 +17,7 @@
package de.erethon.dungeonsxl.sign; package de.erethon.dungeonsxl.sign;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent;
import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGamePlayer;
@ -34,8 +35,8 @@ public class LeaveSign extends DSign {
private DSignType type = DSignTypeDefault.LEAVE; private DSignType type = DSignTypeDefault.LEAVE;
public LeaveSign(Sign sign, String[] lines, DGameWorld gameWorld) { public LeaveSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld); super(plugin, sign, lines, gameWorld);
} }
@Override @Override
@ -81,7 +82,7 @@ public class LeaveSign extends DSign {
@Override @Override
public void onTrigger() { public void onTrigger() {
for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) { for (DGamePlayer dPlayer : plugin.getDPlayerCache().getDGamePlayers()) {
DGamePlayerEscapeEvent event = new DGamePlayerEscapeEvent(dPlayer); DGamePlayerEscapeEvent event = new DGamePlayerEscapeEvent(dPlayer);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);

Some files were not shown because too many files have changed in this diff Show More