-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added blockface mod xyz expression and cartesian condition
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...java/it/jakegblp/lusk/elements/minecraft/blockface/conditions/CondBlockFaceCartesian.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,29 @@ | ||
package it.jakegblp.lusk.elements.minecraft.blockface.conditions; | ||
|
||
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.BlockFace; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Name("Blockface - is Cartesian") | ||
@Description("Returns true if the provided blockfaces are aligned with one of the unit axes in 3D Cartesian space (NORTH, SOUTH, EAST, WEST, UP, DOWN).") | ||
@Examples("if {_blockface} is cartesian") | ||
@Since("1.2") | ||
public class CondBlockFaceCartesian extends PropertyCondition<BlockFace> { | ||
static { | ||
register(CondBlockFaceCartesian.class, "cartesian", "blockfaces"); | ||
} | ||
|
||
@Override | ||
public boolean check(BlockFace blockFace) { | ||
return blockFace.isCartesian(); | ||
} | ||
|
||
@Override | ||
protected @NotNull String getPropertyName() { | ||
return "cartesian"; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...n/java/it/jakegblp/lusk/elements/minecraft/blockface/expressions/ExprBlockFaceModXYZ.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,48 @@ | ||
package it.jakegblp.lusk.elements.minecraft.blockface.expressions; | ||
|
||
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; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.block.BlockFace; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@Name("BlockFace - Mod XYZ") | ||
@Description("Returns the amount of x/y/z to modify to get the represented block(s).") | ||
@Examples({"broadcast mod-y of {_blockfaces::*}"}) | ||
@Since("1.2") | ||
public class ExprBlockFaceModXYZ extends SimplePropertyExpression<BlockFace, Integer> { | ||
static { | ||
register(ExprBlockFaceModXYZ.class, Integer.class, "mod(-| )(:y|:x|z)", "blockfaces"); | ||
} | ||
|
||
int which; | ||
|
||
@Override | ||
public @NotNull Class<? extends Integer> getReturnType() { | ||
return Integer.class; | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
which = parseResult.hasTag("y") ? 0 : (parseResult.hasTag("x") ? 1 : 2); | ||
return super.init(expressions, matchedPattern, isDelayed, parseResult); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public Integer convert(BlockFace blockFace) { | ||
return which == 0 ? blockFace.getModX() : (which == 1 ? blockFace.getModY() : blockFace.getModZ()); | ||
} | ||
|
||
@Override | ||
protected @NotNull String getPropertyName() { | ||
return "opposite blockface"; | ||
} | ||
} |