2011-09-20 02:52:08 +00:00
package me.StevenLawson.TotalFreedomMod ;
import java.util.Arrays ;
import java.util.logging.Level ;
import java.util.logging.Logger ;
import org.bukkit.Bukkit ;
import org.bukkit.ChatColor ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
import org.bukkit.plugin.java.JavaPlugin ;
public class TotalFreedomMod extends JavaPlugin
{
private Logger log = Logger . getLogger ( " Minecraft " ) ;
public void onEnable ( )
{
2011-09-20 16:14:09 +00:00
log . log ( Level . INFO , " [Total Freedom Mod] - Enabled! - Version: " + this . getDescription ( ) . getVersion ( ) + " by Madgeek1450 " ) ;
2011-09-20 21:10:13 +00:00
if ( ! Bukkit . getOnlineMode ( ) )
{
log . log ( Level . WARNING , " [Total Freedom Mod]: 'online-mode' is set to FALSE in server.properties. This must be set to TRUE in order for in-game superadmin commands to work. " ) ;
}
2011-09-20 02:52:08 +00:00
}
public void onDisable ( )
{
2011-09-20 16:14:09 +00:00
log . log ( Level . INFO , " [Total Freedom Mod] - Disabled. " ) ;
2011-09-20 02:52:08 +00:00
}
public boolean onCommand ( CommandSender sender , Command cmd , String commandLabel , String [ ] args )
{
2011-09-20 14:03:03 +00:00
Player player = null ;
if ( sender instanceof Player )
2011-09-20 02:52:08 +00:00
{
player = ( Player ) sender ;
2011-09-20 14:03:03 +00:00
}
2011-09-20 02:52:08 +00:00
if ( cmd . getName ( ) . equalsIgnoreCase ( " opme " ) )
{
if ( player = = null )
{
sender . sendMessage ( " This command only works in-game. " ) ;
}
else
{
2011-09-20 14:03:03 +00:00
if ( isUserSuperadmin ( sender . getName ( ) ) )
2011-09-20 02:52:08 +00:00
{
sender . setOp ( true ) ;
sender . sendMessage ( ChatColor . YELLOW + " You are now op! " ) ;
2011-09-20 16:14:09 +00:00
log . log ( Level . INFO , " [Total Freedom Mod]: " + sender . getName ( ) + " gave themselves op. " ) ;
2011-09-20 02:52:08 +00:00
}
else
{
sender . sendMessage ( ChatColor . YELLOW + " You do not have permission to use this command. " ) ;
}
}
return true ;
}
else if ( cmd . getName ( ) . equalsIgnoreCase ( " listreal " ) )
{
StringBuilder online = new StringBuilder ( ) ;
online . append ( ChatColor . BLUE ) . append ( " There are " ) . append ( ChatColor . RED ) . append ( Bukkit . getOnlinePlayers ( ) . length ) ;
online . append ( ChatColor . BLUE ) . append ( " out of a maximum " ) . append ( ChatColor . RED ) . append ( Bukkit . getMaxPlayers ( ) ) ;
online . append ( ChatColor . BLUE ) . append ( " players online. " ) ;
sender . sendMessage ( online . toString ( ) ) ;
StringBuilder onlineUsers = new StringBuilder ( ) ;
onlineUsers . append ( " Connected players: " ) ;
boolean first = true ;
for ( Player p : Bukkit . getOnlinePlayers ( ) )
{
2011-09-20 14:03:03 +00:00
if ( first )
2011-09-20 02:52:08 +00:00
{
first = false ;
}
2011-09-20 14:03:03 +00:00
else
{
onlineUsers . append ( " , " ) ;
}
2011-09-20 02:52:08 +00:00
if ( p . isOp ( ) )
{
onlineUsers . append ( ChatColor . RED ) . append ( p . getName ( ) ) ;
}
else
{
onlineUsers . append ( p . getName ( ) ) ;
}
onlineUsers . append ( ChatColor . WHITE ) ;
}
sender . sendMessage ( onlineUsers . toString ( ) ) ;
return true ;
}
else if ( cmd . getName ( ) . equalsIgnoreCase ( " deopall " ) )
{
2011-09-20 14:03:03 +00:00
if ( isUserSuperadmin ( sender . getName ( ) ) | | player = = null )
{
for ( Player p : Bukkit . getOnlinePlayers ( ) )
{
if ( ! isUserSuperadmin ( p . getName ( ) ) & & ! p . getName ( ) . equals ( sender . getName ( ) ) )
{
p . setOp ( false ) ;
}
}
2011-09-20 16:14:09 +00:00
log . log ( Level . INFO , " [Total Freedom Mod]: " + sender . getName ( ) + " used deopall. " ) ;
2011-09-20 14:03:03 +00:00
Bukkit . broadcastMessage ( ChatColor . YELLOW + sender . getName ( ) + " de-op'd everyone on the server. " ) ;
}
else
{
sender . sendMessage ( ChatColor . YELLOW + " You do not have permission to use this command. " ) ;
}
2011-09-20 02:52:08 +00:00
return true ;
}
else if ( cmd . getName ( ) . equalsIgnoreCase ( " opall " ) )
{
2011-09-20 14:03:03 +00:00
if ( isUserSuperadmin ( sender . getName ( ) ) | | player = = null )
{
for ( Player p : Bukkit . getOnlinePlayers ( ) )
{
p . setOp ( true ) ;
}
2011-09-20 16:14:09 +00:00
log . log ( Level . INFO , " [Total Freedom Mod]: " + sender . getName ( ) + " used opall. " ) ;
2011-09-20 14:03:03 +00:00
Bukkit . broadcastMessage ( ChatColor . YELLOW + sender . getName ( ) + " op'd everyone on the server. " ) ;
}
else
{
sender . sendMessage ( ChatColor . YELLOW + " You do not have permission to use this command. " ) ;
}
2011-09-20 02:52:08 +00:00
return true ;
}
2011-09-20 16:14:09 +00:00
else if ( cmd . getName ( ) . equalsIgnoreCase ( " qop " ) ) //Quick OP
{
if ( args . length ! = 1 )
{
return false ;
}
if ( sender . isOp ( ) | | player = = null | | isUserSuperadmin ( sender . getName ( ) ) )
{
2011-09-20 21:10:13 +00:00
boolean matched_player = false ;
2011-09-20 16:14:09 +00:00
for ( Player p : Bukkit . matchPlayer ( args [ 0 ] ) )
{
2011-09-20 21:10:13 +00:00
matched_player = true ;
2011-09-20 16:14:09 +00:00
p . setOp ( true ) ;
2011-09-20 21:10:13 +00:00
2011-09-20 16:14:09 +00:00
Command . broadcastCommandMessage ( sender , " Oping " + p . getName ( ) ) ;
p . sendMessage ( ChatColor . YELLOW + " You are now op! " ) ;
log . log ( Level . INFO , " [Total Freedom Mod]: " + sender . getName ( ) + " op'd " + p . getName ( ) + " . " ) ;
}
2011-09-20 21:10:13 +00:00
if ( ! matched_player )
{
sender . sendMessage ( " No targets matched. " ) ;
}
2011-09-20 16:14:09 +00:00
}
else
{
sender . sendMessage ( ChatColor . YELLOW + " You do not have permission to use this command. " ) ;
}
return true ;
}
else if ( cmd . getName ( ) . equalsIgnoreCase ( " qdeop " ) ) //Quick De-op
{
if ( args . length ! = 1 )
{
return false ;
}
if ( sender . isOp ( ) | | player = = null | | isUserSuperadmin ( sender . getName ( ) ) )
{
2011-09-20 21:10:13 +00:00
boolean matched_player = false ;
2011-09-20 16:14:09 +00:00
for ( Player p : Bukkit . matchPlayer ( args [ 0 ] ) )
{
2011-09-20 21:10:13 +00:00
matched_player = true ;
2011-09-20 16:14:09 +00:00
p . setOp ( false ) ;
2011-09-20 21:10:13 +00:00
2011-09-20 16:14:09 +00:00
Command . broadcastCommandMessage ( sender , " De-opping " + p . getName ( ) ) ;
p . sendMessage ( ChatColor . YELLOW + " You are now op! " ) ;
log . log ( Level . INFO , " [Total Freedom Mod]: " + sender . getName ( ) + " de-op'd " + p . getName ( ) + " . " ) ;
}
2011-09-20 21:10:13 +00:00
if ( ! matched_player )
{
sender . sendMessage ( " No targets matched. " ) ;
}
2011-09-20 16:14:09 +00:00
}
else
{
sender . sendMessage ( ChatColor . YELLOW + " You do not have permission to use this command. " ) ;
}
return true ;
}
2011-09-20 02:52:08 +00:00
return false ;
}
2011-09-20 14:03:03 +00:00
private boolean isUserSuperadmin ( String userName )
2011-09-20 02:52:08 +00:00
{
2011-09-20 16:14:09 +00:00
if ( ! Bukkit . getOnlineMode ( ) )
{
return false ;
}
2011-09-20 02:52:08 +00:00
return Arrays . asList (
" miwojedk " ,
" markbyron " ,
" madgeek1450 "
2011-09-20 14:03:03 +00:00
) . contains ( userName . toLowerCase ( ) ) ;
2011-09-20 02:52:08 +00:00
}
}