1
0
mirror of https://e.coding.net/circlecloud/AuthMe.git synced 2024-12-22 06:48:55 +00:00

clean up...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-10-29 10:42:07 +08:00
parent 41c940c9d6
commit 67ceb59f05
4 changed files with 89 additions and 93 deletions

View File

@ -204,12 +204,7 @@ public class Utils {
public void run() { public void run() {
final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(pl, locat); final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(pl, locat);
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) { Utils.safeTP(pl, locat);
if (!tpEvent.getTo().getChunk().isLoaded()) {
tpEvent.getTo().getChunk().load();
}
pl.teleport(tpEvent.getTo());
}
} }
}); });
} }
@ -232,6 +227,13 @@ public class Utils {
} }
} }
public static void safeTP(final Player p, final Location loc) {
if (!loc.getWorld().getChunkAt(loc).isLoaded()) {
loc.getWorld().getChunkAt(loc).load();
}
p.teleport(loc);
}
public static void setGroup(final Player player, final GroupType group) { public static void setGroup(final Player player, final GroupType group) {
if (!Settings.isPermissionCheckEnabled) { if (!Settings.isPermissionCheckEnabled) {
return; return;

View File

@ -29,16 +29,16 @@ import fr.xephi.authme.task.TimeoutTask;
public class UnregisterCommand implements CommandExecutor { public class UnregisterCommand implements CommandExecutor {
public AuthMe plugin; public AuthMe plugin;
private Messages m = Messages.getInstance(); private final Messages m = Messages.getInstance();
private JsonCache playerCache; private final JsonCache playerCache;
public UnregisterCommand(AuthMe plugin) { public UnregisterCommand(final AuthMe plugin) {
this.plugin = plugin; this.plugin = plugin;
this.playerCache = new JsonCache(); this.playerCache = new JsonCache();
} }
@Override @Override
public boolean onCommand(final CommandSender sender, Command cmnd, String label, final String[] args) { public boolean onCommand(final CommandSender sender, final Command cmnd, final String label, final String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
return true; return true;
} }
@ -71,8 +71,8 @@ public class UnregisterCommand implements CommandExecutor {
} }
if (Settings.isForcedRegistrationEnabled) { if (Settings.isForcedRegistrationEnabled) {
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) { if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
Location spawn = plugin.getSpawnLocation(player); final Location spawn = plugin.getSpawnLocation(player);
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false); final SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false);
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) { if (!tpEvent.isCancelled()) {
player.teleport(tpEvent.getTo()); player.teleport(tpEvent.getTo());
@ -81,14 +81,15 @@ public class UnregisterCommand implements CommandExecutor {
player.saveData(); player.saveData();
PlayerCache.getInstance().removePlayer(player.getName().toLowerCase()); PlayerCache.getInstance().removePlayer(player.getName().toLowerCase());
if (!Settings.getRegisteredGroup.isEmpty()) if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, GroupType.UNREGISTERED); Utils.setGroup(player, GroupType.UNREGISTERED);
}
LimboCache.getInstance().addLimboPlayer(player); LimboCache.getInstance().addLimboPlayer(player);
int delay = Settings.getRegistrationTimeout * 20; final int delay = Settings.getRegistrationTimeout * 20;
int interval = Settings.getWarnMessageInterval; final int interval = Settings.getWarnMessageInterval;
BukkitScheduler sched = sender.getServer().getScheduler(); final BukkitScheduler sched = sender.getServer().getScheduler();
if (delay != 0) { if (delay != 0) {
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); final BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
} }
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval))); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval)));
@ -105,8 +106,9 @@ public class UnregisterCommand implements CommandExecutor {
if (playerCache.doesCacheExist(player)) { if (playerCache.doesCacheExist(player)) {
playerCache.removeCache(player); playerCache.removeCache(player);
} }
if (Settings.applyBlindEffect) if (Settings.applyBlindEffect) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
}
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
player.setWalkSpeed(0.0f); player.setWalkSpeed(0.0f);
player.setFlySpeed(0.0f); player.setFlySpeed(0.0f);
@ -114,21 +116,16 @@ public class UnregisterCommand implements CommandExecutor {
m.send(player, "unregistered"); m.send(player, "unregistered");
ConsoleLogger.info(player.getDisplayName() + " unregistered himself"); ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) { if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
Location spawn = plugin.getSpawnLocation(player); final Location spawn = plugin.getSpawnLocation(player);
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false); final SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false);
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) { Utils.safeTP(player, spawn);
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
}
player.teleport(tpEvent.getTo());
}
} }
return; return;
} else { } else {
m.send(player, "wrong_pwd"); m.send(player, "wrong_pwd");
} }
} catch (NoSuchAlgorithmException ex) { } catch (final NoSuchAlgorithmException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
sender.sendMessage("Internal Error please read the server log"); sender.sendMessage("Internal Error please read the server log");
} }

View File

@ -24,16 +24,16 @@ import fr.xephi.authme.settings.Settings;
public class ProcessSyncronousPlayerLogin implements Runnable { public class ProcessSyncronousPlayerLogin implements Runnable {
private PlayerAuth auth; private final PlayerAuth auth;
private DataSource database; private final DataSource database;
private LimboPlayer limbo; private final LimboPlayer limbo;
private String name; private final String name;
private Player player; private final Player player;
private JsonCache playerCache; private final JsonCache playerCache;
private AuthMe plugin; private final AuthMe plugin;
private PluginManager pm; private final PluginManager pm;
public ProcessSyncronousPlayerLogin(Player player, AuthMe plugin, DataSource data) { public ProcessSyncronousPlayerLogin(final Player player, final AuthMe plugin, final DataSource data) {
this.plugin = plugin; this.plugin = plugin;
this.database = data; this.database = data;
this.pm = plugin.getServer().getPluginManager(); this.pm = plugin.getServer().getPluginManager();
@ -91,8 +91,9 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
// Re-Force Survival GameMode if we need due to world change // Re-Force Survival GameMode if we need due to world change
// specification // specification
if (Settings.isForceSurvivalModeEnabled) if (Settings.isForceSurvivalModeEnabled) {
Utils.forceGM(player); Utils.forceGM(player);
}
// Restore Permission Group // Restore Permission Group
Utils.setGroup(player, GroupType.LOGGEDIN); Utils.setGroup(player, GroupType.LOGGEDIN);
@ -106,15 +107,17 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
// We can now display the join message // We can now display the join message
if (AuthMePlayerListener.joinMessage.containsKey(name) && AuthMePlayerListener.joinMessage.get(name) != null && !AuthMePlayerListener.joinMessage.get(name).isEmpty()) { if (AuthMePlayerListener.joinMessage.containsKey(name) && AuthMePlayerListener.joinMessage.get(name) != null && !AuthMePlayerListener.joinMessage.get(name).isEmpty()) {
for (Player p : Utils.getOnlinePlayers()) { for (final Player p : Utils.getOnlinePlayers()) {
if (p.isOnline()) if (p.isOnline()) {
p.sendMessage(AuthMePlayerListener.joinMessage.get(name)); p.sendMessage(AuthMePlayerListener.joinMessage.get(name));
}
} }
AuthMePlayerListener.joinMessage.remove(name); AuthMePlayerListener.joinMessage.remove(name);
} }
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);
@ -125,29 +128,30 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
player.saveData(); player.saveData();
// Login is finish, display welcome message // Login is finish, display welcome message
if (Settings.useWelcomeMessage) if (Settings.useWelcomeMessage) {
if (Settings.broadcastWelcomeMessage) { if (Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) { for (final String s : Settings.welcomeMsg) {
Bukkit.getServer().broadcastMessage(plugin.replaceAllInfos(s, player)); Bukkit.getServer().broadcastMessage(plugin.replaceAllInfos(s, player));
} }
} else { } else {
for (String s : Settings.welcomeMsg) { for (final String s : Settings.welcomeMsg) {
player.sendMessage(plugin.replaceAllInfos(s, player)); player.sendMessage(plugin.replaceAllInfos(s, player));
} }
} }
}
// Login is now finish , we can force all commands // Login is now finish , we can force all commands
forceCommands(); forceCommands();
} }
protected void forceCommands() { protected void forceCommands() {
for (String command : Settings.forceCommands) { for (final String command : Settings.forceCommands) {
try { try {
player.performCommand(command.replace("%p", player.getName())); player.performCommand(command.replace("%p", player.getName()));
} catch (Exception ignored) { } catch (final Exception ignored) {
} }
} }
for (String command : Settings.forceCommandsAsConsole) { for (final String command : Settings.forceCommandsAsConsole) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName())); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName()));
} }
} }
@ -157,7 +161,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
} }
protected void restoreInventory() { protected void restoreInventory() {
RestoreInventoryEvent event = new RestoreInventoryEvent(player); final RestoreInventoryEvent event = new RestoreInventoryEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
plugin.inventoryProtector.sendInventoryPacket(player); plugin.inventoryProtector.sendInventoryPacket(player);
@ -178,27 +182,21 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
} }
protected void teleportBackFromSpawn() { protected void teleportBackFromSpawn() {
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, limbo.getLoc()); final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, limbo.getLoc());
pm.callEvent(tpEvent); pm.callEvent(tpEvent);
if (!tpEvent.isCancelled()) { if (!tpEvent.isCancelled()) {
Location fLoc = tpEvent.getTo(); final Location fLoc = tpEvent.getTo();
if (!fLoc.getChunk().isLoaded()) { Utils.safeTP(player, fLoc);
fLoc.getChunk().load();
}
player.teleport(fLoc);
} }
} }
protected void teleportToSpawn() { protected void teleportToSpawn() {
Location spawnL = plugin.getSpawnLocation(player); final Location spawnL = plugin.getSpawnLocation(player);
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnL, true); final SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnL, true);
pm.callEvent(tpEvent); pm.callEvent(tpEvent);
if (!tpEvent.isCancelled()) { if (!tpEvent.isCancelled()) {
Location fLoc = tpEvent.getTo(); final Location fLoc = tpEvent.getTo();
if (!fLoc.getChunk().isLoaded()) { Utils.safeTP(player, fLoc);
fLoc.getChunk().load();
}
player.teleport(fLoc);
} }
} }

View File

@ -24,12 +24,12 @@ import fr.xephi.authme.task.TimeoutTask;
public class ProcessSyncronousPasswordRegister implements Runnable { public class ProcessSyncronousPasswordRegister implements Runnable {
private Messages m = Messages.getInstance(); private final Messages m = Messages.getInstance();
private AuthMe plugin; private final AuthMe plugin;
protected String name; protected String name;
protected Player player; protected Player player;
public ProcessSyncronousPasswordRegister(Player player, AuthMe plugin) { public ProcessSyncronousPasswordRegister(final Player player, final AuthMe plugin) {
this.player = player; this.player = player;
this.name = player.getName().toLowerCase(); this.name = player.getName().toLowerCase();
this.plugin = plugin; this.plugin = plugin;
@ -37,23 +37,20 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
@Override @Override
public void run() { public void run() {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); final LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
if (limbo != null) { if (limbo != null) {
player.setGameMode(limbo.getGameMode()); player.setGameMode(limbo.getGameMode());
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) { if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
Location loca = plugin.getSpawnLocation(player); final Location loca = plugin.getSpawnLocation(player);
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); final RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) { if (!tpEvent.isCancelled()) {
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { Utils.safeTP(player, tpEvent.getTo());
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
}
player.teleport(tpEvent.getTo());
} }
} }
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) { if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
RestoreInventoryEvent event = new RestoreInventoryEvent(player); final RestoreInventoryEvent event = new RestoreInventoryEvent(player);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
plugin.inventoryProtector.sendInventoryPacket(player); plugin.inventoryProtector.sendInventoryPacket(player);
@ -69,14 +66,16 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
Utils.setGroup(player, Utils.GroupType.REGISTERED); Utils.setGroup(player, Utils.GroupType.REGISTERED);
} }
m.send(player, "registered"); m.send(player, "registered");
if (!Settings.getmailAccount.isEmpty()) if (!Settings.getmailAccount.isEmpty()) {
m.send(player, "add_email"); m.send(player, "add_email");
}
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);
@ -85,8 +84,9 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
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) {
@ -101,56 +101,55 @@ 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 (final String s : Settings.welcomeMsg) {
plugin.getServer().broadcastMessage(plugin.replaceAllInfos(s, player)); plugin.getServer().broadcastMessage(plugin.replaceAllInfos(s, player));
} }
} else { } else {
for (String s : Settings.welcomeMsg) { for (final String s : Settings.welcomeMsg) {
player.sendMessage(plugin.replaceAllInfos(s, player)); player.sendMessage(plugin.replaceAllInfos(s, player));
} }
} }
}
// Register is now finish , we can force all commands // Register is now finish , we can force all commands
forceCommands(); forceCommands();
} }
protected void forceCommands() { protected void forceCommands() {
for (String command : Settings.forceRegisterCommands) { for (final String command : Settings.forceRegisterCommands) {
try { try {
player.performCommand(command.replace("%p", player.getName())); player.performCommand(command.replace("%p", player.getName()));
} catch (Exception ignored) { } catch (final Exception ignored) {
} }
} }
for (String command : Settings.forceRegisterCommandsAsConsole) { for (final 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()));
} }
} }
protected void forceLogin(Player player) { protected void forceLogin(final Player player) {
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) { if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
Location spawnLoc = plugin.getSpawnLocation(player); final Location spawnLoc = plugin.getSpawnLocation(player);
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, spawnLoc); final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, spawnLoc);
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) { if (!tpEvent.isCancelled()) {
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { Utils.safeTP(player, tpEvent.getTo());
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
}
player.teleport(tpEvent.getTo());
} }
} }
if (LimboCache.getInstance().hasLimboPlayer(name)) if (LimboCache.getInstance().hasLimboPlayer(name)) {
LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().deleteLimboPlayer(name);
}
LimboCache.getInstance().addLimboPlayer(player); LimboCache.getInstance().addLimboPlayer(player);
int delay = Settings.getRegistrationTimeout * 20; final int delay = Settings.getRegistrationTimeout * 20;
int interval = Settings.getWarnMessageInterval; final int interval = Settings.getWarnMessageInterval;
BukkitScheduler sched = plugin.getServer().getScheduler(); final BukkitScheduler sched = plugin.getServer().getScheduler();
if (delay != 0) { if (delay != 0) {
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); final BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
} }
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval)); final BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
if (player.isInsideVehicle() && player.getVehicle() != null) { if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject(); player.getVehicle().eject();