From 70d66515bd79f5394e3fa28ba45e38bc93b590da Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 19 Feb 2017 23:52:11 +0100 Subject: [PATCH] Refactor listeners; resolves #93 --- .../github/dre2n/dungeonsxl/DungeonsXL.java | 108 +- .../dre2n/dungeonsxl/announcer/Announcer.java | 1 - .../AnnouncerListener.java} | 5 +- .../AnnouncerStartGameTask.java | 3 +- .../{task => announcer}/AnnouncerTask.java | 4 +- .../dungeonsxl/announcer/Announcers.java | 25 + .../dre2n/dungeonsxl/command/ListCommand.java | 2 +- .../dre2n/dungeonsxl/command/MsgCommand.java | 2 +- .../dungeonsxl/command/RenameCommand.java | 2 +- .../dungeonsxl/command/StatusCommand.java | 4 +- .../dre2n/dungeonsxl/config/MainConfig.java | 1 + .../dre2n/dungeonsxl/dungeon/Dungeon.java | 1 - .../{config => dungeon}/DungeonConfig.java | 3 +- .../io/github/dre2n/dungeonsxl/game/Game.java | 12 +- .../dre2n/dungeonsxl/global/GameSign.java | 1 - .../GlobalProtectionListener.java} | 202 ++-- .../dungeonsxl/global/GlobalProtections.java | 5 + .../dungeonsxl/listener/CitizensListener.java | 43 - .../dungeonsxl/listener/EntityListener.java | 284 ------ .../dungeonsxl/listener/WorldListener.java | 51 - .../dungeonsxl/mob/CitizensMobProvider.java | 15 +- .../dre2n/dungeonsxl/mob/DMobListener.java | 91 ++ .../dre2n/dungeonsxl/mob/DMobTypes.java | 3 + .../dungeonsxl/mob/ExternalMobProviders.java | 8 +- .../CreateDInstancePlayerTask.java | 4 +- .../dre2n/dungeonsxl/player/DEditPlayer.java | 1 - .../dre2n/dungeonsxl/player/DGamePlayer.java | 1 - .../dungeonsxl/player/DGlobalPlayer.java | 9 +- .../dre2n/dungeonsxl/player/DGroup.java | 3 +- .../DPlayerData.java} | 7 +- .../DPlayerListener.java} | 941 +++++++++--------- .../dre2n/dungeonsxl/player/DPlayers.java | 66 +- .../{task => player}/LazyUpdateTask.java | 12 +- .../{task => player}/RespawnTask.java | 3 +- .../{task => player}/SecureModeTask.java | 6 +- .../{task => player}/TimeIsRunningTask.java | 4 +- .../{task => player}/UpdateTask.java | 3 +- .../requirement/FeeLevelRequirement.java | 4 +- .../dungeonsxl/reward/RewardListener.java | 119 +++ .../dre2n/dungeonsxl/reward/RewardTypes.java | 5 + .../dre2n/dungeonsxl/sign/DSignListener.java | 116 +++ .../dungeonsxl/sign/DSignTypeDefault.java | 11 + .../dre2n/dungeonsxl/sign/DSignTypes.java | 5 + .../{task => sign}/DelayedPowerTask.java | 3 +- .../dre2n/dungeonsxl/sign/DropSign.java | 16 +- .../dre2n/dungeonsxl/sign/InteractSign.java | 1 - .../dre2n/dungeonsxl/sign/RedstoneSign.java | 1 - .../{task => sign}/SignUpdateTask.java | 2 +- .../dre2n/dungeonsxl/sign/TriggerSign.java | 1 - .../sign/{ => lobby}/ClassesSign.java | 8 +- .../sign/{ => lobby}/LobbySign.java | 5 +- .../sign/{ => lobby}/ReadySign.java | 8 +- .../sign/{ => lobby}/StartSign.java | 5 +- .../sign/{ => message}/ActionBarSign.java | 5 +- .../sign/{ => message}/HologramSign.java | 8 +- .../sign/{ => message}/MessageSign.java | 5 +- .../sign/{ => message}/SoundMessageSign.java | 5 +- .../sign/{ => message}/TitleSign.java | 5 +- .../dungeonsxl/sign/{ => mob}/DMobSign.java | 9 +- .../sign/{ => mob}/ExternalMobSign.java | 9 +- .../mob}/ExternalMobSpawnTask.java | 3 +- .../dungeonsxl/sign/{ => mob}/MobSign.java | 2 +- .../{task => sign/mob}/MobSpawnTask.java | 3 +- .../dre2n/dungeonsxl/task/DropItemTask.java | 48 - .../dungeonsxl/trigger/FortuneTrigger.java | 1 - .../TriggerListener.java} | 26 +- .../dungeonsxl/trigger/TriggerTypes.java | 5 + .../{task => world}/BackupResourceTask.java | 3 +- .../dre2n/dungeonsxl/world/DGameWorld.java | 4 +- .../dungeonsxl/world/DInstanceWorld.java | 1 - .../dungeonsxl/world/DResourceWorld.java | 3 - .../dungeonsxl/world/DWorldListener.java | 148 +++ .../dre2n/dungeonsxl/world/DWorlds.java | 42 + .../{config => world}/SignData.java | 5 +- .../{config => world}/WorldConfig.java | 2 +- .../{task => world}/WorldUnloadTask.java | 4 +- .../WorldUpdateTask.java} | 20 +- 77 files changed, 1344 insertions(+), 1268 deletions(-) rename core/src/main/java/io/github/dre2n/dungeonsxl/{listener/GUIListener.java => announcer/AnnouncerListener.java} (91%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => announcer}/AnnouncerStartGameTask.java (96%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => announcer}/AnnouncerTask.java (92%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{config => dungeon}/DungeonConfig.java (98%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{listener/BlockListener.java => global/GlobalProtectionListener.java} (51%) delete mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/listener/CitizensListener.java delete mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/listener/EntityListener.java delete mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/listener/WorldListener.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobListener.java rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => player}/CreateDInstancePlayerTask.java (95%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{config/PlayerData.java => player/DPlayerData.java} (98%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{listener/PlayerListener.java => player/DPlayerListener.java} (69%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => player}/LazyUpdateTask.java (71%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => player}/RespawnTask.java (94%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => player}/SecureModeTask.java (86%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => player}/TimeIsRunningTask.java (95%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => player}/UpdateTask.java (91%) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardListener.java create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignListener.java rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => sign}/DelayedPowerTask.java (94%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => sign}/SignUpdateTask.java (96%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => lobby}/ClassesSign.java (88%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => lobby}/LobbySign.java (87%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => lobby}/ReadySign.java (94%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => lobby}/StartSign.java (89%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => message}/ActionBarSign.java (90%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => message}/HologramSign.java (90%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => message}/MessageSign.java (92%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => message}/SoundMessageSign.java (92%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => message}/TitleSign.java (91%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => mob}/DMobSign.java (93%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => mob}/ExternalMobSign.java (96%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => sign/mob}/ExternalMobSpawnTask.java (96%) rename core/src/main/java/io/github/dre2n/dungeonsxl/sign/{ => mob}/MobSign.java (98%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => sign/mob}/MobSpawnTask.java (97%) delete mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/task/DropItemTask.java rename core/src/main/java/io/github/dre2n/dungeonsxl/{listener/HangingListener.java => trigger/TriggerListener.java} (52%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => world}/BackupResourceTask.java (93%) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java rename core/src/main/java/io/github/dre2n/dungeonsxl/{config => world}/SignData.java (96%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{config => world}/WorldConfig.java (99%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task => world}/WorldUnloadTask.java (92%) rename core/src/main/java/io/github/dre2n/dungeonsxl/{task/RedstoneEventTask.java => world/WorldUpdateTask.java} (64%) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index b400a904..4a1ef8b6 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -22,7 +22,7 @@ import io.github.dre2n.commons.config.MessageConfig; import io.github.dre2n.commons.javaplugin.BRPlugin; import io.github.dre2n.commons.javaplugin.BRPluginSettings; import io.github.dre2n.dungeonsxl.announcer.Announcers; -import io.github.dre2n.dungeonsxl.command.*; +import io.github.dre2n.dungeonsxl.command.DCommands; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.GlobalData; import io.github.dre2n.dungeonsxl.config.MainConfig; @@ -30,7 +30,6 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeons; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.game.GameTypes; import io.github.dre2n.dungeonsxl.global.GlobalProtections; -import io.github.dre2n.dungeonsxl.listener.*; import io.github.dre2n.dungeonsxl.loottable.DLootTables; import io.github.dre2n.dungeonsxl.mob.DMobTypes; import io.github.dre2n.dungeonsxl.mob.ExternalMobProviders; @@ -44,11 +43,6 @@ import io.github.dre2n.dungeonsxl.reward.DLootInventory; import io.github.dre2n.dungeonsxl.reward.RewardTypes; import io.github.dre2n.dungeonsxl.sign.DSignTypes; import io.github.dre2n.dungeonsxl.sign.SignScripts; -import io.github.dre2n.dungeonsxl.task.AnnouncerTask; -import io.github.dre2n.dungeonsxl.task.LazyUpdateTask; -import io.github.dre2n.dungeonsxl.task.SecureModeTask; -import io.github.dre2n.dungeonsxl.task.UpdateTask; -import io.github.dre2n.dungeonsxl.task.WorldUnloadTask; import io.github.dre2n.dungeonsxl.trigger.TriggerTypes; import io.github.dre2n.dungeonsxl.util.NoReload; import io.github.dre2n.dungeonsxl.world.DWorlds; @@ -56,7 +50,6 @@ import java.io.File; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.event.HandlerList; -import org.bukkit.scheduler.BukkitTask; /** * The main class of DungeonsXL. @@ -102,12 +95,6 @@ public class DungeonsXL extends BRPlugin { private SignScripts signScripts; private DWorlds dWorlds; - private BukkitTask announcerTask; - private BukkitTask worldUnloadTask; - private BukkitTask lazyUpdateTask; - private BukkitTask updateTask; - private BukkitTask secureModeTask; - private CopyOnWriteArrayList dLootInventories = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList games = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList dGroups = new CopyOnWriteArrayList<>(); @@ -138,29 +125,8 @@ public class DungeonsXL extends BRPlugin { DPermissions.register(); initFolders(); loadCore(); - - manager.registerEvents(new EntityListener(), this); - manager.registerEvents(new GUIListener(), this); - manager.registerEvents(new PlayerListener(), this); - manager.registerEvents(new BlockListener(), this); - manager.registerEvents(new WorldListener(), this); - manager.registerEvents(new HangingListener(), this); - if (manager.getPlugin("Citizens") != null) { - manager.registerEvents(new CitizensListener(), this); - } - - // Load All loadData(); - // Tasks - startAnnouncerTask(mainConfig.getAnnouncmentInterval()); - startWorldUnloadTask(1200L); - startLazyUpdateTask(20L); - startUpdateTask(20L); - if (mainConfig.isSecureModeEnabled()) { - startSecureModeTask(mainConfig.getSecureModeCheckInterval()); - } - new NoReload(this); } @@ -578,78 +544,6 @@ public class DungeonsXL extends BRPlugin { dWorlds = new DWorlds(MAPS); } - /** - * @return the AnnouncerTask - */ - public BukkitTask getAnnouncerTask() { - return announcerTask; - } - - /** - * start a new AnnouncerTask - */ - public void startAnnouncerTask(long period) { - if (!announcers.getAnnouncers().isEmpty()) { - announcerTask = new AnnouncerTask(announcers).runTaskTimer(this, period, period); - } - } - - /** - * @return the worldUnloadTask - */ - public BukkitTask getWorldUnloadTask() { - return worldUnloadTask; - } - - /** - * start a new WorldUnloadTask - */ - public void startWorldUnloadTask(long period) { - worldUnloadTask = new WorldUnloadTask().runTaskTimer(this, period, period); - } - - /** - * @return the lazyUpdateTask - */ - public BukkitTask getLazyUpdateTask() { - return lazyUpdateTask; - } - - /** - * start a new LazyUpdateTask - */ - public void startLazyUpdateTask(long period) { - lazyUpdateTask = new LazyUpdateTask().runTaskTimer(this, period, period); - } - - /** - * @return the updateTask - */ - public BukkitTask getUpdateTask() { - return updateTask; - } - - /** - * start a new LazyUpdateTask - */ - public void startUpdateTask(long period) { - updateTask = new UpdateTask().runTaskTimer(this, period, period); - } - - /** - * @return the secureModeTask - */ - public BukkitTask getSecureModeTask() { - return secureModeTask; - } - - /** - * start a new SecureModeTask - */ - public void startSecureModeTask(long period) { - updateTask = new SecureModeTask().runTaskTimer(this, period, period); - } - /** * @return the dLootInventories */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java index 660a9d6e..37a511ad 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -25,7 +25,6 @@ import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.player.DGroup; -import io.github.dre2n.dungeonsxl.task.AnnouncerStartGameTask; import java.io.File; import java.util.ArrayList; import java.util.Arrays; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerListener.java similarity index 91% rename from core/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerListener.java index 46c42b8f..5be15979 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerListener.java @@ -14,11 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.listener; +package io.github.dre2n.dungeonsxl.announcer; import io.github.dre2n.commons.util.guiutil.ButtonClickEvent; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.announcer.Announcer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -28,7 +27,7 @@ import org.bukkit.inventory.ItemStack; /** * @author Daniel Saukel */ -public class GUIListener implements Listener { +public class AnnouncerListener implements Listener { DungeonsXL plugin = DungeonsXL.getInstance(); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerStartGameTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerStartGameTask.java similarity index 96% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerStartGameTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerStartGameTask.java index b150352d..ecd531ab 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerStartGameTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerStartGameTask.java @@ -14,10 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.announcer; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.announcer.Announcer; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerTask.java similarity index 92% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerTask.java index c873a118..a29ee09e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerTask.java @@ -14,11 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.announcer; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.announcer.Announcer; -import io.github.dre2n.dungeonsxl.announcer.Announcers; import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import java.util.List; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java index 57316fe3..abbac537 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java @@ -17,11 +17,14 @@ package io.github.dre2n.dungeonsxl.announcer; import io.github.dre2n.commons.util.FileUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; import java.io.File; import java.util.ArrayList; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.inventory.Inventory; +import org.bukkit.scheduler.BukkitTask; /** * Announcer instance manager. @@ -30,6 +33,10 @@ import org.bukkit.inventory.Inventory; */ public class Announcers { + DungeonsXL plugin = DungeonsXL.getInstance(); + + private BukkitTask announcerTask; + private List announcers = new ArrayList<>(); public Announcers(File file) { @@ -38,6 +45,8 @@ public class Announcers { announcers.add(new Announcer(script)); } } + startAnnouncerTask(plugin.getMainConfig().getAnnouncmentInterval()); + Bukkit.getPluginManager().registerEvents(new AnnouncerListener(), plugin); } /** @@ -89,4 +98,20 @@ public class Announcers { announcers.remove(announcer); } + /** + * @return the AnnouncerTask + */ + public BukkitTask getAnnouncerTask() { + return announcerTask; + } + + /** + * start a new AnnouncerTask + */ + public void startAnnouncerTask(long period) { + if (!announcers.isEmpty()) { + announcerTask = new AnnouncerTask(this).runTaskTimer(plugin, period, period); + } + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java index 0e37eee1..1847125f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java @@ -21,8 +21,8 @@ import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; +import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java index f12e5b2c..02f47603 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java @@ -20,9 +20,9 @@ import io.github.dre2n.commons.command.BRCommand; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.world.DEditWorld; +import io.github.dre2n.dungeonsxl.world.WorldConfig; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/RenameCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/RenameCommand.java index 0f4ad02d..81ad62eb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/RenameCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/RenameCommand.java @@ -20,8 +20,8 @@ import io.github.dre2n.commons.command.BRCommand; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; +import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig; import io.github.dre2n.dungeonsxl.global.GameSign; import io.github.dre2n.dungeonsxl.global.GlobalProtection; import io.github.dre2n.dungeonsxl.global.GroupSign; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/StatusCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/StatusCommand.java index d33e0d3c..5aa60a7f 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/StatusCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/StatusCommand.java @@ -53,12 +53,12 @@ public class StatusCommand extends BRCommand { @Override public void onExecute(String[] args, CommandSender sender) { String minecraftVersion = compat.getVersion().toString(); - String bukkitVersion = Bukkit.getName() + " " + Bukkit.getBukkitVersion(); + String bukkitVersion = Bukkit.getName() + (compat.isSpigot() ? " (Spigot)" : new String()) + " " + Bukkit.getBukkitVersion(); String internalsVersion = compat.getInternals().toString(); String dungeonsxlVersion = plugin.getDescription().getVersion(); String internalsVersionCorrect = getSymbol(plugin.getSettings().getInternals().contains(compat.getInternals())); - String bukkitVersionCorrect = getSymbol(bukkitVersion.startsWith("Spigot")); + String bukkitVersionCorrect = getSymbol(bukkitVersion.contains("Spigot")); String dungeonsxlVersionCorrect = getSymbol(!dungeonsxlVersion.contains("SNAPSHOT")); MessageUtil.sendCenteredMessage(sender, "&4&l=> &6STATUS &4&l<="); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index a4f2609d..55438b76 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -23,6 +23,7 @@ import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.util.DColor; import static io.github.dre2n.dungeonsxl.util.DColor.*; +import io.github.dre2n.dungeonsxl.world.WorldConfig; import java.io.File; import java.io.IOException; import java.util.ArrayList; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java index 6dedc685..b728ce77 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java @@ -17,7 +17,6 @@ package io.github.dre2n.dungeonsxl.dungeon; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.world.DResourceWorld; import java.io.File; import java.util.ArrayList; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/DungeonConfig.java similarity index 98% rename from core/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/DungeonConfig.java index 3092d820..f723ec5a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/DungeonConfig.java @@ -14,12 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.config; +package io.github.dre2n.dungeonsxl.dungeon; import io.github.dre2n.commons.config.BRConfig; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.world.DResourceWorld; import io.github.dre2n.dungeonsxl.world.DWorlds; +import io.github.dre2n.dungeonsxl.world.WorldConfig; import java.io.File; import java.util.ArrayList; import java.util.List; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index 2dbcf16c..0eb33b50 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -19,16 +19,16 @@ package io.github.dre2n.dungeonsxl.game; import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; -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.global.GameSign; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.sign.DSign; -import io.github.dre2n.dungeonsxl.sign.MobSign; +import io.github.dre2n.dungeonsxl.sign.mob.MobSign; import io.github.dre2n.dungeonsxl.trigger.ProgressTrigger; import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.DResourceWorld; +import io.github.dre2n.dungeonsxl.world.WorldConfig; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -48,7 +48,7 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class Game { - static DungeonsXL plugin = DungeonsXL.getInstance(); + DungeonsXL plugin = DungeonsXL.getInstance(); private boolean tutorial; private List dGroups = new ArrayList<>(); @@ -461,7 +461,7 @@ public class Game { /* Statics */ public static Game getByDGroup(DGroup dGroup) { - for (Game game : plugin.getGames()) { + for (Game game : DungeonsXL.getInstance().getGames()) { if (game.getDGroups().contains(dGroup)) { return game; } @@ -475,7 +475,7 @@ public class Game { } public static Game getByGameWorld(DGameWorld gameWorld) { - for (Game game : plugin.getGames()) { + for (Game game : DungeonsXL.getInstance().getGames()) { if (gameWorld.equals(game.getWorld())) { return game; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java index e82d8d89..d82ba590 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java @@ -21,7 +21,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.game.Game; -import static io.github.dre2n.dungeonsxl.global.GlobalProtection.plugin; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.world.DResourceWorld; import java.util.HashSet; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtectionListener.java similarity index 51% rename from core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtectionListener.java index 9b146afd..4cc944ad 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtectionListener.java @@ -14,59 +14,39 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.listener; +package io.github.dre2n.dungeonsxl.global; import io.github.dre2n.commons.util.NumberUtil; -import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.global.DPortal; -import io.github.dre2n.dungeonsxl.global.GameSign; -import io.github.dre2n.dungeonsxl.global.GlobalProtection; -import io.github.dre2n.dungeonsxl.global.GroupSign; -import io.github.dre2n.dungeonsxl.global.LeaveSign; import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import io.github.dre2n.dungeonsxl.player.DPermissions; -import io.github.dre2n.dungeonsxl.player.DPlayers; -import io.github.dre2n.dungeonsxl.sign.DSign; -import io.github.dre2n.dungeonsxl.task.RedstoneEventTask; import io.github.dre2n.dungeonsxl.world.DEditWorld; -import io.github.dre2n.dungeonsxl.world.DGameWorld; -import io.github.dre2n.dungeonsxl.world.DInstanceWorld; +import java.util.List; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.block.BlockPhysicsEvent; -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.event.entity.EntityExplodeEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerPortalEvent; /** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel, Wooyoung Son + * @author Daniel Saukel, Wooyoung Son, Frank Baumann, Milan Albrecht */ -public class BlockListener implements Listener { +public class GlobalProtectionListener implements Listener { DungeonsXL plugin = DungeonsXL.getInstance(); - DPlayers dPlayers = plugin.getDPlayers(); - - @EventHandler(priority = EventPriority.HIGH) - public void onPhysics(BlockPhysicsEvent event) { - if (DPortal.getByBlock(event.getBlock()) != null) { - event.setCancelled(true); - } - } @EventHandler - public void onBreakWithSignOnIt(BlockBreakEvent event) { + public void onBlockBreakWithSignOnIt(BlockBreakEvent event) { Block block = event.getBlock(); Player player = event.getPlayer(); @@ -83,66 +63,120 @@ public class BlockListener implements Listener { //let onBreak() method to handle the sign BlockBreakEvent bbe = new BlockBreakEvent(blockAbove, player); - onBreak(bbe); + onBlockBreak(bbe); //follow the onBreak() event.setCancelled(bbe.isCancelled()); } - @EventHandler(priority = EventPriority.HIGH) - public void onBreak(BlockBreakEvent event) { + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); Player player = event.getPlayer(); - DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player); + DGlobalPlayer dGlobalPlayer = plugin.getDPlayers().getByPlayer(player); - GlobalProtection protection = plugin.getGlobalProtections().getByBlock(event.getBlock()); + GlobalProtection protection = plugin.getGlobalProtections().getByBlock(block); if (protection != null) { if (protection.onBreak(dGlobalPlayer)) { event.setCancelled(true); } - return; } + } - // DEditWorld Signs - DEditWorld editWorld = DEditWorld.getByWorld(block.getWorld()); - if (editWorld != null) { - editWorld.getSigns().remove(event.getBlock()); - return; + @EventHandler + public void onBlockSpread(BlockSpreadEvent event) { + if (DPortal.getByBlock(event.getBlock()) != null) { + event.setCancelled(true); } + } - // Deny DGameWorld block breaking - DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld()); - if (gameWorld != null) { - if (gameWorld.onBreak(event)) { + @EventHandler + public void onBlockPhysics(BlockPhysicsEvent event) { + if (DPortal.getByBlock(event.getBlock()) != null) { + event.setCancelled(true); + } + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + List blocklist = event.blockList(); + for (Block block : blocklist) { + if (DungeonsXL.getInstance().getGlobalProtections().isProtectedBlock(block)) { event.setCancelled(true); } } } - @EventHandler(priority = EventPriority.HIGH) - public void onPlace(BlockPlaceEvent event) { - Block block = event.getBlock(); - - // Deny DGameWorld Blocks - DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld()); - if (gameWorld == null) { + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + DPortal dPortal = DPortal.getByLocation(player.getEyeLocation()); + if (dPortal == null) { return; } - if (gameWorld.onPlace(event.getPlayer(), block, event.getBlockAgainst(), event.getItemInHand())) { + Block blockFrom = event.getFrom().getBlock(); + Block blockTo = event.getTo().getBlock(); + if (blockFrom.equals(blockTo)) { + return; + } + + dPortal.teleport(player); + } + + @EventHandler + public void onPlayerPortal(PlayerPortalEvent event) { + Block block1 = event.getFrom().getBlock(); + Block block2 = block1.getRelative(BlockFace.WEST); + Block block3 = block1.getRelative(BlockFace.NORTH); + Block block4 = block1.getRelative(BlockFace.EAST); + Block block5 = block1.getRelative(BlockFace.SOUTH); + if (DPortal.getByBlock(block1) != null || DPortal.getByBlock(block2) != null || DPortal.getByBlock(block3) != null || DPortal.getByBlock(block4) != null || DPortal.getByBlock(block5) != null) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.NORMAL) + /* SUBJECT TO CHANGE */ + @Deprecated + @EventHandler + public void onInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (plugin.getDPlayers().getByPlayer(player).isInBreakMode()) { + return; + } + Block clickedBlock = event.getClickedBlock(); + if (clickedBlock == null) { + return; + } + + if (clickedBlock.getType() == Material.WALL_SIGN || clickedBlock.getType() == Material.SIGN_POST) { + // Check Group Signs + if (GroupSign.playerInteract(clickedBlock, player)) { + event.setCancelled(true); + } + + // Check Game Signs + if (GameSign.playerInteract(clickedBlock, player)) { + event.setCancelled(true); + } + + LeaveSign leaveSign = LeaveSign.getByBlock(clickedBlock); + if (leaveSign != null) { + leaveSign.onPlayerInteract(player); + event.setCancelled(true); + } + } + } + + @Deprecated + @EventHandler public void onSignChange(SignChangeEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); String[] lines = event.getLines(); - DEditWorld editWorld = DEditWorld.getByWorld(player.getWorld()); // Group Signs - if (editWorld == null) { + if (DEditWorld.getByWorld(player.getWorld()) == null) { if (!DPermissions.hasPermission(player, DPermissions.SIGN)) { return; } @@ -181,64 +215,6 @@ public class BlockListener implements Listener { event.setCancelled(true); } - - } else { // Editworld Signs - Sign sign = (Sign) block.getState(); - if (sign != null) { - sign.setLine(0, lines[0]); - sign.setLine(1, lines[1]); - sign.setLine(2, lines[2]); - sign.setLine(3, lines[3]); - - DSign dsign = DSign.create(sign, null); - - if (dsign == null) { - return; - } - - if (!DPermissions.hasPermission(player, dsign.getType().getBuildPermission())) { - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.ERROR_NO_PERMISSIONS)); - return; - } - - if (dsign.check()) { - editWorld.registerSign(block); - editWorld.getSigns().add(block); - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.PLAYER_SIGN_CREATED)); - - } else { - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.ERROR_SIGN_WRONG_FORMAT)); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL) - public void onSpread(BlockSpreadEvent event) { - Block block = event.getSource(); - - DInstanceWorld instance = plugin.getDWorlds().getInstanceByName(block.getWorld().getName()); - if (instance != null && block.getType() == Material.VINE) { - event.setCancelled(true); - - } else if (DPortal.getByBlock(block) != null) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.NORMAL) - public void onRedstoneEvent(BlockRedstoneEvent event) { - new RedstoneEventTask(event.getBlock()).runTaskLater(plugin, 1); - } - - @EventHandler(priority = EventPriority.HIGH) - public void onIgnite(BlockIgniteEvent event) { - if (plugin.getDWorlds().getInstanceByName(event.getBlock().getWorld().getName()) == null) { - return; - } - - if (event.getCause() != IgniteCause.FLINT_AND_STEEL) { - event.setCancelled(true); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java index 472dfa5f..4328c2c3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtections.java @@ -20,6 +20,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import java.io.File; import java.util.HashSet; import java.util.Set; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -37,6 +38,10 @@ public class GlobalProtections { private Set protections = new HashSet<>(); + public GlobalProtections() { + Bukkit.getPluginManager().registerEvents(new GlobalProtectionListener(), plugin); + } + /** * @return the protection which covers this location */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/CitizensListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/CitizensListener.java deleted file mode 100644 index 6375692c..00000000 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/CitizensListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2012-2017 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package io.github.dre2n.dungeonsxl.listener; - -import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.mob.CitizensMobProvider; -import net.citizensnpcs.api.CitizensAPI; -import net.citizensnpcs.api.event.NPCDeathEvent; -import net.citizensnpcs.api.npc.NPC; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -/** - * @author Daniel Saukel - */ -public class CitizensListener implements Listener { - - CitizensMobProvider provider = DungeonsXL.getInstance().getExternalMobProviders().getCitizensMobProvider(); - - @EventHandler - public void onNPCDeath(NPCDeathEvent event) { - NPC npc = event.getNPC(); - if (provider.getSpawnedNPCs().contains(npc)) { - CitizensAPI.getNPCRegistry().deregister(npc); - provider.removeSpawnedNPC(npc); - } - } - -} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/EntityListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/EntityListener.java deleted file mode 100644 index 0e05dd68..00000000 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/EntityListener.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (C) 2012-2017 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package io.github.dre2n.dungeonsxl.listener; - -import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.game.Game; -import io.github.dre2n.dungeonsxl.mob.DMob; -import io.github.dre2n.dungeonsxl.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.player.DGroup; -import io.github.dre2n.dungeonsxl.world.DEditWorld; -import io.github.dre2n.dungeonsxl.world.DGameWorld; -import java.util.List; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityCombustByEntityEvent; -import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.bukkit.event.entity.ItemSpawnEvent; - -/** - * @author Frank Baumann, Tobias Schmitz, Milan Albrecht, Daniel Saukel - */ -public class EntityListener implements Listener { - - // Remove drops from breaking Signs - @EventHandler(priority = EventPriority.HIGH) - public void onItemSpawn(ItemSpawnEvent event) { - if (DGameWorld.getByWorld(event.getLocation().getWorld()) != null) { - if (event.getEntity().getItemStack().getType() == Material.SIGN) { - event.setCancelled(true); - } - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onCreatureSpawn(CreatureSpawnEvent event) { - World world = event.getLocation().getWorld(); - - DEditWorld editWorld = DEditWorld.getByWorld(world); - DGameWorld gameWorld = DGameWorld.getByWorld(world); - - if (editWorld != null || gameWorld != null) { - switch (event.getSpawnReason()) { - case CHUNK_GEN: - case JOCKEY: - case MOUNT: - case NATURAL: - event.setCancelled(true); - } - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onDeath(EntityDeathEvent event) { - World world = event.getEntity().getWorld(); - - if (event.getEntity() instanceof LivingEntity) { - LivingEntity entity = event.getEntity(); - DGameWorld gameWorld = DGameWorld.getByWorld(world); - if (gameWorld != null) { - if (gameWorld.isPlaying()) { - DMob dMob = DMob.getByEntity(entity); - if (dMob != null) { - dMob.onDeath(event); - } - } - } - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onDamage(EntityDamageEvent event) { - World world = event.getEntity().getWorld(); - DGameWorld gameWorld = DGameWorld.getByWorld(world); - - if (gameWorld == null) { - return; - } - - // Deny all Damage in Lobby - if (!gameWorld.isPlaying()) { - event.setCancelled(true); - } - - if (!(event.getEntity() instanceof LivingEntity)) { - return; - } - - boolean dead = ((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0; - if (dead && DMob.getByEntity(event.getEntity()) != null) { - String killer = null; - - if (event instanceof EntityDamageByEntityEvent) { - Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); - - if (damager instanceof Projectile) { - if (((Projectile) damager).getShooter() instanceof Player) { - damager = (Player) ((Projectile) damager).getShooter(); - } - } - - if (damager instanceof Player) { - killer = damager.getName(); - } - } - - gameWorld.getGame().addKill(killer); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onDamageByEntity(EntityDamageByEntityEvent event) { - World world = event.getEntity().getWorld(); - DGameWorld gameWorld = DGameWorld.getByWorld(world); - - if (gameWorld == null) { - return; - } - - Game game = gameWorld.getGame(); - - if (game == null) { - return; - } - - if (!game.hasStarted()) { - return; - } - - boolean pvp = game.getRules().isPlayerVersusPlayer(); - boolean friendlyFire = game.getRules().isFriendlyFire(); - - Entity attackerEntity = event.getDamager(); - Entity attackedEntity = event.getEntity(); - - if (attackerEntity instanceof Projectile) { - attackerEntity = (Entity) ((Projectile) attackerEntity).getShooter(); - } - - Player attackerPlayer = null; - Player attackedPlayer = null; - - DGroup attackerDGroup = null; - DGroup attackedDGroup = null; - - if (!(attackerEntity instanceof LivingEntity) || !(attackedEntity instanceof LivingEntity)) { - return; - } - - if (attackerEntity instanceof Player && attackedEntity instanceof Player) { - attackerPlayer = (Player) attackerEntity; - attackedPlayer = (Player) attackedEntity; - - attackerDGroup = DGroup.getByPlayer(attackerPlayer); - attackedDGroup = DGroup.getByPlayer(attackedPlayer); - - if (!pvp) { - event.setCancelled(true); - return; - } - - if (attackerDGroup != null && attackedDGroup != null) { - if (!friendlyFire && attackerDGroup.equals(attackedDGroup)) { - event.setCancelled(true); - return; - } - } - } - - // Check Dogs - if (attackerEntity instanceof Player || attackedEntity instanceof Player) { - for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) { - if (dPlayer.getWolf() != null) { - if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { - event.setCancelled(true); - return; - } - } - } - } - - for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) { - if (dPlayer.getWolf() != null) { - if (attackerEntity instanceof Player || attackedEntity instanceof Player) { - if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { - event.setCancelled(true); - return; - } - - } else if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { - event.setCancelled(false); - return; - } - } - } - } - - // Deny food in Lobby - @EventHandler(priority = EventPriority.HIGH) - public void onFoodLevelChange(FoodLevelChangeEvent event) { - World world = event.getEntity().getWorld(); - - DGameWorld gameWorld = DGameWorld.getByWorld(world); - if (gameWorld != null) { - if (!gameWorld.isPlaying()) { - event.setCancelled(true); - } - } - } - - // Zombie/skeleton combustion from the sun. - @EventHandler(priority = EventPriority.NORMAL) - public void onCombust(EntityCombustEvent event) { - DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); - if (gameWorld != null) { - event.setCancelled(true); - } - } - - // Allow Other combustion - @EventHandler(priority = EventPriority.HIGH) - public void onCombustByEntity(EntityCombustByEntityEvent event) { - DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); - if (gameWorld != null) { - if (event.isCancelled()) { - event.setCancelled(false); - } - } - } - - // Explosions - @EventHandler - public void onExplode(EntityExplodeEvent event) { - DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); - - if (gameWorld != null) { - if (event.getEntity() instanceof LivingEntity) { - // Disable Creeper explosions in gameWorlds - event.setCancelled(true); - return; - - } else { - // Disable drops from TNT - event.setYield(0); - } - } - - // Prevent GlobalProtection destroying - List blocklist = event.blockList(); - for (Block block : blocklist) { - if (DungeonsXL.getInstance().getGlobalProtections().isProtectedBlock(block)) { - event.setCancelled(true); - } - } - } - -} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/WorldListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/WorldListener.java deleted file mode 100644 index 05592595..00000000 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/WorldListener.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2012-2017 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package io.github.dre2n.dungeonsxl.listener; - -import io.github.dre2n.dungeonsxl.world.DEditWorld; -import io.github.dre2n.dungeonsxl.world.DGameWorld; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.weather.WeatherChangeEvent; -import org.bukkit.event.world.ChunkUnloadEvent; - -/** - * @author Frank Baumann - */ -public class WorldListener implements Listener { - - @EventHandler(priority = EventPriority.HIGH) - public void onChunkUnload(ChunkUnloadEvent event) { - DGameWorld gameWorld = DGameWorld.getByWorld(event.getWorld()); - if (gameWorld != null) { - if (gameWorld.getLoadedChunks().contains(event.getChunk())) { - event.setCancelled(true); - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onWeatherChange(WeatherChangeEvent event) { - if (DEditWorld.getByWorld(event.getWorld()) != null) { - if (event.toWeatherState()) { - event.setCancelled(true); - } - } - } - -} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java index 26a562fb..529f5e35 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java @@ -21,17 +21,20 @@ import io.github.dre2n.dungeonsxl.world.DGameWorld; import java.util.HashSet; import java.util.Set; import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.event.NPCDeathEvent; import net.citizensnpcs.api.npc.AbstractNPC; import net.citizensnpcs.api.npc.NPC; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; /** * ExternalMobProvider implementation for Citizens. * * @author Daniel Saukel */ -public class CitizensMobProvider implements ExternalMobProvider { +public class CitizensMobProvider implements ExternalMobProvider, Listener { private DNPCRegistry registry = new DNPCRegistry(); private String identifier = "CI"; @@ -100,4 +103,14 @@ public class CitizensMobProvider implements ExternalMobProvider { } } + /* Listeners */ + @EventHandler + public void onNPCDeath(NPCDeathEvent event) { + NPC npc = event.getNPC(); + if (spawnedNPCs.contains(npc)) { + CitizensAPI.getNPCRegistry().deregister(npc); + removeSpawnedNPC(npc); + } + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobListener.java new file mode 100644 index 00000000..df910144 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobListener.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2012-2017 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.mob; + +import io.github.dre2n.dungeonsxl.world.DEditWorld; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import org.bukkit.World; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityDeathEvent; + +/** + * @author Daniel Saukel, Frank Baumann + */ +public class DMobListener implements Listener { + + @EventHandler + public void onCreatureSpawn(CreatureSpawnEvent event) { + World world = event.getLocation().getWorld(); + + DEditWorld editWorld = DEditWorld.getByWorld(world); + DGameWorld gameWorld = DGameWorld.getByWorld(world); + + if (editWorld != null || gameWorld != null) { + switch (event.getSpawnReason()) { + case CHUNK_GEN: + case JOCKEY: + case MOUNT: + case NATURAL: + event.setCancelled(true); + } + } + } + + @EventHandler + public void onEntityDeath(EntityDeathEvent event) { + World world = event.getEntity().getWorld(); + + if (event.getEntity() instanceof LivingEntity) { + LivingEntity entity = event.getEntity(); + DGameWorld gameWorld = DGameWorld.getByWorld(world); + if (gameWorld != null) { + if (gameWorld.isPlaying()) { + DMob dMob = DMob.getByEntity(entity); + if (dMob != null) { + dMob.onDeath(event); + } + } + } + } + } + + // Zombie / Skeleton combustion from the sun. + @EventHandler + public void onEntityCombust(EntityCombustEvent event) { + DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); + if (gameWorld != null) { + event.setCancelled(true); + } + } + + // Allow other combustion + @EventHandler + public void onEntityCombustByEntity(EntityCombustByEntityEvent event) { + DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); + if (gameWorld != null) { + if (event.isCancelled()) { + event.setCancelled(false); + } + } + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobTypes.java index dd451dc2..d42957df 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobTypes.java @@ -17,9 +17,11 @@ package io.github.dre2n.dungeonsxl.mob; import io.github.dre2n.commons.util.FileUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; import java.io.File; import java.util.ArrayList; import java.util.List; +import org.bukkit.Bukkit; /** * @author Daniel Saukel @@ -34,6 +36,7 @@ public class DMobTypes { dMobTypes.add(new DMobType(script)); } } + Bukkit.getPluginManager().registerEvents(new DMobListener(), DungeonsXL.getInstance()); } /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProviders.java b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProviders.java index 73dfac38..38b61801 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProviders.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/mob/ExternalMobProviders.java @@ -31,15 +31,19 @@ import org.bukkit.Bukkit; */ public class ExternalMobProviders { + DungeonsXL plugin = DungeonsXL.getInstance(); + private Set providers = new HashSet<>(); public ExternalMobProviders() { // Supported providers providers.addAll(Arrays.asList(ExternalMobPlugin.values())); if (Bukkit.getPluginManager().getPlugin("Citizens") != null) { - providers.add(new CitizensMobProvider()); + CitizensMobProvider citizens = new CitizensMobProvider(); + providers.add(citizens); + Bukkit.getPluginManager().registerEvents(citizens, plugin); } else { - MessageUtil.log("Could not find compatible Citizens plugin. The mob provider Citizens (\"CI\") will not get enabled..."); + MessageUtil.log(plugin, "Could not find compatible Citizens plugin. The mob provider Citizens (\"CI\") will not get enabled..."); } // Custom providers diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/CreateDInstancePlayerTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/CreateDInstancePlayerTask.java similarity index 95% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/CreateDInstancePlayerTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/player/CreateDInstancePlayerTask.java index c69386d8..10335811 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/CreateDInstancePlayerTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/CreateDInstancePlayerTask.java @@ -14,12 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.game.GameType; -import io.github.dre2n.dungeonsxl.player.DEditPlayer; -import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.DInstanceWorld; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java index 84c693d2..45ce2f32 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java @@ -20,7 +20,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent; -import io.github.dre2n.dungeonsxl.task.CreateDInstancePlayerTask; import io.github.dre2n.dungeonsxl.world.DEditWorld; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.ChatColor; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 0f370a24..08b51754 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -33,7 +33,6 @@ import io.github.dre2n.dungeonsxl.game.GameTypeDefault; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; -import io.github.dre2n.dungeonsxl.task.CreateDInstancePlayerTask; import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger; import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.DResourceWorld; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index 45d08a60..23e06348 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -22,7 +22,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.config.PlayerData; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.global.DPortal; @@ -46,7 +45,7 @@ public class DGlobalPlayer { protected Player player; - private PlayerData data; + private DPlayerData data; private boolean breakMode; private boolean chatSpyMode; @@ -102,15 +101,15 @@ public class DGlobalPlayer { /** * @return the saved data */ - public PlayerData getData() { + public DPlayerData getData() { return data; } /** - * Load / reload a new instance of PlayerData + * Load / reload a new instance of DPlayerData */ public void loadPlayerData(File file) { - data = new PlayerData(file); + data = new DPlayerData(file); } /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 037b87c9..60fb71aa 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -20,8 +20,8 @@ import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; +import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupDisbandEvent; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent; @@ -35,7 +35,6 @@ import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; -import io.github.dre2n.dungeonsxl.task.TimeIsRunningTask; import io.github.dre2n.dungeonsxl.util.DColor; import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.DResourceWorld; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerData.java similarity index 98% rename from core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerData.java index 0fbc1578..f54733a2 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerData.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.config; +package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.commons.compatibility.CompatibilityHandler; import io.github.dre2n.commons.compatibility.Internals; @@ -22,6 +22,7 @@ import io.github.dre2n.commons.config.BRConfig; import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.DMessages; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -41,7 +42,7 @@ import org.bukkit.potion.PotionEffect; * * @author Daniel Saukel */ -public class PlayerData extends BRConfig { +public class DPlayerData extends BRConfig { DungeonsXL plugin = DungeonsXL.getInstance(); boolean is1_9 = Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals()); @@ -68,7 +69,7 @@ public class PlayerData extends BRConfig { // Stats private Map timeLastPlayed = new HashMap<>(); - public PlayerData(File file) { + public DPlayerData(File file) { super(file, CONFIG_VERSION); if (initialize) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java similarity index 69% rename from core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java index a0812a26..5cabd9f3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.listener; +package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; @@ -22,44 +22,28 @@ import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.MainConfig; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.global.DPortal; -import io.github.dre2n.dungeonsxl.global.GameSign; import io.github.dre2n.dungeonsxl.global.GlobalProtection; -import io.github.dre2n.dungeonsxl.global.GroupSign; -import io.github.dre2n.dungeonsxl.global.LeaveSign; -import io.github.dre2n.dungeonsxl.player.DEditPlayer; -import io.github.dre2n.dungeonsxl.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; -import io.github.dre2n.dungeonsxl.player.DGroup; -import io.github.dre2n.dungeonsxl.player.DInstancePlayer; -import io.github.dre2n.dungeonsxl.player.DPermissions; -import io.github.dre2n.dungeonsxl.player.DPlayers; -import io.github.dre2n.dungeonsxl.reward.DLootInventory; -import io.github.dre2n.dungeonsxl.task.RespawnTask; -import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; +import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.block.LockedDoor; -import io.github.dre2n.dungeonsxl.world.block.RewardChest; import java.util.ArrayList; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.Chest; -import org.bukkit.block.Sign; +import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerDropItemEvent; @@ -67,24 +51,230 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; /** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel + * @author Daniel Saukel, Frank Baumann, Milan Albrecht */ -public class PlayerListener implements Listener { +public class DPlayerListener { DungeonsXL plugin = DungeonsXL.getInstance(); DPlayers dPlayers = plugin.getDPlayers(); - @EventHandler(priority = EventPriority.HIGH) - public void onDeath(PlayerDeathEvent event) { + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + World world = event.getEntity().getWorld(); + DGameWorld gameWorld = DGameWorld.getByWorld(world); + + if (gameWorld == null) { + return; + } + + // Deny all Damage in Lobby + if (!gameWorld.isPlaying()) { + event.setCancelled(true); + } + + if (!(event.getEntity() instanceof LivingEntity)) { + return; + } + + boolean dead = ((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0; + if (dead && DMob.getByEntity(event.getEntity()) != null) { + String killer = null; + + if (event instanceof EntityDamageByEntityEvent) { + Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); + + if (damager instanceof Projectile) { + if (((Projectile) damager).getShooter() instanceof Player) { + damager = (Player) ((Projectile) damager).getShooter(); + } + } + + if (damager instanceof Player) { + killer = damager.getName(); + } + } + + gameWorld.getGame().addKill(killer); + } + } + + @EventHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + World world = event.getEntity().getWorld(); + DGameWorld gameWorld = DGameWorld.getByWorld(world); + + if (gameWorld == null) { + return; + } + + Game game = gameWorld.getGame(); + + if (game == null) { + return; + } + + if (!game.hasStarted()) { + return; + } + + boolean pvp = game.getRules().isPlayerVersusPlayer(); + boolean friendlyFire = game.getRules().isFriendlyFire(); + + Entity attackerEntity = event.getDamager(); + Entity attackedEntity = event.getEntity(); + + if (attackerEntity instanceof Projectile) { + attackerEntity = (Entity) ((Projectile) attackerEntity).getShooter(); + } + + Player attackerPlayer = null; + Player attackedPlayer = null; + + DGroup attackerDGroup = null; + DGroup attackedDGroup = null; + + if (!(attackerEntity instanceof LivingEntity) || !(attackedEntity instanceof LivingEntity)) { + return; + } + + if (attackerEntity instanceof Player && attackedEntity instanceof Player) { + attackerPlayer = (Player) attackerEntity; + attackedPlayer = (Player) attackedEntity; + + attackerDGroup = DGroup.getByPlayer(attackerPlayer); + attackedDGroup = DGroup.getByPlayer(attackedPlayer); + + if (!pvp) { + event.setCancelled(true); + return; + } + + if (attackerDGroup != null && attackedDGroup != null) { + if (!friendlyFire && attackerDGroup.equals(attackedDGroup)) { + event.setCancelled(true); + return; + } + } + } + + // Check Dogs + if (attackerEntity instanceof Player || attackedEntity instanceof Player) { + for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) { + if (dPlayer.getWolf() != null) { + if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { + event.setCancelled(true); + return; + } + } + } + } + + for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) { + if (dPlayer.getWolf() != null) { + if (attackerEntity instanceof Player || attackedEntity instanceof Player) { + if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { + event.setCancelled(true); + return; + } + + } else if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) { + event.setCancelled(false); + return; + } + } + } + } + + // Players don't need to eat in lobbies + @EventHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) { + World world = event.getEntity().getWorld(); + DGameWorld gameWorld = DGameWorld.getByWorld(world); + if (gameWorld != null) { + if (!gameWorld.isPlaying()) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + if (isCitizensNPC(player)) { + return; + } + DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + if (dPlayer == null) { + return; + } + + if (dPlayer.isInDungeonChat()) { + dPlayer.sendMessage(player.getDisplayName() + ": " + event.getMessage()); + event.setCancelled(true); + } + } + + @EventHandler + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + if (isCitizensNPC(player)) { + return; + } + + if (DPermissions.hasPermission(player, DPermissions.BYPASS)) { + return; + } + + if (!(dPlayers.getByPlayer(player) instanceof DInstancePlayer)) { + return; + } + DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(player); + + String command = event.getMessage().toLowerCase(); + ArrayList commandWhitelist = new ArrayList<>(); + + Game game = Game.getByWorld(dPlayer.getWorld()); + + if (dPlayer instanceof DEditPlayer) { + if (DPermissions.hasPermission(player, DPermissions.CMD_EDIT)) { + return; + + } else { + commandWhitelist.addAll(plugin.getMainConfig().getEditCommandWhitelist()); + } + + } else if (game != null) { + if (game.getRules() != null) { + commandWhitelist.addAll(game.getRules().getGameCommandWhitelist()); + } + } + + commandWhitelist.add("dungeonsxl"); + commandWhitelist.add("dungeon"); + commandWhitelist.add("dxl"); + + event.setCancelled(true); + + for (String whitelistEntry : commandWhitelist) { + if (command.equals('/' + whitelistEntry.toLowerCase()) || command.startsWith('/' + whitelistEntry.toLowerCase() + ' ')) { + event.setCancelled(false); + } + } + + if (event.isCancelled()) { + MessageUtil.sendMessage(player, DMessages.ERROR_CMD.getMessage()); + } + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); if (isCitizensNPC(player)) { return; @@ -96,8 +286,242 @@ public class PlayerListener implements Listener { dPlayer.onDeath(event); } - @EventHandler(priority = EventPriority.HIGHEST) - public void onInteract(PlayerInteractEvent event) { + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerDropItem(PlayerDropItemEvent event) { + Player player = event.getPlayer(); + if (isCitizensNPC(player)) { + return; + } + + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); + if (dPlayer == null) { + return; + } + + if (dPlayer instanceof DEditPlayer && !plugin.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) { + event.setCancelled(true); + } + + if (!(dPlayer instanceof DGamePlayer)) { + return; + } + + DGamePlayer gamePlayer = (DGamePlayer) dPlayer; + + DGroup dGroup = DGroup.getByPlayer(player); + if (dGroup == null) { + return; + } + + if (!dGroup.isPlaying()) { + event.setCancelled(true); + return; + } + + if (!gamePlayer.isReady()) { + event.setCancelled(true); + return; + } + + Game game = Game.getByWorld(gamePlayer.getWorld()); + + for (ItemStack item : game.getRules().getSecureObjects()) { + if (event.getItemDrop().getItemStack().isSimilar(item)) { + event.setCancelled(true); + MessageUtil.sendMessage(player, DMessages.ERROR_DROP.getMessage()); + return; + } + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if (dPlayers.checkPlayer(player)) { + return; + } + + DGlobalPlayer dPlayer = new DGlobalPlayer(player); + if (player.hasPlayedBefore()) { + return; + } + + if (!plugin.getMainConfig().isTutorialActivated()) { + return; + } + + if (DGamePlayer.getByPlayer(player) != null) { + return; + } + + dPlayer.startTutorial(); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerLogin(PlayerLoginEvent event) { + Player player = event.getPlayer(); + MainConfig config = plugin.getMainConfig(); + + if (!config.isTutorialActivated()) { + return; + } + + if (DGamePlayer.getByPlayer(player) != null) { + return; + } + + if (plugin.getPermissionProvider() == null || !plugin.getPermissionProvider().hasGroupSupport()) { + return; + } + + if ((config.getTutorialDungeon() == null || config.getTutorialStartGroup() == null || config.getTutorialEndGroup() == null)) { + return; + } + + for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) { + if (!config.getTutorialStartGroup().equalsIgnoreCase(group)) { + continue; + } + + if (plugin.getDWorlds().getGameWorlds().size() >= config.getMaxInstances()) { + event.setResult(PlayerLoginEvent.Result.KICK_FULL); + event.setKickMessage(DMessages.ERROR_TOO_MANY_TUTORIALS.getMessage()); + } + return; + } + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + if (isCitizensNPC(player)) { + return; + } + DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); + DGamePlayer gamePlayer = DGamePlayer.getByPlayer(player); + if (gameWorld != null && gamePlayer != null && gamePlayer.isStealing()) { + DGroup group = gamePlayer.getDGroup(); + Location startLocation = gameWorld.getStartLocation(group); + + if (startLocation.distance(player.getLocation()) < 3) { + gamePlayer.captureFlag(); + } + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); + DGroup dGroup = DGroup.getByPlayer(player); + Game game = Game.getByWorld(player.getWorld()); + + if (!(dPlayer instanceof DInstancePlayer)) { + dPlayers.removePlayer(dPlayer); + if (dGroup != null) { + dGroup.removePlayer(player); + } + + } else if (game != null) { + int timeUntilKickOfflinePlayer = game.getRules().getTimeUntilKickOfflinePlayer(); + + if (timeUntilKickOfflinePlayer == 0) { + ((DGamePlayer) dPlayer).leave(); + + } else if (timeUntilKickOfflinePlayer > 0) { + dGroup.sendMessage(DMessages.PLAYER_OFFLINE.getMessage(dPlayer.getName(), String.valueOf(timeUntilKickOfflinePlayer)), player); + ((DGamePlayer) dPlayer).setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000); + + } else { + dGroup.sendMessage(DMessages.PLAYER_OFFLINE_NEVER.getMessage(dPlayer.getName()), player); + } + + } else if (dPlayer instanceof DEditPlayer) { + ((DEditPlayer) dPlayer).leave(); + } + } + + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent event) { + Player player = event.getPlayer(); + if (isCitizensNPC(player)) { + return; + } + plugin.getDPlayers().getByPlayer(player).applyRespawnInventory(); + + DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player); + if (dPlayer == null) { + return; + } + + if (dPlayer instanceof DEditPlayer) { + DEditWorld editWorld = DEditWorld.getByWorld(((DEditPlayer) dPlayer).getWorld()); + if (editWorld == null) { + return; + } + + if (editWorld.getLobbyLocation() == null) { + event.setRespawnLocation(editWorld.getWorld().getSpawnLocation()); + + } else { + event.setRespawnLocation(editWorld.getLobbyLocation()); + } + + } else if (dPlayer instanceof DGamePlayer) { + DGamePlayer gamePlayer = (DGamePlayer) dPlayer; + + DGameWorld gameWorld = DGameWorld.getByWorld(gamePlayer.getWorld()); + + if (gameWorld == null) { + return; + } + + DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer()); + + Location respawn = gamePlayer.getCheckpoint(); + + if (respawn == null) { + respawn = dGroup.getGameWorld().getStartLocation(dGroup); + } + + // Because some plugins set another respawn point, DXL teleports a few ticks later. + new RespawnTask(player, respawn).runTaskLater(plugin, 10); + + // Don't forget Doge! + if (gamePlayer.getWolf() != null) { + gamePlayer.getWolf().teleport(respawn); + } + } + } + + @EventHandler + public void onPlayerTeleport(PlayerTeleportEvent event) { + Player player = event.getPlayer(); + if (isCitizensNPC(player)) { + return; + } + DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + + if (dPlayer == null) { + return; + } + + if (dPlayer.getWorld() == event.getTo().getWorld()) { + return; + } + + if (!DPermissions.hasPermission(player, DPermissions.BYPASS)) { + event.setCancelled(true); + } + } + + public static boolean isCitizensNPC(LivingEntity entity) { + return entity.hasMetadata("NPC"); + } + + /* SUBJECT TO CHANGE */ + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (isCitizensNPC(player)) { return; @@ -105,11 +529,6 @@ public class PlayerListener implements Listener { DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player); Block clickedBlock = event.getClickedBlock(); DGameWorld dGameWorld = DGameWorld.getByWorld(player.getWorld()); - - if (dGlobalPlayer.isInBreakMode()) { - return; - } - if (clickedBlock != null) { // Block Enderchests if (dGameWorld != null || DEditWorld.getByWorld(player.getWorld()) != null) { @@ -219,456 +638,6 @@ public class PlayerListener implements Listener { } } } - - // Check Signs - if (clickedBlock != null) { - - if (clickedBlock.getType() == Material.WALL_SIGN || clickedBlock.getType() == Material.SIGN_POST) { - // Check Group Signs - if (GroupSign.playerInteract(event.getClickedBlock(), player)) { - event.setCancelled(true); - } - - // Check Game Signs - if (GameSign.playerInteract(event.getClickedBlock(), player)) { - event.setCancelled(true); - } - - LeaveSign leaveSign = LeaveSign.getByBlock(clickedBlock); - if (leaveSign != null) { - leaveSign.onPlayerInteract(player); - event.setCancelled(true); - } - - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); - if (dPlayer != null) { - - // Check DGameWorld Signs - DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); - if (gameWorld != null) { - - // Trigger InteractTrigger - InteractTrigger trigger = InteractTrigger.getByBlock(clickedBlock, gameWorld); - if (trigger != null) { - if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { - trigger.onTrigger(player); - } - } - - // Class Signs - for (Sign classSign : gameWorld.getClassesSigns()) { - if (classSign != null) { - if (classSign.getLocation().distance(clickedBlock.getLocation()) < 1) { - if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { - dPlayer.setDClass(ChatColor.stripColor(classSign.getLine(1))); - } - break; - } - } - } - } - } - } - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onDropItem(PlayerDropItemEvent event) { - Player player = event.getPlayer(); - if (isCitizensNPC(player)) { - return; - } - - DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); - if (dPlayer == null) { - return; - } - - if (dPlayer instanceof DEditPlayer && !plugin.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) { - event.setCancelled(true); - } - - if (!(dPlayer instanceof DGamePlayer)) { - return; - } - - DGamePlayer gamePlayer = (DGamePlayer) dPlayer; - - DGroup dGroup = DGroup.getByPlayer(player); - if (dGroup == null) { - return; - } - - if (!dGroup.isPlaying()) { - event.setCancelled(true); - return; - } - - if (!gamePlayer.isReady()) { - event.setCancelled(true); - return; - } - - Game game = Game.getByWorld(gamePlayer.getWorld()); - - for (ItemStack item : game.getRules().getSecureObjects()) { - if (event.getItemDrop().getItemStack().isSimilar(item)) { - event.setCancelled(true); - MessageUtil.sendMessage(player, DMessages.ERROR_DROP.getMessage()); - return; - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onRespawn(PlayerRespawnEvent event) { - Player player = event.getPlayer(); - if (isCitizensNPC(player)) { - return; - } - plugin.getDPlayers().getByPlayer(player).applyRespawnInventory(); - - DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player); - if (dPlayer == null) { - return; - } - - if (dPlayer instanceof DEditPlayer) { - DEditWorld editWorld = DEditWorld.getByWorld(((DEditPlayer) dPlayer).getWorld()); - if (editWorld == null) { - return; - } - - if (editWorld.getLobbyLocation() == null) { - event.setRespawnLocation(editWorld.getWorld().getSpawnLocation()); - - } else { - event.setRespawnLocation(editWorld.getLobbyLocation()); - } - - } else if (dPlayer instanceof DGamePlayer) { - DGamePlayer gamePlayer = (DGamePlayer) dPlayer; - - DGameWorld gameWorld = DGameWorld.getByWorld(gamePlayer.getWorld()); - - if (gameWorld == null) { - return; - } - - DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer()); - - Location respawn = gamePlayer.getCheckpoint(); - - if (respawn == null) { - respawn = dGroup.getGameWorld().getStartLocation(dGroup); - } - - // Because some plugins set another respawn point, DXL teleports a few ticks later. - new RespawnTask(player, respawn).runTaskLater(plugin, 10); - - // Don't forget Doge! - if (gamePlayer.getWolf() != null) { - gamePlayer.getWolf().teleport(respawn); - } - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onPortal(PlayerPortalEvent event) { - Block block1 = event.getFrom().getBlock(); - Block block2 = block1.getRelative(BlockFace.WEST); - Block block3 = block1.getRelative(BlockFace.NORTH); - Block block4 = block1.getRelative(BlockFace.EAST); - Block block5 = block1.getRelative(BlockFace.SOUTH); - if (DPortal.getByBlock(block1) != null || DPortal.getByBlock(block2) != null || DPortal.getByBlock(block3) != null || DPortal.getByBlock(block4) != null || DPortal.getByBlock(block5) != null) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onTeleport(PlayerTeleportEvent event) { - Player player = event.getPlayer(); - if (isCitizensNPC(player)) { - return; - } - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); - - if (dPlayer == null) { - return; - } - - if (dPlayer.getWorld() == event.getTo().getWorld()) { - return; - } - - if (!DPermissions.hasPermission(player, DPermissions.BYPASS)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onChat(AsyncPlayerChatEvent event) { - Player player = event.getPlayer(); - if (isCitizensNPC(player)) { - return; - } - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); - if (dPlayer == null) { - return; - } - - if (dPlayer.isInDungeonChat()) { - dPlayer.sendMessage(player.getDisplayName() + ": " + event.getMessage()); - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); - DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); - DGroup dGroup = DGroup.getByPlayer(player); - Game game = Game.getByWorld(player.getWorld()); - - if (!(dPlayer instanceof DInstancePlayer)) { - dPlayers.removePlayer(dPlayer); - if (dGroup != null) { - dGroup.removePlayer(player); - } - - } else if (game != null) { - int timeUntilKickOfflinePlayer = game.getRules().getTimeUntilKickOfflinePlayer(); - - if (timeUntilKickOfflinePlayer == 0) { - ((DGamePlayer) dPlayer).leave(); - - } else if (timeUntilKickOfflinePlayer > 0) { - dGroup.sendMessage(DMessages.PLAYER_OFFLINE.getMessage(dPlayer.getName(), String.valueOf(timeUntilKickOfflinePlayer)), player); - ((DGamePlayer) dPlayer).setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000); - - } else { - dGroup.sendMessage(DMessages.PLAYER_OFFLINE_NEVER.getMessage(dPlayer.getName()), player); - } - - } else if (dPlayer instanceof DEditPlayer) { - ((DEditPlayer) dPlayer).leave(); - } - } - - @EventHandler(priority = EventPriority.NORMAL) - public void onJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if (dPlayers.checkPlayer(player)) { - return; - } - - DGlobalPlayer dPlayer = new DGlobalPlayer(player); - if (player.hasPlayedBefore()) { - return; - } - - if (!plugin.getMainConfig().isTutorialActivated()) { - return; - } - - if (DGamePlayer.getByPlayer(player) != null) { - return; - } - - dPlayer.startTutorial(); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerLogin(PlayerLoginEvent event) { - Player player = event.getPlayer(); - MainConfig config = plugin.getMainConfig(); - - if (!config.isTutorialActivated()) { - return; - } - - if (DGamePlayer.getByPlayer(player) != null) { - return; - } - - if (plugin.getPermissionProvider() == null || !plugin.getPermissionProvider().hasGroupSupport()) { - return; - } - - if ((config.getTutorialDungeon() == null || config.getTutorialStartGroup() == null || config.getTutorialEndGroup() == null)) { - return; - } - - for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) { - if (!config.getTutorialStartGroup().equalsIgnoreCase(group)) { - continue; - } - - if (plugin.getDWorlds().getGameWorlds().size() >= config.getMaxInstances()) { - event.setResult(PlayerLoginEvent.Result.KICK_FULL); - event.setKickMessage(DMessages.ERROR_TOO_MANY_TUTORIALS.getMessage()); - } - - return; - } - } - - // Deny Player Cmds - @EventHandler(priority = EventPriority.HIGH) - public void onCommand(PlayerCommandPreprocessEvent event) { - Player player = event.getPlayer(); - if (isCitizensNPC(player)) { - return; - } - - if (DPermissions.hasPermission(player, DPermissions.BYPASS)) { - return; - } - - if (!(dPlayers.getByPlayer(player) instanceof DInstancePlayer)) { - return; - } - DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(player); - - String command = event.getMessage().toLowerCase(); - ArrayList commandWhitelist = new ArrayList<>(); - - Game game = Game.getByWorld(dPlayer.getWorld()); - - if (dPlayer instanceof DEditPlayer) { - if (DPermissions.hasPermission(player, DPermissions.CMD_EDIT)) { - return; - - } else { - commandWhitelist.addAll(plugin.getMainConfig().getEditCommandWhitelist()); - } - - } else if (game != null) { - if (game.getRules() != null) { - commandWhitelist.addAll(game.getRules().getGameCommandWhitelist()); - } - } - - commandWhitelist.add("dungeonsxl"); - commandWhitelist.add("dungeon"); - commandWhitelist.add("dxl"); - - event.setCancelled(true); - - for (String whitelistEntry : commandWhitelist) { - if (command.equals('/' + whitelistEntry.toLowerCase()) || command.startsWith('/' + whitelistEntry.toLowerCase() + ' ')) { - event.setCancelled(false); - } - } - - if (event.isCancelled()) { - MessageUtil.sendMessage(player, DMessages.ERROR_CMD.getMessage()); - } - } - - // Inventory Events - @EventHandler(priority = EventPriority.HIGH) - public void onInventoryOpen(InventoryOpenEvent event) { - if (!(event.getPlayer() instanceof Player)) { - return; - } - - InventoryView inventory = event.getView(); - - DGameWorld gameWorld = DGameWorld.getByWorld(event.getPlayer().getWorld()); - - if (gameWorld == null) { - return; - } - - if (!(inventory.getTopInventory().getHolder() instanceof Chest)) { - return; - } - - Chest chest = (Chest) inventory.getTopInventory().getHolder(); - - for (RewardChest rewardChest : gameWorld.getRewardChests()) { - if (!rewardChest.getChest().equals(chest)) { - continue; - } - - rewardChest.onOpen((Player) event.getPlayer()); - event.setCancelled(true); - } - - if (!plugin.getMainConfig().getOpenInventories() && !DPermissions.hasPermission(event.getPlayer(), DPermissions.INSECURE)) { - World world = event.getPlayer().getWorld(); - if (event.getInventory().getType() != InventoryType.CREATIVE && DEditWorld.getByWorld(world) != null) { - event.setCancelled(true); - } - } - } - - @EventHandler - public void onInventoryClose(InventoryCloseEvent event) { - Player player = (Player) event.getPlayer(); - - for (DLootInventory inventory : plugin.getDLootInventories()) { - if (event.getView() != inventory.getInventoryView()) { - continue; - } - - if (System.currentTimeMillis() - inventory.getTime() <= 500) { - continue; - } - - for (ItemStack istack : inventory.getInventory().getContents()) { - if (istack != null) { - player.getWorld().dropItem(player.getLocation(), istack); - } - } - - plugin.getDLootInventories().remove(inventory); - } - } - - // Player move - @EventHandler - public void onMove(PlayerMoveEvent event) { - Player player = event.getPlayer(); - if (isCitizensNPC(player)) { - return; - } - DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); - DGamePlayer gamePlayer = DGamePlayer.getByPlayer(player); - if (gameWorld != null && gamePlayer != null && gamePlayer.isStealing()) { - DGroup group = gamePlayer.getDGroup(); - Location startLocation = gameWorld.getStartLocation(group); - - if (startLocation.distance(player.getLocation()) < 3) { - gamePlayer.captureFlag(); - } - } - - DLootInventory inventory = DLootInventory.getByPlayer(player); - if (inventory != null && player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL - && player.getLocation().getBlock().getRelative(1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(-1, 0, 0).getType() != Material.PORTAL - && player.getLocation().getBlock().getRelative(0, 0, 1).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, -1).getType() != Material.PORTAL) { - inventory.setInventoryView(player.openInventory(inventory.getInventory())); - inventory.setTime(System.currentTimeMillis()); - } - - DPortal dPortal = DPortal.getByLocation(player.getEyeLocation()); - if (dPortal == null) { - return; - } - - Block blockFrom = event.getFrom().getBlock(); - Block blockTo = event.getTo().getBlock(); - if (blockFrom.equals(blockTo)) { - return; - } - - dPortal.teleport(player); - } - - boolean isCitizensNPC(LivingEntity entity) { - return entity.hasMetadata("NPC"); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java index 62bd3bd9..03703fd1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java @@ -16,21 +16,42 @@ */ package io.github.dre2n.dungeonsxl.player; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.MainConfig; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.scheduler.BukkitTask; /** * DGlobalPlayer instance manager. * * @author Daniel Saukel */ -public class DPlayers { +public class DPlayers implements Listener { + + DungeonsXL plugin = DungeonsXL.getInstance(); + MainConfig mainConfig = plugin.getMainConfig(); + + private BukkitTask secureModeTask; + private BukkitTask updateTask; + private BukkitTask lazyUpdateTask; private CopyOnWriteArrayList dGlobalPlayers = new CopyOnWriteArrayList<>(); + public DPlayers() { + if (mainConfig.isSecureModeEnabled()) { + startSecureModeTask(mainConfig.getSecureModeCheckInterval()); + } + startUpdateTask(2L); + startLazyUpdateTask(20L); + + Bukkit.getPluginManager().registerEvents(this, plugin); + } + /** * @return the DGlobalPlayer which represents the player */ @@ -144,4 +165,47 @@ public class DPlayers { return true; } + /* Tasks */ + /** + * @return the secureModeTask + */ + public BukkitTask getSecureModeTask() { + return secureModeTask; + } + + /** + * start a new SecureModeTask + */ + public void startSecureModeTask(long period) { + secureModeTask = new SecureModeTask().runTaskTimer(plugin, period, period); + } + + /** + * @return the updateTask + */ + public BukkitTask getUpdateTask() { + return updateTask; + } + + /** + * start a new LazyUpdateTask + */ + public void startUpdateTask(long period) { + updateTask = new UpdateTask().runTaskTimer(plugin, period, period); + } + + /** + * @return the lazyUpdateTask + */ + public BukkitTask getLazyUpdateTask() { + return lazyUpdateTask; + } + + /** + * start a new LazyUpdateTask + */ + public void startLazyUpdateTask(long period) { + lazyUpdateTask = new LazyUpdateTask().runTaskTimer(plugin, period, period); + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/LazyUpdateTask.java similarity index 71% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/player/LazyUpdateTask.java index b02babe0..061c8aff 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/LazyUpdateTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/LazyUpdateTask.java @@ -14,11 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.scheduler.BukkitRunnable; /** @@ -26,15 +24,9 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class LazyUpdateTask extends BukkitRunnable { - DungeonsXL plugin = DungeonsXL.getInstance(); - @Override public void run() { - for (DGameWorld gameWorld : plugin.getDWorlds().getGameWorlds()) { - gameWorld.update(); - } - - for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) { + for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) { dPlayer.update(true); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/RespawnTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/RespawnTask.java similarity index 94% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/RespawnTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/player/RespawnTask.java index e51592ad..1b26470b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/RespawnTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/RespawnTask.java @@ -14,11 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/SecureModeTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/SecureModeTask.java similarity index 86% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/SecureModeTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/player/SecureModeTask.java index 7c4d782e..7c38b976 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/SecureModeTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/SecureModeTask.java @@ -14,13 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.player.DEditPlayer; -import io.github.dre2n.dungeonsxl.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; -import io.github.dre2n.dungeonsxl.player.DPermissions; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/TimeIsRunningTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/TimeIsRunningTask.java similarity index 95% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/TimeIsRunningTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/player/TimeIsRunningTask.java index cc68f3cd..2ef10d4d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/TimeIsRunningTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/TimeIsRunningTask.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.commons.config.MessageConfig; import io.github.dre2n.commons.util.messageutil.MessageUtil; @@ -22,8 +22,6 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; import io.github.dre2n.dungeonsxl.game.Game; -import io.github.dre2n.dungeonsxl.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.player.DGroup; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/UpdateTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/UpdateTask.java similarity index 91% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/UpdateTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/player/UpdateTask.java index 14e022eb..8f8e291d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/UpdateTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/UpdateTask.java @@ -14,10 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import org.bukkit.scheduler.BukkitRunnable; /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java index b61091d6..be6fa107 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java @@ -18,8 +18,8 @@ package io.github.dre2n.dungeonsxl.requirement; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.config.PlayerData; import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DPlayerData; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -71,7 +71,7 @@ public class FeeLevelRequirement extends Requirement { return; } - PlayerData data = dPlayer.getData(); + DPlayerData data = dPlayer.getData(); data.setOldLevel(data.getOldLevel() - fee); MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.REQUIREMENT_FEE, fee + " levels")); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardListener.java new file mode 100644 index 00000000..53f64376 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardListener.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2012-2017 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.reward; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.player.DPermissions; +import io.github.dre2n.dungeonsxl.world.DEditWorld; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import io.github.dre2n.dungeonsxl.world.block.RewardChest; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Chest; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class RewardListener implements Listener { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + @EventHandler + public void onInventoryClose(InventoryCloseEvent event) { + if (!(event.getPlayer() instanceof Player)) { + return; + } + Player player = (Player) event.getPlayer(); + + for (DLootInventory inventory : plugin.getDLootInventories()) { + if (event.getView() != inventory.getInventoryView()) { + continue; + } + + if (System.currentTimeMillis() - inventory.getTime() <= 500) { + continue; + } + + for (ItemStack istack : inventory.getInventory().getContents()) { + if (istack != null) { + player.getWorld().dropItem(player.getLocation(), istack); + } + } + + plugin.getDLootInventories().remove(inventory); + } + } + + @EventHandler + public void onInventoryOpen(InventoryOpenEvent event) { + if (!(event.getPlayer() instanceof Player)) { + return; + } + + InventoryView inventory = event.getView(); + + DGameWorld gameWorld = DGameWorld.getByWorld(event.getPlayer().getWorld()); + + if (gameWorld == null) { + return; + } + + if (!(inventory.getTopInventory().getHolder() instanceof Chest)) { + return; + } + + Chest chest = (Chest) inventory.getTopInventory().getHolder(); + + for (RewardChest rewardChest : gameWorld.getRewardChests()) { + if (!rewardChest.getChest().equals(chest)) { + continue; + } + + rewardChest.onOpen((Player) event.getPlayer()); + event.setCancelled(true); + } + + if (!plugin.getMainConfig().getOpenInventories() && !DPermissions.hasPermission(event.getPlayer(), DPermissions.INSECURE)) { + World world = event.getPlayer().getWorld(); + if (event.getInventory().getType() != InventoryType.CREATIVE && DEditWorld.getByWorld(world) != null) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + DLootInventory inventory = DLootInventory.getByPlayer(player); + if (inventory != null && player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL + && player.getLocation().getBlock().getRelative(1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(-1, 0, 0).getType() != Material.PORTAL + && player.getLocation().getBlock().getRelative(0, 0, 1).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, -1).getType() != Material.PORTAL) { + inventory.setInventoryView(player.openInventory(inventory.getInventory())); + inventory.setTime(System.currentTimeMillis()); + } + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypes.java index d6a71c71..d7254c54 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardTypes.java @@ -16,9 +16,11 @@ */ package io.github.dre2n.dungeonsxl.reward; +import io.github.dre2n.dungeonsxl.DungeonsXL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.bukkit.Bukkit; /** * RewardType instance manager. @@ -27,10 +29,13 @@ import java.util.List; */ public class RewardTypes { + DungeonsXL plugin = DungeonsXL.getInstance(); + private List types = new ArrayList<>(); public RewardTypes() { types.addAll(Arrays.asList(RewardTypeDefault.values())); + Bukkit.getPluginManager().registerEvents(new RewardListener(), plugin); } /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignListener.java new file mode 100644 index 00000000..ea78366d --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignListener.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2012-2017 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DPermissions; +import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; +import io.github.dre2n.dungeonsxl.world.DEditWorld; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import org.bukkit.ChatColor; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class DSignListener implements Listener { + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + Block clickedBlock = event.getClickedBlock(); + if (clickedBlock == null) { + return; + } + DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + if (dPlayer == null) { + return; + } + + DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); + if (gameWorld == null) { + return; + } + + InteractTrigger trigger = InteractTrigger.getByBlock(clickedBlock, gameWorld); + if (trigger != null) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + trigger.onTrigger(player); + } + } + + for (Sign classSign : gameWorld.getClassesSigns()) { + if (classSign != null) { + if (classSign.getLocation().distance(clickedBlock.getLocation()) < 1) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + dPlayer.setDClass(ChatColor.stripColor(classSign.getLine(1))); + } + break; + } + } + } + } + + @EventHandler + public void onSignChange(SignChangeEvent event) { + String[] lines = event.getLines(); + Player player = event.getPlayer(); + Block block = event.getBlock(); + Sign sign = (Sign) block.getState(); + DEditWorld editWorld = DEditWorld.getByWorld(sign.getWorld()); + if (editWorld == null) { + return; + } + + if (sign != null) { + sign.setLine(0, lines[0]); + sign.setLine(1, lines[1]); + sign.setLine(2, lines[2]); + sign.setLine(3, lines[3]); + + DSign dsign = DSign.create(sign, null); + + if (dsign == null) { + return; + } + + if (!DPermissions.hasPermission(player, dsign.getType().getBuildPermission())) { + MessageUtil.sendMessage(player, DMessages.ERROR_NO_PERMISSIONS.getMessage()); + return; + } + + if (dsign.check()) { + editWorld.registerSign(block); + editWorld.getSigns().add(block); + MessageUtil.sendMessage(player, DMessages.PLAYER_SIGN_CREATED.getMessage()); + + } else { + MessageUtil.sendMessage(player, DMessages.ERROR_SIGN_WRONG_FORMAT.getMessage()); + } + } + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index 85b072c7..57c6e5d9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -17,6 +17,17 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.dungeonsxl.player.DPermissions; +import io.github.dre2n.dungeonsxl.sign.lobby.ClassesSign; +import io.github.dre2n.dungeonsxl.sign.lobby.LobbySign; +import io.github.dre2n.dungeonsxl.sign.lobby.ReadySign; +import io.github.dre2n.dungeonsxl.sign.lobby.StartSign; +import io.github.dre2n.dungeonsxl.sign.message.ActionBarSign; +import io.github.dre2n.dungeonsxl.sign.message.HologramSign; +import io.github.dre2n.dungeonsxl.sign.message.MessageSign; +import io.github.dre2n.dungeonsxl.sign.message.SoundMessageSign; +import io.github.dre2n.dungeonsxl.sign.message.TitleSign; +import io.github.dre2n.dungeonsxl.sign.mob.DMobSign; +import io.github.dre2n.dungeonsxl.sign.mob.ExternalMobSign; /** * Default implementation of DSignType. diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypes.java index a82d61e1..a1af64d1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypes.java @@ -16,9 +16,11 @@ */ package io.github.dre2n.dungeonsxl.sign; +import io.github.dre2n.dungeonsxl.DungeonsXL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.bukkit.Bukkit; /** * DSignType instance manager. @@ -27,10 +29,13 @@ import java.util.List; */ public class DSignTypes { + DungeonsXL plugin = DungeonsXL.getInstance(); + private List types = new ArrayList<>(); public DSignTypes() { types.addAll(Arrays.asList(DSignTypeDefault.values())); + Bukkit.getPluginManager().registerEvents(new DSignListener(), plugin); } /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/DelayedPowerTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DelayedPowerTask.java similarity index 94% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/DelayedPowerTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/DelayedPowerTask.java index 863496f1..2fd07641 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/DelayedPowerTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DelayedPowerTask.java @@ -14,9 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.sign; -import io.github.dre2n.dungeonsxl.sign.RedstoneSign; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.scheduler.BukkitRunnable; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java index a4d07fe5..480bfd01 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java @@ -19,12 +19,12 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.caliburn.CaliburnAPI; import io.github.dre2n.caliburn.item.UniversalItem; import io.github.dre2n.commons.util.NumberUtil; -import io.github.dre2n.dungeonsxl.task.DropItemTask; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Sign; import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel @@ -79,13 +79,23 @@ public class DropSign extends DSign { @Override public void onTrigger() { - Location spawnLocation = getSign().getLocation().add(0.5, 0, 0.5); + final Location spawnLocation = getSign().getLocation().add(0.5, 0, 0.5); if (interval < 0) { getSign().getWorld().dropItem(spawnLocation, item); } else { long period = (long) interval * 20; - new DropItemTask(item, spawnLocation).runTaskTimer(plugin, period, period); + + new BukkitRunnable() { + @Override + public void run() { + try { + spawnLocation.getWorld().dropItem(spawnLocation, item); + } catch (NullPointerException exception) { + cancel(); + } + } + }.runTaskTimer(plugin, period, period); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/InteractSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/InteractSign.java index fe5b9abd..3a140d32 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/InteractSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/InteractSign.java @@ -17,7 +17,6 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.commons.util.NumberUtil; -import io.github.dre2n.dungeonsxl.task.SignUpdateTask; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java index d789ae4b..51671663 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/RedstoneSign.java @@ -17,7 +17,6 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.commons.util.NumberUtil; -import io.github.dre2n.dungeonsxl.task.DelayedPowerTask; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/SignUpdateTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignUpdateTask.java similarity index 96% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/SignUpdateTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignUpdateTask.java index 7becd4e3..dbda8dd9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/SignUpdateTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SignUpdateTask.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.sign; import org.bukkit.block.Sign; import org.bukkit.scheduler.BukkitRunnable; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/TriggerSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/TriggerSign.java index e9dcf07e..9f6bd57e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/TriggerSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/TriggerSign.java @@ -17,7 +17,6 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.commons.util.NumberUtil; -import io.github.dre2n.dungeonsxl.task.SignUpdateTask; import io.github.dre2n.dungeonsxl.trigger.SignTrigger; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/ClassesSign.java similarity index 88% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/ClassesSign.java index 0e4a151b..45f13b88 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/ClassesSign.java @@ -14,9 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.lobby; +import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.player.DClass; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.ChatColor; import org.bukkit.block.Sign; @@ -26,6 +30,8 @@ import org.bukkit.block.Sign; */ public class ClassesSign extends DSign { + DungeonsXL plugin = DungeonsXL.getInstance(); + private DSignType type = DSignTypeDefault.CLASSES; private DClass dClass; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LobbySign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/LobbySign.java similarity index 87% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/LobbySign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/LobbySign.java index dfb82430..3d8400a3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/LobbySign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/LobbySign.java @@ -14,8 +14,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.lobby; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.Material; import org.bukkit.block.Sign; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/ReadySign.java similarity index 94% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/ReadySign.java index 8f9cdb8b..908746d9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/ReadySign.java @@ -14,15 +14,19 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.lobby; import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.game.GameTypeDefault; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.util.ProgressBar; import io.github.dre2n.dungeonsxl.world.DGameWorld; @@ -37,6 +41,8 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class ReadySign extends DSign { + DungeonsXL plugin = DungeonsXL.getInstance(); + private DSignType type = DSignTypeDefault.READY; private GameType gameType; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/StartSign.java similarity index 89% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/StartSign.java index 2f657060..4d27765b 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/lobby/StartSign.java @@ -14,9 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.lobby; import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.Material; import org.bukkit.block.Sign; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ActionBarSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/ActionBarSign.java similarity index 90% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/ActionBarSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/ActionBarSign.java index c760807b..3bf79577 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ActionBarSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/ActionBarSign.java @@ -14,9 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.message; import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; +import io.github.dre2n.dungeonsxl.sign.PerPlayerSign; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.Material; import org.bukkit.block.Sign; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/HologramSign.java similarity index 90% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/HologramSign.java index a896e90b..1e057077 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/HologramSign.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.message; import com.gmail.filoghost.holographicdisplays.api.Hologram; import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; @@ -24,6 +24,10 @@ import io.github.dre2n.commons.compatibility.CompatibilityHandler; import io.github.dre2n.commons.compatibility.Version; import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -57,7 +61,7 @@ public class HologramSign extends DSign { Location location = getSign().getLocation(); location = location.add(0.5, NumberUtil.parseDouble(lines[2]), 0.5); - hologram = HologramsAPI.createHologram(plugin, location); + hologram = HologramsAPI.createHologram(DungeonsXL.getInstance(), location); for (String line : holoLines) { if (line.startsWith("Item:")) { String id = line.replace("Item:", ""); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/MessageSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/MessageSign.java similarity index 92% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/MessageSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/MessageSign.java index b8802795..a43ba1be 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/MessageSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/MessageSign.java @@ -14,10 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.message; import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.world.DGameWorld; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Material; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SoundMessageSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/SoundMessageSign.java similarity index 92% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/SoundMessageSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/SoundMessageSign.java index f6ee87c7..d9178c34 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/SoundMessageSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/SoundMessageSign.java @@ -14,9 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.message; import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.world.DGameWorld; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Material; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/TitleSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/TitleSign.java similarity index 91% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/TitleSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/TitleSign.java index e34265e5..5bc8f4bf 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/TitleSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/message/TitleSign.java @@ -14,9 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.message; import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; +import io.github.dre2n.dungeonsxl.sign.PerPlayerSign; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.Material; import org.bukkit.block.Sign; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DMobSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/DMobSign.java similarity index 93% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/DMobSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/DMobSign.java index 8d748d4c..4c8f4b01 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DMobSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/DMobSign.java @@ -14,10 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.mob; import io.github.dre2n.commons.util.NumberUtil; -import io.github.dre2n.dungeonsxl.task.MobSpawnTask; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.Material; import org.bukkit.block.Sign; @@ -126,7 +129,7 @@ public class DMobSign extends DSign implements MobSign { @Override public void initializeTask() { - task = new MobSpawnTask(this).runTaskTimer(plugin, 0L, 20L); + task = new MobSpawnTask(this).runTaskTimer(DungeonsXL.getInstance(), 0L, 20L); } @Override diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ExternalMobSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/ExternalMobSign.java similarity index 96% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/ExternalMobSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/ExternalMobSign.java index 09f019d3..0e6a3d9a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ExternalMobSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/ExternalMobSign.java @@ -14,12 +14,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.mob; import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.mob.ExternalMobPlugin; import io.github.dre2n.dungeonsxl.mob.ExternalMobProvider; -import io.github.dre2n.dungeonsxl.task.ExternalMobSpawnTask; +import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.world.DGameWorld; import java.util.ArrayList; import java.util.List; @@ -36,6 +39,8 @@ import org.bukkit.scheduler.BukkitTask; */ public class ExternalMobSign extends DSign implements MobSign { + DungeonsXL plugin = DungeonsXL.getInstance(); + private DSignType type = DSignTypeDefault.EXTERNAL_MOB; // Variables diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/ExternalMobSpawnTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/ExternalMobSpawnTask.java similarity index 96% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/ExternalMobSpawnTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/ExternalMobSpawnTask.java index f98ed2d9..2dd829c6 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/ExternalMobSpawnTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/ExternalMobSpawnTask.java @@ -14,11 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.sign.mob; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.mob.ExternalMobProvider; -import io.github.dre2n.dungeonsxl.sign.ExternalMobSign; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.World; import org.bukkit.scheduler.BukkitRunnable; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/MobSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/MobSign.java similarity index 98% rename from core/src/main/java/io/github/dre2n/dungeonsxl/sign/MobSign.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/MobSign.java index 4e6fd856..484b3f4a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/MobSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/MobSign.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.sign; +package io.github.dre2n.dungeonsxl.sign.mob; import org.bukkit.scheduler.BukkitTask; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/MobSpawnTask.java similarity index 97% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/MobSpawnTask.java index 5b012760..0d6d2a23 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/mob/MobSpawnTask.java @@ -14,12 +14,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.sign.mob; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.mob.DMobType; -import io.github.dre2n.dungeonsxl.sign.DMobSign; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.Location; import org.bukkit.Material; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/DropItemTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/task/DropItemTask.java deleted file mode 100644 index feb064e6..00000000 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/DropItemTask.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2012-2017 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package io.github.dre2n.dungeonsxl.task; - -import io.github.dre2n.dungeonsxl.DungeonsXL; -import org.bukkit.Location; -import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * @author Frank Baumann, Daniel Saukel - */ -public class DropItemTask extends BukkitRunnable { - - DungeonsXL plugin = DungeonsXL.getInstance(); - - private ItemStack item; - private Location location; - - public DropItemTask(ItemStack item, Location location) { - this.item = item; - this.location = location; - } - - @Override - public void run() { - try { - location.getWorld().dropItem(location, item); - } catch (NullPointerException exception) { - cancel(); - } - } - -} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/FortuneTrigger.java b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/FortuneTrigger.java index 1a4f0491..1cc7558a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/FortuneTrigger.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/FortuneTrigger.java @@ -18,7 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; -import static io.github.dre2n.dungeonsxl.trigger.Trigger.plugin; import io.github.dre2n.dungeonsxl.world.DGameWorld; /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/HangingListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerListener.java similarity index 52% rename from core/src/main/java/io/github/dre2n/dungeonsxl/listener/HangingListener.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerListener.java index 46364f1b..f9f7bb7d 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/HangingListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerListener.java @@ -14,24 +14,32 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.listener; +package io.github.dre2n.dungeonsxl.trigger; +import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.scheduler.BukkitRunnable; /** - * @author Frank Baumann + * @author Milan Albrecht, Daniel Saukel */ -public class HangingListener implements Listener { +public class TriggerListener implements Listener { @EventHandler - public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { - DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); - if (gameWorld != null) { - event.setCancelled(true); - } + public void onRedstoneEvent(final BlockRedstoneEvent event) { + new BukkitRunnable() { + @Override + public void run() { + for (DGameWorld gameWorld : DungeonsXL.getInstance().getDWorlds().getGameWorlds()) { + if (event.getBlock().getWorld() == gameWorld.getWorld()) { + RedstoneTrigger.updateAll(gameWorld); + } + } + } + }.runTaskLater(DungeonsXL.getInstance(), 1); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypes.java b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypes.java index 511c2cec..7cee7ef5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypes.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypes.java @@ -16,9 +16,11 @@ */ package io.github.dre2n.dungeonsxl.trigger; +import io.github.dre2n.dungeonsxl.DungeonsXL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.bukkit.Bukkit; /** * TriggerType instance manager. @@ -27,10 +29,13 @@ import java.util.List; */ public class TriggerTypes { + DungeonsXL plugin = DungeonsXL.getInstance(); + private List types = new ArrayList<>(); public TriggerTypes() { types.addAll(Arrays.asList(TriggerTypeDefault.values())); + Bukkit.getPluginManager().registerEvents(new TriggerListener(), plugin); } /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/BackupResourceTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/BackupResourceTask.java similarity index 93% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/BackupResourceTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/BackupResourceTask.java index cfd2f2d4..3b4085e5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/BackupResourceTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/BackupResourceTask.java @@ -14,11 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.world; import io.github.dre2n.commons.util.FileUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.world.DResourceWorld; import java.io.File; import org.bukkit.scheduler.BukkitRunnable; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index ef03d474..35227c84 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -27,8 +27,8 @@ import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.sign.DSignType; import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; -import io.github.dre2n.dungeonsxl.sign.MobSign; -import io.github.dre2n.dungeonsxl.sign.StartSign; +import io.github.dre2n.dungeonsxl.sign.lobby.StartSign; +import io.github.dre2n.dungeonsxl.sign.mob.MobSign; import io.github.dre2n.dungeonsxl.trigger.FortuneTrigger; import io.github.dre2n.dungeonsxl.trigger.ProgressTrigger; import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java index 84243523..02e288a9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java @@ -18,7 +18,6 @@ package io.github.dre2n.dungeonsxl.world; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import java.io.File; import org.bukkit.Location; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java index 5a5eb5c7..645d8b71 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java @@ -18,11 +18,8 @@ package io.github.dre2n.dungeonsxl.world; import io.github.dre2n.commons.util.FileUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.config.SignData; -import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.event.editworld.EditWorldGenerateEvent; import io.github.dre2n.dungeonsxl.player.DEditPlayer; -import io.github.dre2n.dungeonsxl.task.BackupResourceTask; import io.github.dre2n.dungeonsxl.util.worldloader.WorldLoader; import java.io.File; import java.io.IOException; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java new file mode 100644 index 00000000..75b89c49 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2012-2017 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.world; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.event.world.ChunkUnloadEvent; + +/** + * @author Daniel Saukel, Frank Baumann, Milan Albrecht + */ +public class DWorldListener implements Listener { + + DungeonsXL plugin = DungeonsXL.getInstance(); + DWorlds dWorlds = plugin.getDWorlds(); + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + Block block = event.getBlock(); + // DEditWorld Signs + DEditWorld editWorld = DEditWorld.getByWorld(block.getWorld()); + if (editWorld != null) { + editWorld.getSigns().remove(event.getBlock()); + return; + } + + // Deny DGameWorld block breaking + DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld()); + if (gameWorld != null) { + if (gameWorld.onBreak(event)) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) { + Block block = event.getBlock(); + + DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld()); + if (gameWorld == null) { + return; + } + + if (gameWorld.onPlace(event.getPlayer(), block, event.getBlockAgainst(), event.getItemInHand())) { + event.setCancelled(true); + } + } + + @EventHandler + public void onBlockIgnite(BlockIgniteEvent event) { + if (dWorlds.getInstanceByWorld(event.getBlock().getWorld()) == null) { + return; + } + + if (event.getCause() != BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) { + event.setCancelled(true); + } + } + + @EventHandler + public void onBlockSpread(BlockSpreadEvent event) { + Block block = event.getSource(); + + DInstanceWorld instance = dWorlds.getInstanceByWorld(block.getWorld()); + if (instance != null && block.getType() == Material.VINE) { + event.setCancelled(true); + } + } + + @EventHandler + public void onChunkUnload(ChunkUnloadEvent event) { + DInstanceWorld instance = dWorlds.getInstanceByWorld(event.getWorld()); + if (instance instanceof DGameWorld) { + if (((DGameWorld) instance).getLoadedChunks().contains(event.getChunk())) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); + + if (gameWorld != null) { + if (event.getEntity() instanceof LivingEntity) { + // Disable Creeper explosions in gameWorlds + event.setCancelled(true); + } else { + // Disable drops from TNT + event.setYield(0); + } + } + } + + @EventHandler + public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { + DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); + if (gameWorld != null) { + event.setCancelled(true); + } + } + + @EventHandler + public void onItemSpawn(ItemSpawnEvent event) { + if (DGameWorld.getByWorld(event.getLocation().getWorld()) != null) { + if (event.getEntity().getItemStack().getType() == Material.SIGN) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + if (dWorlds.getInstanceByWorld(event.getWorld()) != null) { + if (event.toWeatherState()) { + event.setCancelled(true); + } + } + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java index f169bb81..f1c64929 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java @@ -25,9 +25,24 @@ import java.io.File; import java.util.HashSet; import java.util.Set; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.scheduler.BukkitTask; /** * World instance manager. @@ -41,6 +56,8 @@ public class DWorlds { public static final File RAW = new File(DungeonsXL.MAPS, ".raw"); + private BukkitTask worldUnloadTask; + private Set resources = new HashSet<>(); private Set instances = new HashSet<>(); @@ -54,6 +71,9 @@ public class DWorlds { if (!RAW.exists()) { createRaw(); } + + startWorldUnloadTask(1200L); + Bukkit.getPluginManager().registerEvents(new DWorldListener(), plugin); } /* Getters and setters */ @@ -70,6 +90,13 @@ public class DWorlds { return null; } + /** + * @return the DInstanceWorld that represents this world + */ + public DInstanceWorld getInstanceByWorld(World world) { + return getInstanceByName(world.getName()); + } + /** * @return the DInstanceWorld that has this name */ @@ -273,4 +300,19 @@ public class DWorlds { FileUtil.removeDirectory(worldFolder); } + /* Tasks */ + /** + * @return the worldUnloadTask + */ + public BukkitTask getWorldUnloadTask() { + return worldUnloadTask; + } + + /** + * start a new WorldUnloadTask + */ + public void startWorldUnloadTask(long period) { + worldUnloadTask = new WorldUnloadTask().runTaskTimer(plugin, period, period); + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/SignData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/SignData.java similarity index 96% rename from core/src/main/java/io/github/dre2n/dungeonsxl/config/SignData.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/SignData.java index 3fb3eac5..33e102d4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/SignData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/SignData.java @@ -14,12 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.config; +package io.github.dre2n.dungeonsxl.world; import io.github.dre2n.dungeonsxl.sign.DSign; -import io.github.dre2n.dungeonsxl.world.DEditWorld; -import io.github.dre2n.dungeonsxl.world.DGameWorld; -import io.github.dre2n.dungeonsxl.world.DResourceWorld; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java similarity index 99% rename from core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java index 15b5f1f7..b29765c5 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.config; +package io.github.dre2n.dungeonsxl.world; import io.github.dre2n.caliburn.CaliburnAPI; import io.github.dre2n.caliburn.item.UniversalItemStack; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldUnloadTask.java similarity index 92% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldUnloadTask.java index c70779dd..b2e749da 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/WorldUnloadTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldUnloadTask.java @@ -14,12 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.world; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.world.DEditWorld; -import io.github.dre2n.dungeonsxl.world.DGameWorld; import org.bukkit.scheduler.BukkitRunnable; /** diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldUpdateTask.java similarity index 64% rename from core/src/main/java/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldUpdateTask.java index 8496e108..8482c2bd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/RedstoneEventTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldUpdateTask.java @@ -14,31 +14,21 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.dre2n.dungeonsxl.task; +package io.github.dre2n.dungeonsxl.world; import io.github.dre2n.dungeonsxl.DungeonsXL; -import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger; -import io.github.dre2n.dungeonsxl.world.DGameWorld; -import org.bukkit.block.Block; import org.bukkit.scheduler.BukkitRunnable; /** - * @author Frank Baumann, Daniel Saukel + * + * @author Daniel Saukel */ -public class RedstoneEventTask extends BukkitRunnable { - - private Block block; - - public RedstoneEventTask(final Block block) { - this.block = block; - } +public class WorldUpdateTask extends BukkitRunnable { @Override public void run() { for (DGameWorld gameWorld : DungeonsXL.getInstance().getDWorlds().getGameWorlds()) { - if (block.getWorld() == gameWorld.getWorld()) { - RedstoneTrigger.updateAll(gameWorld); - } + gameWorld.update(); } }