forked from SteamWar/SteamWar
Fix entity hider.
This commit is contained in:
@@ -26,6 +26,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -72,16 +73,16 @@ public class BlockIdWrapper14 implements BlockIdWrapper {
|
||||
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) {
|
||||
Object tracker = trackers.get(entity);
|
||||
public void trackEntity(Player player, Entity entity) {
|
||||
Object tracker = trackers.get(entity.getEntityId());
|
||||
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) {
|
||||
Object tracker = trackers.get(entity);
|
||||
public void untrackEntity(Player player, Entity entity) {
|
||||
Object tracker = trackers.get(entity.getEntityId());
|
||||
if(tracker != null)
|
||||
clearPlayer.invoke(tracker, getPlayer.invoke(player));
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ plugins {
|
||||
dependencies {
|
||||
compileOnly(project(":SpigotCore", "default"))
|
||||
compileOnly(project(":FightSystem:FightSystem_Core", "default"))
|
||||
compileOnly(project(":FightSystem:FightSystem_14", "default"))
|
||||
|
||||
compileOnly(libs.spigotapi)
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BlockIdWrapper18 extends BlockIdWrapper14 {
|
||||
|
||||
private static final Reflection.FieldAccessor<Map> hiddenEntities = Reflection.getField(Reflection.getClass("{obc}.entity.CraftPlayer"), Map.class, 0, UUID.class, Set.class);
|
||||
@Override
|
||||
public void trackEntity(Player player, Entity entity) {
|
||||
hiddenEntities.get(player).remove(entity.getUniqueId());
|
||||
super.trackEntity(player, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untrackEntity(Player player, Entity entity) {
|
||||
hiddenEntities.get(player).put(entity.getUniqueId(), Collections.emptySet());
|
||||
super.untrackEntity(player, entity);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import de.steamwar.fightsystem.Config;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockIdWrapper8 implements BlockIdWrapper {
|
||||
@@ -57,16 +58,16 @@ public class BlockIdWrapper8 implements BlockIdWrapper {
|
||||
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) {
|
||||
Object tracker = get.invoke(trackers, entity);
|
||||
public void trackEntity(Player player, Entity entity) {
|
||||
Object tracker = get.invoke(trackers, entity.getEntityId());
|
||||
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) {
|
||||
Object tracker = get.invoke(trackers, entity);
|
||||
public void untrackEntity(Player player, Entity entity) {
|
||||
Object tracker = get.invoke(trackers, entity.getEntityId());
|
||||
if(tracker != null)
|
||||
clearPlayer.invoke(tracker, getPlayer.invoke(player));
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface BlockIdWrapper {
|
||||
@@ -41,6 +42,6 @@ public interface BlockIdWrapper {
|
||||
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);
|
||||
void trackEntity(Player player, Entity entity);
|
||||
void untrackEntity(Player player, Entity entity);
|
||||
}
|
||||
|
||||
@@ -87,18 +87,16 @@ public class Hull {
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
System.out.println("Added " + player + " to " + region.centerZ());
|
||||
if(players.add(player)) {
|
||||
for(Entity entity : entities)
|
||||
BlockIdWrapper.impl.untrackEntity(player, entity.getEntityId());
|
||||
BlockIdWrapper.impl.untrackEntity(player, entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(Player player, boolean activeRemoval) {
|
||||
System.out.println("Removed " + player + " from " + region.centerZ());
|
||||
if(players.remove(player) && activeRemoval) {
|
||||
for(Entity entity : entities)
|
||||
BlockIdWrapper.impl.trackEntity(player, entity.getEntityId());
|
||||
BlockIdWrapper.impl.trackEntity(player, entity);
|
||||
// techhider triggers block change sending
|
||||
}
|
||||
}
|
||||
@@ -108,12 +106,12 @@ public class Hull {
|
||||
if(region.inRegion(location) && !visibility.get(new IntVector(location).toId(region))) {
|
||||
if(entities.add(entity)) {
|
||||
for(Player player : players)
|
||||
BlockIdWrapper.impl.untrackEntity(player, entity.getEntityId());
|
||||
BlockIdWrapper.impl.untrackEntity(player, entity);
|
||||
}
|
||||
} else {
|
||||
if(entities.remove(entity)) {
|
||||
for(Player player : players)
|
||||
BlockIdWrapper.impl.trackEntity(player, entity.getEntityId());
|
||||
BlockIdWrapper.impl.trackEntity(player, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,7 +181,7 @@ public class Hull {
|
||||
if(uncoveredSet.contains(new IntVector(entity.getLocation()))) {
|
||||
it.remove();
|
||||
for(Player player : players)
|
||||
BlockIdWrapper.impl.trackEntity(player, entity.getEntityId());
|
||||
BlockIdWrapper.impl.trackEntity(player, entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user