修复踢人时玩家不在产生的空指针异常
查询这段时间里,玩家可能退出了服务器,可能在banned-players.json里面,或者不在whitelist.json里。原来直接调用kick,导致这几种情况下产生空指针异常。现在在踢出之前对玩家是否在线进行一个检测,如果玩家在线才踢出。
This commit is contained in:
parent
f803cf2309
commit
64d9436419
1 changed files with 7 additions and 3 deletions
|
@ -1,10 +1,9 @@
|
|||
package cn.cnklp.studio.UnionBanClientSpigot;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class KickPlayerTask extends BukkitRunnable {
|
||||
private final String username;
|
||||
private final ClientPlugin plugin;
|
||||
|
@ -15,6 +14,11 @@ public class KickPlayerTask extends BukkitRunnable {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
Objects.requireNonNull(Bukkit.getPlayer(username)).kickPlayer("You are in the UnionBan list!");
|
||||
Player player = Bukkit.getPlayer(username);
|
||||
if (player == null) {
|
||||
plugin.getLogger().info("Player " + username + " is not in the server.");
|
||||
} else {
|
||||
player.kickPlayer("You are in the UnionBan list!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue