Update from Git Manager GUI
This commit is contained in:
@@ -7,7 +7,10 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Interaction;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TextDisplay;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
@@ -38,6 +41,7 @@ public class HologramModule implements Module, Listener {
|
||||
loadHolograms();
|
||||
Bukkit.getPluginManager().registerEvents(this, NexusLobby.getInstance());
|
||||
|
||||
// Render-Task: Prüft alle 5 Ticks Sichtbarkeit und Placeholder-Updates
|
||||
Bukkit.getScheduler().runTaskTimer(NexusLobby.getInstance(), () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
holograms.values().forEach(h -> h.renderForPlayer(player));
|
||||
@@ -51,12 +55,21 @@ public class HologramModule implements Module, Listener {
|
||||
}
|
||||
|
||||
private void loadHolograms() {
|
||||
// Vorherige Instanzen säubern
|
||||
holograms.values().forEach(NexusHologram::removeAll);
|
||||
holograms.clear();
|
||||
|
||||
for (String id : config.getKeys(false)) {
|
||||
World world = Bukkit.getWorld(config.getString(id + ".world", "world"));
|
||||
String worldName = config.getString(id + ".world");
|
||||
if (worldName == null) continue;
|
||||
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) continue;
|
||||
Location loc = new Location(world, config.getDouble(id + ".x"), config.getDouble(id + ".y"), config.getDouble(id + ".z"));
|
||||
|
||||
Location loc = new Location(world,
|
||||
config.getDouble(id + ".x"),
|
||||
config.getDouble(id + ".y"),
|
||||
config.getDouble(id + ".z"));
|
||||
|
||||
List<String> pages;
|
||||
if (config.isList(id + ".text")) {
|
||||
@@ -72,7 +85,9 @@ public class HologramModule implements Module, Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEntityEvent event) {
|
||||
// Wir prüfen, ob auf ein Interaction-Entity geklickt wurde
|
||||
// Nur auf Interaction-Entities reagieren (Hologramm-Hitboxen)
|
||||
if (!(event.getRightClicked() instanceof Interaction)) return;
|
||||
|
||||
for (NexusHologram holo : holograms.values()) {
|
||||
if (holo.isInteractionEntity(event.getRightClicked().getUniqueId())) {
|
||||
holo.nextPage(event.getPlayer());
|
||||
@@ -93,25 +108,32 @@ public class HologramModule implements Module, Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
// Cleanup alter Entities für den Joiner
|
||||
// Cleanup alter Entity-Reste, die eventuell noch in der Welt schweben
|
||||
Bukkit.getScheduler().runTaskLater(NexusLobby.getInstance(), () -> {
|
||||
event.getPlayer().getWorld().getEntities().forEach(entity -> {
|
||||
Player p = event.getPlayer();
|
||||
for (Entity entity : p.getWorld().getEntities()) {
|
||||
if (entity.getCustomName() != null && entity.getCustomName().startsWith("nexus_h_")) {
|
||||
if (!entity.getCustomName().endsWith("_" + event.getPlayer().getName())) {
|
||||
event.getPlayer().hideEntity(NexusLobby.getInstance(), entity);
|
||||
// Wenn das Hologramm nicht exakt für diesen Spieler benannt ist -> verstecken
|
||||
if (!entity.getCustomName().endsWith("_" + p.getName())) {
|
||||
p.hideEntity(NexusLobby.getInstance(), entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 5L);
|
||||
}
|
||||
}, 10L);
|
||||
}
|
||||
|
||||
public void createHologram(String id, Location loc, List<String> pages) {
|
||||
// Falls ID bereits existiert, altes Hologramm sauber entfernen
|
||||
if (holograms.containsKey(id)) {
|
||||
removeHologram(id);
|
||||
}
|
||||
|
||||
config.set(id + ".world", loc.getWorld().getName());
|
||||
config.set(id + ".x", loc.getX());
|
||||
config.set(id + ".y", loc.getY());
|
||||
config.set(id + ".z", loc.getZ());
|
||||
config.set(id + ".text", pages);
|
||||
try { config.save(file); } catch (IOException e) { e.printStackTrace(); }
|
||||
saveHoloConfig();
|
||||
|
||||
NexusHologram holo = new NexusHologram(id, loc, pages);
|
||||
holograms.put(id, holo);
|
||||
@@ -119,12 +141,34 @@ public class HologramModule implements Module, Listener {
|
||||
|
||||
public void removeHologram(String id) {
|
||||
NexusHologram holo = holograms.remove(id);
|
||||
if (holo != null) holo.removeAll();
|
||||
if (holo != null) {
|
||||
// Erst für alle Spieler visuell entfernen
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
holo.removeForPlayer(player);
|
||||
}
|
||||
// Dann Entities serverseitig löschen
|
||||
holo.removeAll();
|
||||
}
|
||||
config.set(id, null);
|
||||
try { config.save(file); } catch (IOException e) { e.printStackTrace(); }
|
||||
saveHoloConfig();
|
||||
}
|
||||
|
||||
public Set<String> getHologramIds() { return config.getKeys(false); }
|
||||
private void saveHoloConfig() {
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
NexusLobby.getInstance().getLogger().severe("Konnte holograms.yml nicht speichern!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WICHTIG: Diese Methode wird vom LobbyTabCompleter benötigt!
|
||||
* @return Set aller registrierten Hologramm-IDs
|
||||
*/
|
||||
public Set<String> getHologramIds() {
|
||||
return holograms.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
Reference in New Issue
Block a user