Update from Git Manager GUI

This commit is contained in:
2026-02-18 21:46:32 +01:00
parent 1aba2b7e1a
commit 366e0e9826
5 changed files with 1759 additions and 1068 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,412 @@
package com.viper.autosortchest;
import java.sql.*;
import java.util.*;
public class MySQLManager {
public Connection getConnection() {
return connection;
}
private final String host, database, user, password;
private final int port;
private Connection connection;
public MySQLManager(String host, int port, String database, String user, String password) {
this.host = host;
this.port = port;
this.database = database;
this.user = user;
this.password = password;
}
public boolean connect() {
try {
if (connection != null && !connection.isClosed()) return true;
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://" + host + ":" + port + "/" + database
+ "?useSSL=false&autoReconnect=true&characterEncoding=UTF-8&serverTimezone=UTC",
user, password
);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public void disconnect() {
try {
if (connection != null && !connection.isClosed()) connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void setupTables() {
try (Statement st = connection.createStatement()) {
st.execute("CREATE TABLE IF NOT EXISTS asc_players (uuid VARCHAR(36) PRIMARY KEY, name VARCHAR(32));");
st.execute("CREATE TABLE IF NOT EXISTS asc_input_chests (uuid VARCHAR(36), chest_id VARCHAR(36), world VARCHAR(32), x INT, y INT, z INT, `public` BOOLEAN DEFAULT FALSE, PRIMARY KEY(uuid, chest_id));");
st.execute("CREATE TABLE IF NOT EXISTS asc_target_chests (uuid VARCHAR(36), item VARCHAR(64), world VARCHAR(32), x INT, y INT, z INT, `public` BOOLEAN DEFAULT FALSE, PRIMARY KEY(uuid, item));");
st.execute("CREATE TABLE IF NOT EXISTS asc_rest_chests (uuid VARCHAR(36), world VARCHAR(32), x INT, y INT, z INT, `public` BOOLEAN DEFAULT FALSE, PRIMARY KEY(uuid));");
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* Transfer-Tabelle für serverübergreifende Sortierung.
*/
public void setupTransferTable() {
try (Statement st = connection.createStatement()) {
st.execute(
"CREATE TABLE IF NOT EXISTS asc_transfers (" +
" id BIGINT AUTO_INCREMENT PRIMARY KEY," +
" uuid VARCHAR(36) NOT NULL," +
" item VARCHAR(64) NOT NULL," +
" amount INT NOT NULL," +
" target_world VARCHAR(32) NOT NULL," +
" created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP" +
");"
);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void addTransfer(String uuid, String item, int amount, String targetWorld) {
try (PreparedStatement ps = connection.prepareStatement(
"INSERT INTO asc_transfers (uuid, item, amount, target_world) VALUES (?, ?, ?, ?);")) {
ps.setString(1, uuid);
ps.setString(2, item);
ps.setInt(3, amount);
ps.setString(4, targetWorld);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public List<Map<String, Object>> getPendingTransfers(String uuid) {
List<Map<String, Object>> list = new ArrayList<>();
try (PreparedStatement ps = connection.prepareStatement(
"SELECT id, item, amount, target_world FROM asc_transfers WHERE uuid=? ORDER BY created_at ASC;")) {
ps.setString(1, uuid);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("id", rs.getLong("id"));
map.put("item", rs.getString("item"));
map.put("amount", rs.getInt("amount"));
map.put("target_world", rs.getString("target_world"));
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public void deleteTransfer(long id) {
try (PreparedStatement ps = connection.prepareStatement(
"DELETE FROM asc_transfers WHERE id=?;")) {
ps.setLong(1, id);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void updateTransferAmount(long id, int newAmount) {
try (PreparedStatement ps = connection.prepareStatement(
"UPDATE asc_transfers SET amount=? WHERE id=?;")) {
ps.setInt(1, newAmount);
ps.setLong(2, id);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
// --- Spieler ---
public void savePlayer(String uuid, String name) {
try (PreparedStatement ps = connection.prepareStatement(
"REPLACE INTO asc_players (uuid, name) VALUES (?, ?);")) {
ps.setString(1, uuid);
ps.setString(2, name);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* Gibt alle Spieler aus der asc_players-Tabelle zurück.
* Wird für den Export (MySQL → YAML) benötigt.
*
* @return Liste mit uuid und name je Spieler
*/
public List<Map<String, Object>> getAllPlayers() {
List<Map<String, Object>> list = new ArrayList<>();
try (Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("SELECT uuid, name FROM asc_players;")) {
while (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("uuid", rs.getString("uuid"));
map.put("name", rs.getString("name"));
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
// --- Input-Chest ---
public void addInputChest(String uuid, String chestId, String world, int x, int y, int z) {
addInputChest(uuid, chestId, world, x, y, z, false);
}
public void addInputChest(String uuid, String chestId, String world, int x, int y, int z, boolean isPublic) {
try (PreparedStatement ps = connection.prepareStatement(
"REPLACE INTO asc_input_chests (uuid, chest_id, world, x, y, z, `public`) VALUES (?, ?, ?, ?, ?, ?, ?);")) {
ps.setString(1, uuid);
ps.setString(2, chestId);
ps.setString(3, world);
ps.setInt(4, x);
ps.setInt(5, y);
ps.setInt(6, z);
ps.setBoolean(7, isPublic);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void removeInputChest(String uuid, String chestId) {
try (PreparedStatement ps = connection.prepareStatement(
"DELETE FROM asc_input_chests WHERE uuid=? AND chest_id=?;")) {
ps.setString(1, uuid);
ps.setString(2, chestId);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public List<Map<String, Object>> getInputChests(String uuid) {
List<Map<String, Object>> list = new ArrayList<>();
try (PreparedStatement ps = connection.prepareStatement(
"SELECT * FROM asc_input_chests WHERE uuid=?;")) {
ps.setString(1, uuid);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("chest_id", rs.getString("chest_id"));
map.put("world", rs.getString("world"));
map.put("x", rs.getInt("x"));
map.put("y", rs.getInt("y"));
map.put("z", rs.getInt("z"));
map.put("public", rs.getBoolean("public"));
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
// --- Target-Chest ---
public void setTargetChest(String uuid, String item, String world, int x, int y, int z) {
setTargetChest(uuid, item, world, x, y, z, false);
}
public void setTargetChest(String uuid, String item, String world, int x, int y, int z, boolean isPublic) {
try (PreparedStatement ps = connection.prepareStatement(
"REPLACE INTO asc_target_chests (uuid, item, world, x, y, z, `public`) VALUES (?, ?, ?, ?, ?, ?, ?);")) {
ps.setString(1, uuid);
ps.setString(2, item);
ps.setString(3, world);
ps.setInt(4, x);
ps.setInt(5, y);
ps.setInt(6, z);
ps.setBoolean(7, isPublic);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public Map<String, Object> getTargetChest(String uuid, String item) {
try (PreparedStatement ps = connection.prepareStatement(
"SELECT * FROM asc_target_chests WHERE uuid=? AND item=?;")) {
ps.setString(1, uuid);
ps.setString(2, item);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("world", rs.getString("world"));
map.put("x", rs.getInt("x"));
map.put("y", rs.getInt("y"));
map.put("z", rs.getInt("z"));
map.put("public", rs.getBoolean("public"));
return map;
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public void removeTargetChest(String uuid, String item) {
try (PreparedStatement ps = connection.prepareStatement(
"DELETE FROM asc_target_chests WHERE uuid=? AND item=?;")) {
ps.setString(1, uuid);
ps.setString(2, item);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public List<Map<String, Object>> getTargetChests(String uuid) {
List<Map<String, Object>> list = new ArrayList<>();
try (PreparedStatement ps = connection.prepareStatement(
"SELECT * FROM asc_target_chests WHERE uuid=?;")) {
ps.setString(1, uuid);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("item", rs.getString("item"));
map.put("world", rs.getString("world"));
map.put("x", rs.getInt("x"));
map.put("y", rs.getInt("y"));
map.put("z", rs.getInt("z"));
map.put("public", rs.getBoolean("public"));
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
// --- Rest-Chest ---
public void setRestChest(String uuid, String world, int x, int y, int z) {
setRestChest(uuid, world, x, y, z, false);
}
public void setRestChest(String uuid, String world, int x, int y, int z, boolean isPublic) {
try (PreparedStatement ps = connection.prepareStatement(
"REPLACE INTO asc_rest_chests (uuid, world, x, y, z, `public`) VALUES (?, ?, ?, ?, ?, ?);")) {
ps.setString(1, uuid);
ps.setString(2, world);
ps.setInt(3, x);
ps.setInt(4, y);
ps.setInt(5, z);
ps.setBoolean(6, isPublic);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public Map<String, Object> getRestChest(String uuid) {
try (PreparedStatement ps = connection.prepareStatement(
"SELECT * FROM asc_rest_chests WHERE uuid=?;")) {
ps.setString(1, uuid);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("world", rs.getString("world"));
map.put("x", rs.getInt("x"));
map.put("y", rs.getInt("y"));
map.put("z", rs.getInt("z"));
map.put("public", rs.getBoolean("public"));
return map;
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public void removeRestChest(String uuid) {
try (PreparedStatement ps = connection.prepareStatement(
"DELETE FROM asc_rest_chests WHERE uuid=?;")) {
ps.setString(1, uuid);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
// --- Hilfsmethoden für serverCrosslink ---
public List<Map<String, Object>> getAllInputChests() {
List<Map<String, Object>> list = new ArrayList<>();
try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM asc_input_chests;")) {
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("chest_id", rs.getString("chest_id"));
map.put("uuid", rs.getString("uuid"));
map.put("world", rs.getString("world"));
map.put("x", rs.getInt("x"));
map.put("y", rs.getInt("y"));
map.put("z", rs.getInt("z"));
map.put("public", rs.getBoolean("public"));
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public List<Map<String, Object>> getAllTargetChests() {
List<Map<String, Object>> list = new ArrayList<>();
try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM asc_target_chests;")) {
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("item", rs.getString("item"));
map.put("uuid", rs.getString("uuid"));
map.put("world", rs.getString("world"));
map.put("x", rs.getInt("x"));
map.put("y", rs.getInt("y"));
map.put("z", rs.getInt("z"));
map.put("public", rs.getBoolean("public"));
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public Map<String, Object> getAnyRestChest() {
try (PreparedStatement ps = connection.prepareStatement(
"SELECT * FROM asc_rest_chests WHERE public=1 LIMIT 1;")) {
ResultSet rs = ps.executeQuery();
if (rs.next()) {
Map<String, Object> map = new HashMap<>();
map.put("uuid", rs.getString("uuid"));
map.put("world", rs.getString("world"));
map.put("x", rs.getInt("x"));
map.put("y", rs.getInt("y"));
map.put("z", rs.getInt("z"));
map.put("public", rs.getBoolean("public"));
return map;
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -21,7 +21,8 @@ public class UpdateChecker {
public void getVersion(final Consumer<String> consumer) { public void getVersion(final Consumer<String> consumer) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (InputStream is = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId + "/~").openStream(); Scanner scann = new Scanner(is)) { try (InputStream is = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId + "/~").openStream();
Scanner scann = new Scanner(is)) {
if (scann.hasNext()) { if (scann.hasNext()) {
consumer.accept(scann.next()); consumer.accept(scann.next());
} }
@@ -30,4 +31,47 @@ public class UpdateChecker {
} }
}); });
} }
/**
* Vergleicht zwei Versions-Strings semantisch (z.B. "2.0" vs "1.9").
* Gibt true zurück wenn currentVersion NEUER ODER GLEICH latestVersion ist.
* Gibt false zurück wenn latestVersion neuer ist (= Update verfügbar).
*
* Beispiele:
* isCurrentVersionUpToDate("2.0", "1.9") → true (wir sind neuer, kein Update nötig)
* isCurrentVersionUpToDate("1.9", "1.9") → true (gleich, kein Update nötig)
* isCurrentVersionUpToDate("1.8", "1.9") → false (Update verfügbar)
*/
public static boolean isCurrentVersionUpToDate(String currentVersion, String latestVersion) {
try {
String[] current = currentVersion.trim().split("[.\\-]");
String[] latest = latestVersion.trim().split("[.\\-]");
int length = Math.max(current.length, latest.length);
for (int i = 0; i < length; i++) {
int c = i < current.length ? parseVersionPart(current[i]) : 0;
int l = i < latest.length ? parseVersionPart(latest[i]) : 0;
if (c > l) return true; // Aktuelle Version ist neuer → kein Update nötig
if (c < l) return false; // Veröffentlichte Version ist neuer → Update verfügbar
}
return true; // Versionen sind identisch
} catch (Exception e) {
// Im Zweifel: kein Update anzeigen um false-positives zu vermeiden
return true;
}
}
private static int parseVersionPart(String part) {
try {
// Nur die führenden Ziffern parsen (z.B. "1-SNAPSHOT" → 1)
StringBuilder digits = new StringBuilder();
for (char ch : part.toCharArray()) {
if (Character.isDigit(ch)) digits.append(ch);
else break;
}
return digits.length() > 0 ? Integer.parseInt(digits.toString()) : 0;
} catch (NumberFormatException e) {
return 0;
}
}
} }

View File

@@ -9,10 +9,29 @@
# --- GRUNDLEGUNG --- # --- GRUNDLEGUNG ---
# Version der Konfigurationsdatei. Nicht ändern, um Fehler zu vermeiden! # Version der Konfigurationsdatei. Nicht ändern, um Fehler zu vermeiden!
version: "1.8"
version: "2.0"
# Debug-Modus (true = Ausführliche Logs in der Server-Konsole, nur zum Entwickeln nutzen) # Debug-Modus (true = Ausführliche Logs in der Server-Konsole, nur zum Entwickeln nutzen)
debug: false debug: false
# ---------------------------------------------------
# DATENBANK (MySQL/MariaDB) - Optional
# ---------------------------------------------------
# Aktiviere MySQL/MariaDB Speicherung (true/false)
mysql:
enabled: false
host: "localhost"
port: 3306
database: "autosortchest"
user: "autosortchest"
password: "autosortchest"
# Soll serverübergreifendes Sortieren (mit MySQL) erlaubt sein?
server_crosslink: true
# --------------------------------------------------- # ---------------------------------------------------
# SPRACHE (Language) # SPRACHE (Language)
# --------------------------------------------------- # ---------------------------------------------------
@@ -20,9 +39,19 @@ debug: false
# Ändert den Text von /asc help und /asc info # Ändert den Text von /asc help und /asc info
language: "de" language: "de"
# ---------------------------------------------------
# BLACKLIST FÜR WELTEN (Optional)
# ---------------------------------------------------
# Welten, in denen AutoSortChest NICHT funktioniert
world_blacklist:
- "world_nether"
- "world_the_end"
# --------------------------------------------------- # ---------------------------------------------------
# VISUELLE EFFEKTE (PARTIKEL & TÖNE) # VISUELLE EFFEKTE (PARTIKEL & TÖNE)
# --------------------------------------------------- # ---------------------------------------------------
# Einstellungen für den Regenbogen-Effekt beim Sortieren # Einstellungen für den Regenbogen-Effekt beim Sortieren
effects: effects:
# Sollen Effekte angezeigt werden? # Sollen Effekte angezeigt werden?
@@ -33,10 +62,49 @@ effects:
# 'DUST' ist zwingend für den bunten Regenbogen-Effekt im aktuellen Code. # 'DUST' ist zwingend für den bunten Regenbogen-Effekt im aktuellen Code.
type: "DUST" type: "DUST"
# ---------------------------------------------------
# SORTIER-INTERVALL (Ticks)
# ---------------------------------------------------
# Wie oft soll sortiert werden? (1 Tick = 0,05s)
#
# Wähle hier je nach Server-Leistung:
#
# 1 = SEHR SCHNELL (Items verschwinden sofort)
# WARNUNG: Kann bei vielen Truhen Lagg verursachen!
#
# 5 = SCHNELL (Sehr flüssig, gute Balance)
# Empfohlen für schnelle Server.
#
# 10 = FLÜSSIG (0,5s Verzögerung)
# Spart Ressourcen, fühlt sich noch schnell an.
#
# 20 = STANDARD (1 Sekunde)
# Standard-Wert, minimale Last.
#
# 30+ = SPARSAM (>1,5 Sekunden)
# Für sehr große Server mit schwacher Hardware.
#
sort_interval_ticks: 5
sort_interval_ticks: 5
# ---------------------------------------------------
# LIMITS FÜR SORTIERKISTEN (Optional)
# ---------------------------------------------------
# Maximale Anzahl an Sortierkisten pro Spielergruppe
chest_limits:
default: 50
vip: 100
# Beispiel für weitere Gruppen:
# supporter: 150
# admin: 200
# --------------------------------------------------- # ---------------------------------------------------
# SCHILDFARBEN (Farbcodes wie im Chat) # SCHILDFARBEN (Farbcodes wie im Chat)
# &c = Rot, &a = Grün, &e = Gelb, &6 = Gold, &f = Weiß, &0 = Schwarz # &c = Rot, &a = Grün, &e = Gelb, &6 = Gold, &f = Weiß, &0 = Schwarz
# --------------------------------------------------- # ---------------------------------------------------
sign-colors: sign-colors:
# Farben für die Eingangstruhe ([asc] / input) # Farben für die Eingangstruhe ([asc] / input)
input: input:
@@ -69,6 +137,7 @@ sign-colors:
# SYSTEM NACHRICHTEN (Spieler-Feedback) # SYSTEM NACHRICHTEN (Spieler-Feedback)
# Platzhalter: %player%, %item%, %x%, %y%, %z%, %mode% # Platzhalter: %player%, %item%, %x%, %y%, %z%, %mode%
# --------------------------------------------------- # ---------------------------------------------------
messages: messages:
# --- FEHLERMELDUNGEN --- # --- FEHLERMELDUNGEN ---
no-chest-near-sign: "&cKeine Truhe in der Nähe des Schildes!" no-chest-near-sign: "&cKeine Truhe in der Nähe des Schildes!"
@@ -88,4 +157,5 @@ messages:
target-chest-full: "&cZieltruhe für %item% ist voll! Koordinaten: (%x%, %y%, %z%)" target-chest-full: "&cZieltruhe für %item% ist voll! Koordinaten: (%x%, %y%, %z%)"
mode-changed: "&aModus gewechselt: &e%mode%" mode-changed: "&aModus gewechselt: &e%mode%"
mode-public: "&aÖffentlich" mode-public: "&aÖffentlich"
mode-private: "&cPrivat" mode-private: "&cPrivat"

View File

@@ -1,5 +1,5 @@
name: AutoSortChest name: AutoSortChest
version: 1.9 version: 2.0
main: com.viper.autosortchest.Main main: com.viper.autosortchest.Main
api-version: 1.21 api-version: 1.21
authors: [M_Viper] authors: [M_Viper]
@@ -7,12 +7,18 @@ description: Ein Plugin zum automatischen Sortieren von Items in Truhen
commands: commands:
asc: asc:
description: AutoSortChest Befehle description: AutoSortChest Befehle
usage: /<command> [help|info|reload] usage: /<command> [help|info|reload|import|export]
aliases: [autosortchest] aliases: [autosortchest]
permissions: permissions:
autosortchest.reload: autosortchest.reload:
description: Erlaubt das Neuladen der Konfiguration mit /asc reload description: Erlaubt das Neuladen der Konfiguration mit /asc reload
default: op default: op
autosortchest.import:
description: Erlaubt den Import von players.yml nach MySQL mit /asc import
default: op
autosortchest.export:
description: Erlaubt den Export von MySQL nach players.yml mit /asc export
default: op
autosortchest.bypass: autosortchest.bypass:
description: Erlaubt das Abbauen von ASC-Schildern ohne Shift-Taste und unabhängig vom Besitzer description: Erlaubt das Abbauen von ASC-Schildern ohne Shift-Taste und unabhängig vom Besitzer
default: op default: op