|
4 | 4 | import org.geysermc.geyser.api.event.bedrock.ClientEmoteEvent; |
5 | 5 | import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent; |
6 | 6 | import org.geysermc.geyser.api.extension.Extension; |
7 | | -import org.yaml.snakeyaml.Yaml; |
8 | | - |
9 | | -import java.io.FileReader; |
10 | | -import java.io.IOException; |
11 | | -import java.io.InputStream; |
12 | | -import java.nio.file.Files; |
13 | | -import java.nio.file.Path; |
14 | | -import java.util.Map; |
15 | 7 |
|
16 | 8 | public class EmoteOffhand implements Extension { |
17 | | - private static final Yaml YAML = new Yaml(); |
18 | | - |
19 | | - private boolean passthroughEmotes = false; |
20 | 9 |
|
21 | 10 | @Subscribe |
22 | | - public void onPostInitialize(GeyserPostInitializeEvent event) { |
23 | | - this.logger().info("Loading EmoteOffhand..."); |
24 | | - |
25 | | - try { |
26 | | - Path configPath = this.dataFolder().resolve("config.yml"); |
27 | | - if (Files.notExists(configPath)) createConfig(); |
28 | | - Map<String, Object> config = YAML.load(new FileReader(configPath.toFile())); |
29 | | - if (!config.containsKey("passthrough-emotes") || !(config.get("passthrough-emotes") instanceof Boolean)) { |
30 | | - this.logger().warning("Invalid config found! Config will be rewritten."); |
31 | | - createConfig(); |
32 | | - } else { |
33 | | - this.passthroughEmotes = (boolean) config.get("passthrough-emotes"); |
34 | | - } |
35 | | - } catch (IOException e) { |
36 | | - this.logger().error("Unable to load config! Will use the default config.", e); |
37 | | - } |
38 | | - |
| 11 | + public void onPostInitialize(GeyserPostInitializeEvent ignored) { |
39 | 12 | this.logger().info("Loaded EmoteOffhand!"); |
40 | 13 | } |
41 | 14 |
|
42 | 15 | @Subscribe |
43 | 16 | public void onEmote(ClientEmoteEvent event) { |
44 | | - if (!this.passthroughEmotes) event.setCancelled(true); |
45 | | - |
46 | 17 | event.connection().entities().switchHands(); |
47 | 18 | } |
48 | | - |
49 | | - private void createConfig() throws IOException { |
50 | | - if (Files.notExists(this.dataFolder())) Files.createDirectories(this.dataFolder()); |
51 | | - Path configPath = this.dataFolder().resolve("config.yml"); |
52 | | - |
53 | | - InputStream internalConfig = EmoteOffhand.class.getResourceAsStream("/extension-config.yml"); |
54 | | - if (internalConfig == null) { |
55 | | - throw new IOException("`extension-config.yml` not found within the JAR file. The extension JAR file may be corrupt."); |
56 | | - } |
57 | | - |
58 | | - Files.write(configPath, internalConfig.readAllBytes()); |
59 | | - |
60 | | - internalConfig.close(); |
61 | | - } |
62 | 19 | } |
0 commit comments