cleanup Listeners.

This commit is contained in:
DNx5 2015-09-14 01:42:31 +07:00
parent f60604c86c
commit b4124bc46d
5 changed files with 53 additions and 78 deletions

View File

@ -1,15 +1,14 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.Utils; import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
public class AuthMeBlockListener implements Listener { public class AuthMeBlockListener implements Listener {

View File

@ -1,17 +1,15 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent;
import com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome; import com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.Utils; import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public class AuthMeChestShopListener implements Listener { public class AuthMeChestShopListener implements Listener {

View File

@ -1,22 +1,16 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.Utils; import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.plugin.manager.CombatTagComunicator; import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.*;
public class AuthMeEntityListener implements Listener { public class AuthMeEntityListener implements Listener {

View File

@ -1,14 +1,16 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import java.io.ByteArrayOutputStream; import fr.xephi.authme.AuthMe;
import java.io.DataOutputStream; import fr.xephi.authme.ConsoleLogger;
import java.io.IOException; import fr.xephi.authme.Utils;
import java.util.ArrayList; import fr.xephi.authme.cache.auth.PlayerAuth;
import java.util.Arrays; import fr.xephi.authme.cache.auth.PlayerCache;
import java.util.List; import fr.xephi.authme.cache.limbo.LimboCache;
import java.util.concurrent.ConcurrentHashMap; import fr.xephi.authme.cache.limbo.LimboPlayer;
import java.util.regex.PatternSyntaxException; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -23,26 +25,23 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
import fr.xephi.authme.AuthMe; import java.io.ByteArrayOutputStream;
import fr.xephi.authme.ConsoleLogger; import java.io.DataOutputStream;
import fr.xephi.authme.Utils; import java.io.IOException;
import fr.xephi.authme.cache.auth.PlayerAuth; import java.util.ArrayList;
import fr.xephi.authme.cache.auth.PlayerCache; import java.util.Arrays;
import fr.xephi.authme.cache.limbo.LimboCache; import java.util.List;
import fr.xephi.authme.cache.limbo.LimboPlayer; import java.util.concurrent.ConcurrentHashMap;
import fr.xephi.authme.datasource.DataSource; import java.util.regex.PatternSyntaxException;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
public class AuthMePlayerListener implements Listener { public class AuthMePlayerListener implements Listener {
public static ConcurrentHashMap<String, GameMode> gameMode = new ConcurrentHashMap<String, GameMode>(); public static ConcurrentHashMap<String, GameMode> gameMode = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, String> joinMessage = new ConcurrentHashMap<String, String>(); public static ConcurrentHashMap<String, String> joinMessage = new ConcurrentHashMap<>();
private Messages m = Messages.getInstance(); private Messages m = Messages.getInstance();
public AuthMe plugin; public AuthMe plugin;
public static ConcurrentHashMap<String, Boolean> causeByAuthMe = new ConcurrentHashMap<String, Boolean>(); public static ConcurrentHashMap<String, Boolean> causeByAuthMe = new ConcurrentHashMap<>();
private List<String> antibot = new ArrayList<String>(); private List<String> antibot = new ArrayList<>();
public AuthMePlayerListener(AuthMe plugin) { public AuthMePlayerListener(AuthMe plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -115,7 +114,6 @@ public class AuthMePlayerListener implements Listener {
if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@ -152,7 +150,6 @@ public class AuthMePlayerListener implements Listener {
if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@ -189,7 +186,6 @@ public class AuthMePlayerListener implements Listener {
if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@ -226,7 +222,6 @@ public class AuthMePlayerListener implements Listener {
if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@ -264,7 +259,6 @@ public class AuthMePlayerListener implements Listener {
if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@ -299,7 +293,6 @@ public class AuthMePlayerListener implements Listener {
if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@ -345,7 +338,6 @@ public class AuthMePlayerListener implements Listener {
} }
if ((spawn.distance(player.getLocation()) > radius)) { if ((spawn.distance(player.getLocation()) > radius)) {
event.getPlayer().teleport(spawn); event.getPlayer().teleport(spawn);
return;
} }
} }
} }
@ -402,7 +394,7 @@ public class AuthMePlayerListener implements Listener {
plugin.management.performJoin(player); plugin.management.performJoin(player);
// Remove the join message while the player isn't logging in // Remove the join message while the player isn't logging in
if ((Settings.enableProtection || Settings.delayJoinMessage) && name != null && event.getJoinMessage() != null) { if ((Settings.enableProtection || Settings.delayJoinMessage) && event.getJoinMessage() != null) {
joinMessage.put(name, event.getJoinMessage()); joinMessage.put(name, event.getJoinMessage());
event.setJoinMessage(null); event.setJoinMessage(null);
} }
@ -412,7 +404,7 @@ public class AuthMePlayerListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPreLogin(AsyncPlayerPreLoginEvent event){ public void onPreLogin(AsyncPlayerPreLoginEvent event) {
final String name = event.getName().toLowerCase(); final String name = event.getName().toLowerCase();
final Player player = Bukkit.getServer().getPlayer(name); final Player player = Bukkit.getServer().getPlayer(name);
@ -437,7 +429,6 @@ public class AuthMePlayerListener implements Listener {
} }
}); });
return;
} }
} }
@ -539,14 +530,14 @@ public class AuthMePlayerListener implements Listener {
if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) { if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) {
checkAntiBotMod(player); checkAntiBotMod(player);
if (Settings.bungee) { if (Settings.bungee) {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try { try {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
out.writeUTF("IP"); out.writeUTF("IP");
player.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
} catch (IOException e) { } catch (IOException e) {
ConsoleLogger.writeStackTrace(e);
} }
player.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
} }
return; return;
} }
@ -561,18 +552,15 @@ public class AuthMePlayerListener implements Listener {
int playersOnline = Utils.getOnlinePlayers().size(); int playersOnline = Utils.getOnlinePlayers().size();
if (playersOnline > plugin.getServer().getMaxPlayers()) { if (playersOnline > plugin.getServer().getMaxPlayers()) {
event.allow(); event.allow();
return;
} else { } else {
final Player pl = plugin.generateKickPlayer(plugin.getServer().getOnlinePlayers()); final Player pl = plugin.generateKickPlayer(plugin.getServer().getOnlinePlayers());
if (pl != null) { if (pl != null) {
pl.kickPlayer(m.send("kick_forvip")[0]); pl.kickPlayer(m.send("kick_forvip")[0]);
event.allow(); event.allow();
return;
} else { } else {
ConsoleLogger.info("The player " + player.getName() + " tryed to join, but the server was full"); ConsoleLogger.info("The player " + player.getName() + " tryed to join, but the server was full");
event.setKickMessage(m.send("kick_fullserver")[0]); event.setKickMessage(m.send("kick_fullserver")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_FULL); event.setResult(PlayerLoginEvent.Result.KICK_FULL);
return;
} }
} }
} }
@ -660,7 +648,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
} }
if (event.getClickedBlock() != null){ if (event.getClickedBlock() != null) {
event.setUseInteractedBlock(org.bukkit.event.Event.Result.DENY); event.setUseInteractedBlock(org.bukkit.event.Event.Result.DENY);
} }
event.setUseItemInHand(org.bukkit.event.Event.Result.DENY); event.setUseItemInHand(org.bukkit.event.Event.Result.DENY);
@ -726,7 +714,6 @@ public class AuthMePlayerListener implements Listener {
@Override @Override
public void run() { public void run() {
player.closeInventory(); player.closeInventory();
;
} }
}, 1); }, 1);
@ -764,7 +751,7 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void playerHitPlayerEvent(EntityDamageByEntityEvent event) { public void playerHitPlayerEvent(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager(); Entity damager = event.getDamager();
if (!(damager instanceof Player)){ if (!(damager instanceof Player)) {
return; return;
} }
@ -912,13 +899,11 @@ public class AuthMePlayerListener implements Listener {
Location spawn = plugin.getSpawnLocation(player); Location spawn = plugin.getSpawnLocation(player);
if (Settings.isSaveQuitLocationEnabled && plugin.database.isAuthAvailable(name)) { if (Settings.isSaveQuitLocationEnabled && plugin.database.isAuthAvailable(name)) {
final PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName(), player.getName()); final PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName(), player.getName());
try { plugin.database.updateQuitLoc(auth);
plugin.database.updateQuitLoc(auth);
} catch (NullPointerException npe) {
}
} }
if (spawn != null && spawn.getWorld() != null) if (spawn != null && spawn.getWorld() != null) {
event.setRespawnLocation(spawn); event.setRespawnLocation(spawn);
}
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)

View File

@ -1,5 +1,9 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -7,11 +11,6 @@ import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.server.ServerListPingEvent;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
public class AuthMeServerListener implements Listener { public class AuthMeServerListener implements Listener {
public AuthMe plugin; public AuthMe plugin;