Skip to content

Commit e96f91d

Browse files
authored
Merge branch 'dev/feature' into feature/dyed-expr
2 parents 83a896c + b5160e2 commit e96f91d

File tree

11 files changed

+556
-2
lines changed

11 files changed

+556
-2
lines changed

src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java

+40-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
import org.bukkit.event.block.BlockIgniteEvent;
8585
import org.bukkit.event.block.BlockPlaceEvent;
8686
import org.bukkit.event.block.SignChangeEvent;
87+
import org.bukkit.event.block.BellRingEvent;
88+
import org.bukkit.event.block.BellResonateEvent;
8789
import org.bukkit.event.enchantment.EnchantItemEvent;
8890
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
8991
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
@@ -1799,6 +1801,44 @@ public TransformReason get(EntityTransformEvent event) {
17991801
}
18001802
}, EventValues.TIME_NOW);
18011803

1804+
// BellRingEvent - these are BlockEvents and not EntityEvents, so they have declared methods for getEntity()
1805+
if (Skript.classExists("org.bukkit.event.block.BellRingEvent")) {
1806+
EventValues.registerEventValue(BellRingEvent.class, Entity.class, new Getter<Entity, BellRingEvent>() {
1807+
@Override
1808+
@Nullable
1809+
public Entity get(BellRingEvent event) {
1810+
return event.getEntity();
1811+
}
1812+
}, EventValues.TIME_NOW);
1813+
1814+
EventValues.registerEventValue(BellRingEvent.class, Direction.class, new Getter<Direction, BellRingEvent>() {
1815+
@Override
1816+
public Direction get(BellRingEvent event) {
1817+
return new Direction(event.getDirection(), 1);
1818+
}
1819+
}, EventValues.TIME_NOW);
1820+
} else if (Skript.classExists("io.papermc.paper.event.block.BellRingEvent")) {
1821+
EventValues.registerEventValue(
1822+
io.papermc.paper.event.block.BellRingEvent.class, Entity.class,
1823+
new Getter<Entity, io.papermc.paper.event.block.BellRingEvent>() {
1824+
@Override
1825+
@Nullable
1826+
public Entity get(io.papermc.paper.event.block.BellRingEvent event) {
1827+
return event.getEntity();
1828+
}
1829+
}, EventValues.TIME_NOW);
1830+
}
1831+
1832+
if (Skript.classExists("org.bukkit.event.block.BellResonateEvent")) {
1833+
EventValues.registerEventValue(BellResonateEvent.class, Entity[].class, new Getter<Entity[], BellResonateEvent>() {
1834+
@Override
1835+
@Nullable
1836+
public Entity[] get(BellResonateEvent event) {
1837+
return event.getResonatedEntities().toArray(new LivingEntity[0]);
1838+
}
1839+
}, EventValues.TIME_NOW);
1840+
}
1841+
18021842
// InventoryMoveItemEvent
18031843
EventValues.registerEventValue(InventoryMoveItemEvent.class, Inventory.class, new Getter<Inventory, InventoryMoveItemEvent>() {
18041844
@Override
@@ -1830,7 +1870,5 @@ public ItemStack get(InventoryMoveItemEvent event) {
18301870
return event.getItem();
18311871
}
18321872
}, EventValues.TIME_NOW);
1833-
18341873
}
1835-
18361874
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* This file is part of Skript.
3+
*
4+
* Skript is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Skript is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* Copyright Peter Güttinger, SkriptLang team and contributors
18+
*/
19+
package ch.njol.skript.conditions;
20+
21+
import ch.njol.skript.Skript;
22+
import ch.njol.skript.conditions.base.PropertyCondition;
23+
import ch.njol.skript.doc.Description;
24+
import ch.njol.skript.doc.Examples;
25+
import ch.njol.skript.doc.Name;
26+
import ch.njol.skript.doc.RequiredPlugins;
27+
import ch.njol.skript.doc.Since;
28+
import org.bukkit.block.Bell;
29+
import org.bukkit.block.Block;
30+
import org.bukkit.block.BlockState;
31+
32+
@Name("Bell Is Resonating")
33+
@Description({
34+
"Checks to see if a bell is currently resonating.",
35+
"A bell will start resonating five game ticks after being rung, and will continue to resonate for 40 game ticks."
36+
})
37+
@Examples("target block is resonating")
38+
@RequiredPlugins("Spigot 1.19.4+")
39+
@Since("INSERT VERSION")
40+
public class CondIsResonating extends PropertyCondition<Block> {
41+
42+
static {
43+
if (Skript.classExists("org.bukkit.block.Bell") && Skript.methodExists(Bell.class, "isResonating"))
44+
register(CondIsResonating.class, "resonating", "blocks");
45+
}
46+
47+
@Override
48+
public boolean check(Block value) {
49+
BlockState state = value.getState(false);
50+
return state instanceof Bell && ((Bell) state).isResonating();
51+
}
52+
53+
@Override
54+
protected String getPropertyName() {
55+
return "resonating";
56+
}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* This file is part of Skript.
3+
*
4+
* Skript is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Skript is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* Copyright Peter Güttinger, SkriptLang team and contributors
18+
*/
19+
package ch.njol.skript.conditions;
20+
21+
import ch.njol.skript.Skript;
22+
import ch.njol.skript.conditions.base.PropertyCondition;
23+
import ch.njol.skript.doc.Description;
24+
import ch.njol.skript.doc.Examples;
25+
import ch.njol.skript.doc.Name;
26+
import ch.njol.skript.doc.RequiredPlugins;
27+
import ch.njol.skript.doc.Since;
28+
import org.bukkit.block.Bell;
29+
import org.bukkit.block.Block;
30+
import org.bukkit.block.BlockState;
31+
32+
@Name("Bell Is Ringing")
33+
@Description("Checks to see if a bell is currently ringing. A bell typically rings for 50 game ticks.")
34+
@Examples("target block is ringing")
35+
@RequiredPlugins("Spigot 1.19.4+")
36+
@Since("INSERT VERSION")
37+
public class CondIsRinging extends PropertyCondition<Block> {
38+
39+
static {
40+
if (Skript.classExists("org.bukkit.block.Bell") && Skript.methodExists(Bell.class, "isShaking"))
41+
register(CondIsRinging.class, "ringing", "blocks");
42+
}
43+
44+
@Override
45+
public boolean check(Block value) {
46+
BlockState state = value.getState(false);
47+
return state instanceof Bell && ((Bell) state).isShaking();
48+
}
49+
50+
@Override
51+
protected String getPropertyName() {
52+
return "ringing";
53+
}
54+
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* This file is part of Skript.
3+
*
4+
* Skript is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Skript is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* Copyright Peter Güttinger, SkriptLang team and contributors
18+
*/
19+
package ch.njol.skript.effects;
20+
21+
import ch.njol.skript.Skript;
22+
import ch.njol.skript.doc.Description;
23+
import ch.njol.skript.doc.Examples;
24+
import ch.njol.skript.doc.Name;
25+
import ch.njol.skript.doc.RequiredPlugins;
26+
import ch.njol.skript.doc.Since;
27+
import ch.njol.skript.lang.Effect;
28+
import ch.njol.skript.lang.Expression;
29+
import ch.njol.skript.lang.SkriptParser.ParseResult;
30+
import ch.njol.skript.util.Direction;
31+
import ch.njol.util.Kleenean;
32+
import org.bukkit.block.Bell;
33+
import org.bukkit.block.Block;
34+
import org.bukkit.block.BlockFace;
35+
import org.bukkit.block.BlockState;
36+
import org.bukkit.entity.Entity;
37+
import org.bukkit.event.Event;
38+
import org.eclipse.jdt.annotation.Nullable;
39+
40+
@Name("Ring Bell")
41+
@Description({
42+
"Causes a bell to ring.",
43+
"Optionally, the entity that rang the bell and the direction the bell should ring can be specified.",
44+
"A bell can only ring in two directions, and the direction is determined by which way the bell is facing.",
45+
"By default, the bell will ring in the direction it is facing.",
46+
})
47+
@Examples({"make player ring target-block"})
48+
@RequiredPlugins("Spigot 1.19.4+")
49+
@Since("INSERT VERSION")
50+
public class EffRing extends Effect {
51+
52+
static {
53+
if (Skript.classExists("org.bukkit.block.Bell") && Skript.methodExists(Bell.class, "ring", Entity.class, BlockFace.class))
54+
Skript.registerEffect(EffRing.class,
55+
"ring %blocks% [from [the]] [%-direction%]",
56+
"(make|let) %entity% ring %blocks% [from [the]] [%-direction%]"
57+
);
58+
}
59+
60+
@Nullable
61+
private Expression<Entity> entity;
62+
63+
@SuppressWarnings("NotNullFieldNotInitialized")
64+
private Expression<Block> blocks;
65+
66+
@Nullable
67+
private Expression<Direction> direction;
68+
69+
@Override
70+
@SuppressWarnings("unchecked")
71+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
72+
entity = matchedPattern == 0 ? null : (Expression<Entity>) exprs[0];
73+
blocks = (Expression<Block>) exprs[matchedPattern];
74+
direction = (Expression<Direction>) exprs[matchedPattern + 1];
75+
return true;
76+
}
77+
78+
@Nullable
79+
private BlockFace getBlockFace(Event event) {
80+
if (this.direction == null)
81+
return null;
82+
83+
Direction direction = this.direction.getSingle(event);
84+
if (direction == null)
85+
return null;
86+
87+
return Direction.getFacing(direction.getDirection(), true);
88+
}
89+
90+
@Override
91+
protected void execute(Event event) {
92+
BlockFace blockFace = getBlockFace(event);
93+
Entity actualEntity = entity == null ? null : entity.getSingle(event);
94+
95+
for (Block block : blocks.getArray(event)) {
96+
BlockState state = block.getState(false);
97+
if (state instanceof Bell) {
98+
Bell bell = (Bell) state;
99+
bell.ring(actualEntity, blockFace);
100+
}
101+
}
102+
}
103+
104+
@Override
105+
public String toString(@Nullable Event event, boolean debug) {
106+
return (entity != null ? "make " + entity.toString(event, debug) + " " : "") +
107+
"ring " + blocks.toString(event, debug) + " from " + (direction != null ? direction.toString(event, debug) : "");
108+
}
109+
110+
}

src/main/java/ch/njol/skript/events/SimpleEvents.java

+40
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.papermc.paper.event.player.PlayerDeepSleepEvent;
3333
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
3434
import io.papermc.paper.event.player.PlayerTradeEvent;
35+
import org.bukkit.event.Event;
3536
import org.bukkit.event.block.BlockCanBuildEvent;
3637
import org.bukkit.event.block.BlockDamageEvent;
3738
import org.bukkit.event.block.BlockFertilizeEvent;
@@ -740,6 +741,45 @@ public class SimpleEvents {
740741
)
741742
.since("2.7");
742743

744+
{
745+
final Class<? extends Event> eventClass;
746+
if (Skript.classExists("org.bukkit.event.block.BellRingEvent")) {
747+
eventClass = org.bukkit.event.block.BellRingEvent.class;
748+
} else if (Skript.classExists("io.papermc.paper.event.block.BellRingEvent")) {
749+
//noinspection deprecation
750+
eventClass = io.papermc.paper.event.block.BellRingEvent.class;
751+
} else {
752+
eventClass = null;
753+
}
754+
755+
if (eventClass != null) {
756+
Skript.registerEvent("Bell Ring", SimpleEvent.class, eventClass, "bell ring[ing]")
757+
.description("Called when a bell is rung.")
758+
.examples(
759+
"on bell ring:",
760+
"\tsend \"<gold>Ding-dong!<reset>\" to all players in radius 10 of event-block"
761+
)
762+
.since("INSERT VERSION")
763+
.requiredPlugins("Spigot 1.19.4+ or Paper 1.16.5+ (no event-direction)");
764+
}
765+
}
766+
767+
/*
768+
* Paper supported this in 1.16.5 via io.papermc.paper.event.block.BellRevealRaiderEvent.
769+
* The Paper event, however, is called for each raider, while the Spigot event is called once for all raiders.
770+
* Supporting both would cause confusing behaviour, with the event being triggered in different ways depending
771+
* on the server software and version, so we're only supporting the Spigot event.
772+
*/
773+
if (Skript.classExists("org.bukkit.event.block.BellResonateEvent")) {
774+
Skript.registerEvent("Bell Resonate", SimpleEvent.class, org.bukkit.event.block.BellResonateEvent.class, "bell resonat(e|ing)")
775+
.description("Called when a bell resonates, highlighting nearby raiders.")
776+
.examples(
777+
"on bell resonate:",
778+
"\tsend \"<red>Raiders are nearby!\" to all players in radius 32 around event-block"
779+
)
780+
.since("INSERT VERSION")
781+
.requiredPlugins("Spigot 1.19.4+");
782+
}
743783
}
744784

745785
}

0 commit comments

Comments
 (0)