diff options
author | snowleo <schneeleo@gmail.com> | 2012-01-03 21:43:57 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2012-01-03 21:43:57 +0100 |
commit | 781f42fba175ac9c9c584f498c9b868b531664d7 (patch) | |
tree | f6c533e5ab76c6e9f8feca1df4b4a1a49b4d2e53 | |
parent | 481749b119a99c426fe01efbef6f5eab1227626a (diff) | |
download | Essentials-781f42fba175ac9c9c584f498c9b868b531664d7.tar Essentials-781f42fba175ac9c9c584f498c9b868b531664d7.tar.gz Essentials-781f42fba175ac9c9c584f498c9b868b531664d7.tar.lz Essentials-781f42fba175ac9c9c584f498c9b868b531664d7.tar.xz Essentials-781f42fba175ac9c9c584f498c9b868b531664d7.zip |
More fixes for commands
14 files changed, 116 insertions, 68 deletions
diff --git a/Essentials/src/com/earth2me/essentials/api/IUser.java b/Essentials/src/com/earth2me/essentials/api/IUser.java index 6528a17af..b13fefc26 100644 --- a/Essentials/src/com/earth2me/essentials/api/IUser.java +++ b/Essentials/src/com/earth2me/essentials/api/IUser.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.api; -import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.storage.IStorageObjectHolder; import com.earth2me.essentials.user.CooldownException; import com.earth2me.essentials.user.UserData; @@ -13,13 +12,11 @@ import org.bukkit.entity.Player; 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(); @@ -33,7 +30,7 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload, void giveMoney(double value, CommandSender initiator); void setMoney(double value); - + void payUser(final IUser reciever, final double value) throws Exception; String getGroup(); @@ -102,7 +99,9 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload, boolean toggleTeleportEnabled(); - public boolean gotMailInfo(); + long getTeleportRequestTime(); + + boolean gotMailInfo(); - public List<String> getMails(); + List<String> getMails(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index 75d55d5c6..5deddca30 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -20,10 +20,9 @@ public class Commandban extends EssentialsCommand } @Cleanup final IUser user = getPlayer(args, 0, true); - if (user.getBase() instanceof OfflinePlayer) + if (user.isOnline()) { - if (sender instanceof Player - && !ess.getUser((Player)sender).isAuthorized("essentials.ban.offline")) + if (user.isAuthorized("essentials.ban.exempt")) { sender.sendMessage(_("banExempt")); return; @@ -31,7 +30,8 @@ public class Commandban extends EssentialsCommand } else { - if (user.isAuthorized("essentials.ban.exempt")) + if (sender instanceof Player + && !ess.getUser((Player)sender).isAuthorized("essentials.ban.offline")) { sender.sendMessage(_("banExempt")); return; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index 58703f13e..06f0d5650 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.api.IUser; import com.earth2me.essentials.Util; +import com.earth2me.essentials.api.ISettings; import java.util.Locale; import org.bukkit.Location; import org.bukkit.Material; @@ -37,10 +38,6 @@ public class Commandspawner extends EssentialsCommand user.sendMessage(_("invalidMob")); return; } - if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) - { - throw new Exception(_("unableToSpawnMob")); - } if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase())) { 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 5f581580e..11fdf4bea 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -5,8 +5,10 @@ import com.earth2me.essentials.Mob; import com.earth2me.essentials.Mob.MobException; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; +import com.earth2me.essentials.api.ISettings; import java.util.Locale; import java.util.Random; +import lombok.Cleanup; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.block.Block; @@ -56,10 +58,6 @@ public class Commandspawnmob extends EssentialsCommand throw new Exception(_("invalidMob")); } - if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) - { - throw new Exception(_("disabledToSpawnMob")); - } if (!user.isAuthorized("essentials.spawnmob." + mob.name.toLowerCase())) { throw new Exception(_("noPermToSpawnMob")); @@ -73,7 +71,7 @@ public class Commandspawnmob extends EssentialsCommand IUser otherUser = null; if (args.length >= 3) { - otherUser = getPlayer(ess.getServer(), args, 2); + otherUser = getPlayer(args, 2); } final Location loc = (otherUser == null) ? block.getLocation() : otherUser.getLocation(); final Location sloc = Util.getSafeDestination(loc); @@ -95,10 +93,6 @@ public class Commandspawnmob extends EssentialsCommand return; } - if (ess.getSettings().getProtectPreventSpawn(mobMount.getType().toString().toLowerCase(Locale.ENGLISH))) - { - throw new Exception(_("disabledToSpawnMob")); - } if (!user.isAuthorized("essentials.spawnmob." + mobMount.name.toLowerCase())) { throw new Exception(_("noPermToSpawnMob")); @@ -124,7 +118,17 @@ public class Commandspawnmob extends EssentialsCommand if (args.length >= 2) { int mobCount = Integer.parseInt(args[1]); - int serverLimit = ess.getSettings().getSpawnMobLimit(); + int serverLimit = 1; + ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + try + { + serverLimit = settings.getData().getCommands().getSpawnmob().getLimit(); + } + finally + { + settings.unlock(); + } if (mobCount > serverLimit) { mobCount = serverLimit; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java index cd0232c53..ee8b72878 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java @@ -1,6 +1,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 lombok.Cleanup; @@ -28,9 +29,17 @@ public class Commandtpa extends EssentialsCommand player.sendMessage(_("teleportRequest", user.getDisplayName())); player.sendMessage(_("typeTpaccept")); player.sendMessage(_("typeTpdeny")); - if (ess.getSettings().getTpaAcceptCancellation() != 0) + int tpaAcceptCancellation = 0; + ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + try { + tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + } finally { + settings.unlock(); + } + if (tpaAcceptCancellation != 0) { - player.sendMessage(_("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation())); + player.sendMessage(_("teleportRequestTimeoutInfo", tpaAcceptCancellation)); } } user.sendMessage(_("requestSent", player.getDisplayName())); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java index 5044ce140..de80b02ff 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java @@ -1,6 +1,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 lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -16,14 +17,14 @@ public class Commandtpaall extends EssentialsCommand { if (sender instanceof Player) { - teleportAAllPlayers( sender, ess.getUser(sender)); + teleportAAllPlayers(sender, ess.getUser((Player)sender)); return; } throw new NotEnoughArgumentsException(); } final IUser player = getPlayer(args, 0); - teleportAAllPlayers( sender, player); + teleportAAllPlayers(sender, player); } private void teleportAAllPlayers(final CommandSender sender, final IUser user) @@ -47,14 +48,25 @@ public class Commandtpaall extends EssentialsCommand player.requestTeleport(user, true); player.sendMessage(_("teleportHereRequest", user.getDisplayName())); player.sendMessage(_("typeTpaccept")); - if (ess.getSettings().getTpaAcceptCancellation() != 0) + int tpaAcceptCancellation = 0; + ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + try { - player.sendMessage(_("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation())); + tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + } + finally + { + settings.unlock(); + } + if (tpaAcceptCancellation != 0) + { + player.sendMessage(_("teleportRequestTimeoutInfo", tpaAcceptCancellation)); } } catch (Exception ex) { - ess.showCommandError(sender, commandName, ex); + ess.getCommandHandler().showCommandError(sender, commandName, ex); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index 7c2702dc9..8e047ade9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.Trade; +import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; import org.bukkit.OfflinePlayer; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -25,8 +25,19 @@ public class Commandtpaccept extends EssentialsCommand throw new Exception(_("noPendingRequest")); } - long timeout = ess.getSettings().getTpaAcceptCancellation(); - if (timeout != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > timeout) + int tpaAcceptCancellation = 0; + ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + try + { + tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + } + finally + { + settings.unlock(); + } + + if (tpaAcceptCancellation != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > tpaAcceptCancellation) { user.requestTeleport(null, false); throw new Exception(_("requestTimedOut")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java index 6ae28c0da..4e7a44877 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java @@ -1,6 +1,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 lombok.Cleanup; @@ -25,9 +26,20 @@ public class Commandtpahere extends EssentialsCommand player.requestTeleport(user, true); player.sendMessage(_("teleportHereRequest", user.getDisplayName())); player.sendMessage(_("typeTpaccept")); - if (ess.getSettings().getTpaAcceptCancellation() != 0) + int tpaAcceptCancellation = 0; + ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + try { - player.sendMessage(_("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation())); + tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + } + finally + { + settings.unlock(); + } + if (tpaAcceptCancellation != 0) + { + player.sendMessage(_("teleportRequestTimeoutInfo", tpaAcceptCancellation)); } user.sendMessage(_("requestSent", player.getDisplayName())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index 0e886b0b2..67bf8d279 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -2,7 +2,6 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; -import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -17,17 +16,17 @@ public class Commandtpall extends EssentialsCommand { if (sender instanceof Player) { - teleportAllPlayers(sender, ess.getUser(sender)); + teleportAllPlayers(sender, ess.getUser((Player)sender)); return; } throw new NotEnoughArgumentsException(); } final IUser player = getPlayer(args, 0); - teleportAllPlayers(server, sender, player); + teleportAllPlayers(sender, player); } - private void teleportAllPlayers(Server server, CommandSender sender, IUser user) + private void teleportAllPlayers(CommandSender sender, IUser user) { sender.sendMessage(_("teleportAll")); for (Player onlinePlayer : server.getOnlinePlayers()) @@ -43,7 +42,7 @@ public class Commandtpall extends EssentialsCommand } catch (Exception ex) { - ess.showCommandError(sender, commandName, ex); + ess.getCommandHandler().showCommandError(sender, commandName, ex); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java index e79167f15..9beeda1a2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import java.util.List; import java.util.Locale; import lombok.Cleanup; @@ -85,12 +85,8 @@ public class Commandunlimited extends EssentialsCommand stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2)); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); - if (ess.getSettings().permissionBasedItemSpawn() - && (!user.isAuthorized("essentials.unlimited.item-all") - && !user.isAuthorized("essentials.unlimited.item-" + itemname) - && !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId()) - && !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET) - && user.isAuthorized("essentials.unlimited.item-bucket")))) + if (!user.isAuthorized("essentials.unlimited.item-" + itemname) + && !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId())) { 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 2d6f32ca9..f6b0deb29 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -2,8 +2,8 @@ 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.Util; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IWarps; import java.util.ArrayList; import java.util.Iterator; @@ -80,7 +80,7 @@ public class Commandwarp extends EssentialsCommand while (iterator.hasNext()) { final String warpName = iterator.next(); - if (ess.getSettings().getPerWarpPermission() && !((IUser)sender).isAuthorized("essentials.warp." + warpName)) + if (!((IUser)sender).isAuthorized("essentials.warp." + warpName)) { iterator.remove(); } @@ -110,15 +110,12 @@ public class Commandwarp extends EssentialsCommand { final Trade charge = new Trade(commandName, ess); charge.isAffordableFor(user); - if (ess.getSettings().getPerWarpPermission()) + + if (user.isAuthorized("essentials.warp." + name)) { - if (user.isAuthorized("essentials.warp." + name)) - { - user.getTeleport().warp(name, charge, TeleportCause.COMMAND); - return; - } - throw new Exception(_("warpUsePermission")); + user.getTeleport().warp(name, charge, TeleportCause.COMMAND); + return; } - user.getTeleport().warp(name, charge, TeleportCause.COMMAND); + throw new Exception(_("warpUsePermission")); } }
\ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index 637739714..829c0360f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -13,11 +13,6 @@ import org.bukkit.entity.Player; public class Commandwhois extends EssentialsCommand { - public Commandwhois() - { - super("whois"); - } - @Override public void run(final CommandSender sender, final String[] args) throws Exception { @@ -66,10 +61,7 @@ public class Commandwhois extends EssentialsCommand sender.sendMessage(_("whoisGod", (user.isGodModeEnabled() ? _("true") : _("false")))); sender.sendMessage(_("whoisGamemode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)))); sender.sendMessage(_("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ())); - if (!settings.getData().getEconomy().isEcoDisabled()) - { - sender.sendMessage(_("whoisMoney", Util.formatCurrency(user.getMoney(), ess))); - } + sender.sendMessage(_("whoisMoney", Util.formatCurrency(user.getMoney(), ess))); sender.sendMessage(user.getData().isAfk() ? _("whoisStatusAway") : _("whoisStatusAvailable")); diff --git a/Essentials/src/com/earth2me/essentials/settings/Commands.java b/Essentials/src/com/earth2me/essentials/settings/Commands.java index 2a9012760..caea9352b 100644 --- a/Essentials/src/com/earth2me/essentials/settings/Commands.java +++ b/Essentials/src/com/earth2me/essentials/settings/Commands.java @@ -23,6 +23,7 @@ public class Commands implements StorageObject private Lightning lightning = new Lightning(); private com.earth2me.essentials.settings.commands.List list = new com.earth2me.essentials.settings.commands.List(); private Spawnmob spawnmob = new Spawnmob(); + private Tpa tpa = new Tpa(); @ListType @Comment( { diff --git a/Essentials/src/com/earth2me/essentials/settings/commands/Tpa.java b/Essentials/src/com/earth2me/essentials/settings/commands/Tpa.java new file mode 100644 index 000000000..83c9d4990 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/settings/commands/Tpa.java @@ -0,0 +1,19 @@ +package com.earth2me.essentials.settings.commands; + +import com.earth2me.essentials.storage.Comment; +import com.earth2me.essentials.storage.StorageObject; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@Data +@EqualsAndHashCode(callSuper = false) +public class Tpa implements StorageObject +{ + @Comment( + { + "Set timeout in seconds for players to accept tpa before request is cancelled.", + "Set to 0 for no timeout." + }) + private int timeout = 0; +} |