diff --git a/pom.xml b/pom.xml index 0b08ec8..9deddf1 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ com.loohp Limbo Limbo - 0.7.7-ALPHA + 0.7.8-ALPHA Standalone Limbo Minecraft Server. https://github.com/LOOHP/Limbo @@ -260,31 +260,31 @@ net.kyori adventure-text-serializer-gson - 4.15.0-SNAPSHOT + 4.17.0-SNAPSHOT compile net.kyori adventure-text-serializer-legacy - 4.15.0-SNAPSHOT + 4.17.0-SNAPSHOT compile net.kyori adventure-text-serializer-plain - 4.15.0-SNAPSHOT + 4.17.0-SNAPSHOT compile net.kyori adventure-api - 4.15.0-SNAPSHOT + 4.17.0-SNAPSHOT compile net.kyori adventure-nbt - 4.15.0-SNAPSHOT + 4.17.0-SNAPSHOT compile diff --git a/src/main/java/com/loohp/limbo/Limbo.java b/src/main/java/com/loohp/limbo/Limbo.java index 11693b2..2c48383 100644 --- a/src/main/java/com/loohp/limbo/Limbo.java +++ b/src/main/java/com/loohp/limbo/Limbo.java @@ -160,8 +160,6 @@ public final class Limbo { private final PermissionsManager permissionManager; private final File pluginFolder; - private final File internalDataFolder; - private final DimensionRegistry dimensionRegistry; private final Tick tick; @@ -208,25 +206,16 @@ public final class Limbo { } else { 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(internalDataFolder, mappingName); - if (!mappingFile.exists()) { - try (InputStream in = getClass().getClassLoader().getResourceAsStream(mappingName)) { - Files.copy(in, mappingFile.toPath()); - } catch (IOException e) { - e.printStackTrace(); - } - } + InputStream mappingStream = getClass().getClassLoader().getResourceAsStream(mappingName); + if (mappingStream == null) { + throw new RuntimeException("Failed to load " + mappingName + " from jar!"); + } - console.sendMessage("Loading packet id mappings from mapping.json ..."); - - InputStreamReader reader = new InputStreamReader(Files.newInputStream(mappingFile.toPath()), StandardCharsets.UTF_8); + console.sendMessage("Loading packet id mappings..."); + + InputStreamReader reader = new InputStreamReader(mappingStream, StandardCharsets.UTF_8); JSONObject json = (JSONObject) new JSONParser().parse(reader); reader.close(); @@ -394,10 +383,6 @@ public final class Limbo { return permissionManager; } - public File getInternalDataFolder() { - return internalDataFolder; - } - public EventsManager getEventsManager() { return eventsManager; } diff --git a/src/main/java/com/loohp/limbo/network/ClientConnection.java b/src/main/java/com/loohp/limbo/network/ClientConnection.java index 0a93dd3..485b761 100644 --- a/src/main/java/com/loohp/limbo/network/ClientConnection.java +++ b/src/main/java/com/loohp/limbo/network/ClientConnection.java @@ -63,6 +63,7 @@ import com.loohp.limbo.network.protocol.packets.PacketPlayInPickItem; import com.loohp.limbo.network.protocol.packets.PacketPlayInPluginMessaging; import com.loohp.limbo.network.protocol.packets.PacketPlayInPosition; import com.loohp.limbo.network.protocol.packets.PacketPlayInPositionAndLook; +import com.loohp.limbo.network.protocol.packets.PacketPlayOutGameStateChange; import com.loohp.limbo.network.protocol.packets.ServerboundResourcePackPacket; import com.loohp.limbo.network.protocol.packets.ServerboundResourcePackPacket.Action; import com.loohp.limbo.network.protocol.packets.PacketPlayInRotation; @@ -73,7 +74,6 @@ import com.loohp.limbo.network.protocol.packets.PacketPlayInWindowClick; import com.loohp.limbo.network.protocol.packets.PacketPlayOutDeclareCommands; import com.loohp.limbo.network.protocol.packets.PacketPlayOutDisconnect; import com.loohp.limbo.network.protocol.packets.PacketPlayOutEntityMetadata; -import com.loohp.limbo.network.protocol.packets.PacketPlayOutGameState; import com.loohp.limbo.network.protocol.packets.PacketPlayOutHeldItemChange; import com.loohp.limbo.network.protocol.packets.PacketPlayOutKeepAlive; import com.loohp.limbo.network.protocol.packets.PacketPlayOutLogin; @@ -613,6 +613,8 @@ public class ClientConnection extends Thread { String str = (properties.isLogPlayerIPAddresses() ? inetAddress.getHostName() : "") + ":" + clientSocket.getPort() + "|" + player.getName() + "(" + player.getUniqueId() + ")"; Limbo.getInstance().getConsole().sendMessage("[/" + str + "] <-> Player had connected to the Limbo server!"); + PacketPlayOutGameStateChange gameEvent = new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.GameStateChangeEvent.LEVEL_CHUNKS_LOAD_START, 0); + sendPacket(gameEvent); player.playerInteractManager.update(); PacketPlayOutDeclareCommands declare = DeclareCommands.getDeclareCommandsPacket(player); @@ -634,7 +636,7 @@ public class ClientConnection extends Thread { Limbo.getInstance().getEventsManager().callEvent(new PlayerJoinEvent(player)); if (properties.isAllowFlight()) { - PacketPlayOutGameState state = new PacketPlayOutGameState(3, player.getGamemode().getId()); + PacketPlayOutGameStateChange state = new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.GameStateChangeEvent.CHANGE_GAME_MODE, player.getGamemode().getId()); sendPacket(state); } diff --git a/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayOutGameState.java b/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayOutGameState.java deleted file mode 100644 index ab61263..0000000 --- a/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayOutGameState.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of Limbo. - * - * Copyright (C) 2022. LoohpJames - * Copyright (C) 2022. Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.loohp.limbo.network.protocol.packets; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class PacketPlayOutGameState extends PacketOut { - - private final int reason; - private final float value; - - public PacketPlayOutGameState(int reason, float value) { - this.reason = reason; - this.value = value; - } - - public int getReason() { - return reason; - } - - public float getValue() { - return value; - } - - @Override - public byte[] serializePacket() throws IOException { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - DataOutputStream output = new DataOutputStream(buffer); - output.writeByte(Packet.getPlayOut().get(getClass())); - output.writeByte(reason); - output.writeFloat(value); - - return buffer.toByteArray(); - } - -} diff --git a/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayOutGameStateChange.java b/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayOutGameStateChange.java new file mode 100644 index 0000000..74ab37b --- /dev/null +++ b/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayOutGameStateChange.java @@ -0,0 +1,82 @@ +/* + * This file is part of Limbo. + * + * Copyright (C) 2024. LoohpJames + * Copyright (C) 2024. Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.loohp.limbo.network.protocol.packets; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class PacketPlayOutGameStateChange extends PacketOut { + + public enum GameStateChangeEvent { + NO_RESPAWN_BLOCK_AVAILABLE(0), + START_RAINING(1), + STOP_RAINING(2), + CHANGE_GAME_MODE(3), + WIN_GAME(4), + DEMO_EVENT(5), + ARROW_HIT_PLAYER(6), + RAIN_LEVEL_CHANGE(7), + THUNDER_LEVEL_CHANGE(8), + PUFFER_FISH_STING(9), + GUARDIAN_ELDER_EFFECT(10), + IMMEDIATE_RESPAWN(11), + LIMITED_CRAFTING(12), + LEVEL_CHUNKS_LOAD_START(13); + + private final int id; + + GameStateChangeEvent(int id) { + this.id = id; + } + + public int getId() { + return id; + } + } + + private GameStateChangeEvent event; + private float value; + + public PacketPlayOutGameStateChange(GameStateChangeEvent event, float value) { + this.event = event; + this.value = value; + } + + public GameStateChangeEvent getEvent() { + return event; + } + + public float getValue() { + return value; + } + + public byte[] serializePacket() throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + + DataOutputStream output = new DataOutputStream(buffer); + output.writeByte(Packet.getPlayOut().get(getClass())); + output.writeByte(event.getId()); + output.writeFloat(value); + + return buffer.toByteArray(); + } + +} diff --git a/src/main/java/com/loohp/limbo/player/Player.java b/src/main/java/com/loohp/limbo/player/Player.java index ce2a1c8..804e33a 100644 --- a/src/main/java/com/loohp/limbo/player/Player.java +++ b/src/main/java/com/loohp/limbo/player/Player.java @@ -45,7 +45,7 @@ import com.loohp.limbo.network.protocol.packets.ClientboundSetTitlesAnimationPac import com.loohp.limbo.network.protocol.packets.ClientboundSystemChatPacket; import com.loohp.limbo.network.protocol.packets.PacketOut; import com.loohp.limbo.network.protocol.packets.PacketPlayOutCloseWindow; -import com.loohp.limbo.network.protocol.packets.PacketPlayOutGameState; +import com.loohp.limbo.network.protocol.packets.PacketPlayOutGameStateChange; import com.loohp.limbo.network.protocol.packets.PacketPlayOutHeldItemChange; import com.loohp.limbo.network.protocol.packets.PacketPlayOutNamedSoundEffect; import com.loohp.limbo.network.protocol.packets.PacketPlayOutOpenWindow; @@ -151,7 +151,7 @@ public class Player extends LivingEntity implements CommandSender, InventoryHold public void setGamemode(GameMode gamemode) { if (!this.gamemode.equals(gamemode)) { try { - PacketPlayOutGameState state = new PacketPlayOutGameState(3, gamemode.getId()); + PacketPlayOutGameStateChange state = new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.GameStateChangeEvent.CHANGE_GAME_MODE, gamemode.getId()); clientConnection.sendPacket(state); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/com/loohp/limbo/player/PlayerInteractManager.java b/src/main/java/com/loohp/limbo/player/PlayerInteractManager.java index 719d242..9c57313 100644 --- a/src/main/java/com/loohp/limbo/player/PlayerInteractManager.java +++ b/src/main/java/com/loohp/limbo/player/PlayerInteractManager.java @@ -69,7 +69,7 @@ public class PlayerInteractManager { public Player getPlayer() { return player; } - + public void update() throws IOException { if (player.clientConnection.getClientState() != ClientConnection.ClientState.PLAY) { return; @@ -98,15 +98,15 @@ public class PlayerInteractManager { PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(id); player.clientConnection.sendPacket(packet); } - + entities = entitiesInRange; - + int playerChunkX = (int) location.getX() >> 4; int playerChunkZ = (int) location.getZ() >> 4; World world = location.getWorld(); - + Map chunksInRange = new HashMap<>(); - + for (int x = playerChunkX - viewDistanceChunks; x < playerChunkX + viewDistanceChunks; x++) { for (int z = playerChunkZ - viewDistanceChunks; z < playerChunkZ + viewDistanceChunks; z++) { Chunk chunk = world.getChunkAt(x, z); @@ -117,7 +117,7 @@ public class PlayerInteractManager { } } } - + for (Entry entry : currentViewing.entrySet()) { ChunkPosition chunkPos = entry.getKey(); if (!chunksInRange.containsKey(chunkPos)) { diff --git a/src/main/java/com/loohp/limbo/registry/Registry.java b/src/main/java/com/loohp/limbo/registry/Registry.java index a9086e5..72dab8a 100644 --- a/src/main/java/com/loohp/limbo/registry/Registry.java +++ b/src/main/java/com/loohp/limbo/registry/Registry.java @@ -48,20 +48,17 @@ public class Registry { static { String name = "registries.json"; - File file = new File(Limbo.getInstance().getInternalDataFolder(), name); - if (!file.exists()) { - try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(name)) { - Files.copy(in, file.toPath()); - } catch (IOException e) { - e.printStackTrace(); - } - } Map blockEntityType = new HashMap<>(); Key defaultItemKey = null; BiMap itemIds = HashBiMap.create(); Map menuIds = new HashMap<>(); - try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) { + + InputStream inputStream = Limbo.class.getClassLoader().getResourceAsStream(name); + if (inputStream == null) { + throw new RuntimeException("Failed to load " + name + " from jar!"); + } + try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { JSONObject json = (JSONObject) new JSONParser().parse(reader); JSONObject blockEntityJson = (JSONObject) ((JSONObject) json.get("minecraft:block_entity_type")).get("entries"); diff --git a/src/main/java/com/loohp/limbo/world/DimensionRegistry.java b/src/main/java/com/loohp/limbo/world/DimensionRegistry.java index 323bf7e..c1480a6 100644 --- a/src/main/java/com/loohp/limbo/world/DimensionRegistry.java +++ b/src/main/java/com/loohp/limbo/world/DimensionRegistry.java @@ -37,24 +37,16 @@ public class DimensionRegistry { private CompoundTag defaultTag; private CompoundTag codec; - private File reg; public DimensionRegistry() { this.defaultTag = new CompoundTag(); - String name = "dimension_registry.json"; - File file = new File(Limbo.getInstance().getInternalDataFolder(), name); - if (!file.exists()) { - try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(name)) { - Files.copy(in, file.toPath()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - this.reg = file; - - try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(reg.toPath()), StandardCharsets.UTF_8)) { + + InputStream inputStream = Limbo.class.getClassLoader().getResourceAsStream(name); + if (inputStream == null) { + throw new RuntimeException("Failed to load " + name + " from jar!"); + } + try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { JSONObject json = (JSONObject) new JSONParser().parse(reader); CompoundTag tag = CustomNBTUtils.getCompoundTagFromJson((JSONObject) json.get("value")); defaultTag = tag; @@ -64,10 +56,6 @@ public class DimensionRegistry { } } - public File getFile() { - return reg; - } - public void resetCodec() { codec = defaultTag.clone(); } diff --git a/src/main/java/com/loohp/limbo/world/GeneratedBlockDataMappings.java b/src/main/java/com/loohp/limbo/world/GeneratedBlockDataMappings.java index 4375327..e9dd234 100644 --- a/src/main/java/com/loohp/limbo/world/GeneratedBlockDataMappings.java +++ b/src/main/java/com/loohp/limbo/world/GeneratedBlockDataMappings.java @@ -30,6 +30,8 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.HashMap; import java.util.Map; @@ -41,17 +43,12 @@ public class GeneratedBlockDataMappings { static { String block = "blocks.json"; - File file = new File(Limbo.getInstance().getInternalDataFolder(), block); - if (!file.exists()) { - try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(block)) { - Files.copy(in, file.toPath()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - try { - globalPalette = (JSONObject) new JSONParser().parse(new FileReader(file)); + InputStream inputStream = Limbo.class.getClassLoader().getResourceAsStream(block); + if (inputStream == null) { + throw new RuntimeException("Failed to load " + block + " from jar!"); + } + try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { + globalPalette = (JSONObject) new JSONParser().parse(reader); } catch (IOException | ParseException e) { e.printStackTrace(); } diff --git a/src/main/resources/mapping.json b/src/main/resources/mapping.json index 365880c..365a148 100644 --- a/src/main/resources/mapping.json +++ b/src/main/resources/mapping.json @@ -48,6 +48,7 @@ "ClientboundLevelChunkWithLightPacket": "0x25", "PacketPlayOutUnloadChunk": "0x1F", "PacketPlayOutKeepAlive": "0x15", + "PacketPlayOutGameStateChange": "0x20", "PacketPlayOutPlayerInfo": "0x3C", "PacketPlayOutUpdateViewPosition": "0x52", "PacketPlayOutDisconnect": "0x1B", @@ -55,7 +56,6 @@ "PacketPlayOutTabComplete": "0x10", "PacketPlayOutDeclareCommands": "0x11", "PacketPlayOutRespawn": "0x45", - "PacketPlayOutGameState": "0x20", "PacketPlayOutEntityDestroy": "0x40", "PacketPlayOutEntityMetadata": "0x56", "PacketPlayOutSpawnEntity": "0x01",