From 5a9efad6dfb4162167a0a7af64e677eef0a12188 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Tue, 29 Mar 2022 23:46:57 -0500 Subject: [PATCH] v3.4.0 b623 * chunk kill count tweaks * invalid rules.yml message change * rules.yml changes * added command /lm debug chunk_kill_count reset --- .../me/lokka30/levelledmobs/Companion.java | 9 +++- .../commands/LevelledMobsCommand.java | 2 + .../commands/subcommands/DebugSubcommand.java | 42 ++++++++++++++++--- .../commands/subcommands/RulesSubcommand.java | 21 +++++----- .../listeners/EntityDeathListener.java | 4 +- .../levelledmobs/misc/FileMigrator.java | 8 ++++ src/main/resources/messages.yml | 4 +- 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/main/java/me/lokka30/levelledmobs/Companion.java b/src/main/java/me/lokka30/levelledmobs/Companion.java index cc68ddbc5..3cbb62b9d 100644 --- a/src/main/java/me/lokka30/levelledmobs/Companion.java +++ b/src/main/java/me/lokka30/levelledmobs/Companion.java @@ -446,8 +446,13 @@ public void addUserCooldown(final @NotNull List chunkKeys, final @NotNull } } - public @NotNull HashMap> getEntityDeathInChunkCounter(){ - return this.entityDeathInChunkCounter; + public void clearChunkKillCache(){ + synchronized (entityDeathInChunkCounter_Lock){ + this.entityDeathInChunkCounter.clear(); + } + synchronized (entityDeathInChunkNotifier_Lock){ + this.chunkKillNoticationTracker.clear(); + } } //Check for updates on the Spigot page. diff --git a/src/main/java/me/lokka30/levelledmobs/commands/LevelledMobsCommand.java b/src/main/java/me/lokka30/levelledmobs/commands/LevelledMobsCommand.java index 153c5eacc..d097fe7f2 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/LevelledMobsCommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/LevelledMobsCommand.java @@ -141,6 +141,8 @@ public List onTabComplete(final @NotNull CommandSender sender, final @No return summonSubcommand.parseTabCompletions(main, sender, args); case "egg": return spawnerEggCommand.parseTabCompletions(main, sender, args); + case "debug": + return debugSubcommand.parseTabCompletions(main, sender, args); // the missing subcommands don't have tab completions, don't bother including them. default: return Collections.emptyList(); diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/DebugSubcommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/DebugSubcommand.java index 4b3ce14ce..b6f5e7a5c 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/DebugSubcommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/DebugSubcommand.java @@ -3,6 +3,7 @@ import me.lokka30.levelledmobs.LevelledMobs; import me.lokka30.levelledmobs.commands.MessagesBase; import me.lokka30.levelledmobs.misc.DebugCreator; +import me.lokka30.levelledmobs.misc.Utils; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -15,7 +16,7 @@ public DebugSubcommand(final LevelledMobs main) { } @Override - public void parseSubcommand(final LevelledMobs main, final @NotNull CommandSender sender, final String label, final String[] args) { + public void parseSubcommand(final LevelledMobs main, final @NotNull CommandSender sender, final String label, final String @NotNull [] args) { commandSender = sender; messageLabel = label; @@ -24,15 +25,46 @@ public void parseSubcommand(final LevelledMobs main, final @NotNull CommandSende return; } - if (args.length == 3 && "create".equalsIgnoreCase(args[1]) && "confirm".equalsIgnoreCase(args[2])) - DebugCreator.createDebug(main, sender); + if (args.length <= 1){ + sender.sendMessage("Options: create / chunk_kill_count"); + return; + } + + if ("create".equalsIgnoreCase(args[1])) { + if (args.length >= 3 && "confirm".equalsIgnoreCase(args[2])) + DebugCreator.createDebug(main, sender); + else + showMessage("other.create-debug"); + } + else if ("chunk_kill_count".equalsIgnoreCase(args[1])) { + chunkKillCount(sender, args); + } else showMessage("other.create-debug"); } + private void chunkKillCount(final CommandSender sender, final String @NotNull [] args){ + if (args.length >= 3 && "reset".equalsIgnoreCase(args[2])){ + main.companion.clearChunkKillCache(); + sender.sendMessage("cache has been cleared"); + return; + } + + showChunkKillCountSyntax(sender); + } + + private void showChunkKillCountSyntax(final @NotNull CommandSender sender){ + sender.sendMessage("Options: reset"); + } + @Override - public List parseTabCompletions(final LevelledMobs main, final CommandSender sender, final String[] args) { - // This subcommand has no tab completions. + public List parseTabCompletions(final LevelledMobs main, final CommandSender sender, final String @NotNull [] args) { + Utils.logger.info(String.format("%s", args.length)); + if (args.length <= 2) + return List.of("create", "chunk_kill_count"); + if ("chunk_kill_count".equalsIgnoreCase(args[1])) + return List.of("reset"); + return Collections.emptyList(); } } diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java index 1e5d0aac5..74d9a5a17 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java @@ -202,20 +202,21 @@ private void resetRules(final @NotNull CommandSender sender, final @NotNull Rese showMessage("command.levelledmobs.rules.resetting", "%difficulty%", String.valueOf(difficulty)); final String filename = "rules.yml"; - final String[] replaceWhat = new String[] {" - average_challenge", " - weighted_random_average_difficulty", "", ""}; - final String[] replaceWith = new String[] {"# - average_challenge", "# - weighted_random_average_difficulty", "", ""}; + final String[] replaceWhat = new String[] {" - average_challenge", " - weighted_random_average", "", ""}; + final String[] replaceWith = new String[] {"# - average_challenge", "# - weighted_random_average", "", ""}; switch (difficulty){ case BASIC: - replaceWhat[2] = "# - basic_challenge"; replaceWith[2] = " - basic_challenge"; - replaceWhat[3] = "# - weighted_random_basic_difficulty"; replaceWith[3] = " - weighted_random_basic_difficulty"; + replaceWhat[2] = "# - basic_challenge"; replaceWith[2] = " - basic_challenge"; + replaceWhat[3] = "# - weighted_random_basic"; replaceWith[3] = " - weighted_random_basic"; break; case ADVANCED: - replaceWhat[2] = "# - advanced_challenge"; replaceWith[2] = " - advanced_challenge"; - replaceWhat[3] = "# - weighted_random_advanced_difficulty"; replaceWith[3] = " - weighted_random_advanced_difficulty"; + replaceWhat[2] = "# - advanced_challenge"; replaceWith[2] = " - advanced_challenge"; + replaceWhat[3] = "# - weighted_random_advanced"; replaceWith[3] = " - weighted_random_advanced_difficulty"; break; case EXTREME: - replaceWhat[2] = "# - extreme_challenge"; replaceWith[2] = " - extreme_challenge"; + replaceWhat[2] = "# - extreme_challenge"; replaceWith[2] = " - extreme_challenge"; + replaceWhat[3] = "# - weighted_random_extreme"; replaceWith[3] = " - weighted_random_extreme"; break; } @@ -229,10 +230,8 @@ private void resetRules(final @NotNull CommandSender sender, final @NotNull Rese if (difficulty != ResetDifficulty.AVERAGE) { rulesText = rulesText.replace(replaceWhat[0], replaceWith[0]) .replace(replaceWhat[1], replaceWith[1]) - .replace(replaceWhat[2], replaceWith[2]); - - if (difficulty != ResetDifficulty.EXTREME) - rulesText = rulesText.replace(replaceWhat[3], replaceWith[3]); + .replace(replaceWhat[2], replaceWith[2]) + .replace(replaceWhat[3], replaceWith[3]); } final File rulesFile = new File(main.getDataFolder(), filename); diff --git a/src/main/java/me/lokka30/levelledmobs/listeners/EntityDeathListener.java b/src/main/java/me/lokka30/levelledmobs/listeners/EntityDeathListener.java index d99e30d8c..8fd5c3e3b 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/EntityDeathListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/EntityDeathListener.java @@ -124,8 +124,8 @@ private boolean hasReachedEntityDeathChunkMax(final @NotNull LivingEntityWrapper if (main.companion.doesUserHaveCooldown(chunkKeys, player.getUniqueId())) return true; - Utils.debugLog(main, DebugType.CHUNK_KILL_COUNT, String.format("%s: %s, reached limit, entities recorded: %s, max: %s", - Utils.displayChunkLocation(lmEntity.getLocation()), lmEntity.getTypeName(), numberOfEntityDeathInChunk, maximumDeathInChunkThreshold)); + Utils.debugLog(main, DebugType.CHUNK_KILL_COUNT, String.format("%s: player: %s, entity: %s, reached chunk kill limit, max: %s", + Utils.displayChunkLocation(lmEntity.getLocation()), player.getName(), lmEntity.getTypeName(), maximumDeathInChunkThreshold)); final String prefix = main.configUtils.getPrefix(); final String msg = main.messagesCfg.getString("other.no-drop-in-chunk"); diff --git a/src/main/java/me/lokka30/levelledmobs/misc/FileMigrator.java b/src/main/java/me/lokka30/levelledmobs/misc/FileMigrator.java index fe76b1237..517cc1ce7 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/FileMigrator.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/FileMigrator.java @@ -395,6 +395,10 @@ static void copyYmlValues(final File from, @NotNull final File to, final int old "command.levelledmobs.spawner.spawner-give-message" ); + final List messagesExempt_v7 = List.of( + "command.levelledmobs.rules.reset" + ); + final String useCustomDrops = "use-custom-item-drops-for-mobs"; @@ -437,6 +441,7 @@ else if (currentKey.size() > depth) { if (isSettings && oldVersion <= 20 && !version20KeysToKeep.contains(key)) continue; if (isMessages && oldVersion <= 5 && messagesExempt_v5.contains(key)) continue; + if (isMessages && oldVersion <= 7 && messagesExempt_v7.contains(key)) continue; if (oldConfigMap.containsKey(oldKey) && newConfigMap.containsKey(key)) { final FileMigrator.FieldInfo fiOld = oldConfigMap.get(oldKey); @@ -489,6 +494,7 @@ else if (currentKey.size() > depth) { if (isSettings && oldVersion > 24 && oldVersion <= 26 && version26Resets.contains(key)) continue; if (isMessages && oldVersion <= 5 && messagesExempt_v5.contains(key)) continue; + if (isMessages && oldVersion <= 7 && messagesExempt_v7.contains(key)) continue; if (key.toLowerCase().startsWith("file-version")) continue; if (isSettings && key.equalsIgnoreCase("creature-nametag") && oldVersion > 20 && oldVersion < 26 && migratedValue.equals("'&8[&7Level %level%&8 | &f%displayname%&8 | &c%health%&8/&c%max_health% %heart_symbol%&8]'")) { @@ -517,6 +523,7 @@ else if (currentKey.size() > depth) { if (isSettings && oldVersion > 20 && oldVersion <= 24 && version24Resets.contains(oldValue)) continue; if (isSettings && oldVersion > 24 && oldVersion <= 26 && version26Resets.contains(oldValue)) continue; if (isMessages && oldVersion <= 5 && messagesExempt_v5.contains(key)) continue; + if (isMessages && oldVersion <= 7 && messagesExempt_v7.contains(key)) continue; final FileMigrator.FieldInfo fiOld = entry.getValue(); if (fiOld.isList()) continue; @@ -544,6 +551,7 @@ else if (currentKey.size() > depth) { final String value = line.trim().substring(1).trim(); if (isMessages && oldVersion <= 5 && messagesExempt_v5.contains(key)) continue; + if (isMessages && oldVersion <= 7 && messagesExempt_v7.contains(key)) continue; // we have an array value present in the new config but not the old, so it must've been removed if (oldConfigMap.containsKey(key) && oldConfigMap.get(key).isList() && !oldConfigMap.get(key).valueList.contains(value)) { diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index e1ae1d7e5..892f242b7 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -259,8 +259,8 @@ command: rules-reprocessed: - '%prefix% Rules Reprocessed for &b%entitycount%&7 mobs in &b%worldcount%&7 world(s)' reset: - - '%prefix% Running this command will reset your rules to one of 3 defaults.' - - 'You must select if you want easy/normal/hard difficulty.' + - '%prefix% Running this command will reset your rules to one of 4 defaults.' + - 'You must select if you want basic/average/advanced/extreme difficulty.' - 'A backup will be made and your rules.yml reset to default.' resetting: - '%prefix% Resetting rules to %difficulty%'