Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events for Actions #1296

Merged
merged 16 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions src/api/java/de/teamlapen/vampirism/api/event/ActionEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package de.teamlapen.vampirism.api.event;

import de.teamlapen.vampirism.api.entity.player.IFactionPlayer;
import de.teamlapen.vampirism.api.entity.player.actions.IAction;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("unused")
public abstract class ActionEvent extends Event {

@NotNull
private final IFactionPlayer<?> factionPlayer;
@NotNull
private final IAction<?> action;

public ActionEvent(@NotNull IFactionPlayer<?> factionPlayer, @NotNull IAction<?> action) {
this.factionPlayer = factionPlayer;
this.action = action;
}

/**
* @return The FactionPlayer who activated the action.
*/
public @NotNull IFactionPlayer<?> getFactionPlayer() {
return this.factionPlayer;
}

/**
* @return The action the event is firing for.
*/
public @NotNull IAction<?> getAction() {
return this.action;
}

/**
* Posted before an action fires. Use this to modify the cooldown or duration of action, or to prevent the action from activating.
*/
@Cancelable
public static class ActionActivatedEvent extends ActionEvent {
TheDrOfDoctoring marked this conversation as resolved.
Show resolved Hide resolved

private int cooldown;
private int duration;

public ActionActivatedEvent(@NotNull IFactionPlayer<?> factionPlayer, @NotNull IAction<?> action, int cooldown, int duration) {
TheDrOfDoctoring marked this conversation as resolved.
Show resolved Hide resolved
super(factionPlayer, action);
this.cooldown = cooldown;
this.duration = duration;
}

/**
* @return The original cooldown of the action, in ticks
*/
public int getCooldown() {
return cooldown;
}

/**
* @param cooldown the new cooldown of the action, in ticks.
*/
public void setCooldown(int cooldown) {
this.cooldown = cooldown;
}

/**
* @return The original duration of the action, this will return -1 if the action does not implement ILastingAction.
*/
public int getDuration() {
return duration;
}

/**
* @param duration the new duration of the action, in ticks.
*/
public void setDuration(int duration) {
this.duration = duration;
}
}

/**
* Posted when an action deactivates, either when deactivated manually or when out of time. As regular actions instantly deactivate, this only fires for actions that implement ILastingAction.
*/
public static class ActionDeactivatedEvent extends ActionEvent {
private final int remainingDuration;
private int cooldown;

public ActionDeactivatedEvent(@NotNull IFactionPlayer<?> factionPlayer, @NotNull IAction<?> action, int remainingDuration, int cooldown) {
super(factionPlayer, action);
this.remainingDuration = remainingDuration;
this.cooldown = cooldown;
}

/**
* @return The remaining duration of the action, in ticks.
*/
public int getRemainingDuration() {
return remainingDuration;
}

/**
* @return The original cooldown of the action, in ticks
*/
public int getCooldown() {
return cooldown;
}

/**
* @param cooldown The new cooldown of the action, in ticks
*/
public void setCooldown(int cooldown) {
this.cooldown = cooldown;
}
}

/**
* Posted when an action deactivates, either when deactivated manually or when out of time. As regular actions instantly deactivate, this only fires for actions that implement {@link de.teamlapen.vampirism.api.entity.player.actions.ILastingAction}.
*/
@HasResult
public static class ActionUpdateEvent extends ActionEvent {
private final int remainingDuration;
private boolean overrideDeactivation;

public ActionUpdateEvent(@NotNull IFactionPlayer<?> factionPlayer, @NotNull IAction<?> action, int remainingDuration) {
super(factionPlayer, action);
this.remainingDuration = remainingDuration;
}

/**
* @return The remaining duration of the action, in ticks.
*/
public int getRemainingDuration() {
return this.remainingDuration;
}

/**
* Call this to deactivate the action. Or override the current result.
*
* @param overrideDeactivation If true, the action will be deactivated.
*/
public void setOverrideDeactivation(boolean overrideDeactivation) {
this.overrideDeactivation = overrideDeactivation;
}

/**
* @return If true, the action will be deactivated.
*/
public boolean shouldOverrideDeactivation() {
return this.overrideDeactivation;
}

}

}
Loading
Loading