Trial removing Player NPCs from the paper per-player mob limits

This commit is contained in:
fullwall 2024-10-20 17:09:19 +08:00
parent ec4ba73ada
commit 708bf13afd
17 changed files with 89 additions and 19 deletions

View File

@ -282,6 +282,11 @@ public class CitizensNPC extends AbstractNPC {
getOrAddTrait(SneakTrait.class).setSneaking(sneaking); getOrAddTrait(SneakTrait.class).setSneaking(sneaking);
} }
@Override
public boolean shouldRemoveFromPlayerList() {
return data().get(NPC.Metadata.REMOVE_FROM_PLAYERLIST, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
}
@Override @Override
public boolean shouldRemoveFromTabList() { public boolean shouldRemoveFromTabList() {
return data().get(NPC.Metadata.REMOVE_FROM_TABLIST, Setting.DISABLE_TABLIST.asBoolean()); return data().get(NPC.Metadata.REMOVE_FROM_TABLIST, Setting.DISABLE_TABLIST.asBoolean());

View File

@ -375,6 +375,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
if (!npc.hasTrait(EntityPoseTrait.class) || npc.getTraitNullable(EntityPoseTrait.class).getPose() == null) { if (!npc.hasTrait(EntityPoseTrait.class) || npc.getTraitNullable(EntityPoseTrait.class).getPose() == null) {
eu(); eu();
} }
if (NMSImpl.PAPER_PLAYER_MOB_COUNTS != null && npc.shouldRemoveFromPlayerList()) {
int[] counts;
try {
counts = (int[]) NMSImpl.PAPER_PLAYER_MOB_COUNTS.invoke(this);
for (int i = 0; i < counts.length; i++) {
counts[i] = 0;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {

View File

@ -2367,6 +2367,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle NAVIGATION_S = NMS.getFinalSetter(NavigationAbstract.class, "s"); private static final MethodHandle NAVIGATION_S = NMS.getFinalSetter(NavigationAbstract.class, "s");
private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getSetter(NavigationAbstract.class, "b"); private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getSetter(NavigationAbstract.class, "b");
public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
public static final MethodHandle PAPER_PLAYER_MOB_COUNTS = NMS.getGetter(EntityPlayer.class, "mobCounts");
private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_GETTER = NMS.getGetter(PlayerChunkMap.class, private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_GETTER = NMS.getGetter(PlayerChunkMap.class,
"viewDistance"); "viewDistance");
private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_SETTER = NMS.getSetter(PlayerChunkMap.class, private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_SETTER = NMS.getSetter(PlayerChunkMap.class,

View File

@ -366,6 +366,17 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity()); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
updatePackets(npc.getNavigator().isNavigating()); updatePackets(npc.getNavigator().isNavigating());
npc.update(); npc.update();
if (NMSImpl.PAPER_PLAYER_MOB_COUNTS != null && npc.shouldRemoveFromPlayerList()) {
int[] counts;
try {
counts = (int[]) NMSImpl.PAPER_PLAYER_MOB_COUNTS.invoke(this);
for (int i = 0; i < counts.length; i++) {
counts[i] = 0;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
} }
@Override @Override

View File

@ -2345,6 +2345,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFinalSetter(PathNavigation.class, "t"); private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFinalSetter(PathNavigation.class, "t");
private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class); private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class);
public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
public static final MethodHandle PAPER_PLAYER_MOB_COUNTS = NMS.getGetter(ServerPlayer.class, "mobCounts");
private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_GETTER = NMS.getGetter(ChunkMap.class, "J"); private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_GETTER = NMS.getGetter(ChunkMap.class, "J");
private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_SETTER = NMS.getSetter(ChunkMap.class, "J"); private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_SETTER = NMS.getSetter(ChunkMap.class, "J");
private static final MethodHandle PUFFERFISH_C = NMS.getSetter(Pufferfish.class, "bU"); private static final MethodHandle PUFFERFISH_C = NMS.getSetter(Pufferfish.class, "bU");

View File

@ -363,6 +363,17 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity()); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
updatePackets(npc.getNavigator().isNavigating()); updatePackets(npc.getNavigator().isNavigating());
npc.update(); npc.update();
if (NMSImpl.PAPER_PLAYER_MOB_COUNTS != null && npc.shouldRemoveFromPlayerList()) {
int[] counts;
try {
counts = (int[]) NMSImpl.PAPER_PLAYER_MOB_COUNTS.invoke(this);
for (int i = 0; i < counts.length; i++) {
counts[i] = 0;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
} }
@Override @Override

View File

@ -48,9 +48,7 @@ public class HumanController extends AbstractEntityController {
if (getBukkitEntity() == null || !getBukkitEntity().isValid() if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity()) || getBukkitEntity() != handle.getBukkitEntity())
return; return;
boolean removeFromPlayerList = npc.data().get(NPC.Metadata.REMOVE_FROM_PLAYERLIST, NMS.addOrRemoveFromPlayerList(getBukkitEntity(), npc.shouldRemoveFromPlayerList());
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
}, 20); }, 20);
handle.getBukkitEntity().setSleepingIgnored(true); handle.getBukkitEntity().setSleepingIgnored(true);
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -2394,6 +2394,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFinalSetter(PathNavigation.class, "t"); private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFinalSetter(PathNavigation.class, "t");
private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class); private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class);
public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
public static final MethodHandle PAPER_PLAYER_MOB_COUNTS = NMS.getGetter(ServerPlayer.class, "mobCounts");
private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_GETTER = NMS.getGetter(ChunkMap.class, "N"); private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_GETTER = NMS.getGetter(ChunkMap.class, "N");
private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_SETTER = NMS.getSetter(ChunkMap.class, "N"); private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_SETTER = NMS.getSetter(ChunkMap.class, "N");
private static MethodHandle PORTAL_ENTRANCE_POS_GETTER = NMS.getGetter(Entity.class, "ai"); private static MethodHandle PORTAL_ENTRANCE_POS_GETTER = NMS.getGetter(Entity.class, "ai");

View File

@ -372,6 +372,17 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity()); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
updatePackets(npc.getNavigator().isNavigating()); updatePackets(npc.getNavigator().isNavigating());
npc.update(); npc.update();
if (NMSImpl.PAPER_PLAYER_MOB_COUNTS != null && npc.shouldRemoveFromPlayerList()) {
int[] counts;
try {
counts = (int[]) NMSImpl.PAPER_PLAYER_MOB_COUNTS.invoke(this);
for (int i = 0; i < counts.length; i++) {
counts[i] = 0;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
} }
@Override @Override

View File

@ -48,9 +48,7 @@ public class HumanController extends AbstractEntityController {
if (getBukkitEntity() == null || !getBukkitEntity().isValid() if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity()) || getBukkitEntity() != handle.getBukkitEntity())
return; return;
boolean removeFromPlayerList = npc.data().get(NPC.Metadata.REMOVE_FROM_PLAYERLIST, NMS.addOrRemoveFromPlayerList(getBukkitEntity(), npc.shouldRemoveFromPlayerList());
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
}, 20); }, 20);
handle.getBukkitEntity().setSleepingIgnored(true); handle.getBukkitEntity().setSleepingIgnored(true);
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -2632,6 +2632,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFirstFinalSetter(PathNavigation.class, private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFirstFinalSetter(PathNavigation.class,
PathFinder.class); PathFinder.class);
private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class); private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class);
public static final MethodHandle PAPER_PLAYER_MOB_COUNTS = NMS.getGetter(ServerPlayer.class, "mobCounts");
private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_GETTER = NMS.getFirstGetter(ChunkMap.class, private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_GETTER = NMS.getFirstGetter(ChunkMap.class,
int.class); int.class);
private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_SETTER = NMS.getFirstSetter(ChunkMap.class, private static final MethodHandle PLAYER_CHUNK_MAP_VIEW_DISTANCE_SETTER = NMS.getFirstSetter(ChunkMap.class,

View File

@ -377,6 +377,17 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity()); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
updatePackets(npc.getNavigator().isNavigating()); updatePackets(npc.getNavigator().isNavigating());
npc.update(); npc.update();
if (NMSImpl.PAPER_PLAYER_MOB_COUNTS != null && npc.shouldRemoveFromPlayerList()) {
int[] counts;
try {
counts = (int[]) NMSImpl.PAPER_PLAYER_MOB_COUNTS.invoke(this);
for (int i = 0; i < counts.length; i++) {
counts[i] = 0;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
} }
@Override @Override

View File

@ -50,9 +50,7 @@ public class HumanController extends AbstractEntityController {
if (getBukkitEntity() == null || !getBukkitEntity().isValid() if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity()) || getBukkitEntity() != handle.getBukkitEntity())
return; return;
boolean removeFromPlayerList = npc.data().get(NPC.Metadata.REMOVE_FROM_PLAYERLIST, NMS.addOrRemoveFromPlayerList(getBukkitEntity(), npc.shouldRemoveFromPlayerList());
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
}, 20); }, 20);
handle.getBukkitEntity().setSleepingIgnored(true); handle.getBukkitEntity().setSleepingIgnored(true);
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -2723,9 +2723,10 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFirstFinalSetter(PathNavigation.class, private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFirstFinalSetter(PathNavigation.class,
PathFinder.class); PathFinder.class);
private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class); private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class);
public static final MethodHandle PAPER_PLAYER_MOB_COUNTS = NMS.getGetter(ServerPlayer.class, "mobCounts");
private static final MethodHandle PLAYER_INFO_ENTRIES_LIST = NMS private static final MethodHandle PLAYER_INFO_ENTRIES_LIST = NMS
.getFirstFinalSetter(ClientboundPlayerInfoUpdatePacket.class, List.class); .getFirstFinalSetter(ClientboundPlayerInfoUpdatePacket.class, List.class);
private static final MethodHandle PLAYERINFO_ENTRIES = PLAYER_INFO_ENTRIES_LIST; private static final MethodHandle PLAYERINFO_ENTRIES = PLAYER_INFO_ENTRIES_LIST;
private static final MethodHandle PORTAL_ENTRANCE_POS_GETTER = NMS.getGetter(Entity.class, "ay"); private static final MethodHandle PORTAL_ENTRANCE_POS_GETTER = NMS.getGetter(Entity.class, "ay");
private static final MethodHandle PORTAL_ENTRANCE_POS_SETTER = NMS.getSetter(Entity.class, "ay"); private static final MethodHandle PORTAL_ENTRANCE_POS_SETTER = NMS.getSetter(Entity.class, "ay");

View File

@ -376,6 +376,17 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity()); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
updatePackets(npc.getNavigator().isNavigating()); updatePackets(npc.getNavigator().isNavigating());
npc.update(); npc.update();
if (NMSImpl.PAPER_PLAYER_MOB_COUNTS != null && npc.shouldRemoveFromPlayerList()) {
int[] counts;
try {
counts = (int[]) NMSImpl.PAPER_PLAYER_MOB_COUNTS.invoke(this);
for (int i = 0; i < counts.length; i++) {
counts[i] = 0;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
} }
@Override @Override

View File

@ -50,9 +50,7 @@ public class HumanController extends AbstractEntityController {
if (getBukkitEntity() == null || !getBukkitEntity().isValid() if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity()) || getBukkitEntity() != handle.getBukkitEntity())
return; return;
boolean removeFromPlayerList = npc.data().get(NPC.Metadata.REMOVE_FROM_PLAYERLIST, NMS.addOrRemoveFromPlayerList(getBukkitEntity(), npc.shouldRemoveFromPlayerList());
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
}, 20); }, 20);
handle.getBukkitEntity().setSleepingIgnored(true); handle.getBukkitEntity().setSleepingIgnored(true);
return handle.getBukkitEntity(); return handle.getBukkitEntity();

View File

@ -612,6 +612,12 @@ public class NMSImpl implements NMSBridge {
return NMSBoundingBox.wrap(getHandle(handle).getBoundingBox()); return NMSBoundingBox.wrap(getHandle(handle).getBoundingBox());
} }
@Override
public BoundingBox getCollisionBox(Object data) {
return NMSBoundingBox.wrap(((CraftBlockData) data).getState()
.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO, CollisionContext.empty()).bounds());
}
@Override @Override
public BoundingBox getCollisionBox(org.bukkit.block.Block block) { public BoundingBox getCollisionBox(org.bukkit.block.Block block) {
ServerLevel world = ((CraftWorld) block.getWorld()).getHandle(); ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
@ -619,12 +625,6 @@ public class NMSImpl implements NMSBridge {
return shape.isEmpty() ? BoundingBox.EMPTY : NMSBoundingBox.wrap(shape.bounds()); return shape.isEmpty() ? BoundingBox.EMPTY : NMSBoundingBox.wrap(shape.bounds());
} }
@Override
public BoundingBox getCollisionBox(Object data) {
return NMSBoundingBox.wrap(((CraftBlockData) data).getState()
.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO, CollisionContext.empty()).bounds());
}
@Override @Override
public Map<String, Object> getComponentMap(org.bukkit.inventory.ItemStack item) { public Map<String, Object> getComponentMap(org.bukkit.inventory.ItemStack item) {
if (META_COMPOUND_TAG == null) { if (META_COMPOUND_TAG == null) {
@ -2651,6 +2651,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle ATTRIBUTE_SUPPLIER = NMS.getFirstGetter(AttributeMap.class, private static final MethodHandle ATTRIBUTE_SUPPLIER = NMS.getFirstGetter(AttributeMap.class,
AttributeSupplier.class); AttributeSupplier.class);
private static final MethodHandle AVAILABLE_BEHAVIORS_BY_PRIORITY = NMS.getGetter(Brain.class, "f"); private static final MethodHandle AVAILABLE_BEHAVIORS_BY_PRIORITY = NMS.getGetter(Brain.class, "f");
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.BEE, private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.BEE,
EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT,
@ -2704,6 +2705,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFirstFinalSetter(PathNavigation.class, private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFirstFinalSetter(PathNavigation.class,
PathFinder.class); PathFinder.class);
private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class); private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class);
public static final MethodHandle PAPER_PLAYER_MOB_COUNTS = NMS.getGetter(ServerPlayer.class, "mobCounts");
private static final MethodHandle PLAYER_INFO_ENTRIES_LIST = NMS private static final MethodHandle PLAYER_INFO_ENTRIES_LIST = NMS
.getFirstFinalSetter(ClientboundPlayerInfoUpdatePacket.class, List.class); .getFirstFinalSetter(ClientboundPlayerInfoUpdatePacket.class, List.class);
private static final MethodHandle PLAYERINFO_ENTRIES = PLAYER_INFO_ENTRIES_LIST; private static final MethodHandle PLAYERINFO_ENTRIES = PLAYER_INFO_ENTRIES_LIST;