Yatopia/patches/api/0008-PlayerAttackEntityEvent.patch
Ivan Pekov 4c7a91845b
Updated Upstream and Sidestream(s) (Tuinity/Purpur)
Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
4a99f3e Updated Upstream (Paper)
f5d537e Merge https://github.com/Spottedleaf/Tuinity into ver/1.16.3
7936e2b Make async usage of IteratorSafeOrderedReferenceSet less dangerous

Purpur Changes:
2cce22a Updated Upstream (Paper & Tuinity)
8d407a9 Despawn rate for llama spit
2020-09-23 18:38:34 +03:00

135 lines
3.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Tue, 22 Sep 2020 12:52:57 +0300
Subject: [PATCH] PlayerAttackEntityEvent
Added per request
diff --git a/src/main/java/net/yatopia/api/event/PlayerAttackEntityEvent.java b/src/main/java/net/yatopia/api/event/PlayerAttackEntityEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..72e2cfd4c62f02154d8dddaa964249fe5aa64e98
--- /dev/null
+++ b/src/main/java/net/yatopia/api/event/PlayerAttackEntityEvent.java
@@ -0,0 +1,121 @@
+package net.yatopia.api.event;
+
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when the {@link Player} attacks a {@link Entity}.
+ * <p>
+ * This event is fired earlier than {@link org.bukkit.event.entity.EntityDamageByEntityEvent} .
+ */
+public class PlayerAttackEntityEvent extends Event implements Cancellable {
+
+ private boolean cancelled = false;
+ private final HumanEntity attacker;
+ private final Entity attacked;
+ private final ItemStack attackItem;
+
+ private boolean criticalHit;
+ private float damage;
+
+ public PlayerAttackEntityEvent(HumanEntity attacker, Entity attacked, ItemStack attackItem, boolean criticalHit, float damage) {
+ this.attacker = attacker;
+ this.attacked = attacked;
+ this.attackItem = attackItem;
+ this.criticalHit = criticalHit;
+ this.damage = damage;
+ }
+
+ /**
+ * Returns the attacker.
+ *
+ * @return attacker
+ */
+ @NotNull
+ public HumanEntity getAttacker() {
+ return attacker;
+ }
+
+ /**
+ * Returns the entity attacked.
+ *
+ * @return attacked entity
+ */
+ @NotNull
+ public Entity getAttackedEntity() {
+ return attacked;
+ }
+
+ /**
+ * Returns the attack item used to damage the {@link #getAttackedEntity()}
+ *
+ * @return attack item
+ */
+ @NotNull
+ public ItemStack getAttackItem() {
+ return attackItem;
+ }
+
+ /**
+ * Returns whether or not the hit is a critical hit.
+ * <p>
+ * Minecraft multiplies the damage by 1.5 if the hit is critical.
+ *
+ * @return value
+ */
+ public boolean isCritical() {
+ return criticalHit;
+ }
+
+ /**
+ * Sets if the hit is critical. The value may be ignored if the server has disabled criticals.
+ *
+ * @param critical whether or not you want the hit to be critical.
+ */
+ public void setCritical(boolean critical) {
+ this.criticalHit = critical;
+ }
+
+ /**
+ * Returns the damage which is going to be dealt.
+ * <p>
+ * <b>WARNING: Critical hit is not included.</b>
+ *
+ * @return damage
+ */
+ public float getDamage() {
+ return damage;
+ }
+
+ /**
+ * Sets the damage the {@link #getAttackedEntity()} will receive. If the hit is a {@link #isCritical()}, then the set damage
+ * will be multiplied by 1.5
+ *
+ * @param damage damage
+ */
+ public void setDamage(float damage) {
+ this.damage = damage;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ //
+ private static final HandlerList handlers = new HandlerList();
+ @NotNull @Override public HandlerList getHandlers() { return handlers; }
+ public static HandlerList getHandlerList() { return handlers; }
+ //
+}