move a lot of packet sending to PacketEvents
This commit is contained in:
parent
0efab9d77d
commit
74c954c553
15 changed files with 58 additions and 223 deletions
|
@ -1,5 +1,6 @@
|
|||
package io.github.znetworkw.znpcservers.commands.list;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
@ -180,9 +181,7 @@ public class DefaultCommand extends Command {
|
|||
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.NPC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
foundNPC.getNpcPojo().getNpcEquip().put(
|
||||
ItemSlot.valueOf(args.get("slot").toUpperCase()), sender
|
||||
.getPlayer().getInventory().getItemInHand());
|
||||
foundNPC.getNpcPojo().getNpcEquip().put(EquipmentSlot.valueOf(args.get("slot").toUpperCase()), sender.getPlayer().getInventory().getItemInHand());
|
||||
foundNPC.getPackets().flushCache("equipPackets");
|
||||
Objects.requireNonNull(foundNPC);
|
||||
Objects.requireNonNull(foundNPC);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package io.github.znetworkw.znpcservers.hologram;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities;
|
||||
import io.github.znetworkw.znpcservers.UnexpectedCallException;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import io.github.znetworkw.znpcservers.configuration.Configuration;
|
||||
|
@ -65,13 +67,7 @@ public class Hologram {
|
|||
}
|
||||
|
||||
public void delete(ZUser user) {
|
||||
this.hologramLines.forEach(hologramLine -> {
|
||||
try {
|
||||
Utils.sendPackets(user, this.npc.getPackets().getNms().createEntityDestroyPacket(hologramLine.id));
|
||||
} catch (ReflectiveOperationException operationException) {
|
||||
throw new UnexpectedCallException(operationException);
|
||||
}
|
||||
});
|
||||
this.hologramLines.forEach(hologramLine -> PacketEvents.getAPI().getPlayerManager().sendPacket(user.toPlayer(), new WrapperPlayServerDestroyEntities(hologramLine.id)));
|
||||
}
|
||||
|
||||
public void updateNames(ZUser user) {
|
||||
|
|
|
@ -2,17 +2,14 @@ package io.github.znetworkw.znpcservers.nms;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import io.github.znetworkw.znpcservers.npc.FunctionFactory;
|
||||
import io.github.znetworkw.znpcservers.npc.ItemSlot;
|
||||
import io.github.znetworkw.znpcservers.npc.NPC;
|
||||
import io.github.znetworkw.znpcservers.npc.NPCType;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import io.github.znetworkw.znpcservers.utility.ReflectionUtils;
|
||||
import io.github.znetworkw.znpcservers.utility.Utils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public interface NMS {
|
||||
int version();
|
||||
|
@ -20,41 +17,11 @@ public interface NMS {
|
|||
@PacketValue(keyName = "playerPacket")
|
||||
Object createPlayer(Object paramObject, GameProfile paramGameProfile) throws ReflectiveOperationException;
|
||||
|
||||
@PacketValue(keyName = "spawnPacket")
|
||||
Object createSpawnPacket(Object paramObject, boolean paramBoolean) throws ReflectiveOperationException;
|
||||
|
||||
Object createEntityEquipmentPacket(int paramInt, ItemSlot paramItemSlot, ItemStack paramItemStack) throws ReflectiveOperationException;
|
||||
|
||||
Object createMetadataPacket(int paramInt, Object paramObject) throws ReflectiveOperationException;
|
||||
|
||||
@PacketValue(keyName = "hologramSpawnPacket", valueType = ValueType.ARGUMENTS)
|
||||
Object createArmorStandSpawnPacket(Object paramObject) throws ReflectiveOperationException;
|
||||
|
||||
@SuppressWarnings("SuspiciousTernaryOperatorInVarargsCall")
|
||||
@PacketValue(keyName = "destroyPacket", valueType = ValueType.ARGUMENTS)
|
||||
default Object createEntityDestroyPacket(int entityId) throws ReflectiveOperationException {
|
||||
return Reflections.PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR.get().newInstance(Reflections.PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR.get().getParameterTypes()[0].isArray() ? new int[] {entityId} : entityId);
|
||||
}
|
||||
|
||||
@PacketValue(keyName = "enumSlot", valueType = ValueType.ARGUMENTS)
|
||||
default Object getItemSlot(int slot) {
|
||||
return Reflections.ENUM_ITEM_SLOT.getEnumConstants()[slot];
|
||||
}
|
||||
|
||||
@PacketValue(keyName = "removeTab")
|
||||
default Object createTabRemovePacket(Object nmsEntity) throws ReflectiveOperationException {
|
||||
try {
|
||||
return Reflections.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.get().newInstance(Reflections.REMOVE_PLAYER_FIELD.get(), Collections.singletonList(nmsEntity));
|
||||
} catch (Throwable throwable) {
|
||||
boolean useOldMethod = (Reflections.PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS != null);
|
||||
if (useOldMethod) return Reflections.PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CONSTRUCTOR.get().newInstance(Collections.singletonList(Reflections.GET_UNIQUE_ID_METHOD.get().invoke(nmsEntity)));
|
||||
return Reflections.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.get().newInstance(Reflections.REMOVE_PLAYER_FIELD.get(), nmsEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@PacketValue(keyName = "equipPackets")
|
||||
ImmutableList<Object> createEquipmentPacket(NPC paramNPC) throws ReflectiveOperationException;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@PacketValue(keyName = "scoreboardPackets")
|
||||
default ImmutableList<Object> updateScoreboard(NPC npc) throws ReflectiveOperationException {
|
||||
|
|
|
@ -6,7 +6,7 @@ import io.github.znetworkw.znpcservers.utility.Utils;
|
|||
import java.util.Comparator;
|
||||
|
||||
public final class NMSFactory {
|
||||
public static final ImmutableSet<NMS> ALL = ImmutableSet.of(new NMSV8(), new NMSV9(), new NMSV16(), new NMSV17(), new NMSV18(), new NMSV19());
|
||||
public static final ImmutableSet<NMS> ALL = ImmutableSet.of(new NMSV8(), new NMSV9(), new NMSV17(), new NMSV18(), new NMSV19());
|
||||
|
||||
public static final NMS NMS_FOR_CURRENT_VERSION = findPacketForVersion(Utils.BUKKIT_VERSION);
|
||||
|
||||
|
@ -14,6 +14,6 @@ public final class NMSFactory {
|
|||
return ALL.stream()
|
||||
.filter(NMS -> (version >= NMS.version()))
|
||||
.max(Comparator.comparing(NMS::version))
|
||||
.orElseThrow(() -> new IllegalArgumentException("No packet instance found for version: " + version));
|
||||
.orElseThrow(() -> new IllegalArgumentException("No NMS instance found for version: " + version));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package io.github.znetworkw.znpcservers.nms;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import io.github.znetworkw.znpcservers.npc.ItemSlot;
|
||||
import io.github.znetworkw.znpcservers.npc.NPC;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NMSV16 extends NMSV9 {
|
||||
public int version() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
public ImmutableList<Object> createEquipmentPacket(NPC npc) throws ReflectiveOperationException {
|
||||
List<Pair<?, ?>> pairs = Lists.newArrayListWithCapacity((ItemSlot.values()).length);
|
||||
for (Map.Entry<ItemSlot, ItemStack> entry : npc.getNpcPojo().getNpcEquip().entrySet())
|
||||
pairs.add(new Pair<>(getItemSlot(entry
|
||||
.getKey().getSlot()),
|
||||
createEntityEquipmentPacket(npc.getEntityID(), entry.getKey(), entry.getValue())));
|
||||
return ImmutableList.of(Reflections.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_V1.get().newInstance(npc.getEntityID(), pairs));
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import io.github.znetworkw.znpcservers.npc.NPC;
|
|||
import io.github.znetworkw.znpcservers.utility.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class NMSV17 extends NMSV16 {
|
||||
public class NMSV17 extends NMSV9 {
|
||||
public int version() {
|
||||
return 17;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package io.github.znetworkw.znpcservers.nms;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import io.github.znetworkw.znpcservers.npc.ItemSlot;
|
||||
import io.github.znetworkw.znpcservers.npc.NPC;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import io.github.znetworkw.znpcservers.utility.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Map;
|
||||
|
||||
public class NMSV8 implements NMS {
|
||||
public int version() {
|
||||
|
@ -23,15 +19,6 @@ public class NMSV8 implements NMS {
|
|||
.get().invoke(Bukkit.getServer()), nmsWorld, gameProfile, constructor.newInstance(nmsWorld));
|
||||
}
|
||||
|
||||
public Object createSpawnPacket(Object nmsEntity, boolean isPlayer) throws ReflectiveOperationException {
|
||||
return isPlayer ? Reflections.PACKET_PLAY_OUT_NAMED_ENTITY_CONSTRUCTOR.get().newInstance(nmsEntity) : Reflections.PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR.get().newInstance(nmsEntity);
|
||||
}
|
||||
|
||||
public Object createEntityEquipmentPacket(int entityId, ItemSlot itemSlot, ItemStack itemStack) throws ReflectiveOperationException {
|
||||
return Reflections.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD.get().newInstance(entityId,
|
||||
itemSlot.getSlotOld(), Reflections.AS_NMS_COPY_METHOD.get().invoke(Reflections.CRAFT_ITEM_STACK_CLASS, itemStack));
|
||||
}
|
||||
|
||||
public Object createMetadataPacket(int entityId, Object nmsEntity) throws ReflectiveOperationException {
|
||||
Object dataWatcher = Reflections.GET_DATA_WATCHER_METHOD.get().invoke(nmsEntity);
|
||||
try {
|
||||
|
@ -45,15 +32,6 @@ public class NMSV8 implements NMS {
|
|||
return Reflections.PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR.get().newInstance(armorStand);
|
||||
}
|
||||
|
||||
public ImmutableList<Object> createEquipmentPacket(NPC npc) throws ReflectiveOperationException {
|
||||
ImmutableList.Builder<Object> builder = ImmutableList.builder();
|
||||
for (Map.Entry<ItemSlot, ItemStack> stackEntry : npc.getNpcPojo().getNpcEquip().entrySet()) {
|
||||
builder.add(Reflections.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD.get().newInstance(npc.getEntityID(), stackEntry.getKey().getSlotOld(),
|
||||
createEntityEquipmentPacket(npc.getEntityID(), stackEntry.getKey(), stackEntry.getValue())));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void updateGlow(NPC npc, Object packet) throws ReflectiveOperationException {
|
||||
throw new IllegalStateException("Glow color is not supported for 1.8 version.");
|
||||
}
|
||||
|
|
|
@ -1,33 +1,14 @@
|
|||
package io.github.znetworkw.znpcservers.nms;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import io.github.znetworkw.znpcservers.npc.ItemSlot;
|
||||
import io.github.znetworkw.znpcservers.npc.NPC;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import io.github.znetworkw.znpcservers.utility.Utils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class NMSV9 extends NMSV8 {
|
||||
public int version() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
public Object createEntityEquipmentPacket(int entityId, ItemSlot itemSlot, ItemStack itemStack) throws ReflectiveOperationException {
|
||||
return Reflections.AS_NMS_COPY_METHOD.get().invoke(Reflections.CRAFT_ITEM_STACK_CLASS, itemStack);
|
||||
}
|
||||
|
||||
public ImmutableList<Object> createEquipmentPacket(NPC npc) throws ReflectiveOperationException {
|
||||
ImmutableList.Builder<Object> builder = ImmutableList.builder();
|
||||
for (Map.Entry<ItemSlot, ItemStack> stackEntry : npc.getNpcPojo().getNpcEquip().entrySet()) {
|
||||
builder.add(Reflections.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_NEWEST_OLD.get().newInstance(npc.getEntityID(),
|
||||
getItemSlot(stackEntry.getKey().getSlot()),
|
||||
createEntityEquipmentPacket(npc.getEntityID(), stackEntry.getKey(), stackEntry.getValue())));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void updateGlow(NPC npc, Object packet) throws ReflectiveOperationException {
|
||||
Object enumChatString = Reflections.ENUM_CHAT_TO_STRING_METHOD.get().invoke(npc.getGlowColor());
|
||||
if (Utils.BUKKIT_VERSION > 12) {
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package io.github.znetworkw.znpcservers.npc;
|
||||
|
||||
public enum ItemSlot {
|
||||
HELMET(5),
|
||||
CHESTPLATE(4),
|
||||
LEGGINGS(3),
|
||||
BOOTS(2),
|
||||
OFFHAND(1),
|
||||
HAND(0);
|
||||
|
||||
private final int slot;
|
||||
|
||||
private final int slotOld;
|
||||
|
||||
ItemSlot(int slot) {
|
||||
this.slot = slot;
|
||||
this.slotOld = (slot == 0) ? 0 : (slot - 1);
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
public int getSlotOld() {
|
||||
return this.slotOld;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,13 @@
|
|||
package io.github.znetworkw.znpcservers.npc;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.protocol.player.Equipment;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.*;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
||||
import io.github.znetworkw.znpcservers.UnexpectedCallException;
|
||||
import io.github.znetworkw.znpcservers.hologram.Hologram;
|
||||
import io.github.znetworkw.znpcservers.nms.PacketCache;
|
||||
|
@ -14,6 +18,7 @@ import io.github.znetworkw.znpcservers.utility.Utils;
|
|||
import io.github.znetworkw.znpcservers.utility.location.ZLocation;
|
||||
import lol.pyr.znpcsplus.ZNPCsPlus;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -211,19 +216,31 @@ public class NPC {
|
|||
ImmutableList<Object> scoreboardPackets = this.packets.getNms().updateScoreboard(this);
|
||||
scoreboardPackets.forEach(p -> Utils.sendPackets(user, p));
|
||||
}
|
||||
|
||||
ZLocation location = npcPojo.getLocation();
|
||||
Player player = user.toPlayer();
|
||||
if (npcIsPlayer) {
|
||||
if (FunctionFactory.isTrue(this, "mirror")) updateProfile(user.getGameProfile().getProperties());
|
||||
Utils.sendPackets(user, this.tabConstructor, this.updateTabConstructor);
|
||||
ZNPCsPlus.SCHEDULER.runTask(() -> {
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSpawnPlayer(entityID,
|
||||
this.gameProfile.getId(), SpigotConversionUtil.fromBukkitLocation(location.toBukkitLocation())));
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityHeadLook(entityID, location.getYaw()));
|
||||
});
|
||||
}
|
||||
Utils.sendPackets(user, this.packets.getNms().createSpawnPacket(this.nmsEntity, npcIsPlayer));
|
||||
else PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSpawnEntity(entityID,
|
||||
Optional.of(uuid), SpigotConversionUtil.fromBukkitEntityType(((Entity) bukkitEntity).getType()),
|
||||
location.toVector3d(), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty()));
|
||||
|
||||
|
||||
if (FunctionFactory.isTrue(this, "holo")) this.hologram.spawn(user);
|
||||
updateMetadata(Collections.singleton(user));
|
||||
sendEquipPackets(user);
|
||||
lookAt(user, getLocation(), true);
|
||||
if (npcIsPlayer) {
|
||||
Object removeTabPacket = this.packets.getNms().createTabRemovePacket(this.nmsEntity);
|
||||
ZNPCsPlus.SCHEDULER.scheduleSyncDelayedTask(() -> Utils.sendPackets(user, removeTabPacket, this.updateTabConstructor), 60);
|
||||
}
|
||||
if (npcIsPlayer) ZNPCsPlus.SCHEDULER.scheduleSyncDelayedTask(() -> {
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerPlayerInfoRemove(gameProfile.getId()));
|
||||
Utils.sendPackets(user, this.updateTabConstructor);
|
||||
}, 60);
|
||||
} catch (ReflectiveOperationException operationException) {
|
||||
delete(user);
|
||||
throw new UnexpectedCallException(operationException);
|
||||
|
@ -237,13 +254,10 @@ public class NPC {
|
|||
}
|
||||
|
||||
private void handleDelete(ZUser user) {
|
||||
try {
|
||||
if (this.npcPojo.getNpcType() == NPCType.PLAYER) this.packets.getNms().createTabRemovePacket(this.nmsEntity);
|
||||
this.hologram.delete(user);
|
||||
Utils.sendPackets(user, this.packets.getNms().createEntityDestroyPacket(this.entityID));
|
||||
} catch (ReflectiveOperationException operationException) {
|
||||
throw new UnexpectedCallException(operationException);
|
||||
}
|
||||
Player player = user.toPlayer();
|
||||
this.hologram.delete(user);
|
||||
if (this.npcPojo.getNpcType() == NPCType.PLAYER) PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerPlayerInfoRemove(gameProfile.getId()));
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerDestroyEntities(this.entityID));
|
||||
}
|
||||
|
||||
public void lookAt(ZUser player, Location location, boolean rotation) {
|
||||
|
@ -289,12 +303,12 @@ public class NPC {
|
|||
|
||||
public void sendEquipPackets(ZUser zUser) {
|
||||
if (this.npcPojo.getNpcEquip().isEmpty()) return;
|
||||
try {
|
||||
ImmutableList<Object> equipPackets = this.packets.getNms().createEquipmentPacket(this);
|
||||
equipPackets.forEach(o -> Utils.sendPackets(zUser, o));
|
||||
} catch (ReflectiveOperationException operationException) {
|
||||
throw new UnexpectedCallException(operationException.getCause());
|
||||
}
|
||||
List<Equipment> equipment = npcPojo.getNpcEquip().entrySet().stream()
|
||||
.map(entry -> new Equipment(entry.getKey(), SpigotConversionUtil.fromBukkitItemStack(entry.getValue())))
|
||||
.toList();
|
||||
|
||||
if (Utils.versionNewer(16)) PacketEvents.getAPI().getPlayerManager().sendPacket(zUser.toPlayer(), new WrapperPlayServerEntityEquipment(entityID, equipment));
|
||||
else for (Equipment e : equipment) PacketEvents.getAPI().getPlayerManager().sendPacket(zUser.toPlayer(), new WrapperPlayServerEntityEquipment(entityID, List.of(e)));
|
||||
}
|
||||
|
||||
public void setPath(NPCPath.AbstractTypeWriter typeWriter) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.znetworkw.znpcservers.npc;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
|
||||
import io.github.znetworkw.znpcservers.npc.conversation.ConversationModel;
|
||||
import io.github.znetworkw.znpcservers.utility.location.ZLocation;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -20,7 +21,7 @@ public class NPCModel {
|
|||
private NPCType npcType;
|
||||
private List<String> hologramLines;
|
||||
private List<NPCAction> clickActions;
|
||||
private Map<ItemSlot, ItemStack> npcEquip;
|
||||
private Map<EquipmentSlot, ItemStack> npcEquip;
|
||||
private Map<String, Boolean> npcFunctions;
|
||||
private Map<String, String[]> customizationMap;
|
||||
|
||||
|
@ -190,15 +191,15 @@ public class NPCModel {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Map<ItemSlot, ItemStack> getNpcEquip() {
|
||||
public Map<EquipmentSlot, ItemStack> getNpcEquip() {
|
||||
return this.npcEquip;
|
||||
}
|
||||
|
||||
public void setNpcEquip(Map<ItemSlot, ItemStack> npcEquip) {
|
||||
public void setNpcEquip(Map<EquipmentSlot, ItemStack> npcEquip) {
|
||||
this.npcEquip = npcEquip;
|
||||
}
|
||||
|
||||
public NPCModel withNpcEquip(Map<ItemSlot, ItemStack> npcEquip) {
|
||||
public NPCModel withNpcEquip(Map<EquipmentSlot, ItemStack> npcEquip) {
|
||||
setNpcEquip(npcEquip);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import io.github.znetworkw.znpcservers.reflection.types.MethodReflection;
|
|||
import io.github.znetworkw.znpcservers.utility.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -361,16 +360,9 @@ public final class Reflections {
|
|||
public static final Class<?> ENUM_CHAT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.MINECRAFT)
|
||||
.withClassName("EnumChatFormat")).get();
|
||||
|
||||
public static final Class<?> ENUM_ITEM_SLOT = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
|
||||
.withClassName("EnumItemSlot")
|
||||
.setStrict(Utils.versionNewer(9))).get();
|
||||
|
||||
public static final Class<?> I_CHAT_BASE_COMPONENT = new ClassReflection(new ReflectionBuilder(ReflectionPackage.CHAT)
|
||||
.withClassName("IChatBaseComponent")).get();
|
||||
|
||||
public static final Class<?> ITEM_STACK_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ITEM)
|
||||
.withClassName("ItemStack")).get();
|
||||
|
||||
public static final Class<?> DATA_WATCHER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SYNCHER)
|
||||
.withClassName("DataWatcher")
|
||||
.setStrict(Utils.versionNewer(9))).get();
|
||||
|
@ -390,9 +382,6 @@ public final class Reflections {
|
|||
public static final Class<?> WORLD_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.WORLD_LEVEL)
|
||||
.withClassName("World")).get();
|
||||
|
||||
public static final Class<?> CRAFT_ITEM_STACK_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT)
|
||||
.withClassName("inventory.CraftItemStack")).get();
|
||||
|
||||
public static final Class<?> WORLD_SERVER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SERVER_LEVEL)
|
||||
.withClassName("WorldServer")).get();
|
||||
|
||||
|
@ -409,16 +398,9 @@ public final class Reflections {
|
|||
.withClassName("PacketPlayOutPlayerInfo")
|
||||
.withClassName("ClientboundPlayerInfoUpdatePacket")).get();
|
||||
|
||||
public static final Class<?> PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("ClientboundPlayerInfoRemovePacket")
|
||||
.setStrict(false)).get();
|
||||
|
||||
public static final Class<?> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutScoreboardTeam")).get();
|
||||
|
||||
public static final Class<?> PACKET_PLAY_OUT_ENTITY_DESTROY_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutEntityDestroy")).get();
|
||||
|
||||
public static final Class<?> SCOREBOARD_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.WORLD_SCORES)
|
||||
.withClassName("Scoreboard")).get();
|
||||
|
||||
|
@ -460,10 +442,6 @@ public final class Reflections {
|
|||
.withClassName(PACKET_PLAY_OUT_PLAYER_INFO_CLASS)
|
||||
.withParameterTypes(ENUM_PLAYER_INFO_CLASS, (Utils.BUKKIT_VERSION > 16) ? Collection.class : Iterable.class).withParameterTypes(ENUM_PLAYER_INFO_CLASS, ENTITY_PLAYER_CLASS));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName(PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS)
|
||||
.withParameterTypes(List.class));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_ENTITY_LOOK_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutEntity$PacketPlayOutEntityLook")
|
||||
.withParameterTypes(int.class, byte.class, byte.class, boolean.class));
|
||||
|
@ -485,14 +463,6 @@ public final class Reflections {
|
|||
.withClassName("PacketPlayOutEntityMetadata")
|
||||
.withParameterTypes(int.class, List.class));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_NAMED_ENTITY_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutNamedEntitySpawn")
|
||||
.withParameterTypes(ENTITY_HUMAN_CLASS));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName(PACKET_PLAY_OUT_ENTITY_DESTROY_CLASS)
|
||||
.withParameterTypes(int.class).withParameterTypes(int[].class));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutSpawnEntity")
|
||||
.withClassName("PacketPlayOutSpawnEntityLiving")
|
||||
|
@ -509,18 +479,6 @@ public final class Reflections {
|
|||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutEntityEquipment")
|
||||
.withParameterTypes(int.class, int.class, ITEM_STACK_CLASS));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_NEWEST_OLD = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutEntityEquipment")
|
||||
.withParameterTypes(int.class, ENUM_ITEM_SLOT, ITEM_STACK_CLASS));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_V1 = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutEntityEquipment")
|
||||
.withParameterTypes(int.class, List.class));
|
||||
|
||||
public static final ReflectionLazyLoader<Constructor<?>> I_CHAT_BASE_COMPONENT_A_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.CHAT)
|
||||
.withClassName("ChatComponentText")
|
||||
.withParameterTypes(String.class));
|
||||
|
@ -533,11 +491,6 @@ public final class Reflections {
|
|||
.withClassName(DATA_WATCHER_OBJECT)
|
||||
.withParameterTypes(int.class, DATA_WATCHER_SERIALIZER));
|
||||
|
||||
public static final ReflectionLazyLoader<Method> AS_NMS_COPY_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT)
|
||||
.withClassName("inventory.CraftItemStack")
|
||||
.withMethodName("asNMSCopy")
|
||||
.withParameterTypes(ItemStack.class));
|
||||
|
||||
public static final ReflectionLazyLoader<Method> GET_PROFILE_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
|
||||
.withClassName(ENTITY_HUMAN_CLASS)
|
||||
.withExpectResult(GameProfile.class));
|
||||
|
@ -676,11 +629,6 @@ public final class Reflections {
|
|||
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
|
||||
.withFieldName("d")).staticValueLoader();
|
||||
|
||||
public static final ReflectionLazyLoader<Object> REMOVE_PLAYER_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction")
|
||||
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
|
||||
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "e" : "REMOVE_PLAYER")).staticValueLoader();
|
||||
|
||||
public static final ReflectionLazyLoader<Object> DATA_WATCHER_REGISTER_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
|
||||
.withClassName(DATA_WATCHER_REGISTRY)
|
||||
.withFieldName("a")).staticValueLoader();
|
||||
|
|
|
@ -73,10 +73,7 @@ public final class Utils {
|
|||
|
||||
public static void sendPackets(ZUser user, Object... packets) {
|
||||
try {
|
||||
for (Object packet : packets) {
|
||||
if (packet != null)
|
||||
Reflections.SEND_PACKET_METHOD.get().invoke(user.getPlayerConnection(), packet);
|
||||
}
|
||||
for (Object packet : packets) if (packet != null) Reflections.SEND_PACKET_METHOD.get().invoke(user.getPlayerConnection(), packet);
|
||||
} catch (IllegalAccessException | java.lang.reflect.InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.znetworkw.znpcservers.utility.location;
|
||||
|
||||
import com.github.retrooper.packetevents.util.Vector3d;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.*;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -73,6 +74,10 @@ public class ZLocation {
|
|||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public Vector3d toVector3d() {
|
||||
return new Vector3d(x, y, z);
|
||||
}
|
||||
|
||||
private static final double _2PI = 2 * Math.PI;
|
||||
|
||||
public Location pointingTo(Location loc) {
|
||||
|
|
|
@ -60,7 +60,10 @@ public class ZNPCsPlus extends JavaPlugin {
|
|||
NPC find = NPC.find(id);
|
||||
if (find != null)
|
||||
return find;
|
||||
NPCModel pojo = (new NPCModel(id)).withHologramLines(Collections.singletonList(name)).withHologramHeight(npcType.getHoloHeight()).withLocation(new ZLocation(location)).withNpcType(npcType);
|
||||
NPCModel pojo = new NPCModel(id).withHologramLines(Collections.singletonList(name))
|
||||
.withHologramHeight(npcType.getHoloHeight())
|
||||
.withLocation(new ZLocation(location))
|
||||
.withNpcType(npcType);
|
||||
ConfigurationConstants.NPC_LIST.add(pojo);
|
||||
return new NPC(pojo, true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue