From 0fc5730cf5aee8aafb77e8fe66afe3970405d0bb Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 9 Dec 2019 20:37:18 +0100 Subject: [PATCH] code cleanup; performance update --- .../src/de/steamwar/fightsystem/FightSystem.java | 3 +-- .../src/de/steamwar/fightsystem/fight/Fight.java | 12 ++++++++++++ .../src/de/steamwar/fightsystem/fight/FightTeam.java | 12 ++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index fcd90d7..1ffa994 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -107,8 +107,7 @@ public class FightSystem extends JavaPlugin { new PreRunningCountdown(); - Fight.getRedTeam().replaceSync(); - Fight.getBlueTeam().replaceSync(); + Fight.replaceSync(); new WinconditionAllDead(); new WinconditionCaptainDead(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 9fab60b..020f896 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -2,6 +2,7 @@ package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.Config; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -66,4 +67,15 @@ public class Fight { public static void setLevel(int level) { Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(level)); } + + public static void replaceSync() { + if(Config.ReplaceObsidian) { + Fight.getRedTeam().replaceSync(true, Material.OBSIDIAN, Material.TNT); + Fight.getBlueTeam().replaceSync(true, Material.OBSIDIAN, Material.TNT); + } + if(Config.ReplaceBedrock) { + Fight.getRedTeam().replaceSync(true, Material.BEDROCK, Material.SLIME_BLOCK); + Fight.getBlueTeam().replaceSync(true, Material.BEDROCK, Material.SLIME_BLOCK); + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 9d14e6b..a6a7e43 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -300,7 +300,10 @@ public class FightTeam implements IFightTeam{ } } - public void replaceSync() { + public void replaceSync(boolean replace, Material target, Material replacement) { + if(!replace) + return; + World world = Bukkit.getWorlds().get(0); Location minPoint = new Location(world, cornerX, cornerY, cornerZ); Location maxPoint = new Location(world, (cornerX + Config.SchemsizeX), (cornerY + Config.SchemsizeY), (cornerZ + Config.SchemsizeZ)); @@ -310,11 +313,8 @@ public class FightTeam implements IFightTeam{ for(int y = minPoint.getBlockY(); y <= maxPoint.getBlockY(); y++) { Block block = world.getBlockAt(x, y, z); - - if(Config.ReplaceObsidian && block.getType() == Material.OBSIDIAN) - block.setType(Material.TNT); - else if(Config.ReplaceBedrock && block.getType() == Material.BEDROCK) - block.setType(Material.SLIME_BLOCK); + if(block.getType() == target) + block.setType(replacement); } } }