SteamWar/BungeeCore
Archiviert
13
2

Fix Bugs and code problems
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2023-02-02 11:02:36 +01:00
Ursprung 87efa9659d
Commit 48cdfe35f0
3 geänderte Dateien mit 54 neuen und 87 gelöschten Zeilen

Datei anzeigen

@ -63,8 +63,8 @@ public class ModCommand extends SWCommand {
swStreamInv.open(); swStreamInv.open();
} }
public void updateAndCloseGui(Mod.ModType modType,String modName,Mod.Platform modPlatform,SWInventory toClose,ProxiedPlayer p) { public void updateAndCloseGui(Mod.ModType modType, Mod mod, SWInventory toClose, ProxiedPlayer p) {
Mod.getOrCreate(modName,modPlatform).setModType(modType); mod.setModType(modType);
toClose.close(); toClose.close();
openGui(p); openGui(p);
} }
@ -74,8 +74,8 @@ public class ModCommand extends SWCommand {
inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> playerFilterType.replace(p, Mod.ModType.UNKLASSIFIED)); inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> playerFilterType.replace(p, Mod.ModType.UNKLASSIFIED));
inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> playerFilterType.replace(p, Mod.ModType.GREEN)); inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> playerFilterType.replace(p, Mod.ModType.GREEN));
inv.addItem(3, new SWItem(Message.parse("MOD_PENDING",p), 11),click -> playerFilterType.replace(p, Mod.ModType.YELLOW)); inv.addItem(3, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), click -> playerFilterType.replace(p, Mod.ModType.YELLOW));
inv.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED)); inv.addItem(4, new SWItem(Message.parse("MOD_AUTOBAN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED));
inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> playerFilterType.replace(p, Mod.ModType.YOUTUBER_ONLY)); inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> playerFilterType.replace(p, Mod.ModType.YOUTUBER_ONLY));
inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> { inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> {
@ -89,14 +89,11 @@ public class ModCommand extends SWCommand {
private void openClassificationGui(ProxiedPlayer p,Mod element) { private void openClassificationGui(ProxiedPlayer p,Mod element) {
SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p)); SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p));
String modName = element.getModName(); swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,element,swInventory,p)));
Mod.Platform modPlatform = element.getPlatform(); swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,element,swInventory,p)));
swInventory.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,element,swInventory,p)));
swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,modName,modPlatform,swInventory,p))); swInventory.addItem(5, new SWItem(Message.parse("MOD_AUTOBAN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,element,swInventory,p)));
swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,modName,modPlatform,swInventory,p))); swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,element,swInventory,p)));
swInventory.addItem(4, new SWItem(Message.parse("MOD_PENDING",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,modName,modPlatform,swInventory,p)));
swInventory.addItem(5, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,modName,modPlatform,swInventory,p)));
swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,modName,modPlatform,swInventory,p)));
swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> { swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> {
swInventory.close(); swInventory.close();
@ -116,27 +113,30 @@ public class ModCommand extends SWCommand {
@Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE")
public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) { public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) {
boolean modExists = Mod.doesModExist(modName,platform); Mod mod = Mod.get(modName, platform);
if(mod == null) {
if(!modExists) { Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName, platform.name());
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName);
return; return;
} }
Mod.getOrCreate(modName,platform).setModType(newModType); mod.setModType(newModType);
Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name()); Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name());
} }
@Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE")
public void get(ProxiedPlayer p,String modName,Mod.Platform platform) { public void get(ProxiedPlayer p,String modName,Mod.Platform platform) {
Message.send("MOD_COMMAND_INFO",p,modName,platform.name(),Mod.getModType(modName,platform).name()); Mod mod = Mod.get(modName, platform);
if(mod == null) {
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE", p, modName, platform.name());
return;
}
Message.send("MOD_COMMAND_INFO", p, modName, platform.name(), mod.getModType().name());
} }
@Register(value = {"next"}) @Register(value = {"next"})
public void next(ProxiedPlayer p) { public void next(ProxiedPlayer p) {
Mod mod = Mod.findFirstMod(); Mod mod = Mod.findFirstMod();
if(mod == null) { if(mod == null) {
Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p); Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p);
return; return;

Datei anzeigen

@ -34,9 +34,7 @@ public class Mod {
private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND Platform = ?"); private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND Platform = ?");
private static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE ModType = 0 LIMIT 1"); private static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE ModType = 0 LIMIT 1");
private static final Statement getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?"); private static final Statement getPageOfType = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?");
private static final Statement getAllFiltered = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?");
private final String modName; private final String modName;
private final Platform platform; private final Platform platform;
@ -49,51 +47,46 @@ public class Mod {
} }
private Mod(ResultSet resultSet) throws SQLException { private Mod(ResultSet resultSet) throws SQLException {
this.modName = resultSet.getString("ModName"); this(resultSet.getString("ModName"), Mod.Platform.values()[resultSet.getInt("Platform")], ModType.values()[resultSet.getInt("ModType")]);
this.platform = Mod.Platform.valueOf(resultSet.getInt("Platform"));
this.modType = ModType.valueOf(resultSet.getInt("ModType"));
} }
public static Mod getOrCreate(String modName, Platform platform){ public static Mod get(String name, Platform platform) {
Mod mod = get.select(rs -> { return get.select(rs -> {
if(rs.next()) if(rs.next())
return new Mod(modName, platform, ModType.valueOf(rs.getInt("ModType"))); return new Mod(rs);
return null; return null;
}, modName, platform.value); }, name, platform.ordinal());
}
public static Mod getOrCreate(String name, Platform platform) {
Mod mod = get(name, platform);
if(mod != null) if(mod != null)
return mod; return mod;
insert.update(modName, platform.value); insert.update(name, platform.ordinal());
return new Mod(modName, platform, ModType.UNKLASSIFIED); return new Mod(name, platform, ModType.UNKLASSIFIED);
}
public static ModType getModType(String modName,Mod.Platform platform) {
return getOrCreate(modName,platform).modType;
} }
public void setModType(Mod.ModType newModType) { public void setModType(Mod.ModType newModType) {
set.update(newModType.value ,modName,platform.value); set.update(newModType.ordinal(), modName, platform.ordinal());
} }
public static boolean doesModExist(String modName,Mod.Platform modPlatform) {
return get.select(ResultSet::next,modName,modPlatform.value);
}
public static List<Mod> getAllModsFiltered(int page,int elementsPerPage, Mod.ModType filter) { public static List<Mod> getAllModsFiltered(int page,int elementsPerPage, Mod.ModType filter) {
return Mod.getAllFiltered.select(rs -> { return Mod.getPageOfType.select(rs -> {
List<Mod> f = new ArrayList<>(); List<Mod> f = new ArrayList<>();
while(rs.next()){
Mod entry = new Mod(rs); while(rs.next())
f.add(entry); f.add(new Mod(rs));
}
return f; return f;
},filter.value, page * elementsPerPage, elementsPerPage); },filter.ordinal(), page * elementsPerPage, elementsPerPage);
} }
public static Mod findFirstMod() { public static Mod findFirstMod() {
return findFirst.select(rs -> { return findFirst.select(rs -> {
String name = rs.getString("ModName"); if(rs.next())
int platform = rs.getInt("Platform"); return new Mod(rs);
return new Mod(name,Platform.valueOf(platform),ModType.UNKLASSIFIED); return null;
}); });
} }
@ -110,48 +103,22 @@ public class Mod {
} }
public enum Platform{ public enum Platform{
FORGE(0), FORGE,
LABYMOD(1), LABYMOD,
FABRIC(2); FABRIC
Platform(int value){
this.value = value;
}
static Platform valueOf(int value){
for(Platform mt : values()){
if(value == mt.value)
return mt;
}
throw new EnumConstantNotPresentException(Platform.class, Integer.toString(value));
}
int value;
public int get() {
return value;
}
} }
public enum ModType { public enum ModType {
UNKLASSIFIED(0,"7"), UNKLASSIFIED("7"),
GREEN(1,"a"), GREEN("a"),
YELLOW(2,"e"), YELLOW("e"),
RED(3,"c"), RED("c"),
YOUTUBER_ONLY(4,"6"); YOUTUBER_ONLY("6");
static ModType valueOf(int value){ ModType(String colorcode) {
for(ModType mt : values()){
if(value == mt.value)
return mt;
}
throw new EnumConstantNotPresentException(ModType.class, Integer.toString(value));
}
ModType(int value,String colorcode){
this.value = value;
this.colorcode = colorcode; this.colorcode = colorcode;
} }
int value; private final String colorcode;
String colorcode;
public String getColorCode() { public String getColorCode() {
return colorcode; return colorcode;

Datei anzeigen

@ -674,7 +674,7 @@ MOD_COMMAND_CLASSICIATION_GUI=Mod Type Changer
MOD_OPEN_GUI=§7Open Gui MOD_OPEN_GUI=§7Open Gui
MOD_UNCLASSIFIED=§7Unclassified MOD_UNCLASSIFIED=§7Unclassified
MOD_ALLOWED=§aAllowed MOD_ALLOWED=§aAllowed
MOD_PENDING=§ePending MOD_FORBIDDEN=§eForbidden
MOD_FORBIDDEN=§cForbidden MOD_AUTOBAN=§cAutoban
MOD_YT=§5YT Only MOD_YT=§5YT Only
MOD_ITEM_BACK=§7Back MOD_ITEM_BACK=§7Back