Skip to content

Commit

Permalink
Merge pull request #357 from lokka30/3.3-dev
Browse files Browse the repository at this point in the history
3.3 dev
  • Loading branch information
lokka30 authored Jan 25, 2022
2 parents c07ced6 + b0d6a98 commit 5b1a3a7
Show file tree
Hide file tree
Showing 26 changed files with 300 additions and 75 deletions.
12 changes: 0 additions & 12 deletions .idea/LevelledMobs.iml

This file was deleted.

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.2 b596</version>
<version>3.3.3 b604</version>
<packaging>jar</packaging>

<name>LevelledMobs</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ private void parseSubcommand2(final String @NotNull [] args, final boolean overr
location = (target.getLocation());
world = location.getWorld();
}
else {
location = target.getLocation();
world = target.getWorld();
}


if (offline || world == null) {
showMessage("common.player-offline", "%player%", args[5]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import me.lokka30.levelledmobs.rules.CustomDropsRuleSet;
import me.lokka30.microlib.messaging.MessageUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -33,6 +33,7 @@ class CustomDropProcessingInfo {
this.groupIDsDroppedAlready = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
this.allDropInstances = new LinkedList<>();
this.playerLevelVariableCache = new TreeMap<>();
this.stackToItem = new HashMap<>();
}

public LivingEntityWrapper lmEntity;
Expand All @@ -58,6 +59,7 @@ class CustomDropProcessingInfo {
@NotNull
final List<CustomDropInstance> allDropInstances;
private StringBuilder debugMessages;
public final Map<ItemStack, CustomDropItem> stackToItem;

void addDebugMessage(final String message){
if (this.debugMessages == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@

package me.lokka30.levelledmobs.customdrops;

import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

/**
* Used internally to determine if the mob's
* vanilla items should be removed or not
*
* @author stumper66
* @since 2.6.0
*/
public enum CustomDropResult {
HAS_OVERRIDE,
NO_OVERRIDE
public class CustomDropResult {
public CustomDropResult(final @NotNull Map<ItemStack, CustomDropItem> stackToItem, final boolean hasOverride){
this.stackToItem = stackToItem;
this.hasOverride = hasOverride;
}
public final boolean hasOverride;
public final Map<ItemStack, CustomDropItem> stackToItem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import java.util.WeakHashMap;
import java.util.concurrent.ThreadLocalRandom;

/**
Expand All @@ -51,16 +52,6 @@
* @since 2.4.0
*/
public class CustomDropsHandler {
private final LevelledMobs main;

final Map<EntityType, CustomDropInstance> customDropsitems;
final Map<EntityType, CustomDropInstance> customDropsitems_Babies;
final Map<String, CustomDropInstance> customDropsitems_groups;
final Map<String, CustomDropInstance> customDropIDs;
@Nullable Map<String, CustomDropInstance> customItemGroups;
public final CustomDropsParser customDropsParser;
private final YmlParsingHelper ymlHelper;

public CustomDropsHandler(final LevelledMobs main) {
this.main = main;
this.customDropsitems = new TreeMap<>();
Expand All @@ -69,8 +60,19 @@ public CustomDropsHandler(final LevelledMobs main) {
this.customDropIDs = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
customDropsParser = new CustomDropsParser(main, this);
this.ymlHelper = customDropsParser.ymlHelper;
this.customEquippedItems = new WeakHashMap<>();
}

private final LevelledMobs main;
final Map<EntityType, CustomDropInstance> customDropsitems;
final Map<EntityType, CustomDropInstance> customDropsitems_Babies;
final Map<String, CustomDropInstance> customDropsitems_groups;
final Map<String, CustomDropInstance> customDropIDs;
@Nullable Map<String, CustomDropInstance> customItemGroups;
public final CustomDropsParser customDropsParser;
private final YmlParsingHelper ymlHelper;
private final WeakHashMap<LivingEntity, EquippedItemsInfo> customEquippedItems;

public CustomDropResult getCustomItemDrops(final LivingEntityWrapper lmEntity, final List<ItemStack> drops, final boolean equippedOnly) {
final CustomDropProcessingInfo processingInfo = new CustomDropProcessingInfo();
processingInfo.lmEntity = lmEntity;
Expand Down Expand Up @@ -135,8 +137,7 @@ public CustomDropResult getCustomItemDrops(final LivingEntityWrapper lmEntity, f
lmEntity.getTypeName(), lmEntity.getMobLevel(), processingInfo.mobKiller == null ? "(null)" : processingInfo.mobKiller.getName()));
processingInfo.writeAnyDebugMessages();
}
return processingInfo.hasOverride ?
CustomDropResult.HAS_OVERRIDE : CustomDropResult.NO_OVERRIDE;
return new CustomDropResult(processingInfo.stackToItem, processingInfo.hasOverride);
}

getCustomItemsFromDropInstance(processingInfo); // payload
Expand All @@ -161,8 +162,7 @@ public CustomDropResult getCustomItemDrops(final LivingEntityWrapper lmEntity, f
processingInfo.writeAnyDebugMessages();
}

return processingInfo.hasOverride ?
CustomDropResult.HAS_OVERRIDE : CustomDropResult.NO_OVERRIDE;
return new CustomDropResult(processingInfo.stackToItem, processingInfo.hasOverride);
}

private DropInstanceBuildResult buildDropsListFromGroupsAndEntity(final List<String> groups, final EntityType entityType, @NotNull final CustomDropProcessingInfo info){
Expand Down Expand Up @@ -530,6 +530,7 @@ else if (dropBase instanceof CustomCommand) {
newItem = main.mobHeadManager.getMobHeadFromPlayerHead(newItem, info.lmEntity, dropItem);

info.newDrops.add(newItem);
info.stackToItem.put(newItem, dropItem);
}

private boolean shouldDenyDeathCause(final @NotNull CustomDropBase dropBase, final @NotNull CustomDropProcessingInfo info){
Expand Down Expand Up @@ -594,41 +595,52 @@ private boolean checkIfMadeEquippedDropChance(final CustomDropProcessingInfo inf
if (item.equippedSpawnChance >= 1.0F || !item.onlyDropIfEquipped) return true;
if (item.equippedSpawnChance <= 0.0F) return false;

return isMobWearingItem(item.getItemStack(), info.lmEntity.getLivingEntity());

return isMobWearingItem(item.getItemStack(), info.lmEntity.getLivingEntity(), item);
}

private boolean isMobWearingItem(final ItemStack item, final @NotNull LivingEntity mob){
private boolean isMobWearingItem(final ItemStack item, final @NotNull LivingEntity mob, final CustomDropItem customDropItem){
final EntityEquipment equipment = mob.getEquipment();
if (equipment == null) return false;

final EquippedItemsInfo equippedItemsInfo = this.customEquippedItems.get(mob);
if (equippedItemsInfo == null) return false;

switch (item.getType()){
case LEATHER_HELMET:
case CHAINMAIL_HELMET:
case IRON_HELMET:
case DIAMOND_HELMET:
case NETHERITE_HELMET:
if (equippedItemsInfo.helmet != null && customDropItem == equippedItemsInfo.helmet)
return true;
case LEATHER_CHESTPLATE:
case CHAINMAIL_CHESTPLATE:
case IRON_CHESTPLATE:
case DIAMOND_CHESTPLATE:
case NETHERITE_CHESTPLATE:
return item.isSimilar(equipment.getChestplate());
if (equippedItemsInfo.chestplate != null && customDropItem == equippedItemsInfo.chestplate)
return true;
case LEATHER_LEGGINGS:
case CHAINMAIL_LEGGINGS:
case IRON_LEGGINGS:
case DIAMOND_LEGGINGS:
case NETHERITE_LEGGINGS:
return item.isSimilar(equipment.getLeggings());
if (equippedItemsInfo.leggings != null && customDropItem == equippedItemsInfo.leggings)
return true;
case LEATHER_BOOTS:
case CHAINMAIL_BOOTS:
case IRON_BOOTS:
case DIAMOND_BOOTS:
case NETHERITE_BOOTS:
return item.isSimilar(equipment.getBoots());
if (equippedItemsInfo.boots != null && customDropItem == equippedItemsInfo.boots)
return true;
}

if (item.isSimilar(equipment.getItemInMainHand()))
if (equippedItemsInfo.mainHand != null && customDropItem == equippedItemsInfo.mainHand)
return true;

if (item.isSimilar(equipment.getItemInOffHand()))
return true;

return item.isSimilar(equipment.getHelmet());
return equippedItemsInfo.offhand != null && customDropItem == equippedItemsInfo.offhand;
}

private boolean madePlayerLevelRequirement(final @NotNull CustomDropProcessingInfo info, final CustomDropBase dropBase){
Expand Down Expand Up @@ -759,6 +771,10 @@ private ItemStack getCookedVariantOfMeat(@NotNull final ItemStack itemStack){
}
}

public void addEntityEquippedItems(final @NotNull LivingEntity livingEntity, final @NotNull EquippedItemsInfo equippedItemsInfo){
this.customEquippedItems.put(livingEntity, equippedItemsInfo);
}

private boolean isCustomDropsDebuggingEnabled() {
return main.companion.debugsEnabled.contains(DebugType.CUSTOM_DROPS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.lokka30.levelledmobs.customdrops;

public class EquippedItemsInfo {
public CustomDropItem helmet;
public CustomDropItem chestplate;
public CustomDropItem leggings;
public CustomDropItem boots;
public CustomDropItem mainHand;
public CustomDropItem offhand;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import me.lokka30.levelledmobs.misc.QueueItem;
import me.lokka30.levelledmobs.misc.Utils;
import me.lokka30.levelledmobs.rules.NametagVisibilityEnum;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Guardian;
import org.bukkit.entity.LivingEntity;
Expand Down Expand Up @@ -116,6 +119,16 @@ public void onEntityDamageByEntityEvent(final @NotNull EntityDamageByEntityEvent
}

private void processRangedDamage(@NotNull final EntityDamageByEntityEvent event) {
if (event.getDamager().getType() == EntityType.AREA_EFFECT_CLOUD) {
// ender dragon breath
final AreaEffectCloud aec = (AreaEffectCloud) event.getDamager();
if (!(aec.getSource() instanceof EnderDragon)) return;
final LivingEntityWrapper lmEntity = LivingEntityWrapper.getInstance((LivingEntity) aec.getSource(), main);
processRangedDamage2(lmEntity, event);
lmEntity.free();
return;
}

if (!(event.getDamager() instanceof Projectile)) return;
final Projectile projectile = (Projectile) event.getDamager();

Expand Down Expand Up @@ -150,12 +163,11 @@ private void processRangedDamage2(@NotNull final LivingEntityWrapper shooter, @N
main._mobsQueueManager.addToQueue(new QueueItem(shooter, 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 double newDamage = event.getDamage() + main.mobDataManager.getAdditionsForLevel(shooter, Addition.CUSTOM_RANGED_ATTACK_DAMAGE, 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));
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 @@ -70,7 +70,7 @@ public void onDeath(@NotNull final EntityDeathEvent event) {
} else if (main.rulesManager.getRule_UseCustomDropsForMob(lmEntity).useDrops) {
final List<ItemStack> drops = new LinkedList<>();
final CustomDropResult result = main.customDropsHandler.getCustomItemDrops(lmEntity, drops, false);
if (result == CustomDropResult.HAS_OVERRIDE)
if (result.hasOverride)
main.levelManager.removeVanillaDrops(lmEntity, event.getDrops());

event.getDrops().addAll(drops);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void onEntitySpawn(@NotNull final EntitySpawnEvent event) {
if (!(event.getEntity() instanceof LivingEntity)) return;

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

if (event instanceof CreatureSpawnEvent) {
final CreatureSpawnEvent.SpawnReason spawnReason = ((CreatureSpawnEvent) event).getSpawnReason();
Expand All @@ -80,15 +81,14 @@ public void onEntitySpawn(@NotNull final EntitySpawnEvent event) {
return;
}
}
else if (event instanceof SpawnerSpawnEvent)
lmEntity.setSpawnReason(LevelledMobSpawnReason.SPAWNER);

if (!processMobSpawns) {
lmEntity.free();
return;
}

if (event instanceof CreatureSpawnEvent)
lmEntity.setSpawnReason(adaptVanillaSpawnReason(((CreatureSpawnEvent) event).getSpawnReason()));

if (main.configUtils.playerLevellingEnabled && lmEntity.getPlayerForLevelling() == null)
updateMobForPlayerLevelling(lmEntity);

Expand Down
Loading

0 comments on commit 5b1a3a7

Please sign in to comment.