Skip to content

Commit

Permalink
migrated pre-hard-fork patches 0002-added-ProjectileAllowCollideWithP…
Browse files Browse the repository at this point in the history
…layerEvent.patch and 0004-added-ProjectileAllowCollideWithPlayerEvent.patch
  • Loading branch information
TrainmasterHD committed Jan 5, 2025
1 parent 10824b0 commit 99c4d72
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package net.gommehd.cheetah.event.entity;

import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityEvent;
import org.jetbrains.annotations.NotNull;

/**
* Called when a projectile collides with a player
*
* @author TrainmasterHD | Jendrik E.
* @since 18.10.2022
*/
public class ProjectileAllowCollideWithPlayerEvent extends EntityEvent {
private static final HandlerList handlerList = new HandlerList();
private final Player collidedWith;
private boolean allowCollide = false;

public ProjectileAllowCollideWithPlayerEvent(@NotNull Projectile what, @NotNull Player collidedWith) {
super(what);
this.collidedWith = collidedWith;
}

/**
* Get the projectile that collided
*
* @return the projectile that collided
*/
@NotNull
public Projectile getEntity() {
return (Projectile) super.getEntity();
}

/**
* Get the entity the projectile collided with
*
* @return the entity collided with
*/
@NotNull
public Player getCollidedWith() {
return collidedWith;
}

/**
* Set if the projectile should be allowed to collide with the player
*
* @param allowCollide true if the projectile should be allowed to collide with the player, otherwise false
*/
public void setAllowCollide(final boolean allowCollide) {
this.allowCollide = allowCollide;
}

/**
* If colliding with the player is allowed
*
* @return true if it is allowed, otherwise false
*/
public boolean isAllowCollide() {
return allowCollide;
}

@NotNull
public static HandlerList getHandlerList() {
return handlerList;
}

@NotNull
@Override
public HandlerList getHandlers() {
return handlerList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/net/minecraft/world/entity/projectile/Projectile.java
+++ b/net/minecraft/world/entity/projectile/Projectile.java
@@ -409,7 +_,10 @@
if (owner instanceof net.minecraft.server.level.ServerPlayer && target instanceof net.minecraft.server.level.ServerPlayer) {
org.bukkit.entity.Player collided = (org.bukkit.entity.Player) target.getBukkitEntity();
org.bukkit.entity.Player shooter = (org.bukkit.entity.Player) owner.getBukkitEntity();
- if (!shooter.canSee(collided)) {
+ // Cheetah start - Added ProjectileAllowCollideWithPlayerEvent
+ net.gommehd.cheetah.event.entity.ProjectileAllowCollideWithPlayerEvent allowCollideEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileAllowCollideWithPlayerEvent(this, target);
+ if (!allowCollideEvent.isAllowCollide() && !shooter.canSee(collided)) {
+ // Cheetah end
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1479,7 +_,10 @@
com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = new com.destroystokyo.paper.event.entity.ProjectileCollideEvent(projectile, collided);

if (projectile.getShooter() instanceof Player && collided instanceof Player) {
- if (!((Player) projectile.getShooter()).canSee((Player) collided)) {
+ // Cheetah start - Added ProjectileAllowCollideWithPlayerEvent
+ net.gommehd.cheetah.event.entity.ProjectileAllowCollideWithPlayerEvent allowCollideEvent = callProjectileAllowCollideWithPlayerEvent(entity, position.getEntity());
+ if (!allowCollideEvent.isAllowCollide() && !((Player) projectile.getShooter()).canSee((Player) collided)) {
+ // Cheetah end
event.setCancelled(true);
return event;
}
@@ -1489,6 +_,15 @@
return event;
}
// Paper end
+
+ // Cheetah start - Added ProjectileAllowCollideWithPlayerEvent
+ public static net.gommehd.cheetah.event.entity.ProjectileAllowCollideWithPlayerEvent callProjectileAllowCollideWithPlayerEvent(Entity entity, Entity player) {
+ Projectile projectile = (Projectile) entity.getBukkitEntity();
+ net.gommehd.cheetah.event.entity.ProjectileAllowCollideWithPlayerEvent event = new net.gommehd.cheetah.event.entity.ProjectileAllowCollideWithPlayerEvent(projectile, (Player) player.getBukkitEntity());
+ event.callEvent();
+ return event;
+ }
+ // Cheetah end

public static ProjectileLaunchEvent callProjectileLaunchEvent(Entity entity) {
Projectile bukkitEntity = (Projectile) entity.getBukkitEntity();
85 changes: 0 additions & 85 deletions patches/api/0002-added-ProjectileAllowCollideWithPlayerEvent.patch

This file was deleted.

This file was deleted.

0 comments on commit 99c4d72

Please sign in to comment.