From 1d1e20fbb47da222e1a5da64f2d45478cf86808e Mon Sep 17 00:00:00 2001 From: MagmaGuy Date: Sat, 1 Jan 2022 19:49:45 +0000 Subject: [PATCH] EliteMobs 7.3.12-SNAPSHOT-6 - [New] Added the exports folder - [New] Exports folder now packages resource packs for admins. This hooks up to Model Engine to get the files, and aggregates the resource packs in the exports folder in a non-destructive way, meaning you can safely update existing resource packs if you place an existing one in the exports folder - [New] Added SHA1 texture pack calculation and optional server.properties overriding, updates the server-side data for you. All that is left to be done to apply Custom Models via resource packs is uploading the resource pack at a location of your choice. - [New] Added the command /em generateresourcepack for generating the resource pack - [New] Added the command /em updateresourcepack for automatically updating the SHA1 code of the texture pack based on the zipped resource pack in the exports folder, still requires a restart for it to be applied - [New] Importing dungeons with custom models will now autosuggest generating the resource pack to any online players with elitemobs.* - [Fix] Reloading elitemobs now correctly unregisters timed and action events - [Fix] Fixed error associated to the knockback invulnerability power - [Fix] Fixed a database error which would trigger when a new player logged in and out extremely quickly - [Refactor] Minor Sonarlint improvements Signed-off-by: MagmaGuy --- .../com/magmaguy/elitemobs/EliteMobs.java | 6 +- .../elitemobs/commands/AdminCommands.java | 16 ++ .../elitemobs/commands/setup/SetupMenu.java | 2 +- .../config/ConfigurationExporter.java | 209 ++++++++++++++++++ .../ConfigurationImporter.java | 18 +- .../menus/premade/PlayerStatusMenuConfig.java | 73 +++++- .../elitemobs/events/ActionEvent.java | 4 + .../magmaguy/elitemobs/events/TimedEvent.java | 4 + .../custombosses/BossTrace.java | 4 - .../statusscreen/BossTrackingPage.java | 21 +- .../playerdata/statusscreen/CommandsPage.java | 10 +- .../playerdata/statusscreen/CoverPage.java | 34 +-- .../playerdata/statusscreen/GearPage.java | 22 +- .../statusscreen/PlayerStatusScreen.java | 12 +- .../playerdata/statusscreen/StatsPage.java | 10 +- .../statusscreen/TeleportsPage.java | 12 +- .../InvulnerabilityKnockback.java | 2 + .../playercooldowns/PlayerQuestCooldowns.java | 2 + .../magmaguy/elitemobs/utils/UnzipFile.java | 60 ----- .../com/magmaguy/elitemobs/utils/ZipFile.java | 161 ++++++++++++++ 20 files changed, 543 insertions(+), 139 deletions(-) create mode 100644 src/main/java/com/magmaguy/elitemobs/config/ConfigurationExporter.java rename src/main/java/com/magmaguy/elitemobs/config/{configurationimporter => }/ConfigurationImporter.java (90%) delete mode 100644 src/main/java/com/magmaguy/elitemobs/utils/UnzipFile.java create mode 100644 src/main/java/com/magmaguy/elitemobs/utils/ZipFile.java diff --git a/src/main/java/com/magmaguy/elitemobs/EliteMobs.java b/src/main/java/com/magmaguy/elitemobs/EliteMobs.java index 0d337aae2..1ec3b57a0 100644 --- a/src/main/java/com/magmaguy/elitemobs/EliteMobs.java +++ b/src/main/java/com/magmaguy/elitemobs/EliteMobs.java @@ -9,7 +9,6 @@ import com.magmaguy.elitemobs.commands.guild.AdventurersGuildCommand; import com.magmaguy.elitemobs.config.*; import com.magmaguy.elitemobs.config.commands.CommandsConfig; -import com.magmaguy.elitemobs.config.configurationimporter.ConfigurationImporter; import com.magmaguy.elitemobs.config.custombosses.CustomBossesConfig; import com.magmaguy.elitemobs.config.custombosses.CustomBossesConfigFields; import com.magmaguy.elitemobs.config.customevents.CustomEventsConfig; @@ -234,6 +233,7 @@ public void onEnable() { //Imports custom configurations and mindungeons from the import folder ConfigurationImporter.initializeConfigs(); + ConfigurationExporter.initializeConfigs(); //Import custom items after potentially importing new items new CustomItemsConfig(); @@ -327,6 +327,10 @@ public void onDisable() { new InfoMessage("Wiping Elite entities clean..."); EntityTracker.wipeShutdown(); + new InfoMessage("Clearing events..."); + TimedEvent.shutdown(); + ActionEvent.shutdown(); + new InfoMessage("Clearing valid worlds..."); validWorldList.clear(); new InfoMessage("Clearing zone based worlds..."); diff --git a/src/main/java/com/magmaguy/elitemobs/commands/AdminCommands.java b/src/main/java/com/magmaguy/elitemobs/commands/AdminCommands.java index d61b97222..b5e8bbfc3 100644 --- a/src/main/java/com/magmaguy/elitemobs/commands/AdminCommands.java +++ b/src/main/java/com/magmaguy/elitemobs/commands/AdminCommands.java @@ -9,6 +9,7 @@ import cloud.commandframework.types.tuples.Triplet; import com.magmaguy.elitemobs.ChatColorConverter; import com.magmaguy.elitemobs.commands.admin.*; +import com.magmaguy.elitemobs.config.ConfigurationExporter; import com.magmaguy.elitemobs.config.DefaultConfig; import com.magmaguy.elitemobs.config.custombosses.CustomBossesConfig; import com.magmaguy.elitemobs.config.custombosses.CustomBossesConfigFields; @@ -705,6 +706,21 @@ public AdminCommands(PaperCommandManager manager, Command.Builder } })); + // /em generateresourcepack + manager.command(builder.literal("generateresourcepack") + .senderType(CommandSender.class) + .permission("elitemobs.*") + .meta(CommandMeta.DESCRIPTION, "Generates a resource pack for EliteMobs using ModelEngine") + .handler(commandContext -> ConfigurationExporter.createResourcePack(commandContext.getSender()))); + + // /em updateresourcepack + manager.command(builder.literal("updateresourcepack") + .senderType(CommandSender.class) + .permission("elitemobs.*") + .meta(CommandMeta.DESCRIPTION, "Updates the SHA1 texture pack code based on the zipped resource pack in the exports.") + .handler(commandContext -> ConfigurationExporter.overwriteSHA1(commandContext.getSender()))); + + } private void testFireball(Player player) { diff --git a/src/main/java/com/magmaguy/elitemobs/commands/setup/SetupMenu.java b/src/main/java/com/magmaguy/elitemobs/commands/setup/SetupMenu.java index d6e54578a..659b315cd 100644 --- a/src/main/java/com/magmaguy/elitemobs/commands/setup/SetupMenu.java +++ b/src/main/java/com/magmaguy/elitemobs/commands/setup/SetupMenu.java @@ -187,7 +187,7 @@ public void onInventoryInteraction(InventoryClickEvent event) { if (!setupMenu.adventurersGuildIsDownloaded) { player.closeInventory(); player.sendMessage("----------------------------------------------------"); - player.sendMessage(ChatColorConverter.convert("&8[EliteMobs] &2Adventurer's Guild Hub download link: &9&nhttps://magmaguy.com/downloads/em_adventurers_guild.zip")); + player.sendMessage(ChatColorConverter.convert("&8[EliteMobs] &2Adventurer's Guild Hub download link: https://magmaguy.itch.io/")); player.sendMessage(ChatColorConverter.convert("&8[EliteMobs] &aOnce downloaded, follow this setup guide: &9&nhttps://youtu.be/boRg2X4qhw4")); player.sendMessage(ChatColorConverter.convert("&8[EliteMobs] &2Need help? " + DiscordLinks.mainLink)); player.sendMessage("----------------------------------------------------"); diff --git a/src/main/java/com/magmaguy/elitemobs/config/ConfigurationExporter.java b/src/main/java/com/magmaguy/elitemobs/config/ConfigurationExporter.java new file mode 100644 index 000000000..63995aee9 --- /dev/null +++ b/src/main/java/com/magmaguy/elitemobs/config/ConfigurationExporter.java @@ -0,0 +1,209 @@ +package com.magmaguy.elitemobs.config; + +import com.magmaguy.elitemobs.ChatColorConverter; +import com.magmaguy.elitemobs.MetadataHandler; +import com.magmaguy.elitemobs.utils.InfoMessage; +import com.magmaguy.elitemobs.utils.SpigotMessage; +import com.magmaguy.elitemobs.utils.WarningMessage; +import com.magmaguy.elitemobs.utils.ZipFile; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.security.DigestInputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Properties; + +public class ConfigurationExporter { + private ConfigurationExporter() { + } + + public static void initializeConfigs() { + Path configurationsPath = Paths.get(MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath()); + if (!Files.isDirectory(Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "exports"))) { + try { + Files.createDirectory(Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "exports")); + } catch (Exception exception) { + new WarningMessage("Failed to create exports directory! Tell the dev!"); + exception.printStackTrace(); + } + return; + } + + try { + new File(Paths.get(MetadataHandler.PLUGIN.getDataFolder().getCanonicalPath() + File.separatorChar + "exports").toString()); + } catch (Exception ex) { + new WarningMessage("Failed to get imports folder! Report this to the dev!"); + } + + } + + public static void createResourcePack(CommandSender commandSender) { + if (!Bukkit.getPluginManager().isPluginEnabled("ModelEngine")) { + commandSender.sendMessage(ChatColorConverter.convert("&8[EliteMobs]&c Could not generate resource pack because ModelEngine is not installed! Install ModelEngine to use this feature.")); + return; + } + + File modelEngineResourcePackFile = new File(MetadataHandler.PLUGIN.getDataFolder().getParentFile().toString() + File.separatorChar + "ModelEngine" + File.separatorChar + "resource pack"); + if (!modelEngineResourcePackFile.exists()) { + commandSender.sendMessage(ChatColorConverter.convert("&8[EliteMobs]&c Could not generate resource pack because ModelEngine is not installed! Install ModelEngine to use this feature.")); + return; + } + + + try { + if (!Paths.get(MetadataHandler.PLUGIN.getDataFolder() + "" + File.separatorChar + "exports" + File.separatorChar + "elitemobs_resource_pack").toFile().exists()) + Files.createDirectory(Paths.get(MetadataHandler.PLUGIN.getDataFolder() + "" + File.separatorChar + "exports" + File.separatorChar + "elitemobs_resource_pack")); + } catch (Exception ex) { + commandSender.sendMessage(ChatColorConverter.convert("&8[EliteMobs]&c Failed to generate target directory plugins/EliteMobs/exports/elitemobs_resource_pack required for storing the resource pack! Report this to the dev!")); + return; + } + + copyDirectory(modelEngineResourcePackFile, Paths.get(MetadataHandler.PLUGIN.getDataFolder() + "" + File.separatorChar + "exports" + File.separatorChar + "elitemobs_resource_pack")); + commandSender.sendMessage(ChatColorConverter.convert("&8[EliteMobs]&f Copied all files from Model Engine to " + MetadataHandler.PLUGIN.getDataFolder() + "" + File.separatorChar + "exports" + File.separatorChar + "elitemobs_resource_pack")); + + if (ZipFile.zip(new File(MetadataHandler.PLUGIN.getDataFolder() + "" + File.separatorChar + "exports" + File.separatorChar + "elitemobs_resource_pack"), + MetadataHandler.PLUGIN.getDataFolder() + "" + File.separatorChar + "exports" + File.separatorChar + "elitemobs_resource_pack.zip")) + commandSender.sendMessage(ChatColorConverter.convert("&8[EliteMobs]&f Packaged texture pack into " + + MetadataHandler.PLUGIN.getDataFolder() + "" + File.separatorChar + "exports" + File.separatorChar + "elitemobs_resource_pack.zip") + + " , ready to distribute!"); + else { + commandSender.sendMessage(ChatColorConverter.convert("&8[EliteMobs]&c Failed to package the resource pack into a zipped file! Report this to the dev!")); + return; + } + + if (commandSender instanceof Player) { + ((Player) commandSender).spigot().sendMessage(SpigotMessage.commandHoverMessage(ChatColorConverter.convert("Done! &2You can click here to update your server.properties with the new SHA1 value of this texture pack!"), + "Click runs the /em updateresourcepack command!", "/em updateresourcepack")); + commandSender.sendMessage("If you want to do it manually, your SHA1 code is " + generateResourcePackSHA1(commandSender)); + } else { + commandSender.sendMessage("Done! You can run the command /em updateresourcepack in order to put the right SHA1 value into server.properties. Don't forget to upload the texture place to some place where players can get it!"); + commandSender.sendMessage("If you want to do it manually, your SHA1 code is " + generateResourcePackSHA1(commandSender)); + } + + } + + private static String generateResourcePackSHA1(CommandSender commandSender) { + File zippedResourcePack = Paths.get(MetadataHandler.PLUGIN.getDataFolder() + "" + File.separatorChar + "exports" + File.separatorChar + "elitemobs_resource_pack.zip").toFile(); + if (!zippedResourcePack.exists()) { + commandSender.sendMessage("[EliteMobs] Failed to generate SHA-1 code, no zipped resource pack found!"); + return null; + } + String sha1 = null; + try { + sha1 = sha1Code(zippedResourcePack); + } catch (Exception ex) { + commandSender.sendMessage("[EliteMobs] Failed to generate SHA-1 code! Report this to the dev!"); + ex.printStackTrace(); + return null; + } + if (sha1 == null) { + commandSender.sendMessage("[EliteMobs] SHA-1 code is null! Report this to the dev!"); + return null; + } + return sha1; + } + + public static String sha1Code(File file) throws IOException, NoSuchAlgorithmException { + FileInputStream fileInputStream = new FileInputStream(file); + MessageDigest digest = MessageDigest.getInstance("SHA-1"); + DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, digest); + byte[] bytes = new byte[1024]; + // read all file content + while (digestInputStream.read(bytes) > 0) + digest = digestInputStream.getMessageDigest(); + byte[] resultByteArry = digest.digest(); + return bytesToHexString(resultByteArry); + } + + public static String bytesToHexString(byte[] bytes) { + StringBuilder sb = new StringBuilder(); + for (byte b : bytes) { + int value = b & 0xFF; + if (value < 16) { + // if value less than 16, then it's hex String will be only + // one character, so we need to append a character of '0' + sb.append("0"); + } + sb.append(Integer.toHexString(value).toUpperCase()); + } + return sb.toString(); + } + + private static void copyDirectory(File directoryToClone, Path targetPath) { + for (File file : directoryToClone.listFiles()) + try { + new InfoMessage("Adding " + file.getCanonicalPath()); + copyFile(file, targetPath); + } catch (Exception exception) { + new WarningMessage("Failed to move directories for " + file.getName() + "! Tell the dev!"); + exception.printStackTrace(); + } + } + + private static void copyFile(File file, Path targetPath) { + try { + if (file.isDirectory()) { + if (!Paths.get(targetPath + "" + File.separatorChar + file.getName()).toFile().exists()) + Files.createDirectory(Paths.get(targetPath + "" + File.separatorChar + file.getName())); + for (File iteratedFile : file.listFiles()) + copyFile(iteratedFile, Paths.get(targetPath + "" + File.separatorChar + file.getName())); + } else { + if (!Paths.get(targetPath + "" + File.separatorChar + file.getName()).toFile().exists() || + !targetPath.toString().contains("pack.png") && !targetPath.toString().contains("pack.mcmeta")) + Files.copy(file.toPath(), Paths.get(targetPath + "" + File.separatorChar + file.getName()), StandardCopyOption.REPLACE_EXISTING); + else + new InfoMessage("File " + targetPath + "" + File.separatorChar + file.getName() + " already existed and should not be overwritten, skipping!"); + } + } catch (Exception exception) { + new WarningMessage("Failed to copy directories for " + file.getName() + "! Tell the dev!"); + exception.printStackTrace(); + } + } + + public static void overwriteSHA1(CommandSender commandSender) { + File serverProperties = null; + try { + serverProperties = new File(Paths.get(MetadataHandler.PLUGIN.getDataFolder().getParentFile().getCanonicalFile().getParentFile().toString() + File.separatorChar + "server.properties").toString()); + if (!serverProperties.exists()) { + commandSender.sendMessage("[EliteMobs] Could not find server.properties file correctly! You will have to set the SHA-1 value manually!"); + return; + } + } catch (Exception exception) { + new WarningMessage("[EliteMobs] Could not find server.properties file correctly! You will have to set the SHA-1 value manually."); + exception.printStackTrace(); + return; + } + + String sha1 = generateResourcePackSHA1(commandSender); + if (sha1 == null) return; + try { + FileInputStream in = new FileInputStream(serverProperties); + Properties props = new Properties(); + props.load(in); + in.close(); + + FileOutputStream out = new FileOutputStream(serverProperties); + props.setProperty("resource-pack-sha1", sha1); + props.store(out, null); + out.close(); + } catch (Exception ex) { + commandSender.sendMessage("[EliteMobs] Failed to save SHA1 value " + sha1 + " ! You will have to do this manually."); + } + commandSender.sendMessage(ChatColor.GREEN + "[EliteMobs] Successfully set the value resource-pack-sha1=" + sha1 + " in server.properties!"); + commandSender.sendMessage(ChatColor.RED + "[EliteMobs] Don't forget to update the downloadable resource pack at your online location of choice!" + + " If you don't update the version people download things won't work correctly!"); + commandSender.sendMessage(ChatColor.GREEN + "[EliteMobs] The server.properties modification will work starting with the next restart!"); + + } +} diff --git a/src/main/java/com/magmaguy/elitemobs/config/configurationimporter/ConfigurationImporter.java b/src/main/java/com/magmaguy/elitemobs/config/ConfigurationImporter.java similarity index 90% rename from src/main/java/com/magmaguy/elitemobs/config/configurationimporter/ConfigurationImporter.java rename to src/main/java/com/magmaguy/elitemobs/config/ConfigurationImporter.java index 01015942e..ea240d604 100644 --- a/src/main/java/com/magmaguy/elitemobs/config/configurationimporter/ConfigurationImporter.java +++ b/src/main/java/com/magmaguy/elitemobs/config/ConfigurationImporter.java @@ -1,12 +1,15 @@ -package com.magmaguy.elitemobs.config.configurationimporter; +package com.magmaguy.elitemobs.config; +import com.magmaguy.elitemobs.ChatColorConverter; import com.magmaguy.elitemobs.MetadataHandler; import com.magmaguy.elitemobs.thirdparty.modelengine.CustomModel; import com.magmaguy.elitemobs.utils.InfoMessage; -import com.magmaguy.elitemobs.utils.UnzipFile; +import com.magmaguy.elitemobs.utils.SpigotMessage; import com.magmaguy.elitemobs.utils.WarningMessage; +import com.magmaguy.elitemobs.utils.ZipFile; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import java.io.File; import java.nio.file.Files; @@ -15,6 +18,8 @@ import java.nio.file.StandardCopyOption; public class ConfigurationImporter { + private ConfigurationImporter() { + } public static void initializeConfigs() { Path configurationsPath = Paths.get(MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath()); @@ -44,7 +49,7 @@ public static void initializeConfigs() { File unzippedFile; try { if (zippedFile.getName().contains(".zip")) - unzippedFile = UnzipFile.run(zippedFile.getName()); + unzippedFile = ZipFile.unzip(zippedFile.getName()); else unzippedFile = zippedFile; } catch (Exception e) { new WarningMessage("Failed to unzip config file " + zippedFile.getName() + " ! Tell the dev!"); @@ -115,6 +120,13 @@ public static void initializeConfigs() { if (importedModels) { CustomModel.reloadModels(); + for (Player player : Bukkit.getOnlinePlayers()) + if (player.hasPermission("elitemobs.*")) + player.spigot().sendMessage(SpigotMessage.commandHoverMessage( + ChatColorConverter.convert("&8[EliteMobs] &fEliteMobs just detected that recently imported files had Custom Models in them! " + + "&2Click here to generate the EliteMobs resource pack for those models!"), + "Clicking will run the command /em generateresourcepack", + "/em generateresourcepack")); } } diff --git a/src/main/java/com/magmaguy/elitemobs/config/menus/premade/PlayerStatusMenuConfig.java b/src/main/java/com/magmaguy/elitemobs/config/menus/premade/PlayerStatusMenuConfig.java index 1c4271f8a..40ed7c4c5 100644 --- a/src/main/java/com/magmaguy/elitemobs/config/menus/premade/PlayerStatusMenuConfig.java +++ b/src/main/java/com/magmaguy/elitemobs/config/menus/premade/PlayerStatusMenuConfig.java @@ -4,18 +4,73 @@ import com.magmaguy.elitemobs.config.ConfigurationEngine; import com.magmaguy.elitemobs.config.menus.MenusConfigFields; import com.magmaguy.elitemobs.playerdata.statusscreen.PlayerStatusScreen; +import lombok.Getter; import org.bukkit.configuration.file.FileConfiguration; public class PlayerStatusMenuConfig extends MenusConfigFields { - public static boolean doIndexPage, doStatsPage, doGearPage, doTeleportsPage, doCommandsPage, doQuestTrackingPage, doBossTrackingPage; - public static String[] indexTextLines = new String[13], indexHoverLines = new String[13], indexCommandLines = new String[13]; - public static String[] statsTextLines = new String[13], statsHoverLines = new String[13], statsCommandLines = new String[13]; - public static String[] gearTextLines = new String[13], gearHoverLines = new String[13], gearCommandLines = new String[13]; - public static String[] teleportTextLines = new String[13], teleportHoverLines = new String[13], teleportCommandLines = new String[13]; - public static String[] commandsTextLines = new String[13], commandsHoverLines = new String[13], commandsCommandLines = new String[13]; - public static String[] bossTrackerTextLines = new String[13], bossTrackerHoverLines = new String[13], bossTrackerCommandLines = new String[13]; - public static String[] questTrackerTextLines = new String[13], questTrackerHoverLines = new String[13], questTrackerCommandLines = new String[13]; - public static String onBossTrackHover, onQuestTrackHover, onTeleportHover; + @Getter + private static boolean doIndexPage; + @Getter + private static boolean doStatsPage; + @Getter + private static boolean doGearPage; + @Getter + private static boolean doTeleportsPage; + @Getter + private static boolean doCommandsPage; + @Getter + private static boolean doQuestTrackingPage; + @Getter + private static boolean doBossTrackingPage; + @Getter + private static String[] indexTextLines = new String[13]; + @Getter + private static String[] indexHoverLines = new String[13]; + @Getter + private static String[] indexCommandLines = new String[13]; + @Getter + private static String[] statsTextLines = new String[13]; + @Getter + private static String[] statsHoverLines = new String[13]; + @Getter + private static String[] statsCommandLines = new String[13]; + @Getter + private static String[] gearTextLines = new String[13]; + @Getter + private static String[] gearHoverLines = new String[13]; + @Getter + private static String[] gearCommandLines = new String[13]; + @Getter + private static String[] teleportTextLines = new String[13]; + @Getter + private static String[] teleportHoverLines = new String[13]; + @Getter + private static String[] teleportCommandLines = new String[13]; + @Getter + private static String[] commandsTextLines = new String[13]; + @Getter + private static String[] commandsHoverLines = new String[13]; + @Getter + private static String[] commandsCommandLines = new String[13]; + @Getter + private static String[] bossTrackerTextLines = new String[13]; + @Getter + private static String[] bossTrackerHoverLines = new String[13]; + @Getter + private static String[] bossTrackerCommandLines = new String[13]; + @Getter + private static String[] questTrackerTextLines = new String[13]; + @Getter + private static String[] questTrackerHoverLines = new String[13]; + @Getter + private static String[] questTrackerCommandLines = new String[13]; + @Getter + private static String onBossTrackHover; + @Getter + private static String onQuestTrackHover; + @Getter + private static String onTeleportHover; + public PlayerStatusMenuConfig() { super("player_status_screen", true); } diff --git a/src/main/java/com/magmaguy/elitemobs/events/ActionEvent.java b/src/main/java/com/magmaguy/elitemobs/events/ActionEvent.java index 27d206ee1..8581e54cd 100644 --- a/src/main/java/com/magmaguy/elitemobs/events/ActionEvent.java +++ b/src/main/java/com/magmaguy/elitemobs/events/ActionEvent.java @@ -30,6 +30,10 @@ public class ActionEvent extends CustomEvent { private static final List blueprintEvents = new ArrayList<>(); private static final HashSet playerCooldowns = new HashSet<>(); + public static void shutdown() { + blueprintEvents.clear(); + playerCooldowns.clear(); + } private final double chance; private final List breakableMaterials; private Player player; diff --git a/src/main/java/com/magmaguy/elitemobs/events/TimedEvent.java b/src/main/java/com/magmaguy/elitemobs/events/TimedEvent.java index d4aa19bea..e86e84af8 100644 --- a/src/main/java/com/magmaguy/elitemobs/events/TimedEvent.java +++ b/src/main/java/com/magmaguy/elitemobs/events/TimedEvent.java @@ -23,6 +23,10 @@ public class TimedEvent extends CustomEvent implements Listener { @Getter protected static List blueprintEvents = new ArrayList<>(); protected static List timedEvents = new ArrayList<>(); + public static void shutdown() { + blueprintEvents.clear(); + timedEvents.clear(); + } //stores the time of the last global trigger private static double nextEventTrigger = System.currentTimeMillis() + 5D * 60D * 1000D; private final double localCooldown; diff --git a/src/main/java/com/magmaguy/elitemobs/mobconstructor/custombosses/BossTrace.java b/src/main/java/com/magmaguy/elitemobs/mobconstructor/custombosses/BossTrace.java index f24e0b3c1..ad80fbafa 100644 --- a/src/main/java/com/magmaguy/elitemobs/mobconstructor/custombosses/BossTrace.java +++ b/src/main/java/com/magmaguy/elitemobs/mobconstructor/custombosses/BossTrace.java @@ -46,10 +46,6 @@ private String getPrefix() { return "[" + (ServerTime.getTime() - creationTicksStamp) + "t] "; } - private long getTime() { - return System.currentTimeMillis() - creationTimeStamp; - } - public void postLog(Player player) { if (!DebugMessage.isDebugMode()) player.sendMessage(ChatColor.RED + "[EliteMobs] Debug mode must be on for this to work! Do " + ChatColor.GREEN + "/em debugmode"); diff --git a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/BossTrackingPage.java b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/BossTrackingPage.java index 210ab5784..7c81379a4 100644 --- a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/BossTrackingPage.java +++ b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/BossTrackingPage.java @@ -2,10 +2,9 @@ import com.magmaguy.elitemobs.config.menus.premade.PlayerStatusMenuConfig; import com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity; +import com.magmaguy.elitemobs.utils.SpigotMessage; import com.magmaguy.elitemobs.utils.WarningMessage; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; @@ -21,13 +20,13 @@ protected static TextComponent[] bossTrackingPage(Player player) { for (int i = 0; i < 3; i++) { - TextComponent line = new TextComponent(PlayerStatusMenuConfig.bossTrackerTextLines[i] + "\n"); + TextComponent line = new TextComponent(PlayerStatusMenuConfig.getBossTrackerTextLines()[i] + "\n"); - if (!PlayerStatusMenuConfig.bossTrackerHoverLines[i].isEmpty()) - PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.bossTrackerHoverLines[i]); + if (!PlayerStatusMenuConfig.getBossTrackerHoverLines()[i].isEmpty()) + PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.getBossTrackerHoverLines()[i]); - if (!PlayerStatusMenuConfig.bossTrackerCommandLines[i].isEmpty()) - line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.bossTrackerCommandLines[i])); + if (!PlayerStatusMenuConfig.getBossTrackerCommandLines()[i].isEmpty()) + line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.getBossTrackerCommandLines()[i])); configTextComponent.addExtra(line); } @@ -37,10 +36,10 @@ protected static TextComponent[] bossTrackingPage(Player player) { for (CustomBossEntity customBossEntity : CustomBossEntity.getTrackableCustomBosses()) { try { - TextComponent message = new TextComponent(customBossEntity.getCustomBossBossBar().bossBarMessage(player, customBossEntity.getCustomBossesConfigFields().getLocationMessage()) + "\n"); - message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(PlayerStatusMenuConfig.onBossTrackHover).create())); - message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/elitemobs trackcustomboss " + customBossEntity.getEliteUUID())); - textComponents.add(message); + textComponents.add( SpigotMessage.commandHoverMessage( + customBossEntity.getCustomBossBossBar().bossBarMessage(player, customBossEntity.getCustomBossesConfigFields().getLocationMessage()) + "\n", + PlayerStatusMenuConfig.getOnBossTrackHover(), + "/elitemobs trackcustomboss " + customBossEntity.getEliteUUID())); counter++; } catch (Exception ex) { diff --git a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/CommandsPage.java b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/CommandsPage.java index 71ac9a78d..4d012c89b 100644 --- a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/CommandsPage.java +++ b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/CommandsPage.java @@ -15,13 +15,13 @@ protected static TextComponent commandsPage() { for (int i = 0; i < 13; i++) { - TextComponent line = new TextComponent(PlayerStatusMenuConfig.commandsTextLines[i] + "\n"); + TextComponent line = new TextComponent(PlayerStatusMenuConfig.getCommandsTextLines()[i] + "\n"); - if (!PlayerStatusMenuConfig.commandsHoverLines[i].isEmpty()) - PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.commandsHoverLines[i]); + if (!PlayerStatusMenuConfig.getCommandsHoverLines()[i].isEmpty()) + PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.getCommandsHoverLines()[i]); - if (!PlayerStatusMenuConfig.commandsCommandLines[i].isEmpty()) - line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.commandsCommandLines[i])); + if (!PlayerStatusMenuConfig.getCommandsCommandLines()[i].isEmpty()) + line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.getCommandsCommandLines()[i])); textComponent.addExtra(line); } diff --git a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/CoverPage.java b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/CoverPage.java index 5dea8ae7e..69e97c693 100644 --- a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/CoverPage.java +++ b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/CoverPage.java @@ -11,7 +11,7 @@ protected static TextComponent coverPage(int statsPage, int gearPage, int telepo for (int i = 0; i < 13; i++) { TextComponent line = new TextComponent( - PlayerStatusMenuConfig.indexTextLines[i] + PlayerStatusMenuConfig.getIndexTextLines()[i] .replace("$statsPage", statsPage + "") .replace("$gearPage", gearPage + "") .replace("$teleportsPage", teleportsPage + "") @@ -20,24 +20,24 @@ protected static TextComponent coverPage(int statsPage, int gearPage, int telepo .replace("$bossTrackingPage", bossTrackingPage + "") + "\n"); - if (!PlayerStatusMenuConfig.indexHoverLines[i].isEmpty()) - PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.indexHoverLines[i]); - - if (PlayerStatusMenuConfig.indexCommandLines[i].contains("$statsPage")) - line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.indexCommandLines[i].replace("$statsPage", statsPage + ""))); - else if (PlayerStatusMenuConfig.indexCommandLines[i].contains("$gearPage")) - line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.indexCommandLines[i].replace("$gearPage", gearPage + ""))); - else if (PlayerStatusMenuConfig.indexCommandLines[i].contains("$teleportsPage")) - line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.indexCommandLines[i].replace("$teleportsPage", teleportsPage + ""))); - else if (PlayerStatusMenuConfig.indexCommandLines[i].contains("$commandsPage")) - line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.indexCommandLines[i].replace("$commandsPage", commandsPage + ""))); - else if (PlayerStatusMenuConfig.indexCommandLines[i].contains("$questsPage")) - line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.indexCommandLines[i].replace("$questsPage", questsPage + ""))); - else if (PlayerStatusMenuConfig.indexCommandLines[i].contains("$bossTrackingPage")) - line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.indexCommandLines[i].replace("$bossTrackingPage", bossTrackingPage + ""))); + if (!PlayerStatusMenuConfig.getIndexHoverLines()[i].isEmpty()) + PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.getIndexHoverLines()[i]); + + if (PlayerStatusMenuConfig.getIndexCommandLines()[i].contains("$statsPage")) + line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.getIndexCommandLines()[i].replace("$statsPage", statsPage + ""))); + else if (PlayerStatusMenuConfig.getIndexCommandLines()[i].contains("$gearPage")) + line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.getIndexCommandLines()[i].replace("$gearPage", gearPage + ""))); + else if (PlayerStatusMenuConfig.getIndexCommandLines()[i].contains("$teleportsPage")) + line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.getIndexCommandLines()[i].replace("$teleportsPage", teleportsPage + ""))); + else if (PlayerStatusMenuConfig.getIndexCommandLines()[i].contains("$commandsPage")) + line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.getIndexCommandLines()[i].replace("$commandsPage", commandsPage + ""))); + else if (PlayerStatusMenuConfig.getIndexCommandLines()[i].contains("$questsPage")) + line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.getIndexCommandLines()[i].replace("$questsPage", questsPage + ""))); + else if (PlayerStatusMenuConfig.getIndexCommandLines()[i].contains("$bossTrackingPage")) + line.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, PlayerStatusMenuConfig.getIndexCommandLines()[i].replace("$bossTrackingPage", bossTrackingPage + ""))); else - line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.indexCommandLines[i])); + line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.getIndexCommandLines()[i])); textComponent.addExtra(line); } diff --git a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/GearPage.java b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/GearPage.java index 8511f4555..48391fd5b 100644 --- a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/GearPage.java +++ b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/GearPage.java @@ -18,18 +18,18 @@ protected static TextComponent gearPage(Player targetPlayer) { TextComponent line; - if (!PlayerStatusMenuConfig.gearTextLines[i].contains("{")) { - line = new TextComponent(parseGearPlaceholders(PlayerStatusMenuConfig.gearTextLines[i], targetPlayer) + "\n"); + if (!PlayerStatusMenuConfig.getGearTextLines()[i].contains("{")) { + line = new TextComponent(parseGearPlaceholders(PlayerStatusMenuConfig.getGearTextLines()[i], targetPlayer) + "\n"); gearMultiComponentLine(textComponent, line, i, targetPlayer, false, 0); } else { - TextComponent prePlaceholderElements = new TextComponent(parseGearPlaceholders(PlayerStatusMenuConfig.gearTextLines[i].split("\\{")[0], targetPlayer)); + TextComponent prePlaceholderElements = new TextComponent(parseGearPlaceholders(PlayerStatusMenuConfig.getGearTextLines()[i].split("\\{")[0], targetPlayer)); gearMultiComponentLine(textComponent, prePlaceholderElements, i, targetPlayer, false, 0); - for (int j = 0; j < PlayerStatusMenuConfig.gearTextLines[i].split("\\{").length; j++) { - TextComponent placeholderString = new TextComponent(parseGearPlaceholders(PlayerStatusMenuConfig.gearTextLines[i].split("\\{")[j].split("}")[0], targetPlayer)); + for (int j = 0; j < PlayerStatusMenuConfig.getGearTextLines()[i].split("\\{").length; j++) { + TextComponent placeholderString = new TextComponent(parseGearPlaceholders(PlayerStatusMenuConfig.getGearTextLines()[i].split("\\{")[j].split("}")[0], targetPlayer)); gearMultiComponentLine(textComponent, placeholderString, i, targetPlayer, true, j); - if (PlayerStatusMenuConfig.gearTextLines[i].split("}").length > j - && PlayerStatusMenuConfig.gearTextLines[i].split("}")[j].contains("{")) { - TextComponent spaceBetweenPlaceholders = new TextComponent(parseGearPlaceholders(PlayerStatusMenuConfig.gearTextLines[i].split("}")[j].split("\\{")[0], targetPlayer)); + if (PlayerStatusMenuConfig.getGearTextLines()[i].split("}").length > j + && PlayerStatusMenuConfig.getGearTextLines()[i].split("}")[j].contains("{")) { + TextComponent spaceBetweenPlaceholders = new TextComponent(parseGearPlaceholders(PlayerStatusMenuConfig.getGearTextLines()[i].split("}")[j].split("\\{")[0], targetPlayer)); gearMultiComponentLine(textComponent, spaceBetweenPlaceholders, i, targetPlayer, false, 0); } } @@ -98,8 +98,8 @@ private static String parseGearPlaceholders(String string, Player targetPlayer) private static void gearMultiComponentLine(TextComponent textComponent, TextComponent line, int i, Player targetPlayer, boolean brackets, int bracketCount) { - if (!PlayerStatusMenuConfig.gearHoverLines[i].isEmpty()) { - String hoverLines = PlayerStatusMenuConfig.gearHoverLines[i]; + if (!PlayerStatusMenuConfig.getGearHoverLines()[i].isEmpty()) { + String hoverLines = PlayerStatusMenuConfig.getGearHoverLines()[i]; if (hoverLines.contains("$helmet")) ShareItem.setItemHoverEvent(line, targetPlayer.getInventory().getHelmet()); else if (hoverLines.contains("$chestplate")) @@ -121,7 +121,7 @@ else if (brackets) { PlayerStatusScreen.setHoverText(line, parsedLine); } } else if (!(hoverLines.contains("{") && hoverLines.contains("}"))) - PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.gearHoverLines[i]); + PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.getGearHoverLines()[i]); } diff --git a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/PlayerStatusScreen.java b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/PlayerStatusScreen.java index 5dfe325d3..cac861d46 100644 --- a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/PlayerStatusScreen.java +++ b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/PlayerStatusScreen.java @@ -58,29 +58,29 @@ private ItemStack generateBook(Player requestingPlayer, Player targetPlayer) { int commandsPage = -1; int questsPage = -1; int bossTrackingPage = -1; - if (PlayerStatusMenuConfig.doStatsPage) { + if (PlayerStatusMenuConfig.isDoStatsPage()) { statsPage = pageCounter; pages[pageCounter] = StatsPage.statsPage(targetPlayer); pageCounter++; } - if (PlayerStatusMenuConfig.doGearPage) { + if (PlayerStatusMenuConfig.isDoGearPage()) { gearPage = pageCounter; pages[pageCounter] = GearPage.gearPage(targetPlayer); pageCounter++; } - if (PlayerStatusMenuConfig.doTeleportsPage) { + if (PlayerStatusMenuConfig.isDoTeleportsPage()) { teleportsPage = pageCounter; for (TextComponent textComponent : TeleportsPage.teleportsPage()) { pages[pageCounter] = textComponent; pageCounter++; } } - if (PlayerStatusMenuConfig.doCommandsPage) { + if (PlayerStatusMenuConfig.isDoCommandsPage()) { commandsPage = pageCounter; pages[pageCounter] = CommandsPage.commandsPage(); pageCounter++; } - if (PlayerStatusMenuConfig.doQuestTrackingPage) { + if (PlayerStatusMenuConfig.isDoQuestTrackingPage()) { questsPage = pageCounter; for (TextComponent textComponent : QuestsPage.questsPage(targetPlayer)) { pages[pageCounter] = textComponent; @@ -88,7 +88,7 @@ private ItemStack generateBook(Player requestingPlayer, Player targetPlayer) { } } - if (PlayerStatusMenuConfig.doBossTrackingPage) { + if (PlayerStatusMenuConfig.isDoBossTrackingPage()) { bossTrackingPage = pageCounter; for (TextComponent textComponent : BossTrackingPage.bossTrackingPage(targetPlayer)) { pages[pageCounter] = textComponent; diff --git a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/StatsPage.java b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/StatsPage.java index 6e8235d27..81bd79692 100644 --- a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/StatsPage.java +++ b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/StatsPage.java @@ -18,7 +18,7 @@ protected static TextComponent statsPage(Player targetPlayer) { TextComponent textComponent = new TextComponent(); for (int i = 0; i < 13; i++) { - TextComponent line = new TextComponent(PlayerStatusMenuConfig.statsTextLines[i] + TextComponent line = new TextComponent(PlayerStatusMenuConfig.getStatsTextLines()[i] .replace("$money", EconomyHandler.checkCurrency(targetPlayer.getUniqueId()) + "") .replace("$guildtier", PlayerStatusScreen.convertLightColorsToBlack(AdventurersGuildConfig.getShortenedRankName(GuildRank.getGuildPrestigeRank(targetPlayer), GuildRank.getActiveGuildRank(targetPlayer)))) .replace("$kills", PlayerData.getKills(targetPlayer.getUniqueId()) + "") @@ -27,11 +27,11 @@ protected static TextComponent statsPage(Player targetPlayer) { .replace("$quests", PlayerData.getQuestsCompleted(targetPlayer.getUniqueId()) + "") .replace("$score", PlayerData.getScore(targetPlayer.getUniqueId()) + "") + "\n"); - if (!PlayerStatusMenuConfig.statsHoverLines[i].isEmpty()) - PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.statsHoverLines[i]); + if (!PlayerStatusMenuConfig.getStatsHoverLines()[i].isEmpty()) + PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.getStatsHoverLines()[i]); - if (!PlayerStatusMenuConfig.statsCommandLines[i].isEmpty()) - line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.statsCommandLines[i])); + if (!PlayerStatusMenuConfig.getStatsCommandLines()[i].isEmpty()) + line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.getStatsCommandLines()[i])); textComponent.addExtra(line); } diff --git a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/TeleportsPage.java b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/TeleportsPage.java index 25288e787..2ad2db20a 100644 --- a/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/TeleportsPage.java +++ b/src/main/java/com/magmaguy/elitemobs/playerdata/statusscreen/TeleportsPage.java @@ -17,15 +17,15 @@ protected static TextComponent[] teleportsPage() { TextComponent configTextComponent = new TextComponent(); //Fills the non-dungeon lines int textLineCounter = 0; - for (String string : PlayerStatusMenuConfig.teleportTextLines) { + for (String string : PlayerStatusMenuConfig.getTeleportTextLines()) { if (string == null || string.equals("null")) continue; TextComponent line = new TextComponent(string + "\n"); - if (PlayerStatusMenuConfig.teleportHoverLines[textLineCounter] != null && !PlayerStatusMenuConfig.teleportHoverLines[textLineCounter].isEmpty()) - PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.teleportHoverLines[textLineCounter]); + if (PlayerStatusMenuConfig.getTeleportHoverLines()[textLineCounter] != null && !PlayerStatusMenuConfig.getTeleportHoverLines()[textLineCounter].isEmpty()) + PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.getTeleportHoverLines()[textLineCounter]); - if (PlayerStatusMenuConfig.teleportCommandLines[textLineCounter] != null && !PlayerStatusMenuConfig.teleportCommandLines[textLineCounter].isEmpty()) - line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.teleportCommandLines[textLineCounter])); + if (PlayerStatusMenuConfig.getTeleportCommandLines()[textLineCounter] != null && !PlayerStatusMenuConfig.getTeleportCommandLines()[textLineCounter].isEmpty()) + line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.getTeleportCommandLines()[textLineCounter])); configTextComponent.addExtra(line); textLineCounter++; @@ -39,7 +39,7 @@ protected static TextComponent[] teleportsPage() { if (!minidungeon.isInstalled()) continue; TextComponent message = new TextComponent(PlayerStatusScreen.convertLightColorsToBlack(minidungeon.getDungeonPackagerConfigFields().getName() + "\n")); - String hoverMessage = ChatColorConverter.convert(PlayerStatusMenuConfig.onTeleportHover + "\n" + + String hoverMessage = ChatColorConverter.convert(PlayerStatusMenuConfig.getOnTeleportHover() + "\n" + minidungeon.getDungeonPackagerConfigFields().getPlayerInfo() .replace("$bossCount", minidungeon.getRegionalBossCount() + "") .replace("$lowestTier", minidungeon.getLowestTier() + "") diff --git a/src/main/java/com/magmaguy/elitemobs/powers/defensivepowers/InvulnerabilityKnockback.java b/src/main/java/com/magmaguy/elitemobs/powers/defensivepowers/InvulnerabilityKnockback.java index c48bba834..6f5b234c7 100644 --- a/src/main/java/com/magmaguy/elitemobs/powers/defensivepowers/InvulnerabilityKnockback.java +++ b/src/main/java/com/magmaguy/elitemobs/powers/defensivepowers/InvulnerabilityKnockback.java @@ -21,10 +21,12 @@ public InvulnerabilityKnockback() { @EventHandler public void invulnerabilityKnockback(EliteMobDamagedEvent event) { if (!event.getEliteMobEntity().hasPower(this)) return; + if (!event.getEliteMobEntity().isValid()) return; event.getEntity().setVelocity(new Vector(0, 0, 0)); new BukkitRunnable() { @Override public void run() { + if (!event.getEliteMobEntity().isValid()) return; event.getEntity().setVelocity(new Vector(0, 0, 0)); } }.runTaskLater(MetadataHandler.PLUGIN, 1); diff --git a/src/main/java/com/magmaguy/elitemobs/quests/playercooldowns/PlayerQuestCooldowns.java b/src/main/java/com/magmaguy/elitemobs/quests/playercooldowns/PlayerQuestCooldowns.java index 0c51ddcda..b06be385c 100644 --- a/src/main/java/com/magmaguy/elitemobs/quests/playercooldowns/PlayerQuestCooldowns.java +++ b/src/main/java/com/magmaguy/elitemobs/quests/playercooldowns/PlayerQuestCooldowns.java @@ -38,6 +38,8 @@ public static void addCooldown(Player player, String permission, int delayInMinu } public static void flushPlayer(Player player) { + PlayerQuestCooldowns playerQuestCooldowns = PlayerData.getPlayerQuestCooldowns(player.getUniqueId()); + if (playerQuestCooldowns == null) return; for (QuestCooldown questCooldown : Objects.requireNonNull(PlayerData.getPlayerQuestCooldowns(player.getUniqueId())).questCooldowns) if (questCooldown.getBukkitTask() != null) questCooldown.getBukkitTask().cancel(); diff --git a/src/main/java/com/magmaguy/elitemobs/utils/UnzipFile.java b/src/main/java/com/magmaguy/elitemobs/utils/UnzipFile.java deleted file mode 100644 index 97afddcc2..000000000 --- a/src/main/java/com/magmaguy/elitemobs/utils/UnzipFile.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.magmaguy.elitemobs.utils; - -import com.magmaguy.elitemobs.MetadataHandler; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class UnzipFile { - public static File run(String zippedFileName) throws IOException { - String mainDirectory = MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath() + "/imports/"; - String fileZip = mainDirectory + zippedFileName; - File finalDirectory = new File(mainDirectory + zippedFileName.replace(".zip", "")); - byte[] buffer = new byte[1024]; - ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(fileZip)); - ZipEntry zipEntry = zipInputStream.getNextEntry(); - while (zipEntry != null) { - File newFile = newFile(finalDirectory, zipEntry); - if (zipEntry.isDirectory()) { - if (!newFile.isDirectory() && !newFile.mkdirs()) { - throw new IOException("Failed to create directory " + newFile); - } - } else { - // fix for Windows-created archives - File parent = newFile.getParentFile(); - if (!parent.isDirectory() && !parent.mkdirs()) { - throw new IOException("Failed to create directory " + parent); - } - - // write file content - FileOutputStream fileOutputStream = new FileOutputStream(newFile); - int len; - while ((len = zipInputStream.read(buffer)) > 0) { - fileOutputStream.write(buffer, 0, len); - } - fileOutputStream.close(); - } - zipEntry = zipInputStream.getNextEntry(); - } - zipInputStream.closeEntry(); - zipInputStream.close(); - return finalDirectory; - } - - private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { - File destFile = new File(destinationDir, zipEntry.getName()); - - String destDirPath = destinationDir.getCanonicalPath(); - String destFilePath = destFile.getCanonicalPath(); - - if (!destFilePath.startsWith(destDirPath + File.separatorChar)) { - throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); - } - - return destFile; - } -} diff --git a/src/main/java/com/magmaguy/elitemobs/utils/ZipFile.java b/src/main/java/com/magmaguy/elitemobs/utils/ZipFile.java new file mode 100644 index 000000000..d90dff8d7 --- /dev/null +++ b/src/main/java/com/magmaguy/elitemobs/utils/ZipFile.java @@ -0,0 +1,161 @@ +package com.magmaguy.elitemobs.utils; + +import com.magmaguy.elitemobs.MetadataHandler; + +import java.io.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +public class ZipFile { + private ZipFile() { + } + + public static boolean zip(File directory, String targetZipPath) { + if (!directory.exists()) { + new WarningMessage("Failed to zip directory " + directory.getPath() + " because it does not exist!"); + return false; + } + + try { + ZipUtility.zip(directory, targetZipPath); + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + + public static File unzip(String zippedFileName) throws IOException { + String mainDirectory = MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath() + "/imports/"; + String fileZip = mainDirectory + zippedFileName; + File finalDirectory = new File(mainDirectory + zippedFileName.replace(".zip", "")); + byte[] buffer = new byte[1024]; + ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(fileZip)); + ZipEntry zipEntry = zipInputStream.getNextEntry(); + while (zipEntry != null) { + File newFile = newFile(finalDirectory, zipEntry); + if (zipEntry.isDirectory()) { + if (!newFile.isDirectory() && !newFile.mkdirs()) { + throw new IOException("Failed to create directory " + newFile); + } + } else { + // fix for Windows-created archives + File parent = newFile.getParentFile(); + if (!parent.isDirectory() && !parent.mkdirs()) { + throw new IOException("Failed to create directory " + parent); + } + + // write file content + FileOutputStream fileOutputStream = new FileOutputStream(newFile); + int len; + while ((len = zipInputStream.read(buffer)) > 0) { + fileOutputStream.write(buffer, 0, len); + } + fileOutputStream.close(); + } + zipEntry = zipInputStream.getNextEntry(); + } + zipInputStream.closeEntry(); + zipInputStream.close(); + return finalDirectory; + } + + public static class ZipUtility { + /** + * A constants for buffer size used to read/write data + */ + private static final int BUFFER_SIZE = 4096; + + /** + * Compresses a list of files to a destination zip file + * + * @param file File to zip + * @param destZipFile The path of the destination zip file + * @throws FileNotFoundException + * @throws IOException + */ + public static void zip(File file, String destZipFile) throws FileNotFoundException, IOException { + ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile)); + //This slight tweak avoids making the directory zipped be in the zipped file when what we are looking for is to + //zip the contents of the directory, outside of the directory itself + if (file.isDirectory()) { + for (File file1 : file.listFiles()){ + if (file1.isDirectory()) + zipDirectory(file1, file1.getName(), zos); + else + zipFile(file1, zos); + } + } else { + zipFile(file, zos); + } + zos.flush(); + zos.close(); + } + + /** + * Adds a directory to the current zip output stream + * + * @param folder the directory to be added + * @param parentFolder the path of parent directory + * @param zos the current zip output stream + * @throws FileNotFoundException + * @throws IOException + */ + private static void zipDirectory(File folder, String parentFolder, + ZipOutputStream zos) throws FileNotFoundException, IOException { + for (File file : folder.listFiles()) { + if (file.isDirectory()) { + zipDirectory(file, parentFolder + "/" + file.getName(), zos); + continue; + } + zos.putNextEntry(new ZipEntry(parentFolder + "/" + file.getName())); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); + long bytesRead = 0; + byte[] bytesIn = new byte[BUFFER_SIZE]; + int read = 0; + while ((read = bis.read(bytesIn)) != -1) { + zos.write(bytesIn, 0, read); + bytesRead += read; + } + zos.closeEntry(); + } + } + + /** + * Adds a file to the current zip output stream + * + * @param file the file to be added + * @param zos the current zip output stream + * @throws FileNotFoundException + * @throws IOException + */ + private static void zipFile(File file, ZipOutputStream zos) + throws FileNotFoundException, IOException { + zos.putNextEntry(new ZipEntry(file.getName())); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream( + file)); + long bytesRead = 0; + byte[] bytesIn = new byte[BUFFER_SIZE]; + int read = 0; + while ((read = bis.read(bytesIn)) != -1) { + zos.write(bytesIn, 0, read); + bytesRead += read; + } + zos.closeEntry(); + } + } + + private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { + File destFile = new File(destinationDir, zipEntry.getName()); + + String destDirPath = destinationDir.getCanonicalPath(); + String destFilePath = destFile.getCanonicalPath(); + + if (!destFilePath.startsWith(destDirPath + File.separatorChar)) { + throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); + } + + return destFile; + } +}