Skip to content

Commit

Permalink
Merge pull request #436 from ArcanePlugins/3.9-dev
Browse files Browse the repository at this point in the history
3.9 dev
  • Loading branch information
lokka30 authored Dec 20, 2022
2 parents 120fafd + e7b34b5 commit 82a59e3
Show file tree
Hide file tree
Showing 18 changed files with 950 additions and 532 deletions.
43 changes: 2 additions & 41 deletions 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.8.2 b721</version>
<version>3.9.0 b727</version>
<packaging>jar</packaging>
<name>LevelledMobs</name>
<description>The Ultimate RPG Mob Levelling Plugin</description>
Expand All @@ -33,38 +33,6 @@
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.19.2-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:jar:remapped-mojang
</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>
${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.19.2-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:jar:remapped-obf
</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -188,13 +156,6 @@
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
Expand Down Expand Up @@ -228,7 +189,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<version>2.10</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/me/lokka30/levelledmobs/LevelledMobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import me.lokka30.levelledmobs.misc.NamespacedKeys;
import me.lokka30.levelledmobs.misc.NametagTimerChecker;
import me.lokka30.levelledmobs.misc.YmlParsingHelper;
import me.lokka30.levelledmobs.nms.Definitions;
import me.lokka30.levelledmobs.rules.RulesManager;
import me.lokka30.levelledmobs.rules.RulesParsingManager;
import me.lokka30.levelledmobs.util.ConfigUtils;
Expand Down Expand Up @@ -76,6 +77,7 @@ public final class LevelledMobs extends JavaPlugin {
public YmlParsingHelper helperSettings;
public long playerLevellingMinRelevelTime;
public int maxPlayersRecorded;
private Definitions definitions;
private static LevelledMobs instance;

// Configuration
Expand All @@ -101,6 +103,7 @@ public void onLoad() {
public void onEnable() {
final QuickTimer timer = new QuickTimer();

this.definitions = new Definitions();
this.nametagQueueManager = new NametagQueueManager(this);
this.mobsQueueManager = new MobsQueueManager(this);
this.companion = new Companion(this);
Expand Down Expand Up @@ -207,6 +210,10 @@ public static LevelledMobs getInstance(){
return instance;
}

public @NotNull Definitions getDefinitions(){
return this.definitions;
}

@Override
public void onDisable() {
final QuickTimer disableTimer = new QuickTimer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void forceRelevel(final CommandSender sender) {
for (final World world : Bukkit.getWorlds()) {
worldCount++;
for (final Entity entity : world.getEntities()) {
if (!(entity instanceof LivingEntity)) {
if (!(entity instanceof LivingEntity) || entity instanceof Player) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ private void processRangedDamage2(@NotNull final LivingEntityWrapper shooter,
main.mobsQueueManager.addToQueue(new QueueItem(shooter, event));
}

final double newDamage =
event.getDamage() + main.mobDataManager.getAdditionsForLevel(shooter,
Addition.CUSTOM_RANGED_ATTACK_DAMAGE, event.getDamage());
final float newDamage =
(float) event.getDamage() + main.mobDataManager.getAdditionsForLevel(shooter,
Addition.CUSTOM_RANGED_ATTACK_DAMAGE, (float) event.getDamage());
Utils.debugLog(main, DebugType.RANGED_DAMAGE_MODIFICATION, String.format(
"&7Source: &b%s&7 (lvl &b%s&7), damage: &b%s&7, new damage: &b%s&7",
shooter.getNameIfBaby(), shooter.getMobLevel(), event.getDamage(), newDamage));
Expand Down Expand Up @@ -238,7 +238,7 @@ private void processOtherRangedDamage(@NotNull final EntityDamageByEntityEvent e
final LivingEntityWrapper lmEntity = LivingEntityWrapper.getInstance(livingEntity, main);
event.setDamage(
main.mobDataManager.getAdditionsForLevel(lmEntity, Addition.CUSTOM_RANGED_ATTACK_DAMAGE,
event.getDamage())); // use ranged attack damage value
(float) event.getDamage())); // use ranged attack damage value
Utils.debugLog(main, DebugType.RANGED_DAMAGE_MODIFICATION,
"New guardianDamage: &b" + event.getDamage());
lmEntity.free();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public void setLevelledItemDrops(final LivingEntityWrapper lmEntity,
if (!doNotMultiplyDrops && !dropsToMultiply.isEmpty()) {
// Get currentDrops added per level valu
final double additionValue = main.mobDataManager.getAdditionsForLevel(lmEntity,
Addition.CUSTOM_ITEM_DROP, 2.0);
Addition.CUSTOM_ITEM_DROP, 2.0f);
if (additionValue == -1) {
Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, String.format(
"&7Mob: &b%s&7, mob-lvl: &b%s&7, removing any drops present",
Expand Down Expand Up @@ -611,7 +611,7 @@ public void multiplyDrop(final LivingEntityWrapper lmEntity,
// look thru the animal's inventory for leather. That is the only item that will get duplicated
for (final ItemStack item : chestItems) {
if (item.getType() == Material.LEATHER) {
return Collections.singletonList(item);
return List.of(item);
}
}

Expand Down Expand Up @@ -669,7 +669,7 @@ public void removeVanillaDrops(@NotNull final LivingEntityWrapper lmEntity,
public int getLevelledExpDrops(@NotNull final LivingEntityWrapper lmEntity, final double xp) {
if (lmEntity.isLevelled()) {
final double dropAddition = main.mobDataManager.getAdditionsForLevel(lmEntity,
Addition.CUSTOM_XP_DROP, 3.0);
Addition.CUSTOM_XP_DROP, 3.0f);
double newXp = 0;
if (dropAddition > -1) {
newXp = Math.round(xp + (xp * dropAddition));
Expand Down Expand Up @@ -1145,7 +1145,7 @@ private void checkLevelledEntity(@NotNull final LivingEntityWrapper lmEntity,
final boolean preserveMobName = !main.nametagQueueManager.nmsHandler.isUsingProtocolLib;
final NametagResult nametag = main.levelManager.getNametag(lmEntity, false, preserveMobName);
main.nametagQueueManager.addToQueue(
new QueueItem(lmEntity, nametag, Collections.singletonList(player)));
new QueueItem(lmEntity, nametag, List.of(player)));
}
}

Expand Down
144 changes: 37 additions & 107 deletions src/main/java/me/lokka30/levelledmobs/managers/MobDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import me.lokka30.levelledmobs.misc.CachedModalList;
import me.lokka30.levelledmobs.misc.DebugType;
import me.lokka30.levelledmobs.misc.LivingEntityWrapper;
import me.lokka30.levelledmobs.rules.FineTuningAttributes;
import me.lokka30.levelledmobs.rules.VanillaBonusEnum;
import me.lokka30.levelledmobs.util.Utils;
import org.bukkit.Material;
Expand Down Expand Up @@ -90,9 +91,9 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity,
final @NotNull Attribute attribute, final Addition addition) {
final boolean useStaticValues = main.helperSettings.getBoolean(main.settingsCfg,
"attributes-use-preset-base-values");
final double defaultValue = useStaticValues ?
(double) Objects.requireNonNull(getAttributeDefaultValue(lmEntity, attribute)) :
Objects.requireNonNull(lmEntity.getLivingEntity().getAttribute(attribute))
final float defaultValue = useStaticValues ?
(float) Objects.requireNonNull(getAttributeDefaultValue(lmEntity, attribute)) :
(float) Objects.requireNonNull(lmEntity.getLivingEntity().getAttribute(attribute))
.getBaseValue();
final double additionValue = getAdditionsForLevel(lmEntity, addition, defaultValue);

Expand Down Expand Up @@ -172,115 +173,44 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity,
}
}

public final double getAdditionsForLevel(final LivingEntityWrapper lmEntity,
final Addition addition, final double defaultValue) {
final double maxLevel = main.rulesManager.getRuleMobMaxLevel(lmEntity);

double attributeValue = 0;
double attributeMax = 0;

if (lmEntity.getFineTuningAttributes() != null) {
switch (addition) {
case CUSTOM_XP_DROP:
if (lmEntity.getFineTuningAttributes().xpDrop != null) {
attributeValue = lmEntity.getFineTuningAttributes().xpDrop;
}
if (attributeValue == -1.0) {
return -1;
}
break;
case CUSTOM_ITEM_DROP:
if (lmEntity.getFineTuningAttributes().itemDrop != null) {
attributeValue = lmEntity.getFineTuningAttributes().itemDrop;
}
if (attributeValue == -1.0) {
return -1;
}
break;
case ATTRIBUTE_MAX_HEALTH:
if (lmEntity.getFineTuningAttributes().maxHealth != null) {
attributeValue = lmEntity.getFineTuningAttributes().maxHealth;
}
break;
case ATTRIBUTE_ATTACK_DAMAGE:
if (lmEntity.getFineTuningAttributes().attackDamage != null) {
attributeValue = lmEntity.getFineTuningAttributes().attackDamage;
}
break;
case ATTRIBUTE_MOVEMENT_SPEED:
if (lmEntity.getFineTuningAttributes().movementSpeed != null) {
attributeValue = lmEntity.getFineTuningAttributes().movementSpeed;
}
break;
case CUSTOM_RANGED_ATTACK_DAMAGE:
if (lmEntity.getFineTuningAttributes().rangedAttackDamage != null) {
attributeValue = lmEntity.getFineTuningAttributes().rangedAttackDamage;
}
break;
case CREEPER_BLAST_DAMAGE:
if (lmEntity.getFineTuningAttributes().creeperExplosionRadius != null) {
attributeValue = lmEntity.getFineTuningAttributes().creeperExplosionRadius;
}
break;
case ATTRIBUTE_HORSE_JUMP_STRENGTH:
if (lmEntity.getFineTuningAttributes().horseJumpStrength != null) {
attributeValue = lmEntity.getFineTuningAttributes().horseJumpStrength;
}
break;
case ATTRIBUTE_ARMOR_BONUS:
attributeMax = 30.0;
if (lmEntity.getFineTuningAttributes().armorBonus != null) {
attributeValue = lmEntity.getFineTuningAttributes().armorBonus;
}
break;
case ATTRIBUTE_ARMOR_TOUGHNESS:
attributeMax = 50.0;
if (lmEntity.getFineTuningAttributes().armorToughness != null) {
attributeValue = lmEntity.getFineTuningAttributes().armorToughness;
}
break;
case ATTRIBUTE_ATTACK_KNOCKBACK:
attributeMax = 5.0;
if (lmEntity.getFineTuningAttributes().attackKnockback != null) {
attributeValue = lmEntity.getFineTuningAttributes().attackKnockback;
}
break;
case ATTRIBUTE_FLYING_SPEED:
if (lmEntity.getFineTuningAttributes().flyingSpeed != null) {
attributeValue = lmEntity.getFineTuningAttributes().flyingSpeed;
}
break;
case ATTRIBUTE_KNOCKBACK_RESISTANCE:
attributeMax = 1.0;
if (lmEntity.getFineTuningAttributes().knockbackResistance != null) {
attributeValue = lmEntity.getFineTuningAttributes().knockbackResistance;
}
break;
case ATTRIBUTE_ZOMBIE_SPAWN_REINFORCEMENTS:
attributeMax = 1.0;
if (lmEntity.getFineTuningAttributes().zombieReinforcements != null) {
attributeValue = lmEntity.getFineTuningAttributes().zombieReinforcements;
}
break;
case ATTRIBUTE_FOLLOW_RANGE:
if (lmEntity.getFineTuningAttributes().followRange != null) {
attributeValue = lmEntity.getFineTuningAttributes().followRange;
}
break;
public final float getAdditionsForLevel(final LivingEntityWrapper lmEntity,
final Addition addition, final float defaultValue) {
final float maxLevel = main.rulesManager.getRuleMobMaxLevel(lmEntity);

//double attributeValue = 0;
final FineTuningAttributes fineTuning = lmEntity.getFineTuningAttributes();
FineTuningAttributes.Multiplier multiplier = null;
float attributeMax = 0;

if (fineTuning != null) {
multiplier = fineTuning.getItem(addition);
switch (addition){
case ATTRIBUTE_ARMOR_BONUS -> attributeMax = 30.0f;
case ATTRIBUTE_ARMOR_TOUGHNESS -> attributeMax = 50.0f;
case ATTRIBUTE_ATTACK_KNOCKBACK -> attributeMax = 5.0f;
case ATTRIBUTE_KNOCKBACK_RESISTANCE,
ATTRIBUTE_ZOMBIE_SPAWN_REINFORCEMENTS -> attributeMax = 1.0f;
}
}

if (maxLevel == 0 || attributeValue == 0) {
return 0.0;
if (maxLevel == 0 || multiplier == null) {
return 0.0f;
}

// only used for 5 specific attributes
if (attributeMax > 0.0) {
return (lmEntity.getMobLevel() / maxLevel) * (attributeMax * attributeValue);
} else
// normal formula for most attributes
{
return (defaultValue * attributeValue) * ((lmEntity.getMobLevel()) / maxLevel);
final float multiplierValue = multiplier.value();

if (fineTuning.useStacked || multiplier.useStacked()){
return (float) lmEntity.getMobLevel() * multiplierValue;
}
else {
// only used for 5 specific attributes
if (attributeMax > 0.0) {
return (lmEntity.getMobLevel() / maxLevel) * (attributeMax * multiplierValue);
} else
// normal formula for most attributes
{
return (defaultValue * multiplierValue) * ((lmEntity.getMobLevel()) / maxLevel);
}
}
}
}
Loading

0 comments on commit 82a59e3

Please sign in to comment.