1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-24 07:13:17 +02:00

More fixes for commands

This commit is contained in:
snowleo
2012-01-03 21:43:57 +01:00
parent 481749b119
commit 781f42fba1
14 changed files with 116 additions and 68 deletions

View File

@@ -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();
public List<String> getMails();
boolean gotMailInfo();
List<String> getMails();
}

View File

@@ -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;

View File

@@ -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"));

View File

@@ -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;

View File

@@ -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()));

View File

@@ -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);
}
}
}

View File

@@ -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"));

View File

@@ -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()));
}

View File

@@ -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);
}
}
}

View File

@@ -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));
}

View File

@@ -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"));
}
}

View File

@@ -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"));

View File

@@ -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(
{

View File

@@ -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;
}