mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 18:09:48 -05:00
Introduce new commandProcessor api
This commit is contained in:
1 parent
b3ceef6846
commit
aea344fbdf
5 files changed
+107
-23
No files matched your search
@@ -26,32 +26,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
//For backward compatibility, have migrate to ICommandProcessor
|
||||
@Deprecated
|
||||
public interface CommandProcesser {
|
||||
/**
|
||||
* Accept the onCommand, it will call when have Command Event cmdArg not contains
|
||||
* CommandContainer's prefix. E.g: Register the CommandContainer with Prefix: unlimited
|
||||
* Permission: quickshop.unlimited
|
||||
*
|
||||
* <p>When player type /qs unlimited 123 cmdArg's content is 123
|
||||
*
|
||||
* @param sender Sender
|
||||
* @param cmdArg Args
|
||||
* @param commandLabel The command prefix /qs is qs
|
||||
*/
|
||||
|
||||
void onCommand(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg);
|
||||
|
||||
/**
|
||||
* Accept the onTabComplete, it will call when have Tab Event cmdArg not contains
|
||||
* CommandContainer's prefix. E.g: Register the CommandContainer with Prefix: unlimited
|
||||
* Permission: quickshop.unlimited
|
||||
*
|
||||
* <p>When player type /qs unlimited 123 cmdArg's content is 123
|
||||
*
|
||||
* @param sender Sender
|
||||
* @param cmdArg Args
|
||||
* @param commandLabel The command prefix /qs is qs
|
||||
* @return The result for tab-complete lists
|
||||
*/
|
||||
@Nullable
|
||||
default List<String> onTabComplete(
|
||||
@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.maxgamer.quickshop.command.processor;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
//For backward compatibility, implement CommandProcesser
|
||||
public abstract class CommonCommandProcessor implements ICommandProcessor {
|
||||
/**
|
||||
* Accept the onCommand, it will call when have Command Event cmdArg not contains
|
||||
* CommandContainer's prefix. E.g: Register the CommandContainer with Prefix: unlimited
|
||||
* Permission: quickshop.unlimited
|
||||
*
|
||||
* <p>When player type /qs unlimited 123 the content of cmdArg is ["123"]
|
||||
*
|
||||
* @param sender Sender
|
||||
* @param cmdArg Args
|
||||
* @param commandLabel The command prefix /qs is qs
|
||||
*/
|
||||
public void onCommand(
|
||||
@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
|
||||
|
||||
throw new UnsupportedOperationException("Unimplemented command");
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the onTabComplete, it will call when have Tab Event cmdArg not contains
|
||||
* CommandContainer's prefix. E.g: Register the CommandContainer with Prefix: unlimited
|
||||
* Permission: quickshop.unlimited
|
||||
*
|
||||
* <p>When player type /qs unlimited 123 cmdArg's content is 123
|
||||
*
|
||||
* @param sender Sender
|
||||
* @param cmdArg Args
|
||||
* @param commandLabel The command prefix /qs is qs
|
||||
* @return The result for tab-complete lists
|
||||
*/
|
||||
@Nullable
|
||||
public List<String> onTabComplete(
|
||||
@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package org.maxgamer.quickshop.command.processor;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.maxgamer.quickshop.util.MsgUtil;
|
||||
|
||||
public abstract class ConsoleOnlyCommandProcessor implements ICommandProcessor {
|
||||
|
||||
public void onCommand(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
onCommand((ConsoleCommandSender) sender, commandLabel, cmdArg);
|
||||
} else {
|
||||
MsgUtil.sendMessage(sender, "This command is console only!");
|
||||
}
|
||||
}
|
||||
|
||||
abstract public void onCommand(@NotNull ConsoleCommandSender consoleCommandSender, @NotNull String commandLabel, @NotNull String[] cmdArg);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.maxgamer.quickshop.command.processor;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.maxgamer.quickshop.command.CommandProcesser;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
//For backward compatibility, extended CommandProcesser
|
||||
interface ICommandProcessor extends CommandProcesser {
|
||||
void onCommand(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg);
|
||||
|
||||
@Nullable
|
||||
default List<String> onTabComplete(
|
||||
@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package org.maxgamer.quickshop.command.processor;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.maxgamer.quickshop.util.MsgUtil;
|
||||
|
||||
public abstract class PlayerOnlyCommandProcessor implements ICommandProcessor {
|
||||
public void onCommand(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
|
||||
if (sender instanceof Player) {
|
||||
onCommand((Player) sender, commandLabel, cmdArg);
|
||||
} else {
|
||||
MsgUtil.sendMessage(sender, "This command is player only!");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onCommand(@NotNull Player player, @NotNull String commandLabel, @NotNull String[] cmdArg);
|
||||
}
|
||||
Reference in new issue
Block a user