From e3535c379a737ef7e000894b3aa8b9baa68bb6e8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 7 Mar 2024 12:54:13 +0100 Subject: [PATCH 1/5] 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(); + } } -- 2.39.5 From e0659c1bb2b3fe09cafb91bdb601e9b90781fea3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 10 Mar 2024 19:35:31 +0100 Subject: [PATCH 2/5] 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(); } -- 2.39.5 From c3bb34ed6b28a639a761e1a97402c11f2a9b4816 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 11 Mar 2024 21:33:46 +0100 Subject: [PATCH 3/5] 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<>(); -- 2.39.5 From 0c947f0b5b7accc43b7e7d880b46cc5190b8b660 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 11 Mar 2024 22:49:22 +0100 Subject: [PATCH 4/5] 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(); -- 2.39.5 From 3bd54fcdbdd4d9f7815746380b305103065a0d53 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 13 Mar 2024 13:08:17 +0100 Subject: [PATCH 5/5] 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; -- 2.39.5