mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-04 16:48:16 +08:00
fix(command): 修复SimpleCompleter使用异常
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class SimpleCompleter {
|
public class SimpleCompleter {
|
||||||
|
|
||||||
@@ -21,9 +22,13 @@ public class SimpleCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> objects(@NotNull String input, int limit, List<?> objects) {
|
public static @NotNull List<String> objects(@NotNull String input, int limit, List<?> objects) {
|
||||||
return objects.stream().filter(Objects::nonNull).map(Object::toString)
|
return objects(input, limit, objects.stream());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> objects(@NotNull String input, int limit, Stream<?> stream) {
|
||||||
|
return stream.filter(Objects::nonNull).map(Object::toString)
|
||||||
.filter(s -> StringUtil.startsWithIgnoreCase(s, input))
|
.filter(s -> StringUtil.startsWithIgnoreCase(s, input))
|
||||||
.limit(Math.min(0, limit)).collect(Collectors.toList());
|
.limit(Math.max(0, limit)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> text(@NotNull String input, String... texts) {
|
public static @NotNull List<String> text(@NotNull String input, String... texts) {
|
||||||
@@ -47,7 +52,7 @@ public class SimpleCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> onlinePlayers(@NotNull String input, int limit) {
|
public static @NotNull List<String> onlinePlayers(@NotNull String input, int limit) {
|
||||||
return text(input, limit, Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList()));
|
return objects(input, limit, Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> allPlayers(@NotNull String input) {
|
public static @NotNull List<String> allPlayers(@NotNull String input) {
|
||||||
@@ -55,7 +60,7 @@ public class SimpleCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> allPlayers(@NotNull String input, int limit) {
|
public static @NotNull List<String> allPlayers(@NotNull String input, int limit) {
|
||||||
return text(input, limit, Arrays.stream(Bukkit.getOfflinePlayers()).map(OfflinePlayer::getName).collect(Collectors.toList()));
|
return objects(input, limit, Arrays.stream(Bukkit.getOfflinePlayers()).map(OfflinePlayer::getName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> worlds(@NotNull String input) {
|
public static @NotNull List<String> worlds(@NotNull String input) {
|
||||||
@@ -63,7 +68,7 @@ public class SimpleCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> worlds(@NotNull String input, int limit) {
|
public static @NotNull List<String> worlds(@NotNull String input, int limit) {
|
||||||
return text(input, limit, Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList()));
|
return objects(input, limit, Bukkit.getWorlds().stream().map(World::getName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> materials(@NotNull String input) {
|
public static @NotNull List<String> materials(@NotNull String input) {
|
||||||
@@ -71,7 +76,7 @@ public class SimpleCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> materials(@NotNull String input, int limit) {
|
public static @NotNull List<String> materials(@NotNull String input, int limit) {
|
||||||
return text(input, limit, Arrays.stream(Material.values()).map(Enum::name).collect(Collectors.toList()));
|
return objects(input, limit, Arrays.stream(Material.values()).map(Enum::name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> effects(@NotNull String input) {
|
public static @NotNull List<String> effects(@NotNull String input) {
|
||||||
@@ -79,7 +84,7 @@ public class SimpleCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> effects(@NotNull String input, int limit) {
|
public static @NotNull List<String> effects(@NotNull String input, int limit) {
|
||||||
return text(input, limit, Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName).collect(Collectors.toList()));
|
return objects(input, limit, Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<modules>
|
<modules>
|
||||||
|
|
||||||
<module>base/main</module>
|
<module>base/main</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user