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

BeaconEvents + Expressions #7079

Open
wants to merge 22 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ 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"));

TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

}
37 changes: 33 additions & 4 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@
import ch.njol.skript.util.slot.InventorySlot;
import ch.njol.skript.util.slot.Slot;
import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
import com.destroystokyo.paper.event.entity.EndermanAttackPlayerEvent;
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import io.papermc.paper.event.entity.EntityMoveEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent;
import io.papermc.paper.event.player.PlayerTradeEvent;
import io.papermc.paper.event.player.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.FireworkEffect;
Expand Down Expand Up @@ -1935,5 +1933,36 @@ public RegainReason get(EntityRegainHealthEvent event) {
return event.getRegainReason();
}
}, EventValues.TIME_NOW);

// BeaconEffectEvent
if (Skript.classExists("com.destroystokyo.paper.event.block.BeaconEffectEvent")) {
EventValues.registerEventValue(BeaconEffectEvent.class, PotionEffectType.class, new Getter<PotionEffectType, BeaconEffectEvent>() {
@Override
public PotionEffectType get(BeaconEffectEvent event) {
return event.getEffect().getType();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BeaconEffectEvent.class, Player.class, new Getter<Player, BeaconEffectEvent>() {
@Override
public Player get(BeaconEffectEvent event) {
return event.getPlayer();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BeaconEffectEvent.class, Boolean.class, new Getter<Boolean, BeaconEffectEvent>() {
@Override
public Boolean get(BeaconEffectEvent event) {
return event.isPrimary();
}
}, EventValues.TIME_NOW, "Use 'applied effect is (primary|secondary)' in beacon effect events", BeaconEffectEvent.class);
}
// PlayerChangeBeaconEffectEvent
if (Skript.classExists("io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent")) {
EventValues.registerEventValue(PlayerChangeBeaconEffectEvent.class, Block.class, new Getter<Block, PlayerChangeBeaconEffectEvent>() {
@Override
public Block get(PlayerChangeBeaconEffectEvent event) {
return event.getBeacon();
}
}, EventValues.TIME_NOW);
}
}
}
59 changes: 59 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondAppliedEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Applied Effect")
@Description("Checks to see if the applied effect of a beacon effect event is primary or secondary")
@Examples({
"on beacon effect:",
"\tif applied effect is primary:",
"\t\tbroadcast \"Is Primary\"",
"\telse if applied effect is secondary:",
"\t\tbroadcast \"Is Secondary\""
})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class CondAppliedEffect extends Condition {

static {
Skript.registerCondition(CondAppliedEffect.class,
"[the] applied effect is [the] (primary|:secondary) [[potion] effect]",
"[the] applied effect (isn't|is not) [the] (primary|:secondary) [[potion] effect]"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
);
}

private boolean checkPrimary;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (!getParser().isCurrentEvent(BeaconEffectEvent.class)) {
Skript.error("This condition can only be used in an on beacon effect event.");
return false;
}
checkPrimary = !parseResult.hasTag("secondary");
if (matchedPattern == 1)
setNegated(true);
return true;
}

@Override
public boolean check(Event event) {
BeaconEffectEvent beaconEffectEvent = (BeaconEffectEvent) event;
boolean isPrimary = beaconEffectEvent.isPrimary();
return isPrimary == checkPrimary;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "applied effect is " + (isNegated() ? "not" : "") + (checkPrimary ? "primary" : "secondary");
}

}
78 changes: 78 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtBeacon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ch.njol.skript.events;

import ch.njol.skript.Skript;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
import io.papermc.paper.event.block.BeaconActivatedEvent;
import io.papermc.paper.event.block.BeaconDeactivatedEvent;
import io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

public class EvtBeacon extends SkriptEvent {

static {
if (Skript.classExists("com.destroystokyo.paper.event.block.BeaconEffectEvent")) {
Skript.registerEvent("Beacon Effect", EvtBeacon.class, BeaconEffectEvent.class, "beacon effect")
.description("Called when a player gets an effect from a beacon.")
.examples(
"on beacon effect:",
"\tbroadcast event-potioneffecttype",
"\tbroadcast event-player",
"\tbroadcast event-block"
)
.since("INSERT VERSION")
.requiredPlugins("Paper");
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}
if (Skript.classExists("io.papermc.paper.event.block.BeaconActivatedEvent")) {
Skript.registerEvent("Beacon Toggle", EvtBeacon.class, new Class[] {BeaconActivatedEvent.class, BeaconDeactivatedEvent.class}, "beacon [:de]activat(e|ion)")
.description("Called when a beacon is activated or deactivated.")
.examples(
"on beacon activate:",
"\tbroadcast event-block"
)
.since("INSERT VERSION")
.requiredPlugins("Paper");
}
if (Skript.classExists("io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent")) {
Skript.registerEvent("Beacon Change Effect", EvtBeacon.class, PlayerChangeBeaconEffectEvent.class,
"beacon change effect", "beacon effect change", "player chang(e[s]|ing) [of] beacon effect")
.description("Called when a player changes the effects of a beacon.")
.examples(
"on beacon effect change:",
"\tbroadcast event-player",
"\tbroadcast event-block",
"\tbroadcast primary beacon effect",
"\tbroadcast secondary beacon effect"
)
.since("INSERT VERSION")
.requiredPlugins("Paper");
}
}

private boolean isActivate;

@Override
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
isActivate = !parseResult.hasTag("de");
return true;
}

@Override
public boolean check(Event event) {
if (event instanceof BeaconActivatedEvent) {
return isActivate;
} else if (event instanceof BeaconDeactivatedEvent) {
return !isActivate;
}
return true;
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "beacon effect/activate/deactivate/change effect";
}
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved

}
Loading