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

Entity Potion Effect Event #6532

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e04ce26
Entity Potion Effect Event and event-values
Asleeepp Apr 3, 2024
8189838
Updated syntax for EvtEntityPotion, and readded the imports to EventV…
Asleeepp Apr 7, 2024
569617a
Forgot to change e to event.
Asleeepp Apr 7, 2024
819253d
Added suggested changes :)
Asleeepp Apr 19, 2024
3a86677
silly me
Asleeepp Apr 19, 2024
d62816f
even sillier me (how did I manage to do that)
Asleeepp Apr 19, 2024
3e72634
even sillier me (how did I manage to do that)
Asleeepp Apr 19, 2024
dfe02ab
I don't get why the build is failing
Asleeepp Apr 19, 2024
8ab5484
BRO
Asleeepp Apr 19, 2024
ac1151d
Merge branch 'dev/feature' into addition-entity-potion-effect-event
sovdeeth Apr 19, 2024
8a9b8ee
Merge branch 'dev/feature' into addition-entity-potion-effect-event
sovdeeth Apr 19, 2024
20e990b
Added type stuff, and made check a lot better
Asleeepp Apr 20, 2024
6cdbfef
Merge remote-tracking branch 'origin/addition-entity-potion-effect-ev…
Asleeepp Apr 20, 2024
180f9b3
Changes
Asleeepp Apr 20, 2024
1dcbf6a
change
Asleeepp Apr 20, 2024
2d8e5f7
Merge branch 'dev/feature' into addition-entity-potion-effect-event
sovdeeth Jun 29, 2024
723e288
done
Asleeepp Jul 1, 2024
dcdd8d4
resolve conflict
Asleeepp Jul 1, 2024
ea0518f
Update src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Asleeepp Aug 16, 2024
99467ae
Merge branch 'dev/feature' into addition-entity-potion-effect-event
Asleeepp Aug 16, 2024
68cd6a1
Merge branch 'dev/feature' into addition-entity-potion-effect-event
sovdeeth Sep 22, 2024
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
6 changes: 6 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.EntityTransformEvent.TransformReason;
import org.bukkit.event.inventory.ClickType;
Expand Down Expand Up @@ -1548,6 +1549,11 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Transform Reason")
.description("Represents a transform reason of an <a href='events.html#entity transform'>entity transform event</a>.")
.since("2.8.0"));
Classes.registerClass(new EnumClassInfo<>(EntityPotionEffectEvent.Cause.class, "entitypotioncause", "entity potion causes")
.user("[entity] potion effect cause")
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
.name("Entity Potion Cause")
.description("Represents the cause of the action of a potion effect on an entity, e.g. arrow, command")
.since("INSERT VERSION"));
}

}
30 changes: 17 additions & 13 deletions src/main/java/ch/njol/skript/events/EvtEntityPotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.potion.PotionEffectType;
Expand All @@ -33,7 +33,7 @@ public class EvtEntityPotion extends SkriptEvent {

static {
Skript.registerEvent("Entity Potion Effect", EvtEntityPotion.class, EntityPotionEffectEvent.class,
"entity potion effect [modif[y|ication]] [[of] %potioneffecttypes%]")
"entity potion effect [modif[y|ication]] [[of] %potioneffecttypes%] [due to %entitypotioncause%]")
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
.description("Called when an entity's potion effect is modified.", "This modification can include adding, removing or changing their potion effect.")
.examples(
"on entity potion effect modification:",
Expand All @@ -47,7 +47,7 @@ public class EvtEntityPotion extends SkriptEvent {
private Expression<PotionEffectType> potionEffects;

@Override
public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult) {
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) {
if (args.length > 0) {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
potionEffects = (Expression<PotionEffectType>) args[0];
}
Expand All @@ -57,22 +57,26 @@ public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseRes

@Override
public boolean check(Event event) {
if (event instanceof EntityPotionEffectEvent) {
EntityPotionEffectEvent potionEvent = (EntityPotionEffectEvent) event;
if (potionEffects != null && potionEvent.getNewEffect() != null) {
PotionEffectType effectType = potionEvent.getNewEffect().getType();
for (PotionEffectType potionEffectType : potionEffects.getArray(event)) {
if (potionEffectType.equals(effectType)) {
return true;
}
}
} else {
if (!(event instanceof EntityPotionEffectEvent)) {
return false;
}

Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
EntityPotionEffectEvent potionEvent = (EntityPotionEffectEvent) event;
if (potionEffects == null || potionEvent.getNewEffect() == null) {
return false;
}

PotionEffectType effectType = potionEvent.getNewEffect().getType();
for (PotionEffectType potionEffectType : potionEffects.getArray(event)) {
if (potionEffectType.equals(effectType)) {
return true;
}
}

return false;
}


@Override
public String toString(@Nullable Event event, boolean debug) {
return "on entity potion effect modification";
Expand Down
Loading