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
|
--- a/net/minecraft/world/item/DyeItem.java
+++ b/net/minecraft/world/item/DyeItem.java
@@ -4,35 +4,51 @@
import java.util.Map;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
-import net.minecraft.world.InteractionHand;
+import net.minecraft.world.EnumHand;
import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.SignBlockEntity;
-import net.minecraft.world.level.block.entity.SignText;
+import org.bukkit.event.entity.SheepDyeWoolEvent; // CraftBukkit
public class DyeItem extends Item implements SignApplicator {
+
private static final Map<DyeColor, DyeItem> ITEM_BY_COLOR = Maps.newEnumMap(DyeColor.class);
private final DyeColor dyeColor;
public DyeItem(DyeColor dyeColor, Item.Properties properties) {
super(properties);
this.dyeColor = dyeColor;
- ITEM_BY_COLOR.put(dyeColor, this);
+ DyeItem.ITEM_BY_COLOR.put(dyeColor, this);
}
@Override
- public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity target, InteractionHand hand) {
- if (target instanceof Sheep sheep && sheep.isAlive() && !sheep.isSheared() && sheep.getColor() != this.dyeColor) {
- sheep.level().playSound(player, sheep, SoundEvents.DYE_USE, SoundSource.PLAYERS, 1.0F, 1.0F);
- if (!player.level().isClientSide) {
- sheep.setColor(this.dyeColor);
- stack.shrink(1);
- }
+ public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity target, EnumHand hand) {
+ if (target instanceof Sheep) {
+ Sheep entitysheep = (Sheep) target;
- return InteractionResult.sidedSuccess(player.level().isClientSide);
+ if (entitysheep.isAlive() && !entitysheep.isSheared() && entitysheep.getColor() != this.dyeColor) {
+ entitysheep.level().playSound(player, (Entity) entitysheep, SoundEvents.DYE_USE, SoundSource.PLAYERS, 1.0F, 1.0F);
+ if (!player.level().isClientSide) {
+ // CraftBukkit start
+ byte bColor = (byte) this.dyeColor.getId();
+ SheepDyeWoolEvent event = new SheepDyeWoolEvent((org.bukkit.entity.Sheep) entitysheep.getBukkitEntity(), org.bukkit.DyeColor.getByWoolData(bColor), (org.bukkit.entity.Player) player.getBukkitEntity());
+ entitysheep.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return InteractionResult.PASS;
+ }
+
+ entitysheep.setColor(DyeColor.byId((byte) event.getColor().getWoolData()));
+ // CraftBukkit end
+ stack.shrink(1);
+ }
+
+ return InteractionResult.sidedSuccess(player.level().isClientSide);
+ }
}
return InteractionResult.PASS;
@@ -43,13 +59,15 @@
}
public static DyeItem byColor(DyeColor color) {
- return ITEM_BY_COLOR.get(color);
+ return (DyeItem) DyeItem.ITEM_BY_COLOR.get(color);
}
@Override
public boolean tryApplyToSign(Level level, SignBlockEntity sign, boolean isFront, Player player) {
- if (sign.updateText(signText -> signText.setColor(this.getDyeColor()), isFront)) {
- level.playSound(null, sign.getBlockPos(), SoundEvents.DYE_USE, SoundSource.BLOCKS, 1.0F, 1.0F);
+ if (sign.updateText((signtext) -> {
+ return signtext.setColor(this.getDyeColor());
+ }, isFront)) {
+ level.playSound((Player) null, sign.getBlockPos(), SoundEvents.DYE_USE, SoundSource.BLOCKS, 1.0F, 1.0F);
return true;
} else {
return false;
|