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

105 lines
2.7 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.User;
2013-06-08 21:31:19 +00:00
import com.earth2me.essentials.utils.DateUtil;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server;
public class Commandtogglejail extends EssentialsCommand
{
public Commandtogglejail()
{
super("togglejail");
}
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
final User player = getPlayer(server, args, 0, true, true);
2011-11-18 19:30:05 +00:00
if (args.length >= 2 && !player.isJailed())
{
if (!player.getBase().isOnline())
{
if (sender.isPlayer()
&& !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline"))
{
sender.sendMessage(tl("mayNotJailOffline"));
return;
}
}
else
{
2011-11-18 19:30:05 +00:00
if (player.isAuthorized("essentials.jail.exempt"))
{
sender.sendMessage(tl("mayNotJail"));
return;
}
}
if (player.getBase().isOnline())
2011-07-18 22:59:43 +00:00
{
ess.getJails().sendToJail(player, args[1]);
2011-07-18 22:59:43 +00:00
}
else
{
// Check if jail exists
ess.getJails().getJail(args[1]);
2011-07-18 22:59:43 +00:00
}
2011-11-18 19:30:05 +00:00
player.setJailed(true);
player.sendMessage(tl("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);
2013-06-08 21:31:19 +00:00
timeDiff = DateUtil.parseDateDiff(time, true);
2011-11-18 19:30:05 +00:00
player.setJailTimeout(timeDiff);
}
sender.sendMessage((timeDiff > 0
? tl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(timeDiff))
: tl("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(tl("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);
2013-06-08 21:31:19 +00:00
final long timeDiff = DateUtil.parseDateDiff(time, true);
2011-11-18 19:30:05 +00:00
player.setJailTimeout(timeDiff);
sender.sendMessage(tl("jailSentenceExtended", DateUtil.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(tl("jailReleasedPlayerNotify"));
2011-11-18 19:30:05 +00:00
player.setJail(null);
if (player.getBase().isOnline())
{
2011-11-18 19:30:05 +00:00
player.getTeleport().back();
}
sender.sendMessage(tl("jailReleased", player.getName()));
}
}
}