mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-23 10:35:22 +01:00
Merge branch 'instant-kill' into 'master'
COMPLETE: Provide players access to choose certain damage causes to kill a whole stack on death See merge request Songoda/UltimateStacker!3
This commit is contained in:
parent
c8afea20c6
commit
79a4a6b0e0
@ -5,7 +5,7 @@ variables:
|
||||
name: "UltimateStacker"
|
||||
suffex: "Legacy"
|
||||
path: "/builds/Songoda/$name"
|
||||
version: "1.1.10"
|
||||
version: "1.2.10"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -19,6 +20,36 @@ import java.util.Map;
|
||||
|
||||
public class Methods {
|
||||
|
||||
private static void handleWholeStackDeath(Location killedLocation, EntityStack stack, List<ItemStack> items, int droppedExp) {
|
||||
for (int i = 1; i < stack.getAmount(); i++) {
|
||||
for (ItemStack item : items) {
|
||||
killedLocation.getWorld().dropItemNaturally(killedLocation, item);
|
||||
}
|
||||
|
||||
killedLocation.getWorld().spawn(killedLocation, ExperienceOrb.class).setExperience(droppedExp);
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleSingleStackDeath(LivingEntity killed) {
|
||||
UltimateStacker instance = UltimateStacker.getInstance();
|
||||
EntityStackManager stackManager = instance.getEntityStackManager();
|
||||
Entity newEntity = newEntity(killed);
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners"))
|
||||
if (killed.hasMetadata("ES"))
|
||||
newEntity.setMetadata("ES", new FixedMetadataValue(com.songoda.epicspawners.EpicSpawnersPlugin.getInstance(), "ES"));
|
||||
|
||||
EntityStack entityStack = stackManager.updateStack(killed, newEntity);
|
||||
|
||||
entityStack.addAmount(-1);
|
||||
|
||||
if (entityStack.getAmount() <= 1) {
|
||||
stackManager.removeStack(newEntity);
|
||||
newEntity.setCustomNameVisible(false);
|
||||
newEntity.setCustomName(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onDeath(LivingEntity killed, List<ItemStack> items, int droppedExp) {
|
||||
UltimateStacker instance = UltimateStacker.getInstance();
|
||||
|
||||
@ -32,28 +63,30 @@ public class Methods {
|
||||
EntityStack stack = stackManager.getStack(killed);
|
||||
|
||||
if (instance.getConfig().getBoolean("Entity.Kill Whole Stack On Death") && stack.getAmount() != 1) {
|
||||
for (int i = 1; i < stack.getAmount(); i++) {
|
||||
for (ItemStack item : items) {
|
||||
killed.getWorld().dropItemNaturally(killed.getLocation(), item);
|
||||
handleWholeStackDeath(killed.getLocation(), stack, items, droppedExp);
|
||||
} else if(instance.getConfig().getBoolean("Entity.Kill Whole Stack On Special Death Cause") && stack.getAmount() != 1) {
|
||||
List<String> reasons = instance.getConfig().getStringList("Entity.Special Death Cause");
|
||||
EntityDamageEvent lastDamageCause = killed.getLastDamageCause();
|
||||
|
||||
if(lastDamageCause != null) {
|
||||
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();
|
||||
boolean killWholeStack = false;
|
||||
|
||||
for(String s : reasons) {
|
||||
if(cause.name().equalsIgnoreCase(s)) {
|
||||
killWholeStack = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
killed.getWorld().spawn(killed.getLocation(), ExperienceOrb.class).setExperience(droppedExp);
|
||||
}
|
||||
} else {
|
||||
Entity newEntity = newEntity(killed);
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners"))
|
||||
if (killed.hasMetadata("ES")) newEntity.setMetadata("ES",
|
||||
new FixedMetadataValue(com.songoda.epicspawners.EpicSpawnersPlugin.getInstance(), "ES"));
|
||||
|
||||
stack = stackManager.updateStack(killed, newEntity);
|
||||
|
||||
stack.addAmount(-1);
|
||||
if (stack.getAmount() <= 1) {
|
||||
stackManager.removeStack(newEntity);
|
||||
newEntity.setCustomNameVisible(false);
|
||||
newEntity.setCustomName(null);
|
||||
if(killWholeStack) {
|
||||
handleWholeStackDeath(killed.getLocation(), stack, items, droppedExp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleSingleStackDeath(killed);
|
||||
}
|
||||
|
||||
private static LivingEntity newEntity(LivingEntity killed) {
|
||||
|
@ -185,6 +185,8 @@ public class SettingsManager implements Listener {
|
||||
o4("Entity.Max Stack Size", 15),
|
||||
oo("Entity.Min Stack Amount", 5),
|
||||
o5("Entity.Kill Whole Stack On Death", false),
|
||||
o52("Entity.Kill Whole Stack On Special Death Cause", true),
|
||||
o53("Entity.Special Death Cause", Arrays.asList("FALL", "DROWNING", "LAVA", "VOID")),
|
||||
NAME_FORMAT_ENTITY("Entity.Name Format", "&f{TYPE} &6{AMT}x"),
|
||||
o6("Item.Max Stack Size", 120),
|
||||
NAME_FORMAT_ITEM("Item.Name Format", "&f{TYPE} &6{AMT}x"),
|
||||
|
Loading…
Reference in New Issue
Block a user