-
-
Notifications
You must be signed in to change notification settings - Fork 478
Add PreExplodeEvents #1234
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
Merged
Add PreExplodeEvents #1234
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
40b746d
Add PreExplodeEvents
SageSphinx63920 71531f5
Try to fix weird goat event bug
SageSphinx63920 1886647
Fix annotation
SageSphinx63920 69f4574
Merge remote-tracking branch 'origin/ver/1.19.3' into ver/1.19.3
SageSphinx63920 7118a66
Merge branch 'PurpurMC:ver/1.19.3' into ver/1.19.3
SageSphinx63920 8625b99
Merge branch 'PurpurMC:ver/1.19.3' into ver/1.19.3
SageSphinx63920 579e785
Merge branch 'PurpurMC:ver/1.19.3' into ver/1.19.3
SageSphinx63920 66bb2d1
Merge branch 'PurpurMC:ver/1.19.3' into ver/1.19.3
SageSphinx63920 6e2fa80
Apply suggestions by granny
SageSphinx63920 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 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,196 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: SageSphinx63920 <sage@sagesphinx63920.dev> | ||
| Date: Mon, 26 Dec 2022 23:40:13 +0100 | ||
| Subject: [PATCH] Add PreExplodeEvents | ||
|
|
||
|
|
||
| diff --git a/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..e4bfca1ca2f1cba73244819af6340951498cf4af | ||
| --- /dev/null | ||
| +++ b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java | ||
| @@ -0,0 +1,51 @@ | ||
| +package org.purpurmc.purpur.event; | ||
| + | ||
| +import org.bukkit.block.Block; | ||
| +import org.bukkit.event.Cancellable; | ||
| +import org.bukkit.event.HandlerList; | ||
| +import org.bukkit.event.block.BlockEvent; | ||
| +import org.jetbrains.annotations.NotNull; | ||
| + | ||
| +/** | ||
| + * Called before a block's explosion is processed | ||
| + */ | ||
| +public class PreBlockExplodeEvent extends BlockEvent implements Cancellable { | ||
| + private static final HandlerList handlers = new HandlerList(); | ||
| + private boolean cancelled; | ||
| + private final float yield; | ||
| + | ||
| + public PreBlockExplodeEvent(@NotNull final Block what, final float yield) { | ||
| + super(what); | ||
| + this.yield = yield; | ||
| + this.cancelled = false; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Returns the percentage of blocks to drop from this explosion | ||
| + * | ||
| + * @return The yield. | ||
| + */ | ||
| + public float getYield() { | ||
| + return yield; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public boolean isCancelled() { | ||
| + return this.cancelled; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public void setCancelled(boolean cancel) { | ||
| + this.cancelled = cancel; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public @NotNull HandlerList getHandlers() { | ||
| + return handlers; | ||
| + } | ||
| + | ||
| + @NotNull | ||
| + public static HandlerList getHandlerList() { | ||
| + return handlers; | ||
| + } | ||
| +} | ||
| diff --git a/src/main/java/org/purpurmc/purpur/event/entity/GoatRamEntityEvent.java b/src/main/java/org/purpurmc/purpur/event/entity/GoatRamEntityEvent.java | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..f62c14f3d4999e9112c1c73642aa337d97b94b5a | ||
| --- /dev/null | ||
| +++ b/src/main/java/org/purpurmc/purpur/event/entity/GoatRamEntityEvent.java | ||
|
SageSphinx63920 marked this conversation as resolved.
Outdated
|
||
| @@ -0,0 +1,59 @@ | ||
| +package org.purpurmc.purpur.event.entity; | ||
| + | ||
| +import org.bukkit.entity.Goat; | ||
| +import org.bukkit.entity.LivingEntity; | ||
| +import org.bukkit.event.Cancellable; | ||
| +import org.bukkit.event.HandlerList; | ||
| +import org.bukkit.event.entity.EntityEvent; | ||
| +import org.jetbrains.annotations.NotNull; | ||
| + | ||
| +/** | ||
| + * Called when a goat rams an entity | ||
| + */ | ||
| +public class GoatRamEntityEvent extends EntityEvent implements Cancellable { | ||
| + private static final HandlerList handlers = new HandlerList(); | ||
| + private final LivingEntity rammedEntity; | ||
| + private boolean cancelled; | ||
| + | ||
| + public GoatRamEntityEvent(@NotNull Goat goat, @NotNull LivingEntity rammedEntity) { | ||
| + super(goat); | ||
| + this.rammedEntity = rammedEntity; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Returns the entity that was rammed by the goat | ||
| + * | ||
| + * @return The rammed entity | ||
| + */ | ||
| + @NotNull | ||
| + public LivingEntity getRammedEntity() { | ||
| + return this.rammedEntity; | ||
| + } | ||
| + | ||
| + @Override | ||
| + @NotNull | ||
| + public Goat getEntity() { | ||
| + return (Goat) super.getEntity(); | ||
| + } | ||
| + | ||
| + @Override | ||
| + @NotNull | ||
| + public HandlerList getHandlers() { | ||
| + return handlers; | ||
| + } | ||
| + | ||
| + @NotNull | ||
| + public static HandlerList getHandlerList() { | ||
| + return handlers; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public boolean isCancelled() { | ||
| + return this.cancelled; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public void setCancelled(boolean cancel) { | ||
| + this.cancelled = cancel; | ||
| + } | ||
| +} | ||
| diff --git a/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..8e04a2a391b525d00e36334a6c5b112fb797a821 | ||
| --- /dev/null | ||
| +++ b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java | ||
| @@ -0,0 +1,62 @@ | ||
| +package org.purpurmc.purpur.event.entity; | ||
| + | ||
| +import org.bukkit.Location; | ||
| +import org.bukkit.event.Cancellable; | ||
| +import org.bukkit.event.HandlerList; | ||
| +import org.bukkit.event.entity.EntityEvent; | ||
| +import org.jetbrains.annotations.NotNull; | ||
| + | ||
| +/** | ||
| + * Called before an entity's explosion is processed | ||
| + */ | ||
| +public class PreEntityExplodeEvent extends EntityEvent implements Cancellable { | ||
| + private static final HandlerList handlers = new HandlerList(); | ||
| + private boolean cancelled; | ||
| + private final float yield; | ||
| + private final Location location; | ||
| + | ||
| + public PreEntityExplodeEvent(org.bukkit.entity.Entity what, @NotNull final Location location, final float yield) { | ||
| + super(what); | ||
| + this.cancelled = false; | ||
| + this.yield = yield; | ||
| + this.location = location; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Returns the percentage of blocks to drop from this explosion | ||
| + * | ||
| + * @return The yield. | ||
| + */ | ||
| + public float getYield() { | ||
| + return yield; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Returns the location where the explosion happened. | ||
| + * | ||
| + * @return The location of the explosion | ||
| + */ | ||
| + public Location getLocation() { | ||
| + return location; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public boolean isCancelled() { | ||
| + return this.cancelled; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public void setCancelled(boolean cancel) { | ||
| + this.cancelled = cancel; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public @NotNull HandlerList getHandlers() { | ||
| + return handlers; | ||
| + } | ||
| + | ||
| + @NotNull | ||
| + public static HandlerList getHandlerList() { | ||
| + return handlers; | ||
| + } | ||
| +} | ||
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,42 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: SageSphinx63920 <sage@sagesphinx63920.dev> | ||
| Date: Mon, 26 Dec 2022 23:42:37 +0100 | ||
| Subject: [PATCH] Add PreExplodeEvents | ||
|
|
||
|
|
||
| diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java | ||
| index 51d8271cb8fe246f4c11db8fbc061ed63f416da0..3707347ec139b3ac0010fe0460314fd593f58fb6 100644 | ||
| --- a/src/main/java/net/minecraft/world/level/Explosion.java | ||
| +++ b/src/main/java/net/minecraft/world/level/Explosion.java | ||
| @@ -45,6 +45,7 @@ import org.bukkit.craftbukkit.event.CraftEventFactory; | ||
| import org.bukkit.event.entity.EntityExplodeEvent; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.event.block.BlockExplodeEvent; | ||
| +import org.purpurmc.purpur.event.entity.PreEntityExplodeEvent; | ||
|
granny marked this conversation as resolved.
Outdated
|
||
| // CraftBukkit end | ||
|
|
||
| public class Explosion { | ||
| @@ -141,6 +142,23 @@ public class Explosion { | ||
| return; | ||
| } | ||
| // CraftBukkit end | ||
| + | ||
| + // Purpur start - add PreExplodeEvents | ||
| + if(this.source != null){ | ||
| + Location location = new Location(this.level.getWorld(), this.x, this.y, this.z); | ||
| + if(!new PreEntityExplodeEvent(this.source.getBukkitEntity(), location, this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F).callEvent()) { | ||
| + this.wasCanceled = true; | ||
| + return; | ||
| + } | ||
| + }else { | ||
| + Location location = new Location(this.level.getWorld(), this.x, this.y, this.z); | ||
| + if(!new org.purpurmc.purpur.event.PreBlockExplodeEvent(location.getBlock(), this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F).callEvent()) { | ||
| + this.wasCanceled = true; | ||
| + return; | ||
| + } | ||
| + } | ||
| + //Purpur end | ||
| + | ||
| this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z)); | ||
| Set<BlockPos> set = Sets.newHashSet(); | ||
| boolean flag = true; | ||
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.