aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0409-PlayerLaunchProjectileEvent.patch
blob: d5773b74c1d07824aba11d681fd54b8af4a1eae8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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 5cab47a2821adf869693132f8ce1193b1543f896..886babdcda0b559fc6a760b48074bec44e0f9da1 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 6fccd70a034b5d70729f57e0f2ee56e59e6f9cbc..16f1b734e01ee7cf917d2f9a4a4dc1e98e4f2af9 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.i.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.success(itemstack);
     }
diff --git a/src/main/java/net/minecraft/server/ItemEnderPearl.java b/src/main/java/net/minecraft/server/ItemEnderPearl.java
index cab869e8e9b6a505e23c109c4434178a8824ba45..b57e9f7e72b892165129c3857d5d03a088bee3ee 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.i.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.i.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
 
         return InteractionResultWrapper.success(itemstack);
     }
diff --git a/src/main/java/net/minecraft/server/ItemExpBottle.java b/src/main/java/net/minecraft/server/ItemExpBottle.java
index 071688b3ab45a527a642c3d16c8d8b1f3682e63c..1d575af5269762f6f2616884a7733470cca06be5 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.i.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.i.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.success(itemstack);
     }
diff --git a/src/main/java/net/minecraft/server/ItemLingeringPotion.java b/src/main/java/net/minecraft/server/ItemLingeringPotion.java
index c19b678cfb2bc3c27858488031e119d482905f8b..7672e31fc0c915c49c8752ba864c2706f1292e86 100644
--- a/src/main/java/net/minecraft/server/ItemLingeringPotion.java
+++ b/src/main/java/net/minecraft/server/ItemLingeringPotion.java
@@ -8,7 +8,11 @@ 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.i.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.i.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 5d1f118c5139540a809dbaeee0982fbc7e9c3996..d1beab1ab72dffd3ee671982991d414b9244973d 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.success(itemstack);
     }
diff --git a/src/main/java/net/minecraft/server/ItemSnowball.java b/src/main/java/net/minecraft/server/ItemSnowball.java
index 56ec5089596de4209780a823a2a3f37676ec515b..e6044e654b78ab8ef9d73ef7bd6ad82a079745a8 100644
--- a/src/main/java/net/minecraft/server/ItemSnowball.java
+++ b/src/main/java/net/minecraft/server/ItemSnowball.java
@@ -17,19 +17,27 @@ 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) {
                     itemstack.subtract(1);
+                } else if (entityhuman instanceof EntityPlayer) {
+                    ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
                 }
 
-                world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemSnowball.i.nextFloat() * 0.4F + 0.8F));
-            } else if (entityhuman instanceof EntityPlayer) {
-                ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+                world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_SNOWBALL_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);
             }
         }
         // CraftBukkit end
 
-        entityhuman.b(StatisticList.ITEM_USED.b(this));
+//        entityhuman.b(StatisticList.ITEM_USED.b(this)); // Paper - moved up
         // CraftBukkit start - moved up
         /*
         if (!entityhuman.abilities.canInstantlyBuild) {
diff --git a/src/main/java/net/minecraft/server/ItemSplashPotion.java b/src/main/java/net/minecraft/server/ItemSplashPotion.java
index 18bd846ceecf638fa1184a6cceb5c909ec49372c..e71e933fffb04aa4a00d02cfbc284da8ad3ee925 100644
--- a/src/main/java/net/minecraft/server/ItemSplashPotion.java
+++ b/src/main/java/net/minecraft/server/ItemSplashPotion.java
@@ -8,7 +8,11 @@ public class ItemSplashPotion 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_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (ItemSplashPotion.i.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_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (ItemSplashPotion.i.nextFloat() * 0.4F + 0.8F));
+        return wrapper;
+        // Paper end
     }
 }