Spawn netherite AEs as chestplates when dropped
- When a netherite ArmoredElytra is dropped (death, dispenser, whatever), it will now drop as a netherite chestplate instead of as an elytra. This allows it to not burn in lava and stuff (which is handled client side).
This commit is contained in:
parent
94a06dccba
commit
6bdd7e37d4
@ -4,6 +4,7 @@ import nl.pim16aap2.armoredElytra.handlers.AnvilHandler;
|
||||
import nl.pim16aap2.armoredElytra.handlers.CommandHandler;
|
||||
import nl.pim16aap2.armoredElytra.handlers.EventHandlers;
|
||||
import nl.pim16aap2.armoredElytra.handlers.FlyDurabilityHandler;
|
||||
import nl.pim16aap2.armoredElytra.handlers.ItemDropListener;
|
||||
import nl.pim16aap2.armoredElytra.handlers.LoginHandler;
|
||||
import nl.pim16aap2.armoredElytra.handlers.SmithingTableHandler;
|
||||
import nl.pim16aap2.armoredElytra.handlers.Uninstaller;
|
||||
@ -102,6 +103,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
final Listener creationListener = config.craftingInSmithingTable() ?
|
||||
new SmithingTableHandler(this) : new AnvilHandler(this);
|
||||
Bukkit.getPluginManager().registerEvents(creationListener, this);
|
||||
Bukkit.getPluginManager().registerEvents(new ItemDropListener(this), this);
|
||||
|
||||
// Log all allowed enchantments.
|
||||
myLogger(Level.INFO, ("Allowed enchantments:"));
|
||||
|
@ -0,0 +1,88 @@
|
||||
package nl.pim16aap2.armoredElytra.handlers;
|
||||
|
||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemDropListener implements Listener
|
||||
{
|
||||
protected final ArmoredElytra plugin;
|
||||
|
||||
public ItemDropListener(final ArmoredElytra plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new item to drop by analyzing an item that will be dropped.
|
||||
* <p>
|
||||
* So when dropping an armored elytra of the netherite tier, it will return a netherite chestplate (with the meta
|
||||
* copied over).
|
||||
*
|
||||
* @param itemStack The dropped item to analyze.
|
||||
* @return The new item to drop if it should be changed. If no change is required, null is returned.
|
||||
*/
|
||||
private ItemStack getNewDrop(final ItemStack itemStack)
|
||||
{
|
||||
if (itemStack == null || itemStack.getType() != Material.ELYTRA ||
|
||||
plugin.getNbtEditor().getArmorTier(itemStack) != ArmorTier.NETHERITE)
|
||||
return null;
|
||||
|
||||
ItemStack newDrop = new ItemStack(Material.NETHERITE_CHESTPLATE, 1);
|
||||
newDrop.setItemMeta(itemStack.getItemMeta());
|
||||
|
||||
return newDrop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new item to pick up by analyzing an item that would be picked up.
|
||||
* <p>
|
||||
* So when picking up a placeholder netherite chest plate (as replaced by {@link #getNewDrop(ItemStack)}) it would
|
||||
* return an armored elytra of the netherite tier.
|
||||
*
|
||||
* @param itemStack The picked-up item to analyze.
|
||||
* @return The new item to pick up if it should be changed. If no change is required, null is returned.
|
||||
*/
|
||||
private ItemStack getNewPickup(final ItemStack itemStack)
|
||||
{
|
||||
if (itemStack == null || itemStack.getType() != Material.NETHERITE_CHESTPLATE ||
|
||||
plugin.getNbtEditor().getArmorTier(itemStack) != ArmorTier.NETHERITE)
|
||||
return null;
|
||||
|
||||
ItemStack newDrop = new ItemStack(Material.ELYTRA, 1);
|
||||
newDrop.setItemMeta(itemStack.getItemMeta());
|
||||
|
||||
return newDrop;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onDrop(final ItemSpawnEvent event)
|
||||
{
|
||||
final ItemStack newDrop = getNewDrop(event.getEntity().getItemStack());
|
||||
if (newDrop != null)
|
||||
event.getEntity().setItemStack(newDrop);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onEntityPickup(EntityPickupItemEvent event)
|
||||
{
|
||||
final ItemStack newPickup = getNewPickup(event.getItem().getItemStack());
|
||||
if (newPickup != null)
|
||||
event.getItem().setItemStack(newPickup);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onInventoryPickup(InventoryPickupItemEvent event)
|
||||
{
|
||||
final ItemStack newPickup = getNewPickup(event.getItem().getItemStack());
|
||||
if (newPickup != null)
|
||||
event.getItem().setItemStack(newPickup);
|
||||
}
|
||||
}
|
@ -23,9 +23,6 @@ public class NBTEditor implements INBTEditor
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||
{
|
||||
@ -65,9 +62,6 @@ public class NBTEditor implements INBTEditor
|
||||
meta.addAttributeModifier(attribute, attributeModifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ArmorTier getArmorTier(ItemStack item)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user