2015-10-19 17:43:46 +00:00
package me.totalfreedom.totalfreedommod.commands ;
2011-10-19 00:37:00 +00:00
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.permission.PlayerRank ;
import me.totalfreedom.totalfreedommod.util.FUtil ;
2011-10-19 00:37:00 +00:00
import org.bukkit.GameMode ;
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 . OP , source = SourceType . BOTH )
2014-06-09 16:25:31 +00:00
@CommandParameters ( description = " Quickly change your own gamemode to creative, or define someone's username to change theirs. " , usage = " /<command> [partialname] " , aliases = " gmc " )
2015-10-19 17:43:46 +00:00
public class Command_creative extends FreedomCommand
2011-10-19 00:37:00 +00:00
{
@Override
public boolean run ( CommandSender sender , Player sender_p , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
if ( senderIsConsole )
{
if ( args . length = = 0 )
{
sender . sendMessage ( " When used from the console, you must define a target user to change gamemode on. " ) ;
return true ;
}
}
2011-10-19 02:52:32 +00:00
2013-08-14 14:01:42 +00:00
Player player ;
2011-10-19 00:37:00 +00:00
if ( args . length = = 0 )
{
2013-08-14 14:01:42 +00:00
player = sender_p ;
2011-10-19 00:37:00 +00:00
}
else
{
2013-06-10 06:24:53 +00:00
if ( args [ 0 ] . equalsIgnoreCase ( " -a " ) )
2011-10-19 00:37:00 +00:00
{
2015-10-19 17:43:46 +00:00
if ( ! isAdmin ( sender ) )
2013-07-02 18:31:22 +00:00
{
2015-10-19 17:43:46 +00:00
sender . sendMessage ( FreedomCommand . MSG_NO_PERMS ) ;
2013-07-02 18:31:22 +00:00
return true ;
}
2013-06-10 06:24:53 +00:00
2013-08-14 14:55:37 +00:00
for ( Player targetPlayer : server . getOnlinePlayers ( ) )
2011-11-29 05:41:47 +00:00
{
2013-08-14 14:55:37 +00:00
targetPlayer . setGameMode ( GameMode . CREATIVE ) ;
2011-11-29 05:41:47 +00:00
}
2013-06-10 06:24:53 +00:00
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Changing everyone's gamemode to creative " , false ) ;
2013-06-10 06:24:53 +00:00
return true ;
2011-10-19 00:37:00 +00:00
}
2013-06-10 06:24:53 +00:00
2015-10-19 17:43:46 +00:00
if ( ! ( senderIsConsole | | isAdmin ( sender ) ) )
2011-10-19 00:37:00 +00:00
{
2013-01-07 14:56:53 +00:00
playerMsg ( " Only superadmins can change other user's gamemode. " ) ;
2011-10-19 02:52:32 +00:00
return true ;
2011-10-19 00:37:00 +00:00
}
2013-06-10 06:24:53 +00:00
2014-04-26 11:55:24 +00:00
player = getPlayer ( args [ 0 ] ) ;
if ( player = = null )
2013-06-10 06:24:53 +00:00
{
2015-10-19 17:43:46 +00:00
sender . sendMessage ( FreedomCommand . PLAYER_NOT_FOUND ) ;
2013-06-10 06:24:53 +00:00
return true ;
}
2013-07-02 18:31:22 +00:00
2011-10-19 00:37:00 +00:00
}
2013-08-14 14:01:42 +00:00
playerMsg ( " Setting " + player . getName ( ) + " to game mode 'Creative'. " ) ;
playerMsg ( player , sender . getName ( ) + " set your game mode to 'Creative'. " ) ;
player . setGameMode ( GameMode . CREATIVE ) ;
2011-10-19 00:37:00 +00:00
return true ;
}
}