[Fix] Remove vanished players from server list ping (#837) (#841)

Add listener for ServerListPingEvent and remove any vanished players.
Also refactored EssentialsPluginListener serverListener to
pluginListener
This commit is contained in:
md678685 2016-08-27 03:27:52 +01:00 committed by Blinky™
parent 3c0424226e
commit ee64f7c4ff
2 changed files with 36 additions and 3 deletions

View file

@ -282,9 +282,9 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
LOGGER.log(Level.INFO, "Registering Listeners");
}
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
pm.registerEvents(serverListener, this);
confList.add(serverListener);
final EssentialsPluginListener pluginListener = new EssentialsPluginListener(this);
pm.registerEvents(pluginListener, this);
confList.add(pluginListener);
final EssentialsPlayerListener playerListener = new EssentialsPlayerListener(this);
pm.registerEvents(playerListener, this);
@ -307,6 +307,9 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
final EssentialsWorldListener worldListener = new EssentialsWorldListener(this);
pm.registerEvents(worldListener, this);
final EssentialsServerListener serverListener = new EssentialsServerListener(this);
pm.registerEvents(serverListener, this);
pm.registerEvents(tntListener, this);
jails.resetListener();

View file

@ -0,0 +1,30 @@
package com.earth2me.essentials;
import net.ess3.api.IEssentials;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerListPingEvent;
import java.util.Iterator;
public class EssentialsServerListener implements Listener {
private final transient IEssentials ess;
public EssentialsServerListener(final IEssentials ess) {
this.ess = ess;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onServerListPing(final ServerListPingEvent event) {
Iterator<Player> iterator = event.iterator();
while (iterator.hasNext()) {
Player player = iterator.next();
if (ess.getUser(player).isVanished()) {
iterator.remove();
}
}
}
}