-
-
Notifications
You must be signed in to change notification settings - Fork 414
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
base: master
Are you sure you want to change the base?
Pre Player Attack Entity #8329
Conversation
|
Note that listening to cancelled events does not require the config, you can simply do |
|
Just a thought, could maybe still take an expression but not do anything with it for the condition, or maybe [event-](entity|victim) etc. But obviously could lead to some confusion |
Good to know. I can update the examples and description with that + whatever else is decided |
| @Name("Will Be Attacked") | ||
| @Description(""" | ||
| Checks if the entity in <a href='#Evt'>Player Pre Attack Entity Event</a> will be attacked. | ||
| Returns false for non-living entities. However, the event won't be called for them unless explicitly listened to. |
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.
should clarify what "explicitly listened to" means
|
|
||
| static { | ||
| Skript.registerCondition(CondWillBeAttacked.class, | ||
| "[the] [event-](entity|victim) (:will|will not|won't) be attacked" |
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.
i do not like using event-entity and victim literally in syntaxes, since readers of code will assume they are expressions like they normally are.
If this is always equal to isCancelled, as the javadocs imply, I would say you can just remove the condition entirely.
| public boolean check(Event e) { | ||
| return (e instanceof PrePlayerAttackEntityEvent && ((PrePlayerAttackEntityEvent) e).willAttack()) ^ isNegated(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event e, boolean debug) { |
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.
use event, not e
|
|
||
| @Override | ||
| public boolean check(Event e) { | ||
| return (e instanceof PrePlayerAttackEntityEvent && ((PrePlayerAttackEntityEvent) e).willAttack()) ^ isNegated(); |
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.
use pattern variable here
| .since("2.12"); | ||
|
|
||
| Skript.registerEvent("Pre Player Attack Entity Event", SimpleEvent.class, PrePlayerAttackEntityEvent.class, | ||
| "[player] pre attack[ing] [an] [entity]") |
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.
can you come up with a better syntax than pre attacking? it's really clunky as is but I don't know if I have better suggestions
maybe something along the lines of before attack?
| .examples(""" | ||
| on player pre attack entity: | ||
| cancel event | ||
| send "Your attack was canceled!" |
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.
this would (should) cause a parse error
You will need to update the event value for event-entity to add the pre-attack event as a case to use attacker/victim.
Also need to update ExprAttacker to support attacker in the pre attack event.
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.
this would (should) cause a parse error You will need to update the event value for event-entity to add the pre-attack event as a case to use attacker/victim. Also need to update ExprAttacker to support attacker in the pre attack event.
the reason I didn't make it attacker is since it's always going to be a player event, but yeah making it attacker would be easy. will do tomorrow. command sender is set to player in the event so it won't have any errors in my example
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.
yeah the issue is that what if a player attacks another player? now there's 2 event-players and it's ambiguous which one the user meant
| else if (e instanceof PrePlayerAttackEntityEvent) | ||
| entity = ((PrePlayerAttackEntityEvent) e).getAttacked(); |
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.
please update the expression to use event instead of e and to use pattern variables while you're here.
and the {} for if else
and any other violations of our coding conventions exist in this class
| EventValues.registerEventValue(PrePlayerAttackEntityEvent.class, Entity.class, PrePlayerAttackEntityEvent::getAttacked); | ||
| EventValues.registerEventValue(PrePlayerAttackEntityEvent.class, CommandSender.class, PrePlayerAttackEntityEvent::getPlayer); |
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.
neither of these are necessary, since the user should be using attacker and victim
Efnilite
left a comment
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.
looks good after sovde's changes
|
|
||
| @Name("Will Be Attacked") | ||
| @Description(""" | ||
| Checks if the entity in <a href='#Evt'>Player Pre Attack Entity Event</a> will be attacked. |
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.
| Checks if the entity in <a href='#Evt'>Player Pre Attack Entity Event</a> will be attacked. | |
| Checks if the entity in <a href='#PlayerPreAttackEntity'>Player Pre Attack Entity Event</a> will be attacked. |
| "[player] pre attack[ing] [an] [entity]") | ||
| .description( | ||
| "Called when a player tries to attack an entity.", | ||
| "Canceling this event will prevent the attack and any sounds being played when attacking.", |
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.
| "Canceling this event will prevent the attack and any sounds being played when attacking.", | |
| "Canceling this event will prevent the attack and any sounds from being played when attacking.", |
Problem
This event could be useful in some situations.
https://jd.papermc.io/paper/1.21.11/io/papermc/paper/event/player/PrePlayerAttackEntityEvent.html
Solution
Added
[player] pre attack[ing] [an] [entity]Added
[the] (entity|victim) (:will|will not|won't) be attack(ed|ing)Testing Completed
Supporting Information
Examples and descriptions need some work.
Honestly the will/won't be attacked can probably be removed. It's really not too useful from what I can tell and the event already won't be called unless you enable the config setting to listen to canceled events, since it's sent as canceled already if the entity is non-living and won't be attacked.
For the condition, I went with (entity|victim) instead of an expression since the event itself just has willAttack(boolean). only concern is I'm not sure if this will cause any conflicts. Whole thing needs some work but it's a start
Since it's a player event, I set the event value for command sender to be the player in the event
event-entity is also set to the getAttacked() of the event
also edited ExprAttacked/victim expression to support this so the event could use
Completes: 8266
Related: none
AI assistance: none