Skip to content

Commit

Permalink
Fix bad packet id for chat messages in Protocol107
Browse files Browse the repository at this point in the history
  • Loading branch information
AstFaster committed Apr 23, 2023
1 parent 26eaf8d commit c3112a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
45 changes: 2 additions & 43 deletions src/main/java/fr/hyriode/limbo/HyriLimbo.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package fr.hyriode.limbo;

import fr.hyriode.api.HyriAPI;
import fr.hyriode.api.HyriAPIImpl;
import fr.hyriode.api.language.HyriLanguage;
import fr.hyriode.hyggdrasil.api.limbo.HyggLimbo;
import fr.hyriode.limbo.command.CommandManager;
import fr.hyriode.limbo.config.LimboConfig;
Expand All @@ -14,9 +12,6 @@
import fr.hyriode.limbo.util.References;
import fr.hyriode.limbo.util.logger.ColoredLogger;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
Expand All @@ -31,7 +26,7 @@
*/
public class HyriLimbo {

private static final Path LANG_FOLDERS = Paths.get("lang");
private static final Path LANG_FOLDER = Paths.get("lang");

private static HyriLimbo instance;

Expand Down Expand Up @@ -60,7 +55,7 @@ public void start() {

this.config = LimboConfig.load();
this.hyriAPI = new HyriAPIImpl(this.config.hyriAPI(), this.logger);
this.loadLanguages();
this.hyriAPI.getLanguageManager().loadLanguagesMessages(LANG_FOLDER, "/lang/", HyriLimbo.class::getResourceAsStream);
this.protocolRepository = new ProtocolRepository();
this.commandManager = new CommandManager();

Expand All @@ -86,42 +81,6 @@ public void stop() {
this.server.stop();
}

private void loadLanguages() {
try {
for (HyriLanguage language : HyriLanguage.values()) {
final String path = "/lang/" + language.getCode() + ".json";

try (final InputStream inputStream = HyriLimbo.class.getResourceAsStream(path)) {
if (inputStream == null) {
System.err.println("Cannot get resource from '" + path + "'!");
continue;
}

final Path langFile = Paths.get(LANG_FOLDERS.toString(), language.getCode() + ".json");
final boolean exists = Files.exists(langFile);

if (!exists) {
IOUtil.copyInputStreamToFile(inputStream, langFile.toFile());
continue;
}

try (final InputStream existingInput = Files.newInputStream(langFile); final InputStream clonedInput = HyriLimbo.class.getResourceAsStream(path)) {
if (IOUtil.toMD5(clonedInput).equals(IOUtil.toMD5(existingInput))) {
continue;
}

Files.delete(langFile);
IOUtil.copyInputStreamToFile(inputStream, langFile.toFile());
}
}
}

HyriAPI.get().getLanguageManager().loadLanguagesMessages(LANG_FOLDERS.toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static HyriLimbo get() {
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Protocol107 extends ProtocolCommon {
public void registerPackets() {
super.registerPackets();

this.registry.registerIn(ProtocolState.PLAY, 0x01, PacketPlayInChatMessage.class);
this.registry.registerIn(ProtocolState.PLAY, 0x02, PacketPlayInChatMessage.class);
this.registry.registerIn(ProtocolState.PLAY, 0x0B, PacketPlayInKeepAlive.class);
this.registry.registerOut(ProtocolState.PLAY, 0x1F, PacketPlayOutKeepAlive.class);
this.registry.registerOut(ProtocolState.PLAY, 0x23, PacketPlayOutJoinGame.class);
Expand Down

0 comments on commit c3112a4

Please sign in to comment.