Change for where server does not have EpicSpawners installed.

https://github.com/BentoBoxWorld/addon-limits/issues/20
This commit is contained in:
tastybento 2019-05-28 23:27:35 -07:00
parent 4b40d041b2
commit e0ad361c8b
3 changed files with 42 additions and 9 deletions

View File

@ -3,12 +3,14 @@ package bentobox.addon.limits;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.World;
import bentobox.addon.limits.commands.AdminCommand;
import bentobox.addon.limits.commands.PlayerCommand;
import bentobox.addon.limits.listeners.BlockLimitsListener;
import bentobox.addon.limits.listeners.EntityLimitListener;
import bentobox.addon.limits.listeners.EpicSpawnersListener;
import bentobox.addon.limits.listeners.JoinListener;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.GameModeAddon;
@ -55,6 +57,12 @@ public class Limits extends Addon {
registerListener(blockLimitListener);
registerListener(new JoinListener(this));
registerListener(new EntityLimitListener(this));
// Register epic spawners one tick after load
Bukkit.getScheduler().runTask(getPlugin(), () -> {
if (Bukkit.getServer().getPluginManager().getPlugin("EpicSpawners") != null) {
registerListener(new EpicSpawnersListener(this));
}
});
// Done
}

View File

@ -40,8 +40,6 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.util.Util;
import com.songoda.epicspawners.api.events.SpawnerBreakEvent;
/**
* @author tastybento
*
@ -148,13 +146,7 @@ public class BlockLimitsListener implements Listener {
handleBreak(e, e.getPlayer(), e.getBlock());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(SpawnerBreakEvent e) {
Block b = e.getSpawner().getLocation().getBlock();
handleBreak(e, e.getPlayer(), b);
}
private void handleBreak(Cancellable e, Player player, Block b) {
void handleBreak(Cancellable e, Player player, Block b) {
notify(e, User.getInstance(player), process(b, false), b.getType());
// Player breaks a block and there was a redstone dust/repeater/... above
if (b.getRelative(BlockFace.UP).getType() == Material.REDSTONE_WIRE || b.getRelative(BlockFace.UP).getType() == Material.REPEATER || b.getRelative(BlockFace.UP).getType() == Material.COMPARATOR || b.getRelative(BlockFace.UP).getType() == Material.REDSTONE_TORCH) {

View File

@ -0,0 +1,33 @@
package bentobox.addon.limits.listeners;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.songoda.epicspawners.api.events.SpawnerBreakEvent;
import bentobox.addon.limits.Limits;
/**
* @author tastybento
*
*/
public class EpicSpawnersListener implements Listener {
Limits addon;
/**
* @param addon
*/
public EpicSpawnersListener(Limits addon) {
this.addon = addon;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(SpawnerBreakEvent e) {
Block b = e.getSpawner().getLocation().getBlock();
addon.getBlockLimitListener().handleBreak(e, e.getPlayer(), b);
}
}