PowerRank 1.0.5-b

Rank users based on mcMMO power levels

  1. md_5
    Requirements: mcMMO, Vault

    What it does: Assigns users to groups based on their mcMMO power level.

    Config:
    Code (YAML):

    rank
    :
      '1'
    : noob
      '5'
    : potato
      '50'
    : experienced
      '500'
    : god
    interval
    : 60
     
    Installation:
    Configure your ranks in the form of powerlevel: group. The interval is the time in seconds between trying to rank players.

    Note:
    This plugin will remove users from all other "rank" groups, except the highest one they are meant to be in.

    Source (BSD Licensed):
    Code (Java):
    package net.md_5;

    import com.gmail.nossr50.datatypes.player.McMMOPlayer;
    import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
    import com.gmail.nossr50.util.player.UserManager;
    import java.util.Map;
    import java.util.TreeMap;
    import net.milkbowl.vault.permission.Permission;
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;

    public class PowerRank extends JavaPlugin implements Listener, Runnable
    {

        private final Map<Integer, String> ranks = new TreeMap<Integer, String>();
        private Permission permission;

        @Override
        public void onEnable()
        {
            RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration( Permission.class );
            if ( permissionProvider != null )
            {
                permission = permissionProvider.getProvider();
            }

            if ( !getConfig().contains( "rank" ) )
            {
                getConfig().addDefault( "rank.1", "noob" );
                getConfig().addDefault( "rank.5", "potato" );
                getConfig().addDefault( "rank.50", "experienced" );
                getConfig().addDefault( "rank.500", "god" );
            }

            getConfig().addDefault( "interval", 60 );

            getConfig().options().copyDefaults( true );
            saveConfig();

            ConfigurationSection rankSection = getConfig().getConfigurationSection( "rank" );
            for ( String key : rankSection.getKeys( false ) )
            {
                String group = rankSection.getString( key );
                ranks.put( Integer.parseInt( key ), group );
            }

            int period = getConfig().getInt( "interval" ) * 20;
            getServer().getScheduler().scheduleSyncRepeatingTask( this, this, period, period );

            getServer().getPluginManager().registerEvents( this, this );
        }

        @Override
        public void onDisable()
        {
            permission = null;
        }

        @Override
        public void run()
        {
            for ( Player player : getServer().getOnlinePlayers() )
            {
                rank( player );
            }
        }

        @EventHandler
        public void rankEvent(McMMOPlayerLevelUpEvent event)
        {
            rank( event.getPlayer() );
        }

        private void rank(Player player)
        {
            if ( player.hasPermission( "powerrank.exempt" ) )
            {
                return;
            }

            McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer( player );
            if ( mcMMOPlayer == null )
            {
                return;
            }
            int power = mcMMOPlayer.getPowerLevel();

            String highestRank = null;
            for ( Map.Entry<Integer, String> rank : ranks.entrySet() )
            {
                if ( rank.getKey() > power )
                {
                    break;
                }
                highestRank = rank.getValue();
            }

            if ( highestRank != null )
            {
                if ( permission.playerInGroup( null, player, highestRank ) )
                {
                    return;
                }

                for ( String group : permission.getPlayerGroups( null, player ) )
                {
                    if ( ranks.containsValue( group ) )
                    {
                        permission.playerRemoveGroup( null, player, group );
                    }
                }
                permission.playerAddGroup( null, player, highestRank );
            }
        }
    }
     
    nossr50, Tyrelis, zThana and 4 others like this.

Recent Updates

  1. 1.7.10-1.9 rebuild

Recent Reviews

  1. QuangMInhMCPEYT
    QuangMInhMCPEYT
    5/5,
    Version: 1.0.5-b
    cool . just cool ................................................................................
  2. TiggerMc
    TiggerMc
    5/5,
    Version: 1.0.5-b
    Good ...
    Buy i hop add MySQL DATA :)

    .
    .
    .
    .
    .....


















































    ;.
  3. getrex
    getrex
    5/5,
    Version: 1.0.5-b
    seems good plugin...do i need to set permission and power level for default rank
    1. md_5
  4. ezeiger92
    ezeiger92
    5/5,
    Version: 1.0.5-b
    If you are op'd and it seems like this plugin doesn't work, set "powerrank.exempt" to false
    Please put this in the overview, md_5!

    This plugin is simple and just works, and I highly recommend it to anyone who wants to make really flexible perks for using mcmmo.

    My only gripe is that lowering your power level below the lowest rank does not update your ranks.
  5. minecraft7net
    minecraft7net
    5/5,
    Version: 1.0.5
    nice :-) i will use it at my new survival 1.8+ server
  6. Mil0d
    Mil0d
    5/5,
    Version: 1.0.5
    Easy but fun!