Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
f22052e5f2 | |||
bc801863e1 | |||
c237f2b8c3 | |||
7700c588ff | |||
851ec03788 | |||
a2e75a7142 | |||
c762eff2a1 | |||
cbaa562e1d | |||
a225838f26 | |||
ed1948b8b4 | |||
f9948d8ccc | |||
1c5c03cf63 | |||
e71074a453 | |||
c8ee265de5 | |||
18c041434e | |||
94d64821a6 | |||
3e7c4cbc13 | |||
2df3a217e4 | |||
9078098fb0 | |||
dc14a8dac2 | |||
6a221a3cbe | |||
4187194a3d | |||
fac39de66f | |||
f03efaa6e6 | |||
6016d2af9b |
@@ -16,8 +16,10 @@ public class AFKManager {
|
||||
private final Plugin plugin;
|
||||
private final long afkAfterMillis;
|
||||
private final long kickAfterMillis;
|
||||
private final long joinGracePeriodMillis = 5000; // 5 Sekunden Schonfrist
|
||||
|
||||
private final Map<UUID, Long> lastActivity = new HashMap<>();
|
||||
private final Map<UUID, Long> joinTimes = new HashMap<>();
|
||||
private final Set<UUID> afkPlayers = new HashSet<>();
|
||||
private final Map<UUID, BossBar> bossBars = new WeakHashMap<>();
|
||||
private final Map<UUID, Integer> colorIndex = new HashMap<>();
|
||||
@@ -37,6 +39,9 @@ public class AFKManager {
|
||||
public void updateActivity(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
lastActivity.put(uuid, System.currentTimeMillis());
|
||||
if (!joinTimes.containsKey(uuid)) {
|
||||
joinTimes.put(uuid, System.currentTimeMillis()); // Join-Zeit speichern
|
||||
}
|
||||
|
||||
if (afkPlayers.contains(uuid)) {
|
||||
afkPlayers.remove(uuid);
|
||||
@@ -47,6 +52,7 @@ public class AFKManager {
|
||||
public void reset(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
lastActivity.remove(uuid);
|
||||
joinTimes.remove(uuid); // Join-Zeit entfernen
|
||||
afkPlayers.remove(uuid);
|
||||
removeAFKBossBar(player);
|
||||
}
|
||||
@@ -59,6 +65,17 @@ public class AFKManager {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
// AFK-Prüfung überspringen, wenn Spieler in der Schonfrist ist
|
||||
if (joinTimes.containsKey(uuid) && (currentTime - joinTimes.get(uuid) < joinGracePeriodMillis)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// AFK-Prüfung für Kreativ- oder Zuschauermodus überspringen
|
||||
if (player.getGameMode() == org.bukkit.GameMode.CREATIVE ||
|
||||
player.getGameMode() == org.bukkit.GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!lastActivity.containsKey(uuid)) {
|
||||
lastActivity.put(uuid, currentTime);
|
||||
return;
|
||||
@@ -70,10 +87,11 @@ public class AFKManager {
|
||||
if (diff >= afkAfterMillis) {
|
||||
if (!afkPlayers.contains(uuid)) {
|
||||
afkPlayers.add(uuid);
|
||||
// BossBar wird im Listener angezeigt
|
||||
showAFKBossBar(player, "§cDu bist AFK!");
|
||||
}
|
||||
|
||||
if (kickAfterMillis > 0 && diff >= kickAfterMillis) {
|
||||
plugin.getLogger().info("Spieler " + player.getName() + " wird wegen AFK gekickt. Inaktiv seit: " + (diff / 1000) + " Sekunden");
|
||||
player.kickPlayer("§cDu wurdest wegen AFK gekickt.");
|
||||
}
|
||||
} else {
|
||||
@@ -86,7 +104,7 @@ public class AFKManager {
|
||||
|
||||
public void showAFKBossBar(Player player, String message) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
removeAFKBossBar(player); // sicherstellen, dass nur eine BossBar aktiv ist
|
||||
removeAFKBossBar(player); // Sicherstellen, dass nur eine BossBar aktiv ist
|
||||
|
||||
BossBar bar = Bukkit.createBossBar(message, BarColor.YELLOW, BarStyle.SOLID, BarFlag.CREATE_FOG);
|
||||
bar.addPlayer(player);
|
||||
@@ -121,7 +139,7 @@ public class AFKManager {
|
||||
colorIndex.put(uuid, (index + 1) % colorCycle.size());
|
||||
}
|
||||
};
|
||||
task.runTaskTimer(plugin, 0L, 20L); // alle 20 Ticks (1 Sekunde)
|
||||
task.runTaskTimer(plugin, 0L, 20L); // Alle 20 Ticks (1 Sekunde)
|
||||
colorTasks.put(uuid, task);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,37 @@
|
||||
package de.viper.survivalplus.Manager;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockManager {
|
||||
|
||||
private final Map<UUID, Set<UUID>> blockedPlayers = new HashMap<>();
|
||||
|
||||
public void blockPlayer(Player blocker, Player toBlock) {
|
||||
blockedPlayers.computeIfAbsent(blocker.getUniqueId(), k -> new HashSet<>()).add(toBlock.getUniqueId());
|
||||
}
|
||||
|
||||
public void unblockPlayer(Player blocker, Player toUnblock) {
|
||||
Set<UUID> blocked = blockedPlayers.get(blocker.getUniqueId());
|
||||
if (blocked != null) {
|
||||
blocked.remove(toUnblock.getUniqueId());
|
||||
if (blocked.isEmpty()) {
|
||||
blockedPlayers.remove(blocker.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasBlocked(Player blocker, Player potentialBlocked) {
|
||||
return blockedPlayers.getOrDefault(blocker.getUniqueId(), Collections.emptySet())
|
||||
.contains(potentialBlocked.getUniqueId());
|
||||
}
|
||||
|
||||
public Set<UUID> getBlockedPlayers(Player player) {
|
||||
return blockedPlayers.getOrDefault(player.getUniqueId(), Collections.emptySet());
|
||||
}
|
||||
|
||||
public void clear(Player player) {
|
||||
blockedPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
@@ -7,21 +7,13 @@ import de.viper.survivalplus.listeners.ArmorStandDestroyListener;
|
||||
import de.viper.survivalplus.tasks.AutoClearTask;
|
||||
import de.viper.survivalplus.recipe.BackpackRecipe;
|
||||
import de.viper.survivalplus.Manager.StatsManager;
|
||||
import de.viper.survivalplus.commands.StatsCommand;
|
||||
import de.viper.survivalplus.commands.TrashCommand;
|
||||
import de.viper.survivalplus.commands.WorkbenchCommand;
|
||||
import de.viper.survivalplus.commands.AnvilCommand;
|
||||
import de.viper.survivalplus.listeners.MobLeashLimitListener;
|
||||
import de.viper.survivalplus.listeners.MobCapListener;
|
||||
import de.viper.survivalplus.listeners.SpawnProtectionListener;
|
||||
import de.viper.survivalplus.Manager.BlockManager;
|
||||
import de.viper.survivalplus.util.LockSystem;
|
||||
import de.viper.survivalplus.commands.TeleportCommands;
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
@@ -32,6 +24,7 @@ import org.bukkit.event.HandlerList;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SurvivalPlus extends JavaPlugin {
|
||||
@@ -54,13 +47,10 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
private FileConfiguration mobCapConfig;
|
||||
|
||||
private SpawnProtectionListener spawnProtectionListener;
|
||||
|
||||
|
||||
private int autoClearTaskId = -1;
|
||||
|
||||
private StatsManager statsManager;
|
||||
|
||||
// Listener als Feld speichern, damit man sie beim Reload abmelden kann
|
||||
// Listener als Felder speichern
|
||||
private MobLeashLimitListener mobLeashLimitListener;
|
||||
private MobCapListener mobCapListener;
|
||||
private SleepListener sleepListener;
|
||||
@@ -68,28 +58,24 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
private AFKListener afkListener;
|
||||
private GraveListener graveListener;
|
||||
private SitListener sitListener;
|
||||
|
||||
|
||||
private PlayerJoinListener playerJoinListener; // Neuer Listener
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
createLangFile();
|
||||
updateConfigFiles(); // Config-Dateien aktualisieren
|
||||
createHomesFile();
|
||||
createGravesFile();
|
||||
createHelpFile();
|
||||
createBackpackFile();
|
||||
createFriendsFile();
|
||||
createLeashesFile();
|
||||
createMobCapFile();
|
||||
|
||||
// FirstJoinListener registrieren
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new FirstJoinListener(), this);
|
||||
|
||||
BackpackRecipe.register(this, langConfig);
|
||||
|
||||
|
||||
sitListener = new SitListener(this);
|
||||
afkListener = new AFKListener(this);
|
||||
graveListener = new GraveListener(this);
|
||||
// FriendCommand instanzieren für PlayerJoinListener
|
||||
FriendCommand friendCommand = new FriendCommand(this, friendsConfig, langConfig, getLogger());
|
||||
|
||||
// Commands
|
||||
getCommand("gm").setExecutor(new GamemodeCommand(this));
|
||||
@@ -106,7 +92,7 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
getCommand("closedoors").setExecutor(new CloseDoorsCommand(this));
|
||||
getCommand("sit").setExecutor(new SitCommand(this, sitListener));
|
||||
getCommand("back").setExecutor(new BackCommand(this));
|
||||
getCommand("friend").setExecutor(new FriendCommand(this, friendsConfig, langConfig, getLogger()));
|
||||
getCommand("friend").setExecutor(friendCommand);
|
||||
getCommand("ir").setExecutor(new ItemRenameCommand(this));
|
||||
getCommand("showarmorstands").setExecutor(new ShowArmorStandsCommand(this));
|
||||
getCommand("cleardebugarmorstands").setExecutor(new ClearDebugArmorStandsCommand(this));
|
||||
@@ -119,44 +105,61 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
getCommand("tpa").setExecutor(teleportCommands);
|
||||
getCommand("tpaccept").setExecutor(teleportCommands);
|
||||
getCommand("tpdeny").setExecutor(teleportCommands);
|
||||
getCommand("kit").setExecutor(new KitCommand(this));
|
||||
|
||||
// BlockManager erstellen
|
||||
BlockManager blockManager = new BlockManager();
|
||||
|
||||
// === Stats ===
|
||||
// Konfiguration laden
|
||||
FileConfiguration config = getConfig();
|
||||
|
||||
// Listener registrieren
|
||||
BackpackRecipe.register(this, langConfig);
|
||||
|
||||
sitListener = new SitListener(this);
|
||||
afkListener = new AFKListener(this);
|
||||
graveListener = new GraveListener(this);
|
||||
playerJoinListener = new PlayerJoinListener(friendCommand); // PlayerJoinListener registrieren
|
||||
|
||||
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
|
||||
|
||||
// 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));
|
||||
|
||||
// Stats
|
||||
statsManager = new StatsManager(this);
|
||||
getServer().getPluginManager().registerEvents(new StatsListener(this, statsManager), this);
|
||||
pluginManager.registerEvents(new StatsListener(this, statsManager), this);
|
||||
getCommand("stats").setExecutor(new StatsCommand(this, statsManager));
|
||||
|
||||
// === Event Listener ===
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
|
||||
pm.registerEvents(new InventoryClickListener(this), this);
|
||||
pm.registerEvents(sitListener, this);
|
||||
pm.registerEvents(afkListener, this);
|
||||
pm.registerEvents(graveListener, this);
|
||||
pm.registerEvents(new BackpackListener(backpackConfig, langConfig, getLogger(), backpackFile), this);
|
||||
|
||||
sleepListener = new SleepListener(this);
|
||||
pm.registerEvents(sleepListener, this);
|
||||
pluginManager.registerEvents(sleepListener, this);
|
||||
|
||||
oreAlarmListener = new OreAlarmListener(this);
|
||||
pm.registerEvents(oreAlarmListener, this);
|
||||
pluginManager.registerEvents(oreAlarmListener, this);
|
||||
|
||||
mobLeashLimitListener = new MobLeashLimitListener(this, getConfig());
|
||||
pm.registerEvents(mobLeashLimitListener, this);
|
||||
pluginManager.registerEvents(mobLeashLimitListener, this);
|
||||
|
||||
mobCapListener = new MobCapListener(this, getConfig());
|
||||
pm.registerEvents(mobCapListener, this);
|
||||
pluginManager.registerEvents(mobCapListener, this);
|
||||
|
||||
pm.registerEvents(new de.viper.survivalplus.listeners.LoginListener(this), this);
|
||||
pm.registerEvents(new DebugArmorStandListener(), this);
|
||||
pm.registerEvents(new ArmorStandDestroyListener(), this);
|
||||
|
||||
// SpawnProtectionListener hinzufügen
|
||||
spawnProtectionListener = new SpawnProtectionListener(this);
|
||||
pm.registerEvents(spawnProtectionListener, this);
|
||||
pluginManager.registerEvents(spawnProtectionListener, this);
|
||||
|
||||
LockSystem lockSystem = new LockSystem(this);
|
||||
getServer().getPluginManager().registerEvents(lockSystem, this);
|
||||
pluginManager.registerEvents(lockSystem, this);
|
||||
getCommand("lock").setExecutor(lockSystem);
|
||||
|
||||
// AutoClear Task starten
|
||||
@@ -186,16 +189,16 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (autoClearTaskId != -1) {
|
||||
Bukkit.getScheduler().cancelTask(autoClearTaskId);
|
||||
}
|
||||
saveStats();
|
||||
saveLeashesConfig();
|
||||
saveMobCapConfig();
|
||||
|
||||
getLogger().info(getMessage("plugin.disabled"));
|
||||
public void onDisable() {
|
||||
if (autoClearTaskId != -1) {
|
||||
Bukkit.getScheduler().cancelTask(autoClearTaskId);
|
||||
}
|
||||
saveStats();
|
||||
saveLeashesConfig();
|
||||
saveMobCapConfig();
|
||||
|
||||
getLogger().info(getMessage("plugin.disabled"));
|
||||
}
|
||||
|
||||
public void saveStats() {
|
||||
if (statsManager != null) {
|
||||
@@ -207,6 +210,84 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
return ChatColor.translateAlternateColorCodes('&', getMessage("plugin.info"));
|
||||
}
|
||||
|
||||
// === Config Updating Logic ===
|
||||
private void updateConfigFiles() {
|
||||
updateConfigFile("config.yml");
|
||||
updateConfigFile("lang.yml");
|
||||
updateConfigFile("help.yml");
|
||||
}
|
||||
|
||||
private void updateConfigFile(String fileName) {
|
||||
File file = new File(getDataFolder(), fileName);
|
||||
FileConfiguration currentConfig = YamlConfiguration.loadConfiguration(file);
|
||||
InputStream defaultStream = getResource(fileName);
|
||||
|
||||
if (defaultStream == null) {
|
||||
getLogger().warning(fileName + " nicht im JAR gefunden. Erstelle leere Datei.");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
if (fileName.equals("config.yml")) {
|
||||
saveDefaultConfig();
|
||||
} else if (fileName.equals("lang.yml")) {
|
||||
createLangFile();
|
||||
} else if (fileName.equals("help.yml")) {
|
||||
createHelpFile();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Fehler beim Erstellen der " + fileName + ": " + e.getMessage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FileConfiguration defaultConfig = defaultStream != null ?
|
||||
YamlConfiguration.loadConfiguration(new InputStreamReader(defaultStream)) : new YamlConfiguration();
|
||||
|
||||
// Merge default config into current config
|
||||
mergeConfigs(defaultConfig, currentConfig);
|
||||
|
||||
// Save updated config
|
||||
try {
|
||||
currentConfig.save(file);
|
||||
getLogger().info(fileName + " erfolgreich aktualisiert.");
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Fehler beim Speichern der " + fileName + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
// Update instance variables
|
||||
if (fileName.equals("config.yml")) {
|
||||
reloadConfig();
|
||||
} else if (fileName.equals("lang.yml")) {
|
||||
langFile = file;
|
||||
langConfig = currentConfig;
|
||||
} else if (fileName.equals("help.yml")) {
|
||||
helpFile = file;
|
||||
helpConfig = currentConfig;
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeConfigs(FileConfiguration defaultConfig, FileConfiguration currentConfig) {
|
||||
for (String key : defaultConfig.getKeys(true)) {
|
||||
if (!currentConfig.contains(key)) {
|
||||
currentConfig.set(key, defaultConfig.get(key));
|
||||
} else if (defaultConfig.isConfigurationSection(key) && currentConfig.isConfigurationSection(key)) {
|
||||
// Rekursiv für Untersektionen
|
||||
mergeConfigs(defaultConfig.getConfigurationSection(key), currentConfig.getConfigurationSection(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeConfigs(ConfigurationSection defaultSection, ConfigurationSection currentSection) {
|
||||
for (String key : defaultSection.getKeys(false)) {
|
||||
if (!currentSection.contains(key)) {
|
||||
currentSection.set(key, defaultSection.get(key));
|
||||
} else if (defaultSection.isConfigurationSection(key) && currentSection.isConfigurationSection(key)) {
|
||||
mergeConfigs(defaultSection.getConfigurationSection(key), currentSection.getConfigurationSection(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Lang.yml ===
|
||||
private void createLangFile() {
|
||||
langFile = new File(getDataFolder(), "lang.yml");
|
||||
@@ -226,12 +307,7 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void reloadLangConfig() {
|
||||
try {
|
||||
langConfig = YamlConfiguration.loadConfiguration(langFile);
|
||||
getLogger().info("lang.yml erfolgreich neu geladen.");
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Fehler beim Neuladen der lang.yml: " + e.getMessage());
|
||||
}
|
||||
updateConfigFile("lang.yml");
|
||||
}
|
||||
|
||||
public FileConfiguration getLangConfig() {
|
||||
@@ -242,7 +318,12 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
private void createHomesFile() {
|
||||
homesFile = new File(getDataFolder(), "homes.yml");
|
||||
if (!homesFile.exists()) {
|
||||
saveResource("homes.yml", false);
|
||||
try {
|
||||
homesFile.createNewFile();
|
||||
getLogger().info("homes.yml wurde erstellt.");
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Fehler beim Erstellen der homes.yml: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
homesConfig = YamlConfiguration.loadConfiguration(homesFile);
|
||||
}
|
||||
@@ -260,11 +341,21 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadHomesConfig() {
|
||||
homesConfig = YamlConfiguration.loadConfiguration(homesFile);
|
||||
getLogger().info("homes.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
// === Graves.yml ===
|
||||
private void createGravesFile() {
|
||||
gravesFile = new File(getDataFolder(), "graves.yml");
|
||||
if (!gravesFile.exists()) {
|
||||
saveResource("graves.yml", false);
|
||||
try {
|
||||
gravesFile.createNewFile();
|
||||
getLogger().info("graves.yml wurde erstellt.");
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Fehler beim Erstellen der graves.yml: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
gravesConfig = YamlConfiguration.loadConfiguration(gravesFile);
|
||||
}
|
||||
@@ -282,6 +373,11 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadGravesConfig() {
|
||||
gravesConfig = YamlConfiguration.loadConfiguration(gravesFile);
|
||||
getLogger().info("graves.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
// === Help.yml ===
|
||||
private void createHelpFile() {
|
||||
helpFile = new File(getDataFolder(), "help.yml");
|
||||
@@ -297,8 +393,8 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
helpConfig.set("footer", "§6=====================");
|
||||
helpConfig.save(helpFile);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Fehler beim Laden der help.yml: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Fehler beim Erstellen der help.yml: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
helpConfig = YamlConfiguration.loadConfiguration(helpFile);
|
||||
@@ -309,12 +405,7 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void reloadHelpConfig() {
|
||||
try {
|
||||
helpConfig = YamlConfiguration.loadConfiguration(helpFile);
|
||||
getLogger().info("help.yml erfolgreich neu geladen.");
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Fehler beim Neuladen der help.yml: " + e.getMessage());
|
||||
}
|
||||
updateConfigFile("help.yml");
|
||||
}
|
||||
|
||||
// === Backpack.yml ===
|
||||
@@ -344,6 +435,11 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadBackpackConfig() {
|
||||
backpackConfig = YamlConfiguration.loadConfiguration(backpackFile);
|
||||
getLogger().info("backpacks.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
// === Friends.yml ===
|
||||
private void createFriendsFile() {
|
||||
friendsFile = new File(getDataFolder(), "friends.yml");
|
||||
@@ -371,6 +467,11 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadFriendsConfig() {
|
||||
friendsConfig = YamlConfiguration.loadConfiguration(friendsFile);
|
||||
getLogger().info("friends.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
// === Leashes.yml ===
|
||||
private void createLeashesFile() {
|
||||
leashesFile = new File(getDataFolder(), "leashes.yml");
|
||||
@@ -399,12 +500,8 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void reloadLeashesConfig() {
|
||||
try {
|
||||
leashesConfig = YamlConfiguration.loadConfiguration(leashesFile);
|
||||
getLogger().info("leashes.yml erfolgreich neu geladen.");
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Fehler beim Neuladen der leashes.yml: " + e.getMessage());
|
||||
}
|
||||
leashesConfig = YamlConfiguration.loadConfiguration(leashesFile);
|
||||
getLogger().info("leashes.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
// === MobCap.yml ===
|
||||
@@ -435,12 +532,8 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void reloadMobCapConfig() {
|
||||
try {
|
||||
mobCapConfig = YamlConfiguration.loadConfiguration(mobCapFile);
|
||||
getLogger().info("mobcap.yml erfolgreich neu geladen.");
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Fehler beim Neuladen der mobcap.yml: " + e.getMessage());
|
||||
}
|
||||
mobCapConfig = YamlConfiguration.loadConfiguration(mobCapFile);
|
||||
getLogger().info("mobcap.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
// === AutoClearTask ===
|
||||
@@ -465,11 +558,8 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
// === Reload Plugin ===
|
||||
public void reloadPlugin() {
|
||||
try {
|
||||
// Config-Dateien neu laden
|
||||
reloadConfig();
|
||||
getLogger().info("config.yml erfolgreich neu geladen.");
|
||||
reloadLangConfig();
|
||||
reloadHelpConfig();
|
||||
// Config-Dateien aktualisieren
|
||||
updateConfigFiles();
|
||||
reloadBackpackConfig();
|
||||
reloadFriendsConfig();
|
||||
reloadHomesConfig();
|
||||
@@ -484,6 +574,9 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
HandlerList.unregisterAll(this);
|
||||
|
||||
// FriendCommand instanzieren für PlayerJoinListener
|
||||
FriendCommand friendCommand = new FriendCommand(this, friendsConfig, langConfig, getLogger());
|
||||
|
||||
// Listener neu erstellen und registrieren
|
||||
mobLeashLimitListener = new MobLeashLimitListener(this, getConfig());
|
||||
mobLeashLimitListener.reloadConfig(getConfig());
|
||||
@@ -512,20 +605,26 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
sitListener = new SitListener(this);
|
||||
pm.registerEvents(sitListener, this);
|
||||
|
||||
playerJoinListener = new PlayerJoinListener(friendCommand); // PlayerJoinListener neu registrieren
|
||||
pm.registerEvents(playerJoinListener, this);
|
||||
|
||||
pm.registerEvents(new InventoryClickListener(this), this);
|
||||
pm.registerEvents(new BackpackListener(backpackConfig, langConfig, getLogger(), backpackFile), this);
|
||||
pm.registerEvents(new StatsListener(this, statsManager), this);
|
||||
pm.registerEvents(new LoginListener(this), this);
|
||||
pm.registerEvents(new DebugArmorStandListener(), this);
|
||||
pm.registerEvents(new ArmorStandDestroyListener(), this);
|
||||
pm.registerEvents(new FirstJoinListener(), this);
|
||||
|
||||
spawnProtectionListener = new SpawnProtectionListener(this);
|
||||
pm.registerEvents(spawnProtectionListener, this);
|
||||
|
||||
LockSystem lockSystem = new LockSystem(this);
|
||||
getServer().getPluginManager().registerEvents(lockSystem, this);
|
||||
pm.registerEvents(lockSystem, this);
|
||||
getCommand("lock").setExecutor(lockSystem);
|
||||
|
||||
// Commands neu registrieren
|
||||
getCommand("friend").setExecutor(friendCommand);
|
||||
|
||||
getLogger().info(getMessage("plugin.reloaded"));
|
||||
} catch (Exception e) {
|
||||
@@ -533,24 +632,4 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadBackpackConfig() {
|
||||
backpackConfig = YamlConfiguration.loadConfiguration(backpackFile);
|
||||
getLogger().info("backpacks.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
private void reloadFriendsConfig() {
|
||||
friendsConfig = YamlConfiguration.loadConfiguration(friendsFile);
|
||||
getLogger().info("friends.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
private void reloadHomesConfig() {
|
||||
homesConfig = YamlConfiguration.loadConfiguration(homesFile);
|
||||
getLogger().info("homes.yml erfolgreich neu geladen.");
|
||||
}
|
||||
|
||||
private void reloadGravesConfig() {
|
||||
gravesConfig = YamlConfiguration.loadConfiguration(gravesFile);
|
||||
getLogger().info("graves.yml erfolgreich neu geladen.");
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package de.viper.survivalplus.commands;
|
||||
|
||||
import de.viper.survivalplus.Manager.BlockManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class BlockCommand implements CommandExecutor {
|
||||
|
||||
private final BlockManager blockManager;
|
||||
private final FileConfiguration config;
|
||||
|
||||
public BlockCommand(BlockManager blockManager, FileConfiguration config) {
|
||||
this.blockManager = blockManager;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(config.getString("messages.general.only_players"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
player.sendMessage(config.getString("messages.block.usage"));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayerExact(args[0]);
|
||||
if (target == null || target == player) {
|
||||
player.sendMessage(config.getString("messages.block.invalid_player"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (blockManager.hasBlocked(player, target)) {
|
||||
player.sendMessage(config.getString("messages.block.already_blocked").replace("%player%", target.getName()));
|
||||
} else {
|
||||
blockManager.blockPlayer(player, target);
|
||||
player.sendMessage(config.getString("messages.block.blocked").replace("%player%", target.getName()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package de.viper.survivalplus.commands;
|
||||
|
||||
import de.viper.survivalplus.Manager.BlockManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BlockListCommand implements CommandExecutor {
|
||||
|
||||
private final BlockManager blockManager;
|
||||
private final FileConfiguration config;
|
||||
|
||||
public BlockListCommand(BlockManager blockManager, FileConfiguration config) {
|
||||
this.blockManager = blockManager;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(config.getString("messages.general.only_players"));
|
||||
return true;
|
||||
}
|
||||
|
||||
var blocked = blockManager.getBlockedPlayers(player);
|
||||
if (blocked.isEmpty()) {
|
||||
player.sendMessage(config.getString("messages.blocklist.no_blocked_players"));
|
||||
return true;
|
||||
}
|
||||
|
||||
String list = blocked.stream()
|
||||
.map(Bukkit::getOfflinePlayer)
|
||||
.map(p -> p.getName() != null ? p.getName() : "Unbekannt")
|
||||
.collect(Collectors.joining(", "));
|
||||
|
||||
player.sendMessage(config.getString("messages.blocklist.blocked_players").replace("%list%", list));
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,5 +1,7 @@
|
||||
package de.viper.survivalplus.commands;
|
||||
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -11,7 +13,9 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
@@ -87,6 +91,14 @@ public class FriendCommand implements CommandExecutor {
|
||||
handleFriendDelete(player, args[1]);
|
||||
break;
|
||||
|
||||
case "confirm":
|
||||
if (args.length != 2) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.error.confirm-usage", "&cVerwendung: /friend confirm <Spielername>")));
|
||||
return true;
|
||||
}
|
||||
handleFriendConfirmDelete(player, args[1]);
|
||||
break;
|
||||
|
||||
case "tp":
|
||||
if (args.length != 2) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.error.tp-usage", "&cVerwendung: /friend tp <Spielername>")));
|
||||
@@ -142,10 +154,20 @@ public class FriendCommand implements CommandExecutor {
|
||||
|
||||
pendingRequests.add(playerUUID.toString());
|
||||
friendsConfig.set(targetUUID + ".pending_requests", pendingRequests);
|
||||
friendsConfig.set(targetUUID + ".name", targetName); // Speichere den Namen für Offline-Lookups
|
||||
friendsConfig.set(targetUUID + ".name", targetName);
|
||||
saveFriendsConfig();
|
||||
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.add.sent", "&aFreundschaftsanfrage an %s gesendet!").replace("%s", targetName)));
|
||||
target.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.add.received", "&aDu hast eine Freundschaftsanfrage von %s erhalten! Verwende /friend accept %s oder /friend deny %s.").replace("%s", player.getName())));
|
||||
|
||||
TextComponent message = new TextComponent(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.add.received", "&aDu hast eine Freundschaftsanfrage von %s erhalten! ").replace("%s", player.getName())));
|
||||
TextComponent accept = new TextComponent(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.add.accept-button", "&a[Accept]")));
|
||||
accept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend accept " + player.getName()));
|
||||
TextComponent deny = new TextComponent(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.add.deny-button", "&c [Deny]")));
|
||||
deny.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend deny " + player.getName()));
|
||||
message.addExtra(accept);
|
||||
message.addExtra(deny);
|
||||
target.spigot().sendMessage(message);
|
||||
|
||||
logger.info("Freundschaftsanfrage von " + player.getName() + " an " + targetName + " gesendet.");
|
||||
}
|
||||
|
||||
@@ -182,9 +204,9 @@ public class FriendCommand implements CommandExecutor {
|
||||
requesterFriends.add(playerUUID.toString());
|
||||
|
||||
friendsConfig.set(playerUUID + ".friends", playerFriends);
|
||||
friendsConfig.set(playerUUID + ".name", player.getName()); // Speichere den Namen für Offline-Lookups
|
||||
friendsConfig.set(playerUUID + ".name", player.getName());
|
||||
friendsConfig.set(requesterUUID + ".friends", requesterFriends);
|
||||
friendsConfig.set(requesterUUID + ".name", requesterName); // Speichere den Namen für Offline-Lookups
|
||||
friendsConfig.set(requesterUUID + ".name", requesterName);
|
||||
|
||||
saveFriendsConfig();
|
||||
|
||||
@@ -231,11 +253,26 @@ public class FriendCommand implements CommandExecutor {
|
||||
if (friendUUIDs.isEmpty()) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.list.empty", "&7Du hast keine Freunde.")));
|
||||
} else {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(langConfig.getString("friend.list.date-format", "dd.MM.yyyy HH:mm:ss"));
|
||||
for (String friendUUID : friendUUIDs) {
|
||||
String friendName = getNameFromUUID(UUID.fromString(friendUUID));
|
||||
Player friend = Bukkit.getPlayer(UUID.fromString(friendUUID));
|
||||
String status = friend != null ? langConfig.getString("friend.list.online", "&aOnline") : langConfig.getString("friend.list.offline", "&7Offline");
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.list.entry", "&e%s: %s").replaceFirst("%s", friendName).replaceFirst("%s", status)));
|
||||
TextComponent entry = new TextComponent();
|
||||
|
||||
if (friend != null) {
|
||||
entry.addExtra(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.list.entry", "&e%s: %s").replaceFirst("%s", friendName).replaceFirst("%s", langConfig.getString("friend.list.online", "&aOnline"))));
|
||||
} else {
|
||||
long lastOnline = friendsConfig.getLong(friendUUID + ".last-online", 0);
|
||||
String lastOnlineStr = lastOnline > 0 ? dateFormat.format(new Date(lastOnline)) : langConfig.getString("friend.list.unknown", "&7Unbekannt");
|
||||
entry.addExtra(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.list.entry-offline", "&e%s: %s &7(Zuletzt online: %s)").replaceFirst("%s", friendName).replaceFirst("%s", langConfig.getString("friend.list.offline", "&7Offline")).replace("%s", lastOnlineStr)));
|
||||
}
|
||||
|
||||
TextComponent removeButton = new TextComponent(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.list.remove-button", "&c[X]")));
|
||||
removeButton.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend del " + friendName));
|
||||
entry.addExtra(" ");
|
||||
entry.addExtra(removeButton);
|
||||
|
||||
player.spigot().sendMessage(entry);
|
||||
}
|
||||
}
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.list.footer", "&6=====================")));
|
||||
@@ -249,6 +286,34 @@ public class FriendCommand implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
List<String> playerFriends = friendsConfig.getStringList(playerUUID + ".friends");
|
||||
|
||||
if (!playerFriends.contains(friendUUID.toString())) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.error.not-friends", "&c%s ist nicht in deiner Freundesliste!").replace("%s", friendName)));
|
||||
return;
|
||||
}
|
||||
|
||||
TextComponent confirmMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.del.confirm", "&cMöchtest du %s wirklich aus deiner Freundesliste entfernen? ").replace("%s", friendName)));
|
||||
TextComponent confirmButton = new TextComponent(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.del.confirm-button", "&a[Confirm]")));
|
||||
confirmButton.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend confirm " + friendName));
|
||||
TextComponent cancelButton = new TextComponent(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.del.cancel-button", "&c[Cancel]")));
|
||||
cancelButton.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend list"));
|
||||
confirmMessage.addExtra(confirmButton);
|
||||
confirmMessage.addExtra(" ");
|
||||
confirmMessage.addExtra(cancelButton);
|
||||
player.spigot().sendMessage(confirmMessage);
|
||||
|
||||
logger.info(player.getName() + " wurde zur Bestätigung aufgefordert, " + friendName + " aus der Freundesliste zu entfernen.");
|
||||
}
|
||||
|
||||
private void handleFriendConfirmDelete(Player player, String friendName) {
|
||||
UUID friendUUID = getUUIDFromName(friendName);
|
||||
if (friendUUID == null) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.error.player-not-found", "&cSpieler %s nicht gefunden!").replace("%s", friendName)));
|
||||
return;
|
||||
}
|
||||
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
List<String> playerFriends = friendsConfig.getStringList(playerUUID + ".friends");
|
||||
List<String> friendFriends = friendsConfig.getStringList(friendUUID + ".friends");
|
||||
@@ -305,7 +370,6 @@ public class FriendCommand implements CommandExecutor {
|
||||
if (target != null) {
|
||||
return target.getUniqueId();
|
||||
}
|
||||
// Fallback für Offline-Spieler
|
||||
for (String key : friendsConfig.getKeys(false)) {
|
||||
try {
|
||||
UUID uuid = UUID.fromString(key);
|
||||
@@ -328,7 +392,7 @@ public class FriendCommand implements CommandExecutor {
|
||||
if (storedName != null) {
|
||||
return storedName;
|
||||
}
|
||||
return uuid.toString(); // Fallback auf UUID, falls Name nicht gefunden
|
||||
return uuid.toString();
|
||||
}
|
||||
|
||||
private void saveFriendsConfig() {
|
||||
@@ -340,4 +404,20 @@ public class FriendCommand implements CommandExecutor {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyFriendsOfJoin(Player player) {
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
for (String friendUUIDStr : friendsConfig.getStringList(playerUUID + ".friends")) {
|
||||
Player friend = Bukkit.getPlayer(UUID.fromString(friendUUIDStr));
|
||||
if (friend != null) {
|
||||
friend.sendMessage(ChatColor.translateAlternateColorCodes('&', langConfig.getString("friend.join.notify", "&aDein Freund %s ist dem Server beigetreten.").replace("%s", player.getName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLastOnline(Player player) {
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
friendsConfig.set(playerUUID + ".last-online", System.currentTimeMillis());
|
||||
saveFriendsConfig();
|
||||
}
|
||||
}
|
65
src/main/java/de/viper/survivalplus/commands/KitCommand.java
Normal file
65
src/main/java/de/viper/survivalplus/commands/KitCommand.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package de.viper.survivalplus.commands;
|
||||
|
||||
import de.viper.survivalplus.SurvivalPlus;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KitCommand implements CommandExecutor {
|
||||
|
||||
private final SurvivalPlus plugin;
|
||||
|
||||
public KitCommand(SurvivalPlus plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
// Hole die Konfiguration
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
|
||||
// Hole die Items aus der Konfiguration
|
||||
List<String> items = config.getStringList("first-join-kit.items");
|
||||
|
||||
for (String itemString : items) {
|
||||
// Teile den Item-String auf
|
||||
String[] itemParts = itemString.split(",");
|
||||
String materialName = itemParts[0].toUpperCase();
|
||||
int amount = Integer.parseInt(itemParts[1]);
|
||||
String displayName = itemParts.length > 2 ? itemParts[2] : "";
|
||||
|
||||
// Erstelle das Item
|
||||
Material material = Material.getMaterial(materialName);
|
||||
if (material == null) {
|
||||
player.sendMessage("Unbekanntes Item: " + materialName);
|
||||
continue; // Falls das Item ungültig ist, überspringe es
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(material, amount);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
// Setze den Display-Namen (falls vorhanden)
|
||||
if (meta != null && !displayName.isEmpty()) {
|
||||
meta.setDisplayName(displayName);
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
player.getInventory().addItem(item); // Gib das Item an den Spieler
|
||||
|
||||
}
|
||||
player.sendMessage("Du hast dein Kit erhalten!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package de.viper.survivalplus.commands;
|
||||
|
||||
import de.viper.survivalplus.Manager.BlockManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class UnblockCommand implements CommandExecutor {
|
||||
|
||||
private final BlockManager blockManager;
|
||||
private final FileConfiguration config;
|
||||
|
||||
public UnblockCommand(BlockManager blockManager, FileConfiguration config) {
|
||||
this.blockManager = blockManager;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(config.getString("messages.general.only_players"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
player.sendMessage(config.getString("messages.unblock.usage"));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayerExact(args[0]);
|
||||
if (target == null || target == player) {
|
||||
player.sendMessage(config.getString("messages.unblock.invalid_player"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (blockManager.hasBlocked(player, target)) {
|
||||
blockManager.unblockPlayer(player, target);
|
||||
player.sendMessage(config.getString("messages.unblock.unblocked").replace("%player%", target.getName()));
|
||||
target.sendMessage(config.getString("messages.unblock.unblocked_by").replace("%player%", player.getName()));
|
||||
} else {
|
||||
player.sendMessage(config.getString("messages.unblock.not_blocked").replace("%player%", target.getName()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -51,7 +51,7 @@ public class AFKListener implements Listener {
|
||||
}
|
||||
}
|
||||
};
|
||||
afkTask.runTaskTimer(plugin, 20L, 100L);
|
||||
afkTask.runTaskTimer(plugin, 60L, 100L); // Start nach 3 Sekunden (60 Ticks), dann alle 5 Sekunden (100 Ticks)
|
||||
}
|
||||
|
||||
private void handleActivity(Player player) {
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package de.viper.survivalplus.listeners;
|
||||
|
||||
import de.viper.survivalplus.Manager.BlockManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class ChatBlockListener implements Listener {
|
||||
|
||||
private final BlockManager blockManager;
|
||||
|
||||
public ChatBlockListener(BlockManager blockManager) {
|
||||
this.blockManager = blockManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
Player sender = event.getPlayer();
|
||||
|
||||
event.getRecipients().removeIf(recipient ->
|
||||
blockManager.hasBlocked(recipient, sender) || blockManager.hasBlocked(sender, recipient)
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package de.viper.survivalplus.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public class FirstJoinListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerFirstJoin(PlayerJoinEvent event) {
|
||||
if (event.getPlayer().hasPlayedBefore()) {
|
||||
return; // Nur für den ersten Join
|
||||
}
|
||||
|
||||
// Erstelle ein ItemStack für einen Trank (z.B. Heiltrank)
|
||||
ItemStack potion = new ItemStack(Material.POTION, 1);
|
||||
|
||||
if (potion.getItemMeta() instanceof PotionMeta) {
|
||||
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
|
||||
PotionEffect effect = new PotionEffect(PotionEffectType.REGENERATION, 600, 1);
|
||||
potionMeta.addCustomEffect(effect, true);
|
||||
potion.setItemMeta(potionMeta);
|
||||
}
|
||||
|
||||
// Füge das Trank-Item zum Inventar des Spielers hinzu
|
||||
PlayerInventory inventory = event.getPlayer().getInventory();
|
||||
inventory.addItem(potion);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package de.viper.survivalplus.listeners;
|
||||
|
||||
import de.viper.survivalplus.commands.FriendCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
private final FriendCommand friendCommand;
|
||||
|
||||
public PlayerJoinListener(FriendCommand friendCommand) {
|
||||
this.friendCommand = friendCommand;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
friendCommand.notifyFriendsOfJoin(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
friendCommand.updateLastOnline(player);
|
||||
}
|
||||
}
|
@@ -44,3 +44,10 @@ spawnprotection:
|
||||
protect-pvp: true
|
||||
bypass-permission: survivalplus.spawnprotection.bypass
|
||||
|
||||
# Start Kit (Minecraft item, Menge, Custom-Name)
|
||||
first-join-kit:
|
||||
items:
|
||||
- "bread,2,§6Bernd das Brot"
|
||||
- "apple,1,§7Dornröschen Apfel"
|
||||
- "wooden_sword,1,§eSchwert"
|
||||
- "suspicious_stew,1,§6Heldensuppe"
|
||||
|
@@ -4,10 +4,10 @@ footer: "&6==========================="
|
||||
commands:
|
||||
gm:
|
||||
description: "&eWechselt den Spielmodus (survival, creative, adventure, spectator)."
|
||||
usage: "&b/gm < survival | creative | adventure | spectator >"
|
||||
usage: "&b/gm <survival | creative | adventure | spectator>"
|
||||
sp:
|
||||
description: "&eHauptbefehl für SurvivalPlus mit Unterbefehlen."
|
||||
usage: "&b/sp < reload | help >"
|
||||
usage: "&b/sp <reload | help | info>"
|
||||
sethome:
|
||||
description: "&eSetzt einen neuen Homepunkt."
|
||||
usage: "&b/sethome <name>"
|
||||
@@ -45,8 +45,8 @@ commands:
|
||||
description: "&eTeleportiert dich zurück zum letzten Ort."
|
||||
usage: "&b/back"
|
||||
friend:
|
||||
description: "&eVerwalte Freunde (add, remove, list)."
|
||||
usage: "&b/friend < add | remove | list > [Spieler]"
|
||||
description: "&eVerwalte deine Freundesliste (hinzufügen, entfernen, anzeigen, teleportieren). Unterstützt anklickbare Anfragen und Bestätigungen."
|
||||
usage: "&b/friend <add | accept | deny | list | del | confirm | tp> [Spieler]"
|
||||
ir:
|
||||
description: "&eBenennt Items um."
|
||||
usage: "&b/ir <Name>"
|
||||
@@ -70,8 +70,7 @@ commands:
|
||||
usage: "&b/stats"
|
||||
lock:
|
||||
description: "&eSchützt Container mit dem LockSystem."
|
||||
usage: "&b/lock < lock | unlock | info >"
|
||||
|
||||
usage: "&b/lock <lock | unlock | info>"
|
||||
tp:
|
||||
description: "&eTeleportiert dich zu einem anderen Spieler."
|
||||
usage: "&b/tp <Spieler>"
|
||||
|
@@ -1,8 +1,15 @@
|
||||
sp:
|
||||
no-permission: "§cDu hast keine Berechtigung für diesen Befehl!"
|
||||
plugin.reloaded: "§aSurvivalPlus wurde erfolgreich neu geladen!"
|
||||
sp.invalid-subcommand: "§cUngültiger Unterbefehl! Verwendung: /sp [reload | help]"
|
||||
sp.help-not-found: "§cHilfedatei (help.yml) konnte nicht geladen werden!"
|
||||
invalid-subcommand: "§cUngültiger Unterbefehl! Verwendung: /sp [ reload | help | info ]"
|
||||
help-not-found: "§cHilfedatei (help.yml) konnte nicht geladen werden!"
|
||||
info:
|
||||
header: "§7===== SurvivalPlus Info ====="
|
||||
name: "§ePlugin-Name: §f"
|
||||
version: "§eVersion: §f"
|
||||
author: "§eErsteller: §f"
|
||||
description: "§eBeschreibung: §f"
|
||||
footer: "§7=========================="
|
||||
|
||||
plugin:
|
||||
enabled: "&aSurvivalPlus wurde erfolgreich aktiviert!"
|
||||
@@ -131,16 +138,56 @@ friend:
|
||||
deny-usage: "&cVerwendung: /friend deny <Spielername>"
|
||||
list-usage: "&cVerwendung: /friend list"
|
||||
del-usage: "&cVerwendung: /friend del <Spielername>"
|
||||
confirm-usage: "&cVerwendung: /friend confirm <Spielername>"
|
||||
tp-usage: "&cVerwendung: /friend tp <Spielername>"
|
||||
|
||||
add:
|
||||
sent: "&aFreundschaftsanfrage an %s gesendet!"
|
||||
received: "&aDu hast eine Freundschaftsanfrage von %s erhalten! "
|
||||
accept-button: "&a[Accept]"
|
||||
deny-button: "&c [Deny]"
|
||||
|
||||
accept:
|
||||
success: "&aDu bist jetzt mit %s befreundet!"
|
||||
notify: "&a%s hat deine Freundschaftsanfrage akzeptiert!"
|
||||
|
||||
deny:
|
||||
success: "&aFreundschaftsanfrage von %s abgelehnt."
|
||||
notify: "&c%s hat deine Freundschaftsanfrage abgelehnt."
|
||||
|
||||
list:
|
||||
header: "&6=== Deine Freundesliste ==="
|
||||
entry: "&e%s: %s"
|
||||
entry-offline: "&e%s: %s &7(Zuletzt online: %s)"
|
||||
online: "&aOnline"
|
||||
offline: "&7Offline"
|
||||
unknown: "&7Unbekannt"
|
||||
date-format: "dd.MM.yyyy HH:mm:ss"
|
||||
remove-button: "&c[X]"
|
||||
footer: "&6====================="
|
||||
|
||||
del:
|
||||
success: "&a%s wurde aus deiner Freundesliste entfernt."
|
||||
notify: "&c%s hat dich aus seiner Freundesliste entfernt."
|
||||
confirm: "&cMöchtest du %s wirklich aus deiner Freundesliste entfernen? "
|
||||
confirm-button: "&a[Confirm]"
|
||||
cancel-button: "&c[Cancel]"
|
||||
|
||||
tp:
|
||||
success: "&aDu wurdest zu %s teleportiert!"
|
||||
notify: "&a%s hat sich zu dir teleportiert."
|
||||
|
||||
join:
|
||||
notify: "&aDein Freund %s ist dem Server beigetreten."
|
||||
|
||||
ir:
|
||||
only-player: "&cDieser Befehl kann nur von Spielern ausgeführt werden."
|
||||
no-permission: "&cDu hast keine Berechtigung, diesen Befehl zu benutzen."
|
||||
no-name: "&cBitte gib einen neuen Namen an."
|
||||
usage: "&eBenutze: /ir <NeuerName>"
|
||||
no-item: "&cDu hältst kein Item in der Hand."
|
||||
cant-rename: "&cDieses Item kann nicht umbenannt werden."
|
||||
success: "&aDas Item wurde erfolgreich in {name} umbenannt!"
|
||||
only-player: "&cDieser Befehl kann nur von Spielern ausgeführt werden."
|
||||
no-permission: "&cDu hast keine Berechtigung, diesen Befehl zu benutzen."
|
||||
no-name: "&cBitte gib einen neuen Namen an."
|
||||
usage: "&eBenutze: /ir <NeuerName>"
|
||||
no-item: "&cDu hältst kein Item in der Hand."
|
||||
cant-rename: "&cDieses Item kann nicht umbenannt werden."
|
||||
success: "&aDas Item wurde erfolgreich in {name} umbenannt!"
|
||||
|
||||
afk:
|
||||
set: "&7Du bist jetzt AFK."
|
||||
@@ -168,7 +215,6 @@ welcome:
|
||||
welcome.first-join-sound: ENTITY_FIREWORK_ROCKET_LAUNCH
|
||||
welcome.first-join-sound-volume: 1.0
|
||||
welcome.first-join-sound-pitch: 1.0
|
||||
|
||||
return-message: "&6Willkommen zurück, &e{player}&6!"
|
||||
welcome.return-sound: ENTITY_FIREWORK_ROCKET_BLAST
|
||||
welcome.return-sound-volume: 1.0
|
||||
@@ -207,15 +253,14 @@ lock:
|
||||
unknown-subcommand: "§cUnbekannter Befehl."
|
||||
|
||||
friendadd:
|
||||
usage: "§cBenutzung: /lock friendadd <Spieler>"
|
||||
not-found: "§cSpieler nicht gefunden oder nicht online!"
|
||||
success: "§a{player} wurde erfolgreich als Freund hinzugefügt!"
|
||||
usage: "§cBenutzung: /lock friendadd <Spieler>"
|
||||
not-found: "§cSpieler nicht gefunden oder nicht online!"
|
||||
success: "§a{player} wurde erfolgreich als Freund hinzugefügt!"
|
||||
|
||||
friendremove:
|
||||
usage: "§cBenutzung: /lock friendremove <Spieler>"
|
||||
not-found: "§cSpieler nicht gefunden oder nicht online!"
|
||||
success: "§a{player} wurde erfolgreich als Freund entfernt!"
|
||||
|
||||
usage: "§cBenutzung: /lock friendremove <Spieler>"
|
||||
not-found: "§cSpieler nicht gefunden oder nicht online!"
|
||||
success: "§a{player} wurde erfolgreich als Freund entfernt!"
|
||||
|
||||
teleport-usage: "§cVerwendung: /tp <Spieler>"
|
||||
teleport-success: "§aDu wurdest zu %player% teleportiert!"
|
||||
@@ -239,3 +284,21 @@ no-tpa-request: "§cDu hast keine ausstehende Teleportanfrage."
|
||||
no-permission: "§cDu hast keine Berechtigung für diesen Befehl!"
|
||||
only-players: "§cDieser Befehl kann nur von Spielern ausgeführt werden!"
|
||||
player-not-found: "§cSpieler %player% nicht gefunden!"
|
||||
|
||||
block:
|
||||
usage: "Benutze: /block <Spieler>"
|
||||
invalid_player: "Ungültiger Spieler."
|
||||
blocked: "Du hast §e%player%§c blockiert."
|
||||
already_blocked: "Du hast §e%player%§c schon blockiert."
|
||||
unblocked: "Du hast §e%player%§a entblockt."
|
||||
|
||||
unblock:
|
||||
usage: "Benutze: /unblock <Spieler>"
|
||||
invalid_player: "Ungültiger Spieler."
|
||||
not_blocked: "Du hast §e%player%§c nicht blockiert."
|
||||
unblocked: "Du hast §e%player%§a entblockt."
|
||||
unblocked_by: "Du wurdest von §e%player%§a entblockt."
|
||||
|
||||
blocklist:
|
||||
no_blocked_players: "§7Du hast aktuell niemanden blockiert."
|
||||
blocked_players: "§7Blockierte Spieler: §e%list%"
|
@@ -160,7 +160,20 @@ commands:
|
||||
description: Lehne eine Teleportanfrage ab
|
||||
usage: /tpdeny
|
||||
|
||||
block:
|
||||
description: Blockiere einen Spieler
|
||||
usage: /block <Spieler>
|
||||
permission: survivalplus.block
|
||||
|
||||
unblock:
|
||||
description: Entblocke einen Spieler
|
||||
usage: /unblock <Spieler>
|
||||
permission: survivalplus.unlock
|
||||
|
||||
blocklist:
|
||||
description: Zeige eine Liste der blockierten Spieler
|
||||
usage: /blocklist
|
||||
permission: survivalplus.blocklist
|
||||
|
||||
permissions:
|
||||
survivalplus.*:
|
||||
@@ -341,3 +354,9 @@ permissions:
|
||||
description: Erlaube das Ablehnen von Teleportanfragen
|
||||
default: true
|
||||
|
||||
survivalplus.block:
|
||||
description: Erlaubt das Blockieren anderer Spieler im Chat
|
||||
default: true
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user