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 34 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 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
9fbbe65
Merge remote-tracking branch 'upstream/dev/feature' into dev/beacon-e…
TheAbsolutionism Dec 15, 2024
eaa75e9
Merge remote-tracking branch 'upstream/dev/feature' into dev/beacon-e…
TheAbsolutionism Dec 18, 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
51 changes: 39 additions & 12 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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;
Expand All @@ -53,6 +54,7 @@
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.PlayerChangeBeaconEffectEvent;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.FireworkEffect;
Expand Down Expand Up @@ -1896,19 +1898,19 @@ public TransformReason get(EntityTransformEvent event) {
// BellRingEvent - these are BlockEvents and not EntityEvents, so they have declared methods for getEntity()
if (Skript.classExists("org.bukkit.event.block.BellRingEvent")) {
EventValues.registerEventValue(BellRingEvent.class, Entity.class, new Getter<Entity, BellRingEvent>() {
@Override
@Nullable
public Entity get(BellRingEvent event) {
return event.getEntity();
}
}, EventValues.TIME_NOW);
@Override
@Nullable
public Entity get(BellRingEvent event) {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
return event.getEntity();
}
}, EventValues.TIME_NOW);

EventValues.registerEventValue(BellRingEvent.class, Direction.class, new Getter<Direction, BellRingEvent>() {
@Override
public Direction get(BellRingEvent event) {
return new Direction(event.getDirection(), 1);
}
}, EventValues.TIME_NOW);
@Override
public Direction get(BellRingEvent event) {
return new Direction(event.getDirection(), 1);
}
}, EventValues.TIME_NOW);
} else if (Skript.classExists("io.papermc.paper.event.block.BellRingEvent")) {
EventValues.registerEventValue(
io.papermc.paper.event.block.BellRingEvent.class, Entity.class,
Expand All @@ -1930,7 +1932,7 @@ public Entity[] get(BellResonateEvent event) {
}
}, EventValues.TIME_NOW);
}

// InventoryMoveItemEvent
EventValues.registerEventValue(InventoryMoveItemEvent.class, Inventory.class, new Getter<Inventory, InventoryMoveItemEvent>() {
@Override
Expand Down Expand Up @@ -2018,5 +2020,30 @@ public Timespan get(PlayerExpCooldownChangeEvent event) {
}
}, EventValues.TIME_PAST);


// 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, "Use 'applied effect' in beacon effect events.", BeaconEffectEvent.class);
EventValues.registerEventValue(BeaconEffectEvent.class, Player.class, new Getter<Player, BeaconEffectEvent>() {
@Override
public Player get(BeaconEffectEvent event) {
return event.getPlayer();
}
}, EventValues.TIME_NOW);
}
// 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);
}
}
}
73 changes: 73 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtBeaconEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ch.njol.skript.events;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.classes.data.DefaultComparators;
import ch.njol.skript.doc.*;
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 org.bukkit.event.Event;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.comparator.Relation;

@Name("Beacon Effect")
@Description("Called when a player gets an effect from a beacon.")
@Examples({
"on beacon effect:",
"\tbroadcast applied effect",
"\tbroadcast event-player",
"\tbroadcast event-block",
"on primary beacon effect apply of haste:",
"on application of secondary beacon effect:",
"on beacon effect of speed:"
})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class EvtBeaconEffect extends SkriptEvent {

static {
if (Skript.classExists("com.destroystokyo.paper.event.block.BeaconEffectEvent"))
Skript.registerEvent("Beacon Effect", EvtBeaconEffect.class, BeaconEffectEvent.class,
"[:primary|:secondary] beacon effect [of %-potioneffecttypes%]",
"application of [:primary|:secondary] beacon effect [of %-potioneffecttypes%]",
"[:primary|:secondary] beacon effect apply [of %-potioneffecttypes%]");

}

private @Nullable Literal<PotionEffectType> potionTypes;
private @Nullable Boolean primaryCheck;

@Override
@SuppressWarnings("unchecked")
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
potionTypes = (Literal<PotionEffectType>) exprs[0];
if (parseResult.hasTag("primary")) {
primaryCheck = true;
} else if (parseResult.hasTag("secondary")) {
primaryCheck = false;
}
return true;
}

@Override
public boolean check(Event event) {
if (!(event instanceof BeaconEffectEvent effectEvent))
return false;
if (primaryCheck != null && effectEvent.isPrimary() != primaryCheck)
return false;
if (potionTypes != null) {
return potionTypes.check(event, type -> effectEvent.getEffect().getType() == type);
}
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return (primaryCheck == null ? "" : primaryCheck ? "primary " : "secondary ") +
"beacon effect" + (potionTypes == null ? "" : " of " + potionTypes.toString(event, debug));
}

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

import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import io.papermc.paper.event.block.BeaconActivatedEvent;
import io.papermc.paper.event.block.BeaconDeactivatedEvent;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Beacon Toggle")
@Description("Called when a beacon is activated or deactivated.")
@Examples({
"on beacon toggle:",
"on beacon activate:",
"on beacon deactivate:"
})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class EvtBeaconToggle extends SkriptEvent {

static {
if (Skript.classExists("io.papermc.paper.event.block.BeaconActivatedEvent"))
Skript.registerEvent("Beacon Toggle", EvtBeaconToggle.class, new Class[] {BeaconActivatedEvent.class, BeaconDeactivatedEvent.class},
"beacon toggle",
"beacon activat(e|ion)",
"beacon deactivat(e|ion)");
}

private boolean isActivate, isToggle;

@Override
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
isToggle = matchedPattern == 0;
isActivate = matchedPattern == 1;
return true;
}

@Override
public boolean check(Event event) {
if (!isToggle) {
if (event instanceof BeaconActivatedEvent) {
return isActivate;
} else if (event instanceof BeaconDeactivatedEvent) {
return !isActivate;
}
}
return true;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "beacon " + (isToggle ? "toggle" : isActivate ? "activate" : "deactivate");
}

}
34 changes: 26 additions & 8 deletions src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.event.world.SpawnChangeEvent;
import io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent;

/**
* @author Peter Güttinger
Expand Down Expand Up @@ -475,7 +476,7 @@ public class SimpleEvents {
.description("Called when a player enters a world. Does not work with other entities!")
.examples("on player world change:",
" world is \"city\"",
" send \"Welcome to the City!\"")
" send \"Welcome to the City!\"")
.since("2.2-dev28");
Skript.registerEvent("Flight Toggle", SimpleEvent.class, PlayerToggleFlightEvent.class, "[player] flight toggl(e|ing)", "[player] toggl(e|ing) flight")
.description("Called when a players stops/starts flying.")
Expand Down Expand Up @@ -504,11 +505,11 @@ public class SimpleEvents {
if (Skript.classExists("org.bukkit.event.player.PlayerSwapHandItemsEvent")) {
Skript.registerEvent("Hand Item Swap", SimpleEvent.class, PlayerSwapHandItemsEvent.class, "swap[ping of] [(hand|held)] item[s]")
.description("Called whenever a player swaps the items in their main- and offhand slots.",
"Works also when one or both of the slots are empty.",
"The event is called before the items are actually swapped,",
"so when you use the player's tool or player's offtool expressions,",
"they will return the values before the swap -",
"this enables you to cancel the event before anything happens.")
"Works also when one or both of the slots are empty.",
"The event is called before the items are actually swapped,",
"so when you use the player's tool or player's offtool expressions,",
"they will return the values before the swap -",
"this enables you to cancel the event before anything happens.")
.examples("on swap hand items:",
" event-player's tool is a diamond sword",
" cancel event")
Expand Down Expand Up @@ -639,7 +640,7 @@ public class SimpleEvents {
if (Skript.classExists("com.destroystokyo.paper.event.block.AnvilDamagedEvent")) {
Skript.registerEvent("Anvil Damage", SimpleEvent.class, AnvilDamagedEvent.class, "anvil damag(e|ing)")
.description("Called when an anvil is damaged/broken from being used to repair/rename items.",
"Note: this does not include anvil damage from falling.")
"Note: this does not include anvil damage from falling.")
.requiredPlugins("Paper")
.examples("on anvil damage:",
"\tcancel the event")
Expand Down Expand Up @@ -685,7 +686,7 @@ public class SimpleEvents {
)
.since("2.7");
}

//noinspection deprecation
Skript.registerEvent("Chat", SimpleEvent.class, AsyncPlayerChatEvent.class, "chat")
.description(
Expand Down Expand Up @@ -823,6 +824,23 @@ public class SimpleEvents {
.requiredPlugins("Paper");
}

if (Skript.classExists("io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent")) {
Skript.registerEvent("Beacon Change Effect", SimpleEvent.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",
"on beacon change effect:",
"on player change beacon effect:"
)
.since("INSERT VERSION")
.requiredPlugins("Paper");
}

Skript.registerEvent("Broadcast", SimpleEvent.class, BroadcastMessageEvent.class, "broadcast")
.description("Called when a message is broadcasted.")
.examples(
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprAppliedEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ch.njol.skript.expressions;

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

@Name("Applied Beacon Effect")
@Description("The type of effect applied by a beacon.")
@Examples({
"on beacon effect:",
"\tif the applied effect is primary beacon effect:",
"\t\tbroadcast \"Is Primary\"",
"\telse if applied effect = secondary effect:",
"\t\tbroadcast \"Is Secondary\""
})
@Events("Beacon Effect")
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
public class ExprAppliedEffect extends SimpleExpression<PotionEffectType> {

static {
if (Skript.classExists("com.destroystokyo.paper.event.block.BeaconEffectEvent")) {
Skript.registerExpression(ExprAppliedEffect.class, PotionEffectType.class, ExpressionType.SIMPLE, "[the] applied [beacon] effect");
}
}


@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (!getParser().isCurrentEvent(BeaconEffectEvent.class)) {
Skript.error("You can only use 'applied effect' in a beacon effect event.");
return false;
}
return true;
}

@Override
protected PotionEffectType @Nullable [] get(Event event) {
if (!(event instanceof BeaconEffectEvent effectEvent))
return null;
return new PotionEffectType[]{effectEvent.getEffect().getType()};
}

@Override
public Class<PotionEffectType> getReturnType() {
return PotionEffectType.class;
}

@Override
public boolean isSingle() {
return true;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "applied effect";
}

}
Loading