SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Block HullHider' (#416) from blockHullHider into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #416
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2024-03-13 17:13:37 +01:00
Commit 52e3fd754e
14 geänderte Dateien mit 329 neuen und 76 gelöschten Zeilen

Datei anzeigen

@ -48,6 +48,7 @@ dependencies {
compileOnly 'com.mojang:datafixerupper:4.0.26' compileOnly 'com.mojang:datafixerupper:4.0.26'
compileOnly 'io.netty:netty-all:4.1.68.Final' compileOnly 'io.netty:netty-all:4.1.68.Final'
compileOnly 'com.mojang:authlib:1.5.25' compileOnly 'com.mojang:authlib:1.5.25'
compileOnly 'it.unimi.dsi:fastutil:8.5.6'
compileOnly swdep("Spigot-1.18") compileOnly swdep("Spigot-1.18")
compileOnly swdep("WorldEdit-1.15") compileOnly swdep("WorldEdit-1.15")

Datei anzeigen

@ -0,0 +1,82 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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 org.bukkit.block.data.BlockData;
import java.util.ArrayList;
import java.util.List;
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<Hull.IntVector> changes) {
List<Object> blockdata = new ArrayList<>(changes.size());
changes.removeIf(change -> {
BlockData data = Config.world.getBlockData(change.getX(), change.getY(), change.getZ());
boolean unchanged = data.getMaterial() == Config.ObfuscateWith;
if(!unchanged)
blockdata.add(getState.invoke(data));
return unchanged;
});
if(changes.isEmpty())
return null;
return generateBlockChangePacket(changes, blockdata.toArray());
}
private Object generateBlockChangePacket(List<Hull.IntVector> changes, Object[] blockdata) {
if(changes.size() > 1) {
Hull.IntVector section = changes.get(0);
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()-xOffset) << 8) + ((change.getZ()-zOffset) << 4) + (change.getY()-yOffset));
}
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]);
}
}
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);
}
}

Datei anzeigen

@ -46,6 +46,7 @@ dependencies {
implementation project(":FightSystem_18") implementation project(":FightSystem_18")
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT' compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
compileOnly 'it.unimi.dsi:fastutil:8.5.6'
compileOnly swdep("Spigot-1.20") compileOnly swdep("Spigot-1.20")
} }

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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));
}
}

Datei anzeigen

@ -119,7 +119,7 @@ public class Config {
public static final boolean TechhiderActive; public static final boolean TechhiderActive;
public static final Set<Material> HiddenBlocks; public static final Set<Material> HiddenBlocks;
public static final Set<String> HiddenBlockEntities; public static final Set<String> HiddenBlockEntities;
public static final String ObfuscateWith; public static final Material ObfuscateWith;
//event parameter //event parameter
public static final EventFight EventKampf; public static final EventFight EventKampf;
@ -210,7 +210,7 @@ public class Config {
ForbiddenItems = Collections.unmodifiableSet(config.getStringList("Kits.ForbiddenItems").stream().map(Material::valueOf).collect(Collectors.toSet())); ForbiddenItems = Collections.unmodifiableSet(config.getStringList("Kits.ForbiddenItems").stream().map(Material::valueOf).collect(Collectors.toSet()));
TechhiderActive = config.getBoolean("Techhider.Active", false); 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()); HiddenBlocks = config.getStringList("Techhider.HiddenBlocks").stream().map(String::toUpperCase).map(Material::getMaterial).collect(Collectors.toSet());
HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities")));

Datei anzeigen

@ -83,8 +83,6 @@ public abstract class Countdown {
} }
for(Countdown countdown : new ArrayList<>(currentCountdowns)) { for(Countdown countdown : new ArrayList<>(currentCountdowns)) {
if(countdown.time - smallestTime <= 1)
countdown.prepareFinish();
countdown.time -= smallestTime; countdown.time -= smallestTime;
countdown.show(); countdown.show();
} }
@ -104,8 +102,6 @@ public abstract class Countdown {
Bukkit.getOnlinePlayers().forEach(p -> sendCountdownMessage(p, message, time / divisor, appendix)); Bukkit.getOnlinePlayers().forEach(p -> sendCountdownMessage(p, message, time / divisor, appendix));
} }
protected void prepareFinish() {}
public int getTimeLeft(){ public int getTimeLeft(){
return time; return time;
} }
@ -124,7 +120,6 @@ public abstract class Countdown {
broadcast("COUNTDOWN_SECONDS", 1); broadcast("COUNTDOWN_SECONDS", 1);
break; break;
case 1: case 1:
prepareFinish();
broadcast("COUNTDOWN_SECOND", 1); broadcast("COUNTDOWN_SECOND", 1);
break; break;
case 0: case 0:

Datei anzeigen

@ -22,8 +22,10 @@ package de.steamwar.fightsystem.countdown;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.events.BoardingEvent; import de.steamwar.fightsystem.events.BoardingEvent;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.utils.SWSound;
import de.steamwar.techhider.ProtocolUtils; import de.steamwar.techhider.ProtocolUtils;
import net.md_5.bungee.api.ChatMessageType; 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); FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR);
fightPlayer.ifPlayer(player -> { fightPlayer.ifPlayer(player -> {
FightSystem.getHullHider().updatePlayer(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 @Override
protected void broadcast(String message, int divisor) { protected void broadcast(String message, int divisor) {
fightPlayer.ifPlayer(player -> { fightPlayer.ifPlayer(player -> {

Datei anzeigen

@ -40,7 +40,6 @@ import de.steamwar.fightsystem.winconditions.Winconditions;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import de.steamwar.techhider.ProtocolUtils;
import lombok.Getter; import lombok.Getter;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.*; import org.bukkit.*;
@ -262,7 +261,6 @@ public class FightTeam {
} }
public void addMember(LivingEntity entity, SteamwarUser user, boolean silent) { public void addMember(LivingEntity entity, SteamwarUser user, boolean silent) {
final List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, false);
FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this); FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this);
fightPlayer.revive(); fightPlayer.revive();
players.put(entity.getUniqueId(), fightPlayer); players.put(entity.getUniqueId(), fightPlayer);
@ -291,7 +289,7 @@ public class FightTeam {
if(FightState.Running.contains(FightState.getFightState())) if(FightState.Running.contains(FightState.getFightState()))
fightPlayer.startEnternCountdown(Wincondition.getTimeOverCountdown()); 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()) if(isLeaderless())
setLeader(fightPlayer, silent); setLeader(fightPlayer, silent);
@ -304,7 +302,6 @@ public class FightTeam {
Bukkit.getPluginManager().callEvent(new TeamLeaveEvent(fightPlayer)); Bukkit.getPluginManager().callEvent(new TeamLeaveEvent(fightPlayer));
fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator); fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, true);
players.remove(entity.getUniqueId()); players.remove(entity.getUniqueId());
team.removeEntry(entity.getName()); team.removeEntry(entity.getName());
Permanent.getSpectatorTeam().addEntry(entity.getName()); Permanent.getSpectatorTeam().addEntry(entity.getName());
@ -322,7 +319,7 @@ public class FightTeam {
if(player.isOnline()){ if(player.isOnline()){
FightSystem.getHullHider().updatePlayer(player); 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)) if(ArenaMode.VariableTeams.contains(Config.mode))
HotbarKit.SPECTATOR_KIT.loadToPlayer(player); HotbarKit.SPECTATOR_KIT.loadToPlayer(player);

Datei anzeigen

@ -89,7 +89,7 @@ public class PacketProcessor implements Listener {
private final BukkitTask task; private final BukkitTask task;
private final LinkedList<Runnable> syncList = new LinkedList<>(); private final LinkedList<Runnable> syncList = new LinkedList<>();
private final Set<Integer> hiddenBlockIds = Config.HiddenBlocks.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); private final Set<Integer> 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 FreezeWorld freezer = new FreezeWorld();
private final REntityServer entityServer = new REntityServer(); private final REntityServer entityServer = new REntityServer();
private final Map<Integer, REntity> entities = new HashMap<>(); private final Map<Integer, REntity> entities = new HashMap<>();

Datei anzeigen

@ -19,10 +19,13 @@
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.entity.REntity; import de.steamwar.entity.REntity;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -45,8 +48,9 @@ public class Hull {
private final BitSet occluding; private final BitSet occluding;
private final BitSet visibility; private final BitSet visibility;
private final Map<IntVector, Map<IntVector, BitSet>> blockVisibility = new HashMap<>(); private final Map<IntVector, Map<IntVector, BitSet>> blockVisibility = new HashMap<>();
private final Set<IntVector> uncoveredSurface = new HashSet<>();
private final Set<Player> players = new HashSet<>(); private final HashSet<Player> players = new HashSet<>();
private final Set<Entity> entities = new HashSet<>(); private final Set<Entity> entities = new HashSet<>();
private final Set<REntity> rentities = new HashSet<>(); private final Set<REntity> rentities = new HashSet<>();
@ -90,6 +94,14 @@ 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()));
}
public boolean isLocationHidden(Player player, Location location) { public boolean isLocationHidden(Player player, Location location) {
return players.contains(player) && region.inRegion(location) && !visibility.get(new IntVector(location).toId(region)); return players.contains(player) && region.inRegion(location) && !visibility.get(new IntVector(location).toId(region));
} }
@ -107,6 +119,7 @@ public class Hull {
if(players.remove(player) && activeRemoval) { if(players.remove(player) && activeRemoval) {
for(Entity entity : entities) for(Entity entity : entities)
player.showEntity(FightSystem.getPlugin(), entity); player.showEntity(FightSystem.getPlugin(), entity);
// techhider triggers block change sending
} }
} }
@ -147,6 +160,7 @@ public class Hull {
public void initialize() { public void initialize() {
visibility.clear(); visibility.clear();
occluding.clear(); occluding.clear();
uncoveredSurface.clear();
for (Map<IntVector, BitSet> direction : blockVisibility.values()) { for (Map<IntVector, BitSet> direction : blockVisibility.values()) {
for (BitSet set : direction.values()) for (BitSet set : direction.values())
set.clear(); set.clear();
@ -209,6 +223,26 @@ public class Hull {
entity.hide(false); entity.hide(false);
} }
} }
uncoveredSurface.addAll(uncoveredSet);
uncoveredSurface.remove(root);
}
public void sendUncoveredBlocks() {
Map<IntVector, List<IntVector>> 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<IntVector, List<IntVector>> entry : sectionWise.entrySet()) {
Object packet = HullHiderWrapper.impl.generateBlockChangePacket(entry.getValue());
if(packet == null)
continue;
players.forEach(player -> TinyProtocol.instance.sendPacket(player, packet));
}
} }
private void forEachBorder(BiConsumer<IntVector, IntVector> f) { private void forEachBorder(BiConsumer<IntVector, IntVector> f) {
@ -280,17 +314,13 @@ public class Hull {
} }
private static class IntVector { @Getter
@AllArgsConstructor
public static class IntVector {
private final int x; private final int x;
private final int y; private final int y;
private final int z; 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) { public IntVector(Location location) {
this.x = location.getBlockX(); this.x = location.getBlockX();
this.y = location.getBlockY(); this.y = location.getBlockY();

Datei anzeigen

@ -56,13 +56,19 @@ import java.util.function.Function;
public class HullHider implements Listener { 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<FightTeam, Hull> hulls = new HashMap<>(); private final Map<FightTeam, Hull> hullMap = new HashMap<>();
private final Hull[] hulls;
private final Map<Class<?>, BiFunction<Player, Object, Object>> packetHiders = new HashMap<>(); private final Map<Class<?>, BiFunction<Player, Object, Object>> packetHiders = new HashMap<>();
public HullHider() { public HullHider() {
if(ENABLED) if(!ENABLED) {
Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); hulls = new Hull[0];
return;
}
Fight.teams().forEach(team -> hullMap.put(team, new Hull(team)));
hulls = hullMap.values().toArray(new Hull[0]);
packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider); packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider);
packetHiders.put(packetPlayOutExplosion, this::explosionHider); packetHiders.put(packetPlayOutExplosion, this::explosionHider);
@ -92,7 +98,7 @@ public class HullHider implements Listener {
if(!ENABLED) if(!ENABLED)
return; return;
hulls.get(team).initialize(); hullMap.get(team).initialize();
} }
@ -112,7 +118,7 @@ public class HullHider implements Listener {
FightTeam team = Fight.getPlayerTeam(player); FightTeam team = Fight.getPlayerTeam(player);
FightPlayer fp = Fight.getFightPlayer(player); FightPlayer fp = Fight.getFightPlayer(player);
for(Map.Entry<FightTeam, Hull> hull : hulls.entrySet()) { for(Map.Entry<FightTeam, Hull> hull : hullMap.entrySet()) {
if(hull.getKey() == team || (fp != null && fp.canEntern())) { if(hull.getKey() == team || (fp != null && fp.canEntern())) {
hull.getValue().removePlayer(player, true); hull.getValue().removePlayer(player, true);
} else { } else {
@ -122,7 +128,8 @@ public class HullHider implements Listener {
} }
private void removePlayer(Player player, boolean activeRemoval) { private void removePlayer(Player player, boolean activeRemoval) {
hulls.values().forEach(hull -> hull.removePlayer(player, activeRemoval)); for (Hull hull : hulls)
hull.removePlayer(player, activeRemoval);
} }
@ -133,34 +140,62 @@ public class HullHider implements Listener {
} }
public void blockUpdate(Block block, Material changedType) { public void blockUpdate(Block block, Material changedType) {
for (Hull hull : hulls.values()) for (Hull hull : hulls)
hull.updateBlockVisibility(block, changedType); hull.updateBlockVisibility(block, changedType);
} }
public boolean isBlockHidden(Player player, int x, int y, int z) {
if(!ENABLED)
return false;
for (Hull hull : hulls)
if(hull.isBlockHidden(player, x, y, z))
return true;
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) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSpawn(EntitySpawnEvent e) { public void onSpawn(EntitySpawnEvent e) {
hulls.values().forEach(hull -> hull.checkEntity(e.getEntity())); for (Hull hull : hulls)
hull.checkEntity(e.getEntity());
} }
private void onTick() { private void onTick() {
Recording.iterateOverEntities(Objects::nonNull, entity -> { Recording.iterateOverEntities(Objects::nonNull, entity -> {
for (Hull hull : hulls.values()) for (Hull hull : hulls)
hull.checkEntity(entity); hull.checkEntity(entity);
}); });
for (Hull hull : hulls)
hull.sendUncoveredBlocks();
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(EntityDeathEvent e) { 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) { public void updateREntity(REntity e) {
hulls.values().forEach(hull -> hull.checkREntity(e)); for(Hull hull : hulls)
hull.checkREntity(e);
} }
public void despawnREntity(REntity e) { public void despawnREntity(REntity e) {
hulls.values().forEach(hull -> hull.removeREntity(e)); for(Hull hull : hulls)
hull.removeREntity(e);
} }
@ -197,7 +232,7 @@ public class HullHider implements Listener {
} }
private Object packetHider(Player player, Object packet, Location location) { private Object packetHider(Player player, Object packet, Location location) {
for(Hull hull : hulls.values()) { for(Hull hull : hulls) {
if(hull.isLocationHidden(player, location)) if(hull.isLocationHidden(player, location))
return null; return null;
} }

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Hull.IntVector> changes);
}

Datei anzeigen

@ -31,6 +31,8 @@ import java.util.function.ObjIntConsumer;
@AllArgsConstructor @AllArgsConstructor
public class Region { 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) { 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, return Region.fromSize(minX - extendX, minY - extendY, minZ - extendZ,
sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2); sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2);
@ -80,6 +82,12 @@ public class Region {
getMinChunkZ() > cZ || cZ > getMaxChunkZ(); 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<Integer> executor) { public void forEachChunk(ObjIntConsumer<Integer> executor) {
for(int x = getMinChunkX(); x <= getMaxChunkX(); x++) for(int x = getMinChunkX(); x <= getMaxChunkX(); x++)
for(int z = getMinChunkZ(); z <= getMaxChunkZ(); z++) for(int z = getMinChunkZ(); z <= getMaxChunkZ(); z++)

Datei anzeigen

@ -22,29 +22,34 @@ package de.steamwar.fightsystem.utils;
import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.core.CraftbukkitWrapper;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; 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.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.techhider.ProtocolUtils; import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.techhider.TechHider; 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.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.concurrent.ConcurrentHashMap;
import java.util.Collections;
import java.util.List;
public class TechHiderWrapper extends StateDependent { public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator, Listener {
public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive;
private final ConcurrentHashMap<Player, Region> hiddenRegion = new ConcurrentHashMap<>();
private final TechHider techHider; private final TechHider techHider;
public TechHiderWrapper() { public TechHiderWrapper() {
super(ENABLED, FightState.Schem); super(ENABLED, FightState.Schem);
techHider = new TechHider(this::bypass, 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(); register();
} }
@ -56,43 +61,82 @@ public class TechHiderWrapper extends StateDependent {
@Override @Override
public void disable() { public void disable() {
techHider.disable(); techHider.disable();
hiddenRegion.clear();
} }
public List<ProtocolUtils.ChunkPos> prepareChunkReload(LivingEntity p, boolean hide) { @EventHandler
if(!ENABLED || !(p instanceof Player)) public void teamJoin(TeamSpawnEvent e) {
return Collections.emptyList(); e.getFightPlayer().ifPlayer(player -> hiddenRegion.put(player, getHiddenRegion(player)));
}
List<ProtocolUtils.ChunkPos> chunksToReload = new ArrayList<>(); @EventHandler
Config.ArenaRegion.forEachChunk((x, z) -> { public void boarding(BoardingEvent e) {
if(bypass((Player) p, x, z) == hide) e.getFightPlayer().ifPlayer(player -> hiddenRegion.put(player, getHiddenRegion(player)));
chunksToReload.add(new ProtocolUtils.ChunkPos(x, z)); }
@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<ProtocolUtils.ChunkPos> chunksToReload, boolean hide) { @EventHandler
if(!ENABLED || !FightState.Schem.contains(FightState.getFightState())) 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; return;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { region.forEachChunk((chunkX, chunkZ) -> {
for(ProtocolUtils.ChunkPos chunk : chunksToReload){ if(exclusion.chunkOutside(chunkX, chunkZ))
if(bypass(p, chunk.x(), chunk.z()) != hide) CraftbukkitWrapper.impl.sendChunk(player, chunkX, chunkZ);
CraftbukkitWrapper.impl.sendChunk(p, chunk.x(), chunk.z()); });
}
}, 40);
} }
private boolean bypass(Player p, int chunkX, int chunkZ){ @Override
if(Config.isReferee(p)) public boolean skipChunk(Player player, int chunkX, int chunkZ) {
return true; return getHiddenRegion(player).chunkOutside(chunkX, chunkZ);
}
FightTeam ft = Fight.getPlayerTeam(p); @Override
if(ft == null){ public boolean skipChunkSection(Player player, int chunkX, int chunkY, int chunkZ) {
return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); return getHiddenRegion(player).chunkSectionOutside(chunkX, chunkY, chunkZ);
}else if(ft.isBlue()){ }
return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ);
}else{ @Override
return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); public TechHider.State check(Player player, int x, int y, int z) {
if(hiddenRegion.computeIfAbsent(player, this::getHiddenRegion).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;
} }
} }
@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;
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return Config.ArenaRegion;
if(team.canPlayerEntern(player))
return Region.EMPTY;
return Fight.getOpposite(team).getExtendRegion();
}
} }