Paper/Spigot-Server-Patches/0388-PlayerLaunchProjectileEvent.patch
Mariell Hoversholm 654b792caf Updated Upstream (CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

CraftBukkit Changes:
a339310c #755: Fix NPE when calling getInventory() for virtual EnderChests
2577f9bf Increase outdated build delay
1dabfdc8 #754: Fix pre-1.16 serialized SkullMeta being broken on 1.16+, losing textures
2020-09-27 11:04:51 -04:00

263 Zeilen
16 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 21 Jul 2018 03:11:03 -0500
Subject: [PATCH] PlayerLaunchProjectileEvent
diff --git a/src/main/java/net/minecraft/server/InteractionResultWrapper.java b/src/main/java/net/minecraft/server/InteractionResultWrapper.java
index d59a0b739c0b8787029969a14002042e5c288ae8..8b2fc1c0e608c911b2cdc95ef134f84e3760c05d 100644
--- a/src/main/java/net/minecraft/server/InteractionResultWrapper.java
+++ b/src/main/java/net/minecraft/server/InteractionResultWrapper.java
@@ -10,6 +10,7 @@ public class InteractionResultWrapper<T> {
this.b = t0;
}
+ public EnumInteractionResult getResult() { return this.a(); } // Paper - OBFHELPER
public EnumInteractionResult a() {
return this.a;
}
diff --git a/src/main/java/net/minecraft/server/ItemEgg.java b/src/main/java/net/minecraft/server/ItemEgg.java
index f028cb04d692f848a4682aa2eeac2174eb0f6769..6ddb0237c013e5c40d6c28a300f33443f6f703a5 100644
--- a/src/main/java/net/minecraft/server/ItemEgg.java
+++ b/src/main/java/net/minecraft/server/ItemEgg.java
@@ -16,21 +16,35 @@ public class ItemEgg extends Item {
entityegg.setItem(itemstack);
entityegg.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F);
- // CraftBukkit start
- if (!world.addEntity(entityegg)) {
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entityegg.getBukkitEntity());
+ if (event.callEvent() && world.addEntity(entityegg)) {
+ if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) {
+ itemstack.subtract(1);
+ } else if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ entityhuman.b(StatisticList.ITEM_USED.b(this));
+ } else {
if (entityhuman instanceof EntityPlayer) {
((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
}
- return InteractionResultWrapper.fail(itemstack);
+ return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
}
- // CraftBukkit end
+ // Paper end
+
+
}
world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (ItemEgg.RANDOM.nextFloat() * 0.4F + 0.8F)); // CraftBukkit - from above
+ /* // Paper start - moved up
entityhuman.b(StatisticList.ITEM_USED.b(this));
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack.subtract(1);
}
+ */ // Paper end
return InteractionResultWrapper.a(itemstack, world.s_());
}
diff --git a/src/main/java/net/minecraft/server/ItemEnderPearl.java b/src/main/java/net/minecraft/server/ItemEnderPearl.java
index aa7356e6a18c0bf72314e92809a4eab320d3695f..0e154ee2976694dacf8d41fcd831f21fbbda13af 100644
--- a/src/main/java/net/minecraft/server/ItemEnderPearl.java
+++ b/src/main/java/net/minecraft/server/ItemEnderPearl.java
@@ -16,22 +16,37 @@ public class ItemEnderPearl extends Item {
entityenderpearl.setItem(itemstack);
entityenderpearl.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F);
- if (!world.addEntity(entityenderpearl)) {
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entityenderpearl.getBukkitEntity());
+ if (event.callEvent() && world.addEntity(entityenderpearl)) {
+ if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) {
+ itemstack.subtract(1);
+ } else if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ entityhuman.b(StatisticList.ITEM_USED.b(this));
+ entityhuman.getCooldownTracker().setCooldown(this, 20);
+ } else {
+ // Paper end
if (entityhuman instanceof EntityPlayer) {
((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
}
- return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+ return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
}
}
- world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemEnderPearl.RANDOM.nextFloat() * 0.4F + 0.8F));
- entityhuman.getCooldownTracker().setCooldown(this, 20);
- // CraftBukkit end
-
- entityhuman.b(StatisticList.ITEM_USED.b(this));
- if (!entityhuman.abilities.canInstantlyBuild) {
- itemstack.subtract(1);
- }
+ // Paper start - moved up
+// world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemEnderPearl.RANDOM.nextFloat() * 0.4F + 0.8F));
+// entityhuman.getCooldownTracker().setCooldown(this, 20);
+// // CraftBukkit end
+//
+// entityhuman.b(StatisticList.ITEM_USED.b(this));
+// if (!entityhuman.abilities.canInstantlyBuild) {
+// itemstack.subtract(1);
+// }
+ // Paper end - moved up
return InteractionResultWrapper.a(itemstack, world.s_());
}
diff --git a/src/main/java/net/minecraft/server/ItemExpBottle.java b/src/main/java/net/minecraft/server/ItemExpBottle.java
index 07e12714d064a2ccc7a3a50fbb88517f9a3b8b78..10abf20e907f1ea25797ff33d181de7eaed9a9da 100644
--- a/src/main/java/net/minecraft/server/ItemExpBottle.java
+++ b/src/main/java/net/minecraft/server/ItemExpBottle.java
@@ -15,19 +15,38 @@ public class ItemExpBottle extends Item {
public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(enumhand);
- world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemExpBottle.RANDOM.nextFloat() * 0.4F + 0.8F));
+ //world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemExpBottle.RANDOM.nextFloat() * 0.4F + 0.8F)); // Paper - moved down
if (!world.isClientSide) {
EntityThrownExpBottle entitythrownexpbottle = new EntityThrownExpBottle(world, entityhuman);
entitythrownexpbottle.setItem(itemstack);
entitythrownexpbottle.a(entityhuman, entityhuman.pitch, entityhuman.yaw, -20.0F, 0.7F, 1.0F);
- world.addEntity(entitythrownexpbottle);
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entitythrownexpbottle.getBukkitEntity());
+ if (event.callEvent() && world.addEntity(entitythrownexpbottle)) {
+ if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) {
+ itemstack.subtract(1);
+ } else if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ entityhuman.b(StatisticList.ITEM_USED.b(this));
+ } else {
+ if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ }
+ return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
+ }
+ // Paper end
}
+ /* // Paper start - moved up
entityhuman.b(StatisticList.ITEM_USED.b(this));
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack.subtract(1);
}
+ */ // Paper end
return InteractionResultWrapper.a(itemstack, world.s_());
}
diff --git a/src/main/java/net/minecraft/server/ItemLingeringPotion.java b/src/main/java/net/minecraft/server/ItemLingeringPotion.java
index 685d958994bc35ad5eceba629e6743b41e2cc04b..58f7191a6980265e8fab17cf39769bbbca0ee105 100644
--- a/src/main/java/net/minecraft/server/ItemLingeringPotion.java
+++ b/src/main/java/net/minecraft/server/ItemLingeringPotion.java
@@ -8,7 +8,12 @@ public class ItemLingeringPotion extends ItemPotionThrowable {
@Override
public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) {
- world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_LINGERING_POTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemLingeringPotion.RANDOM.nextFloat() * 0.4F + 0.8F));
- return super.a(world, entityhuman, enumhand);
+ // Paper start
+ InteractionResultWrapper<ItemStack> wrapper = super.a(world, entityhuman, enumhand);
+ if (wrapper.getResult() != EnumInteractionResult.FAIL) {
+ world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_LINGERING_POTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemLingeringPotion.RANDOM.nextFloat() * 0.4F + 0.8F));
+ }
+ return wrapper;
+ // Paper end
}
}
diff --git a/src/main/java/net/minecraft/server/ItemPotionThrowable.java b/src/main/java/net/minecraft/server/ItemPotionThrowable.java
index dee3d4042b0cd1ace86fe1d80d894d0cc48cf941..9c84de77df7e32915a633b92c842cfb69e30e0d0 100644
--- a/src/main/java/net/minecraft/server/ItemPotionThrowable.java
+++ b/src/main/java/net/minecraft/server/ItemPotionThrowable.java
@@ -15,13 +15,31 @@ public class ItemPotionThrowable extends ItemPotion {
entitypotion.setItem(itemstack);
entitypotion.a(entityhuman, entityhuman.pitch, entityhuman.yaw, -20.0F, 0.5F, 1.0F);
- world.addEntity(entitypotion);
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entitypotion.getBukkitEntity());
+ if (event.callEvent() && world.addEntity(entitypotion)) {
+ if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) {
+ itemstack.subtract(1);
+ } else if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ }
+
+ entityhuman.b(StatisticList.ITEM_USED.b(this));
+ } else {
+ if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ }
+ return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
+ }
+ // Paper end
}
+ /* // Paper start - moved up
entityhuman.b(StatisticList.ITEM_USED.b(this));
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack.subtract(1);
}
+ */ // Paper end
return InteractionResultWrapper.a(itemstack, world.s_());
}
diff --git a/src/main/java/net/minecraft/server/ItemSnowball.java b/src/main/java/net/minecraft/server/ItemSnowball.java
index 19ac8cc57d6400e7574dd475dd21f2f48a954324..4242b5c4ed1e7d546fee7e2b3892b7b25e1259ff 100644
--- a/src/main/java/net/minecraft/server/ItemSnowball.java
+++ b/src/main/java/net/minecraft/server/ItemSnowball.java
@@ -17,14 +17,20 @@ public class ItemSnowball extends Item {
entitysnowball.setItem(itemstack);
entitysnowball.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F);
- if (world.addEntity(entitysnowball)) {
- if (!entityhuman.abilities.canInstantlyBuild) {
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entitysnowball.getBukkitEntity());
+ if (event.callEvent() && world.addEntity(entitysnowball)) {
+ if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) {
+ // Paper end
itemstack.subtract(1);
+ } else if (entityhuman instanceof EntityPlayer) { // Paper
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // Paper
}
world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemSnowball.RANDOM.nextFloat() * 0.4F + 0.8F));
- } else if (entityhuman instanceof EntityPlayer) {
- ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } else { // Paper
+ if (entityhuman instanceof EntityPlayer) ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // Paper
+ return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack); // Paper
}
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/ItemSplashPotion.java b/src/main/java/net/minecraft/server/ItemSplashPotion.java
index 3574cf875c6284687c10637159ec96a823ade2dc..c919a402e80a5c6b17fdbd99e110be1abefda747 100644
--- a/src/main/java/net/minecraft/server/ItemSplashPotion.java
+++ b/src/main/java/net/minecraft/server/ItemSplashPotion.java
@@ -8,7 +8,12 @@ public class ItemSplashPotion extends ItemPotionThrowable {
@Override
public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) {
+ // Paper start
+ InteractionResultWrapper<ItemStack> wrapper = super.a(world, entityhuman, enumhand);
+ if (wrapper.getResult() != EnumInteractionResult.FAIL) {
world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (ItemSplashPotion.RANDOM.nextFloat() * 0.4F + 0.8F));
- return super.a(world, entityhuman, enumhand);
+ }
+ return wrapper;
+ // Paper end
}
}