Delete src/main/java/de/lasertag/listener/SignListener.java via Git Manager GUI
This commit is contained in:
@@ -1,246 +0,0 @@
|
||||
package de.lasertag.listener;
|
||||
|
||||
import de.lasertag.LasertagPlugin;
|
||||
import de.lasertag.game.Game;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.sign.Side;
|
||||
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.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Join-Schild System.
|
||||
*
|
||||
* EIN SCHILD ERSTELLEN:
|
||||
* Schreibe auf Zeile 1 exakt: [Lasertag]
|
||||
* Schreibe auf Zeile 2: Den Arenannamen
|
||||
*
|
||||
* Das Plugin erkennt das Schild automatisch und:
|
||||
* - Aktualisiert Status/Spielerzahl live
|
||||
* - Lässt Spieler durch Rechtsklick beitreten
|
||||
*
|
||||
* Format:
|
||||
* Zeile 1: §b[LASERTAG]
|
||||
* Zeile 2: §eArena-Name
|
||||
* Zeile 3: §aWartend / §eStartet / §cLäuft / §8Voll
|
||||
* Zeile 4: §72/16
|
||||
*/
|
||||
public class SignListener implements Listener {
|
||||
|
||||
private final LasertagPlugin plugin;
|
||||
|
||||
/** Location → Arenaname (gespeicherte Schilder) */
|
||||
private final Map<Location, String> signs = new HashMap<>();
|
||||
private File signsFile;
|
||||
private BukkitTask updateTask;
|
||||
|
||||
public SignListener(LasertagPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
loadSigns();
|
||||
startUpdateTask();
|
||||
}
|
||||
|
||||
// ─── Schild erstellen ────────────────────────────────────────────────────
|
||||
|
||||
@EventHandler
|
||||
public void onSignChange(SignChangeEvent e) {
|
||||
// Zeile 1 (Index 0) prüfen
|
||||
String line0 = e.getLine(0);
|
||||
if (line0 == null) return;
|
||||
|
||||
String trigger = plugin.getConfigManager().getSignTriggerLine();
|
||||
if (!ChatColor.stripColor(line0).equalsIgnoreCase(ChatColor.stripColor(trigger))) return;
|
||||
|
||||
if (!e.getPlayer().hasPermission("lasertag.admin")) {
|
||||
e.getPlayer().sendMessage(plugin.getConfigManager().getPrefix()
|
||||
+ "§cNur Admins können Lasertag-Schilder erstellen!");
|
||||
return;
|
||||
}
|
||||
|
||||
String arenaName = ChatColor.stripColor(e.getLine(1) != null ? e.getLine(1) : "");
|
||||
if (arenaName.isEmpty()) {
|
||||
e.getPlayer().sendMessage(plugin.getConfigManager().getPrefix()
|
||||
+ "§cZeile 2 muss den Arenannamen enthalten!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getArenaManager().getArena(arenaName) == null) {
|
||||
e.getPlayer().sendMessage(plugin.getConfigManager().getPrefix()
|
||||
+ "§cArena '§e" + arenaName + "§c' nicht gefunden!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Schild registrieren
|
||||
signs.put(e.getBlock().getLocation(), arenaName);
|
||||
saveSigns();
|
||||
|
||||
// Zeilen setzen
|
||||
e.setLine(0, "§b§l[LASERTAG]");
|
||||
e.setLine(1, "§e" + arenaName);
|
||||
e.setLine(2, "§7Initialisierung...");
|
||||
e.setLine(3, "§7...");
|
||||
|
||||
e.getPlayer().sendMessage(plugin.getConfigManager().getPrefix()
|
||||
+ "§aJoin-Schild für Arena §e" + arenaName + " §aerstellt!");
|
||||
|
||||
// Sofort aktualisieren
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> updateSign(e.getBlock().getLocation(), arenaName), 2L);
|
||||
}
|
||||
|
||||
// ─── Schild anklicken (Beitreten) ────────────────────────────────────────
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent e) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (e.getClickedBlock() == null) return;
|
||||
if (!(e.getClickedBlock().getState() instanceof Sign)) return;
|
||||
|
||||
Location loc = e.getClickedBlock().getLocation();
|
||||
String arenaName = signs.get(loc);
|
||||
if (arenaName == null) return;
|
||||
|
||||
e.setCancelled(true);
|
||||
Player player = e.getPlayer();
|
||||
|
||||
// Ist Spieler bereits in einem Spiel?
|
||||
if (plugin.getGameManager().getGameOf(player) != null) {
|
||||
player.sendMessage(plugin.getConfigManager().getPrefix()
|
||||
+ "§cDu bist bereits in einem Spiel! /lt leave");
|
||||
return;
|
||||
}
|
||||
|
||||
// Beitreten versuchen
|
||||
boolean joined = plugin.getGameManager().joinGame(player, arenaName);
|
||||
if (joined) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1.2f);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Schild zerstören ────────────────────────────────────────────────────
|
||||
|
||||
@EventHandler
|
||||
public void onBreak(BlockBreakEvent e) {
|
||||
Location loc = e.getBlock().getLocation();
|
||||
if (!signs.containsKey(loc)) return;
|
||||
|
||||
if (!e.getPlayer().hasPermission("lasertag.admin")) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(plugin.getConfigManager().getPrefix()
|
||||
+ "§cNur Admins können Lasertag-Schilder abbauen!");
|
||||
return;
|
||||
}
|
||||
|
||||
signs.remove(loc);
|
||||
saveSigns();
|
||||
e.getPlayer().sendMessage(plugin.getConfigManager().getPrefix()
|
||||
+ "§aJoin-Schild entfernt.");
|
||||
}
|
||||
|
||||
// ─── Update-Task ─────────────────────────────────────────────────────────
|
||||
|
||||
private void startUpdateTask() {
|
||||
int interval = plugin.getConfigManager().getSignUpdateInterval();
|
||||
updateTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
for (Map.Entry<Location, String> entry : new HashMap<>(signs).entrySet()) {
|
||||
updateSign(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}, 20L, interval);
|
||||
}
|
||||
|
||||
public void stopUpdateTask() {
|
||||
if (updateTask != null) updateTask.cancel();
|
||||
}
|
||||
|
||||
private void updateSign(Location loc, String arenaName) {
|
||||
Block block = loc.getBlock();
|
||||
if (!(block.getState() instanceof Sign sign)) {
|
||||
// Block ist kein Schild mehr → entfernen
|
||||
signs.remove(loc);
|
||||
saveSigns();
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = plugin.getGameManager().getGame(arenaName);
|
||||
var cfg = plugin.getConfigManager();
|
||||
|
||||
String line2, line3;
|
||||
|
||||
if (game == null || !game.getArena().isReady() || !game.getArena().isEnabled()) {
|
||||
line2 = "§c§lNICHT BEREIT";
|
||||
line3 = "§8Setup fehlt";
|
||||
} else {
|
||||
boolean full = game.getPlayerCount() >= game.getMaxPlayers();
|
||||
String color = switch (game.getState()) {
|
||||
case WAITING -> full ? cfg.getSignColorFull() : cfg.getSignColorWaiting();
|
||||
case STARTING -> cfg.getSignColorStarting();
|
||||
case RUNNING -> cfg.getSignColorRunning();
|
||||
case ENDING -> "§7";
|
||||
};
|
||||
String statusText = switch (game.getState()) {
|
||||
case WAITING -> full ? "Voll" : "Warten";
|
||||
case STARTING -> "Startet...";
|
||||
case RUNNING -> "Läuft";
|
||||
case ENDING -> "Beendet";
|
||||
};
|
||||
line2 = color + statusText;
|
||||
line3 = "§7" + game.getPlayerCount() + "§8/§7" + game.getMaxPlayers();
|
||||
}
|
||||
|
||||
// Spigot 1.20: Sign hat Vorder- und Rückseite
|
||||
try {
|
||||
var signSide = sign.getSide(Side.FRONT);
|
||||
signSide.setLine(0, "§b§l[LASERTAG]");
|
||||
signSide.setLine(1, "§e" + arenaName);
|
||||
signSide.setLine(2, line2);
|
||||
signSide.setLine(3, line3);
|
||||
} catch (Exception ex) {
|
||||
// Fallback für ältere API
|
||||
sign.setLine(0, "§b§l[LASERTAG]");
|
||||
sign.setLine(1, "§e" + arenaName);
|
||||
sign.setLine(2, line2);
|
||||
sign.setLine(3, line3);
|
||||
}
|
||||
sign.update();
|
||||
}
|
||||
|
||||
// ─── Persistenz ──────────────────────────────────────────────────────────
|
||||
|
||||
private void loadSigns() {
|
||||
signsFile = new File(plugin.getDataFolder(), "signs.yml");
|
||||
if (!signsFile.exists()) return;
|
||||
FileConfiguration cfg = YamlConfiguration.loadConfiguration(signsFile);
|
||||
if (!cfg.contains("signs")) return;
|
||||
for (String key : cfg.getConfigurationSection("signs").getKeys(false)) {
|
||||
Location loc = cfg.getLocation("signs." + key + ".location");
|
||||
String arena = cfg.getString("signs." + key + ".arena");
|
||||
if (loc != null && arena != null) signs.put(loc, arena);
|
||||
}
|
||||
plugin.getLogger().info("§a" + signs.size() + " Join-Schilder geladen.");
|
||||
}
|
||||
|
||||
private void saveSigns() {
|
||||
FileConfiguration cfg = new YamlConfiguration();
|
||||
int i = 0;
|
||||
for (Map.Entry<Location, String> e : signs.entrySet()) {
|
||||
cfg.set("signs." + i + ".location", e.getKey());
|
||||
cfg.set("signs." + i + ".arena", e.getValue());
|
||||
i++;
|
||||
}
|
||||
try { cfg.save(signsFile); } catch (IOException ex) { ex.printStackTrace(); }
|
||||
}
|
||||
|
||||
public int getSignCount() { return signs.size(); }
|
||||
}
|
||||
Reference in New Issue
Block a user