From 2faef0090954065503d308d386ebeec0701b941a Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 4 Mar 2013 18:49:59 +1100 Subject: [PATCH] Implement PlayerItemDamageEvent. @Sleaker @Kainzo - if you could kindly tell me why you add code to prevent Heroes from running on a **now supported** platform, I would love to know, maybe we can resolve this once and for all. Unless of course it is simply part of your plan to make people use your rise against CraftBukkit fork with only 1 tiny feature which can and will be replicated in a plugin if need be. --- .../0005-PlayerItemDamageEvent.patch | 73 +++++++++++++++++++ .../0041-PlayerItemDamageEvent.patch | 34 +++++++++ 2 files changed, 107 insertions(+) create mode 100644 Bukkit-Patches/0005-PlayerItemDamageEvent.patch create mode 100644 CraftBukkit-Patches/0041-PlayerItemDamageEvent.patch diff --git a/Bukkit-Patches/0005-PlayerItemDamageEvent.patch b/Bukkit-Patches/0005-PlayerItemDamageEvent.patch new file mode 100644 index 0000000000..89fb3f682b --- /dev/null +++ b/Bukkit-Patches/0005-PlayerItemDamageEvent.patch @@ -0,0 +1,73 @@ +From 9df4bf49783c57d5e7e358a3a895f601bcf7aa30 Mon Sep 17 00:00:00 2001 +From: md_5 +Date: Mon, 4 Mar 2013 18:31:20 +1100 +Subject: [PATCH] PlayerItemDamageEvent + +--- + .../bukkit/event/player/PlayerItemDamageEvent.java | 54 ++++++++++++++++++++++ + 1 file changed, 54 insertions(+) + create mode 100644 src/main/java/org/bukkit/event/player/PlayerItemDamageEvent.java + +diff --git a/src/main/java/org/bukkit/event/player/PlayerItemDamageEvent.java b/src/main/java/org/bukkit/event/player/PlayerItemDamageEvent.java +new file mode 100644 +index 0000000..38a72ab +--- /dev/null ++++ b/src/main/java/org/bukkit/event/player/PlayerItemDamageEvent.java +@@ -0,0 +1,54 @@ ++package org.bukkit.event.player; ++ ++import org.bukkit.entity.Player; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.inventory.ItemStack; ++ ++public class PlayerItemDamageEvent extends PlayerEvent implements Cancellable { ++ ++ private static final HandlerList handlers = new HandlerList(); ++ private final ItemStack item; ++ private int damage; ++ private boolean cancelled = false; ++ ++ public PlayerItemDamageEvent(Player player, ItemStack what, int damage) { ++ super(player); ++ this.item = what; ++ this.damage = damage; ++ } ++ ++ public ItemStack getItem() { ++ return item; ++ } ++ ++ /** ++ * Gets the amount of durability damage this item will be taking. ++ * ++ * @return durability change ++ */ ++ public int getDamage() { ++ return damage; ++ } ++ ++ public void setDamage(int damage) { ++ this.damage = damage; ++ } ++ ++ public boolean isCancelled() { ++ return cancelled; ++ } ++ ++ public void setCancelled(boolean cancel) { ++ this.cancelled = cancel; ++ } ++ ++ @Override ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} +-- +1.8.1-rc2 + diff --git a/CraftBukkit-Patches/0041-PlayerItemDamageEvent.patch b/CraftBukkit-Patches/0041-PlayerItemDamageEvent.patch new file mode 100644 index 0000000000..c4106e5df0 --- /dev/null +++ b/CraftBukkit-Patches/0041-PlayerItemDamageEvent.patch @@ -0,0 +1,34 @@ +From d1f056b206014ed99fcb565e8bc376d8dc88650c Mon Sep 17 00:00:00 2001 +From: md_5 +Date: Mon, 4 Mar 2013 18:45:52 +1100 +Subject: [PATCH] PlayerItemDamageEvent + +--- + src/main/java/net/minecraft/server/ItemStack.java | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java +index 3043db9..8925327 100644 +--- a/src/main/java/net/minecraft/server/ItemStack.java ++++ b/src/main/java/net/minecraft/server/ItemStack.java +@@ -161,7 +161,16 @@ public final class ItemStack { + } + + i -= k; +- if (i <= 0) { ++ // Spigot start ++ if (entityliving instanceof EntityPlayer) { ++ org.bukkit.craftbukkit.inventory.CraftItemStack item = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this); ++ org.bukkit.event.player.PlayerItemDamageEvent event = new org.bukkit.event.player.PlayerItemDamageEvent((org.bukkit.entity.Player) entityliving.getBukkitEntity(), item, damage); ++ org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event); ++ if (event.isCancelled()) return; ++ i = event.getDamage(); ++ } ++ // Spigot end ++ if (i <= 0 ) { + return; + } + } +-- +1.8.1-rc2 +