mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
Disable EssProtect emergency mode when Ess loads late (#1954)
Related: EssentialsX/Essentials#1951.
This commit is contained in:
parent
4873beb100
commit
de57a8c602
@ -10,9 +10,16 @@ import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
|
||||
public class EmergencyListener implements Listener {
|
||||
EssentialsProtect plugin;
|
||||
|
||||
EmergencyListener(final EssentialsProtect essProtPlugin) {
|
||||
plugin = essProtPlugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockBurn(final BlockBurnEvent event) {
|
||||
event.setCancelled(true);
|
||||
@ -47,4 +54,11 @@ public class EmergencyListener implements Listener {
|
||||
public void onEntityDamage(final EntityDamageEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginEnabled(final PluginEnableEvent event) {
|
||||
if (event.getPlugin().getName().equals("Essentials")) {
|
||||
plugin.disableEmergencyMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.protect;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -19,6 +20,8 @@ public class EssentialsProtect extends JavaPlugin implements IProtect {
|
||||
private final Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
|
||||
private EssentialsConnect ess = null;
|
||||
|
||||
private final EmergencyListener emListener = new EmergencyListener(this);
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final PluginManager pm = this.getServer().getPluginManager();
|
||||
@ -27,6 +30,12 @@ public class EssentialsProtect extends JavaPlugin implements IProtect {
|
||||
enableEmergencyMode(pm);
|
||||
return;
|
||||
}
|
||||
|
||||
initialize(pm, essPlugin);
|
||||
}
|
||||
|
||||
private void initialize(final PluginManager pm, final Plugin essPlugin) {
|
||||
LOGGER.log(Level.INFO, "Continuing to enable Protect.");
|
||||
ess = new EssentialsConnect(essPlugin, this);
|
||||
|
||||
final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
|
||||
@ -40,13 +49,30 @@ public class EssentialsProtect extends JavaPlugin implements IProtect {
|
||||
}
|
||||
|
||||
private void enableEmergencyMode(final PluginManager pm) {
|
||||
final EmergencyListener emListener = new EmergencyListener();
|
||||
pm.registerEvents(emListener, this);
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors.");
|
||||
}
|
||||
LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now.");
|
||||
LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essentials Protect is in emergency mode now.");
|
||||
}
|
||||
|
||||
void disableEmergencyMode() {
|
||||
final PluginManager pm = this.getServer().getPluginManager();
|
||||
final Plugin essPlugin = pm.getPlugin("Essentials");
|
||||
if (essPlugin == null || !essPlugin.isEnabled()) {
|
||||
LOGGER.log(Level.SEVERE, "Tried to disable emergency mode, but Essentials still isn't enabled!");
|
||||
return;
|
||||
}
|
||||
|
||||
HandlerList.unregisterAll(emListener);
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
player.sendMessage("Essentials Protect is no longer in emergency mode.");
|
||||
}
|
||||
LOGGER.log(Level.SEVERE, "Essentials was loaded late! Essentials Protect is no longer in emergency mode.");
|
||||
|
||||
initialize(pm, essPlugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user