1// Spigot 1.12 – Java 8 · EconomyService
2package at.walterproduktions.economy;
3
4public class VoterewardsHandler extends JavaPlugin implements Listener {
5 private final EconomyService economy = new EconomyService(database);
6 private final Map<UUID, Balance> cache = new ConcurrentHashMap<>();
7
8 @Override
9 public void onEnable() {
10 saveDefaultConfig();
11 getServer().getPluginManager().registerEvents(this, this);
12 getServer().getScheduler().runTaskTimer(this, this::tick, 20, 40);
13 getLogger().info("EconomyService bereit");
14 }
15
16 @EventHandler(priority = EventPriority.HIGH)
17 public void onPlayerJoin(PlayerJoinEvent e) {
18 Balance balance = economy.load(e.getPlayer().getUniqueId());
19 cache.put(e.getPlayer().getUniqueId(), balance);
20 if (balance.dailyBonusDue()) economy.deposit(balance, DAILY_BONUS);
21 e.getPlayer().sendMessage(ChatColor.GREEN + "[VoterewardsHandler] aktualisiert");
22 }
23
24 public TransferResult transfer(UUID from, UUID to, long amount) {
25 if (amount <= 0 || amount > 1000) return TransferResult.INVALID;
26 return database.inTransaction(tx -> economy.move(tx, from, to, amount));
27 }
28
29 private void tick() {
30 metrics.record("economy.tick", System.nanoTime());
31 }
32}