From dd72e2d367274ef8256b33c8a04103e269152713 Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 28 Mar 2025 19:45:12 +0100 Subject: [PATCH] char list delete ... --- java/src/game/Server.java | 2 +- java/src/game/command/DoubleParser.java | 42 +++++++++-------- java/src/game/gui/GuiCharacters.java | 46 +++++++++++++------ java/src/game/network/ClientPlayer.java | 15 ++++-- java/src/game/network/Player.java | 23 ++++++++-- java/src/game/packet/CPacketAction.java | 1 + .../src/game/packet/SPacketCharacterList.java | 8 ++++ 7 files changed, 93 insertions(+), 44 deletions(-) diff --git a/java/src/game/Server.java b/java/src/game/Server.java index 1910984..9f2828f 100755 --- a/java/src/game/Server.java +++ b/java/src/game/Server.java @@ -709,7 +709,7 @@ public final class Server implements Runnable, IThreadListener { Log.JNI.info(loginUser + "[" + connection.getCutAddress() + "] hat sich mit Objekt-ID " + player.getId() + " auf Level " + world.dimension.getDimensionId() + ": " - + String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? " (Charakter-Editor)" : "'" + player.getCommandName() + "'") + ")"); + + String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? "Charakter-Editor" : "'" + player.getCommandName() + "'") + ")"); if(Config.preloadLocal && conn.isLocal() && this.players.size() == 1) this.preload(world, (int)player.posX, (int)player.posZ); diff --git a/java/src/game/command/DoubleParser.java b/java/src/game/command/DoubleParser.java index 19fec1f..a629fa9 100644 --- a/java/src/game/command/DoubleParser.java +++ b/java/src/game/command/DoubleParser.java @@ -59,18 +59,19 @@ public class DoubleParser extends DefaultingParser { public Double getDefault(CommandEnvironment env) { Position pos = this.defType == null ? null : env.getExecutor().getExecPos(); - switch(this.defType) { - case X: - return pos == null ? null : pos.x; - case Y: - return pos == null ? null : pos.y; - case Z: - return pos == null ? null : pos.z; - case YAW: - return pos == null ? null : (double)pos.yaw; - case PITCH: - return pos == null ? null : (double)pos.pitch; - } + if(this.defType != null) + switch(this.defType) { + case X: + return pos == null ? null : pos.x; + case Y: + return pos == null ? null : pos.y; + case Z: + return pos == null ? null : pos.z; + case YAW: + return pos == null ? null : (double)pos.yaw; + case PITCH: + return pos == null ? null : (double)pos.pitch; + } return (Double)super.getDefault(env); } @@ -80,14 +81,15 @@ public class DoubleParser extends DefaultingParser { public Collection getCompletions(CommandEnvironment env) { BlockPos pos = this.defType == null ? null : env.getExecutor().getPointedPosition(); - switch(this.defType) { - case X: - return pos == null ? null : Lists.newArrayList("" + pos.getX()); - case Y: - return pos == null ? null : Lists.newArrayList("" + pos.getY()); - case Z: - return pos == null ? null : Lists.newArrayList("" + pos.getZ()); - } + if(this.defType != null) + switch(this.defType) { + case X: + return pos == null ? null : Lists.newArrayList("" + pos.getX()); + case Y: + return pos == null ? null : Lists.newArrayList("" + pos.getY()); + case Z: + return pos == null ? null : Lists.newArrayList("" + pos.getZ()); + } return super.getCompletions(env); } } diff --git a/java/src/game/gui/GuiCharacters.java b/java/src/game/gui/GuiCharacters.java index 8d25b3b..53089b6 100644 --- a/java/src/game/gui/GuiCharacters.java +++ b/java/src/game/gui/GuiCharacters.java @@ -11,7 +11,7 @@ import game.gui.element.TransparentBox; import game.packet.CPacketAction; import game.renderer.Drawing; -public class GuiCharacters extends GuiList +public class GuiCharacters extends GuiList implements ActButton.Callback { protected class CharacterEntry implements ListEntry { @@ -40,6 +40,8 @@ public class GuiCharacters extends GuiList public void select(boolean dclick, int mx, int my) { + if(dclick) + GuiCharacters.this.use(GuiCharacters.this.actionButtom, Mode.PRIMARY); GuiCharacters.this.updateButtons(); } } @@ -48,15 +50,17 @@ public class GuiCharacters extends GuiList private TransparentBox descField; private ActButton actionButtom; + private ActButton deleteButtom; private GuiCharacters() { } private void updateButtons() { CharacterEntry entry = this.getSelected(); - this.descField.setText(entry != null && entry.character == null ? "*neuer Charakter*" : (entry == null || entry.character.info == null ? "*keine Beschreibung vorhanden*" : this.getSelected().character.info)); + this.descField.setText(entry == null ? "" : (entry.character == null ? "*neuer Charakter*" : (entry.character.info == null ? "*keine Beschreibung vorhanden*" : this.getSelected().character.info))); this.actionButtom.setText(entry != null && entry.character == null ? "Charakter erstellen" : "Charakter spielen"); - this.actionButtom.enabled = entry != null; + this.actionButtom.enabled = entry != null && !entry.initial; + this.deleteButtom.enabled = entry != null && entry.character != null && !entry.initial; } public void init(int width, int height) @@ -73,18 +77,9 @@ public class GuiCharacters extends GuiList this.setSelected(initialSelection); } this.descField = this.add(new TransparentBox(width - 390, 62, 380, height - 124, "", false)); - this.actionButtom = this.add(new ActButton(width / 2 - 200, height - 28, 198, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { - CharacterEntry entry = GuiCharacters.this.getSelected(); - if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) { - if(entry.character == null) - GuiCharacters.this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_EDITOR)); - else - GuiCharacters.this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_CHARACTER, GuiCharacters.this.selectedElement)); - } - } - }, "")); - this.add(new NavButton(width / 2 + 2, height - 28, 198, 24, GuiMenu.INSTANCE, "Abbrechen")); + this.deleteButtom = this.add(new ActButton(width / 2 - 304, height - 28, 200, 24, this, "Charakter löschen")); + this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 28, 200, 24, this, "")); + this.add(new NavButton(width / 2 + 104, height - 28, 200, 24, GuiMenu.INSTANCE, "Abbrechen")); this.updateButtons(); } @@ -101,4 +96,25 @@ public class GuiCharacters extends GuiList { return 36 + 4; } + + public void use(ActButton elem, Mode action) { + CharacterEntry entry = GuiCharacters.this.getSelected(); + if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) { + if(elem == this.actionButtom) { + if(entry.character == null) + this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_EDITOR)); + else + this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_CHARACTER, this.selectedElement)); + } + else if(elem == this.deleteButtom && entry.character != null) { + this.gm.displayGuiScreen(new GuiConfirm(new GuiConfirm.Callback() { + public void confirm(boolean confirmed) { + if(confirmed) + GuiCharacters.this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.DELETE_CHARACTER, GuiCharacters.this.selectedElement)); + GuiCharacters.this.gm.displayGuiScreen(GuiCharacters.this); + } + }, "Möchtest du diesen Charakter wirklich löschen?", "Der Fortschritt, die Gegenstände und die Historie von \"" + entry.character.name + "\" werden für imer verloren sein!", "Löschen", "Abbrechen")); + } + } + } } diff --git a/java/src/game/network/ClientPlayer.java b/java/src/game/network/ClientPlayer.java index 8333332..3cf789f 100755 --- a/java/src/game/network/ClientPlayer.java +++ b/java/src/game/network/ClientPlayer.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import game.collect.Lists; import game.collect.Maps; import game.Game; @@ -27,6 +28,7 @@ import game.entity.types.EntityLiving; import game.gui.Gui; import game.gui.GuiConsole; import game.gui.GuiChar; +import game.gui.GuiCharacters; import game.gui.container.GuiMachine; import game.gui.container.GuiMerchant; import game.init.EntityRegistry; @@ -141,7 +143,7 @@ public class ClientPlayer extends NetHandler private boolean doneLoadingTerrain; // private boolean travelSound; private final Map playerList = Maps.newTreeMap(); - private final Map characterList = Maps.newHashMap(); + private final List characterList = Lists.newArrayList(); // private final List> players = Lists.newArrayList(); private int selectedCharacter = -1; @@ -1525,15 +1527,20 @@ public class ClientPlayer extends NetHandler for(Entry data : packet.getEntries()) { if(data.getValue() == null) - this.characterList.remove(data.getKey()); + this.characterList.remove(data.getKey().intValue()); + else if(data.getKey() < this.characterList.size()) + this.characterList.set(data.getKey(), data.getValue()); else - this.characterList.put(data.getKey(), data.getValue()); + this.characterList.add(data.getKey(), data.getValue()); } this.selectedCharacter = packet.getSelected(); if(this.gameController.charEditor && this.selectedCharacter >= 0) { this.gameController.charEditor = false; this.gameController.displayGuiScreen(null); } + else if(this.gameController.open instanceof GuiCharacters) { + this.gameController.displayGuiScreen(this.gameController.open); + } } public void handleKeepAlive(SPacketKeepAlive packetIn) @@ -1890,7 +1897,7 @@ public class ClientPlayer extends NetHandler public Collection getCharacterList() { - return this.characterList.values(); + return this.characterList; } public int getSelectedCharacter() diff --git a/java/src/game/network/Player.java b/java/src/game/network/Player.java index 38b7a23..b767bbe 100755 --- a/java/src/game/network/Player.java +++ b/java/src/game/network/Player.java @@ -2508,16 +2508,18 @@ public class Player extends NetHandler implements ICrafting, Executor switch (action) { - case OPEN_EDITOR: + case OPEN_EDITOR: { this.charEditor = true; // if(this.local) // this.server.resetProgress(); NBTTagCompound tag = this.server.swapPlayer(this, null, EntityHuman.class); if(!this.characters.isEmpty() && this.selected >= 0) this.characters.set(this.selected, tag); + int last = this.selected; this.selected = -1; - this.sendPacket(new SPacketCharacterList(this.selected)); + this.sendPacket(!this.characters.isEmpty() && last >= 0 ? new SPacketCharacterList(this.selected, last, this.getCharacterInfo(tag)) : new SPacketCharacterList(this.selected)); break; + } case CLOSE_EDITOR: { this.charEditor = false; @@ -2538,16 +2540,29 @@ public class Player extends NetHandler implements ICrafting, Executor break; } - case SELECT_CHARACTER: + case SELECT_CHARACTER: { int index = packetIn.getAuxData(); if(index == this.selected || index >= this.characters.size() || index < 0) return; NBTTagCompound etag = this.server.swapPlayer(this, this.characters.get(index), null); if(!this.characters.isEmpty() && this.selected >= 0) this.characters.set(this.selected, etag); + int last = this.selected; this.selected = index; - this.sendPacket(new SPacketCharacterList(this.selected)); + this.sendPacket(!this.characters.isEmpty() && last >= 0 ? new SPacketCharacterList(this.selected, last, this.getCharacterInfo(etag)) : new SPacketCharacterList(this.selected)); break; + } + + case DELETE_CHARACTER: { + int index = packetIn.getAuxData(); + if(index == this.selected || index >= this.characters.size() || index < 0) + return; + if(this.selected > index) + this.selected -= 1; + this.characters.remove(index); + this.sendPacket(new SPacketCharacterList(this.selected, index, null)); + break; + } case START_SNEAKING: this.entity.setSneaking(true); diff --git a/java/src/game/packet/CPacketAction.java b/java/src/game/packet/CPacketAction.java index f65fd47..aad4ac0 100755 --- a/java/src/game/packet/CPacketAction.java +++ b/java/src/game/packet/CPacketAction.java @@ -58,6 +58,7 @@ public class CPacketAction implements Packet OPEN_EDITOR, CLOSE_EDITOR, SELECT_CHARACTER, + DELETE_CHARACTER, SWING_ARM, SET_ITEMSLOT, START_SNEAKING, diff --git a/java/src/game/packet/SPacketCharacterList.java b/java/src/game/packet/SPacketCharacterList.java index b5a0440..9e50e49 100644 --- a/java/src/game/packet/SPacketCharacterList.java +++ b/java/src/game/packet/SPacketCharacterList.java @@ -44,6 +44,10 @@ public class SPacketCharacterList implements Packet { for(int z = 0; z < n; z++) { int id = buf.readVarIntFromBuffer(); String name = buf.readStringFromBuffer(Player.MAX_NICK_LENGTH); + if(name.isEmpty()) { + this.players.put(id, null); + continue; + } String info = buf.readStringFromBuffer(Player.MAX_INFO_LENGTH); Alignment align = buf.readEnumValue(Alignment.class); String dim = buf.readStringFromBuffer(256); @@ -60,6 +64,10 @@ public class SPacketCharacterList implements Packet { for(Entry data : this.players.entrySet()) { PlayerCharacter chr = data.getValue(); buf.writeVarIntToBuffer(data.getKey()); + if(chr == null) { + buf.writeString(""); + continue; + } buf.writeString(chr.name); buf.writeString(chr.info); buf.writeEnumValue(chr.align);