-
-
Notifications
You must be signed in to change notification settings - Fork 404
Add EntityShootBowEvent #7714
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
Merged
erenkarakal
merged 22 commits into
SkriptLang:dev/feature
from
Fusezion:feature/entity-shoot-bow-event
Mar 31, 2025
Merged
Add EntityShootBowEvent #7714
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ec465a4
Initial Work
Fusezion 26aceb2
CondWillConsume.java - Remove
Fusezion acd3a2d
Add missing newlines
Fusezion c2e259a
Batch 1/2
Fusezion 63327c3
ExprShotForce.java - Rename to ExprProjectileForce.java
Fusezion 73bdac9
ExprProjectileForce.java - Update Example
Fusezion aab2c48
Merge branch 'dev/feature' into feature/entity-shoot-bow-event
Fusezion 711106a
BukkitEventValues.java - Remove EntityShootBowEvent
Fusezion dac9981
EvtEntityShootBow.java - Add Event-Values
Fusezion cfc620a
ExprConsumedItem.java - Replace ParseResult
Fusezion ce86297
EvtEntityShootBow.java - Add event-entity example
Fusezion c29c005
BukkitEventValues.java - Remove unused import
Fusezion 29935c9
EvtEntityShootBow.java - Add 'on player shooting projectile'
Fusezion 6abb578
Update src/main/java/ch/njol/skript/expressions/ExprProjectileForce.java
Fusezion ec20ddb
Update src/main/java/ch/njol/skript/expressions/ExprShooter.java
Fusezion 35c6799
Update src/main/java/ch/njol/skript/events/EvtEntityShootBow.java
Fusezion 709709e
EvtEntityShootBow.java - Finally look at the class the change is for
Fusezion 1152db2
Merge branch 'dev/feature' into feature/entity-shoot-bow-event
Fusezion 1509410
Plural entity data support
Fusezion da1562f
ExprConsumedItem - Player Consume Item Support
Fusezion 39966a2
EvtEntityShootBow.java - Fix and list
Fusezion 6497323
Merge branch 'dev/feature' into feature/entity-shoot-bow-event
Fusezion 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
92 changes: 92 additions & 0 deletions
92
src/main/java/ch/njol/skript/events/EvtEntityShootBow.java
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,92 @@ | ||
package ch.njol.skript.events; | ||
|
||
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; | ||
import ch.njol.skript.registrations.EventConverter; | ||
import ch.njol.skript.registrations.EventValues; | ||
import ch.njol.skript.util.slot.Slot; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.entity.EntityShootBowEvent; | ||
import org.bukkit.inventory.EntityEquipment; | ||
import org.bukkit.inventory.EquipmentSlot; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import static ch.njol.skript.util.slot.EquipmentSlot.*; | ||
|
||
public class EvtEntityShootBow extends SkriptEvent { | ||
|
||
static { | ||
Skript.registerEvent("Entity Shoot Bow", EvtEntityShootBow.class, EntityShootBowEvent.class, | ||
"%entitydata% shoot[ing] (bow|projectile)") | ||
.description(""" | ||
Called when an entity shoots a bow. | ||
event-entity refers to the shot projectile/entity. | ||
""") | ||
.examples(""" | ||
on player shoot bow: | ||
chance of 30%: | ||
damage event-slot by 10 | ||
send "Your bow has taken increased damage!" to shooter | ||
|
||
on stray shooting bow: | ||
set {_e} to event-entity | ||
spawn a cow at {_e}: | ||
set velocity of entity to velocity of {_e} | ||
set event-entity to last spawned entity | ||
""") | ||
.since("INSERT VERSION"); | ||
|
||
EventValues.registerEventValue(EntityShootBowEvent.class, ItemStack.class, EntityShootBowEvent::getBow); | ||
|
||
EventValues.registerEventValue(EntityShootBowEvent.class, Entity.class, new EventConverter<>() { | ||
@Override | ||
public void set(EntityShootBowEvent event, @Nullable Entity entity) { | ||
if (entity == null) | ||
return; | ||
event.setProjectile(entity); | ||
} | ||
|
||
@Override | ||
public @NotNull Entity convert(EntityShootBowEvent from) { | ||
return from.getProjectile(); | ||
} | ||
}); | ||
|
||
EventValues.registerEventValue(EntityShootBowEvent.class, Slot.class, event -> { | ||
EntityEquipment equipment = event.getEntity().getEquipment(); | ||
EquipSlot equipmentSlot = event.getHand() == EquipmentSlot.OFF_HAND ? EquipSlot.OFF_HAND : EquipSlot.TOOL; | ||
return new ch.njol.skript.util.slot.EquipmentSlot(equipment, equipmentSlot); | ||
Fusezion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
} | ||
|
||
private Literal<EntityData<?>> entityData; | ||
|
||
@Override | ||
public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { | ||
Fusezion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//noinspection unchecked | ||
entityData = (Literal<EntityData<?>>) args[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
if (!(event instanceof EntityShootBowEvent shootBowEvent)) | ||
return false; | ||
EntityData<?> entityData = this.entityData.getSingle(); | ||
if (entityData == null) return false; | ||
return entityData.isInstance(shootBowEvent.getEntity()); | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return this.entityData.toString(event, debug) + " shoot bow"; | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/ch/njol/skript/expressions/ExprConsumedItem.java
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,65 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.EventRestrictedSyntax; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import ch.njol.util.coll.CollectionUtils; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.entity.EntityShootBowEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Consumed Item") | ||
Fusezion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Description("Represents the item consumed within an entity shoot bow event.") | ||
@Example(""" | ||
on player shoot bow: | ||
if the consumed item is an arrow: | ||
cancel event | ||
send "You're now allowed to shoot your arrows." to shooter | ||
""") | ||
@Since("INSERT VERSION") | ||
public class ExprConsumedItem extends SimpleExpression<ItemStack> implements EventRestrictedSyntax { | ||
Fusezion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static { | ||
Skript.registerExpression(ExprConsumedItem.class, ItemStack.class, ExpressionType.SIMPLE, | ||
"[the] consumed item"); | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected ItemStack @Nullable [] get(Event event) { | ||
if (!(event instanceof EntityShootBowEvent shootBowEvent)) | ||
return null; | ||
return new ItemStack[]{shootBowEvent.getConsumable()}; | ||
} | ||
|
||
@Override | ||
public Class<? extends Event>[] supportedEvents() { | ||
return CollectionUtils.array(EntityShootBowEvent.class); | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<? extends ItemStack> getReturnType() { | ||
return ItemStack.class; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "the consumed item"; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/ch/njol/skript/expressions/ExprProjectileForce.java
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,62 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.EventRestrictedSyntax; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import ch.njol.util.coll.CollectionUtils; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.entity.EntityShootBowEvent; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Projectile Force") | ||
@Description("Returns the force at which a projectile was shot within an entity shoot bow event.") | ||
@Example(""" | ||
on entity shoot projectile: | ||
set the velocity of shooter to vector(0,1,0) * projectile force | ||
""") | ||
@Since("INSERT VERSION") | ||
public class ExprProjectileForce extends SimpleExpression<Float> implements EventRestrictedSyntax { | ||
|
||
static { | ||
Skript.registerExpression(ExprProjectileForce.class, Float.class, ExpressionType.SIMPLE, | ||
"[the] projectile force"); | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected Float @Nullable [] get(Event event) { | ||
if (!(event instanceof EntityShootBowEvent shotBowEvent)) | ||
return null; | ||
return new Float[]{shotBowEvent.getForce()}; | ||
} | ||
|
||
@Override | ||
public Class<? extends Event>[] supportedEvents() { | ||
return CollectionUtils.array(EntityShootBowEvent.class); | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<? extends Float> getReturnType() { | ||
return Float.class; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "projectile force"; | ||
} | ||
|
||
} |
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.