full-stack software nerd
jonahseguin / drink Goto Github PK
View Code? Open in Web Editor NEWcommand framework and argument parser for spigot plugins
command framework and argument parser for spigot plugins
I want to use your library in a project of mine but I want to make sure what I'm allowed and not allowed to do with your code
I'd like to suggest some improvements on flag parsing and the autocompletion of flags. This is more of a collection of issues which are all closely related to one another.
I have written a little report on the current situation and how I think an implementation could look like, hoping make the actual development a bit easier.
Current Behaviour:
First Example:
This example uses three flags of different types
Code:
public void withFlags(@Sender Player sender, @Flag('s') String stringFlag, @Flag('i') int integerFlag, @Flag('b') boolean booleanFlag) {
sender.sendMessage(ChatColor.YELLOW + "StringFlag: " + stringFlag + " IntegerFlag: " + integerFlag + " BooleanFlag: " + booleanFlag);
}
Issues:
Flags cannot be completed:
In this example, there is always a boolean-value suggested after the second flag, regardless of order:
Second Example:
This example uses three booleans:
Code:
@Command(name = "bflagtest", desc = "A test command with a bunch of boolean flags")
public void withBooleanFlags(@Sender Player sender, @Flag('a') boolean flag1, @Flag('b') boolean flag2, @Flag('c') boolean flag3) {
sender.sendMessage(ChatColor.YELLOW + "flag1: " + flag1 + " flag2: " + flag2 + " flag3: " + flag3);
}
Issues:
In here, the second suggestion is a boolean-value:
When having a boolean-flag enclosed in two other boolean-flag, it does not get parsed:
Group parsing is not supported:
Proposal for expected behaviour:
My idea would be to mimick the behaviour of WorldEdit, as this libary is already inspired and their solution is good.
Tab-Completion of grouped flags:
Ability to group boolean and value flags with one value flag being able to end a group:
I know it's a lot to ask for, but it might be something to have on the radar.
org.apache.logging.log4j.util.Strings
class should be treated as private and not be used and it's also not avail in all spigot/bukkit runtimes unlike apache commons string utils.
I know the Drink API hasn't had an issue made in a while, but I ran into a weird issue recently where I was working on a ban command.
The command basically should run with these args /ban -s[silent]
For some reason, when I try to use the flag argument normally so I run "/ban Skitbet -s test" it has a command usage error.
https://gyazo.com/d031ad5b9d9388d43ad8f91fd48f064d (Here is the code I have from a test command when I was trying to debug this)
https://gyazo.com/3ade4b12fdab4dcd699b4fce67bc57b2 (Here is a video showcasing the issue)
[02:05:10 ERROR]: Error occurred while enabling GrindCore v1.0 (Is it up to date?)
com.jonahseguin.drink.exception.CommandRegistrationException: Could not register command 'grind-core': No provider bound for ActionType
at com.jonahseguin.drink.command.DrinkCommandService.register(DrinkCommandService.java:132) ~[GrindCore-1.0.jar:?]
at net.gemoria.grindcore.GrindCore.loadCommands(GrindCore.java:162) ~[GrindCore-1.0.jar:?]
at net.gemoria.grindcore.GrindCore.onEnable(GrindCore.java:82) ~[GrindCore-1.0.jar:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281) ~[?:git-UniverseSpigot-"fe2588e"]
at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:189) ~[?:git-UniverseSpigot-"fe2588e"]
at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[?:git-UniverseSpigot-"fe2588e"]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[?:git-UniverseSpigot-"fe2588e"]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugin(CraftServer.java:655) ~[?:git-UniverseSpigot-"fe2588e"]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugins(CraftServer.java:566) ~[?:git-UniverseSpigot-"fe2588e"]
at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:638) ~[?:git-UniverseSpigot-"fe2588e"]
at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:437) ~[?:git-UniverseSpigot-"fe2588e"]
at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:316) ~[?:git-UniverseSpigot-"fe2588e"]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1103) ~[?:git-UniverseSpigot-"fe2588e"]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320) ~[?:git-UniverseSpigot-"fe2588e"]
at java.lang.Thread.run(Thread.java:840) ~[?:?]
Caused by: com.jonahseguin.drink.exception.MissingProviderException: No provider bound for ActionType
at com.jonahseguin.drink.parametric.ProviderAssigner.assignProvidersFor(ProviderAssigner.java:41) ~[GrindCore-1.0.jar:?]
at com.jonahseguin.drink.command.DrinkCommand.<init>(DrinkCommand.java:47) ~[GrindCore-1.0.jar:?]
at com.jonahseguin.drink.command.CommandExtractor.extractCommand(CommandExtractor.java:60) ~[GrindCore-1.0.jar:?]
at com.jonahseguin.drink.command.CommandExtractor.extractCommands(CommandExtractor.java:29) ~[GrindCore-1.0.jar:?]
at com.jonahseguin.drink.command.DrinkCommandService.register(DrinkCommandService.java:124) ~[GrindCore-1.0.jar:?]
By default Drink supports out of the box Enums for commands parameters, but when using an enum as command parameter it triggers this exception on enable
ActionType is just an enum, this is the command
@Command(name = "data", aliases = {}, desc = "Gestione dati dei giocatori in Cache", usage = "data <ACTION> <DATA> <VALUE>")
@Require(value = "grindcore.admin" ) //, message = "Non hai il permesso di usare il comando!")
public void onData(@Sender CommandSender sender, ActionType actionType, DataType data, Player target, @OptArg int value){
final OnlineUser user = OnlineUser.adapter(target);
switch (actionType){
case SET -> user.setData(data, value);
case ADD -> user.addData(data, value);
case REMOVE -> user.removeData(data, value);
}
sender.sendMessage("§7[§eGrindCore§7] §fValore da modificare correttamente impostato per -> " + target.getName());
}
Extend the drink api to include cooldown annotations for ease of managing cooldowns @Require
-like
Per: the time at which the uses gets reset
Rate: the number of times that are allowed the command to be executed in a specific amount of time
BucketType: Which to apply the cooldown on
This is inspired by discord.py cooldowns
@Command
annotated methodThe cooldown applys on that command with respect to the bucket type, if a player is on cooldown. it will call a handler callback1.
Either The cooldown mapping is shared across all sub commands OR Add a mapping as the same as @Cooldown
being annotated on all of the sub commands
You can achive this by making a boolean or another annotated @ClassCooldown
for example
A cooldown handler is should be a function that takes in (Player, DrinkContainer), (You may also make it return a boolean, if false the cooldown will be neglected) ↩
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.