Finalise GUI and implement item names (not yet final)
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
60f6a9cb4c
Commit
69aa98e82e
@ -1,5 +1,6 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
import de.steamwar.bungeecore.inventory.SWInventory;
|
||||||
import de.steamwar.bungeecore.inventory.SWItem;
|
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.inventory.SWStreamInv;
|
||||||
import de.steamwar.bungeecore.sql.*;
|
import de.steamwar.bungeecore.sql.*;
|
||||||
import de.steamwar.command.SWCommand;
|
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 net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
@ -14,43 +18,72 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ModCommand extends SWCommand {
|
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() {
|
public ModCommand() {
|
||||||
super("mod", "bungeecore.softreload", "mods");
|
super("mod", "bungeecore.softreload", "mods");
|
||||||
}
|
}
|
||||||
|
private static FilterType filtertype = FilterType.ALL;
|
||||||
|
|
||||||
@Register()
|
@Register()
|
||||||
public void genericCommand(ProxiedPlayer p) {
|
public void genericCommand(ProxiedPlayer p) {
|
||||||
SWStreamInv<ModEntry> swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> {
|
openGui(p);
|
||||||
openGradingWindow(p,element);
|
|
||||||
},page -> getMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()));
|
|
||||||
|
|
||||||
swStreamInv.open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openGradingWindow(ProxiedPlayer p,ModEntry element) {
|
private void openGui(ProxiedPlayer p) {
|
||||||
|
SWStreamInv<ModEntry> swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> {
|
||||||
SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_GUI",p));
|
SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_GUI",p));
|
||||||
|
|
||||||
String modName = element.modName;
|
String modName = element.modName;
|
||||||
int modPlatform = element.platform.get();
|
int modPlatform = element.platform.get();
|
||||||
|
|
||||||
swInventory.addItem(2,new SWItem("GRAY_CONCRETE","Unclassified"), (click1 -> set.update(0,modName,modPlatform)));
|
swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> Mod.set.update(0, modName, modPlatform)));
|
||||||
swInventory.addItem(3,new SWItem("GREEN_CONCRETE", "Allowed"), (click1 -> set.update(1,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("YELLOW_CONCRETE", "Pending"),(click1 -> set.update(2,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("RED_CONCRETE","Forbidden"),(click1 -> set.update(3,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("PURPLE_CONCRETE", "YT_only"),(click1 -> set.update(4,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();
|
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 openFilterGui(ProxiedPlayer p) {
|
||||||
|
SWInventory inv = new SWInventory(p, 9, "Filter");
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> {
|
||||||
|
inv.close();
|
||||||
|
openGui(p);
|
||||||
|
});
|
||||||
|
|
||||||
|
inv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SWItem getModItem(ModEntry modEntry) {
|
private SWItem getModItem(ModEntry modEntry) {
|
||||||
@ -61,51 +94,60 @@ public class ModCommand extends SWCommand {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ModEntry> getMods(int page,int elementsPerPage) {
|
public List<ModEntry> getAllMods(int page,int elementsPerPage) {
|
||||||
return getAll.select(rs -> {
|
return Mod.getAll.select(rs -> {
|
||||||
List<ModEntry> f = new ArrayList<>();
|
List<ModEntry> f = new ArrayList<>();
|
||||||
while(rs.next()){
|
while(rs.next()){
|
||||||
ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform")));
|
ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform")));
|
||||||
System.out.println(entry.modName);
|
|
||||||
f.add(entry);
|
f.add(entry);
|
||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}, page * elementsPerPage, elementsPerPage);
|
}, 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")
|
@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) {
|
||||||
int modPlatform = platform.get();
|
int modPlatform = platform.get();
|
||||||
boolean modExists = get.select(ResultSet::next,modName,modPlatform);
|
boolean modExists = Mod.get.select(ResultSet::next,modName,modPlatform);
|
||||||
|
|
||||||
if(!modExists) {
|
if(!modExists) {
|
||||||
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName);
|
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
set.update(newModType.getValue(),modName,modPlatform);
|
Mod.set.update(newModType.getValue(),modName,modPlatform);
|
||||||
|
|
||||||
Message.send("MOD_CHANGED_TYPE",p,modName,newModType.name(),newModType);
|
Message.send("MOD_CHANGED_TYPE",p,modName,newModType.name(),newModType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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.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) {
|
private int getModType(String modName,int modPlatform) {
|
||||||
return get.select(rs -> {
|
return Mod.get.select(rs -> {
|
||||||
if(rs.next()) {
|
if(rs.next()) {
|
||||||
return rs.getInt("ModType");
|
return rs.getInt("ModType");
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
},modName,modPlatform);
|
},modName,modPlatform);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = {"next"})
|
@Register(value = {"next"})
|
||||||
public void next(ProxiedPlayer p) {
|
public void next(ProxiedPlayer p) {
|
||||||
Pair<String ,Integer> foundMod = findFirst.select(rs -> {
|
Pair<String ,Integer> foundMod = Mod.findFirst.select(rs -> {
|
||||||
if(rs.next()) {
|
if(rs.next()) {
|
||||||
String name = rs.getString("ModName");
|
String name = rs.getString("ModName");
|
||||||
int platform = rs.getInt("Platform");
|
int platform = rs.getInt("Platform");
|
||||||
@ -119,7 +161,22 @@ public class ModCommand extends SWCommand {
|
|||||||
return;
|
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 {
|
private class ModEntry {
|
||||||
|
@ -23,9 +23,16 @@ import lombok.Getter;
|
|||||||
|
|
||||||
public class Mod {
|
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 (?, ?)");
|
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 String modName;
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
private final ModType modType;
|
private final ModType modType;
|
||||||
@ -91,7 +98,7 @@ public class Mod {
|
|||||||
RED(3),
|
RED(3),
|
||||||
YOUTUBER_ONLY(4);
|
YOUTUBER_ONLY(4);
|
||||||
|
|
||||||
static ModType valueOf(int value){
|
public static ModType valueOf(int value){
|
||||||
for(ModType mt : values()){
|
for(ModType mt : values()){
|
||||||
if(value == mt.value)
|
if(value == mt.value)
|
||||||
return mt;
|
return mt;
|
||||||
|
@ -667,3 +667,11 @@ MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} on platform {1} was§c not §7f
|
|||||||
MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}.
|
MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}.
|
||||||
MOD_COMMAND_GUI_TITLE=§7Unclassified Mods
|
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
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren