Skip to content

Commit

Permalink
v3.4.0 b623
Browse files Browse the repository at this point in the history
* chunk kill count tweaks
* invalid rules.yml message change
* rules.yml changes
* added command /lm debug chunk_kill_count reset
  • Loading branch information
stumper66 committed Mar 30, 2022
1 parent 888feaf commit 5a9efad
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 22 deletions.
9 changes: 7 additions & 2 deletions src/main/java/me/lokka30/levelledmobs/Companion.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,13 @@ public void addUserCooldown(final @NotNull List<Long> chunkKeys, final @NotNull
}
}

public @NotNull HashMap<Long, Map<EntityType, ChunkKillInfo>> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public List<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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<String> parseTabCompletions(final LevelledMobs main, final CommandSender sender, final String[] args) {
// This subcommand has no tab completions.
public List<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/me/lokka30/levelledmobs/misc/FileMigrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> messagesExempt_v7 = List.of(
"command.levelledmobs.rules.reset"
);


final String useCustomDrops = "use-custom-item-drops-for-mobs";

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]'")) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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%'
Expand Down

0 comments on commit 5a9efad

Please sign in to comment.