-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Game rule command now tells you when the value is wrong
- Loading branch information
1 parent
19f35f4
commit 4f659d9
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/net/pedroricardo/commander/content/arguments/GenericGameRuleArgumentType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.pedroricardo.commander.content.arguments; | ||
|
||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.core.data.gamerule.GameRule; | ||
import net.pedroricardo.commander.content.exceptions.CommanderExceptions; | ||
|
||
public class GenericGameRuleArgumentType implements ArgumentType<Object> { | ||
private final GameRule<?> gameRule; | ||
|
||
private GenericGameRuleArgumentType(GameRule<?> gameRule) { | ||
this.gameRule = gameRule; | ||
} | ||
|
||
public static GenericGameRuleArgumentType gameRule(GameRule<?> gameRule) { | ||
return new GenericGameRuleArgumentType(gameRule); | ||
} | ||
|
||
@Override | ||
public Object parse(StringReader reader) throws CommandSyntaxException { | ||
StringBuilder read = new StringBuilder(); | ||
Object value = null; | ||
while (reader.canRead() && (StringReader.isQuotedStringStart(reader.peek()) || StringReader.isAllowedInUnquotedString(reader.peek())) && value == null) { | ||
read.append(reader.readString()); | ||
value = this.gameRule.parseFromString(read.toString()); | ||
} | ||
System.out.println(read); | ||
if (value != null) return value; | ||
throw CommanderExceptions.invalidGameRuleValue().create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters