diff --git a/src/main/java/net/viper/status/modules/economy/EconomyManager.java b/src/main/java/net/viper/status/modules/economy/EconomyManager.java deleted file mode 100644 index a57e03a..0000000 --- a/src/main/java/net/viper/status/modules/economy/EconomyManager.java +++ /dev/null @@ -1,109 +0,0 @@ -package net.viper.status.modules.economy; - -import net.md_5.bungee.api.plugin.Plugin; - -import java.util.UUID; - -/** - * Kein Cache – jeder Zugriff geht direkt in die Datenbank. - * Damit ist der Kontostand immer aktuell, egal von welchem Server - * er zuletzt geändert wurde (SurvivalPlus, CMI, etc.). - */ -public class EconomyManager { - - private final Plugin plugin; - private final EconomyDatabase db; - private final double startBalance; - - public EconomyManager(Plugin plugin, EconomyDatabase db, double startBalance) { - this.plugin = plugin; - this.db = db; - this.startBalance = startBalance; - } - - public void saveNameMapping(UUID uuid, String name) { - db.saveNameMapping(uuid, name); - } - - public UUID resolveUUID(String name) { - // 1. Online-Spieler auf dem Proxy (case-insensitive) - for (net.md_5.bungee.api.connection.ProxiedPlayer p : plugin.getProxy().getPlayers()) { - if (p.getName().equalsIgnoreCase(name)) return p.getUniqueId(); - } - // 2. Eigene bc_player_names Tabelle - UUID uuid = db.findUUIDByNameOwn(name); - if (uuid != null) return uuid; - // 3. CMI_users Fallback - uuid = db.findUUIDByName(name); - if (uuid != null) return uuid; - // 4. Mojang API als letzter Ausweg - return lookupMojang(name); - } - - /** UUID via Mojang API holen (nur wenn alle lokalen Lookups fehlschlagen). */ - private UUID lookupMojang(String name) { - try { - java.net.URL url = new java.net.URL("https://api.mojang.com/users/profiles/minecraft/" + name); - java.net.HttpURLConnection con = (java.net.HttpURLConnection) url.openConnection(); - con.setConnectTimeout(3000); - con.setReadTimeout(3000); - con.setRequestMethod("GET"); - if (con.getResponseCode() != 200) return null; - java.io.BufferedReader br = new java.io.BufferedReader( - new java.io.InputStreamReader(con.getInputStream())); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = br.readLine()) != null) sb.append(line); - br.close(); - String json = sb.toString(); - int idIdx = json.indexOf("\"id\":\""); - if (idIdx < 0) return null; - String raw = json.substring(idIdx + 6, idIdx + 38); - String formatted = raw.replaceFirst( - "(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"); - UUID uuid = UUID.fromString(formatted); - // Für künftige Lookups speichern - db.saveNameMapping(uuid, name); - plugin.getLogger().info("[Economy] Mojang-Lookup: " + name + " → " + uuid); - return uuid; - } catch (Exception e) { - plugin.getLogger().warning("[Economy] Mojang-Lookup fehlgeschlagen für " + name + ": " + e.getMessage()); - return null; - } - } - - public double getBalance(UUID uuid) { - double bal = db.load(uuid); - if (bal < 0) { - // Neuer Spieler – Startkonto anlegen - db.save(uuid, startBalance); - return startBalance; - } - return bal; - } - - public void setBalance(UUID uuid, double amount) { - db.save(uuid, Math.max(0.0, amount)); - } - - public boolean deposit(UUID uuid, double amount) { - if (amount <= 0) return false; - double current = db.load(uuid); - if (current < 0) current = startBalance; - db.save(uuid, current + amount); - return true; - } - - public boolean withdraw(UUID uuid, double amount) { - if (amount <= 0) return false; - double current = db.load(uuid); - if (current < 0) current = 0; - if (current < amount) return false; - db.save(uuid, current - amount); - return true; - } - - public boolean hasAccount(UUID uuid) { - return db.load(uuid) >= 0; - } -}