Use metadata and track players if on the playerlist which should make mobs spawn nearby

This commit is contained in:
fullwall 2021-12-28 20:13:25 +08:00
parent 750f8e2e4c
commit 19ee0e2c19
16 changed files with 65 additions and 14 deletions

View File

@ -1569,13 +1569,14 @@ public class NPCCommands {
permission = "citizens.npc.playerlist")
@Requirements(selected = true, ownership = true, types = EntityType.PLAYER)
public void playerlist(CommandContext args, CommandSender sender, NPC npc) {
boolean remove = !npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
boolean remove = !npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA,
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
if (args.hasFlag('a')) {
remove = false;
} else if (args.hasFlag('r')) {
remove = true;
}
npc.data().setPersistent("removefromplayerlist", remove);
npc.data().setPersistent(NPC.REMOVE_FROM_PLAYERLIST_METADATA, remove);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getOrAddTrait(CurrentLocation.class).getLocation(), SpawnReason.RESPAWN);

View File

@ -235,7 +235,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public IChatBaseComponent getPlayerListName() {
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
if (npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean())) {
return new ChatComponentText("");
}
return super.getPlayerListName();

View File

@ -255,7 +255,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public IChatBaseComponent getPlayerListName() {
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
if (npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean())) {
return new ChatComponentText("");
}
return super.getPlayerListName();

View File

@ -238,7 +238,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public IChatBaseComponent getPlayerListName() {
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
if (npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean())) {
return new ChatComponentText("");
}
return super.getPlayerListName();

View File

@ -229,7 +229,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public IChatBaseComponent getPlayerListName() {
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
if (npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean())) {
return new ChatComponentText("");
}
return super.getPlayerListName();

View File

@ -308,6 +308,13 @@ public class NMSImpl implements NMSBridge {
} else if (!handle.world.getPlayers().contains(handle)) {
((List) handle.world.getPlayers()).add(handle);
}
try {
CHUNKMAP_UPDATE_PLAYER_STATUS.invoke(((WorldServer) handle.world).getChunkProvider().playerChunkMap, handle,
!remove);
} catch (Throwable e) {
e.printStackTrace();
}
// PlayerUpdateTask.addOrRemove(entity, remove);
}
@ -1834,10 +1841,13 @@ public class NMSImpl implements NMSBridge {
EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME,
EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST, EntityType.SHULKER,
EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(BehaviorController.class, "c");
private static final MethodHandle BLOCK_POSITION_B_D = NMS.getMethodHandle(BlockPosition.PooledBlockPosition.class,
"c", false, double.class, double.class, double.class);
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(PlayerChunkMap.class, "a",
true, EntityPlayer.class, boolean.class);
private static final Map<Class<?>, EntityTypes<?>> CITIZENS_ENTITY_TYPES = Maps.newHashMap();
private static final MethodHandle CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getSetter(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;

View File

@ -222,7 +222,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public IChatBaseComponent getPlayerListName() {
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
if (npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean())) {
return new ChatComponentText("");
}
return super.getPlayerListName();

View File

@ -312,6 +312,13 @@ public class NMSImpl implements NMSBridge {
} else if (!handle.world.getPlayers().contains(handle)) {
((List) handle.world.getPlayers()).add(handle);
}
try {
CHUNKMAP_UPDATE_PLAYER_STATUS.invoke(((WorldServer) handle.world).getChunkProvider().playerChunkMap, handle,
!remove);
} catch (Throwable e) {
e.printStackTrace();
}
// PlayerUpdateTask.addOrRemove(entity, remove);
}
@ -1888,8 +1895,11 @@ public class NMSImpl implements NMSBridge {
EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT,
EntityType.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST,
EntityType.SHULKER, EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(BehaviorController.class, "c");
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(PlayerChunkMap.class, "a",
true, EntityPlayer.class, boolean.class);
private static final Map<Class<?>, EntityTypes<?>> CITIZENS_ENTITY_TYPES = Maps.newHashMap();
private static final MethodHandle CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getSetter(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;

View File

@ -235,7 +235,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public IChatBaseComponent getPlayerListName() {
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
if (npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean())) {
return new ChatComponentText("");
}
return super.getPlayerListName();

View File

@ -319,6 +319,13 @@ public class NMSImpl implements NMSBridge {
} else if (!handle.world.getPlayers().contains(handle)) {
((List) handle.world.getPlayers()).add(handle);
}
try {
CHUNKMAP_UPDATE_PLAYER_STATUS.invoke(((WorldServer) handle.world).getChunkProvider().playerChunkMap, handle,
!remove);
} catch (Throwable e) {
e.printStackTrace();
}
// PlayerUpdateTask.addOrRemove(entity, remove);
}
@ -1859,12 +1866,15 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class,
"advancementDataPlayer");
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.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST,
EntityType.SHULKER, EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(BehaviorController.class, "e");
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(PlayerChunkMap.class, "a",
true, EntityPlayer.class, boolean.class);
private static final Map<Class<?>, EntityTypes<?>> CITIZENS_ENTITY_TYPES = Maps.newHashMap();
private static final MethodHandle CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getSetter(CraftBossBar.class, "handle");
private static MethodHandle CRAFTSOUND_GETSOUND = NMS.getMethodHandle(CraftSound.class, "getSound", false,

View File

@ -285,7 +285,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
@Override
public Component getTabListDisplayName() {
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
if (npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean())) {
return new TextComponent("");
}
return super.getTabListDisplayName();

View File

@ -319,6 +319,13 @@ public class NMSImpl implements NMSBridge {
} else if (!handle.level.players().contains(handle)) {
((List) handle.level.players()).add(handle);
}
try {
CHUNKMAP_UPDATE_PLAYER_STATUS.invoke(
((ServerChunkCache) ((ServerLevel) handle.level).getChunkSource()).chunkMap, handle, !remove);
} catch (Throwable e) {
e.printStackTrace();
}
// PlayerUpdateTask.addOrRemove(entity, remove);
}
@ -1868,12 +1875,15 @@ public class NMSImpl implements NMSBridge {
}
private static final MethodHandle ADVANCEMENTS_PLAYER_FIELD = NMS.getFinalSetter(ServerPlayer.class, "cr");
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.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST,
EntityType.SHULKER, EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(Brain.class, "f");
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(ChunkMap.class, "a", true,
ServerPlayer.class, boolean.class);
private static final Map<Class<?>, net.minecraft.world.entity.EntityType<?>> CITIZENS_ENTITY_TYPES = Maps
.newHashMap();
private static final MethodHandle CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getSetter(CraftBossBar.class, "handle");

View File

@ -285,7 +285,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
@Override
public Component getTabListDisplayName() {
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
if (npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA, Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean())) {
return new TextComponent("");
}
return super.getTabListDisplayName();
@ -489,7 +489,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
updatePackets(npc.getNavigator().isNavigating());
npc.update();
}

View File

@ -62,7 +62,7 @@ public class HumanController extends AbstractEntityController {
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
boolean removeFromPlayerList = npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA,
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
}

View File

@ -319,6 +319,13 @@ public class NMSImpl implements NMSBridge {
} else if (!handle.level.players().contains(handle)) {
((List) handle.level.players()).add(handle);
}
try {
CHUNKMAP_UPDATE_PLAYER_STATUS.invoke(((ServerLevel) handle.level).getChunkSource().chunkMap, handle,
!remove);
} catch (Throwable e) {
e.printStackTrace();
}
// PlayerUpdateTask.addOrRemove(entity, remove);
}
@ -1291,7 +1298,7 @@ public class NMSImpl implements NMSBridge {
throw new ReportedException(crashreport);
}
}
boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist",
boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA,
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
if (!entity.isAlive()) {
((ServerLevel) entity.level).getChunkSource().removeEntity(entity);
@ -1868,12 +1875,16 @@ public class NMSImpl implements NMSBridge {
}
private static final MethodHandle ADVANCEMENTS_PLAYER_FIELD = NMS.getFinalSetter(ServerPlayer.class, "cs");
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.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST,
EntityType.SHULKER, EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_TREE_MAP = NMS.getGetter(Brain.class, "f");
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(ChunkMap.class, "a", true,
ServerPlayer.class, boolean.class);
private static final Map<Class<?>, net.minecraft.world.entity.EntityType<?>> CITIZENS_ENTITY_TYPES = Maps
.newHashMap();
private static final MethodHandle CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getSetter(CraftBossBar.class, "handle");

View File

@ -65,7 +65,7 @@ public class HumanController extends AbstractEntityController {
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
boolean removeFromPlayerList = npc.data().get(NPC.REMOVE_FROM_PLAYERLIST_METADATA,
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
}