HelpChat / DeluxeMenus

DeluxeMenus but open source!?
https://wiki.helpch.at/clips-plugins/deluxemenus
MIT License
72 stars 35 forks source link

Add argument validation and `is object` + `string length` requirements #47

Closed Starmism closed 7 months ago

Starmism commented 7 months ago

This PR adds the ability to list argument validation directly in the arguments list, while also maintaining backwards compatibility.

Example: https://paste.helpch.at/medacemeve.yaml

Requirements

This PR also adds two new requirements to facilitate most argument validation: is object & string length.

string length is very simple, it takes an input, and either a max, a min, or both. Example:

      length:
        type: "string length"
        input: "{player}"
        min: 2
        max: 32
        deny_commands:
          - "[message] Player must be between 2 and 32 characters long."

is object is a bit more complex, but also more useful. It attempts to parse the given input as a certain type of Java object. The current options are int, double, uuid, and player. The first three are self-explanatory. player works for both UUIDs and usernames, and uses Bukkit.getPlayer(UUID) and Bukkit.getPlayerExact(USERNAME) to ensure only real online players are counted. Example:

      player:
        type: "is object"
        input: "{player}"
        object: "player"
        deny_commands:
          - "[message] Must be a player's username or UUID."

Further Discussion

A topic open for discussion is the inclusion of an offlineplayer type for is object. On Spigot, this can be abused to send multiple HTTP requests to Mojang on the main thread, thereby lagging servers heavily. On Paper, there is a method that only accesses local storage and is therefore safe, but DeluxeMenus currently does not have the requisite infrastructure, in my opinion, to do something specifically for Paper only.