mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-27 12:35:17 +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"
|
name: "UltimateStacker"
|
||||||
suffex: "Legacy"
|
suffex: "Legacy"
|
||||||
path: "/builds/Songoda/$name"
|
path: "/builds/Songoda/$name"
|
||||||
version: "1.1.10"
|
version: "1.2.10"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
stage: build
|
stage: build
|
||||||
|
@ -7,6 +7,7 @@ import org.bukkit.*;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@ -19,6 +20,36 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class Methods {
|
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) {
|
public static void onDeath(LivingEntity killed, List<ItemStack> items, int droppedExp) {
|
||||||
UltimateStacker instance = UltimateStacker.getInstance();
|
UltimateStacker instance = UltimateStacker.getInstance();
|
||||||
|
|
||||||
@ -32,28 +63,30 @@ public class Methods {
|
|||||||
EntityStack stack = stackManager.getStack(killed);
|
EntityStack stack = stackManager.getStack(killed);
|
||||||
|
|
||||||
if (instance.getConfig().getBoolean("Entity.Kill Whole Stack On Death") && stack.getAmount() != 1) {
|
if (instance.getConfig().getBoolean("Entity.Kill Whole Stack On Death") && stack.getAmount() != 1) {
|
||||||
for (int i = 1; i < stack.getAmount(); i++) {
|
handleWholeStackDeath(killed.getLocation(), stack, items, droppedExp);
|
||||||
for (ItemStack item : items) {
|
} else if(instance.getConfig().getBoolean("Entity.Kill Whole Stack On Special Death Cause") && stack.getAmount() != 1) {
|
||||||
killed.getWorld().dropItemNaturally(killed.getLocation(), item);
|
List<String> reasons = instance.getConfig().getStringList("Entity.Special Death Cause");
|
||||||
}
|
EntityDamageEvent lastDamageCause = killed.getLastDamageCause();
|
||||||
killed.getWorld().spawn(killed.getLocation(), ExperienceOrb.class).setExperience(droppedExp);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Entity newEntity = newEntity(killed);
|
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners"))
|
if(lastDamageCause != null) {
|
||||||
if (killed.hasMetadata("ES")) newEntity.setMetadata("ES",
|
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();
|
||||||
new FixedMetadataValue(com.songoda.epicspawners.EpicSpawnersPlugin.getInstance(), "ES"));
|
boolean killWholeStack = false;
|
||||||
|
|
||||||
stack = stackManager.updateStack(killed, newEntity);
|
for(String s : reasons) {
|
||||||
|
if(cause.name().equalsIgnoreCase(s)) {
|
||||||
stack.addAmount(-1);
|
killWholeStack = true;
|
||||||
if (stack.getAmount() <= 1) {
|
break;
|
||||||
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) {
|
private static LivingEntity newEntity(LivingEntity killed) {
|
||||||
|
@ -185,6 +185,8 @@ public class SettingsManager implements Listener {
|
|||||||
o4("Entity.Max Stack Size", 15),
|
o4("Entity.Max Stack Size", 15),
|
||||||
oo("Entity.Min Stack Amount", 5),
|
oo("Entity.Min Stack Amount", 5),
|
||||||
o5("Entity.Kill Whole Stack On Death", false),
|
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"),
|
NAME_FORMAT_ENTITY("Entity.Name Format", "&f{TYPE} &6{AMT}x"),
|
||||||
o6("Item.Max Stack Size", 120),
|
o6("Item.Max Stack Size", 120),
|
||||||
NAME_FORMAT_ITEM("Item.Name Format", "&f{TYPE} &6{AMT}x"),
|
NAME_FORMAT_ITEM("Item.Name Format", "&f{TYPE} &6{AMT}x"),
|
||||||
|
Loading…
Reference in New Issue
Block a user