From 988fd0d30ca93d06daee43e41e7fa7d58db74e46 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Sat, 24 Sep 2022 18:21:28 -0500 Subject: [PATCH] v3.7.3 b700 * added new option to player levelling: `preserve-entity` with default of `10s` --- pom.xml | 2 +- .../levelledmobs/managers/LevelManager.java | 26 ++++++++++++++++++- .../levelledmobs/misc/NamespacedKeys.java | 2 ++ .../rules/PlayerLevellingOptions.java | 1 + .../rules/RulesParsingManager.java | 1 + src/main/resources/rules.yml | 1 + 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 70c2753bc..63fa0b125 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lokka30 LevelledMobs - 3.7.3 b699 + 3.7.3 b700 jar LevelledMobs The Ultimate RPG Mob Levelling Plugin diff --git a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java index bc023828a..df2309de9 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -979,10 +979,13 @@ private void runNametagCheck_aSync(final @NotNull Map> enti lmEntity.playerForPermissionsCheck = player; if (lmEntity.isLevelled()) { - final boolean skipLevelling = ( + boolean skipLevelling = ( lmEntity.getSpawnReason() == LevelledMobSpawnReason.LM_SPAWNER || lmEntity.getSpawnReason() == LevelledMobSpawnReason.LM_SUMMON ); + if (main.configUtils.playerLevellingEnabled && !checkIfReadyForRelevelling(lmEntity)){ + skipLevelling = true; + } if (main.configUtils.playerLevellingEnabled && !skipLevelling) { final boolean hasKey = entityToPlayer.containsKey(lmEntity); final List players = hasKey ? @@ -1052,6 +1055,25 @@ private void runNametagCheck_aSync(final @NotNull Map> enti } } + private boolean checkIfReadyForRelevelling(final @NotNull LivingEntityWrapper lmEntity){ + final PlayerLevellingOptions opts = main.rulesManager.getRulePlayerLevellingOptions(lmEntity); + if (opts == null || opts.preserveEntityTime == null) { + return true; + } + + if (!lmEntity.getPDC().has(main.namespacedKeys.lastLevelledTime)){ + return true; + } + + final Long lastLevelledTime = lmEntity.getPDC().get(main.namespacedKeys.lastLevelledTime, PersistentDataType.LONG); + if (lastLevelledTime == null) { + return true; + } + + final Instant levelledTime = Instant.ofEpochMilli(lastLevelledTime); + return Utils.getMillisecondsFromInstant(levelledTime) > opts.preserveEntityTime; + } + private void checkEntityForPlayerLevelling(final @NotNull LivingEntityWrapper lmEntity, final @NotNull List players) { final LivingEntity mob = lmEntity.getLivingEntity(); @@ -1651,6 +1673,8 @@ public void run() { main.levelManager.applyCreeperBlastRadius(lmEntity); } + lmEntity.getPDC().set(main.namespacedKeys.lastLevelledTime, PersistentDataType.LONG, Instant.now().toEpochMilli()); + lmEntity.free(); } }; diff --git a/src/main/java/me/lokka30/levelledmobs/misc/NamespacedKeys.java b/src/main/java/me/lokka30/levelledmobs/misc/NamespacedKeys.java index 2b5cffdf0..9c8b60acd 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/NamespacedKeys.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/NamespacedKeys.java @@ -34,6 +34,7 @@ public NamespacedKeys(final LevelledMobs main) { lockedDropRules = new NamespacedKey(main, "lockedDropRules"); lockedDropRulesOverride = new NamespacedKey(main, "lockedDropRulesOverride"); playerLevellingSourceNumber = new NamespacedKey(main, "playerLevellingSourceNumber"); + lastLevelledTime = new NamespacedKey(main, "lastLevelledTime"); spawnerEgg = new NamespacedKey(main, "spawnerEgg"); spawnerEggName = new NamespacedKey(main, "spawnerEggName"); @@ -72,6 +73,7 @@ public NamespacedKeys(final LevelledMobs main) { public final NamespacedKey playerNetherCoordsIntoWorld; public final NamespacedKey skyLightLevel; public final NamespacedKey playerLevellingSourceNumber; + public final NamespacedKey lastLevelledTime; public final NamespacedKey lockSettings; public final NamespacedKey lockedNametag; diff --git a/src/main/java/me/lokka30/levelledmobs/rules/PlayerLevellingOptions.java b/src/main/java/me/lokka30/levelledmobs/rules/PlayerLevellingOptions.java index b145ab6af..9f492308c 100644 --- a/src/main/java/me/lokka30/levelledmobs/rules/PlayerLevellingOptions.java +++ b/src/main/java/me/lokka30/levelledmobs/rules/PlayerLevellingOptions.java @@ -28,6 +28,7 @@ public class PlayerLevellingOptions implements Cloneable { public Boolean usePlayerMaxLevel; public Boolean recheckPlayers; public Integer levelCap; + public Long preserveEntityTime; public Double playerLevelScale; public String variable; public boolean decreaseLevel; diff --git a/src/main/java/me/lokka30/levelledmobs/rules/RulesParsingManager.java b/src/main/java/me/lokka30/levelledmobs/rules/RulesParsingManager.java index 4d350a103..1a049e8f4 100644 --- a/src/main/java/me/lokka30/levelledmobs/rules/RulesParsingManager.java +++ b/src/main/java/me/lokka30/levelledmobs/rules/RulesParsingManager.java @@ -1255,6 +1255,7 @@ private void parsePlayerLevellingOptions(final ConfigurationSection cs) { options.variable = ymlHelper.getString(cs, "variable", options.variable); options.decreaseLevel = ymlHelper.getBoolean(cs, "decrease-level", true); options.recheckPlayers = ymlHelper.getBoolean2(cs, "recheck-players", options.recheckPlayers); + options.preserveEntityTime = ymlHelper.getIntTimeUnitMS(cs, "preserve-entity", options.preserveEntityTime); parsingInfo.playerLevellingOptions = options; final ConfigurationSection csTiers = objTo_CS(cs, "tiers"); diff --git a/src/main/resources/rules.yml b/src/main/resources/rules.yml index e56dfefb8..9e1ce7236 100644 --- a/src/main/resources/rules.yml +++ b/src/main/resources/rules.yml @@ -116,6 +116,7 @@ presets: use-player-max-level: false decrease-level: true recheck-players: false + preserve-entity: 10s player-level-scale: 1.0 level-cap: 30 tiers: