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
|
--- a/net/minecraft/stats/ServerRecipeBook.java
+++ b/net/minecraft/stats/ServerRecipeBook.java
@@ -4,6 +4,7 @@
import com.mojang.logging.LogUtils;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
@@ -19,27 +20,35 @@
import net.minecraft.world.item.crafting.RecipeManager;
import org.slf4j.Logger;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class ServerRecipeBook extends RecipeBook {
+
public static final String RECIPE_BOOK_TAG = "recipeBook";
private static final Logger LOGGER = LogUtils.getLogger();
+ public ServerRecipeBook() {}
+
public int addRecipes(Collection<RecipeHolder<?>> recipes, ServerPlayer player) {
List<ResourceLocation> list = Lists.newArrayList();
int i = 0;
+ Iterator iterator = recipes.iterator();
- for (RecipeHolder<?> recipeHolder : recipes) {
- ResourceLocation resourceLocation = recipeHolder.id();
- if (!this.known.contains(resourceLocation) && !recipeHolder.value().isSpecial()) {
- this.add(resourceLocation);
- this.addHighlight(resourceLocation);
- list.add(resourceLocation);
- CriteriaTriggers.RECIPE_UNLOCKED.trigger(player, recipeHolder);
- i++;
+ while (iterator.hasNext()) {
+ RecipeHolder<?> recipeholder = (RecipeHolder) iterator.next();
+ ResourceLocation minecraftkey = recipeholder.id();
+
+ if (!this.known.contains(minecraftkey) && !recipeholder.value().isSpecial() && CraftEventFactory.handlePlayerRecipeListUpdateEvent(player, minecraftkey)) { // CraftBukkit
+ this.add(minecraftkey);
+ this.addHighlight(minecraftkey);
+ list.add(minecraftkey);
+ CriteriaTriggers.RECIPE_UNLOCKED.trigger(player, recipeholder);
+ ++i;
}
}
if (list.size() > 0) {
- this.sendRecipes(ClientboundRecipePacket.State.ADD, player, list);
+ this.sendRecipes(ClientboundRecipePacket.Action.ADD, player, list);
}
return i;
@@ -48,71 +57,86 @@
public int removeRecipes(Collection<RecipeHolder<?>> recipes, ServerPlayer player) {
List<ResourceLocation> list = Lists.newArrayList();
int i = 0;
+ Iterator iterator = recipes.iterator();
- for (RecipeHolder<?> recipeHolder : recipes) {
- ResourceLocation resourceLocation = recipeHolder.id();
- if (this.known.contains(resourceLocation)) {
- this.remove(resourceLocation);
- list.add(resourceLocation);
- i++;
+ while (iterator.hasNext()) {
+ RecipeHolder<?> recipeholder = (RecipeHolder) iterator.next();
+ ResourceLocation minecraftkey = recipeholder.id();
+
+ if (this.known.contains(minecraftkey)) {
+ this.remove(minecraftkey);
+ list.add(minecraftkey);
+ ++i;
}
}
- this.sendRecipes(ClientboundRecipePacket.State.REMOVE, player, list);
+ this.sendRecipes(ClientboundRecipePacket.Action.REMOVE, player, list);
return i;
}
- private void sendRecipes(ClientboundRecipePacket.State state, ServerPlayer player, List<ResourceLocation> recipes) {
+ private void sendRecipes(ClientboundRecipePacket.Action state, ServerPlayer player, List<ResourceLocation> recipes) {
+ if (player.connection == null) return; // SPIGOT-4478 during PlayerLoginEvent
player.connection.send(new ClientboundRecipePacket(state, recipes, Collections.emptyList(), this.getBookSettings()));
}
public CompoundTag toNbt() {
- CompoundTag compoundTag = new CompoundTag();
- this.getBookSettings().write(compoundTag);
- ListTag list = new ListTag();
+ CompoundTag nbttagcompound = new CompoundTag();
- for (ResourceLocation resourceLocation : this.known) {
- list.add(StringTag.valueOf(resourceLocation.toString()));
+ this.getBookSettings().write(nbttagcompound);
+ ListTag nbttaglist = new ListTag();
+ Iterator iterator = this.known.iterator();
+
+ while (iterator.hasNext()) {
+ ResourceLocation minecraftkey = (ResourceLocation) iterator.next();
+
+ nbttaglist.add(StringTag.valueOf(minecraftkey.toString()));
}
- compoundTag.put("recipes", list);
- ListTag list1 = new ListTag();
+ nbttagcompound.put("recipes", nbttaglist);
+ ListTag nbttaglist1 = new ListTag();
+ Iterator iterator1 = this.highlight.iterator();
- for (ResourceLocation resourceLocation1 : this.highlight) {
- list1.add(StringTag.valueOf(resourceLocation1.toString()));
+ while (iterator1.hasNext()) {
+ ResourceLocation minecraftkey1 = (ResourceLocation) iterator1.next();
+
+ nbttaglist1.add(StringTag.valueOf(minecraftkey1.toString()));
}
- compoundTag.put("toBeDisplayed", list1);
- return compoundTag;
+ nbttagcompound.put("toBeDisplayed", nbttaglist1);
+ return nbttagcompound;
}
public void fromNbt(CompoundTag tag, RecipeManager recipeManager) {
this.setBookSettings(RecipeBookSettings.read(tag));
- ListTag list = tag.getList("recipes", 8);
- this.loadRecipes(list, this::add, recipeManager);
- ListTag list1 = tag.getList("toBeDisplayed", 8);
- this.loadRecipes(list1, this::addHighlight, recipeManager);
+ ListTag nbttaglist = tag.getList("recipes", 8);
+
+ this.loadRecipes(nbttaglist, this::add, recipeManager);
+ ListTag nbttaglist1 = tag.getList("toBeDisplayed", 8);
+
+ this.loadRecipes(nbttaglist1, this::addHighlight, recipeManager);
}
private void loadRecipes(ListTag tags, Consumer<RecipeHolder<?>> recipeConsumer, RecipeManager recipeManager) {
- for (int i = 0; i < tags.size(); i++) {
- String string = tags.getString(i);
+ for (int i = 0; i < tags.size(); ++i) {
+ String s = tags.getString(i);
try {
- ResourceLocation resourceLocation = new ResourceLocation(string);
- Optional<RecipeHolder<?>> optional = recipeManager.byKey(resourceLocation);
+ ResourceLocation minecraftkey = new ResourceLocation(s);
+ Optional<RecipeHolder<?>> optional = recipeManager.byKey(minecraftkey);
+
if (optional.isEmpty()) {
- LOGGER.error("Tried to load unrecognized recipe: {} removed now.", resourceLocation);
+ ServerRecipeBook.LOGGER.error("Tried to load unrecognized recipe: {} removed now.", minecraftkey);
} else {
- recipeConsumer.accept(optional.get());
+ recipeConsumer.accept((RecipeHolder) optional.get());
}
- } catch (ResourceLocationException var8) {
- LOGGER.error("Tried to load improperly formatted recipe: {} removed now.", string);
+ } catch (ResourceLocationException resourcekeyinvalidexception) {
+ ServerRecipeBook.LOGGER.error("Tried to load improperly formatted recipe: {} removed now.", s);
}
}
+
}
public void sendInitialRecipeBook(ServerPlayer player) {
- player.connection.send(new ClientboundRecipePacket(ClientboundRecipePacket.State.INIT, this.known, this.highlight, this.getBookSettings()));
+ player.connection.send(new ClientboundRecipePacket(ClientboundRecipePacket.Action.INIT, this.known, this.highlight, this.getBookSettings()));
}
}
|