command completion
This commit is contained in:
parent
0839beb98e
commit
a8f6af2b37
11 changed files with 400 additions and 347 deletions
|
@ -789,8 +789,11 @@ public class Game implements IThreadListener {
|
||||||
entity.getHealth() + TextColor.GRAY + " / " + EntityLiving.getMaxHpColor(entity.getMaxHealth()) +
|
entity.getHealth() + TextColor.GRAY + " / " + EntityLiving.getMaxHpColor(entity.getMaxHealth()) +
|
||||||
entity.getMaxHealth() + TextColor.GRAY + "]";
|
entity.getMaxHealth() + TextColor.GRAY + "]";
|
||||||
Drawing.drawTextboxCentered(s, x, y, 0x3f000000);
|
Drawing.drawTextboxCentered(s, x, y, 0x3f000000);
|
||||||
Drawing.drawRectColor(x - 200, y + 20, 400, 10, 0xff000000);
|
Drawing.drawRect2GradBorder(x - 200, y + 20, 400, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f);
|
||||||
Drawing.drawRectColor(x - 200, y + 20, (int)(400.0f * ((float)entity.getHealth() / (float)entity.getMaxHealth())), 10, 0xff000000 | entity.getColor());
|
Drawing.drawGradient(x - 200 + 2, y + 20 + 2, (int)(396.0f * ((float)entity.getHealth() / (float)entity.getMaxHealth())), 6, entity.getColor() | 0xff000000,
|
||||||
|
Drawing.mixColor(entity.getColor() | 0xff000000, 0xff000000));
|
||||||
|
// Drawing.drawRectColor(x - 200, y + 20, 400, 10, 0xff000000);
|
||||||
|
// Drawing.drawRectColor(x - 200, y + 20, , 0xff000000 | );
|
||||||
y += 40;
|
y += 40;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2121,8 +2124,11 @@ public class Game implements IThreadListener {
|
||||||
this.full(!this.fullscreen);
|
this.full(!this.fullscreen);
|
||||||
}
|
}
|
||||||
if(!(this.open instanceof GuiLoading)) {
|
if(!(this.open instanceof GuiLoading)) {
|
||||||
if(!(this.open instanceof GuiConsole) && Bind.COMMAND.isPressed()) {
|
if(!(this.open instanceof GuiConsole) && Bind.CONSOLE.isPressed()) {
|
||||||
this.displayGuiScreen(GuiConsole.INSTANCE);
|
this.displayGuiScreen(GuiConsole.INSTANCE.setFull(true));
|
||||||
|
}
|
||||||
|
else if(this.open == null && Bind.COMMAND.isPressed()) {
|
||||||
|
this.displayGuiScreen(GuiConsole.INSTANCE.setFull(false));
|
||||||
}
|
}
|
||||||
// if(this.theWorld != null && this.open == null && Bind.COMMAND.isPressed()) {
|
// if(this.theWorld != null && this.open == null && Bind.COMMAND.isPressed()) {
|
||||||
// this.displayGuiScreen(GuiChat.INSTANCE);
|
// this.displayGuiScreen(GuiChat.INSTANCE);
|
||||||
|
@ -2723,6 +2729,10 @@ public class Game implements IThreadListener {
|
||||||
return (T)cvars.get(name);
|
return (T)cvars.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterable<String> getVars() {
|
||||||
|
return this.cvars.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
public void setDirty() {
|
public void setDirty() {
|
||||||
cfgDirty = true;
|
cfgDirty = true;
|
||||||
}
|
}
|
||||||
|
@ -2859,7 +2869,7 @@ public class Game implements IThreadListener {
|
||||||
}
|
}
|
||||||
Log.CONSOLE.user(TextColor.GREEN + "CVARs insgesamt registriert: %d", cvars.size());
|
Log.CONSOLE.user(TextColor.GREEN + "CVARs insgesamt registriert: %d", cvars.size());
|
||||||
// this.command(line);
|
// this.command(line);
|
||||||
// return;
|
return;
|
||||||
}
|
}
|
||||||
else if(line.startsWith("#")) {
|
else if(line.startsWith("#")) {
|
||||||
String tok = line.substring(1);
|
String tok = line.substring(1);
|
||||||
|
@ -2882,7 +2892,7 @@ public class Game implements IThreadListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(this.thePlayer != null && this.getNetHandler() != null)
|
if(this.thePlayer != null && this.getNetHandler() != null)
|
||||||
this.getNetHandler().addToSendQueue(new CPacketMessage(CPacketMessage.Type.CHAT, line));
|
this.getNetHandler().addToSendQueue(new CPacketMessage(line.startsWith("/") ? CPacketMessage.Type.COMMAND : CPacketMessage.Type.CHAT, line.startsWith("/") ? line.substring(1) : line));
|
||||||
// Log.CONSOLE.user("%s", line);
|
// Log.CONSOLE.user("%s", line);
|
||||||
// this.command(line);
|
// this.command(line);
|
||||||
}
|
}
|
||||||
|
@ -2900,6 +2910,7 @@ public class Game implements IThreadListener {
|
||||||
|
|
||||||
public void log(String prefixed, String line) {
|
public void log(String prefixed, String line) {
|
||||||
String msg = this.conTimestamps ? prefixed : line;
|
String msg = this.conTimestamps ? prefixed : line;
|
||||||
|
// this.addMessage(msg);
|
||||||
if((buffer.length() + msg.length() + 1) > LOG_BUFFER) {
|
if((buffer.length() + msg.length() + 1) > LOG_BUFFER) {
|
||||||
int offset = (msg.length() + 1) > 1024 ? (msg.length() + 1) : 1024;
|
int offset = (msg.length() + 1) > 1024 ? (msg.length() + 1) : 1024;
|
||||||
int nl = buffer.indexOf('\n', offset);
|
int nl = buffer.indexOf('\n', offset);
|
||||||
|
|
|
@ -4,15 +4,18 @@ import java.util.List;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import game.Game;
|
||||||
|
import game.color.TextColor;
|
||||||
import game.gui.element.ActButton;
|
import game.gui.element.ActButton;
|
||||||
import game.gui.element.Fill;
|
import game.gui.element.Fill;
|
||||||
import game.gui.element.Textbox;
|
import game.gui.element.Textbox;
|
||||||
import game.gui.element.Textbox.Action;
|
import game.gui.element.Textbox.Action;
|
||||||
import game.gui.element.TransparentBox;
|
import game.gui.element.TransparentBox;
|
||||||
import game.log.Log;
|
|
||||||
import game.network.NetHandlerPlayServer;
|
import game.network.NetHandlerPlayServer;
|
||||||
import game.packet.CPacketComplete;
|
import game.packet.CPacketComplete;
|
||||||
import game.util.ExtMath;
|
import game.util.ExtMath;
|
||||||
|
import game.vars.BoolVar;
|
||||||
|
import game.vars.CVar;
|
||||||
import game.window.Keysym;
|
import game.window.Keysym;
|
||||||
|
|
||||||
public class GuiConsole extends Gui implements Textbox.Callback {
|
public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
|
@ -20,27 +23,39 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
|
|
||||||
private final List<String> sentMessages = Lists.<String>newArrayList();
|
private final List<String> sentMessages = Lists.<String>newArrayList();
|
||||||
|
|
||||||
|
private boolean full;
|
||||||
|
|
||||||
private String historyBuffer = "";
|
private String historyBuffer = "";
|
||||||
private int sentHistoryCursor = -1;
|
private int sentHistoryCursor = -1;
|
||||||
private boolean playerNamesFound;
|
private boolean playerNamesFound;
|
||||||
private boolean waitingOnAutocomplete;
|
private boolean waitingOnAutocomplete;
|
||||||
|
private boolean reverse;
|
||||||
|
private String prefixFirst;
|
||||||
private int autocompleteIndex;
|
private int autocompleteIndex;
|
||||||
private List<String> foundPlayerNames = Lists.<String>newArrayList();
|
private List<String> foundPlayerNames = Lists.<String>newArrayList();
|
||||||
private Textbox inputField;
|
private Textbox inputField;
|
||||||
private TransparentBox logBox;
|
private TransparentBox logBox;
|
||||||
|
|
||||||
|
public GuiConsole setFull(boolean full) {
|
||||||
|
this.full = full;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void init(int width, int height) {
|
public void init(int width, int height) {
|
||||||
this.addSelector("con_autoclose", 0, 0, 160, 24);
|
if(this.full) {
|
||||||
this.addSelector("con_timestamps", 160, 0, 160, 24);
|
this.addSelector("con_autoclose", 0, 0, 160, 24);
|
||||||
this.addSelector("con_loglevel", 320, 0, 160, 24);
|
this.addSelector("con_timestamps", 160, 0, 160, 24);
|
||||||
this.add(new ActButton(480, 0, 160, 24, new ActButton.Callback() {
|
this.addSelector("con_loglevel", 320, 0, 160, 24);
|
||||||
public void use(ActButton elem, ActButton.Mode action) {
|
this.add(new ActButton(480, 0, 160, 24, new ActButton.Callback() {
|
||||||
GuiConsole.this.reset();
|
public void use(ActButton elem, ActButton.Mode action) {
|
||||||
GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer());
|
GuiConsole.this.reset();
|
||||||
}
|
GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer());
|
||||||
}, "Löschen"));
|
}
|
||||||
this.logBox = this.add(new TransparentBox(0, 24, width, height - 48, this.gm.getBuffer()));
|
}, "Löschen"));
|
||||||
this.add(new Fill(640, 0, width - 640, 24));
|
}
|
||||||
|
this.logBox = this.add(new TransparentBox(0, this.full ? 24 : 0, width, height - (this.full ? 48 : 24), this.gm.getBuffer()));
|
||||||
|
if(this.full)
|
||||||
|
this.add(new Fill(640, 0, width - 640, 24));
|
||||||
this.inputField = this.add(new Textbox(0, height - 24, width, 24, NetHandlerPlayServer.MAX_CMD_LENGTH, true, this, ""));
|
this.inputField = this.add(new Textbox(0, height - 24, width, 24, NetHandlerPlayServer.MAX_CMD_LENGTH, true, this, ""));
|
||||||
this.inputField.setSelected();
|
this.inputField.setSelected();
|
||||||
this.sentHistoryCursor = this.sentMessages.size();
|
this.sentHistoryCursor = this.sentMessages.size();
|
||||||
|
@ -69,7 +84,7 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
public void key(Keysym key, boolean ctrl, boolean shift) {
|
public void key(Keysym key, boolean ctrl, boolean shift) {
|
||||||
super.key(key, ctrl, shift);
|
super.key(key, ctrl, shift);
|
||||||
// this.waitingOnAutocomplete = false;
|
// this.waitingOnAutocomplete = false;
|
||||||
if(key != Keysym.TAB)
|
if(key != Keysym.TAB && key != Keysym.LEFT_SHIFT && key != Keysym.RIGHT_SHIFT)
|
||||||
this.playerNamesFound = false;
|
this.playerNamesFound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +92,9 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
{
|
{
|
||||||
this.waitingOnAutocomplete = false;
|
this.waitingOnAutocomplete = false;
|
||||||
|
|
||||||
if ((value == Action.FORWARD || value == Action.BACKWARD) && this.gm.thePlayer != null)
|
if (value == Action.FORWARD || value == Action.BACKWARD)
|
||||||
{
|
{
|
||||||
|
this.reverse = value == Action.BACKWARD;
|
||||||
this.autocompletePlayerNames();
|
this.autocompletePlayerNames();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -98,13 +114,14 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
{
|
{
|
||||||
if(this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(s))
|
if(this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(s))
|
||||||
this.sentMessages.add(s);
|
this.sentMessages.add(s);
|
||||||
|
this.sentHistoryCursor = this.sentMessages.size();
|
||||||
this.gm.exec(s);
|
this.gm.exec(s);
|
||||||
// if(this.gm.thePlayer != null)
|
// if(this.gm.thePlayer != null)
|
||||||
// this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.CHAT, s));
|
// this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.CHAT, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inputField.setText("");
|
this.inputField.setText("");
|
||||||
if(this.gm.conAutoclose && this.gm.theWorld != null)
|
if((this.gm.conAutoclose || !this.full) && this.gm.theWorld != null)
|
||||||
this.gm.displayGuiScreen(null);
|
this.gm.displayGuiScreen(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +138,16 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addMessage(String msg) {
|
||||||
|
String buffer = this.gm.getBuffer();
|
||||||
|
if((buffer.length() + msg.length() + 2) > Game.LOG_BUFFER) {
|
||||||
|
int offset = (msg.length() + 2) > 1024 ? (msg.length() + 2) : 1024;
|
||||||
|
int nl = buffer.indexOf('\n', offset);
|
||||||
|
buffer = nl >= 0 ? buffer.substring(nl + 1) : "";
|
||||||
|
}
|
||||||
|
this.setLog(buffer + "\n" + TextColor.RESET + msg);
|
||||||
|
}
|
||||||
|
|
||||||
public void autocompletePlayerNames()
|
public void autocompletePlayerNames()
|
||||||
{
|
{
|
||||||
if (this.playerNamesFound)
|
if (this.playerNamesFound)
|
||||||
|
@ -131,6 +158,10 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
{
|
{
|
||||||
this.autocompleteIndex = 0;
|
this.autocompleteIndex = 0;
|
||||||
}
|
}
|
||||||
|
else if (this.autocompleteIndex < 0)
|
||||||
|
{
|
||||||
|
this.autocompleteIndex = this.foundPlayerNames.size() - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -139,7 +170,11 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
this.autocompleteIndex = 0;
|
this.autocompleteIndex = 0;
|
||||||
String s = this.inputField.getText().substring(i).toLowerCase();
|
String s = this.inputField.getText().substring(i).toLowerCase();
|
||||||
String s1 = this.inputField.getText().substring(0, this.inputField.getCursorPosition());
|
String s1 = this.inputField.getText().substring(0, this.inputField.getCursorPosition());
|
||||||
this.sendAutocompleteRequest(s1, s);
|
String[] localMatches = this.sendAutocompleteRequest(s1, s);
|
||||||
|
if(localMatches != null) {
|
||||||
|
this.onAutocompleteResponse(localMatches);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.foundPlayerNames.isEmpty())
|
if (this.foundPlayerNames.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -164,13 +199,42 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
stringbuilder.append(s2);
|
stringbuilder.append(s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.CONSOLE.user(stringbuilder.toString());
|
this.addMessage(stringbuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inputField.insertText((String)this.foundPlayerNames.get(this.autocompleteIndex++));
|
this.inputField.insertText((String)this.foundPlayerNames.get(this.autocompleteIndex));
|
||||||
|
this.autocompleteIndex += this.reverse ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendAutocompleteRequest(String currentText, String newText)
|
private String[] complete(String s) {
|
||||||
|
List<String> list = Lists.<String>newArrayList();
|
||||||
|
String[] argv = s.split(" ", -1);
|
||||||
|
String pre = argv[0];
|
||||||
|
s = argv[argv.length - 1];
|
||||||
|
Iterable<String> res = pre.startsWith("#") ?
|
||||||
|
(argv.length == 1 ? this.gm.getVars() : (argv.length == 2 ? getVarCompletion(argv[0].substring(1)) : Lists.newArrayList())) :
|
||||||
|
(this.gm.thePlayer == null ? Lists.newArrayList() : this.gm.thePlayer.sendQueue.getPlayerNames());
|
||||||
|
if(argv.length == 1 && pre.startsWith("#"))
|
||||||
|
s = s.substring(1);
|
||||||
|
for(String s1 : res) {
|
||||||
|
if(s1.regionMatches(true, 0, s, 0, s.length()))
|
||||||
|
list.add((argv.length == 1 && pre.startsWith("#") ? "#" : "") + s1);
|
||||||
|
}
|
||||||
|
return list.isEmpty() ? null : list.toArray(new String[list.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getVarCompletion(String var) {
|
||||||
|
CVar cv = this.gm.getVar(var);
|
||||||
|
if(cv == null)
|
||||||
|
return Lists.newArrayList();
|
||||||
|
if(cv instanceof BoolVar)
|
||||||
|
return Boolean.parseBoolean(cv.format()) ? Lists.newArrayList("false", "true") : Lists.newArrayList("true", "false");
|
||||||
|
else
|
||||||
|
return Lists.newArrayList(cv.getDefault());
|
||||||
|
// return Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] sendAutocompleteRequest(String currentText, String newText)
|
||||||
{
|
{
|
||||||
if (currentText.length() >= 1)
|
if (currentText.length() >= 1)
|
||||||
{
|
{
|
||||||
|
@ -185,10 +249,23 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
// {
|
// {
|
||||||
// eid = this.gm.pointed.entity.getId();
|
// eid = this.gm.pointed.entity.getId();
|
||||||
// }
|
// }
|
||||||
|
if(currentText.startsWith("/")) {
|
||||||
this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketComplete(currentText));
|
if(this.gm.thePlayer != null) {
|
||||||
this.waitingOnAutocomplete = true;
|
currentText = currentText.substring(1);
|
||||||
|
this.prefixFirst = currentText.split(" ", -1).length == 1 ? "/" : null;
|
||||||
|
this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketComplete(currentText));
|
||||||
|
this.waitingOnAutocomplete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String[] comp = this.complete(currentText);
|
||||||
|
this.prefixFirst = null;
|
||||||
|
if(comp != null)
|
||||||
|
this.waitingOnAutocomplete = true;
|
||||||
|
return comp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getSentHistory(int msgPos)
|
private void getSentHistory(int msgPos)
|
||||||
|
@ -224,8 +301,11 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
||||||
this.playerNamesFound = false;
|
this.playerNamesFound = false;
|
||||||
this.foundPlayerNames.clear();
|
this.foundPlayerNames.clear();
|
||||||
|
|
||||||
for (String s : choices)
|
for (int z = 0; z < choices.length; z++)
|
||||||
{
|
{
|
||||||
|
String s = choices[z];
|
||||||
|
if(this.prefixFirst != null)
|
||||||
|
choices[z] = s = this.prefixFirst + s;
|
||||||
if (s.length() > 0)
|
if (s.length() > 0)
|
||||||
{
|
{
|
||||||
this.foundPlayerNames.add(s);
|
this.foundPlayerNames.add(s);
|
||||||
|
|
|
@ -295,8 +295,10 @@ public abstract class GuiContainer extends Gui
|
||||||
this.renderItemOverlayIntoGUI(overlay.stack, overlay.x, overlay.y, overlay.alt);
|
this.renderItemOverlayIntoGUI(overlay.stack, overlay.x, overlay.y, overlay.alt);
|
||||||
}
|
}
|
||||||
this.drawnOverlays.clear();
|
this.drawnOverlays.clear();
|
||||||
if(this.tooltip != null)
|
if(this.tooltip != null) {
|
||||||
Drawing.drawTextbox(this.tooltip, this.hover_x, this.hover_y, 0xaf000000);
|
int width = Drawing.getBoxWidth(this.tooltip);
|
||||||
|
Drawing.drawTextbox(this.tooltip, this.hover_x + width > this.gm.fb_x ? this.hover_x - width - 32 : this.hover_x, this.hover_y, 0xaf000000);
|
||||||
|
}
|
||||||
this.tooltip = null;
|
this.tooltip = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,45 +1,49 @@
|
||||||
package game.gui.world;
|
package game.gui.world;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import game.collect.Sets;
|
|
||||||
import game.color.TextColor;
|
import game.color.TextColor;
|
||||||
import game.dimension.DimType;
|
import game.dimension.DimType;
|
||||||
import game.dimension.Dimension;
|
import game.dimension.Dimension;
|
||||||
import game.dimension.Space;
|
import game.dimension.Space;
|
||||||
import game.gui.GuiScreen;
|
import game.gui.Gui;
|
||||||
import game.gui.element.Button;
|
import game.gui.element.ActButton;
|
||||||
import game.gui.element.TextField;
|
import game.gui.element.Label;
|
||||||
|
import game.gui.element.Textbox;
|
||||||
|
import game.gui.element.ActButton.Mode;
|
||||||
|
import game.gui.element.Textbox.Action;
|
||||||
|
import game.gui.element.TransparentBox;
|
||||||
|
import game.init.Config;
|
||||||
import game.init.UniverseRegistry;
|
import game.init.UniverseRegistry;
|
||||||
import game.lib.input.Keyboard;
|
import game.log.Log;
|
||||||
|
import game.nbt.NBTLoader;
|
||||||
|
import game.nbt.NBTTagCompound;
|
||||||
import game.network.NetHandlerPlayServer;
|
import game.network.NetHandlerPlayServer;
|
||||||
import game.renderer.FontRenderer;
|
|
||||||
import game.rng.Random;
|
import game.rng.Random;
|
||||||
import game.util.Predicate;
|
import game.util.Util;
|
||||||
import game.world.Region;
|
import game.world.Region;
|
||||||
|
import game.world.World;
|
||||||
|
|
||||||
public class GuiCreate extends GuiScreen
|
public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callback
|
||||||
{
|
{
|
||||||
|
public static final GuiCreate INSTANCE = new GuiCreate();
|
||||||
private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3";
|
private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3";
|
||||||
private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!";
|
private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!";
|
||||||
private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_";
|
private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_";
|
||||||
|
|
||||||
private GuiScreen parentScreen;
|
private Textbox worldNameField;
|
||||||
private TextField worldNameField;
|
private Textbox worldSeedField;
|
||||||
private TextField worldSeedField;
|
private Textbox worldUserField;
|
||||||
private TextField worldUserField;
|
private ActButton dimButton;
|
||||||
// private Button modeButton;
|
private ActButton createButton;
|
||||||
private Button dimButton;
|
private Label actionLabel;
|
||||||
// private String descLine1;
|
private Label nameLabel;
|
||||||
// private String descLine2;
|
private Label userLabel;
|
||||||
private String[] descLines;
|
private Label seed;
|
||||||
|
private Label decoded;
|
||||||
|
private TransparentBox descLines;
|
||||||
|
|
||||||
private boolean alreadyGenerated;
|
private boolean alreadyGenerated;
|
||||||
private boolean fileExists;
|
private boolean fileExists;
|
||||||
private boolean fileInvalid;
|
|
||||||
private String seed;
|
|
||||||
private String decoded;
|
|
||||||
private int dimension;
|
private int dimension;
|
||||||
|
|
||||||
private static long getSeed(String str) {
|
private static long getSeed(String str) {
|
||||||
|
@ -171,235 +175,143 @@ public class GuiCreate extends GuiScreen
|
||||||
return (def == null ? ("" + seed) : def);
|
return (def == null ? ("" + seed) : def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiCreate(GuiScreen parent)
|
private GuiCreate()
|
||||||
{
|
{
|
||||||
UniverseRegistry.clear();
|
|
||||||
this.parentScreen = parent;
|
|
||||||
// this.worldSeed = "";
|
|
||||||
// this.worldName = "Neue Welt";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateScreen()
|
public void updateScreen()
|
||||||
{
|
{
|
||||||
this.worldNameField.updateCursorCounter();
|
|
||||||
this.worldSeedField.updateCursorCounter();
|
|
||||||
this.worldUserField.updateCursorCounter();
|
|
||||||
String text = this.worldSeedField.getText();
|
String text = this.worldSeedField.getText();
|
||||||
if(text.isEmpty()) {
|
if(text.isEmpty()) {
|
||||||
this.seed = "Zufällig";
|
this.seed.setText("Startwert [Zufällig]");
|
||||||
this.decoded = "-";
|
this.decoded.setText("Dekodiert: -");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.seed = "" + getSeed(text);
|
this.seed.setText("Startwert [" + getSeed(text) + "]");
|
||||||
try {
|
try {
|
||||||
this.decoded = decodeSeed(Long.parseLong(text), "-");
|
this.decoded.setText("Dekodiert: " + decodeSeed(Long.parseLong(text), "-"));
|
||||||
}
|
}
|
||||||
catch(NumberFormatException e) {
|
catch(NumberFormatException e) {
|
||||||
this.decoded = decodeSeed(getSeed(text), "-");
|
this.decoded.setText("Dekodiert: " + decodeSeed(getSeed(text), "-"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.fileExists = false;
|
this.fileExists = false;
|
||||||
this.fileInvalid = false;
|
|
||||||
text = this.worldNameField.getText().trim();
|
text = this.worldNameField.getText().trim();
|
||||||
// for(String n : GuiCreate.DISALLOWED_FILES) {
|
this.createButton.enabled = !text.isEmpty() && !this.worldUserField.getText().isEmpty();
|
||||||
// if(text.equalsIgnoreCase(n)) {
|
|
||||||
// ((Button)this.buttonList.get(0)).enabled = false;
|
|
||||||
// this.fileInvalid = true;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if(this.fileInvalid = GuiCreate.DISALLOWED_FILES.contains(text.toUpperCase())) {
|
|
||||||
((Button)this.buttonList.get(0)).enabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
|
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
|
||||||
((Button)this.buttonList.get(0)).enabled = false;
|
this.createButton.enabled = false;
|
||||||
|
this.actionLabel.setText(this.getFolderDesc());
|
||||||
|
this.userLabel.setText(this.getUserDesc());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initGui()
|
public void init(int width, int height)
|
||||||
{
|
{
|
||||||
Keyboard.enableRepeatEvents(true);
|
UniverseRegistry.clear();
|
||||||
this.buttonList.clear();
|
this.alreadyGenerated = false;
|
||||||
this.buttonList.add(new Button(0, this.width / 2 - 155, this.height - 28, 150, 20, "Neue Welt erstellen"));
|
this.dimension = Integer.MAX_VALUE;
|
||||||
this.buttonList.add(new Button(1, this.width / 2 + 5, this.height - 28, 150, 20, "Abbrechen"));
|
this.createButton = this.add(new ActButton(width / 2 - 155, height - 28, 150, 20, (ActButton.Callback)this, "Neue Welt erstellen"));
|
||||||
// this.buttonList.add(this.modeButton = new Button(2, this.width / 2 - 155, 175, 310, 20, ""));
|
this.add(new ActButton(width / 2 + 5, height - 28, 150, 20, (Gui)GuiWorlds.INSTANCE, "Abbrechen"));
|
||||||
this.buttonList.add(this.dimButton = new Button(2, this.width / 2 - 155, 220, 310, 20, ""));
|
this.dimButton = this.add(new ActButton(width / 2 - 155, 220, 310, 20, (ActButton.Callback)this, ""));
|
||||||
this.worldNameField = new TextField(this.width / 2 - 100, 60, 200, 20);
|
this.worldNameField = this.add(new Textbox(width / 2 - 100, 60, 200, 20, 256, true, this, GuiWorlds.VALID_FILE, ""));
|
||||||
this.worldNameField.setFocused(true);
|
this.worldNameField.setSelected();
|
||||||
this.worldNameField.setValidator(new Predicate<String>() {
|
this.worldSeedField = this.add(new Textbox(width / 2 - 100, 136, 200, 20, 256, true, this, ""));
|
||||||
public boolean apply(String name) {
|
this.worldUserField = this.add(new Textbox(width / 2 - 100, 98, 200, 20, NetHandlerPlayServer.MAX_USER_LENGTH, true, this, NetHandlerPlayServer.VALID_USER, ""));
|
||||||
for(int z = 0; z < name.length(); z++) {
|
this.createButton.enabled = false;
|
||||||
if(DISALLOWED_CHARS.contains(name.charAt(z)))
|
this.actionLabel = this.add(new Label(width / 2 - 100, 49, 200, 20, this.getFolderDesc(), true));
|
||||||
return false;
|
this.userLabel = this.add(new Label(width / 2 - 100, 87, 200, 20, this.getUserDesc(), true));
|
||||||
}
|
this.seed = this.add(new Label(width / 2 - 100, 125, 200, 20, "", true));
|
||||||
return true;
|
this.decoded = this.add(new Label(width / 2 - 100, 160, 200, 20, "", true));
|
||||||
}
|
this.descLines = this.add(new TransparentBox(width / 2 - 153, 242, 306, 160, ""));
|
||||||
});
|
|
||||||
// this.worldNameField.setText("Welt");
|
|
||||||
this.worldSeedField = new TextField(this.width / 2 - 100, 136, 200, 20);
|
|
||||||
// this.worldSeedField.setText(this.worldSeed);
|
|
||||||
this.worldUserField = new TextField(this.width / 2 - 100, 98, 200, 20);
|
|
||||||
this.worldUserField.setMaxStringLength(16);
|
|
||||||
this.worldUserField.setValidator(new Predicate<String>() {
|
|
||||||
public boolean apply(String name) {
|
|
||||||
return NetHandlerPlayServer.isValidUser(name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// this.calcSaveDirName();
|
|
||||||
// this.setModeButton();
|
|
||||||
this.setDimButton();
|
this.setDimButton();
|
||||||
((Button)this.buttonList.get(0)).enabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void setModeButton() {
|
public String getTitle() {
|
||||||
// this.modeButton.display = "Kreativmodus: " + (this.noCreative ? "Aus" : "An");
|
return "Neue Welt erstellen";
|
||||||
// this.descLine1 = this.noCreative ? "Suche nach Ressourcen, baue Werkzeuge, Waffen und mehr"
|
}
|
||||||
// : "Unbegrenzte Rohstoffe, Flugmodus, Unverwundbarkeit, keine";
|
|
||||||
// this.descLine2 = this.noCreative ? "Gegenstände, sammle Erfahrung und erkunde die Welten"
|
|
||||||
// : "Energie oder Mana und sofortiges Zerstören von Blöcken";
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void setDimButton() {
|
private void setDimButton() {
|
||||||
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : UniverseRegistry.getBaseDimensions().get(this.dimension);
|
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : UniverseRegistry.getBaseDimensions().get(this.dimension);
|
||||||
this.dimButton.display = (dim == Space.INSTANCE ? "" :
|
this.dimButton.setText((dim == Space.INSTANCE ? "" :
|
||||||
((dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ?
|
((dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ?
|
||||||
"Vorlage" : (dim.getType() == DimType.PLANET ? "Heimplanet" : "Dimension")) + ": ")) +
|
"Vorlage" : (dim.getType() == DimType.PLANET ? "Heimplanet" : "Dimension")) + ": ")) +
|
||||||
(dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? dim.getCustomName() :
|
(dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? dim.getCustomName() :
|
||||||
dim.getFormattedName(false));
|
dim.getFormattedName(false)));
|
||||||
this.descLines = dim.getFormattedName(true).split(" / ");
|
this.descLines.setText(Util.buildLines(dim.getFormattedName(true).split(" / ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void calcSaveDirName()
|
public void use(ActButton button, Mode mode)
|
||||||
// {
|
|
||||||
// this.saveDirName = this.worldNameField.getText().trim();
|
|
||||||
//
|
|
||||||
//// for (char c : DISALLOWED_CHARS)
|
|
||||||
//// {
|
|
||||||
//// this.saveDirName = this.saveDirName.replace(c, '_');
|
|
||||||
//// }
|
|
||||||
//
|
|
||||||
// if (!this.saveDirName.isEmpty())
|
|
||||||
//// {
|
|
||||||
//// this.saveDirName = "World";
|
|
||||||
//// }
|
|
||||||
//
|
|
||||||
// this.saveDirName = getUncollidingSaveDirName(Region.SAVE_DIR, this.saveDirName);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void onGuiClosed()
|
|
||||||
{
|
{
|
||||||
Keyboard.enableRepeatEvents(false);
|
if (button == this.createButton)
|
||||||
}
|
|
||||||
|
|
||||||
protected void actionPerformed(Button button) throws IOException
|
|
||||||
{
|
|
||||||
if (button.enabled)
|
|
||||||
{
|
{
|
||||||
if (button.id == 1)
|
// this.gm.displayGuiScreen(null);
|
||||||
{
|
if(this.alreadyGenerated)
|
||||||
this.gm.displayGuiScreen(this.parentScreen);
|
return;
|
||||||
|
this.alreadyGenerated = true;
|
||||||
|
Config.clear();
|
||||||
|
UniverseRegistry.clear();
|
||||||
|
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE :
|
||||||
|
UniverseRegistry.getBaseDimensions().get(this.dimension);
|
||||||
|
dim.setSeed(getSeed(this.worldSeedField.getText()));
|
||||||
|
File dir = new File(Region.SAVE_DIR, this.worldNameField.getText().trim());
|
||||||
|
Dimension[] dims = UniverseRegistry.registerPreset(dim);
|
||||||
|
Config.set("spawnDim", "" + dims[0].getDimensionId(), null);
|
||||||
|
Region.saveWorldInfo(dir, World.START_TIME, this.worldUserField.getText());
|
||||||
|
for(Dimension sdim : dims) {
|
||||||
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
data.setTag("Generator", sdim.toNbt(true));
|
||||||
|
File chunkDir = new File(new File(dir, "chunk"), sdim.getDimensionName());
|
||||||
|
chunkDir.mkdirs();
|
||||||
|
File file = new File(chunkDir, "data.nbt");
|
||||||
|
try {
|
||||||
|
NBTLoader.writeGZip(data, file);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
Log.IO.error(e, "Konnte Weltdaten nicht speichern");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (button.id == 0)
|
this.gm.startServer(dir, this.worldUserField.getText());
|
||||||
{
|
}
|
||||||
this.gm.displayGuiScreen(null);
|
else if (button == this.dimButton)
|
||||||
if(this.alreadyGenerated)
|
{
|
||||||
return;
|
if(mode == Mode.TERTIARY) {
|
||||||
this.alreadyGenerated = true;
|
this.dimension = Integer.MAX_VALUE;
|
||||||
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE :
|
}
|
||||||
UniverseRegistry.getBaseDimensions().get(this.dimension);
|
else if(this.dimension == Integer.MAX_VALUE) {
|
||||||
dim.setSeed(getSeed(this.worldSeedField.getText()));
|
this.dimension = mode == Mode.SECONDARY ? UniverseRegistry.getBaseDimensions().size() - 1 : 0;
|
||||||
this.gm.launchIntegratedServer(this.worldNameField.getText().trim(), dim, this.worldUserField.getText());
|
}
|
||||||
}
|
else {
|
||||||
// else if (button.id == 2)
|
if(mode == Mode.SECONDARY) {
|
||||||
// {
|
if(--this.dimension < 0)
|
||||||
// this.noCreative ^= true;
|
this.dimension = Integer.MAX_VALUE;
|
||||||
// this.setModeButton();
|
|
||||||
// }
|
|
||||||
else if (button.id == 2)
|
|
||||||
{
|
|
||||||
// int index = Integer.MAX_VALUE;
|
|
||||||
// for(int z = 0; z < UniverseRegistry.getBasePlanets().size(); z++) {
|
|
||||||
// if(UniverseRegistry.getBasePlanets().get(z).getDimensionId() == this.dimension) {
|
|
||||||
// index = z;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if(this.dimension == Integer.MAX_VALUE) {
|
|
||||||
this.dimension = GuiScreen.isShiftKeyDown() ? UniverseRegistry.getBaseDimensions().size() - 1 : 0;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(GuiScreen.isShiftKeyDown()) {
|
if(++this.dimension >= UniverseRegistry.getBaseDimensions().size())
|
||||||
if(--this.dimension < 0)
|
this.dimension = Integer.MAX_VALUE;
|
||||||
this.dimension = Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(++this.dimension >= UniverseRegistry.getBaseDimensions().size())
|
|
||||||
this.dimension = Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// this.dimension = index == Integer.MAX_VALUE ? Space.INSTANCE.getDimensionId() :
|
}
|
||||||
// UniverseRegistry.getBasePlanets().get(index).getDimensionId();
|
this.setDimButton();
|
||||||
this.setDimButton();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void keyTyped(char typedChar, int keyCode) throws IOException
|
public void use(Textbox elem, Action action) {
|
||||||
{
|
if(action == Action.SEND)
|
||||||
// if (this.worldNameField.isFocused())
|
this.use(this.createButton, Mode.PRIMARY);
|
||||||
// {
|
}
|
||||||
this.worldNameField.textboxKeyTyped(typedChar, keyCode);
|
|
||||||
// this.worldName = this.worldNameField.getText();
|
|
||||||
// }
|
|
||||||
// else if (this.worldSeedField.isFocused())
|
|
||||||
// {
|
|
||||||
this.worldSeedField.textboxKeyTyped(typedChar, keyCode);
|
|
||||||
// this.worldSeed = this.worldSeedField.getText();
|
|
||||||
// }
|
|
||||||
// else if (this.worldUserField.isFocused())
|
|
||||||
// {
|
|
||||||
this.worldUserField.textboxKeyTyped(typedChar, keyCode);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (keyCode == 28 || keyCode == 156)
|
private String getFolderDesc() {
|
||||||
{
|
// FontRenderer.drawStringWithShadow("Startwert [" + this.seed + "]", this.width / 2 - 100, 125, -6250336);
|
||||||
this.actionPerformed((Button)this.buttonList.get(0));
|
// FontRenderer.drawStringWithShadow("Dekodiert: " + this.decoded, this.width / 2 - 100, 160, -6250336);
|
||||||
}
|
// FontRenderer.drawStringWithShadow(, this.width / 2 - 100, 49, -6250336);
|
||||||
|
// FontRenderer.drawStringWithShadow((this.worldUserField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Spielername", this.width / 2 - 100, 87, -6250336);
|
||||||
((Button)this.buttonList.get(0)).enabled = this.worldNameField.getText().length() > 0 && this.worldUserField.getText().length() > 0;
|
//
|
||||||
// this.calcSaveDirName();
|
// for(int z = 1; z < this.descLines.length; z++) {
|
||||||
|
// FontRenderer.drawStringWithShadow(this.descLines[z], this.width / 2 - 153, 242 + (z - 1) * (FontRenderer.FONT_HEIGHT + 1), -6250336);
|
||||||
|
// }
|
||||||
|
return (this.worldNameField.getText().trim().isEmpty() || this.fileExists ? TextColor.DRED : "")
|
||||||
|
+ "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
|
private String getUserDesc() {
|
||||||
{
|
return (this.worldUserField.getText().isEmpty() ? TextColor.DRED : "") + "Spielername";
|
||||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
}
|
||||||
|
|
||||||
this.worldSeedField.mouseClicked(mouseX, mouseY, mouseButton);
|
|
||||||
this.worldNameField.mouseClicked(mouseX, mouseY, mouseButton);
|
|
||||||
this.worldUserField.mouseClicked(mouseX, mouseY, mouseButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
|
||||||
{
|
|
||||||
this.drawBackground();
|
|
||||||
FontRenderer.drawCenteredString("Neue Welt erstellen", this.width / 2, 20, -1);
|
|
||||||
|
|
||||||
FontRenderer.drawStringWithShadow("Startwert [" + this.seed + "]", this.width / 2 - 100, 125, -6250336);
|
|
||||||
FontRenderer.drawStringWithShadow("Dekodiert: " + this.decoded, this.width / 2 - 100, 160, -6250336);
|
|
||||||
FontRenderer.drawStringWithShadow((this.worldNameField.getText().trim().isEmpty() || this.fileExists || this.fileInvalid ? TextColor.DARK_RED : "")
|
|
||||||
+ "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : ""), this.width / 2 - 100, 49, -6250336);
|
|
||||||
FontRenderer.drawStringWithShadow((this.worldUserField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Spielername", this.width / 2 - 100, 87, -6250336);
|
|
||||||
|
|
||||||
this.worldSeedField.drawTextBox();
|
|
||||||
this.worldNameField.drawTextBox();
|
|
||||||
this.worldUserField.drawTextBox();
|
|
||||||
|
|
||||||
// FontRenderer.drawStringWithShadow(this.descLine1, this.width / 2 - 153, 197, -6250336);
|
|
||||||
// FontRenderer.drawStringWithShadow(this.descLine2, this.width / 2 - 153, 197 + FontRenderer.FONT_HEIGHT + 1, -6250336);
|
|
||||||
for(int z = 1; z < this.descLines.length; z++) {
|
|
||||||
FontRenderer.drawStringWithShadow(this.descLines[z], this.width / 2 - 153, 242 + (z - 1) * (FontRenderer.FONT_HEIGHT + 1), -6250336);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,7 +347,7 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
||||||
this.gm.startServer(null, "debug");
|
this.gm.startServer(null, "debug");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// this.gm.displayGuiScreen(new GuiCreate(this)); //TODO: create
|
this.gm.displayGuiScreen(GuiCreate.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1855,4 +1855,9 @@ public class NetHandlerPlayClient extends NetHandler
|
||||||
{
|
{
|
||||||
return this.playerList.entrySet();
|
return this.playerList.entrySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterable<String> getPlayerNames()
|
||||||
|
{
|
||||||
|
return this.playerList.keySet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1628,7 +1628,7 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setVar(String line) {
|
private boolean setVar(String line) {
|
||||||
if(!this.isAdmin() || !line.startsWith("#"))
|
if(!this.isAdmin())
|
||||||
return false;
|
return false;
|
||||||
if(line.length() < 2) {
|
if(line.length() < 2) {
|
||||||
for(Entry<String, Config.Value> entry : Config.VARS.entrySet()) {
|
for(Entry<String, Config.Value> entry : Config.VARS.entrySet()) {
|
||||||
|
@ -1650,7 +1650,7 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
||||||
this.addFeed(TextColor.GREEN + "SVARs insgesamt registriert: %d", Config.VARS.size());
|
this.addFeed(TextColor.GREEN + "SVARs insgesamt registriert: %d", Config.VARS.size());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
line = line.substring(1).trim();
|
line = line.trim();
|
||||||
String[] args = /* line.isEmpty() ? new String[0] : */ line.split(" ", -1);
|
String[] args = /* line.isEmpty() ? new String[0] : */ line.split(" ", -1);
|
||||||
if(args.length == 1) {
|
if(args.length == 1) {
|
||||||
// case 0:
|
// case 0:
|
||||||
|
@ -1838,114 +1838,120 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean teleport(String line) {
|
private boolean teleport(String line) {
|
||||||
if((!Config.teleportAllowed && !this.isAdmin()) || !line.startsWith("/"))
|
if(!Config.teleportAllowed && !this.isAdmin())
|
||||||
return false;
|
return false;
|
||||||
line = line.substring(1).trim();
|
line = line.trim();
|
||||||
String[] argv = line.split(" ", -1);
|
String[] argv = line.split(" ", -1);
|
||||||
if(line.isEmpty() || argv.length == 0 || argv.length == 2) {
|
// if(line.isEmpty() || argv.length == 0 || argv.length == 2) {
|
||||||
this.addFeed(TextColor.DRED + "Spieler, @Warp, *Dimension oder X Y Z [Dimension]");
|
// this.addFeed(TextColor.DRED + "+Spieler, @Warp, *Dimension oder X Y Z [Dimension]");
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
if(argv.length != 1) {
|
String tgt = argv[0];
|
||||||
Double ax = parseCoordinate(argv[0], true);
|
if(tgt.equals("#")) {
|
||||||
|
if(argv.length < 4) {
|
||||||
|
this.addFeed(TextColor.DRED + "# X Y Z [Dimension]");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Double ax = parseCoordinate(argv[1], true);
|
||||||
if(ax == null)
|
if(ax == null)
|
||||||
return true;
|
return true;
|
||||||
Double ay = parseCoordinate(argv[1], false);
|
Double ay = parseCoordinate(argv[2], false);
|
||||||
if(ay == null)
|
if(ay == null)
|
||||||
return true;
|
return true;
|
||||||
Double az = parseCoordinate(argv[2], true);
|
Double az = parseCoordinate(argv[3], true);
|
||||||
if(az == null)
|
if(az == null)
|
||||||
return true;
|
return true;
|
||||||
int dimension = this.entity.worldObj.dimension.getDimensionId();
|
int dimension = this.entity.worldObj.dimension.getDimensionId();
|
||||||
if(argv.length > 3) {
|
if(argv.length > 4) {
|
||||||
WorldServer world;
|
WorldServer world;
|
||||||
try {
|
try {
|
||||||
world = this.server.getWorld(Integer.parseInt(argv[3]));
|
world = this.server.getWorld(Integer.parseInt(argv[4]));
|
||||||
}
|
}
|
||||||
catch(NumberFormatException e) {
|
catch(NumberFormatException e) {
|
||||||
world = this.server.getWorld(argv[3]);
|
world = this.server.getWorld(argv[4]);
|
||||||
}
|
}
|
||||||
if(world == null) {
|
if(world == null) {
|
||||||
this.addFeed(TextColor.DRED + "Dimension '%s' existiert nicht", argv[3]);
|
this.addFeed(TextColor.DRED + "Dimension '%s' existiert nicht", argv[4]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
dimension = world.dimension.getDimensionId();
|
dimension = world.dimension.getDimensionId();
|
||||||
}
|
}
|
||||||
this.entity.teleport(ax, ay, az, this.entity.rotYaw, this.entity.rotPitch, dimension);
|
this.entity.teleport(ax, ay, az, this.entity.rotYaw, this.entity.rotPitch, dimension);
|
||||||
}
|
}
|
||||||
else {
|
if(tgt.startsWith("@")) {
|
||||||
String tgt = argv[0];
|
tgt = tgt.substring(1);
|
||||||
if(tgt.startsWith("@")) {
|
if(tgt.equals("spawn")) {
|
||||||
tgt = tgt.substring(1);
|
WorldServer world = this.server.getWorld(Config.spawnDim);
|
||||||
if(tgt.equals("spawn")) {
|
world = world == null ? this.server.getSpace() : world;
|
||||||
WorldServer world = this.server.getWorld(Config.spawnDim);
|
int y = Config.spawnY;
|
||||||
world = world == null ? this.server.getSpace() : world;
|
while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511)
|
||||||
int y = Config.spawnY;
|
y++;
|
||||||
while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511)
|
this.entity.teleport(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d,
|
||||||
y++;
|
Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId());
|
||||||
this.entity.teleport(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d,
|
|
||||||
Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Position pos = this.server.getWarps().get(tgt);
|
|
||||||
if(pos == null) {
|
|
||||||
this.addFeed(TextColor.DRED + "Warp '%s' existiert nicht", tgt);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(this.server.getWorld(pos.dim) == null) {
|
|
||||||
this.addFeed(TextColor.DRED + "Warp '%s' hat kein Level (%s)", tgt, pos.dim);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
this.entity.teleport(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(tgt.startsWith("*")) {
|
|
||||||
tgt = tgt.substring(1);
|
|
||||||
WorldServer world;
|
|
||||||
try {
|
|
||||||
world = this.server.getWorld(Integer.parseInt(tgt));
|
|
||||||
}
|
|
||||||
catch(NumberFormatException e) {
|
|
||||||
world = this.server.getWorld(tgt);
|
|
||||||
}
|
|
||||||
if(world == null) {
|
|
||||||
this.addFeed(TextColor.DRED + "Dimension '%s' existiert nicht", tgt);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// int dimension = world.dimension.getDimensionId();
|
|
||||||
// int dimension = parseDimension(sender, tgt);
|
|
||||||
BlockPos pos = this.entity.getPosition();
|
|
||||||
// WorldServer world = Server.getServer().getWorld(dimension);
|
|
||||||
pos = pos.getY() < 0 ? new BlockPos(pos.getX(), 0, pos.getZ()) : pos;
|
|
||||||
if(world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) {
|
|
||||||
while((world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) && pos.getY() < 511)
|
|
||||||
pos = pos.up();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
while(!(world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) && pos.getY() > 0)
|
|
||||||
pos = pos.down();
|
|
||||||
pos = pos.up();
|
|
||||||
}
|
|
||||||
this.entity.teleport(pos, world.dimension.getDimensionId());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NetHandlerPlayServer conn = this.server.getPlayer(tgt);
|
Position pos = this.server.getWarps().get(tgt);
|
||||||
if(conn == null) {
|
if(pos == null) {
|
||||||
Position pos = this.server.getOfflinePosition(tgt);
|
this.addFeed(TextColor.DRED + "Warp '%s' existiert nicht", tgt);
|
||||||
if(pos == null) {
|
return true;
|
||||||
this.addFeed(TextColor.DRED + "Spieler '%s' konnte nicht gefunden werden", tgt);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
this.entity.teleport(pos);
|
|
||||||
}
|
}
|
||||||
else {
|
if(this.server.getWorld(pos.dim) == null) {
|
||||||
EntityNPC dest = conn.getEntity();
|
this.addFeed(TextColor.DRED + "Warp '%s' hat kein Level (%s)", tgt, pos.dim);
|
||||||
if(dest != null)
|
return true;
|
||||||
this.entity.teleport(dest.posX, dest.posY, dest.posZ, dest.rotYaw, dest.rotPitch, dest.worldObj.dimension.getDimensionId());
|
|
||||||
}
|
}
|
||||||
|
this.entity.teleport(pos);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
else if(tgt.startsWith("*")) {
|
||||||
|
tgt = tgt.substring(1);
|
||||||
|
WorldServer world;
|
||||||
|
try {
|
||||||
|
world = this.server.getWorld(Integer.parseInt(tgt));
|
||||||
|
}
|
||||||
|
catch(NumberFormatException e) {
|
||||||
|
world = this.server.getWorld(tgt);
|
||||||
|
}
|
||||||
|
if(world == null) {
|
||||||
|
this.addFeed(TextColor.DRED + "Dimension '%s' existiert nicht", tgt);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// int dimension = world.dimension.getDimensionId();
|
||||||
|
// int dimension = parseDimension(sender, tgt);
|
||||||
|
BlockPos pos = this.entity.getPosition();
|
||||||
|
// WorldServer world = Server.getServer().getWorld(dimension);
|
||||||
|
pos = pos.getY() < 0 ? new BlockPos(pos.getX(), 0, pos.getZ()) : pos;
|
||||||
|
if(world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) {
|
||||||
|
while((world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) && pos.getY() < 511)
|
||||||
|
pos = pos.up();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
while(!(world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) && pos.getY() > 0)
|
||||||
|
pos = pos.down();
|
||||||
|
pos = pos.up();
|
||||||
|
}
|
||||||
|
this.entity.teleport(pos, world.dimension.getDimensionId());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(tgt.startsWith("+")) {
|
||||||
|
tgt = tgt.substring(1);
|
||||||
|
NetHandlerPlayServer conn = this.server.getPlayer(tgt);
|
||||||
|
if(conn == null) {
|
||||||
|
Position pos = this.server.getOfflinePosition(tgt);
|
||||||
|
if(pos == null) {
|
||||||
|
this.addFeed(TextColor.DRED + "Spieler '%s' konnte nicht gefunden werden", tgt);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this.entity.teleport(pos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EntityNPC dest = conn.getEntity();
|
||||||
|
if(dest != null)
|
||||||
|
this.entity.teleport(dest.posX, dest.posY, dest.posZ, dest.rotYaw, dest.rotPitch, dest.worldObj.dimension.getDimensionId());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processMessage(CPacketMessage packetIn)
|
public void processMessage(CPacketMessage packetIn)
|
||||||
|
@ -1959,8 +1965,13 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
||||||
throw new IllegalArgumentException("Ungültige Zeichen in Nachricht");
|
throw new IllegalArgumentException("Ungültige Zeichen in Nachricht");
|
||||||
}
|
}
|
||||||
switch(packetIn.getType()) {
|
switch(packetIn.getType()) {
|
||||||
|
case COMMAND:
|
||||||
|
if(!this.teleport(msg) && !this.setVar(msg) && !this.setAdmin(msg))
|
||||||
|
this.addFeed(TextColor.RED + "Befehl wurde nicht gefunden");
|
||||||
|
break;
|
||||||
|
|
||||||
case CHAT:
|
case CHAT:
|
||||||
if(!this.teleport(msg) && !this.sendPlayer(msg) && !this.setVar(msg) && !this.setAdmin(msg))
|
if(!this.sendPlayer(msg))
|
||||||
this.server.sendPacket(new SPacketMessage(String.format("%s %s", this.entity.getColoredName(TextColor.LGRAY), msg)));
|
this.server.sendPacket(new SPacketMessage(String.format("%s %s", this.entity.getColoredName(TextColor.LGRAY), msg)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2891,16 +2902,20 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getWarpList() {
|
private Iterable<String> getWarpList(char pre) {
|
||||||
List<String> warps = Lists.newArrayList(this.server.getUsers());
|
switch(pre) {
|
||||||
warps.add("@spawn");
|
case '+':
|
||||||
for(String warp : this.server.getWarps().keySet()) {
|
return Lists.newArrayList(this.server.getUsers());
|
||||||
warps.add("@" + warp);
|
case '@':
|
||||||
|
List<String> warps = Lists.newArrayList("spawn");
|
||||||
|
for(String warp : this.server.getWarps().keySet()) {
|
||||||
|
warps.add(warp);
|
||||||
|
}
|
||||||
|
return warps;
|
||||||
|
case '*':
|
||||||
|
return UniverseRegistry.getWorldNames();
|
||||||
}
|
}
|
||||||
for(String dim : UniverseRegistry.getWorldNames()) {
|
return Lists.newArrayList();
|
||||||
warps.add("*" + dim);
|
|
||||||
}
|
|
||||||
return warps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> getVarList() {
|
private static List<String> getVarList() {
|
||||||
|
@ -2933,15 +2948,14 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting
|
||||||
// if(list == null) {
|
// if(list == null) {
|
||||||
// list = Lists.<String>newArrayList();
|
// list = Lists.<String>newArrayList();
|
||||||
String s = packetIn.getMessage();
|
String s = packetIn.getMessage();
|
||||||
char pre = s.startsWith("@") || (this.isAdmin() && (s.startsWith("#") || s.startsWith("!"))) || ((Config.teleportAllowed || this.isAdmin()) && s.startsWith("/")) ? s.charAt(0) : 0;
|
char pre = s.startsWith("#") || s.startsWith("!") || s.startsWith("+") || s.startsWith("*") || s.startsWith("@") ? s.charAt(0) : 0;
|
||||||
s = pre == 0 ? s : s.substring(1);
|
s = pre == 0 ? s : s.substring(1);
|
||||||
String[] argv = s.split(" ", -1);
|
String[] argv = s.split(" ", -1);
|
||||||
s = argv[argv.length - 1];
|
s = argv[argv.length - 1];
|
||||||
Iterable<String> res = pre == '#' ?
|
Iterable<String> res = pre == '#' && (Config.teleportAllowed || this.isAdmin()) ? (argv.length == 5 ? UniverseRegistry.getWorldNames() : Lists.newArrayList()) : ((pre == '+' || pre == '*' || pre == '@') && (Config.teleportAllowed || this.isAdmin()) ? (argv.length == 1 ? this.getWarpList(pre) : Lists.newArrayList()) : (pre == '!' && this.isAdmin() ? this.server.getAllUsernames() : ((this.isAdmin() ? (argv.length == 1 ? getVarList() : (argv.length == 2 ? (argv[0].equals("time") ? Lists.newArrayList("day", "night", "noon", "midnight", "sunrise", "sunset") : getVarCompletion(argv[0])) : Lists.newArrayList())) : Lists.newArrayList()))));
|
||||||
(argv.length == 1 ? getVarList() : (argv.length == 2 ? (argv[0].equals("time") ? Lists.newArrayList("day", "night", "noon", "midnight", "sunrise", "sunset") : getVarCompletion(argv[0])) : Lists.newArrayList())) : (pre == '/' ? (argv.length == 4 ? UniverseRegistry.getWorldNames() : (argv.length == 1 ? this.getWarpList() : Lists.newArrayList())) : this.server.getAllUsernames());
|
|
||||||
for(String s1 : res) {
|
for(String s1 : res) {
|
||||||
if(s1.regionMatches(true, 0, s, 0, s.length()))
|
if(s1.regionMatches(true, 0, s, 0, s.length()))
|
||||||
list.add((argv.length == 1 ? pre : "") + s1);
|
list.add((argv.length == 1 && pre != 0 ? pre : "") + s1);
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class CPacketMessage implements Packet<NetHandlerPlayServer>
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Type {
|
public static enum Type {
|
||||||
CHAT(NetHandlerPlayServer.MAX_CMD_LENGTH), DISPLAY(NetHandlerPlayServer.MAX_NICK_LENGTH); // , ITEM(30);
|
COMMAND(NetHandlerPlayServer.MAX_CMD_LENGTH), CHAT(NetHandlerPlayServer.MAX_CMD_LENGTH), DISPLAY(NetHandlerPlayServer.MAX_NICK_LENGTH); // , ITEM(30);
|
||||||
|
|
||||||
private final int length;
|
private final int length;
|
||||||
|
|
||||||
|
|
|
@ -512,6 +512,10 @@ public abstract class Drawing {
|
||||||
return txt_size(0, 0, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, str).xpos;
|
return txt_size(0, 0, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, str).xpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getBoxWidth(String str) {
|
||||||
|
return txt_box(0, 0, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, str).xpos + 4;
|
||||||
|
}
|
||||||
|
|
||||||
public static void drawTextbox(String str, int x, int y, int back) {
|
public static void drawTextbox(String str, int x, int y, int back) {
|
||||||
Vec2i size = txt_box(x + 2, y, x + 2, y, Integer.MAX_VALUE, Integer.MAX_VALUE, str);
|
Vec2i size = txt_box(x + 2, y, x + 2, y, Integer.MAX_VALUE, Integer.MAX_VALUE, str);
|
||||||
drawRect(x, y, size.xpos + 2, size.ypos, back);
|
drawRect(x, y, size.xpos + 2, size.ypos, back);
|
||||||
|
|
|
@ -245,6 +245,18 @@ int utf_len(const char *str) {
|
||||||
return buildLines("\n", func, elems);
|
return buildLines("\n", func, elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> String buildLines(String separator, Iterable<T> elems) {
|
||||||
|
return buildLines(separator, new Function<T, String>() {
|
||||||
|
public String apply(T t) {
|
||||||
|
return String.valueOf(t);
|
||||||
|
}
|
||||||
|
}, elems);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> String buildLines(Iterable<T> elems) {
|
||||||
|
return buildLines("\n", elems);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> String buildLines(String separator, Function<T, String> func, T ... elems) {
|
public static <T> String buildLines(String separator, Function<T, String> func, T ... elems) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for(T elem : elems) {
|
for(T elem : elems) {
|
||||||
|
@ -258,4 +270,16 @@ int utf_len(const char *str) {
|
||||||
public static <T> String buildLines(Function<T, String> func, T ... elems) {
|
public static <T> String buildLines(Function<T, String> func, T ... elems) {
|
||||||
return buildLines("\n", func, elems);
|
return buildLines("\n", func, elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> String buildLines(String separator, T ... elems) {
|
||||||
|
return buildLines(separator, new Function<T, String>() {
|
||||||
|
public String apply(T t) {
|
||||||
|
return String.valueOf(t);
|
||||||
|
}
|
||||||
|
}, elems);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> String buildLines(T ... elems) {
|
||||||
|
return buildLines("\n", elems);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public enum Bind implements IStringSerializable, CVar {
|
||||||
SELECT7("select7", "Auswahl #7", Keysym.N7),
|
SELECT7("select7", "Auswahl #7", Keysym.N7),
|
||||||
SELECT8("select8", "Auswahl #8", Keysym.N8),
|
SELECT8("select8", "Auswahl #8", Keysym.N8),
|
||||||
SELECT9("select9", "Auswahl #9", Keysym.N9),
|
SELECT9("select9", "Auswahl #9", Keysym.N9),
|
||||||
|
CONSOLE("console", "Konsole", Keysym.F1),
|
||||||
COMMAND("command", "Befehl / Chat", Keysym.C),
|
COMMAND("command", "Befehl / Chat", Keysym.C),
|
||||||
INFO("info", "Infos einblenden", Keysym.TAB),
|
INFO("info", "Infos einblenden", Keysym.TAB),
|
||||||
PERSPECTIVE("perspective", "Perspektive ändern", Keysym.F5),
|
PERSPECTIVE("perspective", "Perspektive ändern", Keysym.F5),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue