Archiviert
1
0

Refactored Some Code

Dieser Commit ist enthalten in:
Chaoscaot 2020-09-26 12:44:31 +02:00
Ursprung 96bc29b105
Commit 29d7cf0819
4 geänderte Dateien mit 20 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -229,8 +229,8 @@ public class BauCommand {
private static void delete(ProxiedPlayer p, String[] command){
SWInventory inventory = new SWInventory(p, 9, "§eWirklich Welt löschen?");
inventory.addItem(8, new SWItem(8, "§cAbbrechen", 1), click -> inventory.close());
inventory.addItem(0, new SWItem(0, "§aLöschen", 10), click -> {
inventory.addItem(new SWItem(8, "§cAbbrechen", 1), click -> inventory.close());
inventory.addItem(new SWItem(0, "§aLöschen", 10), click -> {
if(bau15(p, command, 2)){
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId());

Datei anzeigen

@ -20,10 +20,13 @@
package de.steamwar.bungeecore.comms.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
import de.steamwar.bungeecore.inventory.InvCallback;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.ProxyServer;
import java.util.HashMap;
import java.util.Map;
@ -36,6 +39,12 @@ public class InventoryCallbackHandler implements SpigotHandler {
public void handle(ByteArrayDataInput byteArrayDataInput) {
SteamwarUser owner = SteamwarUser.get(byteArrayDataInput.readInt());
CallbackType type = CallbackType.valueOf(byteArrayDataInput.readUTF());
if(!inventoryHashMap.containsKey(owner.getId())) {
BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§eAuf grund eines neuladens ist dein Inventar verloren gegangen.");
if(type == CallbackType.CLICK) {
new CloseInventoryPacket(owner.getId()).send(ProxyServer.getInstance().getPlayer(owner.getUuid()));
}
}
if(type == CallbackType.CLICK) {
int pos = byteArrayDataInput.readInt();
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(byteArrayDataInput.readUTF());

Datei anzeigen

@ -22,24 +22,22 @@ 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;
final int player;
@Override
public int getId() {
return PacketIdManager.INVENTORY_CLOSE_PACKET;
}
public CloseInventoryPacket(ProxiedPlayer player) {
public CloseInventoryPacket(int player) {
this.player = player;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(SteamwarUser.get(player).getId());
byteArrayDataOutput.writeInt(player);
}
}

Datei anzeigen

@ -50,6 +50,11 @@ public class SWInventory {
itemMap.put(item.getPosition(), item);
}
public void addItem(SWItem item, InvCallback callback) {
item.setCallback(callback);
itemMap.put(item.getPosition(), item);
}
public void addItem(int position, SWItem item) {
itemMap.put(position, item);
}
@ -116,7 +121,7 @@ public class SWInventory {
}
public void close() {
new CloseInventoryPacket(player).send(player);
new CloseInventoryPacket(SteamwarUser.get(player).getId()).send(player);
}
public void setClose(InvCallback close) {