src/main/java/com/viper/autosortchest/Main.java aktualisiert

This commit is contained in:
2026-01-05 06:09:28 +00:00
parent 431d3286b3
commit 37a0b242f2

View File

@@ -1,9 +1,14 @@
package com.viper.autosortchest;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Sign;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.command.Command;
@@ -20,12 +25,10 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import java.io.File;
import java.io.IOException;
@@ -99,6 +102,27 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
getLogger().info("AutoSortChest Plugin deaktiviert!");
}
// --- NEUE HILFSMETHODE FÜR DOPPELTRUHEN ---
private List<Block> getChestBlocks(Chest chest) {
List<Block> blocks = new ArrayList<>();
InventoryHolder holder = chest.getInventory().getHolder();
if (holder instanceof DoubleChest) {
DoubleChest doubleChest = (DoubleChest) holder;
// Finde beide Blöcke der Doppeltruhe
if (doubleChest.getLeftSide() instanceof Chest) {
blocks.add(((Chest) doubleChest.getLeftSide()).getBlock());
}
if (doubleChest.getRightSide() instanceof Chest) {
blocks.add(((Chest) doubleChest.getRightSide()).getBlock());
}
} else if (holder instanceof Chest) {
blocks.add(chest.getBlock());
}
return blocks;
}
// -----------------------------------------
private void savePlayerData() {
if (playerData == null || playerDataFile == null) {
getLogger().warning("Kann players.yml nicht speichern: playerData oder playerDataFile ist null");
@@ -434,24 +458,27 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
continue;
}
for (Block face : new Block[] {
chestBlock.getRelative(1, 0, 0),
chestBlock.getRelative(-1, 0, 0),
chestBlock.getRelative(0, 0, 1),
chestBlock.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, chestBlock)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("input")) {
sign.setLine(0, getSignColor("input", "line1") + "[asc]");
sign.setLine(1, getSignColor("input", "line2") + "input");
sign.setLine(3, getSignColor("input", "line4") + line3);
sign.update();
if (isDebug()) {
getLogger().fine("Eingangsschild bei " + face.getLocation() + " für Spieler UUID " + uuidString + " aktualisiert");
List<Block> blocks = getChestBlocks((Chest) chestBlock.getState());
for (Block b : blocks) {
for (Block face : new Block[] {
b.getRelative(1, 0, 0),
b.getRelative(-1, 0, 0),
b.getRelative(0, 0, 1),
b.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, b)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("input")) {
sign.setLine(0, getSignColor("input", "line1") + "[asc]");
sign.setLine(1, getSignColor("input", "line2") + "input");
sign.setLine(3, getSignColor("input", "line4") + line3);
sign.update();
if (isDebug()) {
getLogger().fine("Eingangsschild bei " + face.getLocation() + " für Spieler UUID " + uuidString + " aktualisiert");
}
}
}
}
@@ -484,27 +511,30 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
Inventory inventory = chest.getInventory();
boolean isFull = isInventoryFull(inventory);
for (Block face : new Block[] {
chestBlock.getRelative(1, 0, 0),
chestBlock.getRelative(-1, 0, 0),
chestBlock.getRelative(0, 0, 1),
chestBlock.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, chestBlock)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line2 = ChatColor.stripColor((String) (lines[2] != null ? lines[2] : ""));
String line3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("ziel")) {
String colorType = isFull ? "full" : "target";
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
sign.setLine(1, getSignColor(colorType, "line2") + "ziel");
sign.setLine(2, getSignColor(colorType, "line3") + line2);
sign.setLine(3, getSignColor(colorType, "line4") + line3);
sign.update();
if (isDebug()) {
getLogger().fine("Zieltruhe-Schild für Item " + itemType + " bei " + face.getLocation() + " aktualisiert (voll: " + isFull + ")");
List<Block> blocks = getChestBlocks(chest);
for (Block b : blocks) {
for (Block face : new Block[] {
b.getRelative(1, 0, 0),
b.getRelative(-1, 0, 0),
b.getRelative(0, 0, 1),
b.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, b)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line2 = ChatColor.stripColor((String) (lines[2] != null ? lines[2] : ""));
String line3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("ziel")) {
String colorType = isFull ? "full" : "target";
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
sign.setLine(1, getSignColor(colorType, "line2") + "ziel");
sign.setLine(2, getSignColor(colorType, "line3") + line2);
sign.setLine(3, getSignColor(colorType, "line4") + line3);
sign.update();
if (isDebug()) {
getLogger().fine("Zieltruhe-Schild für Item " + itemType + " bei " + face.getLocation() + " aktualisiert (voll: " + isFull + ")");
}
}
}
}
@@ -536,25 +566,28 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
Inventory inventory = chest.getInventory();
boolean isFull = isInventoryFull(inventory);
for (Block face : new Block[] {
chestBlock.getRelative(1, 0, 0),
chestBlock.getRelative(-1, 0, 0),
chestBlock.getRelative(0, 0, 1),
chestBlock.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, chestBlock)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("rest")) {
String colorType = isFull ? "full" : "rest";
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
sign.setLine(1, getSignColor(colorType, "line2") + "rest");
sign.setLine(3, getSignColor(colorType, "line4") + line3);
sign.update();
if (isDebug()) {
getLogger().fine("Rest-Truhe-Schild bei " + face.getLocation() + " für Spieler UUID " + uuidString + " aktualisiert");
List<Block> blocks = getChestBlocks(chest);
for (Block b : blocks) {
for (Block face : new Block[] {
b.getRelative(1, 0, 0),
b.getRelative(-1, 0, 0),
b.getRelative(0, 0, 1),
b.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, b)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("rest")) {
String colorType = isFull ? "full" : "rest";
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
sign.setLine(1, getSignColor(colorType, "line2") + "rest");
sign.setLine(3, getSignColor(colorType, "line4") + line3);
sign.update();
if (isDebug()) {
getLogger().fine("Rest-Truhe-Schild bei " + face.getLocation() + " für Spieler UUID " + uuidString + " aktualisiert");
}
}
}
}
@@ -977,18 +1010,23 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
Block chestBlock = clickedBlock;
Block signBlock = null;
// Suche Schild
for (Block face : new Block[] {
chestBlock.getRelative(1, 0, 0),
chestBlock.getRelative(-1, 0, 0),
chestBlock.getRelative(0, 0, 1),
chestBlock.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, chestBlock)) {
String[] lines = sign.getLines();
if (lines.length >= 2 && ChatColor.stripColor((String) (lines[0] != null ? lines[0] : "")).equalsIgnoreCase("[asc]")) {
signBlock = face;
break;
// Suche Schild an beiden Hälften falls Doppeltruhe
List<Block> blocks = getChestBlocks((Chest) chestBlock.getState());
outerLoop:
for (Block b : blocks) {
for (Block face : new Block[] {
b.getRelative(1, 0, 0),
b.getRelative(-1, 0, 0),
b.getRelative(0, 0, 1),
b.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, b)) {
String[] lines = sign.getLines();
if (lines.length >= 2 && ChatColor.stripColor((String) (lines[0] != null ? lines[0] : "")).equalsIgnoreCase("[asc]")) {
signBlock = face;
break outerLoop; // Schild gefunden
}
}
}
}
@@ -1160,25 +1198,31 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
// Fall 2: Truhe wird abgebaut
if (block.getState() instanceof Chest chestBlock) {
for (Block face : new Block[] {
block.getRelative(1, 0, 0),
block.getRelative(-1, 0, 0),
block.getRelative(0, 0, 1),
block.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, block)) {
String[] lines = sign.getLines();
if (lines.length >= 2 && ChatColor.stripColor((String) (lines[0] != null ? lines[0] : "")).equalsIgnoreCase("[asc]") &&
(ChatColor.stripColor((String) (lines[1] != null ? lines[1] : "")).equalsIgnoreCase("input") ||
ChatColor.stripColor((String) (lines[1] != null ? lines[1] : "")).equalsIgnoreCase("ziel") ||
ChatColor.stripColor((String) (lines[1] != null ? lines[1] : "")).equalsIgnoreCase("rest"))) { // REST hinzugefügt
signBlock = face;
signOwner = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
isAscChest = true;
if (isDebug()) {
getLogger().fine("Truhe mit [asc]-Schild erkannt bei " + block.getLocation() + ", Schild bei " + face.getLocation() + ", Besitzer: " + signOwner);
// Prüfe beide Hälften auf Schilder
List<Block> blocks = getChestBlocks(chestBlock);
outerLoop:
for (Block b : blocks) {
for (Block face : new Block[] {
b.getRelative(1, 0, 0),
b.getRelative(-1, 0, 0),
b.getRelative(0, 0, 1),
b.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, b)) {
String[] lines = sign.getLines();
if (lines.length >= 2 && ChatColor.stripColor((String) (lines[0] != null ? lines[0] : "")).equalsIgnoreCase("[asc]") &&
(ChatColor.stripColor((String) (lines[1] != null ? lines[1] : "")).equalsIgnoreCase("input") ||
ChatColor.stripColor((String) (lines[1] != null ? lines[1] : "")).equalsIgnoreCase("ziel") ||
ChatColor.stripColor((String) (lines[1] != null ? lines[1] : "")).equalsIgnoreCase("rest"))) { // REST hinzugefügt
signBlock = face;
signOwner = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
isAscChest = true;
if (isDebug()) {
getLogger().fine("Truhe mit [asc]-Schild erkannt bei " + block.getLocation() + ", Schild bei " + face.getLocation() + ", Besitzer: " + signOwner);
}
break outerLoop;
}
break;
}
}
}
@@ -1229,62 +1273,78 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if (!(event.getInventory().getHolder() instanceof Chest chest)) return;
InventoryHolder holder = event.getInventory().getHolder();
List<Chest> chestsToCheck = new ArrayList<>();
// FIX: Double Chest Handling
if (holder instanceof Chest) {
chestsToCheck.add((Chest) holder);
} else if (holder instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) holder;
if (dc.getLeftSide() instanceof Chest) chestsToCheck.add((Chest) dc.getLeftSide());
if (dc.getRightSide() instanceof Chest) chestsToCheck.add((Chest) dc.getRightSide());
} else {
return;
}
Player player = (Player) event.getPlayer();
Block chestBlock = chest.getBlock();
Block signBlock = null;
String signType = "target"; // default
// Suche nach einem an die Truhe angehängten Schild
for (Block face : new Block[] {
chestBlock.getRelative(1, 0, 0),
chestBlock.getRelative(-1, 0, 0),
chestBlock.getRelative(0, 0, 1),
chestBlock.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, chestBlock)) {
String[] lines = sign.getLines();
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
if (lines.length >= 2 && ChatColor.stripColor((String) (lines[0] != null ? lines[0] : "")).equalsIgnoreCase("[asc]") && (line1.equalsIgnoreCase("ziel") || line1.equalsIgnoreCase("rest"))) {
signBlock = face;
if (line1.equalsIgnoreCase("rest")) signType = "rest";
break;
for (Chest chest : chestsToCheck) {
Block chestBlock = chest.getBlock();
Block signBlock = null;
String signType = "target"; // default
// Suche nach einem an die Truhe angehängten Schild
for (Block face : new Block[] {
chestBlock.getRelative(1, 0, 0),
chestBlock.getRelative(-1, 0, 0),
chestBlock.getRelative(0, 0, 1),
chestBlock.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, chestBlock)) {
String[] lines = sign.getLines();
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
if (lines.length >= 2 && ChatColor.stripColor((String) (lines[0] != null ? lines[0] : "")).equalsIgnoreCase("[asc]") && (line1.equalsIgnoreCase("ziel") || line1.equalsIgnoreCase("rest"))) {
signBlock = face;
if (line1.equalsIgnoreCase("rest")) signType = "rest";
break;
}
}
}
}
if (signBlock == null) {
if (isDebug()) getLogger().fine("Keine Zieltruhe/Rest-Truhe Schild an Truhe bei " + chestBlock.getLocation());
return;
}
if (signBlock == null) {
continue;
}
Sign sign = (Sign) signBlock.getState();
String[] lines = sign.getLines();
String signOwner = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
if (!signOwner.equalsIgnoreCase(player.getName())) {
if (isDebug()) getLogger().fine("Schild bei " + signBlock.getLocation() + " gehört nicht Spieler " + player.getName() + " (Besitzer: " + signOwner + ")");
return;
}
Sign sign = (Sign) signBlock.getState();
String[] lines = sign.getLines();
String signOwner = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
// FIX: Auch öffentliche Truhen updaten, nicht nur Owner
boolean isPublic = isChestPublic(sign);
if (!signOwner.equalsIgnoreCase(player.getName()) && !isPublic) {
continue;
}
boolean isFull = isInventoryFull(chest.getInventory());
// FIX: Mapping 'ziel' -> 'target'
String configType = signType.equalsIgnoreCase("rest") ? "rest" : "target";
String colorType = isFull ? "full" : configType;
boolean isFull = isInventoryFull(chest.getInventory());
// FIX: Mapping 'ziel' -> 'target'
String configType = signType.equalsIgnoreCase("rest") ? "rest" : "target";
String colorType = isFull ? "full" : configType;
String currentLine0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String currentLine1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String currentLine3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
String currentLine0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String currentLine1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String currentLine3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
if (currentLine0.equalsIgnoreCase("[asc]") && (currentLine1.equalsIgnoreCase("ziel") || currentLine1.equalsIgnoreCase("rest"))) {
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
sign.setLine(1, getSignColor(colorType, "line2") + currentLine1); // Behält "ziel" oder "rest" bei
sign.setLine(2, getSignColor(colorType, "line3") + lines[2]); // Zeile 2 (Item bei Ziel, leer bei Rest)
sign.setLine(3, getSignColor(colorType, "line4") + currentLine3);
sign.update();
if (isDebug()) {
getLogger().fine(signType + "-Truhe Schild bei " + signBlock.getLocation() + " aktualisiert nach Inventar-Schließung (voll: " + isFull + ")");
if (currentLine0.equalsIgnoreCase("[asc]") && (currentLine1.equalsIgnoreCase("ziel") || currentLine1.equalsIgnoreCase("rest"))) {
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
sign.setLine(1, getSignColor(colorType, "line2") + currentLine1); // Behält "ziel" oder "rest" bei
sign.setLine(2, getSignColor(colorType, "line3") + lines[2]); // Zeile 2 (Item bei Ziel, leer bei Rest)
sign.setLine(3, getSignColor(colorType, "line4") + currentLine3);
sign.update();
if (isDebug()) {
getLogger().fine(signType + "-Truhe Schild bei " + signBlock.getLocation() + " aktualisiert nach Inventar-Schließung (voll: " + isFull + ")");
}
}
}
}
@@ -1372,37 +1432,42 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
String signOwner = "Unbekannt";
Block signBlock = null;
// Sign Check erlaubt sowohl "ziel" als auch "rest"
for (Block face : new Block[] {
targetChest.getBlock().getRelative(1, 0, 0),
targetChest.getBlock().getRelative(-1, 0, 0),
targetChest.getBlock().getRelative(0, 0, 1),
targetChest.getBlock().getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, targetChest.getBlock())) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
// Sign Check erlaubt sowohl "ziel" als auch "rest" und prüft beide Hälften bei Doppeltruhen
List<Block> chestBlocks = getChestBlocks(targetChest);
outerLoop:
for (Block b : chestBlocks) {
for (Block face : new Block[] {
b.getRelative(1, 0, 0),
b.getRelative(-1, 0, 0),
b.getRelative(0, 0, 1),
b.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, b)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
// Prüfen ob Schild-Typ zum erwarteten Ziel passt (Rest-Truhe muss "rest" Schild haben, Ziel muss "ziel" haben)
boolean typeMatches = isRestChest ? line1.equalsIgnoreCase("rest") : line1.equalsIgnoreCase("ziel");
// Prüfen ob Schild-Typ zum erwarteten Ziel passt (Rest-Truhe muss "rest" Schild haben, Ziel muss "ziel" haben)
boolean typeMatches = isRestChest ? line1.equalsIgnoreCase("rest") : line1.equalsIgnoreCase("ziel");
if (isDebug()) {
getLogger().fine("Prüfe Zieltruhe-Schild bei " + face.getLocation() + ": Zeile 1='" + line0 + "', Zeile 2='" + line1 + "', Zeile 4='" + line3 + "' für Spieler " + player.getName());
}
if (line0.equalsIgnoreCase("[asc]") && typeMatches) {
signOwner = line3.isEmpty() ? "Unbekannt" : line3;
if (line3.equalsIgnoreCase(player.getName())) {
isValidTarget = true;
signBlock = face;
if (isDebug()) {
getLogger().fine("Gültiges Zieltruhe-Schild gefunden bei " + face.getLocation() + " für Spieler " + player.getName());
}
break;
if (isDebug()) {
getLogger().fine("Prüfe Zieltruhe-Schild bei " + face.getLocation() + ": Zeile 1='" + line0 + "', Zeile 2='" + line1 + "', Zeile 4='" + line3 + "' für Spieler " + player.getName());
}
if (line0.equalsIgnoreCase("[asc]") && typeMatches) {
signOwner = line3.isEmpty() ? "Unbekannt" : line3;
if (line3.equalsIgnoreCase(player.getName())) {
isValidTarget = true;
signBlock = face;
if (isDebug()) {
getLogger().fine("Gültiges Zieltruhe-Schild gefunden bei " + face.getLocation() + " für Spieler " + player.getName());
}
break outerLoop;
}
} else if (isDebug()) {
getLogger().fine("Zieltruhe-Schild bei " + face.getLocation() + " hat ungültige Zeilen oder Typ passt nicht: [asc]=" + line0 + ", typ=" + line1);
}
} else if (isDebug()) {
getLogger().fine("Zieltruhe-Schild bei " + face.getLocation() + " hat ungültige Zeilen oder Typ passt nicht: [asc]=" + line0 + ", typ=" + line1);
}
}
}
@@ -1511,26 +1576,31 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
boolean isPublic = false;
String ownerName = "Unknown";
// Schild suchen und Status prüfen
for (Block face : new Block[] {
chest.getBlock().getRelative(1, 0, 0),
chest.getBlock().getRelative(-1, 0, 0),
chest.getBlock().getRelative(0, 0, 1),
chest.getBlock().getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, chest.getBlock())) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
// FIX: Suche Schild an beiden Hälften bei Doppeltruhen
List<Block> chestBlocks = getChestBlocks(chest);
outerLoop:
for (Block b : chestBlocks) {
for (Block face : new Block[] {
b.getRelative(1, 0, 0),
b.getRelative(-1, 0, 0),
b.getRelative(0, 0, 1),
b.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, b)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("input")) {
inputSignBlock = face;
String line3Raw = lines[3] != null ? lines[3] : "";
String line3Clean = ChatColor.stripColor(line3Raw);
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("input")) {
inputSignBlock = face;
String line3Raw = lines[3] != null ? lines[3] : "";
String line3Clean = ChatColor.stripColor(line3Raw);
isPublic = line3Clean.toLowerCase().endsWith("[public]");
ownerName = line3Clean.replace(" [Public]", "").replace(" [public]", "").trim();
break;
isPublic = line3Clean.toLowerCase().endsWith("[public]");
ownerName = line3Clean.replace(" [Public]", "").replace(" [public]", "").trim();
break outerLoop;
}
}
}
}
@@ -1642,28 +1712,34 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
boolean isValidTarget = false;
Block signBlock = null;
for (Block face : new Block[] {
targetChest.getBlock().getRelative(1, 0, 0),
targetChest.getBlock().getRelative(-1, 0, 0),
targetChest.getBlock().getRelative(0, 0, 1),
targetChest.getBlock().getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, targetChest.getBlock())) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line3Clean = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
// FIX: Suche Schild an beiden Hälften
List<Block> chestBlocks = getChestBlocks(targetChest);
outerLoop:
for (Block b : chestBlocks) {
for (Block face : new Block[] {
b.getRelative(1, 0, 0),
b.getRelative(-1, 0, 0),
b.getRelative(0, 0, 1),
b.getRelative(0, 0, -1)
}) {
if (face.getState() instanceof Sign sign && isSignAttachedToChest(face, b)) {
String[] lines = sign.getLines();
String line0 = ChatColor.stripColor((String) (lines[0] != null ? lines[0] : ""));
String line1 = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
String line3Clean = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
// Typ-Check: Wenn isRestChest true, muss Schild "rest" sagen, sonst "ziel"
boolean typeMatches = isRestChest ? line1.equalsIgnoreCase("rest") : line1.equalsIgnoreCase("ziel");
// Typ-Check: Wenn isRestChest true, muss Schild "rest" sagen, sonst "ziel"
boolean typeMatches = isRestChest ? line1.equalsIgnoreCase("rest") : line1.equalsIgnoreCase("ziel");
String signOwnerName = line3Clean.replace("[Public]", "").replace("[public]", "").trim();
String signOwnerName = line3Clean.replace("[Public]", "").replace("[public]", "").trim();
if (line0.equalsIgnoreCase("[asc]") && typeMatches) {
if (signOwnerName.equalsIgnoreCase(ownerName) || signOwnerName.equalsIgnoreCase("Unknown")) {
isValidTarget = true;
signBlock = face;
break;
if (line0.equalsIgnoreCase("[asc]") && typeMatches) {
if (signOwnerName.equalsIgnoreCase(ownerName) || signOwnerName.equalsIgnoreCase("Unknown")) {
isValidTarget = true;
signBlock = face;
break outerLoop;
}
}
}
}