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 7 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
6 changes: 2 additions & 4 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.*;
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
Expand Down Expand Up @@ -1526,6 +1523,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 @Nullable PotionEffectType get(BeaconEffectEvent event) {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
return event.getEffect().getType();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BeaconEffectEvent.class, Player.class, new Getter<Player, BeaconEffectEvent>() {
@Override
public @Nullable Player get(BeaconEffectEvent event) {
return event.getPlayer();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BeaconEffectEvent.class, Boolean.class, new Getter<Boolean, BeaconEffectEvent>() {
@Override
public @Nullable 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 @Nullable Block get(PlayerChangeBeaconEffectEvent event) {
return event.getBeacon();
}
}, EventValues.TIME_NOW);
}
}
}
62 changes: 62 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,62 @@
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,
"applied effect is primary",
"applied effect is secondary"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
);
}

private int pattern;

@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 a on beacon effect event.");
return false;
}
pattern = matchedPattern;
return true;
}

@Override
public boolean check(Event event) {
BeaconEffectEvent beaconEffectEvent = (BeaconEffectEvent) event;
boolean isPrimary = beaconEffectEvent.isPrimary();
if (pattern == 0) {
return isPrimary;
} else if (pattern == 1) {
return !isPrimary;
}
return false;
}

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

}
77 changes: 77 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,77 @@
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]activate")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.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")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.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