Skip to content

Commit

Permalink
Merge pull request #236 from lokka30/3.0-dev
Browse files Browse the repository at this point in the history
3.0 dev
  • Loading branch information
lokka30 authored Jun 28, 2021
2 parents 5bfd882 + f6a9afc commit e69430f
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 109 deletions.
30 changes: 28 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
# Changelog

***

## v3.0.4 b444

* @stumper66 fixed exception when using lower-mob-level-bias-factor
* @stumper66 added back in lower-mob-level-bias-factor
* @stumper66 fixed custom commands not respecting min and max level restrictions
* @stumper66 adjusted the attribute multiplier slightly
* @stumper66 fixed low level skeletons doing no or little damage with arrows
* @stumper66 fixed enchanted books now work properly with custom drops
* @lokka30 updated MicroLib shaded dep
* @lokka30 cleaned up MC1.17Compat class

***

## v3.0.3 b439

* @stumper66 made minLevel and maxLevel casing possible in customdrops.yml
* @stumper66 fixed shields not blocking damage in certain scenarios
* @lokka30 updated MicroLib & bStats inbuilt deps.
* @lokka30 fixed old groupid being used in inbuilt pom.xml

***

## v3.0.0 b425

* New modular rules system. Make your own customized rule set as broad or as specific as you want. How it works:
* Modify the default rules to apply general rules
* Create custom rules by creating conditions that must be met to apply the rule. Once met then apply any number of constraints, attributes, modifiers and more
* Create custom rules by creating conditions that must be met to apply the rule. Once met then apply any number of
constraints, attributes, modifiers and more
* Create and pick rule presets to avoid repetitiveness and to ease readability.
* New Levelled Spawners. Use a command to create a spawner that creates LevelledMobs only in a specific level or range of levels.
* New Levelled Spawners. Use a command to create a spawner that creates LevelledMobs only in a specific level or range
of levels.
* New mob commands. Run commands when a mob is killed. Can have specific conditions and placeholders are provided
* New customdrops features: drop mob heads, custom mob head textures, overall chance, player caused only option
* New option sunlight-intensity: have mobs burn in the daylight faster
Expand Down
13 changes: 4 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.github.lokka30</groupId>
<groupId>me.lokka30</groupId>
<artifactId>LevelledMobs</artifactId>
<version>3.0.3 b438</version>
<version>3.0.4 b444</version>
<packaging>jar</packaging>

<name>LevelledMobs</name>
Expand Down Expand Up @@ -95,11 +95,6 @@
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>nexus</id>
<name>Lumine Releases</name>
<url>https://mvn.lumine.io/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -124,7 +119,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.7</version>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -136,7 +131,7 @@
<dependency>
<groupId>com.github.lokka30</groupId>
<artifactId>MicroLib</artifactId>
<version>bf026b06</version> <!-- v2.2.0 -->
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.github.dmulloy2</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lokka30/levelledmobs/Companion.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private void buildUniversalGroups(){
EntityType.SNOWMAN
).collect(Collectors.toCollection(HashSet::new));

if (MC1_17_Compat.isServer1_17OrNewer())
if (VersionUtils.isOneSeventeen())
groups_PassiveMobs.addAll(MC1_17_Compat.getPassiveMobs());

if (VersionUtils.isOneSixteen())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@
* @author stumper66
*/
public class MC1_17_Compat {
public static boolean isServer1_17OrNewer() {
boolean result = true;
try{
EntityType.valueOf("AXOLOTL");
}
catch (IllegalArgumentException ignored) {
result = false;
}

return result;
}

public static HashSet<EntityType> getPassiveMobs() {
return Stream.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,14 @@ private void getDropsFromCustomDropItem(@NotNull final CustomDropProcessingInfo

boolean doDrop = dropBase.maxLevel <= -1 || info.lmEntity.getMobLevel() <= dropBase.maxLevel;
if (dropBase.minLevel > -1 && info.lmEntity.getMobLevel() < dropBase.minLevel) doDrop = false;
if (!doDrop && dropBase instanceof CustomDropItem){
final CustomDropItem dropItem = (CustomDropItem) dropBase;
if (!info.equippedOnly && main.settingsCfg.getStringList("debug-misc").contains("CUSTOM_DROPS")) {
final ItemStack itemStack = info.deathByFire ? getCookedVariantOfMeat(dropItem.getItemStack()) : dropItem.getItemStack();
Utils.logger.info(String.format("&8- &7level: &b%s&7, fromSpawner: &b%s&7, item: &b%s&7, minL: &b%s&7, maxL: &b%s&7, nospawner: &b%s&7, dropped: &bfalse",
info.lmEntity.getMobLevel(), info.isSpawner, itemStack.getType().name(), dropBase.minLevel, dropBase.maxLevel, dropBase.noSpawner));
if (!doDrop){
if (dropBase instanceof CustomDropItem) {
final CustomDropItem dropItem = (CustomDropItem) dropBase;
if (!info.equippedOnly && main.settingsCfg.getStringList("debug-misc").contains("CUSTOM_DROPS")) {
final ItemStack itemStack = info.deathByFire ? getCookedVariantOfMeat(dropItem.getItemStack()) : dropItem.getItemStack();
Utils.logger.info(String.format("&8- &7level: &b%s&7, fromSpawner: &b%s&7, item: &b%s&7, minL: &b%s&7, maxL: &b%s&7, nospawner: &b%s&7, dropped: &bfalse",
info.lmEntity.getMobLevel(), info.isSpawner, itemStack.getType().name(), dropBase.minLevel, dropBase.maxLevel, dropBase.noSpawner));
}
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -364,8 +365,17 @@ private void parseCustomDropsAttributes(@NotNull final CustomDropBase dropBase,
enchantLevel = Integer.parseInt(value.toString());

final Enchantment en = Enchantment.getByKey(NamespacedKey.minecraft(enchantName.toLowerCase()));
if (en != null)
item.getItemStack().addUnsafeEnchantment(en, enchantLevel);
if (en != null) {
if (item.getMaterial().equals(Material.ENCHANTED_BOOK)){
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemStack().getItemMeta();
if (meta != null) {
meta.addStoredEnchant(en, enchantLevel, true);
item.getItemStack().setItemMeta(meta);
}
}
else
item.getItemStack().addUnsafeEnchantment(en, enchantLevel);
}
else
Utils.logger.warning("Invalid enchantment: " + enchantName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public EntityDamageListener(final LevelledMobs main) {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onDamage(@NotNull final EntityDamageEvent event) {
if (!(event.getEntity() instanceof LivingEntity)) return;
if (event.getFinalDamage() == 0.0) return;

final LivingEntityWrapper lmEntity = new LivingEntityWrapper((LivingEntity) event.getEntity(), main);

Expand All @@ -44,6 +45,8 @@ public void onDamage(@NotNull final EntityDamageEvent event) {
// Check for levelled ranged damage.
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onRangedDamage(final EntityDamageByEntityEvent event) {
if (event.getFinalDamage() == 0.0) return;

processRangedDamage(event);
processOtherRangedDamage(event);
}
Expand All @@ -63,8 +66,9 @@ private void processRangedDamage(@NotNull final EntityDamageByEntityEvent event)
Utils.debugLog(main, DebugType.RANGED_DAMAGE_MODIFICATION, "Range attack damage modified for &b" + shooter.getLivingEntity().getName() + "&7:");
Utils.debugLog(main, DebugType.RANGED_DAMAGE_MODIFICATION, "Previous rangedDamage: &b" + event.getDamage());
//final int level = shooter.getMobLevel();
event.setDamage(main.mobDataManager.getAdditionsForLevel(shooter, Addition.CUSTOM_RANGED_ATTACK_DAMAGE, event.getDamage()));
Utils.debugLog(main, DebugType.RANGED_DAMAGE_MODIFICATION, "New rangedDamage: &b" + event.getDamage());
final double newDamage = event.getDamage() + main.mobDataManager.getAdditionsForLevel(shooter, Addition.CUSTOM_RANGED_ATTACK_DAMAGE, event.getDamage());
event.setDamage(newDamage);
Utils.debugLog(main, DebugType.RANGED_DAMAGE_MODIFICATION, "New rangedDamage: &b" + newDamage);
}

private void processOtherRangedDamage(@NotNull final EntityDamageByEntityEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public void onEntitySpawn(@NotNull final EntitySpawnEvent event) {

final LivingEntityWrapper lmEntity = new LivingEntityWrapper((LivingEntity) event.getEntity(), main);

if (event instanceof CreatureSpawnEvent && ((CreatureSpawnEvent) event).getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM)){
if (event instanceof CreatureSpawnEvent && ((CreatureSpawnEvent) event).getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM)) {
delayedAddToQueue(lmEntity, event, 20);
return;
}

int mobProcessDelay = main.settingsCfg.getInt("mob-process-delay", 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ public int generateLevel(final LivingEntityWrapper lmEntity, final int minLevel_
return minLevel;

final LevelNumbersWithBias levelNumbersWithBias = main.rulesManager.getRule_LowerMobLevelBiasFactor(lmEntity, minLevel, maxLevel);
if (levelNumbersWithBias != null)
if (levelNumbersWithBias != null) {
if (levelNumbersWithBias.isEmpty()) levelNumbersWithBias.populateData();
return levelNumbersWithBias.getNumberWithinLimits();
}

return ThreadLocalRandom.current().nextInt(minLevel, maxLevel + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ public final double getAdditionsForLevel(final LivingEntityWrapper lmEntity, fin
return attributeValue * (((double) lmEntity.getMobLevel() - 1)/ maxLevel);

// use revised formula for all attributes
return (defaultValue * attributeValue) * ((lmEntity.getMobLevel() - 1) / maxLevel);
return (defaultValue * attributeValue) * ((lmEntity.getMobLevel() - 1) / (maxLevel - 1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,19 @@ private void updateNametag(final @NotNull LivingEntityWrapper lmEntity, final St
final WrappedDataWatcher.WrappedDataWatcherObject watcherObject = new WrappedDataWatcher.WrappedDataWatcherObject(2, chatSerializer);

Optional<Object> optional;
if (Utils.isNullOrEmpty(nametag))
if (Utils.isNullOrEmpty(nametag)) {
optional = Optional.empty();
else
} else {
optional = Optional.of(WrappedChatComponent.fromChatMessage(nametag)[0].getHandle());
}

dataWatcher.setObject(watcherObject, optional);
if (nametag == null)
if (nametag == null) {
dataWatcher.setObject(3, false);
else
} else {
dataWatcher.setObject(3, !"".equals(nametag) && lmEntity.getLivingEntity().isCustomNameVisible() ||
main.rulesManager.getRule_CreatureNametagAlwaysVisible(lmEntity));
}

final PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet.getWatchableCollectionModifier().write(0, dataWatcher.getWatchableObjects());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/lokka30/levelledmobs/misc/FileMigrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public static void migrateSettingsToRules(@NotNull final LevelledMobs main){
final File backedupFile = new File(main.getDataFolder(), "rules.yml.old");
FileUtil.copy(fileRules, backedupFile);

final int worldListAllowedLine = 991;
final int worldListExcludedLine = 992;
final int worldListAllowedLine = 992;
final int worldListExcludedLine = 993;

final YamlConfiguration settings = YamlConfiguration.loadConfiguration(fileSettings);
final YamlConfiguration rules = YamlConfiguration.loadConfiguration(fileRules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public int getFactor(){
return factor;
}

public boolean isEmpty(){
return this.numberList.isEmpty();
}

public void populateData(){
if (!this.numberList.isEmpty()) this.numberList.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ private void parseApplySettings(final ConfigurationSection cs){
parsingInfo.CreatureNametagAlwaysVisible = cs.getBoolean("creature-nametag-always-visible");
if (cs.getString("sunlight-intensity") != null)
parsingInfo.sunlightBurnAmount = cs.getDouble("sunlight-intensity");
if (cs.getString("lower-mob-level-bias-factor") != null)
parsingInfo.lowerMobLevelBiasFactor = cs.getInt("lower-mob-level-bias-factor");
}

private void parseConditions(final ConfigurationSection conditions){
Expand Down
Loading

0 comments on commit e69430f

Please sign in to comment.