mirror of https://github.com/LOOHP/Limbo.git
0.3.0 - Moved supported version to 1.16.2
This commit is contained in:
parent
ff407323e8
commit
85da3cb845
7
pom.xml
7
pom.xml
|
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>Limbo</groupId>
|
||||
<artifactId>Limbo</artifactId>
|
||||
<version>0.2.4-ALPHA</version>
|
||||
<version>0.3.0-ALPHA</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
|
|
@ -33,6 +33,9 @@
|
|||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>com.loohp.limbo.Limbo</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Limbo-Version>${project.version}</Limbo-Version>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
|
|
@ -50,7 +53,7 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}-${project.version}-1.16.1</finalName>
|
||||
<finalName>${project.artifactId}-${project.version}-1.16.2</finalName>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
|
|
|
|||
70329
src/blocks.json
70329
src/blocks.json
File diff suppressed because it is too large
Load Diff
|
|
@ -1,7 +1,6 @@
|
|||
package com.loohp.limbo;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
|
@ -38,8 +37,12 @@ public class Console implements CommandSender {
|
|||
File logs = new File(dir, fileName);
|
||||
this.logs = new PrintStream(logs);
|
||||
|
||||
System.setIn(in == null ? new ByteArrayInputStream(new byte[0]) : in);
|
||||
if (in != null) {
|
||||
System.setIn(in);
|
||||
this.in = System.in;
|
||||
} else {
|
||||
this.in = null;
|
||||
}
|
||||
System.setOut(new ConsoleOutputStream(out == null ? new PrintStream(new PrintStream(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) {
|
||||
|
|
@ -79,6 +82,9 @@ public class Console implements CommandSender {
|
|||
}
|
||||
|
||||
protected void run() {
|
||||
if (in == null) {
|
||||
return;
|
||||
}
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
while (true) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class EventsManager {
|
|||
listeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Event callEvent(Event event) {
|
||||
public <T extends Event> T callEvent(T event) {
|
||||
for (EventPriority priority : EventPriority.getPrioritiesInOrder()) {
|
||||
for (ListenerPair entry : listeners) {
|
||||
Listener listener = entry.listener;
|
||||
|
|
|
|||
|
|
@ -4,16 +4,33 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import com.loohp.limbo.Utils.YamlOrder;
|
||||
|
||||
public class FileConfiguration {
|
||||
|
||||
Map<String, Object> mapping;
|
||||
String header;
|
||||
|
||||
public FileConfiguration(File file) throws FileNotFoundException {
|
||||
public FileConfiguration(File file) {
|
||||
if (file.exists()) {
|
||||
try {
|
||||
reloadConfig(new FileInputStream(file));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
mapping = new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration(InputStream input){
|
||||
|
|
@ -26,6 +43,10 @@ public class FileConfiguration {
|
|||
return this;
|
||||
}
|
||||
|
||||
public void setHeader(String header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(String key, Class<T> returnType) {
|
||||
try {
|
||||
|
|
@ -43,4 +64,42 @@ public class FileConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> void set(String key, T value) {
|
||||
String[] tree = key.split("\\.");
|
||||
Map<String, Object> map = mapping;
|
||||
for (int i = 0; i < tree.length - 1; i++) {
|
||||
Map<String, Object> map1 = (Map<String, Object>) map.get(tree[i]);
|
||||
if (map1 == null) {
|
||||
map1 = new LinkedHashMap<>();
|
||||
map.put(tree[i], map1);
|
||||
}
|
||||
map = map1;
|
||||
}
|
||||
if (value == null) {
|
||||
map.put(tree[tree.length - 1], (T) value);
|
||||
} else {
|
||||
map.remove(tree[tree.length - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveConfig(File file) throws FileNotFoundException, UnsupportedEncodingException {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setIndent(2);
|
||||
options.setPrettyFlow(true);
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
Representer customRepresenter = new Representer();
|
||||
YamlOrder customProperty = new YamlOrder();
|
||||
customRepresenter.setPropertyUtils(customProperty);
|
||||
Yaml yaml = new Yaml(customRepresenter, options);
|
||||
|
||||
PrintWriter pw = new PrintWriter(file, StandardCharsets.UTF_8.toString());
|
||||
if (header != null) {
|
||||
pw.println(header);
|
||||
}
|
||||
yaml.dump(mapping, pw);
|
||||
pw.flush();
|
||||
pw.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class ServerProperties {
|
|||
Properties prop = new Properties();
|
||||
prop.load(new FileInputStream(file));
|
||||
|
||||
protocol = 736;
|
||||
protocol = Limbo.getInstance().serverImplmentationProtocol;
|
||||
|
||||
maxPlayers = Integer.parseInt(prop.getProperty("max-players"));
|
||||
serverPort = Integer.parseInt(prop.getProperty("server-port"));
|
||||
|
|
@ -86,6 +86,10 @@ public class ServerProperties {
|
|||
System.out.println("Loaded server.properties");
|
||||
}
|
||||
|
||||
public String getServerImplementationVersion() {
|
||||
return Limbo.getInstance().serverImplementationVersion;
|
||||
}
|
||||
|
||||
public boolean isBungeecord() {
|
||||
return bungeecord;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,9 @@ public class Limbo {
|
|||
|
||||
//===========================
|
||||
|
||||
public final String serverImplementationVersion = "1.16.2";
|
||||
public final int serverImplmentationProtocol = 751;
|
||||
|
||||
private ServerConnection server;
|
||||
private Console console;
|
||||
|
||||
|
|
@ -110,6 +113,8 @@ public class Limbo {
|
|||
private PermissionsManager permissionManager;
|
||||
private File pluginFolder;
|
||||
|
||||
private File internalDataFolder;
|
||||
|
||||
public AtomicInteger entityIdCount = new AtomicInteger();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -120,9 +125,10 @@ public class Limbo {
|
|||
while (!GUI.loadFinish) {
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
console = new Console(null, System.out, System.err);
|
||||
} else {
|
||||
console = new Console(System.in, System.out, System.err);
|
||||
}
|
||||
|
||||
String spName = "server.properties";
|
||||
File sp = new File(spName);
|
||||
|
|
@ -141,8 +147,13 @@ public class Limbo {
|
|||
console.sendMessage("Starting Limbo server in bungeecord mode!");
|
||||
}
|
||||
|
||||
internalDataFolder = new File("internal_data");
|
||||
if (!internalDataFolder.exists()) {
|
||||
internalDataFolder.mkdirs();
|
||||
}
|
||||
|
||||
String mappingName = "mapping.json";
|
||||
File mappingFile = new File(mappingName);
|
||||
File mappingFile = new File(internalDataFolder, mappingName);
|
||||
if (!mappingFile.exists()) {
|
||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream(mappingName)) {
|
||||
Files.copy(in, mappingFile.toPath());
|
||||
|
|
@ -249,7 +260,7 @@ public class Limbo {
|
|||
|
||||
File defaultCommandsJar = new File(pluginFolder, "LimboDefaultCmd.jar");
|
||||
defaultCommandsJar.delete();
|
||||
System.out.println("Downloading limbo default commands module from github...");
|
||||
console.sendMessage("Downloading limbo default commands module from github...");
|
||||
ReadableByteChannel rbc = Channels.newChannel(new URL("https://github.com/LOOHP/Limbo/raw/master/modules/LimboDefaultCmd.jar").openStream());
|
||||
FileOutputStream fos = new FileOutputStream(defaultCommandsJar);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
|
|
@ -267,6 +278,46 @@ public class Limbo {
|
|||
console.run();
|
||||
}
|
||||
|
||||
public static boolean isNoGui() {
|
||||
return noGui;
|
||||
}
|
||||
|
||||
public String getServerImplementationVersion() {
|
||||
return serverImplementationVersion;
|
||||
}
|
||||
|
||||
public int getServerImplmentationProtocol() {
|
||||
return serverImplmentationProtocol;
|
||||
}
|
||||
|
||||
public ServerConnection getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public Map<String, Player> getPlayersByName() {
|
||||
return playersByName;
|
||||
}
|
||||
|
||||
public Map<UUID, Player> getPlayersByUUID() {
|
||||
return playersByUUID;
|
||||
}
|
||||
|
||||
public ServerProperties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public PermissionsManager getPermissionManager() {
|
||||
return permissionManager;
|
||||
}
|
||||
|
||||
public File getInternalDataFolder() {
|
||||
return internalDataFolder;
|
||||
}
|
||||
|
||||
public AtomicInteger getEntityIdCount() {
|
||||
return entityIdCount;
|
||||
}
|
||||
|
||||
public EventsManager getEventsManager() {
|
||||
return eventsManager;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,976 @@
|
|||
package com.loohp.limbo.Metrics;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.loohp.limbo.Limbo;
|
||||
import com.loohp.limbo.File.FileConfiguration;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
*
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
||||
final String defaultPackage = new String(new byte[] { 'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's' });
|
||||
final String examplePackage = new String(new byte[] { 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e' });
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// A list with all custom charts
|
||||
private final List<CustomChart> charts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public Metrics() {
|
||||
|
||||
// Get the config file
|
||||
File configFile = new File(new File("plugins", "bStats"), "config.yml");
|
||||
FileConfiguration config = new FileConfiguration(configFile);
|
||||
|
||||
// Check if the config file exists
|
||||
if (config.get("serverUuid", String.class) == null) {
|
||||
|
||||
// Add default values
|
||||
config.set("enabled", true);
|
||||
// Every server gets it's unique random id.
|
||||
config.set("serverUuid", UUID.randomUUID().toString());
|
||||
// Should failed request be logged?
|
||||
config.set("logFailedRequests", false);
|
||||
|
||||
// Inform the server owners about bStats
|
||||
config.setHeader(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
"To honor their work, you should not disable it.\n" +
|
||||
"This has nearly no effect on the server performance!\n" +
|
||||
"Check out https://bStats.org/ to learn more :)"
|
||||
);
|
||||
try {
|
||||
config.saveConfig(configFile);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
// Load the data
|
||||
serverUUID = config.get("serverUuid", String.class);
|
||||
logFailedRequests = config.get("logFailedRequests", Boolean.class);
|
||||
if (config.get("enabled", Boolean.class)) {
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
if (chart == null) {
|
||||
throw new IllegalArgumentException("Chart cannot be null!");
|
||||
}
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Scheduler which submits our data every 30 minutes.
|
||||
*/
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true);
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
submitData();
|
||||
}
|
||||
}, 1000*60*5, 1000*60*30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin specific data.
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JSONObject getPluginData() {
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
String pluginName = "Limbo";
|
||||
String pluginVersion = new BufferedReader(new InputStreamReader(Limbo.class.getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF"))).lines().filter(each -> each.startsWith("Limbo-Version:")).findFirst().orElse("Limbo-Version: unknown").substring(14).trim();
|
||||
|
||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JSONArray customCharts = new JSONArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JSONObject chart = customChart.getRequestJsonObject();
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.put("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server specific data.
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
private JSONObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount = Limbo.getInstance().getPlayers().size();
|
||||
int onlineMode = 0;
|
||||
String limboVersion = Limbo.getInstance().serverImplementationVersion;
|
||||
limboVersion = limboVersion.substring(limboVersion.indexOf("MC: ") + 4, limboVersion.length() - 1);
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
data.put("serverUUID", serverUUID);
|
||||
|
||||
data.put("playerAmount", playerAmount);
|
||||
data.put("onlineMode", onlineMode);
|
||||
data.put("limboVersion", limboVersion);
|
||||
|
||||
data.put("javaVersion", javaVersion);
|
||||
data.put("osName", osName);
|
||||
data.put("osArch", osArch);
|
||||
data.put("osVersion", osVersion);
|
||||
data.put("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JSONObject data = getServerData();
|
||||
|
||||
JSONArray pluginData = new JSONArray();
|
||||
pluginData.add(this.getPluginData());
|
||||
data.put("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
System.err.println("Could not submit stats for Limbo " + e);
|
||||
}
|
||||
}
|
||||
}, "Limbo Metrics Submission Thread").start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(JSONObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||
outputStream.write(compressedData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
connection.getInputStream().close(); // We don't care about the response - Just send our data :)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
||||
gzip.write(str.getBytes("UTF-8"));
|
||||
gzip.close();
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public static abstract class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
protected final String chartId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
protected JSONObject getRequestJsonObject() {
|
||||
JSONObject chart = new JSONObject();
|
||||
chart.put("chartId", chartId);
|
||||
try {
|
||||
JSONObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.put("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
System.err.println("Failed to get data for custom chart with id " + chartId + t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JSONObject getChartData();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
public static abstract class SimplePie extends CustomChart {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public SimplePie(String chartId) {
|
||||
super(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the pie.
|
||||
*
|
||||
* @return The value of the pie.
|
||||
*/
|
||||
public abstract String getValue();
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
String value = getValue();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
public static abstract class AdvancedPie extends CustomChart {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public AdvancedPie(String chartId) {
|
||||
super(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the values of the pie.
|
||||
*
|
||||
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
|
||||
* You don't have to create a map yourself!
|
||||
* @return The values of the pie.
|
||||
*/
|
||||
public abstract HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap);
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
public static abstract class SingleLineChart extends CustomChart {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public SingleLineChart(String chartId) {
|
||||
super(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the chart.
|
||||
*
|
||||
* @return The value of the chart.
|
||||
*/
|
||||
public abstract int getValue();
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
int value = getValue();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
public static abstract class MultiLineChart extends CustomChart {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public MultiLineChart(String chartId) {
|
||||
super(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the values of the chart.
|
||||
*
|
||||
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
|
||||
* You don't have to create a map yourself!
|
||||
* @return The values of the chart.
|
||||
*/
|
||||
public abstract HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap);
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
public static abstract class SimpleBarChart extends CustomChart {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public SimpleBarChart(String chartId) {
|
||||
super(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the chart.
|
||||
*
|
||||
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
|
||||
* You don't have to create a map yourself!
|
||||
* @return The value of the chart.
|
||||
*/
|
||||
public abstract HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap);
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
categoryValues.add(entry.getValue());
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
public static abstract class AdvancedBarChart extends CustomChart {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId) {
|
||||
super(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the chart.
|
||||
*
|
||||
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
|
||||
* You don't have to create a map yourself!
|
||||
* @return The value of the chart.
|
||||
*/
|
||||
public abstract HashMap<String, int[]> getValues(HashMap<String, int[]> valueMap);
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<String, int[]> map = getValues(new HashMap<String, int[]>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(categoryValue);
|
||||
}
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple map chart.
|
||||
*/
|
||||
public static abstract class SimpleMapChart extends CustomChart {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public SimpleMapChart(String chartId) {
|
||||
super(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the chart.
|
||||
*
|
||||
* @return The value of the chart.
|
||||
*/
|
||||
public abstract Country getValue();
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
Country value = getValue();
|
||||
|
||||
if (value == null) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value.getCountryIsoTag());
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced map chart.
|
||||
*/
|
||||
public static abstract class AdvancedMapChart extends CustomChart {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
public AdvancedMapChart(String chartId) {
|
||||
super(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the chart.
|
||||
*
|
||||
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
|
||||
* You don't have to create a map yourself!
|
||||
* @return The value of the chart.
|
||||
*/
|
||||
public abstract HashMap<Country, Integer> getValues(HashMap<Country, Integer> valueMap);
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<Country, Integer> map = getValues(new HashMap<Country, Integer>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<Country, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey().getCountryIsoTag(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A enum which is used for custom maps.
|
||||
*/
|
||||
public enum Country {
|
||||
|
||||
/**
|
||||
* bStats will use the country of the server.
|
||||
*/
|
||||
AUTO_DETECT("AUTO", "Auto Detected"),
|
||||
|
||||
ANDORRA("AD", "Andorra"),
|
||||
UNITED_ARAB_EMIRATES("AE", "United Arab Emirates"),
|
||||
AFGHANISTAN("AF", "Afghanistan"),
|
||||
ANTIGUA_AND_BARBUDA("AG", "Antigua and Barbuda"),
|
||||
ANGUILLA("AI", "Anguilla"),
|
||||
ALBANIA("AL", "Albania"),
|
||||
ARMENIA("AM", "Armenia"),
|
||||
NETHERLANDS_ANTILLES("AN", "Netherlands Antilles"),
|
||||
ANGOLA("AO", "Angola"),
|
||||
ANTARCTICA("AQ", "Antarctica"),
|
||||
ARGENTINA("AR", "Argentina"),
|
||||
AMERICAN_SAMOA("AS", "American Samoa"),
|
||||
AUSTRIA("AT", "Austria"),
|
||||
AUSTRALIA("AU", "Australia"),
|
||||
ARUBA("AW", "Aruba"),
|
||||
ALAND_ISLANDS("AX", "Åland Islands"),
|
||||
AZERBAIJAN("AZ", "Azerbaijan"),
|
||||
BOSNIA_AND_HERZEGOVINA("BA", "Bosnia and Herzegovina"),
|
||||
BARBADOS("BB", "Barbados"),
|
||||
BANGLADESH("BD", "Bangladesh"),
|
||||
BELGIUM("BE", "Belgium"),
|
||||
BURKINA_FASO("BF", "Burkina Faso"),
|
||||
BULGARIA("BG", "Bulgaria"),
|
||||
BAHRAIN("BH", "Bahrain"),
|
||||
BURUNDI("BI", "Burundi"),
|
||||
BENIN("BJ", "Benin"),
|
||||
SAINT_BARTHELEMY("BL", "Saint Barthélemy"),
|
||||
BERMUDA("BM", "Bermuda"),
|
||||
BRUNEI("BN", "Brunei"),
|
||||
BOLIVIA("BO", "Bolivia"),
|
||||
BONAIRE_SINT_EUSTATIUS_AND_SABA("BQ", "Bonaire, Sint Eustatius and Saba"),
|
||||
BRAZIL("BR", "Brazil"),
|
||||
BAHAMAS("BS", "Bahamas"),
|
||||
BHUTAN("BT", "Bhutan"),
|
||||
BOUVET_ISLAND("BV", "Bouvet Island"),
|
||||
BOTSWANA("BW", "Botswana"),
|
||||
BELARUS("BY", "Belarus"),
|
||||
BELIZE("BZ", "Belize"),
|
||||
CANADA("CA", "Canada"),
|
||||
COCOS_ISLANDS("CC", "Cocos Islands"),
|
||||
THE_DEMOCRATIC_REPUBLIC_OF_CONGO("CD", "The Democratic Republic Of Congo"),
|
||||
CENTRAL_AFRICAN_REPUBLIC("CF", "Central African Republic"),
|
||||
CONGO("CG", "Congo"),
|
||||
SWITZERLAND("CH", "Switzerland"),
|
||||
COTE_D_IVOIRE("CI", "Côte d'Ivoire"),
|
||||
COOK_ISLANDS("CK", "Cook Islands"),
|
||||
CHILE("CL", "Chile"),
|
||||
CAMEROON("CM", "Cameroon"),
|
||||
CHINA("CN", "China"),
|
||||
COLOMBIA("CO", "Colombia"),
|
||||
COSTA_RICA("CR", "Costa Rica"),
|
||||
CUBA("CU", "Cuba"),
|
||||
CAPE_VERDE("CV", "Cape Verde"),
|
||||
CURACAO("CW", "Curaçao"),
|
||||
CHRISTMAS_ISLAND("CX", "Christmas Island"),
|
||||
CYPRUS("CY", "Cyprus"),
|
||||
CZECH_REPUBLIC("CZ", "Czech Republic"),
|
||||
GERMANY("DE", "Germany"),
|
||||
DJIBOUTI("DJ", "Djibouti"),
|
||||
DENMARK("DK", "Denmark"),
|
||||
DOMINICA("DM", "Dominica"),
|
||||
DOMINICAN_REPUBLIC("DO", "Dominican Republic"),
|
||||
ALGERIA("DZ", "Algeria"),
|
||||
ECUADOR("EC", "Ecuador"),
|
||||
ESTONIA("EE", "Estonia"),
|
||||
EGYPT("EG", "Egypt"),
|
||||
WESTERN_SAHARA("EH", "Western Sahara"),
|
||||
ERITREA("ER", "Eritrea"),
|
||||
SPAIN("ES", "Spain"),
|
||||
ETHIOPIA("ET", "Ethiopia"),
|
||||
FINLAND("FI", "Finland"),
|
||||
FIJI("FJ", "Fiji"),
|
||||
FALKLAND_ISLANDS("FK", "Falkland Islands"),
|
||||
MICRONESIA("FM", "Micronesia"),
|
||||
FAROE_ISLANDS("FO", "Faroe Islands"),
|
||||
FRANCE("FR", "France"),
|
||||
GABON("GA", "Gabon"),
|
||||
UNITED_KINGDOM("GB", "United Kingdom"),
|
||||
GRENADA("GD", "Grenada"),
|
||||
GEORGIA("GE", "Georgia"),
|
||||
FRENCH_GUIANA("GF", "French Guiana"),
|
||||
GUERNSEY("GG", "Guernsey"),
|
||||
GHANA("GH", "Ghana"),
|
||||
GIBRALTAR("GI", "Gibraltar"),
|
||||
GREENLAND("GL", "Greenland"),
|
||||
GAMBIA("GM", "Gambia"),
|
||||
GUINEA("GN", "Guinea"),
|
||||
GUADELOUPE("GP", "Guadeloupe"),
|
||||
EQUATORIAL_GUINEA("GQ", "Equatorial Guinea"),
|
||||
GREECE("GR", "Greece"),
|
||||
SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS("GS", "South Georgia And The South Sandwich Islands"),
|
||||
GUATEMALA("GT", "Guatemala"),
|
||||
GUAM("GU", "Guam"),
|
||||
GUINEA_BISSAU("GW", "Guinea-Bissau"),
|
||||
GUYANA("GY", "Guyana"),
|
||||
HONG_KONG("HK", "Hong Kong"),
|
||||
HEARD_ISLAND_AND_MCDONALD_ISLANDS("HM", "Heard Island And McDonald Islands"),
|
||||
HONDURAS("HN", "Honduras"),
|
||||
CROATIA("HR", "Croatia"),
|
||||
HAITI("HT", "Haiti"),
|
||||
HUNGARY("HU", "Hungary"),
|
||||
INDONESIA("ID", "Indonesia"),
|
||||
IRELAND("IE", "Ireland"),
|
||||
ISRAEL("IL", "Israel"),
|
||||
ISLE_OF_MAN("IM", "Isle Of Man"),
|
||||
INDIA("IN", "India"),
|
||||
BRITISH_INDIAN_OCEAN_TERRITORY("IO", "British Indian Ocean Territory"),
|
||||
IRAQ("IQ", "Iraq"),
|
||||
IRAN("IR", "Iran"),
|
||||
ICELAND("IS", "Iceland"),
|
||||
ITALY("IT", "Italy"),
|
||||
JERSEY("JE", "Jersey"),
|
||||
JAMAICA("JM", "Jamaica"),
|
||||
JORDAN("JO", "Jordan"),
|
||||
JAPAN("JP", "Japan"),
|
||||
KENYA("KE", "Kenya"),
|
||||
KYRGYZSTAN("KG", "Kyrgyzstan"),
|
||||
CAMBODIA("KH", "Cambodia"),
|
||||
KIRIBATI("KI", "Kiribati"),
|
||||
COMOROS("KM", "Comoros"),
|
||||
SAINT_KITTS_AND_NEVIS("KN", "Saint Kitts And Nevis"),
|
||||
NORTH_KOREA("KP", "North Korea"),
|
||||
SOUTH_KOREA("KR", "South Korea"),
|
||||
KUWAIT("KW", "Kuwait"),
|
||||
CAYMAN_ISLANDS("KY", "Cayman Islands"),
|
||||
KAZAKHSTAN("KZ", "Kazakhstan"),
|
||||
LAOS("LA", "Laos"),
|
||||
LEBANON("LB", "Lebanon"),
|
||||
SAINT_LUCIA("LC", "Saint Lucia"),
|
||||
LIECHTENSTEIN("LI", "Liechtenstein"),
|
||||
SRI_LANKA("LK", "Sri Lanka"),
|
||||
LIBERIA("LR", "Liberia"),
|
||||
LESOTHO("LS", "Lesotho"),
|
||||
LITHUANIA("LT", "Lithuania"),
|
||||
LUXEMBOURG("LU", "Luxembourg"),
|
||||
LATVIA("LV", "Latvia"),
|
||||
LIBYA("LY", "Libya"),
|
||||
MOROCCO("MA", "Morocco"),
|
||||
MONACO("MC", "Monaco"),
|
||||
MOLDOVA("MD", "Moldova"),
|
||||
MONTENEGRO("ME", "Montenegro"),
|
||||
SAINT_MARTIN("MF", "Saint Martin"),
|
||||
MADAGASCAR("MG", "Madagascar"),
|
||||
MARSHALL_ISLANDS("MH", "Marshall Islands"),
|
||||
MACEDONIA("MK", "Macedonia"),
|
||||
MALI("ML", "Mali"),
|
||||
MYANMAR("MM", "Myanmar"),
|
||||
MONGOLIA("MN", "Mongolia"),
|
||||
MACAO("MO", "Macao"),
|
||||
NORTHERN_MARIANA_ISLANDS("MP", "Northern Mariana Islands"),
|
||||
MARTINIQUE("MQ", "Martinique"),
|
||||
MAURITANIA("MR", "Mauritania"),
|
||||
MONTSERRAT("MS", "Montserrat"),
|
||||
MALTA("MT", "Malta"),
|
||||
MAURITIUS("MU", "Mauritius"),
|
||||
MALDIVES("MV", "Maldives"),
|
||||
MALAWI("MW", "Malawi"),
|
||||
MEXICO("MX", "Mexico"),
|
||||
MALAYSIA("MY", "Malaysia"),
|
||||
MOZAMBIQUE("MZ", "Mozambique"),
|
||||
NAMIBIA("NA", "Namibia"),
|
||||
NEW_CALEDONIA("NC", "New Caledonia"),
|
||||
NIGER("NE", "Niger"),
|
||||
NORFOLK_ISLAND("NF", "Norfolk Island"),
|
||||
NIGERIA("NG", "Nigeria"),
|
||||
NICARAGUA("NI", "Nicaragua"),
|
||||
NETHERLANDS("NL", "Netherlands"),
|
||||
NORWAY("NO", "Norway"),
|
||||
NEPAL("NP", "Nepal"),
|
||||
NAURU("NR", "Nauru"),
|
||||
NIUE("NU", "Niue"),
|
||||
NEW_ZEALAND("NZ", "New Zealand"),
|
||||
OMAN("OM", "Oman"),
|
||||
PANAMA("PA", "Panama"),
|
||||
PERU("PE", "Peru"),
|
||||
FRENCH_POLYNESIA("PF", "French Polynesia"),
|
||||
PAPUA_NEW_GUINEA("PG", "Papua New Guinea"),
|
||||
PHILIPPINES("PH", "Philippines"),
|
||||
PAKISTAN("PK", "Pakistan"),
|
||||
POLAND("PL", "Poland"),
|
||||
SAINT_PIERRE_AND_MIQUELON("PM", "Saint Pierre And Miquelon"),
|
||||
PITCAIRN("PN", "Pitcairn"),
|
||||
PUERTO_RICO("PR", "Puerto Rico"),
|
||||
PALESTINE("PS", "Palestine"),
|
||||
PORTUGAL("PT", "Portugal"),
|
||||
PALAU("PW", "Palau"),
|
||||
PARAGUAY("PY", "Paraguay"),
|
||||
QATAR("QA", "Qatar"),
|
||||
REUNION("RE", "Reunion"),
|
||||
ROMANIA("RO", "Romania"),
|
||||
SERBIA("RS", "Serbia"),
|
||||
RUSSIA("RU", "Russia"),
|
||||
RWANDA("RW", "Rwanda"),
|
||||
SAUDI_ARABIA("SA", "Saudi Arabia"),
|
||||
SOLOMON_ISLANDS("SB", "Solomon Islands"),
|
||||
SEYCHELLES("SC", "Seychelles"),
|
||||
SUDAN("SD", "Sudan"),
|
||||
SWEDEN("SE", "Sweden"),
|
||||
SINGAPORE("SG", "Singapore"),
|
||||
SAINT_HELENA("SH", "Saint Helena"),
|
||||
SLOVENIA("SI", "Slovenia"),
|
||||
SVALBARD_AND_JAN_MAYEN("SJ", "Svalbard And Jan Mayen"),
|
||||
SLOVAKIA("SK", "Slovakia"),
|
||||
SIERRA_LEONE("SL", "Sierra Leone"),
|
||||
SAN_MARINO("SM", "San Marino"),
|
||||
SENEGAL("SN", "Senegal"),
|
||||
SOMALIA("SO", "Somalia"),
|
||||
SURINAME("SR", "Suriname"),
|
||||
SOUTH_SUDAN("SS", "South Sudan"),
|
||||
SAO_TOME_AND_PRINCIPE("ST", "Sao Tome And Principe"),
|
||||
EL_SALVADOR("SV", "El Salvador"),
|
||||
SINT_MAARTEN_DUTCH_PART("SX", "Sint Maarten (Dutch part)"),
|
||||
SYRIA("SY", "Syria"),
|
||||
SWAZILAND("SZ", "Swaziland"),
|
||||
TURKS_AND_CAICOS_ISLANDS("TC", "Turks And Caicos Islands"),
|
||||
CHAD("TD", "Chad"),
|
||||
FRENCH_SOUTHERN_TERRITORIES("TF", "French Southern Territories"),
|
||||
TOGO("TG", "Togo"),
|
||||
THAILAND("TH", "Thailand"),
|
||||
TAJIKISTAN("TJ", "Tajikistan"),
|
||||
TOKELAU("TK", "Tokelau"),
|
||||
TIMOR_LESTE("TL", "Timor-Leste"),
|
||||
TURKMENISTAN("TM", "Turkmenistan"),
|
||||
TUNISIA("TN", "Tunisia"),
|
||||
TONGA("TO", "Tonga"),
|
||||
TURKEY("TR", "Turkey"),
|
||||
TRINIDAD_AND_TOBAGO("TT", "Trinidad and Tobago"),
|
||||
TUVALU("TV", "Tuvalu"),
|
||||
TAIWAN("TW", "Taiwan"),
|
||||
TANZANIA("TZ", "Tanzania"),
|
||||
UKRAINE("UA", "Ukraine"),
|
||||
UGANDA("UG", "Uganda"),
|
||||
UNITED_STATES_MINOR_OUTLYING_ISLANDS("UM", "United States Minor Outlying Islands"),
|
||||
UNITED_STATES("US", "United States"),
|
||||
URUGUAY("UY", "Uruguay"),
|
||||
UZBEKISTAN("UZ", "Uzbekistan"),
|
||||
VATICAN("VA", "Vatican"),
|
||||
SAINT_VINCENT_AND_THE_GRENADINES("VC", "Saint Vincent And The Grenadines"),
|
||||
VENEZUELA("VE", "Venezuela"),
|
||||
BRITISH_VIRGIN_ISLANDS("VG", "British Virgin Islands"),
|
||||
U_S__VIRGIN_ISLANDS("VI", "U.S. Virgin Islands"),
|
||||
VIETNAM("VN", "Vietnam"),
|
||||
VANUATU("VU", "Vanuatu"),
|
||||
WALLIS_AND_FUTUNA("WF", "Wallis And Futuna"),
|
||||
SAMOA("WS", "Samoa"),
|
||||
YEMEN("YE", "Yemen"),
|
||||
MAYOTTE("YT", "Mayotte"),
|
||||
SOUTH_AFRICA("ZA", "South Africa"),
|
||||
ZAMBIA("ZM", "Zambia"),
|
||||
ZIMBABWE("ZW", "Zimbabwe");
|
||||
|
||||
private String isoTag;
|
||||
private String name;
|
||||
|
||||
Country(String isoTag, String name) {
|
||||
this.isoTag = isoTag;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the country.
|
||||
*
|
||||
* @return The name of the country.
|
||||
*/
|
||||
public String getCountryName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the iso tag of the country.
|
||||
*
|
||||
* @return The iso tag of the country.
|
||||
*/
|
||||
public String getCountryIsoTag() {
|
||||
return isoTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a country by it's iso tag.
|
||||
*
|
||||
* @param isoTag The iso tag of the county.
|
||||
* @return The country with the given iso tag or <code>null</code> if unknown.
|
||||
*/
|
||||
public static Country byIsoTag(String isoTag) {
|
||||
for (Country country : Country.values()) {
|
||||
if (country.getCountryIsoTag().equals(isoTag)) {
|
||||
return country;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a country by a locale.
|
||||
*
|
||||
* @param locale The locale.
|
||||
* @return The country from the giben locale or <code>null</code> if unknown country or
|
||||
* if the locale does not contain a country.
|
||||
*/
|
||||
public static Country byLocale(Locale locale) {
|
||||
return byIsoTag(locale.getCountry());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ import com.loohp.limbo.Server.Packets.PacketPlayOutGameState;
|
|||
import com.loohp.limbo.Server.Packets.PacketPlayOutPositionAndLook;
|
||||
import com.loohp.limbo.Server.Packets.PacketPlayOutRespawn;
|
||||
import com.loohp.limbo.Utils.GameMode;
|
||||
import com.loohp.limbo.World.DimensionRegistry;
|
||||
import com.loohp.limbo.World.World;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
|
@ -104,7 +105,7 @@ public class Player implements CommandSender {
|
|||
public void teleport(Location location) {
|
||||
try {
|
||||
if (!this.location.getWorld().equals(location.getWorld())) {
|
||||
PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(location.getWorld(), 0, gamemode, false, false, true);
|
||||
PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(location.getWorld(), DimensionRegistry.getCodec(), 0, gamemode, false, false, true);
|
||||
clientConnection.sendPacket(respawn);
|
||||
}
|
||||
PacketPlayOutPositionAndLook positionLook = new PacketPlayOutPositionAndLook(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), 1);
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ public class ClientConnection extends Thread {
|
|||
String str = client_socket.getInetAddress().getHostName() + ":" + client_socket.getPort();
|
||||
Limbo.getInstance().getConsole().sendMessage("[/" + str + "] <-> Legacy Status has pinged");
|
||||
ServerProperties p = Limbo.getInstance().getServerProperties();
|
||||
StatusPingEvent event = (StatusPingEvent) Limbo.getInstance().getEventsManager().callEvent(new StatusPingEvent(this, p.getVersionString(), p.getProtocol(), ComponentSerializer.parse(p.getMotdJson()), p.getMaxPlayers(), Limbo.getInstance().getPlayers().size(), p.getFavicon().orElse(null)));
|
||||
StatusPingEvent event = Limbo.getInstance().getEventsManager().callEvent(new StatusPingEvent(this, p.getVersionString(), p.getProtocol(), ComponentSerializer.parse(p.getMotdJson()), p.getMaxPlayers(), Limbo.getInstance().getPlayers().size(), p.getFavicon().orElse(null)));
|
||||
String response = Limbo.getInstance().buildLegacyPingResponse(event.getVersion(), event.getMotd(), event.getMaxPlayers(), event.getPlayersOnline());
|
||||
byte[] bytes = response.getBytes(StandardCharsets.UTF_16BE);
|
||||
output.writeShort(response.length());
|
||||
|
|
@ -208,7 +208,7 @@ public class ClientConnection extends Thread {
|
|||
String str = client_socket.getInetAddress().getHostName() + ":" + client_socket.getPort();
|
||||
Limbo.getInstance().getConsole().sendMessage("[/" + str + "] <-> Handshake Status has pinged");
|
||||
ServerProperties p = Limbo.getInstance().getServerProperties();
|
||||
StatusPingEvent event = (StatusPingEvent) Limbo.getInstance().getEventsManager().callEvent(new StatusPingEvent(this, p.getVersionString(), p.getProtocol(), ComponentSerializer.parse(p.getMotdJson()), p.getMaxPlayers(), Limbo.getInstance().getPlayers().size(), p.getFavicon().orElse(null)));
|
||||
StatusPingEvent event = Limbo.getInstance().getEventsManager().callEvent(new StatusPingEvent(this, p.getVersionString(), p.getProtocol(), ComponentSerializer.parse(p.getMotdJson()), p.getMaxPlayers(), Limbo.getInstance().getPlayers().size(), p.getFavicon().orElse(null)));
|
||||
PacketStatusOutResponse packet = new PacketStatusOutResponse(Limbo.getInstance().buildServerListResponseJson(event.getVersion(), event.getProtocol(), event.getMotd(), event.getMaxPlayers(), event.getPlayersOnline(), event.getFavicon()));
|
||||
sendPacket(packet);
|
||||
} else if (packetType.equals(PacketStatusInPing.class)) {
|
||||
|
|
@ -268,7 +268,7 @@ public class ClientConnection extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
PlayerLoginEvent event = (PlayerLoginEvent) Limbo.getInstance().getEventsManager().callEvent(new PlayerLoginEvent(this, false));
|
||||
PlayerLoginEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerLoginEvent(this, false));
|
||||
if (event.isCancelled()) {
|
||||
disconnectDuringLogin(event.getCancelReason());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ import com.loohp.limbo.Utils.DataTypeIO;
|
|||
import com.loohp.limbo.Utils.GameMode;
|
||||
import com.loohp.limbo.Utils.NamespacedKey;
|
||||
import com.loohp.limbo.World.World;
|
||||
import com.loohp.limbo.World.World.Environment;
|
||||
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
import net.querz.nbt.tag.ListTag;
|
||||
|
||||
public class PacketPlayOutLogin extends PacketOut {
|
||||
|
||||
|
|
@ -19,7 +21,7 @@ public class PacketPlayOutLogin extends PacketOut {
|
|||
private GameMode gamemode;
|
||||
private String[] worldsNames;
|
||||
private CompoundTag dimensionCodec;
|
||||
private String dimension;
|
||||
private Environment dimension;
|
||||
private String worldName;
|
||||
private long hashedSeed;
|
||||
private byte maxPlayers;
|
||||
|
|
@ -38,7 +40,7 @@ public class PacketPlayOutLogin extends PacketOut {
|
|||
this.gamemode = gamemode;
|
||||
this.worldsNames = worldsNames;
|
||||
this.dimensionCodec = dimensionCodec;
|
||||
this.dimension = world.getEnvironment().getNamespacedKey().toString();
|
||||
this.dimension = world.getEnvironment();
|
||||
this.worldName = new NamespacedKey(world.getName()).toString();
|
||||
this.hashedSeed = hashedSeed;
|
||||
this.maxPlayers = maxPlayers;
|
||||
|
|
@ -69,7 +71,7 @@ public class PacketPlayOutLogin extends PacketOut {
|
|||
return dimensionCodec;
|
||||
}
|
||||
|
||||
public String getDimension() {
|
||||
public Environment getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
|
|
@ -112,21 +114,26 @@ public class PacketPlayOutLogin extends PacketOut {
|
|||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
output.writeInt(entityId);
|
||||
int i = gamemode.getId();
|
||||
if (isHardcore) {
|
||||
i |= 8;
|
||||
}
|
||||
output.writeByte((byte) i);
|
||||
output.writeBoolean(isHardcore);
|
||||
output.writeByte((byte) gamemode.getId());
|
||||
output.writeByte((byte) gamemode.getId());
|
||||
DataTypeIO.writeVarInt(output, worldsNames.length);
|
||||
for (int u = 0; u < worldsNames.length; u++) {
|
||||
DataTypeIO.writeString(output, worldsNames[u], StandardCharsets.UTF_8);
|
||||
}
|
||||
DataTypeIO.writeCompoundTag(output, dimensionCodec);
|
||||
DataTypeIO.writeString(output, dimension, StandardCharsets.UTF_8);
|
||||
CompoundTag tag = null;
|
||||
ListTag<CompoundTag> list = dimensionCodec.getCompoundTag("minecraft:dimension_type").getListTag("value").asCompoundTagList();
|
||||
for (CompoundTag each : list) {
|
||||
if (each.getString("name").equals(dimension.getNamespacedKey().toString())) {
|
||||
tag = each.getCompoundTag("element");
|
||||
break;
|
||||
}
|
||||
}
|
||||
DataTypeIO.writeCompoundTag(output, tag != null ? tag : list.get(0));
|
||||
DataTypeIO.writeString(output, worldName, StandardCharsets.UTF_8);
|
||||
output.writeLong(hashedSeed);
|
||||
output.writeByte((byte) maxPlayers);
|
||||
DataTypeIO.writeVarInt(output, maxPlayers);
|
||||
DataTypeIO.writeVarInt(output, viewDistance);
|
||||
output.writeBoolean(reducedDebugInfo);
|
||||
output.writeBoolean(enableRespawnScreen);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import java.util.Iterator;
|
|||
|
||||
import com.loohp.limbo.Utils.ChunkDataUtils;
|
||||
import com.loohp.limbo.Utils.DataTypeIO;
|
||||
import com.loohp.limbo.Utils.GeneratedDataUtils;
|
||||
import com.loohp.limbo.World.GeneratedBlockDataMappings;
|
||||
import com.loohp.limbo.World.World.Environment;
|
||||
|
||||
import net.querz.mca.Chunk;
|
||||
|
|
@ -60,7 +60,6 @@ public class PacketPlayOutMapChunk extends PacketOut {
|
|||
output.writeInt(chunkX);
|
||||
output.writeInt(chunkZ);
|
||||
output.writeBoolean(true);
|
||||
output.writeBoolean(true);
|
||||
int bitmask = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
Section section = chunk.getSection(i);
|
||||
|
|
@ -70,9 +69,8 @@ public class PacketPlayOutMapChunk extends PacketOut {
|
|||
}
|
||||
DataTypeIO.writeVarInt(output, bitmask);
|
||||
DataTypeIO.writeCompoundTag(output, chunk.getHeightMaps());
|
||||
//for (int i : chunk.getBiomes()) {
|
||||
// output.writeInt(i);
|
||||
//}
|
||||
|
||||
DataTypeIO.writeVarInt(output, 1024);
|
||||
int biome;
|
||||
switch (environment) {
|
||||
case END:
|
||||
|
|
@ -87,7 +85,7 @@ public class PacketPlayOutMapChunk extends PacketOut {
|
|||
break;
|
||||
}
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
output.writeInt(biome);
|
||||
DataTypeIO.writeVarInt(output, biome);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream dataBuffer = new ByteArrayOutputStream();
|
||||
|
|
@ -127,7 +125,7 @@ public class PacketPlayOutMapChunk extends PacketOut {
|
|||
counter = 0;
|
||||
while (itr1.hasNext()) {
|
||||
CompoundTag tag = itr1.next();
|
||||
DataTypeIO.writeVarInt(dataOut, GeneratedDataUtils.getGlobalPaletteIDFromState(tag));
|
||||
DataTypeIO.writeVarInt(dataOut, GeneratedBlockDataMappings.getGlobalPaletteIDFromState(tag));
|
||||
//System.out.println(tag + " -> " + GeneratedDataUtils.getGlobalPaletteIDFromState(tag));
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,20 +9,26 @@ import com.loohp.limbo.Utils.DataTypeIO;
|
|||
import com.loohp.limbo.Utils.GameMode;
|
||||
import com.loohp.limbo.Utils.NamespacedKey;
|
||||
import com.loohp.limbo.World.World;
|
||||
import com.loohp.limbo.World.World.Environment;
|
||||
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
import net.querz.nbt.tag.ListTag;
|
||||
|
||||
public class PacketPlayOutRespawn extends PacketOut {
|
||||
|
||||
private String dimension;
|
||||
private Environment dimension;
|
||||
private String worldName;
|
||||
private CompoundTag dimensionCodec;
|
||||
private long hashedSeed;
|
||||
private GameMode gamemode;
|
||||
private boolean isDebug;
|
||||
private boolean isFlat;
|
||||
private boolean copyMetaData;
|
||||
|
||||
public PacketPlayOutRespawn(World world, long hashedSeed, GameMode gamemode, boolean isDebug,
|
||||
public PacketPlayOutRespawn(World world, CompoundTag dimensionCodec, long hashedSeed, GameMode gamemode, boolean isDebug,
|
||||
boolean isFlat, boolean copyMetaData) {
|
||||
this.dimension = world.getEnvironment().getNamespacedKey().toString();
|
||||
this.dimension = world.getEnvironment();
|
||||
this.dimensionCodec = dimensionCodec;
|
||||
this.worldName = new NamespacedKey(world.getName()).toString();
|
||||
this.hashedSeed = hashedSeed;
|
||||
this.gamemode = gamemode;
|
||||
|
|
@ -31,7 +37,11 @@ public class PacketPlayOutRespawn extends PacketOut {
|
|||
this.copyMetaData = copyMetaData;
|
||||
}
|
||||
|
||||
public String getDimension() {
|
||||
public CompoundTag getDimensionCodec() {
|
||||
return dimensionCodec;
|
||||
}
|
||||
|
||||
public Environment getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +75,15 @@ public class PacketPlayOutRespawn extends PacketOut {
|
|||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
DataTypeIO.writeString(output, dimension, StandardCharsets.UTF_8);
|
||||
CompoundTag tag = null;
|
||||
ListTag<CompoundTag> list = dimensionCodec.getCompoundTag("minecraft:dimension_type").getListTag("value").asCompoundTagList();
|
||||
for (CompoundTag each : list) {
|
||||
if (each.getString("name").equals(dimension.getNamespacedKey().toString())) {
|
||||
tag = each.getCompoundTag("element");
|
||||
break;
|
||||
}
|
||||
}
|
||||
DataTypeIO.writeCompoundTag(output, tag != null ? tag : list.get(0));
|
||||
DataTypeIO.writeString(output, worldName, StandardCharsets.UTF_8);
|
||||
output.writeLong(hashedSeed);
|
||||
output.writeByte((byte) gamemode.getId());
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.loohp.limbo.Utils.DataTypeIO;
|
||||
import com.loohp.limbo.World.BlockPosition;
|
||||
|
||||
public class PacketPlayOutSpawnPosition extends PacketOut {
|
||||
|
|
@ -23,10 +24,7 @@ public class PacketPlayOutSpawnPosition extends PacketOut {
|
|||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
int x = position.getX();
|
||||
int y = position.getY();
|
||||
int z = position.getZ();
|
||||
output.writeLong(((x & 0x3FFFFFF) << 38) | ((z & 0x3FFFFFF) << 12) | (y & 0xFFF));
|
||||
DataTypeIO.writeBlockPosition(output, position);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.loohp.limbo.Utils;
|
||||
|
||||
public class CustomArrayUtils {
|
||||
|
||||
public static int[] longArrayToIntArray(long[] numbers) {
|
||||
int[] intNumbers = new int[numbers.length];
|
||||
for(int i = 0; i < numbers.length; i++) {
|
||||
intNumbers[i] = (int) numbers[i];
|
||||
}
|
||||
return intNumbers;
|
||||
}
|
||||
|
||||
public static byte[] longArrayToByteArray(long[] numbers) {
|
||||
byte[] intNumbers = new byte[numbers.length];
|
||||
for(int i = 0; i < numbers.length; i++) {
|
||||
intNumbers[i] = (byte) numbers[i];
|
||||
}
|
||||
return intNumbers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
package com.loohp.limbo.Utils;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import net.querz.nbt.tag.ByteArrayTag;
|
||||
import net.querz.nbt.tag.ByteTag;
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
import net.querz.nbt.tag.DoubleTag;
|
||||
import net.querz.nbt.tag.FloatTag;
|
||||
import net.querz.nbt.tag.IntArrayTag;
|
||||
import net.querz.nbt.tag.IntTag;
|
||||
import net.querz.nbt.tag.ListTag;
|
||||
import net.querz.nbt.tag.LongArrayTag;
|
||||
import net.querz.nbt.tag.LongTag;
|
||||
import net.querz.nbt.tag.ShortTag;
|
||||
import net.querz.nbt.tag.StringTag;
|
||||
import net.querz.nbt.tag.Tag;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class CustomNBTUtils {
|
||||
|
||||
public enum TagClass {
|
||||
CompoundTagClass(CompoundTag.class),
|
||||
ByteTagClass(ByteTag.class),
|
||||
ShortTagClass(ShortTag.class),
|
||||
IntTagClass(IntTag.class),
|
||||
LongTagClass(LongTag.class),
|
||||
FloatTagClass(FloatTag.class),
|
||||
DoubleTagClass(DoubleTag.class),
|
||||
ByteArrayTagClass(ByteArrayTag.class),
|
||||
IntArrayTagClass(IntArrayTag.class),
|
||||
LongArrayTagClass(LongArrayTag.class),
|
||||
StringTagClass(StringTag.class),
|
||||
ListTagClass(ListTag.class);
|
||||
|
||||
Class<? extends Tag> clazz;
|
||||
|
||||
TagClass(Class<? extends Tag> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public Class<? extends Tag> getTagClass() {
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<? extends Tag> getClassFromName(String name) {
|
||||
for (TagClass clazz : TagClass.values()) {
|
||||
if (clazz.getTagClass().getSimpleName().equals(name)) {
|
||||
return clazz.getTagClass();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CompoundTag getCompoundTagFromJson(JSONObject json) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
|
||||
for (Object obj : json.keySet()) {
|
||||
String key = (String) obj;
|
||||
JSONObject inside = (JSONObject) json.get(key);
|
||||
String type = (String) inside.get("type");
|
||||
|
||||
switch (type) {
|
||||
case "ByteTag":
|
||||
tag.putByte(key, (byte) (long) inside.get("value"));
|
||||
break;
|
||||
case "ShortTag":
|
||||
tag.putShort(key, (short) (long) inside.get("value"));
|
||||
break;
|
||||
case "IntTag":
|
||||
tag.putInt(key, (int) (long) inside.get("value"));
|
||||
break;
|
||||
case "LongTag":
|
||||
tag.putLong(key, (long) inside.get("value"));
|
||||
break;
|
||||
case "FloatTag":
|
||||
tag.putFloat(key, inside.get("value") instanceof Long ? (float) (long) inside.get("value") : (float) (double) inside.get("value"));
|
||||
break;
|
||||
case "DoubleTag":
|
||||
tag.putDouble(key, inside.get("value") instanceof Long ? (double) (long) inside.get("value") : (double) inside.get("value"));
|
||||
break;
|
||||
case "ByteArrayTag":
|
||||
tag.putByteArray(key, CustomArrayUtils.longArrayToByteArray((long[]) inside.get("value")));
|
||||
break;
|
||||
case "IntArrayTag":
|
||||
tag.putIntArray(key, CustomArrayUtils.longArrayToIntArray((long[]) inside.get("value")));
|
||||
break;
|
||||
case "LongArrayTag":
|
||||
tag.putLongArray(key, (long[]) inside.get("value"));
|
||||
break;
|
||||
case "StringTag":
|
||||
tag.putString(key, (String) inside.get("value"));
|
||||
break;
|
||||
case "CompoundTag":
|
||||
tag.put(key, getCompoundTagFromJson((JSONObject) inside.get("value")));
|
||||
break;
|
||||
case "ListTag":
|
||||
tag.put(key, getListTagFromJson((JSONObject) inside.get("value")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static ListTag<?> getListTagFromJson(JSONObject json) {
|
||||
String type = (String) json.get("type");
|
||||
JSONArray array = (JSONArray) json.get("list");
|
||||
|
||||
ListTag<?> listTag = ListTag.createUnchecked(getClassFromName(type));
|
||||
|
||||
switch (type) {
|
||||
case "ByteTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addByte((byte) (long) obj);
|
||||
}
|
||||
break;
|
||||
case "ShortTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addShort((short) (long) obj);
|
||||
}
|
||||
break;
|
||||
case "IntTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addInt((int) (long) obj);
|
||||
}
|
||||
break;
|
||||
case "LongTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addLong((long) obj);
|
||||
}
|
||||
break;
|
||||
case "FloatTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addFloat(obj instanceof Long ? (float) (long) obj : (float) (double) obj);
|
||||
}
|
||||
break;
|
||||
case "DoubleTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addDouble(obj instanceof Long ? (double) (long) obj : (double) obj);
|
||||
}
|
||||
break;
|
||||
case "ByteArrayTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addByteArray(CustomArrayUtils.longArrayToByteArray((long[]) obj));
|
||||
}
|
||||
break;
|
||||
case "IntArrayTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addIntArray(CustomArrayUtils.longArrayToIntArray((long[]) obj));
|
||||
}
|
||||
break;
|
||||
case "LongArrayTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addLongArray((long[]) obj);
|
||||
}
|
||||
break;
|
||||
case "StringTag":
|
||||
for (Object obj : array) {
|
||||
listTag.addString((String) obj);
|
||||
}
|
||||
break;
|
||||
case "CompoundTag":
|
||||
for (Object obj : array) {
|
||||
listTag.asCompoundTagList().add(getCompoundTagFromJson((JSONObject) obj));
|
||||
}
|
||||
break;
|
||||
case "ListTag":
|
||||
for (Object obj : array) {
|
||||
listTag.asListTagList().add(getListTagFromJson((JSONObject) obj));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,12 +7,18 @@ import java.io.IOException;
|
|||
import java.nio.charset.Charset;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.loohp.limbo.World.BlockPosition;
|
||||
|
||||
import net.querz.nbt.io.NBTOutputStream;
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
import net.querz.nbt.tag.Tag;
|
||||
|
||||
public class DataTypeIO {
|
||||
|
||||
public static void writeBlockPosition(DataOutputStream out, BlockPosition position) throws IOException {
|
||||
out.writeLong(((position.getX() & 0x3FFFFFF) << 38) | ((position.getZ() & 0x3FFFFFF) << 12) | (position.getY() & 0xFFF));
|
||||
}
|
||||
|
||||
public static void writeUUID(DataOutputStream out, UUID uuid) throws IOException {
|
||||
out.writeLong(uuid.getMostSignificantBits());
|
||||
out.writeLong(uuid.getLeastSignificantBits());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,184 @@
|
|||
package com.loohp.limbo.Utils;
|
||||
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import org.yaml.snakeyaml.introspector.BeanAccess;
|
||||
import org.yaml.snakeyaml.introspector.FieldProperty;
|
||||
import org.yaml.snakeyaml.introspector.MethodProperty;
|
||||
import org.yaml.snakeyaml.introspector.MissingProperty;
|
||||
import org.yaml.snakeyaml.introspector.Property;
|
||||
import org.yaml.snakeyaml.introspector.PropertyUtils;
|
||||
import org.yaml.snakeyaml.util.PlatformFeatureDetector;
|
||||
|
||||
public class YamlOrder extends PropertyUtils {
|
||||
|
||||
private final Map<Class<?>, Map<String, Property>> propertiesCache = new HashMap<Class<?>, Map<String, Property>>();
|
||||
private final Map<Class<?>, Set<Property>> readableProperties = new HashMap<Class<?>, Set<Property>>();
|
||||
private BeanAccess beanAccess = BeanAccess.DEFAULT;
|
||||
private boolean allowReadOnlyProperties = false;
|
||||
private boolean skipMissingProperties = false;
|
||||
|
||||
private PlatformFeatureDetector platformFeatureDetector;
|
||||
|
||||
public YamlOrder() {
|
||||
this(new PlatformFeatureDetector());
|
||||
}
|
||||
|
||||
YamlOrder(PlatformFeatureDetector platformFeatureDetector) {
|
||||
this.platformFeatureDetector = platformFeatureDetector;
|
||||
|
||||
if (platformFeatureDetector.isRunningOnAndroid()) {
|
||||
beanAccess = BeanAccess.FIELD;
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, Property> getPropertiesMap(Class<?> type, BeanAccess bAccess) {
|
||||
if (propertiesCache.containsKey(type)) {
|
||||
return propertiesCache.get(type);
|
||||
}
|
||||
|
||||
Map<String, Property> properties = new LinkedHashMap<String, Property>();
|
||||
boolean inaccessableFieldsExist = false;
|
||||
switch (bAccess) {
|
||||
case FIELD:
|
||||
for (Class<?> c = type; c != null; c = c.getSuperclass()) {
|
||||
for (Field field : c.getDeclaredFields()) {
|
||||
int modifiers = field.getModifiers();
|
||||
if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)
|
||||
&& !properties.containsKey(field.getName())) {
|
||||
properties.put(field.getName(), new FieldProperty(field));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
for (PropertyDescriptor property : Introspector.getBeanInfo(type)
|
||||
.getPropertyDescriptors()) {
|
||||
Method readMethod = property.getReadMethod();
|
||||
if ((readMethod == null || !readMethod.getName().equals("getClass"))
|
||||
&& !isTransient(property)) {
|
||||
properties.put(property.getName(), new MethodProperty(property));
|
||||
}
|
||||
}
|
||||
} catch (IntrospectionException e) {
|
||||
throw new YAMLException(e);
|
||||
}
|
||||
|
||||
for (Class<?> c = type; c != null; c = c.getSuperclass()) {
|
||||
for (Field field : c.getDeclaredFields()) {
|
||||
int modifiers = field.getModifiers();
|
||||
if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) {
|
||||
if (Modifier.isPublic(modifiers)) {
|
||||
properties.put(field.getName(), new FieldProperty(field));
|
||||
} else {
|
||||
inaccessableFieldsExist = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (properties.isEmpty() && inaccessableFieldsExist) {
|
||||
throw new YAMLException("No JavaBean properties found in " + type.getName());
|
||||
}
|
||||
System.out.println(properties);
|
||||
propertiesCache.put(type, properties);
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static final String TRANSIENT = "transient";
|
||||
|
||||
private boolean isTransient(FeatureDescriptor fd) {
|
||||
return Boolean.TRUE.equals(fd.getValue(TRANSIENT));
|
||||
}
|
||||
|
||||
public Set<Property> getProperties(Class<? extends Object> type) {
|
||||
return getProperties(type, beanAccess);
|
||||
}
|
||||
|
||||
public Set<Property> getProperties(Class<? extends Object> type, BeanAccess bAccess) {
|
||||
if (readableProperties.containsKey(type)) {
|
||||
return readableProperties.get(type);
|
||||
}
|
||||
Set<Property> properties = createPropertySet(type, bAccess);
|
||||
readableProperties.put(type, properties);
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bAccess) {
|
||||
Set<Property> properties = new LinkedHashSet<>();
|
||||
Collection<Property> props = getPropertiesMap(type, bAccess).values();
|
||||
for (Property property : props) {
|
||||
if (property.isReadable() && (allowReadOnlyProperties || property.isWritable())) {
|
||||
properties.add(property);
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
public Property getProperty(Class<? extends Object> type, String name) {
|
||||
return getProperty(type, name, beanAccess);
|
||||
}
|
||||
|
||||
public Property getProperty(Class<? extends Object> type, String name, BeanAccess bAccess) {
|
||||
Map<String, Property> properties = getPropertiesMap(type, bAccess);
|
||||
Property property = properties.get(name);
|
||||
if (property == null && skipMissingProperties) {
|
||||
property = new MissingProperty(name);
|
||||
}
|
||||
if (property == null) {
|
||||
throw new YAMLException(
|
||||
"Unable to find property '" + name + "' on class: " + type.getName());
|
||||
}
|
||||
return property;
|
||||
}
|
||||
|
||||
public void setBeanAccess(BeanAccess beanAccess) {
|
||||
if (platformFeatureDetector.isRunningOnAndroid() && beanAccess != BeanAccess.FIELD) {
|
||||
throw new IllegalArgumentException(
|
||||
"JVM is Android - only BeanAccess.FIELD is available");
|
||||
}
|
||||
|
||||
if (this.beanAccess != beanAccess) {
|
||||
this.beanAccess = beanAccess;
|
||||
propertiesCache.clear();
|
||||
readableProperties.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAllowReadOnlyProperties(boolean allowReadOnlyProperties) {
|
||||
if (this.allowReadOnlyProperties != allowReadOnlyProperties) {
|
||||
this.allowReadOnlyProperties = allowReadOnlyProperties;
|
||||
readableProperties.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAllowReadOnlyProperties() {
|
||||
return allowReadOnlyProperties;
|
||||
}
|
||||
|
||||
public void setSkipMissingProperties(boolean skipMissingProperties) {
|
||||
if (this.skipMissingProperties != skipMissingProperties) {
|
||||
this.skipMissingProperties = skipMissingProperties;
|
||||
readableProperties.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSkipMissingProperties() {
|
||||
return skipMissingProperties;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +1,49 @@
|
|||
package com.loohp.limbo.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.loohp.limbo.Limbo;
|
||||
import com.loohp.limbo.Utils.CustomNBTUtils;
|
||||
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
import net.querz.nbt.tag.ListTag;
|
||||
|
||||
public class DimensionRegistry {
|
||||
|
||||
public static CompoundTag defaultTag;
|
||||
private static File reg;
|
||||
|
||||
static {
|
||||
String reg = "dimension_registry.json";
|
||||
File file = new File(Limbo.getInstance().getInternalDataFolder(), reg);
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(reg)) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
DimensionRegistry.reg = file;
|
||||
|
||||
resetTag();
|
||||
}
|
||||
|
||||
public static void resetTag() {
|
||||
CompoundTag overworld = new CompoundTag();
|
||||
overworld.putString("name", "minecraft:overworld");
|
||||
overworld.putByte("natural", (byte) 1);
|
||||
overworld.putFloat("ambient_light", 0.0F);
|
||||
overworld.putByte("has_ceiling", (byte) 0);
|
||||
overworld.putByte("has_skylight", (byte) 1);
|
||||
overworld.putLong("fixed_time", 0);
|
||||
overworld.putByte("shrunk", (byte) 0);
|
||||
overworld.putByte("ultrawarm", (byte) 0);
|
||||
overworld.putByte("has_raids", (byte) 1);
|
||||
overworld.putByte("respawn_anchor_works", (byte) 0);
|
||||
overworld.putByte("bed_works", (byte) 1);
|
||||
overworld.putByte("piglin_safe", (byte) 0);
|
||||
overworld.putInt("logical_height", 256);
|
||||
overworld.putString("infiniburn", "minecraft:infiniburn_overworld");
|
||||
|
||||
CompoundTag overworld_caves = new CompoundTag();
|
||||
overworld_caves.putString("name", "minecraft:overworld_caves");
|
||||
overworld_caves.putByte("natural", (byte) 1);
|
||||
overworld_caves.putFloat("ambient_light", 0.0F);
|
||||
overworld_caves.putByte("has_ceiling", (byte) 1);
|
||||
overworld_caves.putByte("has_skylight", (byte) 1);
|
||||
overworld_caves.putLong("fixed_time", 0);
|
||||
overworld_caves.putByte("shrunk", (byte) 0);
|
||||
overworld_caves.putByte("ultrawarm", (byte) 0);
|
||||
overworld_caves.putByte("has_raids", (byte) 1);
|
||||
overworld_caves.putByte("respawn_anchor_works", (byte) 0);
|
||||
overworld_caves.putByte("bed_works", (byte) 1);
|
||||
overworld_caves.putByte("piglin_safe", (byte) 0);
|
||||
overworld_caves.putInt("logical_height", 256);
|
||||
overworld_caves.putString("infiniburn", "minecraft:infiniburn_overworld");
|
||||
|
||||
CompoundTag nether = new CompoundTag();
|
||||
nether.putString("name", "minecraft:the_nether");
|
||||
nether.putByte("natural", (byte) 0);
|
||||
nether.putFloat("ambient_light", 0.1F);
|
||||
nether.putByte("has_ceiling", (byte) 1);
|
||||
nether.putByte("has_skylight", (byte) 0);
|
||||
nether.putLong("fixed_time", 18000);
|
||||
nether.putByte("shrunk", (byte) 1);
|
||||
nether.putByte("ultrawarm", (byte) 1);
|
||||
nether.putByte("has_raids", (byte) 0);
|
||||
nether.putByte("respawn_anchor_works", (byte) 1);
|
||||
nether.putByte("bed_works", (byte) 0);
|
||||
nether.putByte("piglin_safe", (byte) 1);
|
||||
nether.putInt("logical_height", 128);
|
||||
nether.putString("infiniburn", "minecraft:infiniburn_nether");
|
||||
|
||||
CompoundTag the_end = new CompoundTag();
|
||||
the_end.putString("name", "minecraft:the_end");
|
||||
the_end.putByte("natural", (byte) 0);
|
||||
the_end.putFloat("ambient_light", 0.0F);
|
||||
the_end.putByte("has_ceiling", (byte) 0);
|
||||
the_end.putByte("has_skylight", (byte) 0);
|
||||
the_end.putLong("fixed_time", 6000);
|
||||
the_end.putByte("shrunk", (byte) 0);
|
||||
the_end.putByte("ultrawarm", (byte) 0);
|
||||
the_end.putByte("has_raids", (byte) 1);
|
||||
the_end.putByte("respawn_anchor_works", (byte) 0);
|
||||
the_end.putByte("bed_works", (byte) 0);
|
||||
the_end.putByte("piglin_safe", (byte) 0);
|
||||
the_end.putInt("logical_height", 256);
|
||||
the_end.putString("infiniburn", "minecraft:infiniburn_end");
|
||||
|
||||
ListTag<CompoundTag> listtag = new ListTag<CompoundTag>(CompoundTag.class);
|
||||
listtag.add(overworld);
|
||||
listtag.add(overworld_caves);
|
||||
listtag.add(nether);
|
||||
listtag.add(the_end);
|
||||
|
||||
CompoundTag dimensionTag = new CompoundTag();
|
||||
dimensionTag.put("dimension", listtag);
|
||||
|
||||
defaultTag = dimensionTag;
|
||||
try {
|
||||
JSONObject json = (JSONObject) new JSONParser().parse(new FileReader(reg));
|
||||
CompoundTag tag = CustomNBTUtils.getCompoundTagFromJson((JSONObject) json.get("value"));
|
||||
defaultTag = tag;
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static CompoundTag getCodec() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.loohp.limbo.Utils;
|
||||
package com.loohp.limbo.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
|
@ -17,13 +17,13 @@ import com.loohp.limbo.Limbo;
|
|||
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
|
||||
public class GeneratedDataUtils {
|
||||
public class GeneratedBlockDataMappings {
|
||||
|
||||
private static JSONObject globalPalette = new JSONObject();
|
||||
|
||||
static {
|
||||
String block = "blocks.json";
|
||||
File file = new File(block);
|
||||
File file = new File(Limbo.getInstance().getInternalDataFolder(), block);
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(block)) {
|
||||
Files.copy(in, file.toPath());
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -21,22 +21,22 @@
|
|||
"0x06": "PacketPlayInTabComplete"
|
||||
},
|
||||
"PlayOut": {
|
||||
"PacketPlayOutLogin": "0x25",
|
||||
"PacketPlayOutPositionAndLook": "0x35",
|
||||
"PacketPlayOutLogin": "0x24",
|
||||
"PacketPlayOutPositionAndLook": "0x34",
|
||||
"PacketPlayOutSpawnPosition": "0x42",
|
||||
"PacketPlayOutChat": "0x0E",
|
||||
"PacketPlayOutPlayerAbilities": "0x31",
|
||||
"PacketPlayOutMapChunk": "0x21",
|
||||
"PacketPlayOutKeepAlive": "0x20",
|
||||
"PacketPlayOutPlayerInfo": "0x33",
|
||||
"PacketPlayOutPlayerAbilities": "0x30",
|
||||
"PacketPlayOutMapChunk": "0x20",
|
||||
"PacketPlayOutKeepAlive": "0x1F",
|
||||
"PacketPlayOutPlayerInfo": "0x32",
|
||||
"PacketPlayOutUpdateViewPosition": "0x40",
|
||||
"PacketPlayOutShowPlayerSkins": "0x44",
|
||||
"PacketPlayOutDisconnect": "0x1A",
|
||||
"PacketPlayOutDisconnect": "0x19",
|
||||
"PacketPlayOutPluginMessaging": "0x17",
|
||||
"PacketPlayOutTabComplete": "0x10",
|
||||
"PacketPlayOutDeclareCommands": "0x11",
|
||||
"PacketPlayOutRespawn": "0x3A",
|
||||
"PacketPlayOutGameState": "0x1E"
|
||||
"PacketPlayOutTabComplete": "0x0F",
|
||||
"PacketPlayOutDeclareCommands": "0x10",
|
||||
"PacketPlayOutRespawn": "0x39",
|
||||
"PacketPlayOutGameState": "0x1D"
|
||||
},
|
||||
"StatusIn": {
|
||||
"0x01": "PacketStatusInPing",
|
||||
|
|
|
|||
Loading…
Reference in New Issue