📈 Rank Upper [Universal]

You can configure your desired rank like this:

Member {
    execute-commands=[
        "pex user {player} parent delete group Member",
        "pex user {player} parent add group Expert"
    ]
    levels-needed=0
    message-broadcast="&a>> The player &6{player} &ahas played for &6{time} &aand now is a member Expert on server."
    minutes-needed=720
    money-needed=0
    next-group=Expert

This configuration will give the rank Expert only if the player are in the group Member. if the player is in other any group, will do nothing.

Updated to High-Level commands!

Download: Release

Lol, that’s not exactly what I meant. You’re meant to use CommandSpec to describe the structure of the command. Just defining three strings and making the second two optional isn’t really using this to the full extent. I could write the CommandSpec for this if you want, and trust me it’s much easier to use and it’s extensible.

The javadocs are not exact and dont have many examples. I check if the argumment exists because i didnt understand how work exactly.

But as start, i changed to use high level and i makind another plugin for chat. In this plugin i will aprimore my experiencie with CommandSpec.

Uh, the JavaDocs are pretty clear. The actual explanation, however, resides in SpongeDocs.
To properly use it, make multiple CommandSpecs for each subcommand, then add them as children to the main /ru command. So for instance:

CommandSpec check = CommandSpec.builder()
        .arguments(GenericArguments.playerOrSource(Text.of("player")))
        .executor(new RUCheckCommand())
        .permission("rankupper.check.self").build();

CommandSpec cs = CommandSpec.builder()
        //...
        .child(check, "check")

By the way, note the permission change. A permission automatically inherits things that look like child permissions, so granting rankupper.check automatically grants rankupper.check.others as well. It is explained in SpongeDocs that you should append .self to permissions for commands that require an extra permission to operate on others.
Each subcommand gets its own CommandExecutor. You can use lambdas to simplify this.

RUCommand commands = new RUCommands();
//...
        .executor(commands::check)

And you would have a method just like execute() but named check(). This way you can fit multiple ones in one class.
In your command executor for /ru check, you’d get the player like so:

Player player = args.getOne("player").get();

If you’re targeting a User instead of a Player, you can use GenericArguments.userOrSource() (which I wrote! :3) instead of GenericArguments.playerOrSource().
A couple of other things:
You know that CommandResult you created? Take a look at the method name. CommandResult.success()
This indicates success. If the command failed, don’t return a success, throw a CommandException. That’s what they’re for. The argument for the constructor is a Text, this will be shown to the player. You can also put a boolean after the Text, and if it’s true, it’ll show the usage to the player.
Also, for things that show numbers to the player, maybe try returning a more descriptive result.

return CommandResult.builder().queryResult(minutes).build();

This can be used in command blocks and such by mapmakers.

Essentially, the high-level API is about having Sponge do everything for you. Instead of doing a switch statement on a string, make subcommands. Instead of checking UserStorageService, say that you want a User. Instead of returning success at every point, do things relevant to what actually happened.

In fact, you seem to have skimmed over a lot of SpongeDocs. Things such as injection.

@Inject Game game;
@Inject @ConfigDir(sharedRoot = false) File file;
@Inject PluginContainer container;

Assets.

game.getAssetManager().getAsset(this, "default.conf").get().copyToFile(configFile);

Things like that.
I’d recommend a read of basically all the docs before writing more plugins.

2 Likes

Is this plugin better than [Discontinued] AutoRank [v1.1.1] [API 4.0.3] - #19 by Cubix? Because currently, Autorank continuously and randomly resets my player’s playtime. Sometimes by a few minutes, others by hours, causing them to revert back to the previous ranks.

I think yes, and if not, i am active on community, solving problens and getting some suggestions.

i havent had any issues out of rank upper yet and I’m running one of the latest spongeforge versions with pixelmon. Goodluck mate.

Good to see working fine for you ^^

the commands wont work. Keeps telling unknown command.

And yes, the plugin is installed and shows up on /sponge plugins

Paste your config here to i sse… You added the “/” on command?

Got it fixed so it’s all good now.

This command does not work. It says “Missing language string for commands.added”

Also, [quote=“FabioZumbi12, post:1, topic:12423”]
/ru check [player] - To check for other player.
[/quote] only continues to just your own, not the target player’s.

The language problem you can solve adding this to lang file:

commands.added=&aAdded {time} to player {player}. 

I forgot to add on lang file.

About /ru check [player] maybe show “You played” but is of target.

I’ll check the Lang file but to the /ru check is showing me my own time. I double check that just now.

Our chat is being spammed with promotions, but it’s the same player over and over again.

Its because you dont have configured the correct command to promote the player, then the plugin is trying to promote the same player without sucess, and trying again. Paste your configuration here.

This is what it is supposed to be:

This is what your plugin keeps doing to it:

It looks like your plugin is forcing my lower ranks to the end of the config instead of keeping it in the proper order.

Upon further investigation, it appears that the plugin is forcing all ranks in alphabetic order instead of keeping the order I set up. This is the cause of the spam and commands to not work properly.