2010-10-13 00:49:56 +02:00
//Vminecraft plugin by nossr50 & TrapAlice
import java.util.logging.Level ; //Need this to use LEVEL.INFO etc
public class vminecraftListener extends PluginListener {
public void disable ( ) {
id . a . log ( Level . INFO , " vminecraft disabled " ) ;
2010-09-28 13:47:01 +02:00
}
public void enable ( ) {
2010-10-13 00:49:56 +02:00
settings . getInstance ( ) . loadSettings ( ) ; //Load the settings files
id . a . log ( Level . INFO , " vminecraft enabled " ) ;
2010-09-28 13:47:01 +02:00
}
2010-09-29 18:38:54 +02:00
2010-09-28 13:47:01 +02:00
public boolean onChat ( Player player , String message ) {
2010-10-09 03:20:41 +02:00
String temp2 = " < " + player . getColor ( ) + player . getName ( ) + Colors . White + " > " ; //Copies the formatting of id.java
String adminchat = Colors . DarkPurple + " { " + player . getColor ( ) + player . getName ( ) + Colors . DarkPurple + " } " + Colors . White + " " ; //Special formatting for adminchat
2010-09-29 07:43:48 +02:00
String message2 = " " ; //Used for greentext and FFF
String check = temp2 + message ; //Calculates how long your message will be including your name in the equation, this prevents minecraft clients from crashing when a color code is inserted after a linebreak
2010-10-09 05:09:07 +02:00
if ( settings . getInstance ( ) . adminchat ( ) & & message . startsWith ( " @ " ) & & ( player . isAdmin ( ) ) ) {
2010-09-28 13:47:01 +02:00
for ( Player p : etc . getServer ( ) . getPlayerList ( ) ) {
2010-10-09 00:47:56 +02:00
String blaa = " " ;
2010-09-28 13:47:01 +02:00
if ( p ! = null ) {
2010-10-09 05:09:07 +02:00
if ( player . isAdmin ( ) ) {
2010-09-28 13:47:01 +02:00
for ( int x = 1 ; x < message . length ( ) ; x + + ) {
blaa + = message . charAt ( x ) ;
}
2010-10-09 05:09:07 +02:00
if ( p . isAdmin ( ) ) {
2010-10-09 00:47:56 +02:00
if ( p ! = null ) {
p . sendMessage ( adminchat + blaa ) ;
}
}
2010-09-28 13:47:01 +02:00
}
2010-10-13 00:49:56 +02:00
}
2010-09-28 13:47:01 +02:00
}
2010-10-13 00:49:56 +02:00
id . a . log ( Level . INFO , " @ " + temp2 + message ) ; //So you can read adminchat from the server console
2010-09-28 13:47:01 +02:00
return true ;
2010-10-13 00:49:56 +02:00
2010-09-28 13:47:01 +02:00
}
2010-09-29 07:43:48 +02:00
//Greentext
2010-09-29 18:38:54 +02:00
if ( settings . getInstance ( ) . greentext ( ) & & message . startsWith ( " > " ) ) {
id . a . log ( Level . INFO , " < " + player . getName ( ) + " > " + message ) ;
2010-09-28 13:47:01 +02:00
message = Colors . LightGreen + message ;
message2 = temp2 + message ;
2010-10-13 00:49:56 +02:00
other . gmsg ( message2 ) ;
2010-09-28 13:47:01 +02:00
return true ;
}
2010-09-29 07:43:48 +02:00
//FFF
2010-09-29 18:38:54 +02:00
if ( settings . getInstance ( ) . FFF ( ) & & message . startsWith ( " FFF " ) ) {
id . a . log ( Level . INFO , " < " + player . getName ( ) + " > " + message ) ;
2010-09-28 13:47:01 +02:00
message = Colors . Red + message ;
message2 = temp2 + message ;
2010-10-13 00:49:56 +02:00
other . gmsg ( message2 ) ;
2010-09-28 13:47:01 +02:00
return true ;
}
2010-09-29 07:43:48 +02:00
//QuakeColors
2010-10-13 00:49:56 +02:00
if ( settings . getInstance ( ) . quakeColors ( ) & & message . length ( ) > 2 & & other . lengthCheck ( check ) ) {
2010-09-28 13:47:01 +02:00
String temp = " " ;
for ( int x = 0 ; x < message . length ( ) ; x + + )
{
if ( message . charAt ( x ) = = '^' & & x ! = message . length ( ) - 1 )
{
2010-10-13 00:49:56 +02:00
temp + = other . colorChange ( message . charAt ( x + 1 ) ) ;
2010-09-28 13:47:01 +02:00
x + = 1 ;
}
else {
temp + = message . charAt ( x ) ;
}
}
2010-10-13 00:49:56 +02:00
id . a . log ( Level . INFO , " < " + player . getName ( ) + " > " + message ) ;
2010-09-28 13:47:01 +02:00
message = temp2 + temp + " " ;
for ( Player p : etc . getServer ( ) . getPlayerList ( ) ) {
if ( p ! = null ) {
2010-10-13 00:49:56 +02:00
other . gmsg ( message ) ;
2010-09-28 13:47:01 +02:00
return true ;
}
2010-10-13 00:49:56 +02:00
}
2010-09-28 13:47:01 +02:00
}
return false ;
2010-09-29 07:43:48 +02:00
}
2010-10-13 00:49:56 +02:00
public boolean onCommand ( Player player , String [ ] split ) {
2010-10-09 00:47:56 +02:00
if ( ! player . canUseCommand ( split [ 0 ] ) ) {
return false ;
}
2010-10-09 03:20:41 +02:00
//Replacement for /tp
2010-10-09 06:15:57 +02:00
if ( settings . getInstance ( ) . cmdTp ( ) & & split [ 0 ] . equalsIgnoreCase ( " /tp " ) ) {
2010-10-09 00:47:56 +02:00
{
if ( split . length < 2 ) {
player . sendMessage ( Colors . Rose + " Correct usage is: /tp [player] " ) ;
return true ;
}
Player playerTarget = etc . getServer ( ) . matchPlayer ( split [ 1 ] ) ;
if ( player . getName ( ) . equalsIgnoreCase ( split [ 1 ] ) ) {
player . sendMessage ( Colors . Rose + " You're already here! " ) ;
return true ;
}
if ( ! player . hasControlOver ( playerTarget ) ) {
player . sendMessage ( Colors . Red + " That player has higher permissions than you. " ) ;
return true ;
}
if ( playerTarget ! = null ) {
2010-10-13 00:49:56 +02:00
id . a . log ( Level . INFO , player . getName ( ) + " teleported to " + playerTarget . getName ( ) ) ;
2010-10-09 00:47:56 +02:00
player . teleportTo ( playerTarget ) ;
return true ;
} else {
player . sendMessage ( Colors . Rose + " Can't find user " + split [ 1 ] + " . " ) ;
return true ;
}
}
}
2010-10-09 03:20:41 +02:00
//Replacement for /tphere
2010-10-09 06:15:57 +02:00
if ( settings . getInstance ( ) . cmdTphere ( ) & & ( split [ 0 ] . equalsIgnoreCase ( " /tphere " ) | | split [ 0 ] . equalsIgnoreCase ( " /s " ) ) ) {
2010-10-09 00:47:56 +02:00
if ( split . length < 2 ) {
player . sendMessage ( Colors . Rose + " Correct usage is: /tphere [player] " ) ;
return true ;
}
2010-10-13 00:49:56 +02:00
2010-10-09 00:47:56 +02:00
Player playerTarget = etc . getServer ( ) . matchPlayer ( split [ 1 ] ) ;
2010-10-13 00:49:56 +02:00
2010-10-09 00:47:56 +02:00
if ( ! player . hasControlOver ( playerTarget ) ) {
player . sendMessage ( Colors . Red + " That player has higher permissions than you. " ) ;
return true ;
}
if ( player . getName ( ) . equalsIgnoreCase ( split [ 1 ] ) ) {
player . sendMessage ( Colors . Rose + " Wow look at that! You teleported yourself to yourself! " ) ;
return true ;
}
if ( playerTarget ! = null ) {
2010-10-13 00:49:56 +02:00
id . a . log ( Level . INFO , player . getName ( ) + " teleported " + player . getName ( ) + " to their self. " ) ;
2010-10-09 00:47:56 +02:00
playerTarget . teleportTo ( player ) ;
} else {
player . sendMessage ( Colors . Rose + " Can't find user " + split [ 1 ] + " . " ) ;
}
}
2010-10-09 03:20:41 +02:00
//Global messages that should only parse when a command can be successful
2010-10-09 06:15:57 +02:00
if ( settings . getInstance ( ) . globalmessages ( ) & & split [ 0 ] . equalsIgnoreCase ( " /kick " ) ) {
2010-10-09 03:20:41 +02:00
Player playerTarget = etc . getServer ( ) . matchPlayer ( split [ 1 ] ) ;
if ( playerTarget ! = null & & ! playerTarget . hasControlOver ( player ) ) {
other . gmsg ( player . getColor ( ) + player . getName ( ) + Colors . Blue + " has kicked " + Colors . Red + playerTarget . getColor ( ) + playerTarget . getName ( ) ) ;
2010-10-09 00:47:56 +02:00
}
}
2010-10-09 06:15:57 +02:00
if ( settings . getInstance ( ) . globalmessages ( ) & & split [ 0 ] . equalsIgnoreCase ( " /ban " ) ) {
2010-10-09 03:20:41 +02:00
Player playerTarget = etc . getServer ( ) . matchPlayer ( split [ 1 ] ) ;
if ( playerTarget ! = null & & ! playerTarget . hasControlOver ( player ) ) {
other . gmsg ( player . getColor ( ) + player . getName ( ) + Colors . Blue + " has banned " + Colors . Red + playerTarget . getColor ( ) + playerTarget . getName ( ) ) ;
2010-10-09 00:47:56 +02:00
}
}
2010-10-09 06:15:57 +02:00
if ( settings . getInstance ( ) . globalmessages ( ) & & split [ 0 ] . equalsIgnoreCase ( " /ipban " ) ) {
2010-10-09 03:20:41 +02:00
Player playerTarget = etc . getServer ( ) . matchPlayer ( split [ 1 ] ) ;
if ( playerTarget ! = null & & ! playerTarget . hasControlOver ( player ) ) {
other . gmsg ( player . getColor ( ) + player . getName ( ) + Colors . Blue + " has IP banned " + Colors . Red + playerTarget . getColor ( ) + playerTarget . getName ( ) ) ;
2010-10-09 00:47:56 +02:00
}
}
2010-10-09 06:15:57 +02:00
if ( settings . getInstance ( ) . globalmessages ( ) & & split [ 0 ] . equalsIgnoreCase ( " /time " ) ) {
2010-10-09 00:47:56 +02:00
if ( split . length < = 2 ) {
other . gmsg ( Colors . Blue + " Time changes thanks to " + player . getColor ( ) + player . getName ( ) ) ;
return false ;
}
}
2010-10-13 00:49:56 +02:00
//Should only reload vminecraft settings if the player is able to use /reload
if ( split [ 0 ] . equalsIgnoreCase ( " /reload " ) & & player . canUseCommand ( " /reload " ) ) {
settings . getInstance ( ) . loadSettings ( ) ;
return false ;
}
2010-10-09 00:47:56 +02:00
//Rules
2010-10-09 06:15:57 +02:00
if ( settings . getInstance ( ) . cmdRules ( ) & & split [ 0 ] . equalsIgnoreCase ( " /rules " ) ) {
2010-10-09 07:21:38 +02:00
etc . getInstance ( ) . addCommand ( " /rules " , " Displays the rules " ) ;
2010-10-09 03:20:41 +02:00
for ( String str : settings . getInstance ( ) . getRules ( ) ) {
player . sendMessage ( Colors . Blue + str ) ;
}
2010-10-09 00:47:56 +02:00
return true ;
2010-09-28 13:47:01 +02:00
}
2010-09-29 07:43:48 +02:00
//Fabulous
2010-10-09 00:47:56 +02:00
if ( split [ 0 ] . equalsIgnoreCase ( " /fabulous " ) & & settings . getInstance ( ) . cmdFabulous ( ) ) {
2010-10-09 07:21:38 +02:00
etc . getInstance ( ) . addCommand ( " /fabulous " , " makes text SUUUPER " ) ;
2010-09-28 13:47:01 +02:00
if ( split . length = = 1 ) { return false ; }
String temp = " " ;
String str = " " ;
2010-10-09 00:47:56 +02:00
str = etc . combineSplit ( 1 , split , " " ) ;
2010-09-28 13:47:01 +02:00
String temp2 = " < " + player . getName ( ) + " > " + str ;
String [ ] rainbow = new String [ ] { Colors . Red , Colors . Rose , Colors . Yellow , Colors . Green , Colors . Blue , Colors . LightPurple , Colors . Purple } ;
int counter = 0 ;
2010-10-13 00:49:56 +02:00
if ( other . lengthCheck ( temp2 ) )
2010-09-28 13:47:01 +02:00
{
2010-10-13 00:49:56 +02:00
id . a . log ( Level . INFO , player . getName ( ) + " fabulously said \" " + str + " \" " ) ;
2010-09-28 13:47:01 +02:00
for ( int x = 0 ; x < str . length ( ) ; x + + )
{
temp + = rainbow [ counter ] + str . charAt ( x ) ;
counter + + ;
if ( str . charAt ( x ) = = ' ' ) { counter - - ; }
if ( counter = = - 1 ) { counter = 6 ; }
if ( counter = = 7 ) { counter = 0 ; }
}
str = temp + " " ;
2010-10-09 00:47:56 +02:00
String message = " < " + player . getColor ( ) + player . getName ( ) + Colors . White + " > " + str ;
2010-10-13 00:49:56 +02:00
2010-09-28 13:47:01 +02:00
other . gmsg ( message ) ;
2010-10-13 00:49:56 +02:00
return true ;
2010-09-28 13:47:01 +02:00
} else {
player . sendMessage ( Colors . Rose + " Message is too long " ) ;
}
2010-10-09 00:47:56 +02:00
return true ;
2010-09-28 13:47:01 +02:00
}
2010-09-29 07:43:48 +02:00
//Promote
2010-10-09 00:47:56 +02:00
if ( settings . getInstance ( ) . cmdPromote ( ) & & split [ 0 ] . equalsIgnoreCase ( " /promote " ) ) {
if ( split . length ! = 2 )
{
player . sendMessage ( Colors . Rose + " Usage is /promote [Player] " ) ;
2010-10-13 00:49:56 +02:00
2010-10-09 00:47:56 +02:00
}
Player playerTarget = null ;
2010-10-13 00:49:56 +02:00
if ( split . length = = 2 ) {
2010-10-09 00:47:56 +02:00
for ( Player p : etc . getServer ( ) . getPlayerList ( ) )
{
if ( p . getName ( ) . equalsIgnoreCase ( split [ 1 ] ) )
{
playerTarget = p ;
}
}
if ( playerTarget ! = null )
{
2010-10-13 00:49:56 +02:00
String playerTargetGroup [ ] = playerTarget . getGroups ( ) ;
String playerGroup [ ] = player . getGroups ( ) ;
player . sendMessage ( " Debug data: " ) ;
player . sendMessage ( " PlayerTarget: " + playerTargetGroup [ 0 ] ) ;
player . sendMessage ( " Player: " + playerGroup [ 0 ] ) ;
if ( playerTargetGroup [ 0 ] . equals ( " admins " ) )
2010-10-09 00:47:56 +02:00
{
player . sendMessage ( Colors . Rose + " You can not promote " + split [ 1 ] + " any higher. " ) ;
}
2010-10-13 00:49:56 +02:00
if ( playerTargetGroup [ 0 ] . equals ( " mods " ) & & ( playerGroup [ 0 ] . equals ( " owner " ) ) )
2010-10-09 00:47:56 +02:00
{
playerTarget . setGroups ( ranks . Admins ) ;
etc . getInstance ( ) . getDataSource ( ) . modifyPlayer ( playerTarget ) ;
String message = Colors . Yellow + split [ 1 ] + " was promoted to " + Colors . Rose + " Admin " ;
other . gmsg ( message ) ;
}
2010-10-13 00:49:56 +02:00
else if ( playerTargetGroup [ 0 ] . equals ( " trusted " ) & & ( playerGroup [ 0 ] . equals ( " admins " ) | | playerGroup [ 0 ] . equals ( " owner " ) ) )
2010-10-09 00:47:56 +02:00
{
playerTarget . setGroups ( ranks . Mods ) ;
2010-10-13 00:49:56 +02:00
playerTargetGroup [ 0 ] = " Mods " ;
2010-10-09 00:47:56 +02:00
etc . getInstance ( ) . getDataSource ( ) . modifyPlayer ( playerTarget ) ;
String message = Colors . Yellow + split [ 1 ] + " was promoted to " + Colors . DarkPurple + " Mod " ;
other . gmsg ( message ) ;
}
2010-10-13 00:49:56 +02:00
else if ( playerTargetGroup [ 0 ] . equals ( " default " ) & & ( playerGroup [ 0 ] . equals ( " mods " ) | | playerGroup [ 0 ] . equals ( " admins " ) | | player . isInGroup ( " owner " ) ) )
2010-10-09 00:47:56 +02:00
{
playerTarget . setGroups ( ranks . Trusted ) ;
etc . getInstance ( ) . getDataSource ( ) . modifyPlayer ( playerTarget ) ;
String message = Colors . Yellow + split [ 1 ] + " was promoted to " + Colors . LightGreen + " Trusted " ;
other . gmsg ( message ) ;
}
return true ;
}
else {
player . sendMessage ( Colors . Rose + " Player not found " ) ;
}
2010-10-13 00:49:56 +02:00
id . a . log ( Level . INFO , " Command used by " + player + " " + split [ 0 ] + " " + split [ 1 ] + " " ) ;
2010-10-09 00:47:56 +02:00
}
2010-10-13 00:49:56 +02:00
}
2010-09-29 07:43:48 +02:00
//Demote
2010-10-09 00:47:56 +02:00
if ( settings . getInstance ( ) . cmdPromote ( ) & & split [ 0 ] . equalsIgnoreCase ( " /promote " ) )
{
if ( split . length ! = 2 )
{
player . sendMessage ( Colors . Rose + " Usage is /demote [Player] " ) ;
}
Player playerTarget = null ;
for ( Player p : etc . getServer ( ) . getPlayerList ( ) )
{
if ( p . getName ( ) . equalsIgnoreCase ( split [ 1 ] ) )
{
playerTarget = p ;
}
}
if ( playerTarget ! = null )
{
if ( playerTarget . isInGroup ( " admins " ) & & ( player . isInGroup ( " superadmins " ) ) )
{
playerTarget . setGroups ( ranks . Mods ) ;
etc . getInstance ( ) . getDataSource ( ) . modifyPlayer ( playerTarget ) ;
2010-09-28 13:47:01 +02:00
String message = Colors . Yellow + split [ 1 ] + " was demoted to " + Colors . DarkPurple + " Mod " ;
other . gmsg ( message ) ;
2010-10-09 00:47:56 +02:00
}
if ( playerTarget . isInGroup ( " mods " ) & & ( player . isInGroup ( " admins " ) | | player . isInGroup ( " superadmins " ) ) )
{
playerTarget . setGroups ( ranks . Trusted ) ;
etc . getInstance ( ) . getDataSource ( ) . modifyPlayer ( playerTarget ) ;
String message = Colors . Yellow + split [ 1 ] + " was demoted to " + Colors . LightGreen + " Trusted " ;
other . gmsg ( message ) ;
}
else if ( playerTarget . isInGroup ( " trusted " ) & & ( player . isInGroup ( " mods " ) | | player . isInGroup ( " superadmins " ) | | player . isInGroup ( " admins " ) ) )
{
playerTarget . setGroups ( ranks . Def ) ;
etc . getInstance ( ) . getDataSource ( ) . modifyPlayer ( playerTarget ) ;
String message = Colors . Yellow + split [ 1 ] + " was demoted to " + Colors . White + " Default " ;
other . gmsg ( message ) ;
}
else if ( playerTarget . isInGroup ( " default " ) & & ( player . isInGroup ( " mods " ) | | player . isInGroup ( " admins " ) | | player . isInGroup ( " superadmins " ) ) )
{
player . sendMessage ( Colors . Rose + " You can not demote " + split [ 1 ] + " any lower. " ) ;
}
}
else {
player . sendMessage ( Colors . Rose + " Player not found " ) ;
}
2010-10-13 00:49:56 +02:00
id . a . log ( Level . INFO , " Command used by " + player + " " + split [ 0 ] + " " + split [ 1 ] + " " ) ;
2010-10-09 00:47:56 +02:00
return true ;
}
2010-10-09 03:20:41 +02:00
//Whois will display info about a player
2010-10-09 07:21:38 +02:00
if ( settings . getInstance ( ) . cmdWhoIs ( ) & & split [ 0 ] . equalsIgnoreCase ( " /whois " ) ) {
etc . getInstance ( ) . addCommand ( " /whois " , " /whois [user] " ) ;
2010-10-09 03:20:41 +02:00
if ( split . length < 2 ) {
2010-10-09 00:47:56 +02:00
player . sendMessage ( Colors . Rose + " Usage is /whois [player] " ) ;
}
2010-09-29 07:43:48 +02:00
String admin = " " ;
String ignore = " " ;
2010-10-09 00:47:56 +02:00
String IP = " " ;
Player playerTarget = null ;
for ( Player p : etc . getServer ( ) . getPlayerList ( ) )
{
if ( p . getName ( ) . equalsIgnoreCase ( split [ 1 ] ) )
{
playerTarget = p ;
}
}
if ( playerTarget ! = null ) {
2010-10-13 00:49:56 +02:00
2010-10-09 00:47:56 +02:00
IP = playerTarget . getIP ( ) ;
if ( playerTarget . canIgnoreRestrictions ( ) ) {
2010-09-29 07:43:48 +02:00
ignore = " True " ;
} else {
ignore = " False " ;
}
2010-10-09 00:47:56 +02:00
if ( playerTarget . canIgnoreRestrictions ( ) ) {
2010-09-29 07:43:48 +02:00
admin = " True " ;
} else {
admin = " False " ;
2010-10-09 00:47:56 +02:00
}
2010-10-09 07:21:38 +02:00
2010-10-09 03:20:41 +02:00
//Displaying the information
2010-10-09 00:47:56 +02:00
player . sendMessage ( Colors . Blue + " Whois results for " + split [ 1 ] + " . " ) ;
2010-10-09 03:20:41 +02:00
//Group
2010-10-09 07:21:38 +02:00
for ( String group : playerTarget . getGroups ( ) ) {
player . sendMessage ( Colors . Blue + " Groups: " + group ) ;
}
2010-10-09 03:20:41 +02:00
//Admin
2010-10-09 00:47:56 +02:00
player . sendMessage ( Colors . Blue + " Admin: " + admin ) ;
2010-10-09 03:20:41 +02:00
//IP
2010-10-09 00:47:56 +02:00
player . sendMessage ( Colors . Blue + " IP: " + IP ) ;
2010-10-09 03:20:41 +02:00
//Restrictions
2010-10-09 00:47:56 +02:00
player . sendMessage ( Colors . Blue + " Can ignore restrictions: " + ignore ) ;
2010-10-09 07:21:38 +02:00
2010-10-09 00:47:56 +02:00
} else {
player . sendMessage ( Colors . Rose + " Player not found. " ) ;
}
2010-10-09 07:21:38 +02:00
return true ;
2010-10-09 03:20:41 +02:00
}
//Say
2010-10-09 06:15:57 +02:00
if ( settings . getInstance ( ) . cmdSay ( ) & & ( split [ 0 ] . equalsIgnoreCase ( " /say " ) ) ) {
2010-10-09 00:47:56 +02:00
String sayan ;
sayan = etc . combineSplit ( 1 , split , " " ) ;
other . gmsg ( Colors . Yellow + sayan ) ;
}
2010-10-09 03:20:41 +02:00
//Should this be included?
else {
2010-09-28 13:47:01 +02:00
return false ;
2010-10-09 03:20:41 +02:00
}
//Needs to be included
2010-09-28 13:47:01 +02:00
return true ;
}
2010-10-13 00:49:56 +02:00
//Temporary until I can figure out how to make my plugin load on startup
public void onLogin ( Player player ) {
settings . getInstance ( ) . loadSettings ( ) ;
}
}