Skip to content

Commit

Permalink
Merge branch '3.7-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
lokka30 committed Sep 25, 2022
2 parents cf7af45 + c35df10 commit b7a3ce4
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 94 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.2 b695</version>
<version>3.7.3 b701</version>
<packaging>jar</packaging>
<name>LevelledMobs</name>
<description>The Ultimate RPG Mob Levelling Plugin</description>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/me/lokka30/levelledmobs/Companion.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import me.lokka30.levelledmobs.listeners.PlayerInteractEventListener;
import me.lokka30.levelledmobs.listeners.PlayerJoinListener;
import me.lokka30.levelledmobs.listeners.PlayerPortalEventListener;
import me.lokka30.levelledmobs.listeners.ServerStartListener;
import me.lokka30.levelledmobs.managers.ExternalCompatibilityManager;
import me.lokka30.levelledmobs.managers.LevelManager;
import me.lokka30.levelledmobs.managers.PlaceholderApiIntegration;
Expand Down Expand Up @@ -292,7 +291,6 @@ void registerListeners() {
pluginManager.registerEvents(new CombustListener(main), main);
pluginManager.registerEvents(main.blockPlaceListener, main);
pluginManager.registerEvents(new PlayerPortalEventListener(main), main);
pluginManager.registerEvents(new ServerStartListener(main), main);
main.chunkLoadListener = new ChunkLoadListener(main);
main.playerInteractEventListener = new PlayerInteractEventListener(main);
pluginManager.registerEvents(main.playerInteractEventListener, main);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/me/lokka30/levelledmobs/LevelledMobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import me.lokka30.levelledmobs.managers.MobsQueueManager;
import me.lokka30.levelledmobs.managers.NametagQueueManager;
import me.lokka30.levelledmobs.managers.PlaceholderApiIntegration;
import me.lokka30.levelledmobs.misc.FileLoader;
import me.lokka30.levelledmobs.misc.LivingEntityWrapper;
import me.lokka30.levelledmobs.misc.NamespacedKeys;
import me.lokka30.levelledmobs.misc.NametagTimerChecker;
Expand Down Expand Up @@ -127,6 +128,8 @@ public void onEnable() {
levelManager.startNametagAutoUpdateTask();
levelManager.startNametagTimer();
}

prepareToLoadCustomDrops();
companion.startCleanupTask();
companion.setupMetrics();
companion.checkUpdates();
Expand All @@ -135,6 +138,20 @@ public void onEnable() {
Utils.logger.info("Start-up complete (took " + loadTime + "ms)");
}

private void prepareToLoadCustomDrops(){
if (Bukkit.getPluginManager().getPlugin("LM_Items") != null){
final LevelledMobs mainInstance = this;
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> customDropsHandler.customDropsParser.loadDrops(
FileLoader.loadFile(mainInstance, "customdrops", FileLoader.CUSTOMDROPS_FILE_VERSION)
), 10L);
}
else{
customDropsHandler.customDropsParser.loadDrops(
FileLoader.loadFile(this, "customdrops", FileLoader.CUSTOMDROPS_FILE_VERSION)
);
}
}

public void reloadLM(final @NotNull CommandSender sender) {
migratedFromPre30 = false;
List<String> reloadStartedMsg = messagesCfg.getStringList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void doNbtDump(final @NotNull CommandSender sender, final String @NotNul
}

final LivingEntityWrapper lmEntity = main.levelledMobsCommand.rulesSubcommand.getMobBeingLookedAt(
player, true);
player, true, sender);
if (lmEntity == null) {
sender.sendMessage("Could not locate any mobs near player: " + player.getName());
return;
Expand All @@ -110,11 +110,9 @@ private void doNbtDump(final @NotNull CommandSender sender, final String @NotNul
lmEntity.getNameIfBaby(),
lmEntity.getWorldName(),
locationStr,
MiscUtils.getNBTDump(main.nametagQueueManager.nmsHandler.nmsVersionString, lmEntity.getLivingEntity())
MiscUtils.getNBTDump(lmEntity.getLivingEntity(), main)
);

final String nmsVersion = main.nametagQueueManager.nmsHandler.nmsVersionString;

lmEntity.free();
Utils.logger.info(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private void showRule(final CommandSender sender, @NotNull final String @NotNull

private void showEffectiveRules(@NotNull final Player player, final boolean showOnConsole,
final boolean findNearbyEntities) {
final LivingEntityWrapper lmEntity = getMobBeingLookedAt(player, findNearbyEntities);
final LivingEntityWrapper lmEntity = getMobBeingLookedAt(player, findNearbyEntities, this.commandSender);
if (lmEntity == null) {
return;
}
Expand Down Expand Up @@ -389,7 +389,8 @@ public void run() {
}

@Nullable public LivingEntityWrapper getMobBeingLookedAt(@NotNull final Player player,
final boolean findNearbyEntities) {
final boolean findNearbyEntities, final @NotNull CommandSender sender) {
this.commandSender = sender;
LivingEntity livingEntity = null;
LivingEntityWrapper lmEntity = null;
final Location eye = player.getEyeLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package me.lokka30.levelledmobs.listeners;

import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import me.lokka30.levelledmobs.LevelledMobs;
Expand All @@ -27,6 +28,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;

/**
Expand Down Expand Up @@ -119,6 +121,8 @@ public void onEntityDamageEvent(@NotNull final EntityDamageEvent event) {
}
}

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

// Update their nametag with a 1 tick delay so that their health after the damage is shown
main.levelManager.updateNametagWithDelay(lmEntity);
lmEntity.free();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,10 @@ public static boolean isMythicMob(@NotNull final LivingEntityWrapper lmEntity) {
return false;
}

if (!p.getDescription().getVersion().startsWith("4.12") && !p.getDescription().getVersion()
.startsWith("5.")) {
final NamespacedKey mmKey = new NamespacedKey(p, "type");
synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) {
return lmEntity.getPDC().has(mmKey, PersistentDataType.STRING);
}
}

if (lmEntity.getLivingEntity().hasMetadata("mythicmob")) {
final List<MetadataValue> metadatas = lmEntity.getLivingEntity()
.getMetadata("mythicmob");
for (final MetadataValue md : metadatas) {
if (md.asBoolean()) {
return true;
}
}
final NamespacedKey mmKey = new NamespacedKey(p, "type");
synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) {
return lmEntity.getPDC().has(mmKey, PersistentDataType.STRING);
}

return false;
}

@NotNull public static String getMythicMobInternalName(@NotNull final LivingEntityWrapper lmEntity) {
Expand All @@ -224,33 +209,11 @@ public static boolean isMythicMob(@NotNull final LivingEntityWrapper lmEntity) {
return "";
}

final boolean useNamespaceKey =
p.getDescription().getVersion().startsWith("5.") &&
!p.getDescription().getVersion().startsWith("5.01") &&
!p.getDescription().getVersion().startsWith("5.00");

if (useNamespaceKey) {
final NamespacedKey mmKey = new NamespacedKey(p, "type");
synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) {
if (lmEntity.getPDC().has(mmKey, PersistentDataType.STRING)) {
final String type = lmEntity.getPDC().get(mmKey, PersistentDataType.STRING);
return type == null ? "" : type;
} else {
return "";
}
}
}

// MM version 4, 5.00 and 5.01 detection below:

if (!lmEntity.getLivingEntity().hasMetadata("mobname")) {
return "";
}

final List<MetadataValue> metadatas = lmEntity.getLivingEntity().getMetadata("mobname");
for (final MetadataValue md : metadatas) {
if ("true".equalsIgnoreCase(md.asString())) {
return md.asString();
final NamespacedKey mmKey = new NamespacedKey(p, "type");
synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) {
if (lmEntity.getPDC().has(mmKey, PersistentDataType.STRING)) {
final String type = lmEntity.getPDC().get(mmKey, PersistentDataType.STRING);
return type == null ? "" : type;
}
}

Expand Down
57 changes: 51 additions & 6 deletions src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private int generateRandomLevel(RandomLevellingStrategy randomLevelling, final i

int levelSource;
final String variableToUse =
Utils.isNullOrEmpty(options.variable) ? "%level%" : options.variable;
Utils.isNullOrEmpty(options.variable) ? "%level%" : options.variable;
final double scale = options.playerLevelScale != null ? options.playerLevelScale : 1.0;
final boolean usePlayerMax = options.usePlayerMaxLevel != null && options.usePlayerMaxLevel;
final boolean matchPlayerLvl = options.matchPlayerLevel != null && options.matchPlayerLevel;
Expand Down Expand Up @@ -348,13 +348,19 @@ private int generateRandomLevel(RandomLevellingStrategy randomLevelling, final i
}
}

if (options.recheckPlayers != null && options.recheckPlayers) {
final String numberOrString = playerLevelSourceResult.isNumericResult ?
playerLevelSourceResult.numericResult + "" : playerLevelSourceResult.stringResult;
if (numberOrString != null)
lmEntity.getPDC().set(main.namespacedKeys.playerLevellingSourceNumber, PersistentDataType.STRING, numberOrString);
}
lmEntity.playerLevellingAllowDecrease = options.decreaseLevel;

return results;
}

public PlayerLevelSourceResult getPlayerLevelSourceNumber(final Player player,
final String variableToUse) {
public @NotNull PlayerLevelSourceResult getPlayerLevelSourceNumber(final @Nullable Player player,
final @NotNull String variableToUse) {
if (player == null) {
return new PlayerLevelSourceResult(1);
}
Expand Down Expand Up @@ -973,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 @@ -1046,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.lastDamageTime)){
return true;
}

final Long lastLevelledTime = lmEntity.getPDC().get(main.namespacedKeys.lastDamageTime, 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 @@ -1079,7 +1107,7 @@ private void checkEntityForPlayerLevelling(final @NotNull LivingEntityWrapper lm
main.companion.removeRecentlyJoinedPlayer(closestPlayer);
}

if (doesMobNeedRelevelling(mob, closestPlayer)) {
if (doesMobNeedRelevelling(lmEntity, closestPlayer)) {
lmEntity.pendingPlayerIdToSet = closestPlayer.getUniqueId().toString();
lmEntity.setPlayerForLevelling(closestPlayer);
lmEntity.reEvaluateLevel = true;
Expand Down Expand Up @@ -1119,8 +1147,10 @@ private void checkLevelledEntity(@NotNull final LivingEntityWrapper lmEntity,
}
}

private boolean doesMobNeedRelevelling(final @NotNull LivingEntity mob,
private boolean doesMobNeedRelevelling(final @NotNull LivingEntityWrapper lmEntity,
final @NotNull Player player) {
final LivingEntity mob = lmEntity.getLivingEntity();

if (main.playerLevellingMinRelevelTime > 0L && main.playerLevellingEntities.containsKey(
mob)) {
final Instant lastCheck = main.playerLevellingEntities.get(mob);
Expand Down Expand Up @@ -1152,6 +1182,21 @@ private boolean doesMobNeedRelevelling(final @NotNull LivingEntity mob,
return true;
}

final PlayerLevellingOptions opts = main.rulesManager.getRulePlayerLevellingOptions(lmEntity);
if (player.getUniqueId().toString().equals(playerId) && opts != null && opts.recheckPlayers != null && opts.recheckPlayers){
final String previousResult = lmEntity.getPDC().get(main.namespacedKeys.playerLevellingSourceNumber, PersistentDataType.STRING);
if (previousResult == null) {
return true;
}
final String variableToUse =
Utils.isNullOrEmpty(opts.variable) ? "%level%" : opts.variable;
PlayerLevelSourceResult result = getPlayerLevelSourceNumber(player, variableToUse);
final String sourceNumberStr = result.isNumericResult ?
result.numericResult + "" : result.stringResult;

return !previousResult.equals(sourceNumberStr);
}

return !player.getUniqueId().toString().equals(playerId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public NamespacedKeys(final LevelledMobs main) {
lockedNameOverride = new NamespacedKey(main, "lockedNameOverride");
lockedDropRules = new NamespacedKey(main, "lockedDropRules");
lockedDropRulesOverride = new NamespacedKey(main, "lockedDropRulesOverride");
playerLevellingSourceNumber = new NamespacedKey(main, "playerLevellingSourceNumber");
lastDamageTime = new NamespacedKey(main, "lastDamageTime");

spawnerEgg = new NamespacedKey(main, "spawnerEgg");
spawnerEggName = new NamespacedKey(main, "spawnerEggName");
Expand Down Expand Up @@ -70,6 +72,8 @@ public NamespacedKeys(final LevelledMobs main) {
public final NamespacedKey playerNetherCoords;
public final NamespacedKey playerNetherCoordsIntoWorld;
public final NamespacedKey skyLightLevel;
public final NamespacedKey playerLevellingSourceNumber;
public final NamespacedKey lastDamageTime;

public final NamespacedKey lockSettings;
public final NamespacedKey lockedNametag;
Expand Down
Loading

0 comments on commit b7a3ce4

Please sign in to comment.