mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-22 17:18:20 +01:00
Reset packetrotationsession yaw to physical yaw on removal
This commit is contained in:
parent
1416557ce3
commit
8ca8c14f89
@ -451,7 +451,7 @@ public class EventListen implements Listener {
|
||||
if (!tracker.isValid() || !event.getPlayer().isValid())
|
||||
return;
|
||||
|
||||
NMS.sendPositionUpdate(tracker, false, null, null, NMS.getHeadYaw(tracker));
|
||||
NMS.sendPositionUpdateNearby(tracker, false, null, null, NMS.getHeadYaw(tracker));
|
||||
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks() + 1);
|
||||
|
||||
boolean resetYaw = event.getNPC().data().get(NPC.Metadata.RESET_YAW_ON_SPAWN,
|
||||
|
@ -55,7 +55,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.ProtocolLibListener;
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.StoredShops;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
@ -163,7 +162,6 @@ import net.citizensnpcs.util.Util;
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public class NPCCommands {
|
||||
private final CommandHistory history;
|
||||
private final ProtocolLibListener protocolListener;
|
||||
private final NPCSelector selector;
|
||||
private final StoredShops shops;
|
||||
private final NPCRegistry temporaryRegistry;
|
||||
@ -173,7 +171,6 @@ public class NPCCommands {
|
||||
shops = plugin.getShops();
|
||||
temporaryRegistry = CitizensAPI.createCitizensBackedNPCRegistry(new MemoryNPCDataStore());
|
||||
history = new CommandHistory(selector);
|
||||
protocolListener = plugin.getProtocolLibListener();
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -458,7 +455,7 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "command|cmd (add [command] | remove [id] | permissions [permissions] | sequential | random | clearerror [type] (name|uuid) | errormsg [type] [msg] | persistsequence [true|false] | cost [cost] (id) | expcost [cost] (id) | itemcost (id)) (-s(hift)) (-l[eft]/-r[ight]) (-p[layer] -o[p]), --cooldown --gcooldown [seconds] --delay [ticks] --permissions [perms] --n [max # of uses]",
|
||||
usage = "command|cmd (add [command] | remove [id|all] | permissions [permissions] | sequential | random | clearerror [type] (name|uuid) | errormsg [type] [msg] | persistsequence [true|false] | cost [cost] (id) | expcost [cost] (id) | itemcost (id)) (-s(hift)) (-l[eft]/-r[ight]) (-p[layer] -o[p]), --cooldown --gcooldown [seconds] --delay [ticks] --permissions [perms] --n [max # of uses]",
|
||||
desc = "Controls commands which will be run when clicking on an NPC",
|
||||
help = Messages.NPC_COMMAND_HELP,
|
||||
modifiers = { "command", "cmd" },
|
||||
@ -535,11 +532,16 @@ public class NPCCommands {
|
||||
} else if (action.equalsIgnoreCase("remove")) {
|
||||
if (args.argsLength() == 2)
|
||||
throw new CommandUsageException();
|
||||
int id = args.getInteger(2, -1);
|
||||
if (!commands.hasCommandId(id))
|
||||
throw new CommandException(Messages.COMMAND_UNKNOWN_COMMAND_ID, id);
|
||||
commands.removeCommandById(id);
|
||||
Messaging.sendTr(sender, Messages.COMMAND_REMOVED, id);
|
||||
if (args.getString(2).equalsIgnoreCase("all")) {
|
||||
commands.clear();
|
||||
Messaging.sendTr(sender, Messages.COMMANDS_CLEARED, npc.getName());
|
||||
} else {
|
||||
int id = args.getInteger(2, -1);
|
||||
if (!commands.hasCommandId(id))
|
||||
throw new CommandException(Messages.COMMAND_UNKNOWN_COMMAND_ID, id);
|
||||
commands.removeCommandById(id);
|
||||
Messaging.sendTr(sender, Messages.COMMAND_REMOVED, id);
|
||||
}
|
||||
} else if (action.equalsIgnoreCase("permissions") || action.equalsIgnoreCase("perms")) {
|
||||
if (!sender.hasPermission("citizens.admin"))
|
||||
throw new NoPermissionsException();
|
||||
@ -2556,7 +2558,8 @@ public class NPCCommands {
|
||||
if (yaw != null) {
|
||||
NMS.setBodyYaw(npc.getEntity(), yaw);
|
||||
if (npc.getEntity().getType() == EntityType.PLAYER) {
|
||||
NMS.sendPositionUpdate(npc.getEntity(), true, yaw, npc.getStoredLocation().getPitch(), null);
|
||||
NMS.sendPositionUpdateNearby(npc.getEntity(), true, yaw, npc.getEntity().getLocation().getPitch(),
|
||||
null);
|
||||
PlayerAnimation.ARM_SWING.play((Player) npc.getEntity());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.citizensnpcs.npc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -306,8 +305,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
if (getEntity() instanceof SkinnableEntity && !hasTrait(SkinLayers.class)) {
|
||||
((SkinnableEntity) getEntity()).setSkinFlags(EnumSet.allOf(SkinLayers.Layer.class));
|
||||
}
|
||||
Collection<Trait> onPreSpawn = traits.values();
|
||||
for (Trait trait : onPreSpawn.toArray(new Trait[onPreSpawn.size()])) {
|
||||
for (Trait trait : traits.values().toArray(new Trait[traits.values().size()])) {
|
||||
try {
|
||||
trait.onPreSpawn();
|
||||
} catch (Throwable ex) {
|
||||
@ -315,12 +313,12 @@ public class CitizensNPC extends AbstractNPC {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
boolean loaded = Messaging.isDebugging() ? false : Util.isLoaded(at);
|
||||
boolean wasLoaded = Messaging.isDebugging() ? Util.isLoaded(at) : false;
|
||||
boolean couldSpawn = entityController.spawn(at);
|
||||
|
||||
if (!couldSpawn) {
|
||||
if (Messaging.isDebugging()) {
|
||||
Messaging.debug("Retrying spawn of", this, "later, SpawnReason." + reason + ". Was loaded", loaded,
|
||||
Messaging.debug("Retrying spawn of", this, "later, SpawnReason." + reason + ". Was loaded", wasLoaded,
|
||||
"is loaded", Util.isLoaded(at));
|
||||
}
|
||||
// we need to wait before trying to spawn
|
||||
|
@ -142,6 +142,10 @@ public class CommandTrait extends Trait {
|
||||
return action == null ? Transaction.success() : action.take(player, 1);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
commands.clear();
|
||||
}
|
||||
|
||||
public void clearHistory(CommandTraitError which, String raw) {
|
||||
if (which == CommandTraitError.ON_GLOBAL_COOLDOWN && raw != null) {
|
||||
globalCooldowns.remove(BaseEncoding.base64().encode(raw.getBytes()));
|
||||
|
@ -340,8 +340,7 @@ public class HologramTrait extends Trait {
|
||||
}
|
||||
if (nameLine != null && nameLine.hologram.isSpawned()) {
|
||||
if (updatePosition && !useDisplayEntities) {
|
||||
nameLine.hologram.teleport(npcLoc.clone().add(0, getEntityBbHeight(), 0),
|
||||
TeleportCause.PLUGIN);
|
||||
nameLine.hologram.teleport(npcLoc.clone().add(0, getEntityBbHeight(), 0), TeleportCause.PLUGIN);
|
||||
}
|
||||
if (updateName) {
|
||||
nameLine.setText(npc.getRawName());
|
||||
|
@ -3,7 +3,6 @@ package net.citizensnpcs.trait;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -110,18 +109,18 @@ public class LookClose extends Trait implements Toggleable {
|
||||
session.getSession().rotateToFace(player);
|
||||
seen.add(player.getUniqueId());
|
||||
}
|
||||
for (Iterator<Entry<UUID, PacketRotationSession>> iterator = sessions.entrySet().iterator(); iterator
|
||||
.hasNext();) {
|
||||
Entry<UUID, PacketRotationSession> entry = iterator.next();
|
||||
if (!seen.contains(entry.getKey())) {
|
||||
entry.getValue().end();
|
||||
for (Iterator<UUID> iterator = sessions.keySet().iterator(); iterator.hasNext();) {
|
||||
UUID uuid = iterator.next();
|
||||
if (!seen.contains(uuid)) {
|
||||
rotationTrait.resetPlayerToPhysicalSession(uuid);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (sessions.size() > 0) {
|
||||
for (PacketRotationSession session : sessions.values()) {
|
||||
session.end();
|
||||
RotationTrait rotationTrait = npc.getOrAddTrait(RotationTrait.class);
|
||||
for (UUID uuid : sessions.keySet()) {
|
||||
rotationTrait.resetPlayerToPhysicalSession(uuid);
|
||||
}
|
||||
sessions.clear();
|
||||
}
|
||||
|
@ -11,11 +11,13 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
@ -93,6 +95,16 @@ public class RotationTrait extends Trait {
|
||||
return globalSession;
|
||||
}
|
||||
|
||||
public void resetPlayerToPhysicalSession(UUID uuid) {
|
||||
PacketRotationSession prs = packetSessionsByUUID.remove(uuid);
|
||||
if (prs == null || !npc.isSpawned())
|
||||
return;
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null)
|
||||
return;
|
||||
NMS.sendPositionUpdate(npc.getEntity(), ImmutableList.of(player), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!npc.isSpawned())
|
||||
@ -205,7 +217,7 @@ public class RotationTrait extends Trait {
|
||||
@Override
|
||||
public void apply() {
|
||||
if (Math.abs(lastBodyYaw - bodyYaw) + Math.abs(lastHeadYaw - headYaw) + Math.abs(pitch - lastPitch) > 1) {
|
||||
NMS.sendPositionUpdate(entity, false, bodyYaw, pitch, headYaw);
|
||||
NMS.sendPositionUpdateNearby(entity, false, bodyYaw, pitch, headYaw);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -547,9 +547,9 @@ public class ShopTrait extends Trait {
|
||||
int pos = 0;
|
||||
|
||||
for (GUI template : NPCShopAction.getGUIs()) {
|
||||
if (template.createMenuItem(null) == null) {
|
||||
if (template.createMenuItem(null) == null)
|
||||
continue;
|
||||
}
|
||||
|
||||
NPCShopAction oldCost = modified.cost.stream().filter(template::manages).findFirst().orElse(null);
|
||||
costItems.getSlots().get(pos)
|
||||
.setItemStack(Util.editTitle(template.createMenuItem(oldCost), title -> title + " Cost"));
|
||||
|
@ -78,6 +78,7 @@ public class Messages {
|
||||
public static final String COMMAND_TRIGGER_ADDED = "citizens.editors.waypoints.triggers.command.added";
|
||||
public static final String COMMAND_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.command.prompt";
|
||||
public static final String COMMAND_UNKNOWN_COMMAND_ID = "citizens.commands.npc.command.unknown-id";
|
||||
public static final String COMMANDS_CLEARED = "citizens.commands.npc.command.cleared";
|
||||
public static final String COMMANDS_PERSIST_SEQUENCE_SET = "citizens.commands.npc.command.persist-sequence-set";
|
||||
public static final String COMMANDS_PERSIST_SEQUENCE_UNSET = "citizens.commands.npc.command.persist-sequence-unset";
|
||||
public static final String COMMANDS_RANDOM_SET = "citizens.commands.npc.commands.random-set";
|
||||
|
@ -42,6 +42,7 @@ import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.ProfileLookupCallback;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.ai.NavigatorParameters;
|
||||
import net.citizensnpcs.api.astar.pathfinder.SwimmingExaminer;
|
||||
import net.citizensnpcs.api.command.CommandManager;
|
||||
@ -517,6 +518,22 @@ public class NMS {
|
||||
return BRIDGE.getNBT(item);
|
||||
}
|
||||
|
||||
private static Collection<Player> getNearbyPlayers(Entity from) {
|
||||
return getNearbyPlayers(from, from.getLocation(), 64);
|
||||
}
|
||||
|
||||
private static Collection<Player> getNearbyPlayers(Entity from, Location location, double radius) {
|
||||
List<Player> players = Lists.newArrayList();
|
||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) {
|
||||
if (location.getWorld() != player.getWorld() || from != null && !player.canSee(from)
|
||||
|| location.distance(player.getLocation()) > radius)
|
||||
continue;
|
||||
|
||||
players.add(player);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
public static NPC getNPC(Entity entity) {
|
||||
return BRIDGE.getNPC(entity);
|
||||
}
|
||||
@ -734,8 +751,23 @@ public class NMS {
|
||||
BRIDGE.replaceTrackerEntry(entity);
|
||||
}
|
||||
|
||||
public static void sendPositionUpdate(Entity from, boolean position, Float bodyYaw, Float pitch, Float headYaw) {
|
||||
BRIDGE.sendPositionUpdate(from, position, bodyYaw, pitch, headYaw);
|
||||
public static void sendPositionUpdate(Entity from, Collection<Player> to, boolean position) {
|
||||
sendPositionUpdate(from, to, position, NMS.getYaw(from), from.getLocation().getPitch(), NMS.getHeadYaw(from));
|
||||
}
|
||||
|
||||
public static void sendPositionUpdate(Entity from, Collection<Player> to, boolean position, Float bodyYaw,
|
||||
Float pitch, Float headYaw) {
|
||||
BRIDGE.sendPositionUpdate(from, to, position, bodyYaw, pitch, headYaw);
|
||||
}
|
||||
|
||||
public static void sendPositionUpdateNearby(Entity from, boolean position) {
|
||||
sendPositionUpdate(from, getNearbyPlayers(from), position, NMS.getYaw(from), from.getLocation().getPitch(),
|
||||
NMS.getHeadYaw(from));
|
||||
}
|
||||
|
||||
public static void sendPositionUpdateNearby(Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
sendPositionUpdate(from, getNearbyPlayers(from), position, bodyYaw, pitch, headYaw);
|
||||
}
|
||||
|
||||
public static boolean sendTabListAdd(Player recipient, Player listPlayer) {
|
||||
|
@ -168,7 +168,8 @@ public interface NMSBridge {
|
||||
|
||||
public void replaceTrackerEntry(Entity entity);
|
||||
|
||||
public void sendPositionUpdate(Entity from, boolean position, Float bodyYaw, Float pitch, Float headYaw);
|
||||
public void sendPositionUpdate(Entity from, Collection<Player> to, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw);
|
||||
|
||||
public boolean sendTabListAdd(Player recipient, Player listPlayer);
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
||||
"citizens.commands.npc.collidable.unset" : "[[{0}]] will no longer collide with entities.",
|
||||
"citizens.commands.npc.command.command-added" : "Command [[{0}]] added with id [[{1}]].",
|
||||
"citizens.commands.npc.command.command-removed" : "Command [[{0}]] removed.",
|
||||
"citizens.commands.npc.command.cleared" : "[[{0}]]''s commands cleared.",
|
||||
"citizens.commands.npc.command.cost-missing" : "Missing cost to set.",
|
||||
"citizens.commands.npc.command.cost-set" : "Set cost per click to [[{0}]].",
|
||||
"citizens.commands.npc.command.describe-format" : "<br> - {0} [{1}s] [cost:{2}] [exp:{3}] [<click:run_command:/npc cmd remove {4}><hover:show_text:Remove this command><red><u>-</hover></click>]",
|
||||
|
@ -1080,8 +1080,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.yaw;
|
||||
@ -1110,7 +1110,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1881,6 +1883,14 @@ public class NMSImpl implements NMSBridge {
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
|
@ -1133,8 +1133,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.yaw;
|
||||
@ -1163,7 +1163,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1940,6 +1942,14 @@ public class NMSImpl implements NMSBridge {
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
|
@ -1140,8 +1140,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.yaw;
|
||||
@ -1170,7 +1170,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1947,6 +1949,14 @@ public class NMSImpl implements NMSBridge {
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
|
@ -1177,8 +1177,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.yaw;
|
||||
@ -1207,7 +1207,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2061,6 +2063,14 @@ public class NMSImpl implements NMSBridge {
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
|
@ -4,7 +4,6 @@ import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -1196,8 +1195,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.yaw;
|
||||
@ -1226,7 +1225,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2101,14 +2102,12 @@ public class NMSImpl implements NMSBridge {
|
||||
((EntityPlayer) NMSImpl.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<>();
|
||||
list.add(packet);
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
|
@ -4,7 +4,6 @@ import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -1213,8 +1212,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.yaw;
|
||||
@ -1243,7 +1242,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2166,14 +2167,12 @@ public class NMSImpl implements NMSBridge {
|
||||
((EntityPlayer) NMSImpl.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<>();
|
||||
list.add(packet);
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
|
@ -4,7 +4,6 @@ import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -1249,8 +1248,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.yaw;
|
||||
@ -1279,7 +1278,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2164,14 +2165,12 @@ public class NMSImpl implements NMSBridge {
|
||||
((EntityPlayer) NMSImpl.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<>();
|
||||
list.add(packet);
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
|
@ -4,8 +4,6 @@ import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@ -1243,8 +1241,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.getYRot();
|
||||
@ -1273,7 +1271,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2163,34 +2163,14 @@ public class NMSImpl implements NMSBridge {
|
||||
((ServerPlayer) NMSImpl.getHandle(player)).connection.send(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<>();
|
||||
list.add(packet);
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) {
|
||||
if (world != player.getWorld() || from != null && !player.canSee(from)
|
||||
|| location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) {
|
||||
continue;
|
||||
}
|
||||
for (Packet<?> packet : packets) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((ServerPlayer) getHandle(player)).connection.send(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Packet<?>... packets) {
|
||||
NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64);
|
||||
}
|
||||
|
||||
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
|
||||
try {
|
||||
ADVANCEMENTS_PLAYER_FIELD.invoke(getHandle(entity), instance);
|
||||
|
@ -3,8 +3,6 @@ package net.citizensnpcs.nms.v1_18_R2.util;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@ -1252,8 +1250,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.getYRot();
|
||||
@ -1282,7 +1280,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2170,34 +2170,14 @@ public class NMSImpl implements NMSBridge {
|
||||
((ServerPlayer) NMSImpl.getHandle(player)).connection.send(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<>();
|
||||
list.add(packet);
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) {
|
||||
if (world != player.getWorld() || from != null && !player.canSee(from)
|
||||
|| location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) {
|
||||
continue;
|
||||
}
|
||||
for (Packet<?> packet : packets) {
|
||||
NMSImpl.sendPacket(player, packet);
|
||||
}
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((ServerPlayer) getHandle(player)).connection.send(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Packet<?>... packets) {
|
||||
NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64);
|
||||
}
|
||||
|
||||
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
|
||||
try {
|
||||
ADVANCEMENTS_PLAYER_FIELD.invoke(getHandle(entity), instance);
|
||||
|
@ -4,7 +4,6 @@ package net.citizensnpcs.nms.v1_19_R3.util;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -1375,10 +1374,12 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
List<Packet<?>> toSend = getPositionUpdate(from, position, bodyYaw, pitch, headYaw);
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player dest : to) {
|
||||
sendPackets(dest, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2396,34 +2397,14 @@ public class NMSImpl implements NMSBridge {
|
||||
((ServerPlayer) getHandle(player)).connection.send(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<>();
|
||||
list.add(packet);
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) {
|
||||
if (world != player.getWorld() || from != null && !player.canSee(from)
|
||||
|| location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) {
|
||||
continue;
|
||||
}
|
||||
for (Packet<?> packet : packets) {
|
||||
sendPacket(player, packet);
|
||||
}
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((ServerPlayer) getHandle(player)).connection.send(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Packet<?>... packets) {
|
||||
sendPacketsNearby(from, location, Arrays.asList(packets), 64);
|
||||
}
|
||||
|
||||
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
|
||||
try {
|
||||
ADVANCEMENTS_PLAYER_SETTER.invoke(getHandle(entity), instance);
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.citizensnpcs.nms.v1_20_R3.util;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -1346,10 +1345,12 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
List<Packet<?>> toSend = getPositionUpdate(from, position, bodyYaw, pitch, headYaw);
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player dest : to) {
|
||||
sendPackets(dest, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2357,34 +2358,14 @@ public class NMSImpl implements NMSBridge {
|
||||
((ServerPlayer) getHandle(player)).connection.send(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<>();
|
||||
list.add(packet);
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) {
|
||||
if (world != player.getWorld() || from != null && !player.canSee(from)
|
||||
|| location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) {
|
||||
continue;
|
||||
}
|
||||
for (Packet<?> packet : packets) {
|
||||
sendPacket(player, packet);
|
||||
}
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((ServerPlayer) getHandle(player)).connection.send(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Packet<?>... packets) {
|
||||
sendPacketsNearby(from, location, Arrays.asList(packets), 64);
|
||||
}
|
||||
|
||||
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
|
||||
try {
|
||||
ADVANCEMENTS_PLAYER_SETTER.invoke(getHandle(entity), instance);
|
||||
|
@ -1006,8 +1006,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch,
|
||||
Float headYaw) {
|
||||
public void sendPositionUpdate(org.bukkit.entity.Entity from, Collection<Player> to, boolean position,
|
||||
Float bodyYaw, Float pitch, Float headYaw) {
|
||||
Entity handle = getHandle(from);
|
||||
if (bodyYaw == null) {
|
||||
bodyYaw = handle.yaw;
|
||||
@ -1030,7 +1030,9 @@ public class NMSImpl implements NMSBridge {
|
||||
if (headYaw != null) {
|
||||
toSend.add(new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)));
|
||||
}
|
||||
sendPacketsNearby(null, from.getLocation(), toSend, 64);
|
||||
for (Player player : to) {
|
||||
sendPackets(player, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1738,6 +1740,14 @@ public class NMSImpl implements NMSBridge {
|
||||
sendPacketsNearby(from, location, list, radius);
|
||||
}
|
||||
|
||||
public static void sendPackets(Player player, Iterable<Packet<?>> packets) {
|
||||
if (packets == null)
|
||||
return;
|
||||
for (Packet<?> packet : packets) {
|
||||
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
|
||||
radius *= radius;
|
||||
final org.bukkit.World world = location.getWorld();
|
||||
|
Loading…
Reference in New Issue
Block a user