Stats Reset For Everyone

Discussion in 'Spigot Plugin Development' started by KingDotCom, Jun 5, 2016.

  1. So I have a command and when you execute the command it only works for online players and shows an internal error.

    this is my code
    Code (Text):
    for(OfflinePlayer q : Bukkit.getOfflinePlayers()){

    q.setStatistic(org.bukkit.Statistic.PLAYER_KILLS, 0);
    q.setStatistic(org.bukkit.Statistic.DEATHS, 0);

    }
    Please respond right away thanks!
     
  2. What's the error
     
  3. Its an internal error in game.
     
  4. Yes, show me the error message.
     
  5. Code (Text):
    04.06 18:27:22 [Server] INFO ... 13 more
    04.06 18:27:22 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at me.dev.aaron.Main.onCommand(Main.java:63) ~[?:?]
    04.06 18:27:22 [Server] INFO Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.CraftOfflinePlayer cannot be cast to org.bukkit.entity.Player
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:880) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1043) [spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    04.06 18:27:22 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'resetstats' in plugin FFA v1.0
     
  6. What's at line 63 of your onCommand?
     
  7. Code (Text):
    q.setStatistic(org.bukkit.Statistic.PLAYER_KILLS, 0);
    This is the line #63
     
  8. OfflinePlayer doesn't have a method setStatistic. That method is only present in the Player object, do
    Code (Text):
    Bukkit.getOnlinePlayers().forEach(p -> {
        p.setStatistic(Statistic.PLAYER_KILLS, 0);
        p.setStatistic(Statistic.DEATHS, 0);
    });