Archiviert
1
0

Merge pull request 'Packet System + Bungee GUI' (#111) from packet-system into master

Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
YoyoNow 2020-09-26 09:21:45 +02:00
Commit ff113967e8
18 geänderte Dateien mit 1082 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bungeecore;
import de.steamwar.bungeecore.commands.*;
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;
@ -69,6 +70,9 @@ public class BungeeCore extends Plugin {
@Override
public void onEnable(){
getProxy().registerChannel("sw:bridge");
setInstance(this);
loadConfig();
@ -124,6 +128,7 @@ public class BungeeCore extends Plugin {
new EventStarter();
new Broadcaster();
new SessionManager();
new SpigotReceiver();
new TablistManager();

Datei anzeigen

@ -20,6 +20,8 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*;
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;
@ -226,32 +228,31 @@ public class BauCommand {
}
private static void delete(ProxiedPlayer p, String[] command){
if(bau15(p, command, 2)){
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDeine Welt wird zurückgesetzt.");
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) {
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) {
subserver.stop();
break;
}
}
SWInventory inventory = new SWInventory(p, 9, "§eWirklich Welt löschen?");
inventory.addItem(8, new SWItem(8, "§cAbbrechen", 1), click -> inventory.close());
inventory.addItem(1, new SWItem(1, "§aLöchen", 10), click -> {
if(bau15(p, command, 2)){
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
File directory = new File(BungeeCore.USERWORLDS15 + user.getId());
del(directory);
});
}else{
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDeine Welt wird zurückgesetzt.");
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) {
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) {
subserver.stop();
break;
}
deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId());
}else{
deleteWorld(p, BungeeCore.WORLD_FOLDER + p.getUniqueId().toString());
}
});
inventory.open();
}
private static void deleteWorld(ProxiedPlayer player, String world) {
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aDeine Welt wird zurückgesetzt.");
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) {
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(player.getUniqueId())) {
subserver.stop();
break;
}
File directory = new File(BungeeCore.WORLD_FOLDER + p.getUniqueId().toString());
del(directory);
});
}
}
File directory = new File(world);
del(directory);
});
}
private static void testarena(ProxiedPlayer p, String[] command){

Datei anzeigen

@ -67,8 +67,8 @@ public class CheckCommand extends BasicCommand {
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
List<Schematic> schematics = getSchemsToCheck();
if(!schematics.isEmpty())
ServerTeamchatCommand.sendToTeam("§7Es sind §e" + schematics.size() + " §7Schematics zu prüfen§8!");
if(schematics.size() != currentCheckers.size())
ServerTeamchatCommand.sendToTeam("§7Es sind §e" + (schematics.size() - currentCheckers.size()) + " §7Schematics zu prüfen§8!");
}, 10, 10, TimeUnit.MINUTES);
}

Datei anzeigen

@ -0,0 +1,47 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import java.io.ByteArrayOutputStream;
public abstract class BungeePacket {
public void send(Server server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeByte(getId());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writeVars(out);
out.writeUTF(outputStream.toByteArray().toString());
server.sendData("sw:bridge", out.toByteArray());
}
public void send(ProxiedPlayer player) {
send(player.getServer());
}
public abstract int getId();
public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput);
}

Datei anzeigen

@ -0,0 +1,30 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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

@ -0,0 +1,27 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms;
import com.google.common.io.ByteArrayDataInput;
public interface SpigotHandler {
void handle(ByteArrayDataInput byteArrayDataInput);
}

Datei anzeigen

@ -0,0 +1,57 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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<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")){
event.setCancelled(true);
return;
}
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
Byte handler = in.readByte();
handlerMap.get(handler).handle(in);
event.setCancelled(true);
}
public static void registerHandler(Byte id, SpigotHandler handler) {
handlerMap.put(id, handler);
}
static {
registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler());
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.inventory.InvCallback;
import de.steamwar.bungeecore.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) {
if(inventoryHashMap.get(owner.getId()).isNext()) {
inventoryHashMap.get(owner.getId()).handleClose();
return;
}
inventoryHashMap.get(owner.getId()).setNext(true);
}
}
public enum CallbackType {
CLICK,
CLOSE,
}
}

Datei anzeigen

@ -0,0 +1,45 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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 {
final ProxiedPlayer player;
@Override
public int getId() {
return PacketIdManager.INVENTORY_CLOSE_PACKET;
}
public CloseInventoryPacket(ProxiedPlayer player) {
this.player = player;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(SteamwarUser.get(player).getId());
}
}

Datei anzeigen

@ -0,0 +1,80 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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.PacketIdManager;
import de.steamwar.bungeecore.inventory.SWInventory;
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;
import java.util.HashMap;
import java.util.Map;
public class InventoryPacket extends BungeePacket {
final String title;
final int player;
final int size;
final Map<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();
}
public InventoryPacket(SWInventory inventory) {
items = inventory.getItems();
this.title = inventory.getTitle();
this.size = inventory.getSize();
this.player = SteamwarUser.get(inventory.getPlayer()).getId();
}
@Override
public int getId() {
return PacketIdManager.INVENTORY_PACKET;
}
@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,43 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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 {
final int id;
@Override
public int getId() {
return PacketIdManager.PING_PACKET;
}
public PingPacket(int id) {
this.id = id;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(id);
}
}

Datei anzeigen

@ -0,0 +1,61 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.inventory;
public interface InvCallback {
void clicked(ClickType click);
public static enum ClickType {
LEFT,
SHIFT_LEFT,
RIGHT,
SHIFT_RIGHT,
WINDOW_BORDER_LEFT,
WINDOW_BORDER_RIGHT,
MIDDLE,
NUMBER_KEY,
DOUBLE_CLICK,
DROP,
CONTROL_DROP,
CREATIVE,
UNKNOWN;
public boolean isKeyboardClick() {
return this == NUMBER_KEY || this == DROP || this == CONTROL_DROP;
}
public boolean isCreativeAction() {
return this == MIDDLE || this == CREATIVE;
}
public boolean isRightClick() {
return this == RIGHT || this == SHIFT_RIGHT;
}
public boolean isLeftClick() {
return this == LEFT || this == SHIFT_LEFT || this == DOUBLE_CLICK || this == CREATIVE;
}
public boolean isShiftClick() {
return this == SHIFT_LEFT || this == SHIFT_RIGHT || this == CONTROL_DROP;
}
}
}

Datei anzeigen

@ -0,0 +1,137 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.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;
private boolean next;
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;
next = false;
}
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 setNext(boolean next) {
this.next = next;
}
public boolean isNext() {
return next;
}
public Map<Integer, SWItem> getItems() {
return itemMap;
}
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);
}
public void open() {
InventoryPacket inv = new InventoryPacket(this);
inv.send(player);
}
public void close() {
new CloseInventoryPacket(player).send(player);
}
public void setClose(InvCallback close) {
this.close = close;
}
public ProxiedPlayer getPlayer() {
return player;
}
public void setPlayer(ProxiedPlayer player) {
this.player = player;
}
public String getTitle() {
return title;
}
}

Datei anzeigen

@ -0,0 +1,159 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.inventory;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.List;
public class SWItem {
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;
}
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;
}
public String getMaterial() {
return material;
}
public void setMaterial(String material) {
this.material = material.toUpperCase();
}
public String getSkullOwner() {
return skullOwner;
}
public void setSkullOwner(String skullOwner) {
this.skullOwner = skullOwner;
}
public boolean isEnchanted() {
return enchanted;
}
public void setEnchanted(boolean enchanted) {
this.enchanted = enchanted;
}
public boolean isHideAttributes() {
return hideAttributes;
}
public void setHideAttributes(boolean hideAttributes) {
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 JsonObject writeToString() {
JsonObject object = new JsonObject();
object.addProperty("material", material);
object.addProperty("position", position);
object.addProperty("title", title);
if(skullOwner != null)
object.addProperty("skullOwner", skullOwner);
if(enchanted)
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:
lore) {
array.add(lores);
}
object.add("lore", array);
}
return object;
}
@Override
public boolean equals(Object o) {
if(!(o instanceof SWItem))
return false;
SWItem item = (SWItem) o;
if(item.enchanted != enchanted)
return false;
if(item.hideAttributes != hideAttributes)
return false;
if(!item.material.equals(material))
return false;
if(!item.lore.equals(lore))
return false;
if(!item.skullOwner.equals(skullOwner))
return false;
if(item.position != position)
return false;
return true;
}
}

Datei anzeigen

@ -0,0 +1,145 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.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

@ -24,6 +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.comms.packets.PingPacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team;
import net.md_5.bungee.api.ChatColor;
@ -188,6 +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(SteamwarUser.get(target).getId()).send(target);
}else {
builder.append(curr).append(" ");
}

Datei anzeigen

@ -30,12 +30,14 @@ public class Schematic {
private final String schemName;
private final int schemOwner;
private SchematicType schemType;
private String schemItem;
private Schematic(ResultSet rs) throws SQLException {
this.schemID = rs.getInt("SchemID");
this.schemName = rs.getString("SchemName");
this.schemOwner = rs.getInt("SchemOwner");
this.schemType = SchematicType.fromDB(rs.getString("SchemType"));
this.schemItem = rs.getString("Item");
}
public static Schematic getSchemFromDB(String schemName, UUID schemOwner){
@ -43,7 +45,7 @@ public class Schematic {
}
public static Schematic getSchemFromDB(String schemName, int schemOwner){
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType FROM Schematic WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner);
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner);
try {
if(schematic == null || !schematic.next()){
return null;
@ -55,7 +57,7 @@ public class Schematic {
}
public static Schematic getSchemFromDB(int schemID){
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType FROM Schematic WHERE SchemID = ?", schemID);
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemID = ?", schemID);
try {
if(!schematic.next())
throw new SecurityException("Failed loading schematic " + schemID);
@ -67,7 +69,7 @@ public class Schematic {
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
try{
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType FROM Schematic WHERE SchemType = ?", schemType.toDB());
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemType = ?", schemType.toDB());
List<Schematic> schematics = new ArrayList<>();
while(schematic.next()){
schematics.add(new Schematic(schematic));
@ -80,7 +82,7 @@ public class Schematic {
public static List<Schematic> getSchemsOfType(int userId, SchematicType schemType){
try{
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType FROM Schematic WHERE SchemType = ? AND SchemOwner = ?", schemType.toDB(), userId);
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemType = ? AND SchemOwner = ?", schemType.toDB(), userId);
List<Schematic> schematics = new ArrayList<>();
while(schematic.next()){
schematics.add(new Schematic(schematic));
@ -91,6 +93,23 @@ public class Schematic {
}
}
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
try{
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, Rank, SchemFormat, Item 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;
}
@ -103,6 +122,10 @@ public class Schematic {
return schemOwner;
}
public String getSchemItem() {
return schemItem;
}
public SchematicType getSchemType() {
return schemType;
}

Datei anzeigen

@ -0,0 +1,134 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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);
}
}