0

I have a command that kicks a player from a MySQL database, but it's not working when the player is offline; it won't delete them from the database.

Here's my code:

this.ms.connect();
PreparedStatement kick = this.ms.prepare("DELETE FROM `players` WHERE `nick` = ?");

try {
    kick.setString(1, args[0]);
} catch (SQLException e) {
    e.printStackTrace();
}

this.ms.execute(kick);

The error I get is:

Caused by: java.lang.IllegalArgumentException: OfflinePlayer cannot be null
spongebob
  • 8,370
  • 15
  • 50
  • 83

2 Answers2

0

This is very unclear but if nick is the player's username then do:

Bukkit.getOfflinePlayer(args[0]).getName()

Remember, args[0] should be the username but if it's the UUID then do:

Bukkit.getOfflinePlayer(UUID.fromString(args[0]))
spongebob
  • 8,370
  • 15
  • 50
  • 83
InfIV
  • 15
  • 6
0

You need to use the players uuid, if you can not find the offline player by itβ€˜s exact name. Also, make sure, that all your mySql requests are working on a new Async thread, not in the main server thread.

gyurix
  • 1,106
  • 9
  • 23