From b3b7c7312316db38a4fdfef937903d716442b28e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 18 Nov 2019 18:49:51 +0100 Subject: [PATCH 1/6] Starting 1.14 support --- .../fightsystem/utils/ColorConverter_12.java | 11 +++++ FightSystem_14/pom.xml | 42 +++++++++++++++++++ .../fightsystem/utils/ColorConverter_14.java | 11 +++++ FightSystem_Main/pom.xml | 8 +++- .../de/steamwar/fightsystem/commands/GUI.java | 10 ++--- .../steamwar/fightsystem/fight/FightTeam.java | 16 ++++--- .../fightsystem/utils/ColorConverter.java | 11 ++++- .../fightsystem/utils/WaterRemover.java | 2 +- pom.xml | 1 + 9 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 FightSystem_12/src/de/steamwar/fightsystem/utils/ColorConverter_12.java create mode 100644 FightSystem_14/pom.xml create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/ColorConverter_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/ColorConverter_12.java new file mode 100644 index 0000000..d86d85d --- /dev/null +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/ColorConverter_12.java @@ -0,0 +1,11 @@ +package de.steamwar.fightsystem.utils; + +import org.bukkit.DyeColor; + +class ColorConverter_12 { + private ColorConverter_12(){} + + static DyeColor getSilver(){ + return DyeColor.SILVER; + } +} diff --git a/FightSystem_14/pom.xml b/FightSystem_14/pom.xml new file mode 100644 index 0000000..3019895 --- /dev/null +++ b/FightSystem_14/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + steamwar + FightSystem + 1.0 + + + FightSystem_14 + 1.0 + + + src + + + src + + **/*.java + **/*.kt + + + + + + + + steamwar + Spigot + 1.14 + provided + + + steamwar + FightSystem_API + 1.0 + + + \ No newline at end of file diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java new file mode 100644 index 0000000..95f6efd --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java @@ -0,0 +1,11 @@ +package de.steamwar.fightsystem.utils; + +import org.bukkit.DyeColor; + +class ColorConverter_14 { + private ColorConverter_14(){} + + static DyeColor getSilver(){ + return DyeColor.LIGHT_GRAY; + } +} diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index 1ad01a1..700526f 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -48,7 +48,7 @@ steamwar Spigot - 1.8 + 1.14 provided @@ -63,6 +63,12 @@ 1.0 compile + + steamwar + FightSystem_14 + 1.0 + compile + steamwar FightSystem_API diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index d57cfb2..6f39df1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -28,11 +28,11 @@ public class GUI { static void invitation(Player p, Player target){ SWInventory inv = new SWInventory(target, 9, "Einladung von " + p.getName()); - inv.setItem(0, Material.INK_SACK, (byte)10, "§aAnnehmen", (ClickType click) ->{ + inv.setItem(0, SWItem.getDye(10), (byte)10, "§aAnnehmen", (ClickType click) ->{ Commands.acceptInvitation(target); target.closeInventory(); }); - inv.setItem(8, Material.INK_SACK, (byte)1, "§cAblehnen", (ClickType click) ->{ + inv.setItem(8, SWItem.getDye(1), (byte)1, "§cAblehnen", (ClickType click) ->{ Commands.declineInvitation(target); target.closeInventory(); }); @@ -94,11 +94,11 @@ public class GUI { SWInventory inv = new SWInventory(p, 9, Config.GameName + "-Auswahl"); inv.setItem(8, Material.REDSTONE, "§eÖffentliches " + Config.GameName, (ClickType click) -> schemDialog(p, true)); if(Config.OnlyPublicSchematics){ - inv.setItem(0, Material.INK_SACK, (byte)8, "§7Keine privaten Schematics erlaubt", (ClickType click)->{}); + inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Keine privaten Schematics erlaubt", (ClickType click)->{}); }else if(Schematic.getSchemsOfType(p.getUniqueId(), Config.SchematicType).isEmpty() && !Config.test()){ - inv.setItem(0, Material.INK_SACK, (byte)8, "§7Kein privates " + Config.GameName + " vorhanden", (ClickType click)->{}); + inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Kein privates " + Config.GameName + " vorhanden", (ClickType click)->{}); }else{ - inv.setItem(0, Material.CAULDRON_ITEM, "§ePrivates " + Config.GameName, (ClickType click) -> schemDialog(p, false)); + inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), "§ePrivates " + Config.GameName, (ClickType click) -> schemDialog(p, false)); } inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index d6d7dff..e9feb35 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -7,7 +7,11 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.kit.KitManager; -import de.steamwar.fightsystem.utils.*; +import de.steamwar.fightsystem.utils.ColorConverter; +import de.steamwar.fightsystem.utils.FightScoreboard; +import de.steamwar.fightsystem.utils.ItemBuilder; +import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.inventory.SWItem; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import javafx.util.Pair; @@ -188,10 +192,10 @@ public class FightTeam implements IFightTeam{ inventory.setItem(1, new ItemBuilder(Material.AIR).build()); if(!Config.event()){ inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build()); - inventory.setItem(3, new ItemBuilder(Material.FIREWORK_CHARGE).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); - inventory.setItem(4, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); + inventory.setItem(3, new ItemBuilder(Material.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); + inventory.setItem(4, new ItemBuilder(Material.getMaterial("INK_SACK"), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); } - inventory.setItem(0, new ItemBuilder(Material.CAULDRON_ITEM).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); + inventory.setItem(0, new ItemBuilder(Material.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); } public Set getPlayers() { @@ -270,13 +274,13 @@ public class FightTeam implements IFightTeam{ this.ready = ready; if(ready) { - l.getInventory().setItem(4, new ItemBuilder(Material.INK_SACK, (short) 8).removeAllAttributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build()); + l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build()); broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!"); if(Fight.getOpposite(this).isReady() || Config.test()) { FightSystem.setPreRunningState(); } } else { - l.getInventory().setItem(4, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); + l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit!"); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java index 9118751..890e751 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java @@ -1,5 +1,6 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.core.Core; import org.bukkit.ChatColor; import org.bukkit.DyeColor; @@ -20,7 +21,6 @@ public class ColorConverter { chat2dye.put(ChatColor.GREEN, DyeColor.LIME); chat2dye.put(ChatColor.RED, DyeColor.RED); chat2dye.put(ChatColor.DARK_GRAY, DyeColor.GRAY); - chat2dye.put(ChatColor.GRAY, DyeColor.SILVER); chat2dye.put(ChatColor.DARK_AQUA, DyeColor.CYAN); chat2dye.put(ChatColor.DARK_PURPLE, DyeColor.PURPLE); chat2dye.put(ChatColor.DARK_BLUE, DyeColor.BLUE); @@ -28,8 +28,15 @@ public class ColorConverter { chat2dye.put(ChatColor.DARK_GREEN, DyeColor.GREEN); chat2dye.put(ChatColor.DARK_RED, DyeColor.RED); chat2dye.put(ChatColor.BLACK, DyeColor.BLACK); - //Rosa 9pink, Braun 3brown + + switch(Core.getVersion()){ + case 14: + chat2dye.put(ChatColor.GRAY, ColorConverter_14.getSilver()); + break; + default: + chat2dye.put(ChatColor.GRAY, ColorConverter_12.getSilver()); + } } public static DyeColor chat2dye(ChatColor color){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index f60b26d..02c09b9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -80,7 +80,7 @@ public class WaterRemover { if (anchor.getType() == Material.STATIONARY_WATER) collected.add(anchor); - if(visitedBlocks.size() > 50) { + if(visitedBlocks.size() > 100) { collected.clear(); return; } diff --git a/pom.xml b/pom.xml index 8d27342..0fb0790 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ FightSystem_API FightSystem_8 FightSystem_12 + FightSystem_14 FightSystem_Main -- 2.39.5 From 82add15c9c45087c137f22e080a6d645fc5ca799 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 21 Nov 2019 10:33:44 +0100 Subject: [PATCH 2/6] Maven refactoring --- .gitignore | 1 + FightSystem_Main/pom.xml | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index ee44a96..7eae63f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea target +dependency-reduced-pom.xml \ No newline at end of file diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index 700526f..41c7cb5 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -26,22 +26,20 @@ - maven-assembly-plugin + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 package - single + shade - - - jar-with-dependencies - - + FightSystem -- 2.39.5 From ab9e32a7ca59acf994cb7ce6bf39dec1121d35e3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 18 Nov 2019 18:49:51 +0100 Subject: [PATCH 3/6] Starting 1.14 support --- .../fightsystem/utils/ColorConverter_12.java | 11 +++++ FightSystem_14/pom.xml | 42 +++++++++++++++++++ .../fightsystem/utils/ColorConverter_14.java | 11 +++++ FightSystem_Main/pom.xml | 8 +++- .../de/steamwar/fightsystem/commands/GUI.java | 10 ++--- .../steamwar/fightsystem/fight/FightTeam.java | 16 ++++--- .../fightsystem/utils/ColorConverter.java | 11 ++++- .../fightsystem/utils/WaterRemover.java | 2 +- pom.xml | 1 + 9 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 FightSystem_12/src/de/steamwar/fightsystem/utils/ColorConverter_12.java create mode 100644 FightSystem_14/pom.xml create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/ColorConverter_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/ColorConverter_12.java new file mode 100644 index 0000000..d86d85d --- /dev/null +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/ColorConverter_12.java @@ -0,0 +1,11 @@ +package de.steamwar.fightsystem.utils; + +import org.bukkit.DyeColor; + +class ColorConverter_12 { + private ColorConverter_12(){} + + static DyeColor getSilver(){ + return DyeColor.SILVER; + } +} diff --git a/FightSystem_14/pom.xml b/FightSystem_14/pom.xml new file mode 100644 index 0000000..3019895 --- /dev/null +++ b/FightSystem_14/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + steamwar + FightSystem + 1.0 + + + FightSystem_14 + 1.0 + + + src + + + src + + **/*.java + **/*.kt + + + + + + + + steamwar + Spigot + 1.14 + provided + + + steamwar + FightSystem_API + 1.0 + + + \ No newline at end of file diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java new file mode 100644 index 0000000..95f6efd --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java @@ -0,0 +1,11 @@ +package de.steamwar.fightsystem.utils; + +import org.bukkit.DyeColor; + +class ColorConverter_14 { + private ColorConverter_14(){} + + static DyeColor getSilver(){ + return DyeColor.LIGHT_GRAY; + } +} diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index 1ad01a1..700526f 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -48,7 +48,7 @@ steamwar Spigot - 1.8 + 1.14 provided @@ -63,6 +63,12 @@ 1.0 compile + + steamwar + FightSystem_14 + 1.0 + compile + steamwar FightSystem_API diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index d57cfb2..6f39df1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -28,11 +28,11 @@ public class GUI { static void invitation(Player p, Player target){ SWInventory inv = new SWInventory(target, 9, "Einladung von " + p.getName()); - inv.setItem(0, Material.INK_SACK, (byte)10, "§aAnnehmen", (ClickType click) ->{ + inv.setItem(0, SWItem.getDye(10), (byte)10, "§aAnnehmen", (ClickType click) ->{ Commands.acceptInvitation(target); target.closeInventory(); }); - inv.setItem(8, Material.INK_SACK, (byte)1, "§cAblehnen", (ClickType click) ->{ + inv.setItem(8, SWItem.getDye(1), (byte)1, "§cAblehnen", (ClickType click) ->{ Commands.declineInvitation(target); target.closeInventory(); }); @@ -94,11 +94,11 @@ public class GUI { SWInventory inv = new SWInventory(p, 9, Config.GameName + "-Auswahl"); inv.setItem(8, Material.REDSTONE, "§eÖffentliches " + Config.GameName, (ClickType click) -> schemDialog(p, true)); if(Config.OnlyPublicSchematics){ - inv.setItem(0, Material.INK_SACK, (byte)8, "§7Keine privaten Schematics erlaubt", (ClickType click)->{}); + inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Keine privaten Schematics erlaubt", (ClickType click)->{}); }else if(Schematic.getSchemsOfType(p.getUniqueId(), Config.SchematicType).isEmpty() && !Config.test()){ - inv.setItem(0, Material.INK_SACK, (byte)8, "§7Kein privates " + Config.GameName + " vorhanden", (ClickType click)->{}); + inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Kein privates " + Config.GameName + " vorhanden", (ClickType click)->{}); }else{ - inv.setItem(0, Material.CAULDRON_ITEM, "§ePrivates " + Config.GameName, (ClickType click) -> schemDialog(p, false)); + inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), "§ePrivates " + Config.GameName, (ClickType click) -> schemDialog(p, false)); } inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index d6d7dff..e9feb35 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -7,7 +7,11 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.kit.KitManager; -import de.steamwar.fightsystem.utils.*; +import de.steamwar.fightsystem.utils.ColorConverter; +import de.steamwar.fightsystem.utils.FightScoreboard; +import de.steamwar.fightsystem.utils.ItemBuilder; +import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.inventory.SWItem; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import javafx.util.Pair; @@ -188,10 +192,10 @@ public class FightTeam implements IFightTeam{ inventory.setItem(1, new ItemBuilder(Material.AIR).build()); if(!Config.event()){ inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build()); - inventory.setItem(3, new ItemBuilder(Material.FIREWORK_CHARGE).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); - inventory.setItem(4, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); + inventory.setItem(3, new ItemBuilder(Material.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); + inventory.setItem(4, new ItemBuilder(Material.getMaterial("INK_SACK"), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); } - inventory.setItem(0, new ItemBuilder(Material.CAULDRON_ITEM).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); + inventory.setItem(0, new ItemBuilder(Material.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); } public Set getPlayers() { @@ -270,13 +274,13 @@ public class FightTeam implements IFightTeam{ this.ready = ready; if(ready) { - l.getInventory().setItem(4, new ItemBuilder(Material.INK_SACK, (short) 8).removeAllAttributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build()); + l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build()); broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!"); if(Fight.getOpposite(this).isReady() || Config.test()) { FightSystem.setPreRunningState(); } } else { - l.getInventory().setItem(4, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); + l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit!"); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java index 9118751..890e751 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java @@ -1,5 +1,6 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.core.Core; import org.bukkit.ChatColor; import org.bukkit.DyeColor; @@ -20,7 +21,6 @@ public class ColorConverter { chat2dye.put(ChatColor.GREEN, DyeColor.LIME); chat2dye.put(ChatColor.RED, DyeColor.RED); chat2dye.put(ChatColor.DARK_GRAY, DyeColor.GRAY); - chat2dye.put(ChatColor.GRAY, DyeColor.SILVER); chat2dye.put(ChatColor.DARK_AQUA, DyeColor.CYAN); chat2dye.put(ChatColor.DARK_PURPLE, DyeColor.PURPLE); chat2dye.put(ChatColor.DARK_BLUE, DyeColor.BLUE); @@ -28,8 +28,15 @@ public class ColorConverter { chat2dye.put(ChatColor.DARK_GREEN, DyeColor.GREEN); chat2dye.put(ChatColor.DARK_RED, DyeColor.RED); chat2dye.put(ChatColor.BLACK, DyeColor.BLACK); - //Rosa 9pink, Braun 3brown + + switch(Core.getVersion()){ + case 14: + chat2dye.put(ChatColor.GRAY, ColorConverter_14.getSilver()); + break; + default: + chat2dye.put(ChatColor.GRAY, ColorConverter_12.getSilver()); + } } public static DyeColor chat2dye(ChatColor color){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index f60b26d..02c09b9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -80,7 +80,7 @@ public class WaterRemover { if (anchor.getType() == Material.STATIONARY_WATER) collected.add(anchor); - if(visitedBlocks.size() > 50) { + if(visitedBlocks.size() > 100) { collected.clear(); return; } diff --git a/pom.xml b/pom.xml index 8d27342..0fb0790 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ FightSystem_API FightSystem_8 FightSystem_12 + FightSystem_14 FightSystem_Main -- 2.39.5 From 39e4ab421e6fdefdec1f1888be2fa9048b9072af Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 21 Nov 2019 10:33:44 +0100 Subject: [PATCH 4/6] Maven refactoring --- .gitignore | 1 + FightSystem_Main/pom.xml | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index ee44a96..7eae63f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea target +dependency-reduced-pom.xml \ No newline at end of file diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index 700526f..41c7cb5 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -26,22 +26,20 @@ - maven-assembly-plugin + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 package - single + shade - - - jar-with-dependencies - - + FightSystem -- 2.39.5 From 95e901115ade2c32f14510aa3f3294d4dc38bcc0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 23 Nov 2019 18:15:45 +0100 Subject: [PATCH 5/6] Full untested 1.14 without 1.14 Techhider --- FightSystem_12/pom.xml | 6 + .../fightsystem/fight/FightTeam_12.java | 14 +- .../fightsystem/utils/TechHider_12.java | 231 +++++++++++++++++ .../fightsystem/utils/WaterRemover_12.java | 11 + FightSystem_14/pom.xml | 6 + .../fightsystem/fight/FightTeam_14.java | 87 +++++++ .../fightsystem/utils/WaterRemover_14.java | 11 + FightSystem_8/pom.xml | 6 + .../fightsystem/fight/FightTeam_8.java | 16 +- .../src/de/steamwar/fightsystem/Config.java | 40 ++- .../fightsystem/utils/ITechHider.java | 26 +- FightSystem_Main/pom.xml | 6 + .../de/steamwar/fightsystem/fight/Fight.java | 4 +- .../steamwar/fightsystem/fight/FightTeam.java | 44 ++-- .../steamwar/fightsystem/utils/TechHider.java | 237 +----------------- .../fightsystem/utils/WaterRemover.java | 17 +- .../WinconditionWaterTechKO.java | 5 +- pom.xml | 6 - 18 files changed, 476 insertions(+), 297 deletions(-) create mode 100644 FightSystem_12/src/de/steamwar/fightsystem/utils/WaterRemover_12.java create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java diff --git a/FightSystem_12/pom.xml b/FightSystem_12/pom.xml index 09aae32..c4ab97a 100644 --- a/FightSystem_12/pom.xml +++ b/FightSystem_12/pom.xml @@ -43,6 +43,12 @@ 1.0 provided + + steamwar + WorldEdit + 1.0 + provided + steamwar Spigot diff --git a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java index bfd47f0..71cd313 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java @@ -8,6 +8,7 @@ import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.World; +import de.steamwar.fightsystem.Config; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.DyeColor; @@ -41,14 +42,17 @@ public class FightTeam_12 { @SuppressWarnings("deprecation") - static void replaceTeamColor(EditSession e, DyeColor c, CuboidRegion region){ - FightTeam_8.replaceTeamColor(e, c, region); + static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){ + FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); + Vector corner = new Vector(cornerX, cornerY, cornerZ); + CuboidRegion region = new CuboidRegion(corner, corner.add(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ)); e.replaceBlocks(region, CONCRETE_SET, new BaseBlock(CONCRETE.getId(), c.getWoolData())); e.replaceBlocks(region, CONCRETE_POWDER_SET, new BaseBlock(CONCRETE_POWDER.getId(), c.getWoolData())); } - static EditSession pasteSchematic(File file, Vector paste, boolean rotate, boolean alignWater, int waterDepth){ + static EditSession pasteSchematic(File file, int pasteX, int pasteY, int pasteZ, boolean rotate){ com.boydti.fawe.object.schematic.Schematic schem; + Vector paste = new Vector(pasteX, pasteY, pasteZ); try { schem = FaweAPI.load(file); if(schem.getClipboard() == null) @@ -70,14 +74,14 @@ public class FightTeam_12 { v = paste.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); } - if(alignWater){ + if(Config.AlignWater){ Vector it = schem.getClipboard().getMinimumPoint(); int depth = 0; while(!schem.getClipboard().getBlock(it).isAir()){ depth++; it = it.setY(it.getY()+1); } - v = v.add(0, waterDepth - depth, 0); + v = v.add(0, Config.WaterDepth - depth, 0); } return schem.paste(w, v, false, true, aT); diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java index ca07526..6beb2c5 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java @@ -1,15 +1,246 @@ package de.steamwar.fightsystem.utils; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.BlockPosition; +import com.comphenix.protocol.wrappers.ChunkCoordIntPair; +import com.comphenix.protocol.wrappers.MultiBlockChangeInfo; +import com.comphenix.protocol.wrappers.WrappedBlockData; +import com.comphenix.protocol.wrappers.nbt.NbtCompound; +import com.comphenix.protocol.wrappers.nbt.NbtFactory; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.IFightSystem; +import de.steamwar.inventory.SWItem; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; import javafx.util.Pair; import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk; +import org.bukkit.Material; import org.bukkit.craftbukkit.v1_12_R1.CraftChunk; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static de.steamwar.fightsystem.utils.ITechHider.bypass; + class TechHider_12 { private TechHider_12(){} + private static final short obfuscateShift4; + private static final Set hiddenBlocks; + + static{ + //noinspection deprecation + obfuscateShift4 = (short)(SWItem.getMaterial(Config.ObfuscateWith).getId() << 4); + + Set hBs = new HashSet<>(); + for(String mat : Config.HiddenBlocks){ + //noinspection deprecation + hBs.add(Material.getMaterial(mat).getId()); + } + hiddenBlocks = Collections.unmodifiableSet(hBs); + } + static void reloadChunk(Player p, Pair chunk){ ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535)); } + + static void start(){ + chunkHider(); + multiBlockHider(); + blockHider(); + blockActionHider(); + } + + private static void chunkHider(){ + ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + StructureModifier ints = packet.getIntegers(); + + int chunkX = ints.read(0); + int chunkZ = ints.read(1); + Player p = e.getPlayer(); + if(bypass(p, chunkX, chunkZ)) + return; + + PacketContainer cached = ITechHider.packetCache.get(packet); + if(cached != null){ + e.setPacket(cached); + return; + } + + cached = packet.deepClone(); + ITechHider.packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier list = cached.getSpecificModifier(List.class); + List nmsTags = list.read(0); + boolean changed = false; + for(int i = nmsTags.size() - 1; i >= 0; i--){ + NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTags.get(i)); + if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ + nmsTags.remove(i); + changed = true; + } + } + if(changed){ + list.write(0, nmsTags); + } + + changed = false; + StructureModifier byteArray = cached.getByteArrays(); + byte [] data = byteArray.read(0); + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); + int i = 0; + + while(i < data.length){ + byte bitsPerBlock = data[i++]; + buffer.writeByte(bitsPerBlock); + if(bitsPerBlock < 4) + bitsPerBlock = 4; + else if(bitsPerBlock > 8){ + bitsPerBlock = 13; + buffer.writeByte(data[++i]); + } + + if(bitsPerBlock != 13){ + int paletteLength = ITechHider.readVarInt(data, i); + int paletteLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, paletteLengthLength); + i += paletteLengthLength; + for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ + int actPalette = ITechHider.readVarInt(data, i); + int actPaletteLength = ITechHider.readVarIntLength(data, i); + + int blockId = actPalette >> 4; + if(hiddenBlocks.contains(blockId)){ + byte[] a = ITechHider.writeVarInt(obfuscateShift4); + buffer.writeBytes(a); + changed = true; + }else{ + buffer.writeBytes(data, i, actPaletteLength); + } + i += actPaletteLength; + } + int dataArrayLength = ITechHider.readVarInt(data, i); + int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); + i += dataArrayLengthLength; + i += dataArrayLength * 8; + }else{ + int dataArrayLength = ITechHider.readVarInt(data, i); + int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); + i += dataArrayLengthLength; + i += dataArrayLength * 8; + } + + buffer.writeBytes(data, i, 4096); + i += 4096; //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048 + } + + if(changed){ + data = new byte[buffer.readableBytes()]; + buffer.readBytes(data); + byteArray.write(0, data); + } + } + }).start(ITechHider.threadMultiplier * 4); + } + + private static void multiBlockHider(){ + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + + Player p = e.getPlayer(); + ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0); + if(bypass(p, pos.getChunkX(), pos.getChunkZ())) + return; + + PacketContainer cached = ITechHider.packetCache.get(packet); + if(cached != null){ + e.setPacket(cached); + return; + } + + cached = packet.shallowClone(); + ITechHider.packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier blockStructure = cached.getMultiBlockChangeInfoArrays(); + MultiBlockChangeInfo[] changes = blockStructure.read(0).clone(); + boolean changed = false; + for(MultiBlockChangeInfo mbci : changes){ + WrappedBlockData block = mbci.getData(); + //noinspection deprecation + if(hiddenBlocks.contains(block.getType().getId())){ + changed = true; + block.setType(ITechHider.obfuscateMaterial); + mbci.setData(block); + } + } + + if(changed){ + blockStructure.write(0, changes); + } + } + }); + } + + private static void blockHider(){ + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + BlockPosition pos = packet.getBlockPositionModifier().read(0); + + Player p = e.getPlayer(); + if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + return; + + PacketContainer cached = ITechHider.packetCache.get(packet); + if(cached != null){ + e.setPacket(cached); + return; + } + + cached = packet.deepClone(); + ITechHider.packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier blockStructure = cached.getBlockData(); + WrappedBlockData block = blockStructure.read(0); + //noinspection deprecation + if(hiddenBlocks.contains(block.getType().getId())){ + block.setType(ITechHider.obfuscateMaterial); + blockStructure.write(0, block); + } + } + }); + } + + private static void blockActionHider(){ + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + BlockPosition pos = packet.getBlockPositionModifier().read(0); + + Player p = e.getPlayer(); + if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + return; + + e.setCancelled(true); + } + }); + } } diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/WaterRemover_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/WaterRemover_12.java new file mode 100644 index 0000000..06bbd21 --- /dev/null +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/WaterRemover_12.java @@ -0,0 +1,11 @@ +package de.steamwar.fightsystem.utils; + +import org.bukkit.Material; + +class WaterRemover_12 { + private WaterRemover_12(){} + + static boolean isWater(Material type){ + return type == Material.WATER || type == Material.STATIONARY_WATER; + } +} diff --git a/FightSystem_14/pom.xml b/FightSystem_14/pom.xml index 3019895..f6d65f0 100644 --- a/FightSystem_14/pom.xml +++ b/FightSystem_14/pom.xml @@ -38,5 +38,11 @@ FightSystem_API 1.0 + + steamwar + FAWE + 1.14 + provided + \ No newline at end of file diff --git a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java new file mode 100644 index 0000000..0d06b54 --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java @@ -0,0 +1,87 @@ +package de.steamwar.fightsystem.fight; + +import com.boydti.fawe.FaweAPI; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import de.steamwar.fightsystem.Config; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; +import org.bukkit.scoreboard.Team; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.Set; +import java.util.logging.Level; + +class FightTeam_14 { + private FightTeam_14(){} + + private static final Set WOOL_SET = Collections.singleton(new BaseBlock(BlockState.get("PINK_WOOL"))); + private static final Set CLAY_SET = Collections.singleton(new BaseBlock(BlockState.get("PINK_TERRACOTTA"))); + private static final Set GLASS_SET = Collections.singleton(new BaseBlock(BlockState.get("PINK_STAINED_GLASS"))); + private static final Set GLASS_PANE_SET = Collections.singleton(new BaseBlock(BlockState.get("PINK_STAINED_GLASS_PANE"))); + private static final Set CONCRETE_SET = Collections.singleton(new BaseBlock(BlockState.get("PINK_CONCRETE"))); + private static final Set CONCRETE_POWDER_SET = Collections.singleton(new BaseBlock(BlockState.get("PINK_CONCRETE_POWDER"))); + + static void setTeamColor(Team team, ChatColor color){ + team.setColor(color); + team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); + } + + static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){ + BlockVector3 corner3 = BlockVector3.at(cornerX, cornerY, cornerZ); + BlockVector3 schemsize3 = BlockVector3.at(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ); + CuboidRegion region = new CuboidRegion(corner3, corner3.add(schemsize3)); + e.replaceBlocks(region, WOOL_SET, new BaseBlock(BlockState.get(c.name() + "_WOOL"))); + e.replaceBlocks(region, CLAY_SET, new BaseBlock(BlockState.get(c.name() + "_TERRACOTTA"))); + e.replaceBlocks(region, GLASS_SET, new BaseBlock(BlockState.get(c.name() + "_STAINED_GLASS"))); + e.replaceBlocks(region, GLASS_PANE_SET, new BaseBlock(BlockState.get(c.name() + "_STAINED_GLASS_PANE"))); + e.replaceBlocks(region, CONCRETE_SET, new BaseBlock(BlockState.get(c.name() + "_CONCRETE"))); + e.replaceBlocks(region, CONCRETE_POWDER_SET, new BaseBlock(BlockState.get(c.name() + "_CONCRETE_POWDER"))); + } + + static EditSession pasteSchematic(File file, int pX, int pY, int pZ, boolean rotate){ + BlockVector3 paste = BlockVector3.at(pX, pY, pZ); + com.boydti.fawe.object.schematic.Schematic schem; + try { + schem = FaweAPI.load(file); + if(schem.getClipboard() == null) + throw new IOException(); + }catch(IOException e){ + Bukkit.getLogger().log(Level.SEVERE, "Failed loading Schematic", e); + return null; + } + + World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + BlockVector3 dimensions = schem.getClipboard().getDimensions(); + BlockVector3 v; + BlockVector3 offset = schem.getClipboard().getRegion().getMinimumPoint().subtract(schem.getClipboard().getOrigin()); + AffineTransform aT = new AffineTransform(); + if(rotate){ + aT = aT.rotateY(180); + v = paste.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); + }else{ + v = paste.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); + } + + if(Config.AlignWater){ + BlockVector3 it = schem.getClipboard().getMinimumPoint(); + int depth = 0; + while(!schem.getClipboard().getBlock(it).getMaterial().isAir()){ + depth++; + it = it.add(0, 1, 0); + } + v = v.add(0, Config.WaterDepth - depth, 0); + } + + return schem.paste(w, v, false, true, aT); + } +} diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java new file mode 100644 index 0000000..2e173bf --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java @@ -0,0 +1,11 @@ +package de.steamwar.fightsystem.utils; + +import org.bukkit.Material; + +class WaterRemover_14 { + private WaterRemover_14(){} + + static boolean isWater(Material type){ + return type == Material.WATER; + } +} diff --git a/FightSystem_8/pom.xml b/FightSystem_8/pom.xml index 0354cb3..7e0b234 100644 --- a/FightSystem_8/pom.xml +++ b/FightSystem_8/pom.xml @@ -38,5 +38,11 @@ FightSystem_API 1.0 + + steamwar + WorldEdit + 1.0 + provided + \ No newline at end of file diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java index ef10ebe..cce899a 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java @@ -7,6 +7,8 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.schematic.SchematicFormat; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.IFightSystem; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.DyeColor; @@ -15,7 +17,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.plugin.Plugin; import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; @@ -51,7 +52,9 @@ class FightTeam_8 { } @SuppressWarnings("deprecation") - static void replaceTeamColor(EditSession e, DyeColor c, CuboidRegion region){ + static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){ + Vector corner = new Vector(cornerX, cornerY, cornerZ); + CuboidRegion region = new CuboidRegion(corner, corner.add(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ)); try { e.replaceBlocks(region, WOOL_SET, new BaseBlock(WOOL.getId(), c.getWoolData())); e.replaceBlocks(region, CLAY_SET, new BaseBlock(CLAY.getId(), c.getWoolData())); @@ -62,7 +65,8 @@ class FightTeam_8 { } } - static EditSession pasteSchematic(File file, Vector paste, boolean rotate, boolean alignWater, int waterDepth, Plugin plugin){ + static EditSession pasteSchematic(File file, int pasteX, int pasteY, int pasteZ, boolean rotate){ + Vector paste = new Vector(pasteX, pasteY, pasteZ); CuboidClipboard clipboard; try { @@ -83,19 +87,19 @@ class FightTeam_8 { v = paste.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); } - if(alignWater){ + if(Config.AlignWater){ Vector it = Vector.ZERO; int depth = 0; while(!clipboard.getBlock(it).isAir()){ depth++; it = it.setY(it.getY()+1); } - v = v.add(0, waterDepth - depth, 0); + v = v.add(0, Config.WaterDepth - depth, 0); } EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); FreezeWorld freezer = new FreezeWorld(); - Bukkit.getPluginManager().registerEvents(freezer, plugin); + Bukkit.getPluginManager().registerEvents(freezer, IFightSystem.getPlugin()); try { clipboard.paste(e, v, false, true); } catch (MaxChangedBlocksException ex) { diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 55b4e2e..23cff16 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -1,6 +1,5 @@ package de.steamwar.fightsystem; -import com.sk89q.worldedit.Vector; import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; @@ -30,19 +29,18 @@ public class Config { public static final int SchemsizeX; public static final int SchemsizeY; public static final int SchemsizeZ; - public static final Vector Schemsize; public static final int TeamBlueCornerX; public static final int TeamBlueCornerY; public static final int TeamBlueCornerZ; - public static final Vector TeamBlueCorner; + private static final int TeamBluePasteX; + private static final int TeamBluePasteZ; public static final Location TeamBlueSpawn; - public static final Vector TeamBluePaste; public static final int TeamRedCornerX; public static final int TeamRedCornerY; public static final int TeamRedCornerZ; - public static final Vector TeamRedCorner; + private static final int TeamRedPasteX; + private static final int TeamRedPasteZ; public static final Location TeamRedSpawn; - public static final Vector TeamRedPaste; private static final int TeamBluetoReddistanceX; private static final int TeamBluetoReddistanceY; public static final int TeamBluetoReddistanceZ; @@ -95,9 +93,9 @@ public class Config { public static final String LeaderDefault; //tech hider parameter - public static final List HiddenBlocks; + public static final List HiddenBlocks; public static final List HiddenBlockEntities; - public static final int ObfuscateWith; + public static final String ObfuscateWith; //event parameter private static final int EventKampfID; @@ -165,9 +163,9 @@ public class Config { MemberDefault = config.getString("Kits.MemberDefault"); LeaderDefault = config.getString("Kits.LeaderDefault"); - HiddenBlocks = Collections.unmodifiableList(config.getIntegerList("Techhider.HiddenBlocks")); + HiddenBlocks = Collections.unmodifiableList(config.getStringList("Techhider.HiddenBlocks")); HiddenBlockEntities = Collections.unmodifiableList(config.getStringList("Techhider.HiddenBlockEntities")); - ObfuscateWith = config.getInt("Techhider.ObfuscateWith"); + ObfuscateWith = config.getString("Techhider.ObfuscateWith"); if(schemsizeX < 0){ SchemsizeX = -schemsizeX; @@ -197,24 +195,18 @@ public class Config { TeamRedCornerY = TeamBluetoReddistanceY + TeamBlueCornerY; TeamRedCornerZ = TeamBluetoReddistanceZ + TeamBlueCornerZ; - int teamBluePasteX = TeamBlueCornerX + SchemsizeX / 2; - int teamBluePasteZ = TeamBlueCornerZ + SchemsizeZ / 2; - int teamRedPasteX = teamBluePasteX + TeamBluetoReddistanceX; - int teamRedPasteZ = teamBluePasteZ + TeamBluetoReddistanceZ; - - TeamBluePaste = new Vector(teamBluePasteX, TeamBlueCornerY, teamBluePasteZ); - TeamRedPaste = new Vector(teamRedPasteX, TeamRedCornerY, teamRedPasteZ); - Schemsize = new Vector(SchemsizeX, SchemsizeY, SchemsizeZ); - TeamBlueCorner = new Vector(TeamBlueCornerX, TeamBlueCornerY, TeamBlueCornerZ); - TeamRedCorner = new Vector(TeamRedCornerX, TeamRedCornerY, TeamRedCornerZ); + TeamBluePasteX = TeamBlueCornerX + SchemsizeX / 2; + TeamBluePasteZ = TeamBlueCornerZ + SchemsizeZ / 2; + TeamRedPasteX = TeamBluePasteX + TeamBluetoReddistanceX; + TeamRedPasteZ = TeamBluePasteZ + TeamBluetoReddistanceZ; World world = Bukkit.getWorlds().get(0); - TeamBlueSpawn = new Location(world, teamBluePasteX + 0.5, TeamBlueCornerY + (double)SchemsizeY, teamBluePasteZ + 0.5); - TeamRedSpawn = new Location(world, teamRedPasteX + 0.5, TeamRedCornerY + (double)SchemsizeY, teamRedPasteZ + 0.5); + TeamBlueSpawn = new Location(world, TeamBluePasteX + 0.5, TeamBlueCornerY + (double)SchemsizeY, TeamBluePasteZ + 0.5); + TeamRedSpawn = new Location(world, TeamRedPasteX + 0.5, TeamRedCornerY + (double)SchemsizeY, TeamRedPasteZ + 0.5); SpecSpawn = new Location(world, - teamBluePasteX + TeamBluetoReddistanceX/2.0, + TeamBluePasteX + TeamBluetoReddistanceX/2.0, TeamBlueCornerY + TeamBluetoReddistanceY/2.0 + SchemsizeY/2.0, - teamBluePasteZ + TeamBluetoReddistanceZ/2.0); + TeamBluePasteZ + TeamBluetoReddistanceZ/2.0); boolean teamRedRotate; boolean teamBlueRotate; diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java index cea8016..5d2a58d 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -1,18 +1,32 @@ package de.steamwar.fightsystem.utils; +import com.comphenix.protocol.events.PacketContainer; import com.google.common.primitives.Bytes; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.fight.IFight; import de.steamwar.fightsystem.fight.IFightTeam; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class ITechHider { private ITechHider (){} + static final Map packetCache = new HashMap<>(); + static final Material obfuscateMaterial; + static final int threadMultiplier; + static final int arenaMinX; + static final int arenaMaxX; + static final int arenaMinZ; + static final int arenaMaxZ; + private static final int blueMinX; private static final int blueMaxX; private static final int blueMinZ; @@ -21,10 +35,6 @@ public class ITechHider { private static final int redMaxX; private static final int redMinZ; private static final int redMaxZ; - private static int arenaMinX; - private static int arenaMaxX; - private static int arenaMinZ; - private static int arenaMaxZ; static{ blueMinX = ITechHider.posToChunk(Config.TeamBlueCornerX); @@ -39,6 +49,14 @@ public class ITechHider { arenaMaxX = ITechHider.posToChunk(Config.ArenaMaxX) + 1; arenaMinZ = ITechHider.posToChunk(Config.ArenaMinZ); arenaMaxZ = ITechHider.posToChunk(Config.ArenaMaxZ) + 1; + + obfuscateMaterial = SWItem.getMaterial(Config.ObfuscateWith); + Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1); + + if(Config.event()) + threadMultiplier = 4; + else + threadMultiplier = 1; } static boolean bypass(Player p, int chunkX, int chunkZ){ diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index 41c7cb5..fd1557d 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -73,5 +73,11 @@ 1.0 compile + + steamwar + WorldEdit + 1.0 + provided + \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index e1fbc94..9fab60b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -8,8 +8,8 @@ import org.bukkit.entity.Player; public class Fight { private Fight(){} - public static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedPrefix, Config.TeamRedSpawn, Config.TeamRedPaste, Config.TeamRedCorner, Config.TeamRedRotate, false, Config.RedLeader); - public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBluePaste, Config.TeamBlueCorner, Config.TeamBlueRotate, true, Config.BlueLeader); + public static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedPrefix, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader); + public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader); public static void init(){ IFight.init(redTeam, blueTeam); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index e9feb35..be15e27 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -1,8 +1,6 @@ package de.steamwar.fightsystem.fight; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.regions.CuboidRegion; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -43,18 +41,26 @@ public class FightTeam implements IFightTeam{ private final boolean blue; private final Location spawn; - private final Vector paste; - private final Vector corner; + private final int pasteX; + private final int pasteY; + private final int pasteZ; + private final int cornerX; + private final int cornerY; + private final int cornerZ; private final boolean rotate; - public FightTeam(String name, String prefix, Location spawn, Vector paste, Vector corner, boolean rotate, boolean blue, UUID designatedLeader) { + public FightTeam(String name, String prefix, Location spawn, int cornerX, int cornerY, int cornerZ, boolean rotate, boolean blue, UUID designatedLeader) { this.spawn = spawn; - this.paste = paste; + this.pasteX = cornerX + Config.SchemsizeX/2; + this.pasteY = cornerY; + this.pasteZ = cornerZ + Config.SchemsizeZ/2; this.name = name; this.prefix = prefix; this.ready = false; this.rotate = rotate; - this.corner = corner; + this.cornerX = cornerX; + this.cornerY = cornerY; + this.cornerZ = cornerZ; this.blue = blue; this.designatedLeader = designatedLeader; color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); @@ -71,6 +77,9 @@ public class FightTeam implements IFightTeam{ case 8: FightTeam_8.setTeamColor(team, color); break; + case 14: + FightTeam_14.setTeamColor(team, color); + break; default: FightTeam_12.setTeamColor(team, color); } @@ -192,10 +201,10 @@ public class FightTeam implements IFightTeam{ inventory.setItem(1, new ItemBuilder(Material.AIR).build()); if(!Config.event()){ inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build()); - inventory.setItem(3, new ItemBuilder(Material.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); - inventory.setItem(4, new ItemBuilder(Material.getMaterial("INK_SACK"), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); + inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); + inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); } - inventory.setItem(0, new ItemBuilder(Material.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); + inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); } public Set getPlayers() { @@ -211,25 +220,30 @@ public class FightTeam implements IFightTeam{ EditSession e; switch(Core.getVersion()){ case 8: - e = FightTeam_8.pasteSchematic(file, paste, rotate, Config.AlignWater, Config.WaterDepth, FightSystem.getPlugin()); + e = FightTeam_8.pasteSchematic(file, pasteX, pasteY, pasteZ, rotate); + break; + case 14: + e = FightTeam_14.pasteSchematic(file, pasteX, pasteY, pasteZ, rotate); break; default: - e = FightTeam_12.pasteSchematic(file, paste, rotate, Config.AlignWater, Config.WaterDepth); + e = FightTeam_12.pasteSchematic(file, pasteX, pasteY, pasteZ, rotate); } replaceTeamColor(e); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40); } private void replaceTeamColor(EditSession e){ - CuboidRegion region = new CuboidRegion(corner, corner.add(Config.Schemsize)); DyeColor c = ColorConverter.chat2dye(color); switch(Core.getVersion()){ case 8: - FightTeam_8.replaceTeamColor(e, c, region); + FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); + break; + case 14: + FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); break; default: - FightTeam_12.replaceTeamColor(e, c, region); + FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); } e.flushQueue(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 604174b..50cf397 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -3,69 +3,38 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.reflect.StructureModifier; -import com.comphenix.protocol.wrappers.BlockPosition; -import com.comphenix.protocol.wrappers.ChunkCoordIntPair; -import com.comphenix.protocol.wrappers.MultiBlockChangeInfo; -import com.comphenix.protocol.wrappers.WrappedBlockData; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import com.comphenix.protocol.wrappers.nbt.NbtFactory; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; import javafx.util.Pair; import org.bukkit.Bukkit; import org.bukkit.GameMode; -import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import static de.steamwar.fightsystem.utils.ITechHider.bypass; public class TechHider { private TechHider(){} - private static Map packetCache = new HashMap<>(); - - private static int arenaMinX; - private static int arenaMaxX; - private static int arenaMinZ; - private static int arenaMaxZ; - private static short obfuscateShift4; - private static Material obfuscateMaterial; private static boolean running = false; - private static int threadMultiplier = 1; public static void init(){ if(disabled()) return; - arenaMinX = ITechHider.posToChunk(Config.ArenaMinX); - arenaMinZ = ITechHider.posToChunk(Config.ArenaMinZ); - arenaMaxX = ITechHider.posToChunk(Config.ArenaMaxX) + 1; - arenaMaxZ = ITechHider.posToChunk(Config.ArenaMaxZ) + 1; - - obfuscateShift4 = (short)(Config.ObfuscateWith << 4); - //noinspection deprecation - obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith); - - if(Config.event()) - threadMultiplier = 4; - if(Core.getVersion() > 8){ ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ITEM) { @Override public void onPacketReceiving(PacketEvent e) { Player p = e.getPlayer(); - if(p.getGameMode() == GameMode.SPECTATOR){ + if(p.getGameMode() == GameMode.SPECTATOR) e.setCancelled(true); - } } }); } @@ -74,9 +43,8 @@ public class TechHider { public void onPacketReceiving(PacketEvent e) { Player p = e.getPlayer(); - if(p.getGameMode() == GameMode.SPECTATOR){ + if(p.getGameMode() == GameMode.SPECTATOR) e.setCancelled(true); - } } }); } @@ -89,209 +57,20 @@ public class TechHider { if(disabled()) return; - Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), packetCache::clear, 1, 1); - switch(Core.getVersion()){ case 8: break; default: - chunkHider(); - multiBlockHider(); - blockHider(); - blockActionHider(); + TechHider_12.start(); } } - private static void chunkHider(){ - ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - StructureModifier ints = packet.getIntegers(); - - int chunkX = ints.read(0); - int chunkZ = ints.read(1); - Player p = e.getPlayer(); - if(bypass(p, chunkX, chunkZ)) - return; - - PacketContainer cached = packetCache.get(packet); - if(cached != null){ - e.setPacket(cached); - return; - } - - cached = packet.deepClone(); - packetCache.put(packet, cached); - e.setPacket(cached); - StructureModifier list = cached.getSpecificModifier(List.class); - List nmsTags = list.read(0); - boolean changed = false; - for(int i = nmsTags.size() - 1; i >= 0; i--){ - NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTags.get(i)); - if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ - nmsTags.remove(i); - changed = true; - } - } - if(changed){ - list.write(0, nmsTags); - } - - changed = false; - StructureModifier byteArray = cached.getByteArrays(); - byte [] data = byteArray.read(0); - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); - int i = 0; - - while(i < data.length){ - byte bitsPerBlock = data[i++]; - buffer.writeByte(bitsPerBlock); - if(bitsPerBlock < 4) - bitsPerBlock = 4; - else if(bitsPerBlock > 8){ - bitsPerBlock = 13; - buffer.writeByte(data[++i]); - } - - if(bitsPerBlock != 13){ - int paletteLength = ITechHider.readVarInt(data, i); - int paletteLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, paletteLengthLength); - i += paletteLengthLength; - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int actPalette = ITechHider.readVarInt(data, i); - int actPaletteLength = ITechHider.readVarIntLength(data, i); - - int blockId = actPalette >> 4; - if(Config.HiddenBlocks.contains(blockId)){ - byte[] a = ITechHider.writeVarInt(obfuscateShift4); - buffer.writeBytes(a); - changed = true; - }else{ - buffer.writeBytes(data, i, actPaletteLength); - } - i += actPaletteLength; - } - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); - i += dataArrayLengthLength; - i += dataArrayLength * 8; - }else{ - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); - i += dataArrayLengthLength; - i += dataArrayLength * 8; - } - - buffer.writeBytes(data, i, 4096); - i += 4096; //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048 - } - - if(changed){ - data = new byte[buffer.readableBytes()]; - buffer.readBytes(data); - byteArray.write(0, data); - } - } - }).start(threadMultiplier * 4); - } - - private static void multiBlockHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - - Player p = e.getPlayer(); - ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0); - if(bypass(p, pos.getChunkX(), pos.getChunkZ())) - return; - - PacketContainer cached = packetCache.get(packet); - if(cached != null){ - e.setPacket(cached); - return; - } - - cached = packet.shallowClone(); - packetCache.put(packet, cached); - e.setPacket(cached); - StructureModifier blockStructure = cached.getMultiBlockChangeInfoArrays(); - MultiBlockChangeInfo[] changes = blockStructure.read(0).clone(); - boolean changed = false; - for(MultiBlockChangeInfo mbci : changes){ - WrappedBlockData block = mbci.getData(); - //noinspection deprecation - if(Config.HiddenBlocks.contains(block.getType().getId())){ - changed = true; - block.setType(obfuscateMaterial); - mbci.setData(block); - } - } - - if(changed){ - blockStructure.write(0, changes); - } - } - }); - } - - private static void blockHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - BlockPosition pos = packet.getBlockPositionModifier().read(0); - - Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) - return; - - PacketContainer cached = packetCache.get(packet); - if(cached != null){ - e.setPacket(cached); - return; - } - - cached = packet.deepClone(); - packetCache.put(packet, cached); - e.setPacket(cached); - StructureModifier blockStructure = cached.getBlockData(); - WrappedBlockData block = blockStructure.read(0); - //noinspection deprecation - if(Config.HiddenBlocks.contains(block.getType().getId())){ - block.setType(obfuscateMaterial); - blockStructure.write(0, block); - } - } - }); - } - - private static void blockActionHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - BlockPosition pos = packet.getBlockPositionModifier().read(0); - - Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) - return; - - e.setCancelled(true); - } - }); - } - public static List> prepareChunkReload(Player p){ if(disabled()) return Collections.emptyList(); List> chunksToReload = new ArrayList<>(); - for(int x = arenaMinX; x <= arenaMaxX; x++) - for(int z = arenaMinZ; z <= arenaMaxZ; z++) + for(int x = ITechHider.arenaMinX; x <= ITechHider.arenaMaxX; x++) + for(int z = ITechHider.arenaMinZ; z <= ITechHider.arenaMaxZ; z++) if(!bypass(p, x, z)) chunksToReload.add(new Pair<>(x, z)); return chunksToReload; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index 02c09b9..6f20077 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -1,5 +1,6 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.core.Core; import de.steamwar.fightsystem.FightSystem; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -35,7 +36,7 @@ public class WaterRemover { while (it.hasNext()) { Map.Entry e = it.next(); Block b = e.getKey().getBlock(); - if (b.getType() == Material.STATIONARY_WATER || b.getType() == Material.WATER) + if (isWater(b.getType())) waterList.add(b); if(b.getType() != Material.AIR){ @@ -56,7 +57,7 @@ public class WaterRemover { while(it.hasNext()){ Block b = it.next(); blocksToRemove.addAll(getSourceBlocksOfWater(b)); - if (b.getType() != Material.STATIONARY_WATER && b.getType() != Material.WATER) + if (!isWater(b.getType())) it.remove(); } @@ -71,13 +72,13 @@ public class WaterRemover { private static void collectBlocks(Block anchor, Set collected, Set visitedBlocks) { if( - (anchor.getType() != Material.WATER && anchor.getType() != Material.STATIONARY_WATER) || + !isWater(anchor.getType()) || visitedBlocks.contains(anchor) ) return; visitedBlocks.add(anchor); - if (anchor.getType() == Material.STATIONARY_WATER) + if (isWater(anchor.getType())) collected.add(anchor); if(visitedBlocks.size() > 100) { @@ -91,4 +92,12 @@ public class WaterRemover { collectBlocks(anchor.getRelative(BlockFace.WEST), collected, visitedBlocks); } + public static boolean isWater(Material type){ + switch(Core.getVersion()){ + case 14: + return WaterRemover_14.isWater(type); + default: + return WaterRemover_12.isWater(type); + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index a7ba9ac..6273036 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -1,10 +1,11 @@ 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.fight.FightTeam; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.utils.WaterRemover; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -70,7 +71,7 @@ public class WinconditionWaterTechKO { for(int y = minY; y <= maxY; y++) { for (int z = minZ; z <= maxZ; z++) { Material type = WORLD.getBlockAt(x, y, z).getType(); - if (type == Material.STATIONARY_WATER || type == Material.WATER) + if (WaterRemover.isWater(type)) teamWater.add(new Location(WORLD, x, y, z)); } } diff --git a/pom.xml b/pom.xml index 0fb0790..2046376 100644 --- a/pom.xml +++ b/pom.xml @@ -50,12 +50,6 @@ 2.0 provided - - steamwar - WorldEdit - 1.0 - provided - steamwar ProtocolLib -- 2.39.5 From 691f3d8cfae2d3abab1426e05d03f9e8713a2dbd Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 25 Nov 2019 17:53:23 +0100 Subject: [PATCH 6/6] Full 1.14 untested support (with techhider) --- .../fightsystem/utils/TechHider_12.java | 116 +-------------- .../fightsystem/utils/TechHider_14.java | 138 ++++++++++++++++++ .../src/de/steamwar/fightsystem/Config.java | 10 +- .../fightsystem/utils/ITechHider.java | 3 +- .../steamwar/fightsystem/utils/TechHider.java | 103 +++++++++++++ 5 files changed, 250 insertions(+), 120 deletions(-) create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java index 6beb2c5..b9533dd 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java @@ -6,48 +6,26 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.reflect.StructureModifier; -import com.comphenix.protocol.wrappers.BlockPosition; -import com.comphenix.protocol.wrappers.ChunkCoordIntPair; -import com.comphenix.protocol.wrappers.MultiBlockChangeInfo; -import com.comphenix.protocol.wrappers.WrappedBlockData; import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtFactory; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; -import de.steamwar.inventory.SWItem; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import javafx.util.Pair; import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk; -import org.bukkit.Material; import org.bukkit.craftbukkit.v1_12_R1.CraftChunk; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import static de.steamwar.fightsystem.utils.ITechHider.bypass; class TechHider_12 { private TechHider_12(){} - private static final short obfuscateShift4; - private static final Set hiddenBlocks; - - static{ - //noinspection deprecation - obfuscateShift4 = (short)(SWItem.getMaterial(Config.ObfuscateWith).getId() << 4); - - Set hBs = new HashSet<>(); - for(String mat : Config.HiddenBlocks){ - //noinspection deprecation - hBs.add(Material.getMaterial(mat).getId()); - } - hiddenBlocks = Collections.unmodifiableSet(hBs); - } + private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4); static void reloadChunk(Player p, Pair chunk){ ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535)); @@ -55,9 +33,6 @@ class TechHider_12 { static void start(){ chunkHider(); - multiBlockHider(); - blockHider(); - blockActionHider(); } private static void chunkHider(){ @@ -122,7 +97,7 @@ class TechHider_12 { int actPaletteLength = ITechHider.readVarIntLength(data, i); int blockId = actPalette >> 4; - if(hiddenBlocks.contains(blockId)){ + if(Config.HiddenBlocks.contains(blockId)){ byte[] a = ITechHider.writeVarInt(obfuscateShift4); buffer.writeBytes(a); changed = true; @@ -156,91 +131,4 @@ class TechHider_12 { } }).start(ITechHider.threadMultiplier * 4); } - - private static void multiBlockHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - - Player p = e.getPlayer(); - ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0); - if(bypass(p, pos.getChunkX(), pos.getChunkZ())) - return; - - PacketContainer cached = ITechHider.packetCache.get(packet); - if(cached != null){ - e.setPacket(cached); - return; - } - - cached = packet.shallowClone(); - ITechHider.packetCache.put(packet, cached); - e.setPacket(cached); - StructureModifier blockStructure = cached.getMultiBlockChangeInfoArrays(); - MultiBlockChangeInfo[] changes = blockStructure.read(0).clone(); - boolean changed = false; - for(MultiBlockChangeInfo mbci : changes){ - WrappedBlockData block = mbci.getData(); - //noinspection deprecation - if(hiddenBlocks.contains(block.getType().getId())){ - changed = true; - block.setType(ITechHider.obfuscateMaterial); - mbci.setData(block); - } - } - - if(changed){ - blockStructure.write(0, changes); - } - } - }); - } - - private static void blockHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - BlockPosition pos = packet.getBlockPositionModifier().read(0); - - Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) - return; - - PacketContainer cached = ITechHider.packetCache.get(packet); - if(cached != null){ - e.setPacket(cached); - return; - } - - cached = packet.deepClone(); - ITechHider.packetCache.put(packet, cached); - e.setPacket(cached); - StructureModifier blockStructure = cached.getBlockData(); - WrappedBlockData block = blockStructure.read(0); - //noinspection deprecation - if(hiddenBlocks.contains(block.getType().getId())){ - block.setType(ITechHider.obfuscateMaterial); - blockStructure.write(0, block); - } - } - }); - } - - private static void blockActionHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - BlockPosition pos = packet.getBlockPositionModifier().read(0); - - Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) - return; - - e.setCancelled(true); - } - }); - } } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java new file mode 100644 index 0000000..1b03adb --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java @@ -0,0 +1,138 @@ +package de.steamwar.fightsystem.utils; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.nbt.NbtCompound; +import com.comphenix.protocol.wrappers.nbt.NbtFactory; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.IFightSystem; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import javafx.util.Pair; +import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk; +import org.bukkit.craftbukkit.v1_14_R1.CraftChunk; +import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import java.util.List; + +import static de.steamwar.fightsystem.utils.ITechHider.bypass; + +public class TechHider_14 { + private TechHider_14(){} + + static void reloadChunk(Player p, Pair chunk){ + ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535)); + } + + static void start(){ + chunkHider(); + } + + private static void chunkHider(){ + ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + StructureModifier ints = packet.getIntegers(); + + int chunkX = ints.read(0); + int chunkZ = ints.read(1); + Player p = e.getPlayer(); + if(bypass(p, chunkX, chunkZ)) + return; + + PacketContainer cached = ITechHider.packetCache.get(packet); + if(cached != null){ + e.setPacket(cached); + return; + } + + cached = packet.deepClone(); + ITechHider.packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier list = cached.getSpecificModifier(List.class); + List nmsTags = list.read(1); + boolean changed = false; + for(int i = nmsTags.size() - 1; i >= 0; i--){ + NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTags.get(i)); + if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ + nmsTags.remove(i); + changed = true; + } + } + if(changed){ + list.write(0, nmsTags); + } + + changed = false; + StructureModifier byteArray = cached.getByteArrays(); + int primaryBitMask = ints.read(2); + int numChunkSections = 0; + while(primaryBitMask != 0){ + numChunkSections += primaryBitMask & 1; + primaryBitMask >>= 1; + } + byte [] data = byteArray.read(0); + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); + int i = 0; + + while(numChunkSections > 0){ + buffer.writeBytes(data, i, 2); // Block count + i += 2; + byte bitsPerBlock = data[i++]; + buffer.writeByte(bitsPerBlock); + if(bitsPerBlock < 4) + bitsPerBlock = 4; + else if(bitsPerBlock > 8){ + bitsPerBlock = 14; + buffer.writeByte(data[++i]); + } + + if(bitsPerBlock != 14){ + int paletteLength = ITechHider.readVarInt(data, i); + int paletteLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, paletteLengthLength); + i += paletteLengthLength; + for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ + int blockId = ITechHider.readVarInt(data, i); + int actPaletteLength = ITechHider.readVarIntLength(data, i); + + if(Config.HiddenBlocks.contains(blockId)){ + byte[] a = ITechHider.writeVarInt(Config.ObfuscateWith); + buffer.writeBytes(a); + changed = true; + }else{ + buffer.writeBytes(data, i, actPaletteLength); + } + i += actPaletteLength; + } + int dataArrayLength = ITechHider.readVarInt(data, i); + int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); + i += dataArrayLengthLength; + i += dataArrayLength * 8; + }else{ + int dataArrayLength = ITechHider.readVarInt(data, i); + int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); + i += dataArrayLengthLength; + i += dataArrayLength * 8; + } + numChunkSections--; + } + buffer.writeBytes(data, i, data.length - i); + + if(changed){ + data = new byte[buffer.readableBytes()]; + buffer.readBytes(data); + byteArray.write(0, data); + } + } + }).start(ITechHider.threadMultiplier * 4); + } +} diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 23cff16..ee08967 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -93,9 +93,10 @@ public class Config { public static final String LeaderDefault; //tech hider parameter - public static final List HiddenBlocks; + public static final List HiddenBlocks; public static final List HiddenBlockEntities; - public static final String ObfuscateWith; + public static final int ObfuscateWith; + public static final String ObfuscateWithTag; //event parameter private static final int EventKampfID; @@ -163,9 +164,10 @@ public class Config { MemberDefault = config.getString("Kits.MemberDefault"); LeaderDefault = config.getString("Kits.LeaderDefault"); - HiddenBlocks = Collections.unmodifiableList(config.getStringList("Techhider.HiddenBlocks")); + HiddenBlocks = Collections.unmodifiableList(config.getIntegerList("Techhider.HiddenBlocks")); HiddenBlockEntities = Collections.unmodifiableList(config.getStringList("Techhider.HiddenBlockEntities")); - ObfuscateWith = config.getString("Techhider.ObfuscateWith"); + ObfuscateWith = config.getInt("Techhider.ObfuscateWith"); + ObfuscateWithTag = config.getString("Techhider.ObfuscateWithTag"); if(schemsizeX < 0){ SchemsizeX = -schemsizeX; diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java index 5d2a58d..cb8da02 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -6,7 +6,6 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.fight.IFight; import de.steamwar.fightsystem.fight.IFightTeam; -import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -50,7 +49,7 @@ public class ITechHider { arenaMinZ = ITechHider.posToChunk(Config.ArenaMinZ); arenaMaxZ = ITechHider.posToChunk(Config.ArenaMaxZ) + 1; - obfuscateMaterial = SWItem.getMaterial(Config.ObfuscateWith); + obfuscateMaterial = Material.getMaterial(Config.ObfuscateWithTag); Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1); if(Config.event()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 50cf397..32ae288 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -3,10 +3,17 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.BlockPosition; +import com.comphenix.protocol.wrappers.ChunkCoordIntPair; +import com.comphenix.protocol.wrappers.MultiBlockChangeInfo; +import com.comphenix.protocol.wrappers.WrappedBlockData; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.IFightSystem; import javafx.util.Pair; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -57,14 +64,107 @@ public class TechHider { if(disabled()) return; + blockActionHider(); + blockHider(); + multiBlockHider(); switch(Core.getVersion()){ case 8: break; + case 14: + TechHider_14.start(); + break; default: TechHider_12.start(); } } + private static void multiBlockHider(){ + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + + Player p = e.getPlayer(); + ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0); + if(bypass(p, pos.getChunkX(), pos.getChunkZ())) + return; + + PacketContainer cached = ITechHider.packetCache.get(packet); + if(cached != null){ + e.setPacket(cached); + return; + } + + cached = packet.shallowClone(); + ITechHider.packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier blockStructure = cached.getMultiBlockChangeInfoArrays(); + MultiBlockChangeInfo[] changes = blockStructure.read(0).clone(); + boolean changed = false; + for(MultiBlockChangeInfo mbci : changes){ + WrappedBlockData block = mbci.getData(); + //noinspection deprecation + if(Config.HiddenBlocks.contains(block.getType().getId())){ + changed = true; + block.setType(ITechHider.obfuscateMaterial); + mbci.setData(block); + } + } + + if(changed){ + blockStructure.write(0, changes); + } + } + }); + } + + private static void blockHider(){ + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + BlockPosition pos = packet.getBlockPositionModifier().read(0); + + Player p = e.getPlayer(); + if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + return; + + PacketContainer cached = ITechHider.packetCache.get(packet); + if(cached != null){ + e.setPacket(cached); + return; + } + + cached = packet.deepClone(); + ITechHider.packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier blockStructure = cached.getBlockData(); + WrappedBlockData block = blockStructure.read(0); + //noinspection deprecation + if(Config.HiddenBlocks.contains(block.getType().getId())){ + block.setType(ITechHider.obfuscateMaterial); + blockStructure.write(0, block); + } + } + }); + } + + private static void blockActionHider(){ + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + BlockPosition pos = packet.getBlockPositionModifier().read(0); + + Player p = e.getPlayer(); + if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + return; + + e.setCancelled(true); + } + }); + } + public static List> prepareChunkReload(Player p){ if(disabled()) return Collections.emptyList(); @@ -92,6 +192,9 @@ public class TechHider { case 8: TechHider_8.reloadChunk(p, chunk); break; + case 14: + TechHider_14.reloadChunk(p, chunk); + break; default: TechHider_12.reloadChunk(p, chunk); } -- 2.39.5