mirror of https://github.com/LOOHP/Limbo.git
style: fix formatting
This commit is contained in:
parent
f48c48e6e5
commit
342404f586
|
|
@ -98,129 +98,130 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class Limbo {
|
public final class Limbo {
|
||||||
|
|
||||||
public static final String LIMBO_BRAND = "Limbo";
|
public static final String LIMBO_BRAND = "Limbo";
|
||||||
|
|
||||||
private static Limbo instance;
|
private static Limbo instance;
|
||||||
public static boolean noGui = false;
|
public static boolean noGui = false;
|
||||||
|
|
||||||
public static void main(String args[]) throws IOException, ParseException, NumberFormatException, ClassNotFoundException, InterruptedException {
|
public static void main(String args[]) throws IOException, ParseException, NumberFormatException, ClassNotFoundException, InterruptedException {
|
||||||
for (String flag : args) {
|
for (String flag : args) {
|
||||||
if (flag.equals("--nogui") || flag.equals("nogui")) {
|
if (flag.equals("--nogui") || flag.equals("nogui")) {
|
||||||
noGui = true;
|
noGui = true;
|
||||||
} else if (flag.equals("--help")) {
|
} else if (flag.equals("--help")) {
|
||||||
System.out.println("Accepted flags:");
|
System.out.println("Accepted flags:");
|
||||||
System.out.println(" --nogui <- Disable the GUI");
|
System.out.println(" --nogui <- Disable the GUI");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Unknown flag: \"" + flag + "\". Ignoring...");
|
System.out.println("Unknown flag: \"" + flag + "\". Ignoring...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GraphicsEnvironment.isHeadless()) {
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
noGui = true;
|
noGui = true;
|
||||||
}
|
}
|
||||||
if (!noGui) {
|
if (!noGui) {
|
||||||
System.out.println("Launching Server GUI.. Add \"--nogui\" in launch arguments to disable");
|
System.out.println("Launching Server GUI.. Add \"--nogui\" in launch arguments to disable");
|
||||||
Thread t1 = new Thread(() -> {
|
Thread t1 = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
GUI.main();
|
GUI.main();
|
||||||
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException |
|
||||||
e.printStackTrace();
|
IllegalAccessException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
});
|
}
|
||||||
t1.start();
|
});
|
||||||
}
|
t1.start();
|
||||||
|
}
|
||||||
|
|
||||||
new Limbo();
|
new Limbo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Limbo getInstance() {
|
public static Limbo getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================
|
//===========================
|
||||||
|
|
||||||
public final String SERVER_IMPLEMENTATION_VERSION = "1.20.4";
|
public final String SERVER_IMPLEMENTATION_VERSION = "1.20.4";
|
||||||
public final int SERVER_IMPLEMENTATION_PROTOCOL = 765;
|
public final int SERVER_IMPLEMENTATION_PROTOCOL = 765;
|
||||||
public final String LIMBO_IMPLEMENTATION_VERSION;
|
public final String LIMBO_IMPLEMENTATION_VERSION;
|
||||||
|
|
||||||
private final AtomicBoolean isRunning;
|
private final AtomicBoolean isRunning;
|
||||||
|
|
||||||
private final ServerConnection server;
|
private final ServerConnection server;
|
||||||
private final Console console;
|
private final Console console;
|
||||||
|
|
||||||
private final List<World> worlds = new CopyOnWriteArrayList<>();
|
private final List<World> worlds = new CopyOnWriteArrayList<>();
|
||||||
final Map<String, Player> playersByName = new ConcurrentHashMap<>();
|
final Map<String, Player> playersByName = new ConcurrentHashMap<>();
|
||||||
final Map<UUID, Player> playersByUUID = new ConcurrentHashMap<>();
|
final Map<UUID, Player> playersByUUID = new ConcurrentHashMap<>();
|
||||||
private final Map<Key, KeyedBossBar> bossBars = new ConcurrentHashMap<>();
|
private final Map<Key, KeyedBossBar> bossBars = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final ServerProperties properties;
|
private final ServerProperties properties;
|
||||||
|
|
||||||
private final PluginManager pluginManager;
|
private final PluginManager pluginManager;
|
||||||
private final EventsManager eventsManager;
|
private final EventsManager eventsManager;
|
||||||
private final PermissionsManager permissionManager;
|
private final PermissionsManager permissionManager;
|
||||||
private final File pluginFolder;
|
private final File pluginFolder;
|
||||||
|
|
||||||
private final File internalDataFolder;
|
private final File internalDataFolder;
|
||||||
|
|
||||||
private final DimensionRegistry dimensionRegistry;
|
private final DimensionRegistry dimensionRegistry;
|
||||||
|
|
||||||
private final Tick tick;
|
private final Tick tick;
|
||||||
private final LimboScheduler scheduler;
|
private final LimboScheduler scheduler;
|
||||||
|
|
||||||
private final Metrics metrics;
|
private final Metrics metrics;
|
||||||
|
|
||||||
public final AtomicInteger entityIdCount = new AtomicInteger();
|
public final AtomicInteger entityIdCount = new AtomicInteger();
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private Unsafe unsafe;
|
private Unsafe unsafe;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Limbo() throws IOException, ParseException, NumberFormatException, ClassNotFoundException, InterruptedException {
|
public Limbo() throws IOException, ParseException, NumberFormatException, ClassNotFoundException, InterruptedException {
|
||||||
instance = this;
|
instance = this;
|
||||||
unsafe = new Unsafe(this);
|
unsafe = new Unsafe(this);
|
||||||
isRunning = new AtomicBoolean(true);
|
isRunning = new AtomicBoolean(true);
|
||||||
|
|
||||||
if (!noGui) {
|
if (!noGui) {
|
||||||
while (!GUI.loadFinish) {
|
while (!GUI.loadFinish) {
|
||||||
TimeUnit.MILLISECONDS.sleep(500);
|
TimeUnit.MILLISECONDS.sleep(500);
|
||||||
}
|
}
|
||||||
console = new Console(null, System.out, System.err);
|
console = new Console(null, System.out, System.err);
|
||||||
} else {
|
} else {
|
||||||
console = new Console(System.in, System.out, System.err);
|
console = new Console(System.in, System.out, System.err);
|
||||||
}
|
}
|
||||||
|
|
||||||
LIMBO_IMPLEMENTATION_VERSION = getLimboVersion();
|
LIMBO_IMPLEMENTATION_VERSION = getLimboVersion();
|
||||||
console.sendMessage("Loading Limbo Version " + LIMBO_IMPLEMENTATION_VERSION + " on Minecraft " + SERVER_IMPLEMENTATION_VERSION);
|
console.sendMessage("Loading Limbo Version " + LIMBO_IMPLEMENTATION_VERSION + " on Minecraft " + SERVER_IMPLEMENTATION_VERSION);
|
||||||
|
|
||||||
String spName = "server.properties";
|
String spName = "server.properties";
|
||||||
File sp = new File(spName);
|
File sp = new File(spName);
|
||||||
if (!sp.exists()) {
|
if (!sp.exists()) {
|
||||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream(spName)) {
|
try (InputStream in = getClass().getClassLoader().getResourceAsStream(spName)) {
|
||||||
Files.copy(in, sp.toPath());
|
Files.copy(in, sp.toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
properties = new ServerProperties(sp);
|
properties = new ServerProperties(sp);
|
||||||
|
|
||||||
if (!properties.isBungeecord()) {
|
if (!properties.isBungeecord()) {
|
||||||
console.sendMessage("If you are using bungeecord, consider turning that on in the settings!");
|
console.sendMessage("If you are using bungeecord, consider turning that on in the settings!");
|
||||||
} else {
|
} else {
|
||||||
console.sendMessage("Starting Limbo server in bungeecord mode!");
|
console.sendMessage("Starting Limbo server in bungeecord mode!");
|
||||||
}
|
}
|
||||||
|
|
||||||
internalDataFolder = new File("internal_data");
|
internalDataFolder = new File("internal_data");
|
||||||
if (!internalDataFolder.exists()) {
|
if (!internalDataFolder.exists()) {
|
||||||
internalDataFolder.mkdirs();
|
internalDataFolder.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.sendMessage("Loading packet id mappings from mapping.json ...");
|
console.sendMessage("Loading packet id mappings from mapping.json ...");
|
||||||
|
|
||||||
InputStream mappingStream = getClass().getClassLoader().getResourceAsStream("mapping.json");
|
InputStream mappingStream = getClass().getClassLoader().getResourceAsStream("mapping.json");
|
||||||
if (mappingStream == null) {
|
if (mappingStream == null) {
|
||||||
console.sendMessage("Failed to load mapping.json from jar!");
|
console.sendMessage("Failed to load mapping.json from jar!");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStreamReader reader = new InputStreamReader(mappingStream, StandardCharsets.UTF_8);
|
InputStreamReader reader = new InputStreamReader(mappingStream, StandardCharsets.UTF_8);
|
||||||
JSONObject json = (JSONObject) new JSONParser().parse(reader);
|
JSONObject json = (JSONObject) new JSONParser().parse(reader);
|
||||||
|
|
@ -229,107 +230,107 @@ public final class Limbo {
|
||||||
String classPrefix = Packet.class.getName().substring(0, Packet.class.getName().lastIndexOf(".") + 1);
|
String classPrefix = Packet.class.getName().substring(0, Packet.class.getName().lastIndexOf(".") + 1);
|
||||||
int mappingsCount = 0;
|
int mappingsCount = 0;
|
||||||
|
|
||||||
Map<Integer, Class<? extends PacketIn>> HandshakeIn = new HashMap<>();
|
Map<Integer, Class<? extends PacketIn>> HandshakeIn = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("HandshakeIn")).keySet()) {
|
for (Object key : ((JSONObject) json.get("HandshakeIn")).keySet()) {
|
||||||
int packetId = Integer.decode((String) key);
|
int packetId = Integer.decode((String) key);
|
||||||
HandshakeIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("HandshakeIn")).get(key)));
|
HandshakeIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("HandshakeIn")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setHandshakeIn(HandshakeIn);
|
Packet.setHandshakeIn(HandshakeIn);
|
||||||
mappingsCount += HandshakeIn.size();
|
mappingsCount += HandshakeIn.size();
|
||||||
|
|
||||||
Map<Integer, Class<? extends PacketIn>> StatusIn = new HashMap<>();
|
Map<Integer, Class<? extends PacketIn>> StatusIn = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("StatusIn")).keySet()) {
|
for (Object key : ((JSONObject) json.get("StatusIn")).keySet()) {
|
||||||
int packetId = Integer.decode((String) key);
|
int packetId = Integer.decode((String) key);
|
||||||
StatusIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("StatusIn")).get(key)));
|
StatusIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("StatusIn")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setStatusIn(StatusIn);
|
Packet.setStatusIn(StatusIn);
|
||||||
mappingsCount += StatusIn.size();
|
mappingsCount += StatusIn.size();
|
||||||
|
|
||||||
Map<Class<? extends PacketOut>, Integer> StatusOut = new HashMap<>();
|
Map<Class<? extends PacketOut>, Integer> StatusOut = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("StatusOut")).keySet()) {
|
for (Object key : ((JSONObject) json.get("StatusOut")).keySet()) {
|
||||||
Class<? extends PacketOut> packetClass = (Class<? extends PacketOut>) Class.forName(classPrefix + key);
|
Class<? extends PacketOut> packetClass = (Class<? extends PacketOut>) Class.forName(classPrefix + key);
|
||||||
StatusOut.put(packetClass, Integer.decode((String) ((JSONObject) json.get("StatusOut")).get(key)));
|
StatusOut.put(packetClass, Integer.decode((String) ((JSONObject) json.get("StatusOut")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setStatusOut(StatusOut);
|
Packet.setStatusOut(StatusOut);
|
||||||
mappingsCount += StatusOut.size();
|
mappingsCount += StatusOut.size();
|
||||||
|
|
||||||
Map<Integer, Class<? extends PacketIn>> LoginIn = new HashMap<>();
|
Map<Integer, Class<? extends PacketIn>> LoginIn = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("LoginIn")).keySet()) {
|
for (Object key : ((JSONObject) json.get("LoginIn")).keySet()) {
|
||||||
int packetId = Integer.decode((String) key);
|
int packetId = Integer.decode((String) key);
|
||||||
LoginIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("LoginIn")).get(key)));
|
LoginIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("LoginIn")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setLoginIn(LoginIn);
|
Packet.setLoginIn(LoginIn);
|
||||||
mappingsCount += LoginIn.size();
|
mappingsCount += LoginIn.size();
|
||||||
|
|
||||||
Map<Class<? extends PacketOut>, Integer> LoginOut = new HashMap<>();
|
Map<Class<? extends PacketOut>, Integer> LoginOut = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("LoginOut")).keySet()) {
|
for (Object key : ((JSONObject) json.get("LoginOut")).keySet()) {
|
||||||
Class<? extends PacketOut> packetClass = (Class<? extends PacketOut>) Class.forName(classPrefix + key);
|
Class<? extends PacketOut> packetClass = (Class<? extends PacketOut>) Class.forName(classPrefix + key);
|
||||||
LoginOut.put(packetClass, Integer.decode((String) ((JSONObject) json.get("LoginOut")).get(key)));
|
LoginOut.put(packetClass, Integer.decode((String) ((JSONObject) json.get("LoginOut")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setLoginOut(LoginOut);
|
Packet.setLoginOut(LoginOut);
|
||||||
mappingsCount += LoginOut.size();
|
mappingsCount += LoginOut.size();
|
||||||
|
|
||||||
Map<Integer, Class<? extends PacketIn>> ConfigurationIn = new HashMap<>();
|
Map<Integer, Class<? extends PacketIn>> ConfigurationIn = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("ConfigurationIn")).keySet()) {
|
for (Object key : ((JSONObject) json.get("ConfigurationIn")).keySet()) {
|
||||||
int packetId = Integer.decode((String) key);
|
int packetId = Integer.decode((String) key);
|
||||||
ConfigurationIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("ConfigurationIn")).get(key)));
|
ConfigurationIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("ConfigurationIn")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setConfigurationIn(ConfigurationIn);
|
Packet.setConfigurationIn(ConfigurationIn);
|
||||||
mappingsCount += ConfigurationIn.size();
|
mappingsCount += ConfigurationIn.size();
|
||||||
|
|
||||||
Map<Class<? extends PacketOut>, Integer> ConfigurationOut = new HashMap<>();
|
Map<Class<? extends PacketOut>, Integer> ConfigurationOut = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("ConfigurationOut")).keySet()) {
|
for (Object key : ((JSONObject) json.get("ConfigurationOut")).keySet()) {
|
||||||
Class<? extends PacketOut> packetClass = (Class<? extends PacketOut>) Class.forName(classPrefix + key);
|
Class<? extends PacketOut> packetClass = (Class<? extends PacketOut>) Class.forName(classPrefix + key);
|
||||||
ConfigurationOut.put(packetClass, Integer.decode((String) ((JSONObject) json.get("ConfigurationOut")).get(key)));
|
ConfigurationOut.put(packetClass, Integer.decode((String) ((JSONObject) json.get("ConfigurationOut")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setConfigurationOut(ConfigurationOut);
|
Packet.setConfigurationOut(ConfigurationOut);
|
||||||
mappingsCount += ConfigurationOut.size();
|
mappingsCount += ConfigurationOut.size();
|
||||||
|
|
||||||
Map<Integer, Class<? extends PacketIn>> PlayIn = new HashMap<>();
|
Map<Integer, Class<? extends PacketIn>> PlayIn = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("PlayIn")).keySet()) {
|
for (Object key : ((JSONObject) json.get("PlayIn")).keySet()) {
|
||||||
int packetId = Integer.decode((String) key);
|
int packetId = Integer.decode((String) key);
|
||||||
PlayIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("PlayIn")).get(key)));
|
PlayIn.put(packetId, (Class<? extends PacketIn>) Class.forName(classPrefix + ((JSONObject) json.get("PlayIn")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setPlayIn(PlayIn);
|
Packet.setPlayIn(PlayIn);
|
||||||
mappingsCount += PlayIn.size();
|
mappingsCount += PlayIn.size();
|
||||||
|
|
||||||
Map<Class<? extends PacketOut>, Integer> PlayOut = new HashMap<>();
|
Map<Class<? extends PacketOut>, Integer> PlayOut = new HashMap<>();
|
||||||
for (Object key : ((JSONObject) json.get("PlayOut")).keySet()) {
|
for (Object key : ((JSONObject) json.get("PlayOut")).keySet()) {
|
||||||
Class<? extends PacketOut> packetClass = (Class<? extends PacketOut>) Class.forName(classPrefix + key);
|
Class<? extends PacketOut> packetClass = (Class<? extends PacketOut>) Class.forName(classPrefix + key);
|
||||||
PlayOut.put(packetClass, Integer.decode((String) ((JSONObject) json.get("PlayOut")).get(key)));
|
PlayOut.put(packetClass, Integer.decode((String) ((JSONObject) json.get("PlayOut")).get(key)));
|
||||||
}
|
}
|
||||||
Packet.setPlayOut(PlayOut);
|
Packet.setPlayOut(PlayOut);
|
||||||
mappingsCount += PlayOut.size();
|
mappingsCount += PlayOut.size();
|
||||||
|
|
||||||
console.sendMessage("Loaded all " + mappingsCount + " packet id mappings!");
|
console.sendMessage("Loaded all " + mappingsCount + " packet id mappings!");
|
||||||
|
|
||||||
dimensionRegistry = new DimensionRegistry();
|
dimensionRegistry = new DimensionRegistry();
|
||||||
|
|
||||||
worlds.add(loadDefaultWorld());
|
worlds.add(loadDefaultWorld());
|
||||||
Location spawn = properties.getWorldSpawn();
|
Location spawn = properties.getWorldSpawn();
|
||||||
properties.setWorldSpawn(new Location(getWorld(properties.getLevelName().value()), spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getYaw(), spawn.getPitch()));
|
properties.setWorldSpawn(new Location(getWorld(properties.getLevelName().value()), spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getYaw(), spawn.getPitch()));
|
||||||
|
|
||||||
if (!NetworkUtils.available(properties.getServerPort())) {
|
if (!NetworkUtils.available(properties.getServerPort())) {
|
||||||
console.sendMessage("");
|
console.sendMessage("");
|
||||||
console.sendMessage("*****FAILED TO BIND PORT [" + properties.getServerPort() + "]*****");
|
console.sendMessage("*****FAILED TO BIND PORT [" + properties.getServerPort() + "]*****");
|
||||||
console.sendMessage("*****PORT ALREADY IN USE*****");
|
console.sendMessage("*****PORT ALREADY IN USE*****");
|
||||||
console.sendMessage("*****PERHAPS ANOTHER INSTANCE OF THE SERVER IS ALREADY RUNNING?*****");
|
console.sendMessage("*****PERHAPS ANOTHER INSTANCE OF THE SERVER IS ALREADY RUNNING?*****");
|
||||||
console.sendMessage("");
|
console.sendMessage("");
|
||||||
System.exit(2);
|
System.exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
String permissionName = "permission.yml";
|
String permissionName = "permission.yml";
|
||||||
File permissionFile = new File(permissionName);
|
File permissionFile = new File(permissionName);
|
||||||
if (!permissionFile.exists()) {
|
if (!permissionFile.exists()) {
|
||||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream(permissionName)) {
|
try (InputStream in = getClass().getClassLoader().getResourceAsStream(permissionName)) {
|
||||||
Files.copy(in, permissionFile.toPath());
|
Files.copy(in, permissionFile.toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduler = new LimboScheduler();
|
scheduler = new LimboScheduler();
|
||||||
tick = new Tick(this);
|
tick = new Tick(this);
|
||||||
|
|
||||||
permissionManager = new PermissionsManager();
|
permissionManager = new PermissionsManager();
|
||||||
permissionManager.loadDefaultPermissionFile(permissionFile);
|
permissionManager.loadDefaultPermissionFile(permissionFile);
|
||||||
|
|
@ -339,323 +340,324 @@ public final class Limbo {
|
||||||
pluginFolder = new File("plugins");
|
pluginFolder = new File("plugins");
|
||||||
pluginFolder.mkdirs();
|
pluginFolder.mkdirs();
|
||||||
|
|
||||||
pluginManager = new PluginManager(new DefaultCommands(), pluginFolder);
|
pluginManager = new PluginManager(new DefaultCommands(), pluginFolder);
|
||||||
try {
|
try {
|
||||||
Method loadPluginsMethod = PluginManager.class.getDeclaredMethod("loadPlugins");
|
Method loadPluginsMethod = PluginManager.class.getDeclaredMethod("loadPlugins");
|
||||||
loadPluginsMethod.setAccessible(true);
|
loadPluginsMethod.setAccessible(true);
|
||||||
loadPluginsMethod.invoke(pluginManager);
|
loadPluginsMethod.invoke(pluginManager);
|
||||||
loadPluginsMethod.setAccessible(false);
|
loadPluginsMethod.setAccessible(false);
|
||||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException |
|
||||||
e.printStackTrace();
|
InvocationTargetException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
for (LimboPlugin plugin : Limbo.getInstance().getPluginManager().getPlugins()) {
|
for (LimboPlugin plugin : Limbo.getInstance().getPluginManager().getPlugins()) {
|
||||||
try {
|
try {
|
||||||
console.sendMessage("Enabling plugin " + plugin.getName() + " " + plugin.getInfo().getVersion());
|
console.sendMessage("Enabling plugin " + plugin.getName() + " " + plugin.getInfo().getVersion());
|
||||||
plugin.onEnable();
|
plugin.onEnable();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
new RuntimeException("Error while enabling " + plugin.getName() + " " + plugin.getInfo().getVersion(), e).printStackTrace();
|
new RuntimeException("Error while enabling " + plugin.getName() + " " + plugin.getInfo().getVersion(), e).printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server = new ServerConnection(properties.getServerIp(), properties.getServerPort());
|
server = new ServerConnection(properties.getServerIp(), properties.getServerPort());
|
||||||
|
|
||||||
metrics = new Metrics();
|
metrics = new Metrics();
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
Limbo.getInstance().terminate();
|
Limbo.getInstance().terminate();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.run();
|
console.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Unsafe getUnsafe() {
|
public Unsafe getUnsafe() {
|
||||||
return unsafe;
|
return unsafe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tick getHeartBeat() {
|
public Tick getHeartBeat() {
|
||||||
return tick;
|
return tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LimboScheduler getScheduler() {
|
public LimboScheduler getScheduler() {
|
||||||
return scheduler;
|
return scheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DimensionRegistry getDimensionRegistry() {
|
public DimensionRegistry getDimensionRegistry() {
|
||||||
return dimensionRegistry;
|
return dimensionRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionsManager getPermissionsManager() {
|
public PermissionsManager getPermissionsManager() {
|
||||||
return permissionManager;
|
return permissionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getInternalDataFolder() {
|
public File getInternalDataFolder() {
|
||||||
return internalDataFolder;
|
return internalDataFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventsManager getEventsManager() {
|
public EventsManager getEventsManager() {
|
||||||
return eventsManager;
|
return eventsManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getPluginFolder() {
|
public File getPluginFolder() {
|
||||||
return pluginFolder;
|
return pluginFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginManager getPluginManager() {
|
public PluginManager getPluginManager() {
|
||||||
return pluginManager;
|
return pluginManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private World loadDefaultWorld() throws IOException {
|
private World loadDefaultWorld() throws IOException {
|
||||||
console.sendMessage("Loading world " + properties.getLevelName() + " with the schematic file " + properties.getSchemFileName() + " ...");
|
console.sendMessage("Loading world " + properties.getLevelName() + " with the schematic file " + properties.getSchemFileName() + " ...");
|
||||||
|
|
||||||
File schem = new File(properties.getSchemFileName());
|
File schem = new File(properties.getSchemFileName());
|
||||||
|
|
||||||
if (!schem.exists()) {
|
if (!schem.exists()) {
|
||||||
console.sendMessage("Schemetic file " + properties.getSchemFileName() + " for world " + properties.getLevelName() + " not found!");
|
console.sendMessage("Schemetic file " + properties.getSchemFileName() + " for world " + properties.getLevelName() + " not found!");
|
||||||
console.sendMessage("Creating default world...");
|
console.sendMessage("Creating default world...");
|
||||||
try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream("spawn.schem")) {
|
try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream("spawn.schem")) {
|
||||||
Files.copy(in, schem.toPath());
|
Files.copy(in, schem.toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
World world = Schematic.toWorld(properties.getLevelName().value(), Environment.fromKey(properties.getLevelDimension()), (CompoundTag) NBTUtil.read(schem).getTag());
|
World world = Schematic.toWorld(properties.getLevelName().value(), Environment.fromKey(properties.getLevelDimension()), (CompoundTag) NBTUtil.read(schem).getTag());
|
||||||
console.sendMessage("Loaded world " + properties.getLevelName() + "!");
|
console.sendMessage("Loaded world " + properties.getLevelName() + "!");
|
||||||
return world;
|
return world;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
console.sendMessage("Unable to load world " + properties.getSchemFileName() + "!");
|
console.sendMessage("Unable to load world " + properties.getSchemFileName() + "!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
console.sendMessage("Server will exit!");
|
console.sendMessage("Server will exit!");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerWorld(World world) {
|
public void registerWorld(World world) {
|
||||||
if (!worlds.contains(world)) {
|
if (!worlds.contains(world)) {
|
||||||
worlds.add(world);
|
worlds.add(world);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("World already registered");
|
throw new RuntimeException("World already registered");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterWorld(World world) {
|
public void unregisterWorld(World world) {
|
||||||
if (worlds.indexOf(world) == 0) {
|
if (worlds.indexOf(world) == 0) {
|
||||||
throw new RuntimeException("World already registered");
|
throw new RuntimeException("World already registered");
|
||||||
} else if (!worlds.contains(world)) {
|
} else if (!worlds.contains(world)) {
|
||||||
throw new RuntimeException("World not registered");
|
throw new RuntimeException("World not registered");
|
||||||
} else {
|
} else {
|
||||||
for (Player player : world.getPlayers()) {
|
for (Player player : world.getPlayers()) {
|
||||||
player.teleport(properties.getWorldSpawn());
|
player.teleport(properties.getWorldSpawn());
|
||||||
}
|
}
|
||||||
worlds.remove(world);
|
worlds.remove(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyedBossBar createBossBar(Key Key, Component name, float progress, BossBar.Color color, BossBar.Overlay overlay, BossBar.Flag... flags) {
|
public KeyedBossBar createBossBar(Key Key, Component name, float progress, BossBar.Color color, BossBar.Overlay overlay, BossBar.Flag... flags) {
|
||||||
KeyedBossBar keyedBossBar = com.loohp.limbo.bossbar.Unsafe.a(Key, BossBar.bossBar(name, progress, color, overlay, new HashSet<>(Arrays.asList(flags))));
|
KeyedBossBar keyedBossBar = com.loohp.limbo.bossbar.Unsafe.a(Key, BossBar.bossBar(name, progress, color, overlay, new HashSet<>(Arrays.asList(flags))));
|
||||||
bossBars.put(Key, keyedBossBar);
|
bossBars.put(Key, keyedBossBar);
|
||||||
return keyedBossBar;
|
return keyedBossBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeBossBar(Key Key) {
|
public void removeBossBar(Key Key) {
|
||||||
KeyedBossBar keyedBossBar = bossBars.remove(Key);
|
KeyedBossBar keyedBossBar = bossBars.remove(Key);
|
||||||
keyedBossBar.getProperties().removeListener(keyedBossBar.getUnsafe().a());
|
keyedBossBar.getProperties().removeListener(keyedBossBar.getUnsafe().a());
|
||||||
keyedBossBar.getUnsafe().b();
|
keyedBossBar.getUnsafe().b();
|
||||||
PacketPlayOutBoss packetPlayOutBoss = new PacketPlayOutBoss(keyedBossBar, PacketPlayOutBoss.BossBarAction.REMOVE);
|
PacketPlayOutBoss packetPlayOutBoss = new PacketPlayOutBoss(keyedBossBar, PacketPlayOutBoss.BossBarAction.REMOVE);
|
||||||
for (Player player : keyedBossBar.getPlayers()) {
|
for (Player player : keyedBossBar.getPlayers()) {
|
||||||
try {
|
try {
|
||||||
player.clientConnection.sendPacket(packetPlayOutBoss);
|
player.clientConnection.sendPacket(packetPlayOutBoss);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Key, KeyedBossBar> getBossBars() {
|
public Map<Key, KeyedBossBar> getBossBars() {
|
||||||
return Collections.unmodifiableMap(bossBars);
|
return Collections.unmodifiableMap(bossBars);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerProperties getServerProperties() {
|
public ServerProperties getServerProperties() {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerConnection getServerConnection() {
|
public ServerConnection getServerConnection() {
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Console getConsole() {
|
public Console getConsole() {
|
||||||
return console;
|
return console;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Metrics getMetrics() {
|
public Metrics getMetrics() {
|
||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Player> getPlayers() {
|
public Set<Player> getPlayers() {
|
||||||
return new HashSet<>(playersByUUID.values());
|
return new HashSet<>(playersByUUID.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer(String name) {
|
public Player getPlayer(String name) {
|
||||||
return playersByName.get(name);
|
return playersByName.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer(UUID uuid) {
|
public Player getPlayer(UUID uuid) {
|
||||||
return playersByUUID.get(uuid);
|
return playersByUUID.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<World> getWorlds() {
|
public List<World> getWorlds() {
|
||||||
return new ArrayList<>(worlds);
|
return new ArrayList<>(worlds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld(String name) {
|
public World getWorld(String name) {
|
||||||
for (World world : worlds) {
|
for (World world : worlds) {
|
||||||
if (world.getName().equalsIgnoreCase(name)) {
|
if (world.getName().equalsIgnoreCase(name)) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public String buildServerListResponseJson(String version, int protocol, Component motd, int maxPlayers, int playersOnline, BufferedImage favicon) throws IOException {
|
public String buildServerListResponseJson(String version, int protocol, Component motd, int maxPlayers, int playersOnline, BufferedImage favicon) throws IOException {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
JSONObject versionJson = new JSONObject();
|
JSONObject versionJson = new JSONObject();
|
||||||
versionJson.put("name", version);
|
versionJson.put("name", version);
|
||||||
versionJson.put("protocol", protocol);
|
versionJson.put("protocol", protocol);
|
||||||
json.put("version", versionJson);
|
json.put("version", versionJson);
|
||||||
|
|
||||||
JSONObject playersJson = new JSONObject();
|
JSONObject playersJson = new JSONObject();
|
||||||
playersJson.put("max", maxPlayers);
|
playersJson.put("max", maxPlayers);
|
||||||
playersJson.put("online", playersOnline);
|
playersJson.put("online", playersOnline);
|
||||||
json.put("players", playersJson);
|
json.put("players", playersJson);
|
||||||
|
|
||||||
json.put("description", "%MOTD%");
|
json.put("description", "%MOTD%");
|
||||||
|
|
||||||
if (favicon != null) {
|
if (favicon != null) {
|
||||||
if (favicon.getWidth() == 64 && favicon.getHeight() == 64) {
|
if (favicon.getWidth() == 64 && favicon.getHeight() == 64) {
|
||||||
String base64 = "data:image/png;base64," + ImageUtils.imgToBase64String(favicon, "png");
|
String base64 = "data:image/png;base64," + ImageUtils.imgToBase64String(favicon, "png");
|
||||||
json.put("favicon", base64);
|
json.put("favicon", base64);
|
||||||
} else {
|
} else {
|
||||||
console.sendMessage("Server List Favicon must be 64 x 64 in size!");
|
console.sendMessage("Server List Favicon must be 64 x 64 in size!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject modInfoJson = new JSONObject();
|
JSONObject modInfoJson = new JSONObject();
|
||||||
modInfoJson.put("type", "FML");
|
modInfoJson.put("type", "FML");
|
||||||
modInfoJson.put("modList", new JSONArray());
|
modInfoJson.put("modList", new JSONArray());
|
||||||
json.put("modinfo", modInfoJson);
|
json.put("modinfo", modInfoJson);
|
||||||
|
|
||||||
|
|
||||||
TreeMap<String, Object> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
TreeMap<String, Object> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
treeMap.putAll(json);
|
treeMap.putAll(json);
|
||||||
|
|
||||||
Gson g = new GsonBuilder().create();
|
Gson g = new GsonBuilder().create();
|
||||||
|
|
||||||
return g.toJson(treeMap).replace("\"%MOTD%\"", GsonComponentSerializer.gson().serialize(motd));
|
return g.toJson(treeMap).replace("\"%MOTD%\"", GsonComponentSerializer.gson().serialize(motd));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String buildLegacyPingResponse(String version, Component motd, int maxPlayers, int playersOnline) {
|
public String buildLegacyPingResponse(String version, Component motd, int maxPlayers, int playersOnline) {
|
||||||
String begin = "<EFBFBD>1";
|
String begin = "<EFBFBD>1";
|
||||||
return String.join("\00", begin, "127", version, String.join("", Arrays.asList(motd).stream().map(each -> LegacyComponentSerializer.legacySection().serialize(each)).collect(Collectors.toList())), String.valueOf(playersOnline), String.valueOf(maxPlayers));
|
return String.join("\00", begin, "127", version, String.join("", Arrays.asList(motd).stream().map(each -> LegacyComponentSerializer.legacySection().serialize(each)).collect(Collectors.toList())), String.valueOf(playersOnline), String.valueOf(maxPlayers));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void terminate() {
|
protected void terminate() {
|
||||||
isRunning.set(false);
|
isRunning.set(false);
|
||||||
console.sendMessage("Stopping Server...");
|
console.sendMessage("Stopping Server...");
|
||||||
|
|
||||||
for (LimboPlugin plugin : Limbo.getInstance().getPluginManager().getPlugins()) {
|
for (LimboPlugin plugin : Limbo.getInstance().getPluginManager().getPlugins()) {
|
||||||
try {
|
try {
|
||||||
console.sendMessage("Disabling plugin " + plugin.getName() + " " + plugin.getInfo().getVersion());
|
console.sendMessage("Disabling plugin " + plugin.getName() + " " + plugin.getInfo().getVersion());
|
||||||
plugin.onDisable();
|
plugin.onDisable();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
new RuntimeException("Error while disabling " + plugin.getName() + " " + plugin.getInfo().getVersion(), e).printStackTrace();
|
new RuntimeException("Error while disabling " + plugin.getName() + " " + plugin.getInfo().getVersion(), e).printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tick.waitAndKillThreads(5000);
|
tick.waitAndKillThreads(5000);
|
||||||
|
|
||||||
for (Player player : getPlayers()) {
|
for (Player player : getPlayers()) {
|
||||||
player.disconnect("Server closed");
|
player.disconnect("Server closed");
|
||||||
}
|
}
|
||||||
while (!getPlayers().isEmpty()) {
|
while (!getPlayers().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
TimeUnit.MILLISECONDS.sleep(500);
|
TimeUnit.MILLISECONDS.sleep(500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.sendMessage("Server closed");
|
console.sendMessage("Server closed");
|
||||||
console.logs.close();
|
console.logs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopServer() {
|
public void stopServer() {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return isRunning.get();
|
return isRunning.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNextEntityId() {
|
public int getNextEntityId() {
|
||||||
return entityIdCount.getAndUpdate(i -> i == Integer.MAX_VALUE ? 0 : ++i);
|
return entityIdCount.getAndUpdate(i -> i == Integer.MAX_VALUE ? 0 : ++i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchCommand(CommandSender sender, String str) {
|
public void dispatchCommand(CommandSender sender, String str) {
|
||||||
String[] command;
|
String[] command;
|
||||||
if (str.startsWith("/")) {
|
if (str.startsWith("/")) {
|
||||||
command = CustomStringUtils.splitStringToArgs(str.substring(1));
|
command = CustomStringUtils.splitStringToArgs(str.substring(1));
|
||||||
} else {
|
} else {
|
||||||
command = CustomStringUtils.splitStringToArgs(str);
|
command = CustomStringUtils.splitStringToArgs(str);
|
||||||
}
|
}
|
||||||
dispatchCommand(sender, command);
|
dispatchCommand(sender, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchCommand(CommandSender sender, String... args) {
|
public void dispatchCommand(CommandSender sender, String... args) {
|
||||||
try {
|
try {
|
||||||
Limbo.getInstance().getPluginManager().fireExecutors(sender, args);
|
Limbo.getInstance().getPluginManager().fireExecutors(sender, args);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLimboVersion() throws IOException {
|
private String getLimboVersion() throws IOException {
|
||||||
Enumeration<URL> manifests = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
|
Enumeration<URL> manifests = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
|
||||||
while (manifests.hasMoreElements()) {
|
while (manifests.hasMoreElements()) {
|
||||||
URL url = manifests.nextElement();
|
URL url = manifests.nextElement();
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
|
||||||
Optional<String> line = br.lines().filter(each -> each.startsWith("Limbo-Version:")).findFirst();
|
Optional<String> line = br.lines().filter(each -> each.startsWith("Limbo-Version:")).findFirst();
|
||||||
if (line.isPresent()) {
|
if (line.isPresent()) {
|
||||||
return line.get().substring(14).trim();
|
return line.get().substring(14).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inventory createInventory(Component title, int slots, InventoryHolder holder) {
|
public Inventory createInventory(Component title, int slots, InventoryHolder holder) {
|
||||||
return CustomInventory.create(title, slots, holder);
|
return CustomInventory.create(title, slots, holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inventory createInventory(InventoryType type, InventoryHolder holder) {
|
public Inventory createInventory(InventoryType type, InventoryHolder holder) {
|
||||||
return createInventory(null, type, holder);
|
return createInventory(null, type, holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inventory createInventory(Component title, InventoryType type, InventoryHolder holder) {
|
public Inventory createInventory(Component title, InventoryType type, InventoryHolder holder) {
|
||||||
if (!type.isCreatable()) {
|
if (!type.isCreatable()) {
|
||||||
throw new UnsupportedOperationException("This InventoryType cannot be created.");
|
throw new UnsupportedOperationException("This InventoryType cannot be created.");
|
||||||
}
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ANVIL:
|
case ANVIL:
|
||||||
return new AnvilInventory(title, holder);
|
return new AnvilInventory(title, holder);
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("This InventoryType has not been implemented yet.");
|
throw new UnsupportedOperationException("This InventoryType has not been implemented yet.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,31 +25,31 @@ import java.io.IOException;
|
||||||
|
|
||||||
public class PacketPlayOutGameEvent extends PacketOut {
|
public class PacketPlayOutGameEvent extends PacketOut {
|
||||||
|
|
||||||
private byte event;
|
private byte event;
|
||||||
private float value;
|
private float value;
|
||||||
|
|
||||||
public PacketPlayOutGameEvent(byte event, float value) {
|
public PacketPlayOutGameEvent(byte event, float value) {
|
||||||
this.event = event;
|
this.event = event;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEvent() {
|
public int getEvent() {
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getValue() {
|
public float getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] serializePacket() throws IOException {
|
public byte[] serializePacket() throws IOException {
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
|
||||||
DataOutputStream output = new DataOutputStream(buffer);
|
DataOutputStream output = new DataOutputStream(buffer);
|
||||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||||
output.writeByte(Byte.toUnsignedInt(event));
|
output.writeByte(Byte.toUnsignedInt(event));
|
||||||
output.writeFloat(value);
|
output.writeFloat(value);
|
||||||
|
|
||||||
return buffer.toByteArray();
|
return buffer.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,26 +141,26 @@ public class PlayerInteractManager {
|
||||||
player.clientConnection.sendPacket(chunkBatchStartPacket);
|
player.clientConnection.sendPacket(chunkBatchStartPacket);
|
||||||
for (Entry<ChunkPosition, Chunk> entry : chunksInRange.entrySet()) {
|
for (Entry<ChunkPosition, Chunk> entry : chunksInRange.entrySet()) {
|
||||||
ChunkPosition chunkPos = entry.getKey();
|
ChunkPosition chunkPos = entry.getKey();
|
||||||
Chunk chunk = chunkPos.getWorld().getChunkAt(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
Chunk chunk = chunkPos.getWorld().getChunkAt(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
ClientboundLevelChunkWithLightPacket chunkdata = new ClientboundLevelChunkWithLightPacket(chunkPos.getChunkX(), chunkPos.getChunkZ(), entry.getValue(), world.getEnvironment(), Collections.emptyList(), Collections.emptyList());
|
ClientboundLevelChunkWithLightPacket chunkdata = new ClientboundLevelChunkWithLightPacket(chunkPos.getChunkX(), chunkPos.getChunkZ(), entry.getValue(), world.getEnvironment(), Collections.emptyList(), Collections.emptyList());
|
||||||
player.clientConnection.sendPacket(chunkdata);
|
player.clientConnection.sendPacket(chunkdata);
|
||||||
} else {
|
} else {
|
||||||
List<Byte[]> blockChunk = world.getLightEngineBlock().getBlockLightBitMask(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
List<Byte[]> blockChunk = world.getLightEngineBlock().getBlockLightBitMask(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
||||||
if (blockChunk == null) {
|
if (blockChunk == null) {
|
||||||
blockChunk = new ArrayList<>();
|
blockChunk = new ArrayList<>();
|
||||||
}
|
}
|
||||||
List<Byte[]> skyChunk = null;
|
List<Byte[]> skyChunk = null;
|
||||||
if (world.hasSkyLight()) {
|
if (world.hasSkyLight()) {
|
||||||
skyChunk = world.getLightEngineSky().getSkyLightBitMask(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
skyChunk = world.getLightEngineSky().getSkyLightBitMask(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
||||||
}
|
}
|
||||||
if (skyChunk == null) {
|
if (skyChunk == null) {
|
||||||
skyChunk = new ArrayList<>();
|
skyChunk = new ArrayList<>();
|
||||||
}
|
}
|
||||||
ClientboundLevelChunkWithLightPacket chunkdata = new ClientboundLevelChunkWithLightPacket(chunkPos.getChunkX(), chunkPos.getChunkZ(), chunk, world.getEnvironment(), skyChunk, blockChunk);
|
ClientboundLevelChunkWithLightPacket chunkdata = new ClientboundLevelChunkWithLightPacket(chunkPos.getChunkX(), chunkPos.getChunkZ(), chunk, world.getEnvironment(), skyChunk, blockChunk);
|
||||||
player.clientConnection.sendPacket(chunkdata);
|
player.clientConnection.sendPacket(chunkdata);
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
ClientboundChunkBatchFinishedPacket chunkBatchFinishedPacket = new ClientboundChunkBatchFinishedPacket(counter);
|
ClientboundChunkBatchFinishedPacket chunkBatchFinishedPacket = new ClientboundChunkBatchFinishedPacket(counter);
|
||||||
player.clientConnection.sendPacket(chunkBatchFinishedPacket);
|
player.clientConnection.sendPacket(chunkBatchFinishedPacket);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue