Welcome to Bukkit France

Inscrivez-vous maintenant pour profiter d'un accès total à tout le contenu offert par la meilleur communauté Bukkit française ! Une fois inscrit et connecté, vous pourrez contribuez à la communauté en postant vos propres sujets et questions ou en répondant à ceux existants. Vous pourrez aussi customiser votre profil, recevoir des points de réputations, communiquer avec les autres membres via le chat, et plus encore! 

  • Annonces

    • Pskyco

      Bukkit France passe sous Discord !   02/20/16

      Bukkit France est désormais passé sur Discord, au revoir donc notre vieux Teamspeak ! Téléchargez le client et venez nous rejoindre sur notre salon en suivant les instructions suivantes.
      M-à-j du 25/02/2017 : Désormais, seuls les comptes actifs sur le forum se verront donner l'accès au Discord, ce dernier n'est pas une plateforme d'aide de la même manière que le chat.

5 messages dans ce sujet

Version (serveur) : 1.12
API utilisée : Spigot
IDE utilisé : Eclipse
Explications du problème rencontré : Bonjour, alors voilà j'ai récupérer la classe de mon amis je connais le nms mais la je ne vois vraiment pas pourquoi ça ne marche pas alors je me tourne vers vous, alors voila les armorsStand ne spawn pas et je ne vois pas les équipement non plus du coup ce qui est logique
Recherches effectuées : /
Code d'erreur :
Code :

 

ReflectedArmorStand

Spoiler
package net.heroyn.heroynserverapi.nms.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;

import net.heroyn.heroynserverapi.nms.Reflection;
import net.heroyn.heroynserverapi.nms.player.NMSPlayer;
import net.heroyn.heroynserverapi.utils.CC;
import net.heroyn.heroynserverapi.utils.UtilMath;

@SuppressWarnings("unused")
public class ReflectedArmorStand
{
    private static Class<?> craftItemStackClass;
    private static Class<?> packetEquipClass;
    private static Class<?> packetTeleportClass;
    private static Class<?> packetRotationClass;
    private static Class<?> nmsWorldField;
    private static Class<?> packetSpawnEntityLivingClass;
    private static Class<?> entityArmorStandClass;
    private static Class<?> entityClass;
    private static Class<?> entityLivingClass;
    private static Class<?> itemStackClass;
    private static Class<?> enumItemSlotClass;
    private static Class<?> vector3fClass;
    private static Class<?> datawatcherClass;
    private static Class<?> nbtTagCompoundClass;
    private static Reflection.MethodInvoker getIdMethod;
    private static Reflection.MethodInvoker asNMSCopyMethod;
    private static Reflection.MethodInvoker getHandleWorldMethod;
    private static Reflection.MethodInvoker setPositionMethod;
    private static Reflection.MethodInvoker setCustomeNameMethod;
    private static Reflection.MethodInvoker setCustomeNameVisibleMethod;
    private static Reflection.MethodInvoker setInvisibleMethod;
    private static Reflection.MethodInvoker setSmallMethod;
    private static Reflection.MethodInvoker setHeadPoseMethod;
    private static Reflection.MethodInvoker setRightArmPosePoseMethod;
    private static Reflection.MethodInvoker setArmsMethod;
    private static Reflection.MethodInvoker setBasePlateMethod;
    private static Reflection.MethodInvoker setMarkerMethod;
    private static Reflection.MethodInvoker getBukkitEntityMethod;
    private static Reflection.MethodInvoker setEntityNBTTag;
    private static Reflection.MethodInvoker setArmorStandNBTTag;
    private static Reflection.MethodInvoker getEquipmentMethod;
    private static Reflection.ConstructorInvoker packetmetaConstructor;
    private static Reflection.ConstructorInvoker armorStandConstructor;
    private static Reflection.ConstructorInvoker packetEquipConstructor;
    private static Reflection.ConstructorInvoker packetSpawnConstructor;
    private static Reflection.ConstructorInvoker packetRotationContrustuctor;
    private static Reflection.ConstructorInvoker packetTeleportContrustuctor;
    private static Reflection.ConstructorInvoker vector3fConstructor;
    private static Reflection.FieldAccessor<?> IDPacketEquipField;
    private static Reflection.FieldAccessor<?> enumItemSlotPacketEquipField;
    private static Reflection.FieldAccessor<?> itemStackPacketEquipField;
    private static Reflection.FieldAccessor<?> datawatcherField;
    private Object packetSpawn;
    private Entity bukkitEntity;
    private List<Object> packetEquip;
    private Object packetRotation;
    private List<Object> packets;
    private int ID;
    private Location location;
    private String displayName;
    private boolean visible;
	private boolean hide;
    private boolean small;
    private boolean arms;
    private boolean marker;
    private boolean basePlate;
    private float yaw;
    private float pitch;
    private Object armorStand;
    
    static {
        ReflectedArmorStand.craftItemStackClass = Reflection.getClass("{obc}.inventory.CraftItemStack");
        ReflectedArmorStand.packetEquipClass = Reflection.getClass("{nms}.PacketPlayOutEntityEquipment");
        ReflectedArmorStand.packetTeleportClass = Reflection.getMinecraftClass("PacketPlayOutEntityTeleport");
        ReflectedArmorStand.packetRotationClass = Reflection.getMinecraftClass("PacketPlayOutEntity$PacketPlayOutEntityLook");
        ReflectedArmorStand.nmsWorldField = Reflection.getClass("{nms}.World");
        ReflectedArmorStand.packetSpawnEntityLivingClass = Reflection.getClass("{nms}.PacketPlayOutSpawnEntityLiving");
        ReflectedArmorStand.entityArmorStandClass = Reflection.getClass("{nms}.EntityArmorStand");
        ReflectedArmorStand.entityClass = Reflection.getClass("{nms}.Entity");
        ReflectedArmorStand.entityLivingClass = Reflection.getClass("{nms}.EntityLiving");
        ReflectedArmorStand.itemStackClass = Reflection.getMinecraftClass("ItemStack");
        ReflectedArmorStand.enumItemSlotClass = Reflection.getMinecraftClass("EnumItemSlot");
        ReflectedArmorStand.vector3fClass = Reflection.getMinecraftClass("Vector3f");
        ReflectedArmorStand.datawatcherClass = Reflection.getMinecraftClass("DataWatcher");
        ReflectedArmorStand.nbtTagCompoundClass = Reflection.getMinecraftClass("NBTTagCompound");
        ReflectedArmorStand.getIdMethod = Reflection.getMethod(ReflectedArmorStand.entityClass, "getId", (Class<?>[])new Class[0]);
        ReflectedArmorStand.asNMSCopyMethod = Reflection.getMethod(ReflectedArmorStand.craftItemStackClass, "asNMSCopy", ItemStack.class);
        ReflectedArmorStand.getHandleWorldMethod = Reflection.getMethod("{obc}.CraftWorld", "getHandle", (Class<?>[])new Class[0]);
        ReflectedArmorStand.setPositionMethod = Reflection.getMethod(ReflectedArmorStand.entityClass, "setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE);
        ReflectedArmorStand.setCustomeNameMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setCustomName", String.class);
        ReflectedArmorStand.setCustomeNameVisibleMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setCustomNameVisible", Boolean.TYPE);
        ReflectedArmorStand.setInvisibleMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setInvisible", Boolean.TYPE);
        ReflectedArmorStand.setSmallMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setSmall", Boolean.TYPE);
        ReflectedArmorStand.setHeadPoseMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setHeadPose", ReflectedArmorStand.vector3fClass);
        ReflectedArmorStand.setRightArmPosePoseMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setRightArmPose", ReflectedArmorStand.vector3fClass);
        ReflectedArmorStand.setArmsMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setArms", Boolean.TYPE);
        ReflectedArmorStand.setBasePlateMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setBasePlate", Boolean.TYPE);
        ReflectedArmorStand.setMarkerMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setMarker", Boolean.TYPE);
        ReflectedArmorStand.getBukkitEntityMethod = Reflection.getMethod(ReflectedArmorStand.entityClass, "getBukkitEntity", (Class<?>[])new Class[0]);
        ReflectedArmorStand.setEntityNBTTag = Reflection.getMethod(ReflectedArmorStand.entityClass, "f", ReflectedArmorStand.nbtTagCompoundClass);
        ReflectedArmorStand.setArmorStandNBTTag = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "a", ReflectedArmorStand.nbtTagCompoundClass);
        ReflectedArmorStand.getEquipmentMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "getEquipment", ReflectedArmorStand.enumItemSlotClass);
        ReflectedArmorStand.packetmetaConstructor = Reflection.getConstructor(Reflection.getMinecraftClass("PacketPlayOutEntityMetadata"), Integer.TYPE, ReflectedArmorStand.datawatcherClass, Boolean.TYPE);
        ReflectedArmorStand.armorStandConstructor = Reflection.getConstructor(ReflectedArmorStand.entityArmorStandClass, ReflectedArmorStand.nmsWorldField);
        ReflectedArmorStand.packetEquipConstructor = Reflection.getConstructor(ReflectedArmorStand.packetEquipClass, (Class<?>[])new Class[0]);
        ReflectedArmorStand.packetSpawnConstructor = Reflection.getConstructor(ReflectedArmorStand.packetSpawnEntityLivingClass, ReflectedArmorStand.entityLivingClass);
        ReflectedArmorStand.packetRotationContrustuctor = Reflection.getConstructor(ReflectedArmorStand.packetRotationClass, Integer.TYPE, Byte.TYPE, Byte.TYPE, Boolean.TYPE);
        ReflectedArmorStand.packetTeleportContrustuctor = Reflection.getConstructor(ReflectedArmorStand.packetTeleportClass, ReflectedArmorStand.entityClass);
        ReflectedArmorStand.vector3fConstructor = Reflection.getConstructor(ReflectedArmorStand.vector3fClass, Float.TYPE, Float.TYPE, Float.TYPE);
        ReflectedArmorStand.IDPacketEquipField = Reflection.getField(ReflectedArmorStand.packetEquipClass, (Class<?>)Integer.TYPE, 0);
        ReflectedArmorStand.enumItemSlotPacketEquipField = Reflection.getField(ReflectedArmorStand.packetEquipClass, ReflectedArmorStand.enumItemSlotClass, 0);
        ReflectedArmorStand.itemStackPacketEquipField = Reflection.getField(ReflectedArmorStand.packetEquipClass, ReflectedArmorStand.itemStackClass, 0);
        ReflectedArmorStand.datawatcherField = Reflection.getField(ReflectedArmorStand.entityClass, "datawatcher", ReflectedArmorStand.datawatcherClass);
    }
    
    public ReflectedArmorStand(final Location location) {
        this.packetEquip = new ArrayList<Object>();
        this.displayName = "";
        this.visible = true;
        this.hide = false;
        this.small = false;
        this.arms = false;
        this.marker = false;
        this.basePlate = false;
        this.yaw = 0.0f;
        this.pitch = 0.0f;
        this.location = location;
        this.armorStand = ReflectedArmorStand.armorStandConstructor.invoke(ReflectedArmorStand.getHandleWorldMethod.invoke(location.getWorld(), new Object[0]));
        ReflectedArmorStand.setPositionMethod.invoke(this.armorStand, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
        this.packetSpawn = ReflectedArmorStand.packetSpawnConstructor.invoke(this.armorStand);
        this.ID = (int)ReflectedArmorStand.getIdMethod.invoke(this.armorStand, new Object[0]);
        this.bukkitEntity = (Entity)ReflectedArmorStand.getBukkitEntityMethod.invoke(this.armorStand, new Object[0]);
    }
    
    public void updateName(final String s) {
        ReflectedArmorStand.setCustomeNameMethod.invoke(this.armorStand, CC.colored(s));
        NMSPlayer.sendPacket(ReflectedArmorStand.packetmetaConstructor.invoke(this.ID, ReflectedArmorStand.datawatcherField.get(this.armorStand), true));
    }
    
    public void updateName(final String s, final Player player) {
        ReflectedArmorStand.setCustomeNameMethod.invoke(this.armorStand, CC.colored(s));
        NMSPlayer.sendPacket(player, ReflectedArmorStand.packetmetaConstructor.invoke(this.ID, ReflectedArmorStand.datawatcherField.get(this.armorStand), true));
    }
    
    public void updateName(final String s, final List<UUID> list) {
        ReflectedArmorStand.setCustomeNameMethod.invoke(this.armorStand, s);
        NMSPlayer.sendPacketExclude(list, ReflectedArmorStand.packetmetaConstructor.invoke(this.ID, ReflectedArmorStand.datawatcherField.get(this.armorStand), true));
    }
    
    public ReflectedArmorStand setVisible(final boolean visible) {
        ReflectedArmorStand.setInvisibleMethod.invoke(this.armorStand, !visible);
        this.visible = visible;
        return this;
    }
    
    public ReflectedArmorStand setSmall(final boolean small) {
        ReflectedArmorStand.setSmallMethod.invoke(this.armorStand, small);
        this.small = small;
        return this;
    }
    
    public ReflectedArmorStand setBasePlate(final boolean b) {
        ReflectedArmorStand.setBasePlateMethod.invoke(this.armorStand, b);
        this.basePlate = b;
        return this;
    }
    
    public ReflectedArmorStand setHeadPose(final EulerAngle eulerAngle) {
        final EulerAngle nms = this.toNMS(eulerAngle);
        ReflectedArmorStand.setHeadPoseMethod.invoke(this.armorStand, ReflectedArmorStand.vector3fConstructor.invoke((float)nms.getX(), (float)nms.getY(), (float)nms.getZ()));
        return this;
    }
    
    public ReflectedArmorStand setRightArmPose(final EulerAngle eulerAngle) {
        final EulerAngle nms = this.toNMS(eulerAngle);
        ReflectedArmorStand.setRightArmPosePoseMethod.invoke(this.armorStand, ReflectedArmorStand.vector3fConstructor.invoke((float)nms.getX(), (float)nms.getY(), (float)nms.getZ()));
        return this;
    }
    
    public ReflectedArmorStand setRotation(final float yaw, final float pitch) {
        this.packetRotation = ReflectedArmorStand.packetRotationContrustuctor.invoke(this.ID, UtilMath.toPackedByte(yaw), UtilMath.toPackedByte(pitch), false);
        this.yaw = yaw;
        this.pitch = pitch;
        NMSPlayer.sendPacket(this.packetRotation);
        return this;
    }
    
    public ReflectedArmorStand setRotation(final Player player, final float yaw, final float pitch) {
        this.packetRotation = ReflectedArmorStand.packetRotationContrustuctor.invoke(this.ID, UtilMath.toPackedByte(yaw), UtilMath.toPackedByte(pitch), false);
        this.yaw = yaw;
        this.pitch = pitch;
        NMSPlayer.sendPacket(player, this.packetRotation);
        return this;
    }
    
    public void updateMetadata() {
        NMSPlayer.sendPacket(ReflectedArmorStand.packetmetaConstructor.invoke(this.ID, ReflectedArmorStand.datawatcherField.get(this.armorStand), true));
    }
    
    public ReflectedArmorStand cloneNBTTag(final Object o) {
        ReflectedArmorStand.setEntityNBTTag.invoke(this.armorStand, o);
        ReflectedArmorStand.setArmorStandNBTTag.invoke(this.armorStand, o);
        for (int i = 0; i <= 5; ++i) {
            final Object invoke = ReflectedArmorStand.packetEquipConstructor.invoke(new Object[0]);
            ReflectedArmorStand.IDPacketEquipField.set(invoke, this.ID);
            ReflectedArmorStand.enumItemSlotPacketEquipField.set(invoke, ReflectedArmorStand.enumItemSlotClass.getEnumConstants()[i]);
            ReflectedArmorStand.itemStackPacketEquipField.set(invoke, ReflectedArmorStand.getEquipmentMethod.invoke(this.armorStand, ReflectedArmorStand.enumItemSlotClass.getEnumConstants()[i]));
            this.packetEquip.add(invoke);
        }
        return this;
    }
    
    public ReflectedArmorStand setEquipment(final int n, final ItemStack itemStack) {
        final Object invoke = ReflectedArmorStand.packetEquipConstructor.invoke(new Object[0]);
        ReflectedArmorStand.IDPacketEquipField.set(invoke, this.ID);
        ReflectedArmorStand.enumItemSlotPacketEquipField.set(invoke, ReflectedArmorStand.enumItemSlotClass.getEnumConstants()[n]);
        ReflectedArmorStand.itemStackPacketEquipField.set(invoke, ReflectedArmorStand.asNMSCopyMethod.invoke(ReflectedArmorStand.craftItemStackClass, itemStack));
        this.packetEquip.add(invoke);
        NMSPlayer.sendPacket(invoke);
        return this;
    }
    
    public ReflectedArmorStand setDisplayName(final String displayName) {
        ReflectedArmorStand.setCustomeNameMethod.invoke(this.armorStand, displayName);
        ReflectedArmorStand.setCustomeNameVisibleMethod.invoke(this.armorStand, true);
        this.displayName = displayName;
        return this;
    }
    
    public ReflectedArmorStand setMarker(final boolean marker) {
        ReflectedArmorStand.setMarkerMethod.invoke(this.armorStand, marker);
        this.marker = marker;
        return this;
    }
    
    public ReflectedArmorStand setArms(final boolean arms) {
        ReflectedArmorStand.setArmsMethod.invoke(this.armorStand, arms);
        this.arms = arms;
        return this;
    }
    
    public void setLocation(final Location location) {
        this.location = location;
    }
    
    public int getID() {
        return this.ID;
    }
    
    public boolean isVisible() {
        return this.visible;
    }
    
    public boolean isSmall() {
        return this.small;
    }
    
    public void teleport(final Player player, final Location location) {
        ReflectedArmorStand.setPositionMethod.invoke(this.armorStand, location.getX(), location.getY(), location.getZ(), this.yaw, this.pitch);
        NMSPlayer.sendPacket(player, ReflectedArmorStand.packetTeleportContrustuctor.invoke(this.armorStand));
        this.location = location;
    }
    
    public void faketeleport(final Player player, final Location location) {
        ReflectedArmorStand.setPositionMethod.invoke(this.armorStand, location.getX(), location.getY(), location.getZ(), this.yaw, this.pitch);
        NMSPlayer.sendPacket(player, ReflectedArmorStand.packetTeleportContrustuctor.invoke(this.armorStand));
    }
    
    public void teleport(final Location location) {
        ReflectedArmorStand.setPositionMethod.invoke(this.armorStand, location.getX(), location.getY(), location.getZ(), this.yaw, this.pitch);
        NMSPlayer.sendPacket(ReflectedArmorStand.packetTeleportContrustuctor.invoke(this.armorStand));
        this.location = location;
    }
    
    public void hide() {
        NMSPlayer.destroyEntity(this.ID);
        this.hide = true;
    }
    
    public void hide(final Player player) {
        NMSPlayer.destroyEntity(player, this.ID);
        this.hide = true;
    }
    
    public void show(final Player player) {
        NMSPlayer.sendPacket(player, this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacket(player, o));
        this.hide = false;
    }
    
    public void show() {
        NMSPlayer.sendPacket(this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacket(o));
        this.hide = false;
    }
    
    public void remove() {
        NMSPlayer.destroyEntity(this.ID);
        if (this.packets != null) {
            NMSPlayer.getPacketsToSend().removeAll(this.packets);
        }
    }
    
    public ReflectedArmorStand spawnArmorStand() {
        NMSPlayer.sendPacketNearby(this.location, this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacketNearby(this.location, o));
        return this;
    }
    
    public ReflectedArmorStand spawnConstantArmorStand() {
        this.packets = NMSPlayer.sendConstantPacket(this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendConstantPacket(o));
        this.packets.addAll(this.packetEquip);
        return this;
    }
    
    public ReflectedArmorStand spawnArmorStand(final Player player) {
        NMSPlayer.sendPacket(player, this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacket(o));
        return this;
    }
    
    public ReflectedArmorStand spawnArmorStandExlude(final Player player) {
        NMSPlayer.sendPacketExclude(Bukkit.getOnlinePlayers(), player, this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacketExclude(Bukkit.getOnlinePlayers(), player, o));
        return this;
    }
    
    public Entity getBukkitEntity() {
        return this.bukkitEntity;
    }
    
    private EulerAngle toNMS(final EulerAngle eulerAngle) {
        return new EulerAngle((double)(float)Math.toDegrees(eulerAngle.getX()), (double)(float)Math.toDegrees(eulerAngle.getY()), (double)(float)Math.toDegrees(eulerAngle.getZ()));
    }
    
    public Location getLocation() {
        return this.location;
    }
    
    public String getDisplayName() {
        return this.displayName;
    }
    
    public float getYaw() {
        return this.yaw;
    }
}

 

 

Reflection:

Spoiler
package net.heroyn.heroynserverapi.nms;

import org.bukkit.*;
import java.util.*;
import java.lang.reflect.*;
import java.util.regex.*;

@SuppressWarnings({"unchecked","rawtypes"})
public final class Reflection
{
    private static String OBC_PREFIX;
    private static String NMS_PREFIX;
    private static String VERSION;
    private static Pattern MATCH_VARIABLE;
    
    static {
    	Reflection.OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName();
    	Reflection.NMS_PREFIX = Reflection.OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server");
    	Reflection.VERSION = Reflection.OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", "");
    	Reflection.MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}");
    }
    
    public static <T> FieldAccessor<T> getField(final Class<?> clazz, final String s, final Class<T> clazz2) {
        return getField(clazz, s, clazz2, 0);
    }
    
    public static <T> FieldAccessor<T> getField(final String s, final String s2, final Class<T> clazz) {
        return getField(getClass(s), s2, clazz, 0);
    }
    
    public static <T> FieldAccessor<T> getField(final Class<?> clazz, final Class<T> clazz2, final int n) {
        return getField(clazz, null, clazz2, n);
    }
    
    public static <T> FieldAccessor<T> getField(final String s, final Class<T> clazz, final int n) {
        return getField(getClass(s), clazz, n);
    }
    
    private static <T> FieldAccessor<T> getField(final Class<?> clazz, final String s, final Class<T> clazz2, int n) {
        Field[] declaredFields;
        for (int length = (declaredFields = clazz.getDeclaredFields()).length, i = 0; i < length; ++i) {
            final Field field = declaredFields[i];
            if ((s == null || field.getName().equals(s)) && clazz2.isAssignableFrom(field.getType()) && n-- <= 0) {
                field.setAccessible(true);
                return new FieldAccessor<T>() {
					@Override
                    public T get(final Object o) {
                        try {
                            return (T)field.get(o);
                        }
                        catch (IllegalAccessException ex) {
                            throw new RuntimeException("Cannot access reflection.", ex);
                        }
                    }
                    
                    @Override
                    public void set(final Object o, final Object o2) {
                        try {
                            field.set(o, o2);
                        }
                        catch (IllegalAccessException ex) {
                            throw new RuntimeException("Cannot access reflection.", ex);
                        }
                    }
                    
                    @Override
                    public boolean hasField(final Object o) {
                        return field.getDeclaringClass().isAssignableFrom(o.getClass());
                    }
                };
            }
        }
        if (clazz.getSuperclass() != null) {
            return (FieldAccessor<T>)getField(clazz.getSuperclass(), s, (Class<Object>)clazz2, n);
        }
        throw new IllegalArgumentException("Cannot find field with type " + clazz2);
    }
    
    public static MethodInvoker getMethod(final String s, final String s2, final Class<?>... array) {
        return getTypedMethod(getClass(s), s2, null, array);
    }
    
    public static MethodInvoker getMethod(final Class<?> clazz, final String s, final Class<?>... array) {
        return getTypedMethod(clazz, s, null, array);
    }
    
    public static MethodInvoker getTypedMethod(final Class<?> clazz, final String s, final Class<?> clazz2, final Class<?>... array) {
        Method[] declaredMethods;
        for (int length = (declaredMethods = clazz.getDeclaredMethods()).length, i = 0; i < length; ++i) {
            final Method method = declaredMethods[i];
            if ((s == null || method.getName().equals(s)) && (clazz2 == null || method.getReturnType().equals(clazz2)) && Arrays.equals(method.getParameterTypes(), array)) {
                method.setAccessible(true);
                return new MethodInvoker() {
                    @Override
                    public Object invoke(final Object o, final Object... array) {
                        try {
                            return method.invoke(o, array);
                        }
                        catch (Exception ex) {
                            throw new RuntimeException("Cannot invoke method " + method, ex);
                        }
                    }
                };
            }
        }
        if (clazz.getSuperclass() != null) {
            return getMethod(clazz.getSuperclass(), s, array);
        }
        throw new IllegalStateException(String.format("Unable to find method %s (%s).", s, Arrays.asList(array)));
    }
    
    public static ConstructorInvoker getConstructor(final String s, final Class<?>... array) {
        return getConstructor(getClass(s), array);
    }
    
    public static ConstructorInvoker getConstructor(final Class<?> clazz, final Class<?>... array) {
		Constructor[] declaredConstructors;
        for (int length = (declaredConstructors = clazz.getDeclaredConstructors()).length, i = 0; i < length; ++i) {
            final Constructor constructor = declaredConstructors[i];
            if (Arrays.equals(constructor.getParameterTypes(), array)) {
                constructor.setAccessible(true);
                return new ConstructorInvoker() {
                    @Override
                    public Object invoke(final Object... array) {
                        try {
                            return constructor.newInstance(array);
                        }
                        catch (Exception ex) {
                            throw new RuntimeException("Cannot invoke constructor " + constructor, ex);
                        }
                    }
                };
            }
        }
        throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(array)));
    }
    
    public static Class<Object> getUntypedClass(final String s) {
        return (Class<Object>)getClass(s);
    }
    
    public static Class<?> getClass(final String s) {
        return getCanonicalClass(expandVariables(s));
    }
    
    public static Class<?> getMinecraftClass(final String s) {
        return getCanonicalClass(String.valueOf(Reflection.NMS_PREFIX) + "." + s);
    }
    
    public static Class<?> getCraftBukkitClass(final String s) {
        return getCanonicalClass(String.valueOf(Reflection.OBC_PREFIX) + "." + s);
    }
    
    private static Class<?> getCanonicalClass(final String s) {
        try {
            return Class.forName(s);
        }
        catch (ClassNotFoundException ex) {
            throw new IllegalArgumentException("Cannot find " + s, ex);
        }
    }
    
    private static String expandVariables(final String s) {
        final StringBuffer sb = new StringBuffer();
        final Matcher matcher = Reflection.MATCH_VARIABLE.matcher(s);
        while (matcher.find()) {
            final String group = matcher.group(1);
            String s2;
            if ("nms".equalsIgnoreCase(group)) {
                s2 = Reflection.NMS_PREFIX;
            }
            else if ("obc".equalsIgnoreCase(group)) {
                s2 = Reflection.OBC_PREFIX;
            }
            else {
                if (!"version".equalsIgnoreCase(group)) {
                    throw new IllegalArgumentException("Unknown variable: " + group);
                }
                s2 = Reflection.VERSION;
            }
            if (s2.length() > 0 && matcher.end() < s.length() && s.charAt(matcher.end()) != '.') {
                s2 = String.valueOf(s2) + ".";
            }
            matcher.appendReplacement(sb, Matcher.quoteReplacement(s2));
        }
        matcher.appendTail(sb);
        return sb.toString();
    }
    
    public interface ConstructorInvoker
    {
        Object invoke(final Object... p0);
    }
    
    public interface FieldAccessor<T>
    {
        T get(final Object p0);
        
        void set(final Object p0, final Object p1);
        
        boolean hasField(final Object p0);
    }
    
    public interface MethodInvoker
    {
        Object invoke(final Object p0, final Object... p1);
    }
}

 

 

Partager ce message


Lien à poster
Partager sur d’autres sites
Il y a 3 heures, Foulehistory a dit :

Version (serveur) : 1.12
API utilisée : Spigot
IDE utilisé : Eclipse
Explications du problème rencontré : Bonjour, alors voilà j'ai récupérer la classe de mon amis je connais le nms mais la je ne vois vraiment pas pourquoi ça ne marche pas alors je me tourne vers vous, alors voila les armorsStand ne spawn pas et je ne vois pas les équipement non plus du coup ce qui est logique
Recherches effectuées : /
Code d'erreur :
Code :

 

ReflectedArmorStand

  Afficher le contenu masqué

package net.heroyn.heroynserverapi.nms.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;

import net.heroyn.heroynserverapi.nms.Reflection;
import net.heroyn.heroynserverapi.nms.player.NMSPlayer;
import net.heroyn.heroynserverapi.utils.CC;
import net.heroyn.heroynserverapi.utils.UtilMath;

@SuppressWarnings("unused")
public class ReflectedArmorStand
{
    private static Class<?> craftItemStackClass;
    private static Class<?> packetEquipClass;
    private static Class<?> packetTeleportClass;
    private static Class<?> packetRotationClass;
    private static Class<?> nmsWorldField;
    private static Class<?> packetSpawnEntityLivingClass;
    private static Class<?> entityArmorStandClass;
    private static Class<?> entityClass;
    private static Class<?> entityLivingClass;
    private static Class<?> itemStackClass;
    private static Class<?> enumItemSlotClass;
    private static Class<?> vector3fClass;
    private static Class<?> datawatcherClass;
    private static Class<?> nbtTagCompoundClass;
    private static Reflection.MethodInvoker getIdMethod;
    private static Reflection.MethodInvoker asNMSCopyMethod;
    private static Reflection.MethodInvoker getHandleWorldMethod;
    private static Reflection.MethodInvoker setPositionMethod;
    private static Reflection.MethodInvoker setCustomeNameMethod;
    private static Reflection.MethodInvoker setCustomeNameVisibleMethod;
    private static Reflection.MethodInvoker setInvisibleMethod;
    private static Reflection.MethodInvoker setSmallMethod;
    private static Reflection.MethodInvoker setHeadPoseMethod;
    private static Reflection.MethodInvoker setRightArmPosePoseMethod;
    private static Reflection.MethodInvoker setArmsMethod;
    private static Reflection.MethodInvoker setBasePlateMethod;
    private static Reflection.MethodInvoker setMarkerMethod;
    private static Reflection.MethodInvoker getBukkitEntityMethod;
    private static Reflection.MethodInvoker setEntityNBTTag;
    private static Reflection.MethodInvoker setArmorStandNBTTag;
    private static Reflection.MethodInvoker getEquipmentMethod;
    private static Reflection.ConstructorInvoker packetmetaConstructor;
    private static Reflection.ConstructorInvoker armorStandConstructor;
    private static Reflection.ConstructorInvoker packetEquipConstructor;
    private static Reflection.ConstructorInvoker packetSpawnConstructor;
    private static Reflection.ConstructorInvoker packetRotationContrustuctor;
    private static Reflection.ConstructorInvoker packetTeleportContrustuctor;
    private static Reflection.ConstructorInvoker vector3fConstructor;
    private static Reflection.FieldAccessor<?> IDPacketEquipField;
    private static Reflection.FieldAccessor<?> enumItemSlotPacketEquipField;
    private static Reflection.FieldAccessor<?> itemStackPacketEquipField;
    private static Reflection.FieldAccessor<?> datawatcherField;
    private Object packetSpawn;
    private Entity bukkitEntity;
    private List<Object> packetEquip;
    private Object packetRotation;
    private List<Object> packets;
    private int ID;
    private Location location;
    private String displayName;
    private boolean visible;
	private boolean hide;
    private boolean small;
    private boolean arms;
    private boolean marker;
    private boolean basePlate;
    private float yaw;
    private float pitch;
    private Object armorStand;
    
    static {
        ReflectedArmorStand.craftItemStackClass = Reflection.getClass("{obc}.inventory.CraftItemStack");
        ReflectedArmorStand.packetEquipClass = Reflection.getClass("{nms}.PacketPlayOutEntityEquipment");
        ReflectedArmorStand.packetTeleportClass = Reflection.getMinecraftClass("PacketPlayOutEntityTeleport");
        ReflectedArmorStand.packetRotationClass = Reflection.getMinecraftClass("PacketPlayOutEntity$PacketPlayOutEntityLook");
        ReflectedArmorStand.nmsWorldField = Reflection.getClass("{nms}.World");
        ReflectedArmorStand.packetSpawnEntityLivingClass = Reflection.getClass("{nms}.PacketPlayOutSpawnEntityLiving");
        ReflectedArmorStand.entityArmorStandClass = Reflection.getClass("{nms}.EntityArmorStand");
        ReflectedArmorStand.entityClass = Reflection.getClass("{nms}.Entity");
        ReflectedArmorStand.entityLivingClass = Reflection.getClass("{nms}.EntityLiving");
        ReflectedArmorStand.itemStackClass = Reflection.getMinecraftClass("ItemStack");
        ReflectedArmorStand.enumItemSlotClass = Reflection.getMinecraftClass("EnumItemSlot");
        ReflectedArmorStand.vector3fClass = Reflection.getMinecraftClass("Vector3f");
        ReflectedArmorStand.datawatcherClass = Reflection.getMinecraftClass("DataWatcher");
        ReflectedArmorStand.nbtTagCompoundClass = Reflection.getMinecraftClass("NBTTagCompound");
        ReflectedArmorStand.getIdMethod = Reflection.getMethod(ReflectedArmorStand.entityClass, "getId", (Class<?>[])new Class[0]);
        ReflectedArmorStand.asNMSCopyMethod = Reflection.getMethod(ReflectedArmorStand.craftItemStackClass, "asNMSCopy", ItemStack.class);
        ReflectedArmorStand.getHandleWorldMethod = Reflection.getMethod("{obc}.CraftWorld", "getHandle", (Class<?>[])new Class[0]);
        ReflectedArmorStand.setPositionMethod = Reflection.getMethod(ReflectedArmorStand.entityClass, "setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE);
        ReflectedArmorStand.setCustomeNameMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setCustomName", String.class);
        ReflectedArmorStand.setCustomeNameVisibleMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setCustomNameVisible", Boolean.TYPE);
        ReflectedArmorStand.setInvisibleMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setInvisible", Boolean.TYPE);
        ReflectedArmorStand.setSmallMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setSmall", Boolean.TYPE);
        ReflectedArmorStand.setHeadPoseMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setHeadPose", ReflectedArmorStand.vector3fClass);
        ReflectedArmorStand.setRightArmPosePoseMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setRightArmPose", ReflectedArmorStand.vector3fClass);
        ReflectedArmorStand.setArmsMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setArms", Boolean.TYPE);
        ReflectedArmorStand.setBasePlateMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setBasePlate", Boolean.TYPE);
        ReflectedArmorStand.setMarkerMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "setMarker", Boolean.TYPE);
        ReflectedArmorStand.getBukkitEntityMethod = Reflection.getMethod(ReflectedArmorStand.entityClass, "getBukkitEntity", (Class<?>[])new Class[0]);
        ReflectedArmorStand.setEntityNBTTag = Reflection.getMethod(ReflectedArmorStand.entityClass, "f", ReflectedArmorStand.nbtTagCompoundClass);
        ReflectedArmorStand.setArmorStandNBTTag = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "a", ReflectedArmorStand.nbtTagCompoundClass);
        ReflectedArmorStand.getEquipmentMethod = Reflection.getMethod(ReflectedArmorStand.entityArmorStandClass, "getEquipment", ReflectedArmorStand.enumItemSlotClass);
        ReflectedArmorStand.packetmetaConstructor = Reflection.getConstructor(Reflection.getMinecraftClass("PacketPlayOutEntityMetadata"), Integer.TYPE, ReflectedArmorStand.datawatcherClass, Boolean.TYPE);
        ReflectedArmorStand.armorStandConstructor = Reflection.getConstructor(ReflectedArmorStand.entityArmorStandClass, ReflectedArmorStand.nmsWorldField);
        ReflectedArmorStand.packetEquipConstructor = Reflection.getConstructor(ReflectedArmorStand.packetEquipClass, (Class<?>[])new Class[0]);
        ReflectedArmorStand.packetSpawnConstructor = Reflection.getConstructor(ReflectedArmorStand.packetSpawnEntityLivingClass, ReflectedArmorStand.entityLivingClass);
        ReflectedArmorStand.packetRotationContrustuctor = Reflection.getConstructor(ReflectedArmorStand.packetRotationClass, Integer.TYPE, Byte.TYPE, Byte.TYPE, Boolean.TYPE);
        ReflectedArmorStand.packetTeleportContrustuctor = Reflection.getConstructor(ReflectedArmorStand.packetTeleportClass, ReflectedArmorStand.entityClass);
        ReflectedArmorStand.vector3fConstructor = Reflection.getConstructor(ReflectedArmorStand.vector3fClass, Float.TYPE, Float.TYPE, Float.TYPE);
        ReflectedArmorStand.IDPacketEquipField = Reflection.getField(ReflectedArmorStand.packetEquipClass, (Class<?>)Integer.TYPE, 0);
        ReflectedArmorStand.enumItemSlotPacketEquipField = Reflection.getField(ReflectedArmorStand.packetEquipClass, ReflectedArmorStand.enumItemSlotClass, 0);
        ReflectedArmorStand.itemStackPacketEquipField = Reflection.getField(ReflectedArmorStand.packetEquipClass, ReflectedArmorStand.itemStackClass, 0);
        ReflectedArmorStand.datawatcherField = Reflection.getField(ReflectedArmorStand.entityClass, "datawatcher", ReflectedArmorStand.datawatcherClass);
    }
    
    public ReflectedArmorStand(final Location location) {
        this.packetEquip = new ArrayList<Object>();
        this.displayName = "";
        this.visible = true;
        this.hide = false;
        this.small = false;
        this.arms = false;
        this.marker = false;
        this.basePlate = false;
        this.yaw = 0.0f;
        this.pitch = 0.0f;
        this.location = location;
        this.armorStand = ReflectedArmorStand.armorStandConstructor.invoke(ReflectedArmorStand.getHandleWorldMethod.invoke(location.getWorld(), new Object[0]));
        ReflectedArmorStand.setPositionMethod.invoke(this.armorStand, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
        this.packetSpawn = ReflectedArmorStand.packetSpawnConstructor.invoke(this.armorStand);
        this.ID = (int)ReflectedArmorStand.getIdMethod.invoke(this.armorStand, new Object[0]);
        this.bukkitEntity = (Entity)ReflectedArmorStand.getBukkitEntityMethod.invoke(this.armorStand, new Object[0]);
    }
    
    public void updateName(final String s) {
        ReflectedArmorStand.setCustomeNameMethod.invoke(this.armorStand, CC.colored(s));
        NMSPlayer.sendPacket(ReflectedArmorStand.packetmetaConstructor.invoke(this.ID, ReflectedArmorStand.datawatcherField.get(this.armorStand), true));
    }
    
    public void updateName(final String s, final Player player) {
        ReflectedArmorStand.setCustomeNameMethod.invoke(this.armorStand, CC.colored(s));
        NMSPlayer.sendPacket(player, ReflectedArmorStand.packetmetaConstructor.invoke(this.ID, ReflectedArmorStand.datawatcherField.get(this.armorStand), true));
    }
    
    public void updateName(final String s, final List<UUID> list) {
        ReflectedArmorStand.setCustomeNameMethod.invoke(this.armorStand, s);
        NMSPlayer.sendPacketExclude(list, ReflectedArmorStand.packetmetaConstructor.invoke(this.ID, ReflectedArmorStand.datawatcherField.get(this.armorStand), true));
    }
    
    public ReflectedArmorStand setVisible(final boolean visible) {
        ReflectedArmorStand.setInvisibleMethod.invoke(this.armorStand, !visible);
        this.visible = visible;
        return this;
    }
    
    public ReflectedArmorStand setSmall(final boolean small) {
        ReflectedArmorStand.setSmallMethod.invoke(this.armorStand, small);
        this.small = small;
        return this;
    }
    
    public ReflectedArmorStand setBasePlate(final boolean b) {
        ReflectedArmorStand.setBasePlateMethod.invoke(this.armorStand, b);
        this.basePlate = b;
        return this;
    }
    
    public ReflectedArmorStand setHeadPose(final EulerAngle eulerAngle) {
        final EulerAngle nms = this.toNMS(eulerAngle);
        ReflectedArmorStand.setHeadPoseMethod.invoke(this.armorStand, ReflectedArmorStand.vector3fConstructor.invoke((float)nms.getX(), (float)nms.getY(), (float)nms.getZ()));
        return this;
    }
    
    public ReflectedArmorStand setRightArmPose(final EulerAngle eulerAngle) {
        final EulerAngle nms = this.toNMS(eulerAngle);
        ReflectedArmorStand.setRightArmPosePoseMethod.invoke(this.armorStand, ReflectedArmorStand.vector3fConstructor.invoke((float)nms.getX(), (float)nms.getY(), (float)nms.getZ()));
        return this;
    }
    
    public ReflectedArmorStand setRotation(final float yaw, final float pitch) {
        this.packetRotation = ReflectedArmorStand.packetRotationContrustuctor.invoke(this.ID, UtilMath.toPackedByte(yaw), UtilMath.toPackedByte(pitch), false);
        this.yaw = yaw;
        this.pitch = pitch;
        NMSPlayer.sendPacket(this.packetRotation);
        return this;
    }
    
    public ReflectedArmorStand setRotation(final Player player, final float yaw, final float pitch) {
        this.packetRotation = ReflectedArmorStand.packetRotationContrustuctor.invoke(this.ID, UtilMath.toPackedByte(yaw), UtilMath.toPackedByte(pitch), false);
        this.yaw = yaw;
        this.pitch = pitch;
        NMSPlayer.sendPacket(player, this.packetRotation);
        return this;
    }
    
    public void updateMetadata() {
        NMSPlayer.sendPacket(ReflectedArmorStand.packetmetaConstructor.invoke(this.ID, ReflectedArmorStand.datawatcherField.get(this.armorStand), true));
    }
    
    public ReflectedArmorStand cloneNBTTag(final Object o) {
        ReflectedArmorStand.setEntityNBTTag.invoke(this.armorStand, o);
        ReflectedArmorStand.setArmorStandNBTTag.invoke(this.armorStand, o);
        for (int i = 0; i <= 5; ++i) {
            final Object invoke = ReflectedArmorStand.packetEquipConstructor.invoke(new Object[0]);
            ReflectedArmorStand.IDPacketEquipField.set(invoke, this.ID);
            ReflectedArmorStand.enumItemSlotPacketEquipField.set(invoke, ReflectedArmorStand.enumItemSlotClass.getEnumConstants()[i]);
            ReflectedArmorStand.itemStackPacketEquipField.set(invoke, ReflectedArmorStand.getEquipmentMethod.invoke(this.armorStand, ReflectedArmorStand.enumItemSlotClass.getEnumConstants()[i]));
            this.packetEquip.add(invoke);
        }
        return this;
    }
    
    public ReflectedArmorStand setEquipment(final int n, final ItemStack itemStack) {
        final Object invoke = ReflectedArmorStand.packetEquipConstructor.invoke(new Object[0]);
        ReflectedArmorStand.IDPacketEquipField.set(invoke, this.ID);
        ReflectedArmorStand.enumItemSlotPacketEquipField.set(invoke, ReflectedArmorStand.enumItemSlotClass.getEnumConstants()[n]);
        ReflectedArmorStand.itemStackPacketEquipField.set(invoke, ReflectedArmorStand.asNMSCopyMethod.invoke(ReflectedArmorStand.craftItemStackClass, itemStack));
        this.packetEquip.add(invoke);
        NMSPlayer.sendPacket(invoke);
        return this;
    }
    
    public ReflectedArmorStand setDisplayName(final String displayName) {
        ReflectedArmorStand.setCustomeNameMethod.invoke(this.armorStand, displayName);
        ReflectedArmorStand.setCustomeNameVisibleMethod.invoke(this.armorStand, true);
        this.displayName = displayName;
        return this;
    }
    
    public ReflectedArmorStand setMarker(final boolean marker) {
        ReflectedArmorStand.setMarkerMethod.invoke(this.armorStand, marker);
        this.marker = marker;
        return this;
    }
    
    public ReflectedArmorStand setArms(final boolean arms) {
        ReflectedArmorStand.setArmsMethod.invoke(this.armorStand, arms);
        this.arms = arms;
        return this;
    }
    
    public void setLocation(final Location location) {
        this.location = location;
    }
    
    public int getID() {
        return this.ID;
    }
    
    public boolean isVisible() {
        return this.visible;
    }
    
    public boolean isSmall() {
        return this.small;
    }
    
    public void teleport(final Player player, final Location location) {
        ReflectedArmorStand.setPositionMethod.invoke(this.armorStand, location.getX(), location.getY(), location.getZ(), this.yaw, this.pitch);
        NMSPlayer.sendPacket(player, ReflectedArmorStand.packetTeleportContrustuctor.invoke(this.armorStand));
        this.location = location;
    }
    
    public void faketeleport(final Player player, final Location location) {
        ReflectedArmorStand.setPositionMethod.invoke(this.armorStand, location.getX(), location.getY(), location.getZ(), this.yaw, this.pitch);
        NMSPlayer.sendPacket(player, ReflectedArmorStand.packetTeleportContrustuctor.invoke(this.armorStand));
    }
    
    public void teleport(final Location location) {
        ReflectedArmorStand.setPositionMethod.invoke(this.armorStand, location.getX(), location.getY(), location.getZ(), this.yaw, this.pitch);
        NMSPlayer.sendPacket(ReflectedArmorStand.packetTeleportContrustuctor.invoke(this.armorStand));
        this.location = location;
    }
    
    public void hide() {
        NMSPlayer.destroyEntity(this.ID);
        this.hide = true;
    }
    
    public void hide(final Player player) {
        NMSPlayer.destroyEntity(player, this.ID);
        this.hide = true;
    }
    
    public void show(final Player player) {
        NMSPlayer.sendPacket(player, this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacket(player, o));
        this.hide = false;
    }
    
    public void show() {
        NMSPlayer.sendPacket(this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacket(o));
        this.hide = false;
    }
    
    public void remove() {
        NMSPlayer.destroyEntity(this.ID);
        if (this.packets != null) {
            NMSPlayer.getPacketsToSend().removeAll(this.packets);
        }
    }
    
    public ReflectedArmorStand spawnArmorStand() {
        NMSPlayer.sendPacketNearby(this.location, this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacketNearby(this.location, o));
        return this;
    }
    
    public ReflectedArmorStand spawnConstantArmorStand() {
        this.packets = NMSPlayer.sendConstantPacket(this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendConstantPacket(o));
        this.packets.addAll(this.packetEquip);
        return this;
    }
    
    public ReflectedArmorStand spawnArmorStand(final Player player) {
        NMSPlayer.sendPacket(player, this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacket(o));
        return this;
    }
    
    public ReflectedArmorStand spawnArmorStandExlude(final Player player) {
        NMSPlayer.sendPacketExclude(Bukkit.getOnlinePlayers(), player, this.packetSpawn, this.packetRotation);
        this.packetEquip.forEach(o -> NMSPlayer.sendPacketExclude(Bukkit.getOnlinePlayers(), player, o));
        return this;
    }
    
    public Entity getBukkitEntity() {
        return this.bukkitEntity;
    }
    
    private EulerAngle toNMS(final EulerAngle eulerAngle) {
        return new EulerAngle((double)(float)Math.toDegrees(eulerAngle.getX()), (double)(float)Math.toDegrees(eulerAngle.getY()), (double)(float)Math.toDegrees(eulerAngle.getZ()));
    }
    
    public Location getLocation() {
        return this.location;
    }
    
    public String getDisplayName() {
        return this.displayName;
    }
    
    public float getYaw() {
        return this.yaw;
    }
}

 

 

Reflection:

  Afficher le contenu masqué

package net.heroyn.heroynserverapi.nms;

import org.bukkit.*;
import java.util.*;
import java.lang.reflect.*;
import java.util.regex.*;

@SuppressWarnings({"unchecked","rawtypes"})
public final class Reflection
{
    private static String OBC_PREFIX;
    private static String NMS_PREFIX;
    private static String VERSION;
    private static Pattern MATCH_VARIABLE;
    
    static {
    	Reflection.OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName();
    	Reflection.NMS_PREFIX = Reflection.OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server");
    	Reflection.VERSION = Reflection.OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", "");
    	Reflection.MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}");
    }
    
    public static <T> FieldAccessor<T> getField(final Class<?> clazz, final String s, final Class<T> clazz2) {
        return getField(clazz, s, clazz2, 0);
    }
    
    public static <T> FieldAccessor<T> getField(final String s, final String s2, final Class<T> clazz) {
        return getField(getClass(s), s2, clazz, 0);
    }
    
    public static <T> FieldAccessor<T> getField(final Class<?> clazz, final Class<T> clazz2, final int n) {
        return getField(clazz, null, clazz2, n);
    }
    
    public static <T> FieldAccessor<T> getField(final String s, final Class<T> clazz, final int n) {
        return getField(getClass(s), clazz, n);
    }
    
    private static <T> FieldAccessor<T> getField(final Class<?> clazz, final String s, final Class<T> clazz2, int n) {
        Field[] declaredFields;
        for (int length = (declaredFields = clazz.getDeclaredFields()).length, i = 0; i < length; ++i) {
            final Field field = declaredFields[i];
            if ((s == null || field.getName().equals(s)) && clazz2.isAssignableFrom(field.getType()) && n-- <= 0) {
                field.setAccessible(true);
                return new FieldAccessor<T>() {
					@Override
                    public T get(final Object o) {
                        try {
                            return (T)field.get(o);
                        }
                        catch (IllegalAccessException ex) {
                            throw new RuntimeException("Cannot access reflection.", ex);
                        }
                    }
                    
                    @Override
                    public void set(final Object o, final Object o2) {
                        try {
                            field.set(o, o2);
                        }
                        catch (IllegalAccessException ex) {
                            throw new RuntimeException("Cannot access reflection.", ex);
                        }
                    }
                    
                    @Override
                    public boolean hasField(final Object o) {
                        return field.getDeclaringClass().isAssignableFrom(o.getClass());
                    }
                };
            }
        }
        if (clazz.getSuperclass() != null) {
            return (FieldAccessor<T>)getField(clazz.getSuperclass(), s, (Class<Object>)clazz2, n);
        }
        throw new IllegalArgumentException("Cannot find field with type " + clazz2);
    }
    
    public static MethodInvoker getMethod(final String s, final String s2, final Class<?>... array) {
        return getTypedMethod(getClass(s), s2, null, array);
    }
    
    public static MethodInvoker getMethod(final Class<?> clazz, final String s, final Class<?>... array) {
        return getTypedMethod(clazz, s, null, array);
    }
    
    public static MethodInvoker getTypedMethod(final Class<?> clazz, final String s, final Class<?> clazz2, final Class<?>... array) {
        Method[] declaredMethods;
        for (int length = (declaredMethods = clazz.getDeclaredMethods()).length, i = 0; i < length; ++i) {
            final Method method = declaredMethods[i];
            if ((s == null || method.getName().equals(s)) && (clazz2 == null || method.getReturnType().equals(clazz2)) && Arrays.equals(method.getParameterTypes(), array)) {
                method.setAccessible(true);
                return new MethodInvoker() {
                    @Override
                    public Object invoke(final Object o, final Object... array) {
                        try {
                            return method.invoke(o, array);
                        }
                        catch (Exception ex) {
                            throw new RuntimeException("Cannot invoke method " + method, ex);
                        }
                    }
                };
            }
        }
        if (clazz.getSuperclass() != null) {
            return getMethod(clazz.getSuperclass(), s, array);
        }
        throw new IllegalStateException(String.format("Unable to find method %s (%s).", s, Arrays.asList(array)));
    }
    
    public static ConstructorInvoker getConstructor(final String s, final Class<?>... array) {
        return getConstructor(getClass(s), array);
    }
    
    public static ConstructorInvoker getConstructor(final Class<?> clazz, final Class<?>... array) {
		Constructor[] declaredConstructors;
        for (int length = (declaredConstructors = clazz.getDeclaredConstructors()).length, i = 0; i < length; ++i) {
            final Constructor constructor = declaredConstructors[i];
            if (Arrays.equals(constructor.getParameterTypes(), array)) {
                constructor.setAccessible(true);
                return new ConstructorInvoker() {
                    @Override
                    public Object invoke(final Object... array) {
                        try {
                            return constructor.newInstance(array);
                        }
                        catch (Exception ex) {
                            throw new RuntimeException("Cannot invoke constructor " + constructor, ex);
                        }
                    }
                };
            }
        }
        throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(array)));
    }
    
    public static Class<Object> getUntypedClass(final String s) {
        return (Class<Object>)getClass(s);
    }
    
    public static Class<?> getClass(final String s) {
        return getCanonicalClass(expandVariables(s));
    }
    
    public static Class<?> getMinecraftClass(final String s) {
        return getCanonicalClass(String.valueOf(Reflection.NMS_PREFIX) + "." + s);
    }
    
    public static Class<?> getCraftBukkitClass(final String s) {
        return getCanonicalClass(String.valueOf(Reflection.OBC_PREFIX) + "." + s);
    }
    
    private static Class<?> getCanonicalClass(final String s) {
        try {
            return Class.forName(s);
        }
        catch (ClassNotFoundException ex) {
            throw new IllegalArgumentException("Cannot find " + s, ex);
        }
    }
    
    private static String expandVariables(final String s) {
        final StringBuffer sb = new StringBuffer();
        final Matcher matcher = Reflection.MATCH_VARIABLE.matcher(s);
        while (matcher.find()) {
            final String group = matcher.group(1);
            String s2;
            if ("nms".equalsIgnoreCase(group)) {
                s2 = Reflection.NMS_PREFIX;
            }
            else if ("obc".equalsIgnoreCase(group)) {
                s2 = Reflection.OBC_PREFIX;
            }
            else {
                if (!"version".equalsIgnoreCase(group)) {
                    throw new IllegalArgumentException("Unknown variable: " + group);
                }
                s2 = Reflection.VERSION;
            }
            if (s2.length() > 0 && matcher.end() < s.length() && s.charAt(matcher.end()) != '.') {
                s2 = String.valueOf(s2) + ".";
            }
            matcher.appendReplacement(sb, Matcher.quoteReplacement(s2));
        }
        matcher.appendTail(sb);
        return sb.toString();
    }
    
    public interface ConstructorInvoker
    {
        Object invoke(final Object... p0);
    }
    
    public interface FieldAccessor<T>
    {
        T get(final Object p0);
        
        void set(final Object p0, final Object p1);
        
        boolean hasField(final Object p0);
    }
    
    public interface MethodInvoker
    {
        Object invoke(final Object p0, final Object... p1);
    }
}

 

 

Et on dit merci cocoraid ;)

Ton code en entier ? (Là ou tu les utilises)

Partager ce message


Lien à poster
Partager sur d’autres sites

Posté(e) (modifié)

Il y a 10 heures, OpperDev a dit :

Et on dit merci cocoraid ;)

Ton code en entier ? (Là ou tu les utilises)

Je sais que c'est lui perso je l'utilise pas il ma demander de regarder pourquoi ça marchait pas mais j'ai pas trouver je la donne demain 

Edit: donc voila je lui ai demander et il l'utilise comme sa:

Spoiler
final ReflectedArmorStand reflectedArmorStand = new ReflectedArmorStand(clone.clone().subtract(0.0, 0.5, 0.0));
                    reflectedArmorStand.setSmall(true);
                    reflectedArmorStand.setArms(true);
                    reflectedArmorStand.setVisible(true);
                    reflectedArmorStand.setRightArmPose(new EulerAngle(0.0, 0.0, Math.toRadians(323.0)));
                    reflectedArmorStand.setEquipment(0, new UtilItem(Material.WOOL, 10)).getItem());
                    reflectedArmorStand.setLocation(clone.clone().subtract(0.0, 0.5, 0.0));
                    reflectedArmorStand.spawnArmorStand();

 

il a mis le visible a true pour vois si aux moins l'armorStand spawner mais il n'y a rien non plus

Modifié par Foulehistory
Ajout de code

Partager ce message


Lien à poster
Partager sur d’autres sites
Il y a 17 heures, Foulehistory a dit :

Je sais que c'est lui perso je l'utilise pas il ma demander de regarder pourquoi ça marchait pas mais j'ai pas trouver je la donne demain 

Edit: donc voila je lui ai demander et il l'utilise comme sa:

  Masquer le contenu

final ReflectedArmorStand reflectedArmorStand = new ReflectedArmorStand(clone.clone().subtract(0.0, 0.5, 0.0));
                    reflectedArmorStand.setSmall(true);
                    reflectedArmorStand.setArms(true);
                    reflectedArmorStand.setVisible(true);
                    reflectedArmorStand.setRightArmPose(new EulerAngle(0.0, 0.0, Math.toRadians(323.0)));
                    reflectedArmorStand.setEquipment(0, new UtilItem(Material.WOOL, 10)).getItem());
                    reflectedArmorStand.setLocation(clone.clone().subtract(0.0, 0.5, 0.0));
                    reflectedArmorStand.spawnArmorStand();

 

il a mis le visible a true pour vois si aux moins l'armorStand spawner mais il n'y a rien non plus

Beh c'est sa classe et il l'utilise très bien dans prodigy j'vois pas pourquoi il aurait du mal a l'utiliser la xD (j'sais pas trop comment m'en servir de sa classe j'ai pas trop appronfondit)

Partager ce message


Lien à poster
Partager sur d’autres sites
il y a 6 minutes, OpperDev a dit :

Beh c'est sa classe et il l'utilise très bien dans prodigy j'vois pas pourquoi il aurait du mal a l'utiliser la xD (j'sais pas trop comment m'en servir de sa classe j'ai pas trop appronfondit)

Je sais pas même moi je vois pas les armorstand spawner :/

 

Partager ce message


Lien à poster
Partager sur d’autres sites

Créer un compte ou se connecter pour commenter

Vous devez être membre afin de pouvoir déposer un commentaire

Créer un compte

Créez un compte sur notre communauté. C’est facile !


Créer un nouveau compte

Se connecter

Vous avez déjà un compte ? Connectez-vous ici.


Connectez-vous maintenant

  • En ligne récemment   0 membre est en ligne

    Aucun utilisateur enregistré regarde cette page.