mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-26 19:18:29 +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.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.world.WorldLoadEvent;
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
@ -176,6 +177,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
itemDb = new ItemDb(this);
|
itemDb = new ItemDb(this);
|
||||||
confList.add(itemDb);
|
confList.add(itemDb);
|
||||||
execTimer.mark("Init(Worth/ItemDB)");
|
execTimer.mark("Init(Worth/ItemDB)");
|
||||||
|
jails = new Jails(this);
|
||||||
|
confList.add(jails);
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
catch (YAMLException exception)
|
catch (YAMLException exception)
|
||||||
@ -207,6 +210,39 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
backup = new Backup(this);
|
backup = new Backup(this);
|
||||||
permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
|
permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
|
||||||
alternativeCommandsHandler = new AlternativeCommandsHandler(this);
|
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);
|
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
|
||||||
pm.registerEvents(serverListener, this);
|
pm.registerEvents(serverListener, this);
|
||||||
confList.add(serverListener);
|
confList.add(serverListener);
|
||||||
@ -232,34 +268,9 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
final EssentialsWorldListener worldListener = new EssentialsWorldListener(this);
|
final EssentialsWorldListener worldListener = new EssentialsWorldListener(this);
|
||||||
pm.registerEvents(worldListener, 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);
|
pm.registerEvents(tntListener, this);
|
||||||
|
|
||||||
timer = new EssentialsTimer(this);
|
jails.resetListener();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -291,6 +302,9 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
}
|
}
|
||||||
|
|
||||||
i18n.updateLocale(settings.getLocale());
|
i18n.updateLocale(settings.getLocale());
|
||||||
|
|
||||||
|
final PluginManager pm = getServer().getPluginManager();
|
||||||
|
registerListeners(pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,8 +28,7 @@ public class EssentialsBlockListener implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
final boolean unlimitedForUser = user.hasUnlimited(is);
|
if (user.hasUnlimited(is) && user.getGameMode() == GameMode.SURVIVAL)
|
||||||
if (unlimitedForUser && user.getGameMode() == GameMode.SURVIVAL)
|
|
||||||
{
|
{
|
||||||
ess.scheduleSyncDelayedTask(
|
ess.scheduleSyncDelayedTask(
|
||||||
new Runnable()
|
new Runnable()
|
||||||
|
@ -76,8 +76,18 @@ public class EssentialsPlayerListener implements Listener
|
|||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onPlayerMove(final PlayerMoveEvent event)
|
public void onPlayerMove(final PlayerMoveEvent event)
|
||||||
{
|
{
|
||||||
if ((!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
|
if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
|
||||||
|| event.getFrom().getBlockX() == event.getTo().getBlockX()
|
{
|
||||||
|
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().getBlockZ() == event.getTo().getBlockZ()
|
||||||
&& event.getFrom().getBlockY() == event.getTo().getBlockY())
|
&& 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 PluginManager pluginManager = ess.getServer().getPluginManager();
|
||||||
final JailListener blockListener = new JailListener();
|
final JailListener blockListener = new JailListener();
|
||||||
pluginManager.registerEvents(blockListener, ess);
|
pluginManager.registerEvents(blockListener, ess);
|
||||||
|
if (ess.getSettings().isDebug())
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.INFO, "Registering Jail listener");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,16 +59,24 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
|
|||||||
@Override
|
@Override
|
||||||
public void finishRead()
|
public void finishRead()
|
||||||
{
|
{
|
||||||
if (enabled == false && getCount() > 0)
|
checkRegister();
|
||||||
{
|
|
||||||
registerListeners();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finishWrite()
|
public void finishWrite()
|
||||||
{
|
{
|
||||||
if (enabled == false)
|
checkRegister();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetListener()
|
||||||
|
{
|
||||||
|
enabled = false;
|
||||||
|
checkRegister();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkRegister()
|
||||||
|
{
|
||||||
|
if (enabled == false && getCount() > 0)
|
||||||
{
|
{
|
||||||
registerListeners();
|
registerListeners();
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ public class SignBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ public class SignBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
User user = ess.getUser(event.getPlayer());
|
User user = ess.getUser(event.getPlayer());
|
||||||
@ -105,6 +107,7 @@ public class SignBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +132,7 @@ public class SignBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,6 +166,7 @@ public class SignBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +195,7 @@ public class SignBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +224,7 @@ public class SignBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,6 +255,7 @@ public class SignBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ public class SignEntityListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ public class SignEntityListener implements Listener
|
|||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled())
|
if (ess.getSettings().areSignsDisabled())
|
||||||
{
|
{
|
||||||
|
event.getHandlers().unregister(ess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,11 +25,15 @@ public class SignPlayerListener implements Listener
|
|||||||
//Right clicking signs with a block in hand, can now fire cancelled events.
|
//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),
|
//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.
|
//the event will be marked as cancelled, thus preventing 30% of sign purchases.
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -62,10 +66,10 @@ public class SignPlayerListener implements Listener
|
|||||||
final int mat = block.getTypeId();
|
final int mat = block.getTypeId();
|
||||||
if (mat == Material.SIGN_POST.getId() || mat == Material.WALL_SIGN.getId())
|
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())
|
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||||
{
|
{
|
||||||
if (csign.getLine(0).equalsIgnoreCase(sign.getSuccessName()))
|
if (csign.equalsIgnoreCase(sign.getSuccessName()))
|
||||||
{
|
{
|
||||||
sign.onSignInteract(block, event.getPlayer(), ess);
|
sign.onSignInteract(block, event.getPlayer(), ess);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user