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
|
--- a/net/minecraft/advancements/AdvancementTree.java
+++ b/net/minecraft/advancements/AdvancementTree.java
@@ -5,8 +5,10 @@
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
@@ -14,78 +16,96 @@
import org.slf4j.Logger;
public class AdvancementTree {
+
private static final Logger LOGGER = LogUtils.getLogger();
- private final Map<ResourceLocation, AdvancementNode> nodes = new Object2ObjectOpenHashMap<>();
- private final Set<AdvancementNode> roots = new ObjectLinkedOpenHashSet<>();
- private final Set<AdvancementNode> tasks = new ObjectLinkedOpenHashSet<>();
+ private final Map<ResourceLocation, AdvancementNode> nodes = new Object2ObjectOpenHashMap();
+ private final Set<AdvancementNode> roots = new ObjectLinkedOpenHashSet();
+ private final Set<AdvancementNode> tasks = new ObjectLinkedOpenHashSet();
@Nullable
- private AdvancementTree.Listener listener;
+ private AdvancementTree.a listener;
- private void remove(AdvancementNode advancementNode) {
- for (AdvancementNode advancementNode1 : advancementNode.children()) {
- this.remove(advancementNode1);
+ public AdvancementTree() {}
+
+ private void remove(AdvancementNode advancementnode) {
+ Iterator iterator = advancementnode.children().iterator();
+
+ while (iterator.hasNext()) {
+ AdvancementNode advancementnode1 = (AdvancementNode) iterator.next();
+
+ this.remove(advancementnode1);
}
- LOGGER.info("Forgot about advancement {}", advancementNode.holder());
- this.nodes.remove(advancementNode.holder().id());
- if (advancementNode.parent() == null) {
- this.roots.remove(advancementNode);
+ AdvancementTree.LOGGER.info("Forgot about advancement {}", advancementnode.holder());
+ this.nodes.remove(advancementnode.holder().id());
+ if (advancementnode.parent() == null) {
+ this.roots.remove(advancementnode);
if (this.listener != null) {
- this.listener.onRemoveAdvancementRoot(advancementNode);
+ this.listener.onRemoveAdvancementRoot(advancementnode);
}
} else {
- this.tasks.remove(advancementNode);
+ this.tasks.remove(advancementnode);
if (this.listener != null) {
- this.listener.onRemoveAdvancementTask(advancementNode);
+ this.listener.onRemoveAdvancementTask(advancementnode);
}
}
+
}
public void remove(Set<ResourceLocation> set) {
- for (ResourceLocation resourceLocation : set) {
- AdvancementNode advancementNode = this.nodes.get(resourceLocation);
- if (advancementNode == null) {
- LOGGER.warn("Told to remove advancement {} but I don't know what that is", resourceLocation);
+ Iterator iterator = set.iterator();
+
+ while (iterator.hasNext()) {
+ ResourceLocation minecraftkey = (ResourceLocation) iterator.next();
+ AdvancementNode advancementnode = (AdvancementNode) this.nodes.get(minecraftkey);
+
+ if (advancementnode == null) {
+ AdvancementTree.LOGGER.warn("Told to remove advancement {} but I don't know what that is", minecraftkey);
} else {
- this.remove(advancementNode);
+ this.remove(advancementnode);
}
}
+
}
public void addAll(Collection<AdvancementHolder> collection) {
- List<AdvancementHolder> list = new ArrayList<>(collection);
+ ArrayList<AdvancementHolder> arraylist = new ArrayList(collection); // CraftBukkit - decompile error
- while (!list.isEmpty()) {
- if (!list.removeIf(this::tryInsert)) {
- LOGGER.error("Couldn't load advancements: {}", list);
+ while (!arraylist.isEmpty()) {
+ if (!arraylist.removeIf(this::tryInsert)) {
+ AdvancementTree.LOGGER.error("Couldn't load advancements: {}", arraylist);
break;
}
}
- LOGGER.info("Loaded {} advancements", this.nodes.size());
+ // AdvancementTree.LOGGER.info("Loaded {} advancements", this.nodes.size()); // CraftBukkit - moved to AdvancementDataWorld#reload
}
- private boolean tryInsert(AdvancementHolder advancementHolder) {
- Optional<ResourceLocation> optional = advancementHolder.value().parent();
- AdvancementNode advancementNode = optional.map(this.nodes::get).orElse(null);
- if (advancementNode == null && optional.isPresent()) {
+ private boolean tryInsert(AdvancementHolder advancementholder) {
+ Optional<ResourceLocation> optional = advancementholder.value().parent();
+ Map map = this.nodes;
+
+ Objects.requireNonNull(this.nodes);
+ AdvancementNode advancementnode = (AdvancementNode) optional.map(map::get).orElse((Object) null);
+
+ if (advancementnode == null && optional.isPresent()) {
return false;
} else {
- AdvancementNode advancementNode1 = new AdvancementNode(advancementHolder, advancementNode);
- if (advancementNode != null) {
- advancementNode.addChild(advancementNode1);
+ AdvancementNode advancementnode1 = new AdvancementNode(advancementholder, advancementnode);
+
+ if (advancementnode != null) {
+ advancementnode.addChild(advancementnode1);
}
- this.nodes.put(advancementHolder.id(), advancementNode1);
- if (advancementNode == null) {
- this.roots.add(advancementNode1);
+ this.nodes.put(advancementholder.id(), advancementnode1);
+ if (advancementnode == null) {
+ this.roots.add(advancementnode1);
if (this.listener != null) {
- this.listener.onAddAdvancementRoot(advancementNode1);
+ this.listener.onAddAdvancementRoot(advancementnode1);
}
} else {
- this.tasks.add(advancementNode1);
+ this.tasks.add(advancementnode1);
if (this.listener != null) {
- this.listener.onAddAdvancementTask(advancementNode1);
+ this.listener.onAddAdvancementTask(advancementnode1);
}
}
@@ -100,6 +120,7 @@
if (this.listener != null) {
this.listener.onAdvancementsCleared();
}
+
}
public Iterable<AdvancementNode> roots() {
@@ -111,37 +132,47 @@
}
@Nullable
- public AdvancementNode get(ResourceLocation resourceLocation) {
- return this.nodes.get(resourceLocation);
+ public AdvancementNode get(ResourceLocation minecraftkey) {
+ return (AdvancementNode) this.nodes.get(minecraftkey);
}
@Nullable
- public AdvancementNode get(AdvancementHolder advancementHolder) {
- return this.nodes.get(advancementHolder.id());
+ public AdvancementNode get(AdvancementHolder advancementholder) {
+ return (AdvancementNode) this.nodes.get(advancementholder.id());
}
- public void setListener(@Nullable AdvancementTree.Listener listener) {
- this.listener = listener;
- if (listener != null) {
- for (AdvancementNode advancementNode : this.roots) {
- listener.onAddAdvancementRoot(advancementNode);
+ public void setListener(@Nullable AdvancementTree.a advancementtree_a) {
+ this.listener = advancementtree_a;
+ if (advancementtree_a != null) {
+ Iterator iterator = this.roots.iterator();
+
+ AdvancementNode advancementnode;
+
+ while (iterator.hasNext()) {
+ advancementnode = (AdvancementNode) iterator.next();
+ advancementtree_a.onAddAdvancementRoot(advancementnode);
}
- for (AdvancementNode advancementNode : this.tasks) {
- listener.onAddAdvancementTask(advancementNode);
+ iterator = this.tasks.iterator();
+
+ while (iterator.hasNext()) {
+ advancementnode = (AdvancementNode) iterator.next();
+ advancementtree_a.onAddAdvancementTask(advancementnode);
}
}
+
}
- public interface Listener {
- void onAddAdvancementRoot(AdvancementNode advancementNode);
+ public interface a {
- void onRemoveAdvancementRoot(AdvancementNode advancementNode);
+ void onAddAdvancementRoot(AdvancementNode advancementnode);
- void onAddAdvancementTask(AdvancementNode advancementNode);
+ void onRemoveAdvancementRoot(AdvancementNode advancementnode);
- void onRemoveAdvancementTask(AdvancementNode advancementNode);
+ void onAddAdvancementTask(AdvancementNode advancementnode);
+ void onRemoveAdvancementTask(AdvancementNode advancementnode);
+
void onAdvancementsCleared();
}
}
|