-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7854ebd
commit ca81127
Showing
5 changed files
with
153 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/api/java/de/teamlapen/vampirism/api/event/SkillEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package de.teamlapen.vampirism.api.event; | ||
|
||
import de.teamlapen.vampirism.api.entity.player.ISkillPlayer; | ||
import de.teamlapen.vampirism.api.entity.player.skills.ISkill; | ||
import de.teamlapen.vampirism.api.entity.player.skills.ISkillHandler; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.neoforged.bus.api.Event; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Event related to any skill changes of players | ||
*/ | ||
public abstract class SkillEvents<T extends ISkillPlayer<T>, Z extends ISkill<T>> extends Event { | ||
|
||
@NotNull | ||
private final T factionPlayer; | ||
@NotNull | ||
private final Holder<Z> skill; | ||
|
||
@ApiStatus.Internal | ||
public SkillEvents(@NotNull T skillPlayer, @NotNull Holder<Z> skill) { | ||
this.factionPlayer = skillPlayer; | ||
this.skill = skill; | ||
} | ||
|
||
/** | ||
* @return The skill Player for which this event is fired | ||
*/ | ||
public @NotNull ISkillPlayer<?> getFactionPlayer() { | ||
return this.factionPlayer; | ||
} | ||
|
||
/** | ||
* @return The skill the event is firing for. | ||
*/ | ||
public @NotNull Holder<Z> skill() { | ||
return this.skill; | ||
} | ||
|
||
/** | ||
* @return The player for which this event is fired | ||
*/ | ||
@NotNull | ||
public Player getPlayer() { | ||
return this.factionPlayer.asEntity(); | ||
} | ||
|
||
/** | ||
* This event is posted before the skill check is conducted. | ||
* If {@link #result} is set using {@link #setResult(de.teamlapen.vampirism.api.entity.player.skills.ISkillHandler.Result)} the check will be skipped. and {@link #getResult()} will be used as the result. | ||
*/ | ||
public static class SkillUnlockCheckEvent<T extends ISkillPlayer<T>> extends SkillEvents<T, ISkill<T>> { | ||
|
||
@Nullable | ||
private ISkillHandler.Result result; | ||
|
||
@ApiStatus.Internal | ||
@SuppressWarnings("unchecked") | ||
public SkillUnlockCheckEvent(@NotNull T skillPlayer, @NotNull Holder<? extends ISkill<?>> skill) { | ||
super(skillPlayer, (Holder<ISkill<T>>) skill); | ||
} | ||
|
||
/** | ||
* Set the result of {@link de.teamlapen.vampirism.api.entity.player.skills.ISkillHandler#canSkillBeEnabled(net.minecraft.core.Holder)} | ||
*/ | ||
public void setResult(@Nullable ISkillHandler.Result result) { | ||
this.result = result; | ||
} | ||
|
||
/** | ||
* The current result if this event | ||
*/ | ||
@Nullable | ||
public ISkillHandler.Result getResult() { | ||
return this.result; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Fired when a skill is disabled for a player | ||
*/ | ||
public static class SkillDisableEvent<T extends ISkillPlayer<T>> extends SkillEvents<T, ISkill<T>> { | ||
|
||
@ApiStatus.Internal | ||
@SuppressWarnings("unchecked") | ||
public SkillDisableEvent(@NotNull T skillPlayer, @NotNull Holder<? extends ISkill<?>> skill) { | ||
super(skillPlayer, (Holder<ISkill<T>>) skill); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Fired when a skill is enabled for a player | ||
*/ | ||
public static class SkillEnableEvent<T extends ISkillPlayer<T>> extends SkillEvents<T, ISkill<T>> { | ||
|
||
private final boolean fromLoading; | ||
|
||
@ApiStatus.Internal | ||
@SuppressWarnings("unchecked") | ||
public SkillEnableEvent(@NotNull T factionPlayer, @NotNull Holder<? extends ISkill<?>> skill, boolean fromLoading) { | ||
super(factionPlayer, (Holder<ISkill<T>>) skill); | ||
this.fromLoading = fromLoading; | ||
} | ||
|
||
/** | ||
* @return If the skill is enabled because the player is loaded from the save file | ||
*/ | ||
public boolean isFromLoading() { | ||
return fromLoading; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters