mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 09:01:47 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d97837a24 | |||
| 2efdc5f5a6 | |||
| 19f25db0b7 | |||
| 046e901ec1 | |||
| 6685480957 | |||
| ce1538003b |
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<version>1.5.4</version>
|
<version>1.5.8</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -162,9 +162,14 @@ public class ColorParser {
|
|||||||
startColor.getBlue() + bStep * i * bDirection
|
startColor.getBlue() + bStep * i * bDirection
|
||||||
)).toArray(String[]::new);
|
)).toArray(String[]::new);
|
||||||
|
|
||||||
return IntStream.range(0, characters.length)
|
StringBuilder sb = new StringBuilder();
|
||||||
.mapToObj(i -> colorText(characters[i], extraFormats.get(i), buildHexColor(hexes[i])))
|
String extra = null;
|
||||||
.collect(Collectors.joining());
|
for (int i = 0; i < characters.length; i++) {
|
||||||
|
extra = buildExtraFormat(extra, extraFormats.get(i));
|
||||||
|
String s = colorText(characters[i], extra, buildHexColor(hexes[i]));
|
||||||
|
sb.append(s);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String gradientText(@NotNull String text, @Nullable String startHex, @Nullable String endHex) {
|
protected static String gradientText(@NotNull String text, @Nullable String startHex, @Nullable String endHex) {
|
||||||
@@ -205,4 +210,13 @@ public class ColorParser {
|
|||||||
.collect(Collectors.joining("", '§' + "x", ""));
|
.collect(Collectors.joining("", '§' + "x", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static String buildExtraFormat(String current, String extra) {
|
||||||
|
if (extra != null) current = (current == null ? "" : current) + extra;
|
||||||
|
return isResetCode(current) ? null : current;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static boolean isResetCode(String input) {
|
||||||
|
return input != null && (input.toLowerCase().endsWith("&r") || input.toLowerCase().endsWith("§r"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ public class ColorParseTest {
|
|||||||
System.out.println(parseGradientColor("&<#AAAAAA>我真的&<#BBBBBB>爱死&<#111111>你&<#FFFFFF>!"));
|
System.out.println(parseGradientColor("&<#AAAAAA>我真的&<#BBBBBB>爱死&<#111111>你&<#FFFFFF>!"));
|
||||||
|
|
||||||
// 测试穿插
|
// 测试穿插
|
||||||
System.out.println(parse("&<#AAAAAA>&l我&r真&b的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
System.out.println(parse("&<#AAAAAA>&l&m我真的&o尊的&r真的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
||||||
System.out.println(parse("&<#AAAAAA>&l我&r真&(#666666)的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
System.out.println(parse("&<#AAAAAA>&l我&r真&(#666666)的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
||||||
System.out.println(parse("&r正常的颜色理应&c&l不受影响&r。"));
|
System.out.println(parse("&r正常的颜色理应&c&l不受影响&r。"));
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
|
<version>1.5.8</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
</properties>
|
||||||
|
<artifactId>easyplugin-command-alias</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>EasyPlugin-Command-Alias</name>
|
||||||
|
<description>轻松插件指令别名映射模块,支持将插件内复杂的子指令简化为一个单独的指令,方便玩家使用。</description>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>CarmJos</id>
|
||||||
|
<name>Carm Jos</name>
|
||||||
|
<email>carm@carm.cc</email>
|
||||||
|
<url>https://www.carm.cc</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>The MIT License</name>
|
||||||
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<issueManagement>
|
||||||
|
<system>GitHub Issues</system>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
|
<ciManagement>
|
||||||
|
<system>GitHub Actions</system>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||||
|
</ciManagement>
|
||||||
|
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package cc.carm.lib.easyplugin.command.alias;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class AliasCommand extends Command {
|
||||||
|
|
||||||
|
protected final AliasCommandManager aliasCommandManager;
|
||||||
|
protected final String targetCommand;
|
||||||
|
|
||||||
|
public AliasCommand(String name, AliasCommandManager aliasCommandManager, String targetCommand) {
|
||||||
|
super(name);
|
||||||
|
this.aliasCommandManager = aliasCommandManager;
|
||||||
|
this.targetCommand = targetCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SimpleCommandMap getCommandMap() {
|
||||||
|
return this.aliasCommandManager.getCommandMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String buildCommand(String[] args) {
|
||||||
|
return this.targetCommand + " " + String.join(" ", args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
|
||||||
|
return getCommandMap().dispatch(sender, buildCommand(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias,
|
||||||
|
@NotNull String[] args, @Nullable Location location) throws IllegalArgumentException {
|
||||||
|
return Optional.ofNullable(getCommandMap().tabComplete(sender, buildCommand(args))).orElse(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
|
||||||
|
return tabComplete(sender, alias, args, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+88
@@ -0,0 +1,88 @@
|
|||||||
|
package cc.carm.lib.easyplugin.command.alias;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
|
import org.bukkit.plugin.SimplePluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指令简化别名(简化映射)管理器
|
||||||
|
* <br>支持将插件内复杂的子指令简化为一个单独的指令,方便玩家使用。
|
||||||
|
*/
|
||||||
|
public class AliasCommandManager {
|
||||||
|
|
||||||
|
protected final @NotNull JavaPlugin plugin;
|
||||||
|
protected final @NotNull String prefix;
|
||||||
|
|
||||||
|
protected final @NotNull SimpleCommandMap commandMap;
|
||||||
|
protected final @NotNull Field knownCommandsFiled;
|
||||||
|
|
||||||
|
protected final @NotNull Map<String, AliasCommand> registeredCommands = new HashMap<>();
|
||||||
|
|
||||||
|
public AliasCommandManager(@NotNull JavaPlugin plugin) throws Exception {
|
||||||
|
this(plugin, plugin.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliasCommandManager(@NotNull JavaPlugin plugin, @NotNull String prefix) throws Exception {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.prefix = prefix.trim();
|
||||||
|
|
||||||
|
SimplePluginManager manager = (SimplePluginManager) Bukkit.getPluginManager();
|
||||||
|
Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap");
|
||||||
|
commandMapField.setAccessible(true);
|
||||||
|
this.commandMap = (SimpleCommandMap) commandMapField.get(manager);
|
||||||
|
|
||||||
|
this.knownCommandsFiled = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||||
|
this.knownCommandsFiled.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected Map<String, Command> getKnownCommands() {
|
||||||
|
try {
|
||||||
|
return (Map<String, Command>) knownCommandsFiled.get(commandMap);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @NotNull SimpleCommandMap getCommandMap() {
|
||||||
|
return commandMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommandPrefix() {
|
||||||
|
return this.prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(@NotNull String alias, @NotNull String subCommand) {
|
||||||
|
AliasCommand current = this.registeredCommands.get(alias);
|
||||||
|
if (current != null) current.unregister(getCommandMap());
|
||||||
|
|
||||||
|
AliasCommand cmd = new AliasCommand(alias, this, getCommandPrefix() + " " + subCommand);
|
||||||
|
this.registeredCommands.put(alias, cmd);
|
||||||
|
getCommandMap().register(plugin.getName(), cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregister(@NotNull String alias) {
|
||||||
|
AliasCommand current = this.registeredCommands.remove(alias);
|
||||||
|
if (current != null) {
|
||||||
|
getKnownCommands().remove(alias);
|
||||||
|
current.unregister(getCommandMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterAll() {
|
||||||
|
registeredCommands.forEach((k, v) -> {
|
||||||
|
getKnownCommands().remove(k);
|
||||||
|
v.unregister(getCommandMap());
|
||||||
|
});
|
||||||
|
registeredCommands.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.5.4</version>
|
<version>1.5.8</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.5.4</version>
|
<version>1.5.8</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.5.4</version>
|
<version>1.5.8</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<version>1.5.4</version>
|
<version>1.5.8</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -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.5.4</version>
|
<version>1.5.8</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<version>1.5.4</version>
|
<version>1.5.8</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -63,7 +63,11 @@ public abstract class UserDataManager<K, U extends UserData<K>> {
|
|||||||
return key.toString();
|
return key.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract @NotNull U empty(@NotNull K key);
|
public abstract @NotNull U emptyUser(@NotNull K key);
|
||||||
|
|
||||||
|
public @NotNull U errorUser(@NotNull K key) {
|
||||||
|
return emptyUser(key);
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract @Nullable U loadData(@NotNull K key) throws Exception;
|
protected abstract @Nullable U loadData(@NotNull K key) throws Exception;
|
||||||
|
|
||||||
@@ -108,7 +112,7 @@ public abstract class UserDataManager<K, U extends UserData<K>> {
|
|||||||
U data = loadData(key);
|
U data = loadData(key);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
getPlugin().debug("数据库内不存在用户 " + identifier + " 的数据,视作新档案。");
|
getPlugin().debug("数据库内不存在用户 " + identifier + " 的数据,视作新档案。");
|
||||||
return empty(key);
|
return emptyUser(key);
|
||||||
} else {
|
} else {
|
||||||
getPlugin().debug("加载用户 " + identifier + " 的数据完成,耗时 " + (System.currentTimeMillis() - s1) + " ms.");
|
getPlugin().debug("加载用户 " + identifier + " 的数据完成,耗时 " + (System.currentTimeMillis() - s1) + " ms.");
|
||||||
return data;
|
return data;
|
||||||
@@ -116,7 +120,7 @@ public abstract class UserDataManager<K, U extends UserData<K>> {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
getPlugin().error("加载用户 " + serializeKey(key) + " 数据失败,请检查相关配置!");
|
getPlugin().error("加载用户 " + serializeKey(key) + " 数据失败,请检查相关配置!");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
return empty(key);
|
return errorUser(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, executor).thenApply((data) -> {
|
}, executor).thenApply((data) -> {
|
||||||
@@ -223,22 +227,23 @@ public abstract class UserDataManager<K, U extends UserData<K>> {
|
|||||||
return loadGroup(allKeys, (v) -> false);
|
return loadGroup(allKeys, (v) -> false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull CompletableFuture<Integer> saveAll() {
|
public void saveAll() {
|
||||||
CompletableFuture<Integer> future = CompletableFuture.completedFuture(0);
|
if (getDataCache().isEmpty()) return;
|
||||||
if (getDataCache().isEmpty()) return future;
|
for (U u : getDataCache().values()) {
|
||||||
|
try {
|
||||||
for (U value : getDataCache().values()) {
|
saveData(u);
|
||||||
future = future.thenCombine(save(value), (before, result) -> before + (result ? 1 : 0));
|
} catch (Exception e) {
|
||||||
|
getPlugin().error("保存用户 " + serializeKey(u.getKey()) + " 数据失败,请检查相关配置!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return future;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull CompletableFuture<Integer> unloadAll() {
|
public int unloadAll(boolean save) {
|
||||||
return saveAll().thenApply(result -> {
|
if (save) saveAll();
|
||||||
getDataCache().clear();
|
int size = getDataCache().size();
|
||||||
return result;
|
getDataCache().clear();
|
||||||
});
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+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.5.4</version>
|
<version>1.5.8</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.5.4</version>
|
<version>1.5.8</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.5.4</version>
|
<version>1.5.8</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.5.4</version>
|
<version>1.5.8</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.5.4</version>
|
<version>1.5.8</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.5.4</version>
|
<version>1.5.8</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.5.4</version>
|
<version>1.5.8</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package cc.carm.lib.easyplugin.vault;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class EasyVault {
|
||||||
|
public static boolean hasVault() {
|
||||||
|
return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull EasyVault create() throws Exception {
|
||||||
|
return new EasyVault();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Economy economy = null;
|
||||||
|
|
||||||
|
public EasyVault() throws Exception {
|
||||||
|
if (!setupEconomy()) throw new Exception("Vault not found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setupEconomy() {
|
||||||
|
if (!hasVault()) return false;
|
||||||
|
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
|
if (rsp == null) return false;
|
||||||
|
|
||||||
|
this.economy = rsp.getProvider();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Economy getEconomy() {
|
||||||
|
return economy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMoney(@NotNull Player player) {
|
||||||
|
try {
|
||||||
|
return getEconomy().getBalance(player);
|
||||||
|
} catch (NullPointerException ignore) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMoney(@NotNull OfflinePlayer player) {
|
||||||
|
try {
|
||||||
|
return getEconomy().getBalance(player);
|
||||||
|
} catch (NullPointerException ignore) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkMoney(@NotNull OfflinePlayer player, double amount) {
|
||||||
|
return getMoney(player) >= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkMoney(@NotNull Player player, double amount) {
|
||||||
|
return getMoney(player) >= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EconomyResponse removeMoney(Player player, double amount) {
|
||||||
|
return getEconomy().withdrawPlayer(player, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EconomyResponse removeMoney(OfflinePlayer player, double amount) {
|
||||||
|
return getEconomy().withdrawPlayer(player, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EconomyResponse addMoney(Player player, double amount) {
|
||||||
|
return getEconomy().depositPlayer(player, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EconomyResponse addMoney(OfflinePlayer player, double amount) {
|
||||||
|
return getEconomy().depositPlayer(player, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.5.4</version>
|
<version>1.5.8</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>base/color</module>
|
<module>base/color</module>
|
||||||
<module>base/utils</module>
|
<module>base/utils</module>
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
<module>base/messages</module>
|
<module>base/messages</module>
|
||||||
<module>base/gui</module>
|
<module>base/gui</module>
|
||||||
<module>base/command</module>
|
<module>base/command</module>
|
||||||
|
<module>base/command-alias</module>
|
||||||
<module>base/storage</module>
|
<module>base/storage</module>
|
||||||
<module>base/user</module>
|
<module>base/user</module>
|
||||||
|
|
||||||
@@ -34,7 +35,6 @@
|
|||||||
<module>collection/all</module>
|
<module>collection/all</module>
|
||||||
<module>collection/bom</module>
|
<module>collection/bom</module>
|
||||||
<module>collection/common</module>
|
<module>collection/common</module>
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<name>EasyPlugin</name>
|
<name>EasyPlugin</name>
|
||||||
@@ -81,13 +81,22 @@
|
|||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>sonatype</id>
|
||||||
<url>https://repo1.maven.org/maven2/</url>
|
<name>Sonatype Snapshot Repository</name>
|
||||||
|
<url>https://s01.oss.sonatype.org/content/groups/public/</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>minebench-repo</id>
|
||||||
|
<url>https://repo.minebench.de/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>sonatype</id>
|
<id>codemc-snapshots</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public</url>
|
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
@@ -143,22 +152,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>githubreleases4j</artifactId>
|
<artifactId>githubreleases4j</artifactId>
|
||||||
<version>1.3.1</version>
|
<version>1.3.2</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<artifactId>easylistener</artifactId>
|
|
||||||
<version>2.0.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
|
||||||
<version>2.0.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<artifactId>easysql-beecp</artifactId>
|
|
||||||
<version>0.4.3</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|||||||
Reference in New Issue
Block a user