feat: code
This commit is contained in:
@@ -34,7 +34,7 @@ tasks {
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName.set("mineroo-paper.jar")
|
||||
archiveFileName.set("MinerooCore-Paper.jar")
|
||||
}
|
||||
|
||||
withType<Jar> {
|
||||
|
||||
@@ -149,11 +149,17 @@ public class Config {
|
||||
}
|
||||
|
||||
public static class CurrenciesSection {
|
||||
private final boolean enable;
|
||||
private final String primary;
|
||||
public CurrenciesSection(FileConfiguration config) {
|
||||
this.enable = config.getBoolean("currencies.enable", true);
|
||||
this.primary = config.getString("currencies.primary", "money");
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
public String getPrimary() {
|
||||
return primary;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ public class MinerooCore extends JavaPlugin implements Listener {
|
||||
}
|
||||
|
||||
// register vault
|
||||
if (getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") != null
|
||||
&& config.getCurrencies().isEnable()) {
|
||||
MinerooEconomy economy = new MinerooEconomy(this);
|
||||
|
||||
getServer().getServicesManager().register(
|
||||
|
||||
@@ -114,8 +114,6 @@ public class MinerooEconomy extends AbstractEconomy {
|
||||
return has(player, amount);
|
||||
}
|
||||
|
||||
// --- 核心:扣款 (Withdraw) ---
|
||||
|
||||
@Override
|
||||
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
||||
return withdrawPlayer(Bukkit.getOfflinePlayer(playerName), amount);
|
||||
@@ -139,13 +137,20 @@ public class MinerooEconomy extends AbstractEconomy {
|
||||
currency().modifyCachedBalance(player.getUniqueId(), PRIMARY_CURRENCY, -amount);
|
||||
|
||||
long deltaCents = (long) (-amount * 100);
|
||||
currency().ModifyPlayerCurrency(
|
||||
currency()
|
||||
.ModifyPlayerCurrency(
|
||||
deltaCents,
|
||||
player.getUniqueId(),
|
||||
UUID.randomUUID().toString(),
|
||||
PRIMARY_CURRENCY,
|
||||
"Plugin Withdraw"
|
||||
);
|
||||
)
|
||||
.thenAccept(resp -> {
|
||||
if (!resp.isSuccess()) {
|
||||
plugin.getLogger().severe("Sync failed: " + resp.getMessage());
|
||||
currency().modifyCachedBalance(player.getUniqueId(), PRIMARY_CURRENCY, amount);
|
||||
}
|
||||
});
|
||||
|
||||
return new EconomyResponse(
|
||||
amount, balance - amount, EconomyResponse.ResponseType.SUCCESS, null
|
||||
@@ -180,13 +185,20 @@ public class MinerooEconomy extends AbstractEconomy {
|
||||
currency().modifyCachedBalance(player.getUniqueId(), PRIMARY_CURRENCY, amount);
|
||||
|
||||
long deltaCents = (long) (amount * 100);
|
||||
currency().ModifyPlayerCurrency(
|
||||
currency()
|
||||
.ModifyPlayerCurrency(
|
||||
deltaCents,
|
||||
player.getUniqueId(),
|
||||
UUID.randomUUID().toString(),
|
||||
PRIMARY_CURRENCY,
|
||||
"Plugin Deposit"
|
||||
);
|
||||
)
|
||||
.thenAccept(resp -> {
|
||||
if (!resp.isSuccess()) {
|
||||
plugin.getLogger().severe("Sync failed: " + resp.getMessage());
|
||||
currency().modifyCachedBalance(player.getUniqueId(), PRIMARY_CURRENCY, amount);
|
||||
}
|
||||
});
|
||||
|
||||
return new EconomyResponse(
|
||||
amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null
|
||||
|
||||
@@ -13,6 +13,8 @@ server:
|
||||
token: "get token from `mineroo.online/resources/servers` page!"
|
||||
|
||||
currencies:
|
||||
enable: true
|
||||
|
||||
# which currency slug should bound into `VaultApi`
|
||||
primary: "money"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user