Merge branch 'development'

This commit is contained in:
Brianna 2019-10-16 10:57:41 -04:00
commit b1b9b0379c
5 changed files with 28 additions and 38 deletions

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "UltimateStacker"
path: "/builds/$CI_PROJECT_PATH"
version: "1.10.16"
version: "1.10.17"
build:
stage: build

View File

@ -15,6 +15,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
@ -108,7 +109,7 @@ public class EntityStack {
return null;
}
private void handleWholeStackDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp) {
private void handleWholeStackDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp, EntityDeathEvent event) {
Location killedLocation = killed.getLocation();
List<Drop> preStackedDrops = new ArrayList<>();
for (int i = 1; i < amount; i++) {
@ -124,7 +125,7 @@ public class EntityStack {
preStackedDrops.addAll(drops);
}
if (!preStackedDrops.isEmpty())
DropUtils.processStackedDrop(killed, preStackedDrops);
DropUtils.processStackedDrop(killed, preStackedDrops, event);
if (droppedExp > 0)
killedLocation.getWorld().spawn(killedLocation, ExperienceOrb.class).setExperience(droppedExp * amount);
@ -133,7 +134,7 @@ public class EntityStack {
UltimateStacker.getInstance().addExp(killed.getKiller(), this);
}
private void handleSingleStackDeath(LivingEntity killed, List<Drop> drops) {
private void handleSingleStackDeath(LivingEntity killed, List<Drop> drops, EntityDeathEvent event) {
EntityStackManager stackManager = plugin.getEntityStackManager();
LivingEntity newEntity = plugin.getEntityUtils().newEntity(killed);
@ -153,7 +154,7 @@ public class EntityStack {
newEntity.setMetadata(entityMetadataKey, new FixedMetadataValue(UltimateStacker.getInstance(), true));
}
DropUtils.processStackedDrop(killed, drops);
DropUtils.processStackedDrop(killed, drops, event);
EntityStack entityStack = stackManager.updateStack(killed, newEntity);
@ -166,7 +167,7 @@ public class EntityStack {
}
}
public void onDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp) {
public void onDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp, EntityDeathEvent event) {
killed.setCustomName(null);
killed.setCustomNameVisible(true);
killed.setCustomName(Methods.formatText("&7"));
@ -175,7 +176,7 @@ public class EntityStack {
|| plugin.getMobFile().getBoolean("Mobs." + killed.getType().name() + ".Kill Whole Stack");
if (killWholeStack && getAmount() != 1) {
handleWholeStackDeath(killed, drops, custom, droppedExp);
handleWholeStackDeath(killed, drops, custom, droppedExp, event);
} else if (getAmount() != 1) {
List<String> reasons = Settings.INSTANT_KILL.getStringList();
EntityDamageEvent lastDamageCause = killed.getLastDamageCause();
@ -184,11 +185,11 @@ public class EntityStack {
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();
for (String s : reasons) {
if (!cause.name().equalsIgnoreCase(s)) continue;
handleWholeStackDeath(killed, drops, custom, Settings.NO_EXP_INSTANT_KILL.getBoolean() ? 0 : droppedExp);
handleWholeStackDeath(killed, drops, custom, Settings.NO_EXP_INSTANT_KILL.getBoolean() ? 0 : droppedExp, event);
return;
}
}
handleSingleStackDeath(killed, drops);
handleSingleStackDeath(killed, drops, event);
}
}

View File

@ -19,13 +19,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class DeathListeners implements Listener {
@ -43,22 +42,21 @@ public class DeathListeners implements Listener {
|| event.getEntityType() == EntityType.ARMOR_STAND) return;
boolean custom = Settings.CUSTOM_DROPS.getBoolean();
List<Drop> drops = custom ? instance.getLootablesManager().getDrops(event.getEntity()) : new ArrayList<>();
List<Drop> drops = custom ? instance.getLootablesManager().getDrops(event.getEntity())
: event.getDrops().stream().map(Drop::new).collect(Collectors.toList());
if (!custom) {
for (ItemStack item : event.getDrops())
drops.add(new Drop(item));
}
for (ItemStack item : new ArrayList<>(event.getDrops())) {
if (!shouldDrop(event.getEntity(), item.getType()))
event.getDrops().remove(item);
if (custom) {
for (ItemStack item : new ArrayList<>(event.getDrops())) {
if (shouldDrop(event.getEntity(), item.getType()))
drops.add(new Drop(item));
}
}
if (instance.getEntityStackManager().isStacked(event.getEntity()))
instance.getEntityStackManager().getStack(event.getEntity())
.onDeath(event.getEntity(), drops, custom, event.getDroppedExp());
.onDeath(event.getEntity(), drops, custom, event.getDroppedExp(), event);
else
DropUtils.processStackedDrop(event.getEntity(), drops);
DropUtils.processStackedDrop(event.getEntity(), drops, event);
}
private boolean shouldDrop(LivingEntity entity, Material material) {
@ -128,7 +126,7 @@ public class DeathListeners implements Listener {
if (checkUnbreakingChance(unbreakingLevel))
actualDamage++;
tool.setDurability((short)(tool.getDurability() + actualDamage));
tool.setDurability((short) (tool.getDurability() + actualDamage));
if (!this.hasEnoughDurability(tool, 1))
player.getInventory().setItemInHand(null);

View File

@ -177,8 +177,7 @@ public class Settings {
"Should items that are blacklisted display holograms?");
public static final ConfigSetting MAX_STACK_ITEMS = new ConfigSetting(config, "Items.Max Stack Size", 512,
"The max stack size for items.",
"Currently this can only be set to a max of 120.");
"The max stack size for items.");
public static final ConfigSetting NAME_FORMAT_ITEM = new ConfigSetting(config, "Items.Name Format", "&f{TYPE} &r[&6{AMT}x]",
"The text displayed above a dropped item.");

View File

@ -3,24 +3,15 @@ package com.songoda.ultimatestacker.utils;
import com.songoda.lootables.loot.Drop;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DropUtils {
public static void processDrop(LivingEntity entity, Drop drop) {
if (drop == null) return;
if (drop.getItemStack() != null)
dropItems(entity, Collections.singletonList(drop.getItemStack()));
if (drop.getCommand() != null)
runCommands(entity, Collections.singletonList(drop.getCommand()));
}
public static void processStackedDrop(LivingEntity entity, List<Drop> drops) {
public static void processStackedDrop(LivingEntity entity, List<Drop> drops, EntityDeathEvent event) {
List<ItemStack> items = new ArrayList<>();
List<String> commands = new ArrayList<>();
for (Drop drop : drops) {
@ -44,14 +35,15 @@ public class DropUtils {
commands.add(drop.getCommand());
}
if (!items.isEmpty())
dropItems(entity, items);
dropItems(items, event);
else if (!commands.isEmpty())
runCommands(entity, commands);
}
private static void dropItems(LivingEntity entity, List<ItemStack> items) {
private static void dropItems(List<ItemStack> items, EntityDeathEvent event) {
event.getDrops().clear();
for (ItemStack item : items)
entity.getWorld().dropItemNaturally(entity.getLocation(), item);
event.getDrops().add(item);
}
private static void runCommands(LivingEntity entity, List<String> commands) {