Skip to content

Commit

Permalink
Merge pull request #343 from lokka30/3.3-dev
Browse files Browse the repository at this point in the history
3.3 dev
  • Loading branch information
lokka30 authored Dec 17, 2021
2 parents af5c4fb + c45c252 commit b00a5fc
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 78 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.3.0 b582</version>
<version>3.3.1 b587</version>
<packaging>jar</packaging>

<name>LevelledMobs</name>
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/me/lokka30/levelledmobs/Companion.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,6 @@ void registerCommands() {
levelledMobsCommand.setExecutor(main.levelledMobsCommand);
}

void loadSpigotConfig(){
try {
main.levelManager.attributeMaxHealthMax = Bukkit.getServer().spigot().getConfig().getDouble("settings.attribute.maxHealth.max", 2048.0);
main.levelManager.attributeMovementSpeedMax = Bukkit.getServer().spigot().getConfig().getDouble("settings.attribute.movementSpeed.max", 2048.0);
main.levelManager.attributeAttackDamageMax = Bukkit.getServer().spigot().getConfig().getDouble("settings.attribute.attackDamage.max", 2048.0);
} catch (final NoSuchMethodError ignored) {
main.levelManager.attributeMaxHealthMax = Integer.MAX_VALUE;
main.levelManager.attributeMovementSpeedMax = Integer.MAX_VALUE;
main.levelManager.attributeAttackDamageMax = Integer.MAX_VALUE;
}
}

void setupMetrics() {
final Metrics metrics = new Metrics(main, 6269);

Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/lokka30/levelledmobs/LevelledMobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public void onEnable() {
}
companion.registerListeners();
companion.registerCommands();
companion.loadSpigotConfig();

Utils.logger.info("&fStart-up: &7Running misc procedures...");
if (ExternalCompatibilityManager.hasProtocolLibInstalled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ else if (findNearbyEntities && entities.isEmpty())
lmEntity.getLivingEntity().getLocation().getBlockX(),
lmEntity.getLivingEntity().getLocation().getBlockY(),
lmEntity.getLivingEntity().getLocation().getBlockZ());
final String mobLevel = lmEntity.isLevelled() ? lmEntity.getMobLevel() + "" : "0";
final List<String> messages = getMessage("command.levelledmobs.rules.effective-rules",
new String[]{"%mobname%", "%entitytype%", "%location%", "%world%"},
new String[]{ entityName, lmEntity.getNameIfBaby(), locationStr, lmEntity.getWorldName() }
new String[]{"%mobname%", "%entitytype%", "%location%", "%world%", "%level%"},
new String[]{ entityName, lmEntity.getNameIfBaby(), locationStr, lmEntity.getWorldName(), mobLevel }
);


Expand Down Expand Up @@ -407,7 +408,8 @@ private void showEffectiveValues(final CommandSender sender, final @NotNull Livi
final RuleInfo pi = effectiveRules.get(i);

for (final Field f : pi.getClass().getDeclaredFields()) {
if (!Modifier.isPublic(f.getModifiers())) continue;
if (Modifier.isPrivate(f.getModifiers())) continue;
f.setAccessible(true);
if (f.get(pi) == null) continue;
if (printedKeys.contains(f.getName())) continue;
if (f.getName().equals("ruleSourceNames")) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ private String parseFlagValue(final String keyName, final int argNumber, final S
return args[argNumber + 1];
}

static void setMetaItems(final @Nullable ItemMeta meta, final @NotNull CustomSpawnerInfo info){
static void setMetaItems(final @Nullable ItemMeta meta, final @NotNull CustomSpawnerInfo info, final @NotNull String defaultName){
if (meta == null) return;

if (VersionUtils.isRunningPaper())
PaperUtils.updateItemDisplayName(meta, info.customName == null ? "LM Spawn Egg" : info.customName);
PaperUtils.updateItemDisplayName(meta, info.customName == null ? defaultName : info.customName);
else
SpigotUtils.updateItemDisplayName(meta, info.customName == null ? "LM Spawn Egg" : info.customName);
SpigotUtils.updateItemDisplayName(meta, info.customName == null ? defaultName : info.customName);

List<String> lore = new LinkedList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void generateEgg(final @NotNull CustomSpawnerInfo info){
final ItemStack item = new ItemStack(material);
final ItemMeta meta = item.getItemMeta();
if (meta != null){
setMetaItems(meta, info);
setMetaItems(meta, info, "LM Spawn Egg");

meta.getPersistentDataContainer().set(info.main.namespaced_keys.spawnerEgg, PersistentDataType.INTEGER, 1);
meta.getPersistentDataContainer().set(info.main.namespaced_keys.keySpawner_MinLevel, PersistentDataType.INTEGER, info.minLevel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void generateSpawner(final @NotNull CustomSpawnerInfo info){
final ItemStack item = new ItemStack(Material.SPAWNER);
final ItemMeta meta = item.getItemMeta();
if (meta != null){
setMetaItems(meta, info);
setMetaItems(meta, info, "LM Spawner");

meta.getPersistentDataContainer().set(info.main.namespaced_keys.keySpawner, PersistentDataType.INTEGER, 1);
meta.getPersistentDataContainer().set(info.main.namespaced_keys.keySpawner_MinLevel, PersistentDataType.INTEGER, info.minLevel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ private void summonMobs(@NotNull final SummonMobOptions options) {
final Player target = options.player;
Location location = options.lmPlaceHolder.getLocation();

if (main.levelManager.FORCED_BLOCKED_ENTITY_TYPES.contains(options.lmPlaceHolder.getTypeName())) {
if (main.levelManager.FORCED_BLOCKED_ENTITY_TYPES.contains(options.lmPlaceHolder.getEntityType())) {
List<String> messages = main.messagesCfg.getStringList("command.levelledmobs.summon.not-levellable");
messages = Utils.replaceAllInList(messages, "%prefix%", main.configUtils.getPrefix());
messages = Utils.replaceAllInList(messages, "%entity%", options.lmPlaceHolder.getTypeName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import org.bukkit.entity.EntityType;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -26,4 +28,8 @@ public static HashSet<EntityType> getPassiveMobs() {
EntityType.GOAT
).collect(Collectors.toCollection(HashSet::new));
}

public static Collection<EntityType> getForceBlockedEntityType(){
return List.of(EntityType.GLOW_ITEM_FRAME, EntityType.MARKER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class CustomDropItem extends CustomDropBase {
boolean onlyDropIfEquipped;
public String customName;
public String mobHeadTexture;
String nbtData;
public List<String> lore;
List<ItemFlag> itemFlags;
private boolean hasDamageRange;
Expand All @@ -40,7 +39,7 @@ public class CustomDropItem extends CustomDropBase {

CustomDropItem(@NotNull final CustomDropsDefaults defaults) {
super(defaults);
if (!Utils.isNullOrEmpty(defaults.damage)) this.setDamageRangeFromString(defaults.damage);

this.customModelDataId = defaults.customModelData;
this.chance = defaults.chance;
this.maxLevel = defaults.maxLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
*/
public enum CustomDropResult {
HAS_OVERRIDE,
NO_OVERRIDE,
HAS_OVERALL_CHANCE
NO_OVERRIDE
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class CustomDropsDefaults {
float equippedSpawnChance;
Float overallChance;
String groupId;
public String damage;
String playerLevelVariable;
public final List<String> permissions;
final List<String> overallPermissions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ else if (singleCommand != null)
Utils.logger.warning("custom drop " + item.getMaterial().toString() + " for " + dropInstance.getMobOrGroupName() + " has invalid NBT data: " + result.exceptionMessage);
else {
item.setItemStack(result.itemStack);
item.nbtData = nbtStuff;
this.dropsUtilizeNBTAPI = true;
}
} else if (!hasMentionedNBTAPI_Missing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ private LevelledMobSpawnReason adaptVanillaSpawnReason(final CreatureSpawnEvent.
return LevelledMobSpawnReason.valueOf(spawnReason.toString());
}

private void delayedAddToQueue(final LivingEntityWrapper lmEntity, final Event event, final int delay){
private void delayedAddToQueue(final @NotNull LivingEntityWrapper lmEntity, final Event event, final int delay){
final BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
main._mobsQueueManager.addToQueue(new QueueItem(lmEntity, event));
lmEntity.free();
}
};

lmEntity.inUseCount.getAndIncrement();
runnable.runTaskLater(main, delay);
}

Expand Down Expand Up @@ -324,14 +326,20 @@ else if (lmEntity.isBabyMob()) {
}

private static boolean shouldDenyLevel(final @NotNull LivingEntityWrapper lmEntity, final int levelAssignment){
final boolean result =
boolean result =
lmEntity.reEvaluateLevel &&
!lmEntity.isRulesForceAll &&
lmEntity.playerLevellingAllowDecrease != null &&
!lmEntity.playerLevellingAllowDecrease &&
lmEntity.isLevelled() &&
levelAssignment < lmEntity.getMobLevel();

if (result){
synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) {
result = lmEntity.getPDC().has(lmEntity.getMainInstance().namespaced_keys.playerLevelling_Id, PersistentDataType.STRING);
}
}

if (!result && lmEntity.pendingPlayerIdToSet != null) {
synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) {
lmEntity.getPDC().set(lmEntity.getMainInstance().namespaced_keys.playerLevelling_Id, PersistentDataType.STRING, lmEntity.pendingPlayerIdToSet);
Expand Down
49 changes: 32 additions & 17 deletions src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.lokka30.levelledmobs.LevelInterface;
import me.lokka30.levelledmobs.LevelledMobs;
import me.lokka30.levelledmobs.LivingEntityInterface;
import me.lokka30.levelledmobs.compatibility.Compat1_17;
import me.lokka30.levelledmobs.customdrops.CustomDropResult;
import me.lokka30.levelledmobs.events.MobPostLevelEvent;
import me.lokka30.levelledmobs.events.MobPreLevelEvent;
Expand All @@ -19,14 +20,23 @@
import me.lokka30.levelledmobs.rules.strategies.SpawnDistanceStrategy;
import me.lokka30.levelledmobs.rules.strategies.YDistanceStrategy;
import me.lokka30.microlib.messaging.MessageUtils;
import me.lokka30.microlib.other.VersionUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.*;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.Zombie;
import org.bukkit.inventory.AbstractHorseInventory;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -63,13 +73,26 @@ public LevelManager(final LevelledMobs main) {
Material.GOLDEN_HORSE_ARMOR,
Material.DIAMOND_HORSE_ARMOR
);

this.FORCED_BLOCKED_ENTITY_TYPES = new HashSet<>(Arrays.asList(
EntityType.AREA_EFFECT_CLOUD, EntityType.ARMOR_STAND, EntityType.ARROW, EntityType.BOAT,
EntityType.DRAGON_FIREBALL, EntityType.DROPPED_ITEM, EntityType.EGG, EntityType.ENDER_CRYSTAL,
EntityType.ENDER_PEARL, EntityType.ENDER_SIGNAL, EntityType.EXPERIENCE_ORB, EntityType.FALLING_BLOCK,
EntityType.FIREBALL, EntityType.FIREWORK, EntityType.FISHING_HOOK,
EntityType.ITEM_FRAME, EntityType.LEASH_HITCH, EntityType.LIGHTNING, EntityType.LLAMA_SPIT,
EntityType.MINECART, EntityType.MINECART_CHEST, EntityType.MINECART_COMMAND, EntityType.MINECART_FURNACE,
EntityType.MINECART_HOPPER, EntityType.MINECART_MOB_SPAWNER, EntityType.MINECART_TNT, EntityType.PAINTING,
EntityType.PRIMED_TNT, EntityType.SMALL_FIREBALL, EntityType.SNOWBALL, EntityType.SPECTRAL_ARROW,
EntityType.SPLASH_POTION, EntityType.THROWN_EXP_BOTTLE,EntityType.TRIDENT, EntityType.UNKNOWN,
EntityType.WITHER_SKULL, EntityType.SHULKER_BULLET, EntityType.PLAYER
));
if (VersionUtils.isOneSeventeen())
this.FORCED_BLOCKED_ENTITY_TYPES.addAll(Compat1_17.getForceBlockedEntityType());

}

private final LevelledMobs main;
private final List<Material> vehicleNoMultiplierItems;
public double attributeMaxHealthMax = 2048.0;
public double attributeMovementSpeedMax = 2048.0;
public double attributeAttackDamageMax = 2048.0;
public final Map<LivingEntity, Object> summonedOrSpawnEggs;
public static final Object summonedOrSpawnEggs_Lock = new Object();
private boolean hasMentionedNBTAPI_Missing;
Expand All @@ -78,18 +101,8 @@ public LevelManager(final LevelledMobs main) {

/**
* The following entity types *MUST NOT* be levellable.
* Stored as Strings since older versions may not contain certain entity type constants
*/
public final HashSet<String> FORCED_BLOCKED_ENTITY_TYPES = new HashSet<>(Arrays.asList(
"AREA_EFFECT_CLOUD", "ARMOR_STAND", "ARROW", "BOAT", "DRAGON_FIREBALL", "DROPPED_ITEM",
"EGG", "ENDER_CRYSTAL", "ENDER_PEARL", "ENDER_SIGNAL", "EXPERIENCE_ORB",
"FALLING_BLOCK", "FIREBALL", "FIREWORK", "FISHING_HOOK", "GLOW_ITEM_FRAME",
"ITEM_FRAME", "LEASH_HITCH", "LIGHTNING", "LLAMA_SPIT", "MARKER", "MINECART",
"MINECART_CHEST", "MINECART_COMMAND", "MINECART_FURNACE", "MINECART_HOPPER",
"MINECART_MOB_SPAWNER", "MINECART_TNT", "NPC", "PAINTING", "PLAYER", "PRIMED_TNT",
"SMALL_FIREBALL", "SNOWBALL", "SPECTRAL_ARROW", "SPLASH_POTION", "THROWN_EXP_BOTTLE",
"TRIDENT", "UNKNOWN", "WITHER_SKULL"
));
public final HashSet<EntityType> FORCED_BLOCKED_ENTITY_TYPES;

public void clearRandomLevellingCache(){
this.randomLevellingCache.clear();
Expand Down Expand Up @@ -179,7 +192,7 @@ private int generateRandomLevel(RandomLevellingStrategy randomLevelling, final i
int levelSource;
final String variableToUse = Utils.isNullOrEmpty(options.variable) ? "%level%" : options.variable;
final double scale = options.playerLevelScale != null ? options.playerLevelScale : 1.0;
final boolean usePlayerMax = options.usePlayerMaxLevel != null && options.matchPlayerLevel;
final boolean usePlayerMax = options.usePlayerMaxLevel != null && options.usePlayerMaxLevel;
final boolean matchPlayerLvl = options.matchPlayerLevel != null && options.matchPlayerLevel;
final PlayerLevelSourceResult playerLevelSourceResult = getPlayerLevelSourceNumber(lmEntity.getPlayerForLevelling(), variableToUse);
final double origLevelSource = playerLevelSourceResult.isNumericResult ? playerLevelSourceResult.numericResult : 1;
Expand Down Expand Up @@ -756,6 +769,8 @@ private void runNametagCheck_aSync(final @NotNull Map<Player,List<Entity>> entit

// Mob must be a livingentity that is ...living.
if (!(entity instanceof LivingEntity) || entity instanceof Player || !entity.isValid()) continue;
// this is mostly so for spawner mobs and spawner egg mobs as they have a 20 tick delay in before proessing
if (entity.getTicksLived() < 30) continue;

boolean wrapperHasReference = false;
final LivingEntityWrapper lmEntity = LivingEntityWrapper.getInstance((LivingEntity) entity, main);
Expand Down Expand Up @@ -1060,7 +1075,7 @@ public LevellableState getLevellableState(@NotNull final LivingEntityInterface l
This is also ran in getLevellableState(EntityType), however it is important that this is ensured
before all other checks are made.
*/
if (FORCED_BLOCKED_ENTITY_TYPES.contains(lmInterface.getTypeName()))
if (FORCED_BLOCKED_ENTITY_TYPES.contains(lmInterface.getEntityType()))
return LevellableState.DENIED_FORCE_BLOCKED_ENTITY_TYPE;

if (lmInterface.getApplicableRules().isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* @since 2.6.0
*/
public enum CustomUniversalGroups {
NOT_APPLICABLE,
ALL_MOBS,
ALL_LEVELLABLE_MOBS,
ALL_HOSTILE_MOBS,
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/me/lokka30/levelledmobs/misc/LevellableState.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,12 @@ public enum LevellableState {
*/
DENIED_FORCE_BLOCKED_ENTITY_TYPE,

/**
* settings.yml has been configured to block mobs
* spawning in entity's world from being levelled
*/
DENIED_CONFIGURATION_BLOCKED_WORLD,

/**
* settings.yml has been configured to block mobs
* of such entity type from being levelled
*/
DENIED_CONFIGURATION_BLOCKED_ENTITY_TYPE,

/**
* settings.yml has been configured to block mobs
* that spawn with a specific SpawnReason through
* CreatureSpawnEvent.
*/
DENIED_CONFIGURATION_BLOCKED_SPAWN_REASON,

/**
* settings.yml has been configured to block
* DangerousCaves mobs from being levelled.
Expand Down Expand Up @@ -94,12 +81,6 @@ public enum LevellableState {
*/
DENIED_CONFIGURATION_COMPATIBILITY_SIMPLEPETS,

/**
* WorldGuard region flag states that
* mobs are not levellable in its region
*/
DENIED_CONFIGURATION_COMPATIBILITY_WORLD_GUARD,

/**
* A rule has been configured to block
* nametagged mobs from being levelled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ public EntityType getEntityType() {
return main.rulesManager.getApplicableRules(this).allApplicableRules;
}

public ApplicableRulesResult getRules(){
return main.rulesManager.getApplicableRules(this);
}

@NotNull
public String getTypeName(){
return this.entityType.name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* @since 3.0.0
*/
public class FineTuningAttributes implements Cloneable {
EntityType applicableEntity;

public Double attackDamage;
public Double creeperExplosionRadius;
public Double maxHealth;
Expand Down
Loading

0 comments on commit b00a5fc

Please sign in to comment.