From 334459b8487a7d1175ee72f9a2380760842337c9 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 21 Jan 2023 16:31:19 +0100 Subject: [PATCH] Smaller tweaks --- .../bungeecore/commands/ModCommand.java | 6 ++-- .../bungeecore/listeners/mods/Fabric.java | 2 +- .../bungeecore/listeners/mods/Forge.java | 4 +-- .../bungeecore/listeners/mods/Forge12.java | 2 +- .../bungeecore/listeners/mods/LabyMod.java | 2 +- .../listeners/mods/WorldDownloader.java | 2 +- src/de/steamwar/bungeecore/sql/Mod.java | 28 +++++++++---------- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 0c35fe4..cf91e7a 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -28,7 +28,7 @@ import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; -import org.apache.commons.lang3.tuple.Pair; + import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -64,7 +64,7 @@ public class ModCommand extends SWCommand { } public void updateAndCloseGui(Mod.ModType modType,String modName,Mod.Platform modPlatform,SWInventory toClose,ProxiedPlayer p) { - Mod.get(modName,modPlatform).setModType(modType,modName,modPlatform); + Mod.getOrCreate(modName,modPlatform).setModType(modType); toClose.close(); openGui(p); } @@ -123,7 +123,7 @@ public class ModCommand extends SWCommand { return; } - Mod.get(modName,platform).setModType(newModType,modName,platform); + Mod.getOrCreate(modName,platform).setModType(newModType); Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name()); } diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index c8990a7..46c4f91 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -119,7 +119,7 @@ public class Fabric extends BasicListener { } for(JsonElement mod : array) { - mods.add(Mod.get(mod.getAsString(), Mod.Platform.FABRIC)); + mods.add(Mod.getOrCreate(mod.getAsString(), Mod.Platform.FABRIC)); } /* diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge.java b/src/de/steamwar/bungeecore/listeners/mods/Forge.java index 94a0fa2..d6ebf21 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge.java @@ -26,9 +26,7 @@ import io.netty.channel.ChannelPipeline; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.event.LoginEvent; -import net.md_5.bungee.api.event.ProxyPingEvent; import net.md_5.bungee.connection.InitialHandler; -import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PacketHandler; @@ -135,7 +133,7 @@ public class Forge extends BasicListener { Utils.VarInt nameLength = Utils.readVarInt(data, pos); pos += nameLength.length; - mods.add(Mod.get(new String(data, pos, nameLength.value), Mod.Platform.FORGE)); + mods.add(Mod.getOrCreate(new String(data, pos, nameLength.value), Mod.Platform.FORGE)); pos += nameLength.value; } diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge12.java b/src/de/steamwar/bungeecore/listeners/mods/Forge12.java index eb463f4..2bdd5a8 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge12.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge12.java @@ -92,7 +92,7 @@ public class Forge12 extends BasicListener { //Version information is unused bytePos += 1 + data[bytePos]; - mods.add(Mod.get(new String(name), Mod.Platform.FORGE)); + mods.add(Mod.getOrCreate(new String(name), Mod.Platform.FORGE)); } if (Utils.handleMods(p, mods)) { diff --git a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java index e659b4d..22887d4 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java +++ b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java @@ -67,7 +67,7 @@ public class LabyMod extends BasicListener { try{ InfoPacket info = new InfoPacket(value.value); for(InfoPacket.Addon addon : info.addons) { - mods.add(Mod.get(addon.name, Mod.Platform.LABYMOD)); + mods.add(Mod.getOrCreate(addon.name, Mod.Platform.LABYMOD)); } }catch(IOException e){ BungeeCore.log("Could not read JSON", e); diff --git a/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java b/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java index 44270b6..1b39625 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java +++ b/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java @@ -28,6 +28,6 @@ public class WorldDownloader extends BasicListener { return; event.setCancelled(true); - Utils.handleMods((ProxiedPlayer) sender, Lists.newArrayList(Mod.get("wdl", Mod.Platform.FORGE))); + Utils.handleMods((ProxiedPlayer) sender, Lists.newArrayList(Mod.getOrCreate("wdl", Mod.Platform.FORGE))); } } diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index dc46205..391c2cd 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -19,11 +19,8 @@ package de.steamwar.bungeecore.sql; -import lombok.Getter; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; - import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -49,7 +46,13 @@ public class Mod { this.modType = modType; } - public static Mod get(String modName, Platform platform){ + private Mod(ResultSet resultSet) throws SQLException { + this.modName = resultSet.getString("ModName"); + this.platform = Mod.Platform.valueOf(resultSet.getInt("Platform")); + this.modType = ModType.valueOf(resultSet.getInt("ModType")); + } + + public static Mod getOrCreate(String modName, Platform platform){ Mod mod = get.select(rs -> { if(rs.next()) return new Mod(modName, platform, ModType.valueOf(rs.getInt("ModType"))); @@ -62,15 +65,11 @@ public class Mod { return new Mod(modName, platform, ModType.UNKLASSIFIED); } - public static Mod get(String modName, int platform) { - return get(modName,Mod.Platform.valueOf(platform)); - } - public static ModType getModType(String modName,Mod.Platform platform) { - return get(modName,platform).modType; + return getOrCreate(modName,platform).modType; } - public void setModType(Mod.ModType newModType,String modName,Mod.Platform platform) { + public void setModType(Mod.ModType newModType) { set.update(newModType.value ,modName,platform.value); } @@ -81,7 +80,7 @@ public class Mod { return Mod.getAllFiltered.select(rs -> { List f = new ArrayList<>(); while(rs.next()){ - Mod entry = new Mod(rs.getString("ModName"), Mod.Platform.valueOf(rs.getInt("Platform")),Mod.ModType.valueOf(rs.getInt("ModType"))); + Mod entry = new Mod(rs); f.add(entry); } return f; @@ -89,12 +88,11 @@ public class Mod { } public static Mod findFirstMod() { - findFirst.select(rs -> { + return findFirst.select(rs -> { String name = rs.getString("ModName"); int platform = rs.getInt("Platform"); - return get(name,Platform.valueOf(platform)); + return new Mod(name,Platform.valueOf(platform),ModType.UNKLASSIFIED); }); - return null; } public String getModName() {