Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
5602041fdf | |||
133243abea | |||
8ebbe282cc | |||
24a017d794 | |||
4f3bfd0403 |
@@ -1,6 +1,6 @@
|
||||
# 🧩 SurvivalPlus
|
||||
|
||||
**Version:** 1.0.0
|
||||
**Version:** 1.0.1
|
||||
**Autor:** M_Viper
|
||||
**API-Version:** 1.21
|
||||
**Beschreibung:**
|
||||
|
@@ -58,118 +58,122 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
private AFKListener afkListener;
|
||||
private GraveListener graveListener;
|
||||
private SitListener sitListener;
|
||||
private PlayerJoinListener playerJoinListener; // Neuer Listener
|
||||
private PlayerJoinListener playerJoinListener;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
updateConfigFiles(); // Config-Dateien aktualisieren
|
||||
createHomesFile();
|
||||
createGravesFile();
|
||||
createBackpackFile();
|
||||
createFriendsFile();
|
||||
createLeashesFile();
|
||||
createMobCapFile();
|
||||
@Override
|
||||
public void onEnable() {
|
||||
updateConfigFiles(); // Config-Dateien aktualisieren
|
||||
createHomesFile();
|
||||
createGravesFile();
|
||||
createBackpackFile();
|
||||
createFriendsFile();
|
||||
createLeashesFile();
|
||||
createMobCapFile();
|
||||
|
||||
// FirstJoinListener registrieren
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new FirstJoinListener(), this);
|
||||
// PluginManager holen
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
|
||||
// FriendCommand instanzieren für PlayerJoinListener
|
||||
FriendCommand friendCommand = new FriendCommand(this, friendsConfig, langConfig, getLogger());
|
||||
// FriendCommand instanzieren
|
||||
FriendCommand friendCommand = new FriendCommand(this, friendsConfig, langConfig, getLogger());
|
||||
|
||||
// Commands
|
||||
getCommand("gm").setExecutor(new GamemodeCommand(this));
|
||||
getCommand("sp").setExecutor(new PluginCommand(this));
|
||||
getCommand("sethome").setExecutor(new HomeCommand(this));
|
||||
getCommand("delhome").setExecutor(new HomeCommand(this));
|
||||
getCommand("homelist").setExecutor(new HomeCommand(this));
|
||||
getCommand("inv").setExecutor(new InventoryCommand(this));
|
||||
getCommand("ec").setExecutor(new EnderchestCommand(this));
|
||||
getCommand("setspawn").setExecutor(new SetSpawnCommand(this));
|
||||
getCommand("setworldspawn").setExecutor(new SetWorldSpawnCommand(this));
|
||||
getCommand("clearchat").setExecutor(new ClearChatCommand());
|
||||
getCommand("clearitems").setExecutor(new ClearItemsCommand(this));
|
||||
getCommand("closedoors").setExecutor(new CloseDoorsCommand(this));
|
||||
getCommand("sit").setExecutor(new SitCommand(this, sitListener));
|
||||
getCommand("back").setExecutor(new BackCommand(this));
|
||||
getCommand("friend").setExecutor(friendCommand);
|
||||
getCommand("ir").setExecutor(new ItemRenameCommand(this));
|
||||
getCommand("showarmorstands").setExecutor(new ShowArmorStandsCommand(this));
|
||||
getCommand("cleardebugarmorstands").setExecutor(new ClearDebugArmorStandsCommand(this));
|
||||
getCommand("trash").setExecutor(new TrashCommand());
|
||||
getCommand("workbench").setExecutor(new WorkbenchCommand());
|
||||
getCommand("anvil").setExecutor(new AnvilCommand());
|
||||
TeleportCommands teleportCommands = new TeleportCommands(this);
|
||||
getCommand("tp").setExecutor(teleportCommands);
|
||||
getCommand("tphere").setExecutor(teleportCommands);
|
||||
getCommand("tpa").setExecutor(teleportCommands);
|
||||
getCommand("tpaccept").setExecutor(teleportCommands);
|
||||
getCommand("tpdeny").setExecutor(teleportCommands);
|
||||
getCommand("kit").setExecutor(new KitCommand(this));
|
||||
// StatsManager vor den Listenern initialisieren
|
||||
statsManager = new StatsManager(this);
|
||||
|
||||
// BlockManager erstellen
|
||||
BlockManager blockManager = new BlockManager();
|
||||
// Listener initialisieren (sitListener zuerst!)
|
||||
sitListener = new SitListener(this);
|
||||
afkListener = new AFKListener(this);
|
||||
graveListener = new GraveListener(this);
|
||||
playerJoinListener = new PlayerJoinListener(friendCommand);
|
||||
|
||||
// Konfiguration laden
|
||||
FileConfiguration config = getConfig();
|
||||
// Commands registrieren
|
||||
getCommand("gm").setExecutor(new GamemodeCommand(this));
|
||||
getCommand("sp").setExecutor(new PluginCommand(this));
|
||||
getCommand("sethome").setExecutor(new HomeCommand(this));
|
||||
getCommand("delhome").setExecutor(new HomeCommand(this));
|
||||
getCommand("homelist").setExecutor(new HomeCommand(this));
|
||||
getCommand("inv").setExecutor(new InventoryCommand(this));
|
||||
getCommand("ec").setExecutor(new EnderchestCommand(this));
|
||||
getCommand("setspawn").setExecutor(new SetSpawnCommand(this));
|
||||
getCommand("setworldspawn").setExecutor(new SetWorldSpawnCommand(this));
|
||||
getCommand("clearchat").setExecutor(new ClearChatCommand());
|
||||
getCommand("clearitems").setExecutor(new ClearItemsCommand(this));
|
||||
getCommand("closedoors").setExecutor(new CloseDoorsCommand(this));
|
||||
getCommand("sit").setExecutor(new SitCommand(this, sitListener));
|
||||
getCommand("back").setExecutor(new BackCommand(this));
|
||||
getCommand("friend").setExecutor(friendCommand);
|
||||
getCommand("ir").setExecutor(new ItemRenameCommand(this));
|
||||
getCommand("showarmorstands").setExecutor(new ShowArmorStandsCommand(this));
|
||||
getCommand("cleardebugarmorstands").setExecutor(new ClearDebugArmorStandsCommand(this));
|
||||
getCommand("trash").setExecutor(new TrashCommand());
|
||||
getCommand("workbench").setExecutor(new WorkbenchCommand());
|
||||
getCommand("anvil").setExecutor(new AnvilCommand());
|
||||
|
||||
// Listener registrieren
|
||||
BackpackRecipe.register(this, langConfig);
|
||||
TeleportCommands teleportCommands = new TeleportCommands(this);
|
||||
getCommand("tp").setExecutor(teleportCommands);
|
||||
getCommand("tphere").setExecutor(teleportCommands);
|
||||
getCommand("tpa").setExecutor(teleportCommands);
|
||||
getCommand("tpaccept").setExecutor(teleportCommands);
|
||||
getCommand("tpdeny").setExecutor(teleportCommands);
|
||||
|
||||
sitListener = new SitListener(this);
|
||||
afkListener = new AFKListener(this);
|
||||
graveListener = new GraveListener(this);
|
||||
playerJoinListener = new PlayerJoinListener(friendCommand); // PlayerJoinListener registrieren
|
||||
getCommand("kit").setExecutor(new KitCommand(this));
|
||||
|
||||
pluginManager.registerEvents(new ChatBlockListener(blockManager), this);
|
||||
pluginManager.registerEvents(new InventoryClickListener(this), this);
|
||||
pluginManager.registerEvents(sitListener, this);
|
||||
pluginManager.registerEvents(afkListener, this);
|
||||
pluginManager.registerEvents(graveListener, this);
|
||||
pluginManager.registerEvents(new BackpackListener(backpackConfig, langConfig, getLogger(), backpackFile), this);
|
||||
pluginManager.registerEvents(new StatsListener(this, statsManager), this);
|
||||
pluginManager.registerEvents(new LoginListener(this), this);
|
||||
pluginManager.registerEvents(new DebugArmorStandListener(), this);
|
||||
pluginManager.registerEvents(new ArmorStandDestroyListener(), this);
|
||||
pluginManager.registerEvents(playerJoinListener, this); // Listener hinzufügen
|
||||
// BlockManager erstellen
|
||||
BlockManager blockManager = new BlockManager();
|
||||
|
||||
// Befehle mit BlockManager und Konfiguration registrieren
|
||||
getCommand("block").setExecutor(new BlockCommand(blockManager, config));
|
||||
getCommand("blocklist").setExecutor(new BlockListCommand(blockManager, config));
|
||||
getCommand("unblock").setExecutor(new UnblockCommand(blockManager, config));
|
||||
// Konfiguration laden
|
||||
FileConfiguration config = getConfig();
|
||||
|
||||
// Stats
|
||||
statsManager = new StatsManager(this);
|
||||
pluginManager.registerEvents(new StatsListener(this, statsManager), this);
|
||||
getCommand("stats").setExecutor(new StatsCommand(this, statsManager));
|
||||
// Listener registrieren
|
||||
BackpackRecipe.register(this, langConfig);
|
||||
|
||||
sleepListener = new SleepListener(this);
|
||||
pluginManager.registerEvents(sleepListener, this);
|
||||
pluginManager.registerEvents(new ChatBlockListener(blockManager), this);
|
||||
pluginManager.registerEvents(new InventoryClickListener(this), this);
|
||||
pluginManager.registerEvents(sitListener, this);
|
||||
pluginManager.registerEvents(afkListener, this);
|
||||
pluginManager.registerEvents(graveListener, this);
|
||||
pluginManager.registerEvents(new BackpackListener(backpackConfig, langConfig, getLogger(), backpackFile), this);
|
||||
pluginManager.registerEvents(new StatsListener(this, statsManager), this);
|
||||
pluginManager.registerEvents(new LoginListener(this), this);
|
||||
pluginManager.registerEvents(new DebugArmorStandListener(), this);
|
||||
pluginManager.registerEvents(new ArmorStandDestroyListener(), this);
|
||||
pluginManager.registerEvents(new FirstJoinListener(), this);
|
||||
pluginManager.registerEvents(playerJoinListener, this);
|
||||
|
||||
oreAlarmListener = new OreAlarmListener(this);
|
||||
pluginManager.registerEvents(oreAlarmListener, this);
|
||||
// Befehle mit BlockManager und Konfiguration registrieren
|
||||
getCommand("block").setExecutor(new BlockCommand(blockManager, config));
|
||||
getCommand("blocklist").setExecutor(new BlockListCommand(blockManager, config));
|
||||
getCommand("unblock").setExecutor(new UnblockCommand(blockManager, config));
|
||||
|
||||
mobLeashLimitListener = new MobLeashLimitListener(this, getConfig());
|
||||
pluginManager.registerEvents(mobLeashLimitListener, this);
|
||||
// Stats-Befehl registrieren
|
||||
getCommand("stats").setExecutor(new StatsCommand(this, statsManager));
|
||||
|
||||
mobCapListener = new MobCapListener(this, getConfig());
|
||||
pluginManager.registerEvents(mobCapListener, this);
|
||||
sleepListener = new SleepListener(this);
|
||||
pluginManager.registerEvents(sleepListener, this);
|
||||
|
||||
spawnProtectionListener = new SpawnProtectionListener(this);
|
||||
pluginManager.registerEvents(spawnProtectionListener, this);
|
||||
oreAlarmListener = new OreAlarmListener(this);
|
||||
pluginManager.registerEvents(oreAlarmListener, this);
|
||||
|
||||
LockSystem lockSystem = new LockSystem(this);
|
||||
pluginManager.registerEvents(lockSystem, this);
|
||||
getCommand("lock").setExecutor(lockSystem);
|
||||
mobLeashLimitListener = new MobLeashLimitListener(this, getConfig());
|
||||
pluginManager.registerEvents(mobLeashLimitListener, this);
|
||||
|
||||
// AutoClear Task starten
|
||||
startAutoClearTask();
|
||||
mobCapListener = new MobCapListener(this, getConfig());
|
||||
pluginManager.registerEvents(mobCapListener, this);
|
||||
|
||||
// Beispiel ArmorStand
|
||||
spawnArmorStandExample();
|
||||
spawnProtectionListener = new SpawnProtectionListener(this);
|
||||
pluginManager.registerEvents(spawnProtectionListener, this);
|
||||
|
||||
getLogger().info(getMessage("plugin.enabled"));
|
||||
}
|
||||
LockSystem lockSystem = new LockSystem(this);
|
||||
pluginManager.registerEvents(lockSystem, this);
|
||||
getCommand("lock").setExecutor(lockSystem);
|
||||
|
||||
// AutoClear Task starten
|
||||
startAutoClearTask();
|
||||
|
||||
// Beispiel ArmorStand spawnen
|
||||
spawnArmorStandExample();
|
||||
|
||||
getLogger().info(getMessage("plugin.enabled"));
|
||||
}
|
||||
|
||||
private void spawnArmorStandExample() {
|
||||
World world = Bukkit.getWorld("world");
|
||||
@@ -605,7 +609,7 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
sitListener = new SitListener(this);
|
||||
pm.registerEvents(sitListener, this);
|
||||
|
||||
playerJoinListener = new PlayerJoinListener(friendCommand); // PlayerJoinListener neu registrieren
|
||||
playerJoinListener = new PlayerJoinListener(friendCommand);
|
||||
pm.registerEvents(playerJoinListener, this);
|
||||
|
||||
pm.registerEvents(new InventoryClickListener(this), this);
|
||||
|
@@ -1,54 +1,57 @@
|
||||
package de.viper.survivalplus.commands;
|
||||
|
||||
import de.viper.survivalplus.SurvivalPlus;
|
||||
import de.viper.survivalplus.listeners.SitListener;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class SitCommand implements CommandExecutor {
|
||||
private final SurvivalPlus plugin;
|
||||
private final SitListener sitListener;
|
||||
|
||||
public SitCommand(SurvivalPlus plugin, SitListener sitListener) {
|
||||
this.plugin = plugin;
|
||||
this.sitListener = sitListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(plugin.getLangConfig().getString("player-only", "§cDieser Befehl ist nur für Spieler!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
FileConfiguration lang = plugin.getLangConfig();
|
||||
|
||||
if (!player.hasPermission("survivalplus.sit")) {
|
||||
player.sendMessage(lang.getString("no-permission", "§cDu hast keine Berechtigung für diesen Befehl!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 0) {
|
||||
player.sendMessage(lang.getString("sit.usage", "§cVerwendung: /sit"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prüfe, ob der Spieler bereits sitzt
|
||||
if (sitListener.isSitting(player)) {
|
||||
sitListener.standUp(player);
|
||||
player.sendMessage(lang.getString("sit.stand-up", "§aDu bist aufgestanden!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Setze den Spieler direkt auf dem Block
|
||||
Location location = player.getLocation();
|
||||
location.setY(location.getBlockY()); // Direkt auf dem Block (keine Y-Verschiebung)
|
||||
sitListener.sitPlayer(player, location);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package de.viper.survivalplus.commands;
|
||||
|
||||
import de.viper.survivalplus.SurvivalPlus;
|
||||
import de.viper.survivalplus.listeners.SitListener;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class SitCommand implements CommandExecutor {
|
||||
private final SurvivalPlus plugin;
|
||||
private final SitListener sitListener;
|
||||
|
||||
public SitCommand(SurvivalPlus plugin, SitListener sitListener) {
|
||||
this.plugin = plugin;
|
||||
this.sitListener = sitListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(plugin.getLangConfig().getString("player-only", "§cDieser Befehl ist nur für Spieler!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
FileConfiguration lang = plugin.getLangConfig();
|
||||
|
||||
if (!player.hasPermission("survivalplus.sit")) {
|
||||
player.sendMessage(lang.getString("no-permission", "§cDu hast keine Berechtigung für diesen Befehl!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 0) {
|
||||
player.sendMessage(lang.getString("sit.usage", "§cVerwendung: /sit"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prüfe, ob der Spieler bereits sitzt
|
||||
if (sitListener.isSitting(player)) {
|
||||
sitListener.standUp(player);
|
||||
player.sendMessage(lang.getString("sit.stand-up", "§aDu bist aufgestanden!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Setze den Spieler mittig auf den Block und leicht oberhalb (Fix)
|
||||
Location location = player.getLocation();
|
||||
location.setX(location.getBlockX() + 0.5);
|
||||
location.setY(location.getBlockY() + 0.25);
|
||||
location.setZ(location.getBlockZ() + 0.5);
|
||||
|
||||
sitListener.sitPlayer(player, location);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,128 +1,128 @@
|
||||
package de.viper.survivalplus.listeners;
|
||||
|
||||
import de.viper.survivalplus.SurvivalPlus;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.event.block.Action;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SitListener implements Listener {
|
||||
private final SurvivalPlus plugin;
|
||||
private final Map<UUID, ArmorStand> sittingPlayers = new HashMap<>();
|
||||
|
||||
public SitListener(SurvivalPlus plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean isSitting(Player player) {
|
||||
return sittingPlayers.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void sitPlayer(Player player, Location location) {
|
||||
if (sittingPlayers.containsKey(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Erstelle einen unsichtbaren ArmorStand als Sitz
|
||||
ArmorStand armorStand = player.getWorld().spawn(location, ArmorStand.class);
|
||||
armorStand.setGravity(false);
|
||||
armorStand.setMarker(true);
|
||||
armorStand.setInvisible(true);
|
||||
armorStand.setInvulnerable(true);
|
||||
armorStand.addPassenger(player);
|
||||
|
||||
sittingPlayers.put(player.getUniqueId(), armorStand);
|
||||
FileConfiguration lang = plugin.getLangConfig();
|
||||
player.sendMessage(lang.getString("sit.success", "§aDu hast dich hingesetzt!"));
|
||||
plugin.getLogger().log(Level.FINE, "Spieler " + player.getName() + " sitzt bei " + locationToString(location));
|
||||
}
|
||||
|
||||
public void standUp(Player player) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
ArmorStand armorStand = sittingPlayers.remove(playerId);
|
||||
if (armorStand != null) {
|
||||
armorStand.remove();
|
||||
FileConfiguration lang = plugin.getLangConfig();
|
||||
player.sendMessage(lang.getString("sit.stand-up", "§aDu bist aufgestanden!"));
|
||||
plugin.getLogger().log(Level.FINE, "Spieler " + player.getName() + " ist aufgestanden");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getHand() != EquipmentSlot.HAND || event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
FileConfiguration lang = plugin.getLangConfig();
|
||||
|
||||
if (!player.hasPermission("survivalplus.sit")) {
|
||||
player.sendMessage(lang.getString("no-permission", "§cDu hast keine Berechtigung für diesen Befehl!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null || !isStair(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wenn der Spieler bereits sitzt, stehe auf
|
||||
if (sittingPlayers.containsKey(player.getUniqueId())) {
|
||||
standUp(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Setze den Spieler genau auf der Treppenstufe
|
||||
Location location = block.getLocation();
|
||||
location.setX(location.getX() + 0.5);
|
||||
location.setY(location.getY() + 0.5); // Genau auf der Treppenstufe (halbe Blockhöhe)
|
||||
location.setZ(location.getZ() + 0.5);
|
||||
sitPlayer(player, location);
|
||||
event.setCancelled(true); // Verhindere andere Interaktionen mit der Treppe
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (!sittingPlayers.containsKey(playerId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prüfe, ob der Spieler sich bewegt hat (nur Positionsänderung, nicht Kopfbewegung)
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
if (from.getX() != to.getX() || from.getY() != to.getY() || from.getZ() != to.getZ()) {
|
||||
standUp(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
standUp(player);
|
||||
}
|
||||
|
||||
private boolean isStair(Material material) {
|
||||
return material.name().endsWith("_STAIRS");
|
||||
}
|
||||
|
||||
private String locationToString(Location loc) {
|
||||
return String.format("x=%.2f, y=%.2f, z=%.2f, world=%s", loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName());
|
||||
}
|
||||
}
|
||||
package de.viper.survivalplus.listeners;
|
||||
|
||||
import de.viper.survivalplus.SurvivalPlus;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.event.block.Action;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SitListener implements Listener {
|
||||
private final SurvivalPlus plugin;
|
||||
private final Map<UUID, ArmorStand> sittingPlayers = new HashMap<>();
|
||||
|
||||
public SitListener(SurvivalPlus plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean isSitting(Player player) {
|
||||
return sittingPlayers.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void sitPlayer(Player player, Location location) {
|
||||
if (sittingPlayers.containsKey(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Erstelle einen unsichtbaren ArmorStand als Sitz
|
||||
ArmorStand armorStand = player.getWorld().spawn(location, ArmorStand.class);
|
||||
armorStand.setGravity(false);
|
||||
armorStand.setMarker(true);
|
||||
armorStand.setInvisible(true);
|
||||
armorStand.setInvulnerable(true);
|
||||
armorStand.addPassenger(player);
|
||||
|
||||
sittingPlayers.put(player.getUniqueId(), armorStand);
|
||||
FileConfiguration lang = plugin.getLangConfig();
|
||||
player.sendMessage(lang.getString("sit.success", "§aDu hast dich hingesetzt!"));
|
||||
plugin.getLogger().log(Level.FINE, "Spieler " + player.getName() + " sitzt bei " + locationToString(location));
|
||||
}
|
||||
|
||||
public void standUp(Player player) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
ArmorStand armorStand = sittingPlayers.remove(playerId);
|
||||
if (armorStand != null) {
|
||||
armorStand.remove();
|
||||
FileConfiguration lang = plugin.getLangConfig();
|
||||
player.sendMessage(lang.getString("sit.stand-up", "§aDu bist aufgestanden!"));
|
||||
plugin.getLogger().log(Level.FINE, "Spieler " + player.getName() + " ist aufgestanden");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getHand() != EquipmentSlot.HAND || event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
FileConfiguration lang = plugin.getLangConfig();
|
||||
|
||||
if (!player.hasPermission("survivalplus.sit")) {
|
||||
player.sendMessage(lang.getString("no-permission", "§cDu hast keine Berechtigung für diesen Befehl!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null || !isStair(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wenn der Spieler bereits sitzt, stehe auf
|
||||
if (sittingPlayers.containsKey(player.getUniqueId())) {
|
||||
standUp(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Setze den Spieler genau auf der Treppenstufe
|
||||
Location location = block.getLocation();
|
||||
location.setX(location.getX() + 0.5);
|
||||
location.setY(location.getY() + 0.5); // Genau auf der Treppenstufe (halbe Blockhöhe)
|
||||
location.setZ(location.getZ() + 0.5);
|
||||
sitPlayer(player, location);
|
||||
event.setCancelled(true); // Verhindere andere Interaktionen mit der Treppe
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (!sittingPlayers.containsKey(playerId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prüfe, ob der Spieler sich bewegt hat (nur Positionsänderung, nicht Kopfbewegung)
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
if (from.getX() != to.getX() || from.getY() != to.getY() || from.getZ() != to.getZ()) {
|
||||
standUp(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
standUp(player);
|
||||
}
|
||||
|
||||
private boolean isStair(Material material) {
|
||||
return material.name().endsWith("_STAIRS");
|
||||
}
|
||||
|
||||
private String locationToString(Location loc) {
|
||||
return String.format("x=%.2f, y=%.2f, z=%.2f, world=%s", loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user