Archiviert
1
0

Finalise GUI and implement item names (not yet final)

Dieser Commit ist enthalten in:
zOnlyKroks 2023-01-08 14:21:29 +01:00
Ursprung 60f6a9cb4c
Commit 69aa98e82e
3 geänderte Dateien mit 106 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,6 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.inventory.SWItem;
@ -7,6 +8,9 @@ import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.command.SWCommand;
import lombok.Getter;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@ -14,43 +18,72 @@ import org.apache.commons.lang3.tuple.Pair;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class ModCommand extends SWCommand {
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 get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?");
private static final Statement getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?");
public ModCommand() {
super("mod", "bungeecore.softreload", "mods");
}
private static FilterType filtertype = FilterType.ALL;
@Register()
public void genericCommand(ProxiedPlayer p) {
openGui(p);
}
private void openGui(ProxiedPlayer p) {
SWStreamInv<ModEntry> swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> {
openGradingWindow(p,element);
},page -> getMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()));
SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_GUI",p));
String modName = element.modName;
int modPlatform = element.platform.get();
swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> Mod.set.update(0, modName, modPlatform)));
swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> Mod.set.update(1, modName, modPlatform)));
swInventory.addItem(4, new SWItem(Message.parse("MOD_PENDING",p), 11), (click1 -> Mod.set.update(2, modName, modPlatform)));
swInventory.addItem(5, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), (click1 -> Mod.set.update(3, modName, modPlatform)));
swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> Mod.set.update(4, modName, modPlatform)));
swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> {
swInventory.close();
openGui(p);
});
swInventory.open();
},page -> {
if(filtertype == FilterType.ALL) {
return getAllMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList());
}else {
return getAllModsFiltered(page,45,filtertype.value).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList());
}
});
swStreamInv.addItem(52,new SWItem("NAME_TAG","Filter"), click -> {
swStreamInv.close();
openFilterGui(p);
});
swStreamInv.open();
}
private void openGradingWindow(ProxiedPlayer p,ModEntry element) {
SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_GUI",p));
private void openFilterGui(ProxiedPlayer p) {
SWInventory inv = new SWInventory(p, 9, "Filter");
String modName = element.modName;
int modPlatform = element.platform.get();
inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> filtertype = FilterType.UNCLASSIFIED);
inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> filtertype = FilterType.ALLOWED);
inv.addItem(3, new SWItem(Message.parse("MOD_PENDING",p), 11),click -> filtertype = FilterType.PENDING);
inv.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), click -> filtertype = FilterType.FORBIDDEN);
inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> filtertype = FilterType.YT);
inv.addItem(6, new SWItem(Message.parse("MOD_ALL",p),15), click -> filtertype = FilterType.ALL);
swInventory.addItem(2,new SWItem("GRAY_CONCRETE","Unclassified"), (click1 -> set.update(0,modName,modPlatform)));
swInventory.addItem(3,new SWItem("GREEN_CONCRETE", "Allowed"), (click1 -> set.update(1,modName,modPlatform)));
swInventory.addItem(4,new SWItem("YELLOW_CONCRETE", "Pending"),(click1 -> set.update(2,modName,modPlatform)));
swInventory.addItem(5,new SWItem("RED_CONCRETE","Forbidden"),(click1 -> set.update(3,modName,modPlatform)));
swInventory.addItem(6,new SWItem("PURPLE_CONCRETE", "YT_only"),(click1 -> set.update(4,modName,modPlatform)));
inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> {
inv.close();
openGui(p);
});
swInventory.open();
inv.open();
}
private SWItem getModItem(ModEntry modEntry) {
@ -61,51 +94,60 @@ public class ModCommand extends SWCommand {
return item;
}
public List<ModEntry> getMods(int page,int elementsPerPage) {
return getAll.select(rs -> {
public List<ModEntry> getAllMods(int page,int elementsPerPage) {
return Mod.getAll.select(rs -> {
List<ModEntry> f = new ArrayList<>();
while(rs.next()){
ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform")));
System.out.println(entry.modName);
f.add(entry);
}
return f;
}, page * elementsPerPage, elementsPerPage);
}
public List<ModEntry> getAllModsFiltered(int page,int elementsPerPage, int filter) {
return Mod.getAllFiltered.select(rs -> {
List<ModEntry> f = new ArrayList<>();
while(rs.next()){
ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform")));
f.add(entry);
}
return f;
},filter, page * elementsPerPage, elementsPerPage);
}
@Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE")
public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) {
int modPlatform = platform.get();
boolean modExists = get.select(ResultSet::next,modName,modPlatform);
boolean modExists = Mod.get.select(ResultSet::next,modName,modPlatform);
if(!modExists) {
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName);
return;
}
set.update(newModType.getValue(),modName,modPlatform);
Mod.set.update(newModType.getValue(),modName,modPlatform);
Message.send("MOD_CHANGED_TYPE",p,modName,newModType.name(),newModType);
}
@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.Platform.getByValue(getModType(modName,platform)));
Message.send("MOD_COMMAND_INFO",p,modName,platform.name(),Mod.ModType.valueOf(getModType(modName,platform.get())).name());
}
private int getModType(String modName,Mod.Platform modPlatform) {
return get.select(rs -> {
private int getModType(String modName,int modPlatform) {
return Mod.get.select(rs -> {
if(rs.next()) {
return rs.getInt("ModType");
} else {
return 0;
}
return 0;
},modName,modPlatform);
}
@Register(value = {"next"})
public void next(ProxiedPlayer p) {
Pair<String ,Integer> foundMod = findFirst.select(rs -> {
Pair<String ,Integer> foundMod = Mod.findFirst.select(rs -> {
if(rs.next()) {
String name = rs.getString("ModName");
int platform = rs.getInt("Platform");
@ -119,7 +161,22 @@ public class ModCommand extends SWCommand {
return;
}
Message.send("MOD_FOUND_NEXT_MOD",p,foundMod.getKey(), Mod.Platform.getByValue(foundMod.getValue()));
Message.send("MOD_FOUND_NEXT_MOD",p,"MOD_OPEN_GUI",new ClickEvent(ClickEvent.Action.RUN_COMMAND,""),foundMod.getKey(),Mod.Platform.getByValue(foundMod.getValue()));
}
private enum FilterType {
ALL(-1),
UNCLASSIFIED(0),
ALLOWED(1),
PENDING(2),
FORBIDDEN(3),
YT(4);
final int value;
FilterType(int value) {
this.value = value;
}
}
private class ModEntry {

Datei anzeigen

@ -23,9 +23,16 @@ import lombok.Getter;
public class Mod {
private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?");
public static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?");
private static final Statement insert = new Statement("INSERT INTO Mods (ModName, Platform) VALUES (?, ?)");
public static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND Platform = ?");
public static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE ModType = 0 LIMIT 1");
public static final Statement getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?");
public static final Statement getAllFiltered = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?");
private final String modName;
private final Platform platform;
private final ModType modType;
@ -91,7 +98,7 @@ public class Mod {
RED(3),
YOUTUBER_ONLY(4);
static ModType valueOf(int value){
public static ModType valueOf(int value){
for(ModType mt : values()){
if(value == mt.value)
return mt;

Datei anzeigen

@ -666,4 +666,12 @@ MOD_FOUND_NEXT_MOD=§7Next unclassified mod is {0}!
MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} on platform {1} was§c not §7found in the database!
MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}.
MOD_COMMAND_GUI_TITLE=§7Unclassified Mods
MOD_COMMAND_GUI=§7Mod Type Changer
MOD_COMMAND_GUI=§7Mod Type Changer
MOD_OPEN_GUI=§7Open Gui
MOD_UNCLASSIFIED=Unclassified
MOD_ALLOWED=Allowed
MOD_PENDING=Pending
MOD_FORBIDDEN=Forbidden
MOD_YT=YT Only
MOD_ALL=All
MOD_ITEM_BACK=Back