Skip to content

Commit

Permalink
Merge pull request #416 from lokka30/3.7-dev
Browse files Browse the repository at this point in the history
3.7 dev
  • Loading branch information
lokka30 authored Sep 29, 2022
2 parents b7a3ce4 + 7f420da commit bda4615
Show file tree
Hide file tree
Showing 17 changed files with 348 additions and 149 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.3 b701</version>
<version>3.7.4 b708</version>
<packaging>jar</packaging>
<name>LevelledMobs</name>
<description>The Ultimate RPG Mob Levelling Plugin</description>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/me/lokka30/levelledmobs/Companion.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import me.lokka30.levelledmobs.misc.FileLoader;
import me.lokka30.levelledmobs.misc.FileMigrator;
import me.lokka30.levelledmobs.misc.VersionInfo;
import me.lokka30.levelledmobs.nms.ServerVersionInfo;
import me.lokka30.levelledmobs.rules.MetricsInfo;
import me.lokka30.levelledmobs.util.Utils;
import me.lokka30.microlib.exceptions.OutdatedServerVersionException;
Expand Down Expand Up @@ -571,6 +572,7 @@ void shutDownAsyncTasks() {
}

private void buildUniversalGroups() {
final ServerVersionInfo versionInfo = main.nametagQueueManager.nmsHandler.versionInfo;

// include interfaces: Monster, Boss
hostileMobsGroup = Stream.of(
Expand All @@ -595,14 +597,14 @@ private void buildUniversalGroups() {
if (VersionUtils.isOneSeventeen()) {
passiveMobsGroup.addAll(Compat1_17.getPassiveMobs());
}
if (main.nametagQueueManager.nmsHandler.minecraftVersion >= 1.19) {
if (versionInfo.getMajorVersion() >= 1.19) {
passiveMobsGroup.addAll(Compat1_19.getPassiveMobs());
}

if (main.nametagQueueManager.nmsHandler.minecraftVersion >= 1.16) {
if (versionInfo.getMajorVersion() >= 1.16) {
hostileMobsGroup.addAll(Compat1_16.getHostileMobs());
}
if (main.nametagQueueManager.nmsHandler.minecraftVersion >= 1.19) {
if (versionInfo.getMajorVersion() >= 1.19) {
hostileMobsGroup.addAll(Compat1_19.getHostileMobs());
}

Expand All @@ -614,7 +616,7 @@ private void buildUniversalGroups() {
EntityType.TURTLE
).collect(Collectors.toCollection(HashSet::new));

if (main.nametagQueueManager.nmsHandler.minecraftVersion >= 1.19) {
if (versionInfo.getMajorVersion() >= 1.19) {
aquaticMobsGroup.addAll(Compat1_19.getAquaticMobs());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void parseSubcommand(final LevelledMobs main, final @NotNull CommandSende
} else if ("chunk_kill_count".equalsIgnoreCase(args[1])) {
chunkKillCount(sender, args);
} else if ("nbt_dump".equalsIgnoreCase(args[1])) {
if ("unknown".equals(main.nametagQueueManager.nmsHandler.nmsVersionString)){
if (!main.nametagQueueManager.nmsHandler.versionInfo.isNMSVersionValid()){
sender.sendMessage("Unable to dump, an unknown NMS version was detected");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CustomDropProcessingInfo {
}

public LivingEntityWrapper lmEntity;
int addition;
double addition;
Player mobKiller;
@NotNull final Map<String, Integer> playerLevelVariableCache;
boolean isSpawner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No
}

String mobKey = null;
Component itemComp = null;
for (final Component c : tc.args()){
if (c instanceof final TranslatableComponent tc2) {
mobKey = tc2.key();
break;
if ("chat.square_brackets".equals(tc2.key())) {
// this is when the mob was holding a weapon
itemComp = tc2;
}
else {
mobKey = tc2.key();
}
}
}

Expand All @@ -135,10 +141,23 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No
Component.translatable(mobKey) :
LegacyComponentSerializer.legacyAmpersand().deserialize(nametagResult.overriddenName);

newCom = Component.translatable(tc.key(),
Component.text(playerKilled),
leftComp.append(mobNameComponent)
).append(rightComp);
if (itemComp == null) {
// mob wasn't using any weapon
// 2 arguments, example: "death.attack.mob": "%1$s was slain by %2$s"
newCom = Component.translatable(tc.key(),
Component.text(playerKilled),
leftComp.append(mobNameComponent)
).append(rightComp);
}
else {
// mob had a weapon and it's details are stored in the itemComp component
// 3 arguments, example: "death.attack.mob.item": "%1$s was slain by %2$s using %3$s"
newCom = Component.translatable(tc.key(),
Component.text(playerKilled),
leftComp.append(mobNameComponent),
itemComp
).append(rightComp);
}
}

event.deathMessage(newCom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import me.lokka30.levelledmobs.LevelledMobs;
import me.lokka30.levelledmobs.LivingEntityInterface;
import me.lokka30.levelledmobs.misc.LevellableState;
import me.lokka30.levelledmobs.misc.LivingEntityWrapper;
Expand Down Expand Up @@ -158,7 +157,7 @@ private static boolean isMobOfSimplePets(@NotNull final LivingEntityWrapper lmEn

return false;
} else {
return isSimplePets(lmEntity.getLivingEntity());
return isSimplePets(lmEntity);
}
}

Expand All @@ -177,14 +176,19 @@ private static boolean isMobOfEliteBosses(@NotNull final LivingEntityWrapper lmE
return false;
}

private static boolean isMobOfBloodNight(@NotNull final LivingEntityWrapper lmEntity) {
public static boolean isMobOfBloodNight(@NotNull final LivingEntityWrapper lmEntity) {
final Plugin plugin = Bukkit.getPluginManager().getPlugin("BloodNight");
if (plugin == null || !plugin.isEnabled()) {
return false;
}

return lmEntity.getPDC()
.has(new NamespacedKey(plugin, "mobtype"), PersistentDataType.STRING);
final boolean isBloodNightMob = lmEntity.getPDC()
.has(new NamespacedKey(plugin, "mobtype"), PersistentDataType.STRING);

if (isBloodNightMob)
lmEntity.setMobExternalType(ExternalCompatibility.BLOOD_NIGHT);

return isBloodNightMob;
}

public static boolean isMythicMob(@NotNull final LivingEntityWrapper lmEntity) {
Expand Down Expand Up @@ -220,9 +224,9 @@ public static boolean isMythicMob(@NotNull final LivingEntityWrapper lmEntity) {
return "";
}

static LevellableState checkAllExternalCompats(final LivingEntityWrapper lmEntity,
final @NotNull LevelledMobs main) {
final Map<ExternalCompatibilityManager.ExternalCompatibility, Boolean> compatRules = main.rulesManager.getRuleExternalCompatibility(
static LevellableState checkAllExternalCompats(final @NotNull LivingEntityWrapper lmEntity) {
final Map<ExternalCompatibilityManager.ExternalCompatibility, Boolean> compatRules =
lmEntity.getMainInstance().rulesManager.getRuleExternalCompatibility(
lmEntity);

if (!isExternalCompatibilityEnabled(ExternalCompatibility.DANGEROUS_CAVES, compatRules)) {
Expand Down Expand Up @@ -288,6 +292,19 @@ static LevellableState checkAllExternalCompats(final LivingEntityWrapper lmEntit
return LevellableState.ALLOWED;
}

public static void updateAllExternalCompats(final LivingEntityWrapper lmEntity) {
isMobOfDangerousCaves(lmEntity);
isMobOfEcoBosses(lmEntity);
isMobOfMythicMobs(lmEntity);
isMobOfEliteMobs(lmEntity);
isMobOfInfernalMobs(lmEntity);
isMobOfCitizens(lmEntity);
isMobOfShopkeepers(lmEntity);
isMobOfSimplePets(lmEntity);
isMobOfEliteMobs(lmEntity);
isMobOfBloodNight(lmEntity);
}

/**
* @param lmEntity mob to check
* @return if Dangerous Caves compatibility enabled and entity is from DangerousCaves
Expand Down Expand Up @@ -484,7 +501,7 @@ private static boolean isMobOfShopkeepers(final @NotNull LivingEntityWrapper lmE
user.getHomes().get(0));
}

private static boolean isSimplePets(final @NotNull LivingEntity livingEntity){
private static boolean isSimplePets(final @NotNull LivingEntityWrapper lmEntity){
try {
final Class<?> clazz_PetCore = Class.forName(
"simplepets.brainsynder.api.plugin.SimplePets");
Expand All @@ -496,10 +513,10 @@ private static boolean isSimplePets(final @NotNull LivingEntity livingEntity){
final Object objIPetsPlugin = method_getPlugin.invoke(null);

final Method method_isPetEntity = clazz_IPetsPlugin.getDeclaredMethod("isPetEntity", Entity.class);
return (boolean)method_isPetEntity.invoke(objIPetsPlugin, livingEntity);
return (boolean)method_isPetEntity.invoke(objIPetsPlugin, lmEntity.getLivingEntity());
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException |
ClassNotFoundException e) {
Utils.logger.error("Error checking if " + livingEntity.getName() + " is a SimplePet");
Utils.logger.error("Error checking if " + lmEntity.getNameIfBaby() + " is a SimplePet");
e.printStackTrace();
}

Expand Down
28 changes: 18 additions & 10 deletions src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -66,6 +67,7 @@
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Creeper;
Expand Down Expand Up @@ -576,12 +578,12 @@ public void setLevelledItemDrops(final LivingEntityWrapper lmEntity,
}

public void multiplyDrop(final LivingEntityWrapper lmEntity,
@NotNull final ItemStack currentDrop, final int addition, final boolean isCustomDrop) {
@NotNull final ItemStack currentDrop, final double addition, final boolean isCustomDrop) {
final int oldAmount = currentDrop.getAmount();

if (isCustomDrop || main.mobDataManager.isLevelledDropManaged(
lmEntity.getLivingEntity().getType(), currentDrop.getType())) {
int useAmount = currentDrop.getAmount() + (currentDrop.getAmount() * addition);
int useAmount = (int)Math.round(currentDrop.getAmount() + ((double)currentDrop.getAmount() * addition));
if (useAmount > currentDrop.getMaxStackSize()) {
useAmount = currentDrop.getMaxStackSize();
}
Expand Down Expand Up @@ -664,21 +666,21 @@ public void removeVanillaDrops(@NotNull final LivingEntityWrapper lmEntity,
}

//Calculates the XP dropped when a levellable creature dies.
public int getLevelledExpDrops(@NotNull final LivingEntityWrapper lmEntity, final int xp) {
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);
int newXp = 0;
double newXp = 0;
if (dropAddition > -1) {
newXp = (int) Math.round(xp + (xp * dropAddition));
newXp = Math.round(xp + (xp * dropAddition));
}

Utils.debugLog(main, DebugType.SET_LEVELLED_XP_DROPS,
String.format("&7Mob: &b%s&7: lvl: &b%s&7, xp-vanilla: &b%s&7, new-xp: &b%s&7",
lmEntity.getNameIfBaby(), lmEntity.getMobLevel(), xp, newXp));
return newXp;
lmEntity.getNameIfBaby(), lmEntity.getMobLevel(), xp, (int)newXp));
return (int)newXp;
} else {
return xp;
return (int)xp;
}
}

Expand Down Expand Up @@ -1454,7 +1456,7 @@ This is also ran in getLevellableState(EntityType), however it is important that
}

final LevellableState externalCompatResult = ExternalCompatibilityManager.checkAllExternalCompats(
lmEntity, main);
lmEntity);
if (externalCompatResult != LevellableState.ALLOWED) {
return externalCompatResult;
}
Expand Down Expand Up @@ -1865,7 +1867,13 @@ public void removeLevel(@NotNull final LivingEntityWrapper lmEntity) {
continue;
}

attInst.getModifiers().clear();
final Enumeration<AttributeModifier> existingMods = Collections.enumeration(attInst.getModifiers());
while (existingMods.hasMoreElements()){
final AttributeModifier existingMod = existingMods.nextElement();

if (main.mobDataManager.vanillaMultiplierNames.contains(existingMod.getName())) continue;
attInst.removeModifier(existingMod);
}
}
}

Expand Down
45 changes: 26 additions & 19 deletions src/main/java/me/lokka30/levelledmobs/managers/MobDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

package me.lokka30.levelledmobs.managers;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Objects;
import me.lokka30.levelledmobs.LevelledMobs;
Expand All @@ -27,13 +28,24 @@
* @since 2.6.0
*/
public class MobDataManager {

private final LevelledMobs main;

public MobDataManager(final LevelledMobs main) {
this.main = main;
this.vanillaMultiplierNames = List.of(
"Attacking speed boost",
"Baby speed boost",
"Covered armor bonus",
"Drinking speed penalty",
"Leader zombie bonus",
"Random spawn bonus",
"Random zombie-spawn bonus",
"Zombie reinforcement caller charge",
"Zombie reinforcement callee charge"
);
}

private final LevelledMobs main;
public final List<String> vanillaMultiplierNames;

@Nullable private Object getAttributeDefaultValue(@NotNull final LivingEntityWrapper lmEntity,
final Attribute attribute) {
if (lmEntity.isMobTamed()) {
Expand Down Expand Up @@ -74,6 +86,10 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity,
.getBaseValue();
final double additionValue = getAdditionsForLevel(lmEntity, addition, defaultValue);

if (additionValue == 0.0) {
return;
}

final AttributeModifier mod = new AttributeModifier(attribute.name(), additionValue,
AttributeModifier.Operation.ADD_NUMBER);
final AttributeInstance attrib = lmEntity.getLivingEntity().getAttribute(attribute);
Expand All @@ -96,18 +112,12 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity,
.getValue() - lmEntity.getLivingEntity().getHealth();
}

if (attrib.getModifiers().size() > 0) {
final List<AttributeModifier> existingMods = new ArrayList<>(
attrib.getModifiers().size());
existingMods.addAll(attrib.getModifiers());

for (final AttributeModifier existingMod : existingMods) {
attrib.removeModifier(existingMod);
}
}
final Enumeration<AttributeModifier> existingMods = Collections.enumeration(attrib.getModifiers());
while (existingMods.hasMoreElements()){
final AttributeModifier existingMod = existingMods.nextElement();

if (additionValue == 0.0) {
return;
if (this.vanillaMultiplierNames.contains(existingMod.getName())) continue;
attrib.removeModifier(existingMod);
}

if (useStaticValues) {
Expand Down Expand Up @@ -238,10 +248,7 @@ public final double getAdditionsForLevel(final LivingEntityWrapper lmEntity,
}
}

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

Expand Down
Loading

0 comments on commit bda4615

Please sign in to comment.