Add Stuff for Bungee GUI
Dieser Commit ist enthalten in:
Ursprung
2dcecc5a62
Commit
691abd0dea
@ -6,5 +6,5 @@ public abstract class Handler {
|
||||
|
||||
protected abstract String getName();
|
||||
|
||||
public abstract void handle(ByteArrayDataInput byteArrayDataInput) throws Exception;
|
||||
public abstract void handle(ByteArrayDataInput byteArrayDataInput);
|
||||
}
|
@ -3,7 +3,6 @@ package de.steamwar.coms.receiver;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import de.steamwar.coms.receiver.handlers.PingHandler;
|
||||
import de.steamwar.coms.receiver.handlers.TestHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
@ -19,17 +18,12 @@ public class PacketHandler implements PluginMessageListener {
|
||||
}
|
||||
|
||||
static {
|
||||
registerHandler(new TestHandler());
|
||||
registerHandler(new PingHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||
try {
|
||||
handlerMap.get(in.readUTF()).handle(in);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
handlerMap.get(in.readUTF()).handle(in);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package de.steamwar.coms.receiver.handlers;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import de.steamwar.coms.receiver.Handler;
|
||||
import de.steamwar.coms.sender.packets.InventoryCallbackPacket;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class InventoryHandler extends Handler {
|
||||
|
||||
private static HashMap<String, String> callbacks = new HashMap<>();
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Inventory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
||||
String name = byteArrayDataInput.readUTF();
|
||||
String player = byteArrayDataInput.readUTF();
|
||||
String title = byteArrayDataInput.readUTF();
|
||||
int size = byteArrayDataInput.readInt();
|
||||
int lenght = byteArrayDataInput.readInt();
|
||||
Map<Integer, SWItem> items = new HashMap<>();
|
||||
for (int i = 0; i < lenght; i++) {
|
||||
JsonObject object = new JsonParser().parse(byteArrayDataInput.readUTF()).getAsJsonObject();
|
||||
SWItem item = new SWItem(Material.valueOf(object.get("material").getAsString()), object.get("title").getAsString());
|
||||
if(object.has("skullOwner")) {
|
||||
item = SWItem.getPlayerSkull(object.get("skullOwner").getAsString());
|
||||
item.setName(object.get("title").getAsString());
|
||||
}
|
||||
if(object.has("enchanted"))
|
||||
item.setEnchanted(true);
|
||||
if(object.has("hideAttributes"))
|
||||
item.hideAttributes();
|
||||
SWItem finalItem = item;
|
||||
item.setCallback(click -> {
|
||||
new InventoryCallbackPacket().setItem(finalItem).setPosition(object.get("position").getAsInt()).setTitle(title).send();
|
||||
});
|
||||
items.put(object.get("position").getAsInt(), item);
|
||||
}
|
||||
|
||||
SWInventory inventory = new SWInventory(Bukkit.getPlayer(UUID.fromString(player)), size, title,items);
|
||||
inventory.open();
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ public class PingHandler extends Handler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ByteArrayDataInput byteArrayDataInput) throws Exception {
|
||||
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
||||
String uuid = byteArrayDataInput.readUTF();
|
||||
System.out.println(uuid);
|
||||
if(Bukkit.getPlayer(UUID.fromString(uuid)).isOnline()) {
|
||||
|
@ -1,17 +0,0 @@
|
||||
package de.steamwar.coms.receiver.handlers;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import de.steamwar.coms.receiver.Handler;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class TestHandler extends Handler {
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ByteArrayDataInput byteArrayDataInput) throws Exception {
|
||||
Bukkit.getOnlinePlayers().stream().forEach(player -> player.sendMessage("TEST!"));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.steamwar.coms;
|
||||
package de.steamwar.coms.sender;
|
||||
|
||||
import de.steamwar.coms.sender.PacketSender;
|
||||
|
@ -2,7 +2,6 @@ package de.steamwar.coms.sender;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import de.steamwar.coms.Packet;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
package de.steamwar.coms.sender.packets;
|
||||
|
||||
import de.steamwar.coms.sender.Packet;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class InventoryCallbackPacket extends Packet {
|
||||
|
||||
String title;
|
||||
int position;
|
||||
SWItem item;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "InventoryCallback";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeVars(ObjectOutputStream objectOutputStream) {
|
||||
|
||||
}
|
||||
|
||||
public InventoryCallbackPacket setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public InventoryCallbackPacket setPosition(int position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
|
||||
public InventoryCallbackPacket setItem(SWItem item) {
|
||||
this.item = item;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -19,6 +19,8 @@
|
||||
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -137,7 +139,7 @@ public class SWItem {
|
||||
callback = c;
|
||||
}
|
||||
|
||||
private void hideAttributes() {
|
||||
public void hideAttributes() {
|
||||
if (itemMeta == null) return;
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_DESTROYS);
|
||||
@ -193,4 +195,25 @@ public class SWItem {
|
||||
}
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
public String parseToJson(int position) {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("material", itemStack.getType().toString());
|
||||
object.addProperty("position", position);
|
||||
object.addProperty("title", itemMeta.getDisplayName());
|
||||
if(itemMeta.hasEnchant(Enchantment.DURABILITY))
|
||||
object.addProperty("enchanted", true);
|
||||
if(itemMeta.hasItemFlag(ItemFlag.HIDE_ENCHANTS))
|
||||
object.addProperty("hideAttributes", true);
|
||||
if(!itemMeta.getLore().isEmpty()) {
|
||||
JsonArray array = new JsonArray();
|
||||
for (String lores:
|
||||
itemMeta.getLore()) {
|
||||
array.add(lores);
|
||||
}
|
||||
object.add("lore", array);
|
||||
}
|
||||
|
||||
return object.getAsString();
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren