SteamWar/BungeeCore
Archiviert
13
2

wip ingame gui
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
zOnlyKroks 2023-01-06 22:11:25 +01:00
Ursprung dc234b2b33
Commit c59da8ff49
3 geänderte Dateien mit 102 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -1,46 +1,111 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.Mod;
import de.steamwar.bungeecore.sql.Statement;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.command.SWCommand;
import jdk.internal.net.http.common.Pair;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class ModCommand extends SWCommand {
private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND ModType = ?");
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 = ?");
private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?");
private static final Statement getAll = new Statement("SELECT * FROM Mods WHERE ModType = 0 ORDER BY ModName DESC LIMIT ?, ?");
public ModCommand() {
super("mod", "bungeecore.softreload", "mods");
}
@Register(value = "a")
public void genericCommand(ProxiedPlayer p) {
new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> {
SWInventory swInventory = new SWInventory(p,5,"Mod Changer");
String modName = element.modName;
int modPlatform = element.platform.get();
swInventory.addItem(0,new SWItem("GRAY_CONCRETE","Unclassified"), (click1 -> set.update(0,modName,modPlatform)));
swInventory.addItem(1,new SWItem("GREEN_CONCRETE", "Allowed"), (click1 -> set.update(1,modName,modPlatform)));
swInventory.addItem(2,new SWItem("YELLOW_CONCRETE", "Pending"),(click1 -> set.update(2,modName,modPlatform)));
swInventory.addItem(3,new SWItem("RED_CONCRETE","Forbidden"),(click1 -> set.update(3,modName,modPlatform)));
swInventory.addItem(4,new SWItem("PURPLE_CONCRETE", "YT_only"),(click1 -> set.update(4,modName,modPlatform)));
swInventory.open();
},page -> getMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList())).open();
}
private SWItem getModItem(ModEntry modEntry) {
SWItem item = new SWItem("NAME_TAG", modEntry.modName);
item.addLore(modEntry.platform.name());
return item;
}
public List<ModEntry> getMods(int page,int elementsPerPage) {
return 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);
}
@Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE")
public void set(ProxiedPlayer p,String modName,String platform,Integer newModType) {
boolean modExists = get.select(ResultSet::next,modName,Mod.Platform.valueOf(platform));
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);
if(!modExists) {
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName);
return;
}
set.update(newModType,modName);
set.update(newModType.getValue(),modName,modPlatform);
Message.send("MOD_CHANGED_TYPE",p,modName,newModType);
Message.send("MOD_CHANGED_TYPE",p,modName,newModType.name(),newModType);
}
@Register()
@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)));
}
private int getModType(String modName,Mod.Platform modPlatform) {
return get.select(rs -> {
if(rs.next()) {
return rs.getInt("ModType");
} else {
return 0;
}
},modName,modPlatform);
}
@Register(value = {"next"})
public void next(ProxiedPlayer p) {
Pair<String ,Integer> foundMod = findFirst.select(rs -> {
if(rs.next()) {
String name = rs.getString("ModName");
Integer platform = rs.getInt("Platform");
return new Pair<>(name,platform);
int platform = rs.getInt("Platform");
return new ImmutablePair<>(name,platform);
}
return null;
});
@ -50,6 +115,16 @@ public class ModCommand extends SWCommand {
return;
}
Message.send("MOD_FOUND_NEXT_MOD",p,foundMod.first, Mod.Platform.getByValue(foundMod.second));
Message.send("MOD_FOUND_NEXT_MOD",p,foundMod.getKey(), Mod.Platform.getByValue(foundMod.getValue()));
}
private class ModEntry {
private final String modName;
private final Mod.Platform platform;
public ModEntry(String modName, Mod.Platform platform) {
this.modName = modName;
this.platform = platform;
}
}
}

Datei anzeigen

@ -19,6 +19,8 @@
package de.steamwar.bungeecore.sql;
import lombok.Getter;
public class Mod {
private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?");
@ -72,15 +74,13 @@ public class Mod {
return value;
}
public static String getByValue(int val) {
String platform;
public static Platform getByValue(int val) {
switch (val) {
case 0 : platform = "Forge";
case 1: platform = "Labymod";
case 2: platform = "Fabric";
default: platform = "";
case 0 : return FORGE;
case 1: return LABYMOD;
case 2: return FABRIC;
default: return null;
}
return platform;
}
}
@ -102,6 +102,7 @@ public class Mod {
ModType(int value){
this.value = value;
}
@Getter
int value;
}
}

Datei anzeigen

@ -658,8 +658,11 @@ ADVENT_CALENDAR_MESSAGE_HOVER=§eClick to open!
ADVENT_CALENDAR_OPEN=§7You got §e{0} §7from the advent calendar!
#Mod Command
MOD_COMMAND_SET_USAGE=§7/mod [mod name] [ModType 1-4]
MOD_CHANGED_TYPE=§7Successfully reclassified mod {0} to type {1}!
MOD_COMMAND_SET_USAGE=§7/mod set [mod name] [platform] [ModType 1-4]
MOD_COMMAND_GET_USAGE=§7/mod get [mod name] [platform]
MOD_CHANGED_TYPE=§7Successfully reclassified mod {0} on platform {1} to type {2}!
MOD_NO_MORE_UNCLASSIFIED_MODS=§7No more unclassified mods found in databank!
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_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"