Skip to content

Commit

Permalink
Correct implementation for the event handler (#10565)
Browse files Browse the repository at this point in the history
Correct implementation for the entity remove event handler
  • Loading branch information
Thodor12 authored Jan 5, 2025
1 parent a763630 commit ec6eccf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ public class AbstractCitizenModEvent extends AbstractColonyModEvent
/**
* The citizen related to the event.
*/
private final @NotNull ICitizenData citizen;
@NotNull
private final ICitizenData citizen;

/**
* Constructs a citizen-based event.
*
* @param citizen the citizen related to the event.
*/
protected AbstractCitizenModEvent(final @NotNull ICitizenData citizen)
protected AbstractCitizenModEvent(@NotNull final ICitizenData citizen)
{
super(citizen.getColony());
this.citizen = citizen;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
package com.minecolonies.api.eventbus.events.colony.citizens;

import com.minecolonies.api.colony.ICitizenData;
import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.eventbus.events.colony.AbstractColonyModEvent;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;

/**
* Event for when a citizen was removed from the colony.
*/
public final class CitizenRemovedModEvent extends AbstractCitizenModEvent
public final class CitizenRemovedModEvent extends AbstractColonyModEvent
{
/**
* The id of the citizen.
*/
private final int citizenId;

/**
* The damage source that caused a citizen to die.
*/
private final @NotNull Entity.RemovalReason reason;
@NotNull
private final Entity.RemovalReason reason;

/**
* Citizen removed event.
*
* @param citizen the citizen related to the event.
* @param reason the reason the citizen was removed.
* @param colony the colony related to the event.
* @param citizenId the id of the citizen.
* @param reason the reason the citizen was removed.
*/
public CitizenRemovedModEvent(final @NotNull ICitizenData citizen, final @NotNull Entity.RemovalReason reason)
public CitizenRemovedModEvent(final @NotNull IColony colony, final int citizenId, final @NotNull Entity.RemovalReason reason)
{
super(citizen);
super(colony);
this.citizenId = citizenId;
this.reason = reason;
}

/**
* The id of the citizen.
*
* @return the id.
*/
public int getCitizenId()
{
return citizenId;
}

/**
* The damage source that caused the citizen to die.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1582,10 +1582,7 @@ public void die(@NotNull final DamageSource damageSource)
public void remove(final @NotNull RemovalReason reason)
{
super.remove(reason);
if (reason != RemovalReason.DISCARDED && citizenData != null)
{
IMinecoloniesAPI.getInstance().getEventBus().post(new CitizenRemovedModEvent(citizenData, reason));
}
IMinecoloniesAPI.getInstance().getEventBus().post(new CitizenRemovedModEvent(citizenColonyHandler.getColony(), citizenId, reason));
}

/**
Expand Down

0 comments on commit ec6eccf

Please sign in to comment.