TotalFreedomMod/src/me/totalfreedom/totalfreedommod/commands/Command_rollback.java

85 lines
3.1 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.commands;
2013-05-17 20:58:03 +00:00
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
import me.totalfreedom.totalfreedommod.util.FUtil;
2013-05-17 20:58:03 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
2013-08-27 14:22:46 +00:00
@CommandParameters(description = "Issues a rollback on a player", usage = "/<command> <[partialname] | undo [partialname] purge [partialname] | purgeall>", aliases = "rb")
public class Command_rollback extends FreedomCommand
2013-07-02 18:31:22 +00:00
{
2013-05-17 20:58:03 +00:00
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0 || args.length > 2)
{
return false;
}
2013-08-06 02:05:01 +00:00
if (args.length == 1)
2013-05-17 20:58:03 +00:00
{
if ("purgeall".equals(args[0]))
2013-05-17 20:58:03 +00:00
{
FUtil.adminAction(sender.getName(), "Purging all rollback history", false);
playerMsg("Purged all rollback history for " + plugin.rb.purgeEntries() + " players.");
2013-05-17 20:58:03 +00:00
}
2013-08-06 02:05:01 +00:00
else
2013-05-17 20:58:03 +00:00
{
final String playerName = plugin.rb.findPlayer(args[0]);
2013-08-27 14:22:46 +00:00
if (playerName == null)
2013-08-27 14:22:46 +00:00
{
playerMsg("That player has no entries stored.");
return true;
}
if (plugin.rb.canUndoRollback(playerName))
2013-08-27 14:22:46 +00:00
{
playerMsg("That player has just been rolled back.");
}
FUtil.adminAction(sender.getName(), "Rolling back player: " + playerName, false);
playerMsg("Rolled back " + plugin.rb.rollback(playerName) + " edits for " + playerName + ".");
playerMsg("If this rollback was a mistake, use /rollback undo " + playerName + " within 40 seconds to reverse the rollback.");
2013-05-17 20:58:03 +00:00
}
return true;
2013-08-06 02:05:01 +00:00
}
if (args.length == 2)
2013-08-06 02:05:01 +00:00
{
2013-08-27 14:22:46 +00:00
if ("purge".equalsIgnoreCase(args[0]))
2013-05-17 20:58:03 +00:00
{
final String playerName = plugin.rb.findPlayer(args[1]);
2013-08-27 14:22:46 +00:00
if (playerName == null)
2013-08-27 14:22:46 +00:00
{
playerMsg("That player has no entries stored.");
return true;
}
playerMsg("Purged " + plugin.rb.purgeEntries(playerName) + " rollback history entries for " + playerName + ".");
return true;
2013-07-02 18:31:22 +00:00
}
if ("undo".equalsIgnoreCase(args[0]))
2013-08-27 14:22:46 +00:00
{
final String playerName = plugin.rb.findPlayer(args[1]);
2013-08-27 14:22:46 +00:00
if (playerName == null)
2013-08-27 14:22:46 +00:00
{
playerMsg("That player hasn't been rolled back recently.");
return true;
}
FUtil.adminAction(sender.getName(), "Reverting rollback for player: " + playerName, false);
playerMsg("Reverted " + plugin.rb.undoRollback(playerName) + " edits for " + playerName + ".");
return true;
2013-08-27 14:22:46 +00:00
}
2013-05-17 20:58:03 +00:00
}
return false;
2013-08-06 02:05:01 +00:00
}
2013-05-17 20:58:03 +00:00
}