Skip to content

Commit

Permalink
Merge pull request #294 from lokka30/3.1-dev
Browse files Browse the repository at this point in the history
3.1 dev
  • Loading branch information
lokka30 authored Sep 2, 2021
2 parents d252d69 + 684fa4c commit dbe54e0
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>me.lokka30</groupId>
<artifactId>LevelledMobs</artifactId>
<version>3.1.6 b506</version>
<version>3.1.7 b508</version>
<packaging>jar</packaging>

<name>LevelledMobs</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ private LevelledMobSpawnReason adaptVanillaSpawnReason(final CreatureSpawnEvent.
private void getClosestPlayer(final @NotNull LivingEntityWrapper lmEntity) {
if (lmEntity.getPlayerForLevelling() != null) return;

Entity closestEntity = null;
Entity closestPlayer = null;
double closestRange = Double.MAX_VALUE;
final int checkDistance = main.helperSettings.getInt(main.settingsCfg,"async-task-max-blocks-from-player", 100);

for (final Entity entity : lmEntity.getLivingEntity().getNearbyEntities(50, 50, 50)) {
for (final Entity entity : lmEntity.getLivingEntity().getNearbyEntities(checkDistance, checkDistance, checkDistance)) {
if (!(entity instanceof Player)) continue;
if (((Player) entity).getGameMode().equals(GameMode.SPECTATOR)) continue;

Expand All @@ -92,17 +93,17 @@ private void getClosestPlayer(final @NotNull LivingEntityWrapper lmEntity) {

final double range = entity.getLocation().distanceSquared(lmEntity.getLocation());
if (range < closestRange && range <= main.playerLevellingDistance){
closestEntity = entity;
closestPlayer = entity;
closestRange = range;
}
}

if (closestEntity != null) {
synchronized (closestEntity.getPersistentDataContainer()){
closestEntity.getPersistentDataContainer().set(main.levelManager.playerLevelling_Id, PersistentDataType.STRING, (closestEntity).getUniqueId().toString());
if (closestPlayer != null) {
synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()){
lmEntity.getLivingEntity().getPersistentDataContainer().set(main.levelManager.playerLevelling_Id, PersistentDataType.STRING, closestPlayer.getUniqueId().toString());
}

lmEntity.setPlayerForLevelling((Player) closestEntity);
lmEntity.setPlayerForLevelling((Player) closestPlayer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,26 @@ public static boolean isMythicMob(@NotNull final LivingEntityWrapper lmEntity) {

@NotNull
public static String getMythicMobInternalName(@NotNull final LivingEntityWrapper lmEntity){
if (!isMythicMob(lmEntity) || !lmEntity.getLivingEntity().hasMetadata("mobname")) return "";
if (!isMythicMob(lmEntity)) return "";

final Plugin p = Bukkit.getPluginManager().getPlugin("MythicMobs");
if (p == null) return "";

if (!p.getDescription().getVersion().startsWith("4")) {
// MM version 5 must use this method for internal name detection
NamespacedKey mmKey = new NamespacedKey(p, "type");
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 detection below:

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

final List<MetadataValue> metadatas = lmEntity.getLivingEntity().getMetadata("mobname");
for (final MetadataValue md : metadatas){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public void startNametagAutoUpdateTask() {
@Override
public void run() {
final Map<Player, List<Entity>> entitiesPerPlayer = new LinkedHashMap<>();
final int checkDistance = main.helperSettings.getInt(main.settingsCfg,"async-task-update-period", 100);
final int checkDistance = main.helperSettings.getInt(main.settingsCfg,"async-task-max-blocks-from-player", 100);

for (final Player player : Bukkit.getOnlinePlayers()) {
final List<Entity> entities = player.getNearbyEntities(checkDistance, checkDistance, checkDistance);
Expand Down Expand Up @@ -948,7 +948,7 @@ This is also ran in getLevellableState(EntityType), however it is important that
return LevellableState.DENIED_CONFIGURATION_BLOCKED_ENTITY_TYPE;

if (main.rulesManager.getRule_MobMaxLevel(lmInterface) < 1)
return LevellableState.DENIED_OTHER;
return LevellableState.DENIED_LEVEL_0;

if (!(lmInterface instanceof LivingEntityWrapper))
return LevellableState.ALLOWED;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/me/lokka30/levelledmobs/misc/DebugType.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,7 @@ public enum DebugType {

DENIED_RULE_STOP_PROCESSING,

PLAYER_LEVELLING
PLAYER_LEVELLING,

DENIED_RULE_MYTHIC_MOBS_INTERNAL_NAME
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ public enum LevellableState {
* Please contact a lead developer if you
* believe you must resort to using this.
*/
DENIED_OTHER
DENIED_OTHER,

DENIED_LEVEL_0
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public LivingEntityWrapper(final @NotNull LivingEntity livingEntity, final @NotN
private FineTuningAttributes fineTuningAttributes;
private LevelledMobSpawnReason spawnReason;
public EntityDamageEvent.DamageCause deathCause;
public String mythicMobInternalName;
public boolean reEvaluateLevel;
private boolean groupsAreBuilt;
private Double calculatedDistanceFromSpawn;
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,15 @@ private boolean isRuleApplicable_Entity(final LivingEntityWrapper lmEntity, @Not
return false;
}

if (ri.conditions_MM_Names != null && lmEntity.isMobOfExternalType(ExternalCompatibilityManager.ExternalCompatibility.MYTHIC_MOBS)){
String mm_Name = lmEntity.mythicMobInternalName;
if (mm_Name == null) mm_Name = "";
if (ri.conditions_MM_Names != null){
String mm_Name = ExternalCompatibilityManager.getMythicMobInternalName(lmEntity);
if ("".equals(mm_Name)) mm_Name = "(none)";

//noinspection RedundantIfStatement
if (!ri.conditions_MM_Names.isEnabledInList(mm_Name, lmEntity)) return false;
if (!ri.conditions_MM_Names.isEnabledInList(mm_Name, lmEntity)) {
Utils.debugLog(main, DebugType.DENIED_RULE_MYTHIC_MOBS_INTERNAL_NAME, String.format("&b%s&7, mob: &b%s&7, mm_name: &b%s&7",
ri.getRuleName(), lmEntity.getTypeName(), mm_Name));
return false;
}
}

return true;
Expand Down

0 comments on commit dbe54e0

Please sign in to comment.