From cbd5fe407f6c6d56328c6aaffc35cc5a7e97c026 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 9 Sep 2023 18:45:41 +0200 Subject: [PATCH 01/36] Fix Lockschem in Replays Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/commands/LockschemCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java index 9f9bd62..9ea0c13 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -35,7 +35,7 @@ import org.bukkit.entity.Player; public class LockschemCommand implements CommandExecutor { public LockschemCommand() { - new StateDependentCommand(ArenaMode.AntiReplay, FightState.All, "lockschem", this); + new StateDependentCommand(ArenaMode.All, FightState.Schem, "lockschem", this); } @Override From 230169e1631c3a17270903607cdde3f21357725a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 15 Sep 2023 20:50:39 +0200 Subject: [PATCH 02/36] Unchecked schematics Signed-off-by: Lixfel --- .../fightsystem/FightSystem.properties | 2 ++ .../fightsystem/FightSystem_de.properties | 2 ++ .../de/steamwar/fightsystem/commands/GUI.java | 29 ++++++++++++------- .../steamwar/fightsystem/fight/FightTeam.java | 5 ++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index c60b91b..c2590cd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -75,6 +75,7 @@ KITSEARCH_TITLE=Search for kit SCHEM_NO_ENEMY=§cNo schematic selection without an opponent SCHEM_TITLE={0} selection SCHEM_PUBLIC=§ePublic {0} +SCHEM_UNCHECKED=§eUnchecked {0} SCHEM_PRIVATE=§ePrivate {0} SCHEM_NO_PRIVATE=§7No private {0} present SCHEM_PRIVATE_FORBIDDEN=§7No private {0} allowed @@ -99,6 +100,7 @@ SPECTATE_COUNTDOWN=until the arena is reset # Fight SCHEMATIC_UNLOADABLE=§cUnable to load schematic SCHEMATIC_CHOSEN=§7{0} §e{1} §7chosen +SCHEMATIC_UNCHECKED=§7Team {0} §7has chosen an §eunchecked §7schematic§8! TEAM_READY=§aTeam ready TEAM_NOT_READY=§c§mTeam ready SKIP_READY=§aSkipping to next event diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 415652c..62b7861 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -69,6 +69,7 @@ KITSEARCH_TITLE=Nach Kit suchen SCHEM_NO_ENEMY=§cKeine Schematicwahl ohne Gegner SCHEM_TITLE={0}-Auswahl SCHEM_PUBLIC=§eÖffentliches {0} +SCHEM_UNCHECKED=§eUngeprüftes {0} SCHEM_PRIVATE=§ePrivates {0} SCHEM_NO_PRIVATE=§7Kein privates {0} vorhanden SCHEM_PRIVATE_FORBIDDEN=§7Kein privates {0} erlaubt @@ -93,6 +94,7 @@ SPECTATE_COUNTDOWN=bis die Arena zurückgesetzt wird # Fight SCHEMATIC_UNLOADABLE=§cSchematic konnte nicht geladen werden SCHEMATIC_CHOSEN=§7{0} §e{1} §7gewählt +SCHEMATIC_UNCHECKED=§7Team {0} §7hat eine §eungeprüfte §7Schematic gewählt§8! TEAM_READY=§aTeam bereit TEAM_NOT_READY=§c§mTeam bereit SKIP_READY=§aBeschleunigung zum nächsten Event diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index cb63550..3c9a30d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -170,24 +170,33 @@ public class GUI { SWInventory inv = new SWInventory(p, 9, msg.parse("SCHEM_TITLE", p, Config.GameName)); inv.setItem(8, Material.REDSTONE, msg.parse("SCHEM_PUBLIC", p, Config.GameName), (ClickType click) -> { p.closeInventory(); - schemDialog(p, true); + schemDialog(p, true, false); }); if(Fight.getMaxRank() == 0){ inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_PRIVATE_FORBIDDEN", p, Config.GameName), (ClickType click)->{}); - }else if(SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()).isEmpty() && !Config.test()){ - inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, Config.GameName), (ClickType click)->{}); - }else{ - inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, Config.GameName), (ClickType click) -> { - p.closeInventory(); - schemDialog(p, false); - }); + }else { + if (Config.SchematicType.checkType() != null && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.checkType().toDB()).isEmpty()) { + inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_UNCHECKED", p, Config.GameName), (ClickType click) -> { + p.closeInventory(); + schemDialog(p, false, true); + }); + } + + if(SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()).isEmpty() && !Config.test()){ + inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, Config.GameName), (ClickType click)->{}); + }else{ + inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, Config.GameName), (ClickType click) -> { + p.closeInventory(); + schemDialog(p, false, false); + }); + } } inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } - private static void schemDialog(Player p, boolean publicSchems){ - SchematicSelector selector = new SchematicSelector(p, Config.test()?SchematicSelector.selectSchematic():SchematicSelector.selectSchematicTypeWithRank(Config.SchematicType, Fight.getMaxRank()), node -> { + private static void schemDialog(Player p, boolean publicSchems, boolean unchecked){ + SchematicSelector selector = new SchematicSelector(p, Config.test()?SchematicSelector.selectSchematic():SchematicSelector.selectSchematicTypeWithRank(unchecked ? Config.SchematicType.checkType() : Config.SchematicType, Fight.getMaxRank()), node -> { FightTeam fightTeam = Fight.getPlayerTeam(p); if(fightTeam == null) return; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 74092af..94774aa 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -393,6 +393,11 @@ public class FightTeam { } public void pasteSchem(SchematicNode schematic){ + if(schematic.getSchemtype().check()) { + FightStatistics.unrank(); + FightSystem.getMessage().broadcast("SCHEMATIC_UNCHECKED", getColoredName()); + } + setSchem(schematic); testPasteAction(); } From 2cb9c12e46795951e9a49b8cd4a2ea7d0085c12d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 16 Sep 2023 11:09:41 +0200 Subject: [PATCH 03/36] Fix item and item location Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 3c9a30d..ad3c273 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -176,7 +176,7 @@ public class GUI { inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_PRIVATE_FORBIDDEN", p, Config.GameName), (ClickType click)->{}); }else { if (Config.SchematicType.checkType() != null && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.checkType().toDB()).isEmpty()) { - inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_UNCHECKED", p, Config.GameName), (ClickType click) -> { + inv.setItem(4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, Config.GameName), (ClickType click) -> { p.closeInventory(); schemDialog(p, false, true); }); From 4b82ea94262cc86f952fad9dc416270972c19d1f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 8 Oct 2023 18:08:13 +0200 Subject: [PATCH 04/36] Persistent Damage Event Signed-off-by: Lixfel --- FightSystem_Core/src/config.yml | 1 + .../de/steamwar/fightsystem/FightSystem.java | 2 + .../fightsystem/event/PersistentDamage.java | 44 +++++++++++++++++++ .../winconditions/Winconditions.java | 3 +- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/event/PersistentDamage.java diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index e2fffe4..89db437 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -121,6 +121,7 @@ WinConditions: # defaults to none if missing # - HELLS_BELLS # - METEOR + # - PERSISTENT_DAMAGE WinConditionParams: # The time of any of the timeout win conditions in seconds diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 5de02c4..c4898d4 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -26,6 +26,7 @@ import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.event.HellsBells; import de.steamwar.fightsystem.event.Meteor; +import de.steamwar.fightsystem.event.PersistentDamage; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightWorld; @@ -129,6 +130,7 @@ public class FightSystem extends JavaPlugin { new HellsBells(); new Meteor(); + new PersistentDamage(); new WinconditionAmongUs(); new NoPlayersOnlineCountdown(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/event/PersistentDamage.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/PersistentDamage.java new file mode 100644 index 0000000..606894f --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/PersistentDamage.java @@ -0,0 +1,44 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.fightsystem.event; + +import com.sk89q.worldedit.WorldEditException; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; +import de.steamwar.fightsystem.utils.WorldeditWrapper; +import de.steamwar.fightsystem.winconditions.Winconditions; +import de.steamwar.sql.SchematicNode; + +import java.util.logging.Level; + +public class PersistentDamage { + + public PersistentDamage() { + new OneShotStateDependent(Winconditions.PERSISTENT_DAMAGE, FightState.Spectate, () -> Fight.teams().forEach(team -> { + try{ + WorldeditWrapper.impl.saveSchem(SchematicNode.getSchematicNode(team.getSchematic()), team.getExtendRegion(), team.getSchemRegion().getMinY()); + }catch(WorldEditException e){ + FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Could not persist schematic state", e); + } + })); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 620a247..afd3943 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -39,5 +39,6 @@ public enum Winconditions { HELLS_BELLS, METEOR, - AMONG_US + AMONG_US, + PERSISTENT_DAMAGE } From 0c762e56240f1eebc1cbfaacf3239c78d8e43d9c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 8 Oct 2023 18:21:19 +0200 Subject: [PATCH 05/36] TNT Distribution Signed-off-by: Lixfel --- FightSystem_Core/src/config.yml | 1 + .../de/steamwar/fightsystem/FightSystem.java | 2 + .../fightsystem/event/TNTDistributor.java | 39 +++++++++++++++++++ .../winconditions/Winconditions.java | 3 +- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index 89db437..49f992a 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -122,6 +122,7 @@ WinConditions: # defaults to none if missing # - HELLS_BELLS # - METEOR # - PERSISTENT_DAMAGE + # - TNT_DISTRIBUTION WinConditionParams: # The time of any of the timeout win conditions in seconds diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index c4898d4..e6ae767 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -27,6 +27,7 @@ import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.event.HellsBells; import de.steamwar.fightsystem.event.Meteor; import de.steamwar.fightsystem.event.PersistentDamage; +import de.steamwar.fightsystem.event.TNTDistributor; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightWorld; @@ -131,6 +132,7 @@ public class FightSystem extends JavaPlugin { new HellsBells(); new Meteor(); new PersistentDamage(); + new TNTDistributor(); new WinconditionAmongUs(); new NoPlayersOnlineCountdown(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java new file mode 100644 index 0000000..dc630a3 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.fightsystem.event; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentTask; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public class TNTDistributor { + + public TNTDistributor() { + new StateDependentTask(ArenaMode.AntiReplay, FightState.Running, () -> Fight.teams().forEach(team -> team.getPlayers().forEach(fp -> { + if(!fp.isLiving()) + return; + + fp.ifPlayer(player -> player.getInventory().addItem(new ItemStack(Material.TNT, 20))); + })), 0, 300); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index afd3943..fa91d9c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -40,5 +40,6 @@ public enum Winconditions { HELLS_BELLS, METEOR, AMONG_US, - PERSISTENT_DAMAGE + PERSISTENT_DAMAGE, + TNT_DISTRIBUTION } From c87bac641ee65aa3157a9b24695f7b4dad0bd781 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 11 Oct 2023 10:56:05 +0200 Subject: [PATCH 06/36] TPS Warp Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../fightsystem/FightSystem.properties | 3 ++ .../fightsystem/FightSystem_de.properties | 3 ++ .../fightsystem/commands/TPSWarpCommand.java | 52 +++++++++++++++++++ FightSystem_Core/src/plugin.yml | 2 + 5 files changed, 61 insertions(+) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/commands/TPSWarpCommand.java diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index e6ae767..78bb14c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -156,6 +156,7 @@ public class FightSystem extends JavaPlugin { new LockschemCommand(); new StateCommand(); new SkipCommand(); + new TPSWarpCommand(); new UnrankCommand(); new WinCommand(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index c2590cd..3c220d6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -51,6 +51,9 @@ INFO_RANKED=§7Ranked§8: §e{0} INFO_LEADER=§7Leader {0}§8: {1} INFO_SCHEMATIC=§7Schematic {0}§8: §e{1} §7from {2}, Rank: {3} +TPSWARP_HELP=§8/§7tpswarp §8[§eticks per second§8] +TPSWARP_SET=§7TPS set to §e{0} + # GUI STATE_TITLE=Fight state diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 62b7861..06b07d1 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -45,6 +45,9 @@ REMOVE_HELP=§8/§eremove §8[§eSpieler§8] NOT_FIGHTLEADER=§cDu bist nicht Kampfleiter WIN_HELP=§8/§7win §8[§eTeam §8oder §etie§8] +TPSWARP_HELP=§8/§7tpswarp §8[§eTicks pro Sekunde§8] +TPSWARP_SET=§7TPS auf §e{0} §7gesetzt + # GUI STATE_TITLE=Kampfstatus diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/TPSWarpCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/TPSWarpCommand.java new file mode 100644 index 0000000..27927f7 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/TPSWarpCommand.java @@ -0,0 +1,52 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.fightsystem.commands; + +import de.steamwar.core.TPSWarpUtils; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class TPSWarpCommand implements CommandExecutor { + + public TPSWarpCommand() { + new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpswarp", this); + new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpslimit", this); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + double tps; + try { + tps = Double.parseDouble(args[0]); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + FightSystem.getMessage().send("TPSWARP_HELP", sender); + return false; + } + + TPSWarpUtils.warp(tps); + FightSystem.getMessage().broadcastActionbar("TPSWARP_SET", tps); + return false; + } +} diff --git a/FightSystem_Core/src/plugin.yml b/FightSystem_Core/src/plugin.yml index f0df4c2..d876395 100644 --- a/FightSystem_Core/src/plugin.yml +++ b/FightSystem_Core/src/plugin.yml @@ -26,4 +26,6 @@ commands: win: resetwg: resettb: + tpslimit: + tpswarp: unrank: \ No newline at end of file From 7ad5a1dc228442008f40539b36d1fe15824b8e04 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 12 Oct 2023 18:57:03 +0200 Subject: [PATCH 07/36] Fix TNT Distribution Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/event/TNTDistributor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java index dc630a3..6e0d81d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java @@ -19,17 +19,17 @@ package de.steamwar.fightsystem.event; -import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; +import de.steamwar.fightsystem.winconditions.Winconditions; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; public class TNTDistributor { public TNTDistributor() { - new StateDependentTask(ArenaMode.AntiReplay, FightState.Running, () -> Fight.teams().forEach(team -> team.getPlayers().forEach(fp -> { + new StateDependentTask(Winconditions.TNT_DISTRIBUTION, FightState.Running, () -> Fight.teams().forEach(team -> team.getPlayers().forEach(fp -> { if(!fp.isLiving()) return; From 61eb28f78e4eb2ac180b5e29e1f130a263322a51 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 27 Oct 2023 23:38:31 +0200 Subject: [PATCH 08/36] Fix double item drops Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/Permanent.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index e56d472..a0eabba 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -37,7 +37,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDispenseEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.entity.EntityExplodeEvent; @@ -153,14 +152,6 @@ public class Permanent implements Listener { e.setCancelled(true); } - @SuppressWarnings("deprecation") - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onBlockBreak(BlockBreakEvent e) { - Block block = e.getBlock(); - for(ItemStack stack : block.getDrops(e.getPlayer().getItemInHand())) - Config.world.dropItemNaturally(block.getLocation(), stack); - } - @EventHandler public void onDropPickup(PlayerPickupItemEvent e) { if(!(Config.ArenaRegion.inRegion(e.getItem().getLocation()))) From 70c86f40c69f4206d53d354d9dbfe41a9ea0ab12 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 29 Oct 2023 17:35:42 +0100 Subject: [PATCH 09/36] Fix override Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/event/PersistentDamage.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/event/PersistentDamage.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/PersistentDamage.java index 606894f..543eff9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/event/PersistentDamage.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/PersistentDamage.java @@ -20,6 +20,8 @@ package de.steamwar.fightsystem.event; import com.sk89q.worldedit.WorldEditException; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; @@ -33,6 +35,9 @@ import java.util.logging.Level; public class PersistentDamage { public PersistentDamage() { + if(!ArenaMode.SeriousFight.contains(Config.mode)) + return; + new OneShotStateDependent(Winconditions.PERSISTENT_DAMAGE, FightState.Spectate, () -> Fight.teams().forEach(team -> { try{ WorldeditWrapper.impl.saveSchem(SchematicNode.getSchematicNode(team.getSchematic()), team.getExtendRegion(), team.getSchemRegion().getMinY()); From a8112eccc8ef3909b18c98181f50f1415463df14 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 29 Nov 2023 15:34:07 +0100 Subject: [PATCH 10/36] Make Armor Mandatory in yaml kits. Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index 0ba4628..2af787c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -104,10 +104,7 @@ public class Kit { public Kit(ConfigurationSection kit){ name = kit.getName(); inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]); - if(kit.isList("Armor")) - armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]); - else - armor = null; + armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]); leaderAllowed = kit.getBoolean("LeaderAllowed"); memberAllowed = kit.getBoolean("MemberAllowed"); if(kit.isList("Effects")) From 86de472fe09eaacc42893b57b789e31a44e31b3b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 29 Nov 2023 15:35:33 +0100 Subject: [PATCH 11/36] Revert "Make Armor Mandatory in yaml kits." This reverts commit a8112eccc8ef3909b18c98181f50f1415463df14. --- FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index 2af787c..0ba4628 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -104,7 +104,10 @@ public class Kit { public Kit(ConfigurationSection kit){ name = kit.getName(); inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]); - armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]); + if(kit.isList("Armor")) + armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]); + else + armor = null; leaderAllowed = kit.getBoolean("LeaderAllowed"); memberAllowed = kit.getBoolean("MemberAllowed"); if(kit.isList("Effects")) From ef8cdef05cab93614553b5e12105663c672f582b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 29 Nov 2023 15:47:48 +0100 Subject: [PATCH 12/36] Distribute first TNT after 300s Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/event/TNTDistributor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java index 6e0d81d..8982bb3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/TNTDistributor.java @@ -34,6 +34,6 @@ public class TNTDistributor { return; fp.ifPlayer(player -> player.getInventory().addItem(new ItemStack(Material.TNT, 20))); - })), 0, 300); + })), 300, 300); } } From ad5a2d4a085e64b41199bd5f2af73afe1c3a184e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 29 Nov 2023 16:40:10 +0100 Subject: [PATCH 13/36] Document manualcheck option Signed-off-by: Lixfel --- FightSystem_Core/src/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index 49f992a..ab03b87 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -65,6 +65,8 @@ Schematic: Shortcut: "" # defaults to "" if missing # Spigot (1.8) material for GUIs Material: STONE_BUTTON # defaults to STONE_BUTTON if missing + # Manual check of schematic necessary + ManualCheck: true # defaults to true if missing # If the schematics should be rotated during pasting Rotate: true # defaults to true if missing # If the schematics should be pasted aligned to the borders instead of centered From b3ad960973b1b50e40e3f576cc7eb9a04f3c8ffb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Dec 2023 16:14:37 +0100 Subject: [PATCH 14/36] Add MultiSchemType selection for GUI.preSchemDialog --- FightSystem_Core/src/config.yml | 3 +- .../src/de/steamwar/fightsystem/Config.java | 7 +-- .../de/steamwar/fightsystem/commands/GUI.java | 62 +++++++++++-------- .../de/steamwar/fightsystem/fight/Fight.java | 20 ++---- .../steamwar/fightsystem/fight/FightTeam.java | 14 ++--- 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index ab03b87..3ec764b 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -61,6 +61,7 @@ Schematic: z: 0 # The schematic type that can be chosen in this arena Type: Normal # defaults to Normal if missing + SubTypes: [] # defaults to empty List # Shortcut of the schematic type Shortcut: "" # defaults to "" if missing # Spigot (1.8) material for GUIs @@ -73,7 +74,7 @@ Schematic: PasteAligned: false # defaults to false if missing # If only public schematics are allowed OnlyPublicSchematics: false # defaults to false if missing - # If the public only force should be completely disabled + # If the public only force should be completely disabled # TODO: I think this value is now obsolete! IgnorePublicOnly: false # defaults to false if missing # If obsidian and bedrock should be replaced during PRE_RUNNING ReplaceObsidianBedrock: false # defaults to false if missing diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 9b8bf6d..816fefb 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -21,10 +21,7 @@ package de.steamwar.fightsystem; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; -import de.steamwar.sql.Event; -import de.steamwar.sql.EventFight; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.Team; +import de.steamwar.sql.*; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -83,6 +80,7 @@ public class Config { public static final boolean OnlyPublicSchematics; public static final boolean IgnorePublicOnly; public static final de.steamwar.sql.SchematicType SchematicType; + public static final List SubTypes; public static final boolean RedRotate; public static final boolean BlueRotate; public static final boolean PasteAligned; @@ -181,6 +179,7 @@ public class Config { int schemsizeZ = config.getInt("Schematic.Size.z"); RanksEnabled = !config.getStringList("Ranks").isEmpty(); SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.Type", "normal"))); + SubTypes = config.getStringList("Schematic.SubTypes").stream().map(de.steamwar.sql.SchematicType::fromDB).collect(Collectors.toList()); IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly", false); boolean rotate = config.getBoolean("Schematic.Rotate", true); PasteAligned = config.getBoolean("Schematic.PasteAligned", false); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index ad3c273..612bdab 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -29,6 +29,7 @@ import de.steamwar.inventory.*; import de.steamwar.message.Message; import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; @@ -167,36 +168,47 @@ public class GUI { return; } - SWInventory inv = new SWInventory(p, 9, msg.parse("SCHEM_TITLE", p, Config.GameName)); - inv.setItem(8, Material.REDSTONE, msg.parse("SCHEM_PUBLIC", p, Config.GameName), (ClickType click) -> { - p.closeInventory(); - schemDialog(p, true, false); - }); - if(Fight.getMaxRank() == 0){ - inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_PRIVATE_FORBIDDEN", p, Config.GameName), (ClickType click)->{}); - }else { - if (Config.SchematicType.checkType() != null && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.checkType().toDB()).isEmpty()) { - inv.setItem(4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, Config.GameName), (ClickType click) -> { - p.closeInventory(); - schemDialog(p, false, true); - }); - } - - if(SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()).isEmpty() && !Config.test()){ - inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, Config.GameName), (ClickType click)->{}); - }else{ - inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, Config.GameName), (ClickType click) -> { - p.closeInventory(); - schemDialog(p, false, false); - }); - } + int invSize = (Config.SubTypes.size() + 1) * 9; + SWInventory inv = new SWInventory(p, invSize, msg.parse("SCHEM_TITLE", p, Config.GameName)); + setupSchemTypeRow(p, inv, Config.SchematicType, 0); + for (int i = 0; i < Config.SubTypes.size(); i++) { + setupSchemTypeRow(p, inv, Config.SubTypes.get(0), i + 1); } inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } - private static void schemDialog(Player p, boolean publicSchems, boolean unchecked){ - SchematicSelector selector = new SchematicSelector(p, Config.test()?SchematicSelector.selectSchematic():SchematicSelector.selectSchematicTypeWithRank(unchecked ? Config.SchematicType.checkType() : Config.SchematicType, Fight.getMaxRank()), node -> { + private static void setupSchemTypeRow(Player p, SWInventory inv, SchematicType type, int row) { + inv.setItem(row * 9 + 8, Material.REDSTONE, msg.parse("SCHEM_PUBLIC", p, type.name()), (ClickType click) -> { + p.closeInventory(); + schemDialog(p, type, true, false); + }); + + if (Fight.publicOnly()) { + inv.setItem(row * 9, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_PRIVATE_FORBIDDEN", p, type.name()), (ClickType click)->{}); + return; + } + + if (type.checkType() != null && type.checkType() != type && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.checkType().toDB()).isEmpty()) { + inv.setItem(row * 9 + 4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, Config.GameName), (ClickType click) -> { + p.closeInventory(); + schemDialog(p, type, false, true); + }); + } + + if (SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()).isEmpty() && !Config.test()) { + inv.setItem(row * 9, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, Config.GameName), (ClickType click)->{}); + return; + } + + inv.setItem(row * 9, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, Config.GameName), (ClickType click) -> { + p.closeInventory(); + schemDialog(p, type, false, false); + }); + } + + private static void schemDialog(Player p, SchematicType type, boolean publicSchems, boolean unchecked){ + SchematicSelector selector = new SchematicSelector(p, Config.test() ? SchematicSelector.selectSchematic() : SchematicSelector.selectSchematicType(unchecked ? type.checkType() : type), node -> { FightTeam fightTeam = Fight.getPlayerTeam(p); if(fightTeam == null) return; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index f7011d0..c50cf60 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -139,21 +139,13 @@ public class Fight { TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), enable ? GameMode.CREATIVE : GameMode.SPECTATOR)); } - public static int getMaxRank(){ - /* MaxRank of 0 is Pubonly*/ - if(Config.OnlyPublicSchematics){ - return 0; + public static boolean publicOnly() { + if (Config.OnlyPublicSchematics) { + return true; } - - if(Config.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)){ - return 1000; + if (redTeam.isPublicsOnly() || blueTeam.isPublicsOnly()) { + return true; } - - - if(redTeam.getLeader() == null || blueTeam.getLeader() == null){ - return 1000; - } - - return Math.min(redTeam.getSchemRank(), blueTeam.getSchemRank()); + return false; } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 94774aa..02aa943 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -90,7 +90,7 @@ public class FightTeam { private UUID designatedLeader; private FightPlayer leader; - private int schemRank; + private boolean publicsOnly; private final Map players = new HashMap<>(); @@ -113,7 +113,7 @@ public class FightTeam { this.spawn = spawn; this.schemRegion = schemRegion; this.extendRegion = extendRegion; - this.schemRank = 0; + this.publicsOnly = false; this.ready = false; this.skip = false; this.blue = blue; @@ -161,8 +161,8 @@ public class FightTeam { return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId())); } - public int getSchemRank() { - return schemRank; + public boolean isPublicsOnly() { + return publicsOnly; } public void teleportToSpawn(){ @@ -357,11 +357,7 @@ public class FightTeam { if(!silent) FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getEntity().getName()); - Optional maxRank = SchematicNode.getAllAccessibleSchematicsOfType(leader.getUser().getId(), Config.SchematicType.toDB()).stream().map(SchematicNode::getRank).max(Integer::compare); - if(Config.RanksEnabled) - schemRank = maxRank.orElse(1); - else - schemRank = maxRank.isPresent() ? 1 : 0; + publicsOnly = SchematicNode.getAllAccessibleSchematicsOfType(leader.getUser().getId(), Config.SchematicType.toDB()).isEmpty(); if(!Config.PersonalKits) leader.setKit(Kit.getKitByName(Config.LeaderDefault)); From 8d77f4dcf4fe7e1b833e44be7bdb767f09634f6b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Dec 2023 16:19:55 +0100 Subject: [PATCH 15/36] Fix Fight.publicOnly method --- FightSystem_Core/src/config.yml | 2 +- .../src/de/steamwar/fightsystem/fight/Fight.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index 3ec764b..6b0c977 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -74,7 +74,7 @@ Schematic: PasteAligned: false # defaults to false if missing # If only public schematics are allowed OnlyPublicSchematics: false # defaults to false if missing - # If the public only force should be completely disabled # TODO: I think this value is now obsolete! + # If the public only force should be completely disabled IgnorePublicOnly: false # defaults to false if missing # If obsidian and bedrock should be replaced during PRE_RUNNING ReplaceObsidianBedrock: false # defaults to false if missing diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index c50cf60..defed4c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -143,9 +143,9 @@ public class Fight { if (Config.OnlyPublicSchematics) { return true; } - if (redTeam.isPublicsOnly() || blueTeam.isPublicsOnly()) { - return true; + if (Config.IgnorePublicOnly) { + return false; } - return false; + return redTeam.isPublicsOnly() || blueTeam.isPublicsOnly(); } } From c0665b1868f7de77e53ab4f85f950f0d55682fc8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Dec 2023 18:03:09 +0100 Subject: [PATCH 16/36] =?UTF-8?q?Fix=20non=20lower=20case=20SchematicType?= =?UTF-8?q?=20fromDB=20lookup=20Fix=20RankedEvent=20not=20being=20consider?= =?UTF-8?q?ed=20f=C3=BCr=20ignore=20publics=20only=20Fix=20using=20index?= =?UTF-8?q?=200=20instead=20of=20i=20for=20creating=20of=20gui=20Fix=20con?= =?UTF-8?q?fig.yml=20missing=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FightSystem_Core/src/config.yml | 1 + FightSystem_Core/src/de/steamwar/fightsystem/Config.java | 4 ++-- .../src/de/steamwar/fightsystem/commands/GUI.java | 2 +- FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index 6b0c977..408c546 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -61,6 +61,7 @@ Schematic: z: 0 # The schematic type that can be chosen in this arena Type: Normal # defaults to Normal if missing + # The schematic types that are also allowed to be chosen in this arena SubTypes: [] # defaults to empty List # Shortcut of the schematic type Shortcut: "" # defaults to "" if missing diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 816fefb..b48186e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -178,8 +178,8 @@ public class Config { int schemsizeY = config.getInt("Schematic.Size.y"); int schemsizeZ = config.getInt("Schematic.Size.z"); RanksEnabled = !config.getStringList("Ranks").isEmpty(); - SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.Type", "normal"))); - SubTypes = config.getStringList("Schematic.SubTypes").stream().map(de.steamwar.sql.SchematicType::fromDB).collect(Collectors.toList()); + SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.Type", "normal").toLowerCase())); + SubTypes = config.getStringList("Schematic.SubTypes").stream().map(String::toLowerCase).map(de.steamwar.sql.SchematicType::fromDB).collect(Collectors.toList()); IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly", false); boolean rotate = config.getBoolean("Schematic.Rotate", true); PasteAligned = config.getBoolean("Schematic.PasteAligned", false); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 612bdab..b405872 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -172,7 +172,7 @@ public class GUI { SWInventory inv = new SWInventory(p, invSize, msg.parse("SCHEM_TITLE", p, Config.GameName)); setupSchemTypeRow(p, inv, Config.SchematicType, 0); for (int i = 0; i < Config.SubTypes.size(); i++) { - setupSchemTypeRow(p, inv, Config.SubTypes.get(0), i + 1); + setupSchemTypeRow(p, inv, Config.SubTypes.get(i), i + 1); } inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index defed4c..9f7f649 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -143,7 +143,7 @@ public class Fight { if (Config.OnlyPublicSchematics) { return true; } - if (Config.IgnorePublicOnly) { + if (Config.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)) { return false; } return redTeam.isPublicsOnly() || blueTeam.isPublicsOnly(); From 3ee7411591dc9ba83a32c5db9fd6fcef452202d6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Dec 2023 18:15:28 +0100 Subject: [PATCH 17/36] Revert lowercase Fix SchematicType not used for checking available schematics Fix leader not present to enable public only schem selection --- FightSystem_Core/src/de/steamwar/fightsystem/Config.java | 9 ++++++--- .../src/de/steamwar/fightsystem/commands/GUI.java | 8 ++++---- .../src/de/steamwar/fightsystem/fight/Fight.java | 3 +++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index b48186e..656c994 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -21,7 +21,10 @@ package de.steamwar.fightsystem; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; -import de.steamwar.sql.*; +import de.steamwar.sql.Event; +import de.steamwar.sql.EventFight; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.Team; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -178,8 +181,8 @@ public class Config { int schemsizeY = config.getInt("Schematic.Size.y"); int schemsizeZ = config.getInt("Schematic.Size.z"); RanksEnabled = !config.getStringList("Ranks").isEmpty(); - SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.Type", "normal").toLowerCase())); - SubTypes = config.getStringList("Schematic.SubTypes").stream().map(String::toLowerCase).map(de.steamwar.sql.SchematicType::fromDB).collect(Collectors.toList()); + SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.Type", "normal"))); + SubTypes = config.getStringList("Schematic.SubTypes").stream().map(de.steamwar.sql.SchematicType::fromDB).collect(Collectors.toList()); IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly", false); boolean rotate = config.getBoolean("Schematic.Rotate", true); PasteAligned = config.getBoolean("Schematic.PasteAligned", false); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index b405872..cbb392b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -190,18 +190,18 @@ public class GUI { } if (type.checkType() != null && type.checkType() != type && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.checkType().toDB()).isEmpty()) { - inv.setItem(row * 9 + 4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, Config.GameName), (ClickType click) -> { + inv.setItem(row * 9 + 4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, type.name()), (ClickType click) -> { p.closeInventory(); schemDialog(p, type, false, true); }); } - if (SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()).isEmpty() && !Config.test()) { - inv.setItem(row * 9, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, Config.GameName), (ClickType click)->{}); + if (SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.toDB()).isEmpty() && !Config.test()) { + inv.setItem(row * 9, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, type.name()), (ClickType click)->{}); return; } - inv.setItem(row * 9, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, Config.GameName), (ClickType click) -> { + inv.setItem(row * 9, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, type.name()), (ClickType click) -> { p.closeInventory(); schemDialog(p, type, false, false); }); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 9f7f649..e8966ab 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -146,6 +146,9 @@ public class Fight { if (Config.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)) { return false; } + if (redTeam.getLeader() == null || blueTeam.getLeader() == null) { + return false; + } return redTeam.isPublicsOnly() || blueTeam.isPublicsOnly(); } } From c08cec7cf251b955628c986b84c5e9f06bc3ed43 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 2 Dec 2023 16:02:30 +0100 Subject: [PATCH 18/36] Add pasting of non prepared schem on red side --- .../src/de/steamwar/fightsystem/FightSystem.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 78bb14c..3ee5d15 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -168,7 +168,13 @@ public class FightSystem extends JavaPlugin { if(Config.mode == ArenaMode.EVENT) { FightState.setFightState(FightState.PRE_SCHEM_SETUP); }else if(Config.mode == ArenaMode.CHECK){ - Fight.getBlueTeam().setSchem(SchematicNode.getSchematicNode(Config.CheckSchemID)); + SchematicNode checkSchematicNode = SchematicNode.getSchematicNode(Config.CheckSchemID); + Fight.getBlueTeam().setSchem(checkSchematicNode); + + if (checkSchematicNode.getName().endsWith("-prepared")) { + SchematicNode nonPreparedSchematicNode = SchematicNode.getSchematicNode(checkSchematicNode.getOwner(), checkSchematicNode.getName().substring(0, checkSchematicNode.getName().length() - 9), checkSchematicNode.getParent()); + Fight.getRedTeam().setSchem(nonPreparedSchematicNode); + } }else if(Config.mode == ArenaMode.PREPARE) { Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID)); } From 2e8ad5301ee0e4418fa87c066b3b493a89d53f4f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 2 Dec 2023 20:03:48 +0100 Subject: [PATCH 19/36] Add pasting of non prepared schem on red side --- .../src/de/steamwar/fightsystem/FightSystem.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 3ee5d15..3c10d4f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -172,8 +172,10 @@ public class FightSystem extends JavaPlugin { Fight.getBlueTeam().setSchem(checkSchematicNode); if (checkSchematicNode.getName().endsWith("-prepared")) { - SchematicNode nonPreparedSchematicNode = SchematicNode.getSchematicNode(checkSchematicNode.getOwner(), checkSchematicNode.getName().substring(0, checkSchematicNode.getName().length() - 9), checkSchematicNode.getParent()); - Fight.getRedTeam().setSchem(nonPreparedSchematicNode); + SchematicNode unpreparedSchematicNode = SchematicNode.getSchematicNode(checkSchematicNode.getOwner(), checkSchematicNode.getName().substring(0, checkSchematicNode.getName().length() - 9), checkSchematicNode.getParent()); + if (unpreparedSchematicNode != null) { + Fight.getRedTeam().setSchem(unpreparedSchematicNode); + } } }else if(Config.mode == ArenaMode.PREPARE) { Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID)); From d140db2401c11fa4cbf5eaf8f9f8d53b95c6191b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 3 Dec 2023 20:26:04 +0100 Subject: [PATCH 20/36] Fix entern after reset Signed-off-by: Lixfel --- .../steamwar/fightsystem/countdown/EnternCountdown.java | 8 +++----- .../src/de/steamwar/fightsystem/fight/FightPlayer.java | 5 +++-- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 3 ++- .../src/de/steamwar/fightsystem/utils/EnterHandler.java | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index 7517be6..d8c78d9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -25,17 +25,15 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.techhider.ProtocolUtils; -import de.steamwar.fightsystem.winconditions.Wincondition; import net.md_5.bungee.api.ChatMessageType; import java.util.List; public class EnternCountdown extends Countdown { - private static int calcTime(FightPlayer fp) { + private static int calcTime(FightPlayer fp, Countdown countdown) { int time = Config.EnterStages.get(fp.getKit().getEnterStage()); - Countdown countdown = Wincondition.getTimeOverCountdown(); if(countdown != null) { time -= Config.TimeoutTime - countdown.getTimeLeft(); @@ -49,8 +47,8 @@ public class EnternCountdown extends Countdown { private final FightPlayer fightPlayer; private List chunkPos; - public EnternCountdown(FightPlayer fp) { - super(calcTime(fp), new Message("ENTERN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); + public EnternCountdown(FightPlayer fp, Countdown countdown) { + super(calcTime(fp, countdown), new Message("ENTERN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); fightPlayer = fp; enable(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java index 2ea6f58..e6740a8 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.ai.AI; +import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.countdown.EnternCountdown; import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SteamwarUser; @@ -65,9 +66,9 @@ public class FightPlayer { ifAI(AI::stop); } - public void startEnternCountdown() { + public void startEnternCountdown(Countdown countdown) { if(Config.EnterStages.size() > kit.getEnterStage() && kit.getEnterStage() >= 0) - enternCountdown = new EnternCountdown(this); + enternCountdown = new EnternCountdown(this, countdown); } public void stopEnternCountdown(){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 94774aa..878aa79 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -33,6 +33,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.*; +import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.inventory.SWItem; import de.steamwar.sql.SchematicNode; @@ -284,7 +285,7 @@ public class FightTeam { }); if(FightState.Running.contains(FightState.getFightState())) - fightPlayer.startEnternCountdown(); + fightPlayer.startEnternCountdown(Wincondition.getTimeOverCountdown()); GlobalRecorder.getInstance().playerJoins(entity, user); fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunksToReload, false)); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java index ee5aa79..042efba 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java @@ -51,7 +51,7 @@ public class EnterHandler implements IStateDependent { private void registerTeam(FightTeam team){ for(FightPlayer fp : team.getPlayers()){ - fp.startEnternCountdown(); + fp.startEnternCountdown(null); } } From 63962641940ebf37c8f52c37bd769d44aa1e6b07 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 3 Dec 2023 20:55:36 +0100 Subject: [PATCH 21/36] Fix schem deleted bug Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/FightStatistics.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 7467e0e..df12a82 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -98,12 +98,12 @@ public class FightStatistics { Integer redSchem; try { blueSchem = SchematicNode.getSchematicNode(Fight.getBlueTeam().getSchematic()).getId(); - } catch (SecurityException e) { + } catch (NullPointerException e) { blueSchem = null; } try { redSchem = SchematicNode.getSchematicNode(Fight.getRedTeam().getSchematic()).getId(); - } catch (SecurityException e) { + } catch (NullPointerException e) { redSchem = null; } From 4f6502349117c2d58ad0bf10a55527df0a01988d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Dec 2023 15:36:40 +0100 Subject: [PATCH 22/36] Hotfix FightSchematic public choosing with no publics abailable in schematictype --- .../fightsystem/fight/FightSchematic.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 0ffff16..ee1ab0a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -33,6 +33,7 @@ import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.WorldeditWrapper; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SchematicType; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -44,6 +45,7 @@ import java.io.IOException; import java.util.List; import java.util.Random; import java.util.logging.Level; +import java.util.stream.Stream; public class FightSchematic extends StateDependent { @@ -100,8 +102,17 @@ public class FightSchematic extends StateDependent { if(clipboard == null){ List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); - if(publics.isEmpty()) - return; + if(publics.isEmpty()) { + for (SchematicType type : Config.SubTypes) { + publics = SchematicNode.getAllSchematicsOfType(0, type.toDB()); + if (!publics.isEmpty()) { + break; + } + } + if (publics.isEmpty()) { + return; + } + } setSchematic(publics.get(new Random().nextInt(publics.size()))); } From 0a45b161a2c2abf945775718393d642289603827 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 12 Dec 2023 00:10:05 +0100 Subject: [PATCH 23/36] Simplify percent system by adding entern percent and whitelist config toggles Signed-off-by: Lixfel --- FightSystem_Core/src/config.yml | 6 ++-- .../src/de/steamwar/fightsystem/Config.java | 4 +++ .../de/steamwar/fightsystem/FightSystem.java | 4 +-- .../winconditions/Wincondition.java | 4 +-- .../WinconditionBlacklistPercent.java | 27 --------------- ...ondition.java => WinconditionPercent.java} | 34 +++++++------------ .../WinconditionPercentSystem.java | 30 ---------------- .../winconditions/WinconditionPoints.java | 4 +-- .../WinconditionPointsAirShip.java | 4 +-- .../WinconditionWhitelistPercent.java | 31 ----------------- .../winconditions/Winconditions.java | 2 -- 11 files changed, 28 insertions(+), 122 deletions(-) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlacklistPercent.java rename FightSystem_Core/src/de/steamwar/fightsystem/winconditions/{PercentWincondition.java => WinconditionPercent.java} (74%) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWhitelistPercent.java diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index 408c546..ca3645d 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -114,8 +114,6 @@ WinConditions: # defaults to none if missing # - CAPTAIN_DEAD # - PERCENT_SYSTEM - # - WHITELIST_PERCENT - # - RELATIVE_PERCENT # - POINTS # - POINTS_AIRSHIP @@ -133,6 +131,10 @@ WinConditionParams: TimeoutTime: 1200 # defaults to 1200 if missing # The percentage when any of the percent win conditions limits or triggers a win PercentWin: 7.0 # defaults to 7.0 if missing + # Does the percentage still change after the start of the enter phase + PercentEntern: true # defaults to true if missing + # Is Blocks a whitelist (true) or blacklist (false) + BlocksWhitelist: false # defaults to false if missing # Special Blocks (Valid spigot material values) used by the percent win conditions Blocks: [] # defaults to none if missing diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 656c994..331491f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -107,6 +107,8 @@ public class Config { //win condition parameters public static final int TimeoutTime; public static final double PercentWin; + public static final boolean PercentEntern; + public static final boolean PercentBlocksWhitelist; public static final Set PercentBlocks; //default kits @@ -197,6 +199,8 @@ public class Config { TimeoutTime = config.getInt("WinConditionParams.TimeoutTime", 1200); PercentWin = config.getDouble("WinConditionParams.PercentWin", 7.0); + PercentEntern = config.getBoolean("WinConditionParams.PercentEntern", true); + PercentBlocksWhitelist = config.getBoolean("WinConditionParams.BlocksWhitelist", false); PercentBlocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.Blocks").stream().map(Material::valueOf).collect(Collectors.toSet())); EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 3c10d4f..d56d7d9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -118,9 +118,7 @@ public class FightSystem extends JavaPlugin { new WinconditionCaptainDead(); new WinconditionBlocks(Winconditions.WATER_TECH_KO, "WaterTechKO", "BAR_WATER", FlatteningWrapper.impl::isWater); new WinconditionBlocks(Winconditions.PUMPKIN_TECH_KO, "PumpkinTechKO", "BAR_CANNONS", block -> block.getType() == WinconditionBlocks.PUMPKIN_LANTERN); - new WinconditionPercentSystem(); - new WinconditionBlacklistPercent(); - new WinconditionWhitelistPercent(); + new WinconditionPercent(Winconditions.PERCENT_SYSTEM, "Percent"); new WinconditionPoints(); new WinconditionPointsAirShip(); new WinconditionTimeout(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java index 8e6e283..3f0f58e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java @@ -34,7 +34,7 @@ import java.util.stream.Collectors; public abstract class Wincondition { - protected static PercentWincondition percentWincondition = null; + protected static WinconditionPercent percentWincondition = null; protected static StateDependentCountdown timeOverCountdown = null; protected static final List printableWinconditions = new ArrayList<>(); @@ -65,7 +65,7 @@ public abstract class Wincondition { return printableWinconditions; } - public static PercentWincondition getPercentWincondition() { + public static WinconditionPercent getPercentWincondition() { return percentWincondition; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlacklistPercent.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlacklistPercent.java deleted file mode 100644 index a823079..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlacklistPercent.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.winconditions; - -public class WinconditionBlacklistPercent extends PercentWincondition { - - public WinconditionBlacklistPercent(){ - super("RelativePercent", Winconditions.RELATIVE_PERCENT); - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java similarity index 74% rename from FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java index 40b227f..4b7839a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java @@ -26,7 +26,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.Message; -import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -34,27 +33,12 @@ import org.bukkit.event.entity.EntityExplodeEvent; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.BooleanSupplier; import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; -public class PercentWincondition extends Wincondition implements PrintableWincondition { +public class WinconditionPercent extends Wincondition implements PrintableWincondition { private final Map teamMap = new HashMap<>(); - protected BooleanSupplier explosionFilter = () -> !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft(); - protected Predicate testBlock = type -> !Config.PercentBlocks.contains(type); - protected ToIntFunction totalBlockCalc = team -> { - AtomicInteger blocks = new AtomicInteger(); - team.getSchemRegion().forEach((x, y, z) -> { - if (testBlock.test(Config.world.getBlockAt(x, y, z).getType())) { - blocks.getAndIncrement(); - } - }); - return blocks.get(); - }; protected Consumer checkWin = team -> { if (getPercent(team) >= Config.PercentWin) { win(Fight.getOpposite(team), "WIN_PERCENT", team.getColoredName()); @@ -62,7 +46,7 @@ public class PercentWincondition extends Wincondition implements PrintableWincon }; protected Consumer postEnable = team -> {}; - public PercentWincondition(String windescription, Winconditions wincondition) { + public WinconditionPercent(Winconditions wincondition, String windescription) { super(windescription); if (Config.ActiveWinconditions.contains(wincondition)) { @@ -105,12 +89,16 @@ public class PercentWincondition extends Wincondition implements PrintableWincon @EventHandler public void onEntityExplode(EntityExplodeEvent event) { - if (event.getEntityType() == EntityType.FIREBALL || explosionFilter.getAsBoolean() || !team.getExtendRegion().inRegion(event.getEntity().getLocation())) { + if ( + event.getEntityType() == EntityType.FIREBALL || + !team.getExtendRegion().inRegion(event.getEntity().getLocation()) || + (!Config.PercentEntern && !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft()) + ) { return; } event.blockList().forEach(block -> { - if (testBlock.test(block.getType())) { + if (Config.PercentBlocks.contains(block.getType()) == Config.PercentBlocksWhitelist) { currentBlocks--; } }); @@ -119,7 +107,11 @@ public class PercentWincondition extends Wincondition implements PrintableWincon } private void enable() { - totalBlocks = totalBlockCalc.applyAsInt(team); + totalBlocks = 0; + team.getSchemRegion().forEach((x, y, z) -> { + if (Config.PercentBlocks.contains(Config.world.getBlockAt(x, y, z).getType()) == Config.PercentBlocksWhitelist) + totalBlocks++; + }); currentBlocks = totalBlocks; postEnable.accept(team); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java deleted file mode 100644 index 6be7476..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.winconditions; - -public class WinconditionPercentSystem extends PercentWincondition { - - public WinconditionPercentSystem() { - super("Percent", Winconditions.PERCENT_SYSTEM); - - totalBlockCalc = team -> team.getSchemRegion().volume(); - explosionFilter = () -> false; - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 2d0396d..028e893 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -36,12 +36,12 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; import java.util.Map; -public class WinconditionPoints extends PercentWincondition implements Listener { +public class WinconditionPoints extends WinconditionPercent implements Listener { private final Map teamMap = new HashMap<>(); public WinconditionPoints(){ - super("Points", Winconditions.POINTS); + super(Winconditions.POINTS, "Points"); checkWin = team -> {}; postEnable = this::pointInit; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPointsAirShip.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPointsAirShip.java index 124ed14..4f166a6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPointsAirShip.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPointsAirShip.java @@ -35,7 +35,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; -public class WinconditionPointsAirShip extends PercentWincondition implements Listener { +public class WinconditionPointsAirShip extends WinconditionPercent implements Listener { private double[] as = new double[] { 0.5, @@ -56,7 +56,7 @@ public class WinconditionPointsAirShip extends PercentWincondition implements Li private final Map teamMap = new HashMap<>(); public WinconditionPointsAirShip(){ - super("Points", Winconditions.POINTS_AIRSHIP); + super(Winconditions.POINTS_AIRSHIP, "Points"); checkWin = team -> { if (teamMap.get(team).getPoints() > TeamPoints.WIN_POINTS) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWhitelistPercent.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWhitelistPercent.java deleted file mode 100644 index 6607173..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWhitelistPercent.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.fightsystem.winconditions; - -import de.steamwar.fightsystem.Config; - -public class WinconditionWhitelistPercent extends PercentWincondition { - - public WinconditionWhitelistPercent() { - super("WhitelistPercent", Winconditions.WHITELIST_PERCENT); - - testBlock = Config.PercentBlocks::contains; - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index fa91d9c..296cf97 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -28,8 +28,6 @@ public enum Winconditions { CAPTAIN_DEAD, PERCENT_SYSTEM, - WHITELIST_PERCENT, - RELATIVE_PERCENT, POINTS, POINTS_AIRSHIP, From 0fb7a7b8ce353812f787d585c25178ffe0d0e90c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 12 Dec 2023 12:48:56 +0100 Subject: [PATCH 24/36] Change percent damage display to damage health Signed-off-by: Lixfel --- .../steamwar/fightsystem/winconditions/WinconditionPercent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java index 4b7839a..4e19412 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java @@ -58,7 +58,7 @@ public class WinconditionPercent extends Wincondition implements PrintableWincon } public Message getDisplay(FightTeam team) { - return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(100.0 * getPercent(team)) / 100.0)); + return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(100.0 * (100.0 - getPercent(team) / Config.PercentWin)) / 100.0)); } public double getPercent(FightTeam team) { From 5851d5019b15d93e11004502af628ef2b59ad993 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 12 Dec 2023 17:24:07 +0100 Subject: [PATCH 25/36] Fix percent display Signed-off-by: Lixfel --- .../steamwar/fightsystem/winconditions/WinconditionPercent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java index 4e19412..37d3faf 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java @@ -58,7 +58,7 @@ public class WinconditionPercent extends Wincondition implements PrintableWincon } public Message getDisplay(FightTeam team) { - return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(100.0 * (100.0 - getPercent(team) / Config.PercentWin)) / 100.0)); + return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(10000.0 * (1.0 - getPercent(team) / Config.PercentWin)) / 100.0)); } public double getPercent(FightTeam team) { From a17bd4c40136d85ef24ec6643936f6e3b3d6ee17 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 16 Dec 2023 14:08:14 +0100 Subject: [PATCH 26/36] Fix imports Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java | 1 - 1 file changed, 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index d56d7d9..c5adc13 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -21,7 +21,6 @@ package de.steamwar.fightsystem; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; -import de.steamwar.fightsystem.ai.LixfelAI; import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.event.HellsBells; From 29927985b1fd51e436c685ed989bb5931d039a4a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 16 Dec 2023 18:21:33 +0100 Subject: [PATCH 27/36] =?UTF-8?q?Initial=20directional=20quadrant=2045?= =?UTF-8?q?=C2=B0=20hullhider=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../steamwar/fightsystem/utils/HullHider.java | 295 ++++++++++++++++++ .../de/steamwar/fightsystem/utils/Region.java | 12 +- 3 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index c5adc13..fcbafbc 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -108,6 +108,7 @@ public class FightSystem extends JavaPlugin { new EnterHandler(); techHider = new TechHiderWrapper(); + new HullHider(); new FightWorld(); new FightUI(); new FightStatistics(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java new file mode 100644 index 0000000..08ae9c7 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -0,0 +1,295 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2022 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.fightsystem.utils; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.techhider.BlockIds; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPhysicsEvent; + +import java.util.*; +import java.util.function.BiConsumer; + +public class HullHider implements Listener { + + private final Hull blue = new Hull(Fight.getBlueTeam()); + private final Hull red = new Hull(Fight.getRedTeam()); + + //SpawnPackets: PacketPlayOutSpawnEntity, PacketPlayOutSpawnEntityWeather, PacketPlayOutSpawnEntityLiving, PacketPlayOutSpawnEntityPainting, PacketPlayOutSpawnEntityPlayer + //One-timePackets: PacketPlayOutEntityAnimation, PacketPlayOutBlockBreakAnimation, PacketPlayOutEntityStatus, PacketPlayOutEntityPosition, PacketPlayOutEntityPositionAndRotation, PacketPlayOutEntityRotation, PacketPlayOutEntityMovement, EntityHeadLook, EntitySoundEffect, CollectItem, EntityTeleport, + //Permanent: EntityMetadata, AttachEntity, EntityEquipment, SetPassengers, EntityProperties, EntityEffect, RemoveEntityEffect + //Other: Effect, Particle, Explosion + //Death: DestroyEntities + public HullHider() { + //TODO player enters/leaves team + new OneShotStateDependent(ArenaMode.AntiTest, FightState.Schem, () -> Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { + blue.newSchem(); + red.newSchem(); + }, 1)); //TODO better paste timer, SYNC PASTE + new StateDependentListener(ArenaMode.AntiTest, FightState.Schem, this); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onBlockPhysic(BlockPhysicsEvent e) { + Block b = e.getBlock(); + //TODO adapt to 1.8 etc., Look out for Occluding->NotOccluding change + if(e.getSourceBlock() == b && b.getType().isOccluding() && !e.getChangedType().isOccluding()) { + if(blue.region.inRegion(b)) { + blue.updateBlockVisibility(new IntVector(b.getX(), b.getY(), b.getZ())); + blue.printDebug(b.getX(), b.getY(), b.getZ()); + } + if(red.region.inRegion(b)) { + red.updateBlockVisibility(new IntVector(b.getX(), b.getY(), b.getZ())); + red.printDebug(b.getX(), b.getY(), b.getZ()); + } + } + } + + private static class Hull { + private final Region region; + + private final BitSet visibility; + private final Map> blockVisibility = new HashMap<>(); + + private final boolean groundVisible; + + public Hull(FightTeam team) { + this.region = team.getSchemRegion(); + this.groundVisible = region.getMinY() != Config.PlayerRegion.getMinY(); + this.visibility = new BitSet(region.volume()); + + IntVector[] directions; + if(groundVisible) { + directions = new IntVector[] { + new IntVector(1, 0, 0), + new IntVector(-1, 0, 0), + new IntVector(0, 1, 0), + new IntVector(0, -1, 0), + new IntVector(0, 0, 1), + new IntVector(0, 0, -1) + }; + } else { + directions = new IntVector[] { + new IntVector(1, 0, 0), + new IntVector(-1, 0, 0), + new IntVector(0, -1, 0), + new IntVector(0, 0, 1), + new IntVector(0, 0, -1) + }; + } + + for(IntVector direction : directions) { + Map map = new HashMap<>(); + for(int z = (direction.z == 0 ? -1 : 0); z <= 1; z+=2) { + for(int y = (direction.y == 0 ? -1 : 0); y <= 1; y+=2) { + for(int x = (direction.x == 0 ? -1 : 0); x <= 1; x+=2) { + map.put(new IntVector(x, y, z), new BitSet(region.volume())); + } + } + } + blockVisibility.put(direction, map); + } + } + + private final int air = BlockIds.impl.materialToId(Material.AIR); + private final int stone = BlockIds.impl.materialToId(Material.STONE); + private final int red = BlockIds.impl.materialToId(Material.RED_CONCRETE); + public void printDebug(int x, int y, int z) { + int id = coordToId(x, y, z); + + BlockIdWrapper.impl.setBlock(Config.world, x, y + Config.BlueExtendRegion.getSizeY(), z, visibility.get(id) ? (new IntVector(x, y, z).isOccluding() ? red : air) : stone); + } + + public void forEachBorder(BiConsumer f) { + for(int x = region.getMinX(); x < region.getMaxX(); x++) { + for(int z = region.getMinZ(); z < region.getMaxZ(); z++) { + if(groundVisible) + f.accept(new IntVector(x, region.getMinY(), z), new IntVector(0, 1, 0)); + f.accept(new IntVector(x, region.getMaxY()-1, z), new IntVector(0, -1, 0)); + } + } + + for(int x = region.getMinX(); x < region.getMaxX(); x++) { + for(int y = region.getMinY(); y < region.getMaxY(); y++) { + f.accept(new IntVector(x, y, region.getMinZ()), new IntVector(0, 0, 1)); + f.accept(new IntVector(x, y, region.getMaxZ()-1), new IntVector(0, 0, -1)); + } + } + + for(int z = region.getMinZ(); z < region.getMaxZ(); z++) { + for(int y = region.getMinY(); y < region.getMaxY(); y++) { + f.accept(new IntVector(region.getMinX(), y, z), new IntVector(1, 0, 0)); + f.accept(new IntVector(region.getMaxX()-1, y, z), new IntVector(-1, 0, 0)); + } + } + } + + public void newSchem() { + visibility.clear(); + for(Map direction : blockVisibility.values()) { + for(BitSet set : direction.values()) + set.clear(); + } + + long start = System.currentTimeMillis(); + forEachBorder(this::sideInit); + System.out.println("finish " + (System.currentTimeMillis() - start) + " ms " + visibility.stream().count()); + + region.forEach(this::printDebug); + } + + private void sideInit(IntVector root, IntVector direction) { + for(Map.Entry quadrant : blockVisibility.get(direction).entrySet()) { + checkBlock(root, direction, quadrant.getKey(), quadrant.getValue()); + } + } + + private void checkBlock(IntVector root, IntVector direction, IntVector quadrant, BitSet quadVisibility) { + Set checkSet = new HashSet<>(); + checkSet.add(root); + + while(!checkSet.isEmpty()) { + Set nextSet = new HashSet<>(); + + for(IntVector block : checkSet) { + if(!block.inRegion(region)) + continue; + + int id = block.toId(region); + if(quadVisibility.get(id)) + continue; + + quadVisibility.set(id); + visibility.set(id); + if(block.isOccluding()) + continue; + + IntVector neighbour = block.add(direction); + nextSet.add(neighbour); + boolean neigbourTransparent = !neighbour.isOccluding(); + if(direction.x == 0 && (neigbourTransparent || !block.add(quadrant.x, 0, 0).isOccluding())) { + nextSet.add(neighbour.add(quadrant.x, 0, 0)); + if(!neighbour.add(quadrant.x, 0, 0).isOccluding()) + nextSet.add(neighbour.add(quadrant)); + } + + if(direction.y == 0 && (neigbourTransparent || !block.add(0, quadrant.y, 0).isOccluding())){ + nextSet.add(neighbour.add(0, quadrant.y, 0)); + if(!neighbour.add(0, quadrant.y, 0).isOccluding()) + nextSet.add(neighbour.add(quadrant)); + } + + if(direction.z == 0 && (neigbourTransparent || !block.add(0, 0, quadrant.z).isOccluding())) { + nextSet.add(neighbour.add(0, 0, quadrant.z)); + if(!neighbour.add(0, 0, quadrant.z).isOccluding()) + nextSet.add(neighbour.add(quadrant)); + } + } + + checkSet = nextSet; + } + } + + private void updateBlockVisibility(IntVector root) { + if(!root.inRegion(region)) + return; + + int id = root.toId(region); + for(Map.Entry> direction : blockVisibility.entrySet()) { + for(Map.Entry quadrant : direction.getValue().entrySet()) { + if(quadrant.getValue().get(id)) { + quadrant.getValue().clear(id); + checkBlock(root, direction.getKey(), quadrant.getKey(), quadrant.getValue()); + } + } + } + } + + private int coordToId(int x, int y, int z) { + return regionCoordToId(x - region.getMinX(), y - region.getMinY(), z - region.getMinZ()); + } + private int regionCoordToId(int x, int y, int z) { + return (y * region.getSizeZ() + z) * region.getSizeX() + x; + } + } + + private static class IntVector { + private final int x; + private final int y; + private final int z; + + public IntVector(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public boolean inRegion(Region region) { + return region.inRegion(x, y, z); + } + + public int toId(Region region) { + return ((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX()); + } + + public boolean isOccluding() { + return Config.world.getBlockAt(x, y, z).getType().isOccluding(); //TODO techhiderblocks? + } + + public IntVector add(int x, int y, int z) { + return new IntVector(this.x + x, this.y + y, this.z + z); + } + + public IntVector add(IntVector v) { + return add(v.x, v.y, v.z); + } + + @Override + public int hashCode() { + return y << 24 ^ x << 12 ^ z; + } + + @Override + public boolean equals(Object o) { + if(o == null || this.getClass() != o.getClass()) + return false; + + IntVector v = (IntVector) o; + return x == v.x && y == v.y && z == v.z; + } + + @Override + public String toString() { + return x + "," + y + "," + z; + } + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index 6789d14..1308f40 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -76,6 +76,10 @@ public class Region { return maxX - minX; } + public int getSizeY() { + return maxY - minY; + } + public int getSizeZ() { return maxZ - minZ; } @@ -110,7 +114,7 @@ public class Region { public void forEach(TriConsumer executor) { for(int x = minX; x < maxX; x++) { for(int y = minY; y < maxY; y++) { - for (int z = minZ; z <= maxZ; z++) { + for (int z = minZ; z < maxZ; z++) { executor.accept(x, y, z); } } @@ -146,13 +150,17 @@ public class Region { } public boolean in2dRegion(int x, int z) { - return minX <= x && x < maxX && minZ <= z && z <= maxZ; + return minX <= x && x < maxX && minZ <= z && z < maxZ; } public boolean inRegion(Block block){ return in2dRegion(block) && minY <= block.getY() && block.getY() < maxY; } + public boolean inRegion(int x, int y, int z) { + return in2dRegion(x, z) && minY <= y && y < maxY; + } + public interface TriConsumer{ void accept(T x, V y, U z); } From 4d5f4e9be6c1e411551d1390ac44359a411df7cc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 16 Dec 2023 21:59:56 +0100 Subject: [PATCH 28/36] =?UTF-8?q?Fast=20recursive=2045=C2=B0=20approx=20hu?= =?UTF-8?q?llhider=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 7 +- .../fightsystem/fight/FightSchematic.java | 2 +- .../steamwar/fightsystem/utils/HullHider.java | 217 +++++++++--------- 3 files changed, 111 insertions(+), 115 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index fcbafbc..48fe546 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -54,6 +54,7 @@ public class FightSystem extends JavaPlugin { private FightTeam lastWinner; private String lastWinreason; private TechHiderWrapper techHider; + private HullHider hullHider; @Override public void onLoad() { @@ -108,7 +109,7 @@ public class FightSystem extends JavaPlugin { new EnterHandler(); techHider = new TechHiderWrapper(); - new HullHider(); + hullHider = new HullHider(); new FightWorld(); new FightUI(); new FightStatistics(); @@ -219,6 +220,10 @@ public class FightSystem extends JavaPlugin { return plugin.techHider; } + public static HullHider getHullHider() { + return plugin.hullHider; + } + public static void shutdown() { //Staggered kick to prevent lobby overloading if(Bukkit.getOnlinePlayers().isEmpty()){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index ee1ab0a..e22c50c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -45,7 +45,6 @@ import java.io.IOException; import java.util.List; import java.util.Random; import java.util.logging.Level; -import java.util.stream.Stream; public class FightSchematic extends StateDependent { @@ -149,6 +148,7 @@ public class FightSchematic extends StateDependent { ).add(new Vector(rotate ? 1 : 0, 0, rotate ? 1 : 0)), new AffineTransform().rotateY(rotate ? 180 : 0) ); + FightSystem.getHullHider().initialize(team); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 08ae9c7..775c34d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -19,16 +19,13 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.techhider.BlockIds; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; @@ -38,11 +35,11 @@ import org.bukkit.event.block.BlockPhysicsEvent; import java.util.*; import java.util.function.BiConsumer; +import java.util.logging.Level; public class HullHider implements Listener { - private final Hull blue = new Hull(Fight.getBlueTeam()); - private final Hull red = new Hull(Fight.getRedTeam()); + private final Map hulls = new HashMap<>(); //SpawnPackets: PacketPlayOutSpawnEntity, PacketPlayOutSpawnEntityWeather, PacketPlayOutSpawnEntityLiving, PacketPlayOutSpawnEntityPainting, PacketPlayOutSpawnEntityPlayer //One-timePackets: PacketPlayOutEntityAnimation, PacketPlayOutBlockBreakAnimation, PacketPlayOutEntityStatus, PacketPlayOutEntityPosition, PacketPlayOutEntityPositionAndRotation, PacketPlayOutEntityRotation, PacketPlayOutEntityMovement, EntityHeadLook, EntitySoundEffect, CollectItem, EntityTeleport, @@ -50,41 +47,40 @@ public class HullHider implements Listener { //Other: Effect, Particle, Explosion //Death: DestroyEntities public HullHider() { + if(TechHiderWrapper.ENABLED) + Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); + + new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this); //TODO player enters/leaves team - new OneShotStateDependent(ArenaMode.AntiTest, FightState.Schem, () -> Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { - blue.newSchem(); - red.newSchem(); - }, 1)); //TODO better paste timer, SYNC PASTE - new StateDependentListener(ArenaMode.AntiTest, FightState.Schem, this); + } + + public void initialize(FightTeam team) { + if(!TechHiderWrapper.ENABLED) + return; + + hulls.get(team).initialize(); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPhysic(BlockPhysicsEvent e) { - Block b = e.getBlock(); - //TODO adapt to 1.8 etc., Look out for Occluding->NotOccluding change - if(e.getSourceBlock() == b && b.getType().isOccluding() && !e.getChangedType().isOccluding()) { - if(blue.region.inRegion(b)) { - blue.updateBlockVisibility(new IntVector(b.getX(), b.getY(), b.getZ())); - blue.printDebug(b.getX(), b.getY(), b.getZ()); - } - if(red.region.inRegion(b)) { - red.updateBlockVisibility(new IntVector(b.getX(), b.getY(), b.getZ())); - red.printDebug(b.getX(), b.getY(), b.getZ()); - } + if(FlatteningWrapper.impl.doRecord(e)) { + hulls.values().forEach(hull -> hull.updateBlockVisibility(e.getBlock(), e.getChangedType())); } } private static class Hull { private final Region region; + private final boolean groundVisible; + private final BitSet occluding; private final BitSet visibility; private final Map> blockVisibility = new HashMap<>(); - private final boolean groundVisible; public Hull(FightTeam team) { this.region = team.getSchemRegion(); this.groundVisible = region.getMinY() != Config.PlayerRegion.getMinY(); + this.occluding = new BitSet(region.volume()); this.visibility = new BitSet(region.volume()); IntVector[] directions; @@ -107,6 +103,7 @@ public class HullHider implements Listener { }; } + // Generate quadrants for each direction for(IntVector direction : directions) { Map map = new HashMap<>(); for(int z = (direction.z == 0 ? -1 : 0); z <= 1; z+=2) { @@ -120,16 +117,62 @@ public class HullHider implements Listener { } } + public void initialize() { + visibility.clear(); + occluding.clear(); + for(Map direction : blockVisibility.values()) { + for(BitSet set : direction.values()) + set.clear(); + } + + long start = System.currentTimeMillis(); + region.forEach((x, y, z) -> { + IntVector block = new IntVector(x, y, z); + if(Config.world.getBlockAt(x, y, z).getType().isOccluding()) //TODO more accurate check + occluding.set(block.toId(region)); + }); + forEachBorder((root, direction) -> { + for(Map.Entry quadrant : blockVisibility.get(direction).entrySet()) { + checkBlock(root, direction, quadrant.getKey(), quadrant.getValue()); + } + }); + FightSystem.getPlugin().getLogger().log(Level.INFO, () -> "[HullHider] initialisation finished: " + (System.currentTimeMillis() - start) + " ms, visible blocks: " + visibility.stream().count()); + + region.forEach(this::printDebug); + } + + public void updateBlockVisibility(Block b, Material changedType) { + IntVector root = new IntVector(b.getX(), b.getY(), b.getZ()); + if(root.notInRegion(region)) + return; + + int id = root.toId(region); + if(!occluding.get(id) || changedType.isOccluding()) //TODO more accurate check + return; + + occluding.clear(id); + for(Map.Entry> direction : blockVisibility.entrySet()) { + for(Map.Entry quadrant : direction.getValue().entrySet()) { + if(quadrant.getValue().get(id)) { + quadrant.getValue().clear(id); + checkBlock(root, direction.getKey(), quadrant.getKey(), quadrant.getValue()); + } + } + } + + printDebug(root.x, root.y, root.z); + } + private final int air = BlockIds.impl.materialToId(Material.AIR); private final int stone = BlockIds.impl.materialToId(Material.STONE); private final int red = BlockIds.impl.materialToId(Material.RED_CONCRETE); - public void printDebug(int x, int y, int z) { - int id = coordToId(x, y, z); + private void printDebug(int x, int y, int z) { + int id = new IntVector(x, y, z).toId(region); - BlockIdWrapper.impl.setBlock(Config.world, x, y + Config.BlueExtendRegion.getSizeY(), z, visibility.get(id) ? (new IntVector(x, y, z).isOccluding() ? red : air) : stone); + BlockIdWrapper.impl.setBlock(Config.world, x, y + Config.BlueExtendRegion.getSizeY(), z, visibility.get(id) ? (occluding.get(id) ? red : air) : stone); } - public void forEachBorder(BiConsumer f) { + private void forEachBorder(BiConsumer f) { for(int x = region.getMinX(); x < region.getMaxX(); x++) { for(int z = region.getMinZ(); z < region.getMaxZ(); z++) { if(groundVisible) @@ -153,92 +196,44 @@ public class HullHider implements Listener { } } - public void newSchem() { - visibility.clear(); - for(Map direction : blockVisibility.values()) { - for(BitSet set : direction.values()) - set.clear(); - } - - long start = System.currentTimeMillis(); - forEachBorder(this::sideInit); - System.out.println("finish " + (System.currentTimeMillis() - start) + " ms " + visibility.stream().count()); - - region.forEach(this::printDebug); - } - - private void sideInit(IntVector root, IntVector direction) { - for(Map.Entry quadrant : blockVisibility.get(direction).entrySet()) { - checkBlock(root, direction, quadrant.getKey(), quadrant.getValue()); - } - } - - private void checkBlock(IntVector root, IntVector direction, IntVector quadrant, BitSet quadVisibility) { - Set checkSet = new HashSet<>(); - checkSet.add(root); - - while(!checkSet.isEmpty()) { - Set nextSet = new HashSet<>(); - - for(IntVector block : checkSet) { - if(!block.inRegion(region)) - continue; - - int id = block.toId(region); - if(quadVisibility.get(id)) - continue; - - quadVisibility.set(id); - visibility.set(id); - if(block.isOccluding()) - continue; - - IntVector neighbour = block.add(direction); - nextSet.add(neighbour); - boolean neigbourTransparent = !neighbour.isOccluding(); - if(direction.x == 0 && (neigbourTransparent || !block.add(quadrant.x, 0, 0).isOccluding())) { - nextSet.add(neighbour.add(quadrant.x, 0, 0)); - if(!neighbour.add(quadrant.x, 0, 0).isOccluding()) - nextSet.add(neighbour.add(quadrant)); - } - - if(direction.y == 0 && (neigbourTransparent || !block.add(0, quadrant.y, 0).isOccluding())){ - nextSet.add(neighbour.add(0, quadrant.y, 0)); - if(!neighbour.add(0, quadrant.y, 0).isOccluding()) - nextSet.add(neighbour.add(quadrant)); - } - - if(direction.z == 0 && (neigbourTransparent || !block.add(0, 0, quadrant.z).isOccluding())) { - nextSet.add(neighbour.add(0, 0, quadrant.z)); - if(!neighbour.add(0, 0, quadrant.z).isOccluding()) - nextSet.add(neighbour.add(quadrant)); - } - } - - checkSet = nextSet; - } - } - - private void updateBlockVisibility(IntVector root) { - if(!root.inRegion(region)) + private void checkBlock(IntVector block, IntVector direction, IntVector quadrant, BitSet quadVisibility) { + if(block.notInRegion(region)) return; - int id = root.toId(region); - for(Map.Entry> direction : blockVisibility.entrySet()) { - for(Map.Entry quadrant : direction.getValue().entrySet()) { - if(quadrant.getValue().get(id)) { - quadrant.getValue().clear(id); - checkBlock(root, direction.getKey(), quadrant.getKey(), quadrant.getValue()); - } - } + int id = block.toId(region); + if(quadVisibility.get(id)) + return; + + quadVisibility.set(id); + visibility.set(id); + if(occluding.get(id)) + return; + + IntVector neighbour = block.add(direction); + checkBlock(neighbour, direction, quadrant, quadVisibility); + boolean neigbourTransparent = boundedNonOccluding(neighbour); + boolean diagonalReachable = false; + if(direction.x == 0 && (neigbourTransparent || boundedNonOccluding(block.add(quadrant.x, 0, 0)))) { + checkBlock(neighbour.add(quadrant.x, 0, 0), direction, quadrant, quadVisibility); + diagonalReachable = boundedNonOccluding(neighbour.add(quadrant.x, 0, 0)); } + + if(direction.y == 0 && (neigbourTransparent || boundedNonOccluding(block.add(0, quadrant.y, 0)))) { + checkBlock(neighbour.add(0, quadrant.y, 0), direction, quadrant, quadVisibility); + diagonalReachable = diagonalReachable || boundedNonOccluding(neighbour.add(0, quadrant.y, 0)); + } + + if(direction.z == 0 && (neigbourTransparent || boundedNonOccluding(block.add(0, 0, quadrant.z)))) { + checkBlock(neighbour.add(0, 0, quadrant.z), direction, quadrant, quadVisibility); + diagonalReachable = diagonalReachable || boundedNonOccluding(neighbour.add(0, 0, quadrant.z)); + } + + if(diagonalReachable) + checkBlock(neighbour.add(quadrant), direction, quadrant, quadVisibility); } - private int coordToId(int x, int y, int z) { - return regionCoordToId(x - region.getMinX(), y - region.getMinY(), z - region.getMinZ()); - } - private int regionCoordToId(int x, int y, int z) { - return (y * region.getSizeZ() + z) * region.getSizeX() + x; + private boolean boundedNonOccluding(IntVector block) { + return !(block.notInRegion(region) || occluding.get(block.toId(region))); } } @@ -253,18 +248,14 @@ public class HullHider implements Listener { this.z = z; } - public boolean inRegion(Region region) { - return region.inRegion(x, y, z); + public boolean notInRegion(Region region) { + return !region.inRegion(x, y, z); } public int toId(Region region) { return ((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX()); } - public boolean isOccluding() { - return Config.world.getBlockAt(x, y, z).getType().isOccluding(); //TODO techhiderblocks? - } - public IntVector add(int x, int y, int z) { return new IntVector(this.x + x, this.y + y, this.z + z); } From 5fab7e540422059a2c13e9698115f50e2997de02 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Dec 2023 16:18:20 +0100 Subject: [PATCH 29/36] Untested entity 1.18+ hullhiding Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 4 +- .../steamwar/fightsystem/fight/FightTeam.java | 2 + .../fightsystem/listener/ArrowStopper.java | 2 +- .../fightsystem/record/PacketProcessor.java | 2 +- .../de/steamwar/fightsystem/utils/Hull.java | 325 ++++++++++++++++++ .../steamwar/fightsystem/utils/HullHider.java | 298 +++++----------- .../fightsystem/utils/TechHiderWrapper.java | 3 +- 7 files changed, 410 insertions(+), 226 deletions(-) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 331491f..b1030f7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -120,7 +120,7 @@ public class Config { //tech hider parameter public static final boolean TechhiderActive; - public static final Set HiddenBlocks; + public static final Set HiddenBlocks; public static final Set HiddenBlockEntities; public static final String ObfuscateWith; @@ -214,7 +214,7 @@ public class Config { TechhiderActive = config.getBoolean("Techhider.Active", false); ObfuscateWith = config.getString("Techhider.ObfuscateWith", "end_stone").toUpperCase(); - HiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks"))); + HiddenBlocks = config.getStringList("Techhider.HiddenBlocks").stream().map(String::toUpperCase).map(Material::getMaterial).collect(Collectors.toSet()); HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); if(schemsizeX < 0){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 54cad8e..6efb3fd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -275,6 +275,7 @@ public class FightTeam { BountifulWrapper.impl.setAttackSpeed(player); player.setFoodLevel(20); player.getInventory().clear(); + FightSystem.getHullHider().removePlayer(this, player); if(FightState.Spectate.contains(FightState.getFightState())) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); @@ -318,6 +319,7 @@ public class FightTeam { player.getInventory().clear(); if(player.isOnline()){ + FightSystem.getHullHider().addPlayer(this, player); FightSystem.getTechHider().reloadChunks(player, chunksToReload, true); if(ArenaMode.VariableTeams.contains(Config.mode)) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index e7b4d01..3fd7f7d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -85,7 +85,7 @@ public class ArrowStopper { } private boolean checkBlock(Block block) { - return Config.HiddenBlocks.contains(block.getType().name().toLowerCase()); + return Config.HiddenBlocks.contains(block.getType()); } private boolean invalidEntity(Projectile entity) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index d7c31fd..f50007a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -88,7 +88,7 @@ public class PacketProcessor implements Listener { private final PacketSource source; private final BukkitTask task; private final LinkedList syncList = new LinkedList<>(); - private final Set hiddenBlockIds = Config.HiddenBlocks.stream().map(String::toUpperCase).map(Material::getMaterial).flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); + private final Set hiddenBlockIds = Config.HiddenBlocks.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); private final int obfuscateWith = BlockIds.impl.materialToId(Material.getMaterial(Config.ObfuscateWith.toUpperCase())); private final FreezeWorld freezer = new FreezeWorld(); private final REntityServer entityServer = new REntityServer(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java new file mode 100644 index 0000000..904c0cd --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -0,0 +1,325 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.fightsystem.utils; + +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.techhider.BlockIds; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.function.BiConsumer; +import java.util.logging.Level; + +public class Hull { + + private static boolean isOccluding(Material material) { + return material.isOccluding() || Config.HiddenBlocks.contains(material); + } + + private final Region region; + private final boolean groundVisible; + + private final BitSet occluding; + private final BitSet visibility; + private final Map> blockVisibility = new HashMap<>(); + + private final Set players = new HashSet<>(); + private final Set entities = new HashSet<>(); + + public Hull(FightTeam team) { + this.region = team.getSchemRegion(); + this.groundVisible = region.getMinY() != Config.PlayerRegion.getMinY(); + this.occluding = new BitSet(region.volume()); + this.visibility = new BitSet(region.volume()); + + IntVector[] directions; + if (groundVisible) { + directions = new IntVector[]{ + new IntVector(1, 0, 0), + new IntVector(-1, 0, 0), + new IntVector(0, 1, 0), + new IntVector(0, -1, 0), + new IntVector(0, 0, 1), + new IntVector(0, 0, -1) + }; + } else { + directions = new IntVector[]{ + new IntVector(1, 0, 0), + new IntVector(-1, 0, 0), + new IntVector(0, -1, 0), + new IntVector(0, 0, 1), + new IntVector(0, 0, -1) + }; + } + + // Generate quadrants for each direction + for (IntVector direction : directions) { + Map map = new HashMap<>(); + for (int z = (direction.z == 0 ? -1 : 0); z <= 1; z += 2) { + for (int y = (direction.y == 0 ? -1 : 0); y <= 1; y += 2) { + for (int x = (direction.x == 0 ? -1 : 0); x <= 1; x += 2) { + map.put(new IntVector(x, y, z), new BitSet(region.volume())); + } + } + } + blockVisibility.put(direction, map); + } + } + + @SuppressWarnings("deprecation") + public void addPlayer(Player player, boolean activeHiding) { + if(players.add(player) && activeHiding) { + for(Entity entity : entities) + player.hideEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + } + } + + @SuppressWarnings("deprecation") + public void removePlayer(Player player, boolean activeRemoval) { + if(players.remove(player) && activeRemoval) { + for(Entity entity : entities) + player.showEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + } + } + + public void checkEntity(Entity entity) { + Location location = entity.getLocation(); + if(region.inRegion(location) && !visibility.get(new IntVector(location).toId(region))) { //TODO more precise + if(entities.add(entity)) { + for(Player player : players) + player.hideEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + } + } else { + if(entities.remove(entity)) { + for(Player player : players) + player.showEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + } + } + } + + public void removeEntity(Entity entity) { + entities.remove(entity); + } + + public void initialize() { + visibility.clear(); + occluding.clear(); + for (Map direction : blockVisibility.values()) { + for (BitSet set : direction.values()) + set.clear(); + } + + long start = System.currentTimeMillis(); + region.forEach((x, y, z) -> { + IntVector block = new IntVector(x, y, z); + if (isOccluding(Config.world.getBlockAt(x, y, z).getType())) + occluding.set(block.toId(region)); + }); + forEachBorder((root, direction) -> { + for (Map.Entry quadrant : blockVisibility.get(direction).entrySet()) { + checkBlock(new NullList<>(), root, direction, quadrant.getKey(), quadrant.getValue()); + } + }); + FightSystem.getPlugin().getLogger().log(Level.INFO, () -> "[HullHider] initialisation finished: " + (System.currentTimeMillis() - start) + " ms, visible blocks: " + visibility.cardinality()); + + region.forEach(this::printDebug); + } + + public void updateBlockVisibility(Block b, Material changedType) { + IntVector root = new IntVector(b.getX(), b.getY(), b.getZ()); + if (root.notInRegion(region)) + return; + + int id = root.toId(region); + if (!occluding.get(id) || isOccluding(changedType)) + return; + + List uncovered = new ArrayList<>(); + occluding.clear(id); + for (Map.Entry> direction : blockVisibility.entrySet()) { + for (Map.Entry quadrant : direction.getValue().entrySet()) { + if (quadrant.getValue().get(id)) { + quadrant.getValue().clear(id); + checkBlock(uncovered, root, direction.getKey(), quadrant.getKey(), quadrant.getValue()); + } + } + } + + for (IntVector block : uncovered) + printDebug(block.x, block.y, block.z); + + //TODO uncover entities + } + + private final int air = BlockIds.impl.materialToId(Material.AIR); + private final int stone = BlockIds.impl.materialToId(Material.STONE); + private final int red = BlockIds.impl.materialToId(Material.RED_CONCRETE); + + private void printDebug(int x, int y, int z) { + int id = new IntVector(x, y, z).toId(region); + + BlockIdWrapper.impl.setBlock(Config.world, x, y + Config.BlueExtendRegion.getSizeY(), z, visibility.get(id) ? (occluding.get(id) ? red : air) : stone); + } + + private void forEachBorder(BiConsumer f) { + for (int x = region.getMinX(); x < region.getMaxX(); x++) { + for (int z = region.getMinZ(); z < region.getMaxZ(); z++) { + if (groundVisible) + f.accept(new IntVector(x, region.getMinY(), z), new IntVector(0, 1, 0)); + f.accept(new IntVector(x, region.getMaxY() - 1, z), new IntVector(0, -1, 0)); + } + } + + for (int x = region.getMinX(); x < region.getMaxX(); x++) { + for (int y = region.getMinY(); y < region.getMaxY(); y++) { + f.accept(new IntVector(x, y, region.getMinZ()), new IntVector(0, 0, 1)); + f.accept(new IntVector(x, y, region.getMaxZ() - 1), new IntVector(0, 0, -1)); + } + } + + for (int z = region.getMinZ(); z < region.getMaxZ(); z++) { + for (int y = region.getMinY(); y < region.getMaxY(); y++) { + f.accept(new IntVector(region.getMinX(), y, z), new IntVector(1, 0, 0)); + f.accept(new IntVector(region.getMaxX() - 1, y, z), new IntVector(-1, 0, 0)); + } + } + } + + private void checkBlock(List uncovered, IntVector block, IntVector direction, IntVector quadrant, BitSet quadVisibility) { + if (block.notInRegion(region)) + return; + + int id = block.toId(region); + if (quadVisibility.get(id)) + return; + + quadVisibility.set(id); + if (!visibility.get(id)) { + visibility.set(id); + uncovered.add(block); + } + + if (occluding.get(id)) + return; + + IntVector neighbour = block.add(direction); + checkBlock(uncovered, neighbour, direction, quadrant, quadVisibility); + boolean neigbourTransparent = boundedNonOccluding(neighbour); + boolean diagonalReachable = false; + if (direction.x == 0 && (neigbourTransparent || boundedNonOccluding(block.add(quadrant.x, 0, 0)))) { + checkBlock(uncovered, neighbour.add(quadrant.x, 0, 0), direction, quadrant, quadVisibility); + diagonalReachable = boundedNonOccluding(neighbour.add(quadrant.x, 0, 0)); + } + + if (direction.y == 0 && (neigbourTransparent || boundedNonOccluding(block.add(0, quadrant.y, 0)))) { + checkBlock(uncovered, neighbour.add(0, quadrant.y, 0), direction, quadrant, quadVisibility); + diagonalReachable = diagonalReachable || boundedNonOccluding(neighbour.add(0, quadrant.y, 0)); + } + + if (direction.z == 0 && (neigbourTransparent || boundedNonOccluding(block.add(0, 0, quadrant.z)))) { + checkBlock(uncovered, neighbour.add(0, 0, quadrant.z), direction, quadrant, quadVisibility); + diagonalReachable = diagonalReachable || boundedNonOccluding(neighbour.add(0, 0, quadrant.z)); + } + + if (diagonalReachable) + checkBlock(uncovered, neighbour.add(quadrant), direction, quadrant, quadVisibility); + } + + private boolean boundedNonOccluding(IntVector block) { + return !(block.notInRegion(region) || occluding.get(block.toId(region))); + } + + + private static class IntVector { + private final int x; + private final int y; + private final int z; + + public IntVector(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public IntVector(Location location) { + this.x = location.getBlockX(); + this.y = location.getBlockY(); + this.z = location.getBlockZ(); + } + + public boolean notInRegion(Region region) { + return !region.inRegion(x, y, z); + } + + public int toId(Region region) { + return ((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX()); + } + + public IntVector add(int x, int y, int z) { + return new IntVector(this.x + x, this.y + y, this.z + z); + } + + public IntVector add(IntVector v) { + return add(v.x, v.y, v.z); + } + + @Override + public int hashCode() { + return y << 24 ^ x << 12 ^ z; + } + + @Override + public boolean equals(Object o) { + if(o == null || this.getClass() != o.getClass()) + return false; + + IntVector v = (IntVector) o; + return x == v.x && y == v.y && z == v.z; + } + + @Override + public String toString() { + return x + "," + y + "," + z; + } + } + + private static class NullList extends AbstractList { + @Override + public void add(int index, E element) { + // Straight to /dev/null! + } + + @Override + public E get(int index) { + return null; + } + + @Override + public int size() { + return 0; + } + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 775c34d..1291202 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -19,23 +19,27 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.techhider.BlockIds; -import org.bukkit.Material; -import org.bukkit.block.Block; +import de.steamwar.fightsystem.states.StateDependentTask; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; -import java.util.*; -import java.util.function.BiConsumer; -import java.util.logging.Level; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; public class HullHider implements Listener { @@ -51,7 +55,18 @@ public class HullHider implements Listener { Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this); - //TODO player enters/leaves team + new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) { + @Override + public void enable() { + Bukkit.getOnlinePlayers().forEach(player -> addPlayer(player, true)); + } + + @Override + public void disable() { + Bukkit.getOnlinePlayers().forEach(player -> removePlayer(player, true)); + } + }; + new StateDependentTask(TechHiderWrapper.ENABLED, FightState.Schem, this::onTick, 0, 1); } public void initialize(FightTeam team) { @@ -61,226 +76,69 @@ public class HullHider implements Listener { hulls.get(team).initialize(); } + + public void addPlayer(FightTeam team, Player player) { + if(!TechHiderWrapper.ENABLED) + return; + + hulls.get(team).addPlayer(player, true); + } + + public void removePlayer(FightTeam team, Player player) { + if(!TechHiderWrapper.ENABLED) + return; + + hulls.get(team).removePlayer(player, true); + } + + @EventHandler(priority = EventPriority.HIGH) + public void onJoin(PlayerJoinEvent e) { + addPlayer(e.getPlayer(), false); + } + + @EventHandler + public void onLeave(PlayerQuitEvent e) { + removePlayer(e.getPlayer(), false); + } + + private void addPlayer(Player player, boolean activeHiding) { + FightTeam team = Fight.getPlayerTeam(player); + for(Map.Entry hull : hulls.entrySet()) { + if(hull.getKey() == team) + continue; + + hull.getValue().addPlayer(player, activeHiding); + } + } + + private void removePlayer(Player player, boolean activeRemoval) { + hulls.values().forEach(hull -> hull.removePlayer(player, activeRemoval)); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPhysic(BlockPhysicsEvent e) { if(FlatteningWrapper.impl.doRecord(e)) { - hulls.values().forEach(hull -> hull.updateBlockVisibility(e.getBlock(), e.getChangedType())); + for (Hull hull : hulls.values()) + hull.updateBlockVisibility(e.getBlock(), e.getChangedType()); } } - private static class Hull { - private final Region region; - private final boolean groundVisible; - private final BitSet occluding; - private final BitSet visibility; - private final Map> blockVisibility = new HashMap<>(); - - - public Hull(FightTeam team) { - this.region = team.getSchemRegion(); - this.groundVisible = region.getMinY() != Config.PlayerRegion.getMinY(); - this.occluding = new BitSet(region.volume()); - this.visibility = new BitSet(region.volume()); - - IntVector[] directions; - if(groundVisible) { - directions = new IntVector[] { - new IntVector(1, 0, 0), - new IntVector(-1, 0, 0), - new IntVector(0, 1, 0), - new IntVector(0, -1, 0), - new IntVector(0, 0, 1), - new IntVector(0, 0, -1) - }; - } else { - directions = new IntVector[] { - new IntVector(1, 0, 0), - new IntVector(-1, 0, 0), - new IntVector(0, -1, 0), - new IntVector(0, 0, 1), - new IntVector(0, 0, -1) - }; - } - - // Generate quadrants for each direction - for(IntVector direction : directions) { - Map map = new HashMap<>(); - for(int z = (direction.z == 0 ? -1 : 0); z <= 1; z+=2) { - for(int y = (direction.y == 0 ? -1 : 0); y <= 1; y+=2) { - for(int x = (direction.x == 0 ? -1 : 0); x <= 1; x+=2) { - map.put(new IntVector(x, y, z), new BitSet(region.volume())); - } - } - } - blockVisibility.put(direction, map); - } - } - - public void initialize() { - visibility.clear(); - occluding.clear(); - for(Map direction : blockVisibility.values()) { - for(BitSet set : direction.values()) - set.clear(); - } - - long start = System.currentTimeMillis(); - region.forEach((x, y, z) -> { - IntVector block = new IntVector(x, y, z); - if(Config.world.getBlockAt(x, y, z).getType().isOccluding()) //TODO more accurate check - occluding.set(block.toId(region)); - }); - forEachBorder((root, direction) -> { - for(Map.Entry quadrant : blockVisibility.get(direction).entrySet()) { - checkBlock(root, direction, quadrant.getKey(), quadrant.getValue()); - } - }); - FightSystem.getPlugin().getLogger().log(Level.INFO, () -> "[HullHider] initialisation finished: " + (System.currentTimeMillis() - start) + " ms, visible blocks: " + visibility.stream().count()); - - region.forEach(this::printDebug); - } - - public void updateBlockVisibility(Block b, Material changedType) { - IntVector root = new IntVector(b.getX(), b.getY(), b.getZ()); - if(root.notInRegion(region)) - return; - - int id = root.toId(region); - if(!occluding.get(id) || changedType.isOccluding()) //TODO more accurate check - return; - - occluding.clear(id); - for(Map.Entry> direction : blockVisibility.entrySet()) { - for(Map.Entry quadrant : direction.getValue().entrySet()) { - if(quadrant.getValue().get(id)) { - quadrant.getValue().clear(id); - checkBlock(root, direction.getKey(), quadrant.getKey(), quadrant.getValue()); - } - } - } - - printDebug(root.x, root.y, root.z); - } - - private final int air = BlockIds.impl.materialToId(Material.AIR); - private final int stone = BlockIds.impl.materialToId(Material.STONE); - private final int red = BlockIds.impl.materialToId(Material.RED_CONCRETE); - private void printDebug(int x, int y, int z) { - int id = new IntVector(x, y, z).toId(region); - - BlockIdWrapper.impl.setBlock(Config.world, x, y + Config.BlueExtendRegion.getSizeY(), z, visibility.get(id) ? (occluding.get(id) ? red : air) : stone); - } - - private void forEachBorder(BiConsumer f) { - for(int x = region.getMinX(); x < region.getMaxX(); x++) { - for(int z = region.getMinZ(); z < region.getMaxZ(); z++) { - if(groundVisible) - f.accept(new IntVector(x, region.getMinY(), z), new IntVector(0, 1, 0)); - f.accept(new IntVector(x, region.getMaxY()-1, z), new IntVector(0, -1, 0)); - } - } - - for(int x = region.getMinX(); x < region.getMaxX(); x++) { - for(int y = region.getMinY(); y < region.getMaxY(); y++) { - f.accept(new IntVector(x, y, region.getMinZ()), new IntVector(0, 0, 1)); - f.accept(new IntVector(x, y, region.getMaxZ()-1), new IntVector(0, 0, -1)); - } - } - - for(int z = region.getMinZ(); z < region.getMaxZ(); z++) { - for(int y = region.getMinY(); y < region.getMaxY(); y++) { - f.accept(new IntVector(region.getMinX(), y, z), new IntVector(1, 0, 0)); - f.accept(new IntVector(region.getMaxX()-1, y, z), new IntVector(-1, 0, 0)); - } - } - } - - private void checkBlock(IntVector block, IntVector direction, IntVector quadrant, BitSet quadVisibility) { - if(block.notInRegion(region)) - return; - - int id = block.toId(region); - if(quadVisibility.get(id)) - return; - - quadVisibility.set(id); - visibility.set(id); - if(occluding.get(id)) - return; - - IntVector neighbour = block.add(direction); - checkBlock(neighbour, direction, quadrant, quadVisibility); - boolean neigbourTransparent = boundedNonOccluding(neighbour); - boolean diagonalReachable = false; - if(direction.x == 0 && (neigbourTransparent || boundedNonOccluding(block.add(quadrant.x, 0, 0)))) { - checkBlock(neighbour.add(quadrant.x, 0, 0), direction, quadrant, quadVisibility); - diagonalReachable = boundedNonOccluding(neighbour.add(quadrant.x, 0, 0)); - } - - if(direction.y == 0 && (neigbourTransparent || boundedNonOccluding(block.add(0, quadrant.y, 0)))) { - checkBlock(neighbour.add(0, quadrant.y, 0), direction, quadrant, quadVisibility); - diagonalReachable = diagonalReachable || boundedNonOccluding(neighbour.add(0, quadrant.y, 0)); - } - - if(direction.z == 0 && (neigbourTransparent || boundedNonOccluding(block.add(0, 0, quadrant.z)))) { - checkBlock(neighbour.add(0, 0, quadrant.z), direction, quadrant, quadVisibility); - diagonalReachable = diagonalReachable || boundedNonOccluding(neighbour.add(0, 0, quadrant.z)); - } - - if(diagonalReachable) - checkBlock(neighbour.add(quadrant), direction, quadrant, quadVisibility); - } - - private boolean boundedNonOccluding(IntVector block) { - return !(block.notInRegion(region) || occluding.get(block.toId(region))); - } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onSpawn(EntitySpawnEvent e) { + hulls.values().forEach(hull -> hull.checkEntity(e.getEntity())); } - private static class IntVector { - private final int x; - private final int y; - private final int z; + private void onTick() { + Recording.iterateOverEntities(Objects::nonNull, entity -> { + for (Hull hull : hulls.values()) + hull.checkEntity(entity); + }); + } - public IntVector(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public boolean notInRegion(Region region) { - return !region.inRegion(x, y, z); - } - - public int toId(Region region) { - return ((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX()); - } - - public IntVector add(int x, int y, int z) { - return new IntVector(this.x + x, this.y + y, this.z + z); - } - - public IntVector add(IntVector v) { - return add(v.x, v.y, v.z); - } - - @Override - public int hashCode() { - return y << 24 ^ x << 12 ^ z; - } - - @Override - public boolean equals(Object o) { - if(o == null || this.getClass() != o.getClass()) - return false; - - IntVector v = (IntVector) o; - return x == v.x && y == v.y && z == v.z; - } - - @Override - public String toString() { - return x + "," + y + "," + z; - } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onDeath(EntityDeathEvent e) { + hulls.values().forEach(hull -> hull.removeEntity(e.getEntity())); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java index 5b443da..9638292 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -36,7 +36,6 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; public class TechHiderWrapper extends StateDependent { @@ -45,7 +44,7 @@ public class TechHiderWrapper extends StateDependent { public TechHiderWrapper() { super(ENABLED, FightState.Schem); - techHider = new TechHider(this::bypass, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks.stream().map(String::toUpperCase).map(Material::getMaterial).collect(Collectors.toSet()), Config.HiddenBlockEntities); + techHider = new TechHider(this::bypass, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks, Config.HiddenBlockEntities); register(); } From 8de15e0af5de4457a1e83ce96469f595f1aa39ed Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Dec 2023 16:29:04 +0100 Subject: [PATCH 30/36] Fix rotation of teamname display in gamemodes without schematic rotation Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightSchematic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index ee1ab0a..426c66e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -198,7 +198,7 @@ public class FightSchematic extends StateDependent { } length -= 1; - AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0); + AffineTransform aT = new AffineTransform().rotateY(((team == Fight.getRedTeam()) == (Config.BlueToRedZ > 0)) ? 180 : 0); Location base = new Location(Config.world, region.centerX(), team.getExtendRegion().getMaxY(), region.centerZ()); for(int i = 0; i < characters.length; i++){ WorldeditWrapper.impl.pasteClipboard(characters[i], base, new Vector(offsets[i] - length/2, 0, -region.getSizeZ()/2), aT); From ce3384c7e95e7a3d65520944f23135a57d57fa74 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Dec 2023 18:23:54 +0100 Subject: [PATCH 31/36] Bugfixes, remove debug info Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/utils/Hull.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 904c0cd..c9f4d72 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -22,7 +22,6 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.techhider.BlockIds; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -144,10 +143,9 @@ public class Hull { } }); FightSystem.getPlugin().getLogger().log(Level.INFO, () -> "[HullHider] initialisation finished: " + (System.currentTimeMillis() - start) + " ms, visible blocks: " + visibility.cardinality()); - - region.forEach(this::printDebug); } + @SuppressWarnings("deprecation") public void updateBlockVisibility(Block b, Material changedType) { IntVector root = new IntVector(b.getX(), b.getY(), b.getZ()); if (root.notInRegion(region)) @@ -168,20 +166,19 @@ public class Hull { } } - for (IntVector block : uncovered) - printDebug(block.x, block.y, block.z); + if(uncovered.isEmpty()) + return; - //TODO uncover entities - } - - private final int air = BlockIds.impl.materialToId(Material.AIR); - private final int stone = BlockIds.impl.materialToId(Material.STONE); - private final int red = BlockIds.impl.materialToId(Material.RED_CONCRETE); - - private void printDebug(int x, int y, int z) { - int id = new IntVector(x, y, z).toId(region); - - BlockIdWrapper.impl.setBlock(Config.world, x, y + Config.BlueExtendRegion.getSizeY(), z, visibility.get(id) ? (occluding.get(id) ? red : air) : stone); + Set uncoveredSet = new HashSet<>(uncovered); + Iterator it = entities.iterator(); + while(it.hasNext()) { + Entity entity = it.next(); + if(uncoveredSet.contains(new IntVector(entity.getLocation()))) { //TODO more precise + it.remove(); + for(Player player : players) + player.showEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + } + } } private void forEachBorder(BiConsumer f) { From 9b781035922beca9061f329a826caf8fbdddb40d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 19 Dec 2023 16:40:12 +0100 Subject: [PATCH 32/36] Replay HullHider, Fix HullHider for players already online Signed-off-by: Lixfel --- .../fightsystem/utils/BlockIdWrapper14.java | 8 +++++ .../fightsystem/utils/BlockIdWrapper8.java | 10 ++++++ .../fightsystem/record/PacketProcessor.java | 5 ++- .../fightsystem/utils/BlockIdWrapper.java | 2 ++ .../steamwar/fightsystem/utils/HullHider.java | 31 ++++++++++++------- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 916bfb6..934d9b6 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; import de.steamwar.core.Core; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -56,4 +57,11 @@ public class BlockIdWrapper14 implements BlockIdWrapper { getTypeAndData.invoke(nworld, pos, blockData, 1042); flagDirty.invoke(getChunkProvider.invoke(nworld), pos); } + + private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("{obc}.util.CraftMagicNumbers"), "getMaterial", Material.class, block); + private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); + @Override + public Material idToMaterial(int blockState) { + return (Material)getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(getByCombinedId.invoke(null, blockState))); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index aedd2e8..cbf186a 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.utils; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -37,4 +38,13 @@ public class BlockIdWrapper8 implements BlockIdWrapper { world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); } + + @Override + @SuppressWarnings("deprecation") + public Material idToMaterial(int blockState) { + if((blockState >> 4) > 256) // Illegal blockstate / corrupted replay + blockState = 0; + + return Material.getMaterial(blockState >> 4); + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index f50007a..fff0512 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -437,7 +437,10 @@ public class PacketProcessor implements Listener { if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena - execSync(() -> BlockIdWrapper.impl.setBlock(Config.world, x, y, z, TechHiderWrapper.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); + execSync(() -> { + BlockIdWrapper.impl.setBlock(Config.world, x, y, z, TechHiderWrapper.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState); + FightSystem.getHullHider().blockUpdate(Config.world.getBlockAt(x, y, z), BlockIdWrapper.impl.idToMaterial(blockState)); + }); } private void particle() throws IOException { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index 6cda218..399e63d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -21,12 +21,14 @@ package de.steamwar.fightsystem.utils; import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; public interface BlockIdWrapper { BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + Material idToMaterial(int blockState); int blockToId(Block block); void setBlock(World world, int x, int y, int z, int blockState); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 1291202..c7f8e0d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.core.Core; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.Recording; @@ -27,6 +28,8 @@ import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -43,6 +46,7 @@ import java.util.Objects; public class HullHider implements Listener { + private static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18; private final Map hulls = new HashMap<>(); //SpawnPackets: PacketPlayOutSpawnEntity, PacketPlayOutSpawnEntityWeather, PacketPlayOutSpawnEntityLiving, PacketPlayOutSpawnEntityPainting, PacketPlayOutSpawnEntityPlayer @@ -51,11 +55,11 @@ public class HullHider implements Listener { //Other: Effect, Particle, Explosion //Death: DestroyEntities public HullHider() { - if(TechHiderWrapper.ENABLED) + if(ENABLED) Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); - new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this); - new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) { + new StateDependentListener(ENABLED, FightState.Schem, this); + new StateDependent(ENABLED, FightState.Schem) { @Override public void enable() { Bukkit.getOnlinePlayers().forEach(player -> addPlayer(player, true)); @@ -65,12 +69,12 @@ public class HullHider implements Listener { public void disable() { Bukkit.getOnlinePlayers().forEach(player -> removePlayer(player, true)); } - }; - new StateDependentTask(TechHiderWrapper.ENABLED, FightState.Schem, this::onTick, 0, 1); + }.register(); + new StateDependentTask(ENABLED, FightState.Schem, this::onTick, 0, 1); } public void initialize(FightTeam team) { - if(!TechHiderWrapper.ENABLED) + if(!ENABLED) return; hulls.get(team).initialize(); @@ -78,14 +82,14 @@ public class HullHider implements Listener { public void addPlayer(FightTeam team, Player player) { - if(!TechHiderWrapper.ENABLED) + if(!ENABLED) return; hulls.get(team).addPlayer(player, true); } public void removePlayer(FightTeam team, Player player) { - if(!TechHiderWrapper.ENABLED) + if(!ENABLED) return; hulls.get(team).removePlayer(player, true); @@ -118,10 +122,13 @@ public class HullHider implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPhysic(BlockPhysicsEvent e) { - if(FlatteningWrapper.impl.doRecord(e)) { - for (Hull hull : hulls.values()) - hull.updateBlockVisibility(e.getBlock(), e.getChangedType()); - } + if(FlatteningWrapper.impl.doRecord(e)) + blockUpdate(e.getBlock(), e.getChangedType()); + } + + public void blockUpdate(Block block, Material changedType) { + for (Hull hull : hulls.values()) + hull.updateBlockVisibility(block, changedType); } From 65028799b03c3c02c1aee074054f762afc1d967b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 19 Dec 2023 22:18:16 +0100 Subject: [PATCH 33/36] Correct HullHider behaviour for boarding Signed-off-by: Lixfel --- .../countdown/EnternCountdown.java | 5 ++- .../steamwar/fightsystem/fight/FightTeam.java | 4 +-- .../de/steamwar/fightsystem/utils/Hull.java | 4 +-- .../steamwar/fightsystem/utils/HullHider.java | 36 ++++++++----------- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index d8c78d9..157c296 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -56,7 +56,10 @@ public class EnternCountdown extends Countdown { @Override public void countdownFinished() { FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR); - fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunkPos, false)); + fightPlayer.ifPlayer(player -> { + FightSystem.getHullHider().updatePlayer(player); + FightSystem.getTechHider().reloadChunks(player, chunkPos, false); + }); } @Override diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 6efb3fd..7aad62d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -275,7 +275,7 @@ public class FightTeam { BountifulWrapper.impl.setAttackSpeed(player); player.setFoodLevel(20); player.getInventory().clear(); - FightSystem.getHullHider().removePlayer(this, player); + FightSystem.getHullHider().updatePlayer(player); if(FightState.Spectate.contains(FightState.getFightState())) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); @@ -319,7 +319,7 @@ public class FightTeam { player.getInventory().clear(); if(player.isOnline()){ - FightSystem.getHullHider().addPlayer(this, player); + FightSystem.getHullHider().updatePlayer(player); FightSystem.getTechHider().reloadChunks(player, chunksToReload, true); if(ArenaMode.VariableTeams.contains(Config.mode)) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index c9f4d72..3f168a3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -89,8 +89,8 @@ public class Hull { } @SuppressWarnings("deprecation") - public void addPlayer(Player player, boolean activeHiding) { - if(players.add(player) && activeHiding) { + public void addPlayer(Player player) { + if(players.add(player)) { for(Entity entity : entities) player.hideEntity(FightSystem.getPlugin(), entity); //TODO 1.15- } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index c7f8e0d..423f8cc 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils; import de.steamwar.core.Core; import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.states.FightState; @@ -62,7 +63,7 @@ public class HullHider implements Listener { new StateDependent(ENABLED, FightState.Schem) { @Override public void enable() { - Bukkit.getOnlinePlayers().forEach(player -> addPlayer(player, true)); + Bukkit.getOnlinePlayers().forEach(player -> updatePlayer(player)); } @Override @@ -81,23 +82,9 @@ public class HullHider implements Listener { } - public void addPlayer(FightTeam team, Player player) { - if(!ENABLED) - return; - - hulls.get(team).addPlayer(player, true); - } - - public void removePlayer(FightTeam team, Player player) { - if(!ENABLED) - return; - - hulls.get(team).removePlayer(player, true); - } - @EventHandler(priority = EventPriority.HIGH) public void onJoin(PlayerJoinEvent e) { - addPlayer(e.getPlayer(), false); + updatePlayer(e.getPlayer()); } @EventHandler @@ -105,13 +92,18 @@ public class HullHider implements Listener { removePlayer(e.getPlayer(), false); } - private void addPlayer(Player player, boolean activeHiding) { - FightTeam team = Fight.getPlayerTeam(player); - for(Map.Entry hull : hulls.entrySet()) { - if(hull.getKey() == team) - continue; + public void updatePlayer(Player player) { + if(!ENABLED) + return; - hull.getValue().addPlayer(player, activeHiding); + FightTeam team = Fight.getPlayerTeam(player); + FightPlayer fp = Fight.getFightPlayer(player); + for(Map.Entry hull : hulls.entrySet()) { + if(hull.getKey() == team || (fp != null && fp.canEntern())) { + hull.getValue().removePlayer(player, true); + } else { + hull.getValue().addPlayer(player); + } } } From 6f4e0f0293ee2b47810e0950ca01d065c4362de2 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 30 Dec 2023 12:26:11 +0100 Subject: [PATCH 34/36] Replay REntity HullHider Signed-off-by: Lixfel --- .../fightsystem/record/PacketProcessor.java | 22 ++++++++---- .../de/steamwar/fightsystem/utils/Hull.java | 36 ++++++++++++++++--- .../steamwar/fightsystem/utils/HullHider.java | 16 +++++---- 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index fff0512..cb1dddb 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -165,6 +165,11 @@ public class PacketProcessor implements Listener { entityServer.addPlayer(player); } + private void addREntity(int entityId, REntity entity) { + entities.put(entityId, entity); + FightSystem.getHullHider().updateREntity(entity); + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerJoin(PlayerJoinEvent e) { entityServer.addPlayer(e.getPlayer()); @@ -235,7 +240,7 @@ public class PacketProcessor implements Listener { execSync(() -> { SteamwarUser user = SteamwarUser.get(userId); - entities.put(entityId, new RPlayer(entityServer, user.getUUID(), user.getUserName(), Config.SpecSpawn)); + addREntity(entityId, new RPlayer(entityServer, user.getUUID(), user.getUserName(), Config.SpecSpawn)); team.addEntry(user.getUserName()); }); } @@ -257,8 +262,10 @@ public class PacketProcessor implements Listener { execSync(() -> { REntity entity = entities.get(entityId); - if(entity != null) + if(entity != null) { entity.move(locX, locY, locZ, pitch, yaw, headYaw); + FightSystem.getHullHider().updateREntity(entity); + } }); } @@ -267,8 +274,10 @@ public class PacketProcessor implements Listener { execSync(() -> { REntity entity = entities.remove(entityId); - if(entity != null) + if(entity != null) { + FightSystem.getHullHider().despawnREntity(entity); entity.die(); + } }); } @@ -289,7 +298,7 @@ public class PacketProcessor implements Listener { private void tntSpawn() throws IOException { int entityId = source.readInt(); - execSync(() -> entities.put(entityId, new REntity(entityServer, EntityType.PRIMED_TNT, Config.SpecSpawn))); + execSync(() -> addREntity(entityId, new REntity(entityServer, EntityType.PRIMED_TNT, Config.SpecSpawn))); } private void entityVelocity() throws IOException { @@ -344,13 +353,13 @@ public class PacketProcessor implements Listener { private void arrowSpawn() throws IOException { int entityId = source.readInt(); - execSync(() -> entities.put(entityId, new REntity(entityServer, EntityType.ARROW, Config.SpecSpawn))); + execSync(() -> addREntity(entityId, new REntity(entityServer, EntityType.ARROW, Config.SpecSpawn))); } private void fireballSpawn() throws IOException { int entityId = source.readInt(); - execSync(() -> entities.put(entityId, new REntity(entityServer, EntityType.FIREBALL, Config.SpecSpawn))); + execSync(() -> addREntity(entityId, new REntity(entityServer, EntityType.FIREBALL, Config.SpecSpawn))); } private void send(ChatMessageType type) throws IOException { @@ -581,6 +590,7 @@ public class PacketProcessor implements Listener { private void endReplay() { HandlerList.unregisterAll(this); entityServer.close(); + entities.values().forEach(FightSystem.getHullHider()::despawnREntity); entities.clear(); freezer.disable(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 3f168a3..57cfa29 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.entity.REntity; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.FightTeam; @@ -47,6 +48,7 @@ public class Hull { private final Set players = new HashSet<>(); private final Set entities = new HashSet<>(); + private final Set rentities = new HashSet<>(); public Hull(FightTeam team) { this.region = team.getSchemRegion(); @@ -92,7 +94,7 @@ public class Hull { public void addPlayer(Player player) { if(players.add(player)) { for(Entity entity : entities) - player.hideEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + player.hideEntity(FightSystem.getPlugin(), entity); } } @@ -100,7 +102,7 @@ public class Hull { public void removePlayer(Player player, boolean activeRemoval) { if(players.remove(player) && activeRemoval) { for(Entity entity : entities) - player.showEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + player.showEntity(FightSystem.getPlugin(), entity); } } @@ -109,12 +111,12 @@ public class Hull { if(region.inRegion(location) && !visibility.get(new IntVector(location).toId(region))) { //TODO more precise if(entities.add(entity)) { for(Player player : players) - player.hideEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + player.hideEntity(FightSystem.getPlugin(), entity); } } else { if(entities.remove(entity)) { for(Player player : players) - player.showEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + player.showEntity(FightSystem.getPlugin(), entity); } } } @@ -123,6 +125,21 @@ public class Hull { entities.remove(entity); } + public void checkREntity(REntity entity) { + Location location = new Location(Config.world, entity.getX(), entity.getY(), entity.getZ()); + if(region.inRegion(location) && !visibility.get(new IntVector(location).toId(region))) { //TODO more precise + if(rentities.add(entity)) + entity.hide(true); + } else { + if(rentities.remove(entity)) + entity.hide(false); + } + } + + public void removeREntity(REntity entity) { + rentities.remove(entity); + } + public void initialize() { visibility.clear(); occluding.clear(); @@ -176,7 +193,16 @@ public class Hull { if(uncoveredSet.contains(new IntVector(entity.getLocation()))) { //TODO more precise it.remove(); for(Player player : players) - player.showEntity(FightSystem.getPlugin(), entity); //TODO 1.15- + player.showEntity(FightSystem.getPlugin(), entity); + } + } + + Iterator rit = rentities.iterator(); + while(rit.hasNext()) { + REntity entity = rit.next(); + if(uncoveredSet.contains(new IntVector(new Location(Config.world, entity.getX(), entity.getY(), entity.getZ())))) { //TODO more precise + it.remove(); + entity.hide(false); } } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 423f8cc..1d95eef 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.utils; import de.steamwar.core.Core; +import de.steamwar.entity.REntity; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; @@ -50,11 +51,6 @@ public class HullHider implements Listener { private static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18; private final Map hulls = new HashMap<>(); - //SpawnPackets: PacketPlayOutSpawnEntity, PacketPlayOutSpawnEntityWeather, PacketPlayOutSpawnEntityLiving, PacketPlayOutSpawnEntityPainting, PacketPlayOutSpawnEntityPlayer - //One-timePackets: PacketPlayOutEntityAnimation, PacketPlayOutBlockBreakAnimation, PacketPlayOutEntityStatus, PacketPlayOutEntityPosition, PacketPlayOutEntityPositionAndRotation, PacketPlayOutEntityRotation, PacketPlayOutEntityMovement, EntityHeadLook, EntitySoundEffect, CollectItem, EntityTeleport, - //Permanent: EntityMetadata, AttachEntity, EntityEquipment, SetPassengers, EntityProperties, EntityEffect, RemoveEntityEffect - //Other: Effect, Particle, Explosion - //Death: DestroyEntities public HullHider() { if(ENABLED) Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); @@ -63,7 +59,7 @@ public class HullHider implements Listener { new StateDependent(ENABLED, FightState.Schem) { @Override public void enable() { - Bukkit.getOnlinePlayers().forEach(player -> updatePlayer(player)); + Bukkit.getOnlinePlayers().forEach(HullHider.this::updatePlayer); } @Override @@ -140,4 +136,12 @@ public class HullHider implements Listener { public void onDeath(EntityDeathEvent e) { hulls.values().forEach(hull -> hull.removeEntity(e.getEntity())); } + + public void updateREntity(REntity e) { + hulls.values().forEach(hull -> hull.checkREntity(e)); + } + + public void despawnREntity(REntity e) { + hulls.values().forEach(hull -> hull.removeREntity(e)); + } } From 7fab960315aefa16c7f1f3d6beb5dd52290bd1e5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 1 Jan 2024 16:45:32 +0100 Subject: [PATCH 35/36] Fix unchecked schematics at events Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index cbb392b..438bd1a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.*; @@ -189,7 +190,7 @@ public class GUI { return; } - if (type.checkType() != null && type.checkType() != type && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.checkType().toDB()).isEmpty()) { + if (type.checkType() != null && type.checkType() != type && ArenaMode.AntiEvent.contains(Config.mode) && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.checkType().toDB()).isEmpty()) { inv.setItem(row * 9 + 4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, type.name()), (ClickType click) -> { p.closeInventory(); schemDialog(p, type, false, true); From 7f9cfe73f72045bcc3060082a3dddf07fe7d41e1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 1 Jan 2024 16:46:25 +0100 Subject: [PATCH 36/36] Fix unchecked schematics at events Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index cbb392b..438bd1a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.*; @@ -189,7 +190,7 @@ public class GUI { return; } - if (type.checkType() != null && type.checkType() != type && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.checkType().toDB()).isEmpty()) { + if (type.checkType() != null && type.checkType() != type && ArenaMode.AntiEvent.contains(Config.mode) && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.checkType().toDB()).isEmpty()) { inv.setItem(row * 9 + 4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, type.name()), (ClickType click) -> { p.closeInventory(); schemDialog(p, type, false, true);