Solved Am I using NMS or Reflection

Discussion in 'Spigot Plugin Development' started by WAS, Apr 28, 2017.

  1. WAS


    Uhmm... I went into this with the whole NMS on different versions without Reflection but my friend tells me my class is reflection. Now I am just confused. Can someone please verify?

    Code (Java):
    public class FakePlayer_v1_11_R1 {
       public void spawnFakePlayer(Player player, Location location) {
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
        WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
        EntityPlayer npc = new EntityPlayer(server,
                           new GameProfile(player.getUniqueId(),
                                   new PlayerInteractManager(world));

        npc.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
        ItemStack feet = CraftItemStack.asNMSCopy(player.getInventory().getBoots());
        ItemStack legs = CraftItemStack.asNMSCopy(player.getInventory().getLeggings());
        ItemStack chest = CraftItemStack.asNMSCopy(player.getInventory().getChestplate());
        ItemStack head = CraftItemStack.asNMSCopy(player.getInventory().getHelmet());
        ItemStack mainHand = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
        ItemStack offHand = CraftItemStack.asNMSCopy(player.getInventory().getItemInOffHand());
        npc.setEquipment(EnumItemSlot.FEET, feet);
        npc.setEquipment(EnumItemSlot.LEGS, legs);
        npc.setEquipment(EnumItemSlot.CHEST, chest);
        npc.setEquipment(EnumItemSlot.HEAD, head);
        npc.setEquipment(EnumItemSlot.MAINHAND, mainHand);
        npc.setEquipment(EnumItemSlot.OFFHAND, offHand);
        for(Player p : Bukkit.getOnlinePlayers()){
          PlayerConnection connection = ((CraftPlayer) p).getHandle().playerConnection;
          connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
          connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));

    #1 WAS, Apr 28, 2017
    Last edited: Apr 28, 2017
  2. NMS stands for net.minecraft.server
    This is typically followed by a version number.

    This means that using that class will only work if the server is that exact version.

    If you have any imports using Java.lang.reflect

    Then you're using reflection methods

    Sent from my iPhone using Tapatalk
  3. Your friend is being silly :)

    Check your imports, they contain NMS imports, so it's not reflection.
  4. WAS


    See that's what I thought. I thought reflection was an actual package and methods. Yeah no reflection import. Nothing from Java packages.

    Thanks guys. Lol wow.