2013-01-15 23:55:41 +01:00
package com.gmail.nossr50.commands.mc ;
2013-01-16 08:50:18 +01:00
import org.bukkit.Bukkit ;
2013-01-15 23:55:41 +01:00
import org.bukkit.ChatColor ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandExecutor ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
import com.gmail.nossr50.config.Config ;
import com.gmail.nossr50.datatypes.SkillType ;
2013-01-16 20:58:14 +01:00
import com.gmail.nossr50.locale.LocaleLoader ;
2013-01-16 08:50:18 +01:00
import com.gmail.nossr50.runnables.mcRankAsync ;
2013-01-15 23:55:41 +01:00
import com.gmail.nossr50.util.Leaderboard ;
2013-01-16 20:58:14 +01:00
import com.gmail.nossr50.util.Skills ;
2013-01-15 23:55:41 +01:00
public class McrankCommand implements CommandExecutor {
2013-01-16 00:35:21 +01:00
@Override
2013-01-16 08:50:18 +01:00
public boolean onCommand ( CommandSender sender , Command command , String label , String [ ] args ) {
2013-01-16 05:09:49 +01:00
if ( ! Config . getInstance ( ) . getUseMySQL ( ) )
Leaderboard . updateLeaderboards ( ) ; //Make sure the information is up to date
2013-01-16 00:35:21 +01:00
2013-01-16 08:50:18 +01:00
if ( sender instanceof Player ) {
Player player = ( Player ) sender ;
String playerName ;
switch ( args . length ) {
case 0 :
playerName = player . getName ( ) ;
break ;
case 1 :
playerName = args [ 0 ] ;
break ;
default :
return false ;
}
sender . sendMessage ( ChatColor . GOLD + " -=PERSONAL RANKINGS=- " ) ;
sender . sendMessage ( ChatColor . RED + " TARGET: " + ChatColor . WHITE + playerName ) ;
2013-01-16 00:35:21 +01:00
if ( Config . getInstance ( ) . getUseMySQL ( ) ) {
2013-01-16 08:50:18 +01:00
sqlDisplay ( sender , playerName ) ;
2013-01-16 00:35:21 +01:00
} else {
2013-01-16 08:50:18 +01:00
flatfileDisplay ( sender , playerName ) ;
2013-01-16 00:35:21 +01:00
}
} else {
2013-01-16 08:50:18 +01:00
sender . sendMessage ( " Command currently not supported for console. " ) ;
2013-01-16 00:35:21 +01:00
}
return true ;
}
2013-01-16 01:09:48 +01:00
public void flatfileDisplay ( CommandSender sender , String playerName ) {
2013-01-16 00:35:21 +01:00
for ( SkillType skillType : SkillType . values ( ) ) {
2013-01-16 20:58:14 +01:00
int [ ] rankInts = Leaderboard . getPlayerRank ( playerName , skillType ) ;
2013-01-16 00:35:21 +01:00
if ( skillType . equals ( SkillType . ALL ) )
continue ; // We want the overall ranking to be at the bottom
2013-01-16 20:58:14 +01:00
if ( rankInts [ 1 ] = = 0 ) {
sender . sendMessage ( LocaleLoader . getString ( " Commands.mcrank.Skill " , new Object [ ] { Skills . localizeSkillName ( skillType ) , LocaleLoader . getString ( " Commands.mcrank.Unranked " ) } ) ) ; //Don't bother showing ranking for players without skills
} else {
sender . sendMessage ( LocaleLoader . getString ( " Commands.mcrank.Skill " , new Object [ ] { Skills . localizeSkillName ( skillType ) , String . valueOf ( rankInts [ 0 ] ) } ) ) ;
}
}
//Show the powerlevel ranking
int [ ] rankInts = Leaderboard . getPlayerRank ( playerName , SkillType . ALL ) ;
if ( rankInts [ 1 ] = = 0 ) {
sender . sendMessage ( LocaleLoader . getString ( " Commands.mcrank.Skill " , new Object [ ] { Skills . localizeSkillName ( SkillType . ALL ) , LocaleLoader . getString ( " Commands.mcrank.Unranked " ) } ) ) ; //Don't bother showing ranking for players without skills
} else {
sender . sendMessage ( LocaleLoader . getString ( " Commands.mcrank.Skill " , new Object [ ] { Skills . localizeSkillName ( SkillType . ALL ) , String . valueOf ( rankInts [ 0 ] ) } ) ) ;
2013-01-16 00:35:21 +01:00
}
2013-01-16 20:58:14 +01:00
2013-01-16 00:35:21 +01:00
sender . sendMessage ( ChatColor . YELLOW + " Overall " + ChatColor . GREEN + " - " + ChatColor . GOLD + " Rank " + ChatColor . WHITE + " # " + ChatColor . GREEN + Leaderboard . getPlayerRank ( playerName , SkillType . ALL ) ) ;
}
private void sqlDisplay ( CommandSender sender , String playerName ) {
2013-01-16 08:50:18 +01:00
Bukkit . getScheduler ( ) . runTaskAsynchronously ( Bukkit . getPluginManager ( ) . getPlugin ( " mcMMO " ) , new mcRankAsync ( playerName , sender ) ) ;
2013-01-16 00:35:21 +01:00
}
}