-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Moderocky
merged 21 commits into
SkriptLang:dev/feature
from
ShaneBeee:feature/target-block-update
May 8, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
92fd4a8
ExprTargetedBlock - apply a use for "actual"
ShaneBeee d6b7db9
ExprTargetedBlock - cleanup
ShaneBeee 1915a2d
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee b5e7bd5
ExprTargetedBlock - fixes
ShaneBeee c4e3c40
ExprTargetedBlock - add exact
ShaneBeee c53f2d8
ExprTargetedBlock - missing override
ShaneBeee 792b428
ExprTargetedBlock - add back plural as per request from sovde
ShaneBeee 69178ae
Merge branch 'dev/feature' into feature/target-block-update
sovdeeth e1d7470
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee d4428c8
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee 8cfc5e5
ExprTargetedBlock - use internal isAir check
ShaneBeee 70cba37
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee f62f58a
ExprTargetedBlock - cut down patterns
ShaneBeee 5707b38
ExprTargetedBlock - change player to livingEntity
ShaneBeee c06f704
Merge branch 'dev/feature' into feature/target-block-update
Moderocky 1d6f5be
Merge branch 'dev/feature' into feature/target-block-update
sovdeeth bf748f2
Update src/main/java/ch/njol/skript/expressions/ExprTargetedBlock.java
ShaneBeee 7ac6ace
Merge branch 'dev/feature' into feature/target-block-update
sovdeeth 9e4cd35
Merge branch 'dev/feature' into feature/target-block-update
sovdeeth 1c225be
Merge branch 'dev/feature' into feature/target-block-update
Moderocky fcf2d42
Merge branch 'dev/feature' into feature/target-block-update
Moderocky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ | |||||||||
|
||||||||||
import ch.njol.skript.Skript; | ||||||||||
import ch.njol.skript.SkriptConfig; | ||||||||||
import ch.njol.skript.bukkitutil.ItemUtils; | ||||||||||
import ch.njol.skript.doc.Description; | ||||||||||
import ch.njol.skript.doc.Examples; | ||||||||||
import ch.njol.skript.doc.Name; | ||||||||||
|
@@ -29,62 +30,75 @@ | |||||||||
import ch.njol.skript.lang.ExpressionType; | ||||||||||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||||||||
import ch.njol.util.Kleenean; | ||||||||||
import org.bukkit.Material; | ||||||||||
import org.bukkit.block.Block; | ||||||||||
import org.bukkit.entity.Player; | ||||||||||
import org.bukkit.entity.LivingEntity; | ||||||||||
import org.bukkit.event.Event; | ||||||||||
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"}) | ||||||||||
@Since("1.0") | ||||||||||
public class ExprTargetedBlock extends PropertyExpression<Player, 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.", | ||||||||||
"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, INSERT VERSION (actual/exact)") | ||||||||||
public class ExprTargetedBlock extends PropertyExpression<LivingEntity, 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:(actual[ly]|exact)] target[ed] block[s] [of %livingentities%]", "%livingentities%'[s] [actual:(actual[ly]|exact)] target[ed] block[s]"); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
formatting |
||||||||||
} | ||||||||||
|
||||||||||
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"); | ||||||||||
} | ||||||||||
setExpr((Expression<LivingEntity>) exprs[0]); | ||||||||||
actual = parser.hasTag("actual"); | ||||||||||
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, LivingEntity[] source) { | ||||||||||
Integer distance = SkriptConfig.maxTargetBlockDistance.value(); | ||||||||||
return get(source, livingEntity -> { | ||||||||||
Block block; | ||||||||||
if (actual) { | ||||||||||
block = livingEntity.getTargetBlockExact(distance); | ||||||||||
} else { | ||||||||||
block = livingEntity.getTargetBlock(null, distance); | ||||||||||
} | ||||||||||
if (block != null && ItemUtils.isAir(block.getType())) | ||||||||||
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 "the " + (this.actual ? "actual " : "") + "target " + block + " of " + getExpr().toString(event, debug); | ||||||||||
} | ||||||||||
|
||||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth mentioning support for living entities rather than just players?