remove useless stuff from the player listener

This commit is contained in:
Gabriele C 2016-05-29 17:10:33 +02:00
parent 52c0c7dd64
commit f5b7246d1d

View File

@ -133,18 +133,21 @@ public class AuthMePlayerListener implements Listener {
* Limit player X and Z movements to 1 block * Limit player X and Z movements to 1 block
* Deny player Y+ movements (allows falling) * Deny player Y+ movements (allows falling)
*/ */
if (event.getFrom().getBlockX() == event.getTo().getBlockX() Location from = event.getFrom();
&& event.getFrom().getBlockZ() == event.getTo().getBlockZ() Location to = event.getTo();
&& event.getFrom().getY() - event.getTo().getY() >= 0) { if (from.getBlockX() == to.getBlockX()
&& from.getBlockZ() == to.getBlockZ()
&& from.getY() - to.getY() >= 0) {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
if (Utils.checkAuth(player)) { if (!shouldCancelEvent(player)) {
return; return;
} }
if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) { if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) {
// "cancel" the event
event.setTo(event.getFrom()); event.setTo(event.getFrom());
if (settings.getProperty(RestrictionSettings.REMOVE_SPEED)) { if (settings.getProperty(RestrictionSettings.REMOVE_SPEED)) {
player.setFlySpeed(0.0f); player.setFlySpeed(0.0f);
@ -231,7 +234,7 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event) { public void onPlayerLogin(PlayerLoginEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (player == null || Utils.isUnrestricted(player)) { if (Utils.isUnrestricted(player)) {
return; return;
} else if (onJoinVerifier.refusePlayerForFullServer(event)) { } else if (onJoinVerifier.refusePlayerForFullServer(event)) {
return; return;
@ -241,7 +244,7 @@ public class AuthMePlayerListener implements Listener {
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
final PlayerAuth auth = dataSource.getAuth(player.getName()); final PlayerAuth auth = dataSource.getAuth(player.getName());
final boolean isAuthAvailable = auth != null; final boolean isAuthAvailable = (auth != null);
try { try {
onJoinVerifier.checkAntibot(name, isAuthAvailable); onJoinVerifier.checkAntibot(name, isAuthAvailable);
@ -257,22 +260,12 @@ public class AuthMePlayerListener implements Listener {
} }
antiBot.handlePlayerJoin(player); antiBot.handlePlayerJoin(player);
if (settings.getProperty(HooksSettings.BUNGEECORD)) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("IP");
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player == null) {
return;
}
if (settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)) { if (settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)) {
event.setQuitMessage(null); event.setQuitMessage(null);
} }
@ -288,16 +281,6 @@ public class AuthMePlayerListener implements Listener {
public void onPlayerKick(PlayerKickEvent event) { public void onPlayerKick(PlayerKickEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player == null) {
return;
}
if (!settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)
&& event.getReason().equals(m.retrieveSingle(MessageKey.USERNAME_ALREADY_ONLINE_ERROR))) {
event.setCancelled(true);
return;
}
if (!antiBot.antibotKicked.contains(player.getName())) { if (!antiBot.antibotKicked.contains(player.getName())) {
management.performQuit(player, true); management.performQuit(player, true);
} }
@ -328,7 +311,7 @@ public class AuthMePlayerListener implements Listener {
public void onPlayerInventoryOpen(InventoryOpenEvent event) { public void onPlayerInventoryOpen(InventoryOpenEvent event) {
final Player player = (Player) event.getPlayer(); final Player player = (Player) event.getPlayer();
if (!ListenerService.shouldCancelEvent(player)) { if (!shouldCancelEvent(player)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -354,10 +337,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
if (Utils.checkAuth(player)) { if (!shouldCancelEvent(player)) {
return;
}
if (pluginHooks.isNpc(player)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -365,7 +345,7 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerHitPlayerEvent(EntityDamageByEntityEvent event) { public void onPlayerHitPlayerEvent(EntityDamageByEntityEvent event) {
if (ListenerService.shouldCancelEvent(event)) { if (shouldCancelEvent(event)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -394,11 +374,12 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onSignChange(SignChangeEvent event) { public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (ListenerService.shouldCancelEvent(player)) { if (shouldCancelEvent(player)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
// TODO: check this, why do we need to save the quit loc?
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) { public void onPlayerRespawn(PlayerRespawnEvent event) {
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) { if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {