From 2fc7e841e1911ccae01f458064a7bcd16008ec26 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sat, 16 Jan 2016 14:28:11 +0100 Subject: [PATCH 1/4] New structure --- .../github/dre2n/dungeonsxl/DungeonsXL.java | 119 ++- .../dungeonsxl/command/BreakCommand.java | 8 +- .../dre2n/dungeonsxl/command/ChatCommand.java | 10 +- .../dungeonsxl/command/ChatSpyCommand.java | 8 +- .../dungeonsxl/command/CreateCommand.java | 22 +- .../dre2n/dungeonsxl/command/DCommand.java | 4 +- .../command/DeletePortalCommand.java | 6 +- .../dre2n/dungeonsxl/command/EditCommand.java | 12 +- .../dungeonsxl/command/EscapeCommand.java | 10 +- .../dre2n/dungeonsxl/command/HelpCommand.java | 4 +- .../dungeonsxl/command/InviteCommand.java | 8 +- .../dungeonsxl/command/LeaveCommand.java | 12 +- .../dre2n/dungeonsxl/command/ListCommand.java | 8 +- .../dungeonsxl/command/LivesCommand.java | 10 +- .../dre2n/dungeonsxl/command/MainCommand.java | 12 +- .../dre2n/dungeonsxl/command/MsgCommand.java | 18 +- .../dre2n/dungeonsxl/command/PlayCommand.java | 20 +- .../dungeonsxl/command/PortalCommand.java | 10 +- .../dungeonsxl/command/ReloadCommand.java | 14 +- .../dre2n/dungeonsxl/command/SaveCommand.java | 8 +- .../dre2n/dungeonsxl/command/TestCommand.java | 14 +- .../dungeonsxl/command/UninviteCommand.java | 8 +- .../{dungeon => config}/DungeonConfig.java | 2 +- .../{file => config}/MainConfig.java | 25 +- .../MessageConfig.java} | 6 +- .../{dungeon => config}/WorldConfig.java | 3 +- .../dungeonsxl/dungeon/DLootInventory.java | 34 +- .../dre2n/dungeonsxl/dungeon/Dungeon.java | 1 + .../dre2n/dungeonsxl/dungeon/EditWorld.java | 544 +++++------ .../dungeonsxl/dungeon/game/GameChest.java | 200 ++-- .../dungeon/game/GamePlaceableBlock.java | 2 +- .../dungeonsxl/dungeon/game/GameWorld.java | 342 ++++--- .../dre2n/dungeonsxl/global/DPortal.java | 156 +-- .../dre2n/dungeonsxl/global/GroupSign.java | 10 +- .../dre2n/dungeonsxl/global/LeaveSign.java | 4 +- .../dungeonsxl/listener/BlockListener.java | 41 +- .../dungeonsxl/listener/CommandListener.java | 12 +- .../dungeonsxl/listener/EntityListener.java | 2 +- .../dungeonsxl/listener/PlayerListener.java | 78 +- .../github/dre2n/dungeonsxl/mob/DMobType.java | 10 +- .../dre2n/dungeonsxl/player/DGroup.java | 10 +- .../dre2n/dungeonsxl/player/DPlayer.java | 888 +++++++++--------- .../dre2n/dungeonsxl/player/DSavePlayer.java | 7 +- .../requirement/FeeRequirement.java | 4 +- .../dre2n/dungeonsxl/reward/MoneyReward.java | 4 +- .../dre2n/dungeonsxl/sign/CheckpointSign.java | 6 +- .../dre2n/dungeonsxl/sign/InteractSign.java | 16 +- .../github/dre2n/dungeonsxl/sign/MobSign.java | 190 ++-- .../dre2n/dungeonsxl/sign/MythicMobsSign.java | 232 +++-- .../dre2n/dungeonsxl/sign/ReadySign.java | 6 +- .../dre2n/dungeonsxl/sign/RedstoneSign.java | 196 +++- .../dre2n/dungeonsxl/sign/TriggerSign.java | 16 +- .../dungeonsxl/task/DelayedPowerTask.java | 38 + .../dre2n/dungeonsxl/task/LazyUpdateTask.java | 24 + .../dre2n/dungeonsxl/task/MobSpawnTask.java | 81 ++ .../dungeonsxl/task/MythicMobSpawnTask.java | 57 ++ .../dungeonsxl/task/RedstoneEventTask.java | 27 + .../dre2n/dungeonsxl/task/RespawnTask.java | 41 + .../dre2n/dungeonsxl/task/SignUpdateTask.java | 19 + .../dre2n/dungeonsxl/task/UpdateTask.java | 17 + .../dungeonsxl/task/WorldUnloadTask.java | 31 + .../dre2n/dungeonsxl/util/MiscUtil.java | 95 -- .../PlayerUtil.java} | 12 +- .../v1_7_R3.java | 2 +- .../v1_7_R4.java | 2 +- .../v1_8_R1.java | 2 +- .../v1_8_R2.java | 2 +- .../v1_8_R3.java | 2 +- .../v1_9_R1.java | 2 +- 69 files changed, 2142 insertions(+), 1704 deletions(-) rename src/io/github/dre2n/dungeonsxl/{dungeon => config}/DungeonConfig.java (98%) rename src/io/github/dre2n/dungeonsxl/{file => config}/MainConfig.java (87%) rename src/io/github/dre2n/dungeonsxl/{file/DMessages.java => config/MessageConfig.java} (99%) rename src/io/github/dre2n/dungeonsxl/{dungeon => config}/WorldConfig.java (99%) create mode 100644 src/io/github/dre2n/dungeonsxl/task/DelayedPowerTask.java create mode 100644 src/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java create mode 100644 src/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java create mode 100644 src/io/github/dre2n/dungeonsxl/task/MythicMobSpawnTask.java create mode 100644 src/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java create mode 100644 src/io/github/dre2n/dungeonsxl/task/RespawnTask.java create mode 100644 src/io/github/dre2n/dungeonsxl/task/SignUpdateTask.java create mode 100644 src/io/github/dre2n/dungeonsxl/task/UpdateTask.java create mode 100644 src/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java delete mode 100644 src/io/github/dre2n/dungeonsxl/util/MiscUtil.java rename src/io/github/dre2n/dungeonsxl/util/{offlineplayerutil/OfflinePlayerUtil.java => playerutil/PlayerUtil.java} (89%) rename src/io/github/dre2n/dungeonsxl/util/{offlineplayerutil => playerutil}/v1_7_R3.java (97%) rename src/io/github/dre2n/dungeonsxl/util/{offlineplayerutil => playerutil}/v1_7_R4.java (97%) rename src/io/github/dre2n/dungeonsxl/util/{offlineplayerutil => playerutil}/v1_8_R1.java (97%) rename src/io/github/dre2n/dungeonsxl/util/{offlineplayerutil => playerutil}/v1_8_R2.java (97%) rename src/io/github/dre2n/dungeonsxl/util/{offlineplayerutil => playerutil}/v1_8_R3.java (97%) rename src/io/github/dre2n/dungeonsxl/util/{offlineplayerutil => playerutil}/v1_9_R1.java (97%) diff --git a/src/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/io/github/dre2n/dungeonsxl/DungeonsXL.java index 8ac88d81..a7eed9a3 100644 --- a/src/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -1,13 +1,13 @@ package io.github.dre2n.dungeonsxl; import io.github.dre2n.dungeonsxl.command.DCommands; +import io.github.dre2n.dungeonsxl.config.MainConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig; +import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.DLootInventory; import io.github.dre2n.dungeonsxl.dungeon.Dungeons; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.file.DMessages; -import io.github.dre2n.dungeonsxl.file.MainConfig; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.global.LeaveSign; @@ -23,6 +23,9 @@ import io.github.dre2n.dungeonsxl.player.DSavePlayer; import io.github.dre2n.dungeonsxl.requirement.Requirements; import io.github.dre2n.dungeonsxl.reward.Rewards; import io.github.dre2n.dungeonsxl.sign.DSigns; +import io.github.dre2n.dungeonsxl.task.LazyUpdateTask; +import io.github.dre2n.dungeonsxl.task.UpdateTask; +import io.github.dre2n.dungeonsxl.task.WorldUnloadTask; import io.github.dre2n.dungeonsxl.trigger.Triggers; import io.github.dre2n.dungeonsxl.util.FileUtil; import io.github.dre2n.dungeonsxl.util.VersionUtil; @@ -49,8 +52,10 @@ public class DungeonsXL extends JavaPlugin { private Permission permissionProvider; private MainConfig mainConfig; - private DMessages dMessages; + private MessageConfig messageConfig; + private VersionUtil versionUtil; + private DCommands dCommands; private DSigns dSigns; private Requirements requirements; @@ -58,6 +63,10 @@ public class DungeonsXL extends JavaPlugin { private Triggers triggers; private Dungeons dungeons; + private WorldUnloadTask worldUnloadTask; + private LazyUpdateTask lazyUpdateTask; + private UpdateTask updateTask; + private CopyOnWriteArrayList inBreakMode = new CopyOnWriteArrayList(); private CopyOnWriteArrayList chatSpyers = new CopyOnWriteArrayList(); private CopyOnWriteArrayList dLootInventories = new CopyOnWriteArrayList(); @@ -72,17 +81,16 @@ public class DungeonsXL extends JavaPlugin { @Override public void onEnable() { plugin = this; - getDataFolder().mkdir(); // InitFolders initFolders(); // Load Language - loadDMessages(new File(plugin.getDataFolder(), "languages/en.yml")); + loadMessageConfig(new File(plugin.getDataFolder(), "languages/en.yml")); // Load Config loadMainConfig(new File(plugin.getDataFolder(), "config.yml")); // Load Language 2 - loadDMessages(new File(plugin.getDataFolder(), "languages/" + mainConfig.getLanguage() + ".yml")); + loadMessageConfig(new File(plugin.getDataFolder(), "languages/" + mainConfig.getLanguage() + ".yml")); loadVersionUtil(); loadDCommands(); loadRequirements(); @@ -107,8 +115,10 @@ public class DungeonsXL extends JavaPlugin { // Load All loadAll(); - // Scheduler - initSchedulers(); + // Tasks + startWorldUnloadTask(1200L); + startLazyUpdateTask(20L); + startUpdateTask(20L); // MSG getLogger().info("DungeonsXL " + getDescription().getVersion() + " for Spigot 1.8.8 loaded succesfully!"); @@ -121,7 +131,7 @@ public class DungeonsXL extends JavaPlugin { public void onDisable() { // Save saveData(); - dMessages.save(); + messageConfig.save(); // DPlayer leaves World for (DPlayer dplayer : dPlayers) { @@ -172,41 +182,6 @@ public class DungeonsXL extends JavaPlugin { } } - public void initSchedulers() { - plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { - @Override - public void run() { - for (GameWorld gameWorld : gameWorlds) { - if (gameWorld.getWorld().getPlayers().isEmpty()) { - if (DPlayer.getByWorld(gameWorld.getWorld()).isEmpty()) { - gameWorld.delete(); - } - } - } - for (EditWorld editWorld : editWorlds) { - if (editWorld.getWorld().getPlayers().isEmpty()) { - editWorld.delete(); - } - } - } - }, 0L, 1200L); - - plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { - @Override - public void run() { - GameWorld.update(); - DPlayer.update(true); - } - }, 0L, 20L); - - plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { - @Override - public void run() { - DPlayer.update(false); - } - }, 0L, 2L); - } - // Save and Load public void saveData() { File file = new File(getDataFolder(), "data.yml"); @@ -359,17 +334,17 @@ public class DungeonsXL extends JavaPlugin { } /** - * @return the loaded instance of DMessages + * @return the loaded instance of MessageConfig */ - public DMessages getDMessages() { - return dMessages; + public MessageConfig getMessageConfig() { + return messageConfig; } /** - * load / reload a new instance of DMessages + * load / reload a new instance of MessageConfig */ - public void loadDMessages(File file) { - dMessages = new DMessages(file); + public void loadMessageConfig(File file) { + messageConfig = new MessageConfig(file); } /** @@ -456,6 +431,48 @@ public class DungeonsXL extends JavaPlugin { dungeons = new Dungeons(); } + /** + * @return the worldUnloadTask + */ + public WorldUnloadTask getWorldUnloadTask() { + return worldUnloadTask; + } + + /** + * start a new WorldUnloadTask + */ + public void startWorldUnloadTask(long period) { + worldUnloadTask = (WorldUnloadTask) new WorldUnloadTask().runTaskTimerAsynchronously(this, 0L, period); + } + + /** + * @return the lazyUpdateTask + */ + public LazyUpdateTask getLazyUpdateTask() { + return lazyUpdateTask; + } + + /** + * start a new LazyUpdateTask + */ + public void startLazyUpdateTask(long period) { + lazyUpdateTask = (LazyUpdateTask) new LazyUpdateTask().runTaskTimerAsynchronously(this, 0L, period); + } + + /** + * @return the updateTask + */ + public UpdateTask getUpdateTask() { + return updateTask; + } + + /** + * start a new LazyUpdateTask + */ + public void startUpdateTask(long period) { + updateTask = (UpdateTask) new UpdateTask().runTaskTimerAsynchronously(this, 0L, period); + } + /** * @return the inBreakMode */ diff --git a/src/io/github/dre2n/dungeonsxl/command/BreakCommand.java b/src/io/github/dre2n/dungeonsxl/command/BreakCommand.java index bc1d0b3d..a50846b4 100644 --- a/src/io/github/dre2n/dungeonsxl/command/BreakCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/BreakCommand.java @@ -1,6 +1,6 @@ package io.github.dre2n.dungeonsxl.command; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import org.bukkit.command.CommandSender; @@ -12,7 +12,7 @@ public class BreakCommand extends DCommand { setCommand("break"); setMinArgs(0); setMaxArgs(0); - setHelp(dMessages.getMessage(Messages.HELP_CMD_BREAK)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_BREAK)); setPermission("dxl.break"); setPlayerCommand(true); } @@ -22,11 +22,11 @@ public class BreakCommand extends DCommand { Player player = (Player) sender; if ( !plugin.getInBreakMode().contains(player)) { plugin.getInBreakMode().add(player); - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.CMD_BREAK_BREAK_MODE)); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.CMD_BREAK_BREAK_MODE)); } else { plugin.getInBreakMode().remove(player); - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.CMD_BREAK_PROTECTED_MODE)); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.CMD_BREAK_PROTECTED_MODE)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java b/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java index c28f9f31..901667b2 100644 --- a/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java @@ -1,6 +1,6 @@ package io.github.dre2n.dungeonsxl.command; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -13,7 +13,7 @@ public class ChatCommand extends DCommand { setCommand("chat"); setMinArgs(0); setMaxArgs(0); - setHelp(dMessages.getMessage(Messages.HELP_CMD_CHAT)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_CHAT)); setPermission("dxl.chat"); setPlayerCommand(true); } @@ -24,17 +24,17 @@ public class ChatCommand extends DCommand { DPlayer dplayer = DPlayer.getByPlayer(player); if (dplayer == null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_IN_GROUP)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP)); return; } if (dplayer.isInDungeonChat()) { dplayer.setInDungeonChat(false); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_CHAT_NORMAL_CHAT)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_CHAT_NORMAL_CHAT)); } else { dplayer.setInDungeonChat(true); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_CHAT_DUNGEON_CHAT)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_CHAT_DUNGEON_CHAT)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/ChatSpyCommand.java b/src/io/github/dre2n/dungeonsxl/command/ChatSpyCommand.java index fe100e25..81783a69 100644 --- a/src/io/github/dre2n/dungeonsxl/command/ChatSpyCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/ChatSpyCommand.java @@ -1,6 +1,6 @@ package io.github.dre2n.dungeonsxl.command; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import org.bukkit.command.CommandSender; @@ -12,7 +12,7 @@ public class ChatSpyCommand extends DCommand { setCommand("chatspy"); setMinArgs(0); setMaxArgs(0); - setHelp(dMessages.getMessage(Messages.HELP_CMD_CHATSPY)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_CHATSPY)); setPermission("dxl.chatspy"); setPlayerCommand(true); } @@ -23,11 +23,11 @@ public class ChatSpyCommand extends DCommand { if (plugin.getChatSpyers().contains(player)) { plugin.getChatSpyers().remove(player); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_CHATSPY_STOPPED)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_CHATSPY_STOPPED)); } else { plugin.getChatSpyers().add(player); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_CHATSPY_START)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_CHATSPY_START)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/CreateCommand.java b/src/io/github/dre2n/dungeonsxl/command/CreateCommand.java index 350273de..d8f13aca 100644 --- a/src/io/github/dre2n/dungeonsxl/command/CreateCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/CreateCommand.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -15,7 +15,7 @@ public class CreateCommand extends DCommand { setMinArgs(1); setMaxArgs(1); setCommand("create"); - setHelp(dMessages.getMessage(Messages.HELP_CMD_CREATE)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_CREATE)); setPermission("dxl.create"); setPlayerCommand(true); setConsoleCommand(true); @@ -28,8 +28,8 @@ public class CreateCommand extends DCommand { if (sender instanceof ConsoleCommandSender) { if (name.length() <= 15) { // Msg create - plugin.getLogger().info(dMessages.getMessage(Messages.LOG_NEW_DUNGEON)); - plugin.getLogger().info(dMessages.getMessage(Messages.LOG_GENERATE_NEW_WORLD)); + plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_NEW_DUNGEON)); + plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_GENERATE_NEW_WORLD)); // Create World EditWorld editWorld = new EditWorld(); @@ -39,24 +39,24 @@ public class CreateCommand extends DCommand { editWorld.delete(); // MSG Done - plugin.getLogger().info(dMessages.getMessage(Messages.LOG_WORLD_GENERATION_FINISHED)); + plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_WORLD_GENERATION_FINISHED)); } else { - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.ERROR_NAME_TO_LONG)); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NAME_TO_LONG)); } } else if (sender instanceof Player) { Player player = (Player) sender; if (DPlayer.getByPlayer(player) != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON)); return; } if (name.length() <= 15) { // Msg create - plugin.getLogger().info(dMessages.getMessage(Messages.LOG_NEW_DUNGEON)); - plugin.getLogger().info(dMessages.getMessage(Messages.LOG_GENERATE_NEW_WORLD)); + plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_NEW_DUNGEON)); + plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_GENERATE_NEW_WORLD)); // Create World EditWorld editWorld = new EditWorld(); @@ -64,7 +64,7 @@ public class CreateCommand extends DCommand { editWorld.setMapName(name); // MSG Done - plugin.getLogger().info(dMessages.getMessage(Messages.LOG_WORLD_GENERATION_FINISHED)); + plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_WORLD_GENERATION_FINISHED)); // Tp Player if (editWorld.getLobby() == null) { @@ -75,7 +75,7 @@ public class CreateCommand extends DCommand { } } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NAME_TO_LONG)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NAME_TO_LONG)); } } } diff --git a/src/io/github/dre2n/dungeonsxl/command/DCommand.java b/src/io/github/dre2n/dungeonsxl/command/DCommand.java index 28ed7410..58816397 100644 --- a/src/io/github/dre2n/dungeonsxl/command/DCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/DCommand.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.command; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.file.DMessages; +import io.github.dre2n.dungeonsxl.config.MessageConfig; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import org.bukkit.ChatColor; @@ -11,7 +11,7 @@ import org.bukkit.entity.Player; public abstract class DCommand { static DungeonsXL plugin = DungeonsXL.getPlugin(); - DMessages dMessages = plugin.getDMessages(); + MessageConfig messageConfig = plugin.getMessageConfig(); public boolean costsMoney; private String command; diff --git a/src/io/github/dre2n/dungeonsxl/command/DeletePortalCommand.java b/src/io/github/dre2n/dungeonsxl/command/DeletePortalCommand.java index d3f55fe3..a5b4ccd0 100644 --- a/src/io/github/dre2n/dungeonsxl/command/DeletePortalCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/DeletePortalCommand.java @@ -1,6 +1,6 @@ package io.github.dre2n.dungeonsxl.command; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -29,10 +29,10 @@ public class DeletePortalCommand extends DCommand { if (dPortal != null) { dPortal.delete(); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED)); } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NO_PROTECTED_BLOCK)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NO_PROTECTED_BLOCK)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/EditCommand.java b/src/io/github/dre2n/dungeonsxl/command/EditCommand.java index 0d237e87..23a553f3 100644 --- a/src/io/github/dre2n/dungeonsxl/command/EditCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/EditCommand.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -15,7 +15,7 @@ public class EditCommand extends DCommand { setCommand("edit"); setMinArgs(1); setMaxArgs(1); - setHelp(dMessages.getMessage(Messages.HELP_CMD_EDIT)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_EDIT)); setPlayerCommand(true); } @@ -29,22 +29,22 @@ public class EditCommand extends DCommand { DPlayer dPlayer = DPlayer.getByPlayer(player); if ( !(EditWorld.isInvitedPlayer(mapName, player.getUniqueId(), player.getName()) || player.hasPermission("dxl.edit"))) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NO_PERMISSIONS)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NO_PERMISSIONS)); return; } if (dPlayer != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON)); return; } if (dGroup != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_GROUP)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); return; } if (editWorld == null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, mapName)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, mapName)); return; } diff --git a/src/io/github/dre2n/dungeonsxl/command/EscapeCommand.java b/src/io/github/dre2n/dungeonsxl/command/EscapeCommand.java index 3ce788a8..de69f1ce 100644 --- a/src/io/github/dre2n/dungeonsxl/command/EscapeCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/EscapeCommand.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -15,7 +15,7 @@ public class EscapeCommand extends DCommand { setCommand("escape"); setMinArgs(0); setMaxArgs(0); - setHelp(dMessages.getMessage(Messages.HELP_CMD_ESCAPE)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_ESCAPE)); setPermission("dxl.escape"); setPlayerCommand(true); } @@ -27,7 +27,7 @@ public class EscapeCommand extends DCommand { if (dPlayer != null) { if ( !dPlayer.isEditing()) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON)); return; } @@ -46,10 +46,10 @@ public class EscapeCommand extends DCommand { DGroup dGroup = DGroup.getByPlayer(player); if (dGroup != null) { dGroup.removePlayer(player); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_LEAVE_SUCCESS)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_LEAVE_SUCCESS)); return; } - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/HelpCommand.java b/src/io/github/dre2n/dungeonsxl/command/HelpCommand.java index 28670071..32df58e7 100644 --- a/src/io/github/dre2n/dungeonsxl/command/HelpCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/HelpCommand.java @@ -3,7 +3,7 @@ package io.github.dre2n.dungeonsxl.command; import java.util.ArrayList; import java.util.List; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.util.NumberUtil; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -15,7 +15,7 @@ public class HelpCommand extends DCommand { setCommand("help"); setMinArgs(0); setMaxArgs(1); - setHelp(dMessages.getMessage(Messages.HELP_CMD_HELP)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_HELP)); setPermission("dxl.help"); setPlayerCommand(true); setConsoleCommand(true); diff --git a/src/io/github/dre2n/dungeonsxl/command/InviteCommand.java b/src/io/github/dre2n/dungeonsxl/command/InviteCommand.java index b7885a77..727b3ca6 100644 --- a/src/io/github/dre2n/dungeonsxl/command/InviteCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/InviteCommand.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.util.UUIDUtil; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -13,7 +13,7 @@ public class InviteCommand extends DCommand { setMinArgs(2); setMaxArgs(2); setCommand("invite"); - setHelp(dMessages.getMessage(Messages.HELP_CMD_INVITE)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_INVITE)); setPermission("dxl.invite"); setPlayerCommand(true); setConsoleCommand(true); @@ -22,10 +22,10 @@ public class InviteCommand extends DCommand { @Override public void onExecute(String[] args, CommandSender sender) { if (EditWorld.addInvitedPlayer(args[2], UUIDUtil.getUniqueIdFromName(args[1]))) { - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.CMD_INVITE_SUCCESS, args[1], args[2])); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.CMD_INVITE_SUCCESS, args[1], args[2])); } else { - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, args[2])); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, args[2])); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/LeaveCommand.java b/src/io/github/dre2n/dungeonsxl/command/LeaveCommand.java index cf32a5e5..d076de40 100644 --- a/src/io/github/dre2n/dungeonsxl/command/LeaveCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/LeaveCommand.java @@ -1,8 +1,8 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEscapeEvent; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -16,7 +16,7 @@ public class LeaveCommand extends DCommand { setCommand("leave"); setMinArgs(0); setMaxArgs(0); - setHelp(dMessages.getMessage(Messages.HELP_CMD_LEAVE)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_LEAVE)); setPermission("dxl.leave"); setPlayerCommand(true); } @@ -28,7 +28,7 @@ public class LeaveCommand extends DCommand { if (GameWorld.getByWorld(player.getWorld()) != null) { if (GameWorld.getByWorld(player.getWorld()).isTutorial()) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NO_LEAVE_IN_TUTORIAL)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NO_LEAVE_IN_TUTORIAL)); return; } } @@ -41,17 +41,17 @@ public class LeaveCommand extends DCommand { } dPlayer.leave(); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_LEAVE_SUCCESS)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_LEAVE_SUCCESS)); } else { DGroup dGroup = DGroup.getByPlayer(player); if (dGroup != null) { dGroup.removePlayer(player); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_LEAVE_SUCCESS)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_LEAVE_SUCCESS)); return; } - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/ListCommand.java b/src/io/github/dre2n/dungeonsxl/command/ListCommand.java index d1fa43f5..6edc1f99 100644 --- a/src/io/github/dre2n/dungeonsxl/command/ListCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/ListCommand.java @@ -1,11 +1,11 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; +import io.github.dre2n.dungeonsxl.config.WorldConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; -import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.util.NumberUtil; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -20,7 +20,7 @@ public class ListCommand extends DCommand { setCommand("list"); setMinArgs(0); setMaxArgs(3); - setHelp(dMessages.getMessage(Messages.HELP_CMD_LIST)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_LIST)); setPermission("dxl.list"); setPlayerCommand(true); setConsoleCommand(true); diff --git a/src/io/github/dre2n/dungeonsxl/command/LivesCommand.java b/src/io/github/dre2n/dungeonsxl/command/LivesCommand.java index 12374914..be35f2fe 100644 --- a/src/io/github/dre2n/dungeonsxl/command/LivesCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/LivesCommand.java @@ -1,6 +1,6 @@ package io.github.dre2n.dungeonsxl.command; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -14,7 +14,7 @@ public class LivesCommand extends DCommand { setCommand("lives"); setMinArgs(0); setMaxArgs(1); - setHelp(dMessages.getMessage(Messages.HELP_CMD_LIVES)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_LIVES)); setPermission("dxl.lives"); setPlayerCommand(true); setConsoleCommand(true); @@ -33,16 +33,16 @@ public class LivesCommand extends DCommand { player = (Player) sender; } else { - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.ERROR_NO_CONSOLE_COMMAND, getCommand())); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_CONSOLE_COMMAND, getCommand())); return; } DPlayer dPlayer = DPlayer.getByPlayer(player); if (dPlayer != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_LIVES, player.getName(), String.valueOf(dPlayer.getLives()))); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_LIVES, player.getName(), String.valueOf(dPlayer.getLives()))); } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/MainCommand.java b/src/io/github/dre2n/dungeonsxl/command/MainCommand.java index 25543d9d..91335f3e 100644 --- a/src/io/github/dre2n/dungeonsxl/command/MainCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/MainCommand.java @@ -3,7 +3,7 @@ package io.github.dre2n.dungeonsxl.command; import java.io.File; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -15,7 +15,7 @@ public class MainCommand extends DCommand { public MainCommand() { setCommand("main"); - setHelp(dMessages.getMessage(Messages.HELP_CMD_MAIN)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_MAIN)); setPermission("dxl.main"); setPlayerCommand(true); setConsoleCommand(true); @@ -44,10 +44,10 @@ public class MainCommand extends DCommand { MessageUtil.sendCenteredMessage(sender, "&4" + MessageUtil.BIG_D[2] + "&f" + MessageUtil.BIG_X[2] + MessageUtil.BIG_L[2]); MessageUtil.sendCenteredMessage(sender, "&4" + MessageUtil.BIG_D[3] + "&f" + MessageUtil.BIG_X[3] + MessageUtil.BIG_L[3]); MessageUtil.sendCenteredMessage(sender, "&4" + MessageUtil.BIG_D[4] + "&f" + MessageUtil.BIG_X[4] + MessageUtil.BIG_L[4]); - MessageUtil.sendCenteredMessage(sender, "&b&l####### " + dMessages.getMessage(Messages.CMD_MAIN_WELCOME) + "&7 v" + plugin.getDescription().getVersion() + " &b&l#######"); - MessageUtil.sendCenteredMessage(sender, dMessages.getMessage(Messages.CMD_MAIN_LOADED, String.valueOf(maps), String.valueOf(dungeons), String.valueOf(loaded), String.valueOf(players))); - MessageUtil.sendCenteredMessage(sender, dMessages.getMessage(Messages.CMD_MAIN_COMPATIBILITY, String.valueOf(internals), vault, mythicMobs)); - MessageUtil.sendCenteredMessage(sender, dMessages.getMessage(Messages.CMD_MAIN_HELP)); + MessageUtil.sendCenteredMessage(sender, "&b&l####### " + messageConfig.getMessage(Messages.CMD_MAIN_WELCOME) + "&7 v" + plugin.getDescription().getVersion() + " &b&l#######"); + MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_LOADED, String.valueOf(maps), String.valueOf(dungeons), String.valueOf(loaded), String.valueOf(players))); + MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_COMPATIBILITY, String.valueOf(internals), vault, mythicMobs)); + MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_HELP)); MessageUtil.sendCenteredMessage(sender, "&7\u00a92012-2016 Frank Baumann & contributors; lcsd. under GPLv3."); } diff --git a/src/io/github/dre2n/dungeonsxl/command/MsgCommand.java b/src/io/github/dre2n/dungeonsxl/command/MsgCommand.java index 9d3acd65..07945db4 100644 --- a/src/io/github/dre2n/dungeonsxl/command/MsgCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/MsgCommand.java @@ -1,8 +1,8 @@ package io.github.dre2n.dungeonsxl.command; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; +import io.github.dre2n.dungeonsxl.config.WorldConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.util.NumberUtil; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -18,7 +18,7 @@ public class MsgCommand extends DCommand { setMinArgs( -1); setMaxArgs( -1); setCommand("msg"); - setHelp(dMessages.getMessage(Messages.HELP_CMD_MSG)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_MSG)); setPermission("dxl.msg"); setPlayerCommand(true); } @@ -29,7 +29,7 @@ public class MsgCommand extends DCommand { EditWorld editWorld = EditWorld.getByWorld(player.getWorld()); if (editWorld == null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); return; } @@ -50,7 +50,7 @@ public class MsgCommand extends DCommand { MessageUtil.sendMessage(player, ChatColor.WHITE + msg); } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_MSG_ID_NOT_EXIST, "" + id)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_MSG_ID_NOT_EXIST, "" + id)); } } else { @@ -69,22 +69,22 @@ public class MsgCommand extends DCommand { msg = splitMsg[1]; String old = confreader.getMsg(id, false); if (old == null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_MSG_ADDED, "" + id)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_MSG_ADDED, "" + id)); } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_MSG_UPDATED, "" + id)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_MSG_UPDATED, "" + id)); } confreader.setMsg(msg, id); confreader.save(); } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_MSG_FORMAT)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_MSG_FORMAT)); } } } catch (NumberFormatException e) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_MSG_NO_INT)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_MSG_NO_INT)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java index adea0235..2f9319dd 100644 --- a/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -1,11 +1,11 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.WorldConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -21,7 +21,7 @@ public class PlayCommand extends DCommand { setCommand("play"); setMinArgs(1); setMaxArgs(2); - setHelp(dMessages.getMessage(Messages.HELP_CMD_PLAY)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_PLAY)); setPermission("dxl.play"); setPlayerCommand(true); } @@ -32,7 +32,7 @@ public class PlayCommand extends DCommand { DPlayer dplayer = DPlayer.getByPlayer(player); if (dplayer != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON)); return; } @@ -63,8 +63,8 @@ public class PlayCommand extends DCommand { } } - if ( !multiFloor && !EditWorld.exist(identifier)) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, identifier)); + if ( !multiFloor && !EditWorld.exists(identifier)) { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, identifier)); return; } @@ -75,19 +75,19 @@ public class PlayCommand extends DCommand { WorldConfig confReader = new WorldConfig(file); if (confReader != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_COOLDOWN, "" + confReader.getTimeToNextPlay())); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_COOLDOWN, "" + confReader.getTimeToNextPlay())); } } return; } if ( !GameWorld.checkRequirements(mapName, player)) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_REQUIREMENTS)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_REQUIREMENTS)); return; } if (DGroup.getByPlayer(player) != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_GROUP)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); return; } @@ -108,7 +108,7 @@ public class PlayCommand extends DCommand { } if (dGroup.getGameWorld() == null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_SAVED, DGroup.getByPlayer(player).getMapName())); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_SAVED, DGroup.getByPlayer(player).getMapName())); dGroup.remove(); return; } diff --git a/src/io/github/dre2n/dungeonsxl/command/PortalCommand.java b/src/io/github/dre2n/dungeonsxl/command/PortalCommand.java index 1186ab2d..63817965 100644 --- a/src/io/github/dre2n/dungeonsxl/command/PortalCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/PortalCommand.java @@ -1,6 +1,6 @@ package io.github.dre2n.dungeonsxl.command; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -16,7 +16,7 @@ public class PortalCommand extends DCommand { setCommand("portal"); setMinArgs(0); setMaxArgs(0); - setHelp(dMessages.getMessage(Messages.HELP_CMD_PORTAL)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_PORTAL)); setPermission("dxl.portal"); setPlayerCommand(true); } @@ -27,7 +27,7 @@ public class PortalCommand extends DCommand { DPlayer dPlayer = DPlayer.getByPlayer(player); if (dPlayer != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON)); } DPortal dPortal = DPortal.getByPlayer(player); @@ -37,11 +37,11 @@ public class PortalCommand extends DCommand { dPortal.setPlayer(player); dPortal.setWorld(player.getWorld()); player.getInventory().setItemInHand(new ItemStack(Material.WOOD_SWORD)); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.PLAYER_PORTAL_INTRODUCTION)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PORTAL_INTRODUCTION)); } else { plugin.getDPortals().remove(dPortal); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.PLAYER_PORTAL_ABORT)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PORTAL_ABORT)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/ReloadCommand.java b/src/io/github/dre2n/dungeonsxl/command/ReloadCommand.java index 2970f3b2..0cc6372c 100644 --- a/src/io/github/dre2n/dungeonsxl/command/ReloadCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/ReloadCommand.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.command; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -17,7 +17,7 @@ public class ReloadCommand extends DCommand { setCommand("reload"); setMinArgs(0); setMaxArgs(0); - setHelp(dMessages.getMessage(Messages.HELP_CMD_RELOAD)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_RELOAD)); setPermission("dxl.reload"); setPlayerCommand(true); setConsoleCommand(true); @@ -43,19 +43,19 @@ public class ReloadCommand extends DCommand { // Save plugin.saveData(); - plugin.getDMessages().save(); + plugin.getMessageConfig().save(); // Load Config plugin.loadMainConfig(new File(plugin.getDataFolder(), "config.yml")); - plugin.loadDMessages(new File(plugin.getDataFolder(), "languages/" + plugin.getMainConfig().getLanguage() + ".yml")); + plugin.loadMessageConfig(new File(plugin.getDataFolder(), "languages/" + plugin.getMainConfig().getLanguage() + ".yml")); plugin.loadVersionUtil(); plugin.loadDCommands(); plugin.loadDungeons(); MessageUtil.sendPluginTag(sender, plugin); - MessageUtil.sendCenteredMessage(sender, dMessages.getMessage(Messages.CMD_RELOAD_DONE)); - MessageUtil.sendCenteredMessage(sender, dMessages.getMessage(Messages.CMD_MAIN_LOADED, String.valueOf(maps), String.valueOf(dungeons), String.valueOf(loaded), String.valueOf(players))); - MessageUtil.sendCenteredMessage(sender, dMessages.getMessage(Messages.CMD_MAIN_COMPATIBILITY, String.valueOf(internals), vault, mythicMobs)); + MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_RELOAD_DONE)); + MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_LOADED, String.valueOf(maps), String.valueOf(dungeons), String.valueOf(loaded), String.valueOf(players))); + MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_COMPATIBILITY, String.valueOf(internals), vault, mythicMobs)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/SaveCommand.java b/src/io/github/dre2n/dungeonsxl/command/SaveCommand.java index 91909fed..ed1ca3d1 100644 --- a/src/io/github/dre2n/dungeonsxl/command/SaveCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/SaveCommand.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import org.bukkit.command.CommandSender; @@ -13,7 +13,7 @@ public class SaveCommand extends DCommand { setCommand("save"); setMinArgs(0); setMaxArgs(0); - setHelp(dMessages.getMessage(Messages.HELP_CMD_SAVE)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_SAVE)); setPermission("dxl.save"); setPlayerCommand(true); } @@ -24,10 +24,10 @@ public class SaveCommand extends DCommand { EditWorld editWorld = EditWorld.getByWorld(player.getWorld()); if (editWorld != null) { editWorld.save(); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_SAVE_SUCCESS)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_SAVE_SUCCESS)); } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON)); } } diff --git a/src/io/github/dre2n/dungeonsxl/command/TestCommand.java b/src/io/github/dre2n/dungeonsxl/command/TestCommand.java index 23cee7cf..776a8a8e 100644 --- a/src/io/github/dre2n/dungeonsxl/command/TestCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/TestCommand.java @@ -1,10 +1,10 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -18,7 +18,7 @@ public class TestCommand extends DCommand { setCommand("test"); setMinArgs(1); setMaxArgs(2); - setHelp(dMessages.getMessage(Messages.HELP_CMD_TEST)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_TEST)); setPermission("dxl.test"); setPlayerCommand(true); } @@ -29,7 +29,7 @@ public class TestCommand extends DCommand { DPlayer dplayer = DPlayer.getByPlayer(player); if (dplayer != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_DUNGEON)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON)); return; } @@ -57,13 +57,13 @@ public class TestCommand extends DCommand { } } - if ( !multiFloor && !EditWorld.exist(identifier)) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, identifier)); + if ( !multiFloor && !EditWorld.exists(identifier)) { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, identifier)); return; } if (DGroup.getByPlayer(player) != null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEAVE_GROUP)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); return; } @@ -84,7 +84,7 @@ public class TestCommand extends DCommand { } if (dGroup.getGameWorld() == null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_SAVED, DGroup.getByPlayer(player).getMapName())); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_SAVED, DGroup.getByPlayer(player).getMapName())); dGroup.remove(); return; } diff --git a/src/io/github/dre2n/dungeonsxl/command/UninviteCommand.java b/src/io/github/dre2n/dungeonsxl/command/UninviteCommand.java index 7c8622ba..0ceca63b 100644 --- a/src/io/github/dre2n/dungeonsxl/command/UninviteCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/UninviteCommand.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.util.UUIDUtil; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -13,7 +13,7 @@ public class UninviteCommand extends DCommand { setCommand("uninvite"); setMinArgs(2); setMaxArgs(2); - setHelp(dMessages.getMessage(Messages.HELP_CMD_UNINVITE)); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_UNINVITE)); setPermission("dxl.uninvite"); setPlayerCommand(true); setConsoleCommand(true); @@ -22,10 +22,10 @@ public class UninviteCommand extends DCommand { @Override public void onExecute(String[] args, CommandSender sender) { if (EditWorld.removeInvitedPlayer(args[2], UUIDUtil.getUniqueIdFromName(args[1]), args[1])) { - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.CMD_UNINVITE_SUCCESS, args[1], args[2])); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.CMD_UNINVITE_SUCCESS, args[1], args[2])); } else { - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, args[2])); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, args[2])); } } diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/DungeonConfig.java b/src/io/github/dre2n/dungeonsxl/config/DungeonConfig.java similarity index 98% rename from src/io/github/dre2n/dungeonsxl/dungeon/DungeonConfig.java rename to src/io/github/dre2n/dungeonsxl/config/DungeonConfig.java index 5cc271bc..9775e1db 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/DungeonConfig.java +++ b/src/io/github/dre2n/dungeonsxl/config/DungeonConfig.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.dungeon; +package io.github.dre2n.dungeonsxl.config; import java.io.File; import java.util.ArrayList; diff --git a/src/io/github/dre2n/dungeonsxl/file/MainConfig.java b/src/io/github/dre2n/dungeonsxl/config/MainConfig.java similarity index 87% rename from src/io/github/dre2n/dungeonsxl/file/MainConfig.java rename to src/io/github/dre2n/dungeonsxl/config/MainConfig.java index f0f19e49..f3893dee 100644 --- a/src/io/github/dre2n/dungeonsxl/file/MainConfig.java +++ b/src/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -1,6 +1,4 @@ -package io.github.dre2n.dungeonsxl.file; - -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; +package io.github.dre2n.dungeonsxl.config; import java.io.File; import java.io.IOException; @@ -23,7 +21,7 @@ public class MainConfig { private String tutorialEndGroup = "player"; /* Default Dungeon Settings */ - public WorldConfig defaultDungeon; + private WorldConfig defaultWorldConfig; private List editCommandWhitelist = new ArrayList(); @@ -92,8 +90,8 @@ public class MainConfig { /* Default Dungeon Config */ ConfigurationSection configSection = configFile.getConfigurationSection("default"); if (configSection != null) { - defaultDungeon = new WorldConfig(configSection); - WorldConfig.defaultConfig = defaultDungeon; + setDefaultWorldConfig(new WorldConfig(configSection)); + WorldConfig.defaultConfig = defaultWorldConfig;// TODO } } } @@ -155,4 +153,19 @@ public class MainConfig { return editCommandWhitelist; } + /** + * @return the defaultWorldConfig + */ + public WorldConfig getDefaultWorldConfig() { + return defaultWorldConfig; + } + + /** + * @param defaultWorldConfig + * the defaultWorldConfig to set + */ + public void setDefaultWorldConfig(WorldConfig defaultWorldConfig) { + this.defaultWorldConfig = defaultWorldConfig; + } + } diff --git a/src/io/github/dre2n/dungeonsxl/file/DMessages.java b/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java similarity index 99% rename from src/io/github/dre2n/dungeonsxl/file/DMessages.java rename to src/io/github/dre2n/dungeonsxl/config/MessageConfig.java index 34cb575d..d2c00856 100644 --- a/src/io/github/dre2n/dungeonsxl/file/DMessages.java +++ b/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.file; +package io.github.dre2n.dungeonsxl.config; import java.io.File; import java.io.IOException; @@ -7,7 +7,7 @@ import java.util.Set; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -public class DMessages { +public class MessageConfig { public enum Messages { @@ -175,7 +175,7 @@ public class DMessages { private File file; private FileConfiguration config; - public DMessages(File file) { + public MessageConfig(File file) { this.file = file; if ( !file.exists()) { diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/WorldConfig.java b/src/io/github/dre2n/dungeonsxl/config/WorldConfig.java similarity index 99% rename from src/io/github/dre2n/dungeonsxl/dungeon/WorldConfig.java rename to src/io/github/dre2n/dungeonsxl/config/WorldConfig.java index fdf576e8..de9e8308 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/WorldConfig.java +++ b/src/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.dungeon; +package io.github.dre2n.dungeonsxl.config; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.mob.DMobType; @@ -31,6 +31,7 @@ public class WorldConfig { static DungeonsXL plugin = DungeonsXL.getPlugin(); + @Deprecated public static WorldConfig defaultConfig = new WorldConfig(); private File file; diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/DLootInventory.java b/src/io/github/dre2n/dungeonsxl/dungeon/DLootInventory.java index 96cc68c2..86a40561 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/DLootInventory.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/DLootInventory.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.dungeon; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -23,7 +23,7 @@ public class DLootInventory { public DLootInventory(Player player, ItemStack[] itemStacks) { plugin.getDLootInventories().add(this); - inventory = Bukkit.createInventory(player, 54, ChatColor.translateAlternateColorCodes('&', plugin.getDMessages().getMessage(Messages.PLAYER_TREASURES))); + inventory = Bukkit.createInventory(player, 54, ChatColor.translateAlternateColorCodes('&', plugin.getMessageConfig().getMessage(Messages.PLAYER_TREASURES))); for (ItemStack itemStack : itemStacks) { if (itemStack != null) { inventory.addItem(itemStack); @@ -32,20 +32,6 @@ public class DLootInventory { this.player = player; } - /** - * @param player - * the player whose DLootIntentory will be returned - */ - public static DLootInventory getByPlayer(Player player) { - for (DLootInventory inventory : plugin.getDLootInventories()) { - if (inventory.player == player) { - return inventory; - } - } - - return null; - } - /** * @return the inventory */ @@ -106,4 +92,20 @@ public class DLootInventory { this.time = time; } + // Static + + /** + * @param player + * the player whose DLootIntentory will be returned + */ + public static DLootInventory getByPlayer(Player player) { + for (DLootInventory inventory : plugin.getDLootInventories()) { + if (inventory.player == player) { + return inventory; + } + } + + return null; + } + } diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java b/src/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java index 74cd3cc0..222c8683 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java @@ -1,6 +1,7 @@ package io.github.dre2n.dungeonsxl.dungeon; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; import java.io.File; diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java b/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java index 7dd62a4c..1fe8f6b5 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java @@ -1,6 +1,7 @@ package io.github.dre2n.dungeonsxl.dungeon; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.event.editworld.EditWorldGenerateEvent; import io.github.dre2n.dungeonsxl.event.editworld.EditWorldLoadEvent; import io.github.dre2n.dungeonsxl.event.editworld.EditWorldSaveEvent; @@ -64,277 +65,6 @@ public class EditWorld { name = "DXL_Edit_" + id; } - public void generate() { - WorldCreator creator = WorldCreator.name(name); - creator.type(WorldType.FLAT); - creator.generateStructures(false); - - EditWorldGenerateEvent event = new EditWorldGenerateEvent(this); - - if (event.isCancelled()) { - return; - } - - world = plugin.getServer().createWorld(creator); - } - - public void save() { - EditWorldSaveEvent event = new EditWorldSaveEvent(this); - - if (event.isCancelled()) { - return; - } - - world.save(); - - File dir = new File("DXL_Edit_" + id); - FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName)); - FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName)); - - try { - ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File(plugin.getDataFolder(), "/maps/" + mapName + "/DXLData.data"))); - out.writeInt(sign.size()); - for (Block sign : this.sign) { - out.writeInt(sign.getX()); - out.writeInt(sign.getY()); - out.writeInt(sign.getZ()); - } - out.close(); - - } catch (IOException exception) { - } - } - - public void checkSign(Block block) { - if (block.getState() instanceof Sign) { - Sign sign = (Sign) block.getState(); - String[] lines = sign.getLines(); - - if (lines[0].equalsIgnoreCase("[lobby]")) { - lobby = block.getLocation(); - } - } - } - - public void delete() { - EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, true); - - if (event.isCancelled()) { - return; - } - - plugin.getEditWorlds().remove(this); - for (Player player : world.getPlayers()) { - DPlayer dPlayer = DPlayer.getByPlayer(player); - dPlayer.leave(); - } - - plugin.getServer().unloadWorld(world, true); - File dir = new File("DXL_Edit_" + id); - FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName)); - FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName)); - FileUtil.removeDirectory(dir); - } - - public void deleteNoSave() { - EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, false); - - if (event.isCancelled()) { - return; - } - - plugin.getEditWorlds().remove(this); - for (Player player : world.getPlayers()) { - DPlayer dPlayer = DPlayer.getByPlayer(player); - dPlayer.leave(); - } - - File dir = new File("DXL_Edit_" + id); - FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName)); - FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName)); - plugin.getServer().unloadWorld(world, true); - FileUtil.removeDirectory(dir); - } - - // Static - public static EditWorld getByWorld(World world) { - for (EditWorld editWorld : plugin.getEditWorlds()) { - if (editWorld.world.equals(world)) { - return editWorld; - } - } - - return null; - } - - public static EditWorld getByName(String name) { - for (EditWorld editWorld : plugin.getEditWorlds()) { - if (editWorld.mapName.equalsIgnoreCase(name)) { - return editWorld; - } - } - - return null; - } - - public static void deleteAll() { - for (EditWorld editWorld : plugin.getEditWorlds()) { - editWorld.delete(); - } - } - - public static EditWorld load(String name) { - EditWorldLoadEvent event = new EditWorldLoadEvent(name); - - if (event.isCancelled()) { - return null; - } - - for (EditWorld editWorld : plugin.getEditWorlds()) { - - if (editWorld.mapName.equalsIgnoreCase(name)) { - return editWorld; - } - } - - File file = new File(plugin.getDataFolder(), "/maps/" + name); - - if (file.exists()) { - EditWorld editWorld = new EditWorld(); - editWorld.mapName = name; - // World - FileUtil.copyDirectory(file, new File("DXL_Edit_" + editWorld.id)); - - // Id File - File idFile = new File("DXL_Edit_" + editWorld.id + "/.id_" + name); - try { - idFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - - editWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Edit_" + editWorld.id)); - - try { - ObjectInputStream os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder(), "/maps/" + editWorld.mapName + "/DXLData.data"))); - int length = os.readInt(); - for (int i = 0; i < length; i++) { - int x = os.readInt(); - int y = os.readInt(); - int z = os.readInt(); - Block block = editWorld.world.getBlockAt(x, y, z); - editWorld.checkSign(block); - editWorld.sign.add(block); - } - os.close(); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - return editWorld; - } - - return null; - } - - public static boolean exist(String name) { - // Cheack Loaded EditWorlds - for (EditWorld editWorld : plugin.getEditWorlds()) { - if (editWorld.mapName.equalsIgnoreCase(name)) { - return true; - } - } - - // Cheack Unloaded Worlds - File file = new File(plugin.getDataFolder(), "/maps/" + name); - - if (file.exists()) { - return true; - } - - return false; - } - - public void msg(String msg) { - for (DPlayer dPlayer : DPlayer.getByWorld(world)) { - MessageUtil.sendMessage(dPlayer.getPlayer(), msg); - } - } - - // Invite - public static boolean addInvitedPlayer(String editWorldName, UUID uuid) { - if ( !exist(editWorldName)) { - return false; - } - - File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); - if ( !file.exists()) { - try { - file.createNewFile(); - - } catch (IOException exception) { - exception.printStackTrace(); - return false; - } - } - WorldConfig config = new WorldConfig(file); - config.addInvitedPlayer(uuid.toString()); - config.save(); - - return true; - } - - public static boolean removeInvitedPlayer(String editWorldName, UUID uuid, String name) { - if ( !exist(editWorldName)) { - return false; - } - - File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); - if ( !file.exists()) { - return false; - } - WorldConfig config = new WorldConfig(file); - config.removeInvitedPlayers(uuid.toString(), name.toLowerCase()); - config.save(); - - // Kick Player - EditWorld editWorld = EditWorld.getByName(editWorldName); - if (editWorld != null) { - DPlayer player = DPlayer.getByName(name); - - if (player != null) { - if (editWorld.world.getPlayers().contains(player.getPlayer())) { - player.leave(); - } - } - } - - return true; - } - - public static boolean isInvitedPlayer(String editWorldName, UUID uuid, String name) { - if ( !exist(editWorldName)) { - return false; - } - - File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); - if ( !file.exists()) { - return false; - } - - WorldConfig config = new WorldConfig(file); - // get player from both a 0.9.1 and lower and 0.9.2 and higher file - if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString())) { - return true; - - } else { - return false; - } - } - /** * @return the world */ @@ -455,4 +185,276 @@ public class EditWorld { this.sign = sign; } + public void generate() { + WorldCreator creator = WorldCreator.name(name); + creator.type(WorldType.FLAT); + creator.generateStructures(false); + + EditWorldGenerateEvent event = new EditWorldGenerateEvent(this); + + if (event.isCancelled()) { + return; + } + + world = plugin.getServer().createWorld(creator); + } + + public void save() { + EditWorldSaveEvent event = new EditWorldSaveEvent(this); + + if (event.isCancelled()) { + return; + } + + world.save(); + + File dir = new File("DXL_Edit_" + id); + FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName)); + FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName)); + + try { + ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File(plugin.getDataFolder(), "/maps/" + mapName + "/DXLData.data"))); + out.writeInt(sign.size()); + for (Block sign : this.sign) { + out.writeInt(sign.getX()); + out.writeInt(sign.getY()); + out.writeInt(sign.getZ()); + } + out.close(); + + } catch (IOException exception) { + } + } + + public void checkSign(Block block) { + if (block.getState() instanceof Sign) { + Sign sign = (Sign) block.getState(); + String[] lines = sign.getLines(); + + if (lines[0].equalsIgnoreCase("[lobby]")) { + lobby = block.getLocation(); + } + } + } + + public void delete() { + EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, true); + + if (event.isCancelled()) { + return; + } + + plugin.getEditWorlds().remove(this); + for (Player player : world.getPlayers()) { + DPlayer dPlayer = DPlayer.getByPlayer(player); + dPlayer.leave(); + } + + plugin.getServer().unloadWorld(world, true); + File dir = new File("DXL_Edit_" + id); + FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName)); + FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName)); + FileUtil.removeDirectory(dir); + } + + public void deleteNoSave() { + EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, false); + + if (event.isCancelled()) { + return; + } + + plugin.getEditWorlds().remove(this); + for (Player player : world.getPlayers()) { + DPlayer dPlayer = DPlayer.getByPlayer(player); + dPlayer.leave(); + } + + File dir = new File("DXL_Edit_" + id); + FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName)); + FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName)); + plugin.getServer().unloadWorld(world, true); + FileUtil.removeDirectory(dir); + } + + public void sendMessage(String message) { + for (DPlayer dPlayer : DPlayer.getByWorld(world)) { + MessageUtil.sendMessage(dPlayer.getPlayer(), message); + } + } + + // Static + + public static EditWorld getByWorld(World world) { + for (EditWorld editWorld : plugin.getEditWorlds()) { + if (editWorld.world.equals(world)) { + return editWorld; + } + } + + return null; + } + + public static EditWorld getByName(String name) { + for (EditWorld editWorld : plugin.getEditWorlds()) { + if (editWorld.mapName.equalsIgnoreCase(name)) { + return editWorld; + } + } + + return null; + } + + public static void deleteAll() { + for (EditWorld editWorld : plugin.getEditWorlds()) { + editWorld.delete(); + } + } + + public static EditWorld load(String name) { + EditWorldLoadEvent event = new EditWorldLoadEvent(name); + + if (event.isCancelled()) { + return null; + } + + for (EditWorld editWorld : plugin.getEditWorlds()) { + + if (editWorld.mapName.equalsIgnoreCase(name)) { + return editWorld; + } + } + + File file = new File(plugin.getDataFolder(), "/maps/" + name); + + if (file.exists()) { + EditWorld editWorld = new EditWorld(); + editWorld.mapName = name; + // World + FileUtil.copyDirectory(file, new File("DXL_Edit_" + editWorld.id)); + + // Id File + File idFile = new File("DXL_Edit_" + editWorld.id + "/.id_" + name); + try { + idFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + + editWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Edit_" + editWorld.id)); + + try { + ObjectInputStream os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder(), "/maps/" + editWorld.mapName + "/DXLData.data"))); + int length = os.readInt(); + for (int i = 0; i < length; i++) { + int x = os.readInt(); + int y = os.readInt(); + int z = os.readInt(); + Block block = editWorld.world.getBlockAt(x, y, z); + editWorld.checkSign(block); + editWorld.sign.add(block); + } + os.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return editWorld; + } + + return null; + } + + public static boolean exists(String name) { + // Cheack Loaded EditWorlds + for (EditWorld editWorld : plugin.getEditWorlds()) { + if (editWorld.mapName.equalsIgnoreCase(name)) { + return true; + } + } + + // Cheack Unloaded Worlds + File file = new File(plugin.getDataFolder(), "/maps/" + name); + + if (file.exists()) { + return true; + } + + return false; + } + + // Invite + public static boolean addInvitedPlayer(String editWorldName, UUID uuid) { + if ( !exists(editWorldName)) { + return false; + } + + File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); + if ( !file.exists()) { + try { + file.createNewFile(); + + } catch (IOException exception) { + exception.printStackTrace(); + return false; + } + } + WorldConfig config = new WorldConfig(file); + config.addInvitedPlayer(uuid.toString()); + config.save(); + + return true; + } + + public static boolean removeInvitedPlayer(String editWorldName, UUID uuid, String name) { + if ( !exists(editWorldName)) { + return false; + } + + File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); + if ( !file.exists()) { + return false; + } + WorldConfig config = new WorldConfig(file); + config.removeInvitedPlayers(uuid.toString(), name.toLowerCase()); + config.save(); + + // Kick Player + EditWorld editWorld = EditWorld.getByName(editWorldName); + if (editWorld != null) { + DPlayer player = DPlayer.getByName(name); + + if (player != null) { + if (editWorld.world.getPlayers().contains(player.getPlayer())) { + player.leave(); + } + } + } + + return true; + } + + public static boolean isInvitedPlayer(String editWorldName, UUID uuid, String name) { + if ( !exists(editWorldName)) { + return false; + } + + File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); + if ( !file.exists()) { + return false; + } + + WorldConfig config = new WorldConfig(file); + // get player from both a 0.9.1 and lower and 0.9.2 and higher file + if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString())) { + return true; + + } else { + return false; + } + } + } diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/game/GameChest.java b/src/io/github/dre2n/dungeonsxl/dungeon/game/GameChest.java index b43e70e0..21d2387f 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/game/GameChest.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/game/GameChest.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.dungeon.game; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.reward.Reward; @@ -44,105 +44,6 @@ public class GameChest { gameWorld.getGameChests().add(this); } - public void addTreasure(DGroup dGroup) { - if (dGroup == null) { - return; - } - - boolean hasMoneyReward = false; - - for (Reward reward : dGroup.getRewards()) { - if (reward instanceof MoneyReward) { - hasMoneyReward = true; - ((MoneyReward) reward).addMoney(moneyReward); - } - } - - if ( !hasMoneyReward) { - Reward reward = Reward.create(RewardTypeDefault.MONEY); - ((MoneyReward) reward).addMoney(moneyReward); - dGroup.addReward(reward); - } - - for (Player player : dGroup.getPlayers()) { - DPlayer dPlayer = DPlayer.getByPlayer(player); - if (dPlayer == null) { - continue; - } - - String msg = ""; - for (ItemStack itemStack : chest.getInventory().getContents()) { - - if (itemStack == null) { - continue; - } - - dPlayer.getTreasureInv().addItem(itemStack); - String name = null; - - if (itemStack.hasItemMeta()) { - if (itemStack.getItemMeta().hasDisplayName()) { - name = itemStack.getItemMeta().getDisplayName(); - } - - } - - if (name == null && Bukkit.getPluginManager().getPlugin("Vault") != null) { - ItemInfo itemInfo = Items.itemByStack(itemStack); - if (itemInfo != null) { - name = itemInfo.getName(); - } else { - name = itemStack.getType().name(); - } - } - - msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ","; - } - - msg = msg.substring(0, msg.length() - 1); - - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, msg)); - if (moneyReward != 0) { - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, plugin.getEconomyProvider().format(moneyReward))); - } - } - } - - // Statics - public static void onOpenInventory(InventoryOpenEvent event) { - InventoryView inventory = event.getView(); - - GameWorld gameWorld = GameWorld.getByWorld(event.getPlayer().getWorld()); - - if (gameWorld == null) { - return; - } - - if ( !(inventory.getTopInventory().getHolder() instanceof Chest)) { - return; - } - - Chest chest = (Chest) inventory.getTopInventory().getHolder(); - - for (GameChest gameChest : gameWorld.getGameChests()) { - if ( !gameChest.chest.equals(chest)) { - continue; - } - - if (gameChest.used) { - MessageUtil.sendMessage(plugin.getServer().getPlayer(event.getPlayer().getUniqueId()), plugin.getDMessages().getMessage(Messages.ERROR_CHEST_IS_OPENED)); - event.setCancelled(true); - continue; - } - - if (gameChest.chest.getLocation().distance(chest.getLocation()) < 1) { - gameChest.addTreasure(DGroup.getByGameWorld(gameWorld)); - gameChest.used = true; - event.setCancelled(true); - } - } - } - /** * @return if the GameChest is used */ @@ -203,4 +104,103 @@ public class GameChest { this.moneyReward = moneyReward; } + public void addTreasure(DGroup dGroup) { + if (dGroup == null) { + return; + } + + boolean hasMoneyReward = false; + + for (Reward reward : dGroup.getRewards()) { + if (reward instanceof MoneyReward) { + hasMoneyReward = true; + ((MoneyReward) reward).addMoney(moneyReward); + } + } + + if ( !hasMoneyReward) { + Reward reward = Reward.create(RewardTypeDefault.MONEY); + ((MoneyReward) reward).addMoney(moneyReward); + dGroup.addReward(reward); + } + + for (Player player : dGroup.getPlayers()) { + DPlayer dPlayer = DPlayer.getByPlayer(player); + if (dPlayer == null) { + continue; + } + + String msg = ""; + for (ItemStack itemStack : chest.getInventory().getContents()) { + + if (itemStack == null) { + continue; + } + + dPlayer.getTreasureInv().addItem(itemStack); + String name = null; + + if (itemStack.hasItemMeta()) { + if (itemStack.getItemMeta().hasDisplayName()) { + name = itemStack.getItemMeta().getDisplayName(); + } + + } + + if (name == null && Bukkit.getPluginManager().getPlugin("Vault") != null) { + ItemInfo itemInfo = Items.itemByStack(itemStack); + if (itemInfo != null) { + name = itemInfo.getName(); + } else { + name = itemStack.getType().name(); + } + } + + msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ","; + } + + msg = msg.substring(0, msg.length() - 1); + + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_LOOT_ADDED, msg)); + if (moneyReward != 0) { + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_LOOT_ADDED, plugin.getEconomyProvider().format(moneyReward))); + } + } + } + + // Statics + public static void onOpenInventory(InventoryOpenEvent event) { + InventoryView inventory = event.getView(); + + GameWorld gameWorld = GameWorld.getByWorld(event.getPlayer().getWorld()); + + if (gameWorld == null) { + return; + } + + if ( !(inventory.getTopInventory().getHolder() instanceof Chest)) { + return; + } + + Chest chest = (Chest) inventory.getTopInventory().getHolder(); + + for (GameChest gameChest : gameWorld.getGameChests()) { + if ( !gameChest.chest.equals(chest)) { + continue; + } + + if (gameChest.used) { + MessageUtil.sendMessage(plugin.getServer().getPlayer(event.getPlayer().getUniqueId()), plugin.getMessageConfig().getMessage(Messages.ERROR_CHEST_IS_OPENED)); + event.setCancelled(true); + continue; + } + + if (gameChest.chest.getLocation().distance(chest.getLocation()) < 1) { + gameChest.addTreasure(DGroup.getByGameWorld(gameWorld)); + gameChest.used = true; + event.setCancelled(true); + } + } + } + } diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/game/GamePlaceableBlock.java b/src/io/github/dre2n/dungeonsxl/dungeon/game/GamePlaceableBlock.java index d84d5eb7..dce9a2ad 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/game/GamePlaceableBlock.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/game/GamePlaceableBlock.java @@ -238,7 +238,7 @@ public class GamePlaceableBlock { } } - // Canbuild + // Can build public static boolean canBuildHere(Block block, BlockFace blockFace, Material mat, GameWorld gameWorld) { for (GamePlaceableBlock gamePlacableBlock : gameWorld.getPlaceableBlocks()) { if (gamePlacableBlock.block.getFace(block) != BlockFace.SELF) { diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java b/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java index b8286b6b..f09542a4 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java @@ -1,9 +1,9 @@ package io.github.dre2n.dungeonsxl.dungeon.game; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; +import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; -import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldLoadEvent; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent; @@ -83,49 +83,6 @@ public class GameWorld { } } - public void checkSign(Block block) { - if (block.getState() instanceof Sign) { - Sign sign = (Sign) block.getState(); - dSigns.add(DSign.create(sign, this)); - } - } - - public void startGame() { - GameWorldStartGameEvent event = new GameWorldStartGameEvent(this); - - if (event.isCancelled()) { - return; - } - - isPlaying = true; - - for (DSign dSign : dSigns) { - if (dSign != null) { - if ( !dSign.getType().isOnDungeonInit()) { - dSign.onInit(); - } - } - } - if (RedstoneTrigger.hasTriggers(this)) { - for (RedstoneTrigger trigger : RedstoneTrigger.getTriggersArray(this)) { - trigger.onTrigger(); - } - } - for (DSign dSign : dSigns) { - if (dSign != null) { - if ( !dSign.hasTriggers()) { - dSign.onTrigger(); - } - } - } - } - - public void msg(String msg) { - for (DPlayer dPlayer : DPlayer.getByWorld(world)) { - MessageUtil.sendMessage(dPlayer.getPlayer(), msg); - } - } - /** * @return the tutorial */ @@ -365,8 +322,154 @@ public class GameWorld { return null; } + public void checkSign(Block block) { + if (block.getState() instanceof Sign) { + Sign sign = (Sign) block.getState(); + dSigns.add(DSign.create(sign, this)); + } + } + + public void startGame() { + GameWorldStartGameEvent event = new GameWorldStartGameEvent(this); + + if (event.isCancelled()) { + return; + } + + isPlaying = true; + + for (DSign dSign : dSigns) { + if (dSign != null) { + if ( !dSign.getType().isOnDungeonInit()) { + dSign.onInit(); + } + } + } + if (RedstoneTrigger.hasTriggers(this)) { + for (RedstoneTrigger trigger : RedstoneTrigger.getTriggersArray(this)) { + trigger.onTrigger(); + } + } + for (DSign dSign : dSigns) { + if (dSign != null) { + if ( !dSign.hasTriggers()) { + dSign.onTrigger(); + } + } + } + } + + public void sendMessage(String message) { + for (DPlayer dPlayer : DPlayer.getByWorld(world)) { + MessageUtil.sendMessage(dPlayer.getPlayer(), message); + } + } + + public void delete() { + GameWorldUnloadEvent event = new GameWorldUnloadEvent(this); + + if (event.isCancelled()) { + return; + } + + plugin.getGameWorlds().remove(this); + plugin.getServer().unloadWorld(world, true); + File dir = new File("DXL_Game_" + id); + FileUtil.removeDirectory(dir); + } + + public void update() { + if (getWorld() == null) { + return; + } + + // Update Spiders + for (LivingEntity mob : getWorld().getLivingEntities()) { + if (mob.getType() == EntityType.SPIDER || mob.getType() == EntityType.CAVE_SPIDER) { + Spider spider = (Spider) mob; + if (spider.getTarget() != null) { + if (spider.getTarget().getType() == EntityType.PLAYER) { + continue; + } + } + for (Entity player : spider.getNearbyEntities(10, 10, 10)) { + if (player.getType() == EntityType.PLAYER) { + spider.setTarget((LivingEntity) player); + } + } + } + } + } + // Statics + public static GameWorld load(String name) { + GameWorldLoadEvent event = new GameWorldLoadEvent(name); + + if (event.isCancelled()) { + return null; + } + + File file = new File(plugin.getDataFolder(), "/maps/" + name); + + if (file.exists()) { + GameWorld gameWorld = new GameWorld(); + gameWorld.mapName = name; + + // Unload empty editWorlds + for (EditWorld editWorld : plugin.getEditWorlds()) { + if (editWorld.getWorld().getPlayers().isEmpty()) { + editWorld.delete(); + } + } + + // Config einlesen + gameWorld.worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName, "config.yml")); + + // Secure Objects + gameWorld.secureObjects = gameWorld.worldConfig.getSecureObjects(); + + // World + FileUtil.copyDirectory(file, new File("DXL_Game_" + gameWorld.id)); + + // Id File + File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name); + try { + idFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + + gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id)); + + ObjectInputStream os; + try { + os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName + "/DXLData.data"))); + + int length = os.readInt(); + for (int i = 0; i < length; i++) { + int x = os.readInt(); + int y = os.readInt(); + int z = os.readInt(); + Block block = gameWorld.world.getBlockAt(x, y, z); + gameWorld.checkSign(block); + } + + os.close(); + + } catch (FileNotFoundException exception) { + plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!"); + + } catch (IOException exception) { + exception.printStackTrace(); + } + + return gameWorld; + } + + return null; + } + public static GameWorld getByWorld(World world) { for (GameWorld gameWorld : plugin.getGameWorlds()) { if (gameWorld.world.equals(world)) { @@ -408,6 +511,28 @@ public class GameWorld { return true; } + public static long getPlayerTime(String dungeon, Player player) { + File file = new File(plugin.getDataFolder() + "/maps/" + dungeon, "players.yml"); + + if ( !file.exists()) { + try { + file.createNewFile(); + + } catch (IOException exception) { + exception.printStackTrace(); + } + } + + FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file); + if (playerConfig.contains(player.getUniqueId().toString())) { + return playerConfig.getLong(player.getUniqueId().toString()); + } + if (playerConfig.contains(player.getName())) { + return playerConfig.getLong(player.getName()); + } + return -1; + } + public static boolean checkRequirements(String dungeon, Player player) { if (player.hasPermission("dxl.ignorerequirements")) { return true; @@ -483,131 +608,4 @@ public class GameWorld { return true; } - public static long getPlayerTime(String dungeon, Player player) { - File file = new File(plugin.getDataFolder() + "/maps/" + dungeon, "players.yml"); - - if ( !file.exists()) { - try { - file.createNewFile(); - - } catch (IOException exception) { - exception.printStackTrace(); - } - } - - FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file); - if (playerConfig.contains(player.getUniqueId().toString())) { - return playerConfig.getLong(player.getUniqueId().toString()); - } - if (playerConfig.contains(player.getName())) { - return playerConfig.getLong(player.getName()); - } - return -1; - } - - public void delete() { - GameWorldUnloadEvent event = new GameWorldUnloadEvent(this); - - if (event.isCancelled()) { - return; - } - - plugin.getGameWorlds().remove(this); - plugin.getServer().unloadWorld(world, true); - File dir = new File("DXL_Game_" + id); - FileUtil.removeDirectory(dir); - } - - public static GameWorld load(String name) { - GameWorldLoadEvent event = new GameWorldLoadEvent(name); - - if (event.isCancelled()) { - return null; - } - - File file = new File(plugin.getDataFolder(), "/maps/" + name); - - if (file.exists()) { - GameWorld gameWorld = new GameWorld(); - gameWorld.mapName = name; - - // Unload empty editWorlds - for (EditWorld editWorld : plugin.getEditWorlds()) { - if (editWorld.getWorld().getPlayers().isEmpty()) { - editWorld.delete(); - } - } - - // Config einlesen - gameWorld.worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName, "config.yml")); - - // Secure Objects - gameWorld.secureObjects = gameWorld.worldConfig.getSecureObjects(); - - // World - FileUtil.copyDirectory(file, new File("DXL_Game_" + gameWorld.id)); - - // Id File - File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name); - try { - idFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - - gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id)); - - ObjectInputStream os; - try { - os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName + "/DXLData.data"))); - - int length = os.readInt(); - for (int i = 0; i < length; i++) { - int x = os.readInt(); - int y = os.readInt(); - int z = os.readInt(); - Block block = gameWorld.world.getBlockAt(x, y, z); - gameWorld.checkSign(block); - } - - os.close(); - - } catch (FileNotFoundException exception) { - plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!"); - - } catch (IOException exception) { - exception.printStackTrace(); - } - - return gameWorld; - } - - return null; - } - - public static void update() { - for (GameWorld gameWorld : plugin.getGameWorlds()) { - if (gameWorld.getWorld() == null) { - return; - } - - // Update Spiders - for (LivingEntity mob : gameWorld.getWorld().getLivingEntities()) { - if (mob.getType() == EntityType.SPIDER || mob.getType() == EntityType.CAVE_SPIDER) { - Spider spider = (Spider) mob; - if (spider.getTarget() != null) { - if (spider.getTarget().getType() == EntityType.PLAYER) { - continue; - } - } - for (Entity player : spider.getNearbyEntities(10, 10, 10)) { - if (player.getType() == EntityType.PLAYER) { - spider.setTarget((LivingEntity) player); - } - } - } - } - } - } - } diff --git a/src/io/github/dre2n/dungeonsxl/global/DPortal.java b/src/io/github/dre2n/dungeonsxl/global/DPortal.java index a0b60829..09f00675 100644 --- a/src/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/src/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -1,8 +1,8 @@ package io.github.dre2n.dungeonsxl.global; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -29,6 +29,81 @@ public class DPortal { this.active = active; } + /** + * @return the world + */ + public World getWorld() { + return world; + } + + /** + * @param world + * the world to set + */ + public void setWorld(World world) { + this.world = world; + } + + /** + * @return the block1 + */ + public Block getBlock1() { + return block1; + } + + /** + * @param block1 + * the block1 to set + */ + public void setBlock1(Block block1) { + this.block1 = block1; + } + + /** + * @return the block2 + */ + public Block getBlock2() { + return block2; + } + + /** + * @param block2 + * the block2 to set + */ + public void setBlock2(Block block2) { + this.block2 = block2; + } + + /** + * @return if the portal is active + */ + public boolean isActive() { + return active; + } + + /** + * @param active + * set the DPortal active + */ + public void setActive(boolean active) { + this.active = active; + } + + /** + * @return the player + */ + public Player getPlayer() { + return player; + } + + /** + * @param player + * the player to set + */ + public void setPlayer(Player player) { + this.player = player; + } + public void create() { player = null; @@ -87,7 +162,7 @@ public class DPortal { DGroup dgroup = DGroup.getByPlayer(player); if (dgroup == null) { - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.ERROR_NOT_IN_GROUP)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_NOT_IN_GROUP)); return; } @@ -96,7 +171,7 @@ public class DPortal { } if (dgroup.getGameWorld() == null) { - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, DGroup.getByPlayer(player).getMapName())); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, DGroup.getByPlayer(player).getMapName())); return; } @@ -260,79 +335,4 @@ public class DPortal { } } - /** - * @return the world - */ - public World getWorld() { - return world; - } - - /** - * @param world - * the world to set - */ - public void setWorld(World world) { - this.world = world; - } - - /** - * @return the block1 - */ - public Block getBlock1() { - return block1; - } - - /** - * @param block1 - * the block1 to set - */ - public void setBlock1(Block block1) { - this.block1 = block1; - } - - /** - * @return the block2 - */ - public Block getBlock2() { - return block2; - } - - /** - * @param block2 - * the block2 to set - */ - public void setBlock2(Block block2) { - this.block2 = block2; - } - - /** - * @return if the portal is active - */ - public boolean isActive() { - return active; - } - - /** - * @param active - * set the DPortal active - */ - public void setActive(boolean active) { - this.active = active; - } - - /** - * @return the player - */ - public Player getPlayer() { - return player; - } - - /** - * @param player - * the player to set - */ - public void setPlayer(Player player) { - this.player = player; - } - } diff --git a/src/io/github/dre2n/dungeonsxl/global/GroupSign.java b/src/io/github/dre2n/dungeonsxl/global/GroupSign.java index 69c28b44..3003ff6f 100644 --- a/src/io/github/dre2n/dungeonsxl/global/GroupSign.java +++ b/src/io/github/dre2n/dungeonsxl/global/GroupSign.java @@ -1,10 +1,10 @@ package io.github.dre2n.dungeonsxl.global; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.WorldConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -382,7 +382,7 @@ public class GroupSign { } if (DGroup.getByPlayer(player) != null) { - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.ERROR_LEAVE_GROUP)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_LEAVE_GROUP)); return true; } @@ -391,7 +391,7 @@ public class GroupSign { if (file != null) { WorldConfig confReader = new WorldConfig(file); if (confReader != null) { - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.ERROR_COOLDOWN, String.valueOf(confReader.getTimeToNextPlay()))); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_COOLDOWN, String.valueOf(confReader.getTimeToNextPlay()))); } } @@ -399,7 +399,7 @@ public class GroupSign { } if ( !GameWorld.checkRequirements(groupSign.mapName, player)) { - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.ERROR_REQUIREMENTS)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_REQUIREMENTS)); return true; } diff --git a/src/io/github/dre2n/dungeonsxl/global/LeaveSign.java b/src/io/github/dre2n/dungeonsxl/global/LeaveSign.java index e7aa4db0..7486b108 100644 --- a/src/io/github/dre2n/dungeonsxl/global/LeaveSign.java +++ b/src/io/github/dre2n/dungeonsxl/global/LeaveSign.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.global; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -57,7 +57,7 @@ public class LeaveSign { DGroup dgroup = DGroup.getByPlayer(player); if (dgroup != null) { dgroup.removePlayer(player); - MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().getMessage(Messages.PLAYER_LEAVE_GROUP));// ChatColor.YELLOW+"Du hast deine Gruppe erfolgreich verlassen!"); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_LEAVE_GROUP));// ChatColor.YELLOW+"Du hast deine Gruppe erfolgreich verlassen!"); return true; } } diff --git a/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java index 368eb677..4a20d2e4 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -1,15 +1,15 @@ package io.github.dre2n.dungeonsxl.listener; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GamePlaceableBlock; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.global.LeaveSign; import io.github.dre2n.dungeonsxl.sign.DSign; -import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger; +import io.github.dre2n.dungeonsxl.task.RedstoneEventTask; import io.github.dre2n.dungeonsxl.util.NumberUtil; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -27,7 +27,6 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.scheduler.BukkitRunnable; public class BlockListener implements Listener { @@ -55,8 +54,8 @@ public class BlockListener implements Listener { if (dPortal != null) { if (plugin.getInBreakMode().contains(player)) { dPortal.delete(); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED)); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.CMD_BREAK_PROTECTED_MODE)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.CMD_BREAK_PROTECTED_MODE)); plugin.getInBreakMode().remove(player); } else { @@ -72,8 +71,8 @@ public class BlockListener implements Listener { if (groupSign != null) { if (plugin.getInBreakMode().contains(player)) { groupSign.delete(); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED)); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.CMD_BREAK_PROTECTED_MODE)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.CMD_BREAK_PROTECTED_MODE)); plugin.getInBreakMode().remove(player); } else { @@ -94,8 +93,8 @@ public class BlockListener implements Listener { if (leaveSign != null) { if (plugin.getInBreakMode().contains(player)) { leaveSign.delete(); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED)); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.CMD_BREAK_PROTECTED_MODE)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.CMD_BREAK_PROTECTED_MODE)); plugin.getInBreakMode().remove(player); } else { @@ -217,16 +216,16 @@ public class BlockListener implements Listener { } if ( !player.hasPermission(dsign.getType().getBuildPermission())) { - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.ERROR_NO_PERMISSIONS)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_NO_PERMISSIONS)); } if (dsign.check()) { editWorld.checkSign(block); editWorld.getSign().add(block); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_SIGN_CREATED)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_SIGN_CREATED)); } else { - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.ERROR_SIGN_WRONG_FORMAT)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_SIGN_WRONG_FORMAT)); } } } @@ -259,22 +258,4 @@ public class BlockListener implements Listener { new RedstoneEventTask(event.getBlock()).runTaskLater(plugin, 1); } - public class RedstoneEventTask extends BukkitRunnable { - private final Block block; - - public RedstoneEventTask(final Block block) { - this.block = block; - } - - @Override - public void run() { - for (GameWorld gameWorld : plugin.getGameWorlds()) { - if (block.getWorld() == gameWorld.getWorld()) { - RedstoneTrigger.updateAll(gameWorld); - } - } - } - - } - } diff --git a/src/io/github/dre2n/dungeonsxl/listener/CommandListener.java b/src/io/github/dre2n/dungeonsxl/listener/CommandListener.java index 4f15336f..e783f167 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/CommandListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/CommandListener.java @@ -3,8 +3,8 @@ package io.github.dre2n.dungeonsxl.listener; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.command.DCommand; -import io.github.dre2n.dungeonsxl.file.DMessages; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -19,13 +19,13 @@ public class CommandListener implements CommandExecutor { DungeonsXL plugin = DungeonsXL.getPlugin(); if (args.length > 0) { - DMessages dMessages = plugin.getDMessages(); + MessageConfig MessageConfig = plugin.getMessageConfig(); DCommand dCommand = plugin.getDCommands().getDCommand(args[0]); if (dCommand != null) { if (sender instanceof ConsoleCommandSender) { if ( !dCommand.isConsoleCommand()) { - MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.LOG_ERROR_NO_CONSOLE_COMMAND, dCommand.getCommand())); + MessageUtil.sendMessage(sender, MessageConfig.getMessage(Messages.LOG_ERROR_NO_CONSOLE_COMMAND, dCommand.getCommand())); return false; } } @@ -34,13 +34,13 @@ public class CommandListener implements CommandExecutor { Player player = (Player) sender; if ( !dCommand.isPlayerCommand()) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NO_PLAYER_COMMAND, dCommand.getCommand())); + MessageUtil.sendMessage(player, MessageConfig.getMessage(Messages.ERROR_NO_PLAYER_COMMAND, dCommand.getCommand())); return false; } else { if (dCommand.getPermission() != null) { if ( !dCommand.playerHasPermissions(player)) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NO_PERMISSIONS)); + MessageUtil.sendMessage(player, MessageConfig.getMessage(Messages.ERROR_NO_PERMISSIONS)); return false; } } diff --git a/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java b/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java index 1593df8f..b6581edd 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.listener; +import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GroupSign; diff --git a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index c6a0c878..cfd7df0a 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -3,23 +3,23 @@ package io.github.dre2n.dungeonsxl.listener; import java.util.ArrayList; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig; +import io.github.dre2n.dungeonsxl.config.WorldConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.DLootInventory; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameChest; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent; -import io.github.dre2n.dungeonsxl.file.DMessages; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.global.LeaveSign; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; +import io.github.dre2n.dungeonsxl.task.RespawnTask; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger; -import io.github.dre2n.dungeonsxl.util.MiscUtil; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import org.bukkit.ChatColor; @@ -47,12 +47,11 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.scheduler.BukkitRunnable; public class PlayerListener implements Listener { static DungeonsXL plugin = DungeonsXL.getPlugin(); - DMessages dMessages = plugin.getDMessages(); + MessageConfig messageConfig = plugin.getMessageConfig(); @EventHandler(priority = EventPriority.HIGH) public void onDeath(PlayerDeathEvent event) { @@ -79,17 +78,17 @@ public class PlayerListener implements Listener { dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives()); if (dPlayer.getLives() == 0 && dPlayer.isReady()) { - MessageUtil.broadcastMessage(dMessages.getMessage(Messages.PLAYER_DEATH_KICK, player.getName())); + MessageUtil.broadcastMessage(messageConfig.getMessage(Messages.PLAYER_DEATH_KICK, player.getName())); // TODO: This Runnable is a workaround for a bug I couldn't find, yet... - new BukkitRunnable() { + new org.bukkit.scheduler.BukkitRunnable() { public void run() { dPlayer.leave(); } }.runTaskLater(plugin, 1L); } else if ( !(dPlayer.getLives() == -1)) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.PLAYER_DEATH, String.valueOf(dPlayer.getLives()))); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_DEATH, String.valueOf(dPlayer.getLives()))); } else if (dConfig != null) { if (dConfig.getKeepInventoryOnDeath()) { @@ -118,13 +117,13 @@ public class PlayerListener implements Listener { if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (clickedBlock.getType() == Material.ENDER_CHEST) { if ( !player.hasPermission("dxl.bypass")) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_ENDERCHEST)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_ENDERCHEST)); event.setCancelled(true); } } else if (clickedBlock.getType() == Material.BED_BLOCK) { if ( !player.hasPermission("dxl.bypass")) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_BED)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_BED)); event.setCancelled(true); } } @@ -136,7 +135,7 @@ public class PlayerListener implements Listener { if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (clickedBlock.getType() == Material.DISPENSER) { if ( !player.hasPermission("dxl.bypass")) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_DISPENSER)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DISPENSER)); event.setCancelled(true); } } @@ -154,13 +153,13 @@ public class PlayerListener implements Listener { if (dportal.getPlayer() == player) { if (dportal.getBlock1() == null) { dportal.setBlock1(event.getClickedBlock()); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.PLAYER_PORTAL_PROGRESS)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PORTAL_PROGRESS)); } else if (dportal.getBlock2() == null) { dportal.setBlock2(event.getClickedBlock()); dportal.setActive(true); dportal.create(); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.PLAYER_PORTAL_CREATED)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PORTAL_CREATED)); } event.setCancelled(true); } @@ -240,7 +239,7 @@ public class PlayerListener implements Listener { if (event.getAction() == Action.LEFT_CLICK_BLOCK) { trigger.onTrigger(player); } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEFT_CLICK)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEFT_CLICK)); } } @@ -251,7 +250,7 @@ public class PlayerListener implements Listener { if (event.getAction() == Action.LEFT_CLICK_BLOCK) { dPlayer.setDClass(ChatColor.stripColor(classSign.getLine(1))); } else { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_LEFT_CLICK)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEFT_CLICK)); } return; } @@ -291,7 +290,7 @@ public class PlayerListener implements Listener { for (Material material : gameWorld.getConfig().getSecureObjects()) { if (material == event.getItemDrop().getItemStack().getType()) { event.setCancelled(true); - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_DROP)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DROP)); return; } } @@ -335,7 +334,7 @@ public class PlayerListener implements Listener { // Da einige Plugins einen anderen Respawn setzen wird // ein Scheduler gestartet der den Player nach einer // Sekunde teleportiert. - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RespawnRunnable(player, dGroup.getGameWorld().getLocStart()), 10); + new RespawnTask(player, dGroup.getGameWorld().getLocStart()).runTaskLater(plugin, 10L); if (dPlayer.getWolf() != null) { dPlayer.getWolf().teleport(dGroup.getGameWorld().getLocStart()); @@ -347,7 +346,7 @@ public class PlayerListener implements Listener { // Da einige Plugins einen anderen Respawn setzen wird // ein Scheduler gestartet der den Player nach einer // Sekunde teleportiert. - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RespawnRunnable(player, dPlayer.getCheckpoint()), 10); + new RespawnTask(player, dPlayer.getCheckpoint()).runTaskLater(plugin, 10L); if (dPlayer.getWolf() != null) { dPlayer.getWolf().teleport(dPlayer.getCheckpoint()); @@ -420,11 +419,11 @@ public class PlayerListener implements Listener { dPlayer.leave(); } else if (timeUntilKickOfflinePlayer > 0) { - dGroup.sendMessage(dMessages.getMessage(Messages.PLAYER_OFFLINE, dPlayer.getPlayer().getName(), "" + timeUntilKickOfflinePlayer), player); + dGroup.sendMessage(messageConfig.getMessage(Messages.PLAYER_OFFLINE, dPlayer.getPlayer().getName(), "" + timeUntilKickOfflinePlayer), player); dPlayer.setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000); } else { - dGroup.sendMessage(dMessages.getMessage(Messages.PLAYER_OFFLINE_NEVER, dPlayer.getPlayer().getName()), player); + dGroup.sendMessage(messageConfig.getMessage(Messages.PLAYER_OFFLINE_NEVER, dPlayer.getPlayer().getName()), player); } } else if (dPlayer.isEditing()) { @@ -490,7 +489,7 @@ public class PlayerListener implements Listener { } if (dGroup.getGameWorld() == null) { - MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_TUTORIAL_NOT_EXIST)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_TUTORIAL_NOT_EXIST)); continue; } @@ -544,7 +543,7 @@ public class PlayerListener implements Listener { } if (event.isCancelled()) { - MessageUtil.sendMessage(event.getPlayer(), dMessages.getMessage(Messages.ERROR_CMD)); + MessageUtil.sendMessage(event.getPlayer(), messageConfig.getMessage(Messages.ERROR_CMD)); } } @@ -599,37 +598,4 @@ public class PlayerListener implements Listener { } } - // Etc. --------------------------------- - - public class RespawnRunnable implements Runnable { - private Player player; - private Location location; - - public RespawnRunnable(Player player, Location location) { - this.location = location; - this.player = player; - } - - @Override - public void run() { - if (player.getLocation().distance(location) > 2) { - MiscUtil.secureTeleport(player, location); - } - - DPlayer dPlayer = DPlayer.getByPlayer(player); - - if (dPlayer == null) { - return; - } - - // Respawn Items - if (dPlayer.getRespawnInventory() != null || dPlayer.getRespawnArmor() != null) { - player.getInventory().setContents(dPlayer.getRespawnInventory()); - player.getInventory().setArmorContents(dPlayer.getRespawnArmor()); - dPlayer.setRespawnInventory(null); - dPlayer.setRespawnArmor(null); - } - } - } - } diff --git a/src/io/github/dre2n/dungeonsxl/mob/DMobType.java b/src/io/github/dre2n/dungeonsxl/mob/DMobType.java index 1f7dc56d..28dfe12a 100644 --- a/src/io/github/dre2n/dungeonsxl/mob/DMobType.java +++ b/src/io/github/dre2n/dungeonsxl/mob/DMobType.java @@ -1,8 +1,8 @@ package io.github.dre2n.dungeonsxl.mob; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.util.NumberUtil; import java.util.Arrays; @@ -112,7 +112,7 @@ public class DMobType { EntityType type = EntityType.fromName(configFile.getString(mobName + ".Type")); if (type == null) { - plugin.getLogger().info(plugin.getDMessages().getMessage(Messages.LOG_ERROR_MOBTYPE, configFile.getString(mobName + ".Type"))); + plugin.getLogger().info(plugin.getMessageConfig().getMessage(Messages.LOG_ERROR_MOBTYPE, configFile.getString(mobName + ".Type"))); continue; } @@ -194,7 +194,7 @@ public class DMobType { itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true); } } else { - plugin.getLogger().info(plugin.getDMessages().getMessage(Messages.LOG_ERROR_MOB_ENCHANTMENT, splittedEnchantment[0])); + plugin.getLogger().info(plugin.getMessageConfig().getMessage(Messages.LOG_ERROR_MOB_ENCHANTMENT, splittedEnchantment[0])); } } } @@ -233,8 +233,8 @@ public class DMobType { } } - if (plugin.getMainConfig().defaultDungeon != null) { - for (DMobType mobType : plugin.getMainConfig().defaultDungeon.getMobTypes()) { + if (plugin.getMainConfig().getDefaultWorldConfig() != null) { + for (DMobType mobType : plugin.getMainConfig().getDefaultWorldConfig().getMobTypes()) { if (mobType.name.equalsIgnoreCase(name)) { return mobType; } diff --git a/src/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/io/github/dre2n/dungeonsxl/player/DGroup.java index a8769e1e..92c8f07d 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -1,12 +1,12 @@ package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent; import io.github.dre2n.dungeonsxl.event.requirement.RequirementDemandEvent; import io.github.dre2n.dungeonsxl.event.reward.RewardAdditionEvent; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; @@ -101,7 +101,7 @@ public class DGroup { public void addPlayer(Player player) { // Send message for (Player groupPlayer : getPlayers()) { - MessageUtil.sendMessage(groupPlayer, plugin.getDMessages().getMessage(Messages.PLAYER_JOIN_GROUP, player.getName())); + MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.PLAYER_JOIN_GROUP, player.getName())); } // Add player @@ -118,7 +118,7 @@ public class DGroup { // Send message for (Player groupPlayer : getPlayers()) { - MessageUtil.sendMessage(groupPlayer, plugin.getDMessages().getMessage(Messages.PLAYER_LEFT_GROUP, player.getName())); + MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.PLAYER_LEFT_GROUP, player.getName())); } // Check group @@ -325,7 +325,7 @@ public class DGroup { public void sendMessage(String message) { for (Player player : players) { if (player.isOnline()) { - MessageUtil.sendCenteredMessage(player, message); + MessageUtil.sendMessage(player, message); } } } @@ -339,7 +339,7 @@ public class DGroup { public void sendMessage(String message, Player... except) { for (Player player : players) { if (player.isOnline() && !player.equals(except)) { - MessageUtil.sendCenteredMessage(player, message); + MessageUtil.sendMessage(player, message); } } } diff --git a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java index fc82e792..660292e2 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java @@ -1,8 +1,10 @@ package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig; -import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig; +import io.github.dre2n.dungeonsxl.config.WorldConfig; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.DLootInventory; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; @@ -11,12 +13,10 @@ import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerFinishEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent; -import io.github.dre2n.dungeonsxl.file.DMessages; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.reward.Reward; import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger; import io.github.dre2n.dungeonsxl.util.NumberUtil; -import io.github.dre2n.dungeonsxl.util.MiscUtil; +import io.github.dre2n.dungeonsxl.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import java.io.File; @@ -44,7 +44,7 @@ import org.bukkit.potion.PotionEffect; public class DPlayer { static DungeonsXL plugin = DungeonsXL.getPlugin(); - DMessages dMessages = plugin.getDMessages(); + MessageConfig MessageConfig = plugin.getMessageConfig(); // Variables private Player player; @@ -67,7 +67,7 @@ public class DPlayer { private ItemStack[] respawnArmor; private String[] linesCopy; - private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, dMessages.getMessage(Messages.PLAYER_TREASURES)); + private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, MessageConfig.getMessage(Messages.PLAYER_TREASURES)); private int initialLives = -1; private int lives; @@ -102,7 +102,7 @@ public class DPlayer { lives = initialLives; } - MiscUtil.secureTeleport(this.getPlayer(), teleport); + PlayerUtil.secureTeleport(this.getPlayer(), teleport); } public void clearPlayerData() { @@ -117,330 +117,7 @@ public class DPlayer { } } - public void escape() { - remove(this); - savePlayer.reset(false); - } - - public void leave() { - remove(this); - if ( !editing) { - WorldConfig dConfig = GameWorld.getByWorld(world).getConfig(); - if (finished) { - savePlayer.reset(dConfig.getKeepInventoryOnFinish()); - } else { - savePlayer.reset(dConfig.getKeepInventoryOnEscape()); - } - } else { - savePlayer.reset(false); - } - - if (editing) { - EditWorld editWorld = EditWorld.getByWorld(world); - if (editWorld != null) { - editWorld.save(); - } - - } else { - GameWorld gameWorld = GameWorld.getByWorld(world); - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if (dGroup != null) { - dGroup.removePlayer(getPlayer()); - } - - // Belohnung - if ( !inTestMode) {// Nur wenn man nicht am Testen ist - if (finished) { - for (Reward reward : gameWorld.getConfig().getRewards()) { - reward.giveTo(player); - } - - addTreasure(); - - // Set Time - File file = new File(plugin.getDataFolder() + "/maps/" + gameWorld.getMapName(), "players.yml"); - - if ( !file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file); - - playerConfig.set(getPlayer().getUniqueId().toString(), System.currentTimeMillis()); - - try { - playerConfig.save(file); - - } catch (IOException exception) { - exception.printStackTrace(); - } - - // Tutorial Permissions - if (gameWorld.isTutorial()) { - String endGroup = plugin.getMainConfig().getTutorialEndGroup(); - if (plugin.isGroupEnabled(endGroup)) { - plugin.getPermissionProvider().playerAddGroup(getPlayer(), endGroup); - } - - String startGroup = plugin.getMainConfig().getTutorialStartGroup(); - if (plugin.isGroupEnabled(startGroup)) { - plugin.getPermissionProvider().playerRemoveGroup(getPlayer(), startGroup); - } - } - } - } - - // Give Secure Objects other Players - if (dGroup != null) { - if ( !dGroup.isEmpty()) { - int i = 0; - Player groupPlayer; - do { - groupPlayer = dGroup.getPlayers().get(i); - if (groupPlayer != null) { - for (ItemStack istack : getPlayer().getInventory()) { - if (istack != null) { - if (gameWorld.getSecureObjects().contains(istack.getType())) { - groupPlayer.getInventory().addItem(istack); - } - } - } - } - i++; - } while (groupPlayer == null); - } - } - } - } - - public void ready() { - ready = true; - - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if ( !dGroup.isPlaying()) { - if (dGroup != null) { - for (Player player : dGroup.getPlayers()) { - DPlayer dPlayer = getByPlayer(player); - if ( !dPlayer.ready) { - return; - } - } - } - - dGroup.startGame(); - } else { - respawn(); - } - } - - public void respawn() { - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if (checkpoint == null) { - MiscUtil.secureTeleport(getPlayer(), dGroup.getGameWorld().getLocStart()); - } else { - MiscUtil.secureTeleport(getPlayer(), checkpoint); - } - if (wolf != null) { - wolf.teleport(getPlayer()); - } - - // Respawn Items - if (GameWorld.getByWorld(world).getConfig().getKeepInventoryOnDeath()) { - if (respawnInventory != null || respawnArmor != null) { - getPlayer().getInventory().setContents(respawnInventory); - getPlayer().getInventory().setArmorContents(respawnArmor); - respawnInventory = null; - respawnArmor = null; - } - // P.plugin.updateInventory(this.player); - } - } - - public void finishFloor(String specifiedFloor) { - MessageUtil.sendMessage(getPlayer(), dMessages.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); - finished = true; - - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if (dGroup == null) { - return; - } - - if ( !dGroup.isPlaying()) { - return; - } - - for (Player player : dGroup.getPlayers()) { - DPlayer dPlayer = getByPlayer(player); - if ( !dPlayer.finished) { - MessageUtil.sendMessage(this.getPlayer(), dMessages.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); - return; - } - } - - boolean invalid = false; - - if (dGroup.getDungeon() == null) { - invalid = true; - } - - for (Player player : dGroup.getPlayers()) { - DPlayer dPlayer = getByPlayer(player); - - if (invalid) { - dPlayer.leave(); - - } else { - dPlayer.finished = false; - } - } - - if (invalid) { - return; - } - - DungeonConfig dConfig = dGroup.getDungeon().getConfig(); - int random = NumberUtil.generateRandomInt(0, dConfig.getFloors().size()); - String newFloor = dGroup.getUnplayedFloors().get(random); - if (dConfig.getFloorCount() == dGroup.getFloorCount() - 1) { - newFloor = dConfig.getEndFloor(); - - } else if (specifiedFloor != null) { - newFloor = specifiedFloor; - } - - DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor); - - if (event.isCancelled()) { - return; - } - - dGroup.removeUnplayedFloor(dGroup.getMapName()); - dGroup.setMapName(newFloor); - GameWorld gameWorld = GameWorld.load(newFloor); - dGroup.setGameWorld(gameWorld); - for (Player player : dGroup.getPlayers()) { - DPlayer dPlayer = getByPlayer(player); - dPlayer.setWorld(gameWorld.getWorld()); - dPlayer.setCheckpoint(dGroup.getGameWorld().getLocStart()); - if (dPlayer.getWolf() != null) { - dPlayer.getWolf().teleport(dPlayer.getCheckpoint()); - } - } - dGroup.startGame(); - } - - public void finish() { - MessageUtil.sendMessage(getPlayer(), dMessages.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); - finished = true; - - DGroup dGroup = DGroup.getByPlayer(getPlayer()); - if (dGroup == null) { - return; - } - - if ( !dGroup.isPlaying()) { - return; - } - - boolean first = true; - boolean hasToWait = false; - - for (Player player : dGroup.getPlayers()) { - DPlayer dPlayer = getByPlayer(player); - if ( !dPlayer.finished) { - MessageUtil.sendMessage(this.getPlayer(), dMessages.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); - hasToWait = true; - - } else if (dPlayer != this) { - first = false; - } - } - - DPlayerFinishEvent dPlayerFinishEvent = new DPlayerFinishEvent(this, first, hasToWait); - - if (dPlayerFinishEvent.isCancelled()) { - finished = false; - return; - } - - if (hasToWait) { - return; - } - - DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dGroup); - - if (dGroupFinishDungeonEvent.isCancelled()) { - return; - } - - for (Player player : dGroup.getPlayers()) { - DPlayer dPlayer = getByPlayer(player); - dPlayer.leave(); - - for (Reward reward : dGroup.getRewards()) { - reward.giveTo(player); - } - } - } - - public void sendMessage(String message) { - if (editing) { - EditWorld editWorld = EditWorld.getByWorld(world); - editWorld.msg(message); - for (Player player : plugin.getChatSpyers()) { - if ( !editWorld.getWorld().getPlayers().contains(player)) { - MessageUtil.sendMessage(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message); - } - } - - } else { - GameWorld gameWorld = GameWorld.getByWorld(world); - gameWorld.msg(message); - for (Player player : plugin.getChatSpyers()) { - if ( !gameWorld.getWorld().getPlayers().contains(player)) { - MessageUtil.sendMessage(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message); - } - } - } - } - - @SuppressWarnings("deprecation") - public void poke(Block block) { - if (block.getState() instanceof Sign) { - Sign sign = (Sign) block.getState(); - String[] lines = sign.getLines(); - if (lines[0].equals("") && lines[1].equals("") && lines[2].equals("") && lines[3].equals("")) { - if (linesCopy != null) { - SignChangeEvent event = new SignChangeEvent(block, getPlayer(), linesCopy); - plugin.getServer().getPluginManager().callEvent(event); - if ( !event.isCancelled()) { - sign.setLine(0, event.getLine(0)); - sign.setLine(1, event.getLine(1)); - sign.setLine(2, event.getLine(2)); - sign.setLine(3, event.getLine(3)); - sign.update(); - } - } - } else { - linesCopy = lines; - MessageUtil.sendMessage(getPlayer(), dMessages.getMessage(Messages.PLAYER_SIGN_COPIED)); - } - } else { - String info = "" + block.getType(); - if (block.getData() != 0) { - info = info + "," + block.getData(); - } - MessageUtil.sendMessage(getPlayer(), dMessages.getMessage(Messages.PLAYER_BLOCK_INFO, info)); - } - } - - public void addTreasure() { - new DLootInventory(getPlayer(), treasureInv.getContents()); - } + // Getters and setters /** * @return the player @@ -795,6 +472,442 @@ public class DPlayer { this.lives = lives; } + // ... + + public void escape() { + remove(this); + savePlayer.reset(false); + } + + public void leave() { + remove(this); + if ( !editing) { + WorldConfig dConfig = GameWorld.getByWorld(world).getConfig(); + if (finished) { + savePlayer.reset(dConfig.getKeepInventoryOnFinish()); + } else { + savePlayer.reset(dConfig.getKeepInventoryOnEscape()); + } + } else { + savePlayer.reset(false); + } + + if (editing) { + EditWorld editWorld = EditWorld.getByWorld(world); + if (editWorld != null) { + editWorld.save(); + } + + } else { + GameWorld gameWorld = GameWorld.getByWorld(world); + DGroup dGroup = DGroup.getByPlayer(getPlayer()); + if (dGroup != null) { + dGroup.removePlayer(getPlayer()); + } + + // Belohnung + if ( !inTestMode) {// Nur wenn man nicht am Testen ist + if (finished) { + for (Reward reward : gameWorld.getConfig().getRewards()) { + reward.giveTo(player); + } + + addTreasure(); + + // Set Time + File file = new File(plugin.getDataFolder() + "/maps/" + gameWorld.getMapName(), "players.yml"); + + if ( !file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file); + + playerConfig.set(getPlayer().getUniqueId().toString(), System.currentTimeMillis()); + + try { + playerConfig.save(file); + + } catch (IOException exception) { + exception.printStackTrace(); + } + + // Tutorial Permissions + if (gameWorld.isTutorial()) { + String endGroup = plugin.getMainConfig().getTutorialEndGroup(); + if (plugin.isGroupEnabled(endGroup)) { + plugin.getPermissionProvider().playerAddGroup(getPlayer(), endGroup); + } + + String startGroup = plugin.getMainConfig().getTutorialStartGroup(); + if (plugin.isGroupEnabled(startGroup)) { + plugin.getPermissionProvider().playerRemoveGroup(getPlayer(), startGroup); + } + } + } + } + + // Give Secure Objects other Players + if (dGroup != null) { + if ( !dGroup.isEmpty()) { + int i = 0; + Player groupPlayer; + do { + groupPlayer = dGroup.getPlayers().get(i); + if (groupPlayer != null) { + for (ItemStack istack : getPlayer().getInventory()) { + if (istack != null) { + if (gameWorld.getSecureObjects().contains(istack.getType())) { + groupPlayer.getInventory().addItem(istack); + } + } + } + } + i++; + } while (groupPlayer == null); + } + } + } + } + + public void ready() { + ready = true; + + DGroup dGroup = DGroup.getByPlayer(getPlayer()); + if ( !dGroup.isPlaying()) { + if (dGroup != null) { + for (Player player : dGroup.getPlayers()) { + DPlayer dPlayer = getByPlayer(player); + if ( !dPlayer.ready) { + return; + } + } + } + + dGroup.startGame(); + } else { + respawn(); + } + } + + public void respawn() { + DGroup dGroup = DGroup.getByPlayer(getPlayer()); + if (checkpoint == null) { + PlayerUtil.secureTeleport(getPlayer(), dGroup.getGameWorld().getLocStart()); + } else { + PlayerUtil.secureTeleport(getPlayer(), checkpoint); + } + if (wolf != null) { + wolf.teleport(getPlayer()); + } + + // Respawn Items + if (GameWorld.getByWorld(world).getConfig().getKeepInventoryOnDeath()) { + if (respawnInventory != null || respawnArmor != null) { + getPlayer().getInventory().setContents(respawnInventory); + getPlayer().getInventory().setArmorContents(respawnArmor); + respawnInventory = null; + respawnArmor = null; + } + // P.plugin.updateInventory(this.player); + } + } + + public void finishFloor(String specifiedFloor) { + MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); + finished = true; + + DGroup dGroup = DGroup.getByPlayer(getPlayer()); + if (dGroup == null) { + return; + } + + if ( !dGroup.isPlaying()) { + return; + } + + for (Player player : dGroup.getPlayers()) { + DPlayer dPlayer = getByPlayer(player); + if ( !dPlayer.finished) { + MessageUtil.sendMessage(this.getPlayer(), MessageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); + return; + } + } + + boolean invalid = false; + + if (dGroup.getDungeon() == null) { + invalid = true; + } + + for (Player player : dGroup.getPlayers()) { + DPlayer dPlayer = getByPlayer(player); + + if (invalid) { + dPlayer.leave(); + + } else { + dPlayer.finished = false; + } + } + + if (invalid) { + return; + } + + DungeonConfig dConfig = dGroup.getDungeon().getConfig(); + int random = NumberUtil.generateRandomInt(0, dConfig.getFloors().size()); + String newFloor = dGroup.getUnplayedFloors().get(random); + if (dConfig.getFloorCount() == dGroup.getFloorCount() - 1) { + newFloor = dConfig.getEndFloor(); + + } else if (specifiedFloor != null) { + newFloor = specifiedFloor; + } + + DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor); + + if (event.isCancelled()) { + return; + } + + dGroup.removeUnplayedFloor(dGroup.getMapName()); + dGroup.setMapName(newFloor); + GameWorld gameWorld = GameWorld.load(newFloor); + dGroup.setGameWorld(gameWorld); + for (Player player : dGroup.getPlayers()) { + DPlayer dPlayer = getByPlayer(player); + dPlayer.setWorld(gameWorld.getWorld()); + dPlayer.setCheckpoint(dGroup.getGameWorld().getLocStart()); + if (dPlayer.getWolf() != null) { + dPlayer.getWolf().teleport(dPlayer.getCheckpoint()); + } + } + dGroup.startGame(); + } + + public void finish() { + MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); + finished = true; + + DGroup dGroup = DGroup.getByPlayer(getPlayer()); + if (dGroup == null) { + return; + } + + if ( !dGroup.isPlaying()) { + return; + } + + boolean first = true; + boolean hasToWait = false; + + for (Player player : dGroup.getPlayers()) { + DPlayer dPlayer = getByPlayer(player); + if ( !dPlayer.finished) { + MessageUtil.sendMessage(this.getPlayer(), MessageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); + hasToWait = true; + + } else if (dPlayer != this) { + first = false; + } + } + + DPlayerFinishEvent dPlayerFinishEvent = new DPlayerFinishEvent(this, first, hasToWait); + + if (dPlayerFinishEvent.isCancelled()) { + finished = false; + return; + } + + if (hasToWait) { + return; + } + + DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dGroup); + + if (dGroupFinishDungeonEvent.isCancelled()) { + return; + } + + for (Player player : dGroup.getPlayers()) { + DPlayer dPlayer = getByPlayer(player); + dPlayer.leave(); + + for (Reward reward : dGroup.getRewards()) { + reward.giveTo(player); + } + } + } + + public void sendMessage(String message) { + if (editing) { + EditWorld editWorld = EditWorld.getByWorld(world); + editWorld.sendMessage(message); + for (Player player : plugin.getChatSpyers()) { + if ( !editWorld.getWorld().getPlayers().contains(player)) { + MessageUtil.sendMessage(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message); + } + } + + } else { + GameWorld gameWorld = GameWorld.getByWorld(world); + gameWorld.sendMessage(message); + for (Player player : plugin.getChatSpyers()) { + if ( !gameWorld.getWorld().getPlayers().contains(player)) { + MessageUtil.sendMessage(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message); + } + } + } + } + + @SuppressWarnings("deprecation") + public void poke(Block block) { + if (block.getState() instanceof Sign) { + Sign sign = (Sign) block.getState(); + String[] lines = sign.getLines(); + if (lines[0].equals("") && lines[1].equals("") && lines[2].equals("") && lines[3].equals("")) { + if (linesCopy != null) { + SignChangeEvent event = new SignChangeEvent(block, getPlayer(), linesCopy); + plugin.getServer().getPluginManager().callEvent(event); + if ( !event.isCancelled()) { + sign.setLine(0, event.getLine(0)); + sign.setLine(1, event.getLine(1)); + sign.setLine(2, event.getLine(2)); + sign.setLine(3, event.getLine(3)); + sign.update(); + } + } + } else { + linesCopy = lines; + MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_SIGN_COPIED)); + } + } else { + String info = "" + block.getType(); + if (block.getData() != 0) { + info = info + "," + block.getData(); + } + MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_BLOCK_INFO, info)); + } + } + + public void addTreasure() { + new DLootInventory(getPlayer(), treasureInv.getContents()); + } + + public void update(boolean updateSecond) { + boolean locationValid = true; + Location teleportLocation = getPlayer().getLocation(); + boolean teleportWolf = false; + boolean respawnInventory = false; + boolean offline = false; + boolean kick = false; + boolean triggerAllInDistance = false; + + GameWorld gameWorld = GameWorld.getByWorld(getWorld()); + EditWorld editWorld = EditWorld.getByWorld(getWorld()); + + if ( !updateSecond) { + if ( !getPlayer().getWorld().equals(getWorld())) { + locationValid = false; + + if (isEditing()) { + if (editWorld != null) { + if (editWorld.getLobby() == null) { + teleportLocation = editWorld.getWorld().getSpawnLocation(); + } else { + teleportLocation = editWorld.getLobby(); + } + } + } else { + if (gameWorld != null) { + DGroup dGroup = DGroup.getByPlayer(getPlayer()); + if (getCheckpoint() == null) { + teleportLocation = dGroup.getGameWorld().getLocStart(); + if (getWolf() != null) { + getWolf().teleport(dGroup.getGameWorld().getLocStart()); + } + } else { + teleportLocation = getCheckpoint(); + if (getWolf() != null) { + teleportWolf = true; + } + } + + // Respawn Items + if (getRespawnInventory() != null || getRespawnArmor() != null) { + respawnInventory = true; + } + } + } + } + + } else { + if (gameWorld != null) { + // Update Wolf + if (getWolf() != null) { + if (getWolf().isDead()) { + if (getWolfRespawnTime() <= 0) { + setWolf((Wolf) getWorld().spawnEntity(getPlayer().getLocation(), EntityType.WOLF)); + getWolf().setTamed(true); + getWolf().setOwner(getPlayer()); + setWolfRespawnTime(30); + } + wolfRespawnTime--; + } + } + + // Kick offline plugin.getDPlayers() + if (getOfflineTime() > 0) { + offline = true; + + if (getOfflineTime() < System.currentTimeMillis()) { + kick = true; + } + } + + triggerAllInDistance = true; + } + } + + DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance); + + if (event.isCancelled()) { + return; + } + + if ( !locationValid) { + PlayerUtil.secureTeleport(getPlayer(), teleportLocation); + } + + if (teleportWolf) { + getWolf().teleport(getCheckpoint()); + } + + if (respawnInventory) { + getPlayer().getInventory().setContents(getRespawnInventory()); + getPlayer().getInventory().setArmorContents(getRespawnArmor()); + setRespawnInventory(null); + setRespawnArmor(null); + } + + if (kick) { + DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this); + + if ( !dPlayerKickEvent.isCancelled()) { + leave(); + } + } + + if (triggerAllInDistance) { + DistanceTrigger.triggerAllInDistance(getPlayer(), gameWorld); + } + } + // Static public static void remove(DPlayer player) { @@ -831,115 +944,4 @@ public class DPlayer { return dPlayers; } - public static void update(boolean updateSecond) { - for (DPlayer dPlayer : plugin.getDPlayers()) { - boolean locationValid = true; - Location teleportLocation = dPlayer.getPlayer().getLocation(); - boolean teleportWolf = false; - boolean respawnInventory = false; - boolean offline = false; - boolean kick = false; - boolean triggerAllInDistance = false; - - GameWorld gameWorld = GameWorld.getByWorld(dPlayer.world); - EditWorld editWorld = EditWorld.getByWorld(dPlayer.world); - - if ( !updateSecond) { - if ( !dPlayer.getPlayer().getWorld().equals(dPlayer.world)) { - locationValid = false; - - if (dPlayer.editing) { - if (editWorld != null) { - if (editWorld.getLobby() == null) { - teleportLocation = editWorld.getWorld().getSpawnLocation(); - } else { - teleportLocation = editWorld.getLobby(); - } - } - } else { - if (gameWorld != null) { - DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer()); - if (dPlayer.checkpoint == null) { - teleportLocation = dGroup.getGameWorld().getLocStart(); - if (dPlayer.wolf != null) { - dPlayer.wolf.teleport(dGroup.getGameWorld().getLocStart()); - } - } else { - teleportLocation = dPlayer.getCheckpoint(); - if (dPlayer.wolf != null) { - teleportWolf = true; - } - } - - // Respawn Items - if (dPlayer.respawnInventory != null || dPlayer.respawnArmor != null) { - respawnInventory = true; - } - } - } - } - - } else { - if (gameWorld != null) { - // Update Wolf - if (dPlayer.wolf != null) { - if (dPlayer.wolf.isDead()) { - if (dPlayer.wolfRespawnTime <= 0) { - dPlayer.wolf = (Wolf) dPlayer.world.spawnEntity(dPlayer.getPlayer().getLocation(), EntityType.WOLF); - dPlayer.wolf.setTamed(true); - dPlayer.wolf.setOwner(dPlayer.getPlayer()); - dPlayer.wolfRespawnTime = 30; - } - dPlayer.wolfRespawnTime--; - } - } - - // Kick offline plugin.getDPlayers() - if (dPlayer.offlineTime > 0) { - offline = true; - - if (dPlayer.offlineTime < System.currentTimeMillis()) { - kick = true; - } - } - - triggerAllInDistance = true; - } - } - - DPlayerUpdateEvent event = new DPlayerUpdateEvent(dPlayer, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance); - - if (event.isCancelled()) { - return; - } - - if ( !locationValid) { - MiscUtil.secureTeleport(dPlayer.getPlayer(), teleportLocation); - } - - if (teleportWolf) { - dPlayer.wolf.teleport(dPlayer.checkpoint); - } - - if (respawnInventory) { - dPlayer.getPlayer().getInventory().setContents(dPlayer.respawnInventory); - dPlayer.getPlayer().getInventory().setArmorContents(dPlayer.respawnArmor); - dPlayer.respawnInventory = null; - dPlayer.respawnArmor = null; - } - - if (kick) { - DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer); - - if ( !dPlayerKickEvent.isCancelled()) { - dPlayer.leave(); - } - } - - if (triggerAllInDistance) { - DistanceTrigger.triggerAllInDistance(dPlayer.getPlayer(), gameWorld); - } - } - } - } diff --git a/src/io/github/dre2n/dungeonsxl/player/DSavePlayer.java b/src/io/github/dre2n/dungeonsxl/player/DSavePlayer.java index f9ab6f32..6d7d1450 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DSavePlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DSavePlayer.java @@ -1,8 +1,7 @@ package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.util.MiscUtil; -import io.github.dre2n.dungeonsxl.util.offlineplayerutil.OfflinePlayerUtil; +import io.github.dre2n.dungeonsxl.util.playerutil.PlayerUtil; import java.io.File; import java.io.IOException; @@ -66,7 +65,7 @@ public class DSavePlayer { Player player = plugin.getServer().getPlayer(playerName); boolean offline = false; if (player == null) { - player = OfflinePlayerUtil.getOfflinePlayer(playerName, UUID.fromString(uuid), oldLocation); + player = PlayerUtil.getOfflinePlayer(playerName, UUID.fromString(uuid), oldLocation); offline = true; } if (player == null) { @@ -96,7 +95,7 @@ public class DSavePlayer { } if ( !offline && oldLocation.getWorld() != null) { - MiscUtil.secureTeleport(player, oldLocation); + PlayerUtil.secureTeleport(player, oldLocation); } } catch (NullPointerException exception) { diff --git a/src/io/github/dre2n/dungeonsxl/requirement/FeeRequirement.java b/src/io/github/dre2n/dungeonsxl/requirement/FeeRequirement.java index dbd0e4c1..b30ee5e3 100644 --- a/src/io/github/dre2n/dungeonsxl/requirement/FeeRequirement.java +++ b/src/io/github/dre2n/dungeonsxl/requirement/FeeRequirement.java @@ -1,6 +1,6 @@ package io.github.dre2n.dungeonsxl.requirement; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import org.bukkit.entity.Player; @@ -47,7 +47,7 @@ public class FeeRequirement extends Requirement { } plugin.getEconomyProvider().withdrawPlayer(player, fee); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.REQUIREMENT_FEE, plugin.getEconomyProvider().format(fee))); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.REQUIREMENT_FEE, plugin.getEconomyProvider().format(fee))); } @Override diff --git a/src/io/github/dre2n/dungeonsxl/reward/MoneyReward.java b/src/io/github/dre2n/dungeonsxl/reward/MoneyReward.java index eb58134e..e1c7fcb4 100644 --- a/src/io/github/dre2n/dungeonsxl/reward/MoneyReward.java +++ b/src/io/github/dre2n/dungeonsxl/reward/MoneyReward.java @@ -1,6 +1,6 @@ package io.github.dre2n.dungeonsxl.reward; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import org.bukkit.entity.Player; @@ -41,7 +41,7 @@ public class MoneyReward extends Reward { } plugin.getEconomyProvider().depositPlayer(player, money); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.REWARD_MONEY, plugin.getEconomyProvider().format(money))); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.REWARD_MONEY, plugin.getEconomyProvider().format(money))); } @Override diff --git a/src/io/github/dre2n/dungeonsxl/sign/CheckpointSign.java b/src/io/github/dre2n/dungeonsxl/sign/CheckpointSign.java index f03af57f..c2bdea0f 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/CheckpointSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/CheckpointSign.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.sign; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -43,7 +43,7 @@ public class CheckpointSign extends DSign { for (DPlayer dplayer : DPlayer.getByWorld(getGameWorld().getWorld())) { dplayer.setCheckpoint(getSign().getLocation()); - MessageUtil.sendMessage(dplayer.getPlayer(), plugin.getDMessages().getMessage(Messages.PLAYER_CHECKPOINT_REACHED)); + MessageUtil.sendMessage(dplayer.getPlayer(), plugin.getMessageConfig().getMessage(Messages.PLAYER_CHECKPOINT_REACHED)); } remove(); @@ -60,7 +60,7 @@ public class CheckpointSign extends DSign { if ( !done.contains(dplayer)) { done.add(dplayer); dplayer.setCheckpoint(getSign().getLocation()); - MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_CHECKPOINT_REACHED)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_CHECKPOINT_REACHED)); } } diff --git a/src/io/github/dre2n/dungeonsxl/sign/InteractSign.java b/src/io/github/dre2n/dungeonsxl/sign/InteractSign.java index 5dfad9aa..1eb7b9a2 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/InteractSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/InteractSign.java @@ -2,6 +2,7 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.task.SignUpdateTask; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.util.NumberUtil; @@ -60,7 +61,9 @@ public class InteractSign extends DSign { } getSign().setLine(1, id + ""); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new UpdateTask(), 2); + + new SignUpdateTask(getSign()).runTaskLater(plugin, 2L); + return true; } @@ -89,15 +92,4 @@ public class InteractSign extends DSign { return type; } - public class UpdateTask implements Runnable { - - public UpdateTask() { - } - - @Override - public void run() { - getSign().update(); - } - } - } diff --git a/src/io/github/dre2n/dungeonsxl/sign/MobSign.java b/src/io/github/dre2n/dungeonsxl/sign/MobSign.java index 212206b4..8bde3361 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/MobSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/MobSign.java @@ -1,19 +1,11 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.mob.DMob; -import io.github.dre2n.dungeonsxl.mob.DMobType; +import io.github.dre2n.dungeonsxl.task.MobSpawnTask; import io.github.dre2n.dungeonsxl.util.NumberUtil; -import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Sign; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Skeleton; -import org.bukkit.entity.Skeleton.SkeletonType; -import org.bukkit.inventory.ItemStack; public class MobSign extends DSign { @@ -26,12 +18,117 @@ public class MobSign extends DSign { private int amount = 1; private boolean initialized; private boolean active; - private int taskId = -1; + private MobSpawnTask task; public MobSign(Sign sign, GameWorld gameWorld) { super(sign, gameWorld); } + /** + * @return the mob + */ + public String getMob() { + return mob; + } + + /** + * @param mob + * the mob to set + */ + public void setMob(String mob) { + this.mob = mob; + } + + /** + * @return the maxinterval + */ + public int getMaxinterval() { + return maxinterval; + } + + /** + * @param maxinterval + * the maxinterval to set + */ + public void setMaxinterval(int maxinterval) { + this.maxinterval = maxinterval; + } + + /** + * @return the interval + */ + public int getInterval() { + return interval; + } + + /** + * @param interval + * the interval to set + */ + public void setInterval(int interval) { + this.interval = interval; + } + + /** + * @return the amount + */ + public int getAmount() { + return amount; + } + + /** + * @param amount + * the amount to set + */ + public void setAmount(int amount) { + this.amount = amount; + } + + /** + * @return the initialized + */ + public boolean isInitialized() { + return initialized; + } + + /** + * @param initialized + * the initialized to set + */ + public void setInitialized(boolean initialized) { + this.initialized = initialized; + } + + /** + * @return the active + */ + public boolean isActive() { + return active; + } + + /** + * @param active + * the active to set + */ + public void setActive(boolean active) { + this.active = active; + } + + /** + * @return the task + */ + public MobSpawnTask getTask() { + return task; + } + + /** + * @param task + * the task to set + */ + public void setTask(MobSpawnTask task) { + this.task = task; + } + @Override public boolean check() { String lines[] = getSign().getLines(); @@ -77,9 +174,7 @@ public class MobSign extends DSign { return; } - MobSpawnScheduler scheduler = new MobSpawnScheduler(this); - - taskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, scheduler, 0L, 20L); + task = (MobSpawnTask) new MobSpawnTask(this).runTaskTimer(plugin, 0L, 20L); active = true; } @@ -100,72 +195,9 @@ public class MobSign extends DSign { return; } - if (taskId != -1) { - plugin.getServer().getScheduler().cancelTask(taskId); - taskId = -1; - } - } - - public class MobSpawnScheduler implements Runnable { - private MobSign sign; - - public MobSpawnScheduler(MobSign sign) { - this.sign = sign; - } - - @SuppressWarnings("deprecation") - @Override - public void run() { - if (sign.interval <= 0) { - World world = sign.getSign().getWorld(); - GameWorld gameWorld = GameWorld.getByWorld(world); - - if (gameWorld != null) { - Location spawnLoc = sign.getSign().getLocation().add(0.5, 0, 0.5); - - // Check normal mobs - if (EntityType.fromName(sign.mob) != null) { - if (EntityType.fromName(sign.mob).isAlive()) { - LivingEntity entity = (LivingEntity) world.spawnEntity(spawnLoc, EntityType.fromName(sign.mob)); - - // Add Bow to normal Skeletons - if (entity.getType() == EntityType.SKELETON) { - Skeleton skeleton = (Skeleton) entity; - if (skeleton.getSkeletonType() == SkeletonType.NORMAL) { - skeleton.getEquipment().setItemInHand(new ItemStack(Material.BOW)); - } - } - - // Disable Despawning - entity.setRemoveWhenFarAway(false); - - new DMob(entity, sign.getGameWorld(), null); - } - } - - // Check custom mobs - DMobType mobType = DMobType.getByName(sign.mob, gameWorld.getConfig().getMobTypes()); - - if (mobType != null) { - mobType.spawn(GameWorld.getByWorld(world), spawnLoc); - } - - // Set the amount - if (amount != -1) { - if (amount > 1) { - amount--; - } else { - killTask(); - sign.remove(); - } - } - - sign.interval = sign.maxinterval; - } else { - sign.killTask(); - } - } - sign.interval--; + if (task != null) { + task.cancel(); + task = null; } } diff --git a/src/io/github/dre2n/dungeonsxl/sign/MythicMobsSign.java b/src/io/github/dre2n/dungeonsxl/sign/MythicMobsSign.java index 8bdadb61..b7739d93 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/MythicMobsSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/MythicMobsSign.java @@ -1,15 +1,13 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.mob.DMob; +import io.github.dre2n.dungeonsxl.task.MythicMobSpawnTask; import io.github.dre2n.dungeonsxl.util.NumberUtil; import java.util.ArrayList; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -26,8 +24,8 @@ public class MythicMobsSign extends DSign { private int amount = 1; private boolean initialized; private boolean active; - private int taskId = -1; - private Location spawnLoc; + private MythicMobSpawnTask task; + private Location spawnLocation; private LivingEntity mythicMob; private ArrayList mythicMobs = new ArrayList(); @@ -35,6 +33,156 @@ public class MythicMobsSign extends DSign { super(sign, gameWorld); } + /** + * @return the mob + */ + public String getMob() { + return mob; + } + + /** + * @param mob + * the mob to set + */ + public void setMob(String mob) { + this.mob = mob; + } + + /** + * @return the maxinterval + */ + public int getMaxinterval() { + return maxinterval; + } + + /** + * @param maxinterval + * the maxinterval to set + */ + public void setMaxinterval(int maxinterval) { + this.maxinterval = maxinterval; + } + + /** + * @return the interval + */ + public int getInterval() { + return interval; + } + + /** + * @param interval + * the interval to set + */ + public void setInterval(int interval) { + this.interval = interval; + } + + /** + * @return the amount + */ + public int getAmount() { + return amount; + } + + /** + * @param amount + * the amount to set + */ + public void setAmount(int amount) { + this.amount = amount; + } + + /** + * @return the initialized + */ + public boolean isInitialized() { + return initialized; + } + + /** + * @param initialized + * the initialized to set + */ + public void setInitialized(boolean initialized) { + this.initialized = initialized; + } + + /** + * @return the active + */ + public boolean isActive() { + return active; + } + + /** + * @param active + * the active to set + */ + public void setActive(boolean active) { + this.active = active; + } + + /** + * @return the spawnLocation + */ + public Location getSpawnLocation() { + return spawnLocation; + } + + /** + * @param spawnLocation + * the spawnLocation to set + */ + public void setSpawnLocation(Location spawnLocation) { + this.spawnLocation = spawnLocation; + } + + /** + * @return the mythicMob + */ + public LivingEntity getMythicMob() { + return mythicMob; + } + + /** + * @param mythicMob + * the mythicMob to set + */ + public void setMythicMob(LivingEntity mythicMob) { + this.mythicMob = mythicMob; + } + + /** + * @return the mythicMobs + */ + public ArrayList getMythicMobs() { + return mythicMobs; + } + + /** + * @param mythicMobs + * the mythicMobs to set + */ + public void setMythicMobs(ArrayList mythicMobs) { + this.mythicMobs = mythicMobs; + } + + /** + * @return the task + */ + public MythicMobSpawnTask getTask() { + return task; + } + + /** + * @param task + * the task to set + */ + public void setTask(MythicMobSpawnTask task) { + this.task = task; + } + @Override public boolean check() { String lines[] = getSign().getLines(); @@ -63,9 +211,9 @@ public class MythicMobsSign extends DSign { if (mob != null) { String[] attributes = lines[2].split(","); if (attributes.length == 2) { - this.mob = mob; - maxinterval = NumberUtil.parseInt(attributes[0]); - amount = NumberUtil.parseInt(attributes[1]); + this.setMob(mob); + setMaxinterval(NumberUtil.parseInt(attributes[0])); + setAmount(NumberUtil.parseInt(attributes[1])); } } } @@ -80,9 +228,7 @@ public class MythicMobsSign extends DSign { return; } - MobSpawnScheduler scheduler = new MobSpawnScheduler(this); - - taskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, scheduler, 0L, 20L); + task = (MythicMobSpawnTask) new MythicMobSpawnTask(this).runTaskTimer(plugin, 0L, 20L); active = true; } @@ -94,7 +240,7 @@ public class MythicMobsSign extends DSign { } killTask(); - interval = 0; + setInterval(0); active = false; } @@ -103,64 +249,18 @@ public class MythicMobsSign extends DSign { return; } - if (taskId != -1) { - plugin.getServer().getScheduler().cancelTask(taskId); - taskId = -1; + if (task != null) { + task.cancel(); + task = null; } } - public class MobSpawnScheduler implements Runnable { - private MythicMobsSign sign; - - public MobSpawnScheduler(MythicMobsSign sign) { - this.sign = sign; - } - - @Override - public void run() { - if (sign.interval <= 0) { - World world = sign.getSign().getWorld(); - GameWorld gameWorld = GameWorld.getByWorld(world); - - if (gameWorld != null) { - spawnLoc = sign.getSign().getLocation().add(0.5, 0, 0.5); - double x = spawnLoc.getX(); - double y = spawnLoc.getY(); - double z = spawnLoc.getZ(); - - String command = "mm mobs spawn " + mob + " " + amount + " DXL_Game_" + gameWorld.getId() + "," + x + "," + y + "," + z; - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command); - - setMythicMobs(); - if (mythicMob != null) { - new DMob(mythicMob, sign.getGameWorld(), null, mob); - } - - // Set the amount - if (amount != -1) { - if (amount > 1) { - amount--; - } else { - killTask(); - sign.remove(); - } - } - - sign.interval = sign.maxinterval; - } else { - sign.killTask(); - } - } - sign.interval--; - } - } - - private void setMythicMobs() { - for (Entity entity : spawnLoc.getChunk().getEntities()) { - if (entity.getLocation().getX() >= spawnLoc.getX() - 1 && entity.getLocation().getX() <= spawnLoc.getX() + 1 && entity.getLocation().getY() >= spawnLoc.getY() - 1 - && entity.getLocation().getY() <= spawnLoc.getY() + 1 && entity.getLocation().getZ() >= spawnLoc.getZ() - 1 && entity.getLocation().getZ() <= spawnLoc.getZ() + 1 + public void setMythicMobs() { + for (Entity entity : spawnLocation.getChunk().getEntities()) { + if (entity.getLocation().getX() >= spawnLocation.getX() - 1 && entity.getLocation().getX() <= spawnLocation.getX() + 1 && entity.getLocation().getY() >= spawnLocation.getY() - 1 + && entity.getLocation().getY() <= spawnLocation.getY() + 1 && entity.getLocation().getZ() >= spawnLocation.getZ() - 1 && entity.getLocation().getZ() <= spawnLocation.getZ() + 1 && !mythicMobs.contains(entity) && entity.isCustomNameVisible() && !(entity instanceof Player)) { - mythicMob = (LivingEntity) entity; + setMythicMob((LivingEntity) entity); mythicMobs.add(entity); return; } diff --git a/src/io/github/dre2n/dungeonsxl/sign/ReadySign.java b/src/io/github/dre2n/dungeonsxl/sign/ReadySign.java index 6614b0ab..537e3a52 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/ReadySign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/ReadySign.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.sign; +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; -import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; @@ -68,11 +68,11 @@ public class ReadySign extends DSign { if (getGameWorld().getSignClass().isEmpty() || dPlayer.getDClass() != null) { dPlayer.ready(); - MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getDMessages().getMessage(Messages.PLAYER_READY)); + MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(Messages.PLAYER_READY)); return; } else { - MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getDMessages().getMessage(Messages.ERROR_READY)); + MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(Messages.ERROR_READY)); } } diff --git a/src/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java b/src/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java index 28d00275..0b8c12f6 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java @@ -1,7 +1,7 @@ package io.github.dre2n.dungeonsxl.sign; -import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.task.DelayedPowerTask; import io.github.dre2n.dungeonsxl.util.NumberUtil; import org.bukkit.Material; @@ -15,16 +15,151 @@ public class RedstoneSign extends DSign { // Variables private boolean initialized; private boolean active; - private int enableTaskId = -1; - private int disableTaskId = -1; + private DelayedPowerTask enableTask; + private DelayedPowerTask disableTask; private Block block; private long delay = 0; private long offDelay = 0; private int repeat = 1; private int repeatsToDo = 1; - public RedstoneSign(Sign sign, GameWorld gworld) { - super(sign, gworld); + public RedstoneSign(Sign sign, GameWorld gameWorld) { + super(sign, gameWorld); + } + + /** + * @return the initialized + */ + public boolean isInitialized() { + return initialized; + } + + /** + * @param initialized + * the initialized to set + */ + public void setInitialized(boolean initialized) { + this.initialized = initialized; + } + + /** + * @return the active + */ + public boolean isActive() { + return active; + } + + /** + * @param active + * the active to set + */ + public void setActive(boolean active) { + this.active = active; + } + + /** + * @return the enableTask + */ + public DelayedPowerTask getEnableTask() { + return enableTask; + } + + /** + * @param enableTask + * the enableTask to set + */ + public void setEnableTask(DelayedPowerTask enableTask) { + this.enableTask = enableTask; + } + + /** + * @return the disableTask + */ + public DelayedPowerTask getDisableTask() { + return disableTask; + } + + /** + * @param disableTask + * the disableTask to set + */ + public void setDisableTask(DelayedPowerTask disableTask) { + this.disableTask = disableTask; + } + + /** + * @return the block + */ + public Block getBlock() { + return block; + } + + /** + * @param block + * the block to set + */ + public void setBlock(Block block) { + this.block = block; + } + + /** + * @return the delay + */ + public long getDelay() { + return delay; + } + + /** + * @param delay + * the delay to set + */ + public void setDelay(long delay) { + this.delay = delay; + } + + /** + * @return the offDelay + */ + public long getOffDelay() { + return offDelay; + } + + /** + * @param offDelay + * the offDelay to set + */ + public void setOffDelay(long offDelay) { + this.offDelay = offDelay; + } + + /** + * @return the repeat + */ + public int getRepeat() { + return repeat; + } + + /** + * @param repeat + * the repeat to set + */ + public void setRepeat(int repeat) { + this.repeat = repeat; + } + + /** + * @return the repeatsToDo + */ + public int getRepeatsToDo() { + return repeatsToDo; + } + + /** + * @param repeatsToDo + * the repeatsToDo to set + */ + public void setRepeatsToDo(int repeatsToDo) { + this.repeatsToDo = repeatsToDo; } @Override @@ -74,11 +209,11 @@ public class RedstoneSign extends DSign { } if (delay > 0) { - enableTaskId = DungeonsXL.getPlugin().getServer().getScheduler().scheduleSyncRepeatingTask(DungeonsXL.getPlugin(), new DelayedPower(true), delay, delay + offDelay); + enableTask = (DelayedPowerTask) new DelayedPowerTask(this, true).runTaskTimer(plugin, delay, delay + offDelay); if (repeat != 1) { repeatsToDo = repeat; - disableTaskId = DungeonsXL.getPlugin().getServer().getScheduler().scheduleSyncRepeatingTask(DungeonsXL.getPlugin(), new DelayedPower(false), delay + offDelay, delay + offDelay); + disableTask = (DelayedPowerTask) new DelayedPowerTask(this, false).runTaskTimer(plugin, delay + offDelay, delay + offDelay); } } else { @@ -96,10 +231,8 @@ public class RedstoneSign extends DSign { unpower(); - disableTask(enableTaskId); - disableTask(disableTaskId); - enableTaskId = -1; - disableTaskId = -1; + enableTask.cancel(); + disableTask.cancel(); active = false; } @@ -112,50 +245,9 @@ public class RedstoneSign extends DSign { block.setType(Material.AIR); } - public void disableTask(int taskId) { - if (taskId == -1) { - return; - } - - if (DungeonsXL.getPlugin().getServer().getScheduler().isCurrentlyRunning(taskId) || DungeonsXL.getPlugin().getServer().getScheduler().isQueued(taskId)) { - DungeonsXL.getPlugin().getServer().getScheduler().cancelTask(taskId); - } - } - @Override public DSignType getType() { return type; } - public class DelayedPower implements Runnable { - private final boolean enable; - - public DelayedPower(boolean enable) { - this.enable = enable; - } - - @Override - public void run() { - if (GameWorld.getByWorld(block.getWorld()) == null) { - disableTask(enableTaskId); - disableTask(disableTaskId); - return; - } - if (enable) { - power(); - if (repeatsToDo == 1) { - disableTask(enableTaskId); - enableTaskId = -1; - } - } else { - unpower(); - if (repeatsToDo == 1) { - disableTask(disableTaskId); - disableTaskId = -1; - } - repeatsToDo--; - } - } - } - } diff --git a/src/io/github/dre2n/dungeonsxl/sign/TriggerSign.java b/src/io/github/dre2n/dungeonsxl/sign/TriggerSign.java index 506d84d5..d2ed62e5 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/TriggerSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/TriggerSign.java @@ -2,6 +2,7 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.task.SignUpdateTask; import io.github.dre2n.dungeonsxl.trigger.SignTrigger; import io.github.dre2n.dungeonsxl.util.NumberUtil; @@ -62,7 +63,9 @@ public class TriggerSign extends DSign { } getSign().setLine(1, id + ""); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new UpdateTask(), 2); + + new SignUpdateTask(getSign()).runTaskLater(plugin, 2L); + return true; } @@ -103,15 +106,4 @@ public class TriggerSign extends DSign { return type; } - public class UpdateTask implements Runnable { - - public UpdateTask() { - } - - @Override - public void run() { - getSign().update(); - } - } - } diff --git a/src/io/github/dre2n/dungeonsxl/task/DelayedPowerTask.java b/src/io/github/dre2n/dungeonsxl/task/DelayedPowerTask.java new file mode 100644 index 00000000..b2ae0730 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/DelayedPowerTask.java @@ -0,0 +1,38 @@ +package io.github.dre2n.dungeonsxl.task; + +import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.sign.RedstoneSign; + +import org.bukkit.scheduler.BukkitRunnable; + +public class DelayedPowerTask extends BukkitRunnable { + + private RedstoneSign sign; + private boolean enable; + + public DelayedPowerTask(RedstoneSign sign, boolean enable) { + this.sign = sign; + this.enable = enable; + } + + @Override + public void run() { + if (GameWorld.getByWorld(sign.getBlock().getWorld()) == null) { + sign.getEnableTask().cancel(); + sign.getDisableTask().cancel(); + return; + } + if (enable) { + sign.power(); + if (sign.getRepeatsToDo() == 1) { + sign.getEnableTask().cancel(); + } + } else { + sign.unpower(); + if (sign.getRepeatsToDo() == 1) { + sign.getDisableTask().cancel(); + } + sign.setRepeatsToDo(sign.getRepeatsToDo() - 1); + } + } +} diff --git a/src/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java b/src/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java new file mode 100644 index 00000000..2388ad42 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java @@ -0,0 +1,24 @@ +package io.github.dre2n.dungeonsxl.task; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.player.DPlayer; + +import org.bukkit.scheduler.BukkitRunnable; + +public class LazyUpdateTask extends BukkitRunnable { + + static DungeonsXL plugin = DungeonsXL.getPlugin(); + + @Override + public void run() { + for (GameWorld gameWorld : plugin.getGameWorlds()) { + gameWorld.update(); + } + + for (DPlayer dPlayer : plugin.getDPlayers()) { + dPlayer.update(true); + } + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java b/src/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java new file mode 100644 index 00000000..e9616b99 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java @@ -0,0 +1,81 @@ +package io.github.dre2n.dungeonsxl.task; + +import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.mob.DMob; +import io.github.dre2n.dungeonsxl.mob.DMobType; +import io.github.dre2n.dungeonsxl.sign.MobSign; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Skeleton.SkeletonType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; + +public class MobSpawnTask extends BukkitRunnable { + + private MobSign sign; + + public MobSpawnTask(MobSign sign) { + this.sign = sign; + } + + @SuppressWarnings("deprecation") + @Override + public void run() { + if (sign.getInterval() <= 0) { + World world = sign.getSign().getWorld(); + GameWorld gameWorld = GameWorld.getByWorld(world); + + if (gameWorld != null) { + Location spawnLoc = sign.getSign().getLocation().add(0.5, 0, 0.5); + + // Check normal mobs + if (EntityType.fromName(sign.getMob()) != null) { + if (EntityType.fromName(sign.getMob()).isAlive()) { + LivingEntity entity = (LivingEntity) world.spawnEntity(spawnLoc, EntityType.fromName(sign.getMob())); + + // Add Bow to normal Skeletons + if (entity.getType() == EntityType.SKELETON) { + Skeleton skeleton = (Skeleton) entity; + if (skeleton.getSkeletonType() == SkeletonType.NORMAL) { + skeleton.getEquipment().setItemInHand(new ItemStack(Material.BOW)); + } + } + + // Disable Despawning + entity.setRemoveWhenFarAway(false); + + new DMob(entity, sign.getGameWorld(), null); + } + } + + // Check custom mobs + DMobType mobType = DMobType.getByName(sign.getMob(), gameWorld.getConfig().getMobTypes()); + + if (mobType != null) { + mobType.spawn(GameWorld.getByWorld(world), spawnLoc); + } + + // Set the amount + if (sign.getAmount() != -1) { + if (sign.getAmount() > 1) { + sign.setAmount(sign.getAmount() - 1); + } else { + sign.killTask(); + sign.remove(); + } + } + + sign.setInterval(sign.getMaxinterval()); + } else { + sign.killTask(); + } + } + sign.setInterval(sign.getInterval() - 1); + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/task/MythicMobSpawnTask.java b/src/io/github/dre2n/dungeonsxl/task/MythicMobSpawnTask.java new file mode 100644 index 00000000..910be36a --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/MythicMobSpawnTask.java @@ -0,0 +1,57 @@ +package io.github.dre2n.dungeonsxl.task; + +import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.mob.DMob; +import io.github.dre2n.dungeonsxl.sign.MythicMobsSign; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.scheduler.BukkitRunnable; + +public class MythicMobSpawnTask extends BukkitRunnable { + + private MythicMobsSign sign; + + public MythicMobSpawnTask(MythicMobsSign sign) { + this.sign = sign; + } + + @Override + public void run() { + if (sign.getInterval() <= 0) { + World world = sign.getSign().getWorld(); + GameWorld gameWorld = GameWorld.getByWorld(world); + + if (gameWorld != null) { + sign.setSpawnLocation(sign.getSign().getLocation().add(0.5, 0, 0.5)); + double x = sign.getSpawnLocation().getX(); + double y = sign.getSpawnLocation().getY(); + double z = sign.getSpawnLocation().getZ(); + + String command = "mm mobs spawn " + sign.getMob() + " " + sign.getAmount() + " DXL_Game_" + gameWorld.getId() + "," + x + "," + y + "," + z; + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command); + + sign.setMythicMobs(); + if (sign.getMythicMob() != null) { + new DMob(sign.getMythicMob(), sign.getGameWorld(), null, sign.getMob()); + } + + // Set the amount + if (sign.getAmount() != -1) { + if (sign.getAmount() > 1) { + sign.setAmount(sign.getAmount() - 1); + } else { + sign.killTask(); + sign.remove(); + } + } + + sign.setInterval(sign.getMaxinterval()); + } else { + sign.killTask(); + } + } + sign.setInterval(sign.getInterval() - 1); + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java b/src/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java new file mode 100644 index 00000000..257c2051 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java @@ -0,0 +1,27 @@ +package io.github.dre2n.dungeonsxl.task; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger; + +import org.bukkit.block.Block; +import org.bukkit.scheduler.BukkitRunnable; + +public class RedstoneEventTask extends BukkitRunnable { + + private final Block block; + + public RedstoneEventTask(final Block block) { + this.block = block; + } + + @Override + public void run() { + for (GameWorld gameWorld : DungeonsXL.getPlugin().getGameWorlds()) { + if (block.getWorld() == gameWorld.getWorld()) { + RedstoneTrigger.updateAll(gameWorld); + } + } + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/task/RespawnTask.java b/src/io/github/dre2n/dungeonsxl/task/RespawnTask.java new file mode 100644 index 00000000..72609762 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/RespawnTask.java @@ -0,0 +1,41 @@ +package io.github.dre2n.dungeonsxl.task; + +import io.github.dre2n.dungeonsxl.player.DPlayer; +import io.github.dre2n.dungeonsxl.util.playerutil.PlayerUtil; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +public class RespawnTask extends BukkitRunnable { + + private Player player; + private Location location; + + public RespawnTask(Player player, Location location) { + this.location = location; + this.player = player; + } + + @Override + public void run() { + if (player.getLocation().distance(location) > 2) { + PlayerUtil.secureTeleport(player, location); + } + + DPlayer dPlayer = DPlayer.getByPlayer(player); + + if (dPlayer == null) { + return; + } + + // Respawn Items + if (dPlayer.getRespawnInventory() != null || dPlayer.getRespawnArmor() != null) { + player.getInventory().setContents(dPlayer.getRespawnInventory()); + player.getInventory().setArmorContents(dPlayer.getRespawnArmor()); + dPlayer.setRespawnInventory(null); + dPlayer.setRespawnArmor(null); + } + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/task/SignUpdateTask.java b/src/io/github/dre2n/dungeonsxl/task/SignUpdateTask.java new file mode 100644 index 00000000..0ea842bc --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/SignUpdateTask.java @@ -0,0 +1,19 @@ +package io.github.dre2n.dungeonsxl.task; + +import org.bukkit.block.Sign; +import org.bukkit.scheduler.BukkitRunnable; + +public class SignUpdateTask extends BukkitRunnable { + + private Sign sign; + + public SignUpdateTask(Sign sign) { + this.sign = sign; + } + + @Override + public void run() { + sign.update(); + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/task/UpdateTask.java b/src/io/github/dre2n/dungeonsxl/task/UpdateTask.java new file mode 100644 index 00000000..ce0d2344 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/UpdateTask.java @@ -0,0 +1,17 @@ +package io.github.dre2n.dungeonsxl.task; + +import org.bukkit.scheduler.BukkitRunnable; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.player.DPlayer; + +public class UpdateTask extends BukkitRunnable { + + @Override + public void run() { + for (DPlayer dPlayer : DungeonsXL.getPlugin().getDPlayers()) { + dPlayer.update(false); + } + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java b/src/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java new file mode 100644 index 00000000..a6687bcd --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java @@ -0,0 +1,31 @@ +package io.github.dre2n.dungeonsxl.task; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.dungeon.EditWorld; +import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.player.DPlayer; + +import org.bukkit.scheduler.BukkitRunnable; + +public class WorldUnloadTask extends BukkitRunnable { + + static DungeonsXL plugin = DungeonsXL.getPlugin(); + + @Override + public void run() { + for (GameWorld gameWorld : plugin.getGameWorlds()) { + if (gameWorld.getWorld().getPlayers().isEmpty()) { + if (DPlayer.getByWorld(gameWorld.getWorld()).isEmpty()) { + gameWorld.delete(); + } + } + } + + for (EditWorld editWorld : plugin.getEditWorlds()) { + if (editWorld.getWorld().getPlayers().isEmpty()) { + editWorld.delete(); + } + } + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/util/MiscUtil.java b/src/io/github/dre2n/dungeonsxl/util/MiscUtil.java deleted file mode 100644 index fa6c56cc..00000000 --- a/src/io/github/dre2n/dungeonsxl/util/MiscUtil.java +++ /dev/null @@ -1,95 +0,0 @@ -package io.github.dre2n.dungeonsxl.util; - -import io.github.dre2n.dungeonsxl.DungeonsXL; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.ObjectInputStream; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.block.Block; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -public class MiscUtil { - public static DungeonsXL p = DungeonsXL.getPlugin(); - - public static void convertOldSigns() { - File file = new File(p.getDataFolder(), "/dungeons/"); - - if (file.exists()) { - for (File dungeonFolder : file.listFiles()) { - if (dungeonFolder.isDirectory()) { - FileUtil.copyDirectory(dungeonFolder, new File("DXL_TMP")); - - World world = p.getServer().createWorld(WorldCreator.name("DXL_TMP")); - - // World - try { - ObjectInputStream os = new ObjectInputStream(new FileInputStream(new File(p.getDataFolder(), "/dungeons/" + dungeonFolder.getName() + "/DXLData.data"))); - int length = os.readInt(); - for (int i = 0; i < length; i++) { - int x = os.readInt(); - int y = os.readInt(); - int z = os.readInt(); - Block block = world.getBlockAt(x, y, z); - - if (block.getState() instanceof Sign) { - Sign sign = (Sign) block.getState(); - - if (sign.getLine(0).equalsIgnoreCase("[dxl]")) { - sign.setLine(0, "[" + sign.getLine(1) + "]"); - sign.setLine(1, sign.getLine(2)); - sign.setLine(2, sign.getLine(3)); - sign.update(); - - if (sign.getLine(0).equalsIgnoreCase("[mob]")) { - String[] splitted = sign.getLine(2).split(","); - if (splitted.length >= 3) { - sign.setLine(2, splitted[0] + "," + splitted[1]); - sign.setLine(3, "D " + splitted[2]); - } - } - - if (sign.getLine(0).equalsIgnoreCase("[msg]") || sign.getLine(0).equalsIgnoreCase("[soundmsg]")) { - sign.setLine(3, "D " + sign.getLine(2)); - sign.setLine(2, ""); - } - - if (sign.getLine(0).equalsIgnoreCase("[checkpoint]")) { - sign.setLine(3, "D " + sign.getLine(1)); - sign.setLine(1, ""); - } - - sign.update(); - } - } - } - - os.close(); - p.getServer().unloadWorld(world, true); - FileUtil.copyDirectory(new File("DXL_TMP"), dungeonFolder); - FileUtil.removeDirectory(new File("DXL_TMP")); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } - } - - public static void secureTeleport(Player player, Location location) { - if (player.isInsideVehicle()) { - player.leaveVehicle(); - } - - player.teleport(location); - } - -} diff --git a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/OfflinePlayerUtil.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java similarity index 89% rename from src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/OfflinePlayerUtil.java rename to src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java index 60e9d6c3..32d6f8dd 100644 --- a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/OfflinePlayerUtil.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.util.offlineplayerutil; +package io.github.dre2n.dungeonsxl.util.playerutil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.util.VersionUtil; @@ -9,7 +9,7 @@ import java.util.UUID; import org.bukkit.Location; import org.bukkit.entity.Player; -public class OfflinePlayerUtil { +public class PlayerUtil { public static Player getOfflinePlayer(String player, UUID uuid) { VersionUtil versions = DungeonsXL.getPlugin().getVersion(); @@ -63,4 +63,12 @@ public class OfflinePlayerUtil { } } + public static void secureTeleport(Player player, Location location) { + if (player.isInsideVehicle()) { + player.leaveVehicle(); + } + + player.teleport(location); + } + } diff --git a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_7_R3.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java similarity index 97% rename from src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_7_R3.java rename to src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java index da2f1e44..b139c5f6 100644 --- a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_7_R3.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.util.offlineplayerutil; +package io.github.dre2n.dungeonsxl.util.playerutil; import java.io.File; import java.util.UUID; diff --git a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_7_R4.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java similarity index 97% rename from src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_7_R4.java rename to src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java index 917db00e..c50fee13 100644 --- a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_7_R4.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.util.offlineplayerutil; +package io.github.dre2n.dungeonsxl.util.playerutil; import java.io.File; import java.util.UUID; diff --git a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R1.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java similarity index 97% rename from src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R1.java rename to src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java index d13417ac..3feb37c9 100644 --- a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R1.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.util.offlineplayerutil; +package io.github.dre2n.dungeonsxl.util.playerutil; import java.io.File; import java.util.UUID; diff --git a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R2.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java similarity index 97% rename from src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R2.java rename to src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java index 26cb5ace..030e63d5 100644 --- a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R2.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.util.offlineplayerutil; +package io.github.dre2n.dungeonsxl.util.playerutil; import java.io.File; import java.util.UUID; diff --git a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R3.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java similarity index 97% rename from src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R3.java rename to src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java index d2ecf380..419cb2ac 100644 --- a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_8_R3.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.util.offlineplayerutil; +package io.github.dre2n.dungeonsxl.util.playerutil; import java.io.File; import java.util.UUID; diff --git a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_9_R1.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java similarity index 97% rename from src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_9_R1.java rename to src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java index 44ed1ee3..4d1ca647 100644 --- a/src/io/github/dre2n/dungeonsxl/util/offlineplayerutil/v1_9_R1.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java @@ -1,4 +1,4 @@ -package io.github.dre2n.dungeonsxl.util.offlineplayerutil; +package io.github.dre2n.dungeonsxl.util.playerutil; import java.io.File; import java.util.UUID; From 73bb925df29e234e7364498380667a11fa57d96a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sat, 16 Jan 2016 20:55:46 +0100 Subject: [PATCH 2/4] Fix cast exceptions --- .../github/dre2n/dungeonsxl/DungeonsXL.java | 19 ++++++++++--------- .../github/dre2n/dungeonsxl/sign/MobSign.java | 9 +++++---- .../dre2n/dungeonsxl/sign/MythicMobsSign.java | 9 +++++---- .../dre2n/dungeonsxl/sign/RedstoneSign.java | 17 +++++++++-------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/io/github/dre2n/dungeonsxl/DungeonsXL.java index a7eed9a3..2402792e 100644 --- a/src/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -44,6 +44,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; public class DungeonsXL extends JavaPlugin { @@ -63,9 +64,9 @@ public class DungeonsXL extends JavaPlugin { private Triggers triggers; private Dungeons dungeons; - private WorldUnloadTask worldUnloadTask; - private LazyUpdateTask lazyUpdateTask; - private UpdateTask updateTask; + private BukkitTask worldUnloadTask; + private BukkitTask lazyUpdateTask; + private BukkitTask updateTask; private CopyOnWriteArrayList inBreakMode = new CopyOnWriteArrayList(); private CopyOnWriteArrayList chatSpyers = new CopyOnWriteArrayList(); @@ -434,7 +435,7 @@ public class DungeonsXL extends JavaPlugin { /** * @return the worldUnloadTask */ - public WorldUnloadTask getWorldUnloadTask() { + public BukkitTask getWorldUnloadTask() { return worldUnloadTask; } @@ -442,13 +443,13 @@ public class DungeonsXL extends JavaPlugin { * start a new WorldUnloadTask */ public void startWorldUnloadTask(long period) { - worldUnloadTask = (WorldUnloadTask) new WorldUnloadTask().runTaskTimerAsynchronously(this, 0L, period); + worldUnloadTask = new WorldUnloadTask().runTaskTimerAsynchronously(this, 0L, period); } /** * @return the lazyUpdateTask */ - public LazyUpdateTask getLazyUpdateTask() { + public BukkitTask getLazyUpdateTask() { return lazyUpdateTask; } @@ -456,13 +457,13 @@ public class DungeonsXL extends JavaPlugin { * start a new LazyUpdateTask */ public void startLazyUpdateTask(long period) { - lazyUpdateTask = (LazyUpdateTask) new LazyUpdateTask().runTaskTimerAsynchronously(this, 0L, period); + lazyUpdateTask = new LazyUpdateTask().runTaskTimerAsynchronously(this, 0L, period); } /** * @return the updateTask */ - public UpdateTask getUpdateTask() { + public BukkitTask getUpdateTask() { return updateTask; } @@ -470,7 +471,7 @@ public class DungeonsXL extends JavaPlugin { * start a new LazyUpdateTask */ public void startUpdateTask(long period) { - updateTask = (UpdateTask) new UpdateTask().runTaskTimerAsynchronously(this, 0L, period); + updateTask = new UpdateTask().runTaskTimerAsynchronously(this, 0L, period); } /** diff --git a/src/io/github/dre2n/dungeonsxl/sign/MobSign.java b/src/io/github/dre2n/dungeonsxl/sign/MobSign.java index 8bde3361..21bf0d2e 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/MobSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/MobSign.java @@ -6,6 +6,7 @@ import io.github.dre2n.dungeonsxl.util.NumberUtil; import org.bukkit.Material; import org.bukkit.block.Sign; +import org.bukkit.scheduler.BukkitTask; public class MobSign extends DSign { @@ -18,7 +19,7 @@ public class MobSign extends DSign { private int amount = 1; private boolean initialized; private boolean active; - private MobSpawnTask task; + private BukkitTask task; public MobSign(Sign sign, GameWorld gameWorld) { super(sign, gameWorld); @@ -117,7 +118,7 @@ public class MobSign extends DSign { /** * @return the task */ - public MobSpawnTask getTask() { + public BukkitTask getTask() { return task; } @@ -125,7 +126,7 @@ public class MobSign extends DSign { * @param task * the task to set */ - public void setTask(MobSpawnTask task) { + public void setTask(BukkitTask task) { this.task = task; } @@ -174,7 +175,7 @@ public class MobSign extends DSign { return; } - task = (MobSpawnTask) new MobSpawnTask(this).runTaskTimer(plugin, 0L, 20L); + task = new MobSpawnTask(this).runTaskTimer(plugin, 0L, 20L); active = true; } diff --git a/src/io/github/dre2n/dungeonsxl/sign/MythicMobsSign.java b/src/io/github/dre2n/dungeonsxl/sign/MythicMobsSign.java index b7739d93..f4b7578a 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/MythicMobsSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/MythicMobsSign.java @@ -12,6 +12,7 @@ import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; public class MythicMobsSign extends DSign { @@ -24,7 +25,7 @@ public class MythicMobsSign extends DSign { private int amount = 1; private boolean initialized; private boolean active; - private MythicMobSpawnTask task; + private BukkitTask task; private Location spawnLocation; private LivingEntity mythicMob; private ArrayList mythicMobs = new ArrayList(); @@ -171,7 +172,7 @@ public class MythicMobsSign extends DSign { /** * @return the task */ - public MythicMobSpawnTask getTask() { + public BukkitTask getTask() { return task; } @@ -179,7 +180,7 @@ public class MythicMobsSign extends DSign { * @param task * the task to set */ - public void setTask(MythicMobSpawnTask task) { + public void setTask(BukkitTask task) { this.task = task; } @@ -228,7 +229,7 @@ public class MythicMobsSign extends DSign { return; } - task = (MythicMobSpawnTask) new MythicMobSpawnTask(this).runTaskTimer(plugin, 0L, 20L); + task = new MythicMobSpawnTask(this).runTaskTimer(plugin, 0L, 20L); active = true; } diff --git a/src/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java b/src/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java index 0b8c12f6..2f775e35 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java @@ -7,6 +7,7 @@ import io.github.dre2n.dungeonsxl.util.NumberUtil; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; +import org.bukkit.scheduler.BukkitTask; public class RedstoneSign extends DSign { @@ -15,8 +16,8 @@ public class RedstoneSign extends DSign { // Variables private boolean initialized; private boolean active; - private DelayedPowerTask enableTask; - private DelayedPowerTask disableTask; + private BukkitTask enableTask; + private BukkitTask disableTask; private Block block; private long delay = 0; private long offDelay = 0; @@ -60,7 +61,7 @@ public class RedstoneSign extends DSign { /** * @return the enableTask */ - public DelayedPowerTask getEnableTask() { + public BukkitTask getEnableTask() { return enableTask; } @@ -68,14 +69,14 @@ public class RedstoneSign extends DSign { * @param enableTask * the enableTask to set */ - public void setEnableTask(DelayedPowerTask enableTask) { + public void setEnableTask(BukkitTask enableTask) { this.enableTask = enableTask; } /** * @return the disableTask */ - public DelayedPowerTask getDisableTask() { + public BukkitTask getDisableTask() { return disableTask; } @@ -83,7 +84,7 @@ public class RedstoneSign extends DSign { * @param disableTask * the disableTask to set */ - public void setDisableTask(DelayedPowerTask disableTask) { + public void setDisableTask(BukkitTask disableTask) { this.disableTask = disableTask; } @@ -209,11 +210,11 @@ public class RedstoneSign extends DSign { } if (delay > 0) { - enableTask = (DelayedPowerTask) new DelayedPowerTask(this, true).runTaskTimer(plugin, delay, delay + offDelay); + enableTask = new DelayedPowerTask(this, true).runTaskTimer(plugin, delay, delay + offDelay); if (repeat != 1) { repeatsToDo = repeat; - disableTask = (DelayedPowerTask) new DelayedPowerTask(this, false).runTaskTimer(plugin, delay + offDelay, delay + offDelay); + disableTask = new DelayedPowerTask(this, false).runTaskTimer(plugin, delay + offDelay, delay + offDelay); } } else { From db96fb4014a8d41c7a0aeab709953449b9c7c0c1 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 21 Jan 2016 13:55:49 +0100 Subject: [PATCH 3/4] :C --- src/io/github/dre2n/dungeonsxl/DungeonsXL.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/io/github/dre2n/dungeonsxl/DungeonsXL.java index 2402792e..c8a5df80 100644 --- a/src/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -443,7 +443,7 @@ public class DungeonsXL extends JavaPlugin { * start a new WorldUnloadTask */ public void startWorldUnloadTask(long period) { - worldUnloadTask = new WorldUnloadTask().runTaskTimerAsynchronously(this, 0L, period); + worldUnloadTask = new WorldUnloadTask().runTaskTimer(this, 0L, period); } /** @@ -457,7 +457,7 @@ public class DungeonsXL extends JavaPlugin { * start a new LazyUpdateTask */ public void startLazyUpdateTask(long period) { - lazyUpdateTask = new LazyUpdateTask().runTaskTimerAsynchronously(this, 0L, period); + lazyUpdateTask = new LazyUpdateTask().runTaskTimer(this, 0L, period); } /** @@ -471,7 +471,7 @@ public class DungeonsXL extends JavaPlugin { * start a new LazyUpdateTask */ public void startUpdateTask(long period) { - updateTask = new UpdateTask().runTaskTimerAsynchronously(this, 0L, period); + updateTask = new UpdateTask().runTaskTimer(this, 0L, period); } /** From 69e12306904e863a8390988ec521584126d4dce1 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 27 Jan 2016 20:19:28 +0100 Subject: [PATCH 4/4] Advanced groups --- .../dre2n/dungeonsxl/command/ChatCommand.java | 2 +- .../dre2n/dungeonsxl/command/DCommands.java | 1 + .../dungeonsxl/command/GroupCommand.java | 247 ++++++++++++++++++ .../dre2n/dungeonsxl/command/PlayCommand.java | 50 +++- .../dre2n/dungeonsxl/command/TestCommand.java | 51 +++- .../dungeonsxl/config/MessageConfig.java | 29 +- .../event/dgroup/DGroupCreateEvent.java | 2 +- .../event/dgroup/DGroupDisbandEvent.java | 86 ++++++ .../event/dplayer/DPlayerKickEvent.java | 29 +- .../dre2n/dungeonsxl/global/DPortal.java | 2 +- .../dungeonsxl/listener/EntityListener.java | 3 + .../dungeonsxl/listener/PlayerListener.java | 19 +- .../dre2n/dungeonsxl/player/DGroup.java | 213 ++++++++++++--- .../dre2n/dungeonsxl/player/DPlayer.java | 38 ++- .../util/playerutil/PlayerUtil.java | 41 ++- .../dungeonsxl/util/playerutil/v1_7_R3.java | 28 +- .../dungeonsxl/util/playerutil/v1_7_R4.java | 28 +- .../dungeonsxl/util/playerutil/v1_8_R1.java | 28 +- .../dungeonsxl/util/playerutil/v1_8_R2.java | 28 +- .../dungeonsxl/util/playerutil/v1_8_R3.java | 28 +- .../dungeonsxl/util/playerutil/v1_9_R1.java | 28 +- src/plugin.yml | 4 + 22 files changed, 803 insertions(+), 182 deletions(-) create mode 100644 src/io/github/dre2n/dungeonsxl/command/GroupCommand.java create mode 100644 src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java diff --git a/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java b/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java index 901667b2..53c7af44 100644 --- a/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java @@ -24,7 +24,7 @@ public class ChatCommand extends DCommand { DPlayer dplayer = DPlayer.getByPlayer(player); if (dplayer == null) { - MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); return; } diff --git a/src/io/github/dre2n/dungeonsxl/command/DCommands.java b/src/io/github/dre2n/dungeonsxl/command/DCommands.java index c9ba0518..8044e1a1 100644 --- a/src/io/github/dre2n/dungeonsxl/command/DCommands.java +++ b/src/io/github/dre2n/dungeonsxl/command/DCommands.java @@ -17,6 +17,7 @@ public class DCommands { dCommands.add(new CreateCommand()); dCommands.add(new EditCommand()); dCommands.add(new EscapeCommand()); + dCommands.add(new GroupCommand()); dCommands.add(new InviteCommand()); dCommands.add(new LeaveCommand()); dCommands.add(new ListCommand()); diff --git a/src/io/github/dre2n/dungeonsxl/command/GroupCommand.java b/src/io/github/dre2n/dungeonsxl/command/GroupCommand.java new file mode 100644 index 00000000..7951f8a5 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/command/GroupCommand.java @@ -0,0 +1,247 @@ +package io.github.dre2n.dungeonsxl.command; + +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupDisbandEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; +import io.github.dre2n.dungeonsxl.player.DGroup; +import io.github.dre2n.dungeonsxl.player.DPlayer; +import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class GroupCommand extends DCommand { + + public GroupCommand() { + setCommand("group"); + setMinArgs(0); + setMaxArgs(2); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_GROUP)); + setPermission("dxl.group"); + setPlayerCommand(true); + } + + private CommandSender sender; + private Player player; + private String[] args; + + @Override + public void onExecute(String[] args, CommandSender sender) { + this.sender = sender; + this.player = (Player) sender; + this.args = args; + + DGroup dGroup = DGroup.getByPlayer(player); + + if (args.length == 2) { + + if (args[1].equalsIgnoreCase("disband")) { + disbandGroup(dGroup); + return; + + } else if (args[1].equalsIgnoreCase("show")) { + showGroup(dGroup); + return; + } + + } else if (args.length >= 3) { + + if (args[1].equalsIgnoreCase("kick")) { + kickPlayer(dGroup); + return; + + } else if (args[1].equalsIgnoreCase("invite")) { + invitePlayer(dGroup); + return; + + } else if (args[1].equalsIgnoreCase("uninvite")) { + uninvitePlayer(dGroup); + return; + + } else if (args[1].equalsIgnoreCase("help")) { + showHelp(args[2]); + return; + + } else if (args[1].equalsIgnoreCase("create")) { + createGroup(); + return; + + } else if (args[1].equalsIgnoreCase("disband") && sender.hasPermission("dxl.group.admin")) { + disbandGroup(DGroup.getByName(args[2])); + return; + + } else if (args[1].equalsIgnoreCase("join")) { + joinGroup(DGroup.getByName(args[2])); + return; + + } else if (args[1].equalsIgnoreCase("show") && sender.hasPermission("dxl.group.admin")) { + showGroup(DGroup.getByName(args[2])); + return; + } + } + + showHelp("1"); + } + + public void createGroup() { + if (DGroup.getByPlayer(player) == null && DGroup.getByName(args[2]) == null) { + DGroup dGroup = new DGroup(args[2], player); + DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); + + if (event.isCancelled()) { + plugin.getDGroups().remove(dGroup); + dGroup = null; + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_CREATED, sender.getName(), args[2])); + } + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); + } + } + + public void disbandGroup(DGroup dGroup) { + if (dGroup != null) { + DGroupDisbandEvent event = new DGroupDisbandEvent(dGroup, player, DGroupDisbandEvent.Cause.COMMAND); + + if ( !event.isCancelled()) { + plugin.getDGroups().remove(dGroup); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_DISBANDED, sender.getName(), dGroup.getName())); + dGroup = null; + } + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP)); + } + } + + public void invitePlayer(DGroup dGroup) { + if (dGroup == null) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); + return; + } + + Player toInvite = plugin.getServer().getPlayer(args[2]); + + if (toInvite != null) { + dGroup.addInvitedPlayer(toInvite, false); + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2])); + } + } + + public void uninvitePlayer(DGroup dGroup) { + if (dGroup == null) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); + return; + } + + dGroup.clearOfflineInvitedPlayers(); + + Player toUninvite = plugin.getServer().getPlayer(args[2]); + + if (toUninvite != null) { + if (dGroup.getInvitedPlayers().contains(toUninvite)) { + dGroup.removeInvitedPlayer(toUninvite, false); + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP, args[2])); + } + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2])); + } + } + + public void joinGroup(DGroup dGroup) { + if (dGroup == null) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP, args[2])); + return; + } + + for (DGroup anyDGroup : plugin.getDGroups()) { + if (anyDGroup.getPlayers().contains(player)) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); + } + } + + if ( !dGroup.getInvitedPlayers().contains(player) && !player.hasPermission("dxl.bypass")) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_INVITED, args[2])); + return; + } + + dGroup.addPlayer(player); + dGroup.removeInvitedPlayer(player, true); + } + + public void kickPlayer(DGroup dGroup) { + if (dGroup == null) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); + } + + Player toKick = plugin.getServer().getPlayer(args[2]); + if (toKick != null) { + DPlayerKickEvent event = new DPlayerKickEvent(DPlayer.getByPlayer(toKick.getPlayer()), DPlayerKickEvent.Cause.COMMAND); + + if ( !event.isCancelled()) { + if (dGroup.getPlayers().contains(toKick)) { + dGroup.removePlayer(toKick); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_KICKED_PLAYER, sender.getName(), args[2], dGroup.getName())); + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP, args[2], dGroup.getName())); + } + } + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2])); + } + } + + public void showGroup(DGroup dGroup) { + if (dGroup == null) { + if (args.length == 3) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP, args[2])); + + } else if (args.length == 2) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); + } + + return; + } + + MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dGroup.getName() + " &4&l]"); + MessageUtil.sendMessage(sender, "&bCaptain: &e" + dGroup.getCaptain().getName()); + String players = "&e"; + for (Player player : dGroup.getPlayers()) { + players += (player == dGroup.getPlayers().get(0) ? "" : "&b, &e") + player.getName(); + } + MessageUtil.sendMessage(sender, "&bPlayers: &e" + players); + MessageUtil.sendMessage(sender, "&bDungeon: &e" + (dGroup.getDungeonName() == null ? "N/A" : dGroup.getDungeonName())); + MessageUtil.sendMessage(sender, "&bMap: &e" + (dGroup.getMapName() == null ? "N/A" : dGroup.getMapName())); + } + + public void showHelp(String page) { + MessageUtil.sendPluginTag(sender, plugin); + switch (page) { + default: + MessageUtil.sendCenteredMessage(sender, "&4&l[ &61-5 &4/ &67 &4| &61 &4&l]"); + MessageUtil.sendMessage(sender, "&bcreate" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_CREATE)); + MessageUtil.sendMessage(sender, "&bdisband" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_DISBAND)); + MessageUtil.sendMessage(sender, "&binvite" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_INVITE)); + MessageUtil.sendMessage(sender, "&buninvite" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_UNINVITE)); + MessageUtil.sendMessage(sender, "&bjoin" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_JOIN)); + break; + case "2": + MessageUtil.sendCenteredMessage(sender, "&4&l[ &66-10 &4/ &67 &4| &62 &4&l]"); + MessageUtil.sendMessage(sender, "&bkick" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_KICK)); + MessageUtil.sendMessage(sender, "&bshow" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_SHOW)); + break; + } + + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java index 2f9319dd..1dedc491 100644 --- a/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -1,5 +1,6 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; @@ -29,9 +30,9 @@ public class PlayCommand extends DCommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DPlayer dplayer = DPlayer.getByPlayer(player); + DPlayer dPlayer = DPlayer.getByPlayer(player); - if (dplayer != null) { + if (dPlayer != null) { MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON)); return; } @@ -86,16 +87,43 @@ public class PlayCommand extends DCommand { return; } - if (DGroup.getByPlayer(player) != null) { - MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); - return; - } + DGroup dGroup = DGroup.getByPlayer(player); - DGroup dGroup = new DGroup(player, identifier, multiFloor); + if (dGroup != null) { + if ( !dGroup.getCaptain().equals(player) && !player.hasPermission("dxl.bypass")) { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_CAPTAIN)); + } + + if (dGroup.getMapName() == null) { + if ( !multiFloor) { + dGroup.setMapName(identifier); + + } else { + dGroup.setDungeonName(identifier); + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + + if (dungeon != null) { + DungeonConfig config = dungeon.getConfig(); + + if (config != null) { + dGroup.setMapName(config.getStartFloor()); + } + } + } + + } else { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); + return; + } + + } else { + dGroup = new DGroup(player, identifier, multiFloor); + } DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); if (event.isCancelled()) { + plugin.getDGroups().remove(dGroup); dGroup = null; } @@ -114,10 +142,14 @@ public class PlayCommand extends DCommand { } if (dGroup.getGameWorld().getLocLobby() == null) { - new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false); + for (Player groupPlayer : dGroup.getPlayers()) { + new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false); + } } else { - new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false); + for (Player groupPlayer : dGroup.getPlayers()) { + new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false); + } } } diff --git a/src/io/github/dre2n/dungeonsxl/command/TestCommand.java b/src/io/github/dre2n/dungeonsxl/command/TestCommand.java index 776a8a8e..c716d009 100644 --- a/src/io/github/dre2n/dungeonsxl/command/TestCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/TestCommand.java @@ -1,5 +1,6 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; @@ -62,16 +63,43 @@ public class TestCommand extends DCommand { return; } - if (DGroup.getByPlayer(player) != null) { - MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); - return; - } + DGroup dGroup = DGroup.getByPlayer(player); - DGroup dGroup = new DGroup(player, identifier, multiFloor); + if (dGroup != null) { + if ( !dGroup.getCaptain().equals(player) && !player.hasPermission("dxl.bypass")) { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_CAPTAIN)); + } + + if (dGroup.getMapName() == null) { + if ( !multiFloor) { + dGroup.setMapName(identifier); + + } else { + dGroup.setDungeonName(identifier); + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + + if (dungeon != null) { + DungeonConfig config = dungeon.getConfig(); + + if (config != null) { + dGroup.setMapName(config.getStartFloor()); + } + } + } + + } else { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); + return; + } + + } else { + dGroup = new DGroup(player, identifier, multiFloor); + } DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); if (event.isCancelled()) { + plugin.getDGroups().remove(dGroup); dGroup = null; } @@ -88,17 +116,16 @@ public class TestCommand extends DCommand { dGroup.remove(); return; } - - DPlayer newDPlayer; - if (dGroup.getGameWorld().getLocLobby() == null) { - newDPlayer = new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false); + for (Player groupPlayer : dGroup.getPlayers()) { + new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false).setInTestMode(true); + } } else { - newDPlayer = new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false); + for (Player groupPlayer : dGroup.getPlayers()) { + new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false).setInTestMode(true); + } } - - newDPlayer.setInTestMode(true); } } diff --git a/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java b/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java index d2c00856..81462371 100644 --- a/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java +++ b/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java @@ -11,6 +11,13 @@ public class MessageConfig { public enum Messages { + GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"), + GROUP_DISBANDED("Group_Disbanded", "&4&v1&6 disbanded the group &4&v2&6."), + GROUP_INVITED_PLAYER("Group_InvitedPlayer", "&4&v1&6 invited the player &4&v2&6 to the group &4&v3&6."), + GROUP_UNINVITED_PLAYER("Group_UninvitedPlayer", "&4&v1&6 took back the invitation for &4&v2&6 to the group &4&v3&6."), + GROUP_KICKED_PLAYER("Group_KickedPlayer", "&4&v1&6 kicked the player &4&v2&6 from the group &4&v3&6."), + GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"), + LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!"), LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"), LOG_ERROR_NO_CONSOLE_COMMAND("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as Console!"), @@ -23,10 +30,14 @@ public class MessageConfig { PLAYER_DEATH("Player_Death", "&6You died, lives left: &2&v1"), PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1&6 died and lost his last life."), PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the Dungeon!"), - PLAYER_JOIN_GROUP("Player_JoinGroup", "&6Player &4&v1&6 has joined the Group!"), + PLAYER_INVITED("Player_Invited", "&4&v1&6 invited you to the group &4&v2&6."), + PLAYER_UNINVITED("Player_Uninvited", "&4&v1&6 took back your invitation to the group &4&v2&6."), + PLAYER_JOIN_GROUP("Player_JoinGroup", "&6You successfully joined the group!"), + PLAYER_KICKED("Player_Kicked", "&4You have been kicked out of the group &6&v1&4."), PLAYER_LEAVE_GROUP("Player_LeaveGroup", "&6You have successfully left your group!"), PLAYER_LEFT_GROUP("Player_LeftGroup", "&6Player &4&v1&6 has left the Group!"), PLAYER_LOOT_ADDED("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!"), + PLAYER_NEW_CAPTAIN("Player_NewCaptain", "&6You are now the new captain of your group."), PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!"), PLAYER_OFFLINE_NEVER("Player_OfflineNever", "&Player &4&v1&6 went offline. He will &4not&6 be kicked from the Dungeon automatically!"), PLAYER_PORTAL_ABORT("Player_PortalAbort", "&6Portal creation cancelled!"), @@ -69,6 +80,8 @@ public class MessageConfig { ERROR_DROP("Error_Drop", "&4You cannot drop safe items"), ERROR_DUNGEON_NOT_EXIST("Error_DungeonNotExist", "&4Dungeon &6&v1&4 does not exist!"), ERROR_ENDERCHEST("Error_Enderchest", "&4You cannot use an enderchest while in a Dungeon!"), + ERROR_IN_GROUP("Error_InGroup", "&4The player &6&v1&4 is already member of a group."), + ERROR_JOIN_GROUP("Error_JoinGroup", "&4You have to join a group first!"), ERROR_LEAVE_DUNGEON("Error_LeaveDungeon", "&4You have to leave your current dungeon first!"), ERROR_LEAVE_GROUP("Error_LeaveGroup", "&4You have to leave your group first!"), ERROR_LEFT_CLICK("Error_Leftklick", "&4You have to use Left-Click on this sign!"), @@ -81,8 +94,12 @@ public class MessageConfig { ERROR_NO_PERMISSIONS("Error_NoPermissions", "&4You have no permission to do this!"), ERROR_NO_PLAYER_COMMAND("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"), ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"), + ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"), + ERROR_NO_SUCH_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"), + ERROR_NOT_CAPTAIN("Error_NotCaptain", "&4You are not the captain of your group!"), ERROR_NOT_IN_DUNGEON("Error_NotInDungeon", "&4You are not in a dungeon!"), - ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4You have to join a group first!"), + ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4The player &6&v1&4 is not member of the group &6&v2&v4."), + ERROR_NOT_INVITED("Error_NotInvited", "&4You are not invited to the group &6&v1&4."), ERROR_NOT_SAVED("Error_NotSaved", "&4The map &6&v1&4 has not been saved to the &6DungeonsXL/maps/ &4folder yet!"), ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"), ERROR_READY("Error_Ready", "&4Choose your class first!"), @@ -95,6 +112,14 @@ public class MessageConfig { HELP_CMD_CREATE("Help_Cmd_Create", "/dxl create - Creates a new dungeon"), HELP_CMD_EDIT("Help_Cmd_Edit", "/dxl edit - Edit an existing dungeon"), HELP_CMD_ESCAPE("Help_Cmd_Escape", "/dxl escape - Leaves the current dungeon, without saving!"), + HELP_CMD_GROUP("Help_Cmd_Group", "/dxl group - Shows group command help"), + HELP_CMD_GROUP_CREATE("Help_Cmd_GroupCreate", "/dxl group create [group] - Creates a new group"), + HELP_CMD_GROUP_DISBAND("Help_Cmd_GroupDisband", "/dxl group disband ([group]) - Disbands a group"), + HELP_CMD_GROUP_INVITE("Help_Cmd_GroupInvite", "/dxl group invite [player]- Invites someone to your group"), + HELP_CMD_GROUP_UNINVITE("Help_Cmd_GroupUninvite", "/dxl group uninvite [player] - Takes back an invitation to your group"), + HELP_CMD_GROUP_JOIN("Help_Cmd_GroupJoin", "/dxl group join [group]- Join a group"), + HELP_CMD_GROUP_KICK("Help_Cmd_GroupKick", "/dxl group kick [player] - Kicks a player"), + HELP_CMD_GROUP_SHOW("Help_Cmd_GroupShow", "/dxl group show [group] - Shows a group"), HELP_CMD_HELP("Help_Cmd_Help", "/dxl help - Shows the help page"), HELP_CMD_INVITE("Help_Cmd_Invite", "/dxl invite - Invite a player to edit a dungeon"), HELP_CMD_LEAVE("Help_Cmd_Leave", "/dxl leave - Leaves the current dungeon"), diff --git a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java index 4c82b0d4..59a813f5 100644 --- a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java +++ b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java @@ -12,7 +12,7 @@ public class DGroupCreateEvent extends DGroupEvent implements Cancellable { COMMAND, GROUP_SIGN, - CUSTOM; + CUSTOM } diff --git a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java new file mode 100644 index 00000000..9e01b86b --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java @@ -0,0 +1,86 @@ +package io.github.dre2n.dungeonsxl.event.dgroup; + +import io.github.dre2n.dungeonsxl.player.DGroup; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +public class DGroupDisbandEvent extends DGroupEvent implements Cancellable { + + public enum Cause { + + COMMAND, + DUNGEON_FINISHED, + CUSTOM + + } + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private Player disbander; + + private Cause cause; + + public DGroupDisbandEvent(DGroup dGroup, Cause cause) { + super(dGroup); + this.cause = cause; + } + + public DGroupDisbandEvent(DGroup dGroup, Player disbander, Cause cause) { + super(dGroup); + this.disbander = disbander; + this.cause = cause; + } + + /** + * @return the disbander + */ + public Player getDisbander() { + return disbander; + } + + /** + * @param disbander + * the disbander to set + */ + public void setDisbander(Player disbander) { + this.disbander = disbander; + } + + /** + * @return the cause + */ + public Cause getCause() { + return cause; + } + + /** + * @param cause + * the cause to set + */ + public void setCause(Cause cause) { + this.cause = cause; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerKickEvent.java b/src/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerKickEvent.java index 58992f4d..e85e9df8 100644 --- a/src/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerKickEvent.java +++ b/src/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerKickEvent.java @@ -7,11 +7,38 @@ import org.bukkit.event.HandlerList; public class DPlayerKickEvent extends DPlayerEvent implements Cancellable { + public enum Cause { + + COMMAND, + DEATH, + OFFLINE, + CUSTOM + + } + private static final HandlerList handlers = new HandlerList(); private boolean cancelled; - public DPlayerKickEvent(DPlayer dPlayer) { + private Cause cause; + + public DPlayerKickEvent(DPlayer dPlayer, Cause cause) { super(dPlayer); + this.cause = cause; + } + + /** + * @return the cause + */ + public Cause getCause() { + return cause; + } + + /** + * @param cause + * the cause to set + */ + public void setCause(Cause cause) { + this.cause = cause; } @Override diff --git a/src/io/github/dre2n/dungeonsxl/global/DPortal.java b/src/io/github/dre2n/dungeonsxl/global/DPortal.java index 09f00675..d59d1f26 100644 --- a/src/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/src/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -162,7 +162,7 @@ public class DPortal { DGroup dgroup = DGroup.getByPlayer(player); if (dgroup == null) { - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_NOT_IN_GROUP)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_JOIN_GROUP)); return; } diff --git a/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java b/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java index b6581edd..92ce4d0c 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java @@ -11,6 +11,7 @@ import io.github.dre2n.dungeonsxl.player.DPlayer; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -121,11 +122,13 @@ public class EntityListener implements Listener { attackedDGroup = DGroup.getByPlayer(attackedPlayer); if (config.isPlayerVersusPlayer()) { + Bukkit.broadcastMessage("pvp cancel"); event.setCancelled(true); } if (attackerDGroup != null && attackedDGroup != null) { if (config.isFriendlyFire() && attackerDGroup.equals(attackedDGroup)) { + Bukkit.broadcastMessage("ff cancel"); event.setCancelled(true); } } diff --git a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index cfd7df0a..28d026c9 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -12,6 +12,7 @@ import io.github.dre2n.dungeonsxl.dungeon.game.GameChest; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.global.LeaveSign; @@ -78,14 +79,18 @@ public class PlayerListener implements Listener { dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives()); if (dPlayer.getLives() == 0 && dPlayer.isReady()) { - MessageUtil.broadcastMessage(messageConfig.getMessage(Messages.PLAYER_DEATH_KICK, player.getName())); + DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer, DPlayerKickEvent.Cause.DEATH); - // TODO: This Runnable is a workaround for a bug I couldn't find, yet... - new org.bukkit.scheduler.BukkitRunnable() { - public void run() { - dPlayer.leave(); - } - }.runTaskLater(plugin, 1L); + if ( !dPlayerKickEvent.isCancelled()) { + MessageUtil.broadcastMessage(messageConfig.getMessage(Messages.PLAYER_DEATH_KICK, player.getName())); + + // TODO: This Runnable is a workaround for a bug I couldn't find, yet... + new org.bukkit.scheduler.BukkitRunnable() { + public void run() { + dPlayer.leave(); + } + }.runTaskLater(plugin, 1L); + } } else if ( !(dPlayer.getLives() == -1)) { MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_DEATH, String.valueOf(dPlayer.getLives()))); diff --git a/src/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/io/github/dre2n/dungeonsxl/player/DGroup.java index 92c8f07d..ba3799bd 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -14,7 +14,7 @@ import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; +import java.util.UUID; import org.bukkit.entity.Player; @@ -23,7 +23,9 @@ public class DGroup { static DungeonsXL plugin = DungeonsXL.getPlugin(); private String name; - private CopyOnWriteArrayList players = new CopyOnWriteArrayList(); + private Player captain; + private List players = new ArrayList(); + private List invitedPlayers = new ArrayList(); private String dungeonName; private String mapName; private List unplayedFloors = new ArrayList(); @@ -32,42 +34,75 @@ public class DGroup { private int floorCount; private List rewards = new ArrayList(); - public DGroup(String name, Player player, String identifier, boolean multiFloor) { + public DGroup(String name, Player player) { plugin.getDGroups().add(this); this.name = name; - this.players.add(player); + captain = player; + players.add(player); - Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); - if (multiFloor && dungeon != null) { - this.dungeonName = identifier; - this.mapName = dungeon.getConfig().getStartFloor(); - this.unplayedFloors = dungeon.getConfig().getFloors(); - - } else { - this.mapName = identifier; - } - this.playing = false; - this.floorCount = 0; + playing = false; + floorCount = 0; } public DGroup(Player player, String identifier, boolean multiFloor) { plugin.getDGroups().add(this); - this.name = "Group_" + plugin.getDGroups().size(); + name = "Group_" + plugin.getDGroups().size(); - this.players.add(player); + captain = player; + players.add(player); Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); if (multiFloor && dungeon != null) { - this.dungeonName = identifier; - this.mapName = dungeon.getConfig().getStartFloor(); - this.unplayedFloors = dungeon.getConfig().getFloors(); + dungeonName = identifier; + mapName = dungeon.getConfig().getStartFloor(); + unplayedFloors = dungeon.getConfig().getFloors(); } else { - this.mapName = identifier; + mapName = identifier; } - this.playing = false; - this.floorCount = 0; + playing = false; + floorCount = 0; + } + + public DGroup(String name, Player player, String identifier, boolean multiFloor) { + plugin.getDGroups().add(this); + this.name = name; + + captain = player; + players.add(player); + + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + if (multiFloor && dungeon != null) { + dungeonName = identifier; + mapName = dungeon.getConfig().getStartFloor(); + unplayedFloors = dungeon.getConfig().getFloors(); + + } else { + mapName = identifier; + } + playing = false; + floorCount = 0; + } + + public DGroup(String name, Player captain, List players, String identifier, boolean multiFloor) { + plugin.getDGroups().add(this); + this.name = name; + + this.captain = captain; + this.players = players; + + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + if (multiFloor && dungeon != null) { + dungeonName = identifier; + mapName = dungeon.getConfig().getStartFloor(); + unplayedFloors = dungeon.getConfig().getFloors(); + + } else { + mapName = identifier; + } + playing = false; + floorCount = 0; } // Getters and setters @@ -87,10 +122,25 @@ public class DGroup { this.name = name; } + /** + * @return the captain + */ + public Player getCaptain() { + return captain; + } + + /** + * @param captain + * the captain to set + */ + public void setCaptain(Player captain) { + this.captain = captain; + } + /** * @return the players */ - public CopyOnWriteArrayList getPlayers() { + public List getPlayers() { return players; } @@ -99,13 +149,10 @@ public class DGroup { * the player to add */ public void addPlayer(Player player) { - // Send message - for (Player groupPlayer : getPlayers()) { - MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.PLAYER_JOIN_GROUP, player.getName())); - } + sendMessage(plugin.getMessageConfig().getMessage(Messages.GROUP_PLAYER_JOINED, player.getName())); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_JOIN_GROUP)); - // Add player - getPlayers().add(player); + players.add(player); } /** @@ -113,13 +160,11 @@ public class DGroup { * the player to remove */ public void removePlayer(Player player) { - getPlayers().remove(player); + players.remove(player); GroupSign.updatePerGroup(this); // Send message - for (Player groupPlayer : getPlayers()) { - MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.PLAYER_LEFT_GROUP, player.getName())); - } + sendMessage(plugin.getMessageConfig().getMessage(Messages.PLAYER_LEFT_GROUP, player.getName())); // Check group if (isEmpty()) { @@ -127,6 +172,92 @@ public class DGroup { } } + /** + * @return the players + */ + public List getInvitedPlayers() { + ArrayList players = new ArrayList(); + for (UUID uuid : invitedPlayers) { + players.add(plugin.getServer().getPlayer(uuid)); + } + + return players; + } + + /** + * @param player + * the player to add + */ + public void addInvitedPlayer(Player player, boolean silent) { + if (player == null) { + return; + } + + if (DGroup.getByPlayer(player) != null) { + if ( !silent) { + MessageUtil.sendMessage(captain, plugin.getMessageConfig().getMessage(Messages.ERROR_IN_GROUP, player.getName())); + } + return; + } + + if ( !silent) { + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_INVITED, captain.getName(), name)); + } + + // Send message + if ( !silent) { + sendMessage(plugin.getMessageConfig().getMessage(Messages.GROUP_INVITED_PLAYER, captain.getName(), player.getName(), name)); + } + + // Add player + invitedPlayers.add(player.getUniqueId()); + } + + /** + * @param player + * the player to remove + */ + public void removeInvitedPlayer(Player player, boolean silent) { + if (player == null) { + return; + } + + if (DGroup.getByPlayer(player) != this) { + if ( !silent) { + MessageUtil.sendMessage(captain, plugin.getMessageConfig().getMessage(Messages.ERROR_NOT_IN_GROUP, player.getName(), name)); + } + return; + } + + if ( !silent) { + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_UNINVITED, player.getName(), name)); + } + + // Send message + if ( !silent) { + for (Player groupPlayer : getPlayers()) { + MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.GROUP_UNINVITED_PLAYER, captain.getName(), player.getName(), name)); + } + } + + invitedPlayers.remove(player.getUniqueId()); + } + + /** + * Remove all invitations for players who are not online + */ + public void clearOfflineInvitedPlayers() { + ArrayList toRemove = new ArrayList(); + + for (UUID uuid : invitedPlayers) { + if (plugin.getServer().getPlayer(uuid) == null) { + toRemove.add(uuid); + } + } + + invitedPlayers.removeAll(toRemove); + } + /** * @return the gameWorld */ @@ -184,7 +315,7 @@ public class DGroup { * the name to set */ public void setMapName(String name) { - this.mapName = name; + mapName = name; } /** @@ -332,7 +463,7 @@ public class DGroup { /** * Send a message to all players in the group - * + * * @param except * Players who do not receive the message */ @@ -346,6 +477,16 @@ public class DGroup { // Statics + public static DGroup getByName(String name) { + for (DGroup dGroup : plugin.getDGroups()) { + if (dGroup.getName().equals(name)) { + return dGroup; + } + } + + return null; + } + public static DGroup getByPlayer(Player player) { for (DGroup dGroup : plugin.getDGroups()) { if (dGroup.getPlayers().contains(player)) { diff --git a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java index 660292e2..e7779329 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java @@ -44,7 +44,7 @@ import org.bukkit.potion.PotionEffect; public class DPlayer { static DungeonsXL plugin = DungeonsXL.getPlugin(); - MessageConfig MessageConfig = plugin.getMessageConfig(); + MessageConfig messageConfig = plugin.getMessageConfig(); // Variables private Player player; @@ -67,7 +67,7 @@ public class DPlayer { private ItemStack[] respawnArmor; private String[] linesCopy; - private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, MessageConfig.getMessage(Messages.PLAYER_TREASURES)); + private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, messageConfig.getMessage(Messages.PLAYER_TREASURES)); private int initialLives = -1; private int lives; @@ -488,6 +488,7 @@ public class DPlayer { } else { savePlayer.reset(dConfig.getKeepInventoryOnEscape()); } + } else { savePlayer.reset(false); } @@ -551,18 +552,18 @@ public class DPlayer { } } - // Give Secure Objects other Players if (dGroup != null) { + // Give Secure Objects other Players if ( !dGroup.isEmpty()) { int i = 0; Player groupPlayer; do { groupPlayer = dGroup.getPlayers().get(i); if (groupPlayer != null) { - for (ItemStack istack : getPlayer().getInventory()) { - if (istack != null) { - if (gameWorld.getSecureObjects().contains(istack.getType())) { - groupPlayer.getInventory().addItem(istack); + for (ItemStack itemStack : getPlayer().getInventory()) { + if (itemStack != null) { + if (gameWorld.getSecureObjects().contains(itemStack.getType())) { + groupPlayer.getInventory().addItem(itemStack); } } } @@ -570,7 +571,16 @@ public class DPlayer { i++; } while (groupPlayer == null); } + + if (dGroup.getCaptain().equals(player) && dGroup.getPlayers().size() > 0) { + // Captain here! + Player newCaptain = dGroup.getPlayers().get(0); + dGroup.setCaptain(newCaptain); + MessageUtil.sendMessage(newCaptain, messageConfig.getMessage(Messages.PLAYER_NEW_CAPTAIN)); + // ...*flies away* + } } + } } @@ -618,7 +628,7 @@ public class DPlayer { } public void finishFloor(String specifiedFloor) { - MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); + MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); finished = true; DGroup dGroup = DGroup.getByPlayer(getPlayer()); @@ -633,7 +643,7 @@ public class DPlayer { for (Player player : dGroup.getPlayers()) { DPlayer dPlayer = getByPlayer(player); if ( !dPlayer.finished) { - MessageUtil.sendMessage(this.getPlayer(), MessageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); + MessageUtil.sendMessage(this.getPlayer(), messageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); return; } } @@ -691,7 +701,7 @@ public class DPlayer { } public void finish() { - MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); + MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); finished = true; DGroup dGroup = DGroup.getByPlayer(getPlayer()); @@ -709,7 +719,7 @@ public class DPlayer { for (Player player : dGroup.getPlayers()) { DPlayer dPlayer = getByPlayer(player); if ( !dPlayer.finished) { - MessageUtil.sendMessage(this.getPlayer(), MessageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); + MessageUtil.sendMessage(this.getPlayer(), messageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); hasToWait = true; } else if (dPlayer != this) { @@ -784,14 +794,14 @@ public class DPlayer { } } else { linesCopy = lines; - MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_SIGN_COPIED)); + MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_SIGN_COPIED)); } } else { String info = "" + block.getType(); if (block.getData() != 0) { info = info + "," + block.getData(); } - MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_BLOCK_INFO, info)); + MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_BLOCK_INFO, info)); } } @@ -896,7 +906,7 @@ public class DPlayer { } if (kick) { - DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this); + DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this, DPlayerKickEvent.Cause.OFFLINE); if ( !dPlayerKickEvent.isCancelled()) { leave(); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java index 32d6f8dd..460658d7 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java @@ -6,57 +6,70 @@ import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; public class PlayerUtil { - public static Player getOfflinePlayer(String player, UUID uuid) { + public static Player getOfflinePlayer(String name) { + @SuppressWarnings("deprecation") + OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(name); + return getOfflinePlayer(name, offlinePlayer.getUniqueId()); + } + + public static Player getOfflinePlayer(UUID uuid) { + OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(uuid); + return getOfflinePlayer(offlinePlayer.getName(), uuid); + } + + public static Player getOfflinePlayer(String name, UUID uuid) { VersionUtil versions = DungeonsXL.getPlugin().getVersion(); if (versions.getInternals() == Internals.v1_9_R1) { - return v1_9_R1.getOfflinePlayer(player, uuid); + return v1_9_R1.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_8_R3) { - return v1_8_R3.getOfflinePlayer(player, uuid); + return v1_8_R3.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_8_R2) { - return v1_8_R2.getOfflinePlayer(player, uuid); + return v1_8_R2.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_8_R1) { - return v1_8_R1.getOfflinePlayer(player, uuid); + return v1_8_R1.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_7_R4) { - return v1_7_R4.getOfflinePlayer(player, uuid); + return v1_7_R4.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_7_R3) { - return v1_7_R3.getOfflinePlayer(player, uuid); + return v1_7_R3.getOfflinePlayer(name, uuid); } else { return null; } } - public static Player getOfflinePlayer(String player, UUID uuid, Location location) { + public static Player getOfflinePlayer(String name, UUID uuid, Location location) { VersionUtil versions = DungeonsXL.getPlugin().getVersion(); if (versions.getInternals() == Internals.v1_9_R1) { - return v1_9_R1.getOfflinePlayer(player, uuid, location); + return v1_9_R1.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_8_R3) { - return v1_8_R3.getOfflinePlayer(player, uuid, location); + return v1_8_R3.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_8_R2) { - return v1_8_R2.getOfflinePlayer(player, uuid, location); + return v1_8_R2.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_8_R1) { - return v1_8_R1.getOfflinePlayer(player, uuid, location); + return v1_8_R1.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_7_R4) { - return v1_7_R4.getOfflinePlayer(player, uuid, location); + return v1_7_R4.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_7_R3) { - return v1_7_R3.getOfflinePlayer(player, uuid, location); + return v1_7_R3.getOfflinePlayer(name, uuid, location); } else { return null; diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java index b139c5f6..da6c639e 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java @@ -16,18 +16,18 @@ import org.bukkit.entity.Player; class v1_7_R3 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -43,18 +43,18 @@ class v1_7_R3 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java index c50fee13..a190aa80 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java @@ -16,18 +16,18 @@ import org.bukkit.entity.Player; class v1_7_R4 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -43,18 +43,18 @@ class v1_7_R4 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java index 3feb37c9..8d6294a8 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java @@ -17,18 +17,18 @@ import com.mojang.authlib.GameProfile; class v1_8_R1 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String filename = playerFile.getName(); + String playerName = filename.substring(0, filename.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -44,18 +44,18 @@ class v1_8_R1 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String filename = playerFile.getName(); + String playerName = filename.substring(0, filename.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java index 030e63d5..4b550060 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java @@ -17,18 +17,18 @@ import com.mojang.authlib.GameProfile; class v1_8_R2 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -44,18 +44,18 @@ class v1_8_R2 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java index 419cb2ac..67ea5913 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java @@ -17,18 +17,18 @@ import com.mojang.authlib.GameProfile; class v1_8_R3 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -44,18 +44,18 @@ class v1_8_R3 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java index 4d1ca647..dd98b00e 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java @@ -17,18 +17,18 @@ import com.mojang.authlib.GameProfile; class v1_9_R1 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -44,18 +44,18 @@ class v1_9_R1 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/plugin.yml b/src/plugin.yml index 2d878849..aae5283e 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -22,6 +22,10 @@ permissions: default: op dxl.escape: default: true + dxl.group: + default: op + dxl.group.admin: + default: op dxl.help: default: true dxl.invite: