src/main/java/de/viper/survivalplus/SurvivalPlus.java aktualisiert
This commit is contained in:
@@ -7,26 +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.util.LockSystem;
|
||||
import de.viper.survivalplus.commands.TeleportCommands;
|
||||
import de.viper.survivalplus.commands.BlockListCommand;
|
||||
import de.viper.survivalplus.Manager.BlockManager;
|
||||
import de.viper.survivalplus.commands.UnblockCommand;
|
||||
import de.viper.survivalplus.listeners.FirstJoinListener;
|
||||
import de.viper.survivalplus.commands.KitCommand;
|
||||
|
||||
|
||||
import de.viper.survivalplus.util.LockSystem;
|
||||
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;
|
||||
@@ -37,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 {
|
||||
@@ -59,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;
|
||||
@@ -73,16 +58,13 @@ 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();
|
||||
@@ -92,12 +74,8 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
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));
|
||||
@@ -114,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));
|
||||
@@ -129,58 +107,59 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
getCommand("tpdeny").setExecutor(teleportCommands);
|
||||
getCommand("kit").setExecutor(new KitCommand(this));
|
||||
|
||||
|
||||
// BlockManager erstellen
|
||||
BlockManager blockManager = new BlockManager();
|
||||
|
||||
// Konfiguration laden
|
||||
saveDefaultConfig();
|
||||
FileConfiguration config = getConfig();
|
||||
|
||||
// Listener registrieren
|
||||
getServer().getPluginManager().registerEvents(new ChatBlockListener(blockManager), this);
|
||||
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 ===
|
||||
// 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
|
||||
@@ -231,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");
|
||||
@@ -250,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() {
|
||||
@@ -266,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);
|
||||
}
|
||||
@@ -284,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);
|
||||
}
|
||||
@@ -306,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");
|
||||
@@ -321,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);
|
||||
@@ -333,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 ===
|
||||
@@ -368,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");
|
||||
@@ -395,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");
|
||||
@@ -423,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());
|
||||
}
|
||||
}
|
||||
|
||||
// === MobCap.yml ===
|
||||
@@ -459,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());
|
||||
}
|
||||
}
|
||||
|
||||
// === AutoClearTask ===
|
||||
@@ -489,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();
|
||||
@@ -508,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());
|
||||
@@ -536,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) {
|
||||
@@ -557,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.");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user