2011-10-19 00:37:00 +00:00
package me.StevenLawson.TotalFreedomMod.Commands ;
2012-11-13 01:42:30 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList ;
2013-06-10 06:24:53 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_Util ;
2013-06-09 19:52:13 +00:00
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod ;
import org.bukkit.Bukkit ;
2013-01-07 14:56:53 +00:00
import org.bukkit.ChatColor ;
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 ;
2013-03-19 22:05:20 +00:00
@CommandPermissions ( level = AdminLevel . OP , source = SourceType . BOTH )
2013-06-10 06:24:53 +00:00
@CommandParameters ( description = " Quickly change your own gamemode to survival, or define someone's username to change theirs. " , usage = " /<command> <[partialname] | -a> " )
2011-10-19 00:37:00 +00:00
public class Command_survival extends TFM_Command
{
@Override
public boolean run ( CommandSender sender , Player sender_p , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
if ( senderIsConsole )
{
if ( args . length = = 0 )
{
2013-01-07 14:56:53 +00:00
playerMsg ( " When used from the console, you must define a target user to change gamemode on. " ) ;
2011-10-19 00:37:00 +00:00
return true ;
}
}
2011-10-19 02:52:32 +00:00
2011-10-19 00:37:00 +00:00
Player p ;
2013-06-09 19:52:13 +00:00
2011-10-19 00:37:00 +00:00
if ( args . length = = 0 )
{
2011-10-19 02:52:32 +00:00
p = sender_p ;
2011-10-19 00:37:00 +00:00
}
else
{
2013-06-10 06:24:53 +00:00
if ( args [ 0 ] . equalsIgnoreCase ( " -a " ) )
{
if ( ! TFM_SuperadminList . isUserSuperadmin ( sender ) | | senderIsConsole )
{
sender . sendMessage ( TotalFreedomMod . MSG_NO_PERMS ) ;
return true ;
}
for ( Player player : server . getOnlinePlayers ( ) )
{
player . setGameMode ( GameMode . SURVIVAL ) ;
}
TFM_Util . adminAction ( sender . getName ( ) , " Changing everyone's gamemode to survival " , false ) ;
return true ;
}
2012-11-13 01:42:30 +00:00
if ( senderIsConsole | | TFM_SuperadminList . isUserSuperadmin ( sender ) )
2011-10-19 00:37:00 +00:00
{
2011-11-29 05:41:47 +00:00
try
{
p = getPlayer ( args [ 0 ] ) ;
}
catch ( CantFindPlayerException ex )
{
2013-01-07 14:56:53 +00:00
playerMsg ( ex . getMessage ( ) , ChatColor . RED ) ;
2011-11-29 05:41:47 +00:00
return true ;
}
2011-10-19 00:37:00 +00:00
}
2011-11-29 05:41:47 +00:00
else
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-01-07 14:56:53 +00:00
playerMsg ( " Setting " + p . getName ( ) + " to game mode 'Survival'. " ) ;
2011-10-19 00:37:00 +00:00
p . sendMessage ( sender . getName ( ) + " set your game mode to 'Survival'. " ) ;
p . setGameMode ( GameMode . SURVIVAL ) ;
return true ;
}
}