Add newer CoalGov update

This commit is contained in:
CoalGov Deploy
2026-07-11 02:06:53 +00:00
parent dd69ab17a5
commit 963cdd2d9d
39 changed files with 2763 additions and 43 deletions

View File

@@ -28,7 +28,7 @@ public final class CoalCommand implements CommandExecutor {
return true;
}
if (args.length == 0) {
player.sendMessage(plugin.messages().text("&eUsage: /coal <balance|deposit|withdraw|pay|fines>"));
player.sendMessage(plugin.messages().text("&eUsage: /coal <balance|deposit|withdraw|pay|fines|networth|lottery>"));
return true;
}
try {
@@ -39,7 +39,9 @@ public final class CoalCommand implements CommandExecutor {
case "withdraw" -> withdraw(player, args);
case "pay" -> pay(player, args);
case "fines" -> fines(player, args);
default -> player.sendMessage(plugin.messages().text("&eUsage: /coal <balance|deposit|withdraw|pay|fines>"));
case "networth" -> networth(player);
case "lottery" -> lottery(player, args);
default -> player.sendMessage(plugin.messages().text("&eUsage: /coal <balance|deposit|withdraw|pay|fines|networth|lottery>"));
}
} catch (SQLException exception) {
plugin.getLogger().warning("Coal command failed: " + exception.getMessage());
@@ -52,6 +54,29 @@ public final class CoalCommand implements CommandExecutor {
player.sendMessage(plugin.messages().text("&eBalance: &f" + CoalMoney.format(plugin.economyService().balance(player.getUniqueId()))));
}
private void networth(Player player) throws SQLException {
long balance = plugin.economyService().balance(player.getUniqueId());
long inventory = 0L;
for (ItemStack item : player.getInventory().getStorageContents()) {
if (item == null || item.getType().isAir()) {
continue;
}
Double price = plugin.marketService().basePrices().get(item.getType());
if (price != null) {
inventory += CoalMoney.fromCoal(price * item.getAmount());
}
}
long claims = plugin.claimService().list(player.getUniqueId()).stream()
.mapToLong(plugin.claimService()::claimPurchaseCost)
.filter(value -> value > 0L)
.sum();
long total = balance + inventory + claims;
player.sendMessage(plugin.messages().text("&eNet worth: &f" + CoalMoney.format(total)));
player.sendMessage(plugin.messages().text("&7Balance: &f" + CoalMoney.format(balance)
+ " &7Inventory: &f" + CoalMoney.format(inventory)
+ " &7Claims: &f" + CoalMoney.format(claims)));
}
private void deposit(Player player) throws SQLException {
boolean coalEnabled = plugin.getConfig().getBoolean("economy.deposit_coal", true);
boolean blocksEnabled = plugin.getConfig().getBoolean("economy.deposit_coal_blocks", true);
@@ -177,6 +202,53 @@ public final class CoalCommand implements CommandExecutor {
player.sendMessage(plugin.messages().text("&eUsage: /coal fines [list|pay <id|all>]"));
}
private void lottery(Player player, String[] args) throws SQLException {
if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase("status"))) {
var status = plugin.lotteryService().status();
player.sendMessage(plugin.messages().text("&eLottery round #" + status.round()
+ ": &f" + status.tickets() + " &etickets from &f" + status.players()
+ " &eplayers. Pot: &f" + CoalMoney.format(status.pot())));
return;
}
if (args.length == 2 && args[1].equalsIgnoreCase("buy")) {
buyLottery(player, 1);
return;
}
if (args.length == 3 && args[1].equalsIgnoreCase("buy")) {
int tickets = (int) parsePositive(args[2]);
buyLottery(player, tickets);
return;
}
if (args.length == 2 && args[1].equalsIgnoreCase("draw")) {
if (!player.hasPermission("coalgov.admin")) {
player.sendMessage(plugin.messages().text("&cOnly CoalGov admins can draw the lottery."));
return;
}
var result = plugin.lotteryService().draw();
if (!result.success()) {
player.sendMessage(plugin.messages().text("&c" + result.message()));
return;
}
Bukkit.broadcastMessage(plugin.messages().text("&6Lottery round #" + result.round()
+ " won by &f" + result.winnerName()
+ " &6for &f" + CoalMoney.format(result.pot())
+ " &6from &f" + result.tickets() + " &6tickets."));
return;
}
player.sendMessage(plugin.messages().text("&eUsage: /coal lottery <status|buy [tickets]|draw>"));
}
private void buyLottery(Player player, int tickets) throws SQLException {
var result = plugin.lotteryService().buy(player, tickets);
if (!result.success()) {
player.sendMessage(plugin.messages().text("&c" + result.message()));
return;
}
player.sendMessage(plugin.messages().text("&aBought &f" + result.tickets()
+ " &alottery ticket(s) for &f" + CoalMoney.format(result.cost())
+ " &ain round #" + result.round() + "."));
}
private boolean canFitCoal(Player player, long amount) {
if (amount > Integer.MAX_VALUE) {
return false;