add some commands
This commit is contained in:
parent
6bf6831360
commit
d5269922b9
5 changed files with 65 additions and 1 deletions
|
@ -142,6 +142,10 @@ public abstract class Command implements Executable {
|
||||||
return this.addEnum(name, null, clazz, 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) {
|
protected Command addTag(String name) {
|
||||||
return this.addParameter(new TagParser(name, null));
|
return this.addParameter(new TagParser(name, null));
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,6 +252,8 @@ public class CommandEnvironment {
|
||||||
this.registerExecutable(new CommandTime());
|
this.registerExecutable(new CommandTime());
|
||||||
this.registerExecutable(new CommandRemove());
|
this.registerExecutable(new CommandRemove());
|
||||||
this.registerExecutable(new CommandWeather());
|
this.registerExecutable(new CommandWeather());
|
||||||
|
this.registerExecutable(new CommandKick());
|
||||||
|
this.registerExecutable(new CommandMessage());
|
||||||
|
|
||||||
this.registerExecutable(new CommandHelp(this));
|
this.registerExecutable(new CommandHelp(this));
|
||||||
}
|
}
|
||||||
|
|
28
java/src/game/command/commands/CommandKick.java
Normal file
28
java/src/game/command/commands/CommandKick.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package game.command.commands;
|
||||||
|
|
||||||
|
import game.command.CommandEnvironment;
|
||||||
|
import game.command.RunException;
|
||||||
|
import game.command.Command;
|
||||||
|
import game.command.Executor;
|
||||||
|
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.isLocal())
|
||||||
|
throw new RunException("%s ist der Host-Spieler", player.getUser());
|
||||||
|
else if(player.getAdmin())
|
||||||
|
throw new RunException("%s ist ein Admin", player.getUser());
|
||||||
|
player.disconnect();
|
||||||
|
exec.logConsole("%s wurde vom Server geworfen", player.getUser());
|
||||||
|
}
|
||||||
|
}
|
20
java/src/game/command/commands/CommandMessage.java
Normal file
20
java/src/game/command/commands/CommandMessage.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package game.command.commands;
|
||||||
|
|
||||||
|
import game.command.CommandEnvironment;
|
||||||
|
import game.command.Command;
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1672,6 +1672,16 @@ public class Player extends NetHandler implements ICrafting, Executor
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean sendEmote(String line) {
|
||||||
|
if(!line.startsWith("*") || line.length() < 2)
|
||||||
|
return false;
|
||||||
|
String str = line.substring(1).trim();
|
||||||
|
if(str.isEmpty())
|
||||||
|
return false;
|
||||||
|
this.server.sendPacket(new SPacketMessage(String.format(TextColor.LGRAY + "* %s %s", this.entity.getColoredName(TextColor.LGRAY), str), Type.CHAT));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean setVar(String line) {
|
private boolean setVar(String line) {
|
||||||
if(!this.isAdmin())
|
if(!this.isAdmin())
|
||||||
return false;
|
return false;
|
||||||
|
@ -1969,7 +1979,7 @@ public class Player extends NetHandler implements ICrafting, Executor
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CHAT:
|
case CHAT:
|
||||||
if(!this.sendPlayer(msg))
|
if(!this.sendPlayer(msg) && !this.sendEmote(msg))
|
||||||
this.server.sendPacket(new SPacketMessage(String.format("%s %s", this.entity.getColoredName(TextColor.LGRAY), msg), Type.CHAT));
|
this.server.sendPacket(new SPacketMessage(String.format("%s %s", this.entity.getColoredName(TextColor.LGRAY), msg), Type.CHAT));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue