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
61 changes: 31 additions & 30 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,14 @@
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFertilizeEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.block.*;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.*;
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;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTransformEvent;
import org.bukkit.event.entity.EntityTransformEvent.TransformReason;
import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.entity.HorseJumpEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingEvent;
Expand Down Expand Up @@ -169,6 +142,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 +512,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, Cause.class, new Getter<Cause, EntityPotionEffectEvent>() {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
@Override
public 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
93 changes: 93 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,93 @@
/**
* 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,
"add[ing] [of] [entity] potion effect [[of] %potioneffecttypes%]",
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
"remov[e|ing] [of] [entity] potion effect [[of] %potioneffecttypes%]",
"clear[ing] [of] [entity] potion effect [[of] %potioneffecttypes%]",
"chang[e|ing] [of] [entity] potion effect [[of] %potioneffecttypes%]")
.description("Called when an entity's potion effect is modified.", "This modification can include adding, removing or changing their potion effect.")
.examples("on adding potion effect:", "on removing potion effect:", "on changing potion effect:", "on adding potion effect night vision:")
.since("INSERT VERSION");
}

@SuppressWarnings("unchecked")
private Expression<PotionEffectType> potionEffects;
private int matchedPattern;

private EntityPotionEffectEvent.Action action;

@Override
public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult) {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
potionEffects = (Expression<PotionEffectType>) args[0];
switch (matchedPattern) {
case 0:
action = EntityPotionEffectEvent.Action.ADDED;
break;
case 1:
action = EntityPotionEffectEvent.Action.REMOVED;
break;
case 2:
action = EntityPotionEffectEvent.Action.CHANGED;
break;
}
return true;
}

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


@Override
public String toString(@Nullable Event e, boolean debug) {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
return "on entity potion effect";
}
}