Skip to content

Commit

Permalink
Fix Directing not working on Soulbound items from mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Flo56958 committed Oct 6, 2023
1 parent 7ec843b commit 211f584
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
75 changes: 42 additions & 33 deletions src/main/java/de/flo56958/minetinker/listeners/EntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bukkit.metadata.MetadataValue;
import org.bukkit.projectiles.ProjectileSource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Random;
Expand All @@ -45,23 +46,7 @@ public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
return;
}

Player player = null;

if (event.getDamager() instanceof final Arrow arrow && !(event.getDamager() instanceof Trident)) {
final ProjectileSource source = arrow.getShooter();

if (source instanceof Player) {
player = (Player) source;
}
} else if (event.getDamager() instanceof final Trident trident) {
final ProjectileSource source = trident.getShooter();

if (source instanceof Player) {
player = (Player) source;
}
} else if (event.getDamager() instanceof Player) {
player = (Player) event.getDamager();
}
Player player = getPlayer(event);

if (player == null) return;

Expand Down Expand Up @@ -98,6 +83,28 @@ public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
}
}

@Nullable
private static Player getPlayer(@NotNull EntityDamageByEntityEvent event) {
Player player = null;

if (event.getDamager() instanceof final Arrow arrow && !(event.getDamager() instanceof Trident)) {
final ProjectileSource source = arrow.getShooter();

if (source instanceof Player) {
player = (Player) source;
}
} else if (event.getDamager() instanceof final Trident trident) {
final ProjectileSource source = trident.getShooter();

if (source instanceof Player) {
player = (Player) source;
}
} else if (event.getDamager() instanceof Player) {
player = (Player) event.getDamager();
}
return player;
}

@EventHandler
public void onDeath(@NotNull final EntityDeathEvent event) {
final LivingEntity mob = event.getEntity();
Expand Down Expand Up @@ -128,24 +135,26 @@ public void onDeath(@NotNull final EntityDeathEvent event) {

final FileConfiguration config = MineTinker.getPlugin().getConfig();

if (config.getBoolean("ConvertLoot.MobDrops", true)) {
for (ItemStack item : event.getDrops()) {
modManager.convertLoot(item, player);
if (!(mob instanceof Player)) {
if (config.getBoolean("ConvertLoot.MobDrops", true)) {
for (ItemStack item : event.getDrops()) {
modManager.convertLoot(item, player);
}
}
}

if (config.getBoolean("MobDropModifierItems.Enabled", true)) {
if (config.getBoolean("MobDropModifierItems.ConsiderIncludedMobs") ==
config.getStringList("MobDropModifierItems.IncludedMobs").contains(mob.getType().name())) {
Random rand = new Random();
if (rand.nextInt(100) < config.getInt("MobDropModifierItems.Chance", 2)) {
int amount = rand.nextInt(config.getInt("MobDropModifierItems.MaximumAmount") + 1);
final List<Modifier> mods = modManager.getAllowedMods();
for (int i = 0; i < amount; i++) {
final int index = rand.nextInt(mods.size());
final Modifier mod = mods.get(index);
if (!config.getStringList("MobDropModifierItems.ExcludeModifiers").contains(mod.getKey())) {
event.getDrops().add(mod.getModItem().clone());
if (config.getBoolean("MobDropModifierItems.Enabled", true)) {
if (config.getBoolean("MobDropModifierItems.ConsiderIncludedMobs") ==
config.getStringList("MobDropModifierItems.IncludedMobs").contains(mob.getType().name())) {
Random rand = new Random();
if (rand.nextInt(100) < config.getInt("MobDropModifierItems.Chance", 2)) {
int amount = rand.nextInt(config.getInt("MobDropModifierItems.MaximumAmount") + 1);
final List<Modifier> mods = modManager.getAllowedMods();
for (int i = 0; i < amount; i++) {
final int index = rand.nextInt(mods.size());
final Modifier mod = mods.get(index);
if (!config.getStringList("MobDropModifierItems.ExcludeModifiers").contains(mod.getKey())) {
event.getDrops().add(mod.getModItem().clone());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void effect(MTEntityDeathEvent event) {
: 0;

for (ItemStack current : new ArrayList<>(event.getEvent().getDrops())) {
if (modManager.hasMod(current, Soulbound.instance())) {
if (modManager.hasMod(current, Soulbound.instance()) && event.getEvent().getEntity() instanceof Player) {
continue;
}

Expand Down

0 comments on commit 211f584

Please sign in to comment.