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 32 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
30667ef
Starter Commit
TheAbsolutionism Sep 14, 2024
f70523c
Requested Changes
TheAbsolutionism Sep 15, 2024
8d4bd83
Doc Fix
TheAbsolutionism Sep 15, 2024
d717601
cleanup
TheAbsolutionism Sep 15, 2024
8547c55
Remove Beacon Values
TheAbsolutionism Sep 15, 2024
8781610
Changes
TheAbsolutionism Sep 16, 2024
4fa3dd6
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Sep 19, 2024
9e76bd4
Requested Changes
TheAbsolutionism Sep 20, 2024
7b467d4
Revert Test
TheAbsolutionism Sep 20, 2024
7f35180
Fix JUnit
TheAbsolutionism Sep 20, 2024
c2e7df1
Requested Changes
TheAbsolutionism Sep 21, 2024
4741ff7
Requested Changes
TheAbsolutionism Sep 21, 2024
2cca8b9
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Sep 21, 2024
fcb90c0
:)
TheAbsolutionism Sep 21, 2024
c69e9cb
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Sep 22, 2024
21ef704
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Sep 22, 2024
f6ab79d
Requested Changes
TheAbsolutionism Sep 22, 2024
fb46302
Merge branch 'dev/beacon-events' of https://github.com/TheAbsolutioni…
TheAbsolutionism Sep 22, 2024
48be9ac
More Changes
TheAbsolutionism Sep 22, 2024
5f1e438
Requested Changes
TheAbsolutionism Sep 24, 2024
c9fa0bd
Change
TheAbsolutionism Sep 24, 2024
ef4f467
Requested Changes
TheAbsolutionism Sep 29, 2024
69193ba
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Oct 1, 2024
212ac88
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Oct 2, 2024
4ce0465
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Oct 6, 2024
61fd200
Merge remote-tracking branch 'upstream/dev/feature' into dev/beacon-e…
TheAbsolutionism Oct 13, 2024
041a45f
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Oct 15, 2024
39d31b8
Merge remote-tracking branch 'upstream/dev/feature' into dev/beacon-e…
TheAbsolutionism Oct 27, 2024
b56b63e
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Nov 11, 2024
cdf9f7c
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Nov 16, 2024
27d9291
Miniscule Changes
TheAbsolutionism Nov 23, 2024
e318eef
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Nov 23, 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
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