From 49a3394bc1c03be01bc9a8c1a0d1f1510aec7a3b Mon Sep 17 00:00:00 2001 From: Romain Date: Thu, 2 Jul 2020 23:02:15 +0200 Subject: [PATCH] Addition of functionalities about redstone (#3091) * ExprBlockPower - Expression for recovering redstone power from a block. * ExprRedstoneBlockPower - Code review changes * CondIsBlockRedstonePowered - Condition to check if a block is powered by redstone * ExprRedstoneBlockPower - Code review change --- .../CondIsBlockRedstonePowered.java | 49 +++++++++++++++++ .../expressions/ExprRedstoneBlockPower.java | 55 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/main/java/ch/njol/skript/conditions/CondIsBlockRedstonePowered.java create mode 100644 src/main/java/ch/njol/skript/expressions/ExprRedstoneBlockPower.java diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBlockRedstonePowered.java b/src/main/java/ch/njol/skript/conditions/CondIsBlockRedstonePowered.java new file mode 100644 index 00000000000..fd04cab2aad --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondIsBlockRedstonePowered.java @@ -0,0 +1,49 @@ +/** + * 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 . + * + * + * Copyright 2011-2017 Peter Güttinger and contributors + */ +package ch.njol.skript.conditions; + +import org.bukkit.block.Block; +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.Since; + +@Name("Is Block Redstone Powered") +@Description("Checks if a block is powered by redstone") +@Examples({"if clicked block is redstone powered:", + "\tsend \"This block is well-powered by redstone!\""}) +@Since("INSERT VERSION") +public class CondIsBlockRedstonePowered extends PropertyCondition { + + static { + register(CondIsBlockRedstonePowered.class, "redstone powered", "blocks"); + } + + @Override + public boolean check(Block b) { + return b.isBlockPowered(); + } + + @Override + protected String getPropertyName() { + return "redstone powered"; + } +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprRedstoneBlockPower.java b/src/main/java/ch/njol/skript/expressions/ExprRedstoneBlockPower.java new file mode 100644 index 00000000000..ce11fb907a7 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprRedstoneBlockPower.java @@ -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 . + * + * + * Copyright 2011-2017 Peter Güttinger and contributors + */ +package ch.njol.skript.expressions; + +import org.bukkit.block.Block; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.expressions.base.SimplePropertyExpression; + +@Name("Redstone Block Power") +@Description("Power of a redstone block") +@Examples({"if redstone power of targeted block is 15:", + "\tsend \"This block is very powerful!\""}) +@Since("INSERT VERSION") +public class ExprRedstoneBlockPower extends SimplePropertyExpression { + + static { + register(ExprRedstoneBlockPower.class, Number.class, "redstone power", "blocks"); + } + + @Override + public Number convert(Block b) { + return b.getBlockPower(); + } + + @Override + public Class getReturnType() { + return Number.class; + } + + @Override + protected String getPropertyName() { + return "redstone power"; + } + +}