mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 04:35:50 +01:00
Implement player filtering, replace all entity trackers, compatibility update for async entity tracking
This commit is contained in:
parent
ebcc9c1e8e
commit
b02a3d8766
@ -70,6 +70,7 @@ import net.citizensnpcs.commands.TemplateCommands;
|
|||||||
import net.citizensnpcs.commands.TraitCommands;
|
import net.citizensnpcs.commands.TraitCommands;
|
||||||
import net.citizensnpcs.commands.WaypointCommands;
|
import net.citizensnpcs.commands.WaypointCommands;
|
||||||
import net.citizensnpcs.editor.Editor;
|
import net.citizensnpcs.editor.Editor;
|
||||||
|
import net.citizensnpcs.model.ModelRegistry;
|
||||||
import net.citizensnpcs.npc.CitizensNPCRegistry;
|
import net.citizensnpcs.npc.CitizensNPCRegistry;
|
||||||
import net.citizensnpcs.npc.CitizensTraitFactory;
|
import net.citizensnpcs.npc.CitizensTraitFactory;
|
||||||
import net.citizensnpcs.npc.NPCSelector;
|
import net.citizensnpcs.npc.NPCSelector;
|
||||||
@ -93,6 +94,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
private Settings config;
|
private Settings config;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private LocationLookup locationLookup;
|
private LocationLookup locationLookup;
|
||||||
|
private ModelRegistry modelRegistry;
|
||||||
private final NMSHelper nmsHelper = new NMSHelper() {
|
private final NMSHelper nmsHelper = new NMSHelper() {
|
||||||
private boolean SUPPORT_OWNER_PROFILE = true;
|
private boolean SUPPORT_OWNER_PROFILE = true;
|
||||||
|
|
||||||
@ -245,6 +247,10 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
return locationLookup;
|
return locationLookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModelRegistry getModelRegistry() {
|
||||||
|
return modelRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NPCRegistry getNamedNPCRegistry(String name) {
|
public NPCRegistry getNamedNPCRegistry(String name) {
|
||||||
if (name.equals(npcRegistry.getName()))
|
if (name.equals(npcRegistry.getName()))
|
||||||
@ -384,6 +390,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
Editor.leaveAll();
|
Editor.leaveAll();
|
||||||
despawnNPCs(saveOnDisable);
|
despawnNPCs(saveOnDisable);
|
||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
|
modelRegistry.reset();
|
||||||
npcRegistry = null;
|
npcRegistry = null;
|
||||||
locationLookup = null;
|
locationLookup = null;
|
||||||
enabled = false;
|
enabled = false;
|
||||||
@ -436,6 +443,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
return new ShopTrait(shops);
|
return new ShopTrait(shops);
|
||||||
}));
|
}));
|
||||||
selector = new NPCSelector(this);
|
selector = new NPCSelector(this);
|
||||||
|
modelRegistry = new ModelRegistry();
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new EventListen(storedRegistries), this);
|
Bukkit.getPluginManager().registerEvents(new EventListen(storedRegistries), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new Placeholders(), this);
|
Bukkit.getPluginManager().registerEvents(new Placeholders(), this);
|
||||||
@ -509,9 +517,12 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
despawnNPCs(false);
|
despawnNPCs(false);
|
||||||
ProfileFetcher.reset();
|
ProfileFetcher.reset();
|
||||||
Skin.clearCache();
|
Skin.clearCache();
|
||||||
|
modelRegistry.reset();
|
||||||
|
|
||||||
getServer().getPluginManager().callEvent(new CitizensPreReloadEvent());
|
getServer().getPluginManager().callEvent(new CitizensPreReloadEvent());
|
||||||
|
|
||||||
|
modelRegistry.load(new File(Setting.RESOURCE_PACK_PATH.asString()), new File(getDataFolder(), "models"));
|
||||||
|
|
||||||
saves.reloadFromSource();
|
saves.reloadFromSource();
|
||||||
saves.loadInto(npcRegistry);
|
saves.loadInto(npcRegistry);
|
||||||
|
|
||||||
@ -617,6 +628,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
private class CitizensLoadTask implements Runnable {
|
private class CitizensLoadTask implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
modelRegistry.load(new File(Setting.RESOURCE_PACK_PATH.asString()), new File(getDataFolder(), "models"));
|
||||||
saves.loadInto(npcRegistry);
|
saves.loadInto(npcRegistry);
|
||||||
shops.load();
|
shops.load();
|
||||||
|
|
||||||
|
@ -160,6 +160,7 @@ public class Settings {
|
|||||||
PLACEHOLDER_SKIN_UPDATE_FREQUENCY("npc.skins.placeholder-update-frequency-ticks", 5 * 60 * 20),
|
PLACEHOLDER_SKIN_UPDATE_FREQUENCY("npc.skins.placeholder-update-frequency-ticks", 5 * 60 * 20),
|
||||||
PLAYER_TELEPORT_DELAY("npc.teleport-delay", "npc.delay-player-teleport-ticks", -1),
|
PLAYER_TELEPORT_DELAY("npc.teleport-delay", "npc.delay-player-teleport-ticks", -1),
|
||||||
REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true),
|
REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true),
|
||||||
|
RESOURCE_PACK_PATH("general.resource-pack-path", "plugins/Citizens/resourcepack"),
|
||||||
SAVE_TASK_DELAY("storage.save-task.delay", 20 * 60 * 60),
|
SAVE_TASK_DELAY("storage.save-task.delay", 20 * 60 * 60),
|
||||||
SCOREBOARD_SEND_TICKS("npc.scoreboard-teams.packet-send-ticks", 1),
|
SCOREBOARD_SEND_TICKS("npc.scoreboard-teams.packet-send-ticks", 1),
|
||||||
SELECTION_ITEM("npc.selection.item", "stick"),
|
SELECTION_ITEM("npc.selection.item", "stick"),
|
||||||
|
@ -84,6 +84,7 @@ import net.citizensnpcs.api.trait.Trait;
|
|||||||
import net.citizensnpcs.api.trait.trait.Inventory;
|
import net.citizensnpcs.api.trait.trait.Inventory;
|
||||||
import net.citizensnpcs.api.trait.trait.MobType;
|
import net.citizensnpcs.api.trait.trait.MobType;
|
||||||
import net.citizensnpcs.api.trait.trait.Owner;
|
import net.citizensnpcs.api.trait.trait.Owner;
|
||||||
|
import net.citizensnpcs.api.trait.trait.PlayerFilter;
|
||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.api.trait.trait.Speech;
|
import net.citizensnpcs.api.trait.trait.Speech;
|
||||||
import net.citizensnpcs.api.util.EntityDim;
|
import net.citizensnpcs.api.util.EntityDim;
|
||||||
@ -642,7 +643,7 @@ public class NPCCommands {
|
|||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "create [name] ((-b(aby),u(nspawned),s(ilent),t(emporary),c(enter),p(acket)) --at [x:y:z:world] --type [type] --item (item) --trait ['trait1, trait2...'] --nameplate [true|false|hover] --temporaryticks [ticks] --registry [registry name]",
|
usage = "create [name] ((-b(aby),u(nspawned),s(ilent),t(emporary),c(enter),p(acket)) --at [x:y:z:world] --type [type] --item (item) --trait ['trait1, trait2...'] --model [model name] --nameplate [true|false|hover] --temporaryticks [ticks] --registry [registry name]",
|
||||||
desc = "Create a new NPC",
|
desc = "Create a new NPC",
|
||||||
flags = "bustpc",
|
flags = "bustpc",
|
||||||
modifiers = { "create" },
|
modifiers = { "create" },
|
||||||
@ -652,7 +653,7 @@ public class NPCCommands {
|
|||||||
public void create(CommandContext args, CommandSender sender, NPC npc, @Flag("at") Location at,
|
public void create(CommandContext args, CommandSender sender, NPC npc, @Flag("at") Location at,
|
||||||
@Flag(value = "type", defValue = "PLAYER") EntityType type, @Flag("trait") String traits,
|
@Flag(value = "type", defValue = "PLAYER") EntityType type, @Flag("trait") String traits,
|
||||||
@Flag(value = "nameplate", completions = { "true", "false", "hover" }) String nameplate,
|
@Flag(value = "nameplate", completions = { "true", "false", "hover" }) String nameplate,
|
||||||
@Flag("temporaryticks") Integer temporaryTicks, @Flag("item") String item,
|
@Flag("temporaryticks") Integer temporaryTicks, @Flag("item") String item, @Flag("model") String model,
|
||||||
@Flag("template") String templateName, @Flag("registry") String registryName) throws CommandException {
|
@Flag("template") String templateName, @Flag("registry") String registryName) throws CommandException {
|
||||||
String name = args.getJoinedStrings(1).trim();
|
String name = args.getJoinedStrings(1).trim();
|
||||||
if (args.hasValueFlag("type")) {
|
if (args.hasValueFlag("type")) {
|
||||||
@ -689,6 +690,10 @@ public class NPCCommands {
|
|||||||
registry = temporaryRegistry;
|
registry = temporaryRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (model != null) {
|
||||||
|
type = EntityType.ARMOR_STAND;
|
||||||
|
}
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
ItemStack stack = new ItemStack(Material.STONE, 1);
|
ItemStack stack = new ItemStack(Material.STONE, 1);
|
||||||
try {
|
try {
|
||||||
@ -2066,6 +2071,31 @@ public class NPCCommands {
|
|||||||
animation.play((Player) npc.getEntity(), 64);
|
animation.play((Player) npc.getEntity(), 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
aliases = { "npc" },
|
||||||
|
usage = "playerfilter --hide [uuid] --unhide [uuid] --only [uuid]",
|
||||||
|
desc = "Sets the NPC filter",
|
||||||
|
modifiers = { "playerfilter" },
|
||||||
|
min = 1,
|
||||||
|
max = 1,
|
||||||
|
permission = "citizens.npc.playerfilter")
|
||||||
|
public void playerfilter(CommandContext args, CommandSender sender, NPC npc, @Flag("hide") UUID hide,
|
||||||
|
@Flag("unhide") UUID unhide, @Flag("only") UUID only) {
|
||||||
|
PlayerFilter trait = npc.getOrAddTrait(PlayerFilter.class);
|
||||||
|
if (hide != null) {
|
||||||
|
trait.hide(hide);
|
||||||
|
Messaging.sendTr(sender, Messages.PLAYERFILTER_PLAYER_HIDDEN, hide, npc.getName());
|
||||||
|
}
|
||||||
|
if (unhide != null) {
|
||||||
|
trait.unhide(unhide);
|
||||||
|
Messaging.sendTr(sender, Messages.PLAYERFILTER_PLAYER_UNHIDDEN, unhide, npc.getName());
|
||||||
|
}
|
||||||
|
if (only != null) {
|
||||||
|
trait.only(only);
|
||||||
|
Messaging.sendTr(sender, Messages.PLAYERFILTER_PLAYER_ONLY_ADDED, only, npc.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "playerlist (-a,r)",
|
usage = "playerlist (-a,r)",
|
||||||
|
@ -378,6 +378,8 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EntityType type = getEntity().getType();
|
EntityType type = getEntity().getType();
|
||||||
|
NMS.replaceTracker(getEntity());
|
||||||
|
|
||||||
if (type.isAlive()) {
|
if (type.isAlive()) {
|
||||||
LivingEntity entity = (LivingEntity) getEntity();
|
LivingEntity entity = (LivingEntity) getEntity();
|
||||||
entity.setRemoveWhenFarAway(false);
|
entity.setRemoveWhenFarAway(false);
|
||||||
@ -387,7 +389,6 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type == EntityType.PLAYER) {
|
if (type == EntityType.PLAYER) {
|
||||||
NMS.replaceTrackerEntry((Player) getEntity());
|
|
||||||
PlayerUpdateTask.registerPlayer(getEntity());
|
PlayerUpdateTask.registerPlayer(getEntity());
|
||||||
} else if (data().has(NPC.Metadata.AGGRESSIVE)) {
|
} else if (data().has(NPC.Metadata.AGGRESSIVE)) {
|
||||||
NMS.setAggressive(entity, data().<Boolean> get(NPC.Metadata.AGGRESSIVE));
|
NMS.setAggressive(entity, data().<Boolean> get(NPC.Metadata.AGGRESSIVE));
|
||||||
|
@ -17,8 +17,10 @@ import net.citizensnpcs.api.trait.trait.Equipment;
|
|||||||
import net.citizensnpcs.api.trait.trait.Inventory;
|
import net.citizensnpcs.api.trait.trait.Inventory;
|
||||||
import net.citizensnpcs.api.trait.trait.MobType;
|
import net.citizensnpcs.api.trait.trait.MobType;
|
||||||
import net.citizensnpcs.api.trait.trait.Owner;
|
import net.citizensnpcs.api.trait.trait.Owner;
|
||||||
|
import net.citizensnpcs.api.trait.trait.PlayerFilter;
|
||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.api.trait.trait.Speech;
|
import net.citizensnpcs.api.trait.trait.Speech;
|
||||||
|
import net.citizensnpcs.model.ModelTrait;
|
||||||
import net.citizensnpcs.trait.Age;
|
import net.citizensnpcs.trait.Age;
|
||||||
import net.citizensnpcs.trait.Anchors;
|
import net.citizensnpcs.trait.Anchors;
|
||||||
import net.citizensnpcs.trait.ArmorStandTrait;
|
import net.citizensnpcs.trait.ArmorStandTrait;
|
||||||
@ -89,12 +91,14 @@ public class CitizensTraitFactory implements TraitFactory {
|
|||||||
registerTrait(TraitInfo.create(Inventory.class));
|
registerTrait(TraitInfo.create(Inventory.class));
|
||||||
registerTrait(TraitInfo.create(LookClose.class));
|
registerTrait(TraitInfo.create(LookClose.class));
|
||||||
registerTrait(TraitInfo.create(MirrorTrait.class));
|
registerTrait(TraitInfo.create(MirrorTrait.class));
|
||||||
|
registerTrait(TraitInfo.create(ModelTrait.class).withSupplier(() -> new ModelTrait(plugin.getModelRegistry())));
|
||||||
registerTrait(TraitInfo.create(MountTrait.class));
|
registerTrait(TraitInfo.create(MountTrait.class));
|
||||||
registerTrait(TraitInfo.create(MobType.class).asDefaultTrait());
|
registerTrait(TraitInfo.create(MobType.class).asDefaultTrait());
|
||||||
registerTrait(TraitInfo.create(OcelotModifiers.class));
|
registerTrait(TraitInfo.create(OcelotModifiers.class));
|
||||||
registerTrait(TraitInfo.create(Owner.class));
|
registerTrait(TraitInfo.create(Owner.class));
|
||||||
registerTrait(TraitInfo.create(PacketNPC.class));
|
registerTrait(TraitInfo.create(PacketNPC.class));
|
||||||
registerTrait(TraitInfo.create(PausePathfindingTrait.class));
|
registerTrait(TraitInfo.create(PausePathfindingTrait.class));
|
||||||
|
registerTrait(TraitInfo.create(PlayerFilter.class));
|
||||||
registerTrait(TraitInfo.create(Poses.class));
|
registerTrait(TraitInfo.create(Poses.class));
|
||||||
registerTrait(TraitInfo.create(Powered.class));
|
registerTrait(TraitInfo.create(Powered.class));
|
||||||
registerTrait(TraitInfo.create(RabbitType.class));
|
registerTrait(TraitInfo.create(RabbitType.class));
|
||||||
|
@ -318,6 +318,9 @@ public class Messages {
|
|||||||
public static final String PIGLIN_DANCING_SET = "citizens.commands.npc.piglin.dancing-set";
|
public static final String PIGLIN_DANCING_SET = "citizens.commands.npc.piglin.dancing-set";
|
||||||
public static final String PIGLIN_DANCING_UNSET = "citizens.commands.npc.piglin.dancing-unset";
|
public static final String PIGLIN_DANCING_UNSET = "citizens.commands.npc.piglin.dancing-unset";
|
||||||
public static final String PLAYER_NOT_FOUND_FOR_SPAWN = "citizens.commands.npc.create.no-player-for-spawn";
|
public static final String PLAYER_NOT_FOUND_FOR_SPAWN = "citizens.commands.npc.create.no-player-for-spawn";
|
||||||
|
public static final String PLAYERFILTER_PLAYER_HIDDEN = "citizens.commands.npc.playerfilter.hidden";
|
||||||
|
public static final String PLAYERFILTER_PLAYER_ONLY_ADDED = "citizens.commands.npc.playerfilter.only-added";
|
||||||
|
public static final String PLAYERFILTER_PLAYER_UNHIDDEN = "citizens.commands.npc.playerfilter.unhidden";
|
||||||
public static final String POLAR_BEAR_REARING = "citizens.commands.npc.polarbear.rearing-set";
|
public static final String POLAR_BEAR_REARING = "citizens.commands.npc.polarbear.rearing-set";
|
||||||
public static final String POLAR_BEAR_STOPPED_REARING = "citizens.commands.npc.polarbear.rearing-unset";
|
public static final String POLAR_BEAR_STOPPED_REARING = "citizens.commands.npc.polarbear.rearing-unset";
|
||||||
public static final String POSE_ADDED = "citizens.commands.npc.pose.added";
|
public static final String POSE_ADDED = "citizens.commands.npc.pose.added";
|
||||||
|
@ -90,6 +90,10 @@ public class NMS {
|
|||||||
* an Exception like it should.
|
* an Exception like it should.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public static EntityPacketTracker createPacketTracker(Entity entity) {
|
||||||
|
return BRIDGE.createPacketTracker(entity);
|
||||||
|
}
|
||||||
|
|
||||||
public static void enderTeleportTo(NPC npc, Runnable cb) {
|
public static void enderTeleportTo(NPC npc, Runnable cb) {
|
||||||
if (npc == null) {
|
if (npc == null) {
|
||||||
cb.run();
|
cb.run();
|
||||||
@ -229,6 +233,18 @@ public class NMS {
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MethodHandle getFirstFinalSetter(Class<?> clazz, Class<?> type) {
|
||||||
|
try {
|
||||||
|
Field found = getFirstFieldMatchingType(clazz, type, false);
|
||||||
|
if (found == null)
|
||||||
|
return null;
|
||||||
|
return getFinalSetter(clazz, found.getName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, type, e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static MethodHandle getFirstGetter(Class<?> clazz, Class<?> type) {
|
public static MethodHandle getFirstGetter(Class<?> clazz, Class<?> type) {
|
||||||
try {
|
try {
|
||||||
Field found = getFirstFieldMatchingType(clazz, type, false);
|
Field found = getFirstFieldMatchingType(clazz, type, false);
|
||||||
@ -374,10 +390,6 @@ public class NMS {
|
|||||||
return BRIDGE.getPassengers(entity);
|
return BRIDGE.getPassengers(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EntityPacketTracker createPacketTracker(Entity entity) {
|
|
||||||
return BRIDGE.createPacketTracker(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameProfile getProfile(Player player) {
|
public static GameProfile getProfile(Player player) {
|
||||||
return BRIDGE.getProfile(player);
|
return BRIDGE.getProfile(player);
|
||||||
}
|
}
|
||||||
@ -563,8 +575,8 @@ public class NMS {
|
|||||||
BRIDGE.removeHookIfNecessary(npcRegistry, entity);
|
BRIDGE.removeHookIfNecessary(npcRegistry, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceTrackerEntry(Player player) {
|
public static void replaceTracker(Entity entity) {
|
||||||
BRIDGE.replaceTrackerEntry(player);
|
BRIDGE.replaceTrackerEntry(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPositionUpdate(Player excluding, org.bukkit.entity.Entity from, Location location) {
|
public static void sendPositionUpdate(Player excluding, org.bukkit.entity.Entity from, Location location) {
|
||||||
|
@ -150,7 +150,7 @@ public interface NMSBridge {
|
|||||||
|
|
||||||
public void removeHookIfNecessary(NPCRegistry npcRegistry, FishHook entity);;
|
public void removeHookIfNecessary(NPCRegistry npcRegistry, FishHook entity);;
|
||||||
|
|
||||||
public void replaceTrackerEntry(Player player);
|
public void replaceTrackerEntry(Entity entity);
|
||||||
|
|
||||||
public void sendPositionUpdate(Player excluding, Entity from, Location location);
|
public void sendPositionUpdate(Player excluding, Entity from, Location location);
|
||||||
|
|
||||||
|
@ -220,6 +220,9 @@ citizens.commands.npc.pausepathfinding.rightclick-set=[[{0}]] will now pause pat
|
|||||||
citizens.commands.npc.pausepathfinding.rightclick-unset=[[{0}]] will no longer pause pathfinding on right click.
|
citizens.commands.npc.pausepathfinding.rightclick-unset=[[{0}]] will no longer pause pathfinding on right click.
|
||||||
citizens.commands.npc.playerlist.added=Added [[{0}]] to the player list.
|
citizens.commands.npc.playerlist.added=Added [[{0}]] to the player list.
|
||||||
citizens.commands.npc.playerlist.removed=Removed [[{0}]] from the player list.
|
citizens.commands.npc.playerlist.removed=Removed [[{0}]] from the player list.
|
||||||
|
citizens.commands.npc.playerfilter.only-added=[[{0}]] added to the list of players that will be allowed to see [[{1}]].
|
||||||
|
citizens.commands.npc.playerfilter.hidden=[[{0}]] added to the list of players hidden from [[{1}]].
|
||||||
|
citizens.commands.npc.playerfilter.unhidden=[[{0}]] will now be allowed to see [[{1}]].
|
||||||
citizens.commands.npc.polarbear.rearing-set=[[{0}]] is now rearing.
|
citizens.commands.npc.polarbear.rearing-set=[[{0}]] is now rearing.
|
||||||
citizens.commands.npc.polarbear.rearing-unset=[[{0}]] is no longer rearing.
|
citizens.commands.npc.polarbear.rearing-unset=[[{0}]] is no longer rearing.
|
||||||
citizens.commands.npc.pickupitems.set=[[{0}]] will now pickup items.
|
citizens.commands.npc.pickupitems.set=[[{0}]] will now pickup items.
|
||||||
|
@ -1020,13 +1020,13 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld();
|
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
|
||||||
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(player.getEntityId());
|
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
||||||
server.getTracker().trackedEntities.a(player.getEntityId(), replace);
|
server.getTracker().trackedEntities.a(entity.getEntityId(), replace);
|
||||||
if (TRACKED_ENTITY_SET != null) {
|
if (TRACKED_ENTITY_SET != null) {
|
||||||
try {
|
try {
|
||||||
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
||||||
@ -1038,8 +1038,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked();
|
((EntityHumanNPC) getHandle(entity)).setTracked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package net.citizensnpcs.nms.v1_10_R1.util;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
@ -28,6 +29,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
Entity tracker = getTracker(this);
|
Entity tracker = getTracker(this);
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
|
if (tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
|
return;
|
||||||
if (entityplayer != tracker && c(entityplayer)) {
|
if (entityplayer != tracker && c(entityplayer)) {
|
||||||
if (!this.trackedPlayers.contains(entityplayer)
|
if (!this.trackedPlayers.contains(entityplayer)
|
||||||
&& ((entityplayer.x().getPlayerChunkMap().a(entityplayer, tracker.ac, tracker.ae))
|
&& ((entityplayer.x().getPlayerChunkMap().a(entityplayer, tracker.ac, tracker.ae))
|
||||||
|
@ -1077,13 +1077,13 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld();
|
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
|
||||||
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(player.getEntityId());
|
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
||||||
server.getTracker().trackedEntities.a(player.getEntityId(), replace);
|
server.getTracker().trackedEntities.a(entity.getEntityId(), replace);
|
||||||
if (TRACKED_ENTITY_SET != null) {
|
if (TRACKED_ENTITY_SET != null) {
|
||||||
try {
|
try {
|
||||||
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
||||||
@ -1095,8 +1095,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked();
|
((EntityHumanNPC) getHandle(entity)).setTracked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package net.citizensnpcs.nms.v1_11_R1.util;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
@ -28,6 +29,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
Entity tracker = getTracker(this);
|
Entity tracker = getTracker(this);
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
|
if (tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
|
return;
|
||||||
if (entityplayer != tracker && c(entityplayer)) {
|
if (entityplayer != tracker && c(entityplayer)) {
|
||||||
if (!this.trackedPlayers.contains(entityplayer)
|
if (!this.trackedPlayers.contains(entityplayer)
|
||||||
&& ((entityplayer.x().getPlayerChunkMap().a(entityplayer, tracker.ab, tracker.ad))
|
&& ((entityplayer.x().getPlayerChunkMap().a(entityplayer, tracker.ab, tracker.ad))
|
||||||
|
@ -1085,13 +1085,13 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld();
|
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
|
||||||
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(player.getEntityId());
|
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
||||||
server.getTracker().trackedEntities.a(player.getEntityId(), replace);
|
server.getTracker().trackedEntities.a(entity.getEntityId(), replace);
|
||||||
if (TRACKED_ENTITY_SET != null) {
|
if (TRACKED_ENTITY_SET != null) {
|
||||||
try {
|
try {
|
||||||
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
||||||
@ -1103,8 +1103,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
((EntityHumanNPC) getHandle(entity)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.nms.v1_12_R1.util;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -17,9 +18,11 @@ import net.minecraft.server.v1_12_R1.EntityTrackerEntry;
|
|||||||
|
|
||||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||||
private EntityPlayer lastUpdatedPlayer;
|
private EntityPlayer lastUpdatedPlayer;
|
||||||
|
private final Entity tracker;
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
||||||
super(entity, i, j, k, flag);
|
super(entity, i, j, k, flag);
|
||||||
|
this.tracker = getTracker(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(EntityTrackerEntry entry) {
|
public PlayerlistTrackerEntry(EntityTrackerEntry entry) {
|
||||||
@ -33,7 +36,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (lastUpdatedPlayer == null)
|
if (lastUpdatedPlayer == null)
|
||||||
return;
|
return;
|
||||||
final Entity tracker = getTracker(this);
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
|
return;
|
||||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
lastUpdatedPlayer = null;
|
lastUpdatedPlayer = null;
|
||||||
@ -52,6 +56,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
// prevent updates to NPC "viewers"
|
// prevent updates to NPC "viewers"
|
||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
lastUpdatedPlayer = entityplayer;
|
lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
lastUpdatedPlayer = null;
|
lastUpdatedPlayer = null;
|
||||||
|
@ -1129,13 +1129,13 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld();
|
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
|
||||||
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(player.getEntityId());
|
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
||||||
server.getTracker().trackedEntities.a(player.getEntityId(), replace);
|
server.getTracker().trackedEntities.a(entity.getEntityId(), replace);
|
||||||
if (TRACKED_ENTITY_SET != null) {
|
if (TRACKED_ENTITY_SET != null) {
|
||||||
try {
|
try {
|
||||||
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
||||||
@ -1147,8 +1147,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
((EntityHumanNPC) getHandle(entity)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.nms.v1_13_R2.util;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -17,9 +18,11 @@ import net.minecraft.server.v1_13_R2.EntityTrackerEntry;
|
|||||||
|
|
||||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||||
private EntityPlayer lastUpdatedPlayer;
|
private EntityPlayer lastUpdatedPlayer;
|
||||||
|
private final Entity tracker;
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
||||||
super(entity, i, j, k, flag);
|
super(entity, i, j, k, flag);
|
||||||
|
tracker = getTracker(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(EntityTrackerEntry entry) {
|
public PlayerlistTrackerEntry(EntityTrackerEntry entry) {
|
||||||
@ -31,9 +34,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (lastUpdatedPlayer == null)
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
final Entity tracker = getTracker(this);
|
|
||||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
lastUpdatedPlayer = null;
|
lastUpdatedPlayer = null;
|
||||||
@ -52,6 +54,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
// prevent updates to NPC "viewers"
|
// prevent updates to NPC "viewers"
|
||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
lastUpdatedPlayer = entityplayer;
|
lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
lastUpdatedPlayer = null;
|
lastUpdatedPlayer = null;
|
||||||
|
@ -1156,15 +1156,15 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld();
|
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
|
||||||
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(player.getEntityId());
|
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().playerChunkMap, entry);
|
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().playerChunkMap, entry);
|
||||||
server.getChunkProvider().playerChunkMap.trackedEntities.put(player.getEntityId(), replace);
|
server.getChunkProvider().playerChunkMap.trackedEntities.put(entity.getEntityId(), replace);
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
((EntityHumanNPC) getHandle(entity)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.nms.v1_14_R1.util;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -31,7 +32,7 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (tracker.dead)
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
@ -49,6 +50,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
if (!(entityplayer instanceof EntityHumanNPC)) {
|
if (!(entityplayer instanceof EntityHumanNPC)) {
|
||||||
// prevent updates to NPC "viewers"
|
// prevent updates to NPC "viewers"
|
||||||
|
if (tracker instanceof NPCHolder
|
||||||
|
&& ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
lastUpdatedPlayer = entityplayer;
|
lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
}
|
}
|
||||||
|
@ -1174,15 +1174,15 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld();
|
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
|
||||||
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(player.getEntityId());
|
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().playerChunkMap, entry);
|
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().playerChunkMap, entry);
|
||||||
server.getChunkProvider().playerChunkMap.trackedEntities.put(player.getEntityId(), replace);
|
server.getChunkProvider().playerChunkMap.trackedEntities.put(entity.getEntityId(), replace);
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
((EntityHumanNPC) getHandle(entity)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.nms.v1_15_R1.util;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -31,7 +32,7 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (tracker.dead)
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
@ -48,6 +49,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
if (!(entityplayer instanceof EntityHumanNPC)) {
|
if (!(entityplayer instanceof EntityHumanNPC)) {
|
||||||
|
if (tracker instanceof NPCHolder
|
||||||
|
&& ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
// prevent updates to NPC "viewers"
|
// prevent updates to NPC "viewers"
|
||||||
this.lastUpdatedPlayer = entityplayer;
|
this.lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
|
@ -1204,15 +1204,15 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld();
|
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
|
||||||
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(player.getEntityId());
|
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().playerChunkMap, entry);
|
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().playerChunkMap, entry);
|
||||||
server.getChunkProvider().playerChunkMap.trackedEntities.put(player.getEntityId(), replace);
|
server.getChunkProvider().playerChunkMap.trackedEntities.put(entity.getEntityId(), replace);
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
((EntityHumanNPC) getHandle(entity)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.nms.v1_16_R3.util;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -32,11 +33,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (tracker.dead)
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||||
if (entityplayer == null)
|
|
||||||
return;
|
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||||
return;
|
return;
|
||||||
@ -53,6 +52,8 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
if (entityplayer instanceof EntityHumanNPC) // prevent updates to NPC "viewers"
|
if (entityplayer instanceof EntityHumanNPC) // prevent updates to NPC "viewers"
|
||||||
return;
|
return;
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
this.lastUpdatedPlayer = entityplayer;
|
this.lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
}
|
}
|
||||||
|
@ -392,8 +392,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
((Mob) handle).doHurtTarget(target);
|
((Mob) handle).doHurtTarget(target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AttributeInstance attackDamage = handle.getAttribute(Attributes.ATTACK_DAMAGE);
|
float f = (float) (handle.getAttributes().hasAttribute(Attributes.ATTACK_DAMAGE)
|
||||||
float f = (float) (attackDamage == null ? 1 : attackDamage.getValue());
|
? handle.getAttributeValue(Attributes.ATTACK_DAMAGE)
|
||||||
|
: 1f);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
f += EnchantmentHelper.getDamageBonus(handle.getMainHandItem(), target.getMobType());
|
f += EnchantmentHelper.getDamageBonus(handle.getMainHandItem(), target.getMobType());
|
||||||
i += EnchantmentHelper.getKnockbackBonus(handle);
|
i += EnchantmentHelper.getKnockbackBonus(handle);
|
||||||
@ -1193,15 +1194,15 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
ServerLevel server = (ServerLevel) NMSImpl.getHandle(player).level;
|
ServerLevel server = (ServerLevel) NMSImpl.getHandle(entity).level;
|
||||||
TrackedEntity entry = server.getChunkProvider().chunkMap.G.get(player.getEntityId());
|
TrackedEntity entry = server.getChunkProvider().chunkMap.G.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().chunkMap, entry);
|
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().chunkMap, entry);
|
||||||
server.getChunkProvider().chunkMap.G.put(player.getEntityId(), replace);
|
server.getChunkProvider().chunkMap.G.put(entity.getEntityId(), replace);
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
((EntityHumanNPC) getHandle(entity)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.nms.v1_17_R1.util;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -32,11 +33,10 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (tracker.isRemoved())
|
if (tracker.isRemoved() || lastUpdatedPlayer == null
|
||||||
|
|| tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
||||||
if (entityplayer == null)
|
|
||||||
return;
|
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||||
return;
|
return;
|
||||||
@ -53,6 +53,8 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||||||
public void updatePlayer(final ServerPlayer entityplayer) {
|
public void updatePlayer(final ServerPlayer entityplayer) {
|
||||||
if (entityplayer instanceof EntityHumanNPC) // prevent updates to NPC "viewers"
|
if (entityplayer instanceof EntityHumanNPC) // prevent updates to NPC "viewers"
|
||||||
return;
|
return;
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
this.lastUpdatedPlayer = entityplayer;
|
this.lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
}
|
}
|
||||||
|
@ -396,8 +396,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
((Mob) source).doHurtTarget(target);
|
((Mob) source).doHurtTarget(target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AttributeInstance attackDamage = source.getAttribute(Attributes.ATTACK_DAMAGE);
|
float f = (float) (source.getAttributes().hasAttribute(Attributes.ATTACK_DAMAGE)
|
||||||
float f = (float) (attackDamage == null ? 1 : attackDamage.getValue());
|
? source.getAttributeValue(Attributes.ATTACK_DAMAGE)
|
||||||
|
: 1f);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
f += EnchantmentHelper.getDamageBonus(source.getMainHandItem(), target.getMobType());
|
f += EnchantmentHelper.getDamageBonus(source.getMainHandItem(), target.getMobType());
|
||||||
i += EnchantmentHelper.getKnockbackBonus(source);
|
i += EnchantmentHelper.getKnockbackBonus(source);
|
||||||
@ -1198,15 +1199,15 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
ServerLevel server = (ServerLevel) NMSImpl.getHandle(player).level;
|
ServerLevel server = (ServerLevel) NMSImpl.getHandle(entity).level;
|
||||||
TrackedEntity entry = server.getChunkSource().chunkMap.entityMap.get(player.getEntityId());
|
TrackedEntity entry = server.getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkSource().chunkMap, entry);
|
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkSource().chunkMap, entry);
|
||||||
server.getChunkSource().chunkMap.entityMap.put(player.getEntityId(), replace);
|
server.getChunkSource().chunkMap.entityMap.put(entity.getEntityId(), replace);
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
((EntityHumanNPC) getHandle(entity)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.nms.v1_18_R2.util;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -32,11 +33,10 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (tracker.isRemoved())
|
if (tracker.isRemoved() || lastUpdatedPlayer == null
|
||||||
|
|| tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
||||||
if (entityplayer == null)
|
|
||||||
return;
|
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||||
return;
|
return;
|
||||||
@ -53,6 +53,8 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||||||
public void updatePlayer(final ServerPlayer entityplayer) {
|
public void updatePlayer(final ServerPlayer entityplayer) {
|
||||||
if (entityplayer instanceof EntityHumanNPC) // prevent updates to NPC "viewers"
|
if (entityplayer instanceof EntityHumanNPC) // prevent updates to NPC "viewers"
|
||||||
return;
|
return;
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
this.lastUpdatedPlayer = entityplayer;
|
this.lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ import net.citizensnpcs.nms.v1_19_R2.util.NMSImpl;
|
|||||||
import net.citizensnpcs.nms.v1_19_R2.util.PlayerControllerJump;
|
import net.citizensnpcs.nms.v1_19_R2.util.PlayerControllerJump;
|
||||||
import net.citizensnpcs.nms.v1_19_R2.util.PlayerMoveControl;
|
import net.citizensnpcs.nms.v1_19_R2.util.PlayerMoveControl;
|
||||||
import net.citizensnpcs.nms.v1_19_R2.util.PlayerNavigation;
|
import net.citizensnpcs.nms.v1_19_R2.util.PlayerNavigation;
|
||||||
import net.citizensnpcs.nms.v1_19_R2.util.PlayerlistTracker;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
import net.citizensnpcs.npc.skin.SkinPacketTracker;
|
import net.citizensnpcs.npc.skin.SkinPacketTracker;
|
||||||
@ -54,7 +53,6 @@ import net.minecraft.network.chat.MutableComponent;
|
|||||||
import net.minecraft.network.chat.contents.LiteralContents;
|
import net.minecraft.network.chat.contents.LiteralContents;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.PacketFlow;
|
import net.minecraft.network.protocol.PacketFlow;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
@ -89,7 +87,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
|||||||
private PlayerNavigation navigation;
|
private PlayerNavigation navigation;
|
||||||
private final CitizensNPC npc;
|
private final CitizensNPC npc;
|
||||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||||
private PlayerlistTracker playerlistTracker;
|
|
||||||
private boolean setBukkitEntity;
|
private boolean setBukkitEntity;
|
||||||
private final SkinPacketTracker skinTracker;
|
private final SkinPacketTracker skinTracker;
|
||||||
private EmptyServerStatsCounter statsCache;
|
private EmptyServerStatsCounter statsCache;
|
||||||
@ -110,14 +107,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean broadcastToPlayer(ServerPlayer entityplayer) {
|
|
||||||
if (npc != null && playerlistTracker == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return super.broadcastToPlayer(entityplayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canCutCorner(BlockPathTypes pathtype) {
|
public boolean canCutCorner(BlockPathTypes pathtype) {
|
||||||
return (pathtype != BlockPathTypes.DANGER_FIRE && pathtype != BlockPathTypes.DANGER_CACTUS
|
return (pathtype != BlockPathTypes.DANGER_FIRE && pathtype != BlockPathTypes.DANGER_CACTUS
|
||||||
&& pathtype != BlockPathTypes.DANGER_OTHER && pathtype != BlockPathTypes.WALKABLE_DOOR);
|
&& pathtype != BlockPathTypes.DANGER_OTHER && pathtype != BlockPathTypes.WALKABLE_DOOR);
|
||||||
@ -213,14 +202,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
|
||||||
if (playerlistTracker != null) {
|
|
||||||
playerlistTracker.updateLastPlayer();
|
|
||||||
}
|
|
||||||
return super.getAddEntityPacket();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CraftPlayer getBukkitEntity() {
|
public CraftPlayer getBukkitEntity() {
|
||||||
if (npc != null && !setBukkitEntity) {
|
if (npc != null && !setBukkitEntity) {
|
||||||
@ -470,10 +451,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
|||||||
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
|
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTracked(PlayerlistTracker tracker) {
|
|
||||||
playerlistTracker = tracker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package net.citizensnpcs.nms.v1_19_R2.util;
|
package net.citizensnpcs.nms.v1_19_R2.util;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.google.common.collect.ForwardingSet;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
@ -18,25 +22,44 @@ import net.minecraft.server.level.ServerEntity;
|
|||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
||||||
public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
|
||||||
private ServerPlayer lastUpdatedPlayer;
|
private ServerPlayer lastUpdatedPlayer;
|
||||||
private final Entity tracker;
|
private final Entity tracker;
|
||||||
|
|
||||||
public PlayerlistTracker(ChunkMap map, Entity entity, int i, int j, boolean flag) {
|
public CitizensEntityTracker(ChunkMap map, Entity entity, int i, int j, boolean flag) {
|
||||||
map.super(entity, i, j, flag);
|
map.super(entity, i, j, flag);
|
||||||
this.tracker = entity;
|
this.tracker = entity;
|
||||||
|
try {
|
||||||
|
Set set = (Set) TRACKING_SET_GETTER.invoke(this);
|
||||||
|
TRACKING_SET_SETTER.invoke(this, new ForwardingSet() {
|
||||||
|
@Override
|
||||||
|
public boolean add(Object conn) {
|
||||||
|
boolean res = super.add(conn);
|
||||||
|
if (res) {
|
||||||
|
updateLastPlayer();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerlistTracker(ChunkMap map, TrackedEntity entry) {
|
@Override
|
||||||
|
protected Set delegate() {
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CitizensEntityTracker(ChunkMap map, TrackedEntity entry) {
|
||||||
this(map, getTracker(entry), getTrackingDistance(entry), getE(entry), getF(entry));
|
this(map, getTracker(entry), getTrackingDistance(entry), getE(entry), getF(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (tracker.isRemoved())
|
if (tracker.isRemoved() || lastUpdatedPlayer == null
|
||||||
|
|| tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
||||||
if (entityplayer == null)
|
|
||||||
return;
|
|
||||||
boolean sendTabRemove = NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
boolean sendTabRemove = NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
if (!sendTabRemove || !Setting.DISABLE_TABLIST.asBoolean()) {
|
if (!sendTabRemove || !Setting.DISABLE_TABLIST.asBoolean()) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||||
@ -54,6 +77,9 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||||||
public void updatePlayer(final ServerPlayer entityplayer) {
|
public void updatePlayer(final ServerPlayer entityplayer) {
|
||||||
if (entityplayer instanceof EntityHumanNPC) // prevent updates to NPC "viewers"
|
if (entityplayer instanceof EntityHumanNPC) // prevent updates to NPC "viewers"
|
||||||
return;
|
return;
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
|
|
||||||
this.lastUpdatedPlayer = entityplayer;
|
this.lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
}
|
}
|
||||||
@ -104,4 +130,6 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||||||
private static final MethodHandle TRACKER = NMS.getFirstGetter(TrackedEntity.class, Entity.class);
|
private static final MethodHandle TRACKER = NMS.getFirstGetter(TrackedEntity.class, Entity.class);
|
||||||
private static final MethodHandle TRACKER_ENTRY = NMS.getFirstGetter(TrackedEntity.class, ServerEntity.class);
|
private static final MethodHandle TRACKER_ENTRY = NMS.getFirstGetter(TrackedEntity.class, ServerEntity.class);
|
||||||
private static final MethodHandle TRACKING_RANGE = NMS.getFirstGetter(TrackedEntity.class, int.class);
|
private static final MethodHandle TRACKING_RANGE = NMS.getFirstGetter(TrackedEntity.class, int.class);
|
||||||
|
private static final MethodHandle TRACKING_SET_GETTER = NMS.getFirstGetter(TrackedEntity.class, Set.class);
|
||||||
|
private static final MethodHandle TRACKING_SET_SETTER = NMS.getFirstFinalSetter(TrackedEntity.class, Set.class);
|
||||||
}
|
}
|
@ -416,8 +416,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
((Mob) source).doHurtTarget(target);
|
((Mob) source).doHurtTarget(target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AttributeInstance attackDamage = source.getAttribute(Attributes.ATTACK_DAMAGE);
|
float f = (float) (source.getAttributes().hasAttribute(Attributes.ATTACK_DAMAGE)
|
||||||
float f = (float) (attackDamage == null ? 1 : attackDamage.getValue());
|
? source.getAttributeValue(Attributes.ATTACK_DAMAGE)
|
||||||
|
: 1f);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
f += EnchantmentHelper.getDamageBonus(source.getMainHandItem(), target.getMobType());
|
f += EnchantmentHelper.getDamageBonus(source.getMainHandItem(), target.getMobType());
|
||||||
i += EnchantmentHelper.getKnockbackBonus(source);
|
i += EnchantmentHelper.getKnockbackBonus(source);
|
||||||
@ -1282,16 +1283,13 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
ServerLevel server = (ServerLevel) NMSImpl.getHandle(player).level;
|
ServerLevel server = (ServerLevel) NMSImpl.getHandle(entity).level;
|
||||||
TrackedEntity entry = server.getChunkSource().chunkMap.entityMap.get(player.getEntityId());
|
TrackedEntity entry = server.getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTracker replace = new PlayerlistTracker(server.getChunkSource().chunkMap, entry);
|
CitizensEntityTracker replace = new CitizensEntityTracker(server.getChunkSource().chunkMap, entry);
|
||||||
server.getChunkSource().chunkMap.entityMap.put(player.getEntityId(), replace);
|
server.getChunkSource().chunkMap.entityMap.put(entity.getEntityId(), replace);
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1306,10 +1304,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
float oldPitch = handle.getXRot();
|
float oldPitch = handle.getXRot();
|
||||||
handle.setYBodyRot(bodyYaw);
|
handle.setYBodyRot(bodyYaw);
|
||||||
handle.setXRot(pitch);
|
handle.setXRot(pitch);
|
||||||
sendPacketsNearby(null, from.getLocation(), new ClientboundTeleportEntityPacket(handle), // new
|
sendPacketsNearby(null, from.getLocation(), new ClientboundTeleportEntityPacket(handle),
|
||||||
// ClientboundMoveEntityPacket.Rot(handle.getId(),
|
// new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F),
|
||||||
// (byte) (bodyYaw *
|
|
||||||
// 256.0F / 360.0F),
|
|
||||||
// (byte) (pitch * 256.0F / 360.0F), handle.onGround),
|
// (byte) (pitch * 256.0F / 360.0F), handle.onGround),
|
||||||
new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||||
handle.setYBodyRot(oldBody);
|
handle.setYBodyRot(oldBody);
|
||||||
|
@ -947,13 +947,13 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceTrackerEntry(Player player) {
|
public void replaceTrackerEntry(org.bukkit.entity.Entity entity) {
|
||||||
WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld();
|
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
|
||||||
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(player.getEntityId());
|
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return;
|
return;
|
||||||
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry);
|
||||||
server.getTracker().trackedEntities.a(player.getEntityId(), replace);
|
server.getTracker().trackedEntities.a(entity.getEntityId(), replace);
|
||||||
if (TRACKED_ENTITY_SET != null) {
|
if (TRACKED_ENTITY_SET != null) {
|
||||||
try {
|
try {
|
||||||
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
Set<Object> set = (Set<Object>) TRACKED_ENTITY_SET.get(server.getTracker());
|
||||||
@ -965,8 +965,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(entity) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
((EntityHumanNPC) getHandle(entity)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package net.citizensnpcs.nms.v1_8_R3.util;
|
package net.citizensnpcs.nms.v1_8_R3.util;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
@ -22,7 +25,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(EntityTrackerEntry entry) {
|
public PlayerlistTrackerEntry(EntityTrackerEntry entry) {
|
||||||
this(getTracker(entry), getB(entry), getC(entry), getU(entry));
|
this(entry.tracker, getB(entry), getC(entry), getU(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdating() {
|
public boolean isUpdating() {
|
||||||
@ -32,7 +35,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (lastUpdatedPlayer == null)
|
if (lastUpdatedPlayer == null)
|
||||||
return;
|
return;
|
||||||
final Entity tracker = getTracker(this);
|
if (tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
|
return;
|
||||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
lastUpdatedPlayer = null;
|
lastUpdatedPlayer = null;
|
||||||
@ -52,6 +56,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
// prevent updates to NPC "viewers"
|
// prevent updates to NPC "viewers"
|
||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
|
if (tracker instanceof NPCHolder && ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity()))
|
||||||
|
return;
|
||||||
lastUpdatedPlayer = entityplayer;
|
lastUpdatedPlayer = entityplayer;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
lastUpdatedPlayer = null;
|
lastUpdatedPlayer = null;
|
||||||
@ -59,7 +65,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
|
|
||||||
private static int getB(EntityTrackerEntry entry) {
|
private static int getB(EntityTrackerEntry entry) {
|
||||||
try {
|
try {
|
||||||
Entity entity = getTracker(entry);
|
Entity entity = entry.tracker;
|
||||||
if (entity instanceof NPCHolder) {
|
if (entity instanceof NPCHolder) {
|
||||||
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE, (Integer) B.get(entry));
|
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE, (Integer) B.get(entry));
|
||||||
}
|
}
|
||||||
@ -83,17 +89,6 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entity getTracker(EntityTrackerEntry entry) {
|
|
||||||
try {
|
|
||||||
return (Entity) TRACKER.get(entry);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean getU(EntityTrackerEntry entry) {
|
private static boolean getU(EntityTrackerEntry entry) {
|
||||||
try {
|
try {
|
||||||
return (Boolean) U.get(entry);
|
return (Boolean) U.get(entry);
|
||||||
@ -107,6 +102,5 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
|
|
||||||
private static Field B = NMS.getField(EntityTrackerEntry.class, "b");
|
private static Field B = NMS.getField(EntityTrackerEntry.class, "b");
|
||||||
private static Field C = NMS.getField(EntityTrackerEntry.class, "c");
|
private static Field C = NMS.getField(EntityTrackerEntry.class, "c");
|
||||||
private static Field TRACKER = NMS.getField(EntityTrackerEntry.class, "tracker");
|
|
||||||
private static Field U = NMS.getField(EntityTrackerEntry.class, "u");
|
private static Field U = NMS.getField(EntityTrackerEntry.class, "u");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user