diff options
author | snowleo <schneeleo@gmail.com> | 2012-02-05 17:19:32 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2012-02-05 17:19:32 +0100 |
commit | 8ab5bad988f7ad9c8a1fafd504cf108f3ec84cc3 (patch) | |
tree | 2a33da8fbb378cedbb7210ee80edd1f1891efb87 /EssentialsProtect | |
parent | 8080abacd6fc379acba4136d0b854d780f262f4e (diff) | |
download | Essentials-8ab5bad988f7ad9c8a1fafd504cf108f3ec84cc3.tar Essentials-8ab5bad988f7ad9c8a1fafd504cf108f3ec84cc3.tar.gz Essentials-8ab5bad988f7ad9c8a1fafd504cf108f3ec84cc3.tar.lz Essentials-8ab5bad988f7ad9c8a1fafd504cf108f3ec84cc3.tar.xz Essentials-8ab5bad988f7ad9c8a1fafd504cf108f3ec84cc3.zip |
Modified BetterLocation, and new Permission-System
Diffstat (limited to 'EssentialsProtect')
5 files changed, 71 insertions, 60 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java index 0b39920b5..539ff208b 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java @@ -43,7 +43,7 @@ public class EssentialsConnect return ess; } - public void alert(final IUser user, final String item, final String type) + public void alert(final Player user, final String item, final String type) { final Location loc = user.getLocation(); final String warnMessage = _("alertFormat", user.getName(), type, item, @@ -53,7 +53,7 @@ public class EssentialsConnect for (Player p : ess.getServer().getOnlinePlayers()) { final IUser alertUser = ess.getUser(p); - if (alertUser.isAuthorized("essentials.protect.alerts")) + if (Permissions.ALERTS.isAuthorized(alertUser)) { alertUser.sendMessage(warnMessage); } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index cdd0c2543..f69ede53a 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java @@ -2,13 +2,13 @@ package com.earth2me.essentials.protect; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.protect.data.IProtectedBlock; import java.util.ArrayList; import java.util.List; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -34,12 +34,12 @@ public class EssentialsProtectBlockListener implements Listener return; } - final IUser user = ess.getUser(event.getPlayer()); + final Player user = event.getPlayer(); final ProtectHolder settings = prot.getSettings(); settings.acquireReadLock(); try { - if (!user.isAuthorized(Permissions.BUILD)) + if (!Permissions.BUILD.isAuthorized(user)) { event.setCancelled(true); return; @@ -48,13 +48,13 @@ public class EssentialsProtectBlockListener implements Listener final Block blockPlaced = event.getBlockPlaced(); final int id = blockPlaced.getTypeId(); - if (!user.isAuthorized(BlockPlacePermissions.getPermission(blockPlaced.getType()))) + if (!BlockPlacePermissions.getPermission(blockPlaced.getType()).isAuthorized(user)) { event.setCancelled(true); return; } - if (!user.hasPermission("essentials.protect.alerts.notrigger") && + if (!Permissions.ALERTS_NOTRIGGER.isAuthorized(user) && settings.getData().getAlertOnPlacement().contains(blockPlaced.getType())) { prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced")); @@ -72,7 +72,7 @@ public class EssentialsProtectBlockListener implements Listener final List<Block> protect = new ArrayList<Block>(); if ((blockPlaced.getType() == Material.RAILS || blockPlaced.getType() == Material.POWERED_RAIL || blockPlaced.getType() == Material.DETECTOR_RAIL) && settings.getData().getSignsAndRails().isProtectRails() - && user.isAuthorized("essentials.protect")) + && Permissions.RAILS.isAuthorized(user)) { protect.add(blockPlaced); if (settings.getData().getSignsAndRails().isBlockBelow() @@ -81,7 +81,7 @@ public class EssentialsProtectBlockListener implements Listener protect.add(blockPlaced.getRelative(BlockFace.DOWN)); } } - if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN) + /*if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN) && settings.getData().getSignsAndRails().isProtectSigns() && user.isAuthorized("essentials.protect")) { @@ -93,7 +93,7 @@ public class EssentialsProtectBlockListener implements Listener { protect.add(event.getBlockAgainst()); } - } + }*/ for (Block block : protect) { prot.getStorage().protectBlock(block, user.getName()); @@ -144,7 +144,7 @@ public class EssentialsProtectBlockListener implements Listener if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) && event.getPlayer() != null) { - event.setCancelled(ess.getUser(event.getPlayer()).isAuthorized(Permissions.USEFLINTSTEEL)); + event.setCancelled(Permissions.USEFLINTSTEEL.isAuthorized(event.getPlayer())); return; } @@ -267,9 +267,9 @@ public class EssentialsProtectBlockListener implements Listener { return; } - final IUser user = ess.getUser(event.getPlayer()); + final Player user = event.getPlayer(); - if (!user.isAuthorized(Permissions.BUILD)) + if (!Permissions.BUILD.isAuthorized(user)) { event.setCancelled(true); return; @@ -277,7 +277,7 @@ public class EssentialsProtectBlockListener implements Listener final Block block = event.getBlock(); final int typeId = block.getTypeId(); - if (!user.isAuthorized(BlockBreakPermissions.getPermission(block.getType()))) + if (!BlockBreakPermissions.getPermission(block.getType()).isAuthorized(user)) { event.setCancelled(true); return; @@ -288,13 +288,13 @@ public class EssentialsProtectBlockListener implements Listener { final Material type = block.getType(); - if (!user.hasPermission("essentials.protect.alerts.notrigger") && settings.getData().getAlertOnBreak().contains(type)) + if (!Permissions.ALERTS_NOTRIGGER.isAuthorized(user) && settings.getData().getAlertOnBreak().contains(type)) { prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke")); } final IProtectedBlock storage = prot.getStorage(); - if (user.isAuthorized("essentials.protect.admin")) + if (Permissions.ADMIN.isAuthorized(user)) { if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL) { @@ -489,7 +489,7 @@ public class EssentialsProtectBlockListener implements Listener } } - private boolean isProtected(final Block block, final IUser user, final ProtectHolder settings) + private boolean isProtected(final Block block, final Player user, final ProtectHolder settings) { final Material type = block.getType(); if (settings.getData().getSignsAndRails().isProtectSigns()) diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index bba267d41..d99497f15 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.protect; import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.craftbukkit.FakeExplosion; import org.bukkit.Material; import org.bukkit.block.Block; @@ -46,28 +45,28 @@ public class EssentialsProtectEntityListener implements Listener return; } - final IUser user = target instanceof Player ? ess.getUser((Player)target) : null; + final Player user = target instanceof Player ? (Player)target : null; if (target instanceof Player && event instanceof EntityDamageByBlockEvent) { final DamageCause cause = event.getCause(); if (cause == DamageCause.CONTACT - && (user.isAuthorized(Permissions.PREVENTDAMAGE_CONTACT) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_CONTACT.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if (cause == DamageCause.LAVA - && (user.isAuthorized(Permissions.PREVENTDAMAGE_LAVADAMAGE) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_LAVADAMAGE.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if (cause == DamageCause.BLOCK_EXPLOSION - && (user.isAuthorized(Permissions.PREVENTDAMAGE_TNT) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_TNT.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; @@ -78,11 +77,11 @@ public class EssentialsProtectEntityListener implements Listener { final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; final Entity eAttack = edEvent.getDamager(); - final IUser attacker = eAttack instanceof Player ? ess.getUser((Player)eAttack) : null; + final Player attacker = eAttack instanceof Player ? (Player)eAttack : null; // PVP Settings if (target instanceof Player && eAttack instanceof Player - && (!user.isAuthorized(Permissions.PVP) || !attacker.isAuthorized(Permissions.PVP))) + && (!Permissions.PVP.isAuthorized(user) || !Permissions.PVP.isAuthorized(attacker))) { event.setCancelled(true); return; @@ -90,35 +89,35 @@ public class EssentialsProtectEntityListener implements Listener //Creeper explode prevention if (eAttack instanceof Creeper && settings.getData().getPrevent().isCreeperExplosion() - || (user.isAuthorized(Permissions.PREVENTDAMAGE_CREEPER) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + || (Permissions.PREVENTDAMAGE_CREEPER.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) - && (user.isAuthorized(Permissions.PREVENTDAMAGE_FIREBALL) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_FIREBALL.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if (eAttack instanceof TNTPrimed - && (user.isAuthorized(Permissions.PREVENTDAMAGE_TNT) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_TNT.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if (edEvent.getDamager() instanceof Projectile - && ((user.isAuthorized(Permissions.PREVENTDAMAGE_PROJECTILES) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)) + && ((Permissions.PREVENTDAMAGE_PROJECTILES.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)) || (((Projectile)edEvent.getDamager()).getShooter() instanceof Player - && (!user.isAuthorized(Permissions.PVP) - || !ess.getUser((Player)((Projectile)edEvent.getDamager()).getShooter()).isAuthorized(Permissions.PVP))))) + && (!Permissions.PVP.isAuthorized(user) + || !Permissions.PVP.isAuthorized((Player)((Projectile)edEvent.getDamager()).getShooter()))))) { event.setCancelled(true); return; @@ -129,38 +128,38 @@ public class EssentialsProtectEntityListener implements Listener if (target instanceof Player) { if (cause == DamageCause.FALL - && (user.isAuthorized(Permissions.PREVENTDAMAGE_FALL) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_FALL.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if (cause == DamageCause.SUFFOCATION - && (user.isAuthorized(Permissions.PREVENTDAMAGE_SUFFOCATION) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_SUFFOCATION.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK) - && (user.isAuthorized(Permissions.PREVENTDAMAGE_FIRE) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_FIRE.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if (cause == DamageCause.DROWNING - && (user.isAuthorized(Permissions.PREVENTDAMAGE_DROWNING) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_DROWNING.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; } if (cause == DamageCause.LIGHTNING - && (user.isAuthorized(Permissions.PREVENTDAMAGE_LIGHTNING) - && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) + && (Permissions.PREVENTDAMAGE_LIGHTNING.isAuthorized(user) + && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))) { event.setCancelled(true); return; @@ -289,14 +288,14 @@ public class EssentialsProtectEntityListener implements Listener { return; } - final IUser user = ess.getUser((Player)event.getTarget()); + final Player user = (Player)event.getTarget(); if ((event.getReason() == TargetReason.CLOSEST_PLAYER || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.PIG_ZOMBIE_TARGET || event.getReason() == TargetReason.RANDOM_TARGET || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET) - && user.isAuthorized(Permissions.ENTITYTARGET)) + && Permissions.ENTITYTARGET.isAuthorized(user)) { event.setCancelled(true); return; diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java index 7fe1ea33f..a14fde8bc 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.protect; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.api.IUser; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -28,7 +28,7 @@ public class EssentialsProtectPlayerListener implements Listener public void onPlayerInteract(final PlayerInteractEvent event) { // Do not return if cancelled, because the interact event has 2 cancelled states. - final IUser user = ess.getUser(event.getPlayer()); + final Player user = event.getPlayer(); final ProtectHolder settings = prot.getSettings(); settings.acquireReadLock(); @@ -37,7 +37,7 @@ public class EssentialsProtectPlayerListener implements Listener if (event.hasItem() && (event.getItem().getType() == Material.WATER_BUCKET || event.getItem().getType() == Material.LAVA_BUCKET) - && !user.isAuthorized(Permissions.BUILD)) + && !Permissions.BUILD.isAuthorized(user)) { if (settings.getData().isWarnOnBuildDisallow()) { @@ -47,7 +47,7 @@ public class EssentialsProtectPlayerListener implements Listener return; } - if (!user.isAuthorized(Permissions.INTERACT)) + if (!Permissions.INTERACT.isAuthorized(user)) { if (settings.getData().isWarnOnBuildDisallow()) { @@ -59,13 +59,13 @@ public class EssentialsProtectPlayerListener implements Listener final ItemStack item = event.getItem(); if (item != null - && !user.isAuthorized(ItemUsePermissions.getPermission(item.getType()))) + && !ItemUsePermissions.getPermission(item.getType()).isAuthorized(user)) { event.setCancelled(true); return; } - if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK) + if (Permissions.OWNERINFO.isAuthorized(user) && event.getAction() == Action.RIGHT_CLICK_BLOCK) { final StringBuilder stringBuilder = new StringBuilder(); boolean first = true; @@ -86,8 +86,8 @@ public class EssentialsProtectPlayerListener implements Listener } } if (item != null - && !user.hasPermission("essentials.protect.alerts.notrigger") - && settings.getData().getAlertOnUse().contains(item.getType())) + && !Permissions.ALERTS_NOTRIGGER.isAuthorized(user) + && settings.getData().getAlertOnUse().contains(item.getType())) { prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed")); } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java b/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java index 61ac1b295..1ed32ddda 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java @@ -3,17 +3,21 @@ package com.earth2me.essentials.protect; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IPermission; import java.util.Locale; +import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; public enum Permissions implements IPermission { + ALERTS, + ALERTS_NOTRIGGER, + ADMIN, BUILD(PermissionDefault.TRUE), + ENTITYTARGET(PermissionDefault.TRUE), INTERACT(PermissionDefault.TRUE), - USEFLINTSTEEL(PermissionDefault.TRUE), + OWNERINFO, PVP(PermissionDefault.TRUE), - ENTITYTARGET(PermissionDefault.TRUE), PREVENTDAMAGE_FALL(PermissionDefault.FALSE), PREVENTDAMAGE_CREEPER(PermissionDefault.FALSE), PREVENTDAMAGE_CONTACT(PermissionDefault.FALSE), @@ -25,7 +29,9 @@ public enum Permissions implements IPermission PREVENTDAMAGE_FIRE(PermissionDefault.FALSE), PREVENTDAMAGE_DROWNING(PermissionDefault.FALSE), PREVENTDAMAGE_LIGHTNING(PermissionDefault.FALSE), - PREVENTDAMAGE_NONE(PermissionDefault.FALSE); + PREVENTDAMAGE_NONE(PermissionDefault.FALSE), + RAILS(PermissionDefault.TRUE), + USEFLINTSTEEL(PermissionDefault.TRUE); private static final String base = "essentials.protect."; private final String permission; private final PermissionDefault defaultPerm; @@ -66,4 +72,10 @@ public enum Permissions implements IPermission { return this.defaultPerm; } + + @Override + public boolean isAuthorized(CommandSender sender) + { + return sender.hasPermission(getBukkitPermission()); + } } |