split client and server 2
This commit is contained in:
parent
2fa521c3d1
commit
b17efb5b07
158 changed files with 1080 additions and 515 deletions
33
java/src/game/IServer.java
Normal file
33
java/src/game/IServer.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package game;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.network.IPlayer;
|
||||
import game.network.Packet;
|
||||
import game.world.BlockPos;
|
||||
import game.world.PortalType;
|
||||
import game.world.Position;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public interface IServer {
|
||||
List<IPlayer> getIPlayers();
|
||||
|
||||
void sendPacket(Packet packet);
|
||||
|
||||
void sendPacket(Packet packet, int dimension);
|
||||
|
||||
void sendNear(double x, double y, double z, double radius, int dimension, Packet packet);
|
||||
|
||||
void sendNearExcept(EntityNPC except, double x, double y, double z, double radius, int dimension, Packet packet);
|
||||
|
||||
Map<String, Position> getWarps();
|
||||
|
||||
List<WorldServer> getWorlds();
|
||||
|
||||
WorldServer getWorld(int dimension);
|
||||
|
||||
void placeInDimension(Entity entity, WorldServer oldWorld, WorldServer world, BlockPos pos, PortalType portal);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
public interface ArgCombiner<T> {
|
||||
Object combine(T[] values);
|
||||
Class<?> getTypeClass();
|
||||
Class<T> getInputClass();
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Argument {
|
||||
private final Parameter parameter;
|
||||
private final int position;
|
||||
private final String[] inputs;
|
||||
private final Map<String, Object> values;
|
||||
|
||||
public Argument(Parameter parameter, int position, String[] inputs, Map<String, Object> values) {
|
||||
this.parameter = parameter;
|
||||
this.position = position;
|
||||
this.inputs = inputs;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public Parameter getParameter() {
|
||||
return this.parameter;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public String[] getInputs() {
|
||||
return this.inputs;
|
||||
}
|
||||
|
||||
public Map<String, Object> getValues() {
|
||||
return this.values;
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
|
||||
public abstract class ArgumentParser {
|
||||
public static String[][] splitString(String str) {
|
||||
// if(str.isEmpty()) {
|
||||
// return new String[0];
|
||||
// }
|
||||
int pos;
|
||||
int last = 0;
|
||||
boolean space = true;
|
||||
boolean quote = false;
|
||||
boolean escape = false;
|
||||
char c;
|
||||
String arg = "";
|
||||
List<String> args = Lists.<String>newArrayList();
|
||||
List<String[]> cmds = Lists.<String[]>newArrayList();
|
||||
for(pos = 0; pos < str.length(); pos++) {
|
||||
c = str.charAt(pos);
|
||||
if(escape) {
|
||||
escape = false;
|
||||
switch(c) {
|
||||
case '\\':
|
||||
case ' ':
|
||||
case '"':
|
||||
case ';':
|
||||
arg += c;
|
||||
break;
|
||||
default:
|
||||
throw new RunException("Unbekannte Sequenz bei Zeichen %d: '\\%c'", pos + 1, c);
|
||||
}
|
||||
}
|
||||
else if(c == '\\') {
|
||||
space = false;
|
||||
escape = true;
|
||||
}
|
||||
else if(c == '"') {
|
||||
space = false;
|
||||
quote = !quote;
|
||||
last = pos;
|
||||
}
|
||||
else if(c == ' ' && !quote) {
|
||||
if(!space) {
|
||||
args.add(arg);
|
||||
arg = "";
|
||||
}
|
||||
space = true;
|
||||
}
|
||||
else if(c == ';' && !quote) {
|
||||
if(!space) {
|
||||
args.add(arg);
|
||||
arg = "";
|
||||
}
|
||||
space = true;
|
||||
if(!args.isEmpty()) {
|
||||
cmds.add(args.toArray(new String[args.size()]));
|
||||
args.clear();
|
||||
}
|
||||
}
|
||||
else {
|
||||
space = false;
|
||||
arg += c;
|
||||
}
|
||||
}
|
||||
if(escape)
|
||||
throw new RunException("Unvollständige Sequenz bei Zeichen %d", pos + 1);
|
||||
if(quote)
|
||||
throw new RunException("Nicht geschlossenes Anführungszeichen bei %d", last + 1);
|
||||
if(!space)
|
||||
args.add(arg);
|
||||
if(!args.isEmpty()) {
|
||||
cmds.add(args.toArray(new String[args.size()]));
|
||||
args.clear();
|
||||
}
|
||||
return cmds.toArray(new String[cmds.size()][]);
|
||||
}
|
||||
|
||||
private final String name;
|
||||
|
||||
public ArgumentParser(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public abstract Object parse(CommandEnvironment env, String input);
|
||||
public abstract Object getDefault(CommandEnvironment env);
|
||||
public abstract Collection<String> getCompletions(CommandEnvironment env);
|
||||
public abstract Class<?> getTypeClass();
|
||||
|
||||
public final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
|
@ -1,411 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Maps;
|
||||
import game.collect.Sets;
|
||||
|
||||
public class ArgumentSplitter {
|
||||
private final String command;
|
||||
private final Map<String, Argument> arguments;
|
||||
private final CommandEnvironment env;
|
||||
|
||||
protected ArgumentSplitter(Map<String, Argument> arguments, String command, CommandEnvironment env) {
|
||||
this.arguments = arguments;
|
||||
this.command = command;
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
private static <T> String joinArgs(Iterable<T> iter) {
|
||||
StringBuilder sb = new StringBuilder("'");
|
||||
for(T obj : iter) {
|
||||
if(sb.length() > 1)
|
||||
sb.append("', '");
|
||||
sb.append(String.valueOf(obj));
|
||||
}
|
||||
return sb.append("'").toString();
|
||||
}
|
||||
|
||||
public static ArgumentSplitter parseArgs(CommandEnvironment env, String str, String[] argv, CachedExecutable cached) {
|
||||
Map<String, Parameter> parameters = cached.getParameters();
|
||||
List<Parameter> positionals = Lists.newArrayList(cached.getPositionals());
|
||||
// String[] argv = ArgumentParser.splitString(str);
|
||||
Map<String, Argument> args = Maps.newHashMap();
|
||||
int ppos = 0;
|
||||
boolean parse = true;
|
||||
for(int z = 1; z < argv.length; z++) {
|
||||
String arg = argv[z];
|
||||
Parameter param = null;
|
||||
boolean pos = false;
|
||||
if(parse && arg.equals("--")) {
|
||||
parse = false;
|
||||
continue;
|
||||
}
|
||||
else if(parse && (arg.startsWith("--") || (arg.startsWith("-") && arg.length() == 2))) {
|
||||
param = parameters.get(arg.substring(arg.startsWith("--") ? 2 : 1));
|
||||
if(param != null && param.isPositional() && !args.containsKey(param.getName())) {
|
||||
for(int n = 0; n < positionals.size(); n++) {
|
||||
if(param == positionals.get(n)) {
|
||||
positionals.remove(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(ppos < positionals.size()) {
|
||||
param = positionals.get(ppos++);
|
||||
pos = true;
|
||||
}
|
||||
else {
|
||||
throw new RunException("Position %d: Parameter '%s' ist überflüssig", z, arg);
|
||||
}
|
||||
if(param == null)
|
||||
throw new RunException("Position %d: Argument '%s' ist unbekannt", z, arg);
|
||||
if(args.containsKey(param.getName()))
|
||||
throw new RunException("Position %d: Parameter '%s' mehrfach angegeben", z, param.getName());
|
||||
int nargs = param.getParsers().size();
|
||||
// if(!pos)
|
||||
// z += 1;
|
||||
if(z + (pos ? 0 : 1) + nargs > argv.length)
|
||||
if(nargs == 1 && param.getName().equals(param.getParsers().get(0).getName()))
|
||||
throw new RunException("Position %d: Argument '%s' benötigt einen Parameter", z, param.getName());
|
||||
else
|
||||
throw new RunException("Position %d: Argument '%s' benötigt %d Parameter (%s)", z, param.getName(), nargs,
|
||||
joinArgs(param.getParsers()));
|
||||
Map<String, Object> params = Maps.newHashMapWithExpectedSize(nargs);
|
||||
String[] inputs = new String[nargs + (pos ? 0 : 1)];
|
||||
int apos = 0;
|
||||
for(int n = pos ? 0 : 1; n < nargs + (pos ? 0 : 1); n++) {
|
||||
String par = inputs[n] = argv[z + n];
|
||||
ArgumentParser parser = param.getParsers().get(apos);
|
||||
if(parse && (par.startsWith("--") || (par.startsWith("-") && par.length() == 2)))
|
||||
if(nargs == 1 && param.getName().equals(parser.getName()))
|
||||
throw new RunException("Position %d: Argument '%s': '%s' als Parameter verwendet", z + n, param.getName(), par);
|
||||
else
|
||||
throw new RunException("Position %d: Argument '%s': '%s' als Parameter '%s' (#%d) verwendet", z + n,
|
||||
param.getName(), par, parser.getName(), apos + 1);
|
||||
try {
|
||||
params.put(parser.getName(), parser.parse(env, par));
|
||||
}
|
||||
catch(Throwable e) {
|
||||
if(nargs == 1 && param.getName().equals(parser.getName()))
|
||||
throw new RunException(e, "Position %d: Argument '%s': Parameter konnte nicht interpretiert werden", z + n,
|
||||
param.getName());
|
||||
else
|
||||
throw new RunException(e, "Position %d: Argument '%s': Parameter '%s' (#%d) konnte nicht interpretiert werden", z + n,
|
||||
param.getName(), parser.getName(), apos + 1);
|
||||
}
|
||||
apos += 1;
|
||||
}
|
||||
if(!pos)
|
||||
inputs[0] = arg;
|
||||
args.put(param.getName(), new Argument(param, z, inputs, params));
|
||||
z += nargs - (pos ? 1 : 0);
|
||||
}
|
||||
for(Parameter param : parameters.values()) {
|
||||
if(!args.containsKey(param.getName())) {
|
||||
if(param.isRequired()) {
|
||||
for(ArgumentParser parser : param.getParsers()) {
|
||||
if(parser.getDefault(env) == null)
|
||||
throw new RunException("Argument '%s' muss angegeben werden", param.getName());
|
||||
}
|
||||
}
|
||||
else if(param.getParsers().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> params = Maps.newHashMapWithExpectedSize(param.getParsers().size());
|
||||
for(ArgumentParser parser : param.getParsers()) {
|
||||
params.put(parser.getName(), parser.getDefault(env));
|
||||
}
|
||||
args.put(param.getName(), new Argument(param, -1, null, params));
|
||||
}
|
||||
}
|
||||
return new ArgumentSplitter(args, str, env);
|
||||
}
|
||||
|
||||
private static Iterable<String> getParam(CommandEnvironment env, String[] argv, CachedExecutable cached) {
|
||||
Map<String, Parameter> parameters = cached.getParameters();
|
||||
List<Parameter> positionals = Lists.newArrayList(cached.getPositionals());
|
||||
Set<String> args = Sets.newHashSet();
|
||||
int ppos = 0;
|
||||
boolean parse = true;
|
||||
for(int z = 1; z < argv.length; z++) {
|
||||
String arg = argv[z];
|
||||
Parameter param = null;
|
||||
boolean pos = false;
|
||||
if(z == argv.length - 1) {
|
||||
if(ppos < positionals.size()) {
|
||||
param = positionals.get(ppos);
|
||||
if(param.getParsers().isEmpty()) // np
|
||||
return null;
|
||||
return param.getParsers().get(0).getCompletions(env);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(parse && arg.equals("--")) {
|
||||
parse = false;
|
||||
continue;
|
||||
}
|
||||
else if(parse && (arg.startsWith("--") || (arg.startsWith("-") && arg.length() == 2))) {
|
||||
param = parameters.get(arg.substring(arg.startsWith("--") ? 2 : 1));
|
||||
if(param != null && param.isPositional() && !args.contains(param.getName())) {
|
||||
for(int n = 0; n < positionals.size(); n++) {
|
||||
if(param == positionals.get(n)) {
|
||||
positionals.remove(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(ppos < positionals.size()) {
|
||||
param = positionals.get(ppos++);
|
||||
pos = true;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
if(param == null || args.contains(param.getName()))
|
||||
return null;
|
||||
int nargs = param.getParsers().size();
|
||||
// if(z + (pos ? 0 : 1) + nargs > argv.length - 1) {
|
||||
// return param.getParsers().get(argv.length - z).getCompletions(env);
|
||||
// }
|
||||
int apos = 0;
|
||||
for(int n = pos ? 0 : 1; n < nargs + (pos ? 0 : 1); n++) {
|
||||
if(z + n == argv.length - 1)
|
||||
return param.getParsers().get(apos).getCompletions(env);
|
||||
String par = argv[z + n];
|
||||
if(parse && (par.startsWith("--") || (par.startsWith("-") && par.length() == 2)))
|
||||
return null;
|
||||
apos += 1;
|
||||
}
|
||||
args.add(param.getName());
|
||||
z += nargs - (pos ? 1 : 0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Iterable<String> parseComplete(CommandEnvironment env, String[] argv, CachedExecutable cached, String last) {
|
||||
Iterable<String> comp = getParam(env, argv, cached);
|
||||
if(comp == null /* || comp.length == 0 */ ) {
|
||||
Set<String> params = Sets.newTreeSet();
|
||||
boolean all = last.startsWith("--");
|
||||
for(String param : cached.getParameters().keySet()) {
|
||||
if(all || param.length() == 1)
|
||||
params.add(param.length() == 1 ? "-" + param : ("--" + param));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
// public ScriptArg getArg(String name) {
|
||||
// return this.arguments.get(name);
|
||||
// }
|
||||
|
||||
public boolean hasArg(String name) {
|
||||
return this.arguments.containsKey(name);
|
||||
}
|
||||
|
||||
// public boolean has(String name, String par) {
|
||||
// return this.arguments.containsKey(name) && this.arguments.get(name).getValues().containsKey(par);
|
||||
// }
|
||||
|
||||
// public boolean has(String name) {
|
||||
// return this.has(name, name);
|
||||
// }
|
||||
|
||||
// public <T> T getDefault(String name, String par, T def) {
|
||||
// ScriptArg arg = this.arguments.get(name);
|
||||
// if(arg == null)
|
||||
// return def;
|
||||
// Object value = arg.getValues().get(par);
|
||||
// return value == null ? def : (T)value;
|
||||
// }
|
||||
//
|
||||
// public <T> T getDefault(String name, T def) {
|
||||
// return this.getDefault(name, name, def);
|
||||
// }
|
||||
//
|
||||
// public <T> T getUnchecked(String name, String par) {
|
||||
// return this.getDefault(name, par, null);
|
||||
// }
|
||||
|
||||
public <T> T getUnchecked(String name, String par) {
|
||||
Argument arg = this.arguments.get(name);
|
||||
if(arg == null)
|
||||
return null;
|
||||
Object value = arg.getValues().get(par);
|
||||
return value == null ? null : (T)value;
|
||||
}
|
||||
|
||||
// public <T> T getUnchecked(String name) {
|
||||
// return this.getDefault(name, null);
|
||||
// }
|
||||
//
|
||||
// public boolean getBool(String name, boolean def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public boolean getBool(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public <T extends Enum<?>> T getEnum(String name, T def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public <T extends Enum<?>> T getEnum(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public int getInt(String name, int def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public int getInt(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public long getLong(String name, long def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public long getLong(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public double getDouble(String name, double def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public double getDouble(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public String getString(String name, String def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public String getString(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public String[] getStrings(String name, String[] def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public String[] getStrings(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public Entity getEntity(String name, Entity def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public Entity getEntity(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public EntityLiving getLiving(String name, EntityLiving def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public EntityLiving getLiving(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public EntityNPC getNpc(String name, EntityNPC def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public EntityNPC getNpc(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public Block getBlock(String name, Block def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public Block getBlock(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public State getState(String name, State def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public State getState(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public Item getItem(String name, Item def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public Item getItem(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public ItemStack getStack(String name, ItemStack def) {
|
||||
// return this.getDefault(name, def);
|
||||
// }
|
||||
//
|
||||
// public ItemStack getStack(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public BlockPos getColumnPos(String name, BlockPos def) {
|
||||
// return this.hasArg(name) ? this.getColumnPos(name) : def;
|
||||
// }
|
||||
//
|
||||
// public BlockPos getColumnPos(String name) {
|
||||
// return new BlockPos(this.getUnchecked(name, "x"), 0, this.getUnchecked(name, "z"));
|
||||
// }
|
||||
//
|
||||
// public BlockPos getBlockPos(String name, BlockPos def) {
|
||||
// return this.hasArg(name) ? this.getBlockPos(name) : def;
|
||||
// }
|
||||
//
|
||||
// public BlockPos getBlockPos(String name) {
|
||||
// return new BlockPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
|
||||
// }
|
||||
//
|
||||
// public WorldPos getWorldPos(String name, WorldPos def) {
|
||||
// return this.hasArg(name) ? this.getWorldPos(name) : def;
|
||||
// }
|
||||
//
|
||||
// public WorldPos getWorldPos(String name) {
|
||||
// return new WorldPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"),
|
||||
// this.getUnchecked(name, "dim"));
|
||||
// }
|
||||
//
|
||||
// public Vec3 getVector2D(String name, Vec3 def) {
|
||||
// return this.hasArg(name) ? this.getVector2D(name) : def;
|
||||
// }
|
||||
//
|
||||
// public Vec3 getVector2D(String name) {
|
||||
// return new Vec3(this.getUnchecked(name, "x"), 0.0, this.getUnchecked(name, "z"));
|
||||
// }
|
||||
//
|
||||
// public Vec3 getVector(String name, Vec3 def) {
|
||||
// return this.hasArg(name) ? this.getVector(name) : def;
|
||||
// }
|
||||
//
|
||||
// public Vec3 getVector(String name) {
|
||||
// return new Vec3(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
|
||||
// }
|
||||
//
|
||||
// public WorldServer getWorld(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
//
|
||||
// public NBTTagCompound getTag(String name) {
|
||||
// return this.getUnchecked(name);
|
||||
// }
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
public class BooleanParser extends EnumParser<Boolean> {
|
||||
public BooleanParser(String name, Boolean def) {
|
||||
super(name, Boolean.class, def, true, false);
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return this.hasDefault() ? boolean.class : Boolean.class;
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Maps;
|
||||
|
||||
public class CachedExecutable {
|
||||
private final Executable executable;
|
||||
private final String name;
|
||||
private final Map<String, Parameter> parameters;
|
||||
private final List<Parameter> positionals;
|
||||
private final Method method;
|
||||
|
||||
protected CachedExecutable(Executable executable, Map<String, Parameter> parameters, List<Parameter> positionals, Method method) {
|
||||
this.executable = executable;
|
||||
this.parameters = parameters;
|
||||
this.positionals = positionals;
|
||||
this.name = executable.getName();
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public static CachedExecutable cacheExecutable(Executable executable) {
|
||||
Map<String, Parameter> parameters = Maps.newTreeMap();
|
||||
Map<String, Parameter> params = executable.getParameters();
|
||||
parameters.putAll(params);
|
||||
Parameter[] positions = new Parameter[parameters.size()];
|
||||
int pos = -1;
|
||||
for(Parameter param : params.values()) {
|
||||
if(param.isPositional()) {
|
||||
positions[param.getPosition()] = param;
|
||||
pos = param.getPosition() > pos ? param.getPosition() : pos;
|
||||
}
|
||||
if(param.hasShortName())
|
||||
parameters.put("" + param.getShortName(), param);
|
||||
}
|
||||
List<Parameter> positionals = Lists.newArrayList();
|
||||
for(int z = 0; z <= pos; z++) {
|
||||
if(positions[z] == null)
|
||||
throw new NullPointerException("positions[" + z + "]");
|
||||
positionals.add(positions[z]);
|
||||
}
|
||||
List<Class<?>> classes = Lists.newArrayList(CommandEnvironment.class, Executor.class);
|
||||
for(Parameter param : executable.getParamList()) {
|
||||
ArgCombiner<?> combiner = param.getCombiner();
|
||||
if(combiner != null) {
|
||||
classes.add(combiner.getTypeClass());
|
||||
continue;
|
||||
}
|
||||
if(param.getParsers().isEmpty()) {
|
||||
classes.add(boolean.class);
|
||||
continue;
|
||||
}
|
||||
for(ArgumentParser parser : param.getParsers()) {
|
||||
classes.add(parser.getTypeClass());
|
||||
}
|
||||
}
|
||||
Method method;
|
||||
try {
|
||||
method = executable.getClass().getDeclaredMethod("exec", classes.toArray(new Class<?>[classes.size()]));
|
||||
}
|
||||
catch(NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new CachedExecutable(executable, parameters, positionals, method);
|
||||
}
|
||||
|
||||
public Executable getExecutable() {
|
||||
return this.executable;
|
||||
}
|
||||
|
||||
public Method getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
public Map<String, Parameter> getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
public List<Parameter> getPositionals() {
|
||||
return this.positionals;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import game.color.DyeColor;
|
||||
|
||||
public class ColorParser extends IntParser {
|
||||
public ColorParser(String name, Integer def, Object ... completions) {
|
||||
super(name, true, def, null, null, completions);
|
||||
}
|
||||
|
||||
public ColorParser(String name, Integer def) {
|
||||
this(name, def, (Object[])DyeColor.values());
|
||||
}
|
||||
|
||||
public Integer parse(CommandEnvironment env, String input) {
|
||||
if(input.startsWith("#")) {
|
||||
input = input.substring(1);
|
||||
}
|
||||
else {
|
||||
DyeColor color = DyeColor.getByString(input);
|
||||
if(color != null)
|
||||
return color.getColor();
|
||||
}
|
||||
if(input.length() != 6)
|
||||
throw new RunException("Der Farbcode muss 6 Stellen haben, habe %d ('%s')", input.length(), input);
|
||||
return super.parse(env, input);
|
||||
}
|
||||
}
|
|
@ -1,207 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Maps;
|
||||
import game.command.DoubleParser.DefType;
|
||||
import game.world.Vec3;
|
||||
import game.world.World;
|
||||
|
||||
public abstract class Command implements Executable {
|
||||
private final String name;
|
||||
private final Map<String, Parameter> parameters = Maps.newHashMap();
|
||||
private final List<Parameter> argList = Lists.newArrayList();
|
||||
|
||||
private int parPos = 0;
|
||||
private boolean parReq = true;
|
||||
|
||||
protected Command(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected Command setParamsOptional() {
|
||||
this.parReq = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Command addParameter(String name, ArgCombiner<?> combiner, ArgumentParser ... parsers) {
|
||||
Parameter param = new Parameter(name, (char)0, this.parPos++, this.parReq, Lists.newArrayList(parsers), combiner);
|
||||
this.parameters.put(name, param);
|
||||
this.argList.add(param);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Command addParameter(String name, char shortName, ArgCombiner<?> combiner, ArgumentParser ... parsers) {
|
||||
Parameter param = new Parameter(name, shortName, -1, false, Lists.newArrayList(parsers), combiner);
|
||||
this.parameters.put(name, param);
|
||||
this.argList.add(param);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Command addParameter(String name, ArgumentParser ... parsers) {
|
||||
return this.addParameter(name, null, parsers);
|
||||
}
|
||||
|
||||
protected Command addParameter(String name, char shortName, ArgumentParser ... parsers) {
|
||||
return this.addParameter(name, shortName, null, parsers);
|
||||
}
|
||||
|
||||
protected Command addParameter(ArgumentParser parser) {
|
||||
return this.addParameter(parser.getName(), parser);
|
||||
}
|
||||
|
||||
protected Command addParameter(char shortName, ArgumentParser parser) {
|
||||
return this.addParameter(parser.getName(), shortName, parser);
|
||||
}
|
||||
|
||||
protected Command addVector(String name, boolean defaulted, boolean centered) {
|
||||
return this.addParameter(name, new ArgCombiner<Double>() {
|
||||
public Vec3 combine(Double[] values) {
|
||||
return new Vec3(values[0], values[1], values[2]);
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return Vec3.class;
|
||||
}
|
||||
|
||||
public Class<Double> getInputClass() {
|
||||
return Double.class;
|
||||
}
|
||||
},
|
||||
new DoubleParser("x", defaulted ? DefType.X : null, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE, centered),
|
||||
new DoubleParser("y", defaulted ? DefType.Y : null, 0.0, (double)World.HEIGHT, false),
|
||||
new DoubleParser("z", defaulted ? DefType.Z : null, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE, centered));
|
||||
}
|
||||
|
||||
protected Command addWorld(String name, boolean defaulted) {
|
||||
return this.addParameter(new WorldParser(name, false, defaulted));
|
||||
}
|
||||
|
||||
protected Command addDimension(String name, boolean defaulted) {
|
||||
return this.addParameter(new DimensionParser(name, defaulted));
|
||||
}
|
||||
|
||||
protected Command addInt(String name, char shortName, int min, int max, int def) {
|
||||
return this.addParameter(shortName, new IntParser(name, false, def, min, max, def));
|
||||
}
|
||||
|
||||
protected Command addInt(String name, int min, int max, int def) {
|
||||
return this.addParameter(new IntParser(name, false, def, min, max, def));
|
||||
}
|
||||
|
||||
protected Command addDouble(String name, char shortName, double min, double max, double def) {
|
||||
return this.addParameter(shortName, new DoubleParser(name, def, min, max, false, def));
|
||||
}
|
||||
|
||||
protected Command addDouble(String name, double min, double max, double def) {
|
||||
return this.addParameter(new DoubleParser(name, def, min, max, false, def));
|
||||
}
|
||||
|
||||
protected Command addInt(String name, char shortName, int min, int max) {
|
||||
return this.addParameter(shortName, new IntParser(name, false, null, min, max));
|
||||
}
|
||||
|
||||
protected Command addInt(String name, int min, int max) {
|
||||
return this.addParameter(new IntParser(name, false, null, min, max));
|
||||
}
|
||||
|
||||
protected Command addDouble(String name, char shortName, double min, double max) {
|
||||
return this.addParameter(shortName, new DoubleParser(name, null, min, max, false));
|
||||
}
|
||||
|
||||
protected Command addDouble(String name, double min, double max) {
|
||||
return this.addParameter(new DoubleParser(name, null, min, max, false));
|
||||
}
|
||||
|
||||
protected Command addFlag(String name, char shortName) {
|
||||
return this.addParameter(name, shortName);
|
||||
}
|
||||
|
||||
// protected ScriptExecutable addFlag(String name) {
|
||||
// return this.addParameter(name, name.charAt(0));
|
||||
// }
|
||||
|
||||
protected <T> Command addEnum(String name, T def, Class<T> clazz, T ... values) {
|
||||
return this.addParameter(new EnumParser<T>(name, clazz, def, values));
|
||||
}
|
||||
|
||||
protected <T> Command addEnum(String name, Class<T> clazz, T ... values) {
|
||||
return this.addEnum(name, null, clazz, values);
|
||||
}
|
||||
|
||||
protected <T> Command addEnum(String name, T def, Class<T> clazz, Collection<T> values) {
|
||||
return this.addEnum(name, def, clazz, values.toArray((T[])Array.newInstance(clazz, values.size())));
|
||||
}
|
||||
|
||||
protected <T> Command addEnum(String name, Class<T> clazz, Collection<T> values) {
|
||||
return this.addEnum(name, null, clazz, values);
|
||||
}
|
||||
|
||||
protected <T> Command addEnum(String name, char shortName, T def, Class<T> clazz, T ... values) {
|
||||
return this.addParameter(shortName, new EnumParser<T>(name, clazz, def, values));
|
||||
}
|
||||
|
||||
protected Command addTag(String name) {
|
||||
return this.addParameter(new TagParser(name, null));
|
||||
}
|
||||
|
||||
protected Command addTag(String name, char shortName) {
|
||||
return this.addParameter(shortName, new TagParser(name, null));
|
||||
}
|
||||
|
||||
protected Command addPlayer(String name, boolean defaulted) {
|
||||
return this.addParameter(new PlayerParser(name, defaulted));
|
||||
}
|
||||
|
||||
protected Command addPlayerEntity(String name, boolean defaulted) {
|
||||
return this.addParameter(new PlayerEntityParser(name, defaulted));
|
||||
}
|
||||
|
||||
protected Command addEntity(String name, boolean defaulted) {
|
||||
return this.addParameter(new EntityParser(name, defaulted, false));
|
||||
}
|
||||
|
||||
protected Command addEntity(String name, char shortName, boolean defaulted) {
|
||||
return this.addParameter(shortName, new EntityParser(name, defaulted, false));
|
||||
}
|
||||
|
||||
protected Command addEntityList(String name, boolean defaulted) {
|
||||
return this.addParameter(new EntityListParser(name, defaulted, false));
|
||||
}
|
||||
|
||||
protected Command addEntityList(String name, char shortName, boolean defaulted) {
|
||||
return this.addParameter(shortName, new EntityListParser(name, defaulted, false));
|
||||
}
|
||||
|
||||
protected Command addLivingEntity(String name, boolean defaulted) {
|
||||
return this.addParameter(new EntityParser(name, defaulted, true));
|
||||
}
|
||||
|
||||
protected Command addLivingEntityList(String name, boolean defaulted) {
|
||||
return this.addParameter(new EntityListParser(name, defaulted, true));
|
||||
}
|
||||
|
||||
protected Command addString(String name, boolean allowEmpty, Object ... completions) {
|
||||
return this.addParameter(new StringParser(name, null, allowEmpty, null, null, null, completions));
|
||||
}
|
||||
|
||||
protected Command addString(String name, boolean allowEmpty, StringCompleter completer) {
|
||||
return this.addParameter(new StringParser(name, null, allowEmpty, null, null, null, completer));
|
||||
}
|
||||
|
||||
public Map<String, Parameter> getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
public List<Parameter> getParamList() {
|
||||
return this.argList;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
|
@ -1,275 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Maps;
|
||||
import game.collect.Sets;
|
||||
import game.color.TextColor;
|
||||
import game.command.commands.CommandAdmin;
|
||||
import game.command.commands.CommandHelp;
|
||||
import game.command.commands.CommandKick;
|
||||
import game.command.commands.CommandMessage;
|
||||
import game.command.commands.CommandMilk;
|
||||
import game.command.commands.CommandOfflinetp;
|
||||
import game.command.commands.CommandPotion;
|
||||
import game.command.commands.CommandRemove;
|
||||
import game.command.commands.CommandRevoke;
|
||||
import game.command.commands.CommandSpawn;
|
||||
import game.command.commands.CommandTele;
|
||||
import game.command.commands.CommandTime;
|
||||
import game.command.commands.CommandTp;
|
||||
import game.command.commands.CommandWarp;
|
||||
import game.command.commands.CommandWeather;
|
||||
import game.command.commands.CommandWorld;
|
||||
import game.log.Log;
|
||||
import server.Server;
|
||||
|
||||
public class CommandEnvironment {
|
||||
private final Server server;
|
||||
private final Map<String, CachedExecutable> executables = Maps.newTreeMap();
|
||||
private final List<PatternReplacer> replacers = Lists.newArrayList();
|
||||
private final Set<String> builtins = Sets.newHashSet();
|
||||
private final Map<String, String> variables = Maps.newHashMap();
|
||||
|
||||
private Executor currentExecutor;
|
||||
private Object previousOutput;
|
||||
|
||||
public CommandEnvironment(Server server) {
|
||||
this.server = server;
|
||||
this.registerDefaults();
|
||||
}
|
||||
|
||||
public void registerExecutable(Executable executable) {
|
||||
CachedExecutable cached = CachedExecutable.cacheExecutable(executable);
|
||||
if(this.executables.containsKey(cached.getName()))
|
||||
throw new IllegalStateException("Befehl " + cached.getName() + " ist bereits registriert");
|
||||
this.executables.put(cached.getName(), cached);
|
||||
this.registerReplacer(cached.getName(), new Function<String, String>() {
|
||||
public String apply(String str) {
|
||||
Object o;
|
||||
try {
|
||||
o = CommandEnvironment.this.execute(str, false);
|
||||
}
|
||||
catch(Throwable e) {
|
||||
throw new RunException(e, "Variable konnte nicht ersetzt werden: '%s' konnte nicht ausgeführt werden", str);
|
||||
}
|
||||
if(o == null)
|
||||
throw new RunException("Variable konnte nicht ersetzt werden: null von '%s' zurückgegeben", str);
|
||||
return o.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void registerReplacer(String var, Function<String, String> function) {
|
||||
if(this.builtins.contains(var))
|
||||
throw new IllegalStateException("Variable " + var + " ist bereits registriert");
|
||||
this.replacers.add(new PatternReplacer(var, true, function));
|
||||
this.builtins.add(var);
|
||||
}
|
||||
|
||||
public void registerVariable(String var, Variable variable) {
|
||||
if(this.builtins.contains(var))
|
||||
throw new IllegalStateException("Variable " + var + " ist bereits registriert");
|
||||
this.replacers.add(new PatternReplacer(var, false, new Function<String, String>() {
|
||||
public String apply(String ign) {
|
||||
return variable.get();
|
||||
}
|
||||
}));
|
||||
this.builtins.add(var);
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return this.server;
|
||||
}
|
||||
|
||||
public Map<String, CachedExecutable> getExecutables() {
|
||||
return this.executables;
|
||||
}
|
||||
|
||||
public Executor getExecutor() {
|
||||
return this.currentExecutor;
|
||||
}
|
||||
|
||||
private String substitute(String str) {
|
||||
StringBuffer sb = new StringBuffer(str);
|
||||
for(PatternReplacer replacer : this.replacers) {
|
||||
replacer.replaceVar(sb);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private Object execute(String cmd, boolean setPrev) {
|
||||
String line = this.substitute(cmd);
|
||||
String[][] cmds = ArgumentParser.splitString(line);
|
||||
Object o = null;
|
||||
for(String[] argv : cmds) {
|
||||
String exec = argv[0];
|
||||
String var = null;
|
||||
int eq = exec.indexOf('=');
|
||||
if(eq >= 0) {
|
||||
var = exec.substring(0, eq);
|
||||
exec = exec.substring(eq + 1);
|
||||
}
|
||||
CachedExecutable cached = this.executables.get(exec);
|
||||
if(cached == null)
|
||||
throw new RunException("Befehl '%s' existiert nicht", exec);
|
||||
for(int z = 0; z < argv.length; z++) {
|
||||
String arg = argv[z];
|
||||
if(arg.startsWith("$(") && arg.endsWith(")")) {
|
||||
String resolve = this.variables.get(arg.substring(2, arg.length() - 1));
|
||||
if(resolve != null)
|
||||
argv[z] = resolve;
|
||||
}
|
||||
}
|
||||
ArgumentSplitter args = ArgumentSplitter.parseArgs(this, cmd, argv, cached);
|
||||
List<Object> params = Lists.newArrayList(this, this.currentExecutor);
|
||||
for(Parameter param : cached.getExecutable().getParamList()) {
|
||||
ArgCombiner combiner = param.getCombiner();
|
||||
if(combiner != null) {
|
||||
Object[] data = (Object[])Array.newInstance(combiner.getInputClass(), param.getParsers().size());
|
||||
for(int z = 0; z < data.length; z++) {
|
||||
data[z] = args.getUnchecked(param.getName(), param.getParsers().get(z).getName());
|
||||
if(data[z] == null) {
|
||||
data = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
params.add(data == null ? null : combiner.combine(data));
|
||||
continue;
|
||||
}
|
||||
if(param.getParsers().isEmpty()) {
|
||||
params.add(args.hasArg(param.getName()));
|
||||
continue;
|
||||
}
|
||||
for(ArgumentParser parser : param.getParsers()) {
|
||||
params.add(args.getUnchecked(param.getName(), parser.getName()));
|
||||
}
|
||||
}
|
||||
try {
|
||||
o = cached.getMethod().invoke(cached.getExecutable(), params.toArray(new Object[params.size()]));
|
||||
}
|
||||
catch(InvocationTargetException e) {
|
||||
if(e.getCause() instanceof RuntimeException)
|
||||
throw ((RuntimeException)e.getCause());
|
||||
else
|
||||
throw new RuntimeException(e.getCause());
|
||||
}
|
||||
catch(IllegalAccessException | IllegalArgumentException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// o = cached.getExecutable().exec(this, args);
|
||||
if(setPrev)
|
||||
this.previousOutput = o;
|
||||
if(var != null && !var.isEmpty() && !this.builtins.contains(var)) {
|
||||
if(o != null)
|
||||
this.variables.put(var, String.valueOf(o));
|
||||
else
|
||||
this.variables.remove(var);
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
public void execute(String cmd, Executor exec) {
|
||||
this.currentExecutor = exec;
|
||||
try {
|
||||
this.execute(cmd, true);
|
||||
}
|
||||
catch(RunException e) {
|
||||
Throwable cause = e;
|
||||
do {
|
||||
exec.logConsole(TextColor.RED + cause.getMessage());
|
||||
cause = cause.getCause();
|
||||
}
|
||||
while(cause != null);
|
||||
}
|
||||
catch(Throwable t) {
|
||||
exec.logConsole(TextColor.RED + "Fehler: %s", t.getMessage());
|
||||
Log.CONSOLE.error(t, "Fehler beim Ausführen von Befehl '%s'", cmd);
|
||||
}
|
||||
finally {
|
||||
this.currentExecutor = null;
|
||||
this.previousOutput = null;
|
||||
this.variables.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> complete(String cmd, Executor exec) {
|
||||
this.currentExecutor = exec;
|
||||
List<String> list = Lists.newArrayList();
|
||||
try {
|
||||
String[][] cmds = ArgumentParser.splitString(cmd.endsWith(" ") ? cmd + "END" : cmd);
|
||||
if(cmds.length == 0)
|
||||
return list;
|
||||
String[] argv = cmds[cmds.length - 1];
|
||||
if(argv.length == 0)
|
||||
return list;
|
||||
String param = cmd.endsWith(" ") ? "" : argv[argv.length - 1];
|
||||
Iterable<String> comp;
|
||||
if(argv.length > 1) {
|
||||
int eq = argv[0].indexOf('=');
|
||||
CachedExecutable cached = this.executables.get(eq >= 0 ? argv[0].substring(eq + 1) : argv[0]);
|
||||
if(cached == null)
|
||||
return list;
|
||||
comp = ArgumentSplitter.parseComplete(this, argv, cached, param);
|
||||
}
|
||||
else {
|
||||
comp = this.executables.keySet();
|
||||
}
|
||||
for(String cmp : comp) {
|
||||
if(cmp.regionMatches(true, 0, param, 0, param.length()))
|
||||
list.add(cmp);
|
||||
}
|
||||
}
|
||||
catch(Throwable t) {
|
||||
list.clear();
|
||||
Log.CONSOLE.error(t, "Konnte Befehl '%s' nicht vervollständigen", cmd);
|
||||
}
|
||||
finally {
|
||||
this.currentExecutor = null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void registerDefaults() {
|
||||
this.registerVariable("*", new Variable() {
|
||||
public String get() {
|
||||
return CommandEnvironment.this.currentExecutor.getExecId();
|
||||
}
|
||||
});
|
||||
this.registerVariable("name", new Variable() {
|
||||
public String get() {
|
||||
return CommandEnvironment.this.currentExecutor.getExecName();
|
||||
}
|
||||
});
|
||||
this.registerVariable("!", new Variable() {
|
||||
public String get() {
|
||||
return CommandEnvironment.this.previousOutput == null ? null : CommandEnvironment.this.previousOutput.toString();
|
||||
}
|
||||
});
|
||||
|
||||
this.registerExecutable(new CommandSpawn());
|
||||
this.registerExecutable(new CommandPotion());
|
||||
this.registerExecutable(new CommandMilk());
|
||||
this.registerExecutable(new CommandAdmin());
|
||||
this.registerExecutable(new CommandRevoke());
|
||||
this.registerExecutable(new CommandTp());
|
||||
this.registerExecutable(new CommandTele());
|
||||
this.registerExecutable(new CommandWorld());
|
||||
this.registerExecutable(new CommandOfflinetp());
|
||||
this.registerExecutable(new CommandWarp());
|
||||
this.registerExecutable(new CommandTime());
|
||||
this.registerExecutable(new CommandRemove());
|
||||
this.registerExecutable(new CommandWeather());
|
||||
this.registerExecutable(new CommandKick());
|
||||
this.registerExecutable(new CommandMessage());
|
||||
|
||||
this.registerExecutable(new CommandHelp(this));
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Completer {
|
||||
void complete(List<String> comp, CommandEnvironment env, ArgumentSplitter args, Argument arg);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CompletingParser extends ArgumentParser {
|
||||
private final List<String> defCompletions;
|
||||
|
||||
public CompletingParser(String name, Object ... completions) {
|
||||
super(name);
|
||||
this.defCompletions = new ArrayList<String>(completions.length);
|
||||
for(Object comp : completions) {
|
||||
this.defCompletions.add(String.valueOf(comp));
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
return this.defCompletions;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
public abstract class DefaultingParser extends CompletingParser {
|
||||
private final Object def;
|
||||
|
||||
public DefaultingParser(String name, Object def, Object ... completions) {
|
||||
super(name, completions);
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
return this.def;
|
||||
}
|
||||
|
||||
protected final boolean hasDefault() {
|
||||
return this.def != null;
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import game.dimension.Dimension;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.world.Position;
|
||||
|
||||
public class DimensionParser extends CompletingParser {
|
||||
private final boolean useSender;
|
||||
|
||||
public DimensionParser(String name, boolean useSender) {
|
||||
super(name);
|
||||
this.useSender = useSender;
|
||||
}
|
||||
|
||||
public Object parse(CommandEnvironment env, String input) {
|
||||
Dimension dim = UniverseRegistry.getDimension(input);
|
||||
if(dim != null)
|
||||
return dim;
|
||||
int id = Integer.MIN_VALUE;
|
||||
try {
|
||||
id = Integer.parseInt(input);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
dim = UniverseRegistry.getDimension(id);
|
||||
if(dim == null)
|
||||
throw new RunException("Unbekannte Dimension '%s'", input);
|
||||
return dim;
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
if(!this.useSender)
|
||||
return null;
|
||||
Position pos = env.getExecutor().getExecPos();
|
||||
return pos == null ? null : UniverseRegistry.getDimension(pos.dim);
|
||||
// if(dim == null)
|
||||
// throw new ScriptException("Unbekannte Dimension '%s'");
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
return UniverseRegistry.getWorldNames();
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return Dimension.class;
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Position;
|
||||
|
||||
public class DoubleParser extends DefaultingParser {
|
||||
public static enum DefType {
|
||||
X, Y, Z, YAW, PITCH;
|
||||
}
|
||||
|
||||
private final DefType defType;
|
||||
private final Double min;
|
||||
private final Double max;
|
||||
private final boolean center;
|
||||
|
||||
public DoubleParser(String name, Double def, Double min, Double max, boolean center, Object ... completions) {
|
||||
super(name, def, completions);
|
||||
this.defType = null;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
public DoubleParser(String name, DefType type, Double min, Double max, boolean center) {
|
||||
super(name, null);
|
||||
this.defType = type;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
public Double parse(CommandEnvironment env, String input) {
|
||||
Double pre = this.defType != null && input.startsWith("~") ? this.getDefault(env) : null;
|
||||
input = pre != null ? input.substring(1) : input;
|
||||
double value;
|
||||
try {
|
||||
value = Double.parseDouble(input);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
throw new RunException("Ungültige Gleitkommazahl '%s'", input);
|
||||
}
|
||||
if(this.center && pre == null && input.indexOf('.') < 0)
|
||||
value += 0.5;
|
||||
if(this.min != null && value < this.min)
|
||||
if(this.max != null)
|
||||
throw new RunException("Die Zahl muss im Bereich %f .. %f liegen, habe %f", this.min, this.max, value);
|
||||
else
|
||||
throw new RunException("Die Zahl muss mindestens %f betragen, habe %f", this.min, value);
|
||||
if(this.max != null && value > this.max)
|
||||
if(this.min != null)
|
||||
throw new RunException("Die Zahl muss im Bereich %f .. %f liegen, habe %f", this.min, this.max, value);
|
||||
else
|
||||
throw new RunException("Die Zahl darf höchstens %f betragen, habe %f", this.max, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Double getDefault(CommandEnvironment env) {
|
||||
Position pos = this.defType == null ? null : env.getExecutor().getExecPos();
|
||||
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);
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return this.hasDefault() ? double.class : Double.class;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
BlockPos pos = this.defType == null ? null : env.getExecutor().getPointedPosition();
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Sets;
|
||||
import game.entity.Entity;
|
||||
import game.entity.EntityType;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.EntityRegistry;
|
||||
import game.network.Player;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class EntityListParser extends EntityParser {
|
||||
public EntityListParser(String name, boolean useSender, boolean livingOnly) {
|
||||
super(name, useSender, livingOnly);
|
||||
}
|
||||
|
||||
public Object parse(CommandEnvironment env, String input) {
|
||||
if(input.equals("**")) {
|
||||
List<Entity> list = Lists.newArrayList();
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
if(this.livingOnly) {
|
||||
for(Entity ent : world.getEntities()) {
|
||||
if(ent instanceof EntityLiving)
|
||||
list.add(ent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
list.addAll(world.getEntities());
|
||||
}
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new RunException(this.livingOnly ? "Keine lebendigen Objekte gefunden" : "Keine Objekte gefunden");
|
||||
return list;
|
||||
}
|
||||
else if(input.equals("*")) {
|
||||
List<Entity> list = Lists.newArrayList();
|
||||
for(Player plr : env.getServer().getPlayers()) {
|
||||
if(plr.getPresentEntity() != null)
|
||||
list.add(plr.getPresentEntity());
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new RunException("Keine Spieler gefunden");
|
||||
return list;
|
||||
}
|
||||
Set<Class<? extends Entity>> classes = Sets.newHashSet();
|
||||
Set<EntityType> types = Sets.newHashSet();
|
||||
Set<Entity> entities = Sets.newHashSet();
|
||||
Set<Class<? extends Entity>> nclasses = Sets.newHashSet();
|
||||
Set<EntityType> ntypes = Sets.newHashSet();
|
||||
Set<Entity> nentities = Sets.newHashSet();
|
||||
Boolean living = null;
|
||||
Boolean player = null;
|
||||
for(String tok : input.split(",", -1)) {
|
||||
boolean negate = tok.startsWith("!");
|
||||
tok = negate ? tok.substring(1) : tok;
|
||||
Class<? extends Entity> clazz = EntityRegistry.getEntityClass(tok);
|
||||
if(clazz != null) {
|
||||
if(classes.contains(clazz) || nclasses.contains(clazz))
|
||||
throw new RunException("Objekttyp %s mehrfach angegeben", EntityRegistry.getEntityName(EntityRegistry.getEntityString(clazz)));
|
||||
if(this.livingOnly && !EntityLiving.class.isAssignableFrom(clazz))
|
||||
throw new RunException("Objekttyp %s ist nicht lebendig", EntityRegistry.getEntityName(EntityRegistry.getEntityString(clazz)));
|
||||
(negate ? nclasses : classes).add(clazz);
|
||||
}
|
||||
else if(tok.equals("Player")) {
|
||||
if(player != null)
|
||||
throw new RunException("'Player' mehrfach angegeben");
|
||||
player = !negate;
|
||||
}
|
||||
else if(tok.equals("Living")) {
|
||||
if(living != null)
|
||||
throw new RunException("'Living' mehrfach angegeben");
|
||||
if(this.livingOnly)
|
||||
throw new RunException("Kann nicht 'Living' als Objekttypen angeben");
|
||||
living = !negate;
|
||||
}
|
||||
else {
|
||||
EntityType type = EntityType.getByName(tok);
|
||||
if(type != null) {
|
||||
if(types.contains(type) || ntypes.contains(type))
|
||||
throw new RunException("Objekttyp %s mehrfach angegeben", type.getDisplay());
|
||||
(negate ? ntypes : types).add(type);
|
||||
}
|
||||
else {
|
||||
Entity ent = (Entity)super.parse(env, tok);
|
||||
if(entities.contains(ent) || nentities.contains(ent))
|
||||
throw new RunException("Objekt '%s' mehrfach angegeben", tok);
|
||||
(negate ? nentities : entities).add(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Entity> filtered = Lists.newArrayList(entities);
|
||||
boolean negateOnly = (living == null && player == null && types.isEmpty() && classes.isEmpty() && entities.isEmpty());
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
for(Entity ent : world.getEntities()) {
|
||||
if((!this.livingOnly || ent instanceof EntityLiving) &&
|
||||
(negateOnly || (living != null && types.isEmpty() && classes.isEmpty() && living == (ent instanceof EntityLiving)) || (player != null && types.isEmpty() && classes.isEmpty() && player == ent.isPlayer()) || types.contains(ent.getType()) ||
|
||||
classes.contains(ent.getClass())) &&
|
||||
(living == null || living == (ent instanceof EntityLiving)) && (player == null || player == ent.isPlayer()) &&
|
||||
!ntypes.contains(ent.getType()) && !nclasses.contains(ent.getClass()) && !nentities.contains(ent) && !entities.contains(ent))
|
||||
filtered.add(ent);
|
||||
}
|
||||
}
|
||||
if(filtered.isEmpty())
|
||||
throw new RunException("Keine Objekte gefunden");
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
Entity entity = (Entity)super.getDefault(env);
|
||||
return entity == null ? null : Lists.newArrayList(entity);
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
Collection<String> comp = super.getCompletions(env);
|
||||
comp.add("*");
|
||||
for(Class<? extends Entity> clazz : EntityRegistry.getAllClasses()) {
|
||||
if(!this.livingOnly || EntityLiving.class.isAssignableFrom(clazz))
|
||||
comp.add(EntityRegistry.getEntityString(clazz));
|
||||
}
|
||||
for(EntityType type : EntityType.values()) {
|
||||
comp.add(type.getName());
|
||||
}
|
||||
Collections.addAll(comp, "Player", "Living", "**");
|
||||
return comp;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return List.class;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.entity.Entity;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class EntityParser extends PlayerEntityParser {
|
||||
protected final boolean livingOnly;
|
||||
|
||||
public EntityParser(String name, boolean useSender, boolean livingOnly) {
|
||||
super(name, useSender);
|
||||
this.livingOnly = livingOnly;
|
||||
}
|
||||
|
||||
public Object parse(CommandEnvironment env, String input) {
|
||||
Entity entity = null;
|
||||
if(input.startsWith("#")) {
|
||||
int id = -1;
|
||||
try {
|
||||
id = Integer.parseInt(input.substring(1));
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
if(id != -1) {
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
entity = world.getEntityByID(id);
|
||||
if(entity != null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
entity = (Entity)super.parse(env, input);
|
||||
}
|
||||
if(entity == null)
|
||||
throw new RunException("Objekt '%s' wurde nicht gefunden", input);
|
||||
else if(this.livingOnly && !(entity instanceof EntityLiving))
|
||||
throw new RunException("Objekt '%s' muss lebendig sein", input);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
return this.useSender && (this.livingOnly ? (env.getExecutor() instanceof EntityLiving) : (env.getExecutor() instanceof Entity)) ? env.getExecutor() : super.getDefault(env);
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
Entity target = env.getExecutor().getPointedEntity();
|
||||
List<String> comp = target == null || (this.livingOnly && !(target instanceof EntityLiving)) ? Lists.newArrayList() : Lists.newArrayList("#" + target.getId());
|
||||
comp.addAll(super.getCompletions(env));
|
||||
return comp;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return this.livingOnly ? EntityLiving.class : Entity.class;
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import game.collect.Maps;
|
||||
|
||||
public class EnumParser<T> extends DefaultingParser {
|
||||
private final Class<T> clazz;
|
||||
private final Map<String, T> lookup = Maps.newHashMap();
|
||||
private final T[] selections;
|
||||
|
||||
private static <T> String joinArgs(T[] iter) {
|
||||
StringBuilder sb = new StringBuilder("'");
|
||||
for(T obj : iter) {
|
||||
if(sb.length() > 1)
|
||||
sb.append("', '");
|
||||
sb.append(String.valueOf(obj));
|
||||
}
|
||||
return sb.append("'").toString();
|
||||
}
|
||||
|
||||
public EnumParser(String name, Class<T> clazz, T def, T ... selections) {
|
||||
super(name, def, selections);
|
||||
this.clazz = clazz;
|
||||
this.selections = selections;
|
||||
for(T o : selections) {
|
||||
this.lookup.put(o.toString().toLowerCase(), o);
|
||||
}
|
||||
}
|
||||
|
||||
public T parse(CommandEnvironment env, String input) {
|
||||
T value = this.lookup.get(input.toLowerCase());
|
||||
if(value != null)
|
||||
return value;
|
||||
int id = -1;
|
||||
try {
|
||||
id = Integer.parseInt(input);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
if(id < 0 || id >= this.selections.length)
|
||||
throw new RunException("Ungültige Auswahl '%s', muss eine von diesen Optionen sein: %s", input,
|
||||
joinArgs(this.selections));
|
||||
return this.selections[id];
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return this.clazz;
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Executable {
|
||||
// Object exec(ScriptEnvironment env, ScriptArgs args);
|
||||
Map<String, Parameter> getParameters();
|
||||
List<Parameter> getParamList();
|
||||
String getName();
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Position;
|
||||
|
||||
public interface Executor {
|
||||
void logConsole(String msg);
|
||||
String getExecId();
|
||||
String getExecName();
|
||||
Position getExecPos();
|
||||
Entity getPointedEntity();
|
||||
BlockPos getPointedPosition();
|
||||
|
||||
default void logConsole(String fmt, Object ... args) {
|
||||
this.logConsole(String.format(fmt, args));
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Position;
|
||||
import server.Server;
|
||||
|
||||
public class FixedExecutor implements Executor {
|
||||
private final Server server;
|
||||
private final String id;
|
||||
|
||||
private String name;
|
||||
private Position position;
|
||||
|
||||
public FixedExecutor(Server server, String id, String name, Position pos) {
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.position = pos;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setPosition(Position pos) {
|
||||
this.position = pos;
|
||||
}
|
||||
|
||||
public void logConsole(String msg) {
|
||||
this.server.logConsole(msg);
|
||||
}
|
||||
|
||||
public String getExecId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getExecName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Position getExecPos() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public Entity getPointedEntity() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public BlockPos getPointedPosition() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
public class IntParser extends DefaultingParser {
|
||||
private final Integer min;
|
||||
private final Integer max;
|
||||
private final boolean hex;
|
||||
|
||||
public IntParser(String name, boolean hex, Integer def, Integer min, Integer max, Object ... completions) {
|
||||
super(name, def, completions);
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.hex = hex;
|
||||
}
|
||||
|
||||
public Integer parse(CommandEnvironment env, String input) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt(input, this.hex ? 16 : 10);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
throw new RunException("Ungültige " + (this.hex ? "Hexadezimalzahl" : "Ganzzahl") + " '%s'", input);
|
||||
}
|
||||
if(this.min != null && value < this.min)
|
||||
if(this.max != null)
|
||||
throw new RunException("Die Zahl muss im Bereich %d .. %d liegen, habe %d", this.min, this.max, value);
|
||||
else
|
||||
throw new RunException("Die Zahl muss mindestens %d betragen, habe %d", this.min, value);
|
||||
if(this.max != null && value > this.max)
|
||||
if(this.min != null)
|
||||
throw new RunException("Die Zahl muss im Bereich %d .. %d liegen, habe %d", this.min, this.max, value);
|
||||
else
|
||||
throw new RunException("Die Zahl darf höchstens %d betragen, habe %d", this.max, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return this.hasDefault() ? int.class : Integer.class;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
public class LongParser extends DefaultingParser {
|
||||
private final Long min;
|
||||
private final Long max;
|
||||
|
||||
public LongParser(String name, Long def, Long min, Long max, Object ... completions) {
|
||||
super(name, def, completions);
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Long parse(CommandEnvironment env, String input) {
|
||||
long value;
|
||||
try {
|
||||
value = Long.parseLong(input);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
throw new RunException("Ungültige Ganzzahl '%s'", input);
|
||||
}
|
||||
if(this.min != null && value < this.min)
|
||||
if(this.max != null)
|
||||
throw new RunException("Die Zahl muss im Bereich %d .. %d liegen, habe %d", this.min, this.max, value);
|
||||
else
|
||||
throw new RunException("Die Zahl muss mindestens %d betragen, habe %d", this.min, value);
|
||||
if(this.max != null && value > this.max)
|
||||
if(this.min != null)
|
||||
throw new RunException("Die Zahl muss im Bereich %d .. %d liegen, habe %d", this.min, this.max, value);
|
||||
else
|
||||
throw new RunException("Die Zahl darf höchstens %d betragen, habe %d", this.max, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return this.hasDefault() ? long.class : Long.class;
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
public abstract class NonDefaultingParser extends CompletingParser {
|
||||
public NonDefaultingParser(String name, Object ... completions) {
|
||||
super(name, completions);
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Parameter {
|
||||
private final String name;
|
||||
private final char shortName;
|
||||
private final boolean required;
|
||||
private final int position;
|
||||
private final List<ArgumentParser> parsers;
|
||||
private final ArgCombiner<?> combiner;
|
||||
|
||||
public Parameter(String name, char shortName, int position, boolean required, List<ArgumentParser> parsers, ArgCombiner<?> combiner) {
|
||||
this.name = name;
|
||||
this.shortName = shortName;
|
||||
this.position = position;
|
||||
this.required = required;
|
||||
this.parsers = parsers;
|
||||
this.combiner = combiner;
|
||||
}
|
||||
|
||||
public boolean isPositional() {
|
||||
return this.position >= 0;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public List<ArgumentParser> getParsers() {
|
||||
return this.parsers;
|
||||
}
|
||||
|
||||
public ArgCombiner<?> getCombiner() {
|
||||
return this.combiner;
|
||||
}
|
||||
|
||||
public boolean isRequired() {
|
||||
return this.required;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean hasShortName() {
|
||||
return this.shortName != 0;
|
||||
}
|
||||
|
||||
public char getShortName() {
|
||||
return this.shortName;
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PatternReplacer {
|
||||
private final String variable;
|
||||
private final boolean matchAll;
|
||||
private final Pattern pattern;
|
||||
private final Function<String, String> function;
|
||||
|
||||
public PatternReplacer(String variable, boolean matchAll, Function<String, String> function) {
|
||||
this.variable = variable;
|
||||
this.matchAll = matchAll;
|
||||
this.pattern = Pattern.compile("\\$\\((" + Pattern.quote(variable) + (matchAll ? "[^\\)]*" : "") + ")\\)");
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
public void replaceVar(StringBuffer sb) {
|
||||
String str = sb.toString();
|
||||
sb.delete(0, sb.length());
|
||||
Matcher matcher = this.pattern.matcher(str);
|
||||
while(matcher.find()) {
|
||||
String orig = matcher.group(1);
|
||||
String rep = this.function.apply(orig);
|
||||
if(rep == null)
|
||||
throw new RunException("Variable '%s' konnte in diesem Kontext nicht ersetzt werden", orig);
|
||||
matcher.appendReplacement(sb, rep);
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
}
|
||||
|
||||
public String getVariable() {
|
||||
return this.variable;
|
||||
}
|
||||
|
||||
public boolean matchesAll() {
|
||||
return this.matchAll;
|
||||
}
|
||||
|
||||
public Pattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
public Function<String, String> getFunction() {
|
||||
return this.function;
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Sets;
|
||||
import game.entity.Entity;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.network.Player;
|
||||
|
||||
public class PlayerEntityListParser extends PlayerEntityParser {
|
||||
public PlayerEntityListParser(String name, boolean useSender) {
|
||||
super(name, useSender);
|
||||
}
|
||||
|
||||
public Object parse(CommandEnvironment env, String input) {
|
||||
if(input.equals("*")) {
|
||||
List<Entity> list = Lists.newArrayList();
|
||||
for(Player plr : env.getServer().getPlayers()) {
|
||||
if(plr.getPresentEntity() != null)
|
||||
list.add(plr.getPresentEntity());
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new RunException("Keine Spieler gefunden");
|
||||
return list;
|
||||
}
|
||||
Set<EntityNPC> set = Sets.newHashSet();
|
||||
for(String tok : input.split(",", -1)) {
|
||||
set.add((EntityNPC)super.parse(env, tok));
|
||||
}
|
||||
if(set.isEmpty())
|
||||
throw new RunException("Keine Spieler gefunden");
|
||||
return Lists.newArrayList(set);
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
EntityNPC entity = (EntityNPC)super.getDefault(env);
|
||||
return entity == null ? null : Lists.newArrayList(entity);
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
Collection<String> comp = super.getCompletions(env);
|
||||
comp.add("*");
|
||||
return comp;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return List.class;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.network.Player;
|
||||
|
||||
public class PlayerEntityParser extends PlayerParser {
|
||||
public PlayerEntityParser(String name, boolean useSender) {
|
||||
super(name, useSender);
|
||||
}
|
||||
|
||||
public Object parse(CommandEnvironment env, String input) {
|
||||
Player net = (Player)super.parse(env, input);
|
||||
EntityNPC entity = net.getPresentEntity();
|
||||
if(entity == null)
|
||||
throw new RunException("Spieler-Objekt von '%s' wurde nicht gefunden", input);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
Player net = (Player)super.getDefault(env);
|
||||
return net == null ? null : net.getPresentEntity();
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return EntityNPC.class;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Sets;
|
||||
import game.network.Player;
|
||||
|
||||
public class PlayerListParser extends PlayerParser {
|
||||
public PlayerListParser(String name, boolean useSender) {
|
||||
super(name, useSender);
|
||||
}
|
||||
|
||||
public Object parse(CommandEnvironment env, String input) {
|
||||
if(input.equals("*")) {
|
||||
if(env.getServer().getPlayers().isEmpty())
|
||||
throw new RunException("Keine Spieler gefunden");
|
||||
return Lists.newArrayList(env.getServer().getPlayers());
|
||||
}
|
||||
Set<Player> set = Sets.newHashSet();
|
||||
for(String tok : input.split(",", -1)) {
|
||||
set.add((Player)super.parse(env, tok));
|
||||
}
|
||||
if(set.isEmpty())
|
||||
throw new RunException("Keine Spieler gefunden");
|
||||
return Lists.newArrayList(set);
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
Player net = (Player)super.getDefault(env);
|
||||
return net == null ? null : Lists.newArrayList(net);
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
Collection<String> comp = super.getCompletions(env);
|
||||
comp.add("*");
|
||||
return comp;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return List.class;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import game.network.Player;
|
||||
|
||||
public class PlayerParser extends CompletingParser {
|
||||
protected final boolean useSender;
|
||||
|
||||
public PlayerParser(String name, boolean useSender) {
|
||||
super(name);
|
||||
this.useSender = useSender;
|
||||
}
|
||||
|
||||
public Object parse(CommandEnvironment env, String input) {
|
||||
Player net = env.getServer().getPlayer(input);
|
||||
if(net == null)
|
||||
throw new RunException("Spieler '%s' wurde nicht gefunden", input);
|
||||
return net;
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
return this.useSender && env.getExecutor() instanceof Player ? (Player)env.getExecutor() : null;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
return env.getServer().getAllUsernames();
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return Player.class;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
public class RunException extends RuntimeException {
|
||||
public RunException(String desc) {
|
||||
super(desc);
|
||||
this.setStackTrace(new StackTraceElement[0]);
|
||||
}
|
||||
|
||||
public RunException(String fmt, Object ... args) {
|
||||
super(String.format(fmt, args));
|
||||
this.setStackTrace(new StackTraceElement[0]);
|
||||
}
|
||||
|
||||
public RunException(Throwable cause, String desc) {
|
||||
super(desc, cause);
|
||||
this.setStackTrace(new StackTraceElement[0]);
|
||||
}
|
||||
|
||||
public RunException(Throwable cause, String fmt, Object ... args) {
|
||||
super(String.format(fmt, args), cause);
|
||||
this.setStackTrace(new StackTraceElement[0]);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
this.setStackTrace(new StackTraceElement[0]);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface StringCompleter {
|
||||
Collection<String> complete(CommandEnvironment env);
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import game.util.CharValidator;
|
||||
|
||||
public class StringParser extends DefaultingParser {
|
||||
private final boolean allowEmpty;
|
||||
private final Integer minLength;
|
||||
private final Integer maxLength;
|
||||
private final CharValidator validator;
|
||||
private final StringCompleter completer;
|
||||
|
||||
public StringParser(String name, String def, boolean allowEmpty, Integer minLength, Integer maxLength, CharValidator validator,
|
||||
Object ... completions) {
|
||||
super(name, def, completions);
|
||||
this.allowEmpty = allowEmpty;
|
||||
this.minLength = minLength;
|
||||
this.maxLength = maxLength;
|
||||
this.validator = validator;
|
||||
this.completer = null;
|
||||
}
|
||||
|
||||
public StringParser(String name, String def, boolean allowEmpty, Integer minLength, Integer maxLength, CharValidator validator,
|
||||
StringCompleter completer) {
|
||||
super(name, def);
|
||||
this.allowEmpty = allowEmpty;
|
||||
this.minLength = minLength;
|
||||
this.maxLength = maxLength;
|
||||
this.validator = validator;
|
||||
this.completer = completer;
|
||||
}
|
||||
|
||||
public String parse(CommandEnvironment env, String input) {
|
||||
if(!this.allowEmpty && input.isEmpty())
|
||||
throw new RunException("Die Zeichenkette darf nicht leer sein");
|
||||
if(this.minLength != null && input.length() < this.minLength)
|
||||
if(this.maxLength != null)
|
||||
throw new RunException("Die Zeichenkette muss zwischen %d .. %d Zeichen lang sein, habe %d ('%s')",
|
||||
this.minLength, this.maxLength, input.length(), input);
|
||||
else
|
||||
throw new RunException("Die Zeichenkette muss mindestens %d Zeichen lang sein, habe %d ('%s')",
|
||||
this.minLength, input.length(), input);
|
||||
if(this.maxLength != null && input.length() > this.maxLength)
|
||||
if(this.minLength != null)
|
||||
throw new RunException("Die Zeichenkette muss zwischen %d .. %d Zeichen lang sein, habe %d ('%s')",
|
||||
this.minLength, this.maxLength, input.length(), input);
|
||||
else
|
||||
throw new RunException("Die Zeichenkette darf höchstens %d Zeichen lang sein, habe %d ('%s')",
|
||||
this.maxLength, input.length(), input);
|
||||
if(this.validator != null && !this.validator.valid(input))
|
||||
throw new RunException("Die Zeichenkette '%s' enthält ungültige Zeichen", input);
|
||||
return input;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
return this.completer != null ? this.completer.complete(env) : super.getCompletions(env);
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import game.nbt.NBTException;
|
||||
import game.nbt.NBTParser;
|
||||
import game.nbt.NBTTagCompound;
|
||||
|
||||
public class TagParser extends DefaultingParser {
|
||||
public TagParser(String name, NBTTagCompound def, Object ... completions) {
|
||||
super(name, def, completions);
|
||||
}
|
||||
|
||||
public NBTTagCompound parse(CommandEnvironment env, String input) {
|
||||
NBTTagCompound value;
|
||||
try {
|
||||
value = NBTParser.parseTag(input);
|
||||
}
|
||||
catch(NBTException e) {
|
||||
throw new RunException(e, "Ungültiger NBT-Tag '%s'", input);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return NBTTagCompound.class;
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
public interface Variable {
|
||||
public String get();
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.dimension.Dimension;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class WorldParser extends DimensionParser {
|
||||
private final boolean loadedOnly;
|
||||
|
||||
public WorldParser(String name, boolean loadedOnly, boolean useSender) {
|
||||
super(name, useSender);
|
||||
this.loadedOnly = loadedOnly;
|
||||
}
|
||||
|
||||
public WorldServer parse(CommandEnvironment env, String input) {
|
||||
Dimension dim = (Dimension)super.parse(env, input);
|
||||
WorldServer world = this.loadedOnly ? env.getServer().getWorldNoLoad(dim.getDimensionId()) : env.getServer().getWorld(dim.getDimensionId());
|
||||
if(world == null)
|
||||
throw new RunException("Dimension '%s' ist nicht geladen", dim.getFormattedName(false));
|
||||
return world;
|
||||
}
|
||||
|
||||
public WorldServer getDefault(CommandEnvironment env) {
|
||||
Dimension dim = (Dimension)super.getDefault(env);
|
||||
return this.loadedOnly ? env.getServer().getWorldNoLoad(dim.getDimensionId()) : env.getServer().getWorld(dim.getDimensionId());
|
||||
// if(world == null)
|
||||
// throw new ScriptException("Dimension '%s' ist nicht geladen", dim.getFormattedName(false));
|
||||
// return world;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
if(this.loadedOnly) {
|
||||
List<String> loaded = Lists.newArrayList();
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
loaded.add(world.dimension.getDimensionName());
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
return super.getCompletions(env);
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return WorldServer.class;
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.RunException;
|
||||
import game.network.Player;
|
||||
|
||||
public class CommandAdmin extends Command {
|
||||
public CommandAdmin() {
|
||||
super("admin");
|
||||
|
||||
this.addPlayer("player", false);
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, Player player) {
|
||||
if(player == exec)
|
||||
throw new RunException("Du kannst nicht deinen eigenen Admin-Status erneut setzen");
|
||||
else if(player.getAdmin())
|
||||
throw new RunException("%s ist bereits ein Admin", player.getUser());
|
||||
player.setAdmin(true);
|
||||
player.logConsole("Du hast Administatorrechte von %s bekommen", exec.getExecId());
|
||||
exec.logConsole("%s ist jetzt ein Admin", player.getUser());
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Function;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.command.ArgumentParser;
|
||||
import game.command.CachedExecutable;
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.Parameter;
|
||||
import game.util.Util;
|
||||
|
||||
public class CommandHelp extends Command {
|
||||
public CommandHelp(CommandEnvironment env) {
|
||||
super("help");
|
||||
|
||||
this.setParamsOptional();
|
||||
this.addEnum("command", CachedExecutable.class, env.getExecutables().values());
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, CachedExecutable command) {
|
||||
if(command == null) {
|
||||
for(CachedExecutable cmd : env.getExecutables().values()) {
|
||||
this.exec(env, exec, cmd);
|
||||
}
|
||||
return;
|
||||
}
|
||||
List<String> list = Lists.newArrayList();
|
||||
for(Entry<String, Parameter> entry : command.getParameters().entrySet()) {
|
||||
Parameter param = entry.getValue();
|
||||
if(entry.getKey().length() == 1 && !param.isPositional() && param.hasShortName()) {
|
||||
list.add("-" + param.getShortName() + (param.getParsers().isEmpty() ? " (" + param.getName() + ")" : (param.getParsers().size() == 1 &&
|
||||
param.getParsers().get(0).getName().equals(param.getName()) ? " <" + param.getName() + ">" :
|
||||
" (" + param.getName() + ")" + Util.buildLines(" ", new Function<ArgumentParser, String>() {
|
||||
public String apply(ArgumentParser parser) {
|
||||
return "<" + parser.getName() + ">";
|
||||
}
|
||||
}, param.getParsers()))));
|
||||
}
|
||||
}
|
||||
for(Parameter param : command.getPositionals()) {
|
||||
list.add((param.isRequired() ? "<" : "[") + (param.getParsers().size() == 1 &&
|
||||
param.getParsers().get(0).getName().equals(param.getName()) ? param.getName() :
|
||||
"(" + param.getName() + ") " + Util.buildLines(" ", new Function<ArgumentParser, String>() {
|
||||
public String apply(ArgumentParser parser) {
|
||||
return "<" + parser.getName() + ">";
|
||||
}
|
||||
}, param.getParsers())) + (param.isRequired() ? ">" : "]"));
|
||||
}
|
||||
exec.logConsole("%s %s", command.getName(), Util.buildLines(" ", list));
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.RunException;
|
||||
import game.network.Player;
|
||||
|
||||
public class CommandKick extends Command {
|
||||
public CommandKick() {
|
||||
super("kick");
|
||||
|
||||
this.addPlayer("player", false);
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, Player player) {
|
||||
if(!(exec instanceof Player))
|
||||
throw new RunException("Dieser Befehl kann nur von Spielern ausgeführt werden");
|
||||
else if(player == exec)
|
||||
throw new RunException("Du kannst nicht dich nicht selbst vom Server werfen");
|
||||
else if(player.getAdmin())
|
||||
throw new RunException("%s ist ein Admin", player.getUser());
|
||||
player.disconnect();
|
||||
exec.logConsole("%s wurde vom Server geworfen", player.getUser());
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.packet.SPacketMessage;
|
||||
|
||||
public class CommandMessage extends Command {
|
||||
public CommandMessage() {
|
||||
super("message");
|
||||
|
||||
this.addString("message", false);
|
||||
|
||||
this.addEnum("type", 't', SPacketMessage.Type.CHAT, SPacketMessage.Type.class, SPacketMessage.Type.values());
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, String message, SPacketMessage.Type type) {
|
||||
env.getServer().sendPacket(new SPacketMessage(message, type));
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.potion.Potion;
|
||||
|
||||
public class CommandMilk extends Command {
|
||||
public CommandMilk() {
|
||||
super("milk");
|
||||
|
||||
this.addLivingEntityList("entities", true);
|
||||
this.setParamsOptional();
|
||||
List<Potion> potions = Lists.newArrayList();
|
||||
for(Potion potion : Potion.values()) {
|
||||
if(!potion.isInstant())
|
||||
potions.add(potion);
|
||||
}
|
||||
this.addEnum("type", Potion.class, potions);
|
||||
|
||||
this.addFlag("negative", 'n');
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, List<EntityLiving> entities, Potion type, boolean negative) {
|
||||
int done = 0;
|
||||
for(EntityLiving entity : entities) {
|
||||
if(type != null && entity.hasEffect(type)) {
|
||||
entity.removeEffect(type);
|
||||
exec.logConsole("%s von %s entfernt", type.getDisplay(), entity.getCommandName());
|
||||
done++;
|
||||
}
|
||||
else if(type == null && !entity.getEffects().isEmpty()) {
|
||||
entity.clearEffects(negative);
|
||||
exec.logConsole("Alle Effekte von %s entfernt", entity.getCommandName());
|
||||
done++;
|
||||
}
|
||||
}
|
||||
if(done > 1)
|
||||
exec.logConsole(type == null ? "Alle Effekte von %d Objekten entfernt" : "%d Effekte entfernt", entities.size());
|
||||
return done;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.RunException;
|
||||
import game.command.StringCompleter;
|
||||
import game.entity.Entity;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.network.Player;
|
||||
import game.world.Position;
|
||||
|
||||
public class CommandOfflinetp extends Command {
|
||||
public CommandOfflinetp() {
|
||||
super("offlinetp");
|
||||
|
||||
this.addString("user", false, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
return Lists.newArrayList(env.getServer().getUsers());
|
||||
}
|
||||
});
|
||||
|
||||
this.addEntityList("entities", 'e', true);
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, String user, List<Entity> entities) {
|
||||
Player player = env.getServer().getPlayer(user);
|
||||
Position pos = player != null ? (player.getPresentEntity() != null ? player.getPresentEntity().getPos() : null) : env.getServer().getOfflinePosition(user);
|
||||
if(pos == null)
|
||||
throw new RunException("Spieler '%s' konnte nicht gefunden werden", user);
|
||||
for(Entity entity : entities) {
|
||||
entity.teleport(pos);
|
||||
exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x, (int)pos.y, (int)pos.z, UniverseRegistry.getDimension(pos.dim).getFormattedName(false));
|
||||
}
|
||||
return entities.size();
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.potion.Potion;
|
||||
import game.potion.PotionEffect;
|
||||
|
||||
public class CommandPotion extends Command {
|
||||
public CommandPotion() {
|
||||
super("potion");
|
||||
|
||||
this.addLivingEntityList("entities", true);
|
||||
this.addEnum("type", Potion.class, Potion.values());
|
||||
this.setParamsOptional();
|
||||
this.addInt("duration", 0, 1000000, 1000000);
|
||||
this.addInt("strength", 1, 256, 1);
|
||||
|
||||
this.addFlag("particles", 'p');
|
||||
this.addFlag("ambient", 'a');
|
||||
this.addFlag("keep", 'k');
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, List<EntityLiving> entities, Potion type, int duration, int strength, boolean particles, boolean ambient, boolean keep) {
|
||||
int done = 0;
|
||||
for(EntityLiving entity : entities) {
|
||||
if(entity.isPotionApplicable(type)) {
|
||||
if(type.isInstant()) {
|
||||
type.onImpact(null, null, entity, strength - 1, 1.0);
|
||||
}
|
||||
else {
|
||||
PotionEffect effect = new PotionEffect(type, duration == 0 ? Integer.MAX_VALUE : (duration * 20), strength - 1, ambient, particles);
|
||||
if(!keep && entity.hasEffect(type))
|
||||
entity.removeEffect(type);
|
||||
entity.addEffect(effect);
|
||||
}
|
||||
if(type.isInstant() || duration == 0)
|
||||
exec.logConsole("%d * %s an %s gegeben", strength, type.getDisplay(), entity.getCommandName());
|
||||
else
|
||||
exec.logConsole("%d * %s für %d Sekunden an %s gegeben", strength, type.getDisplay(), duration, entity.getCommandName());
|
||||
done++;
|
||||
}
|
||||
}
|
||||
if(done > 1)
|
||||
exec.logConsole("%d Effekte vergeben", done);
|
||||
return done;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.entity.Entity;
|
||||
|
||||
public class CommandRemove extends Command {
|
||||
public CommandRemove() {
|
||||
super("remove");
|
||||
|
||||
this.addEntityList("entities", true);
|
||||
|
||||
this.addFlag("kill", 'k');
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, List<Entity> entities, boolean kill) {
|
||||
int done = 0;
|
||||
for(Entity entity : entities) {
|
||||
if(entity.isEntityAlive()) {
|
||||
if(kill || entity.isPlayer())
|
||||
entity.kill();
|
||||
else
|
||||
entity.setDead();
|
||||
exec.logConsole(kill ? "%s getötet" : "%s entfernt", entity.getCommandName());
|
||||
done++;
|
||||
}
|
||||
}
|
||||
if(done > 1)
|
||||
exec.logConsole(kill ? "%d Objekte getötet" : "%d Objekte entfernt", done);
|
||||
return done;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.RunException;
|
||||
import game.network.Player;
|
||||
|
||||
public class CommandRevoke extends Command {
|
||||
public CommandRevoke() {
|
||||
super("revoke");
|
||||
|
||||
this.addPlayer("player", false);
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, Player player) {
|
||||
if(exec instanceof Player)
|
||||
throw new RunException("Dieser Befehl kann nur der Konsole ausgeführt werden");
|
||||
// else if(player == exec)
|
||||
// throw new RunException("Du kannst nicht deinen eigenen Admin-Status entfernen");
|
||||
else if(!player.getAdmin())
|
||||
throw new RunException("%s ist kein Admin", player.getUser());
|
||||
player.setAdmin(false);
|
||||
player.logConsole("Der Host hat deine Administatorrechte entfernt");
|
||||
exec.logConsole("%s ist jetzt kein Admin mehr", player.getUser());
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Sets;
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.RunException;
|
||||
import game.entity.Entity;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.EntityRegistry;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.network.Player;
|
||||
import game.util.Util;
|
||||
import game.world.Vec3;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class CommandSpawn extends Command {
|
||||
public CommandSpawn() {
|
||||
super("spawn");
|
||||
|
||||
Set<String> names = Sets.newTreeSet();
|
||||
for(Class<? extends Entity> clazz : EntityRegistry.getAllClasses()) {
|
||||
names.add(EntityRegistry.getEntityString(clazz));
|
||||
}
|
||||
names.add("Lightning");
|
||||
this.addEnum("type", String.class, names);
|
||||
this.setParamsOptional();
|
||||
this.addVector("position", true, true);
|
||||
this.addWorld("dim", true);
|
||||
this.addTag("tag");
|
||||
|
||||
this.addFlag("noinit", 'n');
|
||||
this.addInt("count", 'c', 1, 1024, 1);
|
||||
this.addTag("postTag", 'p');
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, String type, Vec3 pos, WorldServer world, NBTTagCompound tag, boolean noinit, int count, NBTTagCompound postTag) {
|
||||
if(type.equalsIgnoreCase("Lightning")) {
|
||||
for(int z = 0; z < count; z++) {
|
||||
int color = 0xffffff;
|
||||
if(tag != null && tag.hasKey("color", 3))
|
||||
color = tag.getInteger("color");
|
||||
else if(tag != null && tag.hasKey("color", 8)) {
|
||||
try {
|
||||
color = Integer.parseUnsignedInt(tag.getString("color"), 16);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
world.strikeLightning(pos.xCoord, pos.yCoord, pos.zCoord, color,
|
||||
tag != null && tag.hasKey("damage", 3) ? tag.getInteger("damage") : 0, tag != null && tag.hasKey("fire", 1) && tag.getBoolean("fire"),
|
||||
exec instanceof Player && tag != null && tag.hasKey("summoned", 1) && tag.getBoolean("summoned") ? ((Player)exec).getPresentEntity() : null);
|
||||
}
|
||||
exec.logConsole("%sBlitz bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false));
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
List<String> spawned = Lists.newArrayList();
|
||||
for(int z = 0; z < count; z++) {
|
||||
Entity entity = EntityRegistry.createEntityByName(type, world);
|
||||
if(entity == null)
|
||||
throw new RunException("Objekt konnte nicht erzeugt werden");
|
||||
entity.setLocationAndAngles(pos.xCoord, pos.yCoord, pos.zCoord, world.rand.floatv() * 360.0f, 0.0f);
|
||||
if(tag != null) {
|
||||
NBTTagCompound ent = new NBTTagCompound();
|
||||
entity.writeToNBT(ent);
|
||||
ent.merge(tag);
|
||||
entity.readFromNBT(ent);
|
||||
}
|
||||
if(!noinit && (entity instanceof EntityLiving))
|
||||
((EntityLiving)entity).onInitialSpawn(null);
|
||||
world.spawnEntityInWorld(entity);
|
||||
if(postTag != null) {
|
||||
NBTTagCompound ent = new NBTTagCompound();
|
||||
entity.writeToNBT(ent);
|
||||
ent.merge(postTag);
|
||||
entity.readFromNBT(ent);
|
||||
}
|
||||
spawned.add("#" + entity.getId());
|
||||
}
|
||||
exec.logConsole("%s%s bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), EntityRegistry.getEntityName(type), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false));
|
||||
return Util.buildLines(",", spawned);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.dimension.Dimension;
|
||||
import game.entity.Entity;
|
||||
import game.world.Vec3;
|
||||
|
||||
public class CommandTele extends Command {
|
||||
public CommandTele() {
|
||||
super("tele");
|
||||
|
||||
this.addVector("position", false, true);
|
||||
this.setParamsOptional();
|
||||
this.addDimension("dim", true);
|
||||
this.addDouble("yaw", -180.0, 180.0);
|
||||
this.addDouble("pitch", -89.0, 89.0);
|
||||
|
||||
this.addEntityList("entities", 'e', true);
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, Vec3 position, Dimension dim, Double yaw, Double pitch, List<Entity> entities) {
|
||||
for(Entity entity : entities) {
|
||||
entity.teleport(position.xCoord, position.yCoord, position.zCoord, yaw == null ? entity.rotYaw : yaw.floatValue(), pitch == null ? entity.rotPitch : pitch.floatValue(), dim.getDimensionId());
|
||||
exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)position.xCoord, (int)position.yCoord, (int)position.zCoord, dim.getFormattedName(false));
|
||||
}
|
||||
return entities.size();
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.RunException;
|
||||
import game.dimension.Dimension;
|
||||
import game.item.ItemSpaceNavigator;
|
||||
import game.world.Position;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class CommandTime extends Command {
|
||||
public CommandTime() {
|
||||
super("time");
|
||||
|
||||
this.addString("time", false, "day", "night", "noon", "midnight", "sunrise", "sunset");
|
||||
|
||||
this.addFlag("absolute", 'a');
|
||||
}
|
||||
|
||||
private long parseInt(String input, long max) {
|
||||
long num;
|
||||
try {
|
||||
num = Long.parseLong(input);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
throw new RunException("'%s' ist keine gültige Zahl", input);
|
||||
}
|
||||
if(num < 0)
|
||||
throw new RunException("Die Zeit muss mindestens 0 betragen", num);
|
||||
else if(num > max)
|
||||
throw new RunException("Die Zeit darf höchstens %d betragen", num, max);
|
||||
return num;
|
||||
}
|
||||
|
||||
private long parseDayTime(Dimension dim, String arg) {
|
||||
if(arg.equalsIgnoreCase("sunrise"))
|
||||
return dim.getRotationalPeriod() / 6L;
|
||||
else if(arg.equalsIgnoreCase("day"))
|
||||
return dim.getRotationalPeriod() * 5L / 24L;
|
||||
else if(arg.equalsIgnoreCase("noon"))
|
||||
return dim.getRotationalPeriod() / 2L;
|
||||
else if(arg.equalsIgnoreCase("sunset"))
|
||||
return dim.getRotationalPeriod() * 5L / 6L;
|
||||
else if(arg.equalsIgnoreCase("night"))
|
||||
return dim.getRotationalPeriod() * 21L / 24L;
|
||||
else if(arg.equalsIgnoreCase("midnight"))
|
||||
return 0L;
|
||||
else if(arg.startsWith("@"))
|
||||
return this.parseInt(arg.substring(1), dim.getRotationalPeriod() - 1);
|
||||
else
|
||||
return -1L;
|
||||
}
|
||||
|
||||
private long parseTime(Dimension dim, String arg) {
|
||||
long t;
|
||||
if(arg.toLowerCase().endsWith("y"))
|
||||
t = dim.getOrbitalPeriod();
|
||||
else if(arg.toLowerCase().endsWith("d"))
|
||||
t = dim.getRotationalPeriod();
|
||||
else if(arg.toLowerCase().endsWith("h"))
|
||||
t = 1000L;
|
||||
else
|
||||
t = -1L;
|
||||
arg = t == -1L ? arg : arg.substring(0, arg.length() - 1);
|
||||
t = t < 1L ? 1L : t;
|
||||
return t * this.parseInt(arg, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, String timeStr, boolean absolute) {
|
||||
Position pos = exec.getExecPos();
|
||||
WorldServer world = pos == null ? env.getServer().getSpace() : env.getServer().getWorld(pos.dim);
|
||||
long time = absolute ? 0L : world.getDayTime();
|
||||
long fwd = parseDayTime(world.dimension, timeStr);
|
||||
if(fwd >= 0L) {
|
||||
if(absolute) {
|
||||
time += fwd;
|
||||
}
|
||||
else {
|
||||
time -= world.getDayTime() % world.dimension.getRotationalPeriod();
|
||||
time += fwd;
|
||||
time += time <= world.getDayTime() ? world.dimension.getRotationalPeriod() : 0L;
|
||||
}
|
||||
}
|
||||
else {
|
||||
time += parseTime(world.dimension, timeStr);
|
||||
}
|
||||
for(WorldServer dim : env.getServer().getWorlds()) {
|
||||
dim.setDayTime(time);
|
||||
dim.resetWeather();
|
||||
}
|
||||
exec.logConsole("Zeit auf %s gesetzt", ItemSpaceNavigator.formatImperialTime(world, false));
|
||||
return time;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.entity.Entity;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.world.Position;
|
||||
|
||||
public class CommandTp extends Command {
|
||||
public CommandTp() {
|
||||
super("tp");
|
||||
|
||||
this.addEntity("target", false);
|
||||
|
||||
this.addEntityList("entities", 'e', true);
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, Entity target, List<Entity> entities) {
|
||||
Position pos = target.getPos();
|
||||
for(Entity entity : entities) {
|
||||
entity.teleport(pos);
|
||||
exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x, (int)pos.y, (int)pos.z, UniverseRegistry.getDimension(pos.dim).getFormattedName(false));
|
||||
}
|
||||
return entities.size();
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.RunException;
|
||||
import game.command.StringCompleter;
|
||||
import game.entity.Entity;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.world.Position;
|
||||
|
||||
public class CommandWarp extends Command {
|
||||
public CommandWarp() {
|
||||
super("warp");
|
||||
|
||||
this.addString("warp", true, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
// List<String> warps = Lists.newArrayList("spawn");
|
||||
// warps.addAll(env.getServer().getWarps().keySet());
|
||||
return env.getServer().getWarps().keySet();
|
||||
}
|
||||
});
|
||||
|
||||
this.addEntityList("entities", 'e', true);
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, String warp, List<Entity> entities) {
|
||||
Position // pos;
|
||||
// if(warp.equals("spawn")) {
|
||||
// WorldServer world = env.getServer().getWorld(Config.spawnDim);
|
||||
// world = world == null ? env.getServer().getSpace() : world;
|
||||
// int y = Config.spawnY;
|
||||
// while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511)
|
||||
// y++;
|
||||
// pos = new Position(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d,
|
||||
// Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId());
|
||||
// }
|
||||
// else {
|
||||
pos = env.getServer().getWarps().get(warp);
|
||||
if(pos == null)
|
||||
throw new RunException("Warp '%s' existiert nicht", warp);
|
||||
else if(env.getServer().getWorld(pos.dim) == null)
|
||||
throw new RunException("Warp '%s' hat kein Level (%s)", warp, pos.dim);
|
||||
// }
|
||||
for(Entity entity : entities) {
|
||||
entity.teleport(pos);
|
||||
exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x, (int)pos.y, (int)pos.z, UniverseRegistry.getDimension(pos.dim).getFormattedName(false));
|
||||
}
|
||||
return entities.size();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.command.RunException;
|
||||
import game.world.Weather;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class CommandWeather extends Command {
|
||||
public CommandWeather() {
|
||||
super("weather");
|
||||
|
||||
this.addEnum("weather", Weather.class, Weather.values());
|
||||
this.setParamsOptional();
|
||||
this.addWorld("dim", true);
|
||||
|
||||
this.addFlag("transition", 't');
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, Weather weather, WorldServer world, boolean transition) {
|
||||
if(!world.dimension.getType().weather)
|
||||
throw new RunException("Welt %s hat kein Wetter", world.dimension.getFormattedName(false));
|
||||
else if(world.isExterminated())
|
||||
throw new RunException("Welt %s ist zerstört", world.dimension.getFormattedName(false));
|
||||
world.setWeather(weather);
|
||||
if(!transition)
|
||||
world.resetWeather();
|
||||
exec.logConsole("Wetter in %s zu %s geändert", world.dimension.getFormattedName(false), weather.getDisplay());
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package game.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.command.Command;
|
||||
import game.command.CommandEnvironment;
|
||||
import game.command.Executor;
|
||||
import game.entity.Entity;
|
||||
import game.world.BlockPos;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class CommandWorld extends Command {
|
||||
public CommandWorld() {
|
||||
super("world");
|
||||
|
||||
this.addWorld("dim", true);
|
||||
|
||||
this.addEntityList("entities", 'e', true);
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, WorldServer world, List<Entity> entities) {
|
||||
for(Entity entity : entities) {
|
||||
BlockPos pos = entity.getPosition();
|
||||
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();
|
||||
}
|
||||
entity.teleport(pos, world.dimension.getDimensionId());
|
||||
exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), world.dimension.getFormattedName(false));
|
||||
}
|
||||
return entities.size();
|
||||
}
|
||||
}
|
|
@ -83,8 +83,8 @@ import game.item.ItemTool;
|
|||
import game.model.ParticleType;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagList;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.Player;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.IPlayer;
|
||||
import game.packet.CPacketAction;
|
||||
import game.packet.CPacketBreak;
|
||||
import game.packet.CPacketInput;
|
||||
|
@ -198,8 +198,8 @@ public abstract class EntityNPC extends EntityLiving
|
|||
private int healTimer;
|
||||
private byte[] skin;
|
||||
|
||||
public Player connection;
|
||||
public ClientPlayer sendQueue;
|
||||
public IPlayer connection;
|
||||
public IClientPlayer sendQueue;
|
||||
protected Game gm;
|
||||
|
||||
public InventoryPlayer inventory;
|
||||
|
@ -399,13 +399,13 @@ public abstract class EntityNPC extends EntityLiving
|
|||
this.getEntityAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(this.getEntityAttribute(Attributes.MOVEMENT_SPEED).getBaseValue() / 3.0); // 0.10000000149011612D);
|
||||
}
|
||||
|
||||
public final void setServerPlayer(Player connection) {
|
||||
public final void setServerPlayer(IPlayer connection) {
|
||||
this.initPlayer();
|
||||
this.connection = connection;
|
||||
this.stepHeight = 0.0F;
|
||||
}
|
||||
|
||||
public final void setClientPlayer(Game gm, ClientPlayer connection) {
|
||||
public final void setClientPlayer(Game gm, IClientPlayer connection) {
|
||||
this.initPlayer();
|
||||
this.gm = gm;
|
||||
this.sendQueue = connection;
|
||||
|
|
|
@ -50,7 +50,7 @@ import game.material.Material;
|
|||
import game.model.ParticleType;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagList;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
import game.packet.S1BPacketEntityAttach;
|
||||
import game.packet.SPacketAnimation;
|
||||
import game.packet.SPacketCollectItem;
|
||||
|
@ -2462,7 +2462,7 @@ public abstract class EntityLiving extends Entity
|
|||
return;
|
||||
String msg;
|
||||
String kill;
|
||||
Player receiver = null;
|
||||
IPlayer receiver = null;
|
||||
if(this.combat.size() == 0) {
|
||||
msg = kill = natural ? String.format("%s starb", this.getColoredName(TextColor.LGRAY)) : null;
|
||||
}
|
||||
|
@ -2551,7 +2551,7 @@ public abstract class EntityLiving extends Entity
|
|||
if(receiver != null)
|
||||
receiver.addFeed(kill);
|
||||
if(forAll)
|
||||
for(Player player : ((WorldServer)this.worldObj).getServer().getPlayers()) {
|
||||
for(IPlayer player : ((WorldServer)this.worldObj).getServer().getIPlayers()) {
|
||||
if(player != receiver)
|
||||
player.addFeed(msg);
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
package game.network;
|
||||
|
||||
import client.Game;
|
||||
import game.packet.RPacketDisconnect;
|
||||
import game.packet.RPacketEnableCompression;
|
||||
import game.packet.RPacketLoginSuccess;
|
||||
|
||||
public class ClientLoginHandler extends NetHandler {
|
||||
private final Game gm;
|
||||
private final NetConnection networkManager;
|
||||
|
||||
public ClientLoginHandler(NetConnection conn, Game gmIn) {
|
||||
this.networkManager = conn;
|
||||
this.gm = gmIn;
|
||||
}
|
||||
|
||||
public void onDisconnect(String reason)
|
||||
{
|
||||
this.gm.disconnected(reason);
|
||||
}
|
||||
|
||||
public final void handleDisconnect(RPacketDisconnect packetIn)
|
||||
{
|
||||
this.networkManager.closeChannel(packetIn.getReason());
|
||||
}
|
||||
|
||||
public void handleLoginSuccess(RPacketLoginSuccess packetIn)
|
||||
{
|
||||
this.networkManager.setConnectionState(PacketRegistry.PLAY);
|
||||
this.networkManager.setNetHandler(new ClientPlayer(this.gm, this.networkManager));
|
||||
}
|
||||
|
||||
public final void handleEnableCompression(RPacketEnableCompression packetIn)
|
||||
{
|
||||
this.networkManager.setCompressionTreshold(packetIn.getValue());
|
||||
}
|
||||
|
||||
// public void handlePasswordRequest(RPacketPasswordRequest packetIn) {
|
||||
// if(this.server == null) {
|
||||
// this.networkManager.sendPacket(new LPacketPasswordResponse(this.user, "", ""));
|
||||
// }
|
||||
// else if((packetIn.getPasswordRequested() && this.server.pass.isEmpty()) ||
|
||||
// (packetIn.getPasswordProtected() && this.server.access.isEmpty())) {
|
||||
//// this.toChange = this.gm.getConnected();
|
||||
// this.accessRequired = packetIn.getPasswordProtected() && this.server.access.isEmpty();
|
||||
// this.passwordRequired = packetIn.getPasswordRequested() && this.server.pass.isEmpty();
|
||||
// this.networkManager.closeChannel("");
|
||||
// }
|
||||
// else {
|
||||
// this.networkManager.sendPacket(new LPacketPasswordResponse(this.user, this.access, this.pass));
|
||||
// }
|
||||
// }
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,45 +0,0 @@
|
|||
package game.network;
|
||||
|
||||
import game.init.Config;
|
||||
import game.packet.HPacketHandshake;
|
||||
import game.packet.RPacketDisconnect;
|
||||
import server.Server;
|
||||
|
||||
public class HandshakeHandler extends NetHandler
|
||||
{
|
||||
private final Server server;
|
||||
private final NetConnection networkManager;
|
||||
|
||||
public HandshakeHandler(Server serverIn, NetConnection netManager)
|
||||
{
|
||||
this.server = serverIn;
|
||||
this.networkManager = netManager;
|
||||
}
|
||||
|
||||
public void onDisconnect(String reason)
|
||||
{
|
||||
}
|
||||
|
||||
public void processHandshake(HPacketHandshake packetIn)
|
||||
{
|
||||
if(packetIn.getProtocolVersion() == 0) {
|
||||
this.networkManager.closeChannel("Inkompatibel!");
|
||||
return;
|
||||
}
|
||||
this.networkManager.setConnectionState(PacketRegistry.LOGIN);
|
||||
if (packetIn.getProtocolVersion() != Config.PROTOCOL)
|
||||
{
|
||||
String comp;
|
||||
if(packetIn.getProtocolVersion() < Config.PROTOCOL)
|
||||
comp = "Der Server nutzt eine neuere Version: " + Config.VERSION;
|
||||
else
|
||||
comp = "Der Server nutzt eine ältere Version: " + Config.VERSION;
|
||||
this.networkManager.sendPacket(new RPacketDisconnect(comp));
|
||||
this.networkManager.closeChannel(comp);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.networkManager.setNetHandler(new LoginHandler(this.server, this.networkManager));
|
||||
}
|
||||
}
|
||||
}
|
15
java/src/game/network/IClientLoginHandler.java
Normal file
15
java/src/game/network/IClientLoginHandler.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package game.network;
|
||||
|
||||
import game.packet.RPacketDisconnect;
|
||||
import game.packet.RPacketEnableCompression;
|
||||
import game.packet.RPacketLoginSuccess;
|
||||
|
||||
public interface IClientLoginHandler {
|
||||
|
||||
void handleDisconnect(RPacketDisconnect packetIn);
|
||||
|
||||
void handleLoginSuccess(RPacketLoginSuccess packetIn);
|
||||
|
||||
void handleEnableCompression(RPacketEnableCompression packetIn);
|
||||
|
||||
}
|
315
java/src/game/network/IClientPlayer.java
Normal file
315
java/src/game/network/IClientPlayer.java
Normal file
|
@ -0,0 +1,315 @@
|
|||
package game.network;
|
||||
|
||||
import game.packet.S14PacketEntity;
|
||||
import game.packet.S18PacketEntityTeleport;
|
||||
import game.packet.S19PacketEntityHeadLook;
|
||||
import game.packet.S1APacketEntityStatus;
|
||||
import game.packet.S1BPacketEntityAttach;
|
||||
import game.packet.S1CPacketEntityMetadata;
|
||||
import game.packet.S1DPacketEntityEffect;
|
||||
import game.packet.S1EPacketRemoveEntityEffect;
|
||||
import game.packet.S20PacketEntityProperties;
|
||||
import game.packet.S27PacketExplosion;
|
||||
import game.packet.S28PacketEffect;
|
||||
import game.packet.S29PacketSoundEffect;
|
||||
import game.packet.S2APacketParticles;
|
||||
import game.packet.S2BPacketChangeGameState;
|
||||
import game.packet.S2CPacketSpawnGlobalEntity;
|
||||
import game.packet.S2DPacketOpenWindow;
|
||||
import game.packet.S2EPacketCloseWindow;
|
||||
import game.packet.S2FPacketSetSlot;
|
||||
import game.packet.S30PacketWindowItems;
|
||||
import game.packet.S31PacketWindowProperty;
|
||||
import game.packet.S32PacketConfirmTransaction;
|
||||
import game.packet.S33PacketUpdateSign;
|
||||
import game.packet.S35PacketUpdateTileEntity;
|
||||
import game.packet.S36PacketSignEditorOpen;
|
||||
import game.packet.S38PacketPlayerListItem;
|
||||
import game.packet.S39PacketPlayerAbilities;
|
||||
import game.packet.S3APacketTabComplete;
|
||||
import game.packet.S43PacketUpdateEntityNBT;
|
||||
import game.packet.SPacketAnimation;
|
||||
import game.packet.SPacketBiomes;
|
||||
import game.packet.SPacketBlockAction;
|
||||
import game.packet.SPacketBlockBreakAnim;
|
||||
import game.packet.SPacketBlockChange;
|
||||
import game.packet.SPacketCamera;
|
||||
import game.packet.SPacketCharacterList;
|
||||
import game.packet.SPacketChunkData;
|
||||
import game.packet.SPacketCollectItem;
|
||||
import game.packet.SPacketDestroyEntities;
|
||||
import game.packet.SPacketDimensionName;
|
||||
import game.packet.SPacketDisconnect;
|
||||
import game.packet.SPacketEntityEquipment;
|
||||
import game.packet.SPacketEntityVelocity;
|
||||
import game.packet.SPacketHeldItemChange;
|
||||
import game.packet.SPacketJoinGame;
|
||||
import game.packet.SPacketKeepAlive;
|
||||
import game.packet.SPacketLoading;
|
||||
import game.packet.SPacketMapChunkBulk;
|
||||
import game.packet.SPacketMessage;
|
||||
import game.packet.SPacketMultiBlockChange;
|
||||
import game.packet.SPacketPlayerPosLook;
|
||||
import game.packet.SPacketRespawn;
|
||||
import game.packet.SPacketServerTick;
|
||||
import game.packet.SPacketSetExperience;
|
||||
import game.packet.SPacketSkin;
|
||||
import game.packet.SPacketSpawnMob;
|
||||
import game.packet.SPacketSpawnObject;
|
||||
import game.packet.SPacketSpawnPlayer;
|
||||
import game.packet.SPacketTimeUpdate;
|
||||
import game.packet.SPacketTrades;
|
||||
import game.packet.SPacketUpdateHealth;
|
||||
import game.packet.SPacketWorld;
|
||||
|
||||
public interface IClientPlayer {
|
||||
void addToSendQueue(Packet packet);
|
||||
|
||||
void handleJoinGame(SPacketJoinGame packetIn);
|
||||
|
||||
/**
|
||||
* Spawns an instance of the objecttype indicated by the packet and sets its position and momentum
|
||||
*/
|
||||
void handleSpawnObject(SPacketSpawnObject packetIn);
|
||||
|
||||
/**
|
||||
* Handles globally visible entities. Used in vanilla for lightning bolts
|
||||
*/
|
||||
void handleSpawnGlobalEntity(S2CPacketSpawnGlobalEntity packetIn);
|
||||
|
||||
/**
|
||||
* Sets the velocity of the specified entity to the specified value
|
||||
*/
|
||||
void handleEntityVelocity(SPacketEntityVelocity packetIn);
|
||||
|
||||
/**
|
||||
* Invoked when the server registers new proximate objects in your watchlist or when objects in your watchlist have
|
||||
* changed -> Registers any changes locally
|
||||
*/
|
||||
void handleEntityMetadata(S1CPacketEntityMetadata packetIn);
|
||||
|
||||
/**
|
||||
* Handles the creation of a nearby player entity, sets the position and held item
|
||||
*/
|
||||
void handleSpawnPlayer(SPacketSpawnPlayer packetIn);
|
||||
|
||||
/**
|
||||
* Updates an entity's position and rotation as specified by the packet
|
||||
*/
|
||||
void handleEntityTeleport(S18PacketEntityTeleport packetIn);
|
||||
|
||||
/**
|
||||
* Updates which hotbar slot of the player is currently selected
|
||||
*/
|
||||
void handleHeldItemChange(SPacketHeldItemChange packetIn);
|
||||
|
||||
/**
|
||||
* Updates the specified entity's position by the specified relative moment and absolute rotation. Note that
|
||||
* subclassing of the packet allows for the specification of a subset of this data (e.g. only rel. position, abs.
|
||||
* rotation or both).
|
||||
*/
|
||||
void handleEntityMovement(S14PacketEntity packetIn);
|
||||
|
||||
/**
|
||||
* Updates the direction in which the specified entity is looking, normally this head rotation is independent of the
|
||||
* rotation of the entity itself
|
||||
*/
|
||||
void handleEntityHeadLook(S19PacketEntityHeadLook packetIn);
|
||||
|
||||
/**
|
||||
* Locally eliminates the entities. Invoked by the server when the items are in fact destroyed, or the player is no
|
||||
* longer registered as required to monitor them. The latter happens when distance between the player and item
|
||||
* increases beyond a certain treshold (typically the viewing distance)
|
||||
*/
|
||||
void handleDestroyEntities(SPacketDestroyEntities packetIn);
|
||||
|
||||
/**
|
||||
* Handles changes in player positioning and rotation such as when travelling to a new dimension, (re)spawning,
|
||||
* mounting horses etc. Seems to immediately reply to the server with the clients post-processing perspective on the
|
||||
* player positioning
|
||||
*/
|
||||
void handlePlayerPosLook(SPacketPlayerPosLook packetIn);
|
||||
|
||||
/**
|
||||
* Received from the servers PlayerManager if between 1 and 64 blocks in a chunk are changed. If only one block
|
||||
* requires an update, the server sends S23PacketBlockChange and if 64 or more blocks are changed, the server sends
|
||||
* S21PacketChunkData
|
||||
*/
|
||||
void handleMultiBlockChange(SPacketMultiBlockChange packetIn);
|
||||
|
||||
/**
|
||||
* Updates the specified chunk with the supplied data, marks it for re-rendering and lighting recalculation
|
||||
*/
|
||||
void handleChunkData(SPacketChunkData packetIn);
|
||||
|
||||
void handleBiomes(SPacketBiomes packetIn);
|
||||
|
||||
/**
|
||||
* Updates the block and metadata and generates a blockupdate (and notify the clients)
|
||||
*/
|
||||
void handleBlockChange(SPacketBlockChange packetIn);
|
||||
|
||||
/**
|
||||
* Closes the network channel
|
||||
*/
|
||||
void handleDisconnect(SPacketDisconnect packetIn);
|
||||
|
||||
void handleCollectItem(SPacketCollectItem packetIn);
|
||||
|
||||
/**
|
||||
* Prints a chatmessage in the chat GUI
|
||||
*/
|
||||
void handleMessage(SPacketMessage packetIn);
|
||||
|
||||
void handleLoading(SPacketLoading packet);
|
||||
|
||||
/**
|
||||
* Renders a specified animation: Waking up a player, a living entity swinging its currently held item, being hurt
|
||||
* or receiving a critical hit by normal or magical means
|
||||
*/
|
||||
void handleAnimation(SPacketAnimation packetIn);
|
||||
|
||||
/**
|
||||
* Spawns the mob entity at the specified location, with the specified rotation, momentum and type. Updates the
|
||||
* entities Datawatchers with the entity metadata specified in the packet
|
||||
*/
|
||||
void handleSpawnMob(SPacketSpawnMob packetIn);
|
||||
|
||||
void handleTimeUpdate(SPacketTimeUpdate packetIn);
|
||||
|
||||
void handleServerTick(SPacketServerTick packet);
|
||||
|
||||
void handleEntityAttach(S1BPacketEntityAttach packetIn);
|
||||
|
||||
/**
|
||||
* Invokes the entities' handleUpdateHealth method which is implemented in LivingBase (hurt/death),
|
||||
* MinecartMobSpawner (spawn delay), FireworkRocket & MinecartTNT (explosion), IronGolem (throwing,...), Witch
|
||||
* (spawn particles), Zombie (villager transformation), Animal (breeding mode particles), Horse (breeding/smoke
|
||||
* particles), Sheep (...), Tameable (...), Villager (particles for breeding mode, angry and happy), Wolf (...)
|
||||
*/
|
||||
void handleEntityStatus(S1APacketEntityStatus packetIn);
|
||||
|
||||
void handleUpdateHealth(SPacketUpdateHealth packetIn);
|
||||
|
||||
void handleSetExperience(SPacketSetExperience packetIn);
|
||||
|
||||
void handleRespawn(SPacketRespawn packetIn);
|
||||
|
||||
/**
|
||||
* Initiates a new explosion (sound, particles, drop spawn) for the affected blocks indicated by the packet.
|
||||
*/
|
||||
void handleExplosion(S27PacketExplosion packetIn);
|
||||
|
||||
/**
|
||||
* Displays a GUI by ID. In order starting from id 0: Chest, Workbench, Furnace, Dispenser, Enchanting table,
|
||||
* Brewing stand, Villager merchant, Beacon, Anvil, Hopper, Dropper, Horse
|
||||
*/
|
||||
void handleOpenWindow(S2DPacketOpenWindow packetIn);
|
||||
|
||||
/**
|
||||
* Handles pickin up an ItemStack or dropping one in your inventory or an open container
|
||||
*/
|
||||
void handleSetSlot(S2FPacketSetSlot packetIn);
|
||||
|
||||
/**
|
||||
* Verifies that the server and client are synchronized with respect to the inventory/container opened by the player
|
||||
* and confirms if it is the case.
|
||||
*/
|
||||
void handleConfirmTransaction(S32PacketConfirmTransaction packetIn);
|
||||
|
||||
/**
|
||||
* Handles the placement of a specified ItemStack in a specified container/inventory slot
|
||||
*/
|
||||
void handleWindowItems(S30PacketWindowItems packetIn);
|
||||
|
||||
/**
|
||||
* Creates a sign in the specified location if it didn't exist and opens the GUI to edit its text
|
||||
*/
|
||||
void handleSignEditorOpen(S36PacketSignEditorOpen packetIn);
|
||||
|
||||
/**
|
||||
* Updates a specified sign with the specified text lines
|
||||
*/
|
||||
void handleUpdateSign(S33PacketUpdateSign packetIn);
|
||||
|
||||
/**
|
||||
* Updates the NBTTagCompound metadata of instances of the following entitytypes: Mob spawners, command blocks,
|
||||
* beacons, skulls, flowerpot
|
||||
*/
|
||||
void handleUpdateTileEntity(S35PacketUpdateTileEntity packetIn);
|
||||
|
||||
/**
|
||||
* Sets the progressbar of the opened window to the specified value
|
||||
*/
|
||||
void handleWindowProperty(S31PacketWindowProperty packetIn);
|
||||
|
||||
void handleEntityEquipment(SPacketEntityEquipment packetIn);
|
||||
|
||||
/**
|
||||
* Resets the ItemStack held in hand and closes the window that is opened
|
||||
*/
|
||||
void handleCloseWindow(S2EPacketCloseWindow packetIn);
|
||||
|
||||
/**
|
||||
* Triggers Block.onBlockEventReceived, which is implemented in BlockPistonBase for extension/retraction, BlockNote
|
||||
* for setting the instrument (including audiovisual feedback) and in BlockContainer to set the number of players
|
||||
* accessing a (Ender)Chest
|
||||
*/
|
||||
void handleBlockAction(SPacketBlockAction packetIn);
|
||||
|
||||
/**
|
||||
* Updates all registered IWorldAccess instances with destroyBlockInWorldPartially
|
||||
*/
|
||||
void handleBlockBreakAnim(SPacketBlockBreakAnim packetIn);
|
||||
|
||||
void handleMapChunkBulk(SPacketMapChunkBulk packetIn);
|
||||
|
||||
void handleChangeGameState(S2BPacketChangeGameState packetIn);
|
||||
|
||||
void handleEffect(S28PacketEffect packetIn);
|
||||
|
||||
void handleEntityEffect(S1DPacketEntityEffect packetIn);
|
||||
|
||||
void handleCamera(SPacketCamera packetIn);
|
||||
|
||||
void handleRemoveEntityEffect(S1EPacketRemoveEntityEffect packetIn);
|
||||
|
||||
void handlePlayerListItem(S38PacketPlayerListItem packetIn);
|
||||
|
||||
void handleCharacterList(SPacketCharacterList packet);
|
||||
|
||||
void handleKeepAlive(SPacketKeepAlive packetIn);
|
||||
|
||||
void handlePlayerAbilities(S39PacketPlayerAbilities packetIn);
|
||||
|
||||
/**
|
||||
* Displays the available command-completion options the server knows of
|
||||
*/
|
||||
void handleTabComplete(S3APacketTabComplete packetIn);
|
||||
|
||||
void handleSoundEffect(S29PacketSoundEffect packetIn);
|
||||
|
||||
void handleEntityNBT(S43PacketUpdateEntityNBT packetIn);
|
||||
|
||||
/**
|
||||
* Spawns a specified number of particles at the specified location with a randomized displacement according to
|
||||
* specified bounds
|
||||
*/
|
||||
void handleParticles(S2APacketParticles packetIn);
|
||||
|
||||
/**
|
||||
* Updates en entity's attributes and their respective modifiers, which are used for speed bonusses (player
|
||||
* sprinting, animals fleeing, baby speed), weapon/tool attackDamage, hostiles followRange randomization, zombie
|
||||
* maxHealth and knockback resistance as well as reinforcement spawning chance.
|
||||
*/
|
||||
void handleEntityProperties(S20PacketEntityProperties packetIn);
|
||||
|
||||
void handleSkin(SPacketSkin packetIn);
|
||||
|
||||
void handleTrades(SPacketTrades packetIn);
|
||||
|
||||
void handleWorld(SPacketWorld packetIn);
|
||||
|
||||
void handleDimName(SPacketDimensionName packetIn);
|
||||
|
||||
}
|
9
java/src/game/network/IHandshakeHandler.java
Normal file
9
java/src/game/network/IHandshakeHandler.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package game.network;
|
||||
|
||||
import game.packet.HPacketHandshake;
|
||||
|
||||
public interface IHandshakeHandler {
|
||||
|
||||
void processHandshake(HPacketHandshake packetIn);
|
||||
|
||||
}
|
9
java/src/game/network/ILoginHandler.java
Normal file
9
java/src/game/network/ILoginHandler.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package game.network;
|
||||
|
||||
import game.packet.LPacketPasswordResponse;
|
||||
|
||||
public interface ILoginHandler {
|
||||
|
||||
void processPasswordResponse(LPacketPasswordResponse packetIn);
|
||||
|
||||
}
|
173
java/src/game/network/IPlayer.java
Normal file
173
java/src/game/network/IPlayer.java
Normal file
|
@ -0,0 +1,173 @@
|
|||
package game.network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.entity.animal.EntityHorse;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.SoundEvent;
|
||||
import game.inventory.Container;
|
||||
import game.inventory.IInventory;
|
||||
import game.item.ItemStack;
|
||||
import game.packet.CPacketAction;
|
||||
import game.packet.CPacketBook;
|
||||
import game.packet.CPacketBreak;
|
||||
import game.packet.CPacketCheat;
|
||||
import game.packet.CPacketClick;
|
||||
import game.packet.CPacketComplete;
|
||||
import game.packet.CPacketInput;
|
||||
import game.packet.CPacketKeepAlive;
|
||||
import game.packet.CPacketMessage;
|
||||
import game.packet.CPacketPlace;
|
||||
import game.packet.CPacketPlayer;
|
||||
import game.packet.CPacketSign;
|
||||
import game.packet.CPacketSkin;
|
||||
import game.potion.PotionEffect;
|
||||
import game.tileentity.IInteractionObject;
|
||||
import game.tileentity.TileEntitySign;
|
||||
import game.util.CharValidator;
|
||||
import game.world.BlockPos;
|
||||
import game.world.ChunkPos;
|
||||
import game.world.PortalType;
|
||||
|
||||
public interface IPlayer {
|
||||
public static class UserValidator implements CharValidator {
|
||||
public boolean valid(char ch) {
|
||||
return (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '_' || ch == '-';
|
||||
}
|
||||
}
|
||||
|
||||
public static class NickValidator implements CharValidator {
|
||||
public boolean valid(char ch) {
|
||||
return (ch <= 0xff && Character.isLetterOrDigit(ch)) || (ch >= 32 && ch < 126);
|
||||
}
|
||||
}
|
||||
|
||||
public static int MAX_USER_LENGTH = 16;
|
||||
public static int MAX_NICK_LENGTH = 32;
|
||||
public static int MAX_PASS_LENGTH = 64;
|
||||
public static int MAX_CMD_LENGTH = 1024;
|
||||
public static int MAX_INFO_LENGTH = 4096;
|
||||
public static CharValidator VALID_USER = new IPlayer.UserValidator();
|
||||
public static CharValidator VALID_NICK = new IPlayer.NickValidator();
|
||||
|
||||
public static boolean isValidNick(String user) {
|
||||
return VALID_NICK.valid(user);
|
||||
}
|
||||
|
||||
public static boolean isValidUser(String user) {
|
||||
return VALID_USER.valid(user);
|
||||
}
|
||||
|
||||
void onEntityDeath();
|
||||
|
||||
boolean isInEditor();
|
||||
|
||||
EntityNPC getPresentEntity();
|
||||
|
||||
String getUser();
|
||||
|
||||
int getLatency();
|
||||
|
||||
boolean isAdmin();
|
||||
|
||||
void addToPlayerScore(EntityLiving entity);
|
||||
|
||||
void displayTradeGui(EntityNPC npc);
|
||||
|
||||
void setPlayerHealthUpdated();
|
||||
|
||||
void removeEntity(Entity p_152339_1_);
|
||||
|
||||
void sendPlayerAbilities();
|
||||
|
||||
void addFeed(String msg);
|
||||
|
||||
void addHotbar(String msg);
|
||||
|
||||
void addHotbar(String format, Object... args);
|
||||
|
||||
void sendThrowMessage(ItemStack stack);
|
||||
|
||||
void resetLastExperience();
|
||||
|
||||
void travelToDimension(int dimensionId, BlockPos pos, float yaw, float pitch, PortalType portal);
|
||||
|
||||
void teleport(double x, double y, double z, float yaw, float pitch, int dimension);
|
||||
|
||||
void onItemPickup(Entity entity, int amount);
|
||||
|
||||
void mountEntity(Entity entityIn);
|
||||
|
||||
void openEditSign(TileEntitySign signTile);
|
||||
|
||||
void displayGui(IInteractionObject guiOwner);
|
||||
|
||||
void displayGUIChest(IInventory chestInventory);
|
||||
|
||||
void displayGUIHorse(EntityHorse horse, IInventory horseInventory);
|
||||
|
||||
void closeScreen();
|
||||
|
||||
void onItemUseFinish();
|
||||
|
||||
void onNewEffect(PotionEffect id);
|
||||
|
||||
void onChangedEffect(PotionEffect id, boolean added);
|
||||
|
||||
void onFinishedEffect(PotionEffect effect);
|
||||
|
||||
void setPositionAndUpdate(double x, double y, double z);
|
||||
|
||||
void onCriticalHit(Entity entityHit);
|
||||
|
||||
void onEnchantmentCritical(Entity entityHit);
|
||||
|
||||
void updateEffectMeta();
|
||||
|
||||
void playSound(SoundEvent name, float volume);
|
||||
|
||||
void sendContainerToPlayer(Container container);
|
||||
|
||||
void updateEntity();
|
||||
|
||||
void setSelection(boolean primary, BlockPos pos);
|
||||
|
||||
void setSelectMode();
|
||||
|
||||
void sendPacket(Packet packet);
|
||||
|
||||
void setPlayerLocation(double x, double y, double z, float yaw, float pitch);
|
||||
|
||||
void processKeepAlive(CPacketKeepAlive packetIn);
|
||||
|
||||
void processMessage(CPacketMessage packetIn);
|
||||
|
||||
void processComplete(CPacketComplete packetIn);
|
||||
|
||||
void processPlayer(CPacketPlayer packetIn);
|
||||
|
||||
void processBreak(CPacketBreak packetIn);
|
||||
|
||||
void processPlace(CPacketPlace packetIn);
|
||||
|
||||
void processAction(CPacketAction packetIn);
|
||||
|
||||
void processInput(CPacketInput packetIn);
|
||||
|
||||
void processClick(CPacketClick packetIn);
|
||||
|
||||
void processCheat(CPacketCheat packetIn);
|
||||
|
||||
void processSign(CPacketSign packetIn);
|
||||
|
||||
void processSkin(CPacketSkin packetIn);
|
||||
|
||||
void processBook(CPacketBook packetIn);
|
||||
|
||||
List<ChunkPos> getLoadedChunkList();
|
||||
double getManagedX();
|
||||
double getManagedZ();
|
||||
void setManagedPos(double x, double z);
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
package game.network;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.init.Config;
|
||||
import game.log.Log;
|
||||
import game.packet.LPacketPasswordResponse;
|
||||
import game.packet.RPacketDisconnect;
|
||||
import server.Server;
|
||||
|
||||
public class LoginHandler extends NetHandler
|
||||
{
|
||||
private static enum LoginState {
|
||||
PASSWORD, READY_TO_ACCEPT, ACCEPTED;
|
||||
}
|
||||
|
||||
private final Server server;
|
||||
public final NetConnection netManager;
|
||||
|
||||
private LoginState state = LoginState.PASSWORD;
|
||||
private int timer;
|
||||
private String loginUser;
|
||||
private String loginPass;
|
||||
|
||||
public LoginHandler(Server server, NetConnection netManager)
|
||||
{
|
||||
this.netManager = netManager;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void closeConnection(String reason)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.JNI.info("Trenne " + this.getConnectionInfo());
|
||||
this.netManager.sendPacket(new RPacketDisconnect(reason));
|
||||
this.netManager.closeChannel(reason);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.JNI.error(exception, "Fehler beim Trennen des Spielers beim Login");
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisconnect(String reason)
|
||||
{
|
||||
Log.JNI.info(this.getConnectionInfo() + " wurde beim Login getrennt: " + TextColor.stripCodes(reason));
|
||||
}
|
||||
|
||||
public String getConnectionInfo()
|
||||
{
|
||||
return this.loginUser != null ? (this.loginUser + " (" + this.netManager.getCutAddress()
|
||||
+ ")") : this.netManager.getCutAddress();
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
if(this.state == LoginState.READY_TO_ACCEPT)
|
||||
this.tryAcceptPlayer();
|
||||
// else if (this.currentLoginState == LoginState.DELAY_ACCEPT)
|
||||
// {
|
||||
// if (this.server.getPlayer(this.loginUser) == null)
|
||||
// {
|
||||
// this.currentLoginState = LoginState.ACCEPTED;
|
||||
// this.server.addPlayer(this.networkManager, this.loginUser);
|
||||
// }
|
||||
// }
|
||||
if(this.timer++ == 600)
|
||||
this.closeConnection("Anmeldung dauerte zu lange");
|
||||
}
|
||||
|
||||
private void tryAcceptPlayer()
|
||||
{
|
||||
if(this.server.getPlayer(this.loginUser) != null) {
|
||||
this.closeConnection("Nutzername '" + this.loginUser + "' ist bereits vergeben.");
|
||||
return;
|
||||
}
|
||||
// if (this.server.getPlayer(this.loginUser) != null)
|
||||
// {
|
||||
// this.closeConnection("Nutzername '" + this.loginUser + "' ist bereits vergeben.");
|
||||
// return;
|
||||
//// this.currentLoginState = LoginState.DELAY_ACCEPT;
|
||||
//// player.netHandler.kick("Du hast dich von einen anderen Ort verbunden");
|
||||
// }
|
||||
// this.networkManager.sendPacket(new RPacketLoginSuccess());
|
||||
String kick = this.server.addPlayer(this.netManager, this.loginUser, this.loginPass);
|
||||
if(kick != null)
|
||||
this.closeConnection(kick);
|
||||
else
|
||||
this.state = LoginState.ACCEPTED;
|
||||
}
|
||||
|
||||
// public void processLoginStart(LPacketLoginStart packetIn)
|
||||
// {
|
||||
// if(this.state != LoginState.HELLO)
|
||||
// throw new IllegalStateException("Unerwartetes Start-Paket");
|
||||
// if(!this.netManager.isLocalChannel()) {
|
||||
// this.state = LoginState.PASSWORD;
|
||||
// this.netManager.sendPacket(new RPacketPasswordRequest()); // !Config.password.isEmpty(), Config.auth
|
||||
// }
|
||||
// }
|
||||
|
||||
public void processPasswordResponse(LPacketPasswordResponse packetIn) {
|
||||
if(this.state != LoginState.PASSWORD)
|
||||
throw new IllegalStateException("Unerwartetes Passwort-Paket");
|
||||
this.loginUser = packetIn.getUser();
|
||||
this.loginPass = packetIn.getPassword();
|
||||
if(this.loginUser.isEmpty() || !Player.isValidUser(this.loginUser))
|
||||
throw new IllegalStateException("Ungültiger Nutzername!");
|
||||
// if(!this.checkConnect(packetIn.getAccess()))
|
||||
// return;
|
||||
if(!Config.password.isEmpty() && !Config.password.equals(packetIn.getAccess())) {
|
||||
this.closeConnection("Falsches Zugangspasswort");
|
||||
return;
|
||||
}
|
||||
this.state = LoginState.READY_TO_ACCEPT;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import java.util.regex.Pattern;
|
|||
import game.future.ThreadFactoryBuilder;
|
||||
import game.log.Log;
|
||||
import game.network.NetHandler.ThreadQuickExitException;
|
||||
import game.util.LazyLoadBase;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelException;
|
||||
|
|
|
@ -19,7 +19,7 @@ public abstract class NetHandler {
|
|||
public void update() {
|
||||
}
|
||||
|
||||
public static <T extends NetHandler> void checkThread(final Packet<T> packet, final T handler, IThreadListener listener)
|
||||
public static <T> void checkThread(final Packet<T> packet, final T handler, IThreadListener listener)
|
||||
throws ThreadQuickExitException {
|
||||
if(!listener.isMainThread()) {
|
||||
listener.schedule(new Runnable() {
|
||||
|
@ -31,7 +31,7 @@ public abstract class NetHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static <T extends NetHandler> void checkThread(final Packet<T> packet, final T handler, IThreadListener listener, Object check)
|
||||
public static <T> void checkThread(final Packet<T> packet, final T handler, IThreadListener listener, Object check)
|
||||
throws ThreadQuickExitException {
|
||||
if(check == null && listener.isMainThread()) {
|
||||
throw EXIT;
|
||||
|
|
|
@ -2,7 +2,7 @@ package game.network;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Packet<T extends NetHandler>
|
||||
public interface Packet<T>
|
||||
{
|
||||
void readPacketData(PacketBuffer buf) throws IOException;
|
||||
void writePacketData(PacketBuffer buf) throws IOException;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,11 +2,10 @@ package game.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.NetHandler;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public abstract class APacketEmpty<T extends NetHandler> implements Packet<T> {
|
||||
public abstract class APacketEmpty<T> implements Packet<T> {
|
||||
public final void readPacketData(PacketBuffer buf) throws IOException {
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,10 @@ package game.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.NetHandler;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public abstract class APacketVarInt<T extends NetHandler> implements Packet<T> {
|
||||
public abstract class APacketVarInt<T> implements Packet<T> {
|
||||
private int value;
|
||||
|
||||
public APacketVarInt() {
|
||||
|
|
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketAction implements Packet<Player>
|
||||
public class CPacketAction implements Packet<IPlayer>
|
||||
{
|
||||
private Action action;
|
||||
private int auxData;
|
||||
|
@ -38,7 +38,7 @@ public class CPacketAction implements Packet<Player>
|
|||
buf.writeVarIntToBuffer(this.auxData);
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processAction(this);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketBook implements Packet<Player>
|
||||
public class CPacketBook implements Packet<IPlayer>
|
||||
{
|
||||
private String[] pages;
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class CPacketBook implements Packet<Player>
|
|||
}
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processBook(this);
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import java.io.IOException;
|
|||
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
|
||||
public class CPacketBreak implements Packet<Player>
|
||||
public class CPacketBreak implements Packet<IPlayer>
|
||||
{
|
||||
private BlockPos position;
|
||||
private Facing facing;
|
||||
|
@ -39,7 +39,7 @@ public class CPacketBreak implements Packet<Player>
|
|||
buf.writeByte(this.facing.getIndex());
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processBreak(this);
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import java.io.IOException;
|
|||
import game.item.ItemStack;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketCheat implements Packet<Player>
|
||||
public class CPacketCheat implements Packet<IPlayer>
|
||||
{
|
||||
private ItemStack stack;
|
||||
private int slot;
|
||||
|
@ -23,7 +23,7 @@ public class CPacketCheat implements Packet<Player>
|
|||
this.stack.stackSize = full ? this.stack.getMaxStackSize() : 1;
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processCheat(this);
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import java.io.IOException;
|
|||
import game.item.ItemStack;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketClick implements Packet<Player>
|
||||
public class CPacketClick implements Packet<IPlayer>
|
||||
{
|
||||
/** The id of the window which was clicked. 0 for player inventory. */
|
||||
private int windowId;
|
||||
|
@ -41,7 +41,7 @@ public class CPacketClick implements Packet<Player>
|
|||
this.mode = mode;
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processClick(this);
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import java.io.IOException;
|
|||
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
import game.world.BlockPos;
|
||||
|
||||
public class CPacketComplete implements Packet<Player>
|
||||
public class CPacketComplete implements Packet<IPlayer>
|
||||
{
|
||||
private String message;
|
||||
private int entityId;
|
||||
|
@ -41,7 +41,7 @@ public class CPacketComplete implements Packet<Player>
|
|||
buf.writeBlockPos(this.position);
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processComplete(this);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketInput implements Packet<Player>
|
||||
public class CPacketInput implements Packet<IPlayer>
|
||||
{
|
||||
private float strafeSpeed;
|
||||
private float forwardSpeed;
|
||||
|
@ -53,7 +53,7 @@ public class CPacketInput implements Packet<Player>
|
|||
buf.writeByte(b0);
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processInput(this);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package game.packet;
|
||||
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketKeepAlive extends APacketVarInt<Player>
|
||||
public class CPacketKeepAlive extends APacketVarInt<IPlayer>
|
||||
{
|
||||
public CPacketKeepAlive()
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ public class CPacketKeepAlive extends APacketVarInt<Player>
|
|||
super(key);
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processKeepAlive(this);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketMessage implements Packet<Player>
|
||||
public class CPacketMessage implements Packet<IPlayer>
|
||||
{
|
||||
private Type type;
|
||||
private String message;
|
||||
|
@ -33,7 +33,7 @@ public class CPacketMessage implements Packet<Player>
|
|||
buf.writeString(this.message);
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processMessage(this);
|
||||
}
|
||||
|
@ -49,10 +49,10 @@ public class CPacketMessage implements Packet<Player>
|
|||
}
|
||||
|
||||
public static enum Type {
|
||||
COMMAND(Player.MAX_CMD_LENGTH),
|
||||
CHAT(Player.MAX_CMD_LENGTH),
|
||||
DISPLAY(Player.MAX_NICK_LENGTH),
|
||||
INFO(Player.MAX_INFO_LENGTH);
|
||||
COMMAND(IPlayer.MAX_CMD_LENGTH),
|
||||
CHAT(IPlayer.MAX_CMD_LENGTH),
|
||||
DISPLAY(IPlayer.MAX_NICK_LENGTH),
|
||||
INFO(IPlayer.MAX_INFO_LENGTH);
|
||||
// , ITEM(30);
|
||||
|
||||
private final int length;
|
||||
|
|
|
@ -5,10 +5,10 @@ import java.io.IOException;
|
|||
import game.item.ItemStack;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
import game.world.BlockPos;
|
||||
|
||||
public class CPacketPlace implements Packet<Player>
|
||||
public class CPacketPlace implements Packet<IPlayer>
|
||||
{
|
||||
private static final BlockPos DUMMY_POS = new BlockPos(-1, -1, -1);
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class CPacketPlace implements Packet<Player>
|
|||
buf.writeByte((int)(this.facingZ * 16.0F));
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processPlace(this);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketPlayer implements Packet<Player>
|
||||
public class CPacketPlayer implements Packet<IPlayer>
|
||||
{
|
||||
protected double x;
|
||||
protected double y;
|
||||
|
@ -26,7 +26,7 @@ public class CPacketPlayer implements Packet<Player>
|
|||
this.onGround = isOnGround;
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processPlayer(this);
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import java.io.IOException;
|
|||
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
import game.world.BlockPos;
|
||||
|
||||
public class CPacketSign implements Packet<Player>
|
||||
public class CPacketSign implements Packet<IPlayer>
|
||||
{
|
||||
private BlockPos pos;
|
||||
private String[] lines;
|
||||
|
@ -48,7 +48,7 @@ public class CPacketSign implements Packet<Player>
|
|||
}
|
||||
}
|
||||
|
||||
public void processPacket(Player handler)
|
||||
public void processPacket(IPlayer handler)
|
||||
{
|
||||
handler.processSign(this);
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ import client.renderer.texture.EntityTexManager;
|
|||
import game.init.SpeciesRegistry.ModelType;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
import game.network.IPlayer;
|
||||
|
||||
public class CPacketSkin implements Packet<Player> {
|
||||
public class CPacketSkin implements Packet<IPlayer> {
|
||||
private byte[] texture;
|
||||
private String character;
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class CPacketSkin implements Packet<Player> {
|
|||
buf.writeByteArray(this.texture);
|
||||
}
|
||||
|
||||
public void processPacket(Player handler) {
|
||||
public void processPacket(IPlayer handler) {
|
||||
handler.processSkin(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ package game.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.HandshakeHandler;
|
||||
import game.network.IHandshakeHandler;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class HPacketHandshake implements Packet<HandshakeHandler> {
|
||||
public class HPacketHandshake implements Packet<IHandshakeHandler> {
|
||||
private int protocol;
|
||||
|
||||
public HPacketHandshake() {
|
||||
|
@ -30,7 +30,7 @@ public class HPacketHandshake implements Packet<HandshakeHandler> {
|
|||
buf.writeVarIntToBuffer(this.protocol);
|
||||
}
|
||||
|
||||
public void processPacket(HandshakeHandler handler) {
|
||||
public void processPacket(IHandshakeHandler handler) {
|
||||
handler.processHandshake(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ package game.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.LoginHandler;
|
||||
import game.network.IPlayer;
|
||||
import game.network.ILoginHandler;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.network.Player;
|
||||
|
||||
public class LPacketPasswordResponse implements Packet<LoginHandler>
|
||||
public class LPacketPasswordResponse implements Packet<ILoginHandler>
|
||||
{
|
||||
private String user;
|
||||
private String access;
|
||||
|
@ -29,9 +29,9 @@ public class LPacketPasswordResponse implements Packet<LoginHandler>
|
|||
*/
|
||||
public void readPacketData(PacketBuffer buf) throws IOException
|
||||
{
|
||||
this.user = buf.readStringFromBuffer(Player.MAX_USER_LENGTH);
|
||||
this.access = buf.readStringFromBuffer(Player.MAX_PASS_LENGTH);
|
||||
this.password = buf.readStringFromBuffer(Player.MAX_PASS_LENGTH);
|
||||
this.user = buf.readStringFromBuffer(IPlayer.MAX_USER_LENGTH);
|
||||
this.access = buf.readStringFromBuffer(IPlayer.MAX_PASS_LENGTH);
|
||||
this.password = buf.readStringFromBuffer(IPlayer.MAX_PASS_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,7 +47,7 @@ public class LPacketPasswordResponse implements Packet<LoginHandler>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(LoginHandler handler)
|
||||
public void processPacket(ILoginHandler handler)
|
||||
{
|
||||
handler.processPasswordResponse(this);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ package game.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.ClientLoginHandler;
|
||||
import game.network.IClientLoginHandler;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class RPacketDisconnect implements Packet<ClientLoginHandler>
|
||||
public class RPacketDisconnect implements Packet<IClientLoginHandler>
|
||||
{
|
||||
private String reason;
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class RPacketDisconnect implements Packet<ClientLoginHandler>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientLoginHandler handler)
|
||||
public void processPacket(IClientLoginHandler handler)
|
||||
{
|
||||
handler.handleDisconnect(this);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package game.packet;
|
||||
|
||||
import game.network.ClientLoginHandler;
|
||||
import game.network.IClientLoginHandler;
|
||||
|
||||
public class RPacketEnableCompression extends APacketVarInt<ClientLoginHandler>
|
||||
public class RPacketEnableCompression extends APacketVarInt<IClientLoginHandler>
|
||||
{
|
||||
public RPacketEnableCompression()
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ public class RPacketEnableCompression extends APacketVarInt<ClientLoginHandler>
|
|||
super(comp);
|
||||
}
|
||||
|
||||
public void processPacket(ClientLoginHandler handler)
|
||||
public void processPacket(IClientLoginHandler handler)
|
||||
{
|
||||
handler.handleEnableCompression(this);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package game.packet;
|
||||
|
||||
import game.network.ClientLoginHandler;
|
||||
import game.network.IClientLoginHandler;
|
||||
|
||||
public class RPacketLoginSuccess extends APacketEmpty<ClientLoginHandler>
|
||||
public class RPacketLoginSuccess extends APacketEmpty<IClientLoginHandler>
|
||||
{
|
||||
public void processPacket(ClientLoginHandler handler)
|
||||
public void processPacket(IClientLoginHandler handler)
|
||||
{
|
||||
handler.handleLoginSuccess(this);
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package game.packet;
|
|||
import java.io.IOException;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.world.World;
|
||||
|
||||
public class S14PacketEntity implements Packet<ClientPlayer>
|
||||
public class S14PacketEntity implements Packet<IClientPlayer>
|
||||
{
|
||||
protected int entityId;
|
||||
protected byte posX;
|
||||
|
@ -47,7 +47,7 @@ public class S14PacketEntity implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleEntityMovement(this);
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package game.packet;
|
|||
import java.io.IOException;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.util.ExtMath;
|
||||
|
||||
public class S18PacketEntityTeleport implements Packet<ClientPlayer>
|
||||
public class S18PacketEntityTeleport implements Packet<IClientPlayer>
|
||||
{
|
||||
private int entityId;
|
||||
private int posX;
|
||||
|
@ -75,7 +75,7 @@ public class S18PacketEntityTeleport implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleEntityTeleport(this);
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package game.packet;
|
|||
import java.io.IOException;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.world.World;
|
||||
|
||||
public class S19PacketEntityHeadLook implements Packet<ClientPlayer>
|
||||
public class S19PacketEntityHeadLook implements Packet<IClientPlayer>
|
||||
{
|
||||
private int entityId;
|
||||
private byte yaw;
|
||||
|
@ -44,7 +44,7 @@ public class S19PacketEntityHeadLook implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleEntityHeadLook(this);
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package game.packet;
|
|||
import java.io.IOException;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.world.World;
|
||||
|
||||
public class S1APacketEntityStatus implements Packet<ClientPlayer>
|
||||
public class S1APacketEntityStatus implements Packet<IClientPlayer>
|
||||
{
|
||||
private int entityId;
|
||||
private byte logicOpcode;
|
||||
|
@ -44,7 +44,7 @@ public class S1APacketEntityStatus implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleEntityStatus(this);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package game.packet;
|
|||
import java.io.IOException;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class S1BPacketEntityAttach implements Packet<ClientPlayer>
|
||||
public class S1BPacketEntityAttach implements Packet<IClientPlayer>
|
||||
{
|
||||
private int leash;
|
||||
private int entityId;
|
||||
|
@ -47,7 +47,7 @@ public class S1BPacketEntityAttach implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleEntityAttach(this);
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
|
||||
import game.entity.DataWatcher;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class S1CPacketEntityMetadata implements Packet<ClientPlayer>
|
||||
public class S1CPacketEntityMetadata implements Packet<IClientPlayer>
|
||||
{
|
||||
private int entityId;
|
||||
private List<DataWatcher.WatchableObject> field_149378_b;
|
||||
|
@ -52,7 +52,7 @@ public class S1CPacketEntityMetadata implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleEntityMetadata(this);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@ package game.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.potion.Potion;
|
||||
import game.potion.PotionEffect;
|
||||
|
||||
public class S1DPacketEntityEffect implements Packet<ClientPlayer>
|
||||
public class S1DPacketEntityEffect implements Packet<IClientPlayer>
|
||||
{
|
||||
private int entityId;
|
||||
private Potion effectId;
|
||||
|
@ -69,7 +69,7 @@ public class S1DPacketEntityEffect implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleEntityEffect(this);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@ package game.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.potion.Potion;
|
||||
import game.potion.PotionEffect;
|
||||
|
||||
public class S1EPacketRemoveEntityEffect implements Packet<ClientPlayer>
|
||||
public class S1EPacketRemoveEntityEffect implements Packet<IClientPlayer>
|
||||
{
|
||||
private int entityId;
|
||||
private Potion effectId;
|
||||
|
@ -44,7 +44,7 @@ public class S1EPacketRemoveEntityEffect implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleRemoveEntityEffect(this);
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ import java.util.List;
|
|||
import game.collect.Lists;
|
||||
import game.entity.attributes.AttributeInstance;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class S20PacketEntityProperties implements Packet<ClientPlayer>
|
||||
public class S20PacketEntityProperties implements Packet<IClientPlayer>
|
||||
{
|
||||
private int entityId;
|
||||
private final List<S20PacketEntityProperties.Snapshot> field_149444_b = Lists.<S20PacketEntityProperties.Snapshot>newArrayList();
|
||||
|
@ -81,7 +81,7 @@ public class S20PacketEntityProperties implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleEntityProperties(this);
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Vec3;
|
||||
|
||||
public class S27PacketExplosion implements Packet<ClientPlayer>
|
||||
public class S27PacketExplosion implements Packet<IClientPlayer>
|
||||
{
|
||||
private double posX;
|
||||
private double posY;
|
||||
|
@ -106,7 +106,7 @@ public class S27PacketExplosion implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleExplosion(this);
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ package game.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
import game.world.BlockPos;
|
||||
|
||||
public class S28PacketEffect implements Packet<ClientPlayer> {
|
||||
public class S28PacketEffect implements Packet<IClientPlayer> {
|
||||
private int soundType;
|
||||
private BlockPos soundPos;
|
||||
private int soundData;
|
||||
|
@ -33,7 +33,7 @@ public class S28PacketEffect implements Packet<ClientPlayer> {
|
|||
buf.writeInt(this.soundData);
|
||||
}
|
||||
|
||||
public void processPacket(ClientPlayer handler) {
|
||||
public void processPacket(IClientPlayer handler) {
|
||||
handler.handleEffect(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ package game.packet;
|
|||
import java.io.IOException;
|
||||
|
||||
import game.init.SoundEvent;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class S29PacketSoundEffect implements Packet<ClientPlayer>
|
||||
public class S29PacketSoundEffect implements Packet<IClientPlayer>
|
||||
{
|
||||
private SoundEvent sound;
|
||||
private int posX;
|
||||
|
@ -86,7 +86,7 @@ public class S29PacketSoundEffect implements Packet<ClientPlayer>
|
|||
return this.soundVolume;
|
||||
}
|
||||
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleSoundEffect(this);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package game.packet;
|
|||
import java.io.IOException;
|
||||
|
||||
import game.model.ParticleType;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.IClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class S2APacketParticles implements Packet<ClientPlayer>
|
||||
public class S2APacketParticles implements Packet<IClientPlayer>
|
||||
{
|
||||
private ParticleType particleType;
|
||||
private float xCoord;
|
||||
|
@ -183,7 +183,7 @@ public class S2APacketParticles implements Packet<ClientPlayer>
|
|||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(ClientPlayer handler)
|
||||
public void processPacket(IClientPlayer handler)
|
||||
{
|
||||
handler.handleParticles(this);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue