From 9377db47e576a937434af0b493c0a2b99c3caa5a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 8 Jun 2019 12:57:08 +0200 Subject: [PATCH] Adding piston movement listener --- pom.xml | 10 ++-- src/me/yaruma/fightsystem/FightSystem.java | 4 +- .../listener/BlockBreakListener.java | 6 +-- .../fightsystem/listener/PistonListener.java | 49 +++++++++++++++++++ .../listener/PlayerInteractListener.java | 3 ++ src/me/yaruma/fightsystem/utils/Region.java | 2 + .../utils/countdown/FinishNoneEntern.java | 2 +- 7 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 src/me/yaruma/fightsystem/listener/PistonListener.java diff --git a/pom.xml b/pom.xml index 2dcc60b..c5babbe 100644 --- a/pom.xml +++ b/pom.xml @@ -19,10 +19,6 @@ maven https://steamwar.de:81/maven/ - - spigotmc-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - @@ -51,9 +47,9 @@ - org.spigotmc - spigot-api - 1.12.2-R0.1-SNAPSHOT + steamwar + Spigot + 1.0 provided diff --git a/src/me/yaruma/fightsystem/FightSystem.java b/src/me/yaruma/fightsystem/FightSystem.java index 0e016af..986a3db 100644 --- a/src/me/yaruma/fightsystem/FightSystem.java +++ b/src/me/yaruma/fightsystem/FightSystem.java @@ -57,6 +57,7 @@ public class FightSystem extends JavaPlugin { scoreboard = new Scoreboard(); waterRemover = new WaterRemover(); + entern = false; loadConfig(); @@ -78,6 +79,7 @@ public class FightSystem extends JavaPlugin { pm.registerEvents(new EntityExplodeListener(), plugin); pm.registerEvents(new PlayerTeleportListener(), plugin); pm.registerEvents(new ProjectileLaunchListener(), plugin); + pm.registerEvents(new PistonListener(), plugin); //WinConditions if(Config.AllDead) pm.registerEvents(new WinconditionAllDead(), plugin); @@ -227,7 +229,7 @@ public class FightSystem extends JavaPlugin { return fightTime; } - public boolean isEntern() { + public static boolean isEntern() { return entern; } diff --git a/src/me/yaruma/fightsystem/listener/BlockBreakListener.java b/src/me/yaruma/fightsystem/listener/BlockBreakListener.java index 41a9ee8..67f0b2f 100644 --- a/src/me/yaruma/fightsystem/listener/BlockBreakListener.java +++ b/src/me/yaruma/fightsystem/listener/BlockBreakListener.java @@ -10,17 +10,15 @@ import org.bukkit.event.block.BlockBreakEvent; public class BlockBreakListener implements Listener { - private final FightSystem instance = FightSystem.getPlugin(); - @EventHandler public void handleBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); if(Fight.getPlayerTeam(player) == null) event.setCancelled(true); - else if(FightSystem.getPlugin().getFightState() != FightState.RUNNING) { + else if(FightSystem.getFightState() != FightState.RUNNING) { event.setCancelled(true); - if(instance.getFightState() == FightState.SETUP || instance.getFightState() == FightState.PRE_RUNNING) { + if(FightSystem.getFightState() == FightState.SETUP || FightSystem.getFightState() == FightState.PRE_RUNNING) { player.sendMessage(FightSystem.PREFIX + "§cDu darfst erst nach Fightbeginn Blöcke abbauen!"); } else player.sendMessage(FightSystem.PREFIX + "§cDu darfst keine Blöcke mehr abbauen!"); diff --git a/src/me/yaruma/fightsystem/listener/PistonListener.java b/src/me/yaruma/fightsystem/listener/PistonListener.java new file mode 100644 index 0000000..ab3162a --- /dev/null +++ b/src/me/yaruma/fightsystem/listener/PistonListener.java @@ -0,0 +1,49 @@ +package me.yaruma.fightsystem.listener; + +import me.yaruma.fightsystem.FightSystem; +import me.yaruma.fightsystem.fight.FightState; +import me.yaruma.fightsystem.utils.Config; +import me.yaruma.fightsystem.utils.Region; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; + +public class PistonListener implements Listener { + + @EventHandler + public void handlePistonExtend(BlockPistonExtendEvent e){ + if(Config.Entern && FightSystem.getFightState() != FightState.SETUP) + return; + + BlockFace b = e.getDirection(); + for(Block block : e.getBlocks()){ + if( + !Region.isIn2DRange(block.getLocation(), Config.TeamBlueCornerX + b.getModX(), Config.TeamBlueCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) && + !Region.isIn2DRange(block.getLocation(), Config.TeamRedCornerX + b.getModX(), Config.TeamRedCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) + ){ + e.setCancelled(true); + return; + } + } + } + + @EventHandler + public void handlePistonRetract(BlockPistonRetractEvent e){ + if(Config.Entern && FightSystem.getFightState() != FightState.SETUP) + return; + + BlockFace b = e.getDirection(); + for(Block block : e.getBlocks()){ + if( + !Region.isIn2DRange(block.getLocation(), Config.TeamBlueCornerX + b.getModX(), Config.TeamBlueCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) && + !Region.isIn2DRange(block.getLocation(), Config.TeamRedCornerX + b.getModX(), Config.TeamRedCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) + ){ + e.setCancelled(true); + return; + } + } + } +} diff --git a/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java b/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java index 538ca39..3c4277c 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java @@ -27,6 +27,9 @@ public class PlayerInteractListener implements Listener { String displayName = itemMeta.getDisplayName(); event.setCancelled(true); + if(displayName == null) + return; + FightTeam fightTeam = Fight.getPlayerTeam(player); if(displayName.equals("§e" + Config.GameName + " wählen")){ GUI.preSchemDialog(player); diff --git a/src/me/yaruma/fightsystem/utils/Region.java b/src/me/yaruma/fightsystem/utils/Region.java index 0312fc9..dcf102a 100644 --- a/src/me/yaruma/fightsystem/utils/Region.java +++ b/src/me/yaruma/fightsystem/utils/Region.java @@ -4,6 +4,8 @@ import org.bukkit.Location; public class Region { + private Region(){} + public static boolean isInRange(Location location, int minX, int minY, int minZ, int xRange, int yRange, int zRange, int margin) { return isInRegion(location, minX, minY, minZ, minX + xRange, minY + yRange, minZ + zRange, margin); } diff --git a/src/me/yaruma/fightsystem/utils/countdown/FinishNoneEntern.java b/src/me/yaruma/fightsystem/utils/countdown/FinishNoneEntern.java index 6bf851a..9a4465f 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/FinishNoneEntern.java +++ b/src/me/yaruma/fightsystem/utils/countdown/FinishNoneEntern.java @@ -12,7 +12,7 @@ public class FinishNoneEntern implements CountdownCallback { @Override public void countdownFinished() { - FightSystem.getPlugin().setEntern(true); + FightSystem.setEntern(true); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aEntern ist nun erlaubt!"); }