Update from Git Manager GUI
This commit is contained in:
@@ -2,7 +2,10 @@ package de.viper.survivalplus.util;
|
||||
|
||||
import de.viper.survivalplus.SurvivalPlus;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.type.Chest;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -10,9 +13,11 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@@ -27,6 +32,7 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
private final Map<Location, LockData> lockedBlocks = new HashMap<>();
|
||||
private final Set<UUID> lockMode = new HashSet<>();
|
||||
private final Map<UUID, BukkitRunnable> lockTimeoutTasks = new HashMap<>();
|
||||
private final Map<UUID, Long> lastDenyMessage = new HashMap<>();
|
||||
|
||||
private final File lockFile;
|
||||
private FileConfiguration lockConfig;
|
||||
@@ -139,7 +145,16 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
if (lockedBlocks.containsKey(loc)) {
|
||||
player.sendMessage(plugin.getMessage("lock.already-locked"));
|
||||
} else {
|
||||
// Lock den Block
|
||||
lockedBlocks.put(loc, new LockData(uuid.toString()));
|
||||
|
||||
// Prüfe auf Doppeltruhe und locke beide Hälften
|
||||
Block otherChest = getOtherChestHalf(block);
|
||||
if (otherChest != null) {
|
||||
Location otherLoc = otherChest.getLocation();
|
||||
lockedBlocks.put(otherLoc, new LockData(uuid.toString()));
|
||||
}
|
||||
|
||||
saveLocks();
|
||||
player.sendMessage(plugin.getMessage("lock.locked"));
|
||||
}
|
||||
@@ -149,7 +164,19 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
}
|
||||
|
||||
if (!isLockable) return;
|
||||
if (!lockedBlocks.containsKey(loc)) return;
|
||||
|
||||
// Prüfe sowohl den geklickten Block als auch die andere Hälfte bei Doppeltruhen
|
||||
if (!lockedBlocks.containsKey(loc)) {
|
||||
Block otherChest = getOtherChestHalf(block);
|
||||
if (otherChest != null) {
|
||||
loc = otherChest.getLocation();
|
||||
if (!lockedBlocks.containsKey(loc)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LockData lock = lockedBlocks.get(loc);
|
||||
String playerUUID = uuid.toString();
|
||||
@@ -162,6 +189,176 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// NEU: Verhindert das Öffnen von gelockten Türen durch Redstone (Druckplatten, Knöpfe, etc.)
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onRedstoneChange(BlockRedstoneEvent event) {
|
||||
Block block = event.getBlock();
|
||||
|
||||
// Prüfe, ob der Block eine Tür ist
|
||||
if (!block.getType().name().contains("DOOR")) return;
|
||||
|
||||
Location loc = block.getLocation();
|
||||
LockData lock = null;
|
||||
|
||||
// Prüfe, ob die Tür gelockt ist
|
||||
if (lockedBlocks.containsKey(loc)) {
|
||||
lock = lockedBlocks.get(loc);
|
||||
} else {
|
||||
// Prüfe auch die andere Hälfte der Tür (oben/unten)
|
||||
Location above = loc.clone().add(0, 1, 0);
|
||||
Location below = loc.clone().add(0, -1, 0);
|
||||
|
||||
if (lockedBlocks.containsKey(above)) {
|
||||
lock = lockedBlocks.get(above);
|
||||
} else if (lockedBlocks.containsKey(below)) {
|
||||
lock = lockedBlocks.get(below);
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn keine Lock gefunden wurde, erlaube die Änderung
|
||||
if (lock == null) return;
|
||||
|
||||
// Wenn die Tür gelockt ist und Redstone-Signal empfängt, blockiere die Änderung
|
||||
// Es sei denn, das Signal kommt von einem berechtigten Spieler (wird über Druckplatten-Event geprüft)
|
||||
if (event.getNewCurrent() > 0) {
|
||||
event.setNewCurrent(0);
|
||||
}
|
||||
}
|
||||
|
||||
// ZUSÄTZLICH: Verhindert Interaktion mit Druckplatten/Knöpfen in der Nähe von gelockten Türen
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPressurePlateInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.PHYSICAL) return;
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) return;
|
||||
|
||||
// Prüfe, ob es eine Druckplatte ist
|
||||
String typeName = block.getType().name();
|
||||
if (!typeName.contains("PRESSURE_PLATE")) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
// Prüfe alle angrenzenden Blöcke auf gelockte Türen
|
||||
for (BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
|
||||
Block relative = block.getRelative(face);
|
||||
|
||||
// Prüfe bis zu 2 Blöcke in jede Richtung
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (relative.getType().name().contains("DOOR")) {
|
||||
Location doorLoc = relative.getLocation();
|
||||
|
||||
// Prüfe beide Türhälften
|
||||
LockData lock = getLockData(doorLoc);
|
||||
|
||||
if (lock != null && !hasAccess(player, lock)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
// Anti-Spam: Nur alle 3 Sekunden eine Nachricht senden
|
||||
long currentTime = System.currentTimeMillis();
|
||||
Long lastMessage = lastDenyMessage.get(playerUUID);
|
||||
|
||||
if (lastMessage == null || (currentTime - lastMessage) > 3000) {
|
||||
player.sendMessage(plugin.getMessage("lock.block-denied"));
|
||||
lastDenyMessage.put(playerUUID, currentTime);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
relative = relative.getRelative(face);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLockedDoor(Location loc) {
|
||||
return lockedBlocks.containsKey(loc);
|
||||
}
|
||||
|
||||
private LockData getLockData(Location loc) {
|
||||
LockData lock = lockedBlocks.get(loc);
|
||||
if (lock == null) {
|
||||
lock = lockedBlocks.get(loc.clone().add(0, 1, 0));
|
||||
}
|
||||
if (lock == null) {
|
||||
lock = lockedBlocks.get(loc.clone().add(0, -1, 0));
|
||||
}
|
||||
return lock;
|
||||
}
|
||||
|
||||
private boolean hasAccess(Player player, LockData lock) {
|
||||
String playerUUID = player.getUniqueId().toString();
|
||||
return lock.getOwnerUUID().equals(playerUUID) ||
|
||||
lock.isFriend(playerUUID) ||
|
||||
player.isOp();
|
||||
}
|
||||
|
||||
// Hilfsmethode: Findet die andere Hälfte einer Doppeltruhe
|
||||
private Block getOtherChestHalf(Block block) {
|
||||
if (block.getType() != Material.CHEST && block.getType() != Material.TRAPPED_CHEST) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// Versuche moderne BlockData API (1.13+)
|
||||
if (block.getBlockData() instanceof Chest) {
|
||||
Chest chestData = (Chest) block.getBlockData();
|
||||
|
||||
// Prüfe ob es eine Doppeltruhe ist
|
||||
if (chestData.getType() == Chest.Type.SINGLE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Finde die Richtung zur anderen Hälfte
|
||||
BlockFace facing = chestData.getFacing();
|
||||
BlockFace direction;
|
||||
|
||||
if (chestData.getType() == Chest.Type.LEFT) {
|
||||
// Linke Hälfte: Andere Hälfte ist rechts
|
||||
direction = getRight(facing);
|
||||
} else {
|
||||
// Rechte Hälfte: Andere Hälfte ist links
|
||||
direction = getLeft(facing);
|
||||
}
|
||||
|
||||
Block otherBlock = block.getRelative(direction);
|
||||
if (otherBlock.getType() == block.getType()) {
|
||||
return otherBlock;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Fallback für ältere Versionen: Prüfe alle angrenzenden Blöcke
|
||||
for (BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
|
||||
Block relative = block.getRelative(face);
|
||||
if (relative.getType() == block.getType()) {
|
||||
return relative;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private BlockFace getRight(BlockFace face) {
|
||||
switch (face) {
|
||||
case NORTH: return BlockFace.EAST;
|
||||
case EAST: return BlockFace.SOUTH;
|
||||
case SOUTH: return BlockFace.WEST;
|
||||
case WEST: return BlockFace.NORTH;
|
||||
default: return face;
|
||||
}
|
||||
}
|
||||
|
||||
private BlockFace getLeft(BlockFace face) {
|
||||
switch (face) {
|
||||
case NORTH: return BlockFace.WEST;
|
||||
case WEST: return BlockFace.SOUTH;
|
||||
case SOUTH: return BlockFace.EAST;
|
||||
case EAST: return BlockFace.NORTH;
|
||||
default: return face;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@@ -174,6 +371,13 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
String playerUUID = player.getUniqueId().toString();
|
||||
|
||||
if (lock.getOwnerUUID().equals(playerUUID) || lock.isFriend(playerUUID) || player.isOp()) {
|
||||
// Erlaube das Brechen und entferne beide Locks bei Doppeltruhen
|
||||
lockedBlocks.remove(loc);
|
||||
Block otherChest = getOtherChestHalf(block);
|
||||
if (otherChest != null) {
|
||||
lockedBlocks.remove(otherChest.getLocation());
|
||||
}
|
||||
saveLocks();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -233,6 +437,13 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
player.sendMessage(plugin.getMessage("lock.no-permission-unlock"));
|
||||
} else {
|
||||
lockedBlocks.remove(loc);
|
||||
|
||||
// Entferne auch Lock von der anderen Hälfte bei Doppeltruhen
|
||||
Block otherChest = getOtherChestHalf(targetBlock);
|
||||
if (otherChest != null) {
|
||||
lockedBlocks.remove(otherChest.getLocation());
|
||||
}
|
||||
|
||||
saveLocks();
|
||||
player.sendMessage(plugin.getMessage("lock.unlocked"));
|
||||
}
|
||||
@@ -254,6 +465,16 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
player.sendMessage(plugin.getMessage("lock.friendadd.not-found"));
|
||||
} else {
|
||||
lock.addFriend(friend.getUniqueId().toString());
|
||||
|
||||
// Füge Friend auch zur anderen Hälfte bei Doppeltruhen hinzu
|
||||
Block otherChest = getOtherChestHalf(targetBlock);
|
||||
if (otherChest != null) {
|
||||
LockData otherLock = lockedBlocks.get(otherChest.getLocation());
|
||||
if (otherLock != null) {
|
||||
otherLock.addFriend(friend.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
saveLocks();
|
||||
player.sendMessage(plugin.getMessage("lock.friendadd.success").replace("{player}", friend.getName()));
|
||||
}
|
||||
@@ -276,6 +497,16 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
player.sendMessage(plugin.getMessage("lock.friendremove.not-found"));
|
||||
} else {
|
||||
lock.removeFriend(friend.getUniqueId().toString());
|
||||
|
||||
// Entferne Friend auch von der anderen Hälfte bei Doppeltruhen
|
||||
Block otherChest = getOtherChestHalf(targetBlock);
|
||||
if (otherChest != null) {
|
||||
LockData otherLock = lockedBlocks.get(otherChest.getLocation());
|
||||
if (otherLock != null) {
|
||||
otherLock.removeFriend(friend.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
saveLocks();
|
||||
player.sendMessage(plugin.getMessage("lock.friendremove.success").replace("{player}", friend.getName()));
|
||||
}
|
||||
@@ -289,4 +520,4 @@ public class LockSystem implements Listener, CommandExecutor {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user