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 18 commits
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 @@ -60,6 +60,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 @@ -1556,6 +1557,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"));
}

}
29 changes: 29 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTransformEvent;
import org.bukkit.event.entity.EntityTransformEvent.TransformReason;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.entity.HorseJumpEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
Expand Down Expand Up @@ -174,6 +175,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.Recipe;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
Expand Down Expand Up @@ -545,6 +547,33 @@ public DamageCause get(final EntityDeathEvent e) {
return ldc == null ? null : ldc.getCause();
}
}, 0);

// Entity Potion Effect
EventValues.registerEventValue(EntityPotionEffectEvent.class, PotionEffect.class, new Getter<PotionEffect, EntityPotionEffectEvent>() {
@Override
public PotionEffect get(EntityPotionEffectEvent event) {
return event.getOldEffect();
}
}, EventValues.TIME_PAST);
EventValues.registerEventValue(EntityPotionEffectEvent.class, PotionEffect.class, new Getter<PotionEffect, EntityPotionEffectEvent>() {
@Override
public PotionEffect get(EntityPotionEffectEvent event) {
return event.getNewEffect();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(EntityPotionEffectEvent.class, PotionEffectType.class, new Getter<PotionEffectType, EntityPotionEffectEvent>() {
@Override
public PotionEffectType get(EntityPotionEffectEvent event) {
return event.getModifiedType();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(EntityPotionEffectEvent.class, EntityPotionEffectEvent.Cause.class, new Getter<EntityPotionEffectEvent.Cause, EntityPotionEffectEvent>() {
@Override
public EntityPotionEffectEvent.Cause get(EntityPotionEffectEvent event) {
return event.getCause();
}
}, EventValues.TIME_NOW);

// ProjectileHitEvent
// ProjectileHitEvent#getHitBlock was added in 1.11
if (Skript.methodExists(ProjectileHitEvent.class, "getHitBlock"))
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtEntityPotion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.events;

import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.potion.PotionEffectType;

import javax.annotation.Nullable;

public class EvtEntityPotion extends SkriptEvent {

static {
Skript.registerEvent("Entity Potion Effect", EvtEntityPotion.class, EntityPotionEffectEvent.class,
"entity potion effect [modif[y|ication]] [[of] %-potioneffecttypes%] [due to %-entitypotioncause%]")
.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:",
"\t\tbroadcast \"A potion effect was added to %event-entity%!\" ",
"",
"on entity potion effect modification of night vision:")
.since("INSERT VERSION");
}

@SuppressWarnings("unchecked")
private Expression<PotionEffectType> potionEffects;
private Expression<EntityPotionEffectEvent.Cause> cause;

@Override
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) {
potionEffects = (Expression<PotionEffectType>) args[0];
cause = (Expression<EntityPotionEffectEvent.Cause>) args[1];
return true;
}

@Override
public boolean check(Event event) {
EntityPotionEffectEvent potionEvent = (EntityPotionEffectEvent) event;
boolean effectMatches = potionEffects == null ||
(potionEvent.getOldEffect() != null && potionEffects.check(event, effectType -> effectType.equals(potionEvent.getOldEffect().getType()))) ||
(potionEvent.getNewEffect() != null && potionEffects.check(event, effectType -> effectType.equals(potionEvent.getNewEffect().getType())));

boolean causeMatches = cause == null || cause.check(event, cause -> cause.equals(potionEvent.getCause()));

return effectMatches && causeMatches;
}


@Override
public String toString(@Nullable Event event, boolean debug) {
return "on entity potion effect modification";
}
}
26 changes: 26 additions & 0 deletions src/main/resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,32 @@ environments:
the_end: end, the end
custom: custom


entity potion causes:
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
area_effect_cloud: enter area effect cloud
arrow: arrow infliction
attack: attack
beacon: beacon effect
command: command
conduit: conduit effect
conversion: conversion, converted
death: death
dolphin: dolphin boost
expiration: expiration, expired
food: food
illusion: illusion
milk: drinking milk
plugin: plugin
potion_drink: potion drunk, drinking potion
potion_splash: potion splash, splash potion
spider_spawn: spider spawn, spawned spider
totem: removal by resurrection
turtle_helmet: turtle helmet effect
unknown: unknown
villager_trade: villager trade
patrol_captain: pillager captain, patrol captain
wither_rose: wither rose infliction

# -- Moon Phases --
moon phases:
first_quarter: first quarter
Expand Down