Fix npe after register.

This commit is contained in:
DNx5 2015-12-01 01:29:56 +07:00
parent 4af4d424ee
commit 029214c080
4 changed files with 55 additions and 30 deletions

View File

@ -117,8 +117,11 @@ public class LimboCache {
* @param name String * @param name String
*/ */
public void deleteLimboPlayer(String name) { public void deleteLimboPlayer(String name) {
if(cache.containsKey(name)) {
cache.get(name).clearTask();
cache.remove(name); cache.remove(name);
} }
}
/** /**
* Method getLimboPlayer. * Method getLimboPlayer.
@ -148,8 +151,9 @@ public class LimboCache {
* @param player Player * @param player Player
*/ */
public void updateLimboPlayer(Player player) { public void updateLimboPlayer(Player player) {
if (this.hasLimboPlayer(player.getName().toLowerCase())) { String name = player.getName().toLowerCase();
this.deleteLimboPlayer(player.getName().toLowerCase()); if (hasLimboPlayer(name)) {
deleteLimboPlayer(name);
} }
addLimboPlayer(player); addLimboPlayer(player);
} }

View File

@ -108,8 +108,9 @@ public class LimboPlayer {
* @param i BukkitTask * @param i BukkitTask
*/ */
public void setTimeoutTaskId(BukkitTask i) { public void setTimeoutTaskId(BukkitTask i) {
if (this.timeoutTaskId != null) if (this.timeoutTaskId != null) {
this.timeoutTaskId.cancel(); this.timeoutTaskId.cancel();
}
this.timeoutTaskId = i; this.timeoutTaskId = i;
} }
@ -128,11 +129,27 @@ public class LimboPlayer {
* @param messageTaskId BukkitTask * @param messageTaskId BukkitTask
*/ */
public void setMessageTaskId(BukkitTask messageTaskId) { public void setMessageTaskId(BukkitTask messageTaskId) {
if (this.messageTaskId != null) if (this.messageTaskId != null) {
this.messageTaskId.cancel(); this.messageTaskId.cancel();
}
this.messageTaskId = messageTaskId; this.messageTaskId = messageTaskId;
} }
/**
* Method clearTask.
*
*/
public void clearTask() {
if (messageTaskId != null) {
messageTaskId.cancel();
}
messageTaskId = null;
if (timeoutTaskId != null) {
timeoutTaskId.cancel();
}
timeoutTaskId = null;
}
/** /**
* Method isFlying. * Method isFlying.
* *

View File

@ -50,14 +50,12 @@ public class AsynchronousJoin {
} }
public void process() { public void process() {
if (AuthMePlayerListener.gameMode.containsKey(name)) if (Utils.isUnrestricted(player)) {
AuthMePlayerListener.gameMode.remove(name);
AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode());
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
return; return;
} }
AuthMePlayerListener.gameMode.put(name, player.getGameMode());
if (plugin.ess != null && Settings.disableSocialSpy) { if (plugin.ess != null && Settings.disableSocialSpy) {
plugin.ess.getUser(player).setSocialSpyEnabled(false); plugin.ess.getUser(player).setSocialSpyEnabled(false);
} }

View File

@ -41,15 +41,13 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
this.plugin = plugin; this.plugin = plugin;
} }
protected void forceCommands() { private void forceCommands() {
for (String command : Settings.forceRegisterCommands) { for (String command : Settings.forceRegisterCommands) {
try {
player.performCommand(command.replace("%p", player.getName())); player.performCommand(command.replace("%p", player.getName()));
} catch (Exception ignored) {
}
} }
for (String command : Settings.forceRegisterCommandsAsConsole) { for (String command : Settings.forceRegisterCommandsAsConsole) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName())); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
command.replace("%p", player.getName()));
} }
} }
@ -58,20 +56,21 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
* *
* @param player Player * @param player Player
*/ */
protected void forceLogin(Player player) { private void forceLogin(Player player) {
Utils.teleportToSpawn(player); Utils.teleportToSpawn(player);
if (LimboCache.getInstance().hasLimboPlayer(name)) LimboCache cache = LimboCache.getInstance();
LimboCache.getInstance().deleteLimboPlayer(name); cache.updateLimboPlayer(player);
LimboCache.getInstance().addLimboPlayer(player);
int delay = Settings.getRegistrationTimeout * 20; int delay = Settings.getRegistrationTimeout * 20;
int interval = Settings.getWarnMessageInterval; int interval = Settings.getWarnMessageInterval;
BukkitScheduler sched = plugin.getServer().getScheduler(); BukkitScheduler sched = plugin.getServer().getScheduler();
BukkitTask task;
if (delay != 0) { if (delay != 0) {
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); task = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); cache.getLimboPlayer(name).setTimeoutTaskId(task);
} }
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.retrieve(MessageKey.LOGIN_MESSAGE), interval)); task = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name,
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); m.retrieve(MessageKey.LOGIN_MESSAGE), interval));
cache.getLimboPlayer(name).setMessageTaskId(task);
if (player.isInsideVehicle() && player.getVehicle() != null) { if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject(); player.getVehicle().eject();
} }
@ -97,33 +96,39 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
} }
} }
limbo.getTimeoutTaskId().cancel();
limbo.getMessageTaskId().cancel();
LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().deleteLimboPlayer(name);
} }
if (!Settings.getRegisteredGroup.isEmpty()) { if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, Utils.GroupType.REGISTERED); Utils.setGroup(player, Utils.GroupType.REGISTERED);
} }
m.send(player, MessageKey.REGISTER_SUCCESS); m.send(player, MessageKey.REGISTER_SUCCESS);
if (!Settings.getmailAccount.isEmpty())
if (!Settings.getmailAccount.isEmpty()) {
m.send(player, MessageKey.ADD_EMAIL_MESSAGE); m.send(player, MessageKey.ADD_EMAIL_MESSAGE);
}
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(false); player.setAllowFlight(false);
player.setFlying(false); player.setFlying(false);
} }
if (Settings.applyBlindEffect)
if (Settings.applyBlindEffect) {
player.removePotionEffect(PotionEffectType.BLINDNESS); player.removePotionEffect(PotionEffectType.BLINDNESS);
}
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
player.setWalkSpeed(0.2f); player.setWalkSpeed(0.2f);
player.setFlySpeed(0.1f); player.setFlySpeed(0.1f);
} }
// The LoginEvent now fires (as intended) after everything is processed // The LoginEvent now fires (as intended) after everything is processed
plugin.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); plugin.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
player.saveData(); player.saveData();
if (!Settings.noConsoleSpam) if (!Settings.noConsoleSpam) {
ConsoleLogger.info(player.getName() + " registered " + plugin.getIP(player)); ConsoleLogger.info(player.getName() + " registered " + plugin.getIP(player));
}
// Kick Player after Registration is enabled, kick the player // Kick Player after Registration is enabled, kick the player
if (Settings.forceRegKick) { if (Settings.forceRegKick) {
@ -138,7 +143,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
} }
// Register is finish and player is logged, display welcome message // Register is finish and player is logged, display welcome message
if (Settings.useWelcomeMessage) if (Settings.useWelcomeMessage) {
if (Settings.broadcastWelcomeMessage) { if (Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) { for (String s : Settings.welcomeMsg) {
plugin.getServer().broadcastMessage(plugin.replaceAllInfo(s, player)); plugin.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
@ -148,6 +153,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
player.sendMessage(plugin.replaceAllInfo(s, player)); player.sendMessage(plugin.replaceAllInfo(s, player));
} }
} }
}
// Register is now finish , we can force all commands // Register is now finish , we can force all commands
forceCommands(); forceCommands();