PaperMC/patches/server/PlayerLaunchProjectileEvent.patch

302 lines
20 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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/world/item/EggItem.java b/src/main/java/net/minecraft/world/item/EggItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/EggItem.java
+++ b/src/main/java/net/minecraft/world/item/EggItem.java
@@ -0,0 +0,0 @@ public class EggItem extends Item {
entityegg.setItem(itemstack);
2021-06-12 23:31:35 +02:00
entityegg.shootFromRotation(user, user.getXRot(), user.getYRot(), 0.0F, 1.5F, 1.0F);
2021-06-11 14:02:28 +02:00
- // CraftBukkit start
- if (!world.addFreshEntity(entityegg)) {
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entityegg.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(entityegg)) {
2021-06-12 23:31:35 +02:00
+ if (event.shouldConsume() && !user.getAbilities().instabuild) {
2021-06-11 14:02:28 +02:00
+ itemstack.shrink(1);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
2021-06-12 23:31:35 +02:00
+ world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), net.minecraft.sounds.SoundEvents.EGG_THROW, net.minecraft.sounds.SoundSource.PLAYERS, 0.5F, 0.4F / (net.minecraft.world.entity.Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
2021-06-11 14:02:28 +02:00
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
if (user instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
}
2021-06-12 23:31:35 +02:00
return InteractionResultHolder.fail(itemstack);
2021-06-11 14:02:28 +02:00
}
- // CraftBukkit end
+ // Paper end
}
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
2021-06-11 14:02:28 +02:00
+ /* // Paper start - moved up
2021-06-12 23:31:35 +02:00
user.awardStat(Stats.ITEM_USED.get(this));
if (!user.getAbilities().instabuild) {
itemstack.shrink(1);
2021-06-11 14:02:28 +02:00
}
+ */ // Paper end
return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
}
diff --git a/src/main/java/net/minecraft/world/item/EnderpearlItem.java b/src/main/java/net/minecraft/world/item/EnderpearlItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/EnderpearlItem.java
+++ b/src/main/java/net/minecraft/world/item/EnderpearlItem.java
@@ -0,0 +0,0 @@ public class EnderpearlItem extends Item {
entityenderpearl.setItem(itemstack);
2021-06-12 23:31:35 +02:00
entityenderpearl.shootFromRotation(user, user.getXRot(), user.getYRot(), 0.0F, 1.5F, 1.0F);
2021-06-11 14:02:28 +02:00
- if (!world.addFreshEntity(entityenderpearl)) {
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entityenderpearl.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(entityenderpearl)) {
2021-06-12 23:31:35 +02:00
+ if (event.shouldConsume() && !user.getAbilities().instabuild) {
2021-06-11 14:02:28 +02:00
+ itemstack.shrink(1);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (net.minecraft.world.entity.Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ user.awardStat(Stats.ITEM_USED.get(this));
+ user.getCooldowns().addCooldown(this, 20);
+ } else {
+ // Paper end
if (user instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
}
2021-06-12 23:31:35 +02:00
@@ -0,0 +0,0 @@ public class EnderpearlItem extends Item {
2021-06-11 14:02:28 +02:00
}
}
2021-06-12 23:31:35 +02:00
+ /* // Paper start - moved up
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
user.getCooldowns().addCooldown(this, 20);
// CraftBukkit end
@@ -0,0 +0,0 @@ public class EnderpearlItem extends Item {
if (!user.getAbilities().instabuild) {
itemstack.shrink(1);
}
+ */ // Paper end - moved up
2021-06-11 14:02:28 +02:00
return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
}
diff --git a/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java b/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
+++ b/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
@@ -0,0 +0,0 @@ public class ExperienceBottleItem extends Item {
2021-06-12 23:31:35 +02:00
@Override
2021-06-11 14:02:28 +02:00
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
2021-06-12 23:31:35 +02:00
ItemStack itemStack = user.getItemInHand(hand);
- world.playSound((Player)null, user.getX(), user.getY(), user.getZ(), SoundEvents.EXPERIENCE_BOTTLE_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
+ // world.playSound((Player)null, user.getX(), user.getY(), user.getZ(), SoundEvents.EXPERIENCE_BOTTLE_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); // Paper - moved down
2021-06-11 14:02:28 +02:00
if (!world.isClientSide) {
2021-06-12 23:31:35 +02:00
ThrownExperienceBottle thrownExperienceBottle = new ThrownExperienceBottle(world, user);
thrownExperienceBottle.setItem(itemStack);
thrownExperienceBottle.shootFromRotation(user, user.getXRot(), user.getYRot(), -20.0F, 0.7F, 1.0F);
- world.addFreshEntity(thrownExperienceBottle);
2021-06-11 14:02:28 +02:00
+ // Paper start
2021-06-12 23:31:35 +02:00
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) thrownExperienceBottle.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(thrownExperienceBottle)) {
+ if (event.shouldConsume() && !user.getAbilities().instabuild) {
+ itemStack.shrink(1);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
2021-06-11 14:02:28 +02:00
+ }
+
2021-06-12 23:31:35 +02:00
+ world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.EXPERIENCE_BOTTLE_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (net.minecraft.world.entity.Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
2021-06-11 14:02:28 +02:00
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
2021-06-12 23:31:35 +02:00
+ if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
2021-06-11 14:02:28 +02:00
+ }
2021-06-12 23:31:35 +02:00
+ return InteractionResultHolder.fail(itemStack);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
}
+ /* // Paper start - moved up
2021-06-12 23:31:35 +02:00
user.awardStat(Stats.ITEM_USED.get(this));
if (!user.getAbilities().instabuild) {
itemStack.shrink(1);
2021-06-11 14:02:28 +02:00
}
+ */ // Paper end
2021-06-12 23:31:35 +02:00
return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide());
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
+++ b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
@@ -0,0 +0,0 @@ public class FireworkRocketItem extends Item {
2021-06-12 23:31:35 +02:00
Direction direction = context.getClickedFace();
FireworkRocketEntity fireworkRocketEntity = new FireworkRocketEntity(level, context.getPlayer(), vec3.x + (double)direction.getStepX() * 0.15D, vec3.y + (double)direction.getStepY() * 0.15D, vec3.z + (double)direction.getStepZ() * 0.15D, itemStack);
fireworkRocketEntity.spawningEntity = context.getPlayer() == null ? null : context.getPlayer().getUUID(); // Paper
- level.addFreshEntity(fireworkRocketEntity);
- itemStack.shrink(1);
2021-06-11 14:02:28 +02:00
+ // Paper start - PlayerLaunchProjectileEvent
2021-06-12 23:31:35 +02:00
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) context.getPlayer().getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Firework) fireworkRocketEntity.getBukkitEntity());
+ if (!event.callEvent() || !level.addFreshEntity(fireworkRocketEntity)) return InteractionResult.PASS;
+ if (event.shouldConsume() && !context.getPlayer().getAbilities().instabuild) itemStack.shrink(1);
2022-12-07 19:52:24 +01:00
+ else if (context.getPlayer() instanceof net.minecraft.server.level.ServerPlayer) ((net.minecraft.server.level.ServerPlayer) context.getPlayer()).getBukkitEntity().updateInventory();
2021-06-11 14:02:28 +02:00
+ // Paper end
}
2021-06-12 23:31:35 +02:00
return InteractionResult.sidedSuccess(level.isClientSide);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/item/LingeringPotionItem.java b/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
+++ b/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
@@ -0,0 +0,0 @@ public class LingeringPotionItem extends ThrowablePotionItem {
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
+ // Paper start
+ InteractionResultHolder<ItemStack> wrapper = super.use(world, user, hand);
2021-06-12 23:31:35 +02:00
+ if (wrapper.getResult() != net.minecraft.world.InteractionResult.FAIL) {
world.playSound((Player)null, user.getX(), user.getY(), user.getZ(), SoundEvents.LINGERING_POTION_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
- return super.use(world, user, hand);
2021-06-11 14:02:28 +02:00
+ }
+ return wrapper;
+ // Paper end
}
}
diff --git a/src/main/java/net/minecraft/world/item/SnowballItem.java b/src/main/java/net/minecraft/world/item/SnowballItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/SnowballItem.java
+++ b/src/main/java/net/minecraft/world/item/SnowballItem.java
@@ -0,0 +0,0 @@ public class SnowballItem extends Item {
entitysnowball.setItem(itemstack);
2021-06-12 23:31:35 +02:00
entitysnowball.shootFromRotation(user, user.getXRot(), user.getYRot(), 0.0F, 1.5F, 1.0F);
2021-06-11 14:02:28 +02:00
- if (world.addFreshEntity(entitysnowball)) {
2021-06-12 23:31:35 +02:00
- if (!user.getAbilities().instabuild) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entitysnowball.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(entitysnowball)) {
2021-06-12 23:31:35 +02:00
+ user.awardStat(Stats.ITEM_USED.get(this));
+ if (event.shouldConsume() && !user.getAbilities().instabuild) {
2021-06-11 14:02:28 +02:00
+ // Paper end
itemstack.shrink(1);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) { // Paper
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory(); // Paper
}
2021-06-12 23:31:35 +02:00
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
2021-06-11 14:02:28 +02:00
- } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
- ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ } else { // Paper
+ if (user instanceof net.minecraft.server.level.ServerPlayer) ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory(); // Paper
2021-06-12 23:31:35 +02:00
+ return InteractionResultHolder.fail(itemstack); // Paper
2021-06-11 14:02:28 +02:00
}
}
// CraftBukkit end
2021-06-12 23:31:35 +02:00
+ /* // Paper tart - moved up
user.awardStat(Stats.ITEM_USED.get(this));
// CraftBukkit start - moved up
/*
@@ -0,0 +0,0 @@ public class SnowballItem extends Item {
2021-11-23 16:04:41 +01:00
itemstack.shrink(1);
2021-06-12 23:31:35 +02:00
}
*/
+ // Paper end
return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/item/SplashPotionItem.java b/src/main/java/net/minecraft/world/item/SplashPotionItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/SplashPotionItem.java
+++ b/src/main/java/net/minecraft/world/item/SplashPotionItem.java
@@ -0,0 +0,0 @@ public class SplashPotionItem extends ThrowablePotionItem {
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
+ // Paper start
+ InteractionResultHolder<ItemStack> wrapper = super.use(world, user, hand);
2021-06-12 23:31:35 +02:00
+ if (wrapper.getResult() != net.minecraft.world.InteractionResult.FAIL) {
world.playSound((Player)null, user.getX(), user.getY(), user.getZ(), SoundEvents.SPLASH_POTION_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
2021-06-11 14:02:28 +02:00
- return super.use(world, user, hand);
+ }
+ return wrapper;
+ // Paper end
}
}
diff --git a/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java b/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
+++ b/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
@@ -0,0 +0,0 @@ public class ThrowablePotionItem extends PotionItem {
2021-06-12 23:31:35 +02:00
ThrownPotion thrownPotion = new ThrownPotion(world, user);
thrownPotion.setItem(itemStack);
thrownPotion.shootFromRotation(user, user.getXRot(), user.getYRot(), -20.0F, 0.5F, 1.0F);
- world.addFreshEntity(thrownPotion);
2021-06-11 14:02:28 +02:00
+ // Paper start
2021-06-12 23:31:35 +02:00
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) thrownPotion.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(thrownPotion)) {
+ if (event.shouldConsume() && !user.getAbilities().instabuild) {
+ itemStack.shrink(1);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
2021-06-11 14:02:28 +02:00
+ }
+
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
2021-06-12 23:31:35 +02:00
+ if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
2021-06-11 14:02:28 +02:00
+ }
2021-06-12 23:31:35 +02:00
+ return InteractionResultHolder.fail(itemStack);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
}
+ /* // Paper start - moved up
2021-06-12 23:31:35 +02:00
user.awardStat(Stats.ITEM_USED.get(this));
if (!user.getAbilities().instabuild) {
itemStack.shrink(1);
2021-06-11 14:02:28 +02:00
}
+ */ // Paper end
2021-06-12 23:31:35 +02:00
return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide());
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/net/minecraft/world/item/TridentItem.java b/src/main/java/net/minecraft/world/item/TridentItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/TridentItem.java
+++ b/src/main/java/net/minecraft/world/item/TridentItem.java
@@ -0,0 +0,0 @@ public class TridentItem extends Item implements Vanishable {
}
// CraftBukkit start
- if (!world.addFreshEntity(entitythrowntrident)) {
+ // 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(stack), (org.bukkit.entity.Projectile) entitythrowntrident.getBukkitEntity());
+ if (!event.callEvent() || !world.addFreshEntity(entitythrowntrident)) {
+ // Paper end
if (entityhuman instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) entityhuman).getBukkitEntity().updateInventory();
}
return;
}
-
+ if (event.shouldConsume()) { // Paper
stack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
entityhuman1.broadcastBreakEvent(user.getUsedItemHand());
});
+ } // Paper
entitythrowntrident.tridentItem = stack.copy(); // SPIGOT-4511 update since damage call moved
// CraftBukkit end
world.playSound((Player) null, (Entity) entitythrowntrident, SoundEvents.TRIDENT_THROW, SoundSource.PLAYERS, 1.0F, 1.0F);
- if (!entityhuman.getAbilities().instabuild) {
+ if (event.shouldConsume() && !entityhuman.getAbilities().instabuild) { // Paper
entityhuman.getInventory().removeItem(stack);
}
// CraftBukkit start - SPIGOT-5458 also need in this branch :(