-
Notifications
You must be signed in to change notification settings - Fork 3
"provided" provider argument consuming arguments? #6
Comments
Empty aliases should work just fine. From a quick look, that seems like
strange behaviour. Can you reproduce this with the integrated
CommandSenderProvider and OnlinePlayerProvider in a minimal working
example?
…On Sun, 14 Jan 2018, 10:51 Jonah, ***@***.***> wrote:
With my provider for a profile data object, it seems to be consuming an
argument when it shouldn't be.
Here is my command:
@command(aliases = "", desc = "Send a private message", usage = "<player> <message>", flags = "s")
@require("purified.commons.msg")
public void ***@***.*** CommsPlayer player, @PTarget CommsPlayer target, @text String message) {
target.privateMsg(message, player);
}
This is how I'm binding my providers:
commandsManager.bind(CommsPlayer.class).annotatedWith(PTarget.class).toProvider(new CommsPlayerProvider());
commandsManager.bind(CommsPlayer.class).annotatedWith(Sender.class).toProvider(new CommsPlayerSenderProvider());
This is my provider for the 'sender' impl:
public class CommsPlayerSenderProvider extends PCommandProvider<CommsPlayer> {
@OverRide
public boolean isProvided() {
return true;
}
@nullable
@OverRide
public CommsPlayer get(CommandArgs commandArgs, List<? extends Annotation> list) throws ArgumentException, ProvisionException {
CommandSender sender = getFromNamespaceOrFail(commandArgs, CommandSender.class);
if (!(sender instanceof Player)) {
throw new CommandExitMessage("This is a player only command.");
}
Player player = (Player) sender;
CommsPlayer commsPlayer = PurifiedCommons.getInstance().getCache().get(player);
if (commsPlayer != null) {
commsPlayer.msg("Args length: " +commandArgs.size());
return commsPlayer;
} else {
throw new CommandExitMessage(ChatColor.RED + "For some reason, your commons profile is not cached and this command could not be performed.");
}
}
@OverRide
public List<String> getSuggestions(String s) {
return PurifiedCommons.getInstance().getCache().getCache().values().stream()
.map(commsPlayer -> commsPlayer.getPlayer().getName())
.filter(s1 -> s1.toLowerCase().contains(s.toLowerCase()))
.collect(Collectors.toList());
}
}
and this is my provider for the 'target' impl (i.e should be first
argument):
public class CommsPlayerProvider implements Provider<CommsPlayer> {
@OverRide
public boolean isProvided() {
return false;
}
@nullable
@OverRide
public CommsPlayer get(CommandArgs commandArgs, List<? extends Annotation> list) throws ArgumentException, ProvisionException {
String name = commandArgs.next();
return PurifiedCommons.getInstance().getCache().getByUsername(name);
}
@OverRide
public List<String> getSuggestions(String s) {
return PurifiedCommons.getInstance().getCache().getCache().values().stream()
.map(commsPlayer -> commsPlayer.getPlayer().getName())
.filter(s1 -> s1.toLowerCase().contains(s.toLowerCase()))
.collect(Collectors.toList());
}
}
Notice that for the sender, isProvided is true, but for the target
isProvided is false.
However, in order for the command to execute with 'enough arguments' (i.e
not reply with the error: missing argument for commsplayer), I have to type
the command /msg Shawckz Shawckz hi
when it should be /msg Shawckz hi
I added a check in the sender provider to send me the args length, and
upon performing "/msg Shawckz hi", it says that the commandArgs.size() ==
0, when it should be 1?
Could this be with how I'm registering my commands (with the empty aliases
= "")?
Very strange.
@xxyy <https://github.com/xxyy>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAhY_vur-C8lHV3y8nn6ueJ6mcshT2OVks5tKc4agaJpZM4RdiS4>
.
|
Here is the relative maven repo/dependency, for reference:
|
However, when I refactor the command so that there are no required arguments (just sender) like so: public class CmdTest {
@Command(aliases = "", desc = "Test command")
@Require("purified.commons.test")
public void executeTest(@Sender CommandSender sender) {
sender.sendMessage("Test: " + sender.getName());
}
} I get the expected outcome:
So I'm guessing this is not an issue with the 'sender' providers, but instead an issue with the 'target' providers consuming arguments twice? This is only the case when registering with a blank alias though. When adding anything into the I'm guessing something with the way commands are registered into the commandmap and then instructed to consume arguments? I.e the way arguments are processed is not properly accounting for the fact that there is no alias, and it consumes something it shouldn't and passes it blank. |
So when I refactor to this, adding an alias: public class CmdTest {
@Command(aliases = "sub", desc = "Test command")
@Require("purified.commons.test")
public void executeTest(@Sender CommandSender sender, @OnlinePlayer Player player) {
sender.sendMessage("Test: " + player.getName());
}
} I will get the expected outcome by typing /test sub Shawckz. |
Thanks for the detailed explanation! I have been able to track this down to a bug in my modified Intake. I'll push a new release shortly, but will take a quick look at your other issue before while I have a test plugin set up :) update: Here's the test plugin with the proof of concept: https://github.com/xxyy/intake-spigot-test/tree/master/src/main/java/li/l1t/test/intake . The new release has been published. |
Thanks so much. Appreciate it! |
With my provider for a profile data object, it seems to be consuming an argument when it shouldn't be.
Here is my command:
This is how I'm binding my providers:
This is my provider for the 'sender' impl:
and this is my provider for the 'target' impl (i.e should be first argument):
Notice that for the sender,
isProvided
is true, but for the targetisProvided
is false.However, in order for the command to execute with 'enough arguments' (i.e not reply with the error: missing argument for commsplayer), I have to type the command /msg Shawckz Shawckz hi
when it should be /msg Shawckz hi
I added a check in the sender provider to send me the args length, and upon performing "/msg Shawckz hi", it says that the commandArgs.size() == 0, when it should be 1?
Could this be with how I'm registering my commands (with the empty aliases = "")?
Very strange.
@xxyy
Update: upon changing my aliases from being empty to
aliases = "msg"
, I get the expected behavior, however the command is now /msg msg Shawckz hiwhen it should be /msg Shawckz hi
How should I go about registering commands like this? I don't want them all to be in the same class obviously. @xxyy
The text was updated successfully, but these errors were encountered: