geforkt von SteamWar/BungeeCore
Code Cleanup
Dieser Commit ist enthalten in:
Ursprung
70071893fa
Commit
7dd8d707a5
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.bungeecore;
|
package de.steamwar.bungeecore;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.commands.*;
|
import de.steamwar.bungeecore.commands.*;
|
||||||
import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
|
|
||||||
import de.steamwar.bungeecore.comms.SpigotReceiver;
|
import de.steamwar.bungeecore.comms.SpigotReceiver;
|
||||||
import de.steamwar.bungeecore.listeners.*;
|
import de.steamwar.bungeecore.listeners.*;
|
||||||
import de.steamwar.bungeecore.listeners.mods.Fabric;
|
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.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
import org.yaml.snakeyaml.error.YAMLException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
import de.steamwar.bungeecore.*;
|
||||||
import de.steamwar.bungeecore.comms.packets.inventory.SWInventory;
|
import de.steamwar.bungeecore.inventory.SWInventory;
|
||||||
import de.steamwar.bungeecore.comms.packets.inventory.SWItem;
|
import de.steamwar.bungeecore.inventory.SWItem;
|
||||||
import de.steamwar.bungeecore.sql.BauweltMember;
|
import de.steamwar.bungeecore.sql.BauweltMember;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@ -228,11 +228,11 @@ public class BauCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void delete(ProxiedPlayer p, String[] command){
|
private static void delete(ProxiedPlayer p, String[] command){
|
||||||
SWInventory inventory = new SWInventory(p, 9, "§eDelete Confirm");
|
SWInventory inventory = new SWInventory(p, 9, "§e/Bau delete Bestätigen");
|
||||||
inventory.addItem(1, new SWItem(1, "§cDecline", 1), click -> {
|
inventory.addItem(0, new SWItem(0, "§cAbbrechen", 1), click -> {
|
||||||
inventory.close();
|
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)){
|
if(bau15(p, command, 2)){
|
||||||
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDeine Welt wird zurückgesetzt.");
|
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDeine Welt wird zurückgesetzt.");
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
||||||
|
@ -30,7 +30,7 @@ public abstract class BungeePacket {
|
|||||||
|
|
||||||
public void send(Server server) {
|
public void send(Server server) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeInt(getId());
|
out.writeByte(getId());
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
writeVars(out);
|
writeVars(out);
|
||||||
out.writeUTF(outputStream.toByteArray().toString());
|
out.writeUTF(outputStream.toByteArray().toString());
|
||||||
@ -38,12 +38,7 @@ public abstract class BungeePacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void send(ProxiedPlayer player) {
|
public void send(ProxiedPlayer player) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
send(player.getServer());
|
||||||
out.writeInt(getId());
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
writeVars(out);
|
|
||||||
out.writeUTF(outputStream.toByteArray().toString());
|
|
||||||
player.getServer().sendData("sw:bridge", out.toByteArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract int getId();
|
public abstract int getId();
|
||||||
|
11
src/de/steamwar/bungeecore/comms/PacketIdManager.java
Normale Datei
11
src/de/steamwar/bungeecore/comms/PacketIdManager.java
Normale Datei
@ -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;
|
||||||
|
}
|
@ -31,26 +31,25 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class SpigotReceiver extends BasicListener {
|
public class SpigotReceiver extends BasicListener {
|
||||||
|
|
||||||
private static final Map<Integer, SpigotHandler> handlerMap = new HashMap<>();
|
private static final Map<Byte, SpigotHandler> handlerMap = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
public void onPluginMessage(PluginMessageEvent event) {
|
||||||
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
|
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
|
||||||
return;
|
return;
|
||||||
|
if(!event.getSender().getAddress().getHostName().equals("localhost"))
|
||||||
|
return;
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||||
int handler = in.readInt();
|
Byte handler = in.readByte();
|
||||||
handlerMap.get(handler).handle(in);
|
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);
|
handlerMap.put(id, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerHandler(String name, SpigotHandler handler) {
|
|
||||||
handlerMap.put(name.hashCode(), handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
registerHandler("InventoryCallback", new InventoryCallbackHandler());
|
registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ package de.steamwar.bungeecore.comms.handlers;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import de.steamwar.bungeecore.comms.SpigotHandler;
|
import de.steamwar.bungeecore.comms.SpigotHandler;
|
||||||
import de.steamwar.bungeecore.comms.packets.inventory.InvCallback;
|
import de.steamwar.bungeecore.inventory.InvCallback;
|
||||||
import de.steamwar.bungeecore.comms.packets.inventory.SWInventory;
|
import de.steamwar.bungeecore.inventory.SWInventory;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -41,7 +41,11 @@ public class InventoryCallbackHandler implements SpigotHandler {
|
|||||||
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(byteArrayDataInput.readUTF());
|
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(byteArrayDataInput.readUTF());
|
||||||
inventoryHashMap.get(owner.getId()).handleCallback(clickType, pos);
|
inventoryHashMap.get(owner.getId()).handleCallback(clickType, pos);
|
||||||
}else if(type == CallbackType.CLOSE) {
|
}else if(type == CallbackType.CLOSE) {
|
||||||
|
if(inventoryHashMap.get(owner.getId()).isNext()) {
|
||||||
inventoryHashMap.get(owner.getId()).handleClose();
|
inventoryHashMap.get(owner.getId()).handleClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
inventoryHashMap.get(owner.getId()).setNext(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,25 +21,25 @@ package de.steamwar.bungeecore.comms.packets;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import de.steamwar.bungeecore.comms.BungeePacket;
|
import de.steamwar.bungeecore.comms.BungeePacket;
|
||||||
|
import de.steamwar.bungeecore.comms.PacketIdManager;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
public class CloseInventoryPacket extends BungeePacket {
|
public class CloseInventoryPacket extends BungeePacket {
|
||||||
|
|
||||||
ProxiedPlayer player;
|
final ProxiedPlayer player;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return "CloseInventory".hashCode();
|
return PacketIdManager.INVENTORY_CLOSE_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CloseInventoryPacket(ProxiedPlayer player) {
|
||||||
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
||||||
byteArrayDataOutput.writeInt(SteamwarUser.get(player).getId());
|
byteArrayDataOutput.writeInt(SteamwarUser.get(player).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CloseInventoryPacket setPlayer(ProxiedPlayer player) {
|
|
||||||
this.player = player;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,8 @@ package de.steamwar.bungeecore.comms.packets;
|
|||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
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.comms.BungeePacket;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
@ -31,10 +32,10 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class InventoryPacket extends BungeePacket {
|
public class InventoryPacket extends BungeePacket {
|
||||||
|
|
||||||
String title;
|
final String title;
|
||||||
int player;
|
final int player;
|
||||||
int size;
|
final int size;
|
||||||
HashMap<Integer, SWItem> items;
|
final HashMap<Integer, SWItem> items;
|
||||||
|
|
||||||
public InventoryPacket(int size, String title, ProxiedPlayer player) {
|
public InventoryPacket(int size, String title, ProxiedPlayer player) {
|
||||||
items = new HashMap<>();
|
items = new HashMap<>();
|
||||||
@ -45,7 +46,7 @@ public class InventoryPacket extends BungeePacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return "InventoryHandler".hashCode();
|
return PacketIdManager.INVENTORY_PACKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,23 +21,23 @@ package de.steamwar.bungeecore.comms.packets;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import de.steamwar.bungeecore.comms.BungeePacket;
|
import de.steamwar.bungeecore.comms.BungeePacket;
|
||||||
|
import de.steamwar.bungeecore.comms.PacketIdManager;
|
||||||
|
|
||||||
public class PingPacket extends BungeePacket {
|
public class PingPacket extends BungeePacket {
|
||||||
|
|
||||||
int id;
|
final int id;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return "PingHandler".hashCode();
|
return PacketIdManager.PING_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PingPacket(int id) {
|
||||||
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
||||||
byteArrayDataOutput.writeInt(id);
|
byteArrayDataOutput.writeInt(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PingPacket setUser(int id) {
|
|
||||||
this.id = id;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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 {
|
public interface InvCallback {
|
||||||
|
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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.handlers.InventoryCallbackHandler;
|
||||||
import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
|
import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
|
||||||
@ -35,6 +35,7 @@ public class SWInventory {
|
|||||||
private ProxiedPlayer player;
|
private ProxiedPlayer player;
|
||||||
private int size;
|
private int size;
|
||||||
private String title;
|
private String title;
|
||||||
|
private boolean next;
|
||||||
|
|
||||||
public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) {
|
public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) {
|
||||||
itemMap = new HashMap<>();
|
itemMap = new HashMap<>();
|
||||||
@ -42,6 +43,7 @@ public class SWInventory {
|
|||||||
this.player = proxiedPlayer;
|
this.player = proxiedPlayer;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
next = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addItem(SWItem item) {
|
public void addItem(SWItem item) {
|
||||||
@ -86,11 +88,20 @@ public class SWInventory {
|
|||||||
itemMap.get(pos).setCallback(callback);
|
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) {
|
public void handleCallback(InvCallback.ClickType type, int pos) {
|
||||||
itemMap.get(pos).getCallback().clicked(type);
|
itemMap.get(pos).getCallback().clicked(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleClose() {
|
public void handleClose() {
|
||||||
|
InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player).getId(), this);
|
||||||
if(close != null)
|
if(close != null)
|
||||||
close.clicked(null);
|
close.clicked(null);
|
||||||
}
|
}
|
||||||
@ -104,6 +115,6 @@ public class SWInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
new CloseInventoryPacket().setPlayer(player).send(player);
|
new CloseInventoryPacket(player).send(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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.Schematic;
|
||||||
import de.steamwar.bungeecore.sql.SchematicType;
|
import de.steamwar.bungeecore.sql.SchematicType;
|
@ -189,7 +189,7 @@ public class ChatListener extends BasicListener {
|
|||||||
for (String curr : msgSplits) {
|
for (String curr : msgSplits) {
|
||||||
if(curr.equalsIgnoreCase("@" + target.getName())) {
|
if(curr.equalsIgnoreCase("@" + target.getName())) {
|
||||||
builder.append("§e@").append(target.getName()).append(chatcolor).append(" ");
|
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 {
|
}else {
|
||||||
builder.append(curr).append(" ");
|
builder.append(curr).append(" ");
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ public class Schematic {
|
|||||||
|
|
||||||
public String getSchemItem() {
|
public String getSchemItem() {
|
||||||
try {
|
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");
|
return set.getString("Item");
|
||||||
} catch (SQLException throwables) {
|
} catch (SQLException throwables) {
|
||||||
return "CAULDRON_ITEM";
|
return "CAULDRON_ITEM";
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren