2013-08-22 09:11:33 -04:00
package com.gmail.nossr50.commands.experience ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandExecutor ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
import com.gmail.nossr50.mcMMO ;
import com.gmail.nossr50.datatypes.experience.FormulaType ;
import com.gmail.nossr50.locale.LocaleLoader ;
import com.gmail.nossr50.runnables.database.FormulaConversionTask ;
2014-07-27 11:14:46 -04:00
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask ;
2013-08-22 09:11:33 -04:00
import com.gmail.nossr50.util.player.UserManager ;
public class ConvertExperienceCommand implements CommandExecutor {
@Override
public boolean onCommand ( CommandSender sender , Command command , String label , String [ ] args ) {
switch ( args . length ) {
case 2 :
FormulaType previousType = mcMMO . getFormulaManager ( ) . getPreviousFormulaType ( ) ;
FormulaType newType = FormulaType . getFormulaType ( args [ 1 ] . toUpperCase ( ) ) ;
if ( newType = = FormulaType . UNKNOWN ) {
sender . sendMessage ( LocaleLoader . getString ( " Commands.mcconvert.Experience.Invalid " ) ) ;
return true ;
}
if ( previousType = = newType ) {
sender . sendMessage ( LocaleLoader . getString ( " Commands.mcconvert.Experience.Same " , newType . toString ( ) ) ) ;
return true ;
}
sender . sendMessage ( LocaleLoader . getString ( " Commands.mcconvert.Experience.Start " , previousType . toString ( ) , newType . toString ( ) ) ) ;
UserManager . saveAll ( ) ;
UserManager . clearAll ( ) ;
new FormulaConversionTask ( sender , newType ) . runTaskLater ( mcMMO . p , 1 ) ;
for ( Player player : mcMMO . p . getServer ( ) . getOnlinePlayers ( ) ) {
2014-07-27 11:14:46 -04:00
new PlayerProfileLoadingTask ( player ) . runTaskLaterAsynchronously ( mcMMO . p , 1 ) ; // 1 Tick delay to ensure the player is marked as online before we begin loading
2013-08-22 09:11:33 -04:00
}
return true ;
default :
return false ;
}
}
}