char list delete ...
This commit is contained in:
parent
5843594ba3
commit
dd72e2d367
7 changed files with 93 additions and 44 deletions
|
@ -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);
|
||||
|
|
|
@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import game.gui.element.TransparentBox;
|
|||
import game.packet.CPacketAction;
|
||||
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
|
||||
{
|
||||
|
@ -40,6 +40,8 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
|
|||
|
||||
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<GuiCharacters.CharacterEntry>
|
|||
|
||||
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<GuiCharacters.CharacterEntry>
|
|||
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<GuiCharacters.CharacterEntry>
|
|||
{
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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 int selectedCharacter = -1;
|
||||
|
||||
|
@ -1525,15 +1527,20 @@ public class ClientPlayer extends NetHandler
|
|||
|
||||
for(Entry<Integer, PlayerCharacter> 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<PlayerCharacter> getCharacterList()
|
||||
{
|
||||
return this.characterList.values();
|
||||
return this.characterList;
|
||||
}
|
||||
|
||||
public int getSelectedCharacter()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -58,6 +58,7 @@ public class CPacketAction implements Packet<Player>
|
|||
OPEN_EDITOR,
|
||||
CLOSE_EDITOR,
|
||||
SELECT_CHARACTER,
|
||||
DELETE_CHARACTER,
|
||||
SWING_ARM,
|
||||
SET_ITEMSLOT,
|
||||
START_SNEAKING,
|
||||
|
|
|
@ -44,6 +44,10 @@ public class SPacketCharacterList implements Packet<ClientPlayer> {
|
|||
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<ClientPlayer> {
|
|||
for(Entry<Integer, PlayerCharacter> 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue