mirror of
https://github.com/aikar/commands.git
synced 2026-06-24 07:30:38 +00:00
Move MessageFormatter stuff to base class using generics, readd default formatter G/S
This commit is contained in:
@@ -49,7 +49,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class BukkitCommandManager extends CommandManager<CommandSender, BukkitMessageFormatter> {
|
||||
public class BukkitCommandManager extends CommandManager<CommandSender, ChatColor, BukkitMessageFormatter> {
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected final Plugin plugin;
|
||||
@@ -106,26 +106,6 @@ public class BukkitCommandManager extends CommandManager<CommandSender, BukkitMe
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
public BukkitMessageFormatter setFormat(MessageType type, BukkitMessageFormatter formatter) {
|
||||
return (BukkitMessageFormatter) formatters.put(type, formatter);
|
||||
}
|
||||
|
||||
public BukkitMessageFormatter getFormat(MessageType type) {
|
||||
return (BukkitMessageFormatter) formatters.getOrDefault(type, defaultFormatter);
|
||||
}
|
||||
|
||||
public void setFormat(MessageType type, ChatColor... colors) {
|
||||
BukkitMessageFormatter format = getFormat(type);
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
format.setColor(i, colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFormat(MessageType type, int i, ChatColor color) {
|
||||
BukkitMessageFormatter format = getFormat(type);
|
||||
format.setColor(i, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandIssuer(Class<?> type) {
|
||||
return CommandSender.class.isAssignableFrom(type);
|
||||
|
||||
@@ -38,7 +38,7 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BungeeCommandManager extends CommandManager<CommandSender, BungeeMessageFormatter> {
|
||||
public class BungeeCommandManager extends CommandManager<CommandSender, ChatColor, BungeeMessageFormatter> {
|
||||
|
||||
protected final Plugin plugin;
|
||||
protected Map<String, BungeeRootCommand> registeredCommands = new HashMap<>();
|
||||
@@ -58,26 +58,6 @@ public class BungeeCommandManager extends CommandManager<CommandSender, BungeeMe
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
public BungeeMessageFormatter setFormat(MessageType type, BungeeMessageFormatter formatter) {
|
||||
return (BungeeMessageFormatter) formatters.put(type, formatter);
|
||||
}
|
||||
|
||||
public BungeeMessageFormatter getFormat(MessageType type) {
|
||||
return (BungeeMessageFormatter) formatters.getOrDefault(type, defaultFormatter);
|
||||
}
|
||||
|
||||
public void setFormat(MessageType type, ChatColor... colors) {
|
||||
BungeeMessageFormatter format = getFormat(type);
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
format.setColor(i, colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFormat(MessageType type, int i, ChatColor color) {
|
||||
BungeeMessageFormatter format = getFormat(type);
|
||||
format.setColor(i, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized CommandContexts<BungeeCommandExecutionContext> getCommandContexts() {
|
||||
if (this.contexts == null) {
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class BaseCommand {
|
||||
private String execSubcommand;
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
private String[] origArgs;
|
||||
CommandManager<?, ?> manager = null;
|
||||
CommandManager<?, ?, ?> manager = null;
|
||||
BaseCommand parentCommand;
|
||||
Map<String, RootCommand> registeredCommands = new HashMap<>();
|
||||
String description;
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public abstract class CommandManager <I, F extends MessageFormatter<?>> {
|
||||
public abstract class CommandManager <I, FT, F extends MessageFormatter<FT>> {
|
||||
|
||||
/**
|
||||
* This is a stack incase a command calls a command
|
||||
@@ -58,6 +58,34 @@ public abstract class CommandManager <I, F extends MessageFormatter<?>> {
|
||||
return context != null ? context.getCommandManager() : null;
|
||||
}
|
||||
|
||||
public F setFormat(MessageType type, F formatter) {
|
||||
return formatters.put(type, formatter);
|
||||
}
|
||||
|
||||
public F getFormat(MessageType type) {
|
||||
return formatters.getOrDefault(type, defaultFormatter);
|
||||
}
|
||||
|
||||
public void setFormat(MessageType type, FT... colors) {
|
||||
F format = getFormat(type);
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
format.setColor(i, colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFormat(MessageType type, int i, FT color) {
|
||||
F format = getFormat(type);
|
||||
format.setColor(i, color);
|
||||
}
|
||||
|
||||
public F getDefaultFormatter() {
|
||||
return defaultFormatter;
|
||||
}
|
||||
|
||||
public void setDefaultFormatter(F defaultFormatter) {
|
||||
this.defaultFormatter = defaultFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command contexts manager
|
||||
* @return Command Contexts
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.Map;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class Locales {
|
||||
private final CommandManager<?, ?> manager;
|
||||
private final CommandManager<?, ?, ?> manager;
|
||||
private final LocaleManager<CommandIssuer> localeManager;
|
||||
private final SetMultimap<String, Locale> loadedBundles = HashMultimap.create();
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class SpongeCommandManager extends CommandManager<CommandSource, SpongeMessageFormatter> {
|
||||
public class SpongeCommandManager extends CommandManager<CommandSource, TextColor, SpongeMessageFormatter> {
|
||||
|
||||
protected final PluginContainer plugin;
|
||||
protected Map<String, SpongeRootCommand> registeredCommands = new HashMap<>();
|
||||
@@ -65,26 +65,6 @@ public class SpongeCommandManager extends CommandManager<CommandSource, SpongeMe
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public SpongeMessageFormatter setFormat(MessageType type, SpongeMessageFormatter formatter) {
|
||||
return (SpongeMessageFormatter) formatters.put(type, formatter);
|
||||
}
|
||||
|
||||
public SpongeMessageFormatter getFormat(MessageType type) {
|
||||
return (SpongeMessageFormatter) formatters.getOrDefault(type, defaultFormatter);
|
||||
}
|
||||
|
||||
public void setFormat(MessageType type, TextColor... colors) {
|
||||
SpongeMessageFormatter format = getFormat(type);
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
format.setColor(i, colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFormat(MessageType type, int i, TextColor color) {
|
||||
SpongeMessageFormatter format = getFormat(type);
|
||||
format.setColor(i, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandIssuer(Class<?> type) {
|
||||
return CommandSource.class.isAssignableFrom(type);
|
||||
|
||||
Reference in New Issue
Block a user