mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-04 08:38:17 +08:00
feat(command): 指令部分新增基础方法
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.8</version>
|
<version>1.4.9</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ public abstract class CommandHandler implements TabExecutor, NamedExecutor {
|
|||||||
|
|
||||||
public abstract void noArgs(CommandSender sender);
|
public abstract void noArgs(CommandSender sender);
|
||||||
|
|
||||||
public abstract void unknownCommand(CommandSender sender, String[] args);
|
public void unknownCommand(CommandSender sender, String[] args) {
|
||||||
|
noArgs(sender);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void noPermission(CommandSender sender);
|
public abstract void noPermission(CommandSender sender);
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
package cc.carm.lib.easyplugin.command;
|
package cc.carm.lib.easyplugin.command;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
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;
|
||||||
@@ -17,14 +20,22 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class SimpleCompleter {
|
public class SimpleCompleter {
|
||||||
|
|
||||||
public static @NotNull List<String> objects(@NotNull String input, List<?> objects) {
|
public static @NotNull List<String> none() {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> objects(@NotNull String input, Collection<?> objects) {
|
||||||
return objects(input, objects.size(), objects);
|
return objects(input, objects.size(), objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> objects(@NotNull String input, int limit, List<?> objects) {
|
public static @NotNull List<String> objects(@NotNull String input, int limit, Collection<?> objects) {
|
||||||
return objects(input, limit, objects.stream());
|
return objects(input, limit, objects.stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> objects(@NotNull String input, Stream<?> stream) {
|
||||||
|
return objects(input, 20, stream);
|
||||||
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> objects(@NotNull String input, int limit, Stream<?> stream) {
|
public static @NotNull List<String> objects(@NotNull String input, int limit, Stream<?> stream) {
|
||||||
return stream.filter(Objects::nonNull).map(Object::toString)
|
return stream.filter(Objects::nonNull).map(Object::toString)
|
||||||
.filter(s -> StringUtil.startsWithIgnoreCase(s, input))
|
.filter(s -> StringUtil.startsWithIgnoreCase(s, input))
|
||||||
@@ -39,11 +50,11 @@ public class SimpleCompleter {
|
|||||||
return text(input, limit, Arrays.asList(texts));
|
return text(input, limit, Arrays.asList(texts));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> text(@NotNull String input, List<String> texts) {
|
public static @NotNull List<String> text(@NotNull String input, Collection<String> texts) {
|
||||||
return text(input, texts.size(), texts);
|
return text(input, texts.size(), texts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull List<String> text(@NotNull String input, int limit, List<String> texts) {
|
public static @NotNull List<String> text(@NotNull String input, int limit, Collection<String> texts) {
|
||||||
return objects(input, limit, texts);
|
return objects(input, limit, texts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,4 +98,13 @@ public class SimpleCompleter {
|
|||||||
return objects(input, limit, Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName));
|
return objects(input, limit, Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> enchantments(@NotNull String input) {
|
||||||
|
return effects(input, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static @NotNull List<String> enchantments(@NotNull String input, int limit) {
|
||||||
|
return objects(input, limit, Arrays.stream(Enchantment.values()).map(Enchantment::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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</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.8</version>
|
<version>1.4.9</version>
|
||||||
<modules>
|
<modules>
|
||||||
|
|
||||||
<module>base/main</module>
|
<module>base/main</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user