char list delete ...

This commit is contained in:
Sen 2025-03-28 19:45:12 +01:00
parent 5843594ba3
commit dd72e2d367
7 changed files with 93 additions and 44 deletions

View file

@ -709,7 +709,7 @@ public final class Server implements Runnable, IThreadListener {
Log.JNI.info(loginUser + "[" + connection.getCutAddress() + "] hat sich mit Objekt-ID " Log.JNI.info(loginUser + "[" + connection.getCutAddress() + "] hat sich mit Objekt-ID "
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": " + 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) if(Config.preloadLocal && conn.isLocal() && this.players.size() == 1)
this.preload(world, (int)player.posX, (int)player.posZ); this.preload(world, (int)player.posX, (int)player.posZ);

View file

@ -59,18 +59,19 @@ public class DoubleParser extends DefaultingParser {
public Double getDefault(CommandEnvironment env) { public Double getDefault(CommandEnvironment env) {
Position pos = this.defType == null ? null : env.getExecutor().getExecPos(); Position pos = this.defType == null ? null : env.getExecutor().getExecPos();
switch(this.defType) { if(this.defType != null)
case X: switch(this.defType) {
return pos == null ? null : pos.x; case X:
case Y: return pos == null ? null : pos.x;
return pos == null ? null : pos.y; case Y:
case Z: return pos == null ? null : pos.y;
return pos == null ? null : pos.z; case Z:
case YAW: return pos == null ? null : pos.z;
return pos == null ? null : (double)pos.yaw; case YAW:
case PITCH: return pos == null ? null : (double)pos.yaw;
return pos == null ? null : (double)pos.pitch; case PITCH:
} return pos == null ? null : (double)pos.pitch;
}
return (Double)super.getDefault(env); return (Double)super.getDefault(env);
} }
@ -80,14 +81,15 @@ public class DoubleParser extends DefaultingParser {
public Collection<String> getCompletions(CommandEnvironment env) { public Collection<String> getCompletions(CommandEnvironment env) {
BlockPos pos = this.defType == null ? null : env.getExecutor().getPointedPosition(); BlockPos pos = this.defType == null ? null : env.getExecutor().getPointedPosition();
switch(this.defType) { if(this.defType != null)
case X: switch(this.defType) {
return pos == null ? null : Lists.newArrayList("" + pos.getX()); case X:
case Y: return pos == null ? null : Lists.newArrayList("" + pos.getX());
return pos == null ? null : Lists.newArrayList("" + pos.getY()); case Y:
case Z: return pos == null ? null : Lists.newArrayList("" + pos.getY());
return pos == null ? null : Lists.newArrayList("" + pos.getZ()); case Z:
} return pos == null ? null : Lists.newArrayList("" + pos.getZ());
}
return super.getCompletions(env); return super.getCompletions(env);
} }
} }

View file

@ -11,7 +11,7 @@ import game.gui.element.TransparentBox;
import game.packet.CPacketAction; import game.packet.CPacketAction;
import game.renderer.Drawing; import game.renderer.Drawing;
public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> implements ActButton.Callback
{ {
protected class CharacterEntry implements ListEntry protected class CharacterEntry implements ListEntry
{ {
@ -40,6 +40,8 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
public void select(boolean dclick, int mx, int my) public void select(boolean dclick, int mx, int my)
{ {
if(dclick)
GuiCharacters.this.use(GuiCharacters.this.actionButtom, Mode.PRIMARY);
GuiCharacters.this.updateButtons(); GuiCharacters.this.updateButtons();
} }
} }
@ -48,15 +50,17 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
private TransparentBox descField; private TransparentBox descField;
private ActButton actionButtom; private ActButton actionButtom;
private ActButton deleteButtom;
private GuiCharacters() { private GuiCharacters() {
} }
private void updateButtons() { private void updateButtons() {
CharacterEntry entry = this.getSelected(); 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.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) public void init(int width, int height)
@ -73,18 +77,9 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
this.setSelected(initialSelection); this.setSelected(initialSelection);
} }
this.descField = this.add(new TransparentBox(width - 390, 62, 380, height - 124, "", false)); 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() { this.deleteButtom = this.add(new ActButton(width / 2 - 304, height - 28, 200, 24, this, "Charakter löschen"));
public void use(ActButton elem, Mode action) { this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 28, 200, 24, this, ""));
CharacterEntry entry = GuiCharacters.this.getSelected(); this.add(new NavButton(width / 2 + 104, height - 28, 200, 24, GuiMenu.INSTANCE, "Abbrechen"));
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.updateButtons(); this.updateButtons();
} }
@ -101,4 +96,25 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
{ {
return 36 + 4; 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"));
}
}
}
} }

View file

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import game.collect.Lists;
import game.collect.Maps; import game.collect.Maps;
import game.Game; import game.Game;
@ -27,6 +28,7 @@ import game.entity.types.EntityLiving;
import game.gui.Gui; import game.gui.Gui;
import game.gui.GuiConsole; import game.gui.GuiConsole;
import game.gui.GuiChar; import game.gui.GuiChar;
import game.gui.GuiCharacters;
import game.gui.container.GuiMachine; import game.gui.container.GuiMachine;
import game.gui.container.GuiMerchant; import game.gui.container.GuiMerchant;
import game.init.EntityRegistry; import game.init.EntityRegistry;
@ -141,7 +143,7 @@ public class ClientPlayer extends NetHandler
private boolean doneLoadingTerrain; private boolean doneLoadingTerrain;
// private boolean travelSound; // private boolean travelSound;
private final Map<String, Integer> playerList = Maps.<String, Integer>newTreeMap(); private final Map<String, Integer> playerList = Maps.<String, Integer>newTreeMap();
private final Map<Integer, PlayerCharacter> characterList = Maps.<Integer, PlayerCharacter>newHashMap(); private final List<PlayerCharacter> characterList = Lists.<PlayerCharacter>newArrayList();
// private final List<Entry<String, Integer>> players = Lists.newArrayList(); // private final List<Entry<String, Integer>> players = Lists.newArrayList();
private int selectedCharacter = -1; private int selectedCharacter = -1;
@ -1525,15 +1527,20 @@ public class ClientPlayer extends NetHandler
for(Entry<Integer, PlayerCharacter> data : packet.getEntries()) { for(Entry<Integer, PlayerCharacter> data : packet.getEntries()) {
if(data.getValue() == null) 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 else
this.characterList.put(data.getKey(), data.getValue()); this.characterList.add(data.getKey(), data.getValue());
} }
this.selectedCharacter = packet.getSelected(); this.selectedCharacter = packet.getSelected();
if(this.gameController.charEditor && this.selectedCharacter >= 0) { if(this.gameController.charEditor && this.selectedCharacter >= 0) {
this.gameController.charEditor = false; this.gameController.charEditor = false;
this.gameController.displayGuiScreen(null); this.gameController.displayGuiScreen(null);
} }
else if(this.gameController.open instanceof GuiCharacters) {
this.gameController.displayGuiScreen(this.gameController.open);
}
} }
public void handleKeepAlive(SPacketKeepAlive packetIn) public void handleKeepAlive(SPacketKeepAlive packetIn)
@ -1890,7 +1897,7 @@ public class ClientPlayer extends NetHandler
public Collection<PlayerCharacter> getCharacterList() public Collection<PlayerCharacter> getCharacterList()
{ {
return this.characterList.values(); return this.characterList;
} }
public int getSelectedCharacter() public int getSelectedCharacter()

View file

@ -2508,16 +2508,18 @@ public class Player extends NetHandler implements ICrafting, Executor
switch (action) switch (action)
{ {
case OPEN_EDITOR: case OPEN_EDITOR: {
this.charEditor = true; this.charEditor = true;
// if(this.local) // if(this.local)
// this.server.resetProgress(); // this.server.resetProgress();
NBTTagCompound tag = this.server.swapPlayer(this, null, EntityHuman.class); NBTTagCompound tag = this.server.swapPlayer(this, null, EntityHuman.class);
if(!this.characters.isEmpty() && this.selected >= 0) if(!this.characters.isEmpty() && this.selected >= 0)
this.characters.set(this.selected, tag); this.characters.set(this.selected, tag);
int last = this.selected;
this.selected = -1; 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; break;
}
case CLOSE_EDITOR: { case CLOSE_EDITOR: {
this.charEditor = false; this.charEditor = false;
@ -2538,16 +2540,29 @@ public class Player extends NetHandler implements ICrafting, Executor
break; break;
} }
case SELECT_CHARACTER: case SELECT_CHARACTER: {
int index = packetIn.getAuxData(); int index = packetIn.getAuxData();
if(index == this.selected || index >= this.characters.size() || index < 0) if(index == this.selected || index >= this.characters.size() || index < 0)
return; return;
NBTTagCompound etag = this.server.swapPlayer(this, this.characters.get(index), null); NBTTagCompound etag = this.server.swapPlayer(this, this.characters.get(index), null);
if(!this.characters.isEmpty() && this.selected >= 0) if(!this.characters.isEmpty() && this.selected >= 0)
this.characters.set(this.selected, etag); this.characters.set(this.selected, etag);
int last = this.selected;
this.selected = index; 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; 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: case START_SNEAKING:
this.entity.setSneaking(true); this.entity.setSneaking(true);

View file

@ -58,6 +58,7 @@ public class CPacketAction implements Packet<Player>
OPEN_EDITOR, OPEN_EDITOR,
CLOSE_EDITOR, CLOSE_EDITOR,
SELECT_CHARACTER, SELECT_CHARACTER,
DELETE_CHARACTER,
SWING_ARM, SWING_ARM,
SET_ITEMSLOT, SET_ITEMSLOT,
START_SNEAKING, START_SNEAKING,

View file

@ -44,6 +44,10 @@ public class SPacketCharacterList implements Packet<ClientPlayer> {
for(int z = 0; z < n; z++) { for(int z = 0; z < n; z++) {
int id = buf.readVarIntFromBuffer(); int id = buf.readVarIntFromBuffer();
String name = buf.readStringFromBuffer(Player.MAX_NICK_LENGTH); 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); String info = buf.readStringFromBuffer(Player.MAX_INFO_LENGTH);
Alignment align = buf.readEnumValue(Alignment.class); Alignment align = buf.readEnumValue(Alignment.class);
String dim = buf.readStringFromBuffer(256); String dim = buf.readStringFromBuffer(256);
@ -60,6 +64,10 @@ public class SPacketCharacterList implements Packet<ClientPlayer> {
for(Entry<Integer, PlayerCharacter> data : this.players.entrySet()) { for(Entry<Integer, PlayerCharacter> data : this.players.entrySet()) {
PlayerCharacter chr = data.getValue(); PlayerCharacter chr = data.getValue();
buf.writeVarIntToBuffer(data.getKey()); buf.writeVarIntToBuffer(data.getKey());
if(chr == null) {
buf.writeString("");
continue;
}
buf.writeString(chr.name); buf.writeString(chr.name);
buf.writeString(chr.info); buf.writeString(chr.info);
buf.writeEnumValue(chr.align); buf.writeEnumValue(chr.align);