src/main/java/com/viper/autosortchest/Main.java aktualisiert
This commit is contained in:
@@ -42,7 +42,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
private final Map<UUID, Map<Material, Long>> fullChestMessageTracker = new HashMap<>();
|
private final Map<UUID, Map<Material, Long>> fullChestMessageTracker = new HashMap<>();
|
||||||
private static final long MESSAGE_COOLDOWN = 5 * 60 * 1000; // 5 Minuten in Millisekunden
|
private static final long MESSAGE_COOLDOWN = 5 * 60 * 1000; // 5 Minuten in Millisekunden
|
||||||
private static final String CONFIG_VERSION = "1.5";
|
private static final String CONFIG_VERSION = "1.7"; // Version erhöht für das Update
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -83,6 +83,9 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
updateConfig();
|
updateConfig();
|
||||||
updateExistingSigns();
|
updateExistingSigns();
|
||||||
|
|
||||||
|
// ERWEITERUNG: Migration alter Daten in das neue Listen-System
|
||||||
|
migrateInputChests();
|
||||||
|
|
||||||
// ASCII ART LOGO
|
// ASCII ART LOGO
|
||||||
getLogger().info("");
|
getLogger().info("");
|
||||||
getLogger().info(" ___ _ _____ _ _____ _ _ ");
|
getLogger().info(" ___ _ _____ _ _____ _ _ ");
|
||||||
@@ -102,7 +105,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
getLogger().info("AutoSortChest Plugin deaktiviert!");
|
getLogger().info("AutoSortChest Plugin deaktiviert!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- NEUE HILFSMETHODE FÜR DOPPELTRUHEN ---
|
// --- HILFSMETHODE FÜR DOPPELTRUHEN ---
|
||||||
private List<Block> getChestBlocks(Chest chest) {
|
private List<Block> getChestBlocks(Chest chest) {
|
||||||
List<Block> blocks = new ArrayList<>();
|
List<Block> blocks = new ArrayList<>();
|
||||||
InventoryHolder holder = chest.getInventory().getHolder();
|
InventoryHolder holder = chest.getInventory().getHolder();
|
||||||
@@ -417,6 +420,55 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- ERWEITERUNG: Hilfsmethode zum Laden von Location aus einem beliebigen Pfad ---
|
||||||
|
private Location getLocationFromPath(String path) {
|
||||||
|
String worldName = playerData.getString(path + ".world");
|
||||||
|
World world = getServer().getWorld(worldName);
|
||||||
|
if (world == null) return null;
|
||||||
|
int x = playerData.getInt(path + ".x");
|
||||||
|
int y = playerData.getInt(path + ".y");
|
||||||
|
int z = playerData.getInt(path + ".z");
|
||||||
|
return new Location(world, x, y, z);
|
||||||
|
}
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
// --- ERWEITERUNG: Methode zum Migrieren alter Daten ---
|
||||||
|
private void migrateInputChests() {
|
||||||
|
if (playerData.getConfigurationSection("players") == null) return;
|
||||||
|
boolean migrated = false;
|
||||||
|
|
||||||
|
for (String uuidString : playerData.getConfigurationSection("players").getKeys(false)) {
|
||||||
|
String oldPath = "players." + uuidString + ".input-chest";
|
||||||
|
// Prüfen, ob der alte Eintrag existiert
|
||||||
|
if (playerData.contains(oldPath)) {
|
||||||
|
try {
|
||||||
|
UUID uuid = UUID.fromString(uuidString);
|
||||||
|
String world = playerData.getString(oldPath + ".world");
|
||||||
|
int x = playerData.getInt(oldPath + ".x");
|
||||||
|
int y = playerData.getInt(oldPath + ".y");
|
||||||
|
int z = playerData.getInt(oldPath + ".z");
|
||||||
|
World w = Bukkit.getWorld(world);
|
||||||
|
|
||||||
|
if (w != null) {
|
||||||
|
Location loc = new Location(w, x, y, z);
|
||||||
|
// Neue Methode aufrufen, die in die Liste speichert
|
||||||
|
addInputChestLocation(uuid, loc);
|
||||||
|
// Alten Eintrag löschen
|
||||||
|
playerData.set(oldPath, null);
|
||||||
|
migrated = true;
|
||||||
|
getLogger().info("Eingangstruhe für Spieler " + uuidString + " in neues System migriert.");
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
getLogger().warning("Ungültige UUID beim Migrieren: " + uuidString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (migrated) {
|
||||||
|
savePlayerData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
private void updateExistingSigns() {
|
private void updateExistingSigns() {
|
||||||
if (playerData == null) {
|
if (playerData == null) {
|
||||||
getLogger().warning("playerData ist null. Kann bestehende Schilder nicht aktualisieren.");
|
getLogger().warning("playerData ist null. Kann bestehende Schilder nicht aktualisieren.");
|
||||||
@@ -436,27 +488,28 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = "players." + uuidString;
|
String basePath = "players." + uuidString;
|
||||||
|
|
||||||
// Eingangstruhe
|
// --- ERWEITERUNG: Eingangstruhe (Jetzt Liste) ---
|
||||||
String inputPath = path + ".input-chest";
|
String inputListPath = basePath + ".input-chests";
|
||||||
if (playerData.contains(inputPath)) {
|
// Fallback für altes Format (sollte durch Migration eigentlich weg sein, aber zur Sicherheit)
|
||||||
String worldName = playerData.getString(inputPath + ".world");
|
String oldInputPath = basePath + ".input-chest";
|
||||||
World world = getServer().getWorld(worldName);
|
|
||||||
if (world == null) {
|
List<Location> inputLocs = new ArrayList<>();
|
||||||
getLogger().warning("Welt " + worldName + " für Eingangstruhe von Spieler UUID " + uuidString + " nicht gefunden");
|
|
||||||
continue;
|
if (playerData.contains(inputListPath)) {
|
||||||
|
for (String chestId : playerData.getConfigurationSection(inputListPath).getKeys(false)) {
|
||||||
|
Location loc = getLocationFromPath(inputListPath + "." + chestId);
|
||||||
|
if (loc != null) inputLocs.add(loc);
|
||||||
}
|
}
|
||||||
int x = playerData.getInt(inputPath + ".x");
|
} else if (playerData.contains(oldInputPath)) {
|
||||||
int y = playerData.getInt(inputPath + ".y");
|
Location loc = getLocationFromPath(oldInputPath);
|
||||||
int z = playerData.getInt(inputPath + ".z");
|
if (loc != null) inputLocs.add(loc);
|
||||||
Location chestLocation = new Location(world, x, y, z);
|
}
|
||||||
|
|
||||||
|
for (Location chestLocation : inputLocs) {
|
||||||
Block chestBlock = chestLocation.getBlock();
|
Block chestBlock = chestLocation.getBlock();
|
||||||
|
if (!(chestBlock.getState() instanceof Chest)) continue;
|
||||||
if (!(chestBlock.getState() instanceof Chest)) {
|
|
||||||
getLogger().warning("Eingangstruhe bei " + chestLocation + " ist keine Truhe");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Block> blocks = getChestBlocks((Chest) chestBlock.getState());
|
List<Block> blocks = getChestBlocks((Chest) chestBlock.getState());
|
||||||
for (Block b : blocks) {
|
for (Block b : blocks) {
|
||||||
@@ -484,22 +537,16 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ----------------------------------------------
|
||||||
|
|
||||||
// Zieltruhen
|
// Zieltruhen
|
||||||
String targetPath = path + ".target-chests";
|
String targetPath = basePath + ".target-chests";
|
||||||
if (playerData.contains(targetPath)) {
|
if (playerData.contains(targetPath)) {
|
||||||
for (String itemType : playerData.getConfigurationSection(targetPath).getKeys(false)) {
|
for (String itemType : playerData.getConfigurationSection(targetPath).getKeys(false)) {
|
||||||
String targetChestPath = targetPath + "." + itemType;
|
String targetChestPath = targetPath + "." + itemType;
|
||||||
String worldName = playerData.getString(targetChestPath + ".world");
|
Location chestLocation = getLocationFromPath(targetChestPath);
|
||||||
World world = getServer().getWorld(worldName);
|
if (chestLocation == null) continue;
|
||||||
if (world == null) {
|
|
||||||
getLogger().warning("Welt " + worldName + " für Zieltruhe von Item " + itemType + " nicht gefunden");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int x = playerData.getInt(targetChestPath + ".x");
|
|
||||||
int y = playerData.getInt(targetChestPath + ".y");
|
|
||||||
int z = playerData.getInt(targetChestPath + ".z");
|
|
||||||
Location chestLocation = new Location(world, x, y, z);
|
|
||||||
Block chestBlock = chestLocation.getBlock();
|
Block chestBlock = chestLocation.getBlock();
|
||||||
|
|
||||||
if (!(chestBlock.getState() instanceof Chest)) {
|
if (!(chestBlock.getState() instanceof Chest)) {
|
||||||
@@ -543,18 +590,11 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- NEU: Rest-Truhe aktualisieren ---
|
// --- NEU: Rest-Truhe aktualisieren ---
|
||||||
String restPath = path + ".rest-chest";
|
String restPath = basePath + ".rest-chest";
|
||||||
if (playerData.contains(restPath)) {
|
if (playerData.contains(restPath)) {
|
||||||
String worldName = playerData.getString(restPath + ".world");
|
Location chestLocation = getLocationFromPath(restPath);
|
||||||
World world = getServer().getWorld(worldName);
|
if (chestLocation == null) continue;
|
||||||
if (world == null) {
|
|
||||||
getLogger().warning("Welt " + worldName + " für Rest-Truhe von UUID " + uuidString + " nicht gefunden");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int x = playerData.getInt(restPath + ".x");
|
|
||||||
int y = playerData.getInt(restPath + ".y");
|
|
||||||
int z = playerData.getInt(restPath + ".z");
|
|
||||||
Location chestLocation = new Location(world, x, y, z);
|
|
||||||
Block chestBlock = chestLocation.getBlock();
|
Block chestBlock = chestLocation.getBlock();
|
||||||
|
|
||||||
if (!(chestBlock.getState() instanceof Chest)) {
|
if (!(chestBlock.getState() instanceof Chest)) {
|
||||||
@@ -646,8 +686,12 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
return attached;
|
return attached;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setInputChestLocation(UUID playerUUID, Location location) {
|
// --- ERWEITERUNG: Methode zum Hinzufügen einer Input Chest (Liste) ---
|
||||||
String path = "players." + playerUUID + ".input-chest";
|
private void addInputChestLocation(UUID playerUUID, Location location) {
|
||||||
|
String basePath = "players." + playerUUID + ".input-chests";
|
||||||
|
String id = UUID.randomUUID().toString(); // Eindeutige ID für jede Truhe
|
||||||
|
String path = basePath + "." + id;
|
||||||
|
|
||||||
playerData.set(path + ".world", location.getWorld().getName());
|
playerData.set(path + ".world", location.getWorld().getName());
|
||||||
playerData.set(path + ".x", location.getBlockX());
|
playerData.set(path + ".x", location.getBlockX());
|
||||||
playerData.set(path + ".y", location.getBlockY());
|
playerData.set(path + ".y", location.getBlockY());
|
||||||
@@ -655,6 +699,12 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
savePlayerData();
|
savePlayerData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Original-Methode als Wrapper beibehalten (damit onSignChange nicht geändert werden muss)
|
||||||
|
private void setInputChestLocation(UUID playerUUID, Location location) {
|
||||||
|
addInputChestLocation(playerUUID, location);
|
||||||
|
}
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
|
||||||
private void setTargetChestLocation(UUID playerUUID, Location location, Material itemType) {
|
private void setTargetChestLocation(UUID playerUUID, Location location, Material itemType) {
|
||||||
String path = "players." + playerUUID + ".target-chests." + itemType.name();
|
String path = "players." + playerUUID + ".target-chests." + itemType.name();
|
||||||
playerData.set(path + ".world", location.getWorld().getName());
|
playerData.set(path + ".world", location.getWorld().getName());
|
||||||
@@ -770,6 +820,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
loadPlayerData();
|
loadPlayerData();
|
||||||
updateConfig();
|
updateConfig();
|
||||||
updateExistingSigns();
|
updateExistingSigns();
|
||||||
|
migrateInputChests(); // ERWEITERUNG: Migration erneut aufrufen
|
||||||
player.sendMessage(getMessage("reload-success"));
|
player.sendMessage(getMessage("reload-success"));
|
||||||
getLogger().info("Konfiguration und Spielerdaten neu geladen durch " + player.getName());
|
getLogger().info("Konfiguration und Spielerdaten neu geladen durch " + player.getName());
|
||||||
return true;
|
return true;
|
||||||
@@ -835,7 +886,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
event.setLine(0, getSignColor("input", "line1") + "[asc]");
|
event.setLine(0, getSignColor("input", "line1") + "[asc]");
|
||||||
event.setLine(1, getSignColor("input", "line2") + "input");
|
event.setLine(1, getSignColor("input", "line2") + "input");
|
||||||
event.setLine(3, getSignColor("input", "line4") + player.getName());
|
event.setLine(3, getSignColor("input", "line4") + player.getName());
|
||||||
setInputChestLocation(playerUUID, chestBlock.getLocation());
|
setInputChestLocation(playerUUID, chestBlock.getLocation()); // Ruft nun addInputChestLocation auf
|
||||||
player.sendMessage(getMessage("input-chest-set"));
|
player.sendMessage(getMessage("input-chest-set"));
|
||||||
getLogger().info("Eingangstruhe für " + player.getName() + " gesetzt bei " + chestBlock.getLocation());
|
getLogger().info("Eingangstruhe für " + player.getName() + " gesetzt bei " + chestBlock.getLocation());
|
||||||
}
|
}
|
||||||
@@ -1173,6 +1224,36 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- ERWEITERUNG: Hilfsmethode zum Entfernen einer Input Chest ---
|
||||||
|
private void removeInputChestByLocation(UUID uuid, Location loc) {
|
||||||
|
String basePath = "players." + uuid + ".input-chests";
|
||||||
|
String oldPath = "players." + uuid + ".input-chest";
|
||||||
|
|
||||||
|
// Prüfe neues Listen-Format
|
||||||
|
if (playerData.contains(basePath)) {
|
||||||
|
for (String chestId : playerData.getConfigurationSection(basePath).getKeys(false)) {
|
||||||
|
String path = basePath + "." + chestId;
|
||||||
|
Location savedLoc = getLocationFromPath(path);
|
||||||
|
if (savedLoc != null && savedLoc.equals(loc)) {
|
||||||
|
playerData.set(path, null);
|
||||||
|
savePlayerData();
|
||||||
|
if (isDebug()) getLogger().info("Eingangstruhe entfernt bei " + loc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prüfe altes Einzel-Format (Fallback)
|
||||||
|
if (playerData.contains(oldPath)) {
|
||||||
|
Location oldLoc = getLocationFromPath(oldPath);
|
||||||
|
if (oldLoc != null && oldLoc.equals(loc)) {
|
||||||
|
playerData.set(oldPath, null);
|
||||||
|
savePlayerData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
@@ -1263,10 +1344,17 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
// --- Daten bereinigen beim Abbauen ---
|
// --- Daten bereinigen beim Abbauen ---
|
||||||
String[] lines = ((Sign) (isAscChest ? signBlock.getState() : block.getState())).getLines();
|
String[] lines = ((Sign) (isAscChest ? signBlock.getState() : block.getState())).getLines();
|
||||||
String line1 = ChatColor.stripColor(lines[1]);
|
String line1 = ChatColor.stripColor(lines[1]);
|
||||||
|
|
||||||
|
// Hole Location der Truhe, die abgebaut wird (für Datenabgleich)
|
||||||
|
Location chestLoc = isAscChest ? block.getLocation() : ((Sign)block.getState()).getBlock().getRelative(((WallSign)((Sign)block.getState()).getBlockData()).getFacing().getOppositeFace()).getLocation();
|
||||||
|
|
||||||
if (line1.equalsIgnoreCase("rest")) {
|
if (line1.equalsIgnoreCase("rest")) {
|
||||||
playerData.set("players." + player.getUniqueId() + ".rest-chest", null);
|
playerData.set("players." + player.getUniqueId() + ".rest-chest", null);
|
||||||
savePlayerData();
|
savePlayerData();
|
||||||
if (isDebug()) getLogger().info("Rest-Truhe Daten gelöscht für " + player.getName());
|
if (isDebug()) getLogger().info("Rest-Truhe Daten gelöscht für " + player.getName());
|
||||||
|
} else if (line1.equalsIgnoreCase("input")) {
|
||||||
|
// ERWEITERUNG: Input Chest aus Liste löschen
|
||||||
|
removeInputChestByLocation(player.getUniqueId(), chestLoc);
|
||||||
}
|
}
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
|
|
||||||
@@ -1553,28 +1641,50 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = "players." + uuidString + ".input-chest";
|
// --- ERWEITERUNG: Eingangstruhe (Jetzt Liste) ---
|
||||||
if (!playerData.contains(path)) continue;
|
String inputListPath = "players." + uuidString + ".input-chests";
|
||||||
|
// Fallback für altes Format (falls Migration noch nicht lief oder Fehler)
|
||||||
|
String oldInputPath = "players." + uuidString + ".input-chest";
|
||||||
|
|
||||||
String worldName = playerData.getString(path + ".world");
|
List<String> chestsToCheck = new ArrayList<>();
|
||||||
World world = getServer().getWorld(worldName);
|
|
||||||
if (world == null) {
|
|
||||||
getLogger().warning("Welt " + worldName + " für Eingangstruhe von UUID " + uuidString + " nicht gefunden");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x = playerData.getInt(path + ".x");
|
if (playerData.contains(inputListPath)) {
|
||||||
int y = playerData.getInt(path + ".y");
|
chestsToCheck.addAll(playerData.getConfigurationSection(inputListPath).getKeys(false));
|
||||||
int z = playerData.getInt(path + ".z");
|
} else if (playerData.contains(oldInputPath)) {
|
||||||
Location location = new Location(world, x, y, z);
|
// Hier führen wir keine Migration durch (nur lesen), da das im laufenden Betrieb zu Problemen führen könnte.
|
||||||
|
// Wir markieren es für den Task, damit es bei下一次 Update erledigt wird.
|
||||||
if (!(location.getBlock().getState() instanceof Chest)) {
|
Location loc = getLocationFromPath(oldInputPath);
|
||||||
if (isDebug()) {
|
if (loc != null) {
|
||||||
getLogger().fine("Eingangstruhe bei " + location + " existiert nicht");
|
checkSingleInputChest(ownerUUID, loc, "legacy");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chestsToCheck.isEmpty()) continue;
|
||||||
|
|
||||||
|
for (String chestId : chestsToCheck) {
|
||||||
|
String path = inputListPath + "." + chestId;
|
||||||
|
Location loc = getLocationFromPath(path);
|
||||||
|
|
||||||
|
if (loc == null) {
|
||||||
|
playerData.set(path, null); // Ungültigen Eintrag löschen
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean stillValid = checkSingleInputChest(ownerUUID, loc, chestId);
|
||||||
|
if (!stillValid) {
|
||||||
|
playerData.set(path, null);
|
||||||
|
savePlayerData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// -------------------------------------------------
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- ERWEITERUNG: Hilfsmethode zum Prüfen einzelner Eingangstruhe ---
|
||||||
|
private boolean checkSingleInputChest(UUID ownerUUID, Location location, String debugId) {
|
||||||
|
if (!(location.getBlock().getState() instanceof Chest)) return false;
|
||||||
|
|
||||||
Chest chest = (Chest) location.getBlock().getState();
|
Chest chest = (Chest) location.getBlock().getState();
|
||||||
Block inputSignBlock = null;
|
Block inputSignBlock = null;
|
||||||
boolean isPublic = false;
|
boolean isPublic = false;
|
||||||
@@ -1610,8 +1720,8 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inputSignBlock == null) {
|
if (inputSignBlock == null) {
|
||||||
if (isDebug()) getLogger().fine("Kein Eingangsschild an Truhe bei " + location);
|
if (isDebug()) getLogger().fine("Kein Eingangsschild an Truhe " + debugId);
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wenn das Inventar leer ist, brauchen wir nichts tun
|
// Wenn das Inventar leer ist, brauchen wir nichts tun
|
||||||
@@ -1622,7 +1732,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasItems) continue;
|
if (!hasItems) return true;
|
||||||
|
|
||||||
// Jetzt kommt der entscheidende Teil für die Multiplayer-Funktionalität:
|
// Jetzt kommt der entscheidende Teil für die Multiplayer-Funktionalität:
|
||||||
// Wenn PRIVATE: Nur sortieren, wenn der Owner ONLINE ist.
|
// Wenn PRIVATE: Nur sortieren, wenn der Owner ONLINE ist.
|
||||||
@@ -1634,7 +1744,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
|
|
||||||
if (!isPublic) {
|
if (!isPublic) {
|
||||||
// Privat: Nur wenn Owner online
|
// Privat: Nur wenn Owner online
|
||||||
if (ownerPlayer == null || !ownerPlayer.isOnline()) continue;
|
if (ownerPlayer == null || !ownerPlayer.isOnline()) return true;
|
||||||
} else {
|
} else {
|
||||||
// Öffentlich: Wenn Owner offline, können wir keine "Truhe voll" Nachrichten an den Owner senden.
|
// Öffentlich: Wenn Owner offline, können wir keine "Truhe voll" Nachrichten an den Owner senden.
|
||||||
// Wir sortieren trotzdem.
|
// Wir sortieren trotzdem.
|
||||||
@@ -1645,16 +1755,13 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wir rufen distributeItemsForOwner auf.
|
// Wir rufen distributeItemsForOwner auf.
|
||||||
// WICHTIG: distributeItemsForOwner nutzt `player.getUniqueId()` um die Zieltruhen zu finden.
|
distributeItemsForOwner(ownerUUID, ownerPlayer, chest.getInventory(), ownerName);
|
||||||
// Das funktioniert auch, wenn ownerPlayer null ist, solange wir die UUID übergeben.
|
return true;
|
||||||
// Wir müssen aber aufpassen, dass `distributeItemsForOwner` nicht crasht, wenn player null ist.
|
|
||||||
|
|
||||||
distributeItemsForOwner(ownerUUID, ownerPlayer, chest.getInventory());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
// 4. KORRIGIERTE distributeItemsForOwner Methode:
|
// 4. KORRIGIERTE distributeItemsForOwner Methode:
|
||||||
private void distributeItemsForOwner(UUID ownerUUID, Player ownerPlayer, Inventory sourceInventory) {
|
private void distributeItemsForOwner(UUID ownerUUID, Player ownerPlayer, Inventory sourceInventory, String ownerNameOverride) {
|
||||||
boolean hasItems = false;
|
boolean hasItems = false;
|
||||||
for (ItemStack item : sourceInventory.getContents()) {
|
for (ItemStack item : sourceInventory.getContents()) {
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
@@ -1666,7 +1773,9 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|||||||
|
|
||||||
// Owner-Name ermitteln
|
// Owner-Name ermitteln
|
||||||
String ownerName = "Unknown";
|
String ownerName = "Unknown";
|
||||||
if (ownerPlayer != null) {
|
if (ownerNameOverride != null && !ownerNameOverride.isEmpty()) {
|
||||||
|
ownerName = ownerNameOverride;
|
||||||
|
} else if (ownerPlayer != null) {
|
||||||
ownerName = ownerPlayer.getName();
|
ownerName = ownerPlayer.getName();
|
||||||
} else {
|
} else {
|
||||||
// Offline-Namen aus PlayerData holen wenn möglich
|
// Offline-Namen aus PlayerData holen wenn möglich
|
||||||
|
|||||||
Reference in New Issue
Block a user