diff options
Diffstat (limited to 'EssentialsAntiBuild/src/net/ess3/antibuild')
6 files changed, 76 insertions, 196 deletions
diff --git a/EssentialsAntiBuild/src/net/ess3/antibuild/AntiBuildHolder.java b/EssentialsAntiBuild/src/net/ess3/antibuild/AntiBuildHolder.java index 981fb0577..d8bf3623b 100644 --- a/EssentialsAntiBuild/src/net/ess3/antibuild/AntiBuildHolder.java +++ b/EssentialsAntiBuild/src/net/ess3/antibuild/AntiBuildHolder.java @@ -9,7 +9,8 @@ public class AntiBuildHolder extends AsyncStorageObjectHolder<AntiBuild> { public AntiBuildHolder(final IEssentials ess) { - super(ess, AntiBuild.class, new File(ess.getPlugin().getDataFolder(), "protect.yml")); + super(ess, AntiBuild.class, new File(ess.getPlugin().getDataFolder(), "antibuild.yml")); + onReload(); } @Override diff --git a/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsAntiBuild.java b/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsAntiBuild.java index 85353b202..0869d706e 100644 --- a/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsAntiBuild.java +++ b/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsAntiBuild.java @@ -1,8 +1,5 @@ package net.ess3.antibuild; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; import java.util.logging.Logger; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; @@ -19,7 +16,7 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild public void onEnable() { final PluginManager pm = this.getServer().getPluginManager(); - final Plugin essPlugin = pm.getPlugin("Essentials"); + final Plugin essPlugin = pm.getPlugin("Essentials-3"); if (essPlugin == null || !essPlugin.isEnabled()) { return; @@ -31,14 +28,6 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild } @Override - public boolean checkProtectionItems(final int id) - { - //final List<Integer> itemList = settingsList.get(list); - //return itemList != null && !itemList.isEmpty() && itemList.contains(id); - return false; - } - - @Override public EssentialsConnect getEssentialsConnect() { return ess; diff --git a/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsAntiBuildListener.java index 2de39ffb5..d57b05ce4 100644 --- a/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsAntiBuildListener.java @@ -4,6 +4,7 @@ import java.util.logging.Level; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.api.IUser; +import net.ess3.permissions.MaterialDotStarPermission; import net.ess3.user.User; import org.bukkit.Material; import org.bukkit.block.Block; @@ -33,7 +34,7 @@ public class EssentialsAntiBuildListener implements Listener this.ess = antib.getEssentialsConnect().getEssentials(); } -/* private boolean metaPermCheck(final User user, final String action, final Block block) + /*private boolean metaPermCheck(final User user, final String action, final Block block) { if (block == null) { @@ -66,27 +67,23 @@ public class EssentialsAntiBuildListener implements Listener } return user.isAuthorized(blockPerm); - } + }*/ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPlace(final BlockPlaceEvent event) - { - final AntiBuildHolder ab = antib.getSettings(); - ab.acquireReadLock(); + { final IUser user = ess.getUserMap().getUser(event.getPlayer()); final Block block = event.getBlockPlaced(); final int typeId = block.getTypeId(); final Material type = block.getType(); - try - { - - if (ab.getData().isBuild() - && !user.canBuild() && !user.hasPermission("essentials.build") - && !Permissions.getPlacePermission(type).isAuthorized(user)) + if (antib.getSettings().getData().isDisableBuild() + //&& !user.canBuild() + && !Permissions.BUILD.isAuthorized(user) + && !Permissions.PLACEMENT.isAuthorized(user, block)) //metaPermCheck(user, "place", block)) todo - double check metadata { - if (ab.getData().isWarnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildPlace", type.toString())); } @@ -94,10 +91,9 @@ public class EssentialsAntiBuildListener implements Listener return; } - if (ab.getData().getBlacklist().getPlacement().contains(type) && !Permissions.BLACKLIST_ALLOWPLACEMENT.isAuthorized(user)) - //antib.checkProtectionItems(AntiBuildConfig.blacklist_placement, typeId) && !user.isAuthorized("essentials.protect.exemptplacement")) + if (antib.getSettings().getData().getBlacklist().getPlacement().contains(type) && !Permissions.BLACKLIST_ALLOWPLACEMENT.isAuthorized(user)) { - if (ab.getData().isWarnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildPlace", type.toString())); } @@ -105,35 +101,27 @@ public class EssentialsAntiBuildListener implements Listener return; } - if (ab.getData().getAlert().getAlertOnPlacement().contains(type) + if (antib.getSettings().getData().getAlert().getAlertOnPlacement().contains(type) && !Permissions.ALERTS_NOTRIGGER.isAuthorized(user)) { antib.getEssentialsConnect().alert(user, type.toString(), _("alertPlaced")); - } - } - finally - { - ab.unlock(); - } + } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(final BlockBreakEvent event) { - final AntiBuildHolder ab = antib.getSettings(); - ab.acquireReadLock(); final IUser user = ess.getUserMap().getUser(event.getPlayer()); final Block block = event.getBlock(); final int typeId = block.getTypeId(); final Material type = block.getType(); - - try - { - if (ab.getData().isBuild() && !user.canBuild() && !user.isAuthorized("essentials.build") - && !Permissions.getBreakPermission(type).isAuthorized(user)) - //!metaPermCheck(user, "break", block)) + + if (antib.getSettings().getData().isDisableBuild() + //&& !user.canBuild() + && !Permissions.BUILD.isAuthorized(user) + && !Permissions.BREAK.isAuthorized(user, block)) { - if (ab.getData().isWarnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildBreak", type.toString())); } @@ -141,9 +129,9 @@ public class EssentialsAntiBuildListener implements Listener return; } - if (ab.getData().getBlacklist().getBreaking().contains(type) && !Permissions.BLACKLIST_ALLOWBREAK.isAuthorized(user)) + if (antib.getSettings().getData().getBlacklist().getBreaking().contains(type) && !Permissions.BLACKLIST_ALLOWBREAK.isAuthorized(user)) { - if (ab.getData().isWarnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildBreak", type.toString())); } @@ -151,29 +139,26 @@ public class EssentialsAntiBuildListener implements Listener return; } - if (antib.checkProtectionItems(AntiBuildConfig.alert_on_break, typeId) - && !user.isAuthorized("essentials.protect.alerts.notrigger")) + if (antib.getSettings().getData().getAlert().getAlertOnBreak().contains(type) + && !Permissions.ALERTS_NOTRIGGER.isAuthorized(user)) { antib.getEssentialsConnect().alert(user, type.toString(), _("alertBroke")); } - } - finally - { - ab.unlock(); - } } - + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPaintingBreak(final PaintingBreakByEntityEvent event) { final Entity entity = event.getRemover(); if (entity instanceof Player) { - final User user = ess.getUser(entity); - if (antib.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") - && !metaPermCheck(user, "break", Material.PAINTING.getId())) + final IUser user = ess.getUserMap().getUser((Player)entity); + if (antib.getSettings().getData().isDisableBuild() + //&& !user.canBuild() + && !Permissions.BUILD.isAuthorized(user) + && !Permissions.BREAK.isAuthorized(user, Material.PAINTING, null)) { - if (ess.getSettings().warnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildBreak", Material.PAINTING.toString())); } @@ -187,7 +172,7 @@ public class EssentialsAntiBuildListener implements Listener { for (Block block : event.getBlocks()) { - if (antib.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId())) + if (antib.getSettings().getData().getBlacklist().getPiston().contains(block.getType())) { event.setCancelled(true); return; @@ -203,10 +188,9 @@ public class EssentialsAntiBuildListener implements Listener return; } final Block block = event.getRetractLocation().getBlock(); - if (antib.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId())) + if (antib.getSettings().getData().getBlacklist().getPiston().contains(block.getType())) { event.setCancelled(true); - return; } } @@ -214,14 +198,14 @@ public class EssentialsAntiBuildListener implements Listener public void onPlayerInteract(final PlayerInteractEvent event) { // Do not return if cancelled, because the interact event has 2 cancelled states. - final User user = ess.getUser(event.getPlayer()); + final IUser user = ess.getUserMap().getUser(event.getPlayer()); final ItemStack item = event.getItem(); if (item != null - && antib.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getTypeId()) - && !user.isAuthorized("essentials.protect.exemptusage")) + && antib.getSettings().getData().getBlacklist().getUsage().contains(item.getType()) + && !Permissions.BLACKLIST_ALLOWUSAGE.isAuthorized(user)) { - if (ess.getSettings().warnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildUse", item.getType().toString())); } @@ -230,27 +214,29 @@ public class EssentialsAntiBuildListener implements Listener } if (item != null - && antib.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getTypeId()) - && !user.isAuthorized("essentials.protect.alerts.notrigger")) + && antib.getSettings().getData().getAlert().getAlertOnUse().contains(item.getType()) + && !Permissions.ALERTS_NOTRIGGER.isAuthorized(user)) { antib.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed")); } - if (antib.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) + if (antib.getSettings().getData().isDisableUse() + //&& !user.canBuild() + && !Permissions.BUILD.isAuthorized(user)) { - if (event.hasItem() && !metaPermCheck(user, "interact", item.getTypeId(), item.getData().getData())) + if (event.hasItem() && !Permissions.INTERACT.isAuthorized(user, item.getType(), item.getData())) { event.setCancelled(true); - if (ess.getSettings().warnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildUse", item.getType().toString())); } return; } - if (event.hasBlock() && !metaPermCheck(user, "interact", event.getClickedBlock())) + if (event.hasBlock() && !Permissions.INTERACT.isAuthorized(user, event.getClickedBlock())) { event.setCancelled(true); - if (ess.getSettings().warnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildInteract", event.getClickedBlock().getType().toString())); } @@ -265,15 +251,17 @@ public class EssentialsAntiBuildListener implements Listener if (entity instanceof Player) { - final User user = ess.getUser(entity); + final IUser user = ess.getUserMap().getUser((Player)entity); final ItemStack item = event.getRecipe().getResult(); - if (antib.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) + if (antib.getSettings().getData().isDisableUse() + //&& !user.canBuild() + && !Permissions.BUILD.isAuthorized(user)) { - if (!metaPermCheck(user, "craft", item.getTypeId(), item.getData().getData())) + if (!Permissions.CRAFT.isAuthorized(user, item.getType(), item.getData())) { event.setCancelled(true); - if (ess.getSettings().warnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildCraft", item.getType().toString())); } @@ -286,12 +274,14 @@ public class EssentialsAntiBuildListener implements Listener public void onPlayerPickupItem(PlayerPickupItemEvent event) { - final User user = ess.getUser(event.getPlayer()); + final IUser user = ess.getUserMap().getUser(event.getPlayer()); final ItemStack item = event.getItem().getItemStack(); - if (antib.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) + if (antib.getSettings().getData().isDisableUse() + //&& !user.canBuild() + && !Permissions.BUILD.isAuthorized(user)) { - if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getData().getData())) + if (!Permissions.PICKUP.isAuthorized(user, item.getType(), item.getData())) { event.setCancelled(true); event.getItem().setPickupDelay(50); @@ -306,18 +296,19 @@ public class EssentialsAntiBuildListener implements Listener final IUser user = ess.getUserMap().getUser(event.getPlayer()); final ItemStack item = event.getItemDrop().getItemStack(); - if (antib.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) + if (antib.getSettings().getData().isDisableUse() + //&& !user.canBuild() + && !Permissions.BUILD.isAuthorized(user)); { - if (!metaPermCheck(user, "drop", item.getTypeId(), item.getData().getData())) + if (!Permissions.DROP.isAuthorized(user, item.getType(), item.getData())) { event.setCancelled(true); user.getPlayer().updateInventory(); - if (ess.getSettings().warnOnBuildDisallow()) + if (antib.getSettings().getData().isWarnOnBuildDisallow()) { user.sendMessage(_("antiBuildDrop", item.getType().toString())); } } } - } - */ + } } diff --git a/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsConnect.java b/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsConnect.java index b9a669348..042c9a727 100644 --- a/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsConnect.java +++ b/EssentialsAntiBuild/src/net/ess3/antibuild/EssentialsConnect.java @@ -5,6 +5,7 @@ import java.util.logging.Logger; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.api.IUser; +import net.ess3.bukkit.BukkitPlugin; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -22,7 +23,7 @@ public class EssentialsConnect { LOGGER.log(Level.WARNING, _("versionMismatchAll")); } - ess = (IEssentials)essPlugin; + ess = ((BukkitPlugin)essPlugin).getEssentials(); antib = (IAntiBuild)essProtect; antib.setSettings(new AntiBuildHolder(ess)); } diff --git a/EssentialsAntiBuild/src/net/ess3/antibuild/IAntiBuild.java b/EssentialsAntiBuild/src/net/ess3/antibuild/IAntiBuild.java index e65773bd7..599b63a01 100644 --- a/EssentialsAntiBuild/src/net/ess3/antibuild/IAntiBuild.java +++ b/EssentialsAntiBuild/src/net/ess3/antibuild/IAntiBuild.java @@ -5,8 +5,6 @@ import org.bukkit.plugin.Plugin; public interface IAntiBuild extends Plugin { - boolean checkProtectionItems(final int id); - EssentialsConnect getEssentialsConnect(); AntiBuildHolder getSettings(); diff --git a/EssentialsAntiBuild/src/net/ess3/antibuild/Permissions.java b/EssentialsAntiBuild/src/net/ess3/antibuild/Permissions.java index cae97667c..588eebf24 100644 --- a/EssentialsAntiBuild/src/net/ess3/antibuild/Permissions.java +++ b/EssentialsAntiBuild/src/net/ess3/antibuild/Permissions.java @@ -5,6 +5,7 @@ import java.util.Locale; import net.ess3.api.IPermission; import net.ess3.bukkit.PermissionFactory; import net.ess3.permissions.BasePermission; +import net.ess3.permissions.MaterialDotStarPermission; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.permissions.PermissionDefault; @@ -69,113 +70,12 @@ public enum Permissions implements IPermission { return PermissionFactory.checkPermission(sender, this); } - private static EnumMap<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class); - - public static IPermission getPlacePermission(final Material mat) - { - IPermission perm = permissions.get(mat); - if (perm == null) - { - perm = new BasePermission("essentials.place.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) - { - @Override - public PermissionDefault getPermissionDefault() - { - return PermissionDefault.TRUE; - } - }; - permissions.put(mat, perm); - } - return perm; - } - - public static IPermission getBreakPermission(final Material mat) - { - IPermission perm = permissions.get(mat); - if (perm == null) - { - perm = new BasePermission("essentials.break.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) - { - @Override - public PermissionDefault getPermissionDefault() - { - return PermissionDefault.TRUE; - } - }; - permissions.put(mat, perm); - } - return perm; - } - - public static IPermission getInteractPermission(final Material mat) - { - IPermission perm = permissions.get(mat); - if (perm == null) - { - perm = new BasePermission("essentials.interact.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) - { - @Override - public PermissionDefault getPermissionDefault() - { - return PermissionDefault.TRUE; - } - }; - permissions.put(mat, perm); - } - return perm; - } - - public static IPermission getCraftPermission(final Material mat) - { - IPermission perm = permissions.get(mat); - if (perm == null) - { - perm = new BasePermission("essentials.craft.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) - { - @Override - public PermissionDefault getPermissionDefault() - { - return PermissionDefault.TRUE; - } - }; - permissions.put(mat, perm); - } - return perm; - } - - public static IPermission getPickupPermission(final Material mat) - { - IPermission perm = permissions.get(mat); - if (perm == null) - { - perm = new BasePermission("essentials.pickup.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) - { - @Override - public PermissionDefault getPermissionDefault() - { - return PermissionDefault.TRUE; - } - }; - permissions.put(mat, perm); - } - return perm; - } - - public static IPermission getDropPermission(final Material mat) - { - IPermission perm = permissions.get(mat); - if (perm == null) - { - perm = new BasePermission("essentials.drop.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) - { - @Override - public PermissionDefault getPermissionDefault() - { - return PermissionDefault.TRUE; - } - }; - permissions.put(mat, perm); - } - return perm; - } + + public static MaterialDotStarPermission PLACEMENT = new MaterialDotStarPermission("essentials.build.place"); + public static MaterialDotStarPermission BREAK = new MaterialDotStarPermission("essentials.build.break"); + public static MaterialDotStarPermission INTERACT = new MaterialDotStarPermission("essentials.build.interact"); + public static MaterialDotStarPermission CRAFT = new MaterialDotStarPermission("essentials.build.craft"); + public static MaterialDotStarPermission PICKUP = new MaterialDotStarPermission("essentials.build.pickup"); + public static MaterialDotStarPermission DROP = new MaterialDotStarPermission("essentials.build.drop"); + } |