|
|
|
|
@@ -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,11 +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 java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
@@ -38,7 +42,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
private FileConfiguration config;
|
|
|
|
|
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 String CONFIG_VERSION = "1.4";
|
|
|
|
|
private static final String CONFIG_VERSION = "1.5";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onEnable() {
|
|
|
|
|
@@ -98,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");
|
|
|
|
|
@@ -176,7 +201,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
config.createSection("sign-colors.input");
|
|
|
|
|
config.set("sign-colors.input.line1", defaultConfig.getString("sign-colors.input.line1", "&6"));
|
|
|
|
|
config.set("sign-colors.input.line2", defaultConfig.getString("sign-colors.input.line2", "&0"));
|
|
|
|
|
config.set("sign-colors.input.line4", defaultConfig.getString("sign-colors.input.line4", "&f"));
|
|
|
|
|
config.set("sign-colors.input.line4", defaultConfig.getString("sign-colors.input.line4", "&1")); // Korrigiert auf &1 basierend auf user Config
|
|
|
|
|
getLogger().info("Setze Standardwerte für sign-colors.input");
|
|
|
|
|
} else {
|
|
|
|
|
if (!config.contains("sign-colors.input.line1")) {
|
|
|
|
|
@@ -188,7 +213,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.input.line2 = " + config.getString("sign-colors.input.line2"));
|
|
|
|
|
}
|
|
|
|
|
if (!config.contains("sign-colors.input.line4")) {
|
|
|
|
|
config.set("sign-colors.input.line4", defaultConfig.getString("sign-colors.input.line4", "&f"));
|
|
|
|
|
config.set("sign-colors.input.line4", defaultConfig.getString("sign-colors.input.line4", "&1"));
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.input.line4 = " + config.getString("sign-colors.input.line4"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -199,7 +224,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
config.set("sign-colors.target.line1", defaultConfig.getString("sign-colors.target.line1", "&6"));
|
|
|
|
|
config.set("sign-colors.target.line2", defaultConfig.getString("sign-colors.target.line2", "&0"));
|
|
|
|
|
config.set("sign-colors.target.line3", defaultConfig.getString("sign-colors.target.line3", "&f"));
|
|
|
|
|
config.set("sign-colors.target.line4", defaultConfig.getString("sign-colors.target.line4", "&f"));
|
|
|
|
|
config.set("sign-colors.target.line4", defaultConfig.getString("sign-colors.target.line4", "&1")); // Korrigiert auf &1
|
|
|
|
|
getLogger().info("Setze Standardwerte für sign-colors.target");
|
|
|
|
|
} else {
|
|
|
|
|
if (!config.contains("sign-colors.target.line1")) {
|
|
|
|
|
@@ -215,7 +240,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.target.line3 = " + config.getString("sign-colors.target.line3"));
|
|
|
|
|
}
|
|
|
|
|
if (!config.contains("sign-colors.target.line4")) {
|
|
|
|
|
config.set("sign-colors.target.line4", defaultConfig.getString("sign-colors.target.line4", "&f"));
|
|
|
|
|
config.set("sign-colors.target.line4", defaultConfig.getString("sign-colors.target.line4", "&1"));
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.target.line4 = " + config.getString("sign-colors.target.line4"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -226,7 +251,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
config.set("sign-colors.full.line1", defaultConfig.getString("sign-colors.full.line1", "&c"));
|
|
|
|
|
config.set("sign-colors.full.line2", defaultConfig.getString("sign-colors.full.line2", "&4"));
|
|
|
|
|
config.set("sign-colors.full.line3", defaultConfig.getString("sign-colors.full.line3", "&e"));
|
|
|
|
|
config.set("sign-colors.full.line4", defaultConfig.getString("sign-colors.full.line4", "&e"));
|
|
|
|
|
config.set("sign-colors.full.line4", defaultConfig.getString("sign-colors.full.line4", "&1")); // Korrigiert auf &1
|
|
|
|
|
getLogger().info("Setze Standardwerte für sign-colors.full");
|
|
|
|
|
} else {
|
|
|
|
|
if (!config.contains("sign-colors.full.line1")) {
|
|
|
|
|
@@ -242,12 +267,39 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.full.line3 = " + config.getString("sign-colors.full.line3"));
|
|
|
|
|
}
|
|
|
|
|
if (!config.contains("sign-colors.full.line4")) {
|
|
|
|
|
config.set("sign-colors.full.line4", defaultConfig.getString("sign-colors.full.line4", "&e"));
|
|
|
|
|
config.set("sign-colors.full.line4", defaultConfig.getString("sign-colors.full.line4", "&1"));
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.full.line4 = " + config.getString("sign-colors.full.line4"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prüfe und setze messages
|
|
|
|
|
// --- NEU: Prüfe und setze sign-colors.rest ---
|
|
|
|
|
if (!config.contains("sign-colors.rest")) {
|
|
|
|
|
config.createSection("sign-colors.rest");
|
|
|
|
|
config.set("sign-colors.rest.line1", defaultConfig.getString("sign-colors.rest.line1", "&6"));
|
|
|
|
|
config.set("sign-colors.rest.line2", defaultConfig.getString("sign-colors.rest.line2", "&0"));
|
|
|
|
|
config.set("sign-colors.rest.line3", defaultConfig.getString("sign-colors.rest.line3", "&f"));
|
|
|
|
|
config.set("sign-colors.rest.line4", defaultConfig.getString("sign-colors.rest.line4", "&1")); // Korrigiert auf &1
|
|
|
|
|
getLogger().info("Setze Standardwerte für sign-colors.rest");
|
|
|
|
|
} else {
|
|
|
|
|
if (!config.contains("sign-colors.rest.line1")) {
|
|
|
|
|
config.set("sign-colors.rest.line1", defaultConfig.getString("sign-colors.rest.line1", "&6"));
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.rest.line1 = " + config.getString("sign-colors.rest.line1"));
|
|
|
|
|
}
|
|
|
|
|
if (!config.contains("sign-colors.rest.line2")) {
|
|
|
|
|
config.set("sign-colors.rest.line2", defaultConfig.getString("sign-colors.rest.line2", "&0"));
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.rest.line2 = " + config.getString("sign-colors.rest.line2"));
|
|
|
|
|
}
|
|
|
|
|
if (!config.contains("sign-colors.rest.line3")) {
|
|
|
|
|
config.set("sign-colors.rest.line3", defaultConfig.getString("sign-colors.rest.line3", "&f"));
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.rest.line3 = " + config.getString("sign-colors.rest.line3"));
|
|
|
|
|
}
|
|
|
|
|
if (!config.contains("sign-colors.rest.line4")) {
|
|
|
|
|
config.set("sign-colors.rest.line4", defaultConfig.getString("sign-colors.rest.line4", "&1"));
|
|
|
|
|
getLogger().info("Setze Standardwert: sign-colors.rest.line4 = " + config.getString("sign-colors.rest.line4"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
|
|
|
|
|
|
if (!config.contains("messages.no-chest-near-sign")) {
|
|
|
|
|
config.set("messages.no-chest-near-sign", defaultConfig.getString("messages.no-chest-near-sign", "&cKeine Truhe in der Nähe des Schildes!"));
|
|
|
|
|
getLogger().info("Setze Standardwert: messages.no-chest-near-sign");
|
|
|
|
|
@@ -268,6 +320,13 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
config.set("messages.target-chest-set", defaultConfig.getString("messages.target-chest-set", "&aZieltruhe für %item% erfolgreich gesetzt!"));
|
|
|
|
|
getLogger().info("Setze Standardwert: messages.target-chest-set");
|
|
|
|
|
}
|
|
|
|
|
// --- NEU: Message für Rest-Truhe ---
|
|
|
|
|
if (!config.contains("messages.rest-chest-set")) {
|
|
|
|
|
config.set("messages.rest-chest-set", defaultConfig.getString("messages.rest-chest-set", "&aRest-Truhe (Fallback) erfolgreich gesetzt!"));
|
|
|
|
|
getLogger().info("Setze Standardwert: messages.rest-chest-set");
|
|
|
|
|
}
|
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
|
|
if (!config.contains("messages.target-chest-missing")) {
|
|
|
|
|
config.set("messages.target-chest-missing", defaultConfig.getString("messages.target-chest-missing", "&cZieltruhe für %item% fehlt!"));
|
|
|
|
|
getLogger().info("Setze Standardwert: messages.target-chest-missing");
|
|
|
|
|
@@ -308,6 +367,11 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
" &7[asc]\n" +
|
|
|
|
|
" &7ziel\n" +
|
|
|
|
|
"&f3. Rechtsklicke mit einem Item in der Hand.\n" +
|
|
|
|
|
"&eRest-Truhe (Fallback) erstellen:\n" +
|
|
|
|
|
"&f1. Platziere ein Schild an einer Truhe.\n" +
|
|
|
|
|
"&f2. Schreibe:\n" +
|
|
|
|
|
" &7[asc]\n" +
|
|
|
|
|
" &7rest\n" +
|
|
|
|
|
"&eBefehle:\n" +
|
|
|
|
|
"&f- &b/asc help &f- Zeigt diese Hilfe.\n" +
|
|
|
|
|
"&f- &b/asc info &f- Zeigt Plugin-Informationen.\n" +
|
|
|
|
|
@@ -394,13 +458,15 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Block> blocks = getChestBlocks((Chest) chestBlock.getState());
|
|
|
|
|
for (Block b : blocks) {
|
|
|
|
|
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)
|
|
|
|
|
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, chestBlock)) {
|
|
|
|
|
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] : ""));
|
|
|
|
|
@@ -417,6 +483,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Zieltruhen
|
|
|
|
|
String targetPath = path + ".target-chests";
|
|
|
|
|
@@ -444,13 +511,15 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
Inventory inventory = chest.getInventory();
|
|
|
|
|
boolean isFull = isInventoryFull(inventory);
|
|
|
|
|
|
|
|
|
|
List<Block> blocks = getChestBlocks(chest);
|
|
|
|
|
for (Block b : blocks) {
|
|
|
|
|
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)
|
|
|
|
|
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, chestBlock)) {
|
|
|
|
|
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] : ""));
|
|
|
|
|
@@ -472,6 +541,60 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- NEU: Rest-Truhe aktualisieren ---
|
|
|
|
|
String restPath = path + ".rest-chest";
|
|
|
|
|
if (playerData.contains(restPath)) {
|
|
|
|
|
String worldName = playerData.getString(restPath + ".world");
|
|
|
|
|
World world = getServer().getWorld(worldName);
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
if (!(chestBlock.getState() instanceof Chest)) {
|
|
|
|
|
getLogger().warning("Rest-Truhe bei " + chestLocation + " ist keine Truhe");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Chest chest = (Chest) chestBlock.getState();
|
|
|
|
|
Inventory inventory = chest.getInventory();
|
|
|
|
|
boolean isFull = isInventoryFull(inventory);
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isInventoryFull(Inventory inventory) {
|
|
|
|
|
@@ -542,6 +665,33 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
getLogger().info("Zieltruhe für " + getServer().getPlayer(playerUUID).getName() + " (" + itemType.name() + ") gesetzt bei " + location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- NEU: Methoden für Rest-Truhe ---
|
|
|
|
|
private void setRestChestLocation(UUID playerUUID, Location location) {
|
|
|
|
|
String path = "players." + playerUUID + ".rest-chest";
|
|
|
|
|
playerData.set(path + ".world", location.getWorld().getName());
|
|
|
|
|
playerData.set(path + ".x", location.getBlockX());
|
|
|
|
|
playerData.set(path + ".y", location.getBlockY());
|
|
|
|
|
playerData.set(path + ".z", location.getBlockZ());
|
|
|
|
|
savePlayerData();
|
|
|
|
|
getLogger().info("Rest-Truhe für " + getServer().getPlayer(playerUUID).getName() + " gesetzt bei " + location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Location getRestChestLocation(UUID playerUUID) {
|
|
|
|
|
String path = "players." + playerUUID + ".rest-chest";
|
|
|
|
|
if (!playerData.contains(path)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
|
|
private Location getTargetChestLocation(UUID playerUUID, Material itemType) {
|
|
|
|
|
String path = "players." + playerUUID + ".target-chests." + itemType.name();
|
|
|
|
|
if (!playerData.contains(path)) {
|
|
|
|
|
@@ -630,14 +780,44 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) // <- Geändert: Priorität erhöht und Cancel ignoriert
|
|
|
|
|
public void onSignChange(SignChangeEvent event) {
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
UUID playerUUID = player.getUniqueId();
|
|
|
|
|
Block signBlock = event.getBlock();
|
|
|
|
|
String[] lines = event.getLines();
|
|
|
|
|
|
|
|
|
|
// --- NEU: Sign Change für Rest-Truhe ---
|
|
|
|
|
if (lines.length >= 2 && lines[0].equalsIgnoreCase("[asc]") && lines[1].equalsIgnoreCase("rest")) {
|
|
|
|
|
event.setCancelled(false); // <- HIER: WorldGuard Cancel rückgängig machen
|
|
|
|
|
|
|
|
|
|
Block chestBlock = null;
|
|
|
|
|
if (signBlock.getBlockData() instanceof WallSign wallSign) {
|
|
|
|
|
Block attachedBlock = signBlock.getRelative(wallSign.getFacing().getOppositeFace());
|
|
|
|
|
if (attachedBlock.getState() instanceof Chest) {
|
|
|
|
|
chestBlock = attachedBlock;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (chestBlock == null) {
|
|
|
|
|
player.sendMessage(getMessage("no-chest-near-sign"));
|
|
|
|
|
getLogger().warning("Keine Truhe an Schild bei " + signBlock.getLocation() + " für Spieler " + player.getName());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event.setLine(0, getSignColor("rest", "line1") + "[asc]");
|
|
|
|
|
event.setLine(1, getSignColor("rest", "line2") + "rest");
|
|
|
|
|
event.setLine(3, getSignColor("rest", "line4") + player.getName());
|
|
|
|
|
setRestChestLocation(playerUUID, chestBlock.getLocation());
|
|
|
|
|
player.sendMessage(getMessage("rest-chest-set"));
|
|
|
|
|
getLogger().info("Rest-Truhe für " + player.getName() + " gesetzt bei " + chestBlock.getLocation());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------
|
|
|
|
|
|
|
|
|
|
if (lines.length >= 2 && lines[0].equalsIgnoreCase("[asc]") && lines[1].equalsIgnoreCase("input")) {
|
|
|
|
|
event.setCancelled(false); // <- HIER: WorldGuard Cancel rückgängig machen
|
|
|
|
|
|
|
|
|
|
Block chestBlock = null;
|
|
|
|
|
if (signBlock.getBlockData() instanceof WallSign wallSign) {
|
|
|
|
|
Block attachedBlock = signBlock.getRelative(wallSign.getFacing().getOppositeFace());
|
|
|
|
|
@@ -693,9 +873,10 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String line1Clean = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
|
|
|
|
|
boolean isTargetOrRest = line1Clean.equalsIgnoreCase("ziel") || line1Clean.equalsIgnoreCase("rest");
|
|
|
|
|
|
|
|
|
|
// --- LOGIK FÜR ZIELTRUHEN (ZIEL) ---
|
|
|
|
|
if (line1Clean.equalsIgnoreCase("ziel")) {
|
|
|
|
|
// --- LOGIK FÜR ZIELTRUHEN (ZIEL) UND REST-TRUHEN ---
|
|
|
|
|
if (isTargetOrRest) {
|
|
|
|
|
String line3Raw = lines[3] != null ? lines[3] : "";
|
|
|
|
|
String line3Clean = ChatColor.stripColor(line3Raw);
|
|
|
|
|
String pureOwnerName = line3Clean.replace("[Public]", "").replace("[public]", "").trim();
|
|
|
|
|
@@ -709,14 +890,16 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
String newModeText;
|
|
|
|
|
String newLine4;
|
|
|
|
|
|
|
|
|
|
String colorType = line1Clean.equalsIgnoreCase("rest") ? "rest" : "target";
|
|
|
|
|
|
|
|
|
|
if (isPublic) {
|
|
|
|
|
// Wechsel zu Privat
|
|
|
|
|
newModeText = getMessage("mode-private");
|
|
|
|
|
newLine4 = getSignColor("target", "line4") + pureOwnerName;
|
|
|
|
|
newLine4 = getSignColor(colorType, "line4") + pureOwnerName;
|
|
|
|
|
} else {
|
|
|
|
|
// Wechsel zu Öffentlich
|
|
|
|
|
newModeText = getMessage("mode-public");
|
|
|
|
|
newLine4 = getSignColor("target", "line4") + pureOwnerName + " " + ChatColor.RESET + "[Public]";
|
|
|
|
|
newLine4 = getSignColor(colorType, "line4") + pureOwnerName + " " + ChatColor.RESET + "[Public]";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sign.setLine(3, newLine4);
|
|
|
|
|
@@ -731,8 +914,8 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. FALL: ITEM ZUWEISEN / AKTUALISIEREN (Klick + Item in Hand)
|
|
|
|
|
// ERWEITERUNG: Wir prüfen nicht mehr, ob Zeile 2 leer ist. Wenn ein Item in der Hand ist, wird es aktualisiert.
|
|
|
|
|
// 2. FALL: ITEM ZUWEISEN / AKTUALISIEREN (Nur bei ZIEL, nicht bei REST)
|
|
|
|
|
if (line1Clean.equalsIgnoreCase("ziel")) {
|
|
|
|
|
if (itemInHand != null && itemInHand.getType() != Material.AIR) {
|
|
|
|
|
// Prüfe, ob der Spieler das Recht hat (Owner oder unbeansprucht)
|
|
|
|
|
if (!pureOwnerName.isEmpty() && !pureOwnerName.equalsIgnoreCase("Unknown") && !isOwner) {
|
|
|
|
|
@@ -741,6 +924,10 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- FIX: Alten Eintrag für diese Truhe löschen ---
|
|
|
|
|
removeOldTargetEntry(player.getUniqueId(), chestBlock.getLocation(), itemInHand.getType().name());
|
|
|
|
|
// ------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Chest chest = (Chest) chestBlock.getState();
|
|
|
|
|
boolean isFull = isInventoryFull(chest.getInventory());
|
|
|
|
|
String colorType = isFull ? "full" : "target";
|
|
|
|
|
@@ -763,6 +950,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Zugriffsschutz für konfigurierte Truhen (wenn kein Item in Hand zum Updaten)
|
|
|
|
|
// Wenn nicht Owner und NICHT öffentlich -> Zugriff verweigern
|
|
|
|
|
@@ -826,18 +1014,23 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
Block chestBlock = clickedBlock;
|
|
|
|
|
Block signBlock = null;
|
|
|
|
|
|
|
|
|
|
// Suche Schild
|
|
|
|
|
// 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[] {
|
|
|
|
|
chestBlock.getRelative(1, 0, 0),
|
|
|
|
|
chestBlock.getRelative(-1, 0, 0),
|
|
|
|
|
chestBlock.getRelative(0, 0, 1),
|
|
|
|
|
chestBlock.getRelative(0, 0, -1)
|
|
|
|
|
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, chestBlock)) {
|
|
|
|
|
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;
|
|
|
|
|
break outerLoop; // Schild gefunden
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -847,8 +1040,8 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
String[] lines = sign.getLines();
|
|
|
|
|
String line1Clean = ChatColor.stripColor((String) (lines[1] != null ? lines[1] : ""));
|
|
|
|
|
|
|
|
|
|
// NUR FÜR ZIELTRUHEN
|
|
|
|
|
if (line1Clean.equalsIgnoreCase("ziel")) {
|
|
|
|
|
// NUR FÜR ZIELTRUHEN und REST (hier nur Moduswechsel)
|
|
|
|
|
if (line1Clean.equalsIgnoreCase("ziel") || line1Clean.equalsIgnoreCase("rest")) {
|
|
|
|
|
String line3Raw = lines[3] != null ? lines[3] : "";
|
|
|
|
|
String line3Clean = ChatColor.stripColor(line3Raw);
|
|
|
|
|
String pureOwnerName = line3Clean.replace("[public]", "").replace("[Public]", "").trim();
|
|
|
|
|
@@ -861,7 +1054,8 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
String newModeText;
|
|
|
|
|
String newLine4;
|
|
|
|
|
|
|
|
|
|
String baseName = getSignColor("target", "line4") + pureOwnerName;
|
|
|
|
|
String colorType = line1Clean.equalsIgnoreCase("rest") ? "rest" : "target";
|
|
|
|
|
String baseName = getSignColor(colorType, "line4") + pureOwnerName;
|
|
|
|
|
|
|
|
|
|
if (isPublic) {
|
|
|
|
|
newModeText = getMessage("mode-private");
|
|
|
|
|
@@ -883,9 +1077,8 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. FALL: ITEM ZUWEISEN (Nur wenn Zeile 2 leer ist - Logik beibehalten für Klick auf Truhe)
|
|
|
|
|
// Hinweis: Um das Item zu aktualisieren, sollte das Schild angeklickt werden, nicht die Truhe direkt.
|
|
|
|
|
// Dies verhindert, dass man versehentlich die Sortierung ändert, wenn man Items in die Truhe legen will.
|
|
|
|
|
// 2. FALL: ITEM ZUWEISEN (Nur bei ZIEL, nicht bei REST, und nur wenn Zeile 2 leer ist)
|
|
|
|
|
if (line1Clean.equalsIgnoreCase("ziel")) {
|
|
|
|
|
String line2Clean = ChatColor.stripColor((String) (lines[2] != null ? lines[2] : ""));
|
|
|
|
|
if (line2Clean.isEmpty()) {
|
|
|
|
|
if (itemInHand == null || itemInHand.getType() == Material.AIR) {
|
|
|
|
|
@@ -900,6 +1093,10 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- FIX: Alten Eintrag auch beim Klick auf die Truhe löschen ---
|
|
|
|
|
removeOldTargetEntry(player.getUniqueId(), chestBlock.getLocation(), itemInHand.getType().name());
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Chest chest = (Chest) chestBlock.getState();
|
|
|
|
|
boolean isFull = isInventoryFull(chest.getInventory());
|
|
|
|
|
String colorType = isFull ? "full" : "target";
|
|
|
|
|
@@ -921,6 +1118,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wenn nicht Owner und nicht öffentlich -> Zugriff verweigern
|
|
|
|
|
if (!isOwner && !isChestPublic(sign)) {
|
|
|
|
|
@@ -991,7 +1189,9 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
if (block.getState() instanceof Sign sign) {
|
|
|
|
|
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("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 = block;
|
|
|
|
|
signOwner = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
|
|
|
|
|
if (isDebug()) {
|
|
|
|
|
@@ -1002,23 +1202,31 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
|
|
|
|
|
// Fall 2: Truhe wird abgebaut
|
|
|
|
|
if (block.getState() instanceof Chest chestBlock) {
|
|
|
|
|
// Prüfe beide Hälften auf Schilder
|
|
|
|
|
List<Block> blocks = getChestBlocks(chestBlock);
|
|
|
|
|
|
|
|
|
|
outerLoop:
|
|
|
|
|
for (Block b : blocks) {
|
|
|
|
|
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)
|
|
|
|
|
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, block)) {
|
|
|
|
|
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("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;
|
|
|
|
|
break outerLoop;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1052,6 +1260,16 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Daten bereinigen beim Abbauen ---
|
|
|
|
|
String[] lines = ((Sign) (isAscChest ? signBlock.getState() : block.getState())).getLines();
|
|
|
|
|
String line1 = ChatColor.stripColor(lines[1]);
|
|
|
|
|
if (line1.equalsIgnoreCase("rest")) {
|
|
|
|
|
playerData.set("players." + player.getUniqueId() + ".rest-chest", null);
|
|
|
|
|
savePlayerData();
|
|
|
|
|
if (isDebug()) getLogger().info("Rest-Truhe Daten gelöscht für " + player.getName());
|
|
|
|
|
}
|
|
|
|
|
// --------------------------------
|
|
|
|
|
|
|
|
|
|
if (isDebug()) {
|
|
|
|
|
getLogger().fine("Spieler " + player.getName() + " hat " + (isAscChest ? "Truhe" : "Schild") + " bei " + block.getLocation() + " erfolgreich abgebaut");
|
|
|
|
|
}
|
|
|
|
|
@@ -1059,11 +1277,26 @@ 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();
|
|
|
|
|
|
|
|
|
|
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[] {
|
|
|
|
|
@@ -1074,45 +1307,74 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
}) {
|
|
|
|
|
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]") && ChatColor.stripColor((String) (lines[1] != null ? lines[1] : "")).equalsIgnoreCase("ziel")) {
|
|
|
|
|
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-Schild an Truhe bei " + chestBlock.getLocation());
|
|
|
|
|
return;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
// FIX: Auch öffentliche Truhen updaten, nicht nur Owner
|
|
|
|
|
boolean isPublic = isChestPublic(sign);
|
|
|
|
|
if (!signOwner.equalsIgnoreCase(player.getName()) && !isPublic) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean isFull = isInventoryFull(chest.getInventory());
|
|
|
|
|
String colorType = isFull ? "full" : "target";
|
|
|
|
|
|
|
|
|
|
// 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 currentLine2 = ChatColor.stripColor((String) (lines[2] != null ? lines[2] : ""));
|
|
|
|
|
String currentLine3 = ChatColor.stripColor((String) (lines[3] != null ? lines[3] : ""));
|
|
|
|
|
|
|
|
|
|
if (currentLine0.equalsIgnoreCase("[asc]") && currentLine1.equalsIgnoreCase("ziel")) {
|
|
|
|
|
if (currentLine0.equalsIgnoreCase("[asc]") && (currentLine1.equalsIgnoreCase("ziel") || currentLine1.equalsIgnoreCase("rest"))) {
|
|
|
|
|
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
|
|
|
|
|
sign.setLine(1, getSignColor(colorType, "line2") + "ziel");
|
|
|
|
|
sign.setLine(2, getSignColor(colorType, "line3") + currentLine2);
|
|
|
|
|
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("Zieltruhe-Schild bei " + signBlock.getLocation() + " aktualisiert nach Inventar-Schließung (voll: " + isFull + ")");
|
|
|
|
|
getLogger().fine(signType + "-Truhe Schild bei " + signBlock.getLocation() + " aktualisiert nach Inventar-Schließung (voll: " + isFull + ")");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- HILFSMETHODE zum Entfernen alter Einträge ---
|
|
|
|
|
private void removeOldTargetEntry(UUID uuid, Location loc, String newItemType) {
|
|
|
|
|
String basePath = "players." + uuid + ".target-chests";
|
|
|
|
|
if (!playerData.contains(basePath)) return;
|
|
|
|
|
|
|
|
|
|
for (String existingType : playerData.getConfigurationSection(basePath).getKeys(false)) {
|
|
|
|
|
if (existingType.equalsIgnoreCase(newItemType)) continue; // Gleiches Item ignorieren
|
|
|
|
|
|
|
|
|
|
String path = basePath + "." + existingType;
|
|
|
|
|
if (playerData.getString(path + ".world").equals(loc.getWorld().getName()) &&
|
|
|
|
|
playerData.getInt(path + ".x") == loc.getBlockX() &&
|
|
|
|
|
playerData.getInt(path + ".y") == loc.getBlockY() &&
|
|
|
|
|
playerData.getInt(path + ".z") == loc.getBlockZ()) {
|
|
|
|
|
|
|
|
|
|
playerData.set(path, null);
|
|
|
|
|
if (isDebug()) getLogger().info("Altes Zieltruhen-Item '" + existingType + "' für " + uuid + " entfernt (Update).");
|
|
|
|
|
// Nicht speichern hier, savePlayerData() wird am Ende von setTargetChestLocation aufgerufen
|
|
|
|
|
break; // Eine Truhe kann nur ein Item sein (nicht Rest)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
|
|
|
|
|
|
private void distributeItems(Player player, Inventory sourceInventory) {
|
|
|
|
|
UUID playerUUID = player.getUniqueId();
|
|
|
|
|
@@ -1136,18 +1398,34 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
if (item == null || item.getType() == Material.AIR) continue;
|
|
|
|
|
|
|
|
|
|
Location targetChestLocation = getTargetChestLocation(playerUUID, item.getType());
|
|
|
|
|
boolean isRestChest = false;
|
|
|
|
|
|
|
|
|
|
// Wenn kein spezifisches Ziel, versuche Rest-Truhe
|
|
|
|
|
if (targetChestLocation == null) {
|
|
|
|
|
if (isDebug()) getLogger().fine("Keine Zieltruhe für Item " + item.getType().name() + " für Spieler " + player.getName());
|
|
|
|
|
targetChestLocation = getRestChestLocation(playerUUID);
|
|
|
|
|
if (targetChestLocation != null) {
|
|
|
|
|
isRestChest = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (targetChestLocation == null) {
|
|
|
|
|
if (isDebug()) getLogger().fine("Keine Zieltruhe und keine Rest-Truhe für Item " + item.getType().name() + " für Spieler " + player.getName());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(targetChestLocation.getBlock().getState() instanceof Chest)) {
|
|
|
|
|
String msgKey = isRestChest ? "target-chest-missing" : "target-chest-missing"; // Kann gleiche Nachricht nutzen
|
|
|
|
|
if (canSendFullChestMessage(playerUUID, item.getType())) {
|
|
|
|
|
player.sendMessage(getMessage("target-chest-missing").replace("%item%", item.getType().name()));
|
|
|
|
|
player.sendMessage(getMessage(msgKey).replace("%item%", (isRestChest ? "Rest-Truhe" : item.getType().name())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isRestChest) {
|
|
|
|
|
playerData.set("players." + playerUUID + ".rest-chest", null);
|
|
|
|
|
} else {
|
|
|
|
|
playerData.set("players." + playerUUID + ".target-chests." + item.getType().name(), null);
|
|
|
|
|
}
|
|
|
|
|
savePlayerData();
|
|
|
|
|
getLogger().warning("Zieltruhe für " + item.getType().name() + " fehlt bei " + targetChestLocation);
|
|
|
|
|
getLogger().warning("Zieltruhe (" + (isRestChest ? "Rest" : item.getType().name()) + ") fehlt bei " + targetChestLocation);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1157,21 +1435,31 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
boolean isValidTarget = false;
|
|
|
|
|
String signOwner = "Unbekannt";
|
|
|
|
|
Block signBlock = null;
|
|
|
|
|
|
|
|
|
|
// 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[] {
|
|
|
|
|
targetChest.getBlock().getRelative(1, 0, 0),
|
|
|
|
|
targetChest.getBlock().getRelative(-1, 0, 0),
|
|
|
|
|
targetChest.getBlock().getRelative(0, 0, 1),
|
|
|
|
|
targetChest.getBlock().getRelative(0, 0, -1)
|
|
|
|
|
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, targetChest.getBlock())) {
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
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]") && line1.equalsIgnoreCase("ziel")) {
|
|
|
|
|
if (line0.equalsIgnoreCase("[asc]") && typeMatches) {
|
|
|
|
|
signOwner = line3.isEmpty() ? "Unbekannt" : line3;
|
|
|
|
|
if (line3.equalsIgnoreCase(player.getName())) {
|
|
|
|
|
isValidTarget = true;
|
|
|
|
|
@@ -1179,10 +1467,11 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
if (isDebug()) {
|
|
|
|
|
getLogger().fine("Gültiges Zieltruhe-Schild gefunden bei " + face.getLocation() + " für Spieler " + player.getName());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
break outerLoop;
|
|
|
|
|
}
|
|
|
|
|
} else if (isDebug()) {
|
|
|
|
|
getLogger().fine("Zieltruhe-Schild bei " + face.getLocation() + " hat ungültige Zeilen: [asc]=" + line0 + ", ziel=" + line1);
|
|
|
|
|
getLogger().fine("Zieltruhe-Schild bei " + face.getLocation() + " hat ungültige Zeilen oder Typ passt nicht: [asc]=" + line0 + ", typ=" + line1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1206,10 +1495,14 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
if (line0.equalsIgnoreCase("[asc]") && (line1.equalsIgnoreCase("ziel") || line1.equalsIgnoreCase("rest"))) {
|
|
|
|
|
// FIX: Mapping 'ziel' -> 'target'
|
|
|
|
|
String configType = line1.equalsIgnoreCase("rest") ? "rest" : "target";
|
|
|
|
|
String colorType = isFull ? "full" : configType;
|
|
|
|
|
|
|
|
|
|
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
|
|
|
|
|
sign.setLine(1, getSignColor(colorType, "line2") + "ziel");
|
|
|
|
|
sign.setLine(1, getSignColor(colorType, "line2") + line1);
|
|
|
|
|
sign.setLine(2, getSignColor(colorType, "line3") + line2);
|
|
|
|
|
sign.setLine(3, getSignColor(colorType, "line4") + line3);
|
|
|
|
|
sign.update();
|
|
|
|
|
@@ -1287,14 +1580,18 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
boolean isPublic = false;
|
|
|
|
|
String ownerName = "Unknown";
|
|
|
|
|
|
|
|
|
|
// Schild suchen und Status prüfen
|
|
|
|
|
// FIX: Suche Schild an beiden Hälften bei Doppeltruhen
|
|
|
|
|
List<Block> chestBlocks = getChestBlocks(chest);
|
|
|
|
|
|
|
|
|
|
outerLoop:
|
|
|
|
|
for (Block b : chestBlocks) {
|
|
|
|
|
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)
|
|
|
|
|
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, chest.getBlock())) {
|
|
|
|
|
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] : ""));
|
|
|
|
|
@@ -1306,7 +1603,8 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
|
|
|
|
|
isPublic = line3Clean.toLowerCase().endsWith("[public]");
|
|
|
|
|
ownerName = line3Clean.replace(" [Public]", "").replace(" [public]", "").trim();
|
|
|
|
|
break;
|
|
|
|
|
break outerLoop;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1340,13 +1638,16 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
} else {
|
|
|
|
|
// Öffentlich: Wenn Owner offline, können wir keine "Truhe voll" Nachrichten an den Owner senden.
|
|
|
|
|
// Wir sortieren trotzdem.
|
|
|
|
|
// Wir setzen ownerPlayer auf null, damit distributeItems weiß, dass niemand Besitzer ist (für Messages).
|
|
|
|
|
// Wir setzen ownerPlayer auf null, damit distributeItemsForOwner weiß, dass niemand Besitzer ist (für Messages).
|
|
|
|
|
if (ownerPlayer == null || !ownerPlayer.isOnline()) {
|
|
|
|
|
ownerPlayer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wir rufen distributeItems auf.
|
|
|
|
|
// WICHTIG: distributeItems nutzt `player.getUniqueId()` um die Zieltruhen zu finden.
|
|
|
|
|
// Wir rufen distributeItemsForOwner auf.
|
|
|
|
|
// WICHTIG: distributeItemsForOwner nutzt `player.getUniqueId()` um die Zieltruhen zu finden.
|
|
|
|
|
// Das funktioniert auch, wenn ownerPlayer null ist, solange wir die UUID übergeben.
|
|
|
|
|
// Wir müssen aber aufpassen, dass `distributeItems` nicht crasht, wenn player null ist.
|
|
|
|
|
// Wir müssen aber aufpassen, dass `distributeItemsForOwner` nicht crasht, wenn player null ist.
|
|
|
|
|
|
|
|
|
|
distributeItemsForOwner(ownerUUID, ownerPlayer, chest.getInventory());
|
|
|
|
|
}
|
|
|
|
|
@@ -1369,7 +1670,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
ownerName = ownerPlayer.getName();
|
|
|
|
|
} else {
|
|
|
|
|
// Offline-Namen aus PlayerData holen wenn möglich
|
|
|
|
|
org.bukkit.OfflinePlayer offlinePlayer = getServer().getOfflinePlayer(ownerUUID);
|
|
|
|
|
OfflinePlayer offlinePlayer = getServer().getOfflinePlayer(ownerUUID);
|
|
|
|
|
if (offlinePlayer.hasPlayedBefore()) {
|
|
|
|
|
ownerName = offlinePlayer.getName();
|
|
|
|
|
}
|
|
|
|
|
@@ -1380,13 +1681,31 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
if (item == null || item.getType() == Material.AIR) continue;
|
|
|
|
|
|
|
|
|
|
Location targetChestLocation = getTargetChestLocation(ownerUUID, item.getType());
|
|
|
|
|
if (targetChestLocation == null) continue;
|
|
|
|
|
boolean isRestChest = false;
|
|
|
|
|
|
|
|
|
|
// FALLBACK LOGIK: Wenn kein Ziel definiert, suche Rest-Truhe
|
|
|
|
|
if (targetChestLocation == null) {
|
|
|
|
|
targetChestLocation = getRestChestLocation(ownerUUID);
|
|
|
|
|
if (targetChestLocation != null) {
|
|
|
|
|
isRestChest = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (targetChestLocation == null) {
|
|
|
|
|
if (isDebug()) getLogger().fine("Kein Ziel und keine Rest-Truhe für Item " + item.getType().name());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(targetChestLocation.getBlock().getState() instanceof Chest)) {
|
|
|
|
|
if (ownerPlayer != null && canSendFullChestMessage(ownerUUID, item.getType())) {
|
|
|
|
|
ownerPlayer.sendMessage(getMessage("target-chest-missing").replace("%item%", item.getType().name()));
|
|
|
|
|
ownerPlayer.sendMessage(getMessage("target-chest-missing").replace("%item%", (isRestChest ? "Rest-Truhe" : item.getType().name())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isRestChest) {
|
|
|
|
|
playerData.set("players." + ownerUUID + ".rest-chest", null);
|
|
|
|
|
} else {
|
|
|
|
|
playerData.set("players." + ownerUUID + ".target-chests." + item.getType().name(), null);
|
|
|
|
|
}
|
|
|
|
|
savePlayerData();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
@@ -1397,25 +1716,34 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
boolean isValidTarget = false;
|
|
|
|
|
Block signBlock = null;
|
|
|
|
|
|
|
|
|
|
// FIX: Suche Schild an beiden Hälften
|
|
|
|
|
List<Block> chestBlocks = getChestBlocks(targetChest);
|
|
|
|
|
|
|
|
|
|
outerLoop:
|
|
|
|
|
for (Block b : chestBlocks) {
|
|
|
|
|
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)
|
|
|
|
|
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, targetChest.getBlock())) {
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
String signOwnerName = line3Clean.replace("[Public]", "").replace("[public]", "").trim();
|
|
|
|
|
|
|
|
|
|
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("ziel")) {
|
|
|
|
|
if (line0.equalsIgnoreCase("[asc]") && typeMatches) {
|
|
|
|
|
if (signOwnerName.equalsIgnoreCase(ownerName) || signOwnerName.equalsIgnoreCase("Unknown")) {
|
|
|
|
|
isValidTarget = true;
|
|
|
|
|
signBlock = face;
|
|
|
|
|
break;
|
|
|
|
|
break outerLoop;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1435,12 +1763,15 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor {
|
|
|
|
|
String line2 = ChatColor.stripColor((String) (lines[2] != null ? lines[2] : ""));
|
|
|
|
|
String line3Raw = lines[3] != null ? lines[3] : "";
|
|
|
|
|
|
|
|
|
|
if (line0.equalsIgnoreCase("[asc]") && line1.equalsIgnoreCase("ziel")) {
|
|
|
|
|
String colorType = isFull ? "full" : "target";
|
|
|
|
|
if (line0.equalsIgnoreCase("[asc]") && (line1.equalsIgnoreCase("ziel") || line1.equalsIgnoreCase("rest"))) {
|
|
|
|
|
// FIX: Mapping 'ziel' -> 'target'
|
|
|
|
|
String configType = line1.equalsIgnoreCase("rest") ? "rest" : "target";
|
|
|
|
|
String colorType = isFull ? "full" : configType;
|
|
|
|
|
|
|
|
|
|
sign.setLine(0, getSignColor(colorType, "line1") + "[asc]");
|
|
|
|
|
sign.setLine(1, getSignColor(colorType, "line2") + "ziel");
|
|
|
|
|
sign.setLine(1, getSignColor(colorType, "line2") + line1);
|
|
|
|
|
sign.setLine(2, getSignColor(colorType, "line3") + line2);
|
|
|
|
|
sign.setLine(3, line3Raw);
|
|
|
|
|
sign.setLine(3, line3Raw); // Original behalten (mit Farbe)
|
|
|
|
|
sign.update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|