完善 @TCommand 注解
新增 TCommandHandler 类用于动态命令注册
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package me.skymc.taboolib.string;
|
||||
|
||||
import com.ilummc.tlib.util.Strings;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
@@ -65,6 +68,26 @@ public class ArrayUtils {
|
||||
return (T) objectInputStream.readObject();
|
||||
}
|
||||
|
||||
public static <T> T skipEmpty(T obj) {
|
||||
return skipEmpty(obj, null);
|
||||
}
|
||||
|
||||
public static <T> T[] skipEmpty(T[] obj) {
|
||||
return skipEmpty(obj, null);
|
||||
}
|
||||
|
||||
public static <T> T skipEmpty(T obj, T def) {
|
||||
return Strings.isEmpty(String.valueOf(obj)) ? def : obj;
|
||||
}
|
||||
|
||||
public static <T> T[] skipEmpty(T[] obj, T[] def) {
|
||||
if (obj.length == 0) {
|
||||
return def;
|
||||
}
|
||||
T firstElement = skipEmpty(obj[0]);
|
||||
return firstElement == null ? def : obj;
|
||||
}
|
||||
|
||||
// *********************************
|
||||
//
|
||||
// Deprecated
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.skymc.taboolib.string.obfuscated;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
@Deprecated
|
||||
public class CT {
|
||||
|
||||
public static String decode(CodeType type, String string) {
|
||||
@@ -16,34 +17,36 @@ public class CT {
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
default:
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String encode(CodeType type, String string) {
|
||||
switch (type) {
|
||||
case BASE64: {
|
||||
return DatatypeConverter.printBase64Binary(string.getBytes());
|
||||
}
|
||||
case BINARY: {
|
||||
StringBuilder binary = new StringBuilder();
|
||||
for (byte b: string.getBytes()) {
|
||||
int value = b;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
binary.append((value & 128) == 0 ? 0: 1);
|
||||
value <<= 1;
|
||||
}
|
||||
binary.append(" ");
|
||||
}
|
||||
return binary.toString();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String encode(CodeType type, String string) {
|
||||
switch (type) {
|
||||
case BASE64: {
|
||||
return DatatypeConverter.printBase64Binary(string.getBytes());
|
||||
}
|
||||
case BINARY: {
|
||||
StringBuilder binary = new StringBuilder();
|
||||
for (byte b : string.getBytes()) {
|
||||
int value = b;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
binary.append((value & 128) == 0 ? 0 : 1);
|
||||
value <<= 1;
|
||||
}
|
||||
binary.append(" ");
|
||||
}
|
||||
return binary.toString();
|
||||
}
|
||||
default:
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public enum CodeType {
|
||||
BASE64,
|
||||
BINARY
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user