TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java

107 lines
2.7 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.OfflinePlayer;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandtogglejail extends EssentialsCommand
{
public Commandtogglejail()
{
super("togglejail");
}
@Override
2011-11-18 19:30:05 +00:00
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
2011-11-18 19:30:05 +00:00
final User player = getPlayer(server, args, 0, true);
2011-11-18 19:30:05 +00:00
if (args.length >= 2 && !player.isJailed())
{
2011-11-18 19:30:05 +00:00
if (player.getBase() instanceof OfflinePlayer)
{
if (sender instanceof Player
&& !ess.getUser(sender).isAuthorized("essentials.togglejail.offline"))
{
sender.sendMessage(_("mayNotJail"));
return;
}
}
else
{
2011-11-18 19:30:05 +00:00
if (player.isAuthorized("essentials.jail.exempt"))
{
sender.sendMessage(_("mayNotJail"));
return;
}
}
2011-11-18 19:30:05 +00:00
if (!(player.getBase() instanceof OfflinePlayer))
2011-07-18 22:59:43 +00:00
{
2011-11-18 19:30:05 +00:00
ess.getJail().sendToJail(player, args[1]);
2011-07-18 22:59:43 +00:00
}
else
{
// Check if jail exists
ess.getJail().getJail(args[1]);
}
2011-11-18 19:30:05 +00:00
player.setJailed(true);
player.sendMessage(_("userJailed"));
2011-11-18 19:30:05 +00:00
player.setJail(null);
player.setJail(args[1]);
long timeDiff = 0;
if (args.length > 2)
{
2011-11-18 19:30:05 +00:00
final String time = getFinalArg(args, 2);
timeDiff = Util.parseDateDiff(time, true);
2011-11-18 19:30:05 +00:00
player.setJailTimeout(timeDiff);
}
sender.sendMessage((timeDiff > 0
? _("playerJailedFor", player.getName(), Util.formatDateDiff(timeDiff))
: _("playerJailed", player.getName())));
return;
}
2011-11-18 19:30:05 +00:00
if (args.length >= 2 && player.isJailed() && !args[1].equalsIgnoreCase(player.getJail()))
{
sender.sendMessage(_("jailAlreadyIncarcerated", player.getJail()));
return;
}
2011-11-18 19:30:05 +00:00
if (args.length >= 2 && player.isJailed() && args[1].equalsIgnoreCase(player.getJail()))
{
2011-11-18 19:30:05 +00:00
final String time = getFinalArg(args, 2);
final long timeDiff = Util.parseDateDiff(time, true);
player.setJailTimeout(timeDiff);
sender.sendMessage(_("jailSentenceExtended", Util.formatDateDiff(timeDiff)));
return;
}
2011-11-18 19:30:05 +00:00
if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase(player.getJail())))
{
2011-11-18 19:30:05 +00:00
if (!player.isJailed())
{
throw new NotEnoughArgumentsException();
}
2011-11-18 19:30:05 +00:00
player.setJailed(false);
player.setJailTimeout(0);
player.sendMessage(_("jailReleasedPlayerNotify"));
2011-11-18 19:30:05 +00:00
player.setJail(null);
if (!(player.getBase() instanceof OfflinePlayer))
{
2011-11-18 19:30:05 +00:00
player.getTeleport().back();
}
sender.sendMessage(_("jailReleased", player.getName()));
}
}
}