Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e19de4b638 | |||
| 90d66b6e96 | |||
| 11576ef695 | |||
| dd8ae45000 | |||
| adeeb88ca5 | |||
| ba7647c732 | |||
| be191df87e | |||
| a884822115 | |||
| 95052e9da4 | |||
| fe7b0fed4b |
2
pom.xml
2
pom.xml
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.mviper</groupId>
|
<groupId>de.mviper</groupId>
|
||||||
<artifactId>Elevator</artifactId>
|
<artifactId>Elevator</artifactId>
|
||||||
<version>1.2</version>
|
<version>1.5</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
|||||||
@@ -30,20 +30,89 @@ public class DatabaseManager {
|
|||||||
localConfig.set(key + ".name", "Etage");
|
localConfig.set(key + ".name", "Etage");
|
||||||
localConfig.set(key + ".public", true);
|
localConfig.set(key + ".public", true);
|
||||||
saveLocal();
|
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 void removeElevator(Location loc) {
|
||||||
public boolean isElevator(Location loc) { return localConfig.contains(locToKey(loc)); }
|
localConfig.set(locToKey(loc), null);
|
||||||
public String getFloorCustomName(Location loc) { return localConfig.getString(locToKey(loc) + ".name", "Etage"); }
|
saveLocal();
|
||||||
public void setFloorName(Location loc, String name) { localConfig.set(locToKey(loc) + ".name", name); 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) {
|
public UUID getOwner(Location loc) {
|
||||||
String s = localConfig.getString(locToKey(loc) + ".owner");
|
String s = localConfig.getString(locToKey(loc) + ".owner");
|
||||||
return s != null ? UUID.fromString(s) : UUID.randomUUID();
|
return s != null ? UUID.fromString(s) : UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPublic(Location loc) { return localConfig.getBoolean(locToKey(loc) + ".public", true); }
|
public boolean isPublic(Location loc) {
|
||||||
public void setPublic(Location loc, boolean status) { localConfig.set(locToKey(loc) + ".public", status); saveLocal(); }
|
String key = locToKey(loc);
|
||||||
private String locToKey(Location l) { return "data." + l.getWorld().getName() + "_" + l.getBlockX() + "_" + l.getBlockY() + "_" + l.getBlockZ(); }
|
String fullKey = key + ".public";
|
||||||
private void saveLocal() { try { localConfig.save(localFile); } catch (IOException e) { e.printStackTrace(); } }
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,9 @@ public class Elevator extends JavaPlugin implements Listener {
|
|||||||
private DatabaseManager databaseManager;
|
private DatabaseManager databaseManager;
|
||||||
private HologramManager hologramManager;
|
private HologramManager hologramManager;
|
||||||
private String latestVersionFound;
|
private String latestVersionFound;
|
||||||
private final String releaseUrl = "https://git.viper.ipv64.net/M_Viper/Elevator/releases";
|
|
||||||
|
private final int RESOURCE_ID = 132220;
|
||||||
|
private final String releaseUrl = "https://www.spigotmc.org/resources/" + RESOURCE_ID;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -45,20 +47,22 @@ public class Elevator extends JavaPlugin implements Listener {
|
|||||||
// Rezept laden
|
// Rezept laden
|
||||||
registerElevatorRecipe();
|
registerElevatorRecipe();
|
||||||
|
|
||||||
// Update Check starten
|
// Update Check starten (Offizielle Spigot API)
|
||||||
checkForUpdates();
|
checkForUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForUpdates() {
|
private void checkForUpdates() {
|
||||||
new UpdateChecker(this).getLatestVersion(version -> {
|
new UpdateChecker(this, RESOURCE_ID).getLatestVersion(version -> {
|
||||||
this.latestVersionFound = version;
|
this.latestVersionFound = version;
|
||||||
String currentVersion = this.getDescription().getVersion();
|
String currentVersion = this.getDescription().getVersion();
|
||||||
|
|
||||||
if (!currentVersion.equalsIgnoreCase(version)) {
|
if (!currentVersion.equalsIgnoreCase(version)) {
|
||||||
getLogger().info("====================================================");
|
getLogger().info("====================================================");
|
||||||
getLogger().info("NEUES UPDATE VERFÜGBAR: " + version);
|
getLogger().info("NEUES UPDATE VERFÜGBAR: v" + version);
|
||||||
getLogger().info("Download: " + releaseUrl);
|
getLogger().info("Download: " + releaseUrl);
|
||||||
getLogger().info("====================================================");
|
getLogger().info("====================================================");
|
||||||
|
} else {
|
||||||
|
getLogger().info("Plugin ist auf dem neuesten Stand (v" + currentVersion + ").");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -75,7 +79,7 @@ public class Elevator extends JavaPlugin implements Listener {
|
|||||||
TextComponent message = new TextComponent("§eDownload: ");
|
TextComponent message = new TextComponent("§eDownload: ");
|
||||||
TextComponent link = new TextComponent("§6§l[KLICK HIER FÜR UPDATE]");
|
TextComponent link = new TextComponent("§6§l[KLICK HIER FÜR UPDATE]");
|
||||||
link.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, releaseUrl));
|
link.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, releaseUrl));
|
||||||
link.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§7Öffnet die Release-Seite")));
|
link.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§7Öffnet die SpigotMC-Seite")));
|
||||||
|
|
||||||
message.addExtra(link);
|
message.addExtra(link);
|
||||||
player.spigot().sendMessage(message);
|
player.spigot().sendMessage(message);
|
||||||
@@ -85,25 +89,11 @@ public class Elevator extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerElevatorRecipe() {
|
private void registerElevatorRecipe() {
|
||||||
// Das Resultat-Item (Aufzug-Modul)
|
ItemStack item = createElevatorModuleItem();
|
||||||
ItemStack item = new ItemStack(Material.DAYLIGHT_DETECTOR);
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
if (meta != null) {
|
|
||||||
meta.setDisplayName("§b§lAufzug-Modul");
|
|
||||||
meta.setLore(Arrays.asList(
|
|
||||||
"§7Platziere dies als Etage.",
|
|
||||||
"§eRechtsklick: §fMenü öffnen",
|
|
||||||
"§eSpringen/Sneaken: §fReisen"
|
|
||||||
));
|
|
||||||
meta.addEnchant(Enchantment.LUCK, 1, true);
|
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
NamespacedKey key = new NamespacedKey(this, "elevator_module");
|
NamespacedKey key = new NamespacedKey(this, "elevator_module");
|
||||||
ShapedRecipe recipe = new ShapedRecipe(key, item);
|
ShapedRecipe recipe = new ShapedRecipe(key, item);
|
||||||
|
|
||||||
// Shape laden und bereinigen (verhindert den "Length 5" Fehler)
|
|
||||||
List<String> shapeLines = getConfig().getStringList("recipe.shape");
|
List<String> shapeLines = getConfig().getStringList("recipe.shape");
|
||||||
if (shapeLines.size() != 3) {
|
if (shapeLines.size() != 3) {
|
||||||
getLogger().severe("Rezept konnte nicht geladen werden: 'shape' benötigt genau 3 Zeilen!");
|
getLogger().severe("Rezept konnte nicht geladen werden: 'shape' benötigt genau 3 Zeilen!");
|
||||||
@@ -112,14 +102,10 @@ public class Elevator extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
String[] cleanedRows = new String[3];
|
String[] cleanedRows = new String[3];
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
// Entferne alle Leerzeichen für die interne Verarbeitung
|
|
||||||
String line = shapeLines.get(i).replace(" ", "");
|
String line = shapeLines.get(i).replace(" ", "");
|
||||||
|
|
||||||
// Mit Leerzeichen auffüllen, falls die Zeile kürzer als 3 ist
|
|
||||||
while (line.length() < 3) {
|
while (line.length() < 3) {
|
||||||
line += " ";
|
line += " ";
|
||||||
}
|
}
|
||||||
// Kürzen, falls sie länger als 3 ist
|
|
||||||
if (line.length() > 3) {
|
if (line.length() > 3) {
|
||||||
line = line.substring(0, 3);
|
line = line.substring(0, 3);
|
||||||
}
|
}
|
||||||
@@ -128,7 +114,6 @@ public class Elevator extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
recipe.shape(cleanedRows[0], cleanedRows[1], cleanedRows[2]);
|
recipe.shape(cleanedRows[0], cleanedRows[1], cleanedRows[2]);
|
||||||
|
|
||||||
// Zutaten zuweisen
|
|
||||||
ConfigurationSection section = getConfig().getConfigurationSection("recipe.ingredients");
|
ConfigurationSection section = getConfig().getConfigurationSection("recipe.ingredients");
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
getLogger().severe("Keine 'recipe.ingredients' in der Config gefunden!");
|
getLogger().severe("Keine 'recipe.ingredients' in der Config gefunden!");
|
||||||
@@ -167,4 +152,21 @@ public class Elevator extends JavaPlugin implements Listener {
|
|||||||
public static Elevator getInstance() { return instance; }
|
public static Elevator getInstance() { return instance; }
|
||||||
public DatabaseManager getDatabaseManager() { return databaseManager; }
|
public DatabaseManager getDatabaseManager() { return databaseManager; }
|
||||||
public HologramManager getHologramManager() { return hologramManager; }
|
public HologramManager getHologramManager() { return hologramManager; }
|
||||||
|
|
||||||
|
public ItemStack createElevatorModuleItem() {
|
||||||
|
ItemStack item = new ItemStack(Material.DAYLIGHT_DETECTOR);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName("§b§lAufzug-Modul");
|
||||||
|
meta.setLore(Arrays.asList(
|
||||||
|
"§7Platziere dies als Etage.",
|
||||||
|
"§eRechtsklick: §fMenü öffnen",
|
||||||
|
"§eSpringen/Sneaken: §fReisen"
|
||||||
|
));
|
||||||
|
meta.addEnchant(Enchantment.LUCK, 1, true);
|
||||||
|
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,19 +19,26 @@ public class ElevatorCommand implements CommandExecutor {
|
|||||||
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
||||||
Block moduleBlock = null;
|
Block moduleBlock = null;
|
||||||
|
|
||||||
// GROBE ERKENNUNG:
|
// VERBESSERTE ERKENNUNG: Prüfe direkt unter den Füßen und erweiterten Radius
|
||||||
// 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.
|
|
||||||
Location pLoc = p.getLocation();
|
Location pLoc = p.getLocation();
|
||||||
|
|
||||||
outerLoop:
|
// Erst direkt unter dem Spieler prüfen (häufigster Fall)
|
||||||
for (double x = -0.5; x <= 0.5; x += 0.5) {
|
Block directBelow = pLoc.clone().subtract(0, 1, 0).getBlock();
|
||||||
for (double z = -0.5; z <= 0.5; z += 0.5) {
|
if (directBelow.getType() == Material.DAYLIGHT_DETECTOR && db.isElevator(directBelow.getLocation())) {
|
||||||
for (double y = -1.2; y <= 0.2; y += 0.4) {
|
moduleBlock = directBelow;
|
||||||
Block check = pLoc.clone().add(x, y, z).getBlock();
|
}
|
||||||
if (check.getType() == Material.DAYLIGHT_DETECTOR && db.isElevator(check.getLocation())) {
|
|
||||||
moduleBlock = check;
|
// Wenn nicht gefunden, erweiterte Suche
|
||||||
break outerLoop; // Modul gefunden, Suche beenden
|
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) {
|
if (moduleBlock == null) {
|
||||||
p.sendMessage("§8[§bElevator§8] §cKein Aufzug-Modul in deiner Nähe gefunden!");
|
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;
|
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)
|
// Berechtigungs-Check (Besitzer oder Admin)
|
||||||
if (!db.getOwner(moduleBlock.getLocation()).equals(p.getUniqueId()) && !p.hasPermission("elevator.admin")) {
|
if (!db.getOwner(moduleBlock.getLocation()).equals(p.getUniqueId()) && !p.hasPermission("elevator.admin")) {
|
||||||
p.sendMessage("§8[§bElevator§8] §cDies ist nicht dein Aufzug!");
|
p.sendMessage("§8[§bElevator§8] §cDies ist nicht dein Aufzug!");
|
||||||
@@ -61,14 +73,33 @@ public class ElevatorCommand implements CommandExecutor {
|
|||||||
|
|
||||||
// Befehle: /elevator private | public
|
// Befehle: /elevator private | public
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
|
Location modLocation = moduleBlock.getLocation();
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("private")) {
|
if (args[0].equalsIgnoreCase("private")) {
|
||||||
db.setPublic(moduleBlock.getLocation(), false);
|
db.setPublic(modLocation, false);
|
||||||
p.sendMessage("§8[§bElevator§8] §7Status: §cPrivat");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("public")) {
|
if (args[0].equalsIgnoreCase("public")) {
|
||||||
db.setPublic(moduleBlock.getLocation(), true);
|
db.setPublic(modLocation, true);
|
||||||
p.sendMessage("§8[§bElevator§8] §7Status: §aÖffentlich");
|
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;
|
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 name <Text> §7- Namen der Etage ändern");
|
||||||
p.sendMessage("§e/elevator private §7- Zugriff nur für dich");
|
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 public §7- Zugriff für alle");
|
||||||
|
p.sendMessage("§e/elevator status §7- Zeigt den aktuellen Status");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,8 @@ public class ElevatorListener implements Listener {
|
|||||||
"http://textures.minecraft.net/texture/be8440e9d54ec7630b3e387f84e19e15f0b09d438a6bd784305df5d7608e6903";
|
"http://textures.minecraft.net/texture/be8440e9d54ec7630b3e387f84e19e15f0b09d438a6bd784305df5d7608e6903";
|
||||||
|
|
||||||
private final Map<UUID, Long> cooldowns = new HashMap<>();
|
private final Map<UUID, Long> cooldowns = new HashMap<>();
|
||||||
|
private final Map<UUID, Long> deniedMessageCooldown = new HashMap<>(); // NEU: Für "Privat"-Meldungen
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteract(PlayerInteractEvent e) {
|
public void onInteract(PlayerInteractEvent e) {
|
||||||
@@ -48,14 +50,25 @@ public class ElevatorListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (elevatorLoc != null) {
|
if (elevatorLoc != null) {
|
||||||
if (!db.isPublic(elevatorLoc)
|
Player player = e.getPlayer();
|
||||||
&& !db.getOwner(elevatorLoc).equals(e.getPlayer().getUniqueId())
|
boolean isPublic = db.isPublic(elevatorLoc);
|
||||||
&& !e.getPlayer().hasPermission("elevator.admin")) {
|
boolean isOwner = db.getOwner(elevatorLoc).equals(player.getUniqueId());
|
||||||
e.getPlayer().sendMessage("§cDieser Aufzug ist privat!");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.setCancelled(true);
|
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()));
|
showVisualFeedback(p, p.getWorld().getBlockAt(p.getLocation().getBlockX(), targetY, p.getLocation().getBlockZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onJump(PlayerMoveEvent e) {
|
public void onJump(PlayerMoveEvent e) {
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
@@ -211,6 +225,12 @@ public class ElevatorListener implements Listener {
|
|||||||
|
|
||||||
Block b = findModuleUnderPlayer(p);
|
Block b = findModuleUnderPlayer(p);
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
|
// Prüfe Berechtigung
|
||||||
|
if (!hasPermissionToUse(p, b)) {
|
||||||
|
sendDeniedMessage(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cooldowns.put(p.getUniqueId(), System.currentTimeMillis());
|
cooldowns.put(p.getUniqueId(), System.currentTimeMillis());
|
||||||
handleQuickMove(p, 1);
|
handleQuickMove(p, 1);
|
||||||
}
|
}
|
||||||
@@ -225,6 +245,12 @@ public class ElevatorListener implements Listener {
|
|||||||
|
|
||||||
Block b = findModuleUnderPlayer(p);
|
Block b = findModuleUnderPlayer(p);
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
|
// Prüfe Berechtigung
|
||||||
|
if (!hasPermissionToUse(p, b)) {
|
||||||
|
sendDeniedMessage(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cooldowns.put(p.getUniqueId(), System.currentTimeMillis());
|
cooldowns.put(p.getUniqueId(), System.currentTimeMillis());
|
||||||
handleQuickMove(p, -1);
|
handleQuickMove(p, -1);
|
||||||
}
|
}
|
||||||
@@ -242,6 +268,36 @@ public class ElevatorListener implements Listener {
|
|||||||
return null;
|
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");
|
||||||
|
|
||||||
|
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) {
|
private boolean isElevatorModule(Block b) {
|
||||||
if (b == null) return false;
|
if (b == null) return false;
|
||||||
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
||||||
@@ -291,19 +347,43 @@ public class ElevatorListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showVisualFeedback(Player p, Block targetBlock) {
|
private void showVisualFeedback(Player p, Block targetBlock) {
|
||||||
List<Block> floors = findFloorsInColumn(targetBlock);
|
DatabaseManager db = Elevator.getInstance().getDatabaseManager();
|
||||||
floors.sort(Comparator.comparingInt(Block::getY));
|
|
||||||
|
|
||||||
int floorIndex = -1;
|
// Hole benutzerdefinierten Namen
|
||||||
for (int i = 0; i < floors.size(); i++) {
|
String customName = db.getFloorCustomName(targetBlock.getLocation());
|
||||||
if (floors.get(i).getY() == targetBlock.getY()) {
|
|
||||||
floorIndex = i;
|
// Falls ein Custom Name existiert, benutze diesen, sonst Fallback
|
||||||
break;
|
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;
|
String label = (floorIndex <= 0) ? "Erdgeschoss" : "Etage " + floorIndex;
|
||||||
p.sendTitle("", "§b" + label, 5, 25, 5);
|
p.sendTitle("", "§b" + label, 5, 25, 5);
|
||||||
|
|
||||||
|
// Optional: Zeige auch ein Hologramm
|
||||||
|
Elevator.getInstance().getHologramManager().spawnElevatorHolo(
|
||||||
|
p.getLocation(),
|
||||||
|
label
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -331,7 +411,27 @@ public class ElevatorListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
db.removeElevator(e.getBlock().getLocation());
|
e.setDropItems(false);
|
||||||
|
e.setExpToDrop(0);
|
||||||
|
|
||||||
|
Location breakLoc = e.getBlock().getLocation();
|
||||||
|
|
||||||
|
db.removeElevator(breakLoc);
|
||||||
|
e.getBlock().setType(Material.AIR);
|
||||||
|
|
||||||
|
if (e.getPlayer().getGameMode() == GameMode.SURVIVAL) {
|
||||||
|
ItemStack moduleItem = Elevator.getInstance().createElevatorModuleItem();
|
||||||
|
HashMap<Integer, ItemStack> leftover = e.getPlayer().getInventory().addItem(moduleItem);
|
||||||
|
for (ItemStack rest : leftover.values()) {
|
||||||
|
breakLoc.getWorld().dropItemNaturally(breakLoc, rest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (breakLoc.getWorld() != null) {
|
||||||
|
breakLoc.getWorld().spawnParticle(Particle.CLOUD, breakLoc.add(0.5, 0.5, 0.5), 12, 0.2, 0.2, 0.2, 0.01);
|
||||||
|
breakLoc.getWorld().playSound(breakLoc, Sound.BLOCK_IRON_DOOR_CLOSE, 0.7f, 1.6f);
|
||||||
|
}
|
||||||
|
|
||||||
e.getPlayer().sendMessage("§eAufzug-Modul entfernt.");
|
e.getPlayer().sendMessage("§eAufzug-Modul entfernt.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +1,31 @@
|
|||||||
package de.mviper.elevator;
|
package de.mviper.elevator;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Scanner;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class UpdateChecker {
|
public class UpdateChecker {
|
||||||
|
|
||||||
private final Elevator plugin;
|
private final Elevator plugin;
|
||||||
private final String versionUrl = "https://git.viper.ipv64.net/api/v1/repos/M_Viper/Elevator/releases/latest";
|
private final int resourceId;
|
||||||
|
|
||||||
public UpdateChecker(Elevator plugin) {
|
public UpdateChecker(Elevator plugin, int resourceId) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.resourceId = resourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getLatestVersion(Consumer<String> consumer) {
|
public void getLatestVersion(final Consumer<String> consumer) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||||
try {
|
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream();
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(versionUrl).openConnection();
|
Scanner scanner = new Scanner(inputStream)) {
|
||||||
connection.setRequestMethod("GET");
|
if (scanner.hasNext()) {
|
||||||
connection.setConnectTimeout(5000);
|
consumer.accept(scanner.next());
|
||||||
connection.setReadTimeout(5000);
|
|
||||||
|
|
||||||
if (connection.getResponseCode() == 200) {
|
|
||||||
InputStreamReader reader = new InputStreamReader(connection.getInputStream());
|
|
||||||
JsonObject jsonResponse = JsonParser.parseReader(reader).getAsJsonObject();
|
|
||||||
// Holt den Tag-Namen (z.B. v1.1) aus der Gitea API
|
|
||||||
if (jsonResponse.has("tag_name")) {
|
|
||||||
String latestVersion = jsonResponse.get("tag_name").getAsString();
|
|
||||||
consumer.accept(latestVersion);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (IOException exception) {
|
||||||
plugin.getLogger().warning("Update-Check fehlgeschlagen: " + e.getMessage());
|
plugin.getLogger().info("Update-Check fehlgeschlagen: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: Elevator
|
name: Elevator
|
||||||
version: 1.2
|
version: 1.5
|
||||||
main: de.mviper.elevator.Elevator
|
main: de.mviper.elevator.Elevator
|
||||||
api-version: 1.20
|
api-version: 1.20
|
||||||
author: mviper
|
author: mviper
|
||||||
|
|||||||
Reference in New Issue
Block a user