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 | |
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
98 files changed, 873 insertions, 709 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index ac080af78..8dfd79207 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -19,7 +19,6 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.*; -import com.earth2me.essentials.craftbukkit.BetterLocation; import com.earth2me.essentials.listener.*; import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.register.payment.Methods; @@ -235,7 +234,6 @@ public class Essentials extends JavaPlugin implements IEssentials i18n.onDisable(); Economy.setEss(null); Trade.closeLog(); - BetterLocation.cleanup(); } @Override diff --git a/Essentials/src/com/earth2me/essentials/EssentialsCommandHandler.java b/Essentials/src/com/earth2me/essentials/EssentialsCommandHandler.java index 1c04a5694..0999d2b52 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsCommandHandler.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsCommandHandler.java @@ -113,7 +113,7 @@ public class EssentialsCommandHandler implements ICommandHandler } // Check authorization - if (user != null && !user.isAuthorized(cmd)) + if (sender != null && cmd.isAuthorized(sender)) { LOGGER.log(Level.WARNING, _("deniedAccessCommand", user.getName())); user.sendMessage(_("noAccessCommand")); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java index 66fba3822..58b8ec446 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import java.util.HashSet; import java.util.Iterator; @@ -42,7 +43,7 @@ public class EssentialsTimer implements Runnable settings.unlock(); } // New mail notification - if (user != null && !mailDisabled && user.isAuthorized("essentials.mail") && !user.gotMailInfo()) + if (user != null && !mailDisabled && Permissions.MAIL.isAuthorized(user) && !user.gotMailInfo()) { final List<String> mail = user.getMails(); if (mail != null && !mail.isEmpty()) diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index 775c0df4e..49ab64ea4 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IItemDb; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -77,7 +78,7 @@ public class ItemDb implements IItemDb else { final int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize(); - if (oversizedStackSize > 0 && user.isAuthorized("essentials.oversizedstacks")) + if (oversizedStackSize > 0 && Permissions.OVERSIZEDSTACKS.isAuthorized(user)) { stack.setAmount(oversizedStackSize); } diff --git a/Essentials/src/com/earth2me/essentials/Jails.java b/Essentials/src/com/earth2me/essentials/Jails.java index 8fc504b5c..aa46e56d0 100644 --- a/Essentials/src/com/earth2me/essentials/Jails.java +++ b/Essentials/src/com/earth2me/essentials/Jails.java @@ -65,7 +65,7 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett { throw new Exception(_("jailNotExist")); } - Location loc = getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)); + Location loc = getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)).getBukkitLocation(); if (loc == null || loc.getWorld() == null) { throw new Exception(_("jailNotExist")); @@ -149,9 +149,9 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett { if (getData().getJails() == null) { - getData().setJails(new HashMap<String, Location>()); + getData().setJails(new HashMap<String, com.earth2me.essentials.storage.Location>()); } - getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), loc); + getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.Location(loc)); } finally { diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index acbd9b3d9..78844d7b1 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ITeleport; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.commands.NotEnoughArgumentsException; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.user.CooldownException; import com.earth2me.essentials.user.UserData.TimestampType; import java.util.Calendar; @@ -152,7 +153,7 @@ public class Teleport implements Runnable, ITeleport { try { - user.checkCooldown(TimestampType.LASTTELEPORT, ess.getGroups().getTeleportCooldown(user), !check, "essentials.teleport.cooldown.bypass"); + user.checkCooldown(TimestampType.LASTTELEPORT, ess.getGroups().getTeleportCooldown(user), !check, Permissions.TELEPORT_COOLDOWN_BYPASS); } catch (CooldownException ex) { @@ -210,7 +211,7 @@ public class Teleport implements Runnable, ITeleport chargeFor.isAffordableFor(user); } cooldown(true); - if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass")) + if (delay <= 0 || Permissions.TELEPORT_TIMER_BYPASS.isAuthorized(user)) { cooldown(false); now(target, cause); diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java index f92a1d504..0c3bc8bb2 100644 --- a/Essentials/src/com/earth2me/essentials/Trade.java +++ b/Essentials/src/com/earth2me/essentials/Trade.java @@ -6,6 +6,8 @@ import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.craftbukkit.SetExpFix; +import com.earth2me.essentials.perm.NoCommandCostPermissions; +import com.earth2me.essentials.perm.Permissions; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -63,7 +65,7 @@ public class Trade if (getMoney() != null && mon < getMoney() && getMoney() > 0 - && !user.isAuthorized("essentials.eco.loan")) + && !Permissions.ECO_LOAN.isAuthorized(user)) { throw new ChargeException(_("notEnoughMoney")); } @@ -79,11 +81,10 @@ public class Trade settings.acquireReadLock(); if (command != null && !command.isEmpty() - && !user.isAuthorized("essentials.nocommandcost.all") - && !user.isAuthorized("essentials.nocommandcost." + command) + && !NoCommandCostPermissions.getPermission(command).isAuthorized(user) && mon < settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command) && 0 < settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command) - && !user.isAuthorized("essentials.eco.loan")) + && !Permissions.ECO_LOAN.isAuthorized(user)) { throw new ChargeException(_("notEnoughMoney")); } @@ -135,7 +136,7 @@ public class Trade if (getMoney() != null) { final double mon = user.getMoney(); - if (mon < getMoney() && getMoney() > 0 && !user.isAuthorized("essentials.eco.loan")) + if (mon < getMoney() && getMoney() > 0 && !Permissions.ECO_LOAN.isAuthorized(user)) { throw new ChargeException(_("notEnoughMoney")); } @@ -151,15 +152,14 @@ public class Trade user.updateInventory(); } if (command != null && !command.isEmpty() - && !user.isAuthorized("essentials.nocommandcost.all") - && !user.isAuthorized("essentials.nocommandcost." + command)) + && !NoCommandCostPermissions.getPermission(command).isAuthorized(user)) { @Cleanup final ISettings settings = ess.getSettings(); settings.acquireReadLock(); final double mon = user.getMoney(); final double cost = settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command); - if (mon < cost && cost > 0 && !user.isAuthorized("essentials.eco.loan")) + if (mon < cost && cost > 0 && !Permissions.ECO_LOAN.isAuthorized(user)) { throw new ChargeException(_("notEnoughMoney")); } diff --git a/Essentials/src/com/earth2me/essentials/Warps.java b/Essentials/src/com/earth2me/essentials/Warps.java index 97db07cbc..bbf01678b 100644 --- a/Essentials/src/com/earth2me/essentials/Warps.java +++ b/Essentials/src/com/earth2me/essentials/Warps.java @@ -66,7 +66,7 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps warp.acquireReadLock(); try { - return warp.getData().getLocation(); + return warp.getData().getLocation().getBukkitLocation(); } finally { @@ -77,6 +77,11 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps @Override public void setWarp(final String name, final Location loc) throws Exception { + setWarp(name, new com.earth2me.essentials.storage.Location(loc)); + } + + public void setWarp(final String name, final com.earth2me.essentials.storage.Location loc) throws Exception + { IWarp warp = getObject(name); if (warp == null) { diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java index 4e7b01fc4..942cf6666 100644 --- a/Essentials/src/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/com/earth2me/essentials/api/Economy.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.api; import com.earth2me.essentials.Util; import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.user.User; import java.io.File; import java.util.logging.Level; @@ -141,7 +142,7 @@ public final class Economy { throw new UserDoesNotExistException(name); } - if (balance < 0.0 && !user.isAuthorized("essentials.eco.loan")) + if (balance < 0.0 && !Permissions.ECO_LOAN.isAuthorized(user)) { throw new NoLoanPermittedException(); } diff --git a/Essentials/src/com/earth2me/essentials/api/IPermission.java b/Essentials/src/com/earth2me/essentials/api/IPermission.java index bebf8380e..e993ffe4d 100644 --- a/Essentials/src/com/earth2me/essentials/api/IPermission.java +++ b/Essentials/src/com/earth2me/essentials/api/IPermission.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.api; +import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; @@ -7,6 +8,8 @@ import org.bukkit.permissions.PermissionDefault; public interface IPermission { String getPermission(); + + boolean isAuthorized(CommandSender sender); Permission getBukkitPermission(); diff --git a/Essentials/src/com/earth2me/essentials/api/IUser.java b/Essentials/src/com/earth2me/essentials/api/IUser.java index ea7c8b930..29150e246 100644 --- a/Essentials/src/com/earth2me/essentials/api/IUser.java +++ b/Essentials/src/com/earth2me/essentials/api/IUser.java @@ -13,12 +13,6 @@ import org.bukkit.inventory.ItemStack; public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload, IReplyTo, Comparable<IUser> { - boolean isAuthorized(String node); - - boolean isAuthorized(IPermission node); - - //boolean isAuthorized(IEssentialsCommand cmd); - //boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix); Player getBase(); double getMoney(); @@ -53,7 +47,7 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload, ITeleport getTeleport(); - void checkCooldown(UserData.TimestampType cooldownType, double cooldown, boolean set, String bypassPermission) throws CooldownException; + void checkCooldown(UserData.TimestampType cooldownType, double cooldown, boolean set, IPermission bypassPermission) throws CooldownException; boolean toggleAfk(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index c5f02a990..d238b0ed8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -12,7 +12,7 @@ public class Commandafk extends EssentialsCommand @Override public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length > 0 && user.isAuthorized(Permissions.AFK_OTHERS)) + if (args.length > 0 && Permissions.AFK_OTHERS.isAuthorized(user)) { IUser afkUser = ess.getUser((Player)ess.getServer().matchPlayer(args[0])); if (afkUser != null) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index 73cadde0d..483ed8596 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -23,7 +23,7 @@ public class Commandbalance extends EssentialsCommand public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { final double bal = (args.length < 1 - || !user.isAuthorized(Permissions.BALANCE_OTHERS) + || !Permissions.BALANCE_OTHERS.isAuthorized(user) ? user : getPlayer(args, 0, true)).getMoney(); user.sendMessage(_("balance", Util.formatCurrency(bal, ess))); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index 4e0190b35..5119a53ef 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.user.Ban; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -22,7 +23,7 @@ public class Commandban extends EssentialsCommand final IUser user = getPlayer(args, 0, true); if (user.isOnline()) { - if (user.isAuthorized("essentials.ban.exempt")) + if (Permissions.BAN_EXEMPT.isAuthorized(user)) { sender.sendMessage(_("banExempt")); return; @@ -30,8 +31,7 @@ public class Commandban extends EssentialsCommand } else { - if (sender instanceof Player - && !ess.getUser((Player)sender).isAuthorized("essentials.ban.offline")) + if (Permissions.BAN_OFFLINE.isAuthorized(sender)) { sender.sendMessage(_("banExempt")); return; @@ -57,7 +57,7 @@ public class Commandban extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { final IUser player = ess.getUser(onlinePlayer); - if (player.isAuthorized("essentials.ban.notify")) + if (Permissions.BAN_NOTIFY.isAuthorized(player)) { onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java b/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java index 12b25a14a..3d07107ea 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.block.BlockBreakEvent; @@ -21,7 +22,7 @@ public class Commandbreak extends EssentialsCommand { throw new NoChargeException(); } - if (block.getType() == Material.BEDROCK && !user.isAuthorized("essentials.break.bedrock")) + if (block.getType() == Material.BEDROCK && !Permissions.BREAK_BEDROCK.isAuthorized(user)) { throw new Exception("You are not allowed to destroy bedrock."); //TODO: Translation } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index cd16aa1ee..aaabd7825 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.List; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -13,7 +14,7 @@ public class Commandclearinventory extends EssentialsCommand @Override public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length > 0 && user.isAuthorized("essentials.clearinventory.others")) + if (args.length > 0 && Permissions.CLEARINVENTORY_OTHERS.isAuthorized(user)) { //TODO: Fix fringe user match case. if (args[0].length() >= 3) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java index 5e7438721..8e2b4ed1e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.Locale; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -34,7 +35,7 @@ public class Commanddelhome extends EssentialsCommand expandedArg = args; } - if (expandedArg.length > 1 && (user == null || user.isAuthorized("essentials.delhome.others"))) + if (expandedArg.length > 1 && (user == null || Permissions.DELHOME_OTHERS.isAuthorized(user))) { user = getPlayer(expandedArg, 0, true); name = expandedArg[1]; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java index 37d0fdd1d..28a809844 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.Enchantments; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.EnchantPermissions; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -29,7 +30,7 @@ public class Commandenchant extends EssentialsCommand for (Map.Entry<String, Enchantment> entry : Enchantments.entrySet()) { final String enchantmentName = entry.getValue().getName().toLowerCase(Locale.ENGLISH); - if (enchantmentslist.contains(enchantmentName) || user.isAuthorized("essentials.enchant." + enchantmentName)) + if (enchantmentslist.contains(enchantmentName) || EnchantPermissions.getPermission(enchantmentName).isAuthorized(user)) { enchantmentslist.add(entry.getKey()); //enchantmentslist.add(enchantmentName); @@ -84,7 +85,7 @@ public class Commandenchant extends EssentialsCommand throw new Exception(_("enchantmentNotFound")); } final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); - if (user != null && !user.isAuthorized("essentials.enchant." + enchantmentName)) + if (user != null && !EnchantPermissions.getPermission(enchantmentName).isAuthorized(user)) { throw new Exception(_("enchantmentPerm", enchantmentName)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java index c815c6375..cfaf27c1a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.List; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -12,7 +13,7 @@ public class Commandfeed extends EssentialsCommand @Override protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length > 0 && user.isAuthorized("essentials.feed.others")) + if (args.length > 0 && Permissions.FEED_OTHERS.isAuthorized(user)) { feedOtherPlayers(user, args[0]); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java index dfab50ee6..46365cafc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.Locale; import org.bukkit.GameMode; import org.bukkit.command.CommandSender; @@ -24,7 +25,7 @@ public class Commandgamemode extends EssentialsCommand @Override protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length > 0 && !args[0].trim().isEmpty() && user.isAuthorized("essentials.gamemode.others")) + if (args.length > 0 && !args[0].trim().isEmpty() && Permissions.GAMEMODE_OTHERS.isAuthorized(user)) { gamemodeOtherPlayers(user, args[0]); return; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java index 3ce81b156..a286ce78b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -10,7 +11,7 @@ public class Commandgetpos extends EssentialsCommand @Override public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length > 0 && user.isAuthorized("essentials.getpos.others")) + if (args.length > 0 && Permissions.GETPOS_OTHERS.isAuthorized(user)) { final IUser otherUser = getPlayer(args, 0); outputPosition(user, otherUser.getLocation(), user.getLocation()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 446eff530..2c0a66d60 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.GivePermissions; import java.util.Locale; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -26,9 +27,7 @@ public class Commandgive extends EssentialsCommand final ItemStack stack = ess.getItemDb().get(args[1], giveTo); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); - if (sender instanceof Player - && (!ess.getUser((Player)sender).isAuthorized("essentials.give.item-" + itemname) - && !ess.getUser((Player)sender).isAuthorized("essentials.give.item-" + stack.getTypeId()))) + if (!GivePermissions.getPermission(stack.getType()).isAuthorized(sender)) { throw new Exception(ChatColor.RED + "You are not allowed to spawn the item " + itemname); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index 2530d8674..42968b796 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -22,7 +23,7 @@ public class Commandgod extends EssentialsCommand @Override protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length > 0 && !args[0].trim().isEmpty() && user.isAuthorized("essentials.god.others")) + if (args.length > 0 && !args[0].trim().isEmpty() && Permissions.GOD_OTHERS.isAuthorized(user)) { godOtherPlayers(user, args[0]); return; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index 3e4437aeb..c145efec7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import java.util.List; import org.bukkit.command.CommandSender; @@ -14,15 +15,15 @@ public class Commandheal extends EssentialsCommand public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length > 0 && user.isAuthorized("essentials.heal.others")) + if (args.length > 0 && Permissions.HEAL_OTHERS.isAuthorized(user)) { - user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, "essentials.heal.cooldown.bypass"); + user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, Permissions.HEAL_COOLDOWN_BYPASS); healOtherPlayers(user, args[0]); return; } - user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, "essentials.heal.cooldown.bypass"); + user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, Permissions.HEAL_COOLDOWN_BYPASS); user.setHealth(20); user.setFoodLevel(20); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index 3226c3553..c4b97d59b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.logging.Level; import org.bukkit.entity.Player; @@ -22,7 +23,7 @@ public class Commandhelpop extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { final IUser player = ess.getUser(onlinePlayer); - if (!player.isAuthorized("essentials.helpop.receive")) + if (!Permissions.HELPOP_RECEIVE.isAuthorized(player)) { continue; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index a30c1cc06..89daff45a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.List; import java.util.Locale; import org.bukkit.Location; @@ -24,7 +25,7 @@ public class Commandhome extends EssentialsCommand if (args.length > 0) { nameParts = args[0].split(":"); - if (nameParts[0].length() == args[0].length() || !user.isAuthorized("essentials.home.others")) + if (nameParts[0].length() == args[0].length() || !Permissions.HOME_OTHERS.isAuthorized(user)) { homeName = nameParts[0]; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 9483f2661..a8c8a4828 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.ItemPermissions; import java.util.Locale; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -20,8 +21,7 @@ public class Commanditem extends EssentialsCommand final ItemStack stack = ess.getItemDb().get(args[0], user); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); - if (!user.isAuthorized("essentials.itemspawn.item-" + itemname) - && !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId())) + if (!ItemPermissions.getPermission(stack.getType()).isAuthorized(user)) { throw new Exception(_("cantSpawnItem", itemname)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index ada0c1296..e1c44b606 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,7 +19,7 @@ public class Commandkick extends EssentialsCommand } final IUser user = getPlayer(args, 0); - if (user.isAuthorized("essentials.kick.exempt")) + if (Permissions.KICK_EXEMPT.isAuthorized(user)) { throw new Exception(_("kickExempt")); } @@ -29,7 +30,7 @@ public class Commandkick extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { final IUser player = ess.getUser(onlinePlayer); - if (player.isAuthorized("essentials.kick.notify")) + if (Permissions.KICK_NOTIFY.isAuthorized(player)) { onlinePlayer.sendMessage(_("playerKicked", senderName, user.getName(), kickReason)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index a21e4b38d..1fb3d8011 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.KitPermissions; import com.earth2me.essentials.settings.Kit; import java.util.Collection; import java.util.Locale; @@ -25,7 +26,7 @@ public class Commandkit extends EssentialsCommand { for (String kitName : kitList) { - if (!user.isAuthorized("essentials.kit." + kitName)) + if (!KitPermissions.getPermission(kitName).isAuthorized(user)) { kitList.remove(kitName); } @@ -39,7 +40,7 @@ public class Commandkit extends EssentialsCommand final String kitName = args[0].toLowerCase(Locale.ENGLISH); final Kit kit = ess.getKits().getKit(kitName); - if (!user.isAuthorized("essentials.kit." + kitName)) + if (!KitPermissions.getPermission(kitName).isAuthorized(user)) { throw new Exception(_("noKitPermission", "essentials.kit." + kitName)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 26a070ec2..0e7d38ede 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.*; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -14,14 +15,7 @@ public class Commandlist extends EssentialsCommand public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { boolean showhidden = false; - if (sender instanceof Player) - { - if (ess.getUser((Player)sender).isAuthorized("essentials.list.hidden")) - { - showhidden = true; - } - } - else + if (Permissions.LIST_HIDDEN.isAuthorized(sender)) { showhidden = true; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index c570bb9a4..e99c1916a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.List; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,7 +32,7 @@ public class Commandmail extends EssentialsCommand } if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) { - if (!user.isAuthorized("essentials.mail.send")) + if (!Permissions.MAIL_SEND.isAuthorized(user)) { throw new Exception(_("noPerm", "essentials.mail.send")); } @@ -59,7 +60,7 @@ public class Commandmail extends EssentialsCommand } if (args.length > 1 && "sendall".equalsIgnoreCase(args[0])) { - if (!user.isAuthorized("essentials.mail.sendall")) + if (!Permissions.MAIL_SENDALL.isAuthorized(user)) { throw new Exception(_("noPerm", "essentials.mail.sendall")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index a71656e92..8ac6b10ad 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; public class Commandme extends EssentialsCommand @@ -21,7 +22,7 @@ public class Commandme extends EssentialsCommand } String message = getFinalArg(args, 0); - if (user.isAuthorized("essentials.chat.color")) + if (Permissions.CHAT_COLOR.isAuthorized(user)) { message = Util.replaceColor(message); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmore.java b/Essentials/src/com/earth2me/essentials/commands/Commandmore.java index d28d8e0fe..4a0d41ccc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmore.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmore.java @@ -3,7 +3,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.ItemPermissions; +import com.earth2me.essentials.perm.Permissions; import java.util.Locale; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -30,19 +33,18 @@ public class Commandmore extends EssentialsCommand { settings.unlock(); } - if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks")) + if (stack.getAmount() >= (Permissions.OVERSIZEDSTACKS.isAuthorized(user) ? oversizedStackSize : defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize())) { throw new NoChargeException(); } final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); - if (!user.isAuthorized("essentials.itemspawn.item-" + itemname) - && !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId())) + if (!ItemPermissions.getPermission(stack.getType()).isAuthorized(user)) { throw new Exception(_("cantSpawnItem", itemname)); } - if (user.isAuthorized("essentials.oversizedstacks")) + if (Permissions.OVERSIZEDSTACKS.isAuthorized(user)) { stack.setAmount(oversizedStackSize); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index cd72c34f0..f33adc1ee 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IReplyTo; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.List; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -31,7 +32,7 @@ public class Commandmsg extends EssentialsCommand { throw new Exception(_("voiceSilenced")); } - if (user.isAuthorized("essentials.msg.color")) + if (Permissions.MSG_COLOR.isAuthorized(user)) { message = Util.replaceColor(message); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index 59d401f96..20bd18e2b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -21,7 +22,7 @@ public class Commandmute extends EssentialsCommand @Cleanup final IUser player = getPlayer(args, 0, true); player.acquireReadLock(); - if (!player.getData().isMuted() && player.isAuthorized("essentials.mute.exempt")) + if (!player.getData().isMuted() && Permissions.MUTE_EXEMPT.isAuthorized(player)) { throw new Exception(_("muteExempt")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java index 368dd90a3..901aa5a6f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -43,7 +44,7 @@ public class Commandnear extends EssentialsCommand { } } - if (otherUser == null || user.isAuthorized("essentials.near.others")) + if (otherUser == null || Permissions.NEAR_OTHERS.isAuthorized(user)) { user.sendMessage(_("nearbyPlayers", getLocal(otherUser == null ? user : otherUser, radius))); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index 76aecc2a1..5b863ba01 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.Locale; import lombok.Cleanup; import org.bukkit.Server; @@ -29,7 +30,7 @@ public class Commandnick extends EssentialsCommand } if (args.length > 1) { - if (!user.isAuthorized("essentials.nick.others")) + if (!Permissions.NICK_OTHERS.isAuthorized(user)) { throw new Exception(_("nickOthersPermission")); } @@ -67,7 +68,7 @@ public class Commandnick extends EssentialsCommand private String formatNickname(final IUser user, final String nick) { - if (user == null || user.isAuthorized("essentials.nick.color")) + if (user == null || Permissions.NICK_COLOR.isAuthorized(user)) { return nick.replace('&', '\u00a7').replaceAll("\u00a7+k", ""); } else { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index 78e338722..b450552b1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -71,7 +72,7 @@ public class Commandpowertool extends EssentialsCommand { if (command.startsWith("a:")) { - if (!user.isAuthorized("essentials.powertool.append")) + if (!Permissions.POWERTOOL_APPEND.isAuthorized(user)) { throw new Exception(_("noPerm", "essentials.powertool.append")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java index 62a6fa298..1ad065214 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.DescParseTickFormat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.*; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -40,7 +41,7 @@ public class Commandptime extends EssentialsCommand } IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null; - if ((!users.contains(user) || users.size() > 1) && user != null && !user.isAuthorized("essentials.ptime.others")) + if ((!users.contains(user) || users.size() > 1) && user != null && !Permissions.PTIME_OTHERS.isAuthorized(user)) { user.sendMessage(_("pTimeOthersPermission")); return; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index 06b8f59f6..2088bf086 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IReplyTo; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -26,7 +27,7 @@ public class Commandr extends EssentialsCommand if (sender instanceof Player) { IUser user = ess.getUser((Player)sender); - if (user.isAuthorized("essentials.msg.color")) + if (Permissions.MSG_COLOR.isAuthorized(user)) { message = Util.replaceColor(message); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java index 6ad0d729c..8b124bfb4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java @@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -31,7 +32,7 @@ public class Commandrepair extends EssentialsCommand } if (!item.getEnchantments().isEmpty() - && !user.isAuthorized("essentials.repair.enchanted")) + && !Permissions.REPAIR_ENCHANTED.isAuthorized(user)) { throw new Exception(_("repairEnchanted")); } @@ -52,7 +53,7 @@ public class Commandrepair extends EssentialsCommand final List<String> repaired = new ArrayList<String>(); repairItems(user.getInventory().getContents(), user, repaired); - if (user.isAuthorized("essentials.repair.armor")) + if (Permissions.REPAIR_ARMOR.isAuthorized(user)) { repairItems(user.getInventory().getArmorContents(), user, repaired); } @@ -109,7 +110,7 @@ public class Commandrepair extends EssentialsCommand continue; } if (!item.getEnchantments().isEmpty() - && !user.isAuthorized("essentials.repair.enchanted")) + && !Permissions.REPAIR_ENCHANTED.isAuthorized(user)) { continue; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index 02d1a916f..f2cf9d762 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.HashMap; import java.util.Locale; import lombok.Cleanup; @@ -24,12 +25,12 @@ public class Commandsethome extends EssentialsCommand if (args.length < 2) { - if (user.isAuthorized("essentials.sethome.multiple")) + if (Permissions.SETHOME_MULTIPLE.isAuthorized(user)) { if ("bed".equals(args[0].toLowerCase(Locale.ENGLISH))) { throw new NotEnoughArgumentsException(); } - if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getGroups().getHomeLimit(user)) + if ((user.getHomes().size() < ess.getGroups().getHomeLimit(user)) || (user.getHomes().contains(args[0].toLowerCase(Locale.ENGLISH)))) { user.acquireWriteLock(); @@ -52,7 +53,7 @@ public class Commandsethome extends EssentialsCommand } else { - if (user.isAuthorized("essentials.sethome.others")) + if (Permissions.SETHOME_OTHERS.isAuthorized(user)) { @Cleanup IUser usersHome = ess.getUser(ess.getServer().getPlayer(args[0])); @@ -61,7 +62,7 @@ public class Commandsethome extends EssentialsCommand throw new Exception(_("playerNotFound")); } String name = args[1].toLowerCase(Locale.ENGLISH); - if (!user.isAuthorized("essentials.sethome.multiple")) + if (!Permissions.SETHOME_MULTIPLE.isAuthorized(user)) { name = "home"; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index 23e3b9a7e..93e399d2f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.SpawnerPermissions; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.CreatureSpawner; @@ -36,7 +37,7 @@ public class Commandspawner extends EssentialsCommand user.sendMessage(_("invalidMob")); return; } - if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase())) + if (!SpawnerPermissions.getPermission(mob.name).isAuthorized(user)) { throw new Exception(_("unableToSpawnMob")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 9649a50e4..f2c62c218 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -6,6 +6,7 @@ import com.earth2me.essentials.Mob.MobException; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.SpawnmobPermissions; import java.util.Locale; import java.util.Random; import org.bukkit.DyeColor; @@ -57,7 +58,7 @@ public class Commandspawnmob extends EssentialsCommand throw new Exception(_("invalidMob")); } - if (!user.isAuthorized("essentials.spawnmob." + mob.name.toLowerCase())) + if (!SpawnmobPermissions.getPermission(mob.name).isAuthorized(user)) { throw new Exception(_("noPermToSpawnMob")); } @@ -92,7 +93,7 @@ public class Commandspawnmob extends EssentialsCommand return; } - if (!user.isAuthorized("essentials.spawnmob." + mobMount.name.toLowerCase())) + if (!SpawnmobPermissions.getPermission(mobMount.name).isAuthorized(user)) { throw new Exception(_("noPermToSpawnMob")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java index fb631be20..ab6cbef89 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.user.Ban; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -22,8 +23,7 @@ public class Commandtempban extends EssentialsCommand final IUser user = getPlayer(args, 0, true); if (user.getBase() instanceof OfflinePlayer) { - if (sender instanceof Player - && !ess.getUser((Player)sender).isAuthorized("essentials.tempban.offline")) + if (Permissions.TEMPBAN_OFFLINE.isAuthorized(sender)) { sender.sendMessage(_("tempbanExempt")); return; @@ -31,7 +31,7 @@ public class Commandtempban extends EssentialsCommand } else { - if (user.isAuthorized("essentials.tempban.exempt")) + if (Permissions.TEMPBAN_EXEMPT.isAuthorized(user)) { sender.sendMessage(_("tempbanExempt")); return; @@ -52,7 +52,7 @@ public class Commandtempban extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { final IUser player = ess.getUser(onlinePlayer); - if (player.isAuthorized("essentials.ban.notify")) + if (Permissions.BAN_NOTIFY.isAuthorized(player)) { onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index 991eea80d..0f5e7a1a5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.DescParseTickFormat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.*; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -29,10 +30,9 @@ public class Commandtime extends EssentialsCommand return; } - final IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null; - if (user != null && !user.isAuthorized("essentials.time.set")) + if (Permissions.TIME_SET.isAuthorized(sender)) { - user.sendMessage(_("timeSetPermission")); + sender.sendMessage(_("timeSetPermission")); return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index 4406d5958..daa542975 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import lombok.Cleanup; import org.bukkit.OfflinePlayer; @@ -28,8 +29,7 @@ public class Commandtogglejail extends EssentialsCommand { if (player.getBase() instanceof OfflinePlayer) { - if (sender instanceof Player - && !ess.getUser((Player)sender).isAuthorized("essentials.togglejail.offline")) + if (Permissions.TOGGLEJAIL_OFFLINE.isAuthorized(sender)) { sender.sendMessage(_("mayNotJail")); return; @@ -37,7 +37,7 @@ public class Commandtogglejail extends EssentialsCommand } else { - if (player.isAuthorized("essentials.jail.exempt")) + if (Permissions.JAIL_EXEMPT.isAuthorized(player)) { sender.sendMessage(_("mayNotJail")); return; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index 85c72605a..2652a3a43 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import lombok.Cleanup; import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -34,7 +35,7 @@ public class Commandtp extends EssentialsCommand throw new NoChargeException(); default: - if (!user.isAuthorized("essentials.tpohere")) + if (!Permissions.TPOHERE.isAuthorized(user)) { //TODO: Translate this throw new Exception("You need access to /tpohere to teleport other players."); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index b32158069..d176aef29 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.OfflinePlayer; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -20,7 +21,7 @@ public class Commandtpaccept extends EssentialsCommand final IUser target = user.getTeleportRequester(); if (target.getBase() instanceof OfflinePlayer - || (user.isTeleportRequestHere() && !target.isAuthorized("essentials.tpahere"))) + || (user.isTeleportRequestHere() && !Permissions.TPAHERE.isAuthorized(target))) { throw new Exception(_("noPendingRequest")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java index c7b5312c8..075ac7e17 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java @@ -2,6 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; +import com.earth2me.essentials.perm.Permissions2Handler; import org.bukkit.OfflinePlayer; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -25,7 +27,7 @@ public class Commandtpo extends EssentialsCommand } // Verify permission - if (!player.isHidden() || user.isAuthorized("essentials.teleport.hidden")) + if (!player.isHidden() || Permissions.TELEPORT_HIDDEN.isAuthorized(user)) { user.getTeleport().now(player, false, TeleportCause.COMMAND); user.sendMessage(_("teleporting")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java index bfd52562d..33351eeb7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.OfflinePlayer; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -26,7 +27,7 @@ public class Commandtpohere extends EssentialsCommand } // Verify permission - if (!player.isHidden() || user.isAuthorized("essentials.teleport.hidden")) + if (!player.isHidden() || Permissions.TELEPORT_HIDDEN.isAuthorized(user)) { player.getTeleport().now(user, false, TeleportCause.COMMAND); user.sendMessage(_("teleporting")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java index ebfad6ee8..8c822ff8e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java @@ -3,6 +3,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; +import com.earth2me.essentials.perm.Permissions; +import com.earth2me.essentials.perm.UnlimitedItemPermissions; import java.util.Locale; import java.util.Set; import lombok.Cleanup; @@ -23,7 +25,7 @@ public class Commandunlimited extends EssentialsCommand @Cleanup IUser target = user; - if (args.length > 1 && user.isAuthorized("essentials.unlimited.others")) + if (args.length > 1 && Permissions.UNLIMITED_OTHERS.isAuthorized(user)) { target = getPlayer(args, 1); target.acquireReadLock(); @@ -80,8 +82,7 @@ public class Commandunlimited extends EssentialsCommand stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2)); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); - if (!user.isAuthorized("essentials.unlimited.item-" + itemname) - && !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId())) + if (!UnlimitedItemPermissions.getPermission(stack.getType()).isAuthorized(user)) { throw new Exception(_("unlimitedItemPermission", itemname)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 06a203f85..c5614b798 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -5,6 +5,8 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IWarps; +import com.earth2me.essentials.perm.Permissions; +import com.earth2me.essentials.perm.WarpPermissions; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -21,7 +23,7 @@ public class Commandwarp extends EssentialsCommand { if (args.length == 0 || args[0].matches("[0-9]+")) { - if (!user.isAuthorized("essentials.warp.list")) + if (!Permissions.WARP_LIST.isAuthorized(user)) { throw new Exception(_("warpListPermission")); } @@ -31,7 +33,7 @@ public class Commandwarp extends EssentialsCommand if (args.length > 0) { IUser otherUser = null; - if (args.length == 2 && user.isAuthorized("essentials.warp.otherplayers")) + if (args.length == 2 && Permissions.WARP_OTHERS.isAuthorized(user)) { otherUser = ess.getUser(server.getPlayer(args[1])); if (otherUser == null) @@ -80,7 +82,7 @@ public class Commandwarp extends EssentialsCommand while (iterator.hasNext()) { final String warpName = iterator.next(); - if (!((IUser)sender).isAuthorized("essentials.warp." + warpName)) + if (!WarpPermissions.getPermission(warpName).isAuthorized(sender)) { iterator.remove(); } @@ -111,7 +113,7 @@ public class Commandwarp extends EssentialsCommand final Trade charge = new Trade(commandName, ess); charge.isAffordableFor(user); - if (user.isAuthorized("essentials.warp." + name)) + if (WarpPermissions.getPermission(name).isAuthorized(user)) { user.getTeleport().warp(name, charge, TeleportCause.COMMAND); return; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index 1632722bc..4ec9b9c04 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.Locale; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -22,7 +23,7 @@ public class Commandwhois extends EssentialsCommand boolean showhidden = false; if (sender instanceof Player) { - if (ess.getUser((Player)sender).isAuthorized("essentials.list.hidden")) + if (Permissions.LIST_HIDDEN.isAuthorized(sender)) { showhidden = true; } @@ -67,7 +68,7 @@ public class Commandwhois extends EssentialsCommand sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString())); final String location = user.getData().getGeolocation(); if (location != null - && (sender instanceof Player ? ess.getUser((Player)sender).isAuthorized("essentials.geoip.show") : true)) + && Permissions.GEOIP_SHOW.isAuthorized(sender)) { sender.sendMessage(_("whoisGeoLocation", location)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java index 920900a57..b11aa8bac 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.WorldPermissions; import java.util.List; import org.bukkit.Location; import org.bukkit.World; @@ -49,7 +50,7 @@ public class Commandworld extends EssentialsCommand } - if (!user.isAuthorized("essentials.world." + world.getName())) + if (!WorldPermissions.getPermission(world.getName()).isAuthorized(user)) { user.sendMessage(_("invalidWorld")); //TODO: Make a "world teleport denied" translation throw new NoChargeException(); diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index a70471327..c5b7c5ad9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -21,13 +21,14 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp protected transient IEssentials ess; protected transient IEssentialsModule module; protected transient Server server; - protected final static Logger logger = Logger.getLogger("Minecraft"); + protected transient Logger logger; private transient String permission; private transient Permission bukkitPerm; public void init(final IEssentials ess, final String commandName) { this.ess = ess; + this.logger = ess.getLogger(); this.server = ess.getServer(); this.commandName = commandName; this.permission = "essentials." + commandName; diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/BetterLocation.java b/Essentials/src/com/earth2me/essentials/craftbukkit/BetterLocation.java deleted file mode 100644 index e57a7ddde..000000000 --- a/Essentials/src/com/earth2me/essentials/craftbukkit/BetterLocation.java +++ /dev/null @@ -1,254 +0,0 @@ -package com.earth2me.essentials.craftbukkit; - -import java.lang.ref.WeakReference; -import java.util.*; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.event.world.WorldLoadEvent; -import org.bukkit.event.world.WorldUnloadEvent; - - -public class BetterLocation extends Location -{ - private transient String worldName; - private static BetterLocationListener listener = new BetterLocationListener(); - - public static BetterLocationListener getListener() - { - return listener; - } - - public static void cleanup() - { - synchronized (listener.locationMap) - { - listener.locationMap.clear(); - } - } - - public BetterLocation(final String worldName, final double x, final double y, final double z) - { - super(Bukkit.getWorld(worldName), x, y, z); - this.worldName = worldName; - addToMap(this); - } - - public BetterLocation(final String worldName, final double x, final double y, - final double z, final float yaw, final float pitch) - { - super(Bukkit.getWorld(worldName), x, y, z, yaw, pitch); - this.worldName = worldName; - addToMap(this); - } - - public BetterLocation(final World world, final double x, final double y, final double z) - { - super(world, x, y, z); - if (world == null) - { - throw new WorldNotLoadedException(); - } - this.worldName = world.getName(); - addToMap(this); - } - - public BetterLocation(final World world, final double x, final double y, - final double z, final float yaw, final float pitch) - { - super(world, x, y, z, yaw, pitch); - if (world == null) - { - throw new WorldNotLoadedException(); - } - this.worldName = world.getName(); - addToMap(this); - } - - public BetterLocation(final Location location) - { - super(location.getWorld(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null) - { - throw new WorldNotLoadedException(); - } - this.worldName = location.getWorld().getName(); - addToMap(this); - } - - @Override - public World getWorld() - { - World world = super.getWorld(); - if (world == null) - { - world = Bukkit.getWorld(worldName); - } - if (world == null) - { - throw new WorldNotLoadedException(); - } - else - { - super.setWorld(world); - } - return world; - } - - @Override - public void setWorld(final World world) - { - if (world == null) - { - throw new WorldNotLoadedException(); - } - if (!world.getName().equals(this.worldName)) - { - getListener().removeLocation(this); - this.worldName = world.getName(); - addToMap(this); - } - super.setWorld(world); - } - - public String getWorldName() - { - return worldName; - } - - private void addToMap(final BetterLocation location) - { - synchronized (listener.locationMap) - { - List<WeakReference<Location>> locations = listener.locationMap.get(location.getWorldName()); - if (locations == null) - { - locations = new LinkedList<WeakReference<Location>>(); - listener.locationMap.put(location.getWorldName(), locations); - } - locations.add(new WeakReference<Location>(location)); - } - } - - - public static class WorldNotLoadedException extends RuntimeException - { - public WorldNotLoadedException() - { - super("World is not loaded."); - } - } - - - public static class BetterLocationListener extends org.bukkit.event.world.WorldListener implements Runnable - { - private static Random random = new Random(); - private final transient Map<String, List<WeakReference<Location>>> locationMap = new HashMap<String, List<WeakReference<Location>>>(); - - @Override - public void onWorldLoad(final WorldLoadEvent event) - { - final String worldName = event.getWorld().getName(); - synchronized (locationMap) - { - final List<WeakReference<Location>> locations = locationMap.get(worldName); - if (locations != null) - { - for (final Iterator<WeakReference<Location>> it = locations.iterator(); it.hasNext();) - { - final WeakReference<Location> weakReference = it.next(); - final Location loc = weakReference.get(); - if (loc == null) - { - it.remove(); - } - else - { - loc.setWorld(event.getWorld()); - } - } - } - } - } - - @Override - public void onWorldUnload(final WorldUnloadEvent event) - { - final String worldName = event.getWorld().getName(); - synchronized (locationMap) - { - final List<WeakReference<Location>> locations = locationMap.get(worldName); - if (locations != null) - { - for (final Iterator<WeakReference<Location>> it = locations.iterator(); it.hasNext();) - { - final WeakReference<Location> weakReference = it.next(); - final Location loc = weakReference.get(); - if (loc == null) - { - it.remove(); - } - else - { - loc.setWorld(null); - } - } - } - } - } - - @Override - public void run() - { - synchronized (locationMap) - { - // Pick a world by random - final Collection<List<WeakReference<Location>>> allWorlds = locationMap.values(); - final int randomPick = (allWorlds.isEmpty() ? 0 : random.nextInt(allWorlds.size())); - List<WeakReference<Location>> locations = null; - final Iterator<List<WeakReference<Location>>> iterator = allWorlds.iterator(); - for (int i = 0; iterator.hasNext() && i < randomPick; i++) - { - iterator.next(); - } - if (iterator.hasNext()) - { - locations = iterator.next(); - } - if (locations != null) - { - for (final Iterator<WeakReference<Location>> it = locations.iterator(); it.hasNext();) - { - final WeakReference<Location> weakReference = it.next(); - final Location loc = weakReference.get(); - if (loc == null) - { - it.remove(); - } - } - } - } - } - - private void removeLocation(final BetterLocation location) - { - final String worldName = location.getWorldName(); - synchronized (locationMap) - { - final List<WeakReference<Location>> locations = locationMap.get(worldName); - if (locations != null) - { - for (final Iterator<WeakReference<Location>> it = locations.iterator(); it.hasNext();) - { - final WeakReference<Location> weakReference = it.next(); - final Location loc = weakReference.get(); - if (loc == null || loc == location) - { - it.remove(); - } - } - } - } - } - } -} diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/OfflineBedLocation.java b/Essentials/src/com/earth2me/essentials/craftbukkit/OfflineBedLocation.java index 6e0dcf94a..8a89c7052 100644 --- a/Essentials/src/com/earth2me/essentials/craftbukkit/OfflineBedLocation.java +++ b/Essentials/src/com/earth2me/essentials/craftbukkit/OfflineBedLocation.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.craftbukkit; import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.storage.Location; import java.util.logging.Level; import java.util.logging.Logger; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.WorldNBTStorage; -import org.bukkit.Location; import org.bukkit.craftbukkit.CraftServer; @@ -38,7 +38,7 @@ public class OfflineBedLocation { spawnWorld = cserver.getWorlds().get(0).getName(); } - return new BetterLocation(spawnWorld, playerStorage.getInt("SpawnX"), playerStorage.getInt("SpawnY"), playerStorage.getInt("SpawnZ")); + return new Location(spawnWorld, playerStorage.getInt("SpawnX"), playerStorage.getInt("SpawnY"), playerStorage.getInt("SpawnZ")); } return null; } diff --git a/Essentials/src/com/earth2me/essentials/listener/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/listener/EssentialsEntityListener.java index 26b5a55d1..7db48e9fd 100644 --- a/Essentials/src/com/earth2me/essentials/listener/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/listener/EssentialsEntityListener.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.List; import lombok.Cleanup; import org.bukkit.Material; @@ -98,7 +99,7 @@ public class EssentialsEntityListener extends EntityListener @Cleanup final ISettings settings = ess.getSettings(); settings.acquireReadLock(); - if (user.isAuthorized("essentials.back.ondeath") && !settings.getData().getCommands().isDisabled("back")) + if (Permissions.BACK_ONDEATH.isAuthorized(user) && !settings.getData().getCommands().isDisabled("back")) { user.setLastLocation(); user.sendMessage(_("backAfterDeath")); diff --git a/Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java index 5250fba52..49abd6298 100644 --- a/Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.TextInput; @@ -150,7 +151,7 @@ public class EssentialsPlayerListener implements Listener user.updateDisplayName(); user.getData().setIpAddress(user.getAddress().getAddress().getHostAddress()); user.updateActivity(false); - if (user.isAuthorized("essentials.sleepingignored")) + if (Permissions.SLEEPINGIGNORED.isAuthorized(user)) { user.setSleepingIgnored(true); } @@ -159,7 +160,7 @@ public class EssentialsPlayerListener implements Listener final ISettings settings = ess.getSettings(); settings.acquireReadLock(); - if (!settings.getData().getCommands().isDisabled("motd") && user.isAuthorized("essentials.motd")) + if (!settings.getData().getCommands().isDisabled("motd") && Permissions.MOTD.isAuthorized(user)) { try { @@ -181,7 +182,7 @@ public class EssentialsPlayerListener implements Listener } } - if (!settings.getData().getCommands().isDisabled("mail") && user.isAuthorized("essentials.mail")) + if (!settings.getData().getCommands().isDisabled("mail") && Permissions.MAIL.isAuthorized(user)) { final List<String> mail = user.getData().getMails(); if (mail == null || mail.isEmpty()) @@ -219,7 +220,7 @@ public class EssentialsPlayerListener implements Listener return; } - if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !user.isAuthorized("essentials.joinfullserver")) + if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !Permissions.JOINFULLSERVER.isAuthorized(user)) { event.disallow(Result.KICK_FULL, _("serverFull")); return; @@ -382,7 +383,7 @@ public class EssentialsPlayerListener implements Listener @Cleanup final IUser user = ess.getUser(event.getPlayer()); user.acquireReadLock(); - if (!settings.getData().getWorldOptions(event.getPlayer().getLocation().getWorld().getName()).isGodmode() && !user.isAuthorized("essentials.nogod.override")) + if (!settings.getData().getWorldOptions(event.getPlayer().getLocation().getWorld().getName()).isGodmode() && !Permissions.NOGOD_OVERRIDE.isAuthorized(user)) { if (user.getData().isGodmode()) { diff --git a/Essentials/src/com/earth2me/essentials/perm/AbstractSuperpermsPermission.java b/Essentials/src/com/earth2me/essentials/perm/AbstractSuperpermsPermission.java index a4cef71a3..a6239e1af 100644 --- a/Essentials/src/com/earth2me/essentials/perm/AbstractSuperpermsPermission.java +++ b/Essentials/src/com/earth2me/essentials/perm/AbstractSuperpermsPermission.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.perm; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IPermission; +import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; @@ -23,9 +24,19 @@ public abstract class AbstractSuperpermsPermission implements IPermission } } + /** + * PermissionDefault is OP, if the method is not overwritten. + * @return + */ @Override public PermissionDefault getPermissionDefault() { return PermissionDefault.OP; } + + @Override + public boolean isAuthorized(CommandSender sender) + { + return sender.hasPermission(getBukkitPermission()); + } } diff --git a/Essentials/src/com/earth2me/essentials/perm/BasePermission.java b/Essentials/src/com/earth2me/essentials/perm/BasePermission.java new file mode 100644 index 000000000..4a9c64582 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/BasePermission.java @@ -0,0 +1,18 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; + +public class BasePermission extends AbstractSuperpermsPermission { + protected String permission; + + public BasePermission(String base, String permission) + { + this.permission = base + permission; + + } + + public String getPermission() + { + return permission; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/EnchantPermissions.java b/Essentials/src/com/earth2me/essentials/perm/EnchantPermissions.java new file mode 100644 index 000000000..debb4a979 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/EnchantPermissions.java @@ -0,0 +1,23 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + + +public class EnchantPermissions +{ + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String enchantName) + { + IPermission perm = permissions.get(enchantName); + if (perm == null) + { + perm = new BasePermission("essentials.enchant.",enchantName.toLowerCase(Locale.ENGLISH)); + permissions.put(enchantName, perm); + } + return perm; + } +}
\ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/perm/GivePermissions.java b/Essentials/src/com/earth2me/essentials/perm/GivePermissions.java new file mode 100644 index 000000000..0748fe707 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/GivePermissions.java @@ -0,0 +1,30 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.EnumMap; +import java.util.Locale; +import java.util.Map; +import org.bukkit.Material; +import org.bukkit.permissions.PermissionDefault; + +public class GivePermissions { + private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class); + + public static IPermission getPermission(final Material mat) + { + IPermission perm = permissions.get(mat); + if (perm == null) + { + perm = new BasePermission("essentials.give.item-", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) + { + @Override + public PermissionDefault getPermissionDefault() + { + return PermissionDefault.TRUE; + } + }; + permissions.put(mat, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/GroupsPermissions.java b/Essentials/src/com/earth2me/essentials/perm/GroupsPermissions.java new file mode 100644 index 000000000..8305c0daa --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/GroupsPermissions.java @@ -0,0 +1,23 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + + +public class GroupsPermissions +{ + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String groupName) + { + IPermission perm = permissions.get(groupName); + if (perm == null) + { + perm = new BasePermission("essentials.groups.",groupName.toLowerCase(Locale.ENGLISH)); + permissions.put(groupName, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/HelpPermissions.java b/Essentials/src/com/earth2me/essentials/perm/HelpPermissions.java new file mode 100644 index 000000000..8079201b0 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/HelpPermissions.java @@ -0,0 +1,23 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + + +public class HelpPermissions +{ + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String pluginName) + { + IPermission perm = permissions.get(pluginName); + if (perm == null) + { + perm = new BasePermission("essentials.help.", pluginName.toLowerCase(Locale.ENGLISH)); + permissions.put(pluginName, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/ItemPermissions.java b/Essentials/src/com/earth2me/essentials/perm/ItemPermissions.java new file mode 100644 index 000000000..b36e5643d --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/ItemPermissions.java @@ -0,0 +1,32 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.EnumMap; +import java.util.Locale; +import java.util.Map; +import org.bukkit.Material; +import org.bukkit.permissions.PermissionDefault; + + +public class ItemPermissions +{ + private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class); + + public static IPermission getPermission(final Material mat) + { + IPermission perm = permissions.get(mat); + if (perm == null) + { + perm = new BasePermission("essentials.itemspawn.item-", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) + { + @Override + public PermissionDefault getPermissionDefault() + { + return PermissionDefault.TRUE; + } + }; + permissions.put(mat, perm); + } + return perm; + } +}
\ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/perm/KitPermissions.java b/Essentials/src/com/earth2me/essentials/perm/KitPermissions.java new file mode 100644 index 000000000..5440436d0 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/KitPermissions.java @@ -0,0 +1,31 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import org.bukkit.permissions.PermissionDefault; + + +public class KitPermissions +{ + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String kitName) + { + IPermission perm = permissions.get(kitName); + if (perm == null) + { + perm = new BasePermission("essentials.kit.", kitName.toLowerCase(Locale.ENGLISH)) + { + @Override + public PermissionDefault getPermissionDefault() + { + return PermissionDefault.TRUE; + } + }; + permissions.put(kitName, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/NoCommandCostPermissions.java b/Essentials/src/com/earth2me/essentials/perm/NoCommandCostPermissions.java new file mode 100644 index 000000000..286240dfa --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/NoCommandCostPermissions.java @@ -0,0 +1,23 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + + +public class NoCommandCostPermissions +{ + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String command) + { + IPermission perm = permissions.get(command); + if (perm == null) + { + perm = new BasePermission("essentials.nocommandcost.", command.toLowerCase(Locale.ENGLISH)); + permissions.put(command, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/Permissions.java b/Essentials/src/com/earth2me/essentials/perm/Permissions.java index 80b6abf56..b5bf00edb 100644 --- a/Essentials/src/com/earth2me/essentials/perm/Permissions.java +++ b/Essentials/src/com/earth2me/essentials/perm/Permissions.java @@ -3,14 +3,73 @@ package com.earth2me.essentials.perm; 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 { + AFK, + AFK_KICKEXEMPT, AFK_OTHERS, - BALANCE_OTHERS; + BACK_ONDEATH, + BALANCE_OTHERS, + BAN_EXEMPT, + BAN_NOTIFY, + BAN_OFFLINE, + BREAK_BEDROCK, + CHAT_COLOR, + CHAT_SPY, + CLEARINVENTORY_OTHERS, + DELHOME_OTHERS, + ECO_LOAN(PermissionDefault.FALSE), + FEED_OTHERS, + GAMEMODE_OTHERS, + GEOIP_HIDE(PermissionDefault.FALSE), + GEOIP_SHOW(PermissionDefault.TRUE), + GETPOS_OTHERS, + GOD_OTHERS, + HEAL_COOLDOWN_BYPASS, + HEAL_OTHERS, + HELPOP_RECEIVE, + HOME_OTHERS, + JAIL_EXEMPT, + JOINFULLSERVER, + KICK_EXEMPT, + KICK_NOTIFY, + LIST_HIDDEN, + MAIL, + MAIL_SEND, + MAIL_SENDALL, + MOTD, + MSG_COLOR, + MUTE_EXEMPT, + NEAR_OTHERS, + NICK_COLOR, + NICK_OTHERS, + NOGOD_OVERRIDE, + OVERSIZEDSTACKS(PermissionDefault.FALSE), + POWERTOOL_APPEND, + PTIME_OTHERS, + REPAIR_ARMOR, + REPAIR_ENCHANTED, + SETHOME_MULTIPLE, + SETHOME_OTHERS, + SLEEPINGIGNORED, + SPAWN_OTHERS, + TELEPORT_COOLDOWN_BYPASS, + TELEPORT_HIDDEN, + TELEPORT_TIMER_BYPASS, + TEMPBAN_EXEMPT, + TEMPBAN_OFFLINE, + TIME_SET, + TOGGLEJAIL_OFFLINE, + TPAHERE, + TPOHERE, + UNLIMITED_OTHERS, + WARP_LIST(PermissionDefault.TRUE), + WARP_OTHERS; private static final String base = "essentials."; private final String permission; private final PermissionDefault defaultPerm; @@ -51,4 +110,10 @@ public enum Permissions implements IPermission { return this.defaultPerm; } + + @Override + public boolean isAuthorized(CommandSender sender) + { + return sender.hasPermission(getBukkitPermission()); + } } diff --git a/Essentials/src/com/earth2me/essentials/perm/SpawnerPermissions.java b/Essentials/src/com/earth2me/essentials/perm/SpawnerPermissions.java new file mode 100644 index 000000000..2e70d9dcf --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/SpawnerPermissions.java @@ -0,0 +1,23 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + + +public class SpawnerPermissions +{ + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String mobName) + { + IPermission perm = permissions.get(mobName); + if (perm == null) + { + perm = new BasePermission("essentials.spawner.", mobName.toLowerCase(Locale.ENGLISH).replace("_", "")); + permissions.put(mobName, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/SpawnmobPermissions.java b/Essentials/src/com/earth2me/essentials/perm/SpawnmobPermissions.java new file mode 100644 index 000000000..4535ab4d4 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/SpawnmobPermissions.java @@ -0,0 +1,21 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public class SpawnmobPermissions { + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String mobName) + { + IPermission perm = permissions.get(mobName); + if (perm == null) + { + perm = new BasePermission("essentials.spawnmob.", mobName.toLowerCase(Locale.ENGLISH).replace("_", "")); + permissions.put(mobName, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/UnlimitedItemPermissions.java b/Essentials/src/com/earth2me/essentials/perm/UnlimitedItemPermissions.java new file mode 100644 index 000000000..e3e8d9c65 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/UnlimitedItemPermissions.java @@ -0,0 +1,23 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.EnumMap; +import java.util.Locale; +import java.util.Map; +import org.bukkit.Material; + +public class UnlimitedItemPermissions +{ + private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class); + + public static IPermission getPermission(final Material mat) + { + IPermission perm = permissions.get(mat); + if (perm == null) + { + perm = new BasePermission("essentials.unlimited.item-", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")); + permissions.put(mat, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/WarpPermissions.java b/Essentials/src/com/earth2me/essentials/perm/WarpPermissions.java new file mode 100644 index 000000000..ffd3e10b8 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/WarpPermissions.java @@ -0,0 +1,31 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import org.bukkit.permissions.PermissionDefault; + + +public class WarpPermissions +{ + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String warpName) + { + IPermission perm = permissions.get(warpName); + if (perm == null) + { + perm = new BasePermission("essentials.warp.", warpName.toLowerCase(Locale.ENGLISH)) + { + @Override + public PermissionDefault getPermissionDefault() + { + return PermissionDefault.TRUE; + } + }; + permissions.put(warpName, perm); + } + return perm; + } +}
\ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/perm/WorldPermissions.java b/Essentials/src/com/earth2me/essentials/perm/WorldPermissions.java new file mode 100644 index 000000000..b67c11e63 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/WorldPermissions.java @@ -0,0 +1,22 @@ +package com.earth2me.essentials.perm; + +import com.earth2me.essentials.api.IPermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public class WorldPermissions +{ + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String worldName) + { + IPermission perm = permissions.get(worldName); + if (perm == null) + { + perm = new BasePermission("essentials.world.", worldName.toLowerCase(Locale.ENGLISH)); + permissions.put(worldName, perm); + } + return perm; + } +} diff --git a/Essentials/src/com/earth2me/essentials/settings/GroupsHolder.java b/Essentials/src/com/earth2me/essentials/settings/GroupsHolder.java index b04ea1433..7c5403c7b 100644 --- a/Essentials/src/com/earth2me/essentials/settings/GroupsHolder.java +++ b/Essentials/src/com/earth2me/essentials/settings/GroupsHolder.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IGroups; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.GroupsPermissions; import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import java.io.File; import java.text.MessageFormat; @@ -28,25 +29,7 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG { return new File(ess.getDataFolder(), "groups.yml"); } - - public void registerPermissions() - { - acquireReadLock(); - try - { - final Map<String, GroupOptions> groups = getData().getGroups(); - if (groups == null || groups.isEmpty()) - { - return; - } - Util.registerPermissions("essentials.groups", groups.keySet(), true, ess); - } - finally - { - unlock(); - } - } - + public Collection<GroupOptions> getGroups(final IUser player) { acquireReadLock(); @@ -60,7 +43,7 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG final ArrayList<GroupOptions> list = new ArrayList(); for (Entry<String, GroupOptions> entry : groups.entrySet()) { - if (player.isAuthorized("essentials.groups." + entry.getKey())) + if (GroupsPermissions.getPermission(entry.getKey()).isAuthorized(player)) { if(entry.getValue() != null) { diff --git a/Essentials/src/com/earth2me/essentials/settings/Jails.java b/Essentials/src/com/earth2me/essentials/settings/Jails.java index 4f9b79197..3adb4ec1e 100644 --- a/Essentials/src/com/earth2me/essentials/settings/Jails.java +++ b/Essentials/src/com/earth2me/essentials/settings/Jails.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.settings; +import com.earth2me.essentials.storage.Location; import com.earth2me.essentials.storage.MapValueType; import com.earth2me.essentials.storage.StorageObject; import java.util.HashMap; import java.util.Map; import lombok.Data; import lombok.EqualsAndHashCode; -import org.bukkit.Location; @Data diff --git a/Essentials/src/com/earth2me/essentials/settings/Locations.java b/Essentials/src/com/earth2me/essentials/settings/Locations.java deleted file mode 100644 index 7e7f1a63d..000000000 --- a/Essentials/src/com/earth2me/essentials/settings/Locations.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.earth2me.essentials.settings; - -import com.earth2me.essentials.storage.MapValueType; -import com.earth2me.essentials.storage.StorageObject; -import java.util.HashMap; -import java.util.Map; -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.bukkit.Location; - - -@Data -@EqualsAndHashCode(callSuper = false) -public class Locations implements StorageObject -{ - @MapValueType(Location.class) - Map<String, Location> jails = new HashMap<String, Location>(); - @MapValueType(Location.class) - Map<String, Location> warps = new HashMap<String, Location>(); - @MapValueType(Location.class) - Map<String, Location> spawns = new HashMap<String, Location>(); -} diff --git a/Essentials/src/com/earth2me/essentials/settings/Spawns.java b/Essentials/src/com/earth2me/essentials/settings/Spawns.java index c35323dcd..451ef49b1 100644 --- a/Essentials/src/com/earth2me/essentials/settings/Spawns.java +++ b/Essentials/src/com/earth2me/essentials/settings/Spawns.java @@ -1,13 +1,13 @@ package com.earth2me.essentials.settings; import com.earth2me.essentials.storage.Comment; +import com.earth2me.essentials.storage.Location; import com.earth2me.essentials.storage.MapValueType; import com.earth2me.essentials.storage.StorageObject; import java.util.HashMap; import java.util.Map; import lombok.Data; import lombok.EqualsAndHashCode; -import org.bukkit.Location; @Data diff --git a/Essentials/src/com/earth2me/essentials/settings/Warp.java b/Essentials/src/com/earth2me/essentials/settings/Warp.java index 20a252afb..f9c506b58 100644 --- a/Essentials/src/com/earth2me/essentials/settings/Warp.java +++ b/Essentials/src/com/earth2me/essentials/settings/Warp.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.settings; +import com.earth2me.essentials.storage.Location; import com.earth2me.essentials.storage.StorageObject; import lombok.Data; import lombok.EqualsAndHashCode; -import org.bukkit.Location; @Data @EqualsAndHashCode(callSuper = false) diff --git a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java index 95cf9efa4..9d140a85f 100644 --- a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java +++ b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java @@ -1,13 +1,11 @@ package com.earth2me.essentials.storage; import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.craftbukkit.BetterLocation; import java.lang.reflect.Field; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -280,11 +278,12 @@ public class BukkitConstructor extends Constructor { return null; } - return new BetterLocation(worldName, x, y, z, yaw, pitch); + return new Location(worldName, x, y, z, yaw, pitch); } return super.construct(node); } + @Override protected Object constructJavaBean2ndStep(final MappingNode node, final Object object) { Map<Class<? extends Object>, TypeDescription> typeDefinitions; diff --git a/Essentials/src/com/earth2me/essentials/storage/Location.java b/Essentials/src/com/earth2me/essentials/storage/Location.java new file mode 100644 index 000000000..550a06ca4 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/storage/Location.java @@ -0,0 +1,111 @@ +package com.earth2me.essentials.storage; + +import java.lang.ref.WeakReference; +import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.World; + + +public class Location +{ + private WeakReference<org.bukkit.Location> location; + private final String worldname; + private UUID worldUID = null; + private final double x; + private final double y; + private final double z; + private final float yaw; + private final float pitch; + + public Location(org.bukkit.Location loc) + { + location = new WeakReference<org.bukkit.Location>(loc); + worldname = loc.getWorld().getName(); + worldUID = loc.getWorld().getUID(); + x = loc.getX(); + y = loc.getY(); + z = loc.getZ(); + yaw = loc.getYaw(); + pitch = loc.getPitch(); + } + + public Location(String worldname, double x, double y, double z, float yaw, float pitch) + { + this.worldname = worldname; + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + } + + public Location(String worldname, double x, double y, double z) + { + this.worldname = worldname; + this.x = x; + this.y = y; + this.z = z; + this.yaw = 0f; + this.pitch = 0f; + } + + public org.bukkit.Location getBukkitLocation() throws WorldNotLoadedException + { + + org.bukkit.Location loc = location == null ? null : location.get(); + if (loc == null) + { + World world = null; + if (worldUID != null) { + world = Bukkit.getWorld(worldUID); + } + if (world == null) { + world = Bukkit.getWorld(worldname); + } + if (world == null) { + throw new WorldNotLoadedException(worldname); + } + loc = new org.bukkit.Location(world, getX(), getY(), getZ(), getYaw(), getPitch()); + location = new WeakReference<org.bukkit.Location>(loc); + } + return loc; + } + + public String getWorldName() + { + return worldname; + } + + public double getX() + { + return x; + } + + public double getY() + { + return y; + } + + public double getZ() + { + return z; + } + + public float getYaw() + { + return yaw; + } + + public float getPitch() + { + return pitch; + } + + public static class WorldNotLoadedException extends Exception + { + public WorldNotLoadedException(String worldname) + { + super("World "+worldname+" is not loaded."); + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java b/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java index 0b741eda1..cd9b04549 100644 --- a/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java +++ b/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.storage; -import com.earth2me.essentials.craftbukkit.BetterLocation; import java.io.PrintWriter; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -12,7 +11,6 @@ import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -330,14 +328,7 @@ public class YamlStorageWriter implements IStorageWriter writer.println(); writeIndention(depth); writer.print("world: "); - if (entry instanceof BetterLocation) - { - writeScalar(((BetterLocation)entry).getWorldName()); - } - else - { - writeScalar(entry.getWorld().getName()); - } + writeScalar(entry.getWorldName()); writeIndention(depth); writer.print("x: "); writeScalar(entry.getX()); diff --git a/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java b/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java index 7d8fc78d0..78060ccb5 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.HelpPermissions; import java.io.IOException; import java.util.*; import java.util.logging.Level; @@ -53,7 +54,7 @@ public class HelpInput implements IText if (pluginName.contains("essentials")) { final String node = "essentials." + k.getKey(); - if (!settings.getData().getCommands().isDisabled(k.getKey()) && user.isAuthorized(node)) + if (!settings.getData().getCommands().isDisabled(k.getKey()) && user.hasPermission(node)) { lines.add("§c" + k.getKey() + "§7: " + k.getValue().get(DESCRIPTION)); } @@ -72,7 +73,7 @@ public class HelpInput implements IText { permissions = value.get(PERMISSIONS); } - if (user.isAuthorized("essentials.help." + pluginName)) + if (HelpPermissions.getPermission(pluginName).isAuthorized(user)) { lines.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); } @@ -81,7 +82,7 @@ public class HelpInput implements IText boolean enabled = false; for (Object o : (List<Object>)permissions) { - if (o instanceof String && user.isAuthorized(o.toString())) + if (o instanceof String && user.hasPermission(o.toString())) { enabled = true; break; @@ -94,7 +95,7 @@ public class HelpInput implements IText } else if (permissions instanceof String && !"".equals(permissions)) { - if (user.isAuthorized(permissions.toString())) + if (user.hasPermission(permissions.toString())) { lines.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); } diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java index b26e8d83a..1f64b0b05 100644 --- a/Essentials/src/com/earth2me/essentials/user/User.java +++ b/Essentials/src/com/earth2me/essentials/user/User.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.Teleport; import com.earth2me.essentials.Util; import com.earth2me.essentials.api.*; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; +import com.earth2me.essentials.perm.Permissions; import com.earth2me.essentials.register.payment.Method; import java.util.Calendar; import java.util.GregorianCalendar; @@ -76,41 +77,7 @@ public class User extends UserBase implements IUser } @Override - public boolean isAuthorized(String node) - { - if (!isOnlineUser()) - { - return false; - } - - if (getData().isJailed()) - { - return false; - } - //TODO: switch to Superperms only - return ess.getPermissionsHandler().hasPermission(base, node); - } - - @Override - public boolean isAuthorized(IPermission permission) - { - return isAuthorized(permission.getPermission()); - } - - /*@Override - public boolean isAuthorized(IEssentialsCommand cmd) - { - return isAuthorized(cmd, "essentials."); - } - - @Override - public boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix) - { - return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName())); - }*/ - - @Override - public void checkCooldown(final UserData.TimestampType cooldownType, final double cooldown, final boolean set, final String bypassPermission) throws CooldownException + public void checkCooldown(final UserData.TimestampType cooldownType, final double cooldown, final boolean set, final IPermission bypassPermission) throws CooldownException { final Calendar now = new GregorianCalendar(); if (getTimestamp(cooldownType) > 0) @@ -119,7 +86,7 @@ public class User extends UserBase implements IUser cooldownTime.setTimeInMillis(getTimestamp(cooldownType)); cooldownTime.add(Calendar.SECOND, (int)cooldown); cooldownTime.add(Calendar.MILLISECOND, (int)((cooldown * 1000.0) % 1000.0)); - if (cooldownTime.after(now) && !isAuthorized(bypassPermission)) + if (cooldownTime.after(now) && !bypassPermission.isAuthorized(this)) { throw new CooldownException(Util.formatDateDiff(cooldownTime.getTimeInMillis())); } @@ -204,7 +171,7 @@ public class User extends UserBase implements IUser public boolean canAfford(final double cost) { final double mon = getMoney(); - return mon >= cost || isAuthorized("essentials.eco.loan"); + return mon >= cost || Permissions.ECO_LOAN.isAuthorized(this); } public void setHome() @@ -372,7 +339,7 @@ public class User extends UserBase implements IUser acquireWriteLock(); try { - this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set); + this.setSleepingIgnored(Permissions.SLEEPINGIGNORED.isAuthorized(this) ? true : set); if (set && !getData().isAfk()) { afkPosition = getLocation(); @@ -389,7 +356,7 @@ public class User extends UserBase implements IUser public boolean toggleAfk() { final boolean now = super.toggleAfk(); - this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now); + this.setSleepingIgnored(Permissions.SLEEPINGIGNORED.isAuthorized(this) ? true : now); return now; } @@ -497,7 +464,9 @@ public class User extends UserBase implements IUser settings.acquireReadLock(); final long autoafkkick = settings.getData().getCommands().getAfk().getAutoAFKKick(); if (autoafkkick > 0 && lastActivity > 0 && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis() - && !hidden && !isAuthorized("essentials.kick.exempt") && !isAuthorized("essentials.afk.kickexempt")) + && !hidden + && !Permissions.KICK_EXEMPT.isAuthorized(this) + && !Permissions.AFK_KICKEXEMPT.isAuthorized(this)) { final String kickReason = _("autoAfkKickReason", autoafkkick / 60.0); lastActivity = 0; @@ -507,7 +476,7 @@ public class User extends UserBase implements IUser for (Player player : ess.getServer().getOnlinePlayers()) { final IUser user = ess.getUser(player); - if (user.isAuthorized("essentials.kick.notify")) + if (Permissions.KICK_NOTIFY.isAuthorized(user)) { player.sendMessage(_("playerKicked", Console.NAME, getName(), kickReason)); } @@ -517,7 +486,7 @@ public class User extends UserBase implements IUser acquireReadLock(); try { - if (!getData().isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk")) + if (!getData().isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && Permissions.AFK.isAuthorized(this)) { setAfk(true); if (!hidden) @@ -688,7 +657,7 @@ public class User extends UserBase implements IUser } final Map<Integer, ItemStack> overfilled; - if (isAuthorized("essentials.oversizedstacks")) + if (Permissions.OVERSIZEDSTACKS.isAuthorized(this)) { @Cleanup final ISettings settings = ess.getSettings(); diff --git a/Essentials/src/com/earth2me/essentials/user/UserBase.java b/Essentials/src/com/earth2me/essentials/user/UserBase.java index c4a338ce9..f913796c2 100644 --- a/Essentials/src/com/earth2me/essentials/user/UserBase.java +++ b/Essentials/src/com/earth2me/essentials/user/UserBase.java @@ -4,12 +4,14 @@ import com.earth2me.essentials.Util; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.InvalidNameException; -import com.earth2me.essentials.craftbukkit.BetterLocation; import com.earth2me.essentials.craftbukkit.OfflineBedLocation; import com.earth2me.essentials.storage.AsyncStorageObjectHolder; +import com.earth2me.essentials.storage.Location.WorldNotLoadedException; import java.io.File; import java.io.IOException; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; import lombok.Cleanup; import lombok.Delegate; import org.bukkit.Bukkit; @@ -32,7 +34,7 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem Player.class, Entity.class, CommandSender.class, ServerOperator.class, HumanEntity.class, ConfigurationSerializable.class, LivingEntity.class, Permissible.class - }, excludes = {IOfflinePlayer.class, OtherExcludes.class}) + }, excludes = {IOfflinePlayer.class}) protected Player base; protected transient OfflinePlayer offlinePlayer; @@ -116,7 +118,14 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem } else { - return OfflineBedLocation.getBedLocation(base.getName(), ess); + try + { + return OfflineBedLocation.getBedLocation(base.getName(), ess).getBukkitLocation(); + } + catch (WorldNotLoadedException ex) + { + return null; + } } } @@ -437,14 +446,4 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem unlock(); } } - - @Override - public Location getLocation() - { - return new BetterLocation(base.getLocation()); - } - - public static interface OtherExcludes { - Location getLocation(); - } } diff --git a/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java index 05a5d4797..9bb5a2ec8 100644 --- a/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -2,8 +2,8 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.craftbukkit.FakeWorld; import com.earth2me.essentials.settings.Spawns; +import com.earth2me.essentials.storage.Location; import com.earth2me.essentials.storage.YamlStorageWriter; import java.io.*; import java.math.BigInteger; @@ -13,11 +13,11 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; + @Deprecated public class EssentialsUpgrade { @@ -211,14 +211,10 @@ public class EssentialsUpgrade continue; } World world = ess.getServer().getWorlds().get(0); - if (vals.size() > 5) - { - world = ess.getServer().getWorld((String)vals.get(5)); - } if (world != null) { final Location loc = new Location( - world, + (String)vals.get(5), ((Number)vals.get(0)).doubleValue(), ((Number)vals.get(1)).doubleValue(), ((Number)vals.get(2)).doubleValue(), @@ -352,7 +348,7 @@ public class EssentialsUpgrade { continue; } - worldName = loc.getWorld().getName().toLowerCase(Locale.ENGLISH); + worldName = loc.getWorldName().toLowerCase(Locale.ENGLISH); if (worldName != null && !worldName.isEmpty()) { config.setProperty("homes." + worldName, loc); @@ -373,54 +369,21 @@ public class EssentialsUpgrade doneFile.save(); } - /*private void moveUsersDataToUserdataFolder() - { - final File usersFile = new File(ess.getDataFolder(), "users.yml"); - if (!usersFile.exists()) - { - return; - } - final EssentialsConf usersConfig = new EssentialsConf(usersFile); - usersConfig.load(); - for (String username : usersConfig.getKeys(null)) - { - final User user = new User(new OfflinePlayer(username, ess), ess); - final String nickname = usersConfig.getString(username + ".nickname"); - if (nickname != null && !nickname.isEmpty() && !nickname.equals(username)) - { - user.setNickname(nickname); - } - final List<String> mails = usersConfig.getStringList(username + ".mail", null); - if (mails != null && !mails.isEmpty()) - { - user.setMails(mails); - } - if (!user.hasHome()) - { - @SuppressWarnings("unchecked") - final List<Object> vals = (List<Object>)usersConfig.getProperty(username + ".home"); - if (vals != null) - { - World world = ess.getServer().getWorlds().get(0); - if (vals.size() > 5) - { - world = getFakeWorld((String)vals.get(5)); - } - if (world != null) - { - user.setHome("home", new Location(world, - ((Number)vals.get(0)).doubleValue(), - ((Number)vals.get(1)).doubleValue(), - ((Number)vals.get(2)).doubleValue(), - ((Number)vals.get(3)).floatValue(), - ((Number)vals.get(4)).floatValue())); - } - } - } - } - usersFile.renameTo(new File(usersFile.getAbsolutePath() + ".old")); - }*/ - + /* + * private void moveUsersDataToUserdataFolder() { final File usersFile = new File(ess.getDataFolder(), "users.yml"); + * if (!usersFile.exists()) { return; } final EssentialsConf usersConfig = new EssentialsConf(usersFile); + * usersConfig.load(); for (String username : usersConfig.getKeys(null)) { final User user = new User(new + * OfflinePlayer(username, ess), ess); final String nickname = usersConfig.getString(username + ".nickname"); if + * (nickname != null && !nickname.isEmpty() && !nickname.equals(username)) { user.setNickname(nickname); } final + * List<String> mails = usersConfig.getStringList(username + ".mail", null); if (mails != null && !mails.isEmpty()) + * { user.setMails(mails); } if (!user.hasHome()) { @SuppressWarnings("unchecked") final List<Object> vals = + * (List<Object>)usersConfig.getProperty(username + ".home"); if (vals != null) { World world = + * ess.getServer().getWorlds().get(0); if (vals.size() > 5) { world = getFakeWorld((String)vals.get(5)); } if (world + * != null) { user.setHome("home", new Location(world, ((Number)vals.get(0)).doubleValue(), + * ((Number)vals.get(1)).doubleValue(), ((Number)vals.get(2)).doubleValue(), ((Number)vals.get(3)).floatValue(), + * ((Number)vals.get(4)).floatValue())); } } } } usersFile.renameTo(new File(usersFile.getAbsolutePath() + ".old")); + * } + */ private void convertWarps() { final File warpsFolder = new File(ess.getDataFolder(), "warps"); @@ -475,31 +438,16 @@ public class EssentialsUpgrade { rx.close(); } - World w = null; - for (World world : ess.getServer().getWorlds()) - { - if (world.getEnvironment() != World.Environment.NETHER) - { - w = world; - break; - } - } if (worldName != null) { - worldName = worldName.trim(); - World w1 = null; - w1 = getFakeWorld(worldName); - if (w1 != null) + final Location loc = new Location(worldName, x, y, z, yaw, pitch); + ((Warps)ess.getWarps()).setWarp(filename.substring(0, filename.length() - 4), loc); + if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old"))) { - w = w1; + throw new Exception(_("fileRenameError", filename)); } } - final Location loc = new Location(w, x, y, z, yaw, pitch); - ess.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc); - if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old"))) - { - throw new Exception(_("fileRenameError", filename)); - } + } catch (Exception ex) { @@ -509,7 +457,7 @@ public class EssentialsUpgrade } } - final File warpFile = new File(ess.getDataFolder(), "warps.txt"); + /*final File warpFile = new File(ess.getDataFolder(), "warps.txt"); if (warpFile.exists()) { try @@ -542,7 +490,7 @@ public class EssentialsUpgrade break; } } - final Location loc = new Location(w, x, y, z, yaw, pitch); + final Location loc = new Location(name, x, y, z, yaw, pitch); ess.getWarps().setWarp(name, loc); if (!warpFile.renameTo(new File(ess.getDataFolder(), "warps.txt.old"))) { @@ -559,65 +507,30 @@ public class EssentialsUpgrade { LOGGER.log(Level.SEVERE, null, ex); } - } + }*/ } - /*private void sanitizeAllUserFilenames() - { - if (doneFile.getBoolean("sanitizeAllUserFilenames", false)) - { - return; - } - final File usersFolder = new File(ess.getDataFolder(), "userdata"); - if (!usersFolder.exists()) - { - return; - } - final File[] listOfFiles = usersFolder.listFiles(); - for (int i = 0; i < listOfFiles.length; i++) - { - final String filename = listOfFiles[i].getName(); - if (!listOfFiles[i].isFile() || !filename.endsWith(".yml")) - { - continue; - } - final String sanitizedFilename = Util.sanitizeFileName(filename.substring(0, filename.length() - 4)) + ".yml"; - if (sanitizedFilename.equals(filename)) - { - continue; - } - final File tmpFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename + ".tmp"); - final File newFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename); - if (!listOfFiles[i].renameTo(tmpFile)) - { - LOGGER.log(Level.WARNING, _("userdataMoveError", filename, sanitizedFilename)); - continue; - } - if (newFile.exists()) - { - LOGGER.log(Level.WARNING, _("duplicatedUserdata", filename, sanitizedFilename)); - continue; - } - if (!tmpFile.renameTo(newFile)) - { - LOGGER.log(Level.WARNING, _("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); - } - } - doneFile.setProperty("sanitizeAllUserFilenames", true); - doneFile.save(); - }*/ - - private World getFakeWorld(final String name) - { - final File bukkitDirectory = ess.getDataFolder().getParentFile().getParentFile(); - final File worldDirectory = new File(bukkitDirectory, name); - if (worldDirectory.exists() && worldDirectory.isDirectory()) - { - return new FakeWorld(worldDirectory.getName(), World.Environment.NORMAL); - } - return null; + /* + * private void sanitizeAllUserFilenames() { if (doneFile.getBoolean("sanitizeAllUserFilenames", false)) { return; } + * final File usersFolder = new File(ess.getDataFolder(), "userdata"); if (!usersFolder.exists()) { return; } final + * File[] listOfFiles = usersFolder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { final String + * filename = listOfFiles[i].getName(); if (!listOfFiles[i].isFile() || !filename.endsWith(".yml")) { continue; } + * final String sanitizedFilename = Util.sanitizeFileName(filename.substring(0, filename.length() - 4)) + ".yml"; if + * (sanitizedFilename.equals(filename)) { continue; } final File tmpFile = new File(listOfFiles[i].getParentFile(), + * sanitizedFilename + ".tmp"); final File newFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename); if + * (!listOfFiles[i].renameTo(tmpFile)) { LOGGER.log(Level.WARNING, _("userdataMoveError", filename, + * sanitizedFilename)); continue; } if (newFile.exists()) { LOGGER.log(Level.WARNING, _("duplicatedUserdata", + * filename, sanitizedFilename)); continue; } if (!tmpFile.renameTo(newFile)) { LOGGER.log(Level.WARNING, + * _("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); } } + * doneFile.setProperty("sanitizeAllUserFilenames", true); doneFile.save(); } + */ + /* + * private World getFakeWorld(final String name) { final File bukkitDirectory = + * ess.getDataFolder().getParentFile().getParentFile(); final File worldDirectory = new File(bukkitDirectory, name); + * if (worldDirectory.exists() && worldDirectory.isDirectory()) { return new FakeWorld(worldDirectory.getName(), + * World.Environment.NORMAL); } return null; } - + */ public Location getFakeLocation(EssentialsConf config, String path) { String worldName = config.getString((path != null ? path + "." : "") + "world"); @@ -625,12 +538,7 @@ public class EssentialsUpgrade { return null; } - World world = getFakeWorld(worldName); - if (world == null) - { - return null; - } - return new Location(world, + return new Location(worldName, config.getDouble((path != null ? path + "." : "") + "x", 0), config.getDouble((path != null ? path + "." : "") + "y", 0), config.getDouble((path != null ? path + "." : "") + "z", 0), @@ -731,7 +639,7 @@ public class EssentialsUpgrade doneFile.setProperty("updateSpawnsToNewSpawnsConfig", true); doneFile.save(); } - + private void updateJailsToNewJailsConfig() { if (doneFile.getBoolean("updateJailsToNewJailsConfig", false)) diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java b/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java new file mode 100644 index 000000000..5b98002c5 --- /dev/null +++ b/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java @@ -0,0 +1,22 @@ +package com.earth2me.essentials.chat; + +import com.earth2me.essentials.api.IPermission; +import com.earth2me.essentials.perm.BasePermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public class ChatPermissions { + private static Map<String, IPermission> permissions = new HashMap<String, IPermission>(); + + public static IPermission getPermission(final String groupName) + { + IPermission perm = permissions.get(groupName); + if (perm == null) + { + perm = new BasePermission("essentials.chat.",groupName.toLowerCase(Locale.ENGLISH)); + permissions.put(groupName, perm); + } + return perm; + } +} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index a4621661b..cc21b6dae 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -8,6 +8,7 @@ import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IGroups; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.Locale; import java.util.Map; import java.util.logging.Logger; @@ -77,7 +78,7 @@ public abstract class EssentialsChatPlayer implements Listener protected void formatChat(final PlayerChatEvent event, final ChatStore chatStore) { final IUser user = chatStore.getUser(); - if (user.isAuthorized("essentials.chat.color")) + if (Permissions.CHAT_COLOR.isAuthorized(user)) { event.setMessage(Util.stripColor(event.getMessage())); } @@ -141,10 +142,7 @@ public abstract class EssentialsChatPlayer implements Listener if (event.getMessage().length() > 1 && chatStore.getType().length() > 0) { - final StringBuilder permission = new StringBuilder(); - permission.append("essentials.chat.").append(chatStore.getType()); - - if (user.isAuthorized(permission.toString())) + if (ChatPermissions.getPermission(chatStore.getType()).isAuthorized(user)) { final StringBuilder format = new StringBuilder(); format.append(chatStore.getType()).append("Format"); diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java index c7ce5a70d..1eb589ff1 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.chat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Server; @@ -52,7 +53,7 @@ public class EssentialsLocalChatEventListener implements Listener if (delta > event.getRadius()) { - if (user.isAuthorized("essentials.chat.spy")) + if (Permissions.CHAT_SPY.isAuthorized(user)) { type = type.concat(_("chatTypeSpy")); } diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 19cc06dc4..45d21d89c 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IReload; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.Permissions; import com.maxmind.geoip.Location; import com.maxmind.geoip.LookupService; import com.maxmind.geoip.regionName; @@ -45,7 +46,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload public void onPlayerJoin(final PlayerJoinEvent event) { final IUser u = ess.getUser(event.getPlayer()); - if (u.isAuthorized("essentials.geoip.hide")) + if (Permissions.GEOIP_HIDE.isAuthorized(u)) { return; } @@ -93,7 +94,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload for (Player player : event.getPlayer().getServer().getOnlinePlayers()) { final IUser user = ess.getUser(player); - if (user.isAuthorized("essentials.geoip.show")) + if (Permissions.GEOIP_SHOW.isAuthorized(user)) { user.sendMessage(_("geoipJoinFormat", user.getDisplayName(), builder.toString())); } 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()); + } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index 07532653c..357b03a2c 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; +import com.earth2me.essentials.perm.Permissions; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -17,7 +18,7 @@ public class Commandspawn extends EssentialsCommand { final Trade charge = new Trade(commandName, ess); charge.isAffordableFor(user); - if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) + if (args.length > 0 && Permissions.SPAWN_OTHERS.isAuthorized(user)) { final IUser otherUser = getPlayer(args, 0); respawn(otherUser, null); diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java index 067950e96..98545eaf0 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.api.IEssentialsModule; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.settings.Spawns; import com.earth2me.essentials.storage.AsyncStorageObjectHolder; +import com.earth2me.essentials.storage.Location.WorldNotLoadedException; import java.io.File; import java.util.HashMap; import java.util.Locale; @@ -35,9 +36,9 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE { if (getData().getSpawns() == null) { - getData().setSpawns(new HashMap<String, Location>()); + getData().setSpawns(new HashMap<String, com.earth2me.essentials.storage.Location>()); } - getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), loc); + getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.Location(loc)); } finally { @@ -59,7 +60,7 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE { return getWorldSpawn(); } - final Map<String, Location> spawnMap = getData().getSpawns(); + final Map<String, com.earth2me.essentials.storage.Location> spawnMap = getData().getSpawns(); String groupName = group.toLowerCase(Locale.ENGLISH); if (!spawnMap.containsKey(groupName)) { @@ -69,7 +70,14 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE { return getWorldSpawn(); } - return spawnMap.get(groupName); + try + { + return spawnMap.get(groupName).getBukkitLocation(); + } + catch (WorldNotLoadedException ex) + { + return getWorldSpawn(); + } } finally { |