Comments (6)
This should be closed as 'not an issue' or the equivalent.
Technically it's not a bug because :
is not part of the syntax for an unquoted string (though this is undocumented):
brigadier/src/main/java/com/mojang/brigadier/StringReader.java
Lines 169 to 175 in cf754c4
The solution is (as was suggested) to create a custom argument that can parse values with :
in them.
from brigadier.
The best solution here would be a custom argument so you can validate input quicker and do the splitting of port at parse-time instead of execute-time.
If you need to use string, you'll have to quote it. checkit "127.0.0.1:25566"
- unquoted strings can only contain a limited set of characters.
from brigadier.
@DeStilleGast I don't think there's enough information here to help you effectively.
Can you post a code example of the command registration that you were attempting to parse, and the full command that you were entering?
As well as what you expected to happen, (clearly in this case, not throw errors) but it looks like this is only one small piece of the puzzle.
from brigadier.
@ryantheleach yeah sure, makes sense
the code for the command is:
commandDispatcher.register(
literal("checkit")
.then(
argument("server", word())
.executes(c -> {
String server = c.getArgument("server", String.class);
int port = 25565;
if(server.contains(":")) {
String[] split = server.split(":");
server = split[0];
port = Integer.parseInt(split[1]);
}
checkWhitelisted(c.getSource(), server, port, c.getSource().getUsername());
return 1;
})
.then(argument("user", string())
.executes(c -> {
String server = c.getArgument("server", String.class);
int port = 25565;
if(server.contains(":")) {
String[] split = server.split(":");
server = split[0];
port = Integer.parseInt(split[1]);
}
checkWhitelisted(c.getSource(), server, port, c.getArgument("user", String.class));
return 1;
})))
);
and the command that I try to execute (command prefix removed): checkit 127.0.0.1:25566
what this command basicly should do is that is checks the database if a user is whitelisted or not (reply is done in the function itself)
current workaround is to use checkit "127.0.0.1:25566"
but that can get annoying and confusing
from brigadier.
@Dinnerbone I really don't need a string for it, I just parse a ip and port from a string with optional port option. I tried to make a custom argument, thought first it was going to be hard, but it is easier then it looks.
Created my own IpArgumentType and it works pretty.
My code for future people (it's maybe not pretty, but it works well):
Class IpArgumentType
public class IpArgumentType implements ArgumentType<Ip> {
@Override
public <S> Ip parse(StringReader reader) throws CommandSyntaxException {
String input = reader.getRemaining().split(" ")[0];
reader.setCursor(reader.getCursor() + input.length());
return new Ip(input);
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return null;
}
@Override
public Collection<String> getExamples() {
return Arrays.asList("127.0.0.1", "127.0.0.1:25567");
}
}
Class Ip:
public class Ip {
private String ip;
private int port = 25565; //default port
public Ip(String ip) {
this.ip = ip;
if(ip.contains(":")) {
String[] split = ip.split(":");
this.ip = split[0];
try {
port = Integer.parseInt(split[1]);
}catch (NumberFormatException ex){
throw new NumberFormatException(String.format("%s is not a number !!", split[1]));
}
}
}
public Ip(String ip, int port) {
this.ip = ip;
this.port = port;
}
public String getIp() {
return ip;
}
public int getPort() {
return port;
}
}
from brigadier.
but my issue is fixed, keep this bug open or can it be closed ?
from brigadier.
Related Issues (20)
- [BUG] `StringReader.readUnquotedString()` does not support non-ASCII characters HOT 4
- License HOT 4
- Can node graphs have cycles? HOT 1
- Tests (where relevant) don't actually make sure that an exception was thrown. HOT 2
- [Suggestion] Allow registration of 'docs' for completions HOT 1
- Literal has no way to mark as case insensitive.
- [Suggestion] Optional Arguments HOT 7
- Why do I have to use CommandDispatcher<Object> and not CommandDispatcher<CommandSender>? HOT 15
- Tree-Structure does not inherit generics HOT 3
- Sent by mistake. HOT 1
- List argument nodes (not types)
- bug
- Add 1.1.8 to GitHub releases
- Redirected commands with arguments act as the command is valid even when it isn't HOT 3
- Arguments in a `CommandContext` disappear when a node redirects HOT 2
- My Bedrock edition of minecraft has Cherry Blossom Capes, and because I voted, I wonder if the java edition will have cherry blossom Capes. My java id and Bedrock id are different. So I'm afraid I won't get the cape for my java version of the game, and I'll be sad..... HOT 2
- `StringReader#readString` returns a blank string while `StringReader#canRead` returns true, leading a confusing result HOT 1
- Cannot use non-ascii characters HOT 1
- Crashed because of Deepslate Stairs HOT 4
- Is there a way to make my mod's commands use a different prefix than '/'? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brigadier.