Add Bungee GUI Prototype
Dieser Commit ist enthalten in:
Ursprung
691abd0dea
Commit
00c08fc8ad
@ -2,6 +2,8 @@ package de.steamwar.coms.receiver;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
import de.steamwar.coms.receiver.handlers.CloseInventoryHandler;
|
||||||
|
import de.steamwar.coms.receiver.handlers.InventoryHandler;
|
||||||
import de.steamwar.coms.receiver.handlers.PingHandler;
|
import de.steamwar.coms.receiver.handlers.PingHandler;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
@ -19,6 +21,8 @@ public class PacketHandler implements PluginMessageListener {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
registerHandler(new PingHandler());
|
registerHandler(new PingHandler());
|
||||||
|
registerHandler(new InventoryHandler());
|
||||||
|
registerHandler(new CloseInventoryHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package de.steamwar.coms.receiver.handlers;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import de.steamwar.coms.receiver.Handler;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CloseInventoryHandler extends Handler {
|
||||||
|
@Override
|
||||||
|
protected String getName() {
|
||||||
|
return "InvClose";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
||||||
|
Player player = Bukkit.getPlayer(UUID.fromString(byteArrayDataInput.readUTF()));
|
||||||
|
player.closeInventory();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package de.steamwar.coms.receiver.handlers;
|
package de.steamwar.coms.receiver.handlers;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import de.steamwar.coms.receiver.Handler;
|
import de.steamwar.coms.receiver.Handler;
|
||||||
@ -14,8 +15,6 @@ import java.util.*;
|
|||||||
|
|
||||||
public class InventoryHandler extends Handler {
|
public class InventoryHandler extends Handler {
|
||||||
|
|
||||||
private static HashMap<String, String> callbacks = new HashMap<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getName() {
|
protected String getName() {
|
||||||
return "Inventory";
|
return "Inventory";
|
||||||
@ -23,13 +22,12 @@ public class InventoryHandler extends Handler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
||||||
String name = byteArrayDataInput.readUTF();
|
|
||||||
String player = byteArrayDataInput.readUTF();
|
String player = byteArrayDataInput.readUTF();
|
||||||
String title = byteArrayDataInput.readUTF();
|
String title = byteArrayDataInput.readUTF();
|
||||||
int size = byteArrayDataInput.readInt();
|
int size = byteArrayDataInput.readInt();
|
||||||
int lenght = byteArrayDataInput.readInt();
|
int length = byteArrayDataInput.readInt();
|
||||||
Map<Integer, SWItem> items = new HashMap<>();
|
Map<Integer, SWItem> items = new HashMap<>();
|
||||||
for (int i = 0; i < lenght; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
JsonObject object = new JsonParser().parse(byteArrayDataInput.readUTF()).getAsJsonObject();
|
JsonObject object = new JsonParser().parse(byteArrayDataInput.readUTF()).getAsJsonObject();
|
||||||
SWItem item = new SWItem(Material.valueOf(object.get("material").getAsString()), object.get("title").getAsString());
|
SWItem item = new SWItem(Material.valueOf(object.get("material").getAsString()), object.get("title").getAsString());
|
||||||
if(object.has("skullOwner")) {
|
if(object.has("skullOwner")) {
|
||||||
@ -40,14 +38,25 @@ public class InventoryHandler extends Handler {
|
|||||||
item.setEnchanted(true);
|
item.setEnchanted(true);
|
||||||
if(object.has("hideAttributes"))
|
if(object.has("hideAttributes"))
|
||||||
item.hideAttributes();
|
item.hideAttributes();
|
||||||
|
if(object.has("lore")) {
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
JsonArray array = object.getAsJsonArray("lore");
|
||||||
|
array.forEach(jsonElement -> lore.add(jsonElement.getAsString()));
|
||||||
|
item.setLore(lore);
|
||||||
|
}
|
||||||
SWItem finalItem = item;
|
SWItem finalItem = item;
|
||||||
item.setCallback(click -> {
|
item.setCallback(click -> {
|
||||||
new InventoryCallbackPacket().setItem(finalItem).setPosition(object.get("position").getAsInt()).setTitle(title).send();
|
new InventoryCallbackPacket().setItem(finalItem).setClick(click)
|
||||||
|
.setPosition(object.get("position").getAsInt())
|
||||||
|
.setCallback(InventoryCallbackPacket.CallbackType.CLICK)
|
||||||
|
.setOwner(player).send(Bukkit.getPlayer(UUID.fromString(player)));
|
||||||
});
|
});
|
||||||
items.put(object.get("position").getAsInt(), item);
|
items.put(object.get("position").getAsInt(), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
SWInventory inventory = new SWInventory(Bukkit.getPlayer(UUID.fromString(player)), size, title, items);
|
SWInventory inventory = new SWInventory(Bukkit.getPlayer(UUID.fromString(player)), size, title, items);
|
||||||
|
inventory.addCloseCallback(click -> new InventoryCallbackPacket()
|
||||||
|
.setCallback(InventoryCallbackPacket.CallbackType.CLOSE).setOwner(player).send(Bukkit.getPlayer(UUID.fromString(player))));
|
||||||
inventory.open();
|
inventory.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
package de.steamwar.coms.sender;
|
package de.steamwar.coms.sender;
|
||||||
|
|
||||||
import de.steamwar.coms.sender.PacketSender;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public abstract class Packet implements Serializable {
|
public abstract class Packet implements Serializable {
|
||||||
|
|
||||||
public void send() {
|
public void send(Player player) {
|
||||||
PacketSender.sendPacket(this);
|
PacketSender.sendPacket(this, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
public abstract void writeVars(ObjectOutputStream objectOutputStream) throws IOException;
|
public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput);
|
||||||
}
|
}
|
||||||
|
@ -3,27 +3,14 @@ package de.steamwar.coms.sender;
|
|||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class PacketSender {
|
public class PacketSender {
|
||||||
|
|
||||||
public static void sendPacket(Packet packet) {
|
public static void sendPacket(Packet packet, Player player) {
|
||||||
try {
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF(packet.getName());
|
out.writeUTF(packet.getName());
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
packet.writeVars(out);
|
||||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
|
player.sendPluginMessage(Core.getInstance(), "sw:return", out.toByteArray());
|
||||||
packet.writeVars(objectOutputStream);
|
|
||||||
objectOutputStream.flush();
|
|
||||||
out.writeUTF(outputStream.toByteArray().toString());
|
|
||||||
Bukkit.getOnlinePlayers().stream().limit(1).collect(Collectors.toList()).get(0).sendPluginMessage(Core.getInstance(), "sw:bridge", out.toByteArray());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,17 @@
|
|||||||
package de.steamwar.coms.sender.packets;
|
package de.steamwar.coms.sender.packets;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import de.steamwar.coms.sender.Packet;
|
import de.steamwar.coms.sender.Packet;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
|
|
||||||
public class InventoryCallbackPacket extends Packet {
|
public class InventoryCallbackPacket extends Packet {
|
||||||
|
|
||||||
String title;
|
|
||||||
int position;
|
int position;
|
||||||
SWItem item;
|
SWItem item;
|
||||||
|
ClickType clickType;
|
||||||
|
CallbackType callbackType;
|
||||||
|
String owner;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -17,13 +19,13 @@ public class InventoryCallbackPacket extends Packet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeVars(ObjectOutputStream objectOutputStream) {
|
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
||||||
|
byteArrayDataOutput.writeUTF(owner);
|
||||||
|
byteArrayDataOutput.writeUTF(callbackType.name());
|
||||||
|
if(item != null){
|
||||||
|
byteArrayDataOutput.writeUTF(item.parseToJson(position));
|
||||||
|
byteArrayDataOutput.writeUTF(clickType.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryCallbackPacket setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryCallbackPacket setPosition(int position) {
|
public InventoryCallbackPacket setPosition(int position) {
|
||||||
@ -35,4 +37,24 @@ public class InventoryCallbackPacket extends Packet {
|
|||||||
this.item = item;
|
this.item = item;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InventoryCallbackPacket setClick(ClickType type){
|
||||||
|
this.clickType = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryCallbackPacket setCallback(CallbackType callback) {
|
||||||
|
callbackType = callback;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryCallbackPacket setOwner(String uuid) {
|
||||||
|
this.owner = uuid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CallbackType {
|
||||||
|
CLICK,
|
||||||
|
CLOSE,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public class Core extends JavaPlugin{
|
|||||||
if(version >= 12)
|
if(version >= 12)
|
||||||
ErrorLogger.init();
|
ErrorLogger.init();
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new PacketHandler());
|
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new PacketHandler());
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel( this, "sw:bridge" );
|
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:return");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ public class SWItem {
|
|||||||
object.addProperty("enchanted", true);
|
object.addProperty("enchanted", true);
|
||||||
if(itemMeta.hasItemFlag(ItemFlag.HIDE_ENCHANTS))
|
if(itemMeta.hasItemFlag(ItemFlag.HIDE_ENCHANTS))
|
||||||
object.addProperty("hideAttributes", true);
|
object.addProperty("hideAttributes", true);
|
||||||
if(!itemMeta.getLore().isEmpty()) {
|
if(itemMeta.getLore() != null) {
|
||||||
JsonArray array = new JsonArray();
|
JsonArray array = new JsonArray();
|
||||||
for (String lores:
|
for (String lores:
|
||||||
itemMeta.getLore()) {
|
itemMeta.getLore()) {
|
||||||
@ -214,6 +214,6 @@ public class SWItem {
|
|||||||
object.add("lore", array);
|
object.add("lore", array);
|
||||||
}
|
}
|
||||||
|
|
||||||
return object.getAsString();
|
return object.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren