mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-25 18:48:24 +01:00
Unregister unused events.
This commit is contained in:
parent
4cec7fe5c1
commit
8e3ee8576e
@ -50,6 +50,7 @@ import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
@ -176,6 +177,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
itemDb = new ItemDb(this);
|
||||
confList.add(itemDb);
|
||||
execTimer.mark("Init(Worth/ItemDB)");
|
||||
jails = new Jails(this);
|
||||
confList.add(jails);
|
||||
reload();
|
||||
}
|
||||
catch (YAMLException exception)
|
||||
@ -207,6 +210,39 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
backup = new Backup(this);
|
||||
permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
|
||||
alternativeCommandsHandler = new AlternativeCommandsHandler(this);
|
||||
|
||||
timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 100, 100);
|
||||
|
||||
Economy.setEss(this);
|
||||
execTimer.mark("RegHandler");
|
||||
|
||||
final MetricsStarter metricsStarter = new MetricsStarter(this);
|
||||
if (metricsStarter.getStart() != null && metricsStarter.getStart() == true)
|
||||
{
|
||||
getScheduler().scheduleAsyncDelayedTask(this, metricsStarter, 1);
|
||||
}
|
||||
else if (metricsStarter.getStart() != null && metricsStarter.getStart() == false)
|
||||
{
|
||||
final MetricsListener metricsListener = new MetricsListener(this, metricsStarter);
|
||||
pm.registerEvents(metricsListener, this);
|
||||
}
|
||||
|
||||
final String timeroutput = execTimer.end();
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials load " + timeroutput);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListeners(PluginManager pm) {
|
||||
HandlerList.unregisterAll(this);
|
||||
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Registering Listeners");
|
||||
}
|
||||
|
||||
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
|
||||
pm.registerEvents(serverListener, this);
|
||||
confList.add(serverListener);
|
||||
@ -232,34 +268,9 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
final EssentialsWorldListener worldListener = new EssentialsWorldListener(this);
|
||||
pm.registerEvents(worldListener, this);
|
||||
|
||||
//TODO: Check if this should be here, and not above before reload()
|
||||
jails = new Jails(this);
|
||||
confList.add(jails);
|
||||
|
||||
pm.registerEvents(tntListener, this);
|
||||
|
||||
timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 100, 100);
|
||||
|
||||
Economy.setEss(this);
|
||||
execTimer.mark("RegListeners");
|
||||
|
||||
final MetricsStarter metricsStarter = new MetricsStarter(this);
|
||||
if (metricsStarter.getStart() != null && metricsStarter.getStart() == true)
|
||||
{
|
||||
getScheduler().scheduleAsyncDelayedTask(this, metricsStarter, 1);
|
||||
}
|
||||
else if (metricsStarter.getStart() != null && metricsStarter.getStart() == false)
|
||||
{
|
||||
final MetricsListener metricsListener = new MetricsListener(this, metricsStarter);
|
||||
pm.registerEvents(metricsListener, this);
|
||||
}
|
||||
|
||||
final String timeroutput = execTimer.end();
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials load " + timeroutput);
|
||||
}
|
||||
jails.resetListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -291,6 +302,9 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
|
||||
i18n.updateLocale(settings.getLocale());
|
||||
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
registerListeners(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,8 +28,7 @@ public class EssentialsBlockListener implements Listener
|
||||
return;
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final boolean unlimitedForUser = user.hasUnlimited(is);
|
||||
if (unlimitedForUser && user.getGameMode() == GameMode.SURVIVAL)
|
||||
if (user.hasUnlimited(is) && user.getGameMode() == GameMode.SURVIVAL)
|
||||
{
|
||||
ess.scheduleSyncDelayedTask(
|
||||
new Runnable()
|
||||
|
@ -76,8 +76,18 @@ public class EssentialsPlayerListener implements Listener
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerMove(final PlayerMoveEvent event)
|
||||
{
|
||||
if ((!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
|
||||
|| event.getFrom().getBlockX() == event.getTo().getBlockX()
|
||||
if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Unregistering move listener");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (event.getFrom().getBlockX() == event.getTo().getBlockX()
|
||||
&& event.getFrom().getBlockZ() == event.getTo().getBlockZ()
|
||||
&& event.getFrom().getBlockY() == event.getTo().getBlockY())
|
||||
{
|
||||
|
@ -44,6 +44,10 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
|
||||
final PluginManager pluginManager = ess.getServer().getPluginManager();
|
||||
final JailListener blockListener = new JailListener();
|
||||
pluginManager.registerEvents(blockListener, ess);
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Registering Jail listener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,16 +59,24 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
|
||||
@Override
|
||||
public void finishRead()
|
||||
{
|
||||
if (enabled == false && getCount() > 0)
|
||||
{
|
||||
registerListeners();
|
||||
}
|
||||
checkRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishWrite()
|
||||
{
|
||||
if (enabled == false)
|
||||
checkRegister();
|
||||
}
|
||||
|
||||
public void resetListener()
|
||||
{
|
||||
enabled = false;
|
||||
checkRegister();
|
||||
}
|
||||
|
||||
private void checkRegister()
|
||||
{
|
||||
if (enabled == false && getCount() > 0)
|
||||
{
|
||||
registerListeners();
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,6 +81,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
@ -105,6 +107,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -129,6 +132,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -162,6 +166,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -190,6 +195,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -218,6 +224,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -248,6 +255,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ public class SignEntityListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -53,6 +54,7 @@ public class SignEntityListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,11 +25,15 @@ public class SignPlayerListener implements Listener
|
||||
//Right clicking signs with a block in hand, can now fire cancelled events.
|
||||
//This is because when the block place is cancelled (for example not enough space for the block to be placed),
|
||||
//the event will be marked as cancelled, thus preventing 30% of sign purchases.
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled() || (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR))
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(ess);
|
||||
return;
|
||||
}
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -62,10 +66,10 @@ public class SignPlayerListener implements Listener
|
||||
final int mat = block.getTypeId();
|
||||
if (mat == Material.SIGN_POST.getId() || mat == Material.WALL_SIGN.getId())
|
||||
{
|
||||
final Sign csign = (Sign)block.getState();
|
||||
final String csign = ((Sign)block.getState()).getLine(0);
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (csign.getLine(0).equalsIgnoreCase(sign.getSuccessName()))
|
||||
if (csign.equalsIgnoreCase(sign.getSuccessName()))
|
||||
{
|
||||
sign.onSignInteract(block, event.getPlayer(), ess);
|
||||
event.setCancelled(true);
|
||||
|
Loading…
Reference in New Issue
Block a user