mirror of https://github.com/LOOHP/Limbo.git
Cleanup the code a bit more
This commit is contained in:
parent
87aaf7f7b3
commit
c6a0980f15
|
|
@ -96,15 +96,12 @@ public class Console implements CommandSender {
|
||||||
reader.setHandleUserInterrupt(false);
|
reader.setHandleUserInterrupt(false);
|
||||||
|
|
||||||
terminal = TerminalBuilder.builder().streams(in, out).system(true).jansi(true).build();
|
terminal = TerminalBuilder.builder().streams(in, out).system(true).jansi(true).build();
|
||||||
tabReader = LineReaderBuilder.builder().terminal(terminal).completer(new Completer() {
|
tabReader = LineReaderBuilder.builder().terminal(terminal).completer((reader, line, candidates) -> {
|
||||||
@Override
|
|
||||||
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
|
||||||
String[] args = CustomStringUtils.splitStringToArgs(line.line());
|
String[] args = CustomStringUtils.splitStringToArgs(line.line());
|
||||||
List<String> tab = Limbo.getInstance().getPluginManager().getTabOptions(Limbo.getInstance().getConsole(), args);
|
List<String> tab = Limbo.getInstance().getPluginManager().getTabOptions(Limbo.getInstance().getConsole(), args);
|
||||||
for (String each : tab) {
|
for (String each : tab) {
|
||||||
candidates.add(new Candidate(each));
|
candidates.add(new Candidate(each));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}).build();
|
}).build();
|
||||||
tabReader.setAutosuggestion(SuggestionType.NONE);
|
tabReader.setAutosuggestion(SuggestionType.NONE);
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +146,7 @@ public class Console implements CommandSender {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(BaseComponent[] component) {
|
public void sendMessage(BaseComponent[] component) {
|
||||||
sendMessage(String.join("", Arrays.asList(component).stream().map(each -> each.toLegacyText()).collect(Collectors.toList())));
|
sendMessage(Arrays.stream(component).map(BaseComponent::toLegacyText).collect(Collectors.joining("")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -159,7 +156,7 @@ public class Console implements CommandSender {
|
||||||
ConsoleTextOutput.appendText(ChatColor.stripColor("[" + date + " Info] " + message), true);
|
ConsoleTextOutput.appendText(ChatColor.stripColor("[" + date + " Info] " + message), true);
|
||||||
logs.println(ChatColor.stripColor("[" + date + " Info] " + message));
|
logs.println(ChatColor.stripColor("[" + date + " Info] " + message));
|
||||||
try {
|
try {
|
||||||
reader.getOutput().append("[" + date + " Info] " + translateToConsole(message) + "\n");
|
reader.getOutput().append("[").append(date).append(" Info] ").append(translateToConsole(message)).append("\n");
|
||||||
reader.getOutput().flush();
|
reader.getOutput().flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
|
|
@ -191,12 +191,7 @@ public class GUI extends JFrame {
|
||||||
GUI frame = new GUI();
|
GUI frame = new GUI();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
Thread t1 = new Thread(new Runnable() {
|
Thread t1 = new Thread(SystemInfo::printInfo);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
SystemInfo.printInfo();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t1.start();
|
t1.start();
|
||||||
|
|
||||||
loadFinish = true;
|
loadFinish = true;
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ public class SystemInfo {
|
||||||
long allocatedMemory = runtime.totalMemory();
|
long allocatedMemory = runtime.totalMemory();
|
||||||
long freeMemory = runtime.freeMemory();
|
long freeMemory = runtime.freeMemory();
|
||||||
|
|
||||||
sb.append("Free Memory: " + format.format(freeMemory / 1024 / 1024) + " MB\n");
|
sb.append("Free Memory: ").append(format.format(freeMemory / 1024 / 1024)).append(" MB\n");
|
||||||
sb.append("Allocated Memory: " + format.format(allocatedMemory / 1024 / 1024) + " MB\n");
|
sb.append("Allocated Memory: ").append(format.format(allocatedMemory / 1024 / 1024)).append(" MB\n");
|
||||||
sb.append("Max Memory: " + format.format(maxMemory / 1024 / 1024) + " MB\n");
|
sb.append("Max Memory: ").append(format.format(maxMemory / 1024 / 1024)).append(" MB\n");
|
||||||
sb.append("Memory Usage: " + format.format((allocatedMemory - freeMemory) / 1024 / 1024) + "/" + format.format(maxMemory / 1024 / 1024) + " MB (" + Math.round((double) (allocatedMemory - freeMemory) / (double) (maxMemory) * 100) + "%)\n");
|
sb.append("Memory Usage: ").append(format.format((allocatedMemory - freeMemory) / 1024 / 1024)).append("/").append(format.format(maxMemory / 1024 / 1024)).append(" MB (").append(Math.round((double) (allocatedMemory - freeMemory) / (double) (maxMemory) * 100)).append("%)\n");
|
||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -35,9 +35,9 @@ public class SystemInfo {
|
||||||
double systemLoad = operatingSystemMXBean.getSystemCpuLoad();
|
double systemLoad = operatingSystemMXBean.getSystemCpuLoad();
|
||||||
int processors = runtime.availableProcessors();
|
int processors = runtime.availableProcessors();
|
||||||
|
|
||||||
sb.append("Available Processors: " + processors + "\n");
|
sb.append("Available Processors: ").append(processors).append("\n");
|
||||||
sb.append("Process CPU Load: " + Math.round(processLoad * 100) + "%\n");
|
sb.append("Process CPU Load: ").append(Math.round(processLoad * 100)).append("%\n");
|
||||||
sb.append("System CPU Load: " + Math.round(systemLoad * 100) + "%\n");
|
sb.append("System CPU Load: ").append(Math.round(systemLoad * 100)).append("%\n");
|
||||||
GUI.sysText.setText(sb.toString());
|
GUI.sysText.setText(sb.toString());
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import java.util.Properties;
|
||||||
public class ServerProperties {
|
public class ServerProperties {
|
||||||
|
|
||||||
public static final String COMMENT = "For explaination of what each of the options does, please visit:\nhttps://github.com/LOOHP/Limbo/blob/master/src/main/resources/server.properties";
|
public static final String COMMENT = "For explaination of what each of the options does, please visit:\nhttps://github.com/LOOHP/Limbo/blob/master/src/main/resources/server.properties";
|
||||||
Optional<BufferedImage> favicon;
|
private BufferedImage favicon;
|
||||||
private final File file;
|
private final File file;
|
||||||
private final int maxPlayers;
|
private final int maxPlayers;
|
||||||
private final int serverPort;
|
private final int serverPort;
|
||||||
|
|
@ -91,7 +91,7 @@ public class ServerProperties {
|
||||||
try {
|
try {
|
||||||
BufferedImage image = ImageIO.read(png);
|
BufferedImage image = ImageIO.read(png);
|
||||||
if (image.getHeight() == 64 && image.getWidth() == 64) {
|
if (image.getHeight() == 64 && image.getWidth() == 64) {
|
||||||
favicon = Optional.of(image);
|
favicon = image;
|
||||||
} else {
|
} else {
|
||||||
Limbo.getInstance().getConsole().sendMessage("Unable to load server-icon.png! The image is not 64 x 64 in size!");
|
Limbo.getInstance().getConsole().sendMessage("Unable to load server-icon.png! The image is not 64 x 64 in size!");
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +100,7 @@ public class ServerProperties {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Limbo.getInstance().getConsole().sendMessage("No server-icon.png found");
|
Limbo.getInstance().getConsole().sendMessage("No server-icon.png found");
|
||||||
favicon = Optional.empty();
|
favicon = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Limbo.getInstance().getConsole().sendMessage("Loaded server.properties");
|
Limbo.getInstance().getConsole().sendMessage("Loaded server.properties");
|
||||||
|
|
@ -115,7 +115,7 @@ public class ServerProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<BufferedImage> getFavicon() {
|
public Optional<BufferedImage> getFavicon() {
|
||||||
return favicon;
|
return Optional.ofNullable(favicon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile() {
|
public File getFile() {
|
||||||
|
|
|
||||||
|
|
@ -93,26 +93,11 @@ public class Metrics {
|
||||||
startSubmitting();
|
startSubmitting();
|
||||||
}
|
}
|
||||||
|
|
||||||
addCustomChart(new Metrics.SingleLineChart("players", new Callable<Integer>() {
|
addCustomChart(new Metrics.SingleLineChart("players", () -> Limbo.getInstance().getPlayers().size()));
|
||||||
@Override
|
|
||||||
public Integer call() throws Exception {
|
|
||||||
return Limbo.getInstance().getPlayers().size();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
addCustomChart(new Metrics.SimplePie("limbo_version", new Callable<String>() {
|
addCustomChart(new Metrics.SimplePie("limbo_version", () -> limboVersion));
|
||||||
@Override
|
|
||||||
public String call() throws Exception {
|
|
||||||
return limboVersion;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
addCustomChart(new Metrics.SimplePie("minecraftVersion", new Callable<String>() {
|
addCustomChart(new Metrics.SimplePie("minecraftVersion", () -> Limbo.getInstance().serverImplementationVersion));
|
||||||
@Override
|
|
||||||
public String call() throws Exception {
|
|
||||||
return Limbo.getInstance().serverImplementationVersion;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import java.util.List;
|
||||||
public class CustomStringUtils {
|
public class CustomStringUtils {
|
||||||
|
|
||||||
public static boolean arrayContains(String compare, String[] args, boolean IgnoreCase) {
|
public static boolean arrayContains(String compare, String[] args, boolean IgnoreCase) {
|
||||||
return IgnoreCase ? Arrays.asList(args).stream().anyMatch(each -> each.equalsIgnoreCase(compare)) : Arrays.asList(args).stream().anyMatch(each -> each.equals(compare));
|
return IgnoreCase ? Arrays.stream(args).anyMatch(each -> each.equalsIgnoreCase(compare)) : Arrays.asList(args).contains(compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean arrayContains(String compare, String[] args) {
|
public static boolean arrayContains(String compare, String[] args) {
|
||||||
|
|
@ -34,7 +34,7 @@ public class CustomStringUtils {
|
||||||
}
|
}
|
||||||
tokens.add(sb.toString());
|
tokens.add(sb.toString());
|
||||||
|
|
||||||
return tokens.toArray(new String[tokens.size()]);
|
return tokens.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getIndexOfArg(String str, int ordinal) {
|
public static int getIndexOfArg(String str, int ordinal) {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||||
public class DataTypeIO {
|
public class DataTypeIO {
|
||||||
|
|
||||||
public static void writeBlockPosition(DataOutputStream out, BlockPosition position) throws IOException {
|
public static void writeBlockPosition(DataOutputStream out, BlockPosition position) throws IOException {
|
||||||
out.writeLong(((position.getX() & 0x3FFFFFF) << 38) | ((position.getZ() & 0x3FFFFFF) << 12) | (position.getY() & 0xFFF));
|
out.writeLong(((long) (position.getX() & 0x3FFFFFF) << 38) | ((long) (position.getZ() & 0x3FFFFFF) << 12) | (position.getY() & 0xFFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeUUID(DataOutputStream out, UUID uuid) throws IOException {
|
public static void writeUUID(DataOutputStream out, UUID uuid) throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ import java.util.*;
|
||||||
public class YamlOrder extends PropertyUtils {
|
public class YamlOrder extends PropertyUtils {
|
||||||
|
|
||||||
private static final String TRANSIENT = "transient";
|
private static final String TRANSIENT = "transient";
|
||||||
private final Map<Class<?>, Map<String, Property>> propertiesCache = new HashMap<Class<?>, Map<String, Property>>();
|
private final Map<Class<?>, Map<String, Property>> propertiesCache = new HashMap<>();
|
||||||
private final Map<Class<?>, Set<Property>> readableProperties = new HashMap<Class<?>, Set<Property>>();
|
private final Map<Class<?>, Set<Property>> readableProperties = new HashMap<>();
|
||||||
private BeanAccess beanAccess = BeanAccess.DEFAULT;
|
private BeanAccess beanAccess = BeanAccess.DEFAULT;
|
||||||
private boolean allowReadOnlyProperties = false;
|
private boolean allowReadOnlyProperties = false;
|
||||||
private boolean skipMissingProperties = false;
|
private boolean skipMissingProperties = false;
|
||||||
|
|
@ -40,10 +40,9 @@ public class YamlOrder extends PropertyUtils {
|
||||||
return propertiesCache.get(type);
|
return propertiesCache.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Property> properties = new LinkedHashMap<String, Property>();
|
Map<String, Property> properties = new LinkedHashMap<>();
|
||||||
boolean inaccessableFieldsExist = false;
|
boolean inaccessableFieldsExist = false;
|
||||||
switch (bAccess) {
|
if (bAccess == BeanAccess.FIELD) {
|
||||||
case FIELD:
|
|
||||||
for (Class<?> c = type; c != null; c = c.getSuperclass()) {
|
for (Class<?> c = type; c != null; c = c.getSuperclass()) {
|
||||||
for (Field field : c.getDeclaredFields()) {
|
for (Field field : c.getDeclaredFields()) {
|
||||||
int modifiers = field.getModifiers();
|
int modifiers = field.getModifiers();
|
||||||
|
|
@ -53,8 +52,7 @@ public class YamlOrder extends PropertyUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
try {
|
try {
|
||||||
for (PropertyDescriptor property : Introspector.getBeanInfo(type)
|
for (PropertyDescriptor property : Introspector.getBeanInfo(type)
|
||||||
.getPropertyDescriptors()) {
|
.getPropertyDescriptors()) {
|
||||||
|
|
@ -80,7 +78,6 @@ public class YamlOrder extends PropertyUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (properties.isEmpty() && inaccessableFieldsExist) {
|
if (properties.isEmpty() && inaccessableFieldsExist) {
|
||||||
throw new YAMLException("No JavaBean properties found in " + type.getName());
|
throw new YAMLException("No JavaBean properties found in " + type.getName());
|
||||||
|
|
@ -94,11 +91,11 @@ public class YamlOrder extends PropertyUtils {
|
||||||
return Boolean.TRUE.equals(fd.getValue(TRANSIENT));
|
return Boolean.TRUE.equals(fd.getValue(TRANSIENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Property> getProperties(Class<? extends Object> type) {
|
public Set<Property> getProperties(Class<?> type) {
|
||||||
return getProperties(type, beanAccess);
|
return getProperties(type, beanAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Property> getProperties(Class<? extends Object> type, BeanAccess bAccess) {
|
public Set<Property> getProperties(Class<?> type, BeanAccess bAccess) {
|
||||||
if (readableProperties.containsKey(type)) {
|
if (readableProperties.containsKey(type)) {
|
||||||
return readableProperties.get(type);
|
return readableProperties.get(type);
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +104,7 @@ public class YamlOrder extends PropertyUtils {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bAccess) {
|
protected Set<Property> createPropertySet(Class<?> type, BeanAccess bAccess) {
|
||||||
Set<Property> properties = new LinkedHashSet<>();
|
Set<Property> properties = new LinkedHashSet<>();
|
||||||
Collection<Property> props = getPropertiesMap(type, bAccess).values();
|
Collection<Property> props = getPropertiesMap(type, bAccess).values();
|
||||||
for (Property property : props) {
|
for (Property property : props) {
|
||||||
|
|
@ -118,11 +115,11 @@ public class YamlOrder extends PropertyUtils {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Property getProperty(Class<? extends Object> type, String name) {
|
public Property getProperty(Class<?> type, String name) {
|
||||||
return getProperty(type, name, beanAccess);
|
return getProperty(type, name, beanAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Property getProperty(Class<? extends Object> type, String name, BeanAccess bAccess) {
|
public Property getProperty(Class<?> type, String name, BeanAccess bAccess) {
|
||||||
Map<String, Property> properties = getPropertiesMap(type, bAccess);
|
Map<String, Property> properties = getPropertiesMap(type, bAccess);
|
||||||
Property property = properties.get(name);
|
Property property = properties.get(name);
|
||||||
if (property == null && skipMissingProperties) {
|
if (property == null && skipMissingProperties) {
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public class World {
|
||||||
1281525273222484040L, 9548107335L});
|
1281525273222484040L, 9548107335L});
|
||||||
chunk.setHeightMaps(heightMap);
|
chunk.setHeightMaps(heightMap);
|
||||||
chunk.setBiomes(new int[256]);
|
chunk.setBiomes(new int[256]);
|
||||||
chunk.setTileEntities(new ListTag<CompoundTag>(CompoundTag.class));
|
chunk.setTileEntities(new ListTag<>(CompoundTag.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue