feat: 添加异步和事件功能
This commit is contained in:
@@ -17,8 +17,8 @@ dependencies {
|
|||||||
annotationProcessor("org.projectlombok:lombok:1.18.30")
|
annotationProcessor("org.projectlombok:lombok:1.18.30")
|
||||||
|
|
||||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||||
compileOnly("cn.hamster3.mc.plugin:core-bukkit:1.2.1")
|
compileOnly("cn.hamster3.mc.plugin:core-bukkit:+")
|
||||||
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:1.5.0")
|
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:+")
|
||||||
compileOnly("net.milkbowl.vault:VaultAPI:1.7")
|
compileOnly("net.milkbowl.vault:VaultAPI:1.7")
|
||||||
compileOnly("me.clip:placeholderapi:+")
|
compileOnly("me.clip:placeholderapi:+")
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ package cn.hamster3.mc.plugin.currency;
|
|||||||
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.currency.command.currency.ParentCurrencyCommand;
|
import cn.hamster3.mc.plugin.currency.command.currency.ParentCurrencyCommand;
|
||||||
import cn.hamster3.mc.plugin.currency.core.ConfigManager;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyConfigManager;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyMessage;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyMessage;
|
||||||
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
@@ -42,7 +42,7 @@ public class CurrencyPlugin extends JavaPlugin {
|
|||||||
Logger logger = getLogger();
|
Logger logger = getLogger();
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
logger.info("仓鼠经济正在初始化");
|
logger.info("仓鼠经济正在初始化");
|
||||||
ConfigManager.init();
|
CurrencyConfigManager.init();
|
||||||
logger.info("已读取配置文件");
|
logger.info("已读取配置文件");
|
||||||
CurrencyMessage.init(this);
|
CurrencyMessage.init(this);
|
||||||
logger.info("已初始化语言文本");
|
logger.info("已初始化语言文本");
|
||||||
@@ -55,15 +55,15 @@ public class CurrencyPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||||
logger.info("检测到 Vault 已安装");
|
logger.info("检测到 Vault 已安装");
|
||||||
CurrencyType vaultType = CurrencyDataManager.getVaultCurrencyType();
|
Bukkit.getServicesManager().register(Economy.class, VaultEconomyHook.INSTANCE, this, ServicePriority.Normal);
|
||||||
if (vaultType == null) {
|
CurrencyType type = CurrencyDataManager.getVaultCurrencyType();
|
||||||
logger.info("未设置任何经济类型挂载至 Vault");
|
if (type != null) {
|
||||||
|
logger.info(String.format("已挂载货币类型 %s(%s) 至 Vault 系统", type.getId(), type.getName()));
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getServicesManager().register(Economy.class, new VaultEconomyHook(vaultType), this, ServicePriority.Normal);
|
logger.warning("已挂接 Vault 系统,但未找到 Vault 货币类型,请检查配置文件或创建货币类型: " + CurrencyConfigManager.getVaultCurrencyID());
|
||||||
logger.info(String.format("已挂载货币类型 %s(%s) 至 Vault 系统", vaultType.getId(), vaultType.getName()));
|
|
||||||
if (ConfigManager.isEnableVaultCommands()) {
|
|
||||||
logger.info("本插件暂不支持 vault 指令");
|
|
||||||
}
|
}
|
||||||
|
if (CurrencyConfigManager.isEnableVaultCommands()) {
|
||||||
|
logger.info("本插件暂不支持 vault 指令");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.info("未找到 Vault 插件! 取消注册 Vault 经济系统");
|
logger.info("未找到 Vault 插件! 取消注册 Vault 经济系统");
|
||||||
|
@@ -1,114 +1,78 @@
|
|||||||
package cn.hamster3.mc.plugin.currency.api;
|
package cn.hamster3.mc.plugin.currency.api;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.hook.PointAPI;
|
import cn.hamster3.mc.plugin.currency.async.CompletableTask;
|
||||||
import cn.hamster3.mc.plugin.currency.CurrencyPlugin;
|
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
||||||
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
|
import cn.hamster3.mc.plugin.currency.event.CurrencyGiveEvent;
|
||||||
|
import cn.hamster3.mc.plugin.currency.event.CurrencySetEvent;
|
||||||
|
import cn.hamster3.mc.plugin.currency.event.CurrencyTakeEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当 currencyID 为 PlayerPoints 且服务器安装了点券插件时,会自动更改为 PlayerPoints 接口
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"unused", "UnusedReturnValue"})
|
@SuppressWarnings({"unused", "UnusedReturnValue"})
|
||||||
public final class CurrencyAPI {
|
public final class CurrencyAPI {
|
||||||
private CurrencyAPI() {
|
private CurrencyAPI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getPlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID) {
|
@NotNull
|
||||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
public static CompletableTask<Void> givePlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||||
return PointAPI.getPoint(uuid);
|
return CompletableTask.runAsync(() -> {
|
||||||
|
if (amount < 0) {
|
||||||
|
throw new IllegalArgumentException("amount must be greater than 0");
|
||||||
}
|
}
|
||||||
return CurrencyDataManager.getPlayerCurrency(uuid, currencyID);
|
CurrencyType type = getCurrencyType(currencyID);
|
||||||
|
if (type == null) {
|
||||||
|
throw new IllegalArgumentException("can not find currency type with id: " + currencyID);
|
||||||
}
|
}
|
||||||
|
CurrencyGiveEvent event = new CurrencyGiveEvent(uuid, type, amount);
|
||||||
public static boolean hasPlayerCurrency(UUID uuid, @NotNull String currencyID, double amount) {
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return getPlayerCurrency(uuid, currencyID) >= amount;
|
CurrencyDataManager.addPlayerCurrency(event.getUuid(), event.getType().getId(), event.getAmount(), true);
|
||||||
}
|
});
|
||||||
|
|
||||||
public static void addPlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) throws SQLException {
|
|
||||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
|
||||||
PointAPI.givePoint(uuid, (int) amount);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CurrencyDataManager.addPlayerCurrency(uuid, currencyID, amount, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static CompletableFuture<Void> addPlayerCurrencyAsync(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
public static CompletableTask<Void> takePlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
return CompletableTask.runAsync(() -> {
|
||||||
PointAPI.givePoint(uuid, (int) amount);
|
if (amount < 0) {
|
||||||
return CompletableFuture.completedFuture(null);
|
throw new IllegalArgumentException("amount must be greater than 0");
|
||||||
}
|
}
|
||||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
CurrencyType type = getCurrencyType(currencyID);
|
||||||
CurrencyPlugin.async(() -> {
|
if (type == null) {
|
||||||
try {
|
throw new IllegalArgumentException("can not find currency type with id: " + currencyID);
|
||||||
CurrencyDataManager.addPlayerCurrency(uuid, currencyID, amount, true);
|
|
||||||
future.complete(null);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
future.completeExceptionally(e);
|
|
||||||
}
|
}
|
||||||
|
CurrencyTakeEvent event = new CurrencyTakeEvent(uuid, type, amount);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
CurrencyDataManager.takePlayerCurrency(event.getUuid(), event.getType().getId(), event.getAmount(), true);
|
||||||
});
|
});
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void takePlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) throws SQLException {
|
|
||||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
|
||||||
PointAPI.takePoint(uuid, (int) amount);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CurrencyDataManager.takePlayerCurrency(uuid, currencyID, amount, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static CompletableFuture<Void> takePlayerCurrencyAsync(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
public static CompletableTask<Void> setPlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
return CompletableTask.runAsync(() -> {
|
||||||
PointAPI.takePoint(uuid, (int) amount);
|
CurrencyType type = getCurrencyType(currencyID);
|
||||||
return CompletableFuture.completedFuture(null);
|
if (type == null) {
|
||||||
}
|
throw new IllegalArgumentException("can not find currency type with id: " + currencyID);
|
||||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
|
||||||
CurrencyPlugin.async(() -> {
|
|
||||||
try {
|
|
||||||
CurrencyDataManager.takePlayerCurrency(uuid, currencyID, amount, true);
|
|
||||||
future.complete(null);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
future.completeExceptionally(e);
|
|
||||||
}
|
}
|
||||||
|
CurrencySetEvent event = new CurrencySetEvent(uuid, type, amount);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
CurrencyDataManager.setPlayerCurrency(event.getUuid(), event.getType().getId(), event.getAmount(), true);
|
||||||
});
|
});
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setPlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) throws SQLException {
|
|
||||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
|
||||||
PointAPI.setPoint(uuid, (int) amount);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CurrencyDataManager.setPlayerCurrency(uuid, currencyID, amount, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static CompletableFuture<Void> setPlayerCurrencyAsync(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
public static CompletableTask<Map<String, Double>> getPlayerCurrency(@NotNull UUID uuid) {
|
||||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
return CompletableTask.supplyAsync(() -> CurrencyDataManager.getPlayerCurrency(uuid));
|
||||||
PointAPI.setPoint(uuid, (int) amount);
|
|
||||||
return CompletableFuture.completedFuture(null);
|
|
||||||
}
|
}
|
||||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
|
||||||
CurrencyPlugin.async(() -> {
|
@NotNull
|
||||||
try {
|
public static CompletableTask<Double> getPlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID) {
|
||||||
CurrencyDataManager.setPlayerCurrency(uuid, currencyID, amount, true);
|
return CompletableTask.supplyAsync(() -> CurrencyDataManager.getPlayerCurrency(uuid, currencyID));
|
||||||
future.complete(null);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
future.completeExceptionally(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return future;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -116,6 +80,7 @@ public final class CurrencyAPI {
|
|||||||
return CurrencyDataManager.getCurrencyType(id);
|
return CurrencyDataManager.getCurrencyType(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static CurrencyType getVaultCurrencyType() {
|
public static CurrencyType getVaultCurrencyType() {
|
||||||
return CurrencyDataManager.getVaultCurrencyType();
|
return CurrencyDataManager.getVaultCurrencyType();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,172 @@
|
|||||||
|
package cn.hamster3.mc.plugin.currency.async;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@SuppressWarnings("CallToPrintStackTrace")
|
||||||
|
public class CompletableTask<T> {
|
||||||
|
@NotNull
|
||||||
|
private final List<Consumer<T>> onSuccess;
|
||||||
|
@NotNull
|
||||||
|
private final List<Consumer<Throwable>> onFailed;
|
||||||
|
@NotNull
|
||||||
|
private volatile State state;
|
||||||
|
private T value;
|
||||||
|
private Throwable throwable;
|
||||||
|
|
||||||
|
public CompletableTask() {
|
||||||
|
state = State.WAITING;
|
||||||
|
onSuccess = new ArrayList<>();
|
||||||
|
onFailed = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static CompletableTask<Void> runAsync(@NotNull RunTask runTask) {
|
||||||
|
CompletableTask<Void> task = new CompletableTask<>();
|
||||||
|
CoreAPI.getInstance().getExecutorService().submit(() -> {
|
||||||
|
try {
|
||||||
|
runTask.run();
|
||||||
|
task.success(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
task.failed(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <T> CompletableTask<T> supplyAsync(@NotNull SupplyTask<T> supplyTask) {
|
||||||
|
CompletableTask<T> task = new CompletableTask<>();
|
||||||
|
CoreAPI.getInstance().getExecutorService().submit(() -> {
|
||||||
|
try {
|
||||||
|
T call = supplyTask.call();
|
||||||
|
task.success(call);
|
||||||
|
} catch (Exception e) {
|
||||||
|
task.failed(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void success(@Nullable T value) {
|
||||||
|
if (state != State.WAITING) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
state = State.SUCCESS;
|
||||||
|
synchronized (this) {
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
for (Consumer<T> success : onSuccess) {
|
||||||
|
try {
|
||||||
|
success.accept(value);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void failed(@Nullable Throwable throwable) {
|
||||||
|
if (state != State.WAITING) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
this.value = null;
|
||||||
|
state = State.FAILED;
|
||||||
|
this.throwable = throwable;
|
||||||
|
synchronized (this) {
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
for (Consumer<Throwable> consumer : onFailed) {
|
||||||
|
try {
|
||||||
|
consumer.accept(throwable);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public CompletableTask<T> onSuccess(@NotNull Consumer<T> consumer) {
|
||||||
|
if (state == State.SUCCESS) {
|
||||||
|
try {
|
||||||
|
consumer.accept(value);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onSuccess.add(consumer);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public CompletableTask<T> onFailed(@NotNull Consumer<Throwable> consumer) {
|
||||||
|
if (state == State.FAILED) {
|
||||||
|
try {
|
||||||
|
consumer.accept(throwable);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onFailed.add(consumer);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void join() throws InterruptedException {
|
||||||
|
if (state == State.WAITING) {
|
||||||
|
synchronized (this) {
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阻塞当前线程,直到该任务完成为止
|
||||||
|
*/
|
||||||
|
public void joinSilent() {
|
||||||
|
try {
|
||||||
|
join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() throws Throwable {
|
||||||
|
join();
|
||||||
|
switch (state) {
|
||||||
|
case SUCCESS:
|
||||||
|
return value;
|
||||||
|
case FAILED:
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getSilent() {
|
||||||
|
try {
|
||||||
|
return get();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getOrDefault(T defaultValue) {
|
||||||
|
T value = getSilent();
|
||||||
|
if (value == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum State {
|
||||||
|
WAITING,
|
||||||
|
SUCCESS,
|
||||||
|
FAILED
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
package cn.hamster3.mc.plugin.currency.async;
|
||||||
|
|
||||||
|
public interface RunTask {
|
||||||
|
void run() throws Exception;
|
||||||
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
package cn.hamster3.mc.plugin.currency.async;
|
||||||
|
|
||||||
|
public interface SupplyTask<T> {
|
||||||
|
T call() throws Exception;
|
||||||
|
}
|
@@ -2,6 +2,7 @@ package cn.hamster3.mc.plugin.currency.command.currency;
|
|||||||
|
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.currency.CurrencyPlugin;
|
import cn.hamster3.mc.plugin.currency.CurrencyPlugin;
|
||||||
|
import cn.hamster3.mc.plugin.currency.api.CurrencyAPI;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyMessage;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyMessage;
|
||||||
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
@@ -28,7 +29,7 @@ public class CurrencyCreateCommand extends ChildCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getUsage() {
|
public @NotNull String getUsage() {
|
||||||
return "create <货币ID> <货币名称> <vault挂接(t|f)> <支持转账(t|f)>";
|
return "create <货币ID> <货币名称> <支持转账(t|f)>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -47,7 +48,7 @@ public class CurrencyCreateCommand extends ChildCommand {
|
|||||||
ParentCurrencyCommand.INSTANCE.sendHelp(sender);
|
ParentCurrencyCommand.INSTANCE.sendHelp(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (CurrencyDataManager.getCurrencyType(args[0]) != null) {
|
if (CurrencyAPI.getCurrencyType(args[0]) != null) {
|
||||||
CurrencyMessage.CURRENCY_TYPE_EXISTED.show(sender);
|
CurrencyMessage.CURRENCY_TYPE_EXISTED.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -61,25 +62,8 @@ public class CurrencyCreateCommand extends ChildCommand {
|
|||||||
CurrencyMessage.CURRENCY_TYPE_NAME_TOO_LONG.show(sender);
|
CurrencyMessage.CURRENCY_TYPE_NAME_TOO_LONG.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
boolean vault;
|
|
||||||
switch (args[2]) {
|
|
||||||
case "t":
|
|
||||||
case "true": {
|
|
||||||
vault = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "f":
|
|
||||||
case "false": {
|
|
||||||
vault = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
CurrencyMessage.CURRENCY_TYPE_VAULT_INPUT_ERROR.show(sender);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean transferable;
|
boolean transferable;
|
||||||
switch (args[3]) {
|
switch (args[2]) {
|
||||||
case "t":
|
case "t":
|
||||||
case "true": {
|
case "true": {
|
||||||
transferable = true;
|
transferable = true;
|
||||||
@@ -97,7 +81,8 @@ public class CurrencyCreateCommand extends ChildCommand {
|
|||||||
}
|
}
|
||||||
CurrencyPlugin.async(() -> {
|
CurrencyPlugin.async(() -> {
|
||||||
try {
|
try {
|
||||||
CurrencyDataManager.updateCurrencyType(new CurrencyType(id, name, vault, transferable), true);
|
CurrencyType type = new CurrencyType(id, name, transferable);
|
||||||
|
CurrencyDataManager.updateCurrencyType(type, true);
|
||||||
CurrencyMessage.CURRENCY_CREATE_SUCCESS.show(sender);
|
CurrencyMessage.CURRENCY_CREATE_SUCCESS.show(sender);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
CurrencyMessage.CURRENCY_CREATE_ERROR.show(sender);
|
CurrencyMessage.CURRENCY_CREATE_ERROR.show(sender);
|
||||||
|
@@ -59,7 +59,7 @@ public class CurrencyGiveCommand extends ChildCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double amount = Double.parseDouble(args[2]);
|
double amount = Double.parseDouble(args[2]);
|
||||||
CurrencyAPI.addPlayerCurrencyAsync(playerInfo.getUuid(), type.getId(), amount);
|
CurrencyAPI.givePlayerCurrency(playerInfo.getUuid(), type.getId(), amount);
|
||||||
CurrencyMessage.CURRENCY_GIVE_SUCCESS.show(sender);
|
CurrencyMessage.CURRENCY_GIVE_SUCCESS.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -5,8 +5,8 @@ import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
|||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
||||||
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||||
import cn.hamster3.mc.plugin.currency.CurrencyPlugin;
|
|
||||||
import cn.hamster3.mc.plugin.currency.api.CurrencyAPI;
|
import cn.hamster3.mc.plugin.currency.api.CurrencyAPI;
|
||||||
|
import cn.hamster3.mc.plugin.currency.async.CompletableTask;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyMessage;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyMessage;
|
||||||
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
@@ -16,7 +16,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -84,18 +83,22 @@ public class CurrencyPayCommand extends ChildCommand {
|
|||||||
CurrencyMessage.PAY_CURRENCY_NOT_TRANSFERABLE.show(sender);
|
CurrencyMessage.PAY_CURRENCY_NOT_TRANSFERABLE.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double hasAmount = CurrencyAPI.getPlayerCurrency(player.getUniqueId(), type.getId());
|
CompletableTask.supplyAsync(() -> {
|
||||||
|
double hasAmount = CurrencyAPI.getPlayerCurrency(player.getUniqueId(), type.getId()).getOrDefault(0D);
|
||||||
if (hasAmount < payAmount) {
|
if (hasAmount < payAmount) {
|
||||||
CurrencyMessage.PAT_BALANCE_NOT_ENOUGH.show(sender,
|
CurrencyMessage.PAT_BALANCE_NOT_ENOUGH.show(sender,
|
||||||
"%has%", String.format("%.2f", hasAmount),
|
"%has%", String.format("%.2f", hasAmount),
|
||||||
"%need%", String.format("%.2f", payAmount)
|
"%need%", String.format("%.2f", payAmount)
|
||||||
);
|
);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
CurrencyPlugin.async(() -> {
|
|
||||||
try {
|
|
||||||
CurrencyDataManager.takePlayerCurrency(player.getUniqueId(), type.getId(), payAmount, true);
|
CurrencyDataManager.takePlayerCurrency(player.getUniqueId(), type.getId(), payAmount, true);
|
||||||
CurrencyDataManager.addPlayerCurrency(targetInfo.getUuid(), type.getId(), payAmount, true);
|
CurrencyDataManager.addPlayerCurrency(targetInfo.getUuid(), type.getId(), payAmount, true);
|
||||||
|
return true;
|
||||||
|
}).onSuccess(success -> {
|
||||||
|
if (!success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
CurrencyMessage.PAY_SUCCESS.show(sender,
|
CurrencyMessage.PAY_SUCCESS.show(sender,
|
||||||
"%type_id%", type.getId(),
|
"%type_id%", type.getId(),
|
||||||
"%type_name%", type.getName(),
|
"%type_name%", type.getName(),
|
||||||
@@ -109,9 +112,9 @@ public class CurrencyPayCommand extends ChildCommand {
|
|||||||
.replace("%to_player_name%", targetInfo.getName())
|
.replace("%to_player_name%", targetInfo.getName())
|
||||||
.replace("%amount%", String.valueOf(payAmount));
|
.replace("%amount%", String.valueOf(payAmount));
|
||||||
BallAPI.getInstance().sendMessageToPlayer(targetInfo.getUuid(), message, true);
|
BallAPI.getInstance().sendMessageToPlayer(targetInfo.getUuid(), message, true);
|
||||||
} catch (SQLException e) {
|
}).onFailed(throwable -> {
|
||||||
e.printStackTrace();
|
CurrencyMessage.ERROR_EXCEPTION.show(player);
|
||||||
}
|
throwable.printStackTrace();
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ public class CurrencyResetCommand extends ChildCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getUsage() {
|
public @NotNull String getUsage() {
|
||||||
return "reset <货币ID> <货币名称> <vault挂接(t|f)> <支持转账(t|f)>";
|
return "reset <货币ID> <货币名称> <支持转账(t|f)>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,25 +62,8 @@ public class CurrencyResetCommand extends ChildCommand {
|
|||||||
CurrencyMessage.CURRENCY_TYPE_NAME_TOO_LONG.show(sender);
|
CurrencyMessage.CURRENCY_TYPE_NAME_TOO_LONG.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
boolean vault;
|
|
||||||
switch (args[2]) {
|
|
||||||
case "t":
|
|
||||||
case "true": {
|
|
||||||
vault = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "f":
|
|
||||||
case "false": {
|
|
||||||
vault = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
CurrencyMessage.CURRENCY_TYPE_VAULT_INPUT_ERROR.show(sender);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean transferable;
|
boolean transferable;
|
||||||
switch (args[3]) {
|
switch (args[2]) {
|
||||||
case "t":
|
case "t":
|
||||||
case "true": {
|
case "true": {
|
||||||
transferable = true;
|
transferable = true;
|
||||||
@@ -98,7 +81,7 @@ public class CurrencyResetCommand extends ChildCommand {
|
|||||||
}
|
}
|
||||||
CurrencyPlugin.async(() -> {
|
CurrencyPlugin.async(() -> {
|
||||||
try {
|
try {
|
||||||
CurrencyDataManager.updateCurrencyType(new CurrencyType(id, name, vault, transferable), true);
|
CurrencyDataManager.updateCurrencyType(new CurrencyType(id, name, transferable), true);
|
||||||
CurrencyMessage.CURRENCY_RESET_SUCCESS.show(sender);
|
CurrencyMessage.CURRENCY_RESET_SUCCESS.show(sender);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
CurrencyMessage.CURRENCY_RESET_ERROR.show(sender);
|
CurrencyMessage.CURRENCY_RESET_ERROR.show(sender);
|
||||||
|
@@ -3,6 +3,7 @@ package cn.hamster3.mc.plugin.currency.command.currency;
|
|||||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
||||||
|
import cn.hamster3.mc.plugin.currency.api.CurrencyAPI;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyMessage;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyMessage;
|
||||||
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
@@ -11,9 +12,12 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@SuppressWarnings("CallToPrintStackTrace")
|
||||||
public class CurrencySeeCommand extends ChildCommand {
|
public class CurrencySeeCommand extends ChildCommand {
|
||||||
public static final CurrencySeeCommand INSTANCE = new CurrencySeeCommand();
|
public static final CurrencySeeCommand INSTANCE = new CurrencySeeCommand();
|
||||||
|
|
||||||
@@ -51,30 +55,31 @@ public class CurrencySeeCommand extends ChildCommand {
|
|||||||
CurrencyMessage.PLAYER_NOT_FOUND.show(sender);
|
CurrencyMessage.PLAYER_NOT_FOUND.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Collection<CurrencyType> types;
|
||||||
if (args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
CurrencyType type = CurrencyDataManager.getCurrencyType(args[1]);
|
CurrencyType type = CurrencyDataManager.getCurrencyType(args[1]);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
CurrencyMessage.CURRENCY_TYPE_NOT_EXIST.show(sender);
|
CurrencyMessage.CURRENCY_TYPE_NOT_EXIST.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double amount = CurrencyDataManager.getPlayerCurrency(playerInfo.getUuid(), type.getId());
|
types = Collections.singleton(type);
|
||||||
|
} else {
|
||||||
|
types = CurrencyDataManager.getCurrencyTypes();
|
||||||
|
}
|
||||||
|
CurrencyAPI.getPlayerCurrency(playerInfo.getUuid())
|
||||||
|
.onSuccess(map -> {
|
||||||
|
for (CurrencyType type : types) {
|
||||||
CurrencyMessage.CURRENCY_SEE_RESULT.show(sender,
|
CurrencyMessage.CURRENCY_SEE_RESULT.show(sender,
|
||||||
"%type_id%", type.getId(),
|
"%type_id%", type.getId(),
|
||||||
"%type_name%", type.getName(),
|
"%type_name%", type.getName(),
|
||||||
"%amount%", String.valueOf(amount),
|
"%amount%", String.valueOf(map.getOrDefault(type.getId(), 0D)),
|
||||||
"%player_name%", playerInfo.getName()
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (CurrencyType type : CurrencyDataManager.getCurrencyTypes()) {
|
|
||||||
double amount = CurrencyDataManager.getPlayerCurrency(playerInfo.getUuid(), type.getId());
|
|
||||||
CurrencyMessage.CURRENCY_SEE_RESULT.show(sender,
|
|
||||||
"%type_id%", type.getId(),
|
|
||||||
"%type_name%", type.getName(),
|
|
||||||
"%amount%", String.valueOf(amount),
|
|
||||||
"%player_name%", playerInfo.getName()
|
"%player_name%", playerInfo.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}).onFailed(throwable -> {
|
||||||
|
CurrencyMessage.ERROR_EXCEPTION_ADMIN.show(sender);
|
||||||
|
throwable.printStackTrace();
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,8 +59,9 @@ public class CurrencySetCommand extends ChildCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double amount = Double.parseDouble(args[2]);
|
double amount = Double.parseDouble(args[2]);
|
||||||
CurrencyAPI.setPlayerCurrencyAsync(playerInfo.getUuid(), type.getId(), amount);
|
CurrencyAPI.setPlayerCurrency(playerInfo.getUuid(), type.getId(), amount)
|
||||||
CurrencyMessage.CURRENCY_SET_SUCCESS.show(sender);
|
.onFailed(throwable -> CurrencyMessage.ERROR_EXCEPTION_ADMIN.show(sender))
|
||||||
|
.onSuccess(unused -> CurrencyMessage.CURRENCY_SET_SUCCESS.show(sender));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,13 +53,13 @@ public class CurrencyTakeCommand extends ChildCommand {
|
|||||||
CurrencyMessage.PLAYER_NOT_FOUND.show(sender);
|
CurrencyMessage.PLAYER_NOT_FOUND.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CurrencyType type = CurrencyDataManager.getCurrencyType(args[1]);
|
CurrencyType type = CurrencyAPI .getCurrencyType(args[1]);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
CurrencyMessage.CURRENCY_TYPE_NOT_EXIST.show(sender);
|
CurrencyMessage.CURRENCY_TYPE_NOT_EXIST.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double amount = Double.parseDouble(args[2]);
|
double amount = Double.parseDouble(args[2]);
|
||||||
CurrencyAPI.takePlayerCurrencyAsync(playerInfo.getUuid(), type.getId(), amount);
|
CurrencyAPI.takePlayerCurrency(playerInfo.getUuid(), type.getId(), amount);
|
||||||
CurrencyMessage.CURRENCY_TAKE_SUCCESS.show(sender);
|
CurrencyMessage.CURRENCY_TAKE_SUCCESS.show(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -4,10 +4,12 @@ import cn.hamster3.mc.plugin.currency.CurrencyPlugin;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class CurrencyConfigManager {
|
||||||
@Getter
|
@Getter
|
||||||
private static boolean enableVaultCommands;
|
private static boolean enableVaultCommands;
|
||||||
@Getter
|
@Getter
|
||||||
|
private static String vaultCurrencyID;
|
||||||
|
@Getter
|
||||||
private static String vaultNamePlural;
|
private static String vaultNamePlural;
|
||||||
@Getter
|
@Getter
|
||||||
private static String vaultNameSingular;
|
private static String vaultNameSingular;
|
||||||
@@ -20,8 +22,8 @@ public class ConfigManager {
|
|||||||
FileConfiguration pluginConfig = plugin.getConfig();
|
FileConfiguration pluginConfig = plugin.getConfig();
|
||||||
|
|
||||||
enableVaultCommands = pluginConfig.getBoolean("enable-vault-commands", true);
|
enableVaultCommands = pluginConfig.getBoolean("enable-vault-commands", true);
|
||||||
|
vaultCurrencyID = pluginConfig.getString("vault-settings.currency-id", "money");
|
||||||
vaultNamePlural = pluginConfig.getString("vault-settings.currency-name-plural", "金币");
|
vaultNamePlural = pluginConfig.getString("vault-settings.currency-name-plural", "金币");
|
||||||
vaultNameSingular = pluginConfig.getString("vault-settings.currency-name-singular", "金币");
|
vaultNameSingular = pluginConfig.getString("vault-settings.currency-name-singular", "金币");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -13,11 +13,10 @@ import java.util.Collection;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
|
|
||||||
public final class CurrencyDataManager {
|
public final class CurrencyDataManager {
|
||||||
private static final ConcurrentMap<String, CurrencyType> CURRENCY_TYPES = new ConcurrentHashMap<>();
|
private static final Map<String, CurrencyType> CURRENCY_TYPES = new ConcurrentHashMap<>();
|
||||||
private static final ConcurrentMap<UUID, ConcurrentMap<String, Double>> PLAYER_DATA = new ConcurrentHashMap<>();
|
private static final Map<UUID, Map<String, Double>> PLAYER_DATA = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private CurrencyDataManager() {
|
private CurrencyDataManager() {
|
||||||
}
|
}
|
||||||
@@ -28,62 +27,59 @@ public final class CurrencyDataManager {
|
|||||||
statement.execute("CREATE TABLE IF NOT EXISTS hamster_currency_type(" +
|
statement.execute("CREATE TABLE IF NOT EXISTS hamster_currency_type(" +
|
||||||
"`id` VARCHAR(36) PRIMARY KEY," +
|
"`id` VARCHAR(36) PRIMARY KEY," +
|
||||||
"`name` VARCHAR(36) NOT NULL," +
|
"`name` VARCHAR(36) NOT NULL," +
|
||||||
"`vault` BOOLEAN NOT NULL," +
|
|
||||||
"`transferable` BOOLEAN NOT NULL" +
|
"`transferable` BOOLEAN NOT NULL" +
|
||||||
") CHARSET utf8mb4;");
|
") CHARSET utf8mb4;");
|
||||||
statement.execute("CREATE TABLE IF NOT EXISTS hamster_currency_data(" +
|
statement.execute("CREATE TABLE IF NOT EXISTS hamster_currency_data(" +
|
||||||
"`uuid` CHAR(36) NOT NULL," +
|
"`uuid` CHAR(36) NOT NULL," +
|
||||||
"`currency` VARCHAR(36) NOT NULL," +
|
"`currency` VARCHAR(36) NOT NULL," +
|
||||||
"`amount` DOUBLE NOT NULL," +
|
"`amount` DOUBLE NOT NULL," +
|
||||||
"UNIQUE KEY `unique_player_currency` (`uuid`, `currency`)" +
|
"PRIMARY KEY `player_currency` (`uuid`, `currency`)" +
|
||||||
") CHARSET utf8mb4;");
|
") CHARSET utf8mb4;");
|
||||||
try (ResultSet set = statement.executeQuery("SELECT * FROM hamster_currency_type;")) {
|
try (ResultSet set = statement.executeQuery("SELECT * FROM hamster_currency_type;")) {
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
CurrencyType type = new CurrencyType(
|
CurrencyType type = new CurrencyType(
|
||||||
set.getString("id"),
|
set.getString("id"),
|
||||||
set.getString("name"),
|
set.getString("name"),
|
||||||
set.getBoolean("vault"),
|
|
||||||
set.getBoolean("transferable")
|
set.getBoolean("transferable")
|
||||||
);
|
);
|
||||||
CURRENCY_TYPES.put(type.getId(), type);
|
CURRENCY_TYPES.put(type.getId(), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try (ResultSet set = statement.executeQuery("SELECT * FROM hamster_currency_data ORDER BY `uuid`;")) {
|
|
||||||
if (set.next()) {
|
|
||||||
setPlayerCurrency(
|
|
||||||
UUID.fromString(set.getString("uuid")),
|
|
||||||
set.getString("currency"),
|
|
||||||
set.getDouble("amount"),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadPlayerData(@NotNull UUID uuid) throws SQLException {
|
public static Map<String, Double> loadPlayerData(@NotNull UUID uuid) throws SQLException {
|
||||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||||
try (PreparedStatement statement = connection.prepareStatement(
|
try (PreparedStatement statement = connection.prepareStatement(
|
||||||
"SELECT currency, amount FROM hamster_currency_data WHERE `uuid`=?;"
|
"SELECT currency, amount FROM hamster_currency_data WHERE `uuid`=?;"
|
||||||
)) {
|
)) {
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
try (ResultSet set = statement.executeQuery()) {
|
try (ResultSet set = statement.executeQuery()) {
|
||||||
Map<String, Double> currency = getPlayerCurrency(uuid);
|
Map<String, Double> playerData = new ConcurrentHashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
currency.put(set.getString("currency"), set.getDouble("amount"));
|
playerData.put(
|
||||||
|
set.getString("currency"),
|
||||||
|
set.getDouble("amount")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
return playerData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Map<String, Double> getPlayerCurrency(@NotNull UUID uuid) {
|
public static Map<String, Double> getPlayerCurrency(@NotNull UUID uuid) throws SQLException {
|
||||||
return PLAYER_DATA.computeIfAbsent(uuid, o -> new ConcurrentHashMap<>());
|
Map<String, Double> map = PLAYER_DATA.get(uuid);
|
||||||
|
if (map == null) {
|
||||||
|
map = loadPlayerData(uuid);
|
||||||
|
PLAYER_DATA.put(uuid, map);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getPlayerCurrency(@NotNull UUID uuid, @NotNull String typeID) {
|
public static double getPlayerCurrency(@NotNull UUID uuid, @NotNull String typeID) throws SQLException {
|
||||||
return getPlayerCurrency(uuid).getOrDefault(typeID, 0d);
|
return getPlayerCurrency(uuid).getOrDefault(typeID, 0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +94,7 @@ public final class CurrencyDataManager {
|
|||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
statement.setString(2, typeID);
|
statement.setString(2, typeID);
|
||||||
statement.setDouble(3, amount);
|
statement.setDouble(3, amount);
|
||||||
|
statement.setDouble(4, amount);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,12 +138,11 @@ public final class CurrencyDataManager {
|
|||||||
if (broadcast) {
|
if (broadcast) {
|
||||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||||
try (PreparedStatement statement = connection.prepareStatement(
|
try (PreparedStatement statement = connection.prepareStatement(
|
||||||
"REPLACE INTO hamster_currency_type VALUES(?, ?, ?, ?);"
|
"REPLACE INTO hamster_currency_type VALUES(?, ?, ?);"
|
||||||
)) {
|
)) {
|
||||||
statement.setString(1, type.getId());
|
statement.setString(1, type.getId());
|
||||||
statement.setString(2, type.getName());
|
statement.setString(2, type.getName());
|
||||||
statement.setBoolean(3, type.isVault());
|
statement.setBoolean(3, type.isTransferable());
|
||||||
statement.setBoolean(4, type.isTransferable());
|
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
}
|
||||||
BallAPI.getInstance().sendBallMessage(CurrencyPlugin.BALL_CHANNEL, "updateCurrencyType", type);
|
BallAPI.getInstance().sendBallMessage(CurrencyPlugin.BALL_CHANNEL, "updateCurrencyType", type);
|
||||||
@@ -164,7 +160,7 @@ public final class CurrencyDataManager {
|
|||||||
statement.setString(1, typeID);
|
statement.setString(1, typeID);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
}
|
||||||
BallAPI.getInstance().sendBallMessage(CurrencyPlugin.BALL_CHANNEL, "setCurrencyType", typeID);
|
BallAPI.getInstance().sendBallMessage(CurrencyPlugin.BALL_CHANNEL, "deleteCurrencyType", typeID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,11 +177,6 @@ public final class CurrencyDataManager {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static CurrencyType getVaultCurrencyType() {
|
public static CurrencyType getVaultCurrencyType() {
|
||||||
for (CurrencyType type : CURRENCY_TYPES.values()) {
|
return getCurrencyType(CurrencyConfigManager.getVaultCurrencyID());
|
||||||
if (type.isVault()) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,9 @@ package cn.hamster3.mc.plugin.currency.core;
|
|||||||
import cn.hamster3.mc.plugin.core.bukkit.api.CoreBukkitAPI;
|
import cn.hamster3.mc.plugin.core.bukkit.api.CoreBukkitAPI;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
|
import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
|
||||||
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||||
import cn.hamster3.mc.plugin.core.lib.net.kyori.adventure.audience.Audience;
|
|
||||||
import cn.hamster3.mc.plugin.core.lib.net.kyori.adventure.text.TextReplacementConfig;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@@ -17,6 +17,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public enum CurrencyMessage {
|
public enum CurrencyMessage {
|
||||||
|
ERROR_EXCEPTION("服务器处理出现异常,请联系服务器管理员反馈问题"),
|
||||||
|
ERROR_EXCEPTION_ADMIN("服务器处理出现异常,请查看服务器后台报错"),
|
||||||
PLAYER_NOT_FOUND("§c未找到该玩家"),
|
PLAYER_NOT_FOUND("§c未找到该玩家"),
|
||||||
CURRENCY_TYPE_NOT_EXIST("§c未找到该货币类型"),
|
CURRENCY_TYPE_NOT_EXIST("§c未找到该货币类型"),
|
||||||
CURRENCY_TYPE_EXISTED("§c该货币 ID 已存在"),
|
CURRENCY_TYPE_EXISTED("§c该货币 ID 已存在"),
|
||||||
|
@@ -14,10 +14,6 @@ public class CurrencyType {
|
|||||||
* 显示名称
|
* 显示名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
/**
|
|
||||||
* 是否挂接到 vault
|
|
||||||
*/
|
|
||||||
private boolean vault;
|
|
||||||
/**
|
/**
|
||||||
* 是否允许转账
|
* 是否允许转账
|
||||||
*/
|
*/
|
||||||
|
@@ -0,0 +1,36 @@
|
|||||||
|
package cn.hamster3.mc.plugin.currency.event;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class CurrencyEvent extends Event {
|
||||||
|
@Getter
|
||||||
|
private static HandlerList handlerList = new HandlerList();
|
||||||
|
@NotNull
|
||||||
|
private UUID uuid;
|
||||||
|
@NotNull
|
||||||
|
private CurrencyType type;
|
||||||
|
private double amount;
|
||||||
|
|
||||||
|
public CurrencyEvent(@NotNull UUID uuid, @NotNull CurrencyType type, double amount) {
|
||||||
|
super(true);
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.type = type;
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlerList;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,12 @@
|
|||||||
|
package cn.hamster3.mc.plugin.currency.event;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CurrencyGiveEvent extends CurrencyEvent {
|
||||||
|
public CurrencyGiveEvent(@NotNull UUID uuid, @NotNull CurrencyType type, double amount) {
|
||||||
|
super(uuid, type, amount);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,12 @@
|
|||||||
|
package cn.hamster3.mc.plugin.currency.event;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CurrencySetEvent extends CurrencyEvent {
|
||||||
|
public CurrencySetEvent(@NotNull UUID uuid, @NotNull CurrencyType type, double amount) {
|
||||||
|
super(uuid, type, amount);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,12 @@
|
|||||||
|
package cn.hamster3.mc.plugin.currency.event;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CurrencyTakeEvent extends CurrencyEvent {
|
||||||
|
public CurrencyTakeEvent(@NotNull UUID uuid, @NotNull CurrencyType type, double amount) {
|
||||||
|
super(uuid, type, amount);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
package cn.hamster3.mc.plugin.currency.hook;
|
package cn.hamster3.mc.plugin.currency.hook;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
import cn.hamster3.mc.plugin.currency.api.CurrencyAPI;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -32,7 +32,7 @@ public final class PlaceholderHook extends PlaceholderExpansion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||||
return String.format("%.2f", CurrencyDataManager.getPlayerCurrency(player.getUniqueId(), params));
|
return String.format("%.2f", CurrencyAPI.getPlayerCurrency(player.getUniqueId(), params).getOrDefault(0D));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,34 +1,24 @@
|
|||||||
package cn.hamster3.mc.plugin.currency.hook;
|
package cn.hamster3.mc.plugin.currency.hook;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.currency.CurrencyPlugin;
|
import cn.hamster3.mc.plugin.currency.api.CurrencyAPI;
|
||||||
import cn.hamster3.mc.plugin.currency.core.ConfigManager;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyConfigManager;
|
||||||
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
||||||
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||||
import net.milkbowl.vault.economy.AbstractEconomy;
|
import net.milkbowl.vault.economy.AbstractEconomy;
|
||||||
import net.milkbowl.vault.economy.EconomyResponse;
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings("CallToPrintStackTrace")
|
|
||||||
public class VaultEconomyHook extends AbstractEconomy {
|
public class VaultEconomyHook extends AbstractEconomy {
|
||||||
private static final EconomyResponse NOT_IMPLEMENTED_RESPONSE =
|
public static final VaultEconomyHook INSTANCE = new VaultEconomyHook();
|
||||||
new EconomyResponse(
|
private static final EconomyResponse NOT_IMPLEMENTED = new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "HamsterCurrency 未实现该功能~");
|
||||||
0,
|
private static final EconomyResponse CURRENCY_TYPE_NOT_FOUND = new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Vault 货币类型设置出错");
|
||||||
0,
|
|
||||||
EconomyResponse.ResponseType.NOT_IMPLEMENTED,
|
|
||||||
"HamsterCurrency 未实现该功能~"
|
|
||||||
);
|
|
||||||
@NotNull
|
|
||||||
private final CurrencyType currencyType;
|
|
||||||
|
|
||||||
public VaultEconomyHook(@NotNull CurrencyType currencyType) {
|
private VaultEconomyHook() {
|
||||||
this.currencyType = currencyType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,23 +43,31 @@ public class VaultEconomyHook extends AbstractEconomy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String currencyNamePlural() {
|
public String currencyNamePlural() {
|
||||||
return ConfigManager.getVaultNamePlural();
|
return CurrencyConfigManager.getVaultNamePlural();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String currencyNameSingular() {
|
public String currencyNameSingular() {
|
||||||
return ConfigManager.getVaultNameSingular();
|
return CurrencyConfigManager.getVaultNameSingular();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBalance(String playerName) {
|
public double getBalance(String playerName) {
|
||||||
UUID uuid = BallAPI.getInstance().getPlayerInfo(playerName).getUuid();
|
UUID uuid = BallAPI.getInstance().getPlayerInfo(playerName).getUuid();
|
||||||
return CurrencyDataManager.getPlayerCurrency(uuid, currencyType.getId());
|
CurrencyType type = CurrencyDataManager.getVaultCurrencyType();
|
||||||
|
if (type == null) {
|
||||||
|
return 0D;
|
||||||
|
}
|
||||||
|
return CurrencyAPI.getPlayerCurrency(uuid, type.getId()).getSilent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBalance(OfflinePlayer player) {
|
public double getBalance(OfflinePlayer player) {
|
||||||
return CurrencyDataManager.getPlayerCurrency(player.getUniqueId(), currencyType.getId());
|
CurrencyType type = CurrencyDataManager.getVaultCurrencyType();
|
||||||
|
if (type == null) {
|
||||||
|
return 0D;
|
||||||
|
}
|
||||||
|
return CurrencyAPI.getPlayerCurrency(player.getUniqueId(), type.getId()).getSilent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -104,37 +102,33 @@ public class VaultEconomyHook extends AbstractEconomy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
||||||
|
CurrencyType type = CurrencyDataManager.getVaultCurrencyType();
|
||||||
|
if (type == null) {
|
||||||
|
return CURRENCY_TYPE_NOT_FOUND;
|
||||||
|
}
|
||||||
UUID uuid = BallAPI.getInstance().getPlayerInfo(playerName).getUuid();
|
UUID uuid = BallAPI.getInstance().getPlayerInfo(playerName).getUuid();
|
||||||
double balance = CurrencyDataManager.getPlayerCurrency(uuid, currencyType.getId());
|
double balance = CurrencyAPI.getPlayerCurrency(uuid, type.getId()).getSilent();
|
||||||
if (balance < amount) {
|
if (balance < amount) {
|
||||||
return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.FAILURE, "余额不足");
|
return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.FAILURE, "余额不足");
|
||||||
}
|
}
|
||||||
double result = balance - amount;
|
double result = balance - amount;
|
||||||
CurrencyPlugin.async(() -> {
|
CurrencyAPI.setPlayerCurrency(uuid, type.getId(), result).joinSilent();
|
||||||
try {
|
|
||||||
CurrencyDataManager.setPlayerCurrency(uuid, currencyType.getId(), result, true);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return new EconomyResponse(amount, result, EconomyResponse.ResponseType.SUCCESS, "扣款成功");
|
return new EconomyResponse(amount, result, EconomyResponse.ResponseType.SUCCESS, "扣款成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse withdrawPlayer(OfflinePlayer player, double amount) {
|
public EconomyResponse withdrawPlayer(OfflinePlayer player, double amount) {
|
||||||
|
CurrencyType type = CurrencyDataManager.getVaultCurrencyType();
|
||||||
|
if (type == null) {
|
||||||
|
return CURRENCY_TYPE_NOT_FOUND;
|
||||||
|
}
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
double balance = CurrencyDataManager.getPlayerCurrency(uuid, currencyType.getId());
|
double balance = CurrencyAPI.getPlayerCurrency(uuid, type.getId()).getSilent();
|
||||||
if (balance < amount) {
|
if (balance < amount) {
|
||||||
return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.FAILURE, "余额不足");
|
return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.FAILURE, "余额不足");
|
||||||
}
|
}
|
||||||
double result = balance - amount;
|
double result = balance - amount;
|
||||||
CurrencyPlugin.async(() -> {
|
CurrencyAPI.setPlayerCurrency(uuid, type.getId(), result).joinSilent();
|
||||||
try {
|
|
||||||
CurrencyDataManager.setPlayerCurrency(uuid, currencyType.getId(), result, true);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return new EconomyResponse(amount, result, EconomyResponse.ResponseType.SUCCESS, "扣款成功");
|
return new EconomyResponse(amount, result, EconomyResponse.ResponseType.SUCCESS, "扣款成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,31 +144,27 @@ public class VaultEconomyHook extends AbstractEconomy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse depositPlayer(String playerName, double amount) {
|
public EconomyResponse depositPlayer(String playerName, double amount) {
|
||||||
UUID uuid = BallAPI.getInstance().getPlayerInfo(playerName).getUuid();
|
CurrencyType type = CurrencyDataManager.getVaultCurrencyType();
|
||||||
double balance = CurrencyDataManager.getPlayerCurrency(uuid, currencyType.getId());
|
if (type == null) {
|
||||||
double result = balance + amount;
|
return CURRENCY_TYPE_NOT_FOUND;
|
||||||
CurrencyPlugin.async(() -> {
|
|
||||||
try {
|
|
||||||
CurrencyDataManager.setPlayerCurrency(uuid, currencyType.getId(), result, true);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
UUID uuid = BallAPI.getInstance().getPlayerInfo(playerName).getUuid();
|
||||||
|
double balance = CurrencyAPI.getPlayerCurrency(uuid, type.getId()).getSilent();
|
||||||
|
double result = balance + amount;
|
||||||
|
CurrencyAPI.setPlayerCurrency(uuid, type.getId(), result).joinSilent();
|
||||||
return new EconomyResponse(amount, result, EconomyResponse.ResponseType.SUCCESS, "");
|
return new EconomyResponse(amount, result, EconomyResponse.ResponseType.SUCCESS, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse depositPlayer(OfflinePlayer player, double amount) {
|
public EconomyResponse depositPlayer(OfflinePlayer player, double amount) {
|
||||||
UUID uuid = player.getUniqueId();
|
CurrencyType type = CurrencyDataManager.getVaultCurrencyType();
|
||||||
double balance = CurrencyDataManager.getPlayerCurrency(uuid, currencyType.getId());
|
if (type == null) {
|
||||||
double result = balance + amount;
|
return CURRENCY_TYPE_NOT_FOUND;
|
||||||
CurrencyPlugin.async(() -> {
|
|
||||||
try {
|
|
||||||
CurrencyDataManager.setPlayerCurrency(uuid, currencyType.getId(), result, true);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
UUID uuid = player.getUniqueId();
|
||||||
|
double balance = CurrencyAPI.getPlayerCurrency(uuid, type.getId()).getSilent();
|
||||||
|
double result = balance + amount;
|
||||||
|
CurrencyAPI.setPlayerCurrency(uuid, type.getId(), result).joinSilent();
|
||||||
return new EconomyResponse(amount, result, EconomyResponse.ResponseType.SUCCESS, "");
|
return new EconomyResponse(amount, result, EconomyResponse.ResponseType.SUCCESS, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,42 +195,42 @@ public class VaultEconomyHook extends AbstractEconomy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse createBank(String name, String player) {
|
public EconomyResponse createBank(String name, String player) {
|
||||||
return NOT_IMPLEMENTED_RESPONSE;
|
return NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse deleteBank(String name) {
|
public EconomyResponse deleteBank(String name) {
|
||||||
return NOT_IMPLEMENTED_RESPONSE;
|
return NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse bankBalance(String name) {
|
public EconomyResponse bankBalance(String name) {
|
||||||
return NOT_IMPLEMENTED_RESPONSE;
|
return NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse bankHas(String name, double amount) {
|
public EconomyResponse bankHas(String name, double amount) {
|
||||||
return NOT_IMPLEMENTED_RESPONSE;
|
return NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse bankWithdraw(String name, double amount) {
|
public EconomyResponse bankWithdraw(String name, double amount) {
|
||||||
return NOT_IMPLEMENTED_RESPONSE;
|
return NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse bankDeposit(String name, double amount) {
|
public EconomyResponse bankDeposit(String name, double amount) {
|
||||||
return NOT_IMPLEMENTED_RESPONSE;
|
return NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse isBankOwner(String name, String playerName) {
|
public EconomyResponse isBankOwner(String name, String playerName) {
|
||||||
return NOT_IMPLEMENTED_RESPONSE;
|
return NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyResponse isBankMember(String name, String playerName) {
|
public EconomyResponse isBankMember(String name, String playerName) {
|
||||||
return NOT_IMPLEMENTED_RESPONSE;
|
return NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -56,7 +56,7 @@ public class BallListener {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "removeCurrencyType": {
|
case "deleteCurrencyType": {
|
||||||
try {
|
try {
|
||||||
CurrencyDataManager.deleteCurrencyType(event.getContentAsString(), false);
|
CurrencyDataManager.deleteCurrencyType(event.getContentAsString(), false);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@@ -8,12 +8,12 @@ vault-settings:
|
|||||||
# Vault 显示货币名称(复数)
|
# Vault 显示货币名称(复数)
|
||||||
currency-name-plural: 金币
|
currency-name-plural: 金币
|
||||||
|
|
||||||
# 是否预加载玩家数据
|
# 是否提前加载玩家数据
|
||||||
# ALL:对于所有货币类型都进行预加载
|
# ALL:对于所有货币类型都进行提前
|
||||||
# VAULT:只对绑定于 VaultAPI 的货币进行预加载
|
# VAULT:只对绑定于 VaultAPI 的货币进行提前
|
||||||
# NONE:对任何货币都不进行预加载
|
# NONE:对任何货币都不进行提前
|
||||||
# 预加载是指服务端启动时将数据库中所有玩家的货币余额都从数据库中加载到内存
|
# 提前是指服务端启动时将数据库中所有玩家的货币余额都从数据库中加载到内存
|
||||||
# 开启预加载时,如果玩家数量过多,则可能会减慢服务器启动速度
|
# 开启提前加载时,如果玩家数量过多,则可能会减慢服务器启动速度
|
||||||
# 一般来说,设置为 VAULT 即可
|
# 一般来说,设置为 VAULT 即可
|
||||||
# 该功能暂未实现
|
# 该功能暂未实现
|
||||||
pre-load-data: VAULT
|
pre-load-data: VAULT
|
||||||
|
Reference in New Issue
Block a user