-
-
Notifications
You must be signed in to change notification settings - Fork 417
Pre Player Attack Entity #8329
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
Open
MrScopes
wants to merge
36
commits into
SkriptLang:dev/feature
Choose a base branch
from
MrScopes:preplayerattack
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−40
Open
Pre Player Attack Entity #8329
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
69d50e7
Pre Player Attack Entity
MrScopes d049dd2
optional 'event-' prefix to entity/victim in CondWillBeAttacked
MrScopes c12db82
better descriptions
MrScopes 847986b
update description and syntax
MrScopes 025bebc
remove cond will be attacked
MrScopes 5bffa90
update exprattacked conventions
MrScopes a1acd88
update @events temporarily, at least until we come up with better syn…
MrScopes a048c7b
update exprattacker to new conventions + add pre attack event
MrScopes cc39815
remove from event values as it's unnecessary
MrScopes 08925b8
add preplayerattackentity to supported events for ExprAttacker
MrScopes 3d8e2cb
update exprattacker conventions
MrScopes cdb8794
update example in event
MrScopes 154983b
move import down in both exprattacked and exprattacker
MrScopes 5265711
separate attempt attack intos own file. adopt new syntax from pre att…
MrScopes ab198ac
remove all changes to simpleevents
MrScopes 279c247
pre attack -> attempt attack in events mention
MrScopes 652dd2b
remove bracket from null check
MrScopes b4b9da6
actually remove change to simpleevents?
MrScopes 9a84f4b
revert to old simpleevents file
MrScopes a3dcd8a
remove space in the tostring on exprattacked
MrScopes ae8d658
try suggested fix by Efnilite
MrScopes 96a30cf
Update src/main/java/ch/njol/skript/events/EvtAttemptAttack.java
MrScopes 8309f67
Update src/main/java/ch/njol/skript/events/EvtAttemptAttack.java
MrScopes 3bb1396
Update src/main/java/ch/njol/skript/events/EvtAttemptAttack.java
MrScopes f732e80
Update src/main/java/ch/njol/skript/events/EvtAttemptAttack.java
MrScopes fe6c6fb
Update src/main/java/ch/njol/skript/events/EvtAttemptAttack.java
MrScopes 1bc866a
Update src/main/java/ch/njol/skript/events/EvtAttemptAttack.java
MrScopes ad7367c
Update src/main/java/ch/njol/skript/expressions/ExprAttacker.java
MrScopes 561bcf8
remove unnecessary old version mention
MrScopes ba553b5
Merge branch 'preplayerattack' of https://github.com/MrScopes/Skript …
MrScopes 74143c9
e -> event
MrScopes f76f1f9
change other obscure variables
MrScopes 9e4237b
several examples instead of one big block
MrScopes 5cf7306
requested change to use pattern variables
MrScopes 3adb50a
use SyntaxStringBuilder
MrScopes 3d33542
Merge branch 'dev/feature' into preplayerattack
sovdeeth 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,83 @@ | ||
| package ch.njol.skript.events; | ||
|
|
||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.entity.EntityData; | ||
| import ch.njol.skript.lang.Literal; | ||
| import ch.njol.skript.lang.SkriptEvent; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.lang.SyntaxStringBuilder; | ||
| import ch.njol.skript.registrations.Classes; | ||
| import io.papermc.paper.event.player.PrePlayerAttackEntityEvent; | ||
|
|
||
| public class EvtAttemptAttack extends SkriptEvent { | ||
| static { | ||
| Skript.registerEvent("Attempt Attack", EvtAttemptAttack.class, PrePlayerAttackEntityEvent.class, "attack attempt", "attempt[ing] to attack %entitydatas%") | ||
| .description(""" | ||
| Called when a player attempts to attack an entity. | ||
| The event will be cancelled as soon as it is fired for non-living entities. | ||
| Cancelling this event will prevent the attack and any sounds from being played when attacking. | ||
| Any damage events will not be called if this is cancelled. | ||
| """) | ||
| .examples(""" | ||
| on attack attempt: | ||
| if event is cancelled: | ||
| broadcast "%attacker% failed to attack %victim%!" | ||
| else: | ||
| broadcast "%attacker% damaged %victim%!" | ||
| """, | ||
| """ | ||
| on attempt to attack an animal: | ||
| cancel event | ||
| """, | ||
| """ | ||
| on attempting to attack an entity: | ||
| if victim is a creeper: | ||
| cancel event | ||
| """, | ||
| """ | ||
| on attempt to attack a zombie or creeper: | ||
| attacker isn't holding a diamond sword | ||
| cancel event | ||
| """) | ||
| .since("INSERT VERSION"); | ||
| } | ||
|
|
||
| private @Nullable EntityData<?>[] types; | ||
|
|
||
| @Override | ||
| public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parser) { | ||
| types = args.length == 0 ? null : ((Literal<EntityData<?>>) args[0]).getAll(); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(Event event) { | ||
| if (types == null) | ||
| return true; | ||
|
|
||
| if (!(event instanceof PrePlayerAttackEntityEvent preEvent)) | ||
| return false; | ||
| Entity entity = preEvent.getAttacked(); | ||
|
|
||
| for (final EntityData<?> data : types) { | ||
MrScopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (data.isInstance(entity)) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); | ||
| builder.append("attempt attack"); | ||
| if (types != null) { | ||
| builder.append("of", Classes.getDebugMessage(types)); | ||
| } | ||
| return builder.toString(); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.