From 72096710b3b578dd686737ae46ca544de65de0d3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Jan 2020 12:53:31 +0100 Subject: [PATCH] WIP Splitting Setup and refactoring Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 92 +++++++---- .../fightsystem/commands/AkCommand.java | 2 +- .../fightsystem/commands/Commands.java | 2 +- .../fightsystem/fight/FightState.java | 8 - .../steamwar/fightsystem/fight/FightTeam.java | 1 + .../fightsystem/listener/BasicListener.java | 50 +++--- .../fightsystem/listener/BlockListener.java | 30 ---- .../listener/EntityDamageListener.java | 61 ++----- .../listener/EntityExplodeListener.java | 14 +- .../listener/EventJoinListener.java | 15 +- .../listener/FoodLevelChangeListener.java | 7 + .../listener/FreezeWorldStateListener.java | 61 +++++++ .../listener/HotbarGUIListener.java | 15 +- .../listener/InFightDamageListener.java | 65 ++++++++ ...ner.java => InFightInventoryListener.java} | 21 +-- .../listener/NormalJoinListener.java | 13 +- .../fightsystem/listener/PistonListener.java | 18 ++- .../listener/PlayerChatListener.java | 8 +- .../listener/PlayerConnectionListener.java | 62 -------- .../listener/PlayerDeathListener.java | 32 ---- .../listener/PlayerMoveListener.java | 2 +- .../listener/PlayerRespawnListener.java | 21 --- .../listener/PlayerStateListener.java | 113 +++++++++++++ .../listener/PlayerTeleportListener.java | 16 -- .../listener/ProjectileLaunchListener.java | 19 ++- .../fightsystem/listener/TestListener.java | 149 ++++++++++++++++-- .../fightsystem/states/FightState.java | 39 +++++ .../fightsystem/states/StateDependent.java | 26 +++ .../fightsystem/utils/FightScoreboard.java | 7 +- .../steamwar/fightsystem/utils/TechHider.java | 2 +- .../winconditions/PlayerWincondition.java | 2 +- .../WinconditionPercentSystem.java | 2 +- .../WinconditionWaterTechKO.java | 2 +- 33 files changed, 614 insertions(+), 363 deletions(-) delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/fight/FightState.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/BlockListener.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{InventoryListener.java => InFightInventoryListener.java} (82%) delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerConnectionListener.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerDeathListener.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerRespawnListener.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerTeleportListener.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 3fca9c5..4cb4aed 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -4,10 +4,11 @@ import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.*; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.FightScoreboard; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.utils.WaterRemover; @@ -19,14 +20,15 @@ import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import java.util.List; +import java.util.*; public class FightSystem extends JavaPlugin { public static final String PREFIX = "§eArena§8» "; private static FightSystem plugin; - private static FightState fightState = FightState.SETUP; + private static FightState fightState = FightState.PRE_LEADER_SETUP; + private static Map stateDependentFeatures = new HashMap<>(); private static int fightTime = 0; @Override @@ -45,16 +47,14 @@ public class FightSystem extends JavaPlugin { new FoodLevelChangeListener(); new PistonListener(); new PlayerChatListener(); - new PlayerDeathListener(); new HotbarGUIListener(); new PlayerMoveListener(); - new PlayerConnectionListener(); - new PlayerRespawnListener(); - new PlayerTeleportListener(); + new PlayerStateListener(); new ProjectileLaunchListener(); + new InFightDamageListener(); if(!Config.test()){ - new BlockListener(); + new FreezeWorldStateListener(); TechHider.init(); } @@ -89,14 +89,13 @@ public class FightSystem extends JavaPlugin { new NoPlayersOnlineCountdown(); }else{ new NormalJoinListener(); - new InventoryListener(); new NoPlayersOnlineCountdown(); } } public static void setPreRunningState() { - if(fightState != FightState.SETUP) + if(fightState != FightState.PRE_LEADER_SETUP) //TODO return; setFightState(FightState.PRE_RUNNING); Countdown.cancelAllTimers(); @@ -189,31 +188,6 @@ public class FightSystem extends JavaPlugin { } } - private static void loadKits(FightTeam team){ - for(FightPlayer allFightPlayers : team.getPlayers()) { - if(allFightPlayers.getPlayer() == null) - continue; - allFightPlayers.getPlayer().getInventory().clear(); - if(allFightPlayers.getKit() == null) - continue; - allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer()); - } - } - - private static void setAllPlayersGM(GameMode gm) { - for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){ - fightPlayer.getPlayer().setGameMode(gm); - } - for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){ - fightPlayer.getPlayer().setGameMode(gm); - } - } - - private static void setFightState(FightState state){ - fightState = state; - BasicListener.fightStateChange(state); - } - public static void setEventLeiter(Player el){ IFightSystem.setEventLeiter(el); } @@ -249,4 +223,52 @@ public class FightSystem extends JavaPlugin { public static void shutdown(String reason){ IFightSystem.shutdown(reason); } + + public static void registerStateDependent(StateDependent stateDependent){ + stateDependentFeatures.put(stateDependent, false); + } + + private static void loadKits(FightTeam team){ + for(FightPlayer allFightPlayers : team.getPlayers()) { + if(allFightPlayers.getPlayer() == null) + continue; + allFightPlayers.getPlayer().getInventory().clear(); + if(allFightPlayers.getKit() == null) + continue; + allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer()); + } + } + + private static void setAllPlayersGM(GameMode gm) { + for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){ + fightPlayer.getPlayer().setGameMode(gm); + } + for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){ + fightPlayer.getPlayer().setGameMode(gm); + } + } + + private static void setFightState(FightState state){ + fightState = state; + postStateChange(); + } + + private static void postStateChange(){ + for(Map.Entry feature : stateDependentFeatures.entrySet()){ + //Enable feature if should be enabled and currently disabled + if(feature.getKey().enabled().contains(fightState)){ + if(!feature.getValue()){ + feature.getKey().enable(); + feature.setValue(true); + } + feature.getKey().stateChange(fightState); + } + + //Disable feature if should be disabled and currently enabled + if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){ + feature.getKey().disable(); + feature.setValue(false); + } + } + } } \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java index d98aaf1..5f5d775 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java @@ -2,7 +2,7 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.Config; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java index 25f6a83..48a01d8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java @@ -3,7 +3,7 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.kit.Kit; import de.steamwar.fightsystem.kit.KitManager; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightState.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightState.java deleted file mode 100644 index 017990b..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightState.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.steamwar.fightsystem.fight; - -public enum FightState { - SETUP, - PRE_RUNNING, - RUNNING, - SPECTATE -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 2613094..edaaa86 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -3,6 +3,7 @@ package de.steamwar.fightsystem.fight; import com.sk89q.worldedit.EditSession; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.kit.KitManager; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java index e78d504..aa507f3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java @@ -3,48 +3,29 @@ package de.steamwar.fightsystem.listener; import de.steamwar.core.Core; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import java.util.LinkedList; -import java.util.List; +import java.util.Set; -public abstract class BasicListener implements Listener { +public abstract class BasicListener implements Listener, StateDependent { - private static final List listeners = new LinkedList<>(); + private final Set enabled; - BasicListener(){ - Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); - listeners.add(this); - } - - public static void fightStateChange(FightState state){ - for (int i = listeners.size() - 1; i >= 0; i--) { - listeners.get(i).stateChange(state); - } - } - - boolean notRunning(){ - return FightSystem.getFightState() != FightState.RUNNING; + BasicListener(Set enabled){ + this.enabled = enabled; + FightSystem.registerStateDependent(this); } boolean notFighting(Player p){ return Fight.getFightPlayer(p) == null; } - void stateChange(FightState state){ - //Unused - } - - void disable(){ - HandlerList.unregisterAll(this); - listeners.remove(this); - } - public static void toActionbar(Player player, BaseComponent... components){ switch(Core.getVersion()){ case 15: @@ -109,4 +90,19 @@ public abstract class BasicListener implements Listener { BasicListener_12.setAttackSpeed(player); } } + + @Override + public void enable(){ + Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); + } + + @Override + public void disable(){ + HandlerList.unregisterAll(this); + } + + @Override + public Set enabled() { + return enabled; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BlockListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BlockListener.java deleted file mode 100644 index 5c55204..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BlockListener.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.steamwar.fightsystem.listener; - -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; - -public class BlockListener extends BasicListener { - - @EventHandler - public void handleBlockBreak(BlockBreakEvent event) { - Player player = event.getPlayer(); - - if(notRunning() || notFighting(player)){ - event.setCancelled(true); - toActionbar(player, TextComponent.fromLegacyText("§cDu darfst erst nach Fightbeginn Blöcke abbauen!")); - } - } - - @EventHandler - public void handleBlockPlace(BlockPlaceEvent event) { - Player player = event.getPlayer(); - - if(notRunning() || notFighting(player)) { - event.setCancelled(true); - toActionbar(player, TextComponent.fromLegacyText("§cDu darfst erst nach Fightbeginn Blöcke setzen!")); - } - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamageListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamageListener.java index 94b012e..ddda493 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamageListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamageListener.java @@ -1,68 +1,25 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.fightsystem.fight.Fight; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Player; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import java.util.EnumSet; + public class EntityDamageListener extends BasicListener { + public EntityDamageListener() { + super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE)); + } + @EventHandler public void handleEntityDamage(EntityDamageEvent event) { - if(notRunning()){ - event.setCancelled(true); - return; - } - - if(!(event.getEntity() instanceof Player)) - return; - - if(notFighting((Player)event.getEntity())) - event.setCancelled(true); + event.setCancelled(true); } @EventHandler public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) { - if(notRunning()) { - event.setCancelled(true); - return; - } - - if(!(event.getEntity() instanceof Player)) - //Target is not a player - return; - - Player player = ((Player) event.getEntity()).getPlayer(); - Player damager; - - if(event.getDamager() instanceof Player) { - damager = ((Player) event.getDamager()).getPlayer(); - }else if(event.getDamager() instanceof Arrow) { - Arrow damagerArrow = (Arrow) event.getDamager(); - if(!(damagerArrow.getShooter() instanceof Player)) - //Shooter is not a player - return; - - damagerArrow.setFireTicks(0); - player.setFireTicks(0); - damager = (Player) damagerArrow.getShooter(); - }else{ - //Damager is not a player - return; - } - - if(notFighting(damager)){ - event.setCancelled(true); - //Damager is not fighting - return; - } - - if(Fight.getPlayerTeam(player) == Fight.getPlayerTeam(damager)) { - event.setCancelled(true); - toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); - } + event.setCancelled(true); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java index f7b5f6b..390ddfb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java @@ -1,19 +1,21 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.WaterRemover; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityExplodeEvent; +import java.util.EnumSet; + public class EntityExplodeListener extends BasicListener { + public EntityExplodeListener() { + super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + } + @EventHandler public void handleEntityExplode(EntityExplodeEvent event) { - if(notRunning()){ - event.setCancelled(true); - return; - } - - event.setYield(0); //No drops (additionally to world config + event.setYield(0); //No drops (additionally to world config) WaterRemover.add(event.blockList()); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java index e9edb1e..da76ffc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java @@ -1,19 +1,25 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.EnumSet; + public class EventJoinListener extends BasicListener { + public EventJoinListener() { + super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP)); + } + @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); @@ -54,9 +60,4 @@ public class EventJoinListener extends BasicListener { if(player == FightSystem.getEventLeiter()) FightSystem.setEventLeiter(null); } - - @Override - void stateChange(FightState state){ - disable(); - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java index 10121d1..589f3e3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java @@ -1,11 +1,18 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent; +import java.util.EnumSet; + public class FoodLevelChangeListener extends BasicListener { + public FoodLevelChangeListener() { + super(EnumSet.allOf(FightState.class)); + } + @EventHandler public void handleFoodLevelChange(FoodLevelChangeEvent event) { event.setCancelled(true); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java new file mode 100644 index 0000000..4b35430 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java @@ -0,0 +1,61 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.states.FightState; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.event.player.PlayerDropItemEvent; + +import java.util.EnumSet; + +public class FreezeWorldStateListener extends BasicListener { + + public FreezeWorldStateListener() { + super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE)); + } + + @EventHandler + public void handleBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + event.setCancelled(true); + toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke abbauen!")); + } + + @EventHandler + public void handleBlockPlace(BlockPlaceEvent event) { + Player player = event.getPlayer(); + event.setCancelled(true); + toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke setzen!")); + } + + @EventHandler + public void handleEntityExplode(EntityExplodeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onInventoryDrag(InventoryDragEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onDropPickup(InventoryPickupItemEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onDropping(PlayerDropItemEvent e){ + e.setCancelled(true); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java index 738c25a..b5958bf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java @@ -1,17 +1,23 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.commands.GUI; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.meta.ItemMeta; +import java.util.EnumSet; + public class HotbarGUIListener extends BasicListener { + public HotbarGUIListener() { + super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP)); + } + @EventHandler public void handlePlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); @@ -55,9 +61,4 @@ public class HotbarGUIListener extends BasicListener { } } } - - @Override - void stateChange(FightState state){ - disable(); - } } \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java new file mode 100644 index 0000000..cbf4d50 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java @@ -0,0 +1,65 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.states.FightState; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; + +import java.util.EnumSet; + +public class InFightDamageListener extends BasicListener { + + public InFightDamageListener() { + super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + } + + @EventHandler + public void handleEntityDamage(EntityDamageEvent event) { + if(!(event.getEntity() instanceof Player)) + return; + + if(notFighting((Player)event.getEntity())) + event.setCancelled(true); + } + + @EventHandler + public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) { + if(!(event.getEntity() instanceof Player)) + //Target is not a player + return; + + Player player = ((Player) event.getEntity()); + Player damager; + + if(event.getDamager() instanceof Player) { + damager = ((Player) event.getDamager()).getPlayer(); + }else if(event.getDamager() instanceof Arrow) { + Arrow damagerArrow = (Arrow) event.getDamager(); + if(!(damagerArrow.getShooter() instanceof Player)) + //Shooter is not a player + return; + + damagerArrow.setFireTicks(0); + player.setFireTicks(0); + damager = (Player) damagerArrow.getShooter(); + }else{ + //Damager is not a player + return; + } + + if(notFighting(damager)){ + event.setCancelled(true); + //Damager is not fighting + return; + } + + if(Fight.getPlayerTeam(player) == Fight.getPlayerTeam(damager)) { + event.setCancelled(true); + toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InventoryListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java similarity index 82% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/InventoryListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java index 188a983..359116c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InventoryListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java @@ -1,7 +1,6 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.inventory.InventoryClickEvent; @@ -12,15 +11,16 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -public class InventoryListener extends BasicListener { +import java.util.EnumSet; + +public class InFightInventoryListener extends BasicListener { + + public InFightInventoryListener() { + super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + } @EventHandler public void onInventoryClick(InventoryClickEvent event) { - if(FightSystem.getFightState() == FightState.SETUP){ - event.setCancelled(true); - return; - } - Inventory clicked = event.getClickedInventory(); if(event.getClick().isShiftClick()){ ItemStack clickedOn = event.getCurrentItem(); @@ -41,11 +41,6 @@ public class InventoryListener extends BasicListener { @EventHandler public void onInventoryDrag(InventoryDragEvent event) { - if(FightSystem.getFightState() == FightState.SETUP){ - event.setCancelled(true); - return; - } - if (event.getInventory().getType() != InventoryType.PLAYER) { int inventorySize = event.getInventory().getSize(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java index f1739c3..05a22a4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java @@ -4,14 +4,20 @@ import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.countdown.NoPlayersOnlineCountdown; import de.steamwar.fightsystem.countdown.SetupOverCountdown; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; +import java.util.EnumSet; + public class NormalJoinListener extends BasicListener { + public NormalJoinListener() { + super(EnumSet.of(FightState.PRE_LEADER_SETUP)); + } + @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); @@ -31,9 +37,4 @@ public class NormalJoinListener extends BasicListener { new SetupOverCountdown(); } } - - @Override - void stateChange(FightState state){ - disable(); - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java index fbb8e95..472e4b8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java @@ -1,8 +1,7 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.Region; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -10,13 +9,19 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import java.util.EnumSet; + public class PistonListener extends BasicListener { + public PistonListener() { + //Wenn Entern aktiv ist, sollen Raketen etc. entern können + super(Config.Entern + ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) + : EnumSet.allOf(FightState.class)); + } + @EventHandler public void handlePistonExtend(BlockPistonExtendEvent e){ - if(Config.Entern && FightSystem.getFightState() != FightState.SETUP) - return; - BlockFace b = e.getDirection(); for(Block block : e.getBlocks()){ if( @@ -32,9 +37,6 @@ public class PistonListener extends BasicListener { @EventHandler public void handlePistonRetract(BlockPistonRetractEvent e){ - if(Config.Entern && FightSystem.getFightState() != FightState.SETUP) - return; - BlockFace b = e.getDirection(); for(Block block : e.getBlocks()){ if( diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java index 8b9bf92..44ad9bd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java @@ -4,6 +4,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -11,15 +12,20 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.AsyncPlayerChatEvent; +import java.util.EnumSet; + public class PlayerChatListener extends BasicListener { + public PlayerChatListener(){ + super(EnumSet.allOf(FightState.class)); + } + @EventHandler public void handlePlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); String message = event.getMessage(); FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam != null) { String teamName = fightTeam.getColoredName(); if(message.startsWith(Config.TeamChatDetection)) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerConnectionListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerConnectionListener.java deleted file mode 100644 index d3c23be..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerConnectionListener.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.steamwar.fightsystem.listener; - -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.fight.FightState; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.Config; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -public class PlayerConnectionListener extends BasicListener{ - - @EventHandler(priority = EventPriority.HIGH) - public void handlePlayerJoin(PlayerJoinEvent event) { - event.setJoinMessage(null); - - Player player = event.getPlayer(); - player.setHealth(20); - player.setFoodLevel(20); - setAttackSpeed(player); - - FightTeam fightTeam = Fight.getPlayerTeam(player); - - if (fightTeam == null) { - player.setGameMode(GameMode.SPECTATOR); - player.teleport(Config.SpecSpawn); - } else { - player.teleport(fightTeam.getSpawn()); - if(FightSystem.getFightState() == FightState.SETUP) - player.setGameMode(GameMode.ADVENTURE); - else - player.setGameMode(GameMode.SPECTATOR); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void handlePlayerQuit(PlayerQuitEvent event) { - event.setQuitMessage(null); - - Player player = event.getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam == null) - return; - - FightState fightState = FightSystem.getFightState(); - if(fightState == FightState.SETUP){ - fightTeam.removePlayer(player); - }else if(fightState == FightState.PRE_RUNNING || fightState == FightState.RUNNING){ - FightPlayer fightPlayer = fightTeam.getFightPlayer(player); - if(fightPlayer.isLiving()) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §chat den Kampf verlassen!"); - fightTeam.getFightPlayer(player).setOut(); - } - } - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerDeathListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerDeathListener.java deleted file mode 100644 index ae22b48..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerDeathListener.java +++ /dev/null @@ -1,32 +0,0 @@ -package de.steamwar.fightsystem.listener; - -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.countdown.Countdown; -import de.steamwar.fightsystem.countdown.SWSound; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.PlayerDeathEvent; - -public class PlayerDeathListener extends BasicListener { - - @EventHandler(priority = EventPriority.HIGH) - public void handlePlayerDeath(PlayerDeathEvent event) { - Player player = event.getEntity().getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); - - if(fightTeam == null) - return; - - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §cist gestorben!"); - event.setDeathMessage(null); - fightTeam.getFightPlayer(player).setOut(); - player.setGameMode(GameMode.SPECTATOR); - player.teleport(fightTeam.getSpawn()); - Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java index 124aabd..16c3b71 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java @@ -2,7 +2,7 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.utils.Region; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerRespawnListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerRespawnListener.java deleted file mode 100644 index 6a8723a..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerRespawnListener.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.steamwar.fightsystem.listener; - -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.Config; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerRespawnEvent; - -public class PlayerRespawnListener extends BasicListener { - - @EventHandler - public void handlePlayerRespawn(PlayerRespawnEvent event) { - Player player = event.getPlayer(); - FightTeam team = Fight.getPlayerTeam(player); - if(team == null) - event.setRespawnLocation(Config.SpecSpawn); - else - event.setRespawnLocation(team.getSpawn()); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java new file mode 100644 index 0000000..58b0602 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java @@ -0,0 +1,113 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.countdown.SWSound; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +import java.util.EnumSet; + +public class PlayerStateListener extends BasicListener{ + + public PlayerStateListener() { + super(EnumSet.allOf(FightState.class)); + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerJoin(PlayerJoinEvent event) { + event.setJoinMessage(null); + + Player player = event.getPlayer(); + player.setHealth(20); + player.setFoodLevel(20); + setAttackSpeed(player); + + FightTeam fightTeam = Fight.getPlayerTeam(player); + + if (fightTeam == null) { + player.setGameMode(GameMode.SPECTATOR); + player.teleport(Config.SpecSpawn); + } else { + player.teleport(fightTeam.getSpawn()); + if(FightSystem.getFightState().setup()) + player.setGameMode(GameMode.ADVENTURE); + else + player.setGameMode(GameMode.SPECTATOR); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerDeath(PlayerDeathEvent event) { + Player player = event.getEntity().getPlayer(); + FightTeam fightTeam = Fight.getPlayerTeam(player); + + if(fightTeam == null) + return; + + assert player != null; + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §cist gestorben!"); + event.setDeathMessage(null); + fightTeam.getFightPlayer(player).setOut(); + player.setGameMode(GameMode.SPECTATOR); + player.teleport(fightTeam.getSpawn()); + Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F); + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerQuit(PlayerQuitEvent event) { + event.setQuitMessage(null); + + Player player = event.getPlayer(); + FightTeam fightTeam = Fight.getPlayerTeam(player); + if(fightTeam == null) + return; + + FightState fightState = FightSystem.getFightState(); + if(fightState.setup()){ + fightTeam.removePlayer(player); + }else if(fightState.ingame()){ + FightPlayer fightPlayer = fightTeam.getFightPlayer(player); + if(fightPlayer.isLiving()) { + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §chat den Kampf verlassen!"); + fightTeam.getFightPlayer(player).setOut(); + } + } + + //Shutdown server if nobody online and its not an event server + if(!Config.event() && (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(player)))) + FightSystem.shutdown(null); + } + + @EventHandler + public void handlePlayerRespawn(PlayerRespawnEvent event) { + Player player = event.getPlayer(); + FightTeam team = Fight.getPlayerTeam(player); + if(team == null) + event.setRespawnLocation(Config.SpecSpawn); + else + event.setRespawnLocation(team.getSpawn()); + } + + @EventHandler + public void onTpGM3(PlayerTeleportEvent e) { + if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) { + e.setCancelled(true); + toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!")); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerTeleportListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerTeleportListener.java deleted file mode 100644 index 519d61c..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerTeleportListener.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.steamwar.fightsystem.listener; - -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerTeleportEvent; - -public class PlayerTeleportListener extends BasicListener { - - @EventHandler - public void onTpGM3(PlayerTeleportEvent e) { - if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) { - e.setCancelled(true); - toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!")); - } - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ProjectileLaunchListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ProjectileLaunchListener.java index bb3df17..e9c32fe 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ProjectileLaunchListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ProjectileLaunchListener.java @@ -1,22 +1,25 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.ProjectileLaunchEvent; +import java.util.EnumSet; + public class ProjectileLaunchListener extends BasicListener { + public ProjectileLaunchListener() { + super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + } + @EventHandler public void handleProjectileLaunch(ProjectileLaunchEvent event) { - if(FightSystem.getFightState() != FightState.RUNNING) { - event.setCancelled(true); - if(event.getEntity().getShooter() instanceof Player){ - Player player = (Player) event.getEntity().getShooter(); - toActionbar(player, TextComponent.fromLegacyText("§cDu darfst den Bogen erst nach Fightbeginn nutzen!")); - } + event.setCancelled(true); + if(event.getEntity().getShooter() instanceof Player){ + Player player = (Player) event.getEntity().getShooter(); + toActionbar(player, TextComponent.fromLegacyText("§cDu darfst den Bogen erst nach Fightbeginn nutzen!")); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestListener.java index a997cc7..24c6fda 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestListener.java @@ -4,17 +4,21 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.countdown.NoPlayersOnlineCountdown; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.fight.FightTeam; -import org.bukkit.Bukkit; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.permissions.PermissionAttachment; +import java.util.EnumSet; + public class TestListener extends BasicListener { + public TestListener() { + super(EnumSet.allOf(FightState.class)); + } + @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); @@ -26,23 +30,138 @@ public class TestListener extends BasicListener { Countdown.cancelTimerType(NoPlayersOnlineCountdown.class); - PermissionAttachment attachment = player.addAttachment(FightSystem.getPlugin()); attachment.setPermission("fawe.permpack.basic", true); attachment.setPermission("minecraft.command.gamemode", true); attachment.setPermission("minecraft.command.tp", true); attachment.setPermission("worldedit.navigation.jumpto.tool", true); attachment.setPermission("worldedit.navigation.thru.tool", true); - } - - @EventHandler - public void handlePlayerQuit(PlayerQuitEvent event){ - if(Bukkit.getOnlinePlayers().isEmpty()) - FightSystem.shutdown(null); - } - - @Override - void stateChange(FightState state){ - disable(); + attachment.setPermission("worldedit.navigation.jumpto.tool", true); + attachment.setPermission("worldedit.navigation.thru.tool", true); + attachment.setPermission("worldedit.biome.info", true); + attachment.setPermission("worldedit.biome.set", true); + attachment.setPermission("worldedit.biome.list", true); + attachment.setPermission("worldedit.chunkinfo", true); + attachment.setPermission("worldedit.listchunks", true); + attachment.setPermission("worldedit.clipboard.cut", true); + attachment.setPermission("worldedit.clipboard.paste", true); + attachment.setPermission("worldedit.schematic.formats", true); + attachment.setPermission("worldedit.schematic.load", true); + attachment.setPermission("worldedit.schematic.list", true); + attachment.setPermission("worldedit.schematic.save", true); + attachment.setPermission("worldedit.clipboard.clear", true); + attachment.setPermission("worldedit.clipboard.copy", true); + attachment.setPermission("worldedit.clipboard.lazycopy", true); + attachment.setPermission("worldedit.clipboard.place", true); + attachment.setPermission("worldedit.clipboard.download", true); + attachment.setPermission("worldedit.clipboard.flip", true); + attachment.setPermission("worldedit.clipboard.rotate", true); + attachment.setPermission("worldedit.help", true); + attachment.setPermission("worldedit.global-mask", true); + attachment.setPermission("worldedit.global-transform", true); + attachment.setPermission("worldedit.generation.cylinder", true); + attachment.setPermission("worldedit.generation.sphere", true); + attachment.setPermission("worldedit.generation.forest", true); + attachment.setPermission("worldedit.generation.pumpkins", true); + attachment.setPermission("worldedit.generation.pyramid", true); + attachment.setPermission("worldedit.generation.shape", true); + attachment.setPermission("worldedit.biome.set", true); + attachment.setPermission("worldedit.history.undo", true); + attachment.setPermission("worldedit.history.redo", true); + attachment.setPermission("worldedit.history.rollback", true); + attachment.setPermission("worldedit.navigation.unstuck", true); + attachment.setPermission("worldedit.navigation.ascend", true); + attachment.setPermission("worldedit.navigation.descend", true); + attachment.setPermission("worldedit.navigation.ceiling", true); + attachment.setPermission("worldedit.navigation.thru.command", true); + attachment.setPermission("worldedit.navigation.jumpto.command", true); + attachment.setPermission("worldedit.navigation.up", true); + attachment.setPermission("worldedit.region.hollow", true); + attachment.setPermission("worldedit.region.line", true); + attachment.setPermission("worldedit.region.curve", true); + attachment.setPermission("worldedit.region.overlay", true); + attachment.setPermission("worldedit.region.center", true); + attachment.setPermission("worldedit.region.naturalize", true); + attachment.setPermission("worldedit.region.walls", true); + attachment.setPermission("worldedit.region.faces", true); + attachment.setPermission("worldedit.region.smooth", true); + attachment.setPermission("worldedit.region.move", true); + attachment.setPermission("worldedit.region.forest", true); + attachment.setPermission("worldedit.region.replace", true); + attachment.setPermission("worldedit.region.stack", true); + attachment.setPermission("worldedit.region.set", true); + attachment.setPermission("worldedit.selection.pos", true); + attachment.setPermission("worldedit.selection.chunk", true); + attachment.setPermission("worldedit.selection.hpos", true); + attachment.setPermission("worldedit.wand", true); + attachment.setPermission("worldedit.wand.toggle", true); + attachment.setPermission("worldedit.selection.contract", true); + attachment.setPermission("worldedit.selection.outset", true); + attachment.setPermission("worldedit.selection.inset", true); + attachment.setPermission("worldedit.analysis.distr", true); + attachment.setPermission("worldedit.analysis.count", true); + attachment.setPermission("worldedit.selection.size", true); + attachment.setPermission("worldedit.selection.expand", true); + attachment.setPermission("worldedit.selection.shift", true); + attachment.setPermission("worldedit.snapshots.list", true); + attachment.setPermission("worldedit.superpickaxe", true); + attachment.setPermission("worldedit.superpickaxe.area", true); + attachment.setPermission("worldedit.superpickaxe.recursive", true); + attachment.setPermission("worldedit.brush.blendball", true); + attachment.setPermission("worldedit.brush.erode", true); + attachment.setPermission("worldedit.brush.pull", true); + attachment.setPermission("worldedit.brush.circle", true); + attachment.setPermission("worldedit.brush.recursive", true); + attachment.setPermission("worldedit.brush.line", true); + attachment.setPermission("worldedit.brush.spline", true); + attachment.setPermission("worldedit.brush.surfacespline", true); + attachment.setPermission("worldedit.brush.shatter", true); + attachment.setPermission("worldedit.brush.stencil", true); + attachment.setPermission("worldedit.brush.height", true); + attachment.setPermission("worldedit.brush.layer", true); + attachment.setPermission("worldedit.brush.populateschematic", true); + attachment.setPermission("worldedit.brush.scatter", true); + attachment.setPermission("worldedit.brush.splatter", true); + attachment.setPermission("worldedit.brush.scattercommand", true); + attachment.setPermission("worldedit.brush.copy", true); + attachment.setPermission("worldedit.brush.command", true); + attachment.setPermission("worldedit.brush.apply", true); + attachment.setPermission("worldedit.brush.sphere", true); + attachment.setPermission("worldedit.brush.cylinder", true); + attachment.setPermission("worldedit.brush.clipboard", true); + attachment.setPermission("worldedit.brush.smooth", true); + attachment.setPermission("worldedit.brush.ex", true); + attachment.setPermission("worldedit.brush.gravity", true); + attachment.setPermission("worldedit.brush.options.range", true); + attachment.setPermission("worldedit.brush.options.material", true); + attachment.setPermission("worldedit.brush.options.size", true); + attachment.setPermission("worldedit.brush.options.mask", true); + attachment.setPermission("worldedit.brush.options.smask", true); + attachment.setPermission("worldedit.brush.options.transform", true); + attachment.setPermission("worldedit.brush.options.scroll", true); + attachment.setPermission("worldedit.brush.options.visualize", true); + attachment.setPermission("worldedit.tool.deltree", true); + attachment.setPermission("worldedit.tool.farwand", true); + attachment.setPermission("worldedit.tool.lrbuild", true); + attachment.setPermission("worldedit.tool.info", true); + attachment.setPermission("worldedit.tool.tree", true); + attachment.setPermission("worldedit.tool.replacer", true); + attachment.setPermission("worldedit.tool.data-cycler", true); + attachment.setPermission("worldedit.tool.flood-fill", true); + attachment.setPermission("worldedit.tool.inspect", true); + attachment.setPermission("worldedit.fill.recursive", true); + attachment.setPermission("worldedit.drain", true); + attachment.setPermission("worldedit.fixlava", true); + attachment.setPermission("worldedit.fixwater", true); + attachment.setPermission("worldedit.removeabove", true); + attachment.setPermission("worldedit.removebelow", true); + attachment.setPermission("worldedit.removenear", true); + attachment.setPermission("worldedit.replacenear", true); + attachment.setPermission("worldedit.snow", true); + attachment.setPermission("worldedit.thaw", true); + attachment.setPermission("worldedit.green", true); + attachment.setPermission("worldedit.extinguish", true); + attachment.setPermission("worldedit.calc", true); + attachment.setPermission("worldedit.fill", true); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java new file mode 100644 index 0000000..a234745 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java @@ -0,0 +1,39 @@ +package de.steamwar.fightsystem.states; + +public enum FightState { + PRE_LEADER_SETUP(true, true, false, false), //Can be skipped + PRE_SCHEM_SETUP(true, true, false, false), //Can be skipped + POST_SCHEM_SETUP(true, true, false, false), + PRE_RUNNING(false, false, true, false), + RUNNING(false, false, true, true), + ENTERN(false, false, true, true), //Can be skipped + SPECTATE(false, true, false, false); + + private final boolean setup; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP + private final boolean outgame; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP, SPECTATE + private final boolean ingame; //PRE_RUNNING, RUNNING, ENTERN + private final boolean infight; //RUNNING, ENTERN + + FightState(boolean setup, boolean outgame, boolean ingame, boolean infight){ + this.setup = setup; + this.outgame = outgame; + this.ingame = ingame; + this.infight = infight; + } + + public boolean setup(){ + return setup; + } + + public boolean outgame(){ + return outgame; + } + + public boolean ingame(){ + return ingame; + } + + public boolean infight(){ + return infight; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java new file mode 100644 index 0000000..7b257f6 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java @@ -0,0 +1,26 @@ +package de.steamwar.fightsystem.states; + +import java.util.Set; + +public interface StateDependent { + + /** + * @return returns a set containing + */ + Set enabled(); + + /** + * Enables the state dependent object + */ + void enable(); + + /** + * Disables the state dependent object + */ + void disable(); + + /** + * On state change when enabled + */ + default void stateChange(FightState state){} +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index 5c5476e..e8434b9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -3,20 +3,23 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.winconditions.*; import org.bukkit.Bukkit; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; +import java.util.EnumSet; import java.util.Objects; +import java.util.Set; public class FightScoreboard { private FightScoreboard(){} + private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.ENTERN, FightState.SPECTATE); private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); private static final Objective objective; private static int index = 0; @@ -70,7 +73,7 @@ public class FightScoreboard { if (Config.Entern) objective.getScore("§7Entern: " + (FightSystem.isEntern() ? "§aja" : "§cnein")).setScore(2); - if(FightSystem.getFightState() == FightState.RUNNING){ + if(fullScoreboard.contains(FightSystem.getFightState())){ if (Config.PercentSystem){ objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%").setScore(1); objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%").setScore(0); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 404a18c..2743ead 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -213,6 +213,6 @@ public class TechHider { } private static boolean disabled(){ - return Config.OnlyPublicSchematics; + return Config.OnlyPublicSchematics || Config.test(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java index 416b4da..dd12e75 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java @@ -3,7 +3,7 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.entity.Player; abstract class PlayerWincondition extends ListenerWincondition { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 34395af..fae97c3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -2,7 +2,7 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.utils.Region; import org.bukkit.entity.Entity; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index 1c089d1..2731e59 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -3,7 +3,7 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightState; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.utils.WaterRemover; import org.bukkit.Bukkit;