feat: force drop the egg if keepInventory is on

This commit is contained in:
HerozDotExe 2026-02-06 14:41:47 +01:00
parent fb951eae05
commit 19482a09fd

View file

@ -94,14 +94,14 @@ public class MiscListener implements Listener {
announce(String.format("%s placed the dragon egg!", event.getPlayer().getDisplayName()));
}
}
/**
* Prevent the egg being dispensed when inside a shulker box
* TODO allow this to happen and just update the position of the egg
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent event) {
if (event.getBlock().getType().equals(Material.DISPENSER)) {
if (Egg.hasEgg(event.getItem())) {
//if egg or egg container will be dispensed by a dispenser
@ -123,7 +123,7 @@ public class MiscListener implements Listener {
switch (event.getRightClicked().getType()) {
case ALLAY:
Allay allay = (Allay) event.getRightClicked();
Allay allay = (Allay) event.getRightClicked();
if (!(allay.getEquipment().getItemInMainHand().getType().equals(Material.AIR))) { //if allay has an item
if (Egg.hasEgg(allay.getEquipment().getItemInMainHand())
@ -135,16 +135,16 @@ public class MiscListener implements Listener {
}
break; //allay has an item, giving it the egg is not possible
}
//otherwise, continue to next check
case ITEM_FRAME:
case GLOW_ITEM_FRAME:
ItemStack heldItem = playerInv.getItemInMainHand();
if (heldItem.getType().equals(Material.AIR)) { //if main hand empty, check offhand
heldItem = playerInv.getItemInOffHand();
}
if (!heldItem.getType().equals(Material.AIR)) { //if item in either hand
if (Egg.hasEgg(heldItem)) {
data.updateEggLocation(event.getRightClicked());
@ -185,26 +185,26 @@ public class MiscListener implements Listener {
* Handle the egg as a falling block entity
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onFallingBlock(final EntityChangeBlockEvent event){
public void onFallingBlock(final EntityChangeBlockEvent event) {
//check if this is dealing with a falling block, since EntityChangeBlockEvent is generic
if (event.getEntityType() == EntityType.FALLING_BLOCK) {
if (event.getEntityType() == EntityType.FALLING_BLOCK) {
//if the falling block is the egg
if (Egg.hasEgg((FallingBlock)event.getEntity())) {
log("Gravity event involving dragon egg occured");
if (Egg.hasEgg((FallingBlock) event.getEntity())) {
log("Gravity event involving dragon egg occured");
if (event.getBlock().getType() == Material.AIR) {
//egg lands
data.updateEggLocation(event.getBlock());
} else if (Egg.hasEgg(event.getBlock())) {
} else if (Egg.hasEgg(event.getBlock())) {
//egg begins falling
data.updateEggLocation(event.getEntity());
}
}
}
data.updateEggLocation(event.getEntity());
}
}
}
}
//Other event handlers
/**
@ -212,13 +212,17 @@ public class MiscListener implements Listener {
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerDeath(PlayerDeathEvent event) {
if (!event.getKeepInventory() && Egg.hasEgg(event.getEntity().getInventory())) {
if (Egg.hasEgg(event.getEntity().getInventory())) {
if (event.getKeepInventory()) {
// Keep inv is on, force drop the egg
EggController.dropEgg(event.getPlayer(), data, config);
}
data.resetEggOwner(false, config);
announce(String.format("%s died and lost the dragon egg!", event.getEntity().getDisplayName()));
}
}
//Helper methods
private void announce(String msg) {
Announcement.announce(msg, logger);