#Code runs as expected on one account, but not another when hosting 2 instances at one time

1 messages · Page 1 of 1 (latest)

shy plank
#

https://paste.md-5.net/weyagudicu.cs
i have 2 instances of minecraft running so i can test that code is compatible across multiple accounts. This code executes as expected on one, but on the other, it only displays the NullPointerException (which in this case is ignored)

#

and if i add a message to the nullpointerexception it runs it 100% of the time once the TextComponent is used

coral geyser
#

Never, ever, catch NullpointerExceptions. Fix the exception.

shy plank
coral geyser
#

Send it, then we can help

#

Nullpointer almost always occur for fundamental design flaws. They are one of the best indicators that something is wrong with your design/code.

shy plank
shy plank
#

it always sends java if (!plugin.getPlayerToPunish().containsKey(player.getUniqueId().toString())) { MessageManager.playerBad(player, "You do not have anyone selected to punish"); return true; } to one account but to the other it displays as expected

coral geyser
#

Would you mind doing a bit of refactoring with early escapes?
This code is quite unpleasant to read.
An early escape for example is:

if (!(sender instanceof Player player)) {
  return;
}
shy plank
#

i know what they are, i just dont know where to use them for this code

solar silo
#

For example in that code you just sent, the check here should be inverse with an early return

honest cloak
#

okay @shy plank first thing. Print the stacktrace instead of sending the player a message. and send us the stacktrace

shy plank
#
[19:29:45] [Server thread/WARN]:        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45)
[19:29:45] [Server thread/WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149)
[19:29:45] [Server thread/WARN]:        at org.bukkit.craftbukkit.v1_18_R2.CraftServer.dispatchCommand(CraftServer.java:826)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1957)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1796)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1777)
[19:29:45] [Server thread/WARN]:        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:46)
[19:29:45] [Server thread/WARN]:        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:1)
[19:29:45] [Server thread/WARN]:        at net.minecraft.network.protocol.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:31)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.TickTask.run(SourceFile:18)
[19:29:45] [Server thread/WARN]:        at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:157)
[19:29:45] [Server thread/WARN]:        at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1190)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:1)
[19:29:45] [Server thread/WARN]:        at net.minecraft.util.thread.IAsyncTaskHandler.y(SourceFile:131)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.be(MinecraftServer.java:1169)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1162)
[19:29:45] [Server thread/WARN]:        at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:140)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1146)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1051)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304)
[19:29:45] [Server thread/WARN]:        at java.base/java.lang.Thread.run(Thread.java:842)```
honest cloak
#

what;s line 83?

solar silo
honest cloak
shy plank
honest cloak
#

most likely

#

i kinda fixed ur code

shy plank
#

it removes the player/target from the playerToPunish hashmap after the confirm command is executed

honest cloak
#

PlayerToPunish may also be null

honest cloak
#

the entire thing that is

shy plank
#

idk. but that is line 83

honest cloak
#

send the entire thing

#

the entire error

shy plank
#
[19:29:45] [Server thread/WARN]:        at games.kingdoms.kingdoms.admin.punishCMD.ConfirmPunishment.onCommand(ConfirmPunishment.java:83)
[19:29:45] [Server thread/WARN]:        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45)
[19:29:45] [Server thread/WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149)
[19:29:45] [Server thread/WARN]:        at org.bukkit.craftbukkit.v1_18_R2.CraftServer.dispatchCommand(CraftServer.java:826)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1957)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1796)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1777)
[19:29:45] [Server thread/WARN]:        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:46)
[19:29:45] [Server thread/WARN]:        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:1)
[19:29:45] [Server thread/WARN]:        at net.minecraft.network.protocol.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:31)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.TickTask.run(SourceFile:18)
[19:29:45] [Server thread/WARN]:        at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:157)
[19:29:45] [Server thread/WARN]:        at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1190)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:1)
[19:29:45] [Server thread/WARN]:        at net.minecraft.util.thread.IAsyncTaskHandler.y(SourceFile:131)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.be(MinecraftServer.java:1169)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1162)
[19:29:45] [Server thread/WARN]:        at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:140)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1146)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1051)
[19:29:45] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304)
[19:29:45] [Server thread/WARN]:        at java.base/java.lang.Thread.run(Thread.java:842)
[19:38:19] [Server thread/WARN]: Can't keep up! Is the server overloaded? Running 5559ms or 111 ticks behind```
honest cloak
#

plugin.getPlayerToPunish().get(player.getUniqueId().toString())

#

the map does not have a mapping for the player uuid

#

don't use strings, just use uuids

#

Map<String,String> can be

#

Map<UUID,UUID>

shy plank
honest cloak
#

UUID.fromString(uuidstring)

shy plank
#

ah