feat: 新增异步 API
This commit is contained in:
@@ -17,12 +17,17 @@ dependencies {
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.30")
|
||||
|
||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||
compileOnly("cn.hamster3.mc.plugin:core-bukkit:1.2.0")
|
||||
compileOnly("cn.hamster3.mc.plugin:core-bukkit:1.2.1")
|
||||
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:1.5.0")
|
||||
compileOnly("net.milkbowl.vault:VaultAPI:1.7")
|
||||
compileOnly("me.clip:placeholderapi:+")
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
filesMatching("plugin.yml") {
|
||||
|
@@ -33,8 +33,68 @@ public final class CurrencyAPI {
|
||||
return getPlayerCurrency(uuid, currencyID) >= amount;
|
||||
}
|
||||
|
||||
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
|
||||
public static CompletableFuture<Void> setPlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||
public static CompletableFuture<Void> addPlayerCurrencyAsync(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
||||
PointAPI.givePoint(uuid, (int) amount);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
CurrencyPlugin.async(() -> {
|
||||
try {
|
||||
CurrencyDataManager.addPlayerCurrency(uuid, currencyID, amount, true);
|
||||
future.complete(null);
|
||||
} catch (SQLException e) {
|
||||
future.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
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
|
||||
public static CompletableFuture<Void> takePlayerCurrencyAsync(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
||||
PointAPI.takePoint(uuid, (int) amount);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
CurrencyPlugin.async(() -> {
|
||||
try {
|
||||
CurrencyDataManager.takePlayerCurrency(uuid, currencyID, amount, true);
|
||||
future.complete(null);
|
||||
} catch (SQLException e) {
|
||||
future.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
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
|
||||
public static CompletableFuture<Void> setPlayerCurrencyAsync(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
||||
PointAPI.setPoint(uuid, (int) amount);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
@@ -51,46 +111,6 @@ public final class CurrencyAPI {
|
||||
return future;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CompletableFuture<Void> addPlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
||||
PointAPI.givePoint(uuid, (int) amount);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
CurrencyPlugin.async(() -> {
|
||||
try {
|
||||
double currency = CurrencyDataManager.getPlayerCurrency(uuid, currencyID);
|
||||
currency += amount;
|
||||
CurrencyDataManager.setPlayerCurrency(uuid, currencyID, currency, true);
|
||||
future.complete(null);
|
||||
} catch (SQLException e) {
|
||||
future.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CompletableFuture<Void> takePlayerCurrency(@NotNull UUID uuid, @NotNull String currencyID, double amount) {
|
||||
if (currencyID.equals("PlayerPoints") && Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
|
||||
PointAPI.takePoint(uuid, (int) amount);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
CurrencyPlugin.async(() -> {
|
||||
try {
|
||||
double currency = CurrencyDataManager.getPlayerCurrency(uuid, currencyID);
|
||||
currency -= amount;
|
||||
CurrencyDataManager.setPlayerCurrency(uuid, currencyID, currency, true);
|
||||
future.complete(null);
|
||||
} catch (SQLException e) {
|
||||
future.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CurrencyType getCurrencyType(@NotNull String id) {
|
||||
return CurrencyDataManager.getCurrencyType(id);
|
||||
|
@@ -14,6 +14,7 @@ import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class CurrencyCreateCommand extends ChildCommand {
|
||||
public static final CurrencyCreateCommand INSTANCE = new CurrencyCreateCommand();
|
||||
|
||||
@@ -62,11 +63,13 @@ public class CurrencyCreateCommand extends ChildCommand {
|
||||
}
|
||||
boolean vault;
|
||||
switch (args[2]) {
|
||||
case "t": {
|
||||
case "t":
|
||||
case "true": {
|
||||
vault = true;
|
||||
break;
|
||||
}
|
||||
case "f": {
|
||||
case "f":
|
||||
case "false": {
|
||||
vault = false;
|
||||
break;
|
||||
}
|
||||
@@ -77,11 +80,13 @@ public class CurrencyCreateCommand extends ChildCommand {
|
||||
}
|
||||
boolean transferable;
|
||||
switch (args[3]) {
|
||||
case "t": {
|
||||
case "t":
|
||||
case "true": {
|
||||
transferable = true;
|
||||
break;
|
||||
}
|
||||
case "f": {
|
||||
case "f":
|
||||
case "false": {
|
||||
transferable = false;
|
||||
break;
|
||||
}
|
||||
@@ -92,9 +97,10 @@ public class CurrencyCreateCommand extends ChildCommand {
|
||||
}
|
||||
CurrencyPlugin.async(() -> {
|
||||
try {
|
||||
CurrencyDataManager.setCurrencyType(new CurrencyType(id, name, vault, transferable), true);
|
||||
CurrencyDataManager.updateCurrencyType(new CurrencyType(id, name, vault, transferable), true);
|
||||
CurrencyMessage.CURRENCY_CREATE_SUCCESS.show(sender);
|
||||
} catch (SQLException e) {
|
||||
CurrencyMessage.CURRENCY_CREATE_ERROR.show(sender);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
@@ -15,6 +15,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class CurrencyDeleteCommand extends ChildCommand {
|
||||
public static final CurrencyDeleteCommand INSTANCE = new CurrencyDeleteCommand();
|
||||
|
||||
@@ -57,6 +58,7 @@ public class CurrencyDeleteCommand extends ChildCommand {
|
||||
CurrencyDataManager.deleteCurrencyType(type.getId(), true);
|
||||
CurrencyMessage.CURRENCY_DELETE_SUCCESS.show(sender);
|
||||
} catch (SQLException e) {
|
||||
CurrencyMessage.CURRENCY_DELETE_ERROR.show(sender);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
@@ -59,7 +59,7 @@ public class CurrencyGiveCommand extends ChildCommand {
|
||||
return true;
|
||||
}
|
||||
double amount = Double.parseDouble(args[2]);
|
||||
CurrencyAPI.addPlayerCurrency(playerInfo.getUuid(), type.getId(), amount);
|
||||
CurrencyAPI.addPlayerCurrencyAsync(playerInfo.getUuid(), type.getId(), amount);
|
||||
CurrencyMessage.CURRENCY_GIVE_SUCCESS.show(sender);
|
||||
return true;
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class CurrencyPayCommand extends ChildCommand {
|
||||
public static final CurrencyPayCommand INSTANCE = new CurrencyPayCommand();
|
||||
|
||||
@@ -58,8 +59,8 @@ public class CurrencyPayCommand extends ChildCommand {
|
||||
ParentCurrencyCommand.INSTANCE.sendHelp(sender);
|
||||
return true;
|
||||
}
|
||||
BallPlayerInfo playerInfo = BallAPI.getInstance().getPlayerInfo(args[0]);
|
||||
if (playerInfo == null) {
|
||||
BallPlayerInfo targetInfo = BallAPI.getInstance().getPlayerInfo(args[0]);
|
||||
if (targetInfo == null) {
|
||||
CurrencyMessage.PLAYER_NOT_FOUND.show(sender);
|
||||
return true;
|
||||
}
|
||||
@@ -68,14 +69,14 @@ public class CurrencyPayCommand extends ChildCommand {
|
||||
CurrencyMessage.CURRENCY_TYPE_NOT_EXIST.show(sender);
|
||||
return true;
|
||||
}
|
||||
double amount;
|
||||
double payAmount;
|
||||
try {
|
||||
amount = Double.parseDouble(args[2]);
|
||||
payAmount = Double.parseDouble(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
CurrencyMessage.CURRENCY_AMOUNT_NUMBER_INPUT_ERROR.show(sender);
|
||||
return true;
|
||||
}
|
||||
if (amount <= 0) {
|
||||
if (payAmount <= 0) {
|
||||
CurrencyMessage.CURRENCY_AMOUNT_NUMBER_INPUT_ERROR.show(sender);
|
||||
return true;
|
||||
}
|
||||
@@ -83,27 +84,31 @@ public class CurrencyPayCommand extends ChildCommand {
|
||||
CurrencyMessage.PAY_CURRENCY_NOT_TRANSFERABLE.show(sender);
|
||||
return true;
|
||||
}
|
||||
double currency = CurrencyAPI.getPlayerCurrency(player.getUniqueId(), type.getId());
|
||||
if (currency < amount) {
|
||||
CurrencyMessage.PAT_BALANCE_NOT_ENOUGH.show(sender, "%balance%", String.valueOf(currency));
|
||||
double hasAmount = CurrencyAPI.getPlayerCurrency(player.getUniqueId(), type.getId());
|
||||
if (hasAmount < payAmount) {
|
||||
CurrencyMessage.PAT_BALANCE_NOT_ENOUGH.show(sender,
|
||||
"%has%", String.format("%.2f", hasAmount),
|
||||
"%need%", String.format("%.2f", payAmount)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
CurrencyPlugin.async(() -> {
|
||||
try {
|
||||
CurrencyDataManager.setPlayerCurrency(player.getUniqueId(), type.getId(), currency - amount, true);
|
||||
double targetCurrency = CurrencyDataManager.getPlayerCurrency(playerInfo.getUuid(), type.getId());
|
||||
CurrencyDataManager.setPlayerCurrency(playerInfo.getUuid(), type.getId(), targetCurrency + amount, true);
|
||||
CurrencyDataManager.takePlayerCurrency(player.getUniqueId(), type.getId(), payAmount, true);
|
||||
CurrencyDataManager.addPlayerCurrency(targetInfo.getUuid(), type.getId(), payAmount, true);
|
||||
CurrencyMessage.PAY_SUCCESS.show(sender,
|
||||
"%type_id%", type.getId(),
|
||||
"%type_name%", type.getName(),
|
||||
"%to_player_name%", player.getName(),
|
||||
"%amount%", String.valueOf(amount));
|
||||
"%from_player_name%", player.getName(),
|
||||
"%to_player_name%", targetInfo.getName(),
|
||||
"%amount%", String.valueOf(payAmount));
|
||||
DisplayMessage message = CurrencyMessage.PAY_RECEIVED.getMessage().copy()
|
||||
.replace("%type_id%", type.getId())
|
||||
.replace("%type_name%", type.getName())
|
||||
.replace("%from_player_name%", player.getName())
|
||||
.replace("%amount%", String.valueOf(amount));
|
||||
BallAPI.getInstance().sendMessageToPlayer(playerInfo.getUuid(), message, true);
|
||||
.replace("%to_player_name%", targetInfo.getName())
|
||||
.replace("%amount%", String.valueOf(payAmount));
|
||||
BallAPI.getInstance().sendMessageToPlayer(targetInfo.getUuid(), message, true);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class CurrencyResetCommand extends ChildCommand {
|
||||
public static final CurrencyResetCommand INSTANCE = new CurrencyResetCommand();
|
||||
|
||||
@@ -63,11 +64,13 @@ public class CurrencyResetCommand extends ChildCommand {
|
||||
}
|
||||
boolean vault;
|
||||
switch (args[2]) {
|
||||
case "t": {
|
||||
case "t":
|
||||
case "true": {
|
||||
vault = true;
|
||||
break;
|
||||
}
|
||||
case "f": {
|
||||
case "f":
|
||||
case "false": {
|
||||
vault = false;
|
||||
break;
|
||||
}
|
||||
@@ -78,11 +81,13 @@ public class CurrencyResetCommand extends ChildCommand {
|
||||
}
|
||||
boolean transferable;
|
||||
switch (args[3]) {
|
||||
case "t": {
|
||||
case "t":
|
||||
case "true": {
|
||||
transferable = true;
|
||||
break;
|
||||
}
|
||||
case "f": {
|
||||
case "f":
|
||||
case "false": {
|
||||
transferable = false;
|
||||
break;
|
||||
}
|
||||
@@ -93,9 +98,10 @@ public class CurrencyResetCommand extends ChildCommand {
|
||||
}
|
||||
CurrencyPlugin.async(() -> {
|
||||
try {
|
||||
CurrencyDataManager.setCurrencyType(new CurrencyType(id, name, vault, transferable), true);
|
||||
CurrencyDataManager.updateCurrencyType(new CurrencyType(id, name, vault, transferable), true);
|
||||
CurrencyMessage.CURRENCY_RESET_SUCCESS.show(sender);
|
||||
} catch (SQLException e) {
|
||||
CurrencyMessage.CURRENCY_RESET_ERROR.show(sender);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
@@ -59,7 +59,7 @@ public class CurrencySetCommand extends ChildCommand {
|
||||
return true;
|
||||
}
|
||||
double amount = Double.parseDouble(args[2]);
|
||||
CurrencyAPI.setPlayerCurrency(playerInfo.getUuid(), type.getId(), amount);
|
||||
CurrencyAPI.setPlayerCurrencyAsync(playerInfo.getUuid(), type.getId(), amount);
|
||||
CurrencyMessage.CURRENCY_SET_SUCCESS.show(sender);
|
||||
return true;
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ public class CurrencyTakeCommand extends ChildCommand {
|
||||
return true;
|
||||
}
|
||||
double amount = Double.parseDouble(args[2]);
|
||||
CurrencyAPI.takePlayerCurrency(playerInfo.getUuid(), type.getId(), amount);
|
||||
CurrencyAPI.takePlayerCurrencyAsync(playerInfo.getUuid(), type.getId(), amount);
|
||||
CurrencyMessage.CURRENCY_TAKE_SUCCESS.show(sender);
|
||||
return true;
|
||||
}
|
||||
|
@@ -87,13 +87,13 @@ public final class CurrencyDataManager {
|
||||
return getPlayerCurrency(uuid).getOrDefault(typeID, 0d);
|
||||
}
|
||||
|
||||
public static void setPlayerCurrency(@NotNull UUID uuid, @NotNull String typeID, double amount, boolean broadcast) throws SQLException {
|
||||
public static void addPlayerCurrency(@NotNull UUID uuid, @NotNull String typeID, double amount, boolean broadcast) throws SQLException {
|
||||
Map<String, Double> currency = getPlayerCurrency(uuid);
|
||||
currency.put(typeID, amount);
|
||||
currency.put(typeID, currency.getOrDefault(typeID, 0D) + amount);
|
||||
if (broadcast) {
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(
|
||||
"REPLACE INTO hamster_currency_data VALUES(?, ?, ?);"
|
||||
"INSERT INTO hamster_currency_data VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE amount=amount+?;"
|
||||
)) {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, typeID);
|
||||
@@ -105,30 +105,38 @@ public final class CurrencyDataManager {
|
||||
object.addProperty("uuid", uuid.toString());
|
||||
object.addProperty("typeID", typeID);
|
||||
object.addProperty("amount", amount);
|
||||
BallAPI.getInstance().sendBallMessage(CurrencyPlugin.BALL_CHANNEL, "addPlayerCurrency", object);
|
||||
}
|
||||
}
|
||||
|
||||
public static void takePlayerCurrency(@NotNull UUID uuid, @NotNull String typeID, double amount, boolean broadcast) throws SQLException {
|
||||
addPlayerCurrency(uuid, typeID, -amount, broadcast);
|
||||
}
|
||||
|
||||
public static void setPlayerCurrency(@NotNull UUID uuid, @NotNull String typeID, double amount, boolean broadcast) throws SQLException {
|
||||
Map<String, Double> currency = getPlayerCurrency(uuid);
|
||||
currency.put(typeID, amount);
|
||||
if (broadcast) {
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(
|
||||
"INSERT INTO hamster_currency_data VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE amount=?;"
|
||||
)) {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, typeID);
|
||||
statement.setDouble(3, amount);
|
||||
statement.setDouble(4, amount);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("uuid", uuid.toString());
|
||||
object.addProperty("typeID", typeID);
|
||||
object.addProperty("amount", amount);
|
||||
BallAPI.getInstance().sendBallMessage(CurrencyPlugin.BALL_CHANNEL, "setPlayerCurrency", object);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<CurrencyType> getCurrencyTypes() {
|
||||
return CURRENCY_TYPES.values();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CurrencyType getCurrencyType(@NotNull String id) {
|
||||
return CURRENCY_TYPES.get(id);
|
||||
}
|
||||
|
||||
public static CurrencyType getVaultCurrencyType() {
|
||||
for (CurrencyType type : CURRENCY_TYPES.values()) {
|
||||
if (type.isVault()) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setCurrencyType(@NotNull CurrencyType type, boolean broadcast) throws SQLException {
|
||||
public static void updateCurrencyType(@NotNull CurrencyType type, boolean broadcast) throws SQLException {
|
||||
CURRENCY_TYPES.put(type.getId(), type);
|
||||
if (broadcast) {
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
@@ -141,7 +149,7 @@ public final class CurrencyDataManager {
|
||||
statement.setBoolean(4, type.isTransferable());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
BallAPI.getInstance().sendBallMessage(CurrencyPlugin.BALL_CHANNEL, "setCurrencyType", type);
|
||||
BallAPI.getInstance().sendBallMessage(CurrencyPlugin.BALL_CHANNEL, "updateCurrencyType", type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,4 +168,24 @@ public final class CurrencyDataManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<CurrencyType> getCurrencyTypes() {
|
||||
return CURRENCY_TYPES.values();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CurrencyType getCurrencyType(@NotNull String id) {
|
||||
return CURRENCY_TYPES.get(id);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CurrencyType getVaultCurrencyType() {
|
||||
for (CurrencyType type : CURRENCY_TYPES.values()) {
|
||||
if (type.isVault()) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -26,14 +26,17 @@ public enum CurrencyMessage {
|
||||
CURRENCY_TYPE_TRANSFERABLE_INPUT_ERROR("§c货币的 允许转账 类型只能是 't' 或者 'f'"),
|
||||
CURRENCY_AMOUNT_NUMBER_INPUT_ERROR("§c货币金额只能是一个大于 0 的数字"),
|
||||
CURRENCY_CREATE_SUCCESS("货币创建成功"),
|
||||
CURRENCY_CREATE_ERROR("货币创建时出现了一个异常,详情请查看控制台输出"),
|
||||
CURRENCY_RESET_SUCCESS("货币重设成功"),
|
||||
CURRENCY_RESET_ERROR("货币重设时出现了一个异常,详情请查看控制台输出"),
|
||||
CURRENCY_DELETE_SUCCESS("货币删除成功"),
|
||||
CURRENCY_DELETE_ERROR("货币删除时出现了一个异常,详情请查看控制台输出"),
|
||||
CURRENCY_GIVE_SUCCESS("货币给予成功"),
|
||||
CURRENCY_SET_SUCCESS("货币设置成功"),
|
||||
CURRENCY_TAKE_SUCCESS("货币扣除成功"),
|
||||
CURRENCY_RESET_SUCCESS("货币重设成功"),
|
||||
CURRENCY_SEE_RESULT("玩家 %player_name% 的 %type_id% 余额为: %amount% (%type_name%)"),
|
||||
CURRENCY_SEE_RESULT("玩家 %player_name% 的 %type_name%(%type_id%) 余额为: %amount%"),
|
||||
PAY_CURRENCY_NOT_TRANSFERABLE("§c这个货币类型不支持转账"),
|
||||
PAT_BALANCE_NOT_ENOUGH("§c你的余额不够 (剩余 %amount%)"),
|
||||
PAT_BALANCE_NOT_ENOUGH("§c你的余额不够(%has%/%need%)"),
|
||||
PAY_SUCCESS("已向玩家 %to_player_name% 转账 %amount% %type_name%."),
|
||||
PAY_RECEIVED("收到玩家 %from_player_name% 转账 %amount% %type_name%."),
|
||||
;
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package cn.hamster3.mc.plugin.currency.listener;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.data.BallMessage;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.message.MessageReceivedEvent;
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import cn.hamster3.mc.plugin.currency.CurrencyPlugin;
|
||||
import cn.hamster3.mc.plugin.currency.core.CurrencyDataManager;
|
||||
import cn.hamster3.mc.plugin.currency.data.CurrencyType;
|
||||
@@ -24,10 +22,21 @@ public class BallListener {
|
||||
if (!CurrencyPlugin.BALL_CHANNEL.equals(event.getChannel())) {
|
||||
return;
|
||||
}
|
||||
BallMessage message = event.getMessage();
|
||||
switch (message.getAction()) {
|
||||
switch (event.getAction()) {
|
||||
case "addPlayerCurrency": {
|
||||
JsonObject object = event.getContentAsJsonObject();
|
||||
UUID uuid = UUID.fromString(object.get("uuid").getAsString());
|
||||
String typeID = object.get("typeID").getAsString();
|
||||
double amount = object.get("amount").getAsDouble();
|
||||
try {
|
||||
CurrencyDataManager.addPlayerCurrency(uuid, typeID, amount, false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "setPlayerCurrency": {
|
||||
JsonObject object = message.getContentAsJsonObject();
|
||||
JsonObject object = event.getContentAsJsonObject();
|
||||
UUID uuid = UUID.fromString(object.get("uuid").getAsString());
|
||||
String typeID = object.get("typeID").getAsString();
|
||||
double amount = object.get("amount").getAsDouble();
|
||||
@@ -38,10 +47,10 @@ public class BallListener {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "setCurrencyType": {
|
||||
CurrencyType type = CoreAPI.getInstance().getGson().fromJson(message.getContent(), CurrencyType.class);
|
||||
case "updateCurrencyType": {
|
||||
CurrencyType type = event.getContentAs(CurrencyType.class);
|
||||
try {
|
||||
CurrencyDataManager.setCurrencyType(type, false);
|
||||
CurrencyDataManager.updateCurrencyType(type, false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -49,7 +58,7 @@ public class BallListener {
|
||||
}
|
||||
case "removeCurrencyType": {
|
||||
try {
|
||||
CurrencyDataManager.deleteCurrencyType(message.getContentAsString(), false);
|
||||
CurrencyDataManager.deleteCurrencyType(event.getContentAsString(), false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@@ -7,3 +7,13 @@ vault-settings:
|
||||
currency-name-singular: 金币
|
||||
# Vault 显示货币名称(复数)
|
||||
currency-name-plural: 金币
|
||||
|
||||
# 是否预加载玩家数据
|
||||
# ALL:对于所有货币类型都进行预加载
|
||||
# VAULT:只对绑定于 VaultAPI 的货币进行预加载
|
||||
# NONE:对任何货币都不进行预加载
|
||||
# 预加载是指服务端启动时将数据库中所有玩家的货币余额都从数据库中加载到内存
|
||||
# 开启预加载时,如果玩家数量过多,则可能会减慢服务器启动速度
|
||||
# 一般来说,设置为 VAULT 即可
|
||||
# 该功能暂未实现
|
||||
pre-load-data: VAULT
|
||||
|
Reference in New Issue
Block a user