#662: Expose ItemStack and hand used in PlayerShearEntityEvent

This commit is contained in:
Parker Hawke 2020-05-02 17:48:37 +10:00 committed by md_5
parent 77fd87e4d0
commit 1872231235
4 changed files with 27 additions and 27 deletions

View File

@ -1,26 +1,22 @@
--- a/net/minecraft/server/EntityMushroomCow.java --- a/net/minecraft/server/EntityMushroomCow.java
+++ b/net/minecraft/server/EntityMushroomCow.java +++ b/net/minecraft/server/EntityMushroomCow.java
@@ -3,6 +3,11 @@ @@ -3,6 +3,10 @@
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
+// CraftBukkit start +// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTransformEvent; +import org.bukkit.event.entity.EntityTransformEvent;
+import org.bukkit.event.player.PlayerShearEntityEvent;
+// CraftBukkit end +// CraftBukkit end
public class EntityMushroomCow extends EntityCow { public class EntityMushroomCow extends EntityCow {
@@ -81,9 +86,17 @@ @@ -81,9 +85,14 @@
int i; int i;
if (itemstack.getItem() == Items.SHEARS && !this.isBaby()) { if (itemstack.getItem() == Items.SHEARS && !this.isBaby()) {
+ // CraftBukkit start + // CraftBukkit start
+ PlayerShearEntityEvent event = new PlayerShearEntityEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), this.getBukkitEntity()); + if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) {
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return false; + return false;
+ } + }
+ // CraftBukkit end + // CraftBukkit end
@ -31,7 +27,7 @@
EntityCow entitycow = (EntityCow) EntityTypes.COW.a(this.world); EntityCow entitycow = (EntityCow) EntityTypes.COW.a(this.world);
entitycow.setPositionRotation(this.locX(), this.locY(), this.locZ(), this.yaw, this.pitch); entitycow.setPositionRotation(this.locX(), this.locY(), this.locZ(), this.yaw, this.pitch);
@@ -99,7 +112,14 @@ @@ -99,7 +108,14 @@
} }
entitycow.setInvulnerable(this.isInvulnerable()); entitycow.setInvulnerable(this.isInvulnerable());

View File

@ -5,8 +5,8 @@
import javax.annotation.Nullable; import javax.annotation.Nullable;
+// CraftBukkit start +// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.SheepRegrowWoolEvent; +import org.bukkit.event.entity.SheepRegrowWoolEvent;
+import org.bukkit.event.player.PlayerShearEntityEvent;
+import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.InventoryView;
+// CraftBukkit end +// CraftBukkit end
+ +
@ -18,15 +18,12 @@
enummap.put(EnumColor.WHITE, Blocks.WHITE_WOOL); enummap.put(EnumColor.WHITE, Blocks.WHITE_WOOL);
enummap.put(EnumColor.ORANGE, Blocks.ORANGE_WOOL); enummap.put(EnumColor.ORANGE, Blocks.ORANGE_WOOL);
enummap.put(EnumColor.MAGENTA, Blocks.MAGENTA_WOOL); enummap.put(EnumColor.MAGENTA, Blocks.MAGENTA_WOOL);
@@ -141,6 +147,15 @@ @@ -141,6 +147,12 @@
ItemStack itemstack = entityhuman.b(enumhand); ItemStack itemstack = entityhuman.b(enumhand);
if (itemstack.getItem() == Items.SHEARS && !this.isSheared() && !this.isBaby()) { if (itemstack.getItem() == Items.SHEARS && !this.isSheared() && !this.isBaby()) {
+ // CraftBukkit start + // CraftBukkit start
+ PlayerShearEntityEvent event = new PlayerShearEntityEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), this.getBukkitEntity()); + if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) {
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return false; + return false;
+ } + }
+ // CraftBukkit end + // CraftBukkit end
@ -34,7 +31,7 @@
this.shear(); this.shear();
if (!this.world.isClientSide) { if (!this.world.isClientSide) {
itemstack.damage(1, entityhuman, (entityhuman1) -> { itemstack.damage(1, entityhuman, (entityhuman1) -> {
@@ -160,7 +175,9 @@ @@ -160,7 +172,9 @@
int i = 1 + this.random.nextInt(3); int i = 1 + this.random.nextInt(3);
for (int j = 0; j < i; ++j) { for (int j = 0; j < i; ++j) {
@ -44,7 +41,7 @@
if (entityitem != null) { if (entityitem != null) {
entityitem.setMot(entityitem.getMot().add((double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (this.random.nextFloat() * 0.05F), (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F))); entityitem.setMot(entityitem.getMot().add((double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (this.random.nextFloat() * 0.05F), (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F)));
@@ -247,6 +264,12 @@ @@ -247,6 +261,12 @@
@Override @Override
public void blockEaten() { public void blockEaten() {
@ -57,7 +54,7 @@
this.setSheared(false); this.setSheared(false);
if (this.isBaby()) { if (this.isBaby()) {
this.setAge(60); this.setAge(60);
@@ -265,7 +288,7 @@ @@ -265,7 +285,7 @@
EnumColor enumcolor = ((EntitySheep) entityanimal).getColor(); EnumColor enumcolor = ((EntitySheep) entityanimal).getColor();
EnumColor enumcolor1 = ((EntitySheep) entityanimal1).getColor(); EnumColor enumcolor1 = ((EntitySheep) entityanimal1).getColor();
InventoryCrafting inventorycrafting = a(enumcolor, enumcolor1); InventoryCrafting inventorycrafting = a(enumcolor, enumcolor1);
@ -66,7 +63,7 @@
return recipecrafting.a(inventorycrafting); return recipecrafting.a(inventorycrafting);
}).map(ItemStack::getItem); }).map(ItemStack::getItem);
@@ -283,10 +306,18 @@ @@ -283,10 +303,18 @@
public boolean canUse(EntityHuman entityhuman) { public boolean canUse(EntityHuman entityhuman) {
return false; return false;
} }

View File

@ -1,17 +1,16 @@
--- a/net/minecraft/server/EntitySnowman.java --- a/net/minecraft/server/EntitySnowman.java
+++ b/net/minecraft/server/EntitySnowman.java +++ b/net/minecraft/server/EntitySnowman.java
@@ -1,6 +1,10 @@ @@ -1,6 +1,9 @@
package net.minecraft.server; package net.minecraft.server;
import javax.annotation.Nullable; import javax.annotation.Nullable;
+// CraftBukkit start +// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.player.PlayerShearEntityEvent;
+// CraftBukkit end +// CraftBukkit end
public class EntitySnowman extends EntityGolem implements IRangedEntity { public class EntitySnowman extends EntityGolem implements IRangedEntity {
@@ -62,7 +66,7 @@ @@ -62,7 +65,7 @@
} }
if (this.world.getBiome(new BlockPosition(i, 0, k)).getAdjustedTemperature(new BlockPosition(i, j, k)) > 1.0F) { if (this.world.getBiome(new BlockPosition(i, 0, k)).getAdjustedTemperature(new BlockPosition(i, j, k)) > 1.0F) {
@ -20,7 +19,7 @@
} }
if (!this.world.getGameRules().getBoolean(GameRules.MOB_GRIEFING)) { if (!this.world.getGameRules().getBoolean(GameRules.MOB_GRIEFING)) {
@@ -78,7 +82,7 @@ @@ -78,7 +81,7 @@
BlockPosition blockposition = new BlockPosition(i, j, k); BlockPosition blockposition = new BlockPosition(i, j, k);
if (this.world.getType(blockposition).isAir() && this.world.getBiome(blockposition).getAdjustedTemperature(blockposition) < 0.8F && iblockdata.canPlace(this.world, blockposition)) { if (this.world.getType(blockposition).isAir() && this.world.getBiome(blockposition).getAdjustedTemperature(blockposition) < 0.8F && iblockdata.canPlace(this.world, blockposition)) {
@ -29,15 +28,12 @@
} }
} }
} }
@@ -110,6 +114,14 @@ @@ -110,6 +113,11 @@
if (itemstack.getItem() == Items.SHEARS && this.hasPumpkin()) { if (itemstack.getItem() == Items.SHEARS && this.hasPumpkin()) {
if (!this.world.isClientSide) { if (!this.world.isClientSide) {
+ // CraftBukkit start + // CraftBukkit start
+ PlayerShearEntityEvent event = new PlayerShearEntityEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), this.getBukkitEntity()); + if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) {
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return false; + return false;
+ } + }
+ // CraftBukkit end + // CraftBukkit end

View File

@ -196,6 +196,7 @@ import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.event.player.PlayerItemMendEvent; import org.bukkit.event.player.PlayerItemMendEvent;
import org.bukkit.event.player.PlayerLevelChangeEvent; import org.bukkit.event.player.PlayerLevelChangeEvent;
import org.bukkit.event.player.PlayerRecipeDiscoverEvent; import org.bukkit.event.player.PlayerRecipeDiscoverEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerStatisticIncrementEvent; import org.bukkit.event.player.PlayerStatisticIncrementEvent;
import org.bukkit.event.player.PlayerUnleashEntityEvent; import org.bukkit.event.player.PlayerUnleashEntityEvent;
import org.bukkit.event.raid.RaidFinishEvent; import org.bukkit.event.raid.RaidFinishEvent;
@ -1309,6 +1310,16 @@ public class CraftEventFactory {
return bse; return bse;
} }
public static boolean handlePlayerShearEntityEvent(EntityHuman player, Entity sheared, ItemStack shears, EnumHand hand) {
if (!(player instanceof EntityPlayer)) {
return true;
}
PlayerShearEntityEvent event = new PlayerShearEntityEvent((Player) player.getBukkitEntity(), sheared.getBukkitEntity(), CraftItemStack.asCraftMirror(shears), (hand == EnumHand.OFF_HAND ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
Bukkit.getPluginManager().callEvent(event);
return !event.isCancelled();
}
public static Cancellable handleStatisticsIncrease(EntityHuman entityHuman, net.minecraft.server.Statistic<?> statistic, int current, int incrementation) { public static Cancellable handleStatisticsIncrease(EntityHuman entityHuman, net.minecraft.server.Statistic<?> statistic, int current, int incrementation) {
Player player = ((EntityPlayer) entityHuman).getBukkitEntity(); Player player = ((EntityPlayer) entityHuman).getBukkitEntity();
Event event; Event event;