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

@ -185,24 +185,24 @@ 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())) {
if (Egg.hasEgg((FallingBlock) event.getEntity())) {
log("Gravity event involving dragon egg occured");
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,7 +212,11 @@ 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()));