-
-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(events): add events for bells * feat(test): bell events junit tests * feat(syntax): bell related properties * fix(bells): fix incorrect values * feat(bells): add ring effect * fix(test): don't test ringing time pre-1.19.4 * fix(bells): check if Bells exist before using them * fix(bells): more checking if bells exist * chore(docs): specify Spigot instead of Minecraft Co-authored-by: LimeGlass <[email protected]> * fix(docs): specify Bell in syntax names Co-authored-by: LimeGlass <[email protected]> * chore(codestyle): non-invasive codestyle changes Co-authored-by: LimeGlass <[email protected]> * chore(codestyle): import ParseResult * chore: suggestions from code review Co-authored-by: Patrick Miller <[email protected]> * fix(docs): clarify event-direction as missing from paper 1.16.5 * fix: remove reflective call to necessarily non-existent constructor --------- Co-authored-by: LimeGlass <[email protected]> Co-authored-by: Patrick Miller <[email protected]> Co-authored-by: Moderocky <[email protected]>
- Loading branch information
1 parent
0827e01
commit b5160e2
Showing
11 changed files
with
556 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/ch/njol/skript/conditions/CondIsResonating.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.conditions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.conditions.base.PropertyCondition; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.RequiredPlugins; | ||
import ch.njol.skript.doc.Since; | ||
import org.bukkit.block.Bell; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockState; | ||
|
||
@Name("Bell Is Resonating") | ||
@Description({ | ||
"Checks to see if a bell is currently resonating.", | ||
"A bell will start resonating five game ticks after being rung, and will continue to resonate for 40 game ticks." | ||
}) | ||
@Examples("target block is resonating") | ||
@RequiredPlugins("Spigot 1.19.4+") | ||
@Since("INSERT VERSION") | ||
public class CondIsResonating extends PropertyCondition<Block> { | ||
|
||
static { | ||
if (Skript.classExists("org.bukkit.block.Bell") && Skript.methodExists(Bell.class, "isResonating")) | ||
register(CondIsResonating.class, "resonating", "blocks"); | ||
} | ||
|
||
@Override | ||
public boolean check(Block value) { | ||
BlockState state = value.getState(false); | ||
return state instanceof Bell && ((Bell) state).isResonating(); | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "resonating"; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/ch/njol/skript/conditions/CondIsRinging.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.conditions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.conditions.base.PropertyCondition; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.RequiredPlugins; | ||
import ch.njol.skript.doc.Since; | ||
import org.bukkit.block.Bell; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockState; | ||
|
||
@Name("Bell Is Ringing") | ||
@Description("Checks to see if a bell is currently ringing. A bell typically rings for 50 game ticks.") | ||
@Examples("target block is ringing") | ||
@RequiredPlugins("Spigot 1.19.4+") | ||
@Since("INSERT VERSION") | ||
public class CondIsRinging extends PropertyCondition<Block> { | ||
|
||
static { | ||
if (Skript.classExists("org.bukkit.block.Bell") && Skript.methodExists(Bell.class, "isShaking")) | ||
register(CondIsRinging.class, "ringing", "blocks"); | ||
} | ||
|
||
@Override | ||
public boolean check(Block value) { | ||
BlockState state = value.getState(false); | ||
return state instanceof Bell && ((Bell) state).isShaking(); | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "ringing"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.RequiredPlugins; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.util.Direction; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.block.Bell; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.block.BlockState; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.event.Event; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
@Name("Ring Bell") | ||
@Description({ | ||
"Causes a bell to ring.", | ||
"Optionally, the entity that rang the bell and the direction the bell should ring can be specified.", | ||
"A bell can only ring in two directions, and the direction is determined by which way the bell is facing.", | ||
"By default, the bell will ring in the direction it is facing.", | ||
}) | ||
@Examples({"make player ring target-block"}) | ||
@RequiredPlugins("Spigot 1.19.4+") | ||
@Since("INSERT VERSION") | ||
public class EffRing extends Effect { | ||
|
||
static { | ||
if (Skript.classExists("org.bukkit.block.Bell") && Skript.methodExists(Bell.class, "ring", Entity.class, BlockFace.class)) | ||
Skript.registerEffect(EffRing.class, | ||
"ring %blocks% [from [the]] [%-direction%]", | ||
"(make|let) %entity% ring %blocks% [from [the]] [%-direction%]" | ||
); | ||
} | ||
|
||
@Nullable | ||
private Expression<Entity> entity; | ||
|
||
@SuppressWarnings("NotNullFieldNotInitialized") | ||
private Expression<Block> blocks; | ||
|
||
@Nullable | ||
private Expression<Direction> direction; | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
entity = matchedPattern == 0 ? null : (Expression<Entity>) exprs[0]; | ||
blocks = (Expression<Block>) exprs[matchedPattern]; | ||
direction = (Expression<Direction>) exprs[matchedPattern + 1]; | ||
return true; | ||
} | ||
|
||
@Nullable | ||
private BlockFace getBlockFace(Event event) { | ||
if (this.direction == null) | ||
return null; | ||
|
||
Direction direction = this.direction.getSingle(event); | ||
if (direction == null) | ||
return null; | ||
|
||
return Direction.getFacing(direction.getDirection(), true); | ||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
BlockFace blockFace = getBlockFace(event); | ||
Entity actualEntity = entity == null ? null : entity.getSingle(event); | ||
|
||
for (Block block : blocks.getArray(event)) { | ||
BlockState state = block.getState(false); | ||
if (state instanceof Bell) { | ||
Bell bell = (Bell) state; | ||
bell.ring(actualEntity, blockFace); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return (entity != null ? "make " + entity.toString(event, debug) + " " : "") + | ||
"ring " + blocks.toString(event, debug) + " from " + (direction != null ? direction.toString(event, debug) : ""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.