Refactor PlayerAnimation to accept a collection of players rather than radius. Rework NPCLinkToPlayerEvent handling
This commit is contained in:
parent
d17ca61e6e
commit
401e34a4a3
|
@ -433,19 +433,18 @@ public class EventListen implements Listener {
|
|||
@EventHandler(ignoreCancelled = true)
|
||||
public void onNPCLinkToPlayer(NPCLinkToPlayerEvent event) {
|
||||
NPC npc = event.getNPC();
|
||||
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
||||
onNPCPlayerLinkToPlayer(event);
|
||||
}
|
||||
|
||||
ClickRedirectTrait crt = npc.getTraitNullable(ClickRedirectTrait.class);
|
||||
if (crt != null) {
|
||||
HologramTrait ht = crt.getRedirectNPC().getTraitNullable(HologramTrait.class);
|
||||
if (ht != null) {
|
||||
ht.onHologramSeenByPlayer(npc, event.getPlayer());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> ht.onHologramSeenByPlayer(npc, event.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO
|
||||
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
||||
onNPCPlayerLinkToPlayer(event);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void onNPCPlayerLinkToPlayer(NPCLinkToPlayerEvent event) {
|
||||
|
@ -462,8 +461,8 @@ public class EventListen implements Listener {
|
|||
boolean sendTabRemove = NMS.sendTabListAdd(event.getPlayer(), (Player) tracker);
|
||||
if (!sendTabRemove || !Setting.DISABLE_TABLIST.asBoolean()) {
|
||||
if (resetYaw) {
|
||||
// Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
// () -> PlayerAnimation.ARM_SWING.play((Player) tracker, event.getPlayer()), 1);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> PlayerAnimation.ARM_SWING.play((Player) tracker, event.getPlayer()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -474,7 +473,7 @@ public class EventListen implements Listener {
|
|||
|
||||
NMS.sendTabListRemove(event.getPlayer(), (Player) tracker);
|
||||
if (resetYaw) {
|
||||
// PlayerAnimation.ARM_SWING.play((Player) tracker, event.getPlayer());
|
||||
PlayerAnimation.ARM_SWING.play((Player) tracker, event.getPlayer());
|
||||
}
|
||||
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
|
|
@ -1136,7 +1136,8 @@ public class NPCCommands {
|
|||
permission = "citizens.npc.hologram")
|
||||
public void hologram(CommandContext args, CommandSender sender, NPC npc, @Arg(
|
||||
value = 1,
|
||||
completions = { "add", "set", "remove", "clear", "lineheight", "margintop", "marginbottom" }) String action)
|
||||
completions = { "add", "set", "remove", "clear", "lineheight", "margintop", "marginbottom" }) String action,
|
||||
@Arg(value = 2, completionsProvider = HologramTrait.TabCompletions.class) String secondCompletion)
|
||||
throws CommandException {
|
||||
HologramTrait trait = npc.getOrAddTrait(HologramTrait.class);
|
||||
if (args.argsLength() == 1) {
|
||||
|
|
|
@ -207,8 +207,8 @@ public class CitizensNPC extends AbstractNPC {
|
|||
|
||||
@Override
|
||||
public boolean requiresNameHologram() {
|
||||
return super.requiresNameHologram() || (getEntityType() != EntityType.ARMOR_STAND
|
||||
&& !getEntityType().name().equals("TEXT_DISPLAY") && Setting.ALWAYS_USE_NAME_HOLOGRAM.asBoolean());
|
||||
return super.requiresNameHologram()
|
||||
|| (Setting.ALWAYS_USE_NAME_HOLOGRAM.asBoolean() && !data().has(NPC.Metadata.HOLOGRAM_FOR));
|
||||
}
|
||||
|
||||
private void resetCachedCoord() {
|
||||
|
@ -646,11 +646,11 @@ public class CitizensNPC extends AbstractNPC {
|
|||
|
||||
try {
|
||||
if (useItem) {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_MAINHAND_ITEM, player, 64);
|
||||
PlayerAnimation.STOP_USE_ITEM.play(player, 64);
|
||||
PlayerAnimation.START_USE_MAINHAND_ITEM.play(player, 64);
|
||||
} else if (offhand) {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_OFFHAND_ITEM, player, 64);
|
||||
PlayerAnimation.STOP_USE_ITEM.play(player, 64);
|
||||
PlayerAnimation.START_USE_OFFHAND_ITEM.play(player, 64);
|
||||
}
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
SUPPORT_USE_ITEM = false;
|
||||
|
|
|
@ -1,27 +1,33 @@
|
|||
package net.citizensnpcs.trait;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.command.Arg.CompletionsProvider;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.npc.MemoryNPCDataStore;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
|
@ -29,6 +35,7 @@ import net.citizensnpcs.api.persistence.Persist;
|
|||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.api.util.Placeholders;
|
||||
import net.citizensnpcs.api.util.SpigotUtil;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
|
@ -109,6 +116,7 @@ public class HologramTrait extends Trait {
|
|||
hologramNPC.addTrait(PacketNPC.class);
|
||||
}
|
||||
|
||||
hologramNPC.data().set(NPC.Metadata.HOLOGRAM_FOR, npc.getUniqueId().toString());
|
||||
hologramNPC.spawn(currentLoc.clone().add(0, getEntityHeight() + heightOffset, 0));
|
||||
|
||||
Matcher itemMatcher = ITEM_MATCHER.matcher(line);
|
||||
|
@ -227,6 +235,7 @@ public class HologramTrait extends Trait {
|
|||
if (height == -1)
|
||||
return;
|
||||
|
||||
Messaging.debug(npc, "hologram interaction ", hologram.getEntity(), "height offset set to", height);
|
||||
NMS.linkTextInteraction(player, hologram.getEntity(), npc.getEntity(), height);
|
||||
}
|
||||
}
|
||||
|
@ -327,10 +336,6 @@ public class HologramTrait extends Trait {
|
|||
nameLine.hologram.teleport(npcLoc.clone().add(0, getEntityHeight(), 0), TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
if (useDisplayEntities && nameLine.hologram.getEntity().getVehicle() == null) {
|
||||
npc.getEntity().addPassenger(nameLine.hologram.getEntity());
|
||||
}
|
||||
|
||||
if (updateName) {
|
||||
nameLine.setText(npc.getRawName());
|
||||
}
|
||||
|
@ -354,10 +359,6 @@ public class HologramTrait extends Trait {
|
|||
hologramNPC.teleport(tp, TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
if (useDisplayEntities && hologramNPC.getEntity().getVehicle() == null) {
|
||||
npc.getEntity().addPassenger(hologramNPC.getEntity());
|
||||
}
|
||||
|
||||
String text = line.text;
|
||||
if (ITEM_MATCHER.matcher(text).matches()) {
|
||||
hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, false);
|
||||
|
@ -511,13 +512,19 @@ public class HologramTrait extends Trait {
|
|||
}
|
||||
}
|
||||
|
||||
private static final Pattern ITEM_MATCHER = Pattern.compile("<item:(.*?)([:].*?)?>");
|
||||
private static boolean SUPPORTS_TEXT_DISPLAY = false;
|
||||
static {
|
||||
try {
|
||||
EntityType.valueOf("TEXT_DISPLAY");
|
||||
SUPPORTS_TEXT_DISPLAY = true;
|
||||
} catch (IllegalArgumentException iae) {
|
||||
public static class TabCompletions implements CompletionsProvider {
|
||||
@Override
|
||||
public Collection<String> getCompletions(CommandContext args, CommandSender sender, NPC npc) {
|
||||
if (npc != null && LINE_ARGS.contains(args.getString(1).toLowerCase())) {
|
||||
HologramTrait ht = npc.getOrAddTrait(HologramTrait.class);
|
||||
return IntStream.range(0, ht.getLines().size()).mapToObj(Integer::toString)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static final List<String> LINE_ARGS = ImmutableList.of("set", "remove", "margintop", "marginbottom");
|
||||
}
|
||||
|
||||
private static final Pattern ITEM_MATCHER = Pattern.compile("<item:(.*?)([:].*?)?>");
|
||||
}
|
||||
|
|
|
@ -683,8 +683,8 @@ public class NMS {
|
|||
BRIDGE.openHorseScreen(horse, equipper);
|
||||
}
|
||||
|
||||
public static void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
BRIDGE.playAnimation(animation, player, radius);
|
||||
public static void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
BRIDGE.playAnimation(animation, player, to);
|
||||
}
|
||||
|
||||
public static Runnable playerTicker(Player entity) {
|
||||
|
|
|
@ -146,7 +146,7 @@ public interface NMSBridge {
|
|||
|
||||
public void openHorseScreen(Tameable horse, Player equipper);
|
||||
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to);
|
||||
|
||||
public Runnable playerTicker(Player entity);;
|
||||
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package net.citizensnpcs.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.MemoryNPCDataStore;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -39,17 +45,33 @@ public enum PlayerAnimation {
|
|||
play(player, 64);
|
||||
}
|
||||
|
||||
public void play(Player player, int radius) {
|
||||
public void play(Player from, int radius) {
|
||||
Location loc = from.getLocation();
|
||||
Location cloc = new Location(null, 0, 0, 0);
|
||||
List<Player> to = Lists.newArrayList();
|
||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(loc, radius)) {
|
||||
if (loc.getWorld() != player.getWorld() || !player.canSee(from)
|
||||
|| loc.distance(player.getLocation(cloc)) > radius) {
|
||||
continue;
|
||||
}
|
||||
to.add(player);
|
||||
}
|
||||
play(from, to);
|
||||
}
|
||||
|
||||
public void play(Player player, Iterable<Player> to) {
|
||||
if (this == SIT) {
|
||||
if (player instanceof NPCHolder) {
|
||||
((NPCHolder) player).getNPC().getOrAddTrait(SitTrait.class).setSitting(player.getLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
player.setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), true));
|
||||
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
|
||||
if (registry == null) {
|
||||
registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
|
||||
}
|
||||
|
||||
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
|
||||
holder.getOrAddTrait(ArmorStandTrait.class).setAsPointEntity();
|
||||
holder.spawn(player.getLocation());
|
||||
|
@ -96,13 +118,15 @@ public enum PlayerAnimation {
|
|||
}
|
||||
return;
|
||||
} else if (this == STOP_USE_ITEM || this == START_USE_MAINHAND_ITEM || this == START_USE_OFFHAND_ITEM) {
|
||||
NMS.playAnimation(this, player, radius);
|
||||
NMS.playAnimation(this, player, to);
|
||||
if (player.hasMetadata("citizens-using-item-id")) {
|
||||
Bukkit.getScheduler().cancelTask(player.getMetadata("citizens-using-item-id").get(0).asInt());
|
||||
player.removeMetadata("citizens-using-item-id", CitizensAPI.getPlugin());
|
||||
}
|
||||
|
||||
if (this == STOP_USE_ITEM)
|
||||
return;
|
||||
|
||||
if (player.hasMetadata("citizens-using-item-remaining-ticks")) {
|
||||
int remainingTicks = player.getMetadata("citizens-using-item-remaining-ticks").get(0).asInt();
|
||||
new BukkitRunnable() {
|
||||
|
@ -113,8 +137,8 @@ public enum PlayerAnimation {
|
|||
return;
|
||||
}
|
||||
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, radius);
|
||||
NMS.playAnimation(PlayerAnimation.this, player, radius);
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, to);
|
||||
NMS.playAnimation(PlayerAnimation.this, player, to);
|
||||
if (!player.hasMetadata("citizens-using-item-id")) {
|
||||
player.setMetadata("citizens-using-item-id",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId()));
|
||||
|
@ -123,8 +147,14 @@ public enum PlayerAnimation {
|
|||
}.runTaskTimer(CitizensAPI.getPlugin(), Math.max(0, remainingTicks + 1),
|
||||
Math.max(1, remainingTicks + 1));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
NMS.playAnimation(this, player, radius);
|
||||
|
||||
NMS.playAnimation(this, player, to);
|
||||
}
|
||||
|
||||
public void play(Player player, Player to) {
|
||||
play(player, ImmutableList.of(to));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -961,8 +961,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,18 +14,17 @@ import net.minecraft.server.v1_10_R1.PacketPlayOutAnimation;
|
|||
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityMetadata;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
// TODO: this is pretty gross
|
||||
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.getBukkitEntity().setSneaking(true);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.M();
|
||||
|
@ -35,36 +34,34 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.c(EnumHand.MAIN_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.c(EnumHand.OFF_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.getBukkitEntity().setSneaking(false);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.clearActiveItem();
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(EntityPlayer player, Iterable<Player> to, int code) {
|
||||
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -57,9 +56,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||
skinnable.getSkinTracker().updateViewer(entityplayer.getBukkitEntity());
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(
|
||||
((NPCHolder) tracker).getNPC(), entityplayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), entityplayer.getBukkitEntity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1019,8 +1019,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,11 +14,11 @@ import net.minecraft.server.v1_11_R1.PacketPlayOutAnimation;
|
|||
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityMetadata;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
// TODO: this is pretty gross
|
||||
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
|
@ -30,41 +30,38 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case SNEAK:
|
||||
player.getBukkitEntity().setSneaking(true);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.c(EnumHand.MAIN_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.c(EnumHand.OFF_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.getBukkitEntity().setSneaking(false);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.clearActiveItem();
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(EntityPlayer player, Iterable<Player> to, int code) {
|
||||
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -6,14 +6,10 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -22,7 +18,6 @@ import net.citizensnpcs.util.NMS;
|
|||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_11_R1.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutAnimation;
|
||||
|
||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||
private Entity tracker;
|
||||
|
@ -87,30 +82,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||
}
|
||||
|
||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), entityplayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
}
|
||||
|
||||
if (lastUpdatedPlayer == null || tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||
return;
|
||||
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new PacketPlayOutAnimation(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()),
|
||||
Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1031,8 +1031,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,18 +14,17 @@ import net.minecraft.server.v1_12_R1.PacketPlayOutAnimation;
|
|||
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityMetadata;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
// TODO: this is pretty gross
|
||||
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.getBukkitEntity().setSneaking(true);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.N();
|
||||
|
@ -35,36 +34,34 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.c(EnumHand.MAIN_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.c(EnumHand.OFF_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.getBukkitEntity().setSneaking(false);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.clearActiveItem();
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(EntityPlayer player, Iterable<Player> to, int code) {
|
||||
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -6,14 +6,10 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -23,7 +19,6 @@ import net.citizensnpcs.util.NMS;
|
|||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_12_R1.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutAnimation;
|
||||
|
||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||
private final Entity tracker;
|
||||
|
@ -88,30 +83,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||
}
|
||||
|
||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), entityplayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
}
|
||||
|
||||
if (lastUpdatedPlayer == null || tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||
return;
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
lastUpdatedPlayer = null;
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new PacketPlayOutAnimation(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()),
|
||||
Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1067,8 +1067,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,18 +14,17 @@ import net.minecraft.server.v1_13_R2.PacketPlayOutAnimation;
|
|||
import net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
// TODO: this is pretty gross
|
||||
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.getBukkitEntity().setSneaking(true);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.J();
|
||||
|
@ -35,36 +34,34 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.c(EnumHand.MAIN_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.c(EnumHand.OFF_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.getBukkitEntity().setSneaking(false);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.clearActiveItem();
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(EntityPlayer player, Iterable<Player> to, int code) {
|
||||
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -6,14 +6,10 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -23,7 +19,6 @@ import net.citizensnpcs.util.NMS;
|
|||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_13_R2.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutAnimation;
|
||||
|
||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||
private final Entity tracker;
|
||||
|
@ -87,30 +82,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||
}
|
||||
|
||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), entityplayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
}
|
||||
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||
return;
|
||||
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
lastUpdatedPlayer = null;
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new PacketPlayOutAnimation(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()),
|
||||
Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1125,8 +1125,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,17 +14,16 @@ import net.minecraft.server.v1_14_R1.PacketPlayOutAnimation;
|
|||
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.getBukkitEntity().setSneaking(true);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.J();
|
||||
|
@ -34,36 +33,34 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.c(EnumHand.MAIN_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.c(EnumHand.OFF_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.getBukkitEntity().setSneaking(false);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.clearActiveItem();
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(EntityPlayer player, Iterable<Player> to, int code) {
|
||||
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -5,14 +5,10 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -22,7 +18,6 @@ import net.citizensnpcs.util.NMS;
|
|||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutAnimation;
|
||||
import net.minecraft.server.v1_14_R1.PlayerChunkMap;
|
||||
import net.minecraft.server.v1_14_R1.PlayerChunkMap.EntityTracker;
|
||||
|
||||
|
@ -89,29 +84,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||
|
||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(),
|
||||
lastUpdatedPlayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
}
|
||||
|
||||
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||
return;
|
||||
|
||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new PacketPlayOutAnimation(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()),
|
||||
Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1142,8 +1142,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,17 +14,16 @@ import net.minecraft.server.v1_15_R1.PacketPlayOutAnimation;
|
|||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.getBukkitEntity().setSneaking(true);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.startGliding();
|
||||
|
@ -34,36 +33,34 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.c(EnumHand.MAIN_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.c(EnumHand.OFF_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.getBukkitEntity().setSneaking(false);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.clearActiveItem();
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(EntityPlayer player, Iterable<Player> to, int code) {
|
||||
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -5,14 +5,10 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -22,7 +18,6 @@ import net.citizensnpcs.util.NMS;
|
|||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_15_R1.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutAnimation;
|
||||
import net.minecraft.server.v1_15_R1.PlayerChunkMap;
|
||||
import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker;
|
||||
|
||||
|
@ -89,29 +84,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||
|
||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(),
|
||||
lastUpdatedPlayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
}
|
||||
|
||||
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||
return;
|
||||
|
||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new PacketPlayOutAnimation(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()),
|
||||
Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1166,8 +1166,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,17 +15,16 @@ import net.minecraft.server.v1_16_R3.PacketPlayOutAnimation;
|
|||
import net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.setPose(EntityPose.CROUCHING);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.startGliding();
|
||||
|
@ -35,36 +34,34 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.c(EnumHand.MAIN_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.c(EnumHand.OFF_HAND);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.setPose(EntityPose.STANDING);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.clearActiveItem();
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(EntityPlayer player, Iterable<Player> to, int code) {
|
||||
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -5,14 +5,10 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -22,7 +18,6 @@ import net.citizensnpcs.util.NMS;
|
|||
import net.minecraft.server.v1_16_R3.Entity;
|
||||
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R3.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_16_R3.PacketPlayOutAnimation;
|
||||
import net.minecraft.server.v1_16_R3.PlayerChunkMap;
|
||||
import net.minecraft.server.v1_16_R3.PlayerChunkMap.EntityTracker;
|
||||
|
||||
|
@ -89,30 +84,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||
|
||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(),
|
||||
lastUpdatedPlayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
}
|
||||
|
||||
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|
||||
|| !CitizensAPI.hasImplementation())
|
||||
return;
|
||||
|
||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new PacketPlayOutAnimation(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()),
|
||||
Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1166,8 +1166,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,17 +17,16 @@ import net.minecraft.world.InteractionHand;
|
|||
import net.minecraft.world.entity.Pose;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
final ServerPlayer player = (ServerPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.setPose(Pose.CROUCHING);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.startFallFlying();
|
||||
|
@ -37,40 +36,38 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.startUsingItem(InteractionHand.MAIN_HAND);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
player.getBukkitEntity().setMetadata("citizens-using-item-remaining-ticks",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks()));
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.startUsingItem(InteractionHand.OFF_HAND);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
player.getBukkitEntity().setMetadata("citizens-using-item-remaining-ticks",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks()));
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.setPose(Pose.STANDING);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.stopUsingItem();
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(ServerPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(ServerPlayer player, Iterable<Player> to, int code) {
|
||||
ClientboundAnimatePacket packet = new ClientboundAnimatePacket(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, ServerPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -3,11 +3,7 @@ package net.citizensnpcs.nms.v1_17_R1.util;
|
|||
import java.lang.invoke.MethodHandle;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -15,7 +11,6 @@ import net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC;
|
|||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ChunkMap.TrackedEntity;
|
||||
import net.minecraft.server.level.ServerEntity;
|
||||
|
@ -37,30 +32,10 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||
|
||||
public void updateLastPlayer() {
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(),
|
||||
lastUpdatedPlayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
lastUpdatedPlayer = null;
|
||||
}
|
||||
|
||||
if (tracker.isRemoved() || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|
||||
|| !CitizensAPI.hasImplementation())
|
||||
return;
|
||||
|
||||
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()),
|
||||
Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1174,8 +1174,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,17 +17,16 @@ import net.minecraft.world.InteractionHand;
|
|||
import net.minecraft.world.entity.Pose;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
final ServerPlayer player = (ServerPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.setPose(Pose.CROUCHING);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.startFallFlying();
|
||||
|
@ -37,40 +36,38 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.startUsingItem(InteractionHand.MAIN_HAND);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
player.getBukkitEntity().setMetadata("citizens-using-item-remaining-ticks",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks()));
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.startUsingItem(InteractionHand.OFF_HAND);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
player.getBukkitEntity().setMetadata("citizens-using-item-remaining-ticks",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks()));
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.setPose(Pose.STANDING);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.stopUsingItem();
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
|
||||
player, radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(ServerPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(ServerPlayer player, Iterable<Player> to, int code) {
|
||||
ClientboundAnimatePacket packet = new ClientboundAnimatePacket(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, ServerPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -3,11 +3,7 @@ package net.citizensnpcs.nms.v1_18_R2.util;
|
|||
import java.lang.invoke.MethodHandle;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -15,7 +11,6 @@ import net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC;
|
|||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ChunkMap.TrackedEntity;
|
||||
import net.minecraft.server.level.ServerEntity;
|
||||
|
@ -37,30 +32,10 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||
|
||||
public void updateLastPlayer() {
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(),
|
||||
lastUpdatedPlayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
lastUpdatedPlayer = null;
|
||||
}
|
||||
|
||||
if (tracker.isRemoved() || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|
||||
|| !CitizensAPI.hasImplementation())
|
||||
return;
|
||||
|
||||
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
|
||||
NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,11 +73,6 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||
|
||||
if (cancelled)
|
||||
return;
|
||||
|
||||
this.lastUpdatedPlayer = entityplayer;
|
||||
super.updatePlayer(entityplayer);
|
||||
Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(npc, entityplayer.getBukkitEntity()));
|
||||
return;
|
||||
}
|
||||
|
||||
this.lastUpdatedPlayer = entityplayer;
|
||||
|
|
|
@ -4,13 +4,9 @@ import java.lang.invoke.MethodHandle;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -18,7 +14,6 @@ import net.citizensnpcs.nms.v1_19_R3.entity.EntityHumanNPC;
|
|||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ChunkMap.TrackedEntity;
|
||||
import net.minecraft.server.level.ServerEntity;
|
||||
|
@ -39,10 +34,8 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
|
|||
public boolean add(ServerPlayerConnection conn) {
|
||||
boolean res = super.add(conn);
|
||||
if (res) {
|
||||
updateLastPlayer(conn.getPlayer());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(
|
||||
((NPCHolder) tracker).getNPC(), conn.getPlayer().getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(),
|
||||
conn.getPlayer().getBukkitEntity()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -61,31 +54,6 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
|
|||
this(map, getTracker(entry), getTrackingDistance(entry), getE(entry), getF(entry));
|
||||
}
|
||||
|
||||
public void updateLastPlayer(ServerPlayer lastUpdatedPlayer) {
|
||||
if (tracker.isRemoved() || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|
||||
|| !CitizensAPI.hasImplementation())
|
||||
return;
|
||||
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
boolean resetYaw = npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean());
|
||||
boolean sendTabRemove = NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
if (!sendTabRemove || !Setting.DISABLE_TABLIST.asBoolean()) {
|
||||
if (resetYaw) {
|
||||
Bukkit.getScheduler()
|
||||
.scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> NMSImpl
|
||||
.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
|
||||
if (resetYaw) {
|
||||
NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0));
|
||||
}
|
||||
NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePlayer(final ServerPlayer entityplayer) {
|
||||
if (entityplayer instanceof EntityHumanNPC)
|
||||
|
|
|
@ -1304,8 +1304,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,19 +18,19 @@ import net.minecraft.world.InteractionHand;
|
|||
import net.minecraft.world.entity.Pose;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
final ServerPlayer player = (ServerPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case HURT:
|
||||
sendPacketNearby(new ClientboundHurtAnimationPacket(player), player, radius);
|
||||
sendPacketNearby(new ClientboundHurtAnimationPacket(player), to);
|
||||
break;
|
||||
case SNEAK:
|
||||
player.setPose(Pose.CROUCHING);
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.startFallFlying();
|
||||
|
@ -40,42 +40,44 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.startUsingItem(InteractionHand.MAIN_HAND);
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
player.getBukkitEntity().setMetadata("citizens-using-item-remaining-ticks",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks()));
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.startUsingItem(InteractionHand.OFF_HAND);
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
player.getBukkitEntity().setMetadata("citizens-using-item-remaining-ticks",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks()));
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.setPose(Pose.STANDING);
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.stopUsingItem();
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(ServerPlayer player, int radius, int code) {
|
||||
sendPacketNearby(new ClientboundAnimatePacket(player, code), player, radius);
|
||||
protected static void playDefaultAnimation(ServerPlayer player, Iterable<Player> to, int code) {
|
||||
ClientboundAnimatePacket packet = new ClientboundAnimatePacket(player, code);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
private static void sendEntityData(int radius, final ServerPlayer player) {
|
||||
private static void sendEntityData(Iterable<Player> to, final ServerPlayer player) {
|
||||
if (!player.getEntityData().isDirty())
|
||||
return;
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()), player,
|
||||
radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()), to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, ServerPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -4,13 +4,9 @@ import java.lang.invoke.MethodHandle;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -18,8 +14,6 @@ import net.citizensnpcs.nms.v1_20_R2.entity.EntityHumanNPC;
|
|||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ChunkMap.TrackedEntity;
|
||||
import net.minecraft.server.level.ServerEntity;
|
||||
|
@ -40,10 +34,8 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
|
|||
public boolean add(ServerPlayerConnection conn) {
|
||||
boolean res = super.add(conn);
|
||||
if (res) {
|
||||
updateLastPlayer(conn.getPlayer());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(
|
||||
((NPCHolder) tracker).getNPC(), conn.getPlayer().getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(),
|
||||
conn.getPlayer().getBukkitEntity()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -62,41 +54,6 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
|
|||
this(map, getTracker(entry), getTrackingDistance(entry), getUpdateInterval(entry), getTrackDelta(entry));
|
||||
}
|
||||
|
||||
public void updateLastPlayer(ServerPlayer lastUpdatedPlayer) {
|
||||
if (tracker.isRemoved() || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|
||||
|| !CitizensAPI.hasImplementation())
|
||||
return;
|
||||
|
||||
final ServerPlayer entityplayer = lastUpdatedPlayer;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
|
||||
if (tracker.isRemoved() || entityplayer.isRemoved())
|
||||
return;
|
||||
NMSImpl.sendPacket(entityplayer.getBukkitEntity(),
|
||||
new ClientboundRotateHeadPacket(tracker, (byte) (tracker.getYHeadRot() * 256.0F / 360.0F)));
|
||||
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks() + 1);
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
boolean resetYaw = npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean());
|
||||
boolean sendTabRemove = NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
if (!sendTabRemove || !Setting.DISABLE_TABLIST.asBoolean()) {
|
||||
if (resetYaw) {
|
||||
Bukkit.getScheduler()
|
||||
.scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> NMSImpl
|
||||
.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
|
||||
if (tracker.isRemoved() || entityplayer.isRemoved())
|
||||
return;
|
||||
NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
if (resetYaw) {
|
||||
NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0));
|
||||
}
|
||||
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePlayer(final ServerPlayer entityplayer) {
|
||||
if (entityplayer instanceof EntityHumanNPC)
|
||||
|
|
|
@ -918,14 +918,15 @@ public class NMSImpl implements NMSBridge {
|
|||
org.bukkit.entity.Entity mount, double offset) {
|
||||
Interaction handle = (Interaction) getHandle(entity);
|
||||
offset += handle.getMyRidingOffset(getHandle(mount));
|
||||
sendPacket(player, new ClientboundBundlePacket(List.of(
|
||||
new ClientboundSetEntityDataPacket(entity.getEntityId(),
|
||||
List.of(new SynchedEntityData.DataItem<>(INTERACTION_WIDTH, 0f).value(),
|
||||
new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, (float) offset).value(),
|
||||
new SynchedEntityData.DataItem<>(DATA_POSE, Pose.CROAKING).value())),
|
||||
new ClientboundSetPassengersPacket(getHandle(mount)),
|
||||
new ClientboundSetEntityDataPacket(entity.getEntityId(),
|
||||
List.of(new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, 999999f).value())))));
|
||||
sendPacket(player,
|
||||
new ClientboundBundlePacket(List.of(
|
||||
new ClientboundSetEntityDataPacket(entity.getEntityId(),
|
||||
List.of(new SynchedEntityData.DataItem<>(INTERACTION_WIDTH, 0f).value(),
|
||||
new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, (float) offset).value(),
|
||||
new SynchedEntityData.DataItem<>(DATA_POSE, Pose.CROAKING).value())),
|
||||
new ClientboundSetPassengersPacket(getHandle(mount)),
|
||||
new ClientboundSetEntityDataPacket(entity.getEntityId(),
|
||||
List.of(new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, 999999f).value())))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1279,8 +1280,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,20 +18,20 @@ import net.minecraft.world.InteractionHand;
|
|||
import net.minecraft.world.entity.Pose;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
final ServerPlayer player = (ServerPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (animation) {
|
||||
case HURT:
|
||||
sendPacketNearby(new ClientboundHurtAnimationPacket(player), player, radius);
|
||||
sendPacketNearby(new ClientboundHurtAnimationPacket(player), to);
|
||||
break;
|
||||
case SNEAK:
|
||||
player.setPose(Pose.CROUCHING);
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
break;
|
||||
case START_ELYTRA:
|
||||
player.startFallFlying();
|
||||
|
@ -41,42 +41,44 @@ public class PlayerAnimationImpl {
|
|||
break;
|
||||
case START_USE_MAINHAND_ITEM:
|
||||
player.startUsingItem(InteractionHand.MAIN_HAND);
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
player.getBukkitEntity().setMetadata("citizens-using-item-remaining-ticks",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks()));
|
||||
break;
|
||||
case START_USE_OFFHAND_ITEM:
|
||||
player.startUsingItem(InteractionHand.OFF_HAND);
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
player.getBukkitEntity().setMetadata("citizens-using-item-remaining-ticks",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks()));
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.setPose(Pose.STANDING);
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
break;
|
||||
case STOP_USE_ITEM:
|
||||
player.stopUsingItem();
|
||||
sendEntityData(radius, player);
|
||||
sendEntityData(to, player);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(ServerPlayer player, int radius, int code) {
|
||||
sendPacketNearby(new ClientboundAnimatePacket(player, code), player, radius);
|
||||
protected static void playDefaultAnimation(ServerPlayer player, Iterable<Player> to, int code) {
|
||||
ClientboundAnimatePacket packet = new ClientboundAnimatePacket(player, code);
|
||||
sendPacketNearby(packet, to);
|
||||
}
|
||||
|
||||
private static void sendEntityData(int radius, final ServerPlayer player) {
|
||||
private static void sendEntityData(Iterable<Player> to, final ServerPlayer player) {
|
||||
if (!player.getEntityData().isDirty())
|
||||
return;
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()), player,
|
||||
radius);
|
||||
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()), to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, ServerPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketNearby(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -195,7 +195,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||
|
||||
@Override
|
||||
public DataWatcher getDataWatcher() {
|
||||
if (trackerEntry != null && trackerEntry.isUpdating()) {
|
||||
if (trackerEntry != null) {
|
||||
trackerEntry.updateLastPlayer();
|
||||
}
|
||||
return super.getDataWatcher();
|
||||
|
|
|
@ -904,8 +904,8 @@ public class NMSImpl implements NMSBridge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
||||
PlayerAnimationImpl.play(animation, player, radius);
|
||||
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to) {
|
||||
PlayerAnimationImpl.play(animation, player, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1735,10 +1735,6 @@ public class NMSImpl implements NMSBridge {
|
|||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
|
||||
public static void sendPacketNearby(Player from, Location location, Packet<?> packet) {
|
||||
sendPacketNearby(from, location, packet, 64);
|
||||
}
|
||||
|
||||
public static void sendPacketNearby(Player from, Location location, Packet<?> packet, double radius) {
|
||||
List<Packet<?>> list = new ArrayList<Packet<?>>();
|
||||
list.add(packet);
|
||||
|
|
|
@ -13,36 +13,36 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation;
|
|||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
|
||||
|
||||
public class PlayerAnimationImpl {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
|
||||
public static void play(PlayerAnimation animation, Player bplayer, Iterable<Player> to) {
|
||||
// TODO: this is pretty gross
|
||||
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
|
||||
if (DEFAULTS.containsKey(animation)) {
|
||||
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
|
||||
playDefaultAnimation(player, to, DEFAULTS.get(animation));
|
||||
return;
|
||||
}
|
||||
switch (animation) {
|
||||
case SNEAK:
|
||||
player.getBukkitEntity().setSneaking(true);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketTo(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
case STOP_SNEAKING:
|
||||
player.getBukkitEntity().setSneaking(false);
|
||||
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
sendPacketTo(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), to);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) {
|
||||
protected static void playDefaultAnimation(EntityPlayer player, Iterable<Player> to, int code) {
|
||||
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
sendPacketTo(packet, to);
|
||||
}
|
||||
|
||||
protected static void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
|
||||
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
|
||||
protected static void sendPacketTo(Packet<?> packet, Iterable<Player> to) {
|
||||
for (Player player : to) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<PlayerAnimation, Integer> DEFAULTS = Maps.newEnumMap(PlayerAnimation.class);
|
||||
|
|
|
@ -3,11 +3,7 @@ package net.citizensnpcs.nms.v1_8_R3.util;
|
|||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCLinkToPlayerEvent;
|
||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
@ -17,7 +13,6 @@ import net.citizensnpcs.util.NMS;
|
|||
import net.minecraft.server.v1_8_R3.Entity;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation;
|
||||
|
||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||
private EntityPlayer lastUpdatedPlayer;
|
||||
|
@ -30,35 +25,12 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||
this(entry.tracker, getB(entry), getC(entry), getU(entry));
|
||||
}
|
||||
|
||||
public boolean isUpdating() {
|
||||
return lastUpdatedPlayer != null;
|
||||
}
|
||||
|
||||
public void updateLastPlayer() {
|
||||
if (lastUpdatedPlayer != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> Bukkit.getPluginManager().callEvent(new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(),
|
||||
lastUpdatedPlayer.getBukkitEntity())));
|
||||
Bukkit.getPluginManager().callEvent(
|
||||
new NPCLinkToPlayerEvent(((NPCHolder) tracker).getNPC(), lastUpdatedPlayer.getBukkitEntity()));
|
||||
lastUpdatedPlayer = null;
|
||||
}
|
||||
|
||||
if (lastUpdatedPlayer == null || tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||
return;
|
||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
lastUpdatedPlayer = null;
|
||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||
if (npc.data().get(NPC.Metadata.RESET_YAW_ON_SPAWN, Setting.RESET_YAW_ON_SPAWN.asBoolean())) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new PacketPlayOutAnimation(tracker, 0)),
|
||||
1);
|
||||
}
|
||||
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
|
||||
NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,7 +47,6 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||
|
||||
lastUpdatedPlayer = entityplayer;
|
||||
super.updatePlayer(entityplayer);
|
||||
lastUpdatedPlayer = null;
|
||||
}
|
||||
|
||||
private static int getB(EntityTrackerEntry entry) {
|
||||
|
|
Loading…
Reference in New Issue