diff --git a/src/me/yaruma/fightsystem/FightSystem.java b/src/me/yaruma/fightsystem/FightSystem.java index a8b4ff0..9cffb6d 100644 --- a/src/me/yaruma/fightsystem/FightSystem.java +++ b/src/me/yaruma/fightsystem/FightSystem.java @@ -66,8 +66,8 @@ public class FightSystem extends JavaPlugin { public int fightTime = 0; - public double damageRed = 0D; - public double getDamageBlue = 0D; + public double damageRed = 0.0D; + public double getDamageBlue = 0.0D; public boolean entern = false; @@ -198,6 +198,7 @@ public class FightSystem extends JavaPlugin { pm.registerEvents(new PlayerRespawnListener(), plugin); pm.registerEvents(new EntityDamageListener(), plugin); pm.registerEvents(new EntityExplodeListener(), plugin); + pm.registerEvents(new BlockFromToListener(), plugin); //WinConditions if(fileManager.getBooleanFromConfig("WinConditions.AllDead")) pm.registerEvents(new WinconditionAllDead(), plugin); @@ -293,7 +294,7 @@ public class FightSystem extends JavaPlugin { this.fightState = FightState.RUNNING; Countdown.cancelAllTimers(); - getWaterRemover().start(); + //getWaterRemover().start(); setAllPlayersGM(GameMode.SURVIVAL); @@ -332,16 +333,15 @@ public class FightSystem extends JavaPlugin { } } else { //Keine Message! Wird in FinishTimeOver gesendet! - for(FightPlayer fightPlayer : winFightTeam.getPlayers()) { + for(FightPlayer fightPlayer : Fight.getRedTeam().getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(getMoneyToPay("Money.Undecided")); } - for(FightPlayer fightPlayer : Fight.getOpposite(winFightTeam).getPlayers()) { + for(FightPlayer fightPlayer : Fight.getBlueTeam().getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(getMoneyToPay("Money.Undecided")); } } - Countdown.cancelAllTimers(); Countdown countdown = new Countdown(20*60, new FinishSpectateOver()); countdown.startTimer(FightSystem.getPlugin()); } diff --git a/src/me/yaruma/fightsystem/fight/WaterRemover.java b/src/me/yaruma/fightsystem/fight/WaterRemover.java index 2c91df3..c06dc16 100644 --- a/src/me/yaruma/fightsystem/fight/WaterRemover.java +++ b/src/me/yaruma/fightsystem/fight/WaterRemover.java @@ -15,6 +15,8 @@ import java.util.List; public class WaterRemover { + /* + private List> explodedBlocks = new ArrayList>(); private List waterList = new ArrayList(); private BukkitTask task; @@ -103,4 +105,6 @@ public class WaterRemover { this.collectBlocks(anchor.getRelative(BlockFace.WEST), collected, visitedBlocks); } + */ + } diff --git a/src/me/yaruma/fightsystem/listener/BlockFromToListener.java b/src/me/yaruma/fightsystem/listener/BlockFromToListener.java new file mode 100644 index 0000000..ee2cd21 --- /dev/null +++ b/src/me/yaruma/fightsystem/listener/BlockFromToListener.java @@ -0,0 +1,40 @@ +package me.yaruma.fightsystem.listener; + +import me.yaruma.fightsystem.FightSystem; +import me.yaruma.fightsystem.fight.FightState; +import me.yaruma.fightsystem.utils.WorldEdit; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFromToEvent; + +public class BlockFromToListener implements Listener { + + @EventHandler + public void handleBlockFromTo(BlockFromToEvent event) { + if(FightSystem.getPlugin().getFightState() != FightState.RUNNING) return; + + Block block = event.getBlock(); + + if(block.getType() != Material.WATER && block.getType() != Material.STATIONARY_WATER) return; + + Location location = event.getToBlock().getLocation(); + if(WorldEdit.countBlocksInRadius(location, + location.getBlockX() - 2, + location.getBlockY() - 2, + location.getBlockZ() - 2, + location.getBlockX() + 2, + location.getBlockY() + 2, + location.getBlockZ() + 2, + Material.WATER) + < 8) { + event.setCancelled(true); + block.setType(Material.AIR); + } + } + + +} diff --git a/src/me/yaruma/fightsystem/listener/EntityExplodeListener.java b/src/me/yaruma/fightsystem/listener/EntityExplodeListener.java index 0efc40d..72a1fda 100644 --- a/src/me/yaruma/fightsystem/listener/EntityExplodeListener.java +++ b/src/me/yaruma/fightsystem/listener/EntityExplodeListener.java @@ -12,8 +12,8 @@ public class EntityExplodeListener implements Listener { @EventHandler public void handleEntityExplode(EntityExplodeEvent event) { for(Block block : event.blockList()) { - if(block.getType() != Material.WATER || block.getType() != Material.STATIONARY_WATER) - FightSystem.getPlugin().getWaterRemover().add(block.getLocation()); + //if(block.getType() != Material.WATER || block.getType() != Material.STATIONARY_WATER) + //FightSystem.getPlugin().getWaterRemover().add(block.getLocation()); } } diff --git a/src/me/yaruma/fightsystem/utils/WorldEdit.java b/src/me/yaruma/fightsystem/utils/WorldEdit.java index 5332af9..5e9ce0e 100644 --- a/src/me/yaruma/fightsystem/utils/WorldEdit.java +++ b/src/me/yaruma/fightsystem/utils/WorldEdit.java @@ -16,6 +16,8 @@ import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.io.File; @@ -54,10 +56,10 @@ public class WorldEdit { } } - public static int countBlocks(Player player, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, BaseBlock baseBlock) { - World weWorld = new BukkitWorld(player.getWorld()); + public static int countBlocks(org.bukkit.World world, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, BaseBlock baseBlock) { + World weWorld = new BukkitWorld(world); EditSession editSession = new EditSessionBuilder(weWorld).fastmode(true).build(); - CuboidSelection cuboidSelection = new CuboidSelection(player.getWorld(), new Location(player.getWorld(), minX, minY, minZ), new Location(player.getWorld(), maxX, maxY, maxZ)); + CuboidSelection cuboidSelection = new CuboidSelection(world, new Location(world, minX, minY, minZ), new Location(world, maxX, maxY, maxZ)); Set target = new HashSet<>(); target.add(baseBlock); try { @@ -100,5 +102,18 @@ public class WorldEdit { } } + public static int countBlocksInRadius(Location location, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, Material except) { + int containing = 0; + for(int x = minX; x <= maxX; x++) { + for(int y = minY; y <= maxY; y++) { + for(int z = minZ; z <= maxZ; z++) { + Block block = location.getWorld().getBlockAt(x, y, z); + if(block.getType() != Material.AIR && block.getType() != except) containing++; + } + } + } + return containing; + } + } diff --git a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java index 23bfc61..bda6832 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java +++ b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java @@ -18,8 +18,6 @@ public class Countdown { this.time = time; this.countdownCallback = countdownCallback; countdowns.add(this); - - if(countdownCallback == new FinishTimeOver()) FightSystem.getPlugin().fightTime = time; } @@ -44,6 +42,7 @@ public class Countdown { break; } time--; + FightSystem.getPlugin().fightTime = time; } }, 0, 20); } diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionPercentSystem.java b/src/me/yaruma/fightsystem/winconditions/WinconditionPercentSystem.java index 9800511..744f62a 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionPercentSystem.java @@ -18,6 +18,8 @@ public class WinconditionPercentSystem implements Listener { FightSystem instance = FightSystem.getPlugin(); FileManager fileManager = instance.getFileManager(); + public static int percentWin = FightSystem.getPlugin().getFileManager().getIntegerFromConfig("WinConditionParams.PercentWin"); + private static int schematicSize = Math.abs( FightSystem.getPlugin().getFileManager().getIntegerFromConfig("Arena.Schemsize.x") * @@ -26,18 +28,15 @@ public class WinconditionPercentSystem implements Listener { @EventHandler public void handleEntityExplode(EntityExplodeEvent event) { - Bukkit.broadcastMessage("boom"); if(!Methods.isEnabled("WinConditions.PercentSystem")) return; - Bukkit.broadcastMessage("enabled"); Entity entity = event.getEntity(); //Team 1 / Rot if(Region.isInRegion(entity.getLocation(), instance.getTeam1cornerX(), instance.getTeam1cornerY(), instance.getTeam1cornerZ(), instance.getTeam1cornerX() + instance.getSchemsizeX(), instance.getTeam1cornerY() + instance.getSchemsizeY(), instance.getTeam1cornerZ() + instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"))) { team1DestroyedBlocks = team1DestroyedBlocks + event.blockList().size(); - Bukkit.broadcastMessage("red"); double destroyPercent = team1DestroyedBlocks * 100 / schematicSize; - Bukkit.broadcastMessage(" " + destroyPercent); - if(destroyPercent >= fileManager.getIntegerFromConfig("WinConditionParams.PercentWin")) { + instance.damageRed = destroyPercent; + if(destroyPercent >= percentWin) { instance.setSpectateState(Fight.blueTeam); } return; @@ -47,7 +46,7 @@ public class WinconditionPercentSystem implements Listener { if(Region.isInRegion(entity.getLocation(), instance.getTeam2cornerX(), instance.getTeam2cornerY(), instance.getTeam2cornerZ(), instance.getTeam2cornerX() + instance.getSchemsizeX(), instance.getTeam2cornerY() + instance.getSchemsizeY(), instance.getTeam2cornerZ() + instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"))) { team2DestroyedBlocks = team2DestroyedBlocks + event.blockList().size(); double destroyPercent = team2DestroyedBlocks * 100 / schematicSize; - if(destroyPercent >= fileManager.getIntegerFromConfig("WinConditionParams.PercentWin")) { + if(destroyPercent >= percentWin) { instance.setSpectateState(Fight.redTeam); } return;