Archiviert
1
0

Fix Bugs and code problems

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();
}
public void updateAndCloseGui(Mod.ModType modType,String modName,Mod.Platform modPlatform,SWInventory toClose,ProxiedPlayer p) {
Mod.getOrCreate(modName,modPlatform).setModType(modType);
public void updateAndCloseGui(Mod.ModType modType, Mod mod, SWInventory toClose, ProxiedPlayer p) {
mod.setModType(modType);
toClose.close();
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(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(4, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED));
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_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(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) {
SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p));
String modName = element.getModName();
Mod.Platform modPlatform = element.getPlatform();
swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,modName,modPlatform,swInventory,p)));
swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,modName,modPlatform,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(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,element,swInventory,p)));
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(5, new SWItem(Message.parse("MOD_AUTOBAN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,element,swInventory,p)));
swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,element,swInventory,p)));
swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> {
swInventory.close();
@ -116,27 +113,30 @@ public class ModCommand extends SWCommand {
@Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE")
public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) {
boolean modExists = Mod.doesModExist(modName,platform);
if(!modExists) {
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName);
Mod mod = Mod.get(modName, platform);
if(mod == null) {
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName, platform.name());
return;
}
Mod.getOrCreate(modName,platform).setModType(newModType);
mod.setModType(newModType);
Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name());
}
@Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE")
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"})
public void next(ProxiedPlayer p) {
Mod mod = Mod.findFirstMod();
if(mod == null) {
Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p);
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 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 getAllFiltered = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?");
private static final Statement getPageOfType = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?");
private final String modName;
private final Platform platform;
@ -49,51 +47,46 @@ public class Mod {
}
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"));
this(resultSet.getString("ModName"), Mod.Platform.values()[resultSet.getInt("Platform")], ModType.values()[resultSet.getInt("ModType")]);
}
public static Mod getOrCreate(String modName, Platform platform){
Mod mod = get.select(rs -> {
public static Mod get(String name, Platform platform) {
return get.select(rs -> {
if(rs.next())
return new Mod(modName, platform, ModType.valueOf(rs.getInt("ModType")));
return new Mod(rs);
return null;
}, modName, platform.value);
}, name, platform.ordinal());
}
public static Mod getOrCreate(String name, Platform platform) {
Mod mod = get(name, platform);
if(mod != null)
return mod;
insert.update(modName, platform.value);
return new Mod(modName, platform, ModType.UNKLASSIFIED);
}
public static ModType getModType(String modName,Mod.Platform platform) {
return getOrCreate(modName,platform).modType;
insert.update(name, platform.ordinal());
return new Mod(name, platform, ModType.UNKLASSIFIED);
}
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) {
return Mod.getAllFiltered.select(rs -> {
return Mod.getPageOfType.select(rs -> {
List<Mod> f = new ArrayList<>();
while(rs.next()){
Mod entry = new Mod(rs);
f.add(entry);
}
while(rs.next())
f.add(new Mod(rs));
return f;
},filter.value, page * elementsPerPage, elementsPerPage);
},filter.ordinal(), page * elementsPerPage, elementsPerPage);
}
public static Mod findFirstMod() {
return findFirst.select(rs -> {
String name = rs.getString("ModName");
int platform = rs.getInt("Platform");
return new Mod(name,Platform.valueOf(platform),ModType.UNKLASSIFIED);
if(rs.next())
return new Mod(rs);
return null;
});
}
@ -110,48 +103,22 @@ public class Mod {
}
public enum Platform{
FORGE(0),
LABYMOD(1),
FABRIC(2);
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;
}
FORGE,
LABYMOD,
FABRIC
}
public enum ModType {
UNKLASSIFIED(0,"7"),
GREEN(1,"a"),
YELLOW(2,"e"),
RED(3,"c"),
YOUTUBER_ONLY(4,"6");
UNKLASSIFIED("7"),
GREEN("a"),
YELLOW("e"),
RED("c"),
YOUTUBER_ONLY("6");
static ModType valueOf(int value){
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;
ModType(String colorcode) {
this.colorcode = colorcode;
}
int value;
String colorcode;
private final String colorcode;
public String getColorCode() {
return colorcode;

Datei anzeigen

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