mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add source to PlayerExpChangeEvent
This commit is contained in:
parent
951fbf46dc
commit
dfdd4e3334
2 changed files with 109 additions and 0 deletions
|
@ -0,0 +1,57 @@
|
|||
From f57d12d51fc55db4fe7c81778e0390d69f62087c Mon Sep 17 00:00:00 2001
|
||||
From: AlphaBlend <whizkid3000@hotmail.com>
|
||||
Date: Thu, 8 Sep 2016 08:47:08 -0700
|
||||
Subject: [PATCH] Add source to PlayerExpChangeEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/event/player/PlayerExpChangeEvent.java b/src/main/java/org/bukkit/event/player/PlayerExpChangeEvent.java
|
||||
index f37491d..3088255 100644
|
||||
--- a/src/main/java/org/bukkit/event/player/PlayerExpChangeEvent.java
|
||||
+++ b/src/main/java/org/bukkit/event/player/PlayerExpChangeEvent.java
|
||||
@@ -1,21 +1,43 @@
|
||||
package org.bukkit.event.player;
|
||||
|
||||
+import org.bukkit.entity.Entity; // Paper
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
+import javax.annotation.Nullable; // Paper
|
||||
+
|
||||
/**
|
||||
* Called when a players experience changes naturally
|
||||
*/
|
||||
public class PlayerExpChangeEvent extends PlayerEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
+ // Paper start
|
||||
+ @Nullable
|
||||
+ private final Entity source;
|
||||
private int exp;
|
||||
|
||||
public PlayerExpChangeEvent(final Player player, final int expAmount) {
|
||||
+ this(player, null, expAmount);
|
||||
+ }
|
||||
+
|
||||
+ public PlayerExpChangeEvent(final Player player, @Nullable final Entity sourceEntity, final int expAmount) {
|
||||
super(player);
|
||||
+ source = sourceEntity;
|
||||
exp = expAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
+ * Get the source that provided the experience.
|
||||
+ *
|
||||
+ * @return The source of the experience
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public Entity getSource() {
|
||||
+ return source;
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
+ /**
|
||||
* Get the amount of experience the player will receive
|
||||
*
|
||||
* @return The amount of experience
|
||||
--
|
||||
2.10.2
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
From d31d8a65355e7a35e0ef7f574607ef6bec23740f Mon Sep 17 00:00:00 2001
|
||||
From: AlphaBlend <whizkid3000@hotmail.com>
|
||||
Date: Thu, 8 Sep 2016 08:48:33 -0700
|
||||
Subject: [PATCH] Add source to PlayerExpChangeEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
||||
index 9da8ae4..11f3b31 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
||||
@@ -172,7 +172,7 @@ public class EntityExperienceOrb extends Entity {
|
||||
}
|
||||
|
||||
if (this.value > 0) {
|
||||
- entityhuman.giveExp(CraftEventFactory.callPlayerExpChangeEvent(entityhuman, this.value).getAmount()); // CraftBukkit - this.value -> event.getAmount()
|
||||
+ entityhuman.giveExp(CraftEventFactory.callPlayerExpChangeEvent(entityhuman, this).getAmount()); // CraftBukkit - this.value -> event.getAmount() // Paper - supply experience orb object
|
||||
}
|
||||
|
||||
this.die();
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index e7fa96c..777855d 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -44,6 +44,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.ThrownExpBottle;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
+import org.bukkit.entity.ExperienceOrb; // Paper
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.block.*;
|
||||
@@ -642,6 +643,17 @@ public class CraftEventFactory {
|
||||
return event;
|
||||
}
|
||||
|
||||
+ // Paper start - Add orb
|
||||
+ public static PlayerExpChangeEvent callPlayerExpChangeEvent(EntityHuman entity, EntityExperienceOrb entityOrb) {
|
||||
+ Player player = (Player) entity.getBukkitEntity();
|
||||
+ ExperienceOrb source = (ExperienceOrb) entityOrb.getBukkitEntity();
|
||||
+ int expAmount = source.getExperience();
|
||||
+ PlayerExpChangeEvent event = new PlayerExpChangeEvent(player, source, expAmount);
|
||||
+ Bukkit.getPluginManager().callEvent(event);
|
||||
+ return event;
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
public static boolean handleBlockGrowEvent(World world, int x, int y, int z, net.minecraft.server.Block type, int data) {
|
||||
Block block = world.getWorld().getBlockAt(x, y, z);
|
||||
CraftBlockState state = (CraftBlockState) block.getState();
|
||||
--
|
||||
2.10.2
|
||||
|
Loading…
Reference in a new issue