Finish up command API, with permissions and aliases!

This commit is contained in:
md_5
2013-01-12 12:03:59 +11:00
parent f065d0099f
commit b4105f8081
15 changed files with 122 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import static net.md_5.bungee.Logger.$;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.command.*;
import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.PacketFAPluginMessage;

View File

@@ -1,156 +0,0 @@
package net.md_5.bungee;
import java.util.regex.Pattern;
/**
* Simplistic enumeration of all supported color values for chat.
*/
public enum ChatColor
{
/**
* Represents black.
*/
BLACK('0'),
/**
* Represents dark blue.
*/
DARK_BLUE('1'),
/**
* Represents dark green.
*/
DARK_GREEN('2'),
/**
* Represents dark blue (aqua).
*/
DARK_AQUA('3'),
/**
* Represents dark red.
*/
DARK_RED('4'),
/**
* Represents dark purple.
*/
DARK_PURPLE('5'),
/**
* Represents gold.
*/
GOLD('6'),
/**
* Represents gray.
*/
GRAY('7'),
/**
* Represents dark gray.
*/
DARK_GRAY('8'),
/**
* Represents blue.
*/
BLUE('9'),
/**
* Represents green.
*/
GREEN('a'),
/**
* Represents aqua.
*/
AQUA('b'),
/**
* Represents red.
*/
RED('c'),
/**
* Represents light purple.
*/
LIGHT_PURPLE('d'),
/**
* Represents yellow.
*/
YELLOW('e'),
/**
* Represents white.
*/
WHITE('f'),
/**
* Represents magical characters that change around randomly.
*/
MAGIC('k'),
/**
* Makes the text bold.
*/
BOLD('l'),
/**
* Makes a line appear through the text.
*/
STRIKETHROUGH('m'),
/**
* Makes the text appear underlined.
*/
UNDERLINE('n'),
/**
* Makes the text italic.
*/
ITALIC('o'),
/**
* Resets all previous chat colors or formats.
*/
RESET('r');
/**
* The special character which prefixes all chat colour codes. Use this if
* you need to dynamically convert colour codes from your custom format.
*/
public static final char COLOR_CHAR = '\u00A7';
/**
* Pattern to remove all colour codes.
*/
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf(COLOR_CHAR) + "[0-9A-FK-OR]");
/**
* This colour's colour char prefixed by the {@link #COLOR_CHAR}.
*/
private final String toString;
private ChatColor(char code)
{
this.toString = new String(new char[]
{
COLOR_CHAR, code
});
}
@Override
public String toString()
{
return toString;
}
/**
* Strips the given message of all color codes
*
* @param input String to strip of color
* @return A copy of the input string, without any coloring
*/
public static String stripColor(final String input)
{
if (input == null)
{
return null;
}
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
}
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
{
char[] b = textToTranslate.toCharArray();
for (int i = 0; i < b.length - 1; i++)
{
if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1)
{
b[i] = ChatColor.COLOR_CHAR;
b[i + 1] = Character.toLowerCase(b[i + 1]);
}
}
return new String(b);
}
}

View File

@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import static net.md_5.bungee.Logger.$;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.command.CommandSender;
import net.md_5.bungee.command.ConsoleCommandSender;
import org.yaml.snakeyaml.DumperOptions;

View File

@@ -1,12 +1,12 @@
package net.md_5.bungee;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import javax.crypto.SecretKey;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.packet.Packet2Handshake;
import net.md_5.bungee.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.packet.PacketFDEncryptionRequest;

View File

@@ -1,9 +1,9 @@
package net.md_5.bungee.command;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.Permission;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ChatColor;
public class CommandAlert extends Command
{

View File

@@ -1,7 +1,7 @@
package net.md_5.bungee.command;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.api.ChatColor;
public class CommandBungee extends Command
{

View File

@@ -1,8 +1,8 @@
package net.md_5.bungee.command;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.Permission;
import net.md_5.bungee.api.ChatColor;
/**
* Command to terminate the proxy instance. May only be used by the console.

View File

@@ -1,9 +1,9 @@
package net.md_5.bungee.command;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.Permission;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ChatColor;
public class CommandIP extends Command
{

View File

@@ -2,8 +2,8 @@ package net.md_5.bungee.command;
import java.util.Collection;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ChatColor;
/**
* Command to list all players connected to the proxy.

View File

@@ -1,8 +1,8 @@
package net.md_5.bungee.command;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.Permission;
import net.md_5.bungee.api.ChatColor;
/**
* Command to set a temp copy of the motd in real-time without stopping the

View File

@@ -1,8 +1,8 @@
package net.md_5.bungee.command;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.Permission;
import net.md_5.bungee.api.ChatColor;
public class CommandReload extends Command
{

View File

@@ -2,8 +2,8 @@ package net.md_5.bungee.command;
import java.util.Collection;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ChatColor;
/**
* Command to list and switch a player between available servers.

View File

@@ -1,6 +1,6 @@
package net.md_5.bungee.command;
import net.md_5.bungee.ChatColor;
import net.md_5.bungee.api.ChatColor;
/**
* Command sender representing the proxy console.