move Commander
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-22
|
||||
*/
|
||||
package mc.commander;
|
||||
|
||||
import mc.core.player.Player;
|
||||
|
||||
public interface CommandExecutor {
|
||||
void execute(Player sender, String command, String... args);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-22
|
||||
*/
|
||||
package mc.commander;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.chat.ChatStyle;
|
||||
import mc.core.chat.SimpleChatProcessor;
|
||||
import mc.core.player.Player;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.helpers.BasicMarkerFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class Commander extends SimpleChatProcessor {
|
||||
private static final Marker COMMAND_MARKER = new BasicMarkerFactory().getMarker("Command");
|
||||
private static final String UNKNOW_COMMAND_MSG = ChatStyle.RED + "Unknown command \"" + ChatStyle.WHITE + "%s" + ChatStyle.RED + "\"";
|
||||
private Map<String, CommandExecutor> commands = Collections.emptyMap();
|
||||
|
||||
@Override
|
||||
public void process(Player player, String message) {
|
||||
if (message.startsWith("/")) {
|
||||
log.info(COMMAND_MARKER, "<{}> {}", player.getName(), message);
|
||||
|
||||
int idx = message.indexOf(' ');
|
||||
if (idx == -1) {
|
||||
idx = message.length();
|
||||
}
|
||||
|
||||
String command = message.substring(1, idx).toLowerCase();
|
||||
if (commands.containsKey(command)) {
|
||||
String[] args = message.substring(idx).split(" ");
|
||||
commands.get(command).execute(player, command, args);
|
||||
} else {
|
||||
player.getChannel().sendChatMessage(String.format(UNKNOW_COMMAND_MSG, command));
|
||||
}
|
||||
} else {
|
||||
super.process(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user