Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/target block update #6422

Merged
Merged
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
92fd4a8
ExprTargetedBlock - apply a use for "actual"
ShaneBeee Feb 12, 2024
d6b7db9
ExprTargetedBlock - cleanup
ShaneBeee Feb 12, 2024
1915a2d
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee Feb 12, 2024
b5e7bd5
ExprTargetedBlock - fixes
ShaneBeee Feb 12, 2024
c4e3c40
ExprTargetedBlock - add exact
ShaneBeee Feb 12, 2024
c53f2d8
ExprTargetedBlock - missing override
ShaneBeee Feb 12, 2024
792b428
ExprTargetedBlock - add back plural as per request from sovde
ShaneBeee Feb 14, 2024
69178ae
Merge branch 'dev/feature' into feature/target-block-update
sovdeeth Feb 14, 2024
e1d7470
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee Mar 9, 2024
d4428c8
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee Mar 9, 2024
8cfc5e5
ExprTargetedBlock - use internal isAir check
ShaneBeee Mar 9, 2024
70cba37
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee Mar 29, 2024
f62f58a
ExprTargetedBlock - cut down patterns
ShaneBeee Mar 29, 2024
5707b38
ExprTargetedBlock - change player to livingEntity
ShaneBeee Mar 29, 2024
c06f704
Merge branch 'dev/feature' into feature/target-block-update
Moderocky Apr 8, 2024
1d6f5be
Merge branch 'dev/feature' into feature/target-block-update
sovdeeth May 7, 2024
bf748f2
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee May 8, 2024
7ac6ace
Merge branch 'dev/feature' into feature/target-block-update
sovdeeth May 8, 2024
9e4cd35
Merge branch 'dev/feature' into feature/target-block-update
sovdeeth May 8, 2024
1c225be
Merge branch 'dev/feature' into feature/target-block-update
Moderocky May 8, 2024
fcf2d42
Merge branch 'dev/feature' into feature/target-block-update
Moderocky May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 35 additions & 21 deletions src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,55 +36,69 @@
import org.eclipse.jdt.annotation.Nullable;

@Name("Targeted Block")
@Description("The block at the crosshair. This regards all blocks that are not air as fully solid, e.g. torches will be like a solid stone block for this expression.")
@Examples({"# A command to set the block a player looks at to a specific type:",
"command /setblock <material>:",
"\ttrigger:",
"\t\tset targeted block to argument"})
@Description({
"The block at the crosshair. This regards all blocks that are not air as fully solid, e.g. torches will be like a solid stone block for this expression.",
"The actual target block will regard the actual hit box of the block."
})
@Examples({
"set target block of player to stone",
"set target block of player to oak_stairs[waterlogged=true]",
"break target block of player using player's tool",
"give player 1 of type of target block",
"teleport player to location above target block",
"kill all entities in radius 3 around target block of player",
"set {_block} to actual target block of player",
"break actual target block of player"
})
@Since("1.0")
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
public class ExprTargetedBlock extends PropertyExpression<Player, Block> {

static {
Skript.registerExpression(ExprTargetedBlock.class, Block.class, ExpressionType.COMBINED,
"[the] target[ed] block[s] [of %players%]", "%players%'[s] target[ed] block[s]",
"[the] actual[ly] target[ed] block[s] [of %players%]", "%players%'[s] actual[ly] target[ed] block[s]");
"[the] (actual[ly]|exact) target[ed] block[s] [of %players%]", "%players%'[s] (actual[ly]|exact) target[ed] block[s]");
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
}

private boolean actual;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parser) {
setExpr((Expression<Player>) exprs[0]);
if (matchedPattern >= 2) {
// TODO remove 'actual' patterns in the future
Skript.warning("The 'actual' part of the targeted block expression is deprecated, it is now no longer required");
}
actual = matchedPattern > 1;
return true;
}

@Override
protected Block[] get(Event e, Player[] source) {
return get(source, p -> {
Block block = p.getTargetBlock(null, SkriptConfig.maxTargetBlockDistance.value());
if (block.getType() == Material.AIR)
protected Block[] get(Event event, Player[] source) {
Integer distance = SkriptConfig.maxTargetBlockDistance.value();
return get(source, player -> {
Block block;
if (actual)
block = player.getTargetBlockExact(distance);
else
block = player.getTargetBlock(null, distance);
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
if (block != null && block.getType() == Material.AIR)
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
return null;
return block;
});
}

@Override
public Class<Block> getReturnType() {
return Block.class;
}

@Override
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
public boolean setTime(int time) {
super.setTime(time);
return true;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "the targeted block" + (getExpr().isSingle() ? "" : "s") + " of " + getExpr().toString(e, debug);
public Class<Block> getReturnType() {
return Block.class;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
String block = getExpr().isSingle() ? "block" : "blocks";
return (this.actual ? "actual " : "") + "target " + block + " of " + getExpr().toString(event, debug);
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
}

}