Player force another player to spectate?

gl
- in Plugins
7

How can you program it in a Minecraft plugin to force one player to spectate another player? With

player.setSpectatorTarget (entity);

I've already tried, but then I get this error message:

[01:01:45 ERROR]: zero

org.bukkit.command.CommandException: Unhandled exception executing command 'spectate' in plugin ************** v1.8

at org.bukkit.command.PluginCommand.execute (PluginCommand.java:46) ~ [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at org.bukkit.command.SimpleCommandMap.dispatch (SimpleCommandMap.java:141) ~ [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand (CraftServer.java:646) ~ [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand (PlayerConnection.java:1115) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at net.minecraft.server.v1_8_R1.PlayerConnection.a (PlayerConnection.java:950) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at net.minecraft.server.v1_8_R1.PacketPlayInChat.a (PacketPlayInChat.java:26) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at net.minecraft.server.v1_8_R1.PacketPlayInChat.a (PacketPlayInChat.java:53) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at net.minecraft.server.v1_8_R1.PacketHandleTask.run (SourceFile: 13) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at java.util.concurrent.Executors $ RunnableAdapter.call (Executors.java:511) [?: 1.8.0_212]

at java.util.concurrent.FutureTask.run (FutureTask.java:266) [?: 1.8.0_212]

at net.minecraft.server.v1_8_R1.MinecraftServer.z (MinecraftServer.java:696) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at net.minecraft.server.v1_8_R1.DedicatedServer.z (DedicatedServer.java:316) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at net.minecraft.server.v1_8_R1.MinecraftServer.y (MinecraftServer.java:634) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at net.minecraft.server.v1_8_R1.MinecraftServer.run (MinecraftServer.java:537) [spigot-1.8.jar: git-Spigot-550ebac-7019900]

at java.lang.Thread.run (Thread.java:748) [?: 1.8.0_212]

Caused by: java.lang.NoSuchMethodError: org.bukkit.entity.Player.setSpectatorTarget (Lorg / bukkit / entity / Entity;) V

at net. **********. Commands.Spectate.onCommand (Spectate.java:32) ~ [?:?]

at org.bukkit.command.PluginCommand.execute (PluginCommand.java:44) ~ [spigot-1.8.jar: git-Spigot-550ebac-7019900]

… 14 more

I understand the error message, but how should I fix it?

an

How did you get the target player at

player.setSpectatorTarget (…);

inserted?

Send a bit of code from the outside.

gl

By "entity" I mean "target" xD

So the target is the player that the player should spectate

an

Yo, I know, but did you insert that correctly?

Show code.

gl

So I have the target in a for loop

for (Player target: Bukkit.getOnlinePlayers ()) …
player.spectateDochEndlichMal (target);
return true;

an

Hmm, I don't see anything wrong. Even if I don't understand the meaning of the loop, because all players go through it on the same tick. The player is in Spectator Mode? You don't change the target variable in your function?

gl

Yes

an

Send times privately the whole code xD