client side command parsing wip (4)

This commit is contained in:
Bixilon 2020-12-11 17:05:47 +01:00
parent efd23855d5
commit ac0eb4f2f1
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
24 changed files with 133 additions and 32 deletions

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.commands;
import de.bixilon.minosoft.data.commands.parser.CommandParser;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -60,9 +61,9 @@ public class CommandArgumentNode extends CommandLiteralNode {
}
@Override
public void isSyntaxCorrect(ImprovedStringReader stringReader) throws CommandParseException {
parser.isParsable(properties, stringReader);
super.isSyntaxCorrect(stringReader);
public void isSyntaxCorrect(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
parser.isParsable(connection, properties, stringReader);
super.isSyntaxCorrect(connection, stringReader);
}
public enum SuggestionTypes {

View File

@ -17,6 +17,7 @@ import com.google.errorprone.annotations.DoNotCall;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.RequiresMoreArgumentsCommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.WrongArgumentCommandParseException;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
import de.bixilon.minosoft.util.BitByte;
@ -77,7 +78,7 @@ public abstract class CommandNode {
return childrenIds;
}
public void isSyntaxCorrect(ImprovedStringReader stringReader) throws CommandParseException {
public void isSyntaxCorrect(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
String nextArgument = stringReader.getUntilNextCommandArgument();
if (nextArgument.length() == 0) {
if (isExecutable) {
@ -87,14 +88,14 @@ public abstract class CommandNode {
}
if (literalChildren.containsKey(nextArgument)) {
stringReader.skip(nextArgument.length() + ProtocolDefinition.COMMAND_SEPARATOR.length());
literalChildren.get(nextArgument).isSyntaxCorrect(stringReader);
literalChildren.get(nextArgument).isSyntaxCorrect(connection, stringReader);
return;
}
CommandParseException lastException = null;
for (CommandArgumentNode argumentNode : argumentsChildren) {
int currentPosition = stringReader.getPosition();
try {
argumentNode.isSyntaxCorrect(stringReader);
argumentNode.isSyntaxCorrect(connection, stringReader);
return;
} catch (CommandParseException e) {
lastException = e;
@ -108,11 +109,11 @@ public abstract class CommandNode {
throw new WrongArgumentCommandParseException(stringReader, nextArgument);
}
public void isSyntaxCorrect(String string) throws CommandParseException {
public void isSyntaxCorrect(Connection connection, String string) throws CommandParseException {
// replace multiple spaces with nothing
string = string.replaceAll("\\s{2,}", " ");
ImprovedStringReader stringReader = new ImprovedStringReader(string);
isSyntaxCorrect(stringReader);
isSyntaxCorrect(connection, stringReader);
}
public enum NodeTypes {

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.commands;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.UnknownCommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.WrongArgumentCommandParseException;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -25,9 +26,9 @@ public class CommandRootNode extends CommandNode {
}
@Override
public void isSyntaxCorrect(ImprovedStringReader stringReader) throws CommandParseException {
public void isSyntaxCorrect(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
try {
super.isSyntaxCorrect(stringReader);
super.isSyntaxCorrect(connection, stringReader);
} catch (WrongArgumentCommandParseException e) {
if (e.getStartIndex() == 0) {
// beginn of string

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.commands.parser;
import de.bixilon.minosoft.data.commands.parser.exception.BooleanCommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
import javax.annotation.Nullable;
@ -24,7 +25,7 @@ public class BooleanParser extends CommandParser {
public static final BooleanParser BOOLEAN_PARSER = new BooleanParser();
@Override
public void isParsable(@Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, @Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
String argument = stringReader.readUntilNextCommandArgument();
if (!argument.equals("true") && !argument.equals("false")) {
throw new BooleanCommandParseException(stringReader, argument);

View File

@ -17,6 +17,7 @@ import com.google.common.collect.HashBiMap;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.data.mappings.ModIdentifier;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -46,6 +47,6 @@ public abstract class CommandParser {
return null;
}
public abstract void isParsable(@Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException;
public abstract void isParsable(Connection connection, @Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException;
}

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.data.commands.parser.exception.number.DoubleCommandPa
import de.bixilon.minosoft.data.commands.parser.exception.number.ValueOutOfRangeCommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.DoubleParserProperties;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -34,7 +35,7 @@ public class DoubleParser extends CommandParser {
}
@Override
public void isParsable(ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
String argument = stringReader.readUntilNextCommandArgument();
try {
double value = Double.parseDouble(argument);

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.commands.parser;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
import javax.annotation.Nullable;
@ -24,6 +25,6 @@ public class DummyParser extends CommandParser {
public static final DummyParser DUMMY_PARSER = new DummyParser();
@Override
public void isParsable(@Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, @Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
}
}

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.entity.*;
import de.bixilon.minosoft.data.commands.parser.properties.EntityParserProperties;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
import de.bixilon.minosoft.util.Util;
@ -49,8 +50,9 @@ public class EntityParser extends CommandParser {
ENTITY_FILTER_PARAMETER_LIST.put("x_rotation", RangeSelectorArgumentParser.ROTATION_SELECTOR_ARGUMENT_PARSER);
ENTITY_FILTER_PARAMETER_LIST.put("y_rotation", RangeSelectorArgumentParser.ROTATION_SELECTOR_ARGUMENT_PARSER);
ENTITY_FILTER_PARAMETER_LIST.put("tag", StringSelectorArgumentParser.STRING_SELECTOR_ARGUMENT_PARSER);
ENTITY_FILTER_PARAMETER_LIST.put("type", IdentifierSelectorArgumentParser.ENTITY_TYPE_IDENTIFIER_SELECTOR_ARGUMENT_PARSER);
// ToDo: advancements, nbt, type, scores
// ToDo: advancements, nbt, scores
}
@Override
@ -59,7 +61,7 @@ public class EntityParser extends CommandParser {
}
@Override
public void isParsable(ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
EntityParserProperties entityParserProperties = (EntityParserProperties) properties;
if (stringReader.getChar().equals("@")) {
// selector
@ -100,7 +102,7 @@ public class EntityParser extends CommandParser {
stringReader.skipSpaces();
EntitySelectorArgumentParser parser = ENTITY_FILTER_PARAMETER_LIST.get(parameterName);
parser.isParsable(stringReader);
parser.isParsable(connection, stringReader);
stringReader.skipSpaces();
parameters.add(parameterName);

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.data.commands.parser.exception.number.FloatCommandPar
import de.bixilon.minosoft.data.commands.parser.exception.number.ValueOutOfRangeCommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.FloatParserProperties;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -31,7 +32,7 @@ public class FloatParser extends CommandParser {
}
@Override
public void isParsable(ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
String argument = stringReader.readUntilNextCommandArgument();
try {
float value = Float.parseFloat(argument);

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.data.commands.parser.exception.number.IntegerCommandP
import de.bixilon.minosoft.data.commands.parser.exception.number.ValueOutOfRangeCommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.IntegerParserProperties;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -34,7 +35,7 @@ public class IntegerParser extends CommandParser {
}
@Override
public void isParsable(ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
String argument = stringReader.readUntilNextCommandArgument();
try {
int value = Integer.parseInt(argument);

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.commands.parser;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.data.commands.parser.properties.StringParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -32,7 +33,7 @@ public class MessageParser extends StringParser {
}
@Override
public void isParsable(@Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
super.isParsable(STRING_PARSER_PROPERTIES, stringReader);
public void isParsable(Connection connection, @Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
super.isParsable(connection, STRING_PARSER_PROPERTIES, stringReader);
}
}

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.commands.parser;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.data.commands.parser.properties.RangeParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -30,7 +31,7 @@ public class RangeParser extends CommandParser {
}
@Override
public void isParsable(@Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, @Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
// ToDo
}
}

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.commands.parser;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.data.commands.parser.properties.ScoreHolderParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -30,7 +31,7 @@ public class ScoreHolderParser extends CommandParser {
}
@Override
public void isParsable(@Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, @Nullable ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
// ToDo
}
}

View File

@ -17,6 +17,7 @@ import de.bixilon.minosoft.data.commands.parser.exception.BlankStringCommandPars
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties;
import de.bixilon.minosoft.data.commands.parser.properties.StringParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -29,7 +30,7 @@ public class StringParser extends CommandParser {
}
@Override
public void isParsable(ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ParserProperties properties, ImprovedStringReader stringReader) throws CommandParseException {
StringParserProperties stringParserProperties = ((StringParserProperties) properties);
String string = switch (stringParserProperties.getSetting()) {
case SINGLE_WORD -> stringReader.readUntilNextCommandArgument();

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.commands.parser.entity;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.number.DoubleCommandParseException;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.Pair;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -22,7 +23,7 @@ public class DoubleSelectorArgumentParser extends EntitySelectorArgumentParser {
public static final DoubleSelectorArgumentParser DOUBLE_SELECTOR_ARGUMENT_PARSER = new DoubleSelectorArgumentParser();
@Override
public void isParsable(ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
Pair<String, String> match = readNextArgument(stringReader);
try {
Double.parseDouble(match.key);

View File

@ -14,13 +14,14 @@
package de.bixilon.minosoft.data.commands.parser.entity;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.Pair;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
public abstract class EntitySelectorArgumentParser {
private static final String[] ENTITY_VALUE_TERMINATORS = {",", " ", "]"};
public abstract void isParsable(ImprovedStringReader stringReader) throws CommandParseException;
public abstract void isParsable(Connection connection, ImprovedStringReader stringReader) throws CommandParseException;
protected Pair<String, String> readNextArgument(ImprovedStringReader stringReader) {
Pair<String, String> match = stringReader.readUntil(ENTITY_VALUE_TERMINATORS);

View File

@ -0,0 +1,44 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.commands.parser.entity;
import de.bixilon.minosoft.data.EntityClassMappings;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.entity.UnknownEntityCommandParseException;
import de.bixilon.minosoft.data.mappings.ModIdentifier;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.Pair;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
public class IdentifierSelectorArgumentParser extends EntitySelectorArgumentParser {
public static final IdentifierSelectorArgumentParser ENTITY_TYPE_IDENTIFIER_SELECTOR_ARGUMENT_PARSER = new IdentifierSelectorArgumentParser();
@Override
public void isParsable(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
Pair<String, String> match = readNextArgument(stringReader);
String value = match.key;
if (match.key.startsWith("!")) {
value = value.substring(1);
}
ModIdentifier identifier = new ModIdentifier(value);
if (this == ENTITY_TYPE_IDENTIFIER_SELECTOR_ARGUMENT_PARSER) {
if (!EntityClassMappings.ENTITY_CLASS_MAPPINGS.containsValue(identifier)) {
throw new UnknownEntityCommandParseException(stringReader, match.key);
}
return;
}
throw new RuntimeException();
}
}

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.commands.parser.entity;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.number.IntegerCommandParseException;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.Pair;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -22,7 +23,7 @@ public class IntegerSelectorArgumentParser extends EntitySelectorArgumentParser
public static final IntegerSelectorArgumentParser INTEGER_SELECTOR_ARGUMENT_PARSER = new IntegerSelectorArgumentParser();
@Override
public void isParsable(ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
Pair<String, String> match = readNextArgument(stringReader);
try {
Integer.parseInt(match.key);

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.commands.parser.entity;
import de.bixilon.minosoft.data.GameModes;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.entity.UnknownEnumValueCommandParseException;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.Pair;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -44,7 +45,7 @@ public class ListSelectorArgumentParser extends EntitySelectorArgumentParser {
}
@Override
public void isParsable(ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
Pair<String, String> match = readNextArgument(stringReader);
String value = match.key;
if (match.key.startsWith("!")) {

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.commands.parser.entity;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.exception.number.*;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.Pair;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
@ -46,7 +47,7 @@ public class RangeSelectorArgumentParser extends EntitySelectorArgumentParser {
}
@Override
public void isParsable(ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
Pair<String, String> match = readNextArgument(stringReader);
if (match.key.contains("..")) {

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.commands.parser.entity;
import de.bixilon.minosoft.data.commands.parser.StringParser;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.data.commands.parser.properties.StringParserProperties;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
public class StringSelectorArgumentParser extends EntitySelectorArgumentParser {
@ -23,10 +24,10 @@ public class StringSelectorArgumentParser extends EntitySelectorArgumentParser {
private static final StringParserProperties STRING_PARSER_PROPERTIES = new StringParserProperties(StringParserProperties.StringSettings.QUOTABLE_PHRASE, true);
@Override
public void isParsable(ImprovedStringReader stringReader) throws CommandParseException {
public void isParsable(Connection connection, ImprovedStringReader stringReader) throws CommandParseException {
// if it starts with a quote, it will end with a quote
if (stringReader.get(1).equals("\"")) {
StringParser.STRING_PARSER.isParsable(STRING_PARSER_PROPERTIES, stringReader);
StringParser.STRING_PARSER.isParsable(connection, STRING_PARSER_PROPERTIES, stringReader);
return;
}
readNextArgument(stringReader);

View File

@ -0,0 +1,30 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.commands.parser.exception.entity;
import de.bixilon.minosoft.data.commands.parser.exception.CommandParseException;
import de.bixilon.minosoft.util.buffers.ImprovedStringReader;
public class UnknownEntityCommandParseException extends CommandParseException {
private static final String ERROR_MESSAGE = "Unknown entity type!";
public UnknownEntityCommandParseException(ImprovedStringReader command, String currentArgument) {
super(ERROR_MESSAGE, command, currentArgument);
}
public UnknownEntityCommandParseException(ImprovedStringReader command, String currentArgument, Throwable cause) {
super(ERROR_MESSAGE, command, currentArgument, cause);
}
}

View File

@ -818,7 +818,7 @@ public class PacketHandler {
};
for (String command : commands) {
try {
pkg.getRootNode().isSyntaxCorrect(command);
pkg.getRootNode().isSyntaxCorrect(connection, command);
Log.game("Command \"%s\" is valid", command);
} catch (CommandParseException e) {
Log.game("Command \"%s\" is invalid, %s: %s", command, e.getClass().getSimpleName(), e.getErrorMessage());

View File

@ -25,6 +25,7 @@ import de.bixilon.minosoft.protocol.packets.serverbound.play.*;
import java.util.UUID;
public class PacketSender {
public static final String[] ILLEGAL_CHAT_CHARS = new String[]{"§"};
final Connection connection;
public PacketSender(Connection connection) {
@ -36,6 +37,11 @@ public class PacketSender {
}
public void sendChatMessage(String message) {
for (String illegalChar : ILLEGAL_CHAT_CHARS) {
if (message.contains(illegalChar)) {
throw new IllegalArgumentException(String.format("%s is not allowed in chat", illegalChar));
}
}
ChatMessageSendingEvent event = new ChatMessageSendingEvent(connection, message);
if (connection.fireEvent(event)) {
return;