How to teleport all entities of a certain type?

Discussion in 'Plugin Development' started by WilliamD47, Apr 15, 2021.

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

    WilliamD47

    Hello all!

    I am making a plugin that teleports an armour stand to you every time you move so that you can have a custom nametag/playername whatever above your head as normal minecraft does not allow this.
    However I do not know how to teleport all armour stand entities. I would like to be able to have the same result as doing /tp @e[type=minecraft:armour_stand] Username but i do not know how to. Thanks in advance!

    Code:
    @EventHandler
        public void onMove(PlayerMoveEvent e) {
            Entity entity = (Entity) e.getPlayer().getWorld().getEntitiesByClasses(ArmorStand.class);
            entity.teleport(e.getPlayer().getLocation());
    
        }
    Alright I figured out a quick way to do it but it gives an error. The code is
    And the error is
    [19:36:38 ERROR]: Could not pass event PlayerMoveEvent to ChangeNameTag v0.1
    java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class org.bukkit.entity.Entity (java.util.ArrayList is in module java.base of loader 'bootstrap'; org.bukkit.entity.Entity is in unnamed module of loader 'app')
    at net.williamd47.changenametag.NameTagHide.onMove(NameTagHide.java:123) ~[?:?]
    at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor66.execute(Unknown Source) ~[?:?]
    at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.16.5.jar:git-Paper-465]
    at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[patched_1.16.5.jar:git-Paper-465]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[patched_1.16.5.jar:git-Paper-465]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:607) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.PlayerConnection.a(PlayerConnection.java:1260) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.PacketPlayInFlying.a(SourceFile:122) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.PacketPlayInFlying$PacketPlayInPositionLook.a(SourceFile:18) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.PlayerConnectionUtils.lambda$ensureMainThread$1(PlayerConnectionUtils.java:23) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:1133) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:1126) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:1087) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1001) ~[patched_1.16.5.jar:git-Paper-465]
    at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:174) ~[patched_1.16.5.jar:git-Paper-465]
    at java.lang.Thread.run(Thread.java:832) [?:?]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 15, 2021
  2. Offline

    Wick

    You're casting an entire list of entities to just a single entity object. You need to loop over all the entities.
     
  3. Offline

    davidclue

    Your goal is to give the player a custom nametag but teleporting an armor stand to a player with a custom name will just overlap their nametag and make it unreadable. Using NMS you can achieve this and change a player's nametag to whatever you want and even add obfuscated text, colors, underlines, bold text, italic text, and symbols. If you proceed with your way with armor stands just know that this will cause severe server lag especially if you have a lot of people on the server.
     
    Newdel likes this.
Thread Status:
Not open for further replies.

Share This Page