Update from Git Manager GUI
This commit is contained in:
@@ -30,20 +30,89 @@ public class DatabaseManager {
|
||||
localConfig.set(key + ".name", "Etage");
|
||||
localConfig.set(key + ".public", true);
|
||||
saveLocal();
|
||||
|
||||
// Debug-Ausgabe
|
||||
Elevator.getInstance().getLogger().info("Aufzug hinzugefügt: " + key + " | Public: true");
|
||||
}
|
||||
|
||||
public void removeElevator(Location loc) { localConfig.set(locToKey(loc), null); saveLocal(); }
|
||||
public boolean isElevator(Location loc) { return localConfig.contains(locToKey(loc)); }
|
||||
public String getFloorCustomName(Location loc) { return localConfig.getString(locToKey(loc) + ".name", "Etage"); }
|
||||
public void setFloorName(Location loc, String name) { localConfig.set(locToKey(loc) + ".name", name); saveLocal(); }
|
||||
public void removeElevator(Location loc) {
|
||||
localConfig.set(locToKey(loc), null);
|
||||
saveLocal();
|
||||
}
|
||||
|
||||
public boolean isElevator(Location loc) {
|
||||
return localConfig.contains(locToKey(loc));
|
||||
}
|
||||
|
||||
public String getFloorCustomName(Location loc) {
|
||||
return localConfig.getString(locToKey(loc) + ".name", "Etage");
|
||||
}
|
||||
|
||||
public void setFloorName(Location loc, String name) {
|
||||
localConfig.set(locToKey(loc) + ".name", name);
|
||||
saveLocal();
|
||||
}
|
||||
|
||||
public UUID getOwner(Location loc) {
|
||||
String s = localConfig.getString(locToKey(loc) + ".owner");
|
||||
return s != null ? UUID.fromString(s) : UUID.randomUUID();
|
||||
}
|
||||
|
||||
public boolean isPublic(Location loc) { return localConfig.getBoolean(locToKey(loc) + ".public", true); }
|
||||
public void setPublic(Location loc, boolean status) { localConfig.set(locToKey(loc) + ".public", status); saveLocal(); }
|
||||
private String locToKey(Location l) { return "data." + l.getWorld().getName() + "_" + l.getBlockX() + "_" + l.getBlockY() + "_" + l.getBlockZ(); }
|
||||
private void saveLocal() { try { localConfig.save(localFile); } catch (IOException e) { e.printStackTrace(); } }
|
||||
public boolean isPublic(Location loc) {
|
||||
String key = locToKey(loc);
|
||||
String fullKey = key + ".public";
|
||||
|
||||
// Prüfe zuerst, ob der Aufzug überhaupt existiert
|
||||
if (!localConfig.contains(key)) {
|
||||
Elevator.getInstance().getLogger().warning("isPublic: Aufzug existiert nicht: " + key);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Wenn der public-Schlüssel nicht existiert, setze ihn auf true (Standard)
|
||||
if (!localConfig.contains(fullKey)) {
|
||||
Elevator.getInstance().getLogger().info("isPublic: Schlüssel nicht gefunden, setze auf true: " + fullKey);
|
||||
localConfig.set(fullKey, true);
|
||||
saveLocal();
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean value = localConfig.getBoolean(fullKey, true);
|
||||
Elevator.getInstance().getLogger().info("isPublic: " + fullKey + " = " + value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setPublic(Location loc, boolean status) {
|
||||
String key = locToKey(loc);
|
||||
String fullKey = key + ".public";
|
||||
|
||||
// Prüfe, ob der Aufzug existiert
|
||||
if (!localConfig.contains(key)) {
|
||||
Elevator.getInstance().getLogger().warning("setPublic: Aufzug existiert nicht: " + key);
|
||||
return;
|
||||
}
|
||||
|
||||
localConfig.set(fullKey, status);
|
||||
saveLocal();
|
||||
|
||||
// Sofort nochmal laden um zu verifizieren
|
||||
localConfig = YamlConfiguration.loadConfiguration(localFile);
|
||||
boolean verification = localConfig.getBoolean(fullKey, true);
|
||||
|
||||
Elevator.getInstance().getLogger().info("setPublic: " + fullKey + " auf " + status + " gesetzt (Verifiziert: " + verification + ")");
|
||||
}
|
||||
|
||||
private String locToKey(Location l) {
|
||||
// Wichtig: Nutze getBlockX/Y/Z für konsistente Koordinaten
|
||||
String key = "data." + l.getWorld().getName() + "_" + l.getBlockX() + "_" + l.getBlockY() + "_" + l.getBlockZ();
|
||||
return key;
|
||||
}
|
||||
|
||||
private void saveLocal() {
|
||||
try {
|
||||
localConfig.save(localFile);
|
||||
Elevator.getInstance().getLogger().info("Datenbank gespeichert: " + localFile.getName());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,19 +19,26 @@ public class ElevatorCommand implements CommandExecutor {
|
||||
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
||||
Block moduleBlock = null;
|
||||
|
||||
// GROBE ERKENNUNG:
|
||||
// Wir prüfen einen kleinen Radius (0.5 Blöcke) um den Spieler und 1.2 Blöcke nach unten.
|
||||
// Das stellt sicher, dass man nicht pixelgenau in der Mitte stehen muss.
|
||||
// VERBESSERTE ERKENNUNG: Prüfe direkt unter den Füßen und erweiterten Radius
|
||||
Location pLoc = p.getLocation();
|
||||
|
||||
outerLoop:
|
||||
for (double x = -0.5; x <= 0.5; x += 0.5) {
|
||||
for (double z = -0.5; z <= 0.5; z += 0.5) {
|
||||
for (double y = -1.2; y <= 0.2; y += 0.4) {
|
||||
Block check = pLoc.clone().add(x, y, z).getBlock();
|
||||
if (check.getType() == Material.DAYLIGHT_DETECTOR && db.isElevator(check.getLocation())) {
|
||||
moduleBlock = check;
|
||||
break outerLoop; // Modul gefunden, Suche beenden
|
||||
// Erst direkt unter dem Spieler prüfen (häufigster Fall)
|
||||
Block directBelow = pLoc.clone().subtract(0, 1, 0).getBlock();
|
||||
if (directBelow.getType() == Material.DAYLIGHT_DETECTOR && db.isElevator(directBelow.getLocation())) {
|
||||
moduleBlock = directBelow;
|
||||
}
|
||||
|
||||
// Wenn nicht gefunden, erweiterte Suche
|
||||
if (moduleBlock == null) {
|
||||
outerLoop:
|
||||
for (double x = -1.0; x <= 1.0; x += 0.5) {
|
||||
for (double z = -1.0; z <= 1.0; z += 0.5) {
|
||||
for (double y = -2.0; y <= 0.5; y += 0.5) {
|
||||
Block check = pLoc.clone().add(x, y, z).getBlock();
|
||||
if (check.getType() == Material.DAYLIGHT_DETECTOR && db.isElevator(check.getLocation())) {
|
||||
moduleBlock = check;
|
||||
break outerLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,9 +46,14 @@ public class ElevatorCommand implements CommandExecutor {
|
||||
|
||||
if (moduleBlock == null) {
|
||||
p.sendMessage("§8[§bElevator§8] §cKein Aufzug-Modul in deiner Nähe gefunden!");
|
||||
p.sendMessage("§7Tipp: Stelle dich direkt auf das Daylight-Detector Modul.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Debug-Ausgabe
|
||||
Location modLoc = moduleBlock.getLocation();
|
||||
Elevator.getInstance().getLogger().info("Command: Modul gefunden bei X:" + modLoc.getBlockX() + " Y:" + modLoc.getBlockY() + " Z:" + modLoc.getBlockZ());
|
||||
|
||||
// Berechtigungs-Check (Besitzer oder Admin)
|
||||
if (!db.getOwner(moduleBlock.getLocation()).equals(p.getUniqueId()) && !p.hasPermission("elevator.admin")) {
|
||||
p.sendMessage("§8[§bElevator§8] §cDies ist nicht dein Aufzug!");
|
||||
@@ -61,14 +73,33 @@ public class ElevatorCommand implements CommandExecutor {
|
||||
|
||||
// Befehle: /elevator private | public
|
||||
if (args.length == 1) {
|
||||
Location modLocation = moduleBlock.getLocation();
|
||||
|
||||
if (args[0].equalsIgnoreCase("private")) {
|
||||
db.setPublic(moduleBlock.getLocation(), false);
|
||||
db.setPublic(modLocation, false);
|
||||
p.sendMessage("§8[§bElevator§8] §7Status: §cPrivat");
|
||||
p.sendMessage("§7Nur du kannst diesen Aufzug nun benutzen.");
|
||||
|
||||
// Verifizierung
|
||||
boolean currentStatus = db.isPublic(modLocation);
|
||||
p.sendMessage("§8[Debug] Aktueller Status nach Änderung: " + (currentStatus ? "§aÖffentlich" : "§cPrivat"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("public")) {
|
||||
db.setPublic(moduleBlock.getLocation(), true);
|
||||
db.setPublic(modLocation, true);
|
||||
p.sendMessage("§8[§bElevator§8] §7Status: §aÖffentlich");
|
||||
p.sendMessage("§7Alle Spieler können diesen Aufzug nun benutzen.");
|
||||
|
||||
// Verifizierung
|
||||
boolean currentStatus = db.isPublic(modLocation);
|
||||
p.sendMessage("§8[Debug] Aktueller Status nach Änderung: " + (currentStatus ? "§aÖffentlich" : "§cPrivat"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("status")) {
|
||||
boolean isPublic = db.isPublic(modLocation);
|
||||
p.sendMessage("§8[§bElevator§8] §7Aktueller Status: " + (isPublic ? "§aÖffentlich" : "§cPrivat"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -78,6 +109,7 @@ public class ElevatorCommand implements CommandExecutor {
|
||||
p.sendMessage("§e/elevator name <Text> §7- Namen der Etage ändern");
|
||||
p.sendMessage("§e/elevator private §7- Zugriff nur für dich");
|
||||
p.sendMessage("§e/elevator public §7- Zugriff für alle");
|
||||
p.sendMessage("§e/elevator status §7- Zeigt den aktuellen Status");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ public class ElevatorListener implements Listener {
|
||||
"http://textures.minecraft.net/texture/be8440e9d54ec7630b3e387f84e19e15f0b09d438a6bd784305df5d7608e6903";
|
||||
|
||||
private final Map<UUID, Long> cooldowns = new HashMap<>();
|
||||
private final Map<UUID, Long> deniedMessageCooldown = new HashMap<>(); // NEU: Für "Privat"-Meldungen
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent e) {
|
||||
@@ -48,14 +50,25 @@ public class ElevatorListener implements Listener {
|
||||
}
|
||||
|
||||
if (elevatorLoc != null) {
|
||||
if (!db.isPublic(elevatorLoc)
|
||||
&& !db.getOwner(elevatorLoc).equals(e.getPlayer().getUniqueId())
|
||||
&& !e.getPlayer().hasPermission("elevator.admin")) {
|
||||
e.getPlayer().sendMessage("§cDieser Aufzug ist privat!");
|
||||
Player player = e.getPlayer();
|
||||
boolean isPublic = db.isPublic(elevatorLoc);
|
||||
boolean isOwner = db.getOwner(elevatorLoc).equals(player.getUniqueId());
|
||||
boolean isAdmin = player.hasPermission("elevator.admin");
|
||||
|
||||
// Debug-Ausgabe
|
||||
Elevator.getInstance().getLogger().info("Spieler " + player.getName() + " interagiert mit Aufzug:");
|
||||
Elevator.getInstance().getLogger().info(" -> Public: " + isPublic);
|
||||
Elevator.getInstance().getLogger().info(" -> IsOwner: " + isOwner);
|
||||
Elevator.getInstance().getLogger().info(" -> IsAdmin: " + isAdmin);
|
||||
|
||||
if (!isPublic && !isOwner && !isAdmin) {
|
||||
player.sendMessage("§8[§bElevator§8] §cDieser Aufzug ist privat!");
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
openGUI(e.getPlayer(), elevatorLoc.getBlock());
|
||||
openGUI(player, elevatorLoc.getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +215,7 @@ public class ElevatorListener implements Listener {
|
||||
showVisualFeedback(p, p.getWorld().getBlockAt(p.getLocation().getBlockX(), targetY, p.getLocation().getBlockZ()));
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onJump(PlayerMoveEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
@@ -211,6 +225,12 @@ public class ElevatorListener implements Listener {
|
||||
|
||||
Block b = findModuleUnderPlayer(p);
|
||||
if (b != null) {
|
||||
// Prüfe Berechtigung
|
||||
if (!hasPermissionToUse(p, b)) {
|
||||
sendDeniedMessage(p);
|
||||
return;
|
||||
}
|
||||
|
||||
cooldowns.put(p.getUniqueId(), System.currentTimeMillis());
|
||||
handleQuickMove(p, 1);
|
||||
}
|
||||
@@ -225,6 +245,12 @@ public class ElevatorListener implements Listener {
|
||||
|
||||
Block b = findModuleUnderPlayer(p);
|
||||
if (b != null) {
|
||||
// Prüfe Berechtigung
|
||||
if (!hasPermissionToUse(p, b)) {
|
||||
sendDeniedMessage(p);
|
||||
return;
|
||||
}
|
||||
|
||||
cooldowns.put(p.getUniqueId(), System.currentTimeMillis());
|
||||
handleQuickMove(p, -1);
|
||||
}
|
||||
@@ -242,6 +268,39 @@ public class ElevatorListener implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Prüft, ob der Spieler den Aufzug benutzen darf
|
||||
private boolean hasPermissionToUse(Player p, Block elevatorBlock) {
|
||||
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
||||
Location loc = elevatorBlock.getLocation();
|
||||
|
||||
boolean isPublic = db.isPublic(loc);
|
||||
boolean isOwner = db.getOwner(loc).equals(p.getUniqueId());
|
||||
boolean isAdmin = p.hasPermission("elevator.admin");
|
||||
|
||||
// Debug
|
||||
Elevator.getInstance().getLogger().info("Permission-Check für " + p.getName() + ": Public=" + isPublic + ", Owner=" + isOwner + ", Admin=" + isAdmin);
|
||||
|
||||
return isPublic || isOwner || isAdmin;
|
||||
}
|
||||
|
||||
// Sendet "Privat"-Meldung nur, wenn Cooldown abgelaufen ist
|
||||
private void sendDeniedMessage(Player p) {
|
||||
UUID playerId = p.getUniqueId();
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
// Prüfe ob Cooldown aktiv ist (3 Sekunden)
|
||||
if (deniedMessageCooldown.containsKey(playerId)) {
|
||||
long lastMessage = deniedMessageCooldown.get(playerId);
|
||||
if (now - lastMessage < 3000) {
|
||||
return; // Cooldown noch aktiv, keine Nachricht senden
|
||||
}
|
||||
}
|
||||
|
||||
// Sende Nachricht und setze Cooldown
|
||||
p.sendMessage("§8[§bElevator§8] §cDieser Aufzug ist privat!");
|
||||
deniedMessageCooldown.put(playerId, now);
|
||||
}
|
||||
|
||||
private boolean isElevatorModule(Block b) {
|
||||
if (b == null) return false;
|
||||
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
||||
@@ -291,19 +350,43 @@ public class ElevatorListener implements Listener {
|
||||
}
|
||||
|
||||
private void showVisualFeedback(Player p, Block targetBlock) {
|
||||
List<Block> floors = findFloorsInColumn(targetBlock);
|
||||
floors.sort(Comparator.comparingInt(Block::getY));
|
||||
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
||||
|
||||
int floorIndex = -1;
|
||||
for (int i = 0; i < floors.size(); i++) {
|
||||
if (floors.get(i).getY() == targetBlock.getY()) {
|
||||
floorIndex = i;
|
||||
break;
|
||||
// Hole benutzerdefinierten Namen
|
||||
String customName = db.getFloorCustomName(targetBlock.getLocation());
|
||||
|
||||
// Falls ein Custom Name existiert, benutze diesen, sonst Fallback
|
||||
if (customName != null && !customName.isEmpty() && !customName.equals("Etage")) {
|
||||
// Benutzer hat einen eigenen Namen vergeben
|
||||
p.sendTitle("", "§b" + customName, 5, 25, 5);
|
||||
|
||||
// Optional: Zeige auch ein Hologramm
|
||||
Elevator.getInstance().getHologramManager().spawnElevatorHolo(
|
||||
p.getLocation(),
|
||||
customName
|
||||
);
|
||||
} else {
|
||||
// Standard: Etagen-Nummer anzeigen
|
||||
List<Block> floors = findFloorsInColumn(targetBlock);
|
||||
floors.sort(Comparator.comparingInt(Block::getY));
|
||||
|
||||
int floorIndex = -1;
|
||||
for (int i = 0; i < floors.size(); i++) {
|
||||
if (floors.get(i).getY() == targetBlock.getY()) {
|
||||
floorIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String label = (floorIndex <= 0) ? "Erdgeschoss" : "Etage " + floorIndex;
|
||||
p.sendTitle("", "§b" + label, 5, 25, 5);
|
||||
String label = (floorIndex <= 0) ? "Erdgeschoss" : "Etage " + floorIndex;
|
||||
p.sendTitle("", "§b" + label, 5, 25, 5);
|
||||
|
||||
// Optional: Zeige auch ein Hologramm
|
||||
Elevator.getInstance().getHologramManager().spawnElevatorHolo(
|
||||
p.getLocation(),
|
||||
label
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: Elevator
|
||||
version: 1.4
|
||||
version: 1.5
|
||||
main: de.mviper.elevator.Elevator
|
||||
api-version: 1.20
|
||||
author: mviper
|
||||
|
||||
Reference in New Issue
Block a user