diff --git a/build.gradle b/build.gradle index 46aa851..ed13b71 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ ext { apply from: "https://cdn.rocketplugins.space/spigot" group = "me.lorenzo0111" -version = "1.5" +version = "1.6" java { withJavadocJar() @@ -47,13 +47,13 @@ java { repositories { mavenCentral() - maven { url 'https://jitpack.io' } - maven { url 'https://repo.codemc.org/repository/maven-snapshots/' } - maven { url 'https://repo.codemc.org/repository/maven-releases/' } - maven { url 'https://repo.repsy.io/mvn/lorenzo0111/public' } - maven { url 'https://repo.mattstudios.me/artifactory/public/' } - maven { url 'https://oss.sonatype.org/content/repositories/releases/' } - maven { url 'https://oss.sonatype.org/content/repositories/snapshots/'} + maven { url "https://jitpack.io" } + maven { url "https://repo.codemc.org/repository/maven-snapshots/" } + maven { url "https://repo.codemc.org/repository/maven-releases/" } + maven { url "https://repo.repsy.io/mvn/lorenzo0111/public" } + maven { url "https://repo.mattstudios.me/artifactory/public/" } + maven { url "https://oss.sonatype.org/content/repositories/releases/" } + maven { url "https://oss.sonatype.org/content/repositories/snapshots/"} maven { url "https://repo.dmulloy2.net/repository/public/" } maven { url "https://repo.vshnv.tech/releases/" } } @@ -71,7 +71,7 @@ dependencies { slim("net.kyori:adventure-text-serializer-legacy:4.8.1") slim("mysql:mysql-connector-java:8.0.26") slim("org.xerial:sqlite-jdbc:3.36.0.2") - slim('org.slf4j:slf4j-simple:1.7.32') + slim("org.slf4j:slf4j-simple:1.7.32") } sonarqube { diff --git a/src/main/java/me/lorenzo0111/multilang/MultiLangPlugin.java b/src/main/java/me/lorenzo0111/multilang/MultiLangPlugin.java index dfa26ae..a177a6b 100644 --- a/src/main/java/me/lorenzo0111/multilang/MultiLangPlugin.java +++ b/src/main/java/me/lorenzo0111/multilang/MultiLangPlugin.java @@ -31,7 +31,6 @@ import me.lorenzo0111.multilang.cache.PlayersCache; import me.lorenzo0111.multilang.data.StorageType; import me.lorenzo0111.multilang.database.DatabaseManager; -import me.lorenzo0111.multilang.dependency.DependencyManager; import me.lorenzo0111.multilang.exceptions.ReloadException; import me.lorenzo0111.multilang.handlers.ConfigManager; import me.lorenzo0111.multilang.listeners.JoinListener; @@ -43,6 +42,7 @@ import me.lorenzo0111.pluginslib.database.connection.IConnectionHandler; import me.lorenzo0111.pluginslib.database.objects.Column; import me.lorenzo0111.pluginslib.database.objects.Table; +import me.lorenzo0111.pluginslib.dependency.DependencyManager; import me.lorenzo0111.pluginslib.scheduler.BukkitScheduler; import me.lorenzo0111.pluginslib.updater.UpdateChecker; import me.lorenzo0111.rocketplaceholders.api.IRocketPlaceholdersAPI; @@ -64,7 +64,7 @@ public final class MultiLangPlugin extends JavaPlugin { private IRocketPlaceholdersAPI rocketPlaceholdersAPI; private ConfigManager configManager; private PluginLoader loader; - private static MultiLangPlugin instance; + private static MultiLangPlugin instance = null; private DatabaseManager databaseManager; private final Cache playerCache = new PlayersCache(); private File cacheFolder; @@ -82,6 +82,11 @@ public void onLoad() { @Override public void onEnable() { + if (instance == null) { + this.getLogger().warning("Detected plugin reload. Please do not use /reload."); + this.onLoad(); + } + BukkitAudienceManager.init(this); try { this.updateConfig(); @@ -237,7 +242,7 @@ private void loadDependencies() { this.getLogger().info("Note: This might take a few minutes on first run."); try { - long time = new DependencyManager(this) + long time = new DependencyManager(this.getName(), this.getDataFolder().toPath()) .build(); this.getLogger().info(String.format("Loaded libraries in %sms.", time)); } catch (ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException | IOException e) { diff --git a/src/main/java/me/lorenzo0111/multilang/dependency/DependencyManager.java b/src/main/java/me/lorenzo0111/multilang/dependency/DependencyManager.java deleted file mode 100644 index 85bd64f..0000000 --- a/src/main/java/me/lorenzo0111/multilang/dependency/DependencyManager.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of MultiLang, licensed under the MIT License. - * - * Copyright (c) Lorenzo0111 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lorenzo0111.multilang.dependency; - -import io.github.slimjar.app.builder.ApplicationBuilder; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.security.NoSuchAlgorithmException; - -public class DependencyManager { - private final ApplicationBuilder builder; - - public DependencyManager(JavaPlugin plugin) throws ReflectiveOperationException, URISyntaxException, NoSuchAlgorithmException, IOException { - this(plugin,new File(plugin.getDataFolder(), "libs")); - } - - public DependencyManager(JavaPlugin plugin, File directory) throws ReflectiveOperationException, URISyntaxException, NoSuchAlgorithmException, IOException { - directory.mkdirs(); - - this.builder = ApplicationBuilder - .appending(plugin.getName()) - .downloadDirectoryPath(directory.toPath()); - } - - public long build() throws ReflectiveOperationException, IOException, URISyntaxException, NoSuchAlgorithmException { - long before = System.currentTimeMillis(); - builder.build(); - long after = System.currentTimeMillis(); - return after - before; - } - -} diff --git a/src/main/java/me/lorenzo0111/multilang/protocol/adapter/BaseAdapter.java b/src/main/java/me/lorenzo0111/multilang/protocol/adapter/BaseAdapter.java index 9822dda..44a9ad7 100644 --- a/src/main/java/me/lorenzo0111/multilang/protocol/adapter/BaseAdapter.java +++ b/src/main/java/me/lorenzo0111/multilang/protocol/adapter/BaseAdapter.java @@ -4,6 +4,7 @@ import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.wrappers.WrappedChatComponent; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import me.lorenzo0111.multilang.MultiLangPlugin; @@ -17,14 +18,26 @@ public BaseAdapter(MultiLangPlugin plugin, ListenerPriority listenerPriority, Pa super(plugin, listenerPriority, type); } - public void handle(Player player, @NotNull WrappedChatComponent component, @NotNull Runnable save) { + public void handle(Player player, @NotNull WrappedChatComponent component) { JsonObject json = new JsonParser().parse(component.getJson()).getAsJsonObject(); - this.update(json, RegexChecker.replace(player, json)); + if (json.has("text")) { + this.update(json, RegexChecker.replace(player, json)); + } - component.setJson(json.toString()); + // Iterate "extra", check if it has some text and update it + if (json.has("extra")) { + + for (JsonElement element : json.get("extra").getAsJsonArray()) { + JsonObject object = element.getAsJsonObject(); + if (!object.has("text")) continue; + + this.update(object, RegexChecker.replace(player,object)); + } - save.run(); + } + + component.setJson(json.toString()); } protected void update(@NotNull JsonObject object, String value) { diff --git a/src/main/java/me/lorenzo0111/multilang/protocol/adapter/BossBarAdapter.java b/src/main/java/me/lorenzo0111/multilang/protocol/adapter/BossBarAdapter.java index c82438e..4277a2f 100644 --- a/src/main/java/me/lorenzo0111/multilang/protocol/adapter/BossBarAdapter.java +++ b/src/main/java/me/lorenzo0111/multilang/protocol/adapter/BossBarAdapter.java @@ -19,6 +19,12 @@ public BossBarAdapter(MultiLangPlugin plugin, ListenerPriority listenerPriority) public void onPacketSending(@NotNull PacketEvent event) { PacketContainer packet = event.getPacket(); + if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { + if (packet.getStructures().read(1).getChatComponents().size() != 1) return; + } else { + if (packet.getChatComponents().size() < 1) return; + } + WrappedChatComponent component; if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { @@ -27,12 +33,12 @@ public void onPacketSending(@NotNull PacketEvent event) { component = packet.getChatComponents().read(0); } - this.handle(event.getPlayer(),component, () -> { - if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { - packet.getStructures().read(1).getChatComponents().write(0, component); - } else { - packet.getChatComponents().write(0, component); - } - }); + this.handle(event.getPlayer(),component); + + if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { + packet.getStructures().read(1).getChatComponents().write(0,component); + } else { + packet.getChatComponents().write(0, component); + } } } diff --git a/src/main/java/me/lorenzo0111/multilang/protocol/adapter/ChatAdapter.java b/src/main/java/me/lorenzo0111/multilang/protocol/adapter/ChatAdapter.java index 4397241..1e152b5 100644 --- a/src/main/java/me/lorenzo0111/multilang/protocol/adapter/ChatAdapter.java +++ b/src/main/java/me/lorenzo0111/multilang/protocol/adapter/ChatAdapter.java @@ -30,11 +30,7 @@ import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.WrappedChatComponent; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import me.lorenzo0111.multilang.MultiLangPlugin; -import me.lorenzo0111.multilang.utils.RegexChecker; import org.bukkit.entity.Player; public class ChatAdapter extends BaseAdapter { @@ -56,29 +52,6 @@ public void onPacketSending(PacketEvent event) { WrappedChatComponent component = packet.getChatComponents().read(0); if (component == null) return; - JsonObject json = new JsonParser().parse(component.getJson()).getAsJsonObject(); - - // If it has some text, update it - if (json.has("text")) { - this.update(json, RegexChecker.replace(player, json.get("text").getAsString())); - } - - // Iterate "extra", check if it has some text and update it - if (json.has("extra")) { - - for (JsonElement element : json.get("extra").getAsJsonArray()) { - JsonObject object = element.getAsJsonObject(); - if (!object.has("text")) continue; - - String text = object.get("text").getAsString(); - - this.update(object, RegexChecker.replace(player,text)); - } - - } - - // Update the component and the packet - component.setJson(json.toString()); - + this.handle(player,component); } } diff --git a/src/main/java/me/lorenzo0111/multilang/protocol/adapter/InventoryAdapter.java b/src/main/java/me/lorenzo0111/multilang/protocol/adapter/InventoryAdapter.java index d010c0c..4e3a408 100644 --- a/src/main/java/me/lorenzo0111/multilang/protocol/adapter/InventoryAdapter.java +++ b/src/main/java/me/lorenzo0111/multilang/protocol/adapter/InventoryAdapter.java @@ -54,7 +54,7 @@ public void onPacketSending(PacketEvent event) { if (!json.has("text")) return; // Edit packet - this.handle(event.getPlayer(),component, () -> event.getPacket().getChatComponents().write(0,component)); + this.handle(event.getPlayer(),component); } catch (Exception e) { plugin.getLogger().log(Level.SEVERE, "An error has occurred while handling packets", e); }