Solved Teleport to gives me a java.lang.NoSuchMethodException:

Discussion in 'Plugin Development' started by corn666, Feb 12, 2019.

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

    corn666

    hi, i'm actually learning jave and i'm trying to create a bukkit plugin, as small personnal project..

    my plugin works, but i have a proble with the teleportTo() method.

    when i launc the command "teleportm" i get a java.lang.NoSuchMethodException:

    corn issued server command: /teleportm
    [11:31:12 WARN]: java.lang.NoSuchMethodException: net.minecraft.server.v1_12_R1.EntityPlayer.<init>(net.minecraft.server.v1_12_R1.World)
    [11:31:12 WARN]: at java.lang.Class.getConstructor0(Unknown Source)
    [11:31:12 WARN]: at java.lang.Class.getConstructor(Unknown Source)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.EntityTypes.a(SourceFile:155)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.Entity.teleportTo(Entity.java:2379)
    [11:31:12 WARN]: at fr.cazapp.test.Botox.onCommand(Botox.java:87)
    [11:31:12 WARN]: at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    [11:31:12 WARN]: at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
    [11:31:12 WARN]: at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:648)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1399)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1234)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13)
    [11:31:12 WARN]: at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    [11:31:12 WARN]: at java.util.concurrent.FutureTask.run(Unknown Source)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679)
    [11:31:12 WARN]: at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577)
    [11:31:12 WARN]: at java.lang.Thread.run(Unknown Source)

    here is my code.

    Code:
    package fr.cazapp.test;
    
    //import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
    import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
    import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.mojang.authlib.GameProfile;
    
    import net.minecraft.server.v1_12_R1.EntityPlayer;
    //import net.minecraft.server.v1_12_R1.ItemArmor.EnumArmorMaterial;
    import net.minecraft.server.v1_12_R1.MinecraftServer;
    import net.minecraft.server.v1_12_R1.PacketPlayOutNamedEntitySpawn;
    import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo;
    import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
    import net.minecraft.server.v1_12_R1.PlayerConnection;
    import net.minecraft.server.v1_12_R1.PlayerInteractManager;
    import net.minecraft.server.v1_12_R1.WorldServer;
    
    public class Botox extends JavaPlugin implements Listener {
       
        private EntityPlayer npc;
       
       
        @Override
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
                           
        }
       
       
       
        public void onDisable(){
            Bukkit.getServer().getLogger().info("le plugin TEST est descative");
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.AQUA + "la commande doit etre lancée par un joueur");
               
                return false;
            }
           
            Player player= (Player) sender;
           
           
           
            //si le player execute la commande "mule
            //creation d'une entitée mule Player avec l'uuid du player
            if (cmd.getName().equalsIgnoreCase("mule")) {
               
               
                player.sendMessage(ChatColor.GOLD + "ta mule est la!");
                MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
                WorldServer world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle();
               
                npc = new EntityPlayer(server, world, new GameProfile(player.getUniqueId(), player.getName() + "'s Mule"), new PlayerInteractManager(world));
               
               
                //npc.teleportTo(player.getPlayer().getLocation(),false);
                npc.setLocation(player.getPlayer().getLocation().getX(),player.getPlayer().getLocation().getY(),player.getPlayer().getLocation().getZ(),player.getPlayer().getLocation().getYaw(),player.getPlayer().getLocation().getPitch());
               
               
                PlayerConnection connection = ((CraftPlayer) player.getPlayer()).getHandle().playerConnection;
                connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
                connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
                }
               
           
           
            if (cmd.getName().equalsIgnoreCase("bois")) {
                player.sendMessage(ChatColor.GOLD + "je vais chercher du bois de suite!");
            }
           
            if (cmd.getName().equalsIgnoreCase("teleportm")) {
                player.sendMessage(ChatColor.GOLD + "teleportation!");
                npc.teleportTo(player.getLocation(),false);
               
               
               
            }
           
           
            return true;
           
        }
       
    
    }
    

    any help would be really apreciated.
     
  2. Offline

    timtower Ninja on the waves Moderator

    @corn666 Are you building on the same version as you are running?
     
  3. Offline

    corn666

    @timtower hi, thanks for your answer,

    if you are talking of my test server and library i'm using: yes they are both 1.12.2
     
  4. Offline

    0-o

    From what I can tell, the method EntityPlayer.teleportTo() doesn't exist, at least not in the 1.13 source (I don't have the 1.12 so it's possible it may exist on that version). Try and change it to teleport() and see if that works???
     
  5. Offline

    corn666


    hi,
    Teleport() is only available for Player.

    the npc only have teleportTo() (it's an EntityPlayer).
     
  6. Offline

    0-o

    just use setLocation() and then resend the packet
     
  7. Offline

    corn666


    i've already tried the "setLocation".... but didn't resend the packets!

    now it works perfectly, thank you so much. (it helps me understand a bit more how this all works).
     
Thread Status:
Not open for further replies.

Share This Page