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:

    /register
    /reg
    /r
    /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

    Supporter

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

    Please read more carefully before posting spam answers.

     
  4. MiniDigger

    Supporter

    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:

    upload_2017-8-13_16-21-13.png

    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)


    EXAMPLE:

    upload_2017-8-13_16-26-4.png
     

    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):

    @EventHandler
    public void onCommandSend(PlayerCommandPreProcessEvent event) {
        String command = event.getMessage();
        if (command.equalsIgnoreCase(“register”) || command.equalsIgnoreCase(“reg”))
            event.setCancelled(true);
    }
    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

    Supporter

    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.

    upload_2017-8-13_16-36-45.png

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

    Supporter

    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
            bukkitCommandManager.getLocales().loadLanguages();
    With those files in resources folder:

    upload_2017-8-15_6-45-46.png

    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(HashMap.java:1437) ~[?:1.8.0_112]
    at java.util.HashMap$KeyIterator.next(HashMap.java:1461) ~[?:1.8.0_112]
    at com.google.common.collect.AbstractMapBasedMultimap$Itr.next(AbstractMapBasedMultimap.java:1182) ~[minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:47) ~[minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at cz.iwitrag.rpgcore.acf.Locales.loadMissingBundles(Locales.java:100) ~[?:?]
    at cz.iwitrag.rpgcore.acf.CommandManager.addSupportedLanguage(CommandManager.java:287) ~[?:?]
    at cz.iwitrag.rpgcore.RPGCore.onEnable(RPGCore.java:38) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:374) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:323) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:421) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:382) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:337) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544) [minecraft_server.jar:git-Spigot-596221b-9a1fc1e]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_112]

    Any ideas?
     
  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?

    Example:
    Flag to check if a String is valid Minecraft username
    [a-zA-Z0-9_]{3,16}

    upload_2017-8-16_2-27-36.png
     
  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.
     
    #177 Iwitrag, Aug 16, 2017
    Last edited: Aug 16, 2017
  17. MiniDigger

    Supporter

    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
     

Share This Page