Archiviert
1
0

Improve Bungee GUI

Add SWListInv for Schem GUI
Dieser Commit ist enthalten in:
Chaoscaot 2020-09-20 12:02:56 +02:00
Ursprung 51db5a8ad4
Commit 7559012a9b
23 geänderte Dateien mit 579 neuen und 318 gelöschten Zeilen

Datei anzeigen

@ -20,7 +20,8 @@
package de.steamwar.bungeecore;
import de.steamwar.bungeecore.commands.*;
import de.steamwar.bungeecore.coms.receiver.PacketHandler;
import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.comms.SpigotReceiver;
import de.steamwar.bungeecore.listeners.*;
import de.steamwar.bungeecore.listeners.mods.Fabric;
import de.steamwar.bungeecore.listeners.mods.Forge;
@ -43,9 +44,7 @@ import net.md_5.bungee.config.YamlConfiguration;
import org.yaml.snakeyaml.error.YAMLException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.MalformedInputException;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
@ -75,7 +74,6 @@ public class BungeeCore extends Plugin {
public void onEnable(){
getProxy().registerChannel("sw:bridge");
getProxy().registerChannel("sw:return");
setInstance(this);
loadConfig();
@ -134,7 +132,7 @@ public class BungeeCore extends Plugin {
new EventStarter();
new Broadcaster();
new SessionManager();
new PacketHandler();
new SpigotReceiver();
new TablistManager();

Datei anzeigen

@ -1,7 +1,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.coms.packets.inventory.SWInventory;
import de.steamwar.bungeecore.coms.packets.inventory.SWItem;
import de.steamwar.bungeecore.comms.packets.inventory.SWInventory;
import de.steamwar.bungeecore.comms.packets.inventory.SWItem;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -16,7 +16,7 @@ public class TestCommand extends BasicCommand {
if(!(commandSender instanceof ProxiedPlayer))
return;
SWInventory inventory = new SWInventory((ProxiedPlayer) commandSender, 3*9, "Test Inventory");
SWItem item = new SWItem("DIRT", 13, "§e§lTest Item");
SWItem item = new SWItem("DIRT1", 13, "§e§lTest Item");
item.setSkullOwner(commandSender.getName());
for (ProxiedPlayer player:
((ProxiedPlayer) commandSender).getServer().getInfo().getPlayers()) {

Datei anzeigen

@ -1,4 +1,4 @@
package de.steamwar.bungeecore.coms.sender;
package de.steamwar.bungeecore.comms;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
@ -7,23 +7,27 @@ import net.md_5.bungee.api.connection.Server;
import java.io.ByteArrayOutputStream;
public class PacketSender {
public abstract class BungeePacket {
public static void sendPacket(Packet packet, ProxiedPlayer player) {
public void send(Server server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(packet.getName());
out.writeInt(getId());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
packet.writeVars(out);
writeVars(out);
out.writeUTF(outputStream.toByteArray().toString());
server.sendData("sw:bridge", out.toByteArray());
}
public void send(ProxiedPlayer player) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(getId());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writeVars(out);
out.writeUTF(outputStream.toByteArray().toString());
player.getServer().sendData("sw:bridge", out.toByteArray());
}
public static void sendPacket(Packet packet, Server server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(packet.getName());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
packet.writeVars(out);
out.writeUTF(outputStream.toByteArray().toString());
server.sendData("sw:bridge", out.toByteArray());
}
public abstract int getId();
public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput);
}

Datei anzeigen

@ -0,0 +1,8 @@
package de.steamwar.bungeecore.comms;
import com.google.common.io.ByteArrayDataInput;
public interface SpigotHandler {
void handle(ByteArrayDataInput byteArrayDataInput);
}

Datei anzeigen

@ -0,0 +1,37 @@
package de.steamwar.bungeecore.comms;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.listeners.BasicListener;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.event.EventHandler;
import java.util.HashMap;
import java.util.Map;
public class SpigotReceiver extends BasicListener {
private static final Map<Integer, SpigotHandler> handlerMap = new HashMap<>();
@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
return;
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
int handler = in.readInt();
handlerMap.get(handler).handle(in);
}
public static void registerHandler(int id, SpigotHandler handler) {
handlerMap.put(id, handler);
}
public static void registerHandler(String name, SpigotHandler handler) {
handlerMap.put(name.hashCode(), handler);
}
static {
registerHandler("InventoryCallback", new InventoryCallbackHandler());
}
}

Datei anzeigen

@ -0,0 +1,33 @@
package de.steamwar.bungeecore.comms.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.comms.packets.inventory.InvCallback;
import de.steamwar.bungeecore.comms.packets.inventory.SWInventory;
import de.steamwar.bungeecore.sql.SteamwarUser;
import java.util.HashMap;
import java.util.Map;
public class InventoryCallbackHandler implements SpigotHandler {
public static final Map<Integer, SWInventory> inventoryHashMap = new HashMap<>();
@Override
public void handle(ByteArrayDataInput byteArrayDataInput) {
SteamwarUser owner = SteamwarUser.get(byteArrayDataInput.readInt());
CallbackType type = CallbackType.valueOf(byteArrayDataInput.readUTF());
if(type == CallbackType.CLICK) {
int pos = byteArrayDataInput.readInt();
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(byteArrayDataInput.readUTF());
inventoryHashMap.get(owner.getId()).handleCallback(clickType, pos);
}else if(type == CallbackType.CLOSE) {
inventoryHashMap.get(owner.getId()).handleClose();
}
}
public enum CallbackType {
CLICK,
CLOSE,
}
}

Datei anzeigen

@ -1,21 +1,22 @@
package de.steamwar.bungeecore.coms.packets;
package de.steamwar.bungeecore.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.coms.sender.Packet;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class CloseInventoryPacket extends Packet {
public class CloseInventoryPacket extends BungeePacket {
ProxiedPlayer player;
@Override
public String getName() {
return "InvClose";
public int getId() {
return "CloseInventory".hashCode();
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeUTF(player.getUniqueId().toString());
byteArrayDataOutput.writeInt(SteamwarUser.get(player).getId());
}
public CloseInventoryPacket setPlayer(ProxiedPlayer player) {

Datei anzeigen

@ -0,0 +1,51 @@
package de.steamwar.bungeecore.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import de.steamwar.bungeecore.comms.packets.inventory.SWItem;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.HashMap;
public class InventoryPacket extends BungeePacket {
String title;
int player;
int size;
HashMap<Integer, SWItem> items;
public InventoryPacket(int size, String title, ProxiedPlayer player) {
items = new HashMap<>();
this.title = title;
this.size = size;
this.player = SteamwarUser.get(player).getId();
}
@Override
public int getId() {
return "InventoryHandler".hashCode();
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
JsonObject object = new JsonObject();
object.addProperty("id", player);
object.addProperty("title", title);
object.addProperty("size", size);
object.addProperty("itemcount", items.size());
JsonArray array = new JsonArray();
for (int i = 0; i < size; i++) {
if(items.get(i) != null)
array.add(items.get(i).writeToString());
}
object.add("items", array);
byteArrayDataOutput.writeUTF(object.toString());
}
public void setItem(int index, SWItem item) {
items.put(index, item);
}
}

Datei anzeigen

@ -0,0 +1,24 @@
package de.steamwar.bungeecore.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
public class PingPacket extends BungeePacket {
int id;
@Override
public int getId() {
return "PingHandler".hashCode();
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(id);
}
public PingPacket setUser(int id) {
this.id = id;
return this;
}
}

Datei anzeigen

@ -1,4 +1,4 @@
package de.steamwar.bungeecore.coms.packets.inventory;
package de.steamwar.bungeecore.comms.packets.inventory;
public interface InvCallback {
@ -19,9 +19,6 @@ public interface InvCallback {
CREATIVE,
UNKNOWN;
private ClickType() {
}
public boolean isKeyboardClick() {
return this == NUMBER_KEY || this == DROP || this == CONTROL_DROP;
}

Datei anzeigen

@ -0,0 +1,90 @@
package de.steamwar.bungeecore.comms.packets.inventory;
import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
import de.steamwar.bungeecore.comms.packets.InventoryPacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.HashMap;
import java.util.Map;
public class SWInventory {
private final Map<Integer, SWItem> itemMap;
private InvCallback close;
private ProxiedPlayer player;
private int size;
private String title;
public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) {
itemMap = new HashMap<>();
InventoryCallbackHandler.inventoryHashMap.put(SteamwarUser.get(proxiedPlayer).getId(), this);
this.player = proxiedPlayer;
this.size = size;
this.title = title;
}
public void addItem(SWItem item) {
itemMap.put(item.getPosition(), item);
}
public void addItem(int position, SWItem item) {
itemMap.put(position, item);
}
public void addItem(int pos, SWItem item, InvCallback callback) {
item.setCallback(callback);
itemMap.put(pos, item);
}
public void addItem(int pos, SWItem item, String name, InvCallback callback) {
item.setCallback(callback);
itemMap.put(pos, item);
}
public void removeItem(SWItem item) {
itemMap.remove(item.getPosition());
}
public void removeItem(int position) {
itemMap.remove(position);
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public void setTitle(String title) {
this.title = title;
}
public void setCallback(int pos, InvCallback callback) {
itemMap.get(pos).setCallback(callback);
}
public void handleCallback(InvCallback.ClickType type, int pos) {
itemMap.get(pos).getCallback().clicked(type);
}
public void handleClose() {
if(close != null)
close.clicked(null);
}
public void open() {
InventoryPacket inv = new InventoryPacket(size, title, player);
for (Map.Entry<Integer, SWItem> entry : itemMap.entrySet()) {
inv.setItem(entry.getKey(), entry.getValue());
}
inv.send(player);
}
public void close() {
new CloseInventoryPacket().setPlayer(player).send(player);
}
}

Datei anzeigen

@ -1,51 +1,50 @@
package de.steamwar.bungeecore.coms.packets.inventory;
package de.steamwar.bungeecore.comms.packets.inventory;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.List;
public class SWItem {
String material, title, skullOwner;
boolean enchanted, hideAttributes;
int position;
List<String> lore;
InvCallback callback;
private String material, title, skullOwner;
private boolean enchanted, hideAttributes;
private int position;
private List<String> lore;
private InvCallback callback;
private int color;
public SWItem(String material, int position, String title) {
this.material = material.toUpperCase();
lore = new ArrayList<>();
this.position = position;
this.title = title;
color = 0;
}
private SWItem(String json) {
JsonObject object = new JsonParser().parse(json).getAsJsonObject();
material = object.get("material").getAsString();
position = object.get("position").getAsInt();
title = object.get("title").getAsString();
if(object.has("skullOwner")) {
skullOwner = object.get("skullOwner").getAsString();
}
if(object.has("enchanted"))
enchanted = true;
if(object.has("hideAttributes"))
hideAttributes = true;
if(object.has("lore")) {
List<String> lore = new ArrayList<>();
JsonArray array = object.getAsJsonArray("lore");
array.forEach(jsonElement -> lore.add(jsonElement.getAsString()));
this.lore = lore;
}
public SWItem(int position, String title, int color) {
this.material = "DYE";
lore = new ArrayList<>();
this.position = position;
this.title = title;
this.color = color;
}
public static SWItem getSkull(String skullOwner) {
SWItem item = new SWItem("SKULL", 1, skullOwner);
item.setSkullOwner(skullOwner);
return item;
}
public void setCallback(InvCallback callback) {
this.callback = callback;
}
public void setColor(int color) {
this.color = color;
}
public InvCallback getCallback() {
return callback;
}
@ -82,11 +81,19 @@ public class SWItem {
this.hideAttributes = hideAttributes;
}
public int getPosition() {
return position;
}
public void setName(String name) {
title = name;
}
public void addLore(String lore) {
this.lore.add(lore);
}
public String writeToString() {
public JsonObject writeToString() {
JsonObject object = new JsonObject();
object.addProperty("material", material);
object.addProperty("position", position);
@ -97,6 +104,8 @@ public class SWItem {
object.addProperty("enchanted", true);
if(hideAttributes)
object.addProperty("hideAttributes", true);
if(color != 0)
object.addProperty("color", color);
if(lore != null) {
JsonArray array = new JsonArray();
for (String lores:
@ -106,11 +115,7 @@ public class SWItem {
object.add("lore", array);
}
return object.toString();
}
public static SWItem getFromJson(String json) {
return new SWItem(json);
return object;
}
@Override

Datei anzeigen

@ -0,0 +1,126 @@
package de.steamwar.bungeecore.comms.packets.inventory;
import de.steamwar.bungeecore.sql.Schematic;
import de.steamwar.bungeecore.sql.SchematicType;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.*;
public class SWListInv<T> extends SWInventory {
private ListCallback<T> callback;
private List<SWListEntry<T>> elements;
private int page;
public SWListInv(ProxiedPlayer p, String t, List<SWListEntry<T>> l, ListCallback<T> c){
super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
callback = c;
elements = l;
page = 0;
}
@Override
public void open(){
setCallback(-999, (InvCallback.ClickType click) -> close());
if(elements.size() > 54){
if(page != 0)
addItem(45, new SWItem(45, "§eSeite zurück", 10), (InvCallback.ClickType click) -> {
page--;
open();
});
else
addItem(45, new SWItem(45, "§7Seite zurück", 8), (InvCallback.ClickType click) -> {});
if(page < elements.size()/45)
addItem(53, new SWItem( 53, "§eSeite vor", 10), "§eSeite vor", (InvCallback.ClickType click) -> {
page++;
open();
});
else
addItem(53, new SWItem(53, "§eSeite vor", 8), (InvCallback.ClickType click) -> {});
}
int ipageLimit = elements.size() - page*45;
if(ipageLimit > 45 && elements.size() > 54){
ipageLimit = 45;
}
int i = page*45;
for(int ipage=0; ipage < ipageLimit; ipage++ ){
SWItem e = elements.get(i).getItem();
final int pos = i;
addItem(ipage, e);
setCallback(ipage, (InvCallback.ClickType click) -> callback.clicked(click, elements.get(pos).getObject()));
i++;
}
super.open();
}
public void setCallback(ListCallback<T> c){
callback = c;
}
public interface ListCallback<T>{
void clicked(InvCallback.ClickType click, T element);
}
public static List<SWListEntry<UUID>> createPlayerList(UUID without){
List<SWListEntry<UUID>> onlinePlayers = new ArrayList<>();
for(ProxiedPlayer player : BungeeCord.getInstance().getPlayer(without).getServer().getInfo().getPlayers()){
if(without != null && player.getUniqueId().equals(without))
continue;
onlinePlayers.add(new SWListEntry<>(SWItem.getSkull(player.getName()), player.getUniqueId()));
}
return onlinePlayers;
}
public static List<SWListEntry<UUID>> createGlobalPlayerList(UUID without){
List<SWListEntry<UUID>> onlinePlayers = new ArrayList<>();
for(ProxiedPlayer player : BungeeCord.getInstance().getPlayers()){
if(without != null && player.getUniqueId().equals(without))
continue;
onlinePlayers.add(new SWListEntry<>(SWItem.getSkull(player.getName()), player.getUniqueId()));
}
return onlinePlayers;
}
public static List<SWListEntry<Schematic>> getSchemList(SchematicType type, int steamwarUserId){
List<SWListEntry<Schematic>> schemList = new ArrayList<>();
List<Schematic> schems;
if(type == null)
schems = Schematic.getSchemsAccessibleByUser(steamwarUserId);
else
schems = Schematic.getSchemsOfType(steamwarUserId, type);
for(Schematic s : schems){
String m;
if(s.getSchemItem().isEmpty())
m = "CAULDRON_ITEM";
else
m = s.getSchemItem();
SWItem item = new SWItem(m, 0, "§e" + s.getSchemName());
schemList.add(new SWListEntry<>(item, s));
}
return schemList;
}
public static class SWListEntry<T>{
final SWItem item;
final T object;
public SWListEntry(SWItem item, T object){
this.item = item;
this.object = object;
}
public SWItem getItem(){
return item;
}
public T getObject(){
return object;
}
}
}

Datei anzeigen

@ -1,38 +0,0 @@
package de.steamwar.bungeecore.coms.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.coms.packets.inventory.InvCallback;
import de.steamwar.bungeecore.coms.packets.inventory.SWInventory;
import de.steamwar.bungeecore.coms.packets.inventory.SWItem;
import de.steamwar.bungeecore.coms.receiver.Handler;
import java.util.HashMap;
import java.util.Map;
public class InventoryCallbackHandler extends Handler {
public static final Map<String, SWInventory> inventoryHashMap = new HashMap<>();
@Override
protected String getName() {
return "InventoryCallback";
}
@Override
public void handle(ByteArrayDataInput byteArrayDataInput) {
String owner = byteArrayDataInput.readUTF();
CallbackType type = CallbackType.valueOf(byteArrayDataInput.readUTF());
if(type == CallbackType.CLICK) {
SWItem item = SWItem.getFromJson(byteArrayDataInput.readUTF());
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(byteArrayDataInput.readUTF());
inventoryHashMap.get(owner).handleCallback(clickType, item);
}else if(type == CallbackType.CLOSE) {
inventoryHashMap.get(owner).handleClose();
}
}
public enum CallbackType {
CLICK,
CLOSE,
}
}

Datei anzeigen

@ -1,53 +0,0 @@
package de.steamwar.bungeecore.coms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.coms.packets.inventory.SWItem;
import de.steamwar.bungeecore.coms.sender.Packet;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.HashMap;
public class InventoryPacket extends Packet {
String title;
String player;
int size;
HashMap<Integer, SWItem> items;
public InventoryPacket(int size, String title, ProxiedPlayer player) {
items = new HashMap<>();
this.title = title;
this.size = size;
this.player = player.getUniqueId().toString();
}
@Override
public String getName() {
return "Inventory";
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeUTF(player);
byteArrayDataOutput.writeUTF(title);
byteArrayDataOutput.writeInt(size);
byteArrayDataOutput.writeInt(items.size());
for (int i = 0; i < size; i++) {
if(items.get(i) != null)
byteArrayDataOutput.writeUTF(items.get(i).writeToString());
}
}
public void addItem(SWItem item) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i) != null) {
items.put(i, item);
return;
}
}
}
public void setItem(int index, SWItem item) {
items.put(index, item);
}
}

Datei anzeigen

@ -1,24 +0,0 @@
package de.steamwar.bungeecore.coms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.coms.sender.Packet;
public class PingPacket extends Packet {
String UUID;
@Override
public String getName() {
return "Ping";
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeUTF(UUID);
}
public PingPacket setUUID(String UUID) {
this.UUID = UUID;
return this;
}
}

Datei anzeigen

@ -1,75 +0,0 @@
package de.steamwar.bungeecore.coms.packets.inventory;
import de.steamwar.bungeecore.coms.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.coms.packets.CloseInventoryPacket;
import de.steamwar.bungeecore.coms.packets.InventoryPacket;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.HashMap;
import java.util.Map;
public class SWInventory {
Map<Integer, SWItem> itemMap;
InvCallback close;
ProxiedPlayer player;
int size;
String title;
public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) {
itemMap = new HashMap<>();
InventoryCallbackHandler.inventoryHashMap.put(proxiedPlayer.getUniqueId().toString(), this);
this.player = proxiedPlayer;
this.size = size;
this.title = title;
}
public void addItem(SWItem item) {
itemMap.put(item.position, item);
}
public void removeItem(SWItem item) {
itemMap.remove(item.position);
}
public void removeItem(int position) {
itemMap.remove(position);
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public void handleCallback(InvCallback.ClickType type, SWItem item) {
itemMap.get(item.position).callback.clicked(type);
}
public void handleClose() {
if(close != null)
close.clicked(null);
}
public void open() {
InventoryPacket inv = new InventoryPacket(size, title, player);
for (Map.Entry<Integer, SWItem> entry : itemMap.entrySet()) {
inv.setItem(entry.getKey(), entry.getValue());
}
inv.send(player);
}
public void close() {
new CloseInventoryPacket().setPlayer(player).send(player);
}
}

Datei anzeigen

@ -1,10 +0,0 @@
package de.steamwar.bungeecore.coms.receiver;
import com.google.common.io.ByteArrayDataInput;
public abstract class Handler {
protected abstract String getName();
public abstract void handle(ByteArrayDataInput byteArrayDataInput);
}

Datei anzeigen

@ -1,33 +0,0 @@
package de.steamwar.bungeecore.coms.receiver;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import de.steamwar.bungeecore.coms.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.listeners.BasicListener;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.event.EventHandler;
import java.util.HashMap;
import java.util.Map;
public class PacketHandler extends BasicListener {
private static final Map<String, Handler> handlerMap = new HashMap<>();
@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
if(!event.getTag().equalsIgnoreCase("sw:return"))
return;
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
String handler = in.readUTF();
handlerMap.get(handler).handle(in);
}
public static void registerHandler(Handler handler) {
handlerMap.put(handler.getName(), handler);
}
static {
registerHandler(new InventoryCallbackHandler());
}
}

Datei anzeigen

@ -1,21 +0,0 @@
package de.steamwar.bungeecore.coms.sender;
import com.google.common.io.ByteArrayDataOutput;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
public abstract class Packet {
public void send(Server server) {
PacketSender.sendPacket(this, server);
}
public void send(ProxiedPlayer player) {
PacketSender.sendPacket(this, player);
}
public abstract String getName();
//TODO Write Variables Automatic
public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput);
}

Datei anzeigen

@ -24,7 +24,7 @@ import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.commands.BauCommand;
import de.steamwar.bungeecore.commands.TpCommand;
import de.steamwar.bungeecore.coms.packets.PingPacket;
import de.steamwar.bungeecore.comms.packets.PingPacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team;
import net.md_5.bungee.api.ChatColor;
@ -189,7 +189,7 @@ public class ChatListener extends BasicListener {
for (String curr : msgSplits) {
if(curr.equalsIgnoreCase("@" + target.getName())) {
builder.append("§e@").append(target.getName()).append(chatcolor).append(" ");
new PingPacket().setUUID(target.getUniqueId().toString()).send(target);
new PingPacket().setUser(SteamwarUser.get(target).getId()).send(target);
}else {
builder.append(curr).append(" ");
}

Datei anzeigen

@ -91,6 +91,23 @@ public class Schematic {
}
}
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
try{
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, Rank, SchemFormat FROM Schematic WHERE SchemOwner = ? ORDER BY SchemName", schemOwner);
List<Schematic> schematics = new ArrayList<>();
while(schematic.next()){
schematics.add(new Schematic(schematic));
}
List<SchematicMember> addedSchems = SchematicMember.getAccessibleSchems(schemOwner);
for(SchematicMember schem : addedSchems){
schematics.add(getSchemFromDB(schem.getSchemName(), schem.getSchemOwner()));
}
return schematics;
}catch(SQLException e){
throw new SecurityException("Failed listing schematics", e);
}
}
public int getSchemID() {
return schemID;
}
@ -107,6 +124,15 @@ public class Schematic {
return schemType;
}
public String getSchemItem() {
try {
ResultSet set = SQL.select("SELECT Item WHERE SchemID = ? AND SchemOwner = ?", schemID, schemOwner);
return set.getString("Item");
} catch (SQLException throwables) {
return "CAULDRON_ITEM";
}
}
public void setSchemType(SchematicType schemType) {
this.schemType = schemType;
SQL.update("UPDATE Schematic SET SchemType = ? WHERE SchemID = ?", schemType.toDB(), schemID);

Datei anzeigen

@ -0,0 +1,115 @@
package de.steamwar.bungeecore.sql;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class SchematicMember {
private final int schemOwner;
private final String schemName;
private final int member;
private SchematicMember(String schemName, int schemOwner, int schemMember, boolean updateDB){
this.schemOwner = schemOwner;
member = schemMember;
this.schemName = schemName;
if(updateDB)
updateDB();
}
public SchematicMember(String schemName, int schemOwner, int schemMember){
this(schemName, schemOwner, schemMember, true);
}
public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){
this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId(), true);
}
private void updateDB(){
SQL.update("INSERT INTO SchemMember (SchemName, SchemOwner, Member) VALUES (?, ?, ?)", schemName, schemOwner, member);
}
public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){
return getSchemMemberFromDB(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId());
}
public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ? AND Member = ?", schemName, schemOwner, schemMember);
try {
if(schematicMember == null || !schematicMember.next()){
return null;
}
return new SchematicMember(schemName, schemOwner, schemMember, false);
} catch (SQLException e) {
throw new SecurityException("Could not get schemmember", e);
}
}
public static SchematicMember getMemberBySchematic(String schemName, int schemMember){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND Member = ?", schemName, schemMember);
try {
if(schematicMember == null || !schematicMember.next()){
return null;
}
int schemOwner = schematicMember.getInt("SchemOwner");
return new SchematicMember(schemName, schemOwner, schemMember, false);
} catch (SQLException e) {
throw new SecurityException("Could not get member", e);
}
}
public static List<SchematicMember> getSchemMembers(String schemName, UUID schemOwner){
return getSchemMembers(schemName, SteamwarUser.get(schemOwner).getId());
}
public static List<SchematicMember> getSchemMembers(String schemName, int schemOwner){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner);
try {
List<SchematicMember> schematicMembers = new ArrayList<>();
while(schematicMember.next()){
int schemMember = schematicMember.getInt("Member");
schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false));
}
return schematicMembers;
} catch (SQLException e) {
throw new SecurityException("Could not get schemmembers", e);
}
}
public static List<SchematicMember> getAccessibleSchems(UUID schemMember){
return getAccessibleSchems(SteamwarUser.get(schemMember).getId());
}
public static List<SchematicMember> getAccessibleSchems(int schemMember){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE Member = ?", schemMember);
try {
List<SchematicMember> schematicMembers = new ArrayList<>();
while(schematicMember.next()){
String schemName = schematicMember.getString("SchemName");
int schemOwner = schematicMember.getInt("SchemOwner");
schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false));
}
return schematicMembers;
} catch (SQLException e) {
throw new SecurityException("Could not get accessible schems", e);
}
}
public int getSchemOwner() {
return schemOwner;
}
public String getSchemName() {
return schemName;
}
public int getMember() {
return member;
}
public void remove(){
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ? AND Member = ?", schemOwner, schemName, member);
}
}