NPC HELP

Discussion in 'Spigot Plugin Development' started by WildPlaysGames, May 31, 2017.

  1. Hello, People from spigot,
    I've got some code here, and I want to open an inventory whenever the NPC is right clicked. I have two classes.
    NPC Class:
    Code (Text):
    package net.arcanemc.parkour.npc;

    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
    import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    import com.mojang.authlib.GameProfile;

    import net.minecraft.server.v1_8_R3.EntityPlayer;
    import net.minecraft.server.v1_8_R3.MinecraftServer;
    import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
    import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
    import net.minecraft.server.v1_8_R3.PlayerConnection;
    import net.minecraft.server.v1_8_R3.PlayerInteractManager;
    import net.minecraft.server.v1_8_R3.WorldServer;

    public class NPC implements Listener {
       
        private EntityPlayer npc;
       
        @EventHandler
        public void on(PlayerJoinEvent e) {
            Player player = e.getPlayer();
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
            npc = new EntityPlayer(server, world, new GameProfile(UUID.randomUUID(), ChatColor.RED + "Parkour"), new PlayerInteractManager(world));
            npc.setLocation(229.543, 64, 257.522, 0, 0);
            npc.setCustomName(ChatColor.RED + "Parkour");
            npc.setCustomNameVisible(true);
            PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
            connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
            connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
        }
    }
    Now my Listener class:
    Code (Text):
    package net.arcanemc.parkour.npc;

    import org.bukkit.ChatColor;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractAtEntityEvent;

    import net.minecraft.server.v1_8_R3.EntityPlayer;

    public class NPCListener implements Listener {
       
        @EventHandler
        public void NPCInventory(PlayerInteractAtEntityEvent e) {
            if (e.getRightClicked().getType() == EntityType.PLAYER) {
                EntityPlayer entity = (EntityPlayer) e.getRightClicked();
                Player player = (Player) e.getPlayer();
               
                if (entity.getCustomName().equalsIgnoreCase(ChatColor.RED + "Parkour")) {
                    e.setCancelled(true);
                    player.sendMessage(ChatColor.RED + "Coded correctly!");
                }
                else {
                    player.sendMessage("Test");
                }
            }
        }
    }
    Thanks for any help possible!
     
  2. Do you have a main class? ;)
     
  3. Yes of course.
     
  4. I think he/she asking to see it lol
     
    • Like Like x 1
  5. Can i see it?
     
  6. That's new (to me at least) what is com.mojang
     
  7. for a guy that only imports the Bukkit.jar in my Plugins this is a wowfest. I know net.minecraft.server, but... wow, never seen all those imports before, org.Bukkit.craftbukkit, com.mojang...