feat: code

This commit is contained in:
2026-02-12 00:29:35 -08:00
parent ce7b7f50ab
commit bade441923
5 changed files with 39 additions and 18 deletions

View File

@@ -34,7 +34,7 @@ tasks {
} }
shadowJar { shadowJar {
archiveFileName.set("mineroo-paper.jar") archiveFileName.set("MinerooCore-Paper.jar")
} }
withType<Jar> { withType<Jar> {

View File

@@ -149,11 +149,17 @@ public class Config {
} }
public static class CurrenciesSection { public static class CurrenciesSection {
private final boolean enable;
private final String primary; private final String primary;
public CurrenciesSection(FileConfiguration config) { public CurrenciesSection(FileConfiguration config) {
this.enable = config.getBoolean("currencies.enable", true);
this.primary = config.getString("currencies.primary", "money"); this.primary = config.getString("currencies.primary", "money");
} }
public boolean isEnable() {
return enable;
}
public String getPrimary() { public String getPrimary() {
return primary; return primary;
} }

View File

@@ -54,7 +54,8 @@ public class MinerooCore extends JavaPlugin implements Listener {
} }
// register vault // register vault
if (getServer().getPluginManager().getPlugin("Vault") != null) { if (getServer().getPluginManager().getPlugin("Vault") != null
&& config.getCurrencies().isEnable()) {
MinerooEconomy economy = new MinerooEconomy(this); MinerooEconomy economy = new MinerooEconomy(this);
getServer().getServicesManager().register( getServer().getServicesManager().register(

View File

@@ -114,8 +114,6 @@ public class MinerooEconomy extends AbstractEconomy {
return has(player, amount); return has(player, amount);
} }
// --- 核心:扣款 (Withdraw) ---
@Override @Override
public EconomyResponse withdrawPlayer(String playerName, double amount) { public EconomyResponse withdrawPlayer(String playerName, double amount) {
return withdrawPlayer(Bukkit.getOfflinePlayer(playerName), amount); return withdrawPlayer(Bukkit.getOfflinePlayer(playerName), amount);
@@ -139,13 +137,20 @@ public class MinerooEconomy extends AbstractEconomy {
currency().modifyCachedBalance(player.getUniqueId(), PRIMARY_CURRENCY, -amount); currency().modifyCachedBalance(player.getUniqueId(), PRIMARY_CURRENCY, -amount);
long deltaCents = (long) (-amount * 100); long deltaCents = (long) (-amount * 100);
currency().ModifyPlayerCurrency( currency()
deltaCents, .ModifyPlayerCurrency(
player.getUniqueId(), deltaCents,
UUID.randomUUID().toString(), player.getUniqueId(),
PRIMARY_CURRENCY, UUID.randomUUID().toString(),
"Plugin Withdraw" 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( return new EconomyResponse(
amount, balance - amount, EconomyResponse.ResponseType.SUCCESS, null amount, balance - amount, EconomyResponse.ResponseType.SUCCESS, null
@@ -180,13 +185,20 @@ public class MinerooEconomy extends AbstractEconomy {
currency().modifyCachedBalance(player.getUniqueId(), PRIMARY_CURRENCY, amount); currency().modifyCachedBalance(player.getUniqueId(), PRIMARY_CURRENCY, amount);
long deltaCents = (long) (amount * 100); long deltaCents = (long) (amount * 100);
currency().ModifyPlayerCurrency( currency()
deltaCents, .ModifyPlayerCurrency(
player.getUniqueId(), deltaCents,
UUID.randomUUID().toString(), player.getUniqueId(),
PRIMARY_CURRENCY, UUID.randomUUID().toString(),
"Plugin Deposit" 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( return new EconomyResponse(
amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null

View File

@@ -13,6 +13,8 @@ server:
token: "get token from `mineroo.online/resources/servers` page!" token: "get token from `mineroo.online/resources/servers` page!"
currencies: currencies:
enable: true
# which currency slug should bound into `VaultApi` # which currency slug should bound into `VaultApi`
primary: "money" primary: "money"