SteamWar/BungeeCore
Archiviert
13
2
Dieser Commit ist enthalten in:
Chaoscaot 2020-09-21 23:23:39 +02:00
Ursprung 70071893fa
Commit 7dd8d707a5
15 geänderte Dateien mit 71 neuen und 52 gelöschten Zeilen

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.bungeecore;
import de.steamwar.bungeecore.commands.*;
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;
@ -41,7 +40,6 @@ import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import org.yaml.snakeyaml.error.YAMLException;
import java.io.File;
import java.io.IOException;

Datei anzeigen

@ -20,8 +20,8 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.comms.packets.inventory.SWInventory;
import de.steamwar.bungeecore.comms.packets.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.sql.BauweltMember;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.ProxyServer;
@ -228,11 +228,11 @@ public class BauCommand {
}
private static void delete(ProxiedPlayer p, String[] command){
SWInventory inventory = new SWInventory(p, 9, "§eDelete Confirm");
inventory.addItem(1, new SWItem(1, "§cDecline", 1), click -> {
SWInventory inventory = new SWInventory(p, 9, "§e/Bau delete Bestätigen");
inventory.addItem(0, new SWItem(0, "§cAbbrechen", 1), click -> {
inventory.close();
});
inventory.addItem(7, new SWItem(7, "§aAccept", 10), click -> {
inventory.addItem(8, new SWItem(8, "§aLöchen", 10), click -> {
if(bau15(p, command, 2)){
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDeine Welt wird zurückgesetzt.");
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {

Datei anzeigen

@ -30,7 +30,7 @@ public abstract class BungeePacket {
public void send(Server server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(getId());
out.writeByte(getId());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writeVars(out);
out.writeUTF(outputStream.toByteArray().toString());
@ -38,12 +38,7 @@ public abstract class BungeePacket {
}
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());
send(player.getServer());
}
public abstract int getId();

Datei anzeigen

@ -0,0 +1,11 @@
package de.steamwar.bungeecore.comms;
public class PacketIdManager {
//0x0(X) Standalone Packets
public final static byte PING_PACKET = 0x01;
//0x1(X) Bungee Inventory
public final static byte INVENTORY_PACKET = 0x10;
public final static byte INVENTORY_CALLBACK_PACKET = 0x11;
public final static byte INVENTORY_CLOSE_PACKET = 0x12;
}

Datei anzeigen

@ -31,26 +31,25 @@ import java.util.Map;
public class SpigotReceiver extends BasicListener {
private static final Map<Integer, SpigotHandler> handlerMap = new HashMap<>();
private static final Map<Byte, SpigotHandler> handlerMap = new HashMap<>();
@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
return;
if(!event.getSender().getAddress().getHostName().equals("localhost"))
return;
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
int handler = in.readInt();
Byte handler = in.readByte();
handlerMap.get(handler).handle(in);
event.setCancelled(true);
}
public static void registerHandler(int id, SpigotHandler handler) {
public static void registerHandler(Byte 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());
registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler());
}
}

Datei anzeigen

@ -21,8 +21,8 @@ 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.inventory.InvCallback;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.sql.SteamwarUser;
import java.util.HashMap;
@ -41,7 +41,11 @@ public class InventoryCallbackHandler implements SpigotHandler {
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();
if(inventoryHashMap.get(owner.getId()).isNext()) {
inventoryHashMap.get(owner.getId()).handleClose();
return;
}
inventoryHashMap.get(owner.getId()).setNext(true);
}
}

Datei anzeigen

@ -21,25 +21,25 @@ package de.steamwar.bungeecore.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class CloseInventoryPacket extends BungeePacket {
ProxiedPlayer player;
final ProxiedPlayer player;
@Override
public int getId() {
return "CloseInventory".hashCode();
return PacketIdManager.INVENTORY_CLOSE_PACKET;
}
public CloseInventoryPacket(ProxiedPlayer player) {
this.player = player;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(SteamwarUser.get(player).getId());
}
public CloseInventoryPacket setPlayer(ProxiedPlayer player) {
this.player = player;
return this;
}
}

Datei anzeigen

@ -22,7 +22,8 @@ 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.PacketIdManager;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -31,10 +32,10 @@ import java.util.HashMap;
public class InventoryPacket extends BungeePacket {
String title;
int player;
int size;
HashMap<Integer, SWItem> items;
final String title;
final int player;
final int size;
final HashMap<Integer, SWItem> items;
public InventoryPacket(int size, String title, ProxiedPlayer player) {
items = new HashMap<>();
@ -45,7 +46,7 @@ public class InventoryPacket extends BungeePacket {
@Override
public int getId() {
return "InventoryHandler".hashCode();
return PacketIdManager.INVENTORY_PACKET;
}
@Override

Datei anzeigen

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

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.packets.inventory;
package de.steamwar.bungeecore.inventory;
public interface InvCallback {

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.packets.inventory;
package de.steamwar.bungeecore.inventory;
import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
@ -35,6 +35,7 @@ public class SWInventory {
private ProxiedPlayer player;
private int size;
private String title;
private boolean next;
public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) {
itemMap = new HashMap<>();
@ -42,6 +43,7 @@ public class SWInventory {
this.player = proxiedPlayer;
this.size = size;
this.title = title;
next = false;
}
public void addItem(SWItem item) {
@ -86,11 +88,20 @@ public class SWInventory {
itemMap.get(pos).setCallback(callback);
}
public void setNext(boolean next) {
this.next = next;
}
public boolean isNext() {
return next;
}
public void handleCallback(InvCallback.ClickType type, int pos) {
itemMap.get(pos).getCallback().clicked(type);
}
public void handleClose() {
InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player).getId(), this);
if(close != null)
close.clicked(null);
}
@ -104,6 +115,6 @@ public class SWInventory {
}
public void close() {
new CloseInventoryPacket().setPlayer(player).send(player);
new CloseInventoryPacket(player).send(player);
}
}

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.packets.inventory;
package de.steamwar.bungeecore.inventory;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.packets.inventory;
package de.steamwar.bungeecore.inventory;
import de.steamwar.bungeecore.sql.Schematic;
import de.steamwar.bungeecore.sql.SchematicType;

Datei anzeigen

@ -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().setUser(SteamwarUser.get(target).getId()).send(target);
new PingPacket(SteamwarUser.get(target).getId()).send(target);
}else {
builder.append(curr).append(" ");
}

Datei anzeigen

@ -126,7 +126,7 @@ public class Schematic {
public String getSchemItem() {
try {
ResultSet set = SQL.select("SELECT Item WHERE SchemID = ? AND SchemOwner = ?", schemID, schemOwner);
ResultSet set = SQL.select("SELECT Item WHERE SchemID = ?", schemID);
return set.getString("Item");
} catch (SQLException throwables) {
return "CAULDRON_ITEM";