From ace26a7750ed76824125b897c241a8d389b0dc9c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 5 Feb 2024 16:19:08 +0100 Subject: [PATCH 01/18] Fix falling off AirShip during PRE_RUNNING Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/ArenaBorder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java index 8f9c287..caf36f6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -45,7 +45,7 @@ public class ArenaBorder implements Listener { public ArenaBorder() { new StateDependentListener(ArenaMode.All, FightState.All, this); new StateDependentTask(ArenaMode.All, FightState.Running, this::damage, 2, 2); - new StateDependentListener(!Config.GroundWalkable, FightState.AntiIngame, new Listener() { + new StateDependentListener(!Config.GroundWalkable, FightState.AntiRunning, new Listener() { @EventHandler public void onMove(PlayerMoveEvent e) { Player player = e.getPlayer(); From 46e3c383bdf3dd21cda8cfa28a3dbac9e9360526 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Feb 2024 22:11:01 +0100 Subject: [PATCH 02/18] Replace TNT on red side in check arenas Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightSchematic.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 93e6e5f..c0386e4 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -149,6 +149,8 @@ public class FightSchematic extends StateDependent { new AffineTransform().rotateY(rotate ? 180 : 0) ); FightSystem.getHullHider().initialize(team); + if(ArenaMode.Check.contains(Config.mode) && !team.isBlue()) + replaceSync(Material.TNT, Material.RED_WOOL); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); From 470f8613cd48443b26ea03eaebcdd61e5355a21d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Feb 2024 22:50:42 +0100 Subject: [PATCH 03/18] Add logging to debug team area bugs Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/ArenaBorder.java | 4 ++-- .../src/de/steamwar/fightsystem/listener/Border.java | 7 ++++++- .../src/de/steamwar/fightsystem/listener/TeamArea.java | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java index caf36f6..4c0daa4 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -39,8 +39,8 @@ import org.bukkit.event.player.PlayerQuitEvent; public class ArenaBorder implements Listener { - private final Border spectatorBorder = new Border(Config.PlayerRegion, true, 5, "NO_ARENA_LEAVING"); - private final Border playerBorder = new Border(Config.PlayerRegion.to2d(), true, 5, "NO_ARENA_LEAVING"); + private final Border spectatorBorder = new Border(Config.PlayerRegion, true, 5, "NO_ARENA_LEAVING", "ArenaBorder.spectatorBorder"); + private final Border playerBorder = new Border(Config.PlayerRegion.to2d(), true, 5, "NO_ARENA_LEAVING", "ArenaBorder.playerBorder"); public ArenaBorder() { new StateDependentListener(ArenaMode.All, FightState.All, this); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java index 6f8bddd..043dcf0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java @@ -36,6 +36,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.logging.Level; public class Border { @@ -43,13 +44,15 @@ public class Border { private final Map lastLocation = new HashMap<>(); private final boolean contain; private final String resetMessage; + private final String name; private final Region region; private final int ghostRange; private final int ghostSize; - public Border(Region region, boolean contain, int ghostRange, String resetMessage) { + public Border(Region region, boolean contain, int ghostRange, String resetMessage, String name) { this.contain = contain; this.resetMessage = resetMessage; + this.name = name; this.region = region; this.ghostRange = ghostRange; this.ghostSize = 2*ghostRange + 1; @@ -63,6 +66,7 @@ public class Border { ghostBarriers.put(player, new HashSet<>()); lastLocation.put(player, player.getLocation()); + FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was added to border " + name); } public boolean contains(Player player) { @@ -70,6 +74,7 @@ public class Border { } public void removePlayer(Player player) { + FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was removed from border " + name); lastLocation.remove(player); Set blocks = ghostBarriers.remove(player); if(blocks == null || !player.isOnline()) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java index cf241bd..2720b25 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -52,8 +52,8 @@ public class TeamArea implements Listener { public TeamArea(FightTeam team) { this.team = team; - this.spectatorBorder = new Border(team.getExtendRegion(), false, 5, "NO_TEAMAREA"); - this.bordingBorder = new Border(team.getExtendRegion().to2d(), true, 1, "NO_ENTERN"); + this.spectatorBorder = new Border(team.getExtendRegion(), false, 5, "NO_TEAMAREA", team.getName() + ".spectatorBorder"); + this.bordingBorder = new Border(team.getExtendRegion().to2d(), true, 1, "NO_ENTERN", team.getName() + ".boardingBorder"); new StateDependentListener(ArenaMode.AntiTest, FightState.All, this); new StateDependentTask(ArenaMode.AntiTest, FightState.TeamFix, this::realSpectatorCheck, 1, 1); From 39bff371a41311dea106c3546f7f346694e01397 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 8 Feb 2024 13:19:15 +0100 Subject: [PATCH 04/18] Fix y border size for players Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index 807822a..025daf3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -117,7 +117,7 @@ public class Region { } public boolean playerInRegion(Location location){ - return in2dRegion(location) && minY <= location.getY() && location.getY() + 1.8 < maxY; + return in2dRegion(location) && minY <= location.getY() && location.getY() < maxY; } public boolean in2dRegion(Block block){ From e0b6c1b93141c92f131bf51bd76d82d69696f706 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 11 Feb 2024 18:55:32 +0100 Subject: [PATCH 05/18] Potential Border rejoin fix Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 11 +++++++---- .../src/de/steamwar/fightsystem/listener/Border.java | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 544be31..136ede0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -201,13 +201,16 @@ public class FightTeam { schematic.reset(); Set playerSet = new HashSet<>(players.keySet()); - for(UUID uuid : playerSet){ + playerSet.removeIf(uuid -> { Player player = Bukkit.getPlayer(uuid); - if(player == null) + if(player == null || !player.isOnline()) { removePlayer(players.get(uuid).getEntity()); - } + return true; + } + + return false; + }); FightPlayer leaderBackup = leader; - playerSet.removeIf(uuid -> Bukkit.getPlayer(uuid) == null); players.clear(); leader = null; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java index 043dcf0..02c395a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java @@ -61,7 +61,7 @@ public class Border { } public void addPlayer(Player player) { - if(ghostBarriers.containsKey(player)) + if(ghostBarriers.containsKey(player) || !player.isOnline()) return; ghostBarriers.put(player, new HashSet<>()); From 7d7b6226a0a00e1172626167a50a7acee69cc19c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 11 Feb 2024 19:13:47 +0100 Subject: [PATCH 06/18] Potential Border rejoin fix Signed-off-by: Lixfel --- .../steamwar/fightsystem/fight/FightTeam.java | 2 +- .../steamwar/fightsystem/listener/Border.java | 39 ++++++++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 136ede0..4a2b1be 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -203,7 +203,7 @@ public class FightTeam { Set playerSet = new HashSet<>(players.keySet()); playerSet.removeIf(uuid -> { Player player = Bukkit.getPlayer(uuid); - if(player == null || !player.isOnline()) { + if(player == null) { removePlayer(players.get(uuid).getEntity()); return true; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java index 02c395a..6ab6605 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java @@ -27,21 +27,19 @@ import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.Region; import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.logging.Level; public class Border { - private final Map> ghostBarriers = new HashMap<>(); - private final Map lastLocation = new HashMap<>(); + private final Map> ghostBarriers = new HashMap<>(); + private final Map lastLocation = new HashMap<>(); private final boolean contain; private final String resetMessage; private final String name; @@ -61,22 +59,22 @@ public class Border { } public void addPlayer(Player player) { - if(ghostBarriers.containsKey(player) || !player.isOnline()) + if(ghostBarriers.containsKey(player.getUniqueId())) return; - ghostBarriers.put(player, new HashSet<>()); - lastLocation.put(player, player.getLocation()); + ghostBarriers.put(player.getUniqueId(), new HashSet<>()); + lastLocation.put(player.getUniqueId(), player.getLocation()); FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was added to border " + name); } public boolean contains(Player player) { - return ghostBarriers.containsKey(player); + return ghostBarriers.containsKey(player.getUniqueId()); } public void removePlayer(Player player) { FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was removed from border " + name); - lastLocation.remove(player); - Set blocks = ghostBarriers.remove(player); + lastLocation.remove(player.getUniqueId()); + Set blocks = ghostBarriers.remove(player.getUniqueId()); if(blocks == null || !player.isOnline()) return; @@ -85,11 +83,18 @@ public class Border { } private void run() { - for(Map.Entry> entry : ghostBarriers.entrySet()) { - Player player = entry.getKey(); + List offline = new ArrayList<>(); + for(Map.Entry> entry : ghostBarriers.entrySet()) { + UUID uuid = entry.getKey(); + Player player = Bukkit.getPlayer(uuid); + if(player == null) { + offline.add(uuid); + continue; + } + Location location = player.getLocation(); if(region.playerInRegion(location) != contain) { - player.teleport(lastLocation.get(player)); + player.teleport(lastLocation.get(uuid)); FightSystem.getMessage().sendPrefixless(resetMessage, player, ChatMessageType.ACTION_BAR); return; } @@ -122,6 +127,10 @@ public class Border { lastLocation.put(entry.getKey(), location); } + + offline.forEach(uuid -> FightSystem.getPlugin().getLogger().log(Level.INFO, () -> uuid + " was removed from border " + name)); + offline.forEach(ghostBarriers::remove); + offline.forEach(lastLocation::remove); } private void borderIteration(Player player, Set ghostBlocks, Region border) { From 79413434f763574566c4b0945c2c4a06fbe6f82e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 5 Mar 2024 16:17:55 +0100 Subject: [PATCH 07/18] Fix WaterRemover TNT Signed-off-by: Lixfel --- .../steamwar/fightsystem/listener/WaterRemover.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java index 05d6d2a..c89fcab 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -73,8 +73,13 @@ public class WaterRemover implements Listener { FightTeam spawn = tnt.remove(event.getEntity().getEntityId()); if(spawn != null && !spawn.getExtendRegion().inRegion(event.getLocation())) { Block b = event.getLocation().getBlock(); - checkBlock(b); - checkNeighbours(b); + for(int y = -1; y <= 1; y++) { + for(int z = -1; z <= 1; z++) { + for(int x = -1; x <= 1; x++) { + checkBlock(b.getRelative(x, y, z)); + } + } + } } event.blockList().forEach(this::checkNeighbours); @@ -90,7 +95,7 @@ public class WaterRemover implements Listener { } private void checkBlock(Block b) { - //do not remove outside teamareasevent.getLocation().getBlock() + //do not remove outside teamareas if(!Config.BlueExtendRegion.inRegion(b) && !Config.RedExtendRegion.inRegion(b)) return; From e3535c379a737ef7e000894b3aa8b9baa68bb6e8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 7 Mar 2024 12:54:13 +0100 Subject: [PATCH 08/18] Block HullHider Untested Signed-off-by: Lixfel --- FightSystem_18/build.gradle | 1 + .../fightsystem/utils/HullHiderWrapper18.java | 69 +++++++++++++++++++ FightSystem_20/build.gradle | 1 + .../fightsystem/utils/HullHiderWrapper20.java | 32 +++++++++ .../de/steamwar/fightsystem/utils/Hull.java | 31 ++++++++- .../steamwar/fightsystem/utils/HullHider.java | 22 +++++- .../fightsystem/utils/HullHiderWrapper.java | 31 +++++++++ .../de/steamwar/fightsystem/utils/Region.java | 6 ++ .../fightsystem/utils/TechHiderWrapper.java | 55 +++++++++++---- 9 files changed, 230 insertions(+), 18 deletions(-) create mode 100644 FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java create mode 100644 FightSystem_20/src/de/steamwar/fightsystem/utils/HullHiderWrapper20.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java diff --git a/FightSystem_18/build.gradle b/FightSystem_18/build.gradle index 91b8b08..7b0940e 100644 --- a/FightSystem_18/build.gradle +++ b/FightSystem_18/build.gradle @@ -48,6 +48,7 @@ dependencies { compileOnly 'com.mojang:datafixerupper:4.0.26' compileOnly 'io.netty:netty-all:4.1.68.Final' compileOnly 'com.mojang:authlib:1.5.25' + compileOnly 'it.unimi.dsi:fastutil:8.5.6' compileOnly swdep("Spigot-1.18") compileOnly swdep("WorldEdit-1.15") diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java new file mode 100644 index 0000000..0781fe4 --- /dev/null +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -0,0 +1,69 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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 com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.Config; +import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.SectionPosition; +import net.minecraft.network.protocol.game.PacketPlayOutBlockChange; +import net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange; +import net.minecraft.world.level.block.state.IBlockData; + +import java.util.List; + + +public class HullHiderWrapper18 implements HullHiderWrapper { + + private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftBlockData"), "getState", IBlockData.class); + @Override + public Object generateBlockChangePacket(List changes) { + Object[] blockdata = new Object[changes.size()]; + + for(int i = 0; i < changes.size(); i++) { + Hull.IntVector change = changes.get(i); + blockdata[i] = getState.invoke(Config.world.getBlockData(change.getX(), change.getY(), change.getZ())); + } + + return generateBlockChangePacket(changes, blockdata); + } + + private Object generateBlockChangePacket(List changes, Object[] blockdata) { + if(changes.size() > 1) { + short[] pos = new short[changes.size()]; + for(int i = 0; i < changes.size(); i++) { + Hull.IntVector change = changes.get(i); + + pos[i] = (short) ((change.getX()%16) << 8 + (change.getZ()%16) << 4 + change.getY()%16); + } + + Hull.IntVector section = changes.get(0); + return constructMultiBlockChange(new Hull.IntVector(section.getX() >> 4, section.getY() >> 4, section.getZ() >> 4), pos, blockdata); + } else { + Hull.IntVector pos = changes.get(0); + return new PacketPlayOutBlockChange(new BlockPosition(pos.getX(), pos.getY(), pos.getZ()), (IBlockData) blockdata[0]); + } + } + + protected Object constructMultiBlockChange(Hull.IntVector section, short[] pos, Object[] blockdata) { + return new PacketPlayOutMultiBlockChange(SectionPosition.a(section.getX(), section.getY(), section.getZ()), new Short2ObjectArrayMap<>(pos, blockdata, blockdata.length), false); + } +} diff --git a/FightSystem_20/build.gradle b/FightSystem_20/build.gradle index ca641a3..51b5737 100644 --- a/FightSystem_20/build.gradle +++ b/FightSystem_20/build.gradle @@ -46,6 +46,7 @@ dependencies { implementation project(":FightSystem_18") compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT' + compileOnly 'it.unimi.dsi:fastutil:8.5.6' compileOnly swdep("Spigot-1.20") } diff --git a/FightSystem_20/src/de/steamwar/fightsystem/utils/HullHiderWrapper20.java b/FightSystem_20/src/de/steamwar/fightsystem/utils/HullHiderWrapper20.java new file mode 100644 index 0000000..48bf0ad --- /dev/null +++ b/FightSystem_20/src/de/steamwar/fightsystem/utils/HullHiderWrapper20.java @@ -0,0 +1,32 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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 it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap; +import net.minecraft.core.SectionPosition; +import net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange; + +public class HullHiderWrapper20 extends HullHiderWrapper18 { + + @Override + protected Object constructMultiBlockChange(Hull.IntVector section, short[] pos, Object[] blockdata) { + return new PacketPlayOutMultiBlockChange(SectionPosition.a(section.getX(), section.getY(), section.getZ()), new Short2ObjectArrayMap<>(pos, blockdata, blockdata.length)); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 118e564..2e95a7b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -19,10 +19,12 @@ package de.steamwar.fightsystem.utils; +import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.entity.REntity; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.FightTeam; +import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -45,6 +47,7 @@ public class Hull { private final BitSet occluding; private final BitSet visibility; private final Map> blockVisibility = new HashMap<>(); + private final Set uncoveredSurface = new HashSet<>(); private final Set players = new HashSet<>(); private final Set entities = new HashSet<>(); @@ -90,6 +93,10 @@ public class Hull { } } + public boolean isBlockHidden(Player player, int x, int y, int z) { + return players.contains(player) && region.inRegion(x, y, z) && !visibility.get(((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX())); + } + public boolean isLocationHidden(Player player, Location location) { return players.contains(player) && region.inRegion(location) && !visibility.get(new IntVector(location).toId(region)); } @@ -107,6 +114,7 @@ public class Hull { if(players.remove(player) && activeRemoval) { for(Entity entity : entities) player.showEntity(FightSystem.getPlugin(), entity); + // techhider triggers block change sending } } @@ -147,6 +155,7 @@ public class Hull { public void initialize() { visibility.clear(); occluding.clear(); + uncoveredSurface.clear(); for (Map direction : blockVisibility.values()) { for (BitSet set : direction.values()) set.clear(); @@ -209,6 +218,23 @@ public class Hull { entity.hide(false); } } + + uncoveredSurface.addAll(uncoveredSet); + uncoveredSurface.remove(root); + } + + public void sendUncoveredBlocks() { + Map> sectionWise = new HashMap<>(); + + for(IntVector uncovered : uncoveredSurface) { + sectionWise.computeIfAbsent(new IntVector(uncovered.x >> 4, uncovered.y >> 4, uncovered.z >> 4), section -> new ArrayList<>()).add(uncovered); + } + uncoveredSurface.clear(); + + for (Map.Entry> entry : sectionWise.entrySet()) { + Object packet = HullHiderWrapper.impl.generateBlockChangePacket(entry.getValue()); + players.forEach(player -> TinyProtocol.instance.sendPacket(player, packet)); + } } private void forEachBorder(BiConsumer f) { @@ -280,9 +306,12 @@ public class Hull { } - private static class IntVector { + public static class IntVector { + @Getter private final int x; + @Getter private final int y; + @Getter private final int z; public IntVector(int x, int y, int z) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 06363e3..108dce2 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -56,13 +56,15 @@ import java.util.function.Function; public class HullHider implements Listener { - private static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18; + public static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18; private final Map hulls = new HashMap<>(); private final Map, BiFunction> packetHiders = new HashMap<>(); public HullHider() { - if(ENABLED) - Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); + if(!ENABLED) + return; + + Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider); packetHiders.put(packetPlayOutExplosion, this::explosionHider); @@ -137,6 +139,17 @@ public class HullHider implements Listener { hull.updateBlockVisibility(block, changedType); } + public boolean isBlockHidden(Player player, int x, int y, int z) { + if(!ENABLED) + return false; + + for (Hull hull : hulls.values()) + if(hull.isBlockHidden(player, x, y, z)) + return true; + + return false; + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSpawn(EntitySpawnEvent e) { @@ -148,6 +161,9 @@ public class HullHider implements Listener { for (Hull hull : hulls.values()) hull.checkEntity(entity); }); + + for (Hull hull : hulls.values()) + hull.sendUncoveredBlocks(); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java new file mode 100644 index 0000000..17a5195 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java @@ -0,0 +1,31 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.core.VersionDependent; +import de.steamwar.fightsystem.FightSystem; + +import java.util.List; + +public interface HullHiderWrapper { + HullHiderWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + + Object generateBlockChangePacket(List changes); +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index 025daf3..b789641 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -80,6 +80,12 @@ public class Region { getMinChunkZ() > cZ || cZ > getMaxChunkZ(); } + public boolean chunkSectionOutside(int cX, int cY, int cZ) { + return getMinChunkX() > cX || cX > getMaxChunkX() || + ProtocolUtils.posToChunk(minY) > cY || cY > ProtocolUtils.posToChunk(maxY) || + getMinChunkZ() > cZ || cZ > getMaxChunkZ(); + } + public void forEachChunk(ObjIntConsumer executor) { for(int x = getMinChunkX(); x <= getMaxChunkX(); x++) for(int z = getMinChunkZ(); z <= getMaxChunkZ(); z++) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java index 9638292..b47b29c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -37,14 +37,17 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class TechHiderWrapper extends StateDependent { +public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator { public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; + + private final Region empty = Region.fromSize(-10000, -10000, -10000, 0, 0, 0); + private final TechHider techHider; public TechHiderWrapper() { super(ENABLED, FightState.Schem); - techHider = new TechHider(this::bypass, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks, Config.HiddenBlockEntities); + techHider = new TechHider(this, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks, Config.HiddenBlockEntities); register(); } @@ -64,7 +67,7 @@ public class TechHiderWrapper extends StateDependent { List chunksToReload = new ArrayList<>(); Config.ArenaRegion.forEachChunk((x, z) -> { - if(bypass((Player) p, x, z) == hide) + if(skipChunk((Player) p, x, z) == hide) chunksToReload.add(new ProtocolUtils.ChunkPos(x, z)); }); return chunksToReload; @@ -76,23 +79,47 @@ public class TechHiderWrapper extends StateDependent { Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { for(ProtocolUtils.ChunkPos chunk : chunksToReload){ - if(bypass(p, chunk.x(), chunk.z()) != hide) + if(skipChunk(p, chunk.x(), chunk.z()) != hide) CraftbukkitWrapper.impl.sendChunk(p, chunk.x(), chunk.z()); } }, 40); } - private boolean bypass(Player p, int chunkX, int chunkZ){ - if(Config.isReferee(p)) - return true; + @Override + public boolean skipChunk(Player player, int chunkX, int chunkZ) { + return getHiddenRegion(player).chunkOutside(chunkX, chunkZ); + } - FightTeam ft = Fight.getPlayerTeam(p); - if(ft == null){ - return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); - }else if(ft.isBlue()){ - return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ); - }else{ - return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); + @Override + public boolean skipChunkSection(Player player, int chunkX, int chunkY, int chunkZ) { + //TODO chunkhider skip sections + return getHiddenRegion(player).chunkSectionOutside(chunkX, chunkY, chunkZ); + } + + @Override + public TechHider.State check(Player player, int x, int y, int z) { + if(getHiddenRegion(player).inRegion(x, y, z)) { + if(FightSystem.getHullHider().isBlockHidden(player, x, y, z)) { + return TechHider.State.HIDE; + } else { + return TechHider.State.CHECK; + } + } else { + return TechHider.State.SKIP; } } + + private Region getHiddenRegion(Player player) { + if(Config.isReferee(player)) + return empty; + + FightTeam team = Fight.getPlayerTeam(player); + if(team == null) + return Config.ArenaRegion; + + if(team.canPlayerEntern(player)) + return empty; + + return Fight.getOpposite(team).getExtendRegion(); + } } From f964f58d93aae5f092b10948a89468a2acae6dd9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 9 Mar 2024 19:19:42 +0100 Subject: [PATCH 09/18] Allow multiple Referees per Event Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index dba60ee..046cfd8 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; @@ -125,8 +122,8 @@ public class Config { public static final String ObfuscateWith; //event parameter - private static final int EventKampfID; public static final EventFight EventKampf; + private static final Set Referees; public static final int EventTeamBlueID; public static final int EventTeamRedID; public static final boolean BothTeamsPublic; @@ -317,17 +314,17 @@ public class Config { ArenaRegion = Region.withExtension(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0); PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX, world.getMaxHeight(), arenaMaxZ); - EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); - if(EventKampfID >= 1){ - EventFight eventFight = EventFight.get(EventKampfID); - if(eventFight == null){ + int eventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); + if(eventKampfID >= 1){ + EventKampf = EventFight.get(eventKampfID); + if(EventKampf == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight"); Bukkit.shutdown(); } - assert eventFight != null; - Team team1 = Team.get(eventFight.getTeamBlue()); - Team team2 = Team.get(eventFight.getTeamRed()); + assert EventKampf != null; + Team team1 = Team.get(EventKampf.getTeamBlue()); + Team team2 = Team.get(EventKampf.getTeamRed()); if(team1 == null || team2 == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load Team"); @@ -343,9 +340,9 @@ public class Config { EventTeamBlueID = team1.getTeamId(); EventTeamRedID = team2.getTeamId(); BothTeamsPublic = EventTeamRedID == 0 && EventTeamBlueID == 0; - EventKampf = eventFight; + Referees = Referee.get(Config.EventKampf.getEventID()); - Event event = Event.get(eventFight.getEventID()); + Event event = Event.get(EventKampf.getEventID()); if(BothTeamsPublic) { OnlyPublicSchematics = true; MaximumTeamMembers = Integer.MAX_VALUE; @@ -365,6 +362,7 @@ public class Config { EventTeamRedID = 0; EventKampf = null; BothTeamsPublic = true; + Referees = Collections.emptySet(); MaximumTeamMembers = Integer.MAX_VALUE; LiveReplay = false; } @@ -388,9 +386,9 @@ public class Config { mode = ArenaMode.CHECK; }else if(PrepareSchemID != 0){ mode = ArenaMode.PREPARE; - }else if(EventKampfID >= 1){ + }else if(eventKampfID >= 1){ mode = ArenaMode.EVENT; - }else if(EventKampfID == -1){ + }else if(eventKampfID == -1){ mode = ArenaMode.TEST; }else if(ReplayID != 0){ mode = ArenaMode.REPLAY; @@ -410,8 +408,6 @@ public class Config { } public static boolean isReferee(Player player) { - if(EventKampf == null) - return false; - return SteamwarUser.get(player.getUniqueId()).getId() == EventKampf.getKampfleiter(); + return Referees.contains(SteamwarUser.get(player.getUniqueId()).getId()); } } From e0659c1bb2b3fe09cafb91bdb601e9b90781fea3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 10 Mar 2024 19:35:31 +0100 Subject: [PATCH 10/18] Bugfixes, Performance improvements Signed-off-by: Lixfel --- .../fightsystem/utils/HullHiderWrapper18.java | 14 ++-- .../fightsystem/countdown/Countdown.java | 5 -- .../countdown/EnternCountdown.java | 9 +-- .../steamwar/fightsystem/fight/FightTeam.java | 7 +- .../de/steamwar/fightsystem/utils/Hull.java | 4 +- .../steamwar/fightsystem/utils/HullHider.java | 39 +++++++---- .../de/steamwar/fightsystem/utils/Region.java | 2 + .../fightsystem/utils/TechHiderWrapper.java | 70 +++++++++++-------- 8 files changed, 85 insertions(+), 65 deletions(-) diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index 0781fe4..97413f7 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -33,7 +33,7 @@ import java.util.List; public class HullHiderWrapper18 implements HullHiderWrapper { - private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftBlockData"), "getState", IBlockData.class); + private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", IBlockData.class); @Override public Object generateBlockChangePacket(List changes) { Object[] blockdata = new Object[changes.size()]; @@ -48,15 +48,21 @@ public class HullHiderWrapper18 implements HullHiderWrapper { private Object generateBlockChangePacket(List changes, Object[] blockdata) { if(changes.size() > 1) { + Hull.IntVector section = changes.get(0); + //section = new Hull.IntVector(ProtocolUtils.posToChunk(section.getX()), ProtocolUtils.posToChunk(section.getY()), ProtocolUtils.posToChunk(section.getZ())); + section = new Hull.IntVector(section.getX() >> 4, section.getY() >> 4, section.getZ() >> 4); + int xOffset = 16*section.getX(); + int yOffset = 16*section.getY(); + int zOffset = 16*section.getZ(); + short[] pos = new short[changes.size()]; for(int i = 0; i < changes.size(); i++) { Hull.IntVector change = changes.get(i); - pos[i] = (short) ((change.getX()%16) << 8 + (change.getZ()%16) << 4 + change.getY()%16); + pos[i] = (short) (((change.getX()-xOffset) << 8) + ((change.getZ()-zOffset) << 4) + (change.getY()-yOffset)); } - Hull.IntVector section = changes.get(0); - return constructMultiBlockChange(new Hull.IntVector(section.getX() >> 4, section.getY() >> 4, section.getZ() >> 4), pos, blockdata); + return constructMultiBlockChange(section, pos, blockdata); } else { Hull.IntVector pos = changes.get(0); return new PacketPlayOutBlockChange(new BlockPosition(pos.getX(), pos.getY(), pos.getZ()), (IBlockData) blockdata[0]); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java index 46c8ace..e96c6b1 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -83,8 +83,6 @@ public abstract class Countdown { } for(Countdown countdown : new ArrayList<>(currentCountdowns)) { - if(countdown.time - smallestTime <= 1) - countdown.prepareFinish(); countdown.time -= smallestTime; countdown.show(); } @@ -104,8 +102,6 @@ public abstract class Countdown { Bukkit.getOnlinePlayers().forEach(p -> sendCountdownMessage(p, message, time / divisor, appendix)); } - protected void prepareFinish() {} - public int getTimeLeft(){ return time; } @@ -124,7 +120,6 @@ public abstract class Countdown { broadcast("COUNTDOWN_SECONDS", 1); break; case 1: - prepareFinish(); broadcast("COUNTDOWN_SECOND", 1); break; case 0: diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index 5581fe8..55bcbe3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -22,8 +22,10 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.events.BoardingEvent; +import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.utils.Message; +import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.techhider.ProtocolUtils; import net.md_5.bungee.api.ChatMessageType; @@ -61,15 +63,10 @@ public class EnternCountdown extends Countdown { FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR); fightPlayer.ifPlayer(player -> { FightSystem.getHullHider().updatePlayer(player); - FightSystem.getTechHider().reloadChunks(player, chunkPos, false); + FightSystem.getTechHider().reloadChunks(player, Fight.getOpposite(fightPlayer.getTeam()).getExtendRegion(), Region.EMPTY); }); } - @Override - protected void prepareFinish() { - chunkPos = FightSystem.getTechHider().prepareChunkReload(fightPlayer.getEntity(), false); - } - @Override protected void broadcast(String message, int divisor) { fightPlayer.ifPlayer(player -> { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 4a2b1be..853646f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -40,7 +40,6 @@ import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.inventory.SWItem; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; -import de.steamwar.techhider.ProtocolUtils; import lombok.Getter; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.*; @@ -262,7 +261,6 @@ public class FightTeam { } public void addMember(LivingEntity entity, SteamwarUser user, boolean silent) { - final List chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, false); FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this); fightPlayer.revive(); players.put(entity.getUniqueId(), fightPlayer); @@ -291,7 +289,7 @@ public class FightTeam { if(FightState.Running.contains(FightState.getFightState())) fightPlayer.startEnternCountdown(Wincondition.getTimeOverCountdown()); - fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunksToReload, false)); + fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, Config.ArenaRegion, fightPlayer.canEntern() ? Region.EMPTY : Fight.getOpposite(this).getExtendRegion())); if(isLeaderless()) setLeader(fightPlayer, silent); @@ -304,7 +302,6 @@ public class FightTeam { Bukkit.getPluginManager().callEvent(new TeamLeaveEvent(fightPlayer)); fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator); - List chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, true); players.remove(entity.getUniqueId()); team.removeEntry(entity.getName()); Permanent.getSpectatorTeam().addEntry(entity.getName()); @@ -322,7 +319,7 @@ public class FightTeam { if(player.isOnline()){ FightSystem.getHullHider().updatePlayer(player); - FightSystem.getTechHider().reloadChunks(player, chunksToReload, true); + FightSystem.getTechHider().reloadChunks(player, Config.ArenaRegion, Fight.getOpposite(this).getExtendRegion()); if(ArenaMode.VariableTeams.contains(Config.mode)) HotbarKit.SPECTATOR_KIT.loadToPlayer(player); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 2e95a7b..f310fa3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -49,7 +49,7 @@ public class Hull { private final Map> blockVisibility = new HashMap<>(); private final Set uncoveredSurface = new HashSet<>(); - private final Set players = new HashSet<>(); + private final HashSet players = new HashSet<>(); private final Set entities = new HashSet<>(); private final Set rentities = new HashSet<>(); @@ -94,7 +94,7 @@ public class Hull { } public boolean isBlockHidden(Player player, int x, int y, int z) { - return players.contains(player) && region.inRegion(x, y, z) && !visibility.get(((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX())); + return region.inRegion(x, y, z) && players.contains(player) && !visibility.get(((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX())); } public boolean isLocationHidden(Player player, Location location) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 108dce2..259433f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -57,14 +57,18 @@ import java.util.function.Function; public class HullHider implements Listener { public static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18; - private final Map hulls = new HashMap<>(); + private final Map hullMap = new HashMap<>(); + private final Hull[] hulls; private final Map, BiFunction> packetHiders = new HashMap<>(); public HullHider() { - if(!ENABLED) + if(!ENABLED) { + hulls = new Hull[0]; return; + } - Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); + Fight.teams().forEach(team -> hullMap.put(team, new Hull(team))); + hulls = hullMap.values().toArray(new Hull[0]); packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider); packetHiders.put(packetPlayOutExplosion, this::explosionHider); @@ -94,7 +98,7 @@ public class HullHider implements Listener { if(!ENABLED) return; - hulls.get(team).initialize(); + hullMap.get(team).initialize(); } @@ -114,7 +118,7 @@ public class HullHider implements Listener { FightTeam team = Fight.getPlayerTeam(player); FightPlayer fp = Fight.getFightPlayer(player); - for(Map.Entry hull : hulls.entrySet()) { + for(Map.Entry hull : hullMap.entrySet()) { if(hull.getKey() == team || (fp != null && fp.canEntern())) { hull.getValue().removePlayer(player, true); } else { @@ -124,7 +128,8 @@ public class HullHider implements Listener { } private void removePlayer(Player player, boolean activeRemoval) { - hulls.values().forEach(hull -> hull.removePlayer(player, activeRemoval)); + for (Hull hull : hulls) + hull.removePlayer(player, activeRemoval); } @@ -135,7 +140,7 @@ public class HullHider implements Listener { } public void blockUpdate(Block block, Material changedType) { - for (Hull hull : hulls.values()) + for (Hull hull : hulls) hull.updateBlockVisibility(block, changedType); } @@ -143,7 +148,7 @@ public class HullHider implements Listener { if(!ENABLED) return false; - for (Hull hull : hulls.values()) + for (Hull hull : hulls) if(hull.isBlockHidden(player, x, y, z)) return true; @@ -153,30 +158,34 @@ public class HullHider implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSpawn(EntitySpawnEvent e) { - hulls.values().forEach(hull -> hull.checkEntity(e.getEntity())); + for (Hull hull : hulls) + hull.checkEntity(e.getEntity()); } private void onTick() { Recording.iterateOverEntities(Objects::nonNull, entity -> { - for (Hull hull : hulls.values()) + for (Hull hull : hulls) hull.checkEntity(entity); }); - for (Hull hull : hulls.values()) + for (Hull hull : hulls) hull.sendUncoveredBlocks(); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDeath(EntityDeathEvent e) { - hulls.values().forEach(hull -> hull.removeEntity(e.getEntity())); + for(Hull hull : hulls) + hull.removeEntity(e.getEntity()); } public void updateREntity(REntity e) { - hulls.values().forEach(hull -> hull.checkREntity(e)); + for(Hull hull : hulls) + hull.checkREntity(e); } public void despawnREntity(REntity e) { - hulls.values().forEach(hull -> hull.removeREntity(e)); + for(Hull hull : hulls) + hull.removeREntity(e); } @@ -213,7 +222,7 @@ public class HullHider implements Listener { } private Object packetHider(Player player, Object packet, Location location) { - for(Hull hull : hulls.values()) { + for(Hull hull : hulls) { if(hull.isLocationHidden(player, location)) return null; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index b789641..6a55979 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -31,6 +31,8 @@ import java.util.function.ObjIntConsumer; @AllArgsConstructor public class Region { + public static final Region EMPTY = Region.fromSize(-10000, -10000, -10000, 0, 0, 0); + public static Region withExtension(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ, int extendX, int extendY, int extendZ) { return Region.fromSize(minX - extendX, minY - extendY, minZ - extendZ, sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java index b47b29c..6168706 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -22,32 +22,36 @@ package de.steamwar.fightsystem.utils; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.events.BoardingEvent; +import de.steamwar.fightsystem.events.TeamLeaveEvent; +import de.steamwar.fightsystem.events.TeamSpawnEvent; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import de.steamwar.techhider.ProtocolUtils; +import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.techhider.TechHider; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; +import java.util.concurrent.ConcurrentHashMap; -public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator { +public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator, Listener { public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; - private final Region empty = Region.fromSize(-10000, -10000, -10000, 0, 0, 0); - + private final ConcurrentHashMap hiddenRegion = new ConcurrentHashMap<>(); private final TechHider techHider; public TechHiderWrapper() { super(ENABLED, FightState.Schem); techHider = new TechHider(this, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks, Config.HiddenBlockEntities); + + new StateDependentListener(ENABLED, FightState.Schem, this); register(); } @@ -59,30 +63,41 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati @Override public void disable() { techHider.disable(); + hiddenRegion.clear(); } - public List prepareChunkReload(LivingEntity p, boolean hide) { - if(!ENABLED || !(p instanceof Player)) - return Collections.emptyList(); + @EventHandler + public void teamJoin(TeamSpawnEvent e) { + e.getFightPlayer().ifPlayer(player -> hiddenRegion.put(player, getHiddenRegion(player))); + } - List chunksToReload = new ArrayList<>(); - Config.ArenaRegion.forEachChunk((x, z) -> { - if(skipChunk((Player) p, x, z) == hide) - chunksToReload.add(new ProtocolUtils.ChunkPos(x, z)); + @EventHandler + public void boarding(BoardingEvent e) { + e.getFightPlayer().ifPlayer(player -> hiddenRegion.put(player, getHiddenRegion(player))); + } + + @EventHandler + public void teamLeave(TeamLeaveEvent e) { + e.getFightPlayer().ifPlayer(player -> { + if(player.isOnline()) + hiddenRegion.put(player, getHiddenRegion(player)); }); - return chunksToReload; } - public void reloadChunks(Player p, List chunksToReload, boolean hide) { - if(!ENABLED || !FightState.Schem.contains(FightState.getFightState())) + @EventHandler + public void playerQuit(PlayerQuitEvent e) { + Player player = e.getPlayer(); + hiddenRegion.remove(player); + } + + public void reloadChunks(Player player, Region region, Region exclusion) { + if(!ENABLED || !FightState.Schem.contains(FightState.getFightState()) || !player.isOnline()) return; - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { - for(ProtocolUtils.ChunkPos chunk : chunksToReload){ - if(skipChunk(p, chunk.x(), chunk.z()) != hide) - CraftbukkitWrapper.impl.sendChunk(p, chunk.x(), chunk.z()); - } - }, 40); + region.forEachChunk((chunkX, chunkZ) -> { + if(exclusion.chunkOutside(chunkX, chunkZ)) + CraftbukkitWrapper.impl.sendChunk(player, chunkX, chunkZ); + }); } @Override @@ -92,13 +107,12 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati @Override public boolean skipChunkSection(Player player, int chunkX, int chunkY, int chunkZ) { - //TODO chunkhider skip sections return getHiddenRegion(player).chunkSectionOutside(chunkX, chunkY, chunkZ); } @Override public TechHider.State check(Player player, int x, int y, int z) { - if(getHiddenRegion(player).inRegion(x, y, z)) { + if(hiddenRegion.computeIfAbsent(player, this::getHiddenRegion).inRegion(x, y, z)) { if(FightSystem.getHullHider().isBlockHidden(player, x, y, z)) { return TechHider.State.HIDE; } else { @@ -111,14 +125,14 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati private Region getHiddenRegion(Player player) { if(Config.isReferee(player)) - return empty; + return Region.EMPTY; FightTeam team = Fight.getPlayerTeam(player); if(team == null) return Config.ArenaRegion; if(team.canPlayerEntern(player)) - return empty; + return Region.EMPTY; return Fight.getOpposite(team).getExtendRegion(); } From c3bb34ed6b28a639a761e1a97402c11f2a9b4816 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 11 Mar 2024 21:33:46 +0100 Subject: [PATCH 11/18] Performance and information hiding improvements (no unchanged hullhider blocks) Signed-off-by: Lixfel --- .../fightsystem/utils/HullHiderWrapper18.java | 20 ++++++++++++------- .../src/de/steamwar/fightsystem/Config.java | 4 ++-- .../fightsystem/record/PacketProcessor.java | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index 97413f7..86da5d9 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -27,7 +27,10 @@ import net.minecraft.core.SectionPosition; import net.minecraft.network.protocol.game.PacketPlayOutBlockChange; import net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange; import net.minecraft.world.level.block.state.IBlockData; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; +import java.util.ArrayList; import java.util.List; @@ -36,20 +39,23 @@ public class HullHiderWrapper18 implements HullHiderWrapper { private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", IBlockData.class); @Override public Object generateBlockChangePacket(List changes) { - Object[] blockdata = new Object[changes.size()]; + List blockdata = new ArrayList<>(changes.size()); - for(int i = 0; i < changes.size(); i++) { - Hull.IntVector change = changes.get(i); - blockdata[i] = getState.invoke(Config.world.getBlockData(change.getX(), change.getY(), change.getZ())); - } + changes.removeIf(change -> { + //BlockData data = Config.world.getBlockData(change.getX(), change.getY(), change.getZ()); + BlockData data = Material.EMERALD_BLOCK.createBlockData(); + boolean unchanged = data.getMaterial() == Config.ObfuscateWith; + if(!unchanged) + blockdata.add(getState.invoke(data)); + return unchanged; + }); - return generateBlockChangePacket(changes, blockdata); + return generateBlockChangePacket(changes, blockdata.toArray()); } private Object generateBlockChangePacket(List changes, Object[] blockdata) { if(changes.size() > 1) { Hull.IntVector section = changes.get(0); - //section = new Hull.IntVector(ProtocolUtils.posToChunk(section.getX()), ProtocolUtils.posToChunk(section.getY()), ProtocolUtils.posToChunk(section.getZ())); section = new Hull.IntVector(section.getX() >> 4, section.getY() >> 4, section.getZ() >> 4); int xOffset = 16*section.getX(); int yOffset = 16*section.getY(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index dba60ee..d3bd706 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -122,7 +122,7 @@ public class Config { public static final boolean TechhiderActive; public static final Set HiddenBlocks; public static final Set HiddenBlockEntities; - public static final String ObfuscateWith; + public static final Material ObfuscateWith; //event parameter private static final int EventKampfID; @@ -213,7 +213,7 @@ public class Config { ForbiddenItems = Collections.unmodifiableSet(config.getStringList("Kits.ForbiddenItems").stream().map(Material::valueOf).collect(Collectors.toSet())); TechhiderActive = config.getBoolean("Techhider.Active", false); - ObfuscateWith = config.getString("Techhider.ObfuscateWith", "end_stone").toUpperCase(); + ObfuscateWith = Material.getMaterial(config.getString("Techhider.ObfuscateWith", "end_stone").toUpperCase()); HiddenBlocks = config.getStringList("Techhider.HiddenBlocks").stream().map(String::toUpperCase).map(Material::getMaterial).collect(Collectors.toSet()); HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index cb1dddb..6296e37 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -89,7 +89,7 @@ public class PacketProcessor implements Listener { private final BukkitTask task; private final LinkedList syncList = new LinkedList<>(); 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 int obfuscateWith = BlockIds.impl.materialToId(Config.ObfuscateWith); private final FreezeWorld freezer = new FreezeWorld(); private final REntityServer entityServer = new REntityServer(); private final Map entities = new HashMap<>(); From 0c947f0b5b7accc43b7e7d880b46cc5190b8b660 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 11 Mar 2024 22:49:22 +0100 Subject: [PATCH 12/18] Fix debug code Signed-off-by: Lixfel --- .../fightsystem/utils/HullHiderWrapper18.java | 4 +--- .../src/de/steamwar/fightsystem/utils/Hull.java | 12 +++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index 86da5d9..45db342 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -27,7 +27,6 @@ import net.minecraft.core.SectionPosition; import net.minecraft.network.protocol.game.PacketPlayOutBlockChange; import net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange; import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.Material; import org.bukkit.block.data.BlockData; import java.util.ArrayList; @@ -42,8 +41,7 @@ public class HullHiderWrapper18 implements HullHiderWrapper { List blockdata = new ArrayList<>(changes.size()); changes.removeIf(change -> { - //BlockData data = Config.world.getBlockData(change.getX(), change.getY(), change.getZ()); - BlockData data = Material.EMERALD_BLOCK.createBlockData(); + BlockData data = Config.world.getBlockData(change.getX(), change.getY(), change.getZ()); boolean unchanged = data.getMaterial() == Config.ObfuscateWith; if(!unchanged) blockdata.add(getState.invoke(data)); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index f310fa3..6111388 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -24,6 +24,7 @@ import de.steamwar.entity.REntity; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.FightTeam; +import lombok.AllArgsConstructor; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; @@ -306,20 +307,13 @@ public class Hull { } + @Getter + @AllArgsConstructor public static class IntVector { - @Getter private final int x; - @Getter private final int y; - @Getter 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(); From 3bd54fcdbdd4d9f7815746380b305103065a0d53 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 13 Mar 2024 13:08:17 +0100 Subject: [PATCH 13/18] Bugfixes, Block precise performance improvement Signed-off-by: Lixfel --- .../steamwar/fightsystem/utils/HullHiderWrapper18.java | 3 +++ .../src/de/steamwar/fightsystem/utils/Hull.java | 7 +++++++ .../src/de/steamwar/fightsystem/utils/HullHider.java | 10 ++++++++++ .../steamwar/fightsystem/utils/TechHiderWrapper.java | 9 ++++++--- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index 45db342..6087aab 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -48,6 +48,9 @@ public class HullHiderWrapper18 implements HullHiderWrapper { return unchanged; }); + if(changes.isEmpty()) + return null; + return generateBlockChangePacket(changes, blockdata.toArray()); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 6111388..3b96281 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -94,6 +94,10 @@ public class Hull { } } + public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) { + return players.contains(player) && !region.chunkSectionOutside(chunkX, chunkY, chunkZ); + } + public boolean isBlockHidden(Player player, int x, int y, int z) { return region.inRegion(x, y, z) && players.contains(player) && !visibility.get(((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX())); } @@ -234,6 +238,9 @@ public class Hull { for (Map.Entry> entry : sectionWise.entrySet()) { Object packet = HullHiderWrapper.impl.generateBlockChangePacket(entry.getValue()); + if(packet == null) + continue; + players.forEach(player -> TinyProtocol.instance.sendPacket(player, packet)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 259433f..286490c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -155,6 +155,16 @@ public class HullHider implements Listener { return false; } + public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) { + if(!ENABLED) + return false; + + for (Hull hull : hulls) + if(hull.blockPrecise(player, chunkX, chunkY, chunkZ)) + return true; + + return false; + } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSpawn(EntitySpawnEvent e) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java index 6168706..9e97afa 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -31,13 +31,11 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.techhider.TechHider; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.Collections; import java.util.concurrent.ConcurrentHashMap; public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator, Listener { @@ -49,7 +47,7 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati public TechHiderWrapper() { super(ENABLED, FightState.Schem); - techHider = new TechHider(this, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks, Config.HiddenBlockEntities); + techHider = new TechHider(this, Config.ObfuscateWith, Config.HiddenBlocks, Config.HiddenBlockEntities); new StateDependentListener(ENABLED, FightState.Schem, this); register(); @@ -123,6 +121,11 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati } } + @Override + public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) { + return FightSystem.getHullHider().blockPrecise(player, chunkX, chunkY, chunkZ); + } + private Region getHiddenRegion(Player player) { if(Config.isReferee(player)) return Region.EMPTY; From ac4babd44ae25b889cfaee143362a22e0c5823d8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 13 Mar 2024 13:20:11 +0100 Subject: [PATCH 14/18] Configurable spectate port Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 16 +++++++++------- .../fightsystem/record/LiveRecorder.java | 2 +- .../steamwar/fightsystem/record/LiveServer.java | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 046cfd8..6f6fe34 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -138,10 +138,14 @@ public class Config { //replay system parameter public static final String spectateIP = "127.0.0.1"; - public static final int spectatePort = 2222; + public static final int SpectatePort; public static final int ReplayID; static{ + CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); + PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0")); + ReplayID = Integer.parseInt(System.getProperty("replay", "0")); + String configFile = System.getProperty("config", "config.yml"); if(!new File(FightSystem.getPlugin().getDataFolder(), configFile).exists()) { FightSystem.getPlugin().saveDefaultConfig(); @@ -340,6 +344,8 @@ public class Config { EventTeamBlueID = team1.getTeamId(); EventTeamRedID = team2.getTeamId(); BothTeamsPublic = EventTeamRedID == 0 && EventTeamBlueID == 0; + SpectatePort = EventKampf.getSpectatePort(); + LiveReplay = SpectatePort != 0; Referees = Referee.get(Config.EventKampf.getEventID()); Event event = Event.get(EventKampf.getEventID()); @@ -350,7 +356,6 @@ public class Config { OnlyPublicSchematics = event.publicSchemsOnly(); MaximumTeamMembers = event.getMaximumTeamMembers(); } - LiveReplay = event.spectateSystem(); }else{ //No event TeamRedColor = config.getString("Red.Prefix", "§c"); @@ -365,6 +370,7 @@ public class Config { Referees = Collections.emptySet(); MaximumTeamMembers = Integer.MAX_VALUE; LiveReplay = false; + SpectatePort = -ReplayID; } String blueLeader = System.getProperty("blueLeader", null); @@ -378,10 +384,6 @@ public class Config { else RedLeader = null; - CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); - PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0")); - ReplayID = Integer.parseInt(System.getProperty("replay", "0")); - if(CheckSchemID != 0){ mode = ArenaMode.CHECK; }else if(PrepareSchemID != 0){ @@ -401,7 +403,7 @@ public class Config { return ArenaMode.Test.contains(mode); } public static boolean replayserver(){ - return ReplayID == -1; + return ReplayID < 0; } public static boolean blueNegZ(){ return BlueToRedZ > 0; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveRecorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveRecorder.java index b7531d3..55fef03 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveRecorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveRecorder.java @@ -41,7 +41,7 @@ public class LiveRecorder extends StateDependent implements Recorder { @Override public void enable() { try { - socket = new Socket(Config.spectateIP, Config.spectatePort); + socket = new Socket(Config.spectateIP, Config.SpectatePort); socket.setSoTimeout(1); // Wait a maximum of 1ms on a blocking operation (flush) socket.setSoLinger(true, 1); // Wait a maximum of 1ms on disable socket.setTcpNoDelay(true); // Don't wait on ack diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveServer.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveServer.java index b58f0fa..5bb6308 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveServer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveServer.java @@ -33,7 +33,7 @@ public class LiveServer { private final ServerSocket socket; public LiveServer() throws IOException { - socket = new ServerSocket(Config.spectatePort); + socket = new ServerSocket(Config.SpectatePort); Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::acceptConnections); } From df2ced027b52781ead5ee84340f4c99895469b9c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 14 Mar 2024 22:32:03 +0100 Subject: [PATCH 15/18] Fix world reset race condition with TechHider Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightWorld.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java index 6527e51..efcc16a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; @@ -55,7 +56,7 @@ public class FightWorld extends StateDependent { @Override public void disable() { - resetWorld(); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightWorld::resetWorld); //Delay to prevent raceconditions with techhider and hullhider } public static void forceLoad(){ From abb7df4e5c201ac2942128da27ad597428ac72d5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 16 Mar 2024 20:38:11 +0100 Subject: [PATCH 16/18] Fix Entity HullHider for Referee Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/HullHider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 286490c..4daf4ad 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -119,7 +119,7 @@ public class HullHider implements Listener { FightTeam team = Fight.getPlayerTeam(player); FightPlayer fp = Fight.getFightPlayer(player); for(Map.Entry hull : hullMap.entrySet()) { - if(hull.getKey() == team || (fp != null && fp.canEntern())) { + if(Config.isReferee(player) || hull.getKey() == team || (fp != null && fp.canEntern())) { hull.getValue().removePlayer(player, true); } else { hull.getValue().addPlayer(player); From bffbd2cc0651db542b1d109c18c7a89ab2691489 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Mar 2024 16:58:34 +0100 Subject: [PATCH 17/18] 1.8 - 1.15 HullHider, fix Tab Hiding, fix appearing NameTags, improve Performance untested Signed-off-by: Lixfel --- FightSystem_14/build.gradle | 2 + .../fightsystem/utils/BlockIdWrapper14.java | 28 +++++++++- .../fightsystem/utils/HullHiderWrapper18.java | 2 +- .../fightsystem/utils/BlockIdWrapper8.java | 28 ++++++++++ .../fightsystem/utils/HullHiderWrapper8.java | 55 +++++++++++++++++++ .../fightsystem/utils/BlockIdWrapper.java | 12 ++++ .../de/steamwar/fightsystem/utils/Hull.java | 13 ++--- .../steamwar/fightsystem/utils/HullHider.java | 17 +++--- 8 files changed, 136 insertions(+), 21 deletions(-) create mode 100644 FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java diff --git a/FightSystem_14/build.gradle b/FightSystem_14/build.gradle index 29ff288..1d2a18c 100644 --- a/FightSystem_14/build.gradle +++ b/FightSystem_14/build.gradle @@ -46,6 +46,8 @@ dependencies { implementation project(":FightSystem_9") implementation project(":FightSystem_8") + compileOnly 'it.unimi.dsi:fastutil:8.5.6' + compileOnly swdep("Spigot-1.14") compileOnly swdep("WorldEdit-1.15") compileOnly swdep("SpigotCore") diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 934d9b6..f0554b1 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -21,18 +21,29 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; import de.steamwar.core.Core; +import de.steamwar.fightsystem.Config; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.entity.Player; public class BlockIdWrapper14 implements BlockIdWrapper { - private static final Class worldServer = Reflection.getClass("{nms.server.level}.WorldServer"); private static final Class chunkProviderServer = Reflection.getClass("{nms.server.level}.ChunkProviderServer"); + private static final Reflection.MethodInvoker getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); + private static final Class playerChunkMap = Reflection.getClass("{nms.server.level}.PlayerChunkMap"); + private static final Reflection.FieldAccessor getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); + private static final Reflection.FieldAccessor entityTrackers = Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0); private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); + private final Int2ObjectMap trackers; + public BlockIdWrapper14() { + trackers = entityTrackers.get(getPlayerChunkMap.get(getChunkProvider.invoke(getWorldHandle.invoke(Config.world)))); + } + private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(block, null, int.class, iBlockData); private static final Reflection.MethodInvoker getNMS = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.CraftBlock"), "getNMS", iBlockData); @Override @@ -41,11 +52,9 @@ public class BlockIdWrapper14 implements BlockIdWrapper { } private static final Reflection.MethodInvoker getByCombinedId = Reflection.getTypedMethod(block, null, iBlockData, int.class); - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", worldServer); private static final Reflection.ConstructorInvoker newBlockPosition = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); private static final Reflection.MethodInvoker getTypeAndData = Reflection.getMethod(worldServer, null, blockPosition, iBlockData, int.class); private static final Reflection.MethodInvoker removeTileEntity = Reflection.getMethod(worldServer, Core.getVersion() > 15 ? "m" : "removeTileEntity", blockPosition); - private static final Reflection.MethodInvoker getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); private static final Reflection.MethodInvoker flagDirty = Reflection.getMethod(chunkProviderServer, null, blockPosition); @Override public void setBlock(World world, int x, int y, int z, int blockState) { @@ -58,6 +67,19 @@ public class BlockIdWrapper14 implements BlockIdWrapper { flagDirty.invoke(getChunkProvider.invoke(nworld), pos); } + private static final Class entityTracker = Reflection.getClass("{nms.server.level}.PlayerChunkMap$EntityTracker"); + private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); + @Override + public void trackEntity(Player player, int entity) { + updatePlayer.invoke(trackers.get(entity), getPlayer.invoke(player)); + } + + private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "a" : "clear", entityPlayer); + @Override + public void untrackEntity(Player player, int entity) { + clearPlayer.invoke(trackers.get(entity), getPlayer.invoke(player)); + } + 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 diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index 6087aab..8f81cf9 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -42,7 +42,7 @@ public class HullHiderWrapper18 implements HullHiderWrapper { changes.removeIf(change -> { BlockData data = Config.world.getBlockData(change.getX(), change.getY(), change.getZ()); - boolean unchanged = data.getMaterial() == Config.ObfuscateWith; + boolean unchanged = data.getMaterial() == Config.ObfuscateWith || Config.HiddenBlocks.contains(data.getMaterial()); if(!unchanged) blockdata.add(getState.invoke(data)); return unchanged; diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index cbf186a..f77fe95 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -19,11 +19,25 @@ package de.steamwar.fightsystem.utils; +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.Config; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.entity.Player; public class BlockIdWrapper8 implements BlockIdWrapper { + + private static final Class entityTracker = Reflection.getClass("{nms}.EntityTracker"); + private static final Reflection.FieldAccessor getEntityTracker = Reflection.getField(worldServer, entityTracker, 0); + private static final Class intHashMap = Reflection.getClass("{nms}.IntHashMap"); + private static final Reflection.FieldAccessor getTrackedEntities = Reflection.getField(entityTracker, intHashMap, 0); + + private final Object trackers; + public BlockIdWrapper8() { + trackers = getTrackedEntities.get(getEntityTracker.get(getWorldHandle.invoke(Config.world))); + } + @Override @SuppressWarnings("deprecation") public int blockToId(Block block) { @@ -39,6 +53,20 @@ public class BlockIdWrapper8 implements BlockIdWrapper { world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); } + private static final Class entityTrackerEntry = Reflection.getClass("{nms}.EntityTrackerEntry"); + private static final Reflection.MethodInvoker get = Reflection.getTypedMethod(intHashMap, "get", Object.class, int.class); + private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTrackerEntry, "updatePlayer", entityPlayer); + @Override + public void trackEntity(Player player, int entity) { + updatePlayer.invoke(get.invoke(trackers, entity), getPlayer.invoke(player)); + } + + private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTrackerEntry, "a", entityPlayer); + @Override + public void untrackEntity(Player player, int entity) { + clearPlayer.invoke(get.invoke(trackers, entity), getPlayer.invoke(player)); + } + @Override @SuppressWarnings("deprecation") public Material idToMaterial(int blockState) { diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java new file mode 100644 index 0000000..524842e --- /dev/null +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java @@ -0,0 +1,55 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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 com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.Config; +import org.bukkit.Material; + +import java.util.List; + +public class HullHiderWrapper8 implements HullHiderWrapper { + + private static final Reflection.ConstructorInvoker newMultiBlockChange = Reflection.getConstructor("{nms}.PacketPlayOutMultiBlockChange", int.class, short[].class, Reflection.getClass("{nms}.Chunk")); + private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + @Override + public Object generateBlockChangePacket(List changes) { + changes.removeIf(change -> { + Material material = Config.world.getBlockAt(change.getX(), change.getY(), change.getZ()).getType(); + return material == Config.ObfuscateWith || Config.HiddenBlocks.contains(material); + }); + + if(changes.isEmpty()) + return null; + + Hull.IntVector chunk = changes.get(0); + chunk = new Hull.IntVector(chunk.getX() >> 4, chunk.getY() >> 4, chunk.getZ() >> 4); + int xOffset = 16*chunk.getX(); + int zOffset = 16*chunk.getZ(); + short[] pos = new short[changes.size()]; + + for(int i = 0; i < changes.size(); i++) { + Hull.IntVector change = changes.get(i); + pos[i] = (short) (((change.getX()-xOffset) << 12) + ((change.getZ()-zOffset) << 8) + change.getY()); + } + + return newMultiBlockChange.invoke(pos.length, pos, getHandle.invoke(Config.world.getChunkAt(chunk.getX(), chunk.getZ()))); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index 399e63d..a6b825d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -19,16 +19,28 @@ package de.steamwar.fightsystem.utils; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.entity.Player; public interface BlockIdWrapper { + Class worldServer = Reflection.getClass("{nms.server.level}.WorldServer"); + Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", worldServer); + + Class craftPlayer = Reflection.getClass("{obc}.entity.CraftPlayer"); + Class entityPlayer = Reflection.getClass("{nms.server.level}.EntityPlayer"); + Reflection.MethodInvoker getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); + 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); + + void trackEntity(Player player, int entity); + void untrackEntity(Player player, int entity); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 3b96281..05ff3fc 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -106,19 +106,17 @@ public class Hull { return players.contains(player) && region.inRegion(location) && !visibility.get(new IntVector(location).toId(region)); } - @SuppressWarnings("deprecation") public void addPlayer(Player player) { if(players.add(player)) { for(Entity entity : entities) - player.hideEntity(FightSystem.getPlugin(), entity); + BlockIdWrapper.impl.untrackEntity(player, entity.getEntityId()); } } - @SuppressWarnings("deprecation") public void removePlayer(Player player, boolean activeRemoval) { if(players.remove(player) && activeRemoval) { for(Entity entity : entities) - player.showEntity(FightSystem.getPlugin(), entity); + BlockIdWrapper.impl.trackEntity(player, entity.getEntityId()); // techhider triggers block change sending } } @@ -128,12 +126,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); + BlockIdWrapper.impl.untrackEntity(player, entity.getEntityId()); } } else { if(entities.remove(entity)) { for(Player player : players) - player.showEntity(FightSystem.getPlugin(), entity); + BlockIdWrapper.impl.trackEntity(player, entity.getEntityId()); } } } @@ -180,7 +178,6 @@ public class Hull { FightSystem.getPlugin().getLogger().log(Level.INFO, () -> "[HullHider] initialisation finished: " + (System.currentTimeMillis() - start) + " ms, visible blocks: " + visibility.cardinality()); } - @SuppressWarnings("deprecation") public void updateBlockVisibility(Block b, Material changedType) { IntVector root = new IntVector(b.getX(), b.getY(), b.getZ()); if (root.notInRegion(region)) @@ -211,7 +208,7 @@ public class Hull { if(uncoveredSet.contains(new IntVector(entity.getLocation()))) { //TODO more precise it.remove(); for(Player player : players) - player.showEntity(FightSystem.getPlugin(), entity); + BlockIdWrapper.impl.trackEntity(player, entity.getEntityId()); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 4daf4ad..c613a4a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -56,13 +56,12 @@ import java.util.function.Function; public class HullHider implements Listener { - public static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18; private final Map hullMap = new HashMap<>(); private final Hull[] hulls; private final Map, BiFunction> packetHiders = new HashMap<>(); public HullHider() { - if(!ENABLED) { + if(!TechHiderWrapper.ENABLED) { hulls = new Hull[0]; return; } @@ -77,8 +76,8 @@ public class HullHider implements Listener { if(Core.getVersion() >= 9 && Core.getVersion() < 18) posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutCustomSoundEffect", int.class, 8.0); - new StateDependentListener(ENABLED, FightState.Schem, this); - new StateDependent(ENABLED, FightState.Schem) { + new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this); + new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) { @Override public void enable() { packetHiders.forEach(TinyProtocol.instance::addFilter); @@ -91,11 +90,11 @@ public class HullHider implements Listener { packetHiders.forEach(TinyProtocol.instance::removeFilter); } }.register(); - new StateDependentTask(ENABLED, FightState.Schem, this::onTick, 0, 1); + new StateDependentTask(TechHiderWrapper.ENABLED, FightState.Schem, this::onTick, 0, 1); } public void initialize(FightTeam team) { - if(!ENABLED) + if(!TechHiderWrapper.ENABLED) return; hullMap.get(team).initialize(); @@ -113,7 +112,7 @@ public class HullHider implements Listener { } public void updatePlayer(Player player) { - if(!ENABLED) + if(!TechHiderWrapper.ENABLED) return; FightTeam team = Fight.getPlayerTeam(player); @@ -145,7 +144,7 @@ public class HullHider implements Listener { } public boolean isBlockHidden(Player player, int x, int y, int z) { - if(!ENABLED) + if(!TechHiderWrapper.ENABLED) return false; for (Hull hull : hulls) @@ -156,7 +155,7 @@ public class HullHider implements Listener { } public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) { - if(!ENABLED) + if(!TechHiderWrapper.ENABLED) return false; for (Hull hull : hulls) From b9f0039025a6852f57b2322969082e2c1834624b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 22 Mar 2024 20:36:27 +0100 Subject: [PATCH 18/18] Fix HullHider Signed-off-by: Lixfel --- .../fightsystem/utils/BlockIdWrapper14.java | 14 ++++++++++---- .../fightsystem/utils/BlockIdWrapper8.java | 8 ++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index f0554b1..f2330e1 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -28,18 +28,20 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import java.util.Map; + public class BlockIdWrapper14 implements BlockIdWrapper { private static final Class chunkProviderServer = Reflection.getClass("{nms.server.level}.ChunkProviderServer"); private static final Reflection.MethodInvoker getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); private static final Class playerChunkMap = Reflection.getClass("{nms.server.level}.PlayerChunkMap"); private static final Reflection.FieldAccessor getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); - private static final Reflection.FieldAccessor entityTrackers = Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0); + private static final Reflection.FieldAccessor entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0); private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private final Int2ObjectMap trackers; + private final Map trackers; public BlockIdWrapper14() { trackers = entityTrackers.get(getPlayerChunkMap.get(getChunkProvider.invoke(getWorldHandle.invoke(Config.world)))); } @@ -71,13 +73,17 @@ public class BlockIdWrapper14 implements BlockIdWrapper { private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, int entity) { - updatePlayer.invoke(trackers.get(entity), getPlayer.invoke(player)); + Object tracker = trackers.get(entity); + if(tracker != null) + updatePlayer.invoke(tracker, getPlayer.invoke(player)); } private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "a" : "clear", entityPlayer); @Override public void untrackEntity(Player player, int entity) { - clearPlayer.invoke(trackers.get(entity), getPlayer.invoke(player)); + Object tracker = trackers.get(entity); + if(tracker != null) + clearPlayer.invoke(tracker, getPlayer.invoke(player)); } private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("{obc}.util.CraftMagicNumbers"), "getMaterial", Material.class, block); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index f77fe95..d330cfb 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -58,13 +58,17 @@ public class BlockIdWrapper8 implements BlockIdWrapper { private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTrackerEntry, "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, int entity) { - updatePlayer.invoke(get.invoke(trackers, entity), getPlayer.invoke(player)); + Object tracker = get.invoke(trackers, entity); + if(tracker != null) + updatePlayer.invoke(tracker, getPlayer.invoke(player)); } private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTrackerEntry, "a", entityPlayer); @Override public void untrackEntity(Player player, int entity) { - clearPlayer.invoke(get.invoke(trackers, entity), getPlayer.invoke(player)); + Object tracker = get.invoke(trackers, entity); + if(tracker != null) + clearPlayer.invoke(tracker, getPlayer.invoke(player)); } @Override