Skip to content

Commit

Permalink
Removed old dependency manager, fixed bossbar adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo0111 committed Aug 30, 2021
1 parent 6a7786c commit 75b2c98
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 109 deletions.
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ext {
apply from: "https://cdn.rocketplugins.space/spigot"

group = "me.lorenzo0111"
version = "1.5"
version = "1.6"

java {
withJavadocJar()
Expand All @@ -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/" }
}
Expand All @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/me/lorenzo0111/multilang/MultiLangPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<UUID,LocalizedPlayer> playerCache = new PlayersCache();
private File cacheFolder;
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 75b2c98

Please sign in to comment.