Resource (ACF - BETA) Annotation Command Framework

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

  1. If colors is all you want to change, then use manager.setFormat to change what colors are used for <c1><c2><c3>
     
  2. Thank you, what color for Usage? 1?
     
  3. You can specify as many colors as you want, each index maps to the <C#>

    Default text is <c1>

    The color themes are by "message type". Syntax has its own message type, so .setFormat(MessageType.SYNTAX, 1, ChatColor.BLUE); would make the primary color of syntax messages blue instead of yellow.
     
    • Informative Informative x 1
  4. Oh right, so colour 1 (syntax) is yellow by default?

    Usage:
     
  5. I recently added it so you can use Player instead of OnlinePlayer, if you add @Flags("other")

    Also added a flag to it to default to self if null, so:

    Code (Text):
    @Flags("other,defaultself") @Optional Player target
    will let you do the common style of "/foo <target>" where "/foo" w/o a target hits self.
     
    • Useful Useful x 1
  6. Conditions have been deployed, will try to document tomorrow

    example: https://gist.github.com/aikar/420fbb563685580c643f4df35b562f9a

    can put @Conditions("creative") on class or method, or @Conditions("serverowned") on any Residence parameter

    Commit Message:

    please suggest (and hopefully PR) ideas for some default conditions to provide to register in BukkitCommandManager






    And pssst:
    If ACF, Timings, or any of my development libraries have helped you, please consider donating as a thank you.
    [​IMG]
     
    • Like Like x 2
    • Informative Informative x 1
    • Like Like x 1
  7. Did some work on ACF tonight cleaning up issues.

    1) Really looking for someone with JUnit experience to help with unit testing, see https://github.com/aikar/commands/issues/6
    2) Added @CatchAll as a replacement to @UnknownHandler
    - UnknownHandler won't be removed for a while, just marked Deprecated. Just do a find and replace all UnknownHandler with CatchAll and you are done
    3) Added BaseCommand.setContextFlags to allow you to set the value of @Flags on every parameter in the classs/children classes, see https://github.com/aikar/commands/commit/1739bfc39c56dba3cd63fa34d372ec5c1ae0d194
     
    • Winner Winner x 1
  8. MiniDigger

    Supporter

    Thats why we added it ;)
    Once i get time to work on it again ill add the ability to update deoendencies at runtime.
     
    • Winner Winner x 1
  9. Sorry but how can I reload a message file properly? I tried reload it the same way I load it but no use. I'm using file system based language file.
     
  10. Calling BukkitLocales.loadLanguage/loadYamlLanguageFile etc should work, given you are properly passing a new instance of the FileConfiguration.

    I just checked the code, everything should overwrite.
     
    • Like Like x 1
  11. Another problem is when I register BigDecimal.class as OptionalContext, this code throws me a NullPointerException at line 5 when player use the command /withdraw without any argument. I know `amount` is null but I'm not mark the first parameter as Optional. It should send a syntax message back.
    Code (Text):

        @Subcommand("withdraw|ruttien")
        @CommandAlias("withdraw|ruttien")
        @Syntax("<số tiền> [số tờ]")
        public void withdraw(Player player, BigDecimal amount, @Default("1") int size) {
            if (amount.compareTo(new BigDecimal(1000000)) >= 0) {
                if (size > 0 && size < 65) {
                    BigDecimal total = amount.multiply(new BigDecimal(size)).setScale(0, 1);
                    if (this.prisoner.getBalance().compareTo(total) >= 0) {
                        PlayerInventory playerInv = player.getInventory();
                        if (playerInv.firstEmpty() != -1) {
                            this.prisoner.takeMoney(total);
                            playerInv.addItem(PCUtils.buildBanknote(this.prisoner.getName(), amount, size));
                            this.prisoner.message("&aĐã rút thành công &f$" + PCUtils.moneyFormat(total));
                            PCUtils.message(this.plugin.getServer().getConsoleSender(), "&aPlayer &f" + this.prisoner.getName() + " &asuccessfully withdrawn &f$" + PCUtils.moneyFormat(total) + "&a.", true);
                            return;
                        }
                        this.prisoner.message("&cVui lòng làm trống kho đồ trước khi rút tiền.");
                        return;
                    }
                    this.prisoner.message("&cBạn cần phải có &f$" + PCUtils.moneyFormat(total) + " &cđể rút.");
                    return;
                }
                this.prisoner.message("&cSố tờ rút phải lớn hơn &f0 &cvà nhỏ hơn &f65&c.");
                return;
            }
            this.prisoner.message("&cSố tiền rút phải lớn hơn &f$1,000,000&c.");
        }
     
    #217 awsqed, Feb 26, 2018
    Last edited: Feb 26, 2018
  12. Please show the BigDecimal context handler.
     
  13. Code (Text):

    contexts.registerOptionalContext(BigDecimal.class, c -> {
                String arg = c.popFirstArg();
                if (arg != null) {
                    try {
                        return new BigDecimal(arg);
                    } catch (Exception ex) {
                        throw new InvalidCommandArgument("Vui long nhap mot so thap phan hop le.", false);
                    }
                }
                return null;
    });
     
     
  14. Though when I get to code next, I'll add out of the box support for this class to be consistent with the other numbers.

    I think this is technically a bug in ACF, as since its not SenderAware, this should work as you expected.

    In a sender aware context, youd be responsible for throwing InvalidCommandArgument if you can't resolve based on Sender, and i think that expectation bled here.

    I'll try to fix that.
     
    • Like Like x 1

Share This Page