From cc9bf7be82cc19f4d56fdff5ce0364f43a3ee5e5 Mon Sep 17 00:00:00 2001 From: Silverwolfg11 Date: Wed, 27 Apr 2022 16:06:56 -0700 Subject: [PATCH 1/3] Add MapTowny integration! - Functionally the same as the Dynmap / Dynmap-Towny integration. - Uses code from the Dynmap Integration to display siege icon markers. - Add a specific fire icon to use for MapTowny and attribution for the icon in the README. --- README.md | 1 + pom.xml | 212 ++++---- .../com/gmail/goosius/siegewar/SiegeWar.java | 493 +++++++++--------- .../maptowny/MapTownyIntegration.java | 219 ++++++++ .../maptowny/MapTownyReplacementsHandler.java | 37 ++ .../goosius/siegewar/settings/Settings.java | 407 +++++++-------- src/main/resources/fire.png | Bin 0 -> 555 bytes src/main/resources/plugin.yml | 238 ++++----- 8 files changed, 938 insertions(+), 669 deletions(-) create mode 100644 src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyIntegration.java create mode 100644 src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyReplacementsHandler.java create mode 100644 src/main/resources/fire.png diff --git a/README.md b/README.md index e6c9dd051..f2a3408f8 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,4 @@ - Special thanks to the servers *CCNET*, *DatBlock*, and *EarthPol*, who pioneered the use of the system, and have provided much valuable information, feedback, and bug reports. - [Goosius1](https://github.com/Goosius1) was the maintainer of this repo for the TownyAdvanced org, until his retirement from *Minecraft* plugin development in October 2021. - *SiegeWar* is now maintained by the TownyAdvanced org. +- "Fire" icon created by kosonicon diff --git a/pom.xml b/pom.xml index c06a2d8ba..e0cdfbaa1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,104 +1,110 @@ - - 4.0.0 - com.gmail.goosius - SiegeWar - 0.7.14 - siegewar - - - 1.8 - 1.13 - UTF-8 - - - - - glaremasters repo - https://repo.glaremasters.me/repository/towny/ - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jitpack.io - https://jitpack.io - - - dynmap-repo - https://repo.mikeprimm.com/ - - - cannons-repo - https://github.com/DerPavlov/mvn-repo/raw/master/ - - - citizens-repo - https://repo.citizensnpcs.co/ - - - - - - org.spigotmc - spigot-api - 1.18.1-R0.1-SNAPSHOT - provided - - - com.palmergames.bukkit.towny - towny - 0.98.0.0 - provided - - - com.github.TownyAdvanced - Dynmap-Towny - 0.85 - - - org.jetbrains - annotations - 16.0.2 - provided - - - us.dynmap - dynmap-api - 2.5 - - - at.pavlov - Cannons - 2.5.5 - provided - - - net.citizensnpcs - citizensapi - 2.0.28-SNAPSHOT - provided - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 - - ${java.version} - ${java.version} - - - - - - src/main/resources - true - - - - + + 4.0.0 + com.gmail.goosius + SiegeWar + 0.7.14 + siegewar + + + 1.8 + 1.13 + UTF-8 + + + + + glaremasters repo + https://repo.glaremasters.me/repository/towny/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + jitpack.io + https://jitpack.io + + + dynmap-repo + https://repo.mikeprimm.com/ + + + cannons-repo + https://github.com/DerPavlov/mvn-repo/raw/master/ + + + citizens-repo + https://repo.citizensnpcs.co/ + + + + + + org.spigotmc + spigot-api + 1.18.1-R0.1-SNAPSHOT + provided + + + com.palmergames.bukkit.towny + towny + 0.98.0.0 + provided + + + com.github.TownyAdvanced + Dynmap-Towny + 0.85 + + + org.jetbrains + annotations + 16.0.2 + provided + + + us.dynmap + dynmap-api + 2.5 + + + at.pavlov + Cannons + 2.5.5 + provided + + + net.citizensnpcs + citizensapi + 2.0.28-SNAPSHOT + provided + + + me.silverwolfg11 + maptowny-api + 2.0.0-BETA-2 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + ${java.version} + ${java.version} + + + + + + src/main/resources + true + + + + \ No newline at end of file diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java b/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java index 3c64ee1ba..9140d431b 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java @@ -1,244 +1,249 @@ -package com.gmail.goosius.siegewar; - -import com.gmail.goosius.siegewar.enums.SiegeStatus; -import com.gmail.goosius.siegewar.metadata.ResidentMetaDataController; -import com.gmail.goosius.siegewar.objects.Siege; -import com.gmail.goosius.siegewar.settings.SiegeWarSettings; -import com.gmail.goosius.siegewar.settings.migrator.ConfigMigrator; -import com.palmergames.bukkit.towny.TownyUniverse; -import com.palmergames.bukkit.towny.object.Resident; -import com.palmergames.bukkit.towny.object.Translation; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import com.gmail.goosius.siegewar.settings.ConfigNodes; -import com.gmail.goosius.siegewar.settings.Settings; -import com.palmergames.bukkit.config.CommentedConfiguration; -import com.palmergames.bukkit.towny.Towny; -import com.palmergames.bukkit.util.Colors; -import com.palmergames.bukkit.util.Version; -import com.gmail.goosius.siegewar.command.SiegeWarAdminCommand; -import com.gmail.goosius.siegewar.command.SiegeWarCommand; -import com.gmail.goosius.siegewar.command.SiegeWarNationAddonCommand; -import com.gmail.goosius.siegewar.hud.SiegeHUDManager; -import com.gmail.goosius.siegewar.integration.cannons.CannonsIntegration; -import com.gmail.goosius.siegewar.integration.dynmap.DynmapIntegration; -import com.gmail.goosius.siegewar.listeners.SiegeWarActionListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarBukkitEventListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarNationEventListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarPlotEventListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarSafeModeListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarStatusScreenListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarTownEventListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarTownyEventListener; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; - -public class SiegeWar extends JavaPlugin { - - private static SiegeWar plugin; - private final Version requiredTownyVersion = Version.fromString("0.98.0.0"); - private static final SiegeHUDManager siegeHUDManager = new SiegeHUDManager(); - - private static boolean siegeWarPluginError = false; - private CannonsIntegration cannonsIntegration; - - public static SiegeWar getSiegeWar() { - return plugin; - } - - public File getSiegeWarJarFile() { - return getFile(); - } - - public static SiegeHUDManager getSiegeHUDManager() { - return siegeHUDManager; - } - - @Override - public void onEnable() { - - plugin = this; - - printSickASCIIArt(); - - if (!townyVersionCheck(getTownyVersion())) { - severe("Towny version does not meet required minimum version: " + requiredTownyVersion); - siegeWarPluginError = true; - } else { - info("Towny version " + getTownyVersion() + " found."); - } - - handleLegacyConfigs(); - - if (!loadAll()) { - siegeWarPluginError = true; - } - - cleanupBattleSession(); - registerCommands(); - registerListeners(); - checkIntegrations(); - cleanupLegacyMetaData(); - - if(siegeWarPluginError) { - severe("SiegeWar did not load successfully, and is now in safe mode!"); - } else { - info("SiegeWar loaded successfully."); - } - } - - private void handleLegacyConfigs() { - Path configPath = getDataFolder().toPath().resolve("config.yml"); - if (!Files.exists(configPath)) - return; - - CommentedConfiguration config = new CommentedConfiguration(configPath); - if (!config.load() || config.getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), "0.0.0.0").equals(getVersion())) - return; - - ConfigMigrator earlyMigrator = new ConfigMigrator(config, "config-migration.json", true); - earlyMigrator.migrate(); - } - - @Override - public void onDisable() { - info("Shutting down..."); - } - - private boolean loadAll() { - return !Towny.getPlugin().isError() - && Settings.loadSettingsAndLang() - && SiegeController.loadAll() - && TownOccupationController.loadAll(); - } - - public String getVersion() { - return getDescription().getVersion(); - } - - private boolean townyVersionCheck(String version) { - return Version.fromString(version).compareTo(requiredTownyVersion) >= 0; - } - - private String getTownyVersion() { - return Towny.getPlugin().getDescription().getVersion(); - } - - private void checkIntegrations() { - if (siegeWarPluginError) { - severe("SiegeWar is in safe mode! Plugin integrations disabled."); - } else if (!SiegeWarSettings.getWarSiegeEnabled()) { - info("SiegeWar is disabled in config. Plugin integrations disabled."); - } else { - if (getServer().getPluginManager().isPluginEnabled("Cannons")) { - info("SiegeWar found Cannons plugin, enabling Cannons support."); - cannonsIntegration = new CannonsIntegration(this); - } - if (getServer().getPluginManager().isPluginEnabled("dynmap")) { - info("SiegeWar found Dynmap plugin, enabling Dynmap support."); - new DynmapIntegration(this); - } - } - } - - private void registerListeners() { - PluginManager pm = getServer().getPluginManager(); - - if (siegeWarPluginError) - pm.registerEvents(new SiegeWarSafeModeListener(this), this); - else { - pm.registerEvents(new SiegeWarActionListener(this), this); - pm.registerEvents(new SiegeWarBukkitEventListener(this), this); - pm.registerEvents(new SiegeWarTownyEventListener(this), this); - pm.registerEvents(new SiegeWarNationEventListener(), this); - pm.registerEvents(new SiegeWarTownEventListener(this), this); - pm.registerEvents(new SiegeWarPlotEventListener(this), this); - pm.registerEvents(new SiegeWarStatusScreenListener(), this); - } - } - - private void registerCommands() { - if(siegeWarPluginError) { - severe("SiegeWar is in safe mode. SiegeWar commands not registered"); - } else { - getCommand("siegewar").setExecutor(new SiegeWarCommand()); - getCommand("siegewaradmin").setExecutor(new SiegeWarAdminCommand()); - new SiegeWarNationAddonCommand(); - } - } - - private void printSickASCIIArt() { - String art = System.lineSeparator() + "#2DE2E6 _________.__ #FF6C11__ __" + - System.lineSeparator() + "#2DE2E6 / _____/|__| ____ ____ ____#FF6C11/ \\ / \\_____ _______" + - System.lineSeparator() + "#2DE2E6 \\_____ \\ | |/ __ \\ / ___\\_/ __ #FF6C11\\ \\/\\/ /\\__ \\\\_ __ \\" + - System.lineSeparator() + "#2DE2E6 / \\| \\ ___// /_/ > ___/#FF6C11\\ / / __ \\| | \\/" + - System.lineSeparator() + "#2DE2E6 /_______ /|__|\\___ >___ / \\___ >#FF6C11\\__/\\ / (____ /__| " + - System.lineSeparator() + "#2DE2E6 \\/ \\/_____/ \\/ #FF6C11\\/ \\/" + - System.lineSeparator() + "#791E94 By Goosius & LlmDl" + System.lineSeparator(); - Bukkit.getLogger().info(Colors.translateColorCodes(art)); - } - - public static boolean isCannonsPluginInstalled() { - return plugin.cannonsIntegration != null; - } - - public boolean isError() { - return siegeWarPluginError; - } - - public static void info(String msg) { - plugin.getLogger().info(msg); - } - - public static void severe(String msg) { - plugin.getLogger().severe(msg); - } - - /** - * Cleans up the battle session, if it did not exit properly when the plugin shut down. - */ - private void cleanupBattleSession() { - if(siegeWarPluginError) { - severe("SiegeWar is in safe mode. Battle Session Cleanup not attempted."); - } else { - //Find any sieges with unresolved battles - List siegesWithUnresolvedBattles = new ArrayList<>(); - for(Siege siege: SiegeController.getSieges()) { - if(siege.getStatus() == SiegeStatus.IN_PROGRESS - && (siege.getAttackerBattlePoints() > 0 || siege.getDefenderBattlePoints() > 0)) { - siegesWithUnresolvedBattles.add(siege); - } - } - //Resolve battles - if(siegesWithUnresolvedBattles.size() > 0) { - info(Translation.of("msg.battle.session.cleanup.starting")); - int numBattlesUpdated = 0; - for(Siege siege: siegesWithUnresolvedBattles) { - siege.adjustSiegeBalance(siege.getAttackerBattlePoints() - siege.getDefenderBattlePoints()); - siege.setAttackerBattlePoints(0); - siege.setDefenderBattlePoints(0); - SiegeController.saveSiege(siege); - numBattlesUpdated++; - } - - info(Translation.of("msg.battle.session.cleanup.complete", numBattlesUpdated)); - } - } - } - - /** - * Cleanup metadata which is non longer in use - */ - private void cleanupLegacyMetaData() { - for(Resident resident: TownyUniverse.getInstance().getResidents()) { - ResidentMetaDataController.clearPlunder(resident); - } - } -} +package com.gmail.goosius.siegewar; + +import com.gmail.goosius.siegewar.enums.SiegeStatus; +import com.gmail.goosius.siegewar.integration.maptowny.MapTownyIntegration; +import com.gmail.goosius.siegewar.metadata.ResidentMetaDataController; +import com.gmail.goosius.siegewar.objects.Siege; +import com.gmail.goosius.siegewar.settings.SiegeWarSettings; +import com.gmail.goosius.siegewar.settings.migrator.ConfigMigrator; +import com.palmergames.bukkit.towny.TownyUniverse; +import com.palmergames.bukkit.towny.object.Resident; +import com.palmergames.bukkit.towny.object.Translation; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import com.gmail.goosius.siegewar.settings.ConfigNodes; +import com.gmail.goosius.siegewar.settings.Settings; +import com.palmergames.bukkit.config.CommentedConfiguration; +import com.palmergames.bukkit.towny.Towny; +import com.palmergames.bukkit.util.Colors; +import com.palmergames.bukkit.util.Version; +import com.gmail.goosius.siegewar.command.SiegeWarAdminCommand; +import com.gmail.goosius.siegewar.command.SiegeWarCommand; +import com.gmail.goosius.siegewar.command.SiegeWarNationAddonCommand; +import com.gmail.goosius.siegewar.hud.SiegeHUDManager; +import com.gmail.goosius.siegewar.integration.cannons.CannonsIntegration; +import com.gmail.goosius.siegewar.integration.dynmap.DynmapIntegration; +import com.gmail.goosius.siegewar.listeners.SiegeWarActionListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarBukkitEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarNationEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarPlotEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarSafeModeListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarStatusScreenListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarTownEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarTownyEventListener; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +public class SiegeWar extends JavaPlugin { + + private static SiegeWar plugin; + private final Version requiredTownyVersion = Version.fromString("0.98.0.0"); + private static final SiegeHUDManager siegeHUDManager = new SiegeHUDManager(); + + private static boolean siegeWarPluginError = false; + private CannonsIntegration cannonsIntegration; + + public static SiegeWar getSiegeWar() { + return plugin; + } + + public File getSiegeWarJarFile() { + return getFile(); + } + + public static SiegeHUDManager getSiegeHUDManager() { + return siegeHUDManager; + } + + @Override + public void onEnable() { + + plugin = this; + + printSickASCIIArt(); + + if (!townyVersionCheck(getTownyVersion())) { + severe("Towny version does not meet required minimum version: " + requiredTownyVersion); + siegeWarPluginError = true; + } else { + info("Towny version " + getTownyVersion() + " found."); + } + + handleLegacyConfigs(); + + if (!loadAll()) { + siegeWarPluginError = true; + } + + cleanupBattleSession(); + registerCommands(); + registerListeners(); + checkIntegrations(); + cleanupLegacyMetaData(); + + if(siegeWarPluginError) { + severe("SiegeWar did not load successfully, and is now in safe mode!"); + } else { + info("SiegeWar loaded successfully."); + } + } + + private void handleLegacyConfigs() { + Path configPath = getDataFolder().toPath().resolve("config.yml"); + if (!Files.exists(configPath)) + return; + + CommentedConfiguration config = new CommentedConfiguration(configPath); + if (!config.load() || config.getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), "0.0.0.0").equals(getVersion())) + return; + + ConfigMigrator earlyMigrator = new ConfigMigrator(config, "config-migration.json", true); + earlyMigrator.migrate(); + } + + @Override + public void onDisable() { + info("Shutting down..."); + } + + private boolean loadAll() { + return !Towny.getPlugin().isError() + && Settings.loadSettingsAndLang() + && SiegeController.loadAll() + && TownOccupationController.loadAll(); + } + + public String getVersion() { + return getDescription().getVersion(); + } + + private boolean townyVersionCheck(String version) { + return Version.fromString(version).compareTo(requiredTownyVersion) >= 0; + } + + private String getTownyVersion() { + return Towny.getPlugin().getDescription().getVersion(); + } + + private void checkIntegrations() { + if (siegeWarPluginError) { + severe("SiegeWar is in safe mode! Plugin integrations disabled."); + } else if (!SiegeWarSettings.getWarSiegeEnabled()) { + info("SiegeWar is disabled in config. Plugin integrations disabled."); + } else { + if (getServer().getPluginManager().isPluginEnabled("Cannons")) { + info("SiegeWar found Cannons plugin, enabling Cannons support."); + cannonsIntegration = new CannonsIntegration(this); + } + if (getServer().getPluginManager().isPluginEnabled("dynmap")) { + info("SiegeWar found Dynmap plugin, enabling Dynmap support."); + new DynmapIntegration(this); + } + if (getServer().getPluginManager().isPluginEnabled("MapTowny")) { + info("SiegeWar found the MapTowny plugin, enabling MapTowny support."); + new MapTownyIntegration(this); + } + } + } + + private void registerListeners() { + PluginManager pm = getServer().getPluginManager(); + + if (siegeWarPluginError) + pm.registerEvents(new SiegeWarSafeModeListener(this), this); + else { + pm.registerEvents(new SiegeWarActionListener(this), this); + pm.registerEvents(new SiegeWarBukkitEventListener(this), this); + pm.registerEvents(new SiegeWarTownyEventListener(this), this); + pm.registerEvents(new SiegeWarNationEventListener(), this); + pm.registerEvents(new SiegeWarTownEventListener(this), this); + pm.registerEvents(new SiegeWarPlotEventListener(this), this); + pm.registerEvents(new SiegeWarStatusScreenListener(), this); + } + } + + private void registerCommands() { + if(siegeWarPluginError) { + severe("SiegeWar is in safe mode. SiegeWar commands not registered"); + } else { + getCommand("siegewar").setExecutor(new SiegeWarCommand()); + getCommand("siegewaradmin").setExecutor(new SiegeWarAdminCommand()); + new SiegeWarNationAddonCommand(); + } + } + + private void printSickASCIIArt() { + String art = System.lineSeparator() + "#2DE2E6 _________.__ #FF6C11__ __" + + System.lineSeparator() + "#2DE2E6 / _____/|__| ____ ____ ____#FF6C11/ \\ / \\_____ _______" + + System.lineSeparator() + "#2DE2E6 \\_____ \\ | |/ __ \\ / ___\\_/ __ #FF6C11\\ \\/\\/ /\\__ \\\\_ __ \\" + + System.lineSeparator() + "#2DE2E6 / \\| \\ ___// /_/ > ___/#FF6C11\\ / / __ \\| | \\/" + + System.lineSeparator() + "#2DE2E6 /_______ /|__|\\___ >___ / \\___ >#FF6C11\\__/\\ / (____ /__| " + + System.lineSeparator() + "#2DE2E6 \\/ \\/_____/ \\/ #FF6C11\\/ \\/" + + System.lineSeparator() + "#791E94 By Goosius & LlmDl" + System.lineSeparator(); + Bukkit.getLogger().info(Colors.translateColorCodes(art)); + } + + public static boolean isCannonsPluginInstalled() { + return plugin.cannonsIntegration != null; + } + + public boolean isError() { + return siegeWarPluginError; + } + + public static void info(String msg) { + plugin.getLogger().info(msg); + } + + public static void severe(String msg) { + plugin.getLogger().severe(msg); + } + + /** + * Cleans up the battle session, if it did not exit properly when the plugin shut down. + */ + private void cleanupBattleSession() { + if(siegeWarPluginError) { + severe("SiegeWar is in safe mode. Battle Session Cleanup not attempted."); + } else { + //Find any sieges with unresolved battles + List siegesWithUnresolvedBattles = new ArrayList<>(); + for(Siege siege: SiegeController.getSieges()) { + if(siege.getStatus() == SiegeStatus.IN_PROGRESS + && (siege.getAttackerBattlePoints() > 0 || siege.getDefenderBattlePoints() > 0)) { + siegesWithUnresolvedBattles.add(siege); + } + } + //Resolve battles + if(siegesWithUnresolvedBattles.size() > 0) { + info(Translation.of("msg.battle.session.cleanup.starting")); + int numBattlesUpdated = 0; + for(Siege siege: siegesWithUnresolvedBattles) { + siege.adjustSiegeBalance(siege.getAttackerBattlePoints() - siege.getDefenderBattlePoints()); + siege.setAttackerBattlePoints(0); + siege.setDefenderBattlePoints(0); + SiegeController.saveSiege(siege); + numBattlesUpdated++; + } + + info(Translation.of("msg.battle.session.cleanup.complete", numBattlesUpdated)); + } + } + } + + /** + * Cleanup metadata which is non longer in use + */ + private void cleanupLegacyMetaData() { + for(Resident resident: TownyUniverse.getInstance().getResidents()) { + ResidentMetaDataController.clearPlunder(resident); + } + } +} diff --git a/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyIntegration.java b/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyIntegration.java new file mode 100644 index 000000000..b913e7980 --- /dev/null +++ b/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyIntegration.java @@ -0,0 +1,219 @@ +package com.gmail.goosius.siegewar.integration.maptowny; + +import com.gmail.goosius.siegewar.SiegeController; +import com.gmail.goosius.siegewar.SiegeWar; +import com.gmail.goosius.siegewar.enums.SiegeSide; +import com.gmail.goosius.siegewar.objects.BattleSession; +import com.gmail.goosius.siegewar.objects.Siege; +import com.gmail.goosius.siegewar.settings.Settings; +import com.palmergames.bukkit.towny.TownyEconomyHandler; +import com.palmergames.bukkit.towny.TownyUniverse; +import com.palmergames.bukkit.towny.object.TownyWorld; +import com.palmergames.bukkit.towny.object.Translation; +import com.palmergames.util.StringMgmt; +import me.silverwolfg11.maptowny.MapTownyPlugin; +import me.silverwolfg11.maptowny.objects.LayerOptions; +import me.silverwolfg11.maptowny.objects.MarkerOptions; +import me.silverwolfg11.maptowny.objects.Point2D; +import me.silverwolfg11.maptowny.platform.MapLayer; +import me.silverwolfg11.maptowny.platform.MapPlatform; +import me.silverwolfg11.maptowny.platform.MapWorld; +import org.apache.commons.lang.WordUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.logging.Level; + +public class MapTownyIntegration { + + private final String SIEGE_MARKER_PREFIX = "siegewar_siege_"; + private final String SIEGE_LAYER_PREFIX = "siegewar_layer_"; + private final String PEACEFUL_BANNER_ICON_KEY = "siegewar_peaceful"; + private final String BATTLE_BANNER_ICON_KEY = "siegewar_battle"; + + private final MapTownyPlugin mapTowny; + private final Map worldLayers = new HashMap<>(); + private boolean siegesRendered = false; + + public MapTownyIntegration(SiegeWar plugin) { + this.mapTowny = (MapTownyPlugin) Bukkit.getPluginManager().getPlugin("MapTowny"); + + // Check if map towny found a valid web-map platform + if (mapTowny.getPlatform() == null) { + return; + } + + // Register replacement handler + Bukkit.getPluginManager().registerEvents(new MapTownyReplacementsHandler(mapTowny), plugin); + + // Register repeating task that runs every 2 seconds delayed by 15 seconds on start. + Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this::displaySieges, 40L, 300L); + + final String pluginName = plugin.getName(); + // Run marker and layer setup on platform initialize + this.mapTowny.getPlatform().onInitialize(() -> { + registerIcons(plugin); + registerMarkerLayers(pluginName); + }); + } + + private BufferedImage readImage(final InputStream is, final String fileName) { + try { + return ImageIO.read(is); + } catch (IOException ex) { + String errorMsg = String.format("Error reading image from file '%s'...", fileName); + SiegeWar.getSiegeWar().getLogger().log(Level.SEVERE, errorMsg, ex); + return null; + } + } + + private void registerIcons(final SiegeWar plugin) { + final MapPlatform platform = this.mapTowny.getPlatform(); + + if (!platform.hasIcon(PEACEFUL_BANNER_ICON_KEY)) { + String fileName = Settings.PEACEFUL_BANNER_FILE_NAME; + InputStream is = plugin.getResource(fileName); + + BufferedImage img = readImage(is, fileName); + if (img != null) { + platform.registerIcon(PEACEFUL_BANNER_ICON_KEY, img, 16, 16); + } + } + + if (!platform.hasIcon(BATTLE_BANNER_ICON_KEY)) { + String fileName = Settings.BATTLE_BANNER_FILE_NAME; + InputStream is = plugin.getResource(fileName); + + BufferedImage img = readImage(is, fileName); + if (img != null) { + platform.registerIcon(BATTLE_BANNER_ICON_KEY, img, 16, 16); + } + } + } + + private void registerMarkerLayers(String pluginName) { + MapPlatform platform = this.mapTowny.getPlatform(); + LayerOptions layerOptions = new LayerOptions(pluginName, true, false, 10, 10); + + // Register SiegeWar marker layer in all available towny worlds + for (TownyWorld townyWorld : TownyUniverse.getInstance().getTownyWorlds()) { + if(!townyWorld.isUsingTowny()) + continue; + + String worldName = townyWorld.getName(); + World bukkitWorld = Bukkit.getWorld(worldName); + + MapWorld mapWorld = bukkitWorld != null ? platform.getWorld(bukkitWorld) : null; + + if (mapWorld == null) + continue; + + MapLayer mapLayer = mapWorld.registerLayer(SIEGE_LAYER_PREFIX + worldName, layerOptions); + worldLayers.put(worldName, mapLayer); + } + } + + private String getSiegeMarkerKey(UUID townUUID) { + return "siegewar_siege_" + townUUID.toString(); + } + + void displaySieges() { + // Avoid attempting to remove markers if no sieges were rendered + if (siegesRendered) { + // Remove all siege markers before re-rendering all of them + for (Map.Entry worldLayerEntry : worldLayers.entrySet()) { + final MapLayer mapLayer = worldLayerEntry.getValue(); + mapLayer.removeMarkers(s -> s.startsWith(SIEGE_MARKER_PREFIX)); + } + + siegesRendered = false; + } + + // Add all active siege markers + for (Siege siege : SiegeController.getSieges()) { + + String name = Translation.of("dynmap_siege_title", siege.getAttackerNameForDisplay(), siege.getDefenderNameForDisplay()); + try { + if (siege.getStatus().isActive()) { + Location siegeLoc = siege.getFlagLocation(); + final String siegeWorldName = siegeLoc.getWorld().getName(); + + MapLayer mapLayer = worldLayers.get(siegeWorldName); + + if (mapLayer == null) + continue; + + //If siege is dormant, show the fire icon, otherwise show the crossed swords icon. + String iconKey; + if (isSiegeDormant(siege)) { + iconKey = PEACEFUL_BANNER_ICON_KEY; + } else { + iconKey = BATTLE_BANNER_ICON_KEY; + } + + List lines = new ArrayList<>(); + lines.add(Translation.of("dynmap_siege_town", siege.getTown().getName())); + lines.add(Translation.of("dynmap_siege_type", siege.getSiegeType().getName())); + lines.add(Translation.of("dynmap_siege_balance", siege.getSiegeBalance())); + lines.add(Translation.of("dynmap_siege_time_left", siege.getTimeRemaining())); + if(TownyEconomyHandler.isActive()) { + lines.add(Translation.of("dynmap_siege_war_chest", TownyEconomyHandler.getFormattedBalance(siege.getWarChestAmount()))); + } + lines.add(Translation.of("dynmap_siege_banner_control", + WordUtils.capitalizeFully(siege.getBannerControllingSide().name()) + + (siege.getBannerControllingSide() == SiegeSide.NOBODY ? "" : " (" + siege.getBannerControllingResidents().size() + ")"))); + lines.add(Translation.of("dynmap_siege_battle_points", siege.getFormattedAttackerBattlePoints(), siege.getFormattedDefenderBattlePoints())); + lines.add(Translation.of("dynmap_siege_battle_time_left", siege.getFormattedBattleTimeRemaining())); + + String desc = "" + name + "
" + StringMgmt.join(lines, "
"); + + double siegeX = siegeLoc.getX(); + double siegeZ = siegeLoc.getZ(); + final UUID townUUID = siege.getTown().getUUID(); + String siegeMarkerId = getSiegeMarkerKey(townUUID); + + MarkerOptions markerOptions = MarkerOptions.builder() + .name(name) + .clickTooltip(desc) + .hoverTooltip(desc) + .build(); + + Point2D iconLoc = Point2D.of(siegeX, siegeZ); + mapLayer.addIconMarker(siegeMarkerId, iconKey, iconLoc, 16, 16, markerOptions); + siegesRendered = true; + } + } catch (Exception ex) { + SiegeWar.severe("Problem adding siege marker for siege: " + name); + ex.printStackTrace(); + } + } + + } + + /** + * A siege is dormant if there is no significant activity there (e.g. kills, banner control). + * + * This state is represented by a fire icon on the map. + * If the battle becomes active, the icon changes to crossed-swords. + * + * @return true if siege is dormant + */ + private boolean isSiegeDormant(Siege siege) { + return !BattleSession.getBattleSession().isActive() + || (siege.getAttackerBattlePoints() == 0 + && siege.getDefenderBattlePoints() == 0 + && siege.getBannerControllingSide() == SiegeSide.NOBODY + && siege.getBannerControlSessions().size() == 0); + } + +} diff --git a/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyReplacementsHandler.java b/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyReplacementsHandler.java new file mode 100644 index 000000000..e9917d212 --- /dev/null +++ b/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyReplacementsHandler.java @@ -0,0 +1,37 @@ +package com.gmail.goosius.siegewar.integration.maptowny; + +import com.gmail.goosius.siegewar.TownOccupationController; +import me.silverwolfg11.maptowny.MapTownyPlugin; +import me.silverwolfg11.maptowny.events.MapReloadEvent; +import me.silverwolfg11.maptowny.managers.LayerManager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class MapTownyReplacementsHandler implements Listener { + + private final MapTownyPlugin mapTowny; + + public MapTownyReplacementsHandler(MapTownyPlugin mapTowny) { + this.mapTowny = mapTowny; + registerReplacements(); + } + + private void registerReplacements() { + LayerManager layerManager = mapTowny.getLayerManager(); + + if (layerManager == null) + return; + + layerManager.registerReplacement("%occupier%", town -> + TownOccupationController.isTownOccupied(town) ? + TownOccupationController.getTownOccupier(town).getName() : "" + ); + } + + // Re-register replacements when maptowny reloads + @EventHandler + void onMapTownyReload(MapReloadEvent event) { + registerReplacements(); + } + +} diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/Settings.java b/src/main/java/com/gmail/goosius/siegewar/settings/Settings.java index 8a75ff6ff..d553367a4 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/Settings.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/Settings.java @@ -1,203 +1,204 @@ -package com.gmail.goosius.siegewar.settings; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.bukkit.plugin.Plugin; - -import com.gmail.goosius.siegewar.SiegeWar; -import com.gmail.goosius.siegewar.settings.migrator.ConfigMigrator; -import com.gmail.goosius.siegewar.utils.FileMgmt; -import com.gmail.goosius.siegewar.utils.SiegeWarBattleSessionUtil; -import com.palmergames.bukkit.config.CommentedConfiguration; -import com.palmergames.bukkit.towny.TownyAPI; -import com.palmergames.bukkit.towny.object.TranslationLoader; -import com.palmergames.util.TimeTools; - -public class Settings { - private static CommentedConfiguration config, newConfig; - private static File battleIconFile; - public static final String BATTLE_BANNER_FILE_NAME = "crossedswords.png"; - - public static boolean loadSettingsAndLang() { - SiegeWar sw = SiegeWar.getSiegeWar(); - boolean loadSuccessFlag = true; - - try { - Settings.loadConfig(sw.getDataFolder().getPath() + File.separator + "config.yml", sw.getVersion()); - } catch (Exception e) { - SiegeWar.severe("Config.yml failed to load! Disabling!"); - loadSuccessFlag = false; - } - - if (Settings.getLastRunVersion(SiegeWar.getSiegeWar().getVersion()).equals(SiegeWar.getSiegeWar().getVersion())) { - ConfigMigrator migrator = new ConfigMigrator(config, "config-migration.json", false); - migrator.migrate(); - } - - // Some list variables do not reload upon loadConfig. - SiegeWarSettings.resetCachedSettings(); - - try { - Plugin plugin = SiegeWar.getSiegeWar(); - Path langFolderPath = Paths.get(plugin.getDataFolder().getPath()).resolve("lang"); - TranslationLoader loader = new TranslationLoader(langFolderPath, plugin, SiegeWar.class); - loader.load(); - TownyAPI.getInstance().addTranslations(plugin, loader.getTranslations()); - } catch (Exception e) { - SiegeWar.severe("Language file failed to load! Disabling!"); - loadSuccessFlag = false; - } - - //Extract images - try { - battleIconFile = FileMgmt.extractImageFile(BATTLE_BANNER_FILE_NAME); - } catch (Exception e) { - e.printStackTrace(); - SiegeWar.severe("Could not load images! Disabling!"); - loadSuccessFlag = false; - } - - //Schedule next battle session - try { - SiegeWarBattleSessionUtil.attemptToScheduleNextBattleSession(); - } catch (Exception e) { - e.printStackTrace(); - SiegeWar.severe("Problem Scheduling Battle Session! Disabling!"); - loadSuccessFlag = false; - } - - return loadSuccessFlag; - } - - public static void loadConfig(String filepath, String version) throws Exception { - if (FileMgmt.checkOrCreateFile(filepath)) { - File file = new File(filepath); - - // read the config.yml into memory - config = new CommentedConfiguration(file.toPath()); - if (!config.load()) - throw new IOException("Failed to load Config!"); - - setDefaults(version, file); - config.save(); - } - } - - public static void addComment(String root, String... comments) { - - newConfig.addComment(root.toLowerCase(), comments); - } - - private static void setNewProperty(String root, Object value) { - - if (value == null) { - value = ""; - } - newConfig.set(root.toLowerCase(), value.toString()); - } - - private static void setProperty(String root, Object value) { - - config.set(root.toLowerCase(), value.toString()); - } - - public static String getLastRunVersion(String currentVersion) { - - return getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion); - } - - /** - * Builds a new config reading old config data. - */ - private static void setDefaults(String version, File file) { - - newConfig = new CommentedConfiguration(file.toPath()); - newConfig.load(); - - for (ConfigNodes root : ConfigNodes.values()) { - if (root.getComments().length > 0) - addComment(root.getRoot(), root.getComments()); - if (root.getRoot() == ConfigNodes.VERSION.getRoot()) - setNewProperty(root.getRoot(), version); - else if (root.getRoot() == ConfigNodes.LAST_RUN_VERSION.getRoot()) - setNewProperty(root.getRoot(), SiegeWar.getSiegeWar().getVersion()); - else - setNewProperty(root.getRoot(), (config.get(root.getRoot().toLowerCase()) != null) ? config.get(root.getRoot().toLowerCase()) : root.getDefault()); - } - - config = newConfig; - newConfig = null; - } - - public static String getString(String root, String def) { - - String data = config.getString(root.toLowerCase(), def); - if (data == null) { - sendError(root.toLowerCase() + " from config.yml"); - return ""; - } - return data; - } - - private static void sendError(String msg) { - - SiegeWar.severe("Error could not read " + msg); - } - - public static boolean getBoolean(ConfigNodes node) { - - return Boolean.parseBoolean(config.getString(node.getRoot().toLowerCase(), node.getDefault())); - } - - public static double getDouble(ConfigNodes node) { - - try { - return Double.parseDouble(config.getString(node.getRoot().toLowerCase(), node.getDefault()).trim()); - } catch (NumberFormatException e) { - sendError(node.getRoot().toLowerCase() + " from config.yml"); - return 0.0; - } - } - - public static int getInt(ConfigNodes node) { - - try { - return Integer.parseInt(config.getString(node.getRoot().toLowerCase(), node.getDefault()).trim()); - } catch (NumberFormatException e) { - sendError(node.getRoot().toLowerCase() + " from config.yml"); - return 0; - } - } - - public static String getString(ConfigNodes node) { - - return config.getString(node.getRoot().toLowerCase(), node.getDefault()); - } - - public static long getSeconds(ConfigNodes node) { - - try { - return TimeTools.getSeconds(getString(node)); - } catch (NumberFormatException e) { - sendError(node.getRoot().toLowerCase() + " from config.yml"); - return 1; - } - } - - public static void setLastRunVersion(String currentVersion) { - - setProperty(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion); - config.save(); - } - - public static File getBattleIconFile() { - return battleIconFile; - } - - public static CommentedConfiguration getConfig() { - return config; - } -} +package com.gmail.goosius.siegewar.settings; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.bukkit.plugin.Plugin; + +import com.gmail.goosius.siegewar.SiegeWar; +import com.gmail.goosius.siegewar.settings.migrator.ConfigMigrator; +import com.gmail.goosius.siegewar.utils.FileMgmt; +import com.gmail.goosius.siegewar.utils.SiegeWarBattleSessionUtil; +import com.palmergames.bukkit.config.CommentedConfiguration; +import com.palmergames.bukkit.towny.TownyAPI; +import com.palmergames.bukkit.towny.object.TranslationLoader; +import com.palmergames.util.TimeTools; + +public class Settings { + private static CommentedConfiguration config, newConfig; + private static File battleIconFile; + public static final String BATTLE_BANNER_FILE_NAME = "crossedswords.png"; + public static final String PEACEFUL_BANNER_FILE_NAME = "fire.png"; + + public static boolean loadSettingsAndLang() { + SiegeWar sw = SiegeWar.getSiegeWar(); + boolean loadSuccessFlag = true; + + try { + Settings.loadConfig(sw.getDataFolder().getPath() + File.separator + "config.yml", sw.getVersion()); + } catch (Exception e) { + SiegeWar.severe("Config.yml failed to load! Disabling!"); + loadSuccessFlag = false; + } + + if (Settings.getLastRunVersion(SiegeWar.getSiegeWar().getVersion()).equals(SiegeWar.getSiegeWar().getVersion())) { + ConfigMigrator migrator = new ConfigMigrator(config, "config-migration.json", false); + migrator.migrate(); + } + + // Some list variables do not reload upon loadConfig. + SiegeWarSettings.resetCachedSettings(); + + try { + Plugin plugin = SiegeWar.getSiegeWar(); + Path langFolderPath = Paths.get(plugin.getDataFolder().getPath()).resolve("lang"); + TranslationLoader loader = new TranslationLoader(langFolderPath, plugin, SiegeWar.class); + loader.load(); + TownyAPI.getInstance().addTranslations(plugin, loader.getTranslations()); + } catch (Exception e) { + SiegeWar.severe("Language file failed to load! Disabling!"); + loadSuccessFlag = false; + } + + //Extract images + try { + battleIconFile = FileMgmt.extractImageFile(BATTLE_BANNER_FILE_NAME); + } catch (Exception e) { + e.printStackTrace(); + SiegeWar.severe("Could not load images! Disabling!"); + loadSuccessFlag = false; + } + + //Schedule next battle session + try { + SiegeWarBattleSessionUtil.attemptToScheduleNextBattleSession(); + } catch (Exception e) { + e.printStackTrace(); + SiegeWar.severe("Problem Scheduling Battle Session! Disabling!"); + loadSuccessFlag = false; + } + + return loadSuccessFlag; + } + + public static void loadConfig(String filepath, String version) throws Exception { + if (FileMgmt.checkOrCreateFile(filepath)) { + File file = new File(filepath); + + // read the config.yml into memory + config = new CommentedConfiguration(file.toPath()); + if (!config.load()) + throw new IOException("Failed to load Config!"); + + setDefaults(version, file); + config.save(); + } + } + + public static void addComment(String root, String... comments) { + + newConfig.addComment(root.toLowerCase(), comments); + } + + private static void setNewProperty(String root, Object value) { + + if (value == null) { + value = ""; + } + newConfig.set(root.toLowerCase(), value.toString()); + } + + private static void setProperty(String root, Object value) { + + config.set(root.toLowerCase(), value.toString()); + } + + public static String getLastRunVersion(String currentVersion) { + + return getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion); + } + + /** + * Builds a new config reading old config data. + */ + private static void setDefaults(String version, File file) { + + newConfig = new CommentedConfiguration(file.toPath()); + newConfig.load(); + + for (ConfigNodes root : ConfigNodes.values()) { + if (root.getComments().length > 0) + addComment(root.getRoot(), root.getComments()); + if (root.getRoot() == ConfigNodes.VERSION.getRoot()) + setNewProperty(root.getRoot(), version); + else if (root.getRoot() == ConfigNodes.LAST_RUN_VERSION.getRoot()) + setNewProperty(root.getRoot(), SiegeWar.getSiegeWar().getVersion()); + else + setNewProperty(root.getRoot(), (config.get(root.getRoot().toLowerCase()) != null) ? config.get(root.getRoot().toLowerCase()) : root.getDefault()); + } + + config = newConfig; + newConfig = null; + } + + public static String getString(String root, String def) { + + String data = config.getString(root.toLowerCase(), def); + if (data == null) { + sendError(root.toLowerCase() + " from config.yml"); + return ""; + } + return data; + } + + private static void sendError(String msg) { + + SiegeWar.severe("Error could not read " + msg); + } + + public static boolean getBoolean(ConfigNodes node) { + + return Boolean.parseBoolean(config.getString(node.getRoot().toLowerCase(), node.getDefault())); + } + + public static double getDouble(ConfigNodes node) { + + try { + return Double.parseDouble(config.getString(node.getRoot().toLowerCase(), node.getDefault()).trim()); + } catch (NumberFormatException e) { + sendError(node.getRoot().toLowerCase() + " from config.yml"); + return 0.0; + } + } + + public static int getInt(ConfigNodes node) { + + try { + return Integer.parseInt(config.getString(node.getRoot().toLowerCase(), node.getDefault()).trim()); + } catch (NumberFormatException e) { + sendError(node.getRoot().toLowerCase() + " from config.yml"); + return 0; + } + } + + public static String getString(ConfigNodes node) { + + return config.getString(node.getRoot().toLowerCase(), node.getDefault()); + } + + public static long getSeconds(ConfigNodes node) { + + try { + return TimeTools.getSeconds(getString(node)); + } catch (NumberFormatException e) { + sendError(node.getRoot().toLowerCase() + " from config.yml"); + return 1; + } + } + + public static void setLastRunVersion(String currentVersion) { + + setProperty(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion); + config.save(); + } + + public static File getBattleIconFile() { + return battleIconFile; + } + + public static CommentedConfiguration getConfig() { + return config; + } +} diff --git a/src/main/resources/fire.png b/src/main/resources/fire.png new file mode 100644 index 0000000000000000000000000000000000000000..a5c88c73b04430a4c03466cadcc8ca83c2768660 GIT binary patch literal 555 zcmV+`0@VG9P)7CQb9V8j6PM9y|vNu*UnGbszt`-E@{P>fC@ z&M$fKF86N^Ja3~mTwN4l1*tsN{h8^Y%x=2<_1&vf*bJGy4czB~JHVr+5p;Lw+>_db*(o654@Ye@F#=BQ1G-Ukpg)wuAkI9@J*F$Q=g&p+%1u=Ub6vz_EMrG4(Y t#^cu!tJ)W%a&&qiC;4?*eg88!^BXiBd_p`UxV``Y002ovPDHLkV1lzh@i_nh literal 0 HcmV?d00001 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b3ddcd87a..99c3e62c6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,119 +1,119 @@ -name: ${project.artifactId} -main: ${project.groupId}.${project.name}.${project.artifactId} -version: ${project.version} -api-version: ${project.bukkitAPIVersion} -author: [Goosius,LlmDl] -website: 'townyadvanced.github.io' -prefix: ${project.artifactId} -depend: [Towny] -softdepend: [TownyCultures, dynmap, Cannons, Dynmap-Towny] - -description: A war system made by Goosius for Towny. - -commands: - siegewar: - aliases: [sw] - siegewaradmin: - aliases: [swa] - -permissions: - siegewar.admin: - description: User is able to use all siege war commands. - default: op - children: - siegewar.command.siegewaradmin.*: true - siegewar.command.siegewar.*: true - - siegewar.command.siegewaradmin.*: - description: User is able to use all /siegewaradmin commands. - default: op - children: - siegewar.command.siegewaradmin.immunity: true - siegewar.command.siegewaradmin.reload: true - siegewar.command.siegewaradmin.siege: true - siegewar.command.siegewaradmin.town: true - siegewar.command.siegewaradmin.nation: true - siegewar.command.siegewaradmin.installperms: true - siegewar.command.siegewaradmin.battlesession: true - - siegewar.command.siegewar.*: - description: User is able to do all /siegewar commands. - default: false - children: - siegewar.command.siegewar.hud.*: true - siegewar.command.siegewar.town.*: true - siegewar.command.siegewar.nation.*: true - siegewar.command.siegewar.guide: true - siegewar.command.siegewar.collect: true - - siegewar.command.siegewar.preference: - description: User is able to use /sw preference. - default: true - - siegewar.command.siegewar.nextsession: - description: User is able to use /sw nextsession. - default: true - - siegewar.command.siegewar.guide: - description: User is able to use /sw guide. - default: true - - siegewar.command.siegewar.hud.*: - description: User is able to do all /siegewar hud commands. - default: true - children: - siegewar.command.siegewar.hud: true - - siegewar.command.siegewar.town.*: - description: User is able to do all /siegewar town commands. - default: false - children: - siegewar.command.siegewar.town.inviteoccupation: true - - siegewar.command.siegewar.nation.*: - description: User is able to do all /siegewar nation commands. - default: false - children: - siegewar.command.siegewar.nation.paysoldiers: true - siegewar.command.siegewar.nation.removeoccupation: true - siegewar.command.siegewar.nation.transferoccupation: true - - siegewar.nation.siege.*: - description: User holds all of the siegewar nation nodes. - default: false - children: - siegewar.nation.siege.battle.points: true - siegewar.nation.siege.attack: true - siegewar.nation.siege.abandon: true - siegewar.nation.siege.invade: true - siegewar.nation.siege.plunder: true - siegewar.nation.siege.conquest.siege.start: true - siegewar.nation.siege.conquest.siege.abandon: true - siegewar.nation.siege.liberation.siege.start: true - siegewar.nation.siege.liberation.siege.abandon: true - siegewar.nation.siege.revolt.siege.surrender: true - siegewar.nation.siege.suppression.siege.start: true - siegewar.nation.siege.suppression.siege.abandon: true - siegewar.nation.siege.subvertpeacefultown: true - siegewar.nation.siege.use.breach.points: true - siegewar.nation.siege.fire.cannon.in.siegezone: true - - siegewar.town.siege.*: - description: User holds all of the siegewar town nodes. - default: false - children: - siegewar.town.siege.battle.points: true - siegewar.town.siege.conquest.siege.surrender: true - siegewar.town.siege.revolt.siege.start: true - siegewar.town.siege.revolt.siege.abandon: true - siegewar.town.siege.suppression.siege.surrender: true - siegewar.town.siege.revoltpeacefully: true - siegewar.town.siege.fire.cannon.in.siegezone: true - - siegewar.command.siegewar.collect: - description: User is able to do the /siegewar collect command. - default: true - - siegewar.immune.to.war.nausea: - description: User is immune to war nausea. - default: false +name: ${project.artifactId} +main: ${project.groupId}.${project.name}.${project.artifactId} +version: ${project.version} +api-version: ${project.bukkitAPIVersion} +author: [Goosius,LlmDl] +website: 'townyadvanced.github.io' +prefix: ${project.artifactId} +depend: [Towny] +softdepend: [TownyCultures, dynmap, Cannons, Dynmap-Towny, MapTowny] + +description: A war system made by Goosius for Towny. + +commands: + siegewar: + aliases: [sw] + siegewaradmin: + aliases: [swa] + +permissions: + siegewar.admin: + description: User is able to use all siege war commands. + default: op + children: + siegewar.command.siegewaradmin.*: true + siegewar.command.siegewar.*: true + + siegewar.command.siegewaradmin.*: + description: User is able to use all /siegewaradmin commands. + default: op + children: + siegewar.command.siegewaradmin.immunity: true + siegewar.command.siegewaradmin.reload: true + siegewar.command.siegewaradmin.siege: true + siegewar.command.siegewaradmin.town: true + siegewar.command.siegewaradmin.nation: true + siegewar.command.siegewaradmin.installperms: true + siegewar.command.siegewaradmin.battlesession: true + + siegewar.command.siegewar.*: + description: User is able to do all /siegewar commands. + default: false + children: + siegewar.command.siegewar.hud.*: true + siegewar.command.siegewar.town.*: true + siegewar.command.siegewar.nation.*: true + siegewar.command.siegewar.guide: true + siegewar.command.siegewar.collect: true + + siegewar.command.siegewar.preference: + description: User is able to use /sw preference. + default: true + + siegewar.command.siegewar.nextsession: + description: User is able to use /sw nextsession. + default: true + + siegewar.command.siegewar.guide: + description: User is able to use /sw guide. + default: true + + siegewar.command.siegewar.hud.*: + description: User is able to do all /siegewar hud commands. + default: true + children: + siegewar.command.siegewar.hud: true + + siegewar.command.siegewar.town.*: + description: User is able to do all /siegewar town commands. + default: false + children: + siegewar.command.siegewar.town.inviteoccupation: true + + siegewar.command.siegewar.nation.*: + description: User is able to do all /siegewar nation commands. + default: false + children: + siegewar.command.siegewar.nation.paysoldiers: true + siegewar.command.siegewar.nation.removeoccupation: true + siegewar.command.siegewar.nation.transferoccupation: true + + siegewar.nation.siege.*: + description: User holds all of the siegewar nation nodes. + default: false + children: + siegewar.nation.siege.battle.points: true + siegewar.nation.siege.attack: true + siegewar.nation.siege.abandon: true + siegewar.nation.siege.invade: true + siegewar.nation.siege.plunder: true + siegewar.nation.siege.conquest.siege.start: true + siegewar.nation.siege.conquest.siege.abandon: true + siegewar.nation.siege.liberation.siege.start: true + siegewar.nation.siege.liberation.siege.abandon: true + siegewar.nation.siege.revolt.siege.surrender: true + siegewar.nation.siege.suppression.siege.start: true + siegewar.nation.siege.suppression.siege.abandon: true + siegewar.nation.siege.subvertpeacefultown: true + siegewar.nation.siege.use.breach.points: true + siegewar.nation.siege.fire.cannon.in.siegezone: true + + siegewar.town.siege.*: + description: User holds all of the siegewar town nodes. + default: false + children: + siegewar.town.siege.battle.points: true + siegewar.town.siege.conquest.siege.surrender: true + siegewar.town.siege.revolt.siege.start: true + siegewar.town.siege.revolt.siege.abandon: true + siegewar.town.siege.suppression.siege.surrender: true + siegewar.town.siege.revoltpeacefully: true + siegewar.town.siege.fire.cannon.in.siegezone: true + + siegewar.command.siegewar.collect: + description: User is able to do the /siegewar collect command. + default: true + + siegewar.immune.to.war.nausea: + description: User is immune to war nausea. + default: false From d77297c474f0bac9b62b3558891bb9bd56b9594a Mon Sep 17 00:00:00 2001 From: Silverwolfg11 Date: Sun, 1 May 2022 14:00:35 -0700 Subject: [PATCH 2/3] Fix line endings. --- pom.xml | 218 ++++---- .../com/gmail/goosius/siegewar/SiegeWar.java | 498 +++++++++--------- .../goosius/siegewar/settings/Settings.java | 408 +++++++------- src/main/resources/plugin.yml | 238 ++++----- 4 files changed, 681 insertions(+), 681 deletions(-) diff --git a/pom.xml b/pom.xml index e0cdfbaa1..847150bc5 100644 --- a/pom.xml +++ b/pom.xml @@ -1,110 +1,110 @@ - - 4.0.0 - com.gmail.goosius - SiegeWar - 0.7.14 - siegewar - - - 1.8 - 1.13 - UTF-8 - - - - - glaremasters repo - https://repo.glaremasters.me/repository/towny/ - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jitpack.io - https://jitpack.io - - - dynmap-repo - https://repo.mikeprimm.com/ - - - cannons-repo - https://github.com/DerPavlov/mvn-repo/raw/master/ - - - citizens-repo - https://repo.citizensnpcs.co/ - - - - - - org.spigotmc - spigot-api - 1.18.1-R0.1-SNAPSHOT - provided - - - com.palmergames.bukkit.towny - towny - 0.98.0.0 - provided - - - com.github.TownyAdvanced - Dynmap-Towny - 0.85 - - - org.jetbrains - annotations - 16.0.2 - provided - - - us.dynmap - dynmap-api - 2.5 - - - at.pavlov - Cannons - 2.5.5 - provided - - - net.citizensnpcs - citizensapi - 2.0.28-SNAPSHOT - provided - - - me.silverwolfg11 - maptowny-api - 2.0.0-BETA-2 - provided - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 - - ${java.version} - ${java.version} - - - - - - src/main/resources - true - - - - + + 4.0.0 + com.gmail.goosius + SiegeWar + 0.7.14 + siegewar + + + 1.8 + 1.13 + UTF-8 + + + + + glaremasters repo + https://repo.glaremasters.me/repository/towny/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + jitpack.io + https://jitpack.io + + + dynmap-repo + https://repo.mikeprimm.com/ + + + cannons-repo + https://github.com/DerPavlov/mvn-repo/raw/master/ + + + citizens-repo + https://repo.citizensnpcs.co/ + + + + + + org.spigotmc + spigot-api + 1.18.1-R0.1-SNAPSHOT + provided + + + com.palmergames.bukkit.towny + towny + 0.98.0.0 + provided + + + com.github.TownyAdvanced + Dynmap-Towny + 0.85 + + + org.jetbrains + annotations + 16.0.2 + provided + + + us.dynmap + dynmap-api + 2.5 + + + at.pavlov + Cannons + 2.5.5 + provided + + + net.citizensnpcs + citizensapi + 2.0.28-SNAPSHOT + provided + + + me.silverwolfg11 + maptowny-api + 2.0.0-BETA-2 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + ${java.version} + ${java.version} + + + + + + src/main/resources + true + + + + \ No newline at end of file diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java b/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java index 9140d431b..0cbf8f581 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java @@ -1,249 +1,249 @@ -package com.gmail.goosius.siegewar; - -import com.gmail.goosius.siegewar.enums.SiegeStatus; -import com.gmail.goosius.siegewar.integration.maptowny.MapTownyIntegration; -import com.gmail.goosius.siegewar.metadata.ResidentMetaDataController; -import com.gmail.goosius.siegewar.objects.Siege; -import com.gmail.goosius.siegewar.settings.SiegeWarSettings; -import com.gmail.goosius.siegewar.settings.migrator.ConfigMigrator; -import com.palmergames.bukkit.towny.TownyUniverse; -import com.palmergames.bukkit.towny.object.Resident; -import com.palmergames.bukkit.towny.object.Translation; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import com.gmail.goosius.siegewar.settings.ConfigNodes; -import com.gmail.goosius.siegewar.settings.Settings; -import com.palmergames.bukkit.config.CommentedConfiguration; -import com.palmergames.bukkit.towny.Towny; -import com.palmergames.bukkit.util.Colors; -import com.palmergames.bukkit.util.Version; -import com.gmail.goosius.siegewar.command.SiegeWarAdminCommand; -import com.gmail.goosius.siegewar.command.SiegeWarCommand; -import com.gmail.goosius.siegewar.command.SiegeWarNationAddonCommand; -import com.gmail.goosius.siegewar.hud.SiegeHUDManager; -import com.gmail.goosius.siegewar.integration.cannons.CannonsIntegration; -import com.gmail.goosius.siegewar.integration.dynmap.DynmapIntegration; -import com.gmail.goosius.siegewar.listeners.SiegeWarActionListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarBukkitEventListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarNationEventListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarPlotEventListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarSafeModeListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarStatusScreenListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarTownEventListener; -import com.gmail.goosius.siegewar.listeners.SiegeWarTownyEventListener; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; - -public class SiegeWar extends JavaPlugin { - - private static SiegeWar plugin; - private final Version requiredTownyVersion = Version.fromString("0.98.0.0"); - private static final SiegeHUDManager siegeHUDManager = new SiegeHUDManager(); - - private static boolean siegeWarPluginError = false; - private CannonsIntegration cannonsIntegration; - - public static SiegeWar getSiegeWar() { - return plugin; - } - - public File getSiegeWarJarFile() { - return getFile(); - } - - public static SiegeHUDManager getSiegeHUDManager() { - return siegeHUDManager; - } - - @Override - public void onEnable() { - - plugin = this; - - printSickASCIIArt(); - - if (!townyVersionCheck(getTownyVersion())) { - severe("Towny version does not meet required minimum version: " + requiredTownyVersion); - siegeWarPluginError = true; - } else { - info("Towny version " + getTownyVersion() + " found."); - } - - handleLegacyConfigs(); - - if (!loadAll()) { - siegeWarPluginError = true; - } - - cleanupBattleSession(); - registerCommands(); - registerListeners(); - checkIntegrations(); - cleanupLegacyMetaData(); - - if(siegeWarPluginError) { - severe("SiegeWar did not load successfully, and is now in safe mode!"); - } else { - info("SiegeWar loaded successfully."); - } - } - - private void handleLegacyConfigs() { - Path configPath = getDataFolder().toPath().resolve("config.yml"); - if (!Files.exists(configPath)) - return; - - CommentedConfiguration config = new CommentedConfiguration(configPath); - if (!config.load() || config.getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), "0.0.0.0").equals(getVersion())) - return; - - ConfigMigrator earlyMigrator = new ConfigMigrator(config, "config-migration.json", true); - earlyMigrator.migrate(); - } - - @Override - public void onDisable() { - info("Shutting down..."); - } - - private boolean loadAll() { - return !Towny.getPlugin().isError() - && Settings.loadSettingsAndLang() - && SiegeController.loadAll() - && TownOccupationController.loadAll(); - } - - public String getVersion() { - return getDescription().getVersion(); - } - - private boolean townyVersionCheck(String version) { - return Version.fromString(version).compareTo(requiredTownyVersion) >= 0; - } - - private String getTownyVersion() { - return Towny.getPlugin().getDescription().getVersion(); - } - - private void checkIntegrations() { - if (siegeWarPluginError) { - severe("SiegeWar is in safe mode! Plugin integrations disabled."); - } else if (!SiegeWarSettings.getWarSiegeEnabled()) { - info("SiegeWar is disabled in config. Plugin integrations disabled."); - } else { - if (getServer().getPluginManager().isPluginEnabled("Cannons")) { - info("SiegeWar found Cannons plugin, enabling Cannons support."); - cannonsIntegration = new CannonsIntegration(this); - } - if (getServer().getPluginManager().isPluginEnabled("dynmap")) { - info("SiegeWar found Dynmap plugin, enabling Dynmap support."); - new DynmapIntegration(this); - } - if (getServer().getPluginManager().isPluginEnabled("MapTowny")) { - info("SiegeWar found the MapTowny plugin, enabling MapTowny support."); - new MapTownyIntegration(this); - } - } - } - - private void registerListeners() { - PluginManager pm = getServer().getPluginManager(); - - if (siegeWarPluginError) - pm.registerEvents(new SiegeWarSafeModeListener(this), this); - else { - pm.registerEvents(new SiegeWarActionListener(this), this); - pm.registerEvents(new SiegeWarBukkitEventListener(this), this); - pm.registerEvents(new SiegeWarTownyEventListener(this), this); - pm.registerEvents(new SiegeWarNationEventListener(), this); - pm.registerEvents(new SiegeWarTownEventListener(this), this); - pm.registerEvents(new SiegeWarPlotEventListener(this), this); - pm.registerEvents(new SiegeWarStatusScreenListener(), this); - } - } - - private void registerCommands() { - if(siegeWarPluginError) { - severe("SiegeWar is in safe mode. SiegeWar commands not registered"); - } else { - getCommand("siegewar").setExecutor(new SiegeWarCommand()); - getCommand("siegewaradmin").setExecutor(new SiegeWarAdminCommand()); - new SiegeWarNationAddonCommand(); - } - } - - private void printSickASCIIArt() { - String art = System.lineSeparator() + "#2DE2E6 _________.__ #FF6C11__ __" + - System.lineSeparator() + "#2DE2E6 / _____/|__| ____ ____ ____#FF6C11/ \\ / \\_____ _______" + - System.lineSeparator() + "#2DE2E6 \\_____ \\ | |/ __ \\ / ___\\_/ __ #FF6C11\\ \\/\\/ /\\__ \\\\_ __ \\" + - System.lineSeparator() + "#2DE2E6 / \\| \\ ___// /_/ > ___/#FF6C11\\ / / __ \\| | \\/" + - System.lineSeparator() + "#2DE2E6 /_______ /|__|\\___ >___ / \\___ >#FF6C11\\__/\\ / (____ /__| " + - System.lineSeparator() + "#2DE2E6 \\/ \\/_____/ \\/ #FF6C11\\/ \\/" + - System.lineSeparator() + "#791E94 By Goosius & LlmDl" + System.lineSeparator(); - Bukkit.getLogger().info(Colors.translateColorCodes(art)); - } - - public static boolean isCannonsPluginInstalled() { - return plugin.cannonsIntegration != null; - } - - public boolean isError() { - return siegeWarPluginError; - } - - public static void info(String msg) { - plugin.getLogger().info(msg); - } - - public static void severe(String msg) { - plugin.getLogger().severe(msg); - } - - /** - * Cleans up the battle session, if it did not exit properly when the plugin shut down. - */ - private void cleanupBattleSession() { - if(siegeWarPluginError) { - severe("SiegeWar is in safe mode. Battle Session Cleanup not attempted."); - } else { - //Find any sieges with unresolved battles - List siegesWithUnresolvedBattles = new ArrayList<>(); - for(Siege siege: SiegeController.getSieges()) { - if(siege.getStatus() == SiegeStatus.IN_PROGRESS - && (siege.getAttackerBattlePoints() > 0 || siege.getDefenderBattlePoints() > 0)) { - siegesWithUnresolvedBattles.add(siege); - } - } - //Resolve battles - if(siegesWithUnresolvedBattles.size() > 0) { - info(Translation.of("msg.battle.session.cleanup.starting")); - int numBattlesUpdated = 0; - for(Siege siege: siegesWithUnresolvedBattles) { - siege.adjustSiegeBalance(siege.getAttackerBattlePoints() - siege.getDefenderBattlePoints()); - siege.setAttackerBattlePoints(0); - siege.setDefenderBattlePoints(0); - SiegeController.saveSiege(siege); - numBattlesUpdated++; - } - - info(Translation.of("msg.battle.session.cleanup.complete", numBattlesUpdated)); - } - } - } - - /** - * Cleanup metadata which is non longer in use - */ - private void cleanupLegacyMetaData() { - for(Resident resident: TownyUniverse.getInstance().getResidents()) { - ResidentMetaDataController.clearPlunder(resident); - } - } -} +package com.gmail.goosius.siegewar; + +import com.gmail.goosius.siegewar.enums.SiegeStatus; +import com.gmail.goosius.siegewar.integration.maptowny.MapTownyIntegration; +import com.gmail.goosius.siegewar.metadata.ResidentMetaDataController; +import com.gmail.goosius.siegewar.objects.Siege; +import com.gmail.goosius.siegewar.settings.SiegeWarSettings; +import com.gmail.goosius.siegewar.settings.migrator.ConfigMigrator; +import com.palmergames.bukkit.towny.TownyUniverse; +import com.palmergames.bukkit.towny.object.Resident; +import com.palmergames.bukkit.towny.object.Translation; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import com.gmail.goosius.siegewar.settings.ConfigNodes; +import com.gmail.goosius.siegewar.settings.Settings; +import com.palmergames.bukkit.config.CommentedConfiguration; +import com.palmergames.bukkit.towny.Towny; +import com.palmergames.bukkit.util.Colors; +import com.palmergames.bukkit.util.Version; +import com.gmail.goosius.siegewar.command.SiegeWarAdminCommand; +import com.gmail.goosius.siegewar.command.SiegeWarCommand; +import com.gmail.goosius.siegewar.command.SiegeWarNationAddonCommand; +import com.gmail.goosius.siegewar.hud.SiegeHUDManager; +import com.gmail.goosius.siegewar.integration.cannons.CannonsIntegration; +import com.gmail.goosius.siegewar.integration.dynmap.DynmapIntegration; +import com.gmail.goosius.siegewar.listeners.SiegeWarActionListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarBukkitEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarNationEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarPlotEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarSafeModeListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarStatusScreenListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarTownEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarTownyEventListener; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +public class SiegeWar extends JavaPlugin { + + private static SiegeWar plugin; + private final Version requiredTownyVersion = Version.fromString("0.98.0.0"); + private static final SiegeHUDManager siegeHUDManager = new SiegeHUDManager(); + + private static boolean siegeWarPluginError = false; + private CannonsIntegration cannonsIntegration; + + public static SiegeWar getSiegeWar() { + return plugin; + } + + public File getSiegeWarJarFile() { + return getFile(); + } + + public static SiegeHUDManager getSiegeHUDManager() { + return siegeHUDManager; + } + + @Override + public void onEnable() { + + plugin = this; + + printSickASCIIArt(); + + if (!townyVersionCheck(getTownyVersion())) { + severe("Towny version does not meet required minimum version: " + requiredTownyVersion); + siegeWarPluginError = true; + } else { + info("Towny version " + getTownyVersion() + " found."); + } + + handleLegacyConfigs(); + + if (!loadAll()) { + siegeWarPluginError = true; + } + + cleanupBattleSession(); + registerCommands(); + registerListeners(); + checkIntegrations(); + cleanupLegacyMetaData(); + + if(siegeWarPluginError) { + severe("SiegeWar did not load successfully, and is now in safe mode!"); + } else { + info("SiegeWar loaded successfully."); + } + } + + private void handleLegacyConfigs() { + Path configPath = getDataFolder().toPath().resolve("config.yml"); + if (!Files.exists(configPath)) + return; + + CommentedConfiguration config = new CommentedConfiguration(configPath); + if (!config.load() || config.getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), "0.0.0.0").equals(getVersion())) + return; + + ConfigMigrator earlyMigrator = new ConfigMigrator(config, "config-migration.json", true); + earlyMigrator.migrate(); + } + + @Override + public void onDisable() { + info("Shutting down..."); + } + + private boolean loadAll() { + return !Towny.getPlugin().isError() + && Settings.loadSettingsAndLang() + && SiegeController.loadAll() + && TownOccupationController.loadAll(); + } + + public String getVersion() { + return getDescription().getVersion(); + } + + private boolean townyVersionCheck(String version) { + return Version.fromString(version).compareTo(requiredTownyVersion) >= 0; + } + + private String getTownyVersion() { + return Towny.getPlugin().getDescription().getVersion(); + } + + private void checkIntegrations() { + if (siegeWarPluginError) { + severe("SiegeWar is in safe mode! Plugin integrations disabled."); + } else if (!SiegeWarSettings.getWarSiegeEnabled()) { + info("SiegeWar is disabled in config. Plugin integrations disabled."); + } else { + if (getServer().getPluginManager().isPluginEnabled("Cannons")) { + info("SiegeWar found Cannons plugin, enabling Cannons support."); + cannonsIntegration = new CannonsIntegration(this); + } + if (getServer().getPluginManager().isPluginEnabled("dynmap")) { + info("SiegeWar found Dynmap plugin, enabling Dynmap support."); + new DynmapIntegration(this); + } + if (getServer().getPluginManager().isPluginEnabled("MapTowny")) { + info("SiegeWar found the MapTowny plugin, enabling MapTowny support."); + new MapTownyIntegration(this); + } + } + } + + private void registerListeners() { + PluginManager pm = getServer().getPluginManager(); + + if (siegeWarPluginError) + pm.registerEvents(new SiegeWarSafeModeListener(this), this); + else { + pm.registerEvents(new SiegeWarActionListener(this), this); + pm.registerEvents(new SiegeWarBukkitEventListener(this), this); + pm.registerEvents(new SiegeWarTownyEventListener(this), this); + pm.registerEvents(new SiegeWarNationEventListener(), this); + pm.registerEvents(new SiegeWarTownEventListener(this), this); + pm.registerEvents(new SiegeWarPlotEventListener(this), this); + pm.registerEvents(new SiegeWarStatusScreenListener(), this); + } + } + + private void registerCommands() { + if(siegeWarPluginError) { + severe("SiegeWar is in safe mode. SiegeWar commands not registered"); + } else { + getCommand("siegewar").setExecutor(new SiegeWarCommand()); + getCommand("siegewaradmin").setExecutor(new SiegeWarAdminCommand()); + new SiegeWarNationAddonCommand(); + } + } + + private void printSickASCIIArt() { + String art = System.lineSeparator() + "#2DE2E6 _________.__ #FF6C11__ __" + + System.lineSeparator() + "#2DE2E6 / _____/|__| ____ ____ ____#FF6C11/ \\ / \\_____ _______" + + System.lineSeparator() + "#2DE2E6 \\_____ \\ | |/ __ \\ / ___\\_/ __ #FF6C11\\ \\/\\/ /\\__ \\\\_ __ \\" + + System.lineSeparator() + "#2DE2E6 / \\| \\ ___// /_/ > ___/#FF6C11\\ / / __ \\| | \\/" + + System.lineSeparator() + "#2DE2E6 /_______ /|__|\\___ >___ / \\___ >#FF6C11\\__/\\ / (____ /__| " + + System.lineSeparator() + "#2DE2E6 \\/ \\/_____/ \\/ #FF6C11\\/ \\/" + + System.lineSeparator() + "#791E94 By Goosius & LlmDl" + System.lineSeparator(); + Bukkit.getLogger().info(Colors.translateColorCodes(art)); + } + + public static boolean isCannonsPluginInstalled() { + return plugin.cannonsIntegration != null; + } + + public boolean isError() { + return siegeWarPluginError; + } + + public static void info(String msg) { + plugin.getLogger().info(msg); + } + + public static void severe(String msg) { + plugin.getLogger().severe(msg); + } + + /** + * Cleans up the battle session, if it did not exit properly when the plugin shut down. + */ + private void cleanupBattleSession() { + if(siegeWarPluginError) { + severe("SiegeWar is in safe mode. Battle Session Cleanup not attempted."); + } else { + //Find any sieges with unresolved battles + List siegesWithUnresolvedBattles = new ArrayList<>(); + for(Siege siege: SiegeController.getSieges()) { + if(siege.getStatus() == SiegeStatus.IN_PROGRESS + && (siege.getAttackerBattlePoints() > 0 || siege.getDefenderBattlePoints() > 0)) { + siegesWithUnresolvedBattles.add(siege); + } + } + //Resolve battles + if(siegesWithUnresolvedBattles.size() > 0) { + info(Translation.of("msg.battle.session.cleanup.starting")); + int numBattlesUpdated = 0; + for(Siege siege: siegesWithUnresolvedBattles) { + siege.adjustSiegeBalance(siege.getAttackerBattlePoints() - siege.getDefenderBattlePoints()); + siege.setAttackerBattlePoints(0); + siege.setDefenderBattlePoints(0); + SiegeController.saveSiege(siege); + numBattlesUpdated++; + } + + info(Translation.of("msg.battle.session.cleanup.complete", numBattlesUpdated)); + } + } + } + + /** + * Cleanup metadata which is non longer in use + */ + private void cleanupLegacyMetaData() { + for(Resident resident: TownyUniverse.getInstance().getResidents()) { + ResidentMetaDataController.clearPlunder(resident); + } + } +} diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/Settings.java b/src/main/java/com/gmail/goosius/siegewar/settings/Settings.java index d553367a4..812abfe8e 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/Settings.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/Settings.java @@ -1,204 +1,204 @@ -package com.gmail.goosius.siegewar.settings; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.bukkit.plugin.Plugin; - -import com.gmail.goosius.siegewar.SiegeWar; -import com.gmail.goosius.siegewar.settings.migrator.ConfigMigrator; -import com.gmail.goosius.siegewar.utils.FileMgmt; -import com.gmail.goosius.siegewar.utils.SiegeWarBattleSessionUtil; -import com.palmergames.bukkit.config.CommentedConfiguration; -import com.palmergames.bukkit.towny.TownyAPI; -import com.palmergames.bukkit.towny.object.TranslationLoader; -import com.palmergames.util.TimeTools; - -public class Settings { - private static CommentedConfiguration config, newConfig; - private static File battleIconFile; - public static final String BATTLE_BANNER_FILE_NAME = "crossedswords.png"; - public static final String PEACEFUL_BANNER_FILE_NAME = "fire.png"; - - public static boolean loadSettingsAndLang() { - SiegeWar sw = SiegeWar.getSiegeWar(); - boolean loadSuccessFlag = true; - - try { - Settings.loadConfig(sw.getDataFolder().getPath() + File.separator + "config.yml", sw.getVersion()); - } catch (Exception e) { - SiegeWar.severe("Config.yml failed to load! Disabling!"); - loadSuccessFlag = false; - } - - if (Settings.getLastRunVersion(SiegeWar.getSiegeWar().getVersion()).equals(SiegeWar.getSiegeWar().getVersion())) { - ConfigMigrator migrator = new ConfigMigrator(config, "config-migration.json", false); - migrator.migrate(); - } - - // Some list variables do not reload upon loadConfig. - SiegeWarSettings.resetCachedSettings(); - - try { - Plugin plugin = SiegeWar.getSiegeWar(); - Path langFolderPath = Paths.get(plugin.getDataFolder().getPath()).resolve("lang"); - TranslationLoader loader = new TranslationLoader(langFolderPath, plugin, SiegeWar.class); - loader.load(); - TownyAPI.getInstance().addTranslations(plugin, loader.getTranslations()); - } catch (Exception e) { - SiegeWar.severe("Language file failed to load! Disabling!"); - loadSuccessFlag = false; - } - - //Extract images - try { - battleIconFile = FileMgmt.extractImageFile(BATTLE_BANNER_FILE_NAME); - } catch (Exception e) { - e.printStackTrace(); - SiegeWar.severe("Could not load images! Disabling!"); - loadSuccessFlag = false; - } - - //Schedule next battle session - try { - SiegeWarBattleSessionUtil.attemptToScheduleNextBattleSession(); - } catch (Exception e) { - e.printStackTrace(); - SiegeWar.severe("Problem Scheduling Battle Session! Disabling!"); - loadSuccessFlag = false; - } - - return loadSuccessFlag; - } - - public static void loadConfig(String filepath, String version) throws Exception { - if (FileMgmt.checkOrCreateFile(filepath)) { - File file = new File(filepath); - - // read the config.yml into memory - config = new CommentedConfiguration(file.toPath()); - if (!config.load()) - throw new IOException("Failed to load Config!"); - - setDefaults(version, file); - config.save(); - } - } - - public static void addComment(String root, String... comments) { - - newConfig.addComment(root.toLowerCase(), comments); - } - - private static void setNewProperty(String root, Object value) { - - if (value == null) { - value = ""; - } - newConfig.set(root.toLowerCase(), value.toString()); - } - - private static void setProperty(String root, Object value) { - - config.set(root.toLowerCase(), value.toString()); - } - - public static String getLastRunVersion(String currentVersion) { - - return getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion); - } - - /** - * Builds a new config reading old config data. - */ - private static void setDefaults(String version, File file) { - - newConfig = new CommentedConfiguration(file.toPath()); - newConfig.load(); - - for (ConfigNodes root : ConfigNodes.values()) { - if (root.getComments().length > 0) - addComment(root.getRoot(), root.getComments()); - if (root.getRoot() == ConfigNodes.VERSION.getRoot()) - setNewProperty(root.getRoot(), version); - else if (root.getRoot() == ConfigNodes.LAST_RUN_VERSION.getRoot()) - setNewProperty(root.getRoot(), SiegeWar.getSiegeWar().getVersion()); - else - setNewProperty(root.getRoot(), (config.get(root.getRoot().toLowerCase()) != null) ? config.get(root.getRoot().toLowerCase()) : root.getDefault()); - } - - config = newConfig; - newConfig = null; - } - - public static String getString(String root, String def) { - - String data = config.getString(root.toLowerCase(), def); - if (data == null) { - sendError(root.toLowerCase() + " from config.yml"); - return ""; - } - return data; - } - - private static void sendError(String msg) { - - SiegeWar.severe("Error could not read " + msg); - } - - public static boolean getBoolean(ConfigNodes node) { - - return Boolean.parseBoolean(config.getString(node.getRoot().toLowerCase(), node.getDefault())); - } - - public static double getDouble(ConfigNodes node) { - - try { - return Double.parseDouble(config.getString(node.getRoot().toLowerCase(), node.getDefault()).trim()); - } catch (NumberFormatException e) { - sendError(node.getRoot().toLowerCase() + " from config.yml"); - return 0.0; - } - } - - public static int getInt(ConfigNodes node) { - - try { - return Integer.parseInt(config.getString(node.getRoot().toLowerCase(), node.getDefault()).trim()); - } catch (NumberFormatException e) { - sendError(node.getRoot().toLowerCase() + " from config.yml"); - return 0; - } - } - - public static String getString(ConfigNodes node) { - - return config.getString(node.getRoot().toLowerCase(), node.getDefault()); - } - - public static long getSeconds(ConfigNodes node) { - - try { - return TimeTools.getSeconds(getString(node)); - } catch (NumberFormatException e) { - sendError(node.getRoot().toLowerCase() + " from config.yml"); - return 1; - } - } - - public static void setLastRunVersion(String currentVersion) { - - setProperty(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion); - config.save(); - } - - public static File getBattleIconFile() { - return battleIconFile; - } - - public static CommentedConfiguration getConfig() { - return config; - } -} +package com.gmail.goosius.siegewar.settings; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.bukkit.plugin.Plugin; + +import com.gmail.goosius.siegewar.SiegeWar; +import com.gmail.goosius.siegewar.settings.migrator.ConfigMigrator; +import com.gmail.goosius.siegewar.utils.FileMgmt; +import com.gmail.goosius.siegewar.utils.SiegeWarBattleSessionUtil; +import com.palmergames.bukkit.config.CommentedConfiguration; +import com.palmergames.bukkit.towny.TownyAPI; +import com.palmergames.bukkit.towny.object.TranslationLoader; +import com.palmergames.util.TimeTools; + +public class Settings { + private static CommentedConfiguration config, newConfig; + private static File battleIconFile; + public static final String BATTLE_BANNER_FILE_NAME = "crossedswords.png"; + public static final String PEACEFUL_BANNER_FILE_NAME = "fire.png"; + + public static boolean loadSettingsAndLang() { + SiegeWar sw = SiegeWar.getSiegeWar(); + boolean loadSuccessFlag = true; + + try { + Settings.loadConfig(sw.getDataFolder().getPath() + File.separator + "config.yml", sw.getVersion()); + } catch (Exception e) { + SiegeWar.severe("Config.yml failed to load! Disabling!"); + loadSuccessFlag = false; + } + + if (Settings.getLastRunVersion(SiegeWar.getSiegeWar().getVersion()).equals(SiegeWar.getSiegeWar().getVersion())) { + ConfigMigrator migrator = new ConfigMigrator(config, "config-migration.json", false); + migrator.migrate(); + } + + // Some list variables do not reload upon loadConfig. + SiegeWarSettings.resetCachedSettings(); + + try { + Plugin plugin = SiegeWar.getSiegeWar(); + Path langFolderPath = Paths.get(plugin.getDataFolder().getPath()).resolve("lang"); + TranslationLoader loader = new TranslationLoader(langFolderPath, plugin, SiegeWar.class); + loader.load(); + TownyAPI.getInstance().addTranslations(plugin, loader.getTranslations()); + } catch (Exception e) { + SiegeWar.severe("Language file failed to load! Disabling!"); + loadSuccessFlag = false; + } + + //Extract images + try { + battleIconFile = FileMgmt.extractImageFile(BATTLE_BANNER_FILE_NAME); + } catch (Exception e) { + e.printStackTrace(); + SiegeWar.severe("Could not load images! Disabling!"); + loadSuccessFlag = false; + } + + //Schedule next battle session + try { + SiegeWarBattleSessionUtil.attemptToScheduleNextBattleSession(); + } catch (Exception e) { + e.printStackTrace(); + SiegeWar.severe("Problem Scheduling Battle Session! Disabling!"); + loadSuccessFlag = false; + } + + return loadSuccessFlag; + } + + public static void loadConfig(String filepath, String version) throws Exception { + if (FileMgmt.checkOrCreateFile(filepath)) { + File file = new File(filepath); + + // read the config.yml into memory + config = new CommentedConfiguration(file.toPath()); + if (!config.load()) + throw new IOException("Failed to load Config!"); + + setDefaults(version, file); + config.save(); + } + } + + public static void addComment(String root, String... comments) { + + newConfig.addComment(root.toLowerCase(), comments); + } + + private static void setNewProperty(String root, Object value) { + + if (value == null) { + value = ""; + } + newConfig.set(root.toLowerCase(), value.toString()); + } + + private static void setProperty(String root, Object value) { + + config.set(root.toLowerCase(), value.toString()); + } + + public static String getLastRunVersion(String currentVersion) { + + return getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion); + } + + /** + * Builds a new config reading old config data. + */ + private static void setDefaults(String version, File file) { + + newConfig = new CommentedConfiguration(file.toPath()); + newConfig.load(); + + for (ConfigNodes root : ConfigNodes.values()) { + if (root.getComments().length > 0) + addComment(root.getRoot(), root.getComments()); + if (root.getRoot() == ConfigNodes.VERSION.getRoot()) + setNewProperty(root.getRoot(), version); + else if (root.getRoot() == ConfigNodes.LAST_RUN_VERSION.getRoot()) + setNewProperty(root.getRoot(), SiegeWar.getSiegeWar().getVersion()); + else + setNewProperty(root.getRoot(), (config.get(root.getRoot().toLowerCase()) != null) ? config.get(root.getRoot().toLowerCase()) : root.getDefault()); + } + + config = newConfig; + newConfig = null; + } + + public static String getString(String root, String def) { + + String data = config.getString(root.toLowerCase(), def); + if (data == null) { + sendError(root.toLowerCase() + " from config.yml"); + return ""; + } + return data; + } + + private static void sendError(String msg) { + + SiegeWar.severe("Error could not read " + msg); + } + + public static boolean getBoolean(ConfigNodes node) { + + return Boolean.parseBoolean(config.getString(node.getRoot().toLowerCase(), node.getDefault())); + } + + public static double getDouble(ConfigNodes node) { + + try { + return Double.parseDouble(config.getString(node.getRoot().toLowerCase(), node.getDefault()).trim()); + } catch (NumberFormatException e) { + sendError(node.getRoot().toLowerCase() + " from config.yml"); + return 0.0; + } + } + + public static int getInt(ConfigNodes node) { + + try { + return Integer.parseInt(config.getString(node.getRoot().toLowerCase(), node.getDefault()).trim()); + } catch (NumberFormatException e) { + sendError(node.getRoot().toLowerCase() + " from config.yml"); + return 0; + } + } + + public static String getString(ConfigNodes node) { + + return config.getString(node.getRoot().toLowerCase(), node.getDefault()); + } + + public static long getSeconds(ConfigNodes node) { + + try { + return TimeTools.getSeconds(getString(node)); + } catch (NumberFormatException e) { + sendError(node.getRoot().toLowerCase() + " from config.yml"); + return 1; + } + } + + public static void setLastRunVersion(String currentVersion) { + + setProperty(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion); + config.save(); + } + + public static File getBattleIconFile() { + return battleIconFile; + } + + public static CommentedConfiguration getConfig() { + return config; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 99c3e62c6..7da527124 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,119 +1,119 @@ -name: ${project.artifactId} -main: ${project.groupId}.${project.name}.${project.artifactId} -version: ${project.version} -api-version: ${project.bukkitAPIVersion} -author: [Goosius,LlmDl] -website: 'townyadvanced.github.io' -prefix: ${project.artifactId} -depend: [Towny] -softdepend: [TownyCultures, dynmap, Cannons, Dynmap-Towny, MapTowny] - -description: A war system made by Goosius for Towny. - -commands: - siegewar: - aliases: [sw] - siegewaradmin: - aliases: [swa] - -permissions: - siegewar.admin: - description: User is able to use all siege war commands. - default: op - children: - siegewar.command.siegewaradmin.*: true - siegewar.command.siegewar.*: true - - siegewar.command.siegewaradmin.*: - description: User is able to use all /siegewaradmin commands. - default: op - children: - siegewar.command.siegewaradmin.immunity: true - siegewar.command.siegewaradmin.reload: true - siegewar.command.siegewaradmin.siege: true - siegewar.command.siegewaradmin.town: true - siegewar.command.siegewaradmin.nation: true - siegewar.command.siegewaradmin.installperms: true - siegewar.command.siegewaradmin.battlesession: true - - siegewar.command.siegewar.*: - description: User is able to do all /siegewar commands. - default: false - children: - siegewar.command.siegewar.hud.*: true - siegewar.command.siegewar.town.*: true - siegewar.command.siegewar.nation.*: true - siegewar.command.siegewar.guide: true - siegewar.command.siegewar.collect: true - - siegewar.command.siegewar.preference: - description: User is able to use /sw preference. - default: true - - siegewar.command.siegewar.nextsession: - description: User is able to use /sw nextsession. - default: true - - siegewar.command.siegewar.guide: - description: User is able to use /sw guide. - default: true - - siegewar.command.siegewar.hud.*: - description: User is able to do all /siegewar hud commands. - default: true - children: - siegewar.command.siegewar.hud: true - - siegewar.command.siegewar.town.*: - description: User is able to do all /siegewar town commands. - default: false - children: - siegewar.command.siegewar.town.inviteoccupation: true - - siegewar.command.siegewar.nation.*: - description: User is able to do all /siegewar nation commands. - default: false - children: - siegewar.command.siegewar.nation.paysoldiers: true - siegewar.command.siegewar.nation.removeoccupation: true - siegewar.command.siegewar.nation.transferoccupation: true - - siegewar.nation.siege.*: - description: User holds all of the siegewar nation nodes. - default: false - children: - siegewar.nation.siege.battle.points: true - siegewar.nation.siege.attack: true - siegewar.nation.siege.abandon: true - siegewar.nation.siege.invade: true - siegewar.nation.siege.plunder: true - siegewar.nation.siege.conquest.siege.start: true - siegewar.nation.siege.conquest.siege.abandon: true - siegewar.nation.siege.liberation.siege.start: true - siegewar.nation.siege.liberation.siege.abandon: true - siegewar.nation.siege.revolt.siege.surrender: true - siegewar.nation.siege.suppression.siege.start: true - siegewar.nation.siege.suppression.siege.abandon: true - siegewar.nation.siege.subvertpeacefultown: true - siegewar.nation.siege.use.breach.points: true - siegewar.nation.siege.fire.cannon.in.siegezone: true - - siegewar.town.siege.*: - description: User holds all of the siegewar town nodes. - default: false - children: - siegewar.town.siege.battle.points: true - siegewar.town.siege.conquest.siege.surrender: true - siegewar.town.siege.revolt.siege.start: true - siegewar.town.siege.revolt.siege.abandon: true - siegewar.town.siege.suppression.siege.surrender: true - siegewar.town.siege.revoltpeacefully: true - siegewar.town.siege.fire.cannon.in.siegezone: true - - siegewar.command.siegewar.collect: - description: User is able to do the /siegewar collect command. - default: true - - siegewar.immune.to.war.nausea: - description: User is immune to war nausea. - default: false +name: ${project.artifactId} +main: ${project.groupId}.${project.name}.${project.artifactId} +version: ${project.version} +api-version: ${project.bukkitAPIVersion} +author: [Goosius,LlmDl] +website: 'townyadvanced.github.io' +prefix: ${project.artifactId} +depend: [Towny] +softdepend: [TownyCultures, dynmap, Cannons, Dynmap-Towny, MapTowny] + +description: A war system made by Goosius for Towny. + +commands: + siegewar: + aliases: [sw] + siegewaradmin: + aliases: [swa] + +permissions: + siegewar.admin: + description: User is able to use all siege war commands. + default: op + children: + siegewar.command.siegewaradmin.*: true + siegewar.command.siegewar.*: true + + siegewar.command.siegewaradmin.*: + description: User is able to use all /siegewaradmin commands. + default: op + children: + siegewar.command.siegewaradmin.immunity: true + siegewar.command.siegewaradmin.reload: true + siegewar.command.siegewaradmin.siege: true + siegewar.command.siegewaradmin.town: true + siegewar.command.siegewaradmin.nation: true + siegewar.command.siegewaradmin.installperms: true + siegewar.command.siegewaradmin.battlesession: true + + siegewar.command.siegewar.*: + description: User is able to do all /siegewar commands. + default: false + children: + siegewar.command.siegewar.hud.*: true + siegewar.command.siegewar.town.*: true + siegewar.command.siegewar.nation.*: true + siegewar.command.siegewar.guide: true + siegewar.command.siegewar.collect: true + + siegewar.command.siegewar.preference: + description: User is able to use /sw preference. + default: true + + siegewar.command.siegewar.nextsession: + description: User is able to use /sw nextsession. + default: true + + siegewar.command.siegewar.guide: + description: User is able to use /sw guide. + default: true + + siegewar.command.siegewar.hud.*: + description: User is able to do all /siegewar hud commands. + default: true + children: + siegewar.command.siegewar.hud: true + + siegewar.command.siegewar.town.*: + description: User is able to do all /siegewar town commands. + default: false + children: + siegewar.command.siegewar.town.inviteoccupation: true + + siegewar.command.siegewar.nation.*: + description: User is able to do all /siegewar nation commands. + default: false + children: + siegewar.command.siegewar.nation.paysoldiers: true + siegewar.command.siegewar.nation.removeoccupation: true + siegewar.command.siegewar.nation.transferoccupation: true + + siegewar.nation.siege.*: + description: User holds all of the siegewar nation nodes. + default: false + children: + siegewar.nation.siege.battle.points: true + siegewar.nation.siege.attack: true + siegewar.nation.siege.abandon: true + siegewar.nation.siege.invade: true + siegewar.nation.siege.plunder: true + siegewar.nation.siege.conquest.siege.start: true + siegewar.nation.siege.conquest.siege.abandon: true + siegewar.nation.siege.liberation.siege.start: true + siegewar.nation.siege.liberation.siege.abandon: true + siegewar.nation.siege.revolt.siege.surrender: true + siegewar.nation.siege.suppression.siege.start: true + siegewar.nation.siege.suppression.siege.abandon: true + siegewar.nation.siege.subvertpeacefultown: true + siegewar.nation.siege.use.breach.points: true + siegewar.nation.siege.fire.cannon.in.siegezone: true + + siegewar.town.siege.*: + description: User holds all of the siegewar town nodes. + default: false + children: + siegewar.town.siege.battle.points: true + siegewar.town.siege.conquest.siege.surrender: true + siegewar.town.siege.revolt.siege.start: true + siegewar.town.siege.revolt.siege.abandon: true + siegewar.town.siege.suppression.siege.surrender: true + siegewar.town.siege.revoltpeacefully: true + siegewar.town.siege.fire.cannon.in.siegezone: true + + siegewar.command.siegewar.collect: + description: User is able to do the /siegewar collect command. + default: true + + siegewar.immune.to.war.nausea: + description: User is immune to war nausea. + default: false From f37a7557a9b8ead68354b64316765801e7b1ab5e Mon Sep 17 00:00:00 2001 From: Silverwolfg11 Date: Sun, 1 May 2022 14:00:50 -0700 Subject: [PATCH 3/3] Use NewShortTimeEvent to trigger renders. --- .../maptowny/MapTownyIntegration.java | 4 ++-- .../maptowny/MapTownyShortTimeListener.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyShortTimeListener.java diff --git a/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyIntegration.java b/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyIntegration.java index b913e7980..0facc6d26 100644 --- a/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyIntegration.java +++ b/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyIntegration.java @@ -56,8 +56,8 @@ public MapTownyIntegration(SiegeWar plugin) { // Register replacement handler Bukkit.getPluginManager().registerEvents(new MapTownyReplacementsHandler(mapTowny), plugin); - // Register repeating task that runs every 2 seconds delayed by 15 seconds on start. - Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this::displaySieges, 40L, 300L); + // Re-render the sieges every time a new short time event triggers. + Bukkit.getPluginManager().registerEvents(new MapTownyShortTimeListener(this::displaySieges), plugin); final String pluginName = plugin.getName(); // Run marker and layer setup on platform initialize diff --git a/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyShortTimeListener.java b/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyShortTimeListener.java new file mode 100644 index 000000000..075333c60 --- /dev/null +++ b/src/main/java/com/gmail/goosius/siegewar/integration/maptowny/MapTownyShortTimeListener.java @@ -0,0 +1,19 @@ +package com.gmail.goosius.siegewar.integration.maptowny; + +import com.palmergames.bukkit.towny.event.time.NewShortTimeEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class MapTownyShortTimeListener implements Listener { + + private final Runnable renderSieges; + + public MapTownyShortTimeListener(Runnable renderSieges) { + this.renderSieges = renderSieges; + } + + @EventHandler + public void onNewShortTime(NewShortTimeEvent event) { + this.renderSieges.run(); + } +}