Bungee-SchemGUI
Dieser Commit ist enthalten in:
Ursprung
74c3a5ab41
Commit
d0fe58565d
@ -23,24 +23,34 @@ import com.google.common.io.ByteArrayDataInput;
|
|||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import de.steamwar.comms.handlers.BungeeHandler;
|
import de.steamwar.comms.handlers.BungeeHandler;
|
||||||
import de.steamwar.comms.handlers.InventoryHandler;
|
import de.steamwar.comms.handlers.InventoryHandler;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.comms.packets.MaterialsReturnPacket;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.sql.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.SoundCategory;
|
import org.bukkit.SoundCategory;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BungeeReceiver implements PluginMessageListener {
|
public class BungeeReceiver implements PluginMessageListener {
|
||||||
|
|
||||||
private static Map<Byte, BungeeHandler> handlerMap = new HashMap<>();
|
private static Map<Byte, BungeeHandler> handlerMap = new HashMap<>();
|
||||||
|
private static Map<Byte, BungeeHandler> backupMap = new HashMap<>();
|
||||||
|
|
||||||
public static void registerHandler(Byte code, BungeeHandler handler) {
|
public static void registerHandler(Byte code, BungeeHandler handler) {
|
||||||
handlerMap.put(code, handler);
|
handlerMap.put(code, handler);
|
||||||
}
|
}
|
||||||
|
public static void registerBackup(Byte code, BungeeHandler handler) {
|
||||||
|
backupMap.put(code, handler);
|
||||||
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
registerHandler(PacketIdManager.PING_PACKET, byteArrayDataInput -> {
|
registerHandler(PacketIdManager.PING_PACKET, byteArrayDataInput -> {
|
||||||
@ -56,12 +66,68 @@ public class BungeeReceiver implements PluginMessageListener {
|
|||||||
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
|
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
});
|
});
|
||||||
|
registerHandler(PacketIdManager.MATERIALS_GET_PACKET, byteArrayDataInput -> {
|
||||||
|
UUID id = UUID.fromString(byteArrayDataInput.readUTF());
|
||||||
|
MaterialsReturnPacket packet = new MaterialsReturnPacket(id, Material.values());
|
||||||
|
packet.send(Bukkit.getOnlinePlayers().stream().limit(1).collect(Collectors.toList()).get(1));
|
||||||
|
});
|
||||||
|
registerHandler(PacketIdManager.LOAD_SCHEMATIC, byteArrayDataInput -> {
|
||||||
|
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
|
||||||
|
Schematic schematic = Schematic.getSchemFromDB(byteArrayDataInput.readInt());
|
||||||
|
if(SchematicMember.getAccessibleSchems(player.getUniqueId()).contains(schematic)) {
|
||||||
|
try {
|
||||||
|
schematic.loadToPlayer(player);
|
||||||
|
player.sendMessage("§eSchematic§8» §7" + "Schematic §e" + schematic.getSchemName() + " §7geladen");
|
||||||
|
}catch (IOException | NoClipboardException e){
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Schematic konnte nicht geladen werden", e);
|
||||||
|
player.sendMessage("§eSchematic§8» §7" + "§cFehler beim Laden der Schematic. Bitte wende dich an einen Developer");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
registerHandler(PacketIdManager.SAVE_SCHEMATIC, byteArrayDataInput -> {
|
||||||
|
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
|
||||||
|
String name = byteArrayDataInput.readUTF();
|
||||||
|
Schematic schematic = Schematic.getSchemFromDB(name, player.getUniqueId());
|
||||||
|
boolean newSchem = false;
|
||||||
|
if(schematic == null || schematic.getSchemOwner() != SteamwarUser.get(player.getUniqueId()).getId()){
|
||||||
|
newSchem = true;
|
||||||
|
Schematic.createSchem(name, player.getUniqueId(), "", SchematicType.Normal);
|
||||||
|
schematic = Schematic.getSchemFromDB(name, player.getUniqueId());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
schematic.saveFromPlayer(player);
|
||||||
|
}catch(IOException ex){
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Could not save schematic", ex);
|
||||||
|
player.sendMessage(Core.SCHEMATIC_PREFIX + "§cFehler beim Speichern der Schematic. Bitte wende dich an einen Developer");
|
||||||
|
if(newSchem)
|
||||||
|
schematic.remove();
|
||||||
|
return;
|
||||||
|
}catch (NoClipboardException e) {
|
||||||
|
player.sendMessage(Core.SCHEMATIC_PREFIX + "§cDein Clipboard ist leer");
|
||||||
|
if(newSchem)
|
||||||
|
schematic.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (newSchem)
|
||||||
|
player.sendMessage(Core.SCHEMATIC_PREFIX + "Schematic §e" + name + " §7gespeichert");
|
||||||
|
else
|
||||||
|
player.sendMessage(Core.SCHEMATIC_PREFIX + "Schematic §e" + name + " §7überschrieben");
|
||||||
|
});
|
||||||
|
registerBackup((byte) 0x25, byteArrayDataInput -> {
|
||||||
|
byteArrayDataInput.readInt();
|
||||||
|
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
|
||||||
|
player.sendMessage(Core.SCHEMATIC_PREFIX + "§cDieser Server kann keine Schematics prüfen");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
|
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||||
Byte handler = in.readByte();
|
Byte handler = in.readByte();
|
||||||
|
if(handlerMap.containsKey(handler))
|
||||||
handlerMap.get(handler).handle(in);
|
handlerMap.get(handler).handle(in);
|
||||||
|
else if(backupMap.containsKey(handler))
|
||||||
|
backupMap.get(handler).handle(in);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,9 @@ public class PacketIdManager {
|
|||||||
public final static byte INVENTORY_PACKET = 0x10;
|
public final static byte INVENTORY_PACKET = 0x10;
|
||||||
public final static byte INVENTORY_CALLBACK_PACKET = 0x11;
|
public final static byte INVENTORY_CALLBACK_PACKET = 0x11;
|
||||||
public final static byte INVENTORY_CLOSE_PACKET = 0x12;
|
public final static byte INVENTORY_CLOSE_PACKET = 0x12;
|
||||||
|
//0x2(X) Schematic System
|
||||||
|
public final static byte MATERIALS_GET_PACKET = 0x21;
|
||||||
|
public final static byte MATERIALS_RETURN_PACKET = 0x22;
|
||||||
|
public static final byte LOAD_SCHEMATIC = 0x23;
|
||||||
|
public static final byte SAVE_SCHEMATIC = 0x24;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package de.steamwar.comms.packets;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import de.steamwar.comms.PacketIdManager;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MaterialsReturnPacket extends SpigotPacket{
|
||||||
|
|
||||||
|
final UUID id;
|
||||||
|
final Material[] array;
|
||||||
|
|
||||||
|
public MaterialsReturnPacket(UUID id, Material[] array) {
|
||||||
|
this.id = id;
|
||||||
|
this.array = array;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getName() {
|
||||||
|
return PacketIdManager.MATERIALS_RETURN_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
||||||
|
byteArrayDataOutput.writeUTF(id.toString());
|
||||||
|
JsonArray array = new JsonArray();
|
||||||
|
for (int i = 0; i < this.array.length; i++) {
|
||||||
|
if(new ItemStack(this.array[i]).getItemMeta() != null && this.array[i].isItem())
|
||||||
|
array.add(this.array[i].name());
|
||||||
|
}
|
||||||
|
byteArrayDataOutput.writeUTF(array.toString());
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
public class Core extends JavaPlugin{
|
public class Core extends JavaPlugin{
|
||||||
private static Core instance;
|
private static Core instance;
|
||||||
private static final int version;
|
private static final int version;
|
||||||
|
public static final String SCHEMATIC_PREFIX = "§eSchematic§8» §7";
|
||||||
|
|
||||||
static{
|
static{
|
||||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren