Resource (ACF - BETA) Annotation Command Framework

Discussion in 'Spigot Plugin Development' started by Aikar, Apr 19, 2017.

  1. Hi,

    I want to block all commands except register command when player is unregistered
    I have a command for player registration, which can be used these ways:

    /auth register
    /auth reg
    /auth r
    /authme register
    /authme reg
    /authme r

    Does ACF implements some way to listen for command usage?
    So I can block all commands except that for registering?

    Currently I'm using streams to detect all possible combinations but that's not fast.
  2. MiniDigger


    just use the PlayerCommandPreprocessEvent
    • Agree Agree x 1
  3. I do. -.-

    Please read more carefully before posting spam answers.

  4. MiniDigger


    nowhere in your post did you mention that. I would recommend you to stop insulting ppl who are trying to help you.
    acf doesn't implement a specific way to listen for command usage as thats what the bukkit event already does.
    so just listen to the event, check if the player is registered, if not, check if the command entered is in the list of commands you want to allow, if not, block. its as efficient as you will get and if you only have like 10 commands you want to allow, its really not a problem to loop over them.
  5. upload_2017-8-13_16-13-35.png


    I'm asking how to check for that exact command as there are lot of aliases for it.

    Currently those are all aliases player can type to register:


    Checking for all those is inefficient.

    The only solution I can think of is to implement custom listener / event for command...

    so CommandExecutor will save the list of listeners and fire event when command occurs... (inside method)



    Attached Files:

  6. I don’t think you understand + your atitude is not very nice towards someone who is trying to help you (especially when you say you use PlayerCommandPreProcessEvent and you don’t)

    This is what he said you need but you don’t see:
    Code (Text):

    public void onCommandSend(PlayerCommandPreProcessEvent event) {
        String command = event.getMessage();
        if (command.equalsIgnoreCase(“register”) || command.equalsIgnoreCase(“reg”))
    Basially, ACF has no point in providing a method to do that since it is already built into Bukkit. No need to use ACF for this.
  7. MiniDigger


    just add all your aliases into a hashset and then call contains, its O(1).
    acf doesn't really allow you to access anything, it users the minimal access modifiers everywhere.
    when checking you only need to split at space and check contains(args[0]) and contains(args[0] + " " + args[1])
  8. And if I do any change to ACF alias annotation then everything will break.


    I'll just stick to custom event system
  9. MiniDigger


    well, you could fetch the aliases from acf via reflection on start and them populate your filter set using that. they are stored in the subCommand field of the basecommand class (you can just get the keys)
  10. Good day,

    I'm trying to translate messages.
    I have followed instructions from documentation.

    Here is my code in onEnable()

    Code (Text):
            // ACF command manager for Bukkit
            bukkitCommandManager = new BukkitCommandManager(this);
            bukkitCommandManager.addSupportedLanguage(Locales.CZECH); // ERROR
    With those files in resources folder:


    Sadly, I'm getting ConcurrentModificationException: null

    Code (Text):
    [06:43:11 ERROR]: Error occurred while enabling RPGcore v0.0.1 (Is it up to date?)
    java.util.ConcurrentModificationException: null
    at java.util.HashMap$HashIterator.nextNode( ~[?:1.8.0_112]
    at java.util.HashMap$ ~[?:1.8.0_112]
    at$ ~[minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at ~[minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at cz.iwitrag.rpgcore.acf.Locales.loadMissingBundles( ~[?:?]
    at cz.iwitrag.rpgcore.acf.CommandManager.addSupportedLanguage( ~[?:?]
    at cz.iwitrag.rpgcore.RPGCore.onEnable( ~[?:?]
    at ~[minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin( [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin( [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins( [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.t( [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.l( [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.a( [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.DedicatedServer.init( [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at [?:1.8.0_112]

    Any ideas?
    • Winner Winner x 1
  11. @DarkEyeDragon this is the command framework I was talking about btw.
  12. This is amazing...
    • Agree Agree x 1
  13. Def looks like a bug. Let me see what I can do to fix that.
    • Useful Useful x 1
  14. Okay thanks

    Another question:
    Is there a way to add custom flags somehow?

    Flag to check if a String is valid Minecraft username

  15. @Iwitrag and fixed, recompile (use mvn -U to force snapshot if needed)
    Well it is possible if you override the context resolver for OnlinePlayer, you can do it like this:
    Code (Java):

    ContextResolver<?, BukkitCommandExecutionContext> original = getResolver(OnlinePlayer.class);
    registerContext(OnlinePlayer.class, (c) -> {
        String name = c.getFirstArg();
        if (isNameValid(name)) {
            return original.getContext(c);
        } else {
            c.getIssuer().sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name);
            throw new InvalidCommandArgument(false);
    However, just because it's no longer possible to create names that are only 1-2 letters long, there are players out there with them names.

    I've even recently seen a 1 character name join my server, and yeah the length limits on stuff like this made it really hard to do commands on him.
    • Informative Informative x 1
  16. I have tried new version, no exception now but messages are still in english... used the same code as above.

    I have two additional questions:
    1. How can I force command to be for players / console only?
    2. Why is /help not showing command description? It shows only blank command with nothing else.
    #176 Iwitrag, Aug 16, 2017
    Last edited: Aug 16, 2017
  17. MiniDigger


    For player online use Online player as arg.
    There is something like this for console too but I always forget it.
    There is a unstable help api that will greatly improve that.
  18. You need to change the default language too.

    Using per player language isn't finished yet.

    And acf doesn't integrate with /help yet. Maybe soon
  19. Way to advanced for me dude xD
    I hope you can help some other people with it but for me its way to advanced
  20. Opportunity to learn :) It's actually not that advanced. It's powerful, but not really that complex.

    Use this as an opportunity to learn. Study what's going on and when you figure it out, you've learned something!

Share This Page