-
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.
Signed-off-by: astro-angelfish <[email protected]>
- Loading branch information
1 parent
7c99245
commit 1cb08ed
Showing
11 changed files
with
152 additions
and
41 deletions.
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
core/src/main/java/moe/orangemc/fishlib/command/argument/FishUTFStringArgumentType.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,65 @@ | ||
/* | ||
* FishLib, a Bukkit development library | ||
* Copyright (C) Astro angelfish | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package moe.orangemc.fishlib.command.argument; | ||
|
||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.mojang.brigadier.suggestion.Suggestions; | ||
import com.mojang.brigadier.suggestion.SuggestionsBuilder; | ||
import moe.orangemc.fishlib.util.StringUtil; | ||
|
||
import java.util.Collection; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Predicate; | ||
|
||
public class FishUTFStringArgumentType implements ArgumentType<String> { | ||
@Override | ||
public String parse(StringReader reader) throws CommandSyntaxException { | ||
return readUTFString(reader); | ||
} | ||
|
||
public static String readUTFString(StringReader reader, Predicate<Character> matcher) throws CommandSyntaxException { | ||
if (reader.peek() == '"' || reader.peek() == '\'') { | ||
return reader.readQuotedString(); | ||
} | ||
|
||
int start = reader.getCursor(); | ||
while (matcher.test(reader.peek()) && reader.canRead()) { | ||
reader.skip(); | ||
} | ||
|
||
return reader.getString().substring(start, reader.getCursor()); | ||
} | ||
|
||
public static String readUTFString(StringReader reader) throws CommandSyntaxException { | ||
return readUTFString(reader, c -> !StringUtil.isBlankChar(c)); | ||
} | ||
|
||
@Override | ||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) { | ||
return ArgumentType.super.listSuggestions(context, builder); | ||
} | ||
|
||
@Override | ||
public Collection<String> getExamples() { | ||
return ArgumentType.super.getExamples(); | ||
} | ||
} |
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
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
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
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
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
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
36 changes: 36 additions & 0 deletions
36
core/src/main/java/moe/orangemc/fishlib/command/selector/type/StringTypeAdapter.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,36 @@ | ||
/* | ||
* FishLib, a Bukkit development library | ||
* Copyright (C) Astro angelfish | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package moe.orangemc.fishlib.command.selector.type; | ||
|
||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import moe.orangemc.fishlib.command.argument.FishUTFStringArgumentType; | ||
import moe.orangemc.fishlib.command.selector.Selector; | ||
|
||
public class StringTypeAdapter implements SelectorArgumentTypeAdapter<String> { | ||
@Override | ||
public String fromStringReader(Selector selector, StringReader sr) throws CommandSyntaxException { | ||
return FishUTFStringArgumentType.readUTFString(sr); | ||
} | ||
|
||
@Override | ||
public Class<String> getProvidingClass() { | ||
return String.class; | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
core/src/main/java/moe/orangemc/fishlib/command/selector/util/CharFilterUtil.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,27 @@ | ||
/* | ||
* FishLib, a Bukkit development library | ||
* Copyright (C) Astro angelfish | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package moe.orangemc.fishlib.command.selector.util; | ||
|
||
import moe.orangemc.fishlib.util.StringUtil; | ||
|
||
public class CharFilterUtil { | ||
public static boolean charNotSelectorSpecial(char v) { | ||
return !StringUtil.isBlankChar(v) && v != '!' && v != '"' && v != '\'' && v != '[' && v != ']' && v != '=' && v != ',' && v != '@'; | ||
} | ||
} |