Skip to content

Commit

Permalink
v3.7.3 b700
Browse files Browse the repository at this point in the history
* added new option to player levelling: `preserve-entity` with default of `10s`
  • Loading branch information
stumper66 committed Sep 24, 2022
1 parent 7ff367d commit 988fd0d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lokka30</groupId>
<artifactId>LevelledMobs</artifactId>
<version>3.7.3 b699</version>
<version>3.7.3 b700</version>
<packaging>jar</packaging>
<name>LevelledMobs</name>
<description>The Ultimate RPG Mob Levelling Plugin</description>
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,13 @@ private void runNametagCheck_aSync(final @NotNull Map<Player, List<Entity>> 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<Player> players = hasKey ?
Expand Down Expand Up @@ -1052,6 +1055,25 @@ private void runNametagCheck_aSync(final @NotNull Map<Player, List<Entity>> 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<Player> players) {
final LivingEntity mob = lmEntity.getLivingEntity();
Expand Down Expand Up @@ -1651,6 +1673,8 @@ public void run() {
main.levelManager.applyCreeperBlastRadius(lmEntity);
}

lmEntity.getPDC().set(main.namespacedKeys.lastLevelledTime, PersistentDataType.LONG, Instant.now().toEpochMilli());

lmEntity.free();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 988fd0d

Please sign in to comment.