Solved EntityPlayer questions

Discussion in 'Spigot Plugin Development' started by Simagdo, May 29, 2018.

  1. Hey there,

    I am currently working with an EntityPlayer. I have the main thing done so far and now I want to work on the next thing i planned with it.
    Question 1:
    Is it somehow possible to make the EntityPlayer small. There is a method EntityPlayer#setSize(), but it doesn't change anything.
    My second question:
    Is it possible that I can set the created EntityPlayer as a Passenger on a Horse? If i try it like this:
    Code (Text):

    Horse horse = player.getWorld().spawn(player.getLocation(), Horse.class);
    Test test = new Test();
    test.spawn;
    horse.setPassenger((Entity) test);
     
    I get this error:
    Code (Text):

    org.bukkit.command.CommandException: Unhandled exception executing command 'test' in plugin Test v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:648) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1397) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1232) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514) [?:?]
            at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
            at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            at java.lang.Thread.run(Thread.java:844) [?:?]
    Caused by: java.lang.ClassCastException: net.minecraft.server.v1_12_R1.EntityPlayer cannot be cast to org.bukkit.entity.Entity
            at de.simagdo.test.utils.Test.spawn(Test.java:38) ~[?:?]
            at de.simagdo.test.commands.TestCommand.onCommand(TestCommand.java:227) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
            ... 15 more
     
    Yours
    Simagdo
     
  2. The error you get is because you're trying to cast an EntityPlayer to a player. Instead you should use the getBukkitEntity method.
     
  3. For the first question there's no way, as far as I know, to make the player look smaller but you can set it as a passenger of a smaller entity like an arrow or a minecraft and make that entity invisible, but I don't think it's a good way to do it
     
  4. What exact method do you mean? I couldn't find a getBukkitEntity method.
     
  5. JanTuck

    Supporter

  6. The error is on the TestCommand class on the line 227. Can you send the code of these lines to check what is going wrong?
     
  7. I know, where the error comes from. I have already posted the code in the first post.
     
  8. test.getBukkitEntity

    /e The method does exist. I just checked.
     
    • Agree Agree x 1
    • Winner Winner x 1
  9. Thank you very much. It works as it should. :)