2015-10-19 17:43:46 +00:00
package me.totalfreedom.totalfreedommod.commands ;
2013-05-17 20:58:03 +00:00
2015-10-19 17:43:46 +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 ;
2015-10-19 17:43:46 +00:00
@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 " )
2015-10-19 17:43:46 +00:00
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 )
{
2014-08-25 16:47:29 +00:00
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
{
2014-08-25 11:57:13 +00:00
if ( " purgeall " . equals ( args [ 0 ] ) )
2013-05-17 20:58:03 +00:00
{
2015-10-19 17:43:46 +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
{
2015-10-19 17:43:46 +00:00
final String playerName = plugin . rb . findPlayer ( args [ 0 ] ) ;
2013-08-27 14:22:46 +00:00
2014-08-25 11:57:13 +00:00
if ( playerName = = null )
2013-08-27 14:22:46 +00:00
{
playerMsg ( " That player has no entries stored. " ) ;
return true ;
}
2015-10-19 17:43:46 +00:00
if ( plugin . rb . canUndoRollback ( playerName ) )
2013-08-27 14:22:46 +00:00
{
playerMsg ( " That player has just been rolled back. " ) ;
}
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Rolling back player: " + playerName , false ) ;
playerMsg ( " Rolled back " + plugin . rb . rollback ( playerName ) + " edits for " + playerName + " . " ) ;
2014-04-23 14:38:47 +00:00
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
}
2014-08-25 16:47:29 +00:00
return true ;
2013-08-06 02:05:01 +00:00
}
2014-08-25 16:47:29 +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
{
2015-10-19 17:43:46 +00:00
final String playerName = plugin . rb . findPlayer ( args [ 1 ] ) ;
2013-08-27 14:22:46 +00:00
2014-08-25 11:57:13 +00:00
if ( playerName = = null )
2013-08-27 14:22:46 +00:00
{
playerMsg ( " That player has no entries stored. " ) ;
return true ;
}
2015-10-19 17:43:46 +00:00
playerMsg ( " Purged " + plugin . rb . purgeEntries ( playerName ) + " rollback history entries for " + playerName + " . " ) ;
2014-08-25 16:47:29 +00:00
return true ;
2013-07-02 18:31:22 +00:00
}
2014-08-25 16:47:29 +00:00
if ( " undo " . equalsIgnoreCase ( args [ 0 ] ) )
2013-08-27 14:22:46 +00:00
{
2015-10-19 17:43:46 +00:00
final String playerName = plugin . rb . findPlayer ( args [ 1 ] ) ;
2013-08-27 14:22:46 +00:00
2014-08-25 11:57:13 +00:00
if ( playerName = = null )
2013-08-27 14:22:46 +00:00
{
playerMsg ( " That player hasn't been rolled back recently. " ) ;
return true ;
}
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Reverting rollback for player: " + playerName , false ) ;
playerMsg ( " Reverted " + plugin . rb . undoRollback ( playerName ) + " edits for " + playerName + " . " ) ;
2014-08-25 16:47:29 +00:00
return true ;
2013-08-27 14:22:46 +00:00
}
2013-05-17 20:58:03 +00:00
}
2014-08-25 16:47:29 +00:00
return false ;
2013-08-06 02:05:01 +00:00
}
2013-05-17 20:58:03 +00:00
}