-
Notifications
You must be signed in to change notification settings - Fork 141
pass args with dm open command #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -9,7 +9,11 @@ | |||
| import org.jetbrains.annotations.NotNull; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
|
|
||||
| import java.util.Map; | ||||
| import java.util.HashMap; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Optional; | ||||
| import java.util.stream.Collectors; | ||||
|
|
@@ -35,8 +39,6 @@ public void execute(final @NotNull CommandSender sender, final @NotNull List<Str | |||
| return; | ||||
| } | ||||
|
|
||||
| boolean player = (sender instanceof Player); | ||||
|
|
||||
| if (arguments.isEmpty()) { | ||||
| plugin.sms(sender, Messages.WRONG_USAGE_OPEN_COMMAND); | ||||
| return; | ||||
|
|
@@ -47,94 +49,80 @@ public void execute(final @NotNull CommandSender sender, final @NotNull List<Str | |||
| return; | ||||
| } | ||||
|
|
||||
| Player viewer; | ||||
| String placeholderPlayer = null; | ||||
|
|
||||
| if (arguments.size() == 2 && arguments.get(1).startsWith("-p:")) { | ||||
| if (!sender.hasPermission("deluxemenus.placeholdersfor")) { | ||||
| plugin.sms(sender, Messages.NO_PERMISSION_PLAYER_ARGUMENT); | ||||
| return; | ||||
| } | ||||
|
|
||||
| placeholderPlayer = arguments.get(1).replace("-p:", ""); | ||||
|
|
||||
| } else if (arguments.size() >= 3 && arguments.get(2).startsWith("-p:")) { | ||||
| if (!sender.hasPermission("deluxemenus.placeholdersfor")) { | ||||
| plugin.sms(sender, Messages.NO_PERMISSION_PLAYER_ARGUMENT); | ||||
| return; | ||||
| } | ||||
|
|
||||
| placeholderPlayer = arguments.get(2).replace("-p:", ""); | ||||
| } | ||||
|
|
||||
| if (arguments.size() >= 2) { | ||||
| if (placeholderPlayer == null) { | ||||
| if (player && !sender.hasPermission("deluxemenus.open.others")) { | ||||
| plugin.sms(sender, Messages.NO_PERMISSION); | ||||
| List<String> actualArgs = new ArrayList<>(); | ||||
| for (String arg : arguments) { | ||||
| if (arg.startsWith("-p:")) { | ||||
| if (!sender.hasPermission("deluxemenus.placeholdersfor")) { | ||||
| plugin.sms(sender, Messages.NO_PERMISSION_PLAYER_ARGUMENT); | ||||
| return; | ||||
| } | ||||
|
|
||||
| viewer = Bukkit.getPlayerExact(arguments.get(1)); | ||||
|
|
||||
| placeholderPlayer = arg.substring(3); | ||||
| } else { | ||||
| if (arguments.size() >= 3) { | ||||
| if (!sender.hasPermission("deluxemenus.open.others")) { | ||||
| plugin.sms(sender, Messages.NO_PERMISSION); | ||||
| return; | ||||
| } | ||||
| actualArgs.add(arg); | ||||
| } | ||||
| } | ||||
|
|
||||
| viewer = Bukkit.getPlayerExact(arguments.get(1)); | ||||
| String menuName = actualArgs.get(0); | ||||
| Optional<Menu> menu = Menu.getMenuByName(menuName); | ||||
|
|
||||
| } else { | ||||
| if (!player) { | ||||
| plugin.sms(sender, Messages.MUST_SPECIFY_PLAYER); | ||||
| return; | ||||
| } | ||||
| if (menu.isEmpty()) { | ||||
| plugin.sms(sender, Messages.INVALID_MENU.message().replaceText(MENU_REPLACER_BUILDER.replacement(menuName).build())); | ||||
| return; | ||||
| } | ||||
|
|
||||
| viewer = (Player) sender; | ||||
| } | ||||
| String targetPlayerName = actualArgs.size() > 1 ? actualArgs.get(1) : null; | ||||
| Player viewer; | ||||
|
Comment on lines
+83
to
+103
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arguments are parsed as We should use the same parsing we already use everywhere else: the menu commands ( DeluxeMenus/src/main/java/com/extendedclip/deluxemenus/action/ClickActionTask.java Line 165 in 7ae9b95
|
||||
| boolean isPlayer = (sender instanceof Player); | ||||
| if (targetPlayerName != null) { | ||||
| if (isPlayer && !sender.hasPermission("deluxemenus.open.others")) { | ||||
| plugin.sms(sender, Messages.NO_PERMISSION); | ||||
| return; | ||||
| } | ||||
| viewer = Bukkit.getPlayerExact(targetPlayerName); | ||||
| if (viewer == null) { | ||||
| plugin.sms(sender, Messages.PLAYER_IS_NOT_ONLINE.message().replaceText(PLAYER_REPLACER_BUILDER.replacement(targetPlayerName).build())); | ||||
| return; | ||||
| } | ||||
|
|
||||
| } else { | ||||
| if (!player) { | ||||
| if (!isPlayer) { | ||||
| plugin.sms(sender, Messages.MUST_SPECIFY_PLAYER); | ||||
| return; | ||||
| } | ||||
|
|
||||
| viewer = (Player) sender; | ||||
| } | ||||
|
|
||||
| if (viewer == null) { | ||||
| plugin.sms(sender, Messages.PLAYER_IS_NOT_ONLINE.message().replaceText(PLAYER_REPLACER_BUILDER.replacement(arguments.get(1)).build())); | ||||
| return; | ||||
| } | ||||
|
|
||||
| Player placeholder = null; | ||||
|
|
||||
| if (placeholderPlayer != null) { | ||||
| placeholder = Bukkit.getPlayerExact(placeholderPlayer); | ||||
|
|
||||
| if (placeholder == null) { | ||||
| plugin.sms(sender, Messages.PLAYER_IS_NOT_ONLINE.message().replaceText(PLAYER_REPLACER_BUILDER.replacement(placeholderPlayer).build())); | ||||
| return; | ||||
|
|
||||
| } else { | ||||
| if (placeholder.hasPermission("deluxemenus.placeholdersfor.exempt")) { | ||||
| plugin.sms(sender, Messages.PLAYER_IS_EXEMPT.message().replaceText(PLAYER_REPLACER_BUILDER.replacement(placeholderPlayer).build())); | ||||
|
|
||||
| return; | ||||
| } | ||||
| } | ||||
| if (placeholder.hasPermission("deluxemenus.placeholdersfor.exempt")) { | ||||
| plugin.sms(sender, Messages.PLAYER_IS_EXEMPT.message().replaceText(PLAYER_REPLACER_BUILDER.replacement(placeholderPlayer).build())); | ||||
| return; | ||||
| } | ||||
| } | ||||
|
|
||||
| Optional<Menu> menu = Menu.getMenuByName(arguments.get(0)); | ||||
|
|
||||
| if (menu.isEmpty()) { | ||||
| plugin.sms(sender, Messages.INVALID_MENU.message().replaceText(MENU_REPLACER_BUILDER.replacement(arguments.get(0)).build())); | ||||
| List<String> menuArgumentNames = menu.get().options().arguments(); | ||||
| if (menuArgumentNames.isEmpty()) { | ||||
| menu.get().openMenu(viewer, null, placeholder); | ||||
| return; | ||||
| } | ||||
|
|
||||
| menu.get().openMenu(viewer, null, placeholder); | ||||
| List<String> menuArgs = actualArgs.size() > 2 ? actualArgs.subList(2, actualArgs.size()) : Collections.emptyList(); | ||||
| Map<String, String> argumentsMap = new HashMap<>(); | ||||
| for (int index = 0; index < menuArgumentNames.size() && index < menuArgs.size(); index++) { | ||||
| String argumentName = menuArgumentNames.get(index); | ||||
| if (index == menuArgumentNames.size() - 1) { | ||||
| String lastArgumentValue = String.join(" ", menuArgs.subList(index, menuArgs.size())); | ||||
| argumentsMap.put(argumentName, lastArgumentValue); | ||||
| break; | ||||
| } | ||||
| argumentsMap.put(argumentName, menuArgs.get(index)); | ||||
| } | ||||
| menu.get().openMenu(viewer, argumentsMap, placeholder); | ||||
| } | ||||
|
|
||||
| @Override | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.