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 3 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
30 changes: 30 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 @@ -88,6 +88,7 @@
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent.Cause;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
Expand All @@ -96,6 +97,7 @@
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTransformEvent;
Expand Down Expand Up @@ -169,6 +171,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.PotionEffectType;
import org.eclipse.jdt.annotation.Nullable;

Expand Down Expand Up @@ -538,6 +541,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 Cause get(EntityPotionEffectEvent event) {
return event.getCause();
}
}, EventValues.TIME_NOW);
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

// ProjectileHitEvent
// ProjectileHitEvent#getHitBlock was added in 1.11
if (Skript.methodExists(ProjectileHitEvent.class, "getHitBlock"))
Expand Down
80 changes: 80 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,80 @@
/**
* 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;
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%]")
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:",
"\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;

@Override
public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult) {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
if (args.length > 0) {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
potionEffects = (Expression<PotionEffectType>) args[0];
}
return true;
}


@Override
public boolean check(Event event) {
if (event instanceof EntityPotionEffectEvent) {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
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 {
return true;
}
}
return false;
}

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