Skip to content

Commit

Permalink
refactor dispatchConsole to run as BukkitRunnable
Browse files Browse the repository at this point in the history
  • Loading branch information
CyR1en committed Nov 5, 2023
1 parent dcf9ca4 commit 398b618
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
/**
* Player command dispatcher for Support with CommandPrompter.
*
* <p>Because CommandPrompter cannot catch commands that were dispatched from
* <p>
* Because CommandPrompter cannot catch commands that were dispatched from
* {@link org.bukkit.Bukkit#dispatchCommand(CommandSender, String)}, plugins
* need a special way to execute player commands.</p>
* need a special way to execute player commands.
* </p>
*/
public class Dispatcher {

Expand All @@ -58,36 +60,32 @@ public void run() {
}.runTask(plugin);
}

public static void dispatchNative(CommandSender sender, String command) {
final String checked = command.codePointAt(0) == 0x2F ?
command.replace("/", "") : command;
Bukkit.dispatchCommand(sender, checked);
}

/**
* Dispatch the command as Console.
*
* @param command command that would be dispatched.
*/
public static void dispatchConsole(String command) {
if (command.codePointAt(0) == 0x2F)
command = command.replace("/", "");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
public static void dispatchConsole(final String command) {
final String checked = command.codePointAt(0) == 0x2F ? command.replace("/", "") : command;
new BukkitRunnable() {
public void run() {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked);
}
}.runTask(CommandPrompter.getInstance());
}


/**
* Dispatch a command for a player with a PermissionAttachment that contains
* all the whitelisted commands.
*
* @param plugin Instance of plugin.
* @param sender command sender (in menu's, then the item clicker)
* @param command command that would be dispatched.
* @param ticks Number of ticks before the attachment expires
* @param perms Permissions to set to the PermissionAttachment
* @param ticks Number of ticks before the attachment expires
* @param perms Permissions to set to the PermissionAttachment
*/
public static void dispatchWithAttachment
(Plugin plugin, Player sender, String command, int ticks, @NotNull String[] perms) {
public static void dispatchWithAttachment(Plugin plugin, Player sender, String command, int ticks,
@NotNull String[] perms) {
var commandPrompter = (CommandPrompter) plugin;
var logger = commandPrompter.getPluginLogger();

Expand All @@ -104,6 +102,4 @@ public static void dispatchConsole(String command) {
dispatchCommand(plugin, (Player) attachment.getPermissible(), command);
}



}

0 comments on commit 398b618

Please sign in to comment.