BukkitPlugins Just doesnt work

Discussion in 'Plugin Development' started by spoopmyboot, Jan 27, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    spoopmyboot

    Code:
    Code:
    package chf.Quests;
    
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
    import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
    import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.mojang.authlib.GameProfile;
    
    import net.minecraft.server.v1_11_R1.EntityPlayer;
    
    import net.minecraft.server.v1_11_R1.MinecraftServer;
    import net.minecraft.server.v1_11_R1.PacketPlayOutNamedEntitySpawn;
    import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo;
    import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
    import net.minecraft.server.v1_11_R1.PlayerConnection;
    import net.minecraft.server.v1_11_R1.PlayerInteractManager;
    import net.minecraft.server.v1_11_R1.WorldServer;
    
    public class NPC extends JavaPlugin implements Listener {
       
        private EntityPlayer npc;
       
        @Override
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
            MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
            npc = new EntityPlayer(nmsServer, nmsWorld, new GameProfile(UUID.randomUUID(), "HOE"), new PlayerInteractManager(nmsWorld));
        }
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            npc.setLocation(e.getPlayer().getLocation().getX(), e.getPlayer().getLocation().getY(), e.getPlayer().getLocation().getZ(), 0, 0);
            PlayerConnection connection = ((CraftPlayer) e.getPlayer()).getHandle().playerConnection;
            connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
            connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
        }
    }
    

    Problem:
    i used a youtube tutorial to make this plugin which is supposed to spawn a npc as soon as i spawn into the server. The problem is it doesn't do this at all i check the error logs and it didn't show anything

    What you can do to recreate the problem: just add the plugin to the bukkit plugins folder. This was the youtube video i used to code it.

    Possible problematic line(s):
    . i don't know any that could be a problem

    The FULL Error log:
    . There are no lines of error

    What you have tried:
    .Ive tried re downloading and exporting the plugin as im using eclipse to code this one
     
  2. Offline

    Zombie_Striker

    Follow Java naming conventions: Keep packagenames lowercase.

    Main problem: You are sending these packets before the player even joins the server. PlayerJoinEvent is called before the player joins the server (that is why you can cancel it). Create a Delayed task (just needs to be for a few ticks, try 5) and then send the packets.

    [Edit] This may be an issue in the future. Once you update your server, you will have to update all these imports. Though you do not have to worry about them now, you should think about using reflection to handle these packets. If you do not want to use reflection/ do not know how, you could then use ProtocolLib instead.
     
  3. Offline

    Drkmaster83

    Uhhhh.... it worked for me.
    2017-01-28_00.38.31.png
     
  4. Offline

    spoopmyboot

    how did you set up the server for the plugin or how did you export the plugin maybe i did it wrong some how.
     
  5. Offline

    Zombie_Striker

    @spoopmyboot
    No need. He set up the plugin by including it by putting the jar in the /plugins/ directory.

    Your issue may be that there actually is an error in the console, but it may be in the loading area. Please post the full console log (you can get that by going into /<server>/logs/recent.txt and copying the text) into PasteBin.com and post the link here.

    [Edit] remember to post the name of the plugin! That way I know what name to look for.
     
  6. Offline

    spoopmyboot

  7. Offline

    Zombie_Striker

    You have an invalid plugin.yml. Please use the YMAL parserer HERE to see what is wrong If it comes up green but still does not work, post the YML here.
     
Thread Status:
Not open for further replies.

Share This Page