-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add glowing sign text support (#5367)
* Add glowing text syntaxes * Fix example and only register when supported * Address reviews * Address reviews * Address reviews * Address reviews * Address reviews * Update src/main/java/ch/njol/skript/effects/EffGlowingText.java Co-authored-by: LimeGlass <[email protected]> --------- Co-authored-by: LimeGlass <[email protected]> Co-authored-by: Moderocky <[email protected]>
- Loading branch information
1 parent
e1216bf
commit cc19ac0
Showing
3 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/ch/njol/skript/conditions/CondGlowingText.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,71 @@ | ||
/** | ||
* 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.aliases.ItemType; | ||
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; | ||
import org.bukkit.block.BlockState; | ||
import org.bukkit.block.Sign; | ||
import org.bukkit.inventory.meta.BlockStateMeta; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
@Name("Has Glowing Text") | ||
@Description("Checks whether a sign (either a block or an item) has glowing text") | ||
@Examples("if target block has glowing text") | ||
@Since("INSERT VERSION") | ||
public class CondGlowingText extends PropertyCondition<Object> { | ||
|
||
static { | ||
if (Skript.methodExists(Sign.class, "isGlowingText")) | ||
register(CondGlowingText.class, PropertyType.HAVE, "glowing text", "blocks/itemtypes"); | ||
} | ||
|
||
@Override | ||
public boolean check(Object obj) { | ||
if (obj instanceof Block) { | ||
BlockState state = ((Block) obj).getState(); | ||
return state instanceof Sign && ((Sign) state).isGlowingText(); | ||
} else if (obj instanceof ItemType) { | ||
ItemMeta meta = ((ItemType) obj).getItemMeta(); | ||
if (meta instanceof BlockStateMeta) { | ||
BlockState state = ((BlockStateMeta) meta).getBlockState(); | ||
return state instanceof Sign && ((Sign) state).isGlowingText(); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected PropertyType getPropertyType() { | ||
return PropertyType.HAVE; | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "glowing text"; | ||
} | ||
|
||
} |
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,98 @@ | ||
/** | ||
* 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.aliases.ItemType; | ||
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.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.util.Kleenean; | ||
|
||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockState; | ||
import org.bukkit.block.Sign; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.inventory.meta.BlockStateMeta; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
@Name("Make Sign Glow") | ||
@Description("Makes a sign (either a block or item) have glowing text or normal text") | ||
@Examples("make target block of player have glowing text") | ||
@Since("INSERT VERSION") | ||
public class EffGlowingText extends Effect { | ||
|
||
static { | ||
if (Skript.methodExists(Sign.class, "setGlowingText", boolean.class)) { | ||
Skript.registerEffect(EffGlowingText.class, | ||
"make %blocks/itemtypes% have glowing text", | ||
"make %blocks/itemtypes% have (normal|non[-| ]glowing) text" | ||
); | ||
} | ||
} | ||
|
||
@SuppressWarnings("NotNullFieldNotInitialized") | ||
private Expression<?> objects; | ||
|
||
private boolean glowing; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
objects = exprs[0]; | ||
glowing = matchedPattern == 0; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
for (Object obj : objects.getArray(event)) { | ||
if (obj instanceof Block) { | ||
BlockState state = ((Block) obj).getState(); | ||
if (state instanceof Sign) { | ||
((Sign) state).setGlowingText(glowing); | ||
state.update(); | ||
} | ||
} else if (obj instanceof ItemType) { | ||
ItemType item = (ItemType) obj; | ||
ItemMeta meta = item.getItemMeta(); | ||
if (!(meta instanceof BlockStateMeta)) | ||
return; | ||
BlockStateMeta blockMeta = (BlockStateMeta) meta; | ||
BlockState state = blockMeta.getBlockState(); | ||
if (!(state instanceof Sign)) | ||
return; | ||
((Sign) state).setGlowingText(glowing); | ||
state.update(); | ||
blockMeta.setBlockState(state); | ||
item.setItemMeta(meta); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "make " + objects.toString(event, debug) + " have " + (glowing ? "glowing text" : "normal text"); | ||
} | ||
|
||
} |
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,18 @@ | ||
test "glowing sign blocks" when running minecraft "1.17.1": | ||
set {_loc} to spawn of "world" | ||
set {_original block} to type of block at {_loc} | ||
set block at {_loc} to sign | ||
assert block at {_loc} doesn't have glowing text with "Sign had glowing text erroneously (1)" | ||
make block at {_loc} have glowing text | ||
assert block at {_loc} has glowing text with "Sign had normal text erroneously" | ||
make block at {_loc} have normal text | ||
assert block at {_loc} doesn't have glowing text with "Sign had glowing text erroneously (2)" | ||
set block at {_loc} to {_original block} | ||
|
||
test "glowing sign items" when running minecraft "1.17.1": | ||
set {_sign} to sign | ||
assert {_sign} doesn't have glowing text with "Sign had glowing text erroneously (1)" | ||
make {_sign} have glowing text | ||
assert {_sign} has glowing text with "Sign had normal text erroneously" | ||
make {_sign} have normal text | ||
assert {_sign} doesn't have glowing text with "Sign had glowing text erroneously (2)" |