Commits
md_5 authored 53dcd96fa1e
1 - | From 9bf39c34a7e12f71873947bb676ed9d1694ad135 Mon Sep 17 00:00:00 2001 |
1 + | From bf072df2a80134a71b9ce0e317f1670fe897da3c Mon Sep 17 00:00:00 2001 |
2 2 | From: md_5 <md_5@live.com.au> |
3 3 | Date: Sun, 1 Dec 2013 15:10:48 +1100 |
4 4 | Subject: [PATCH] mc-dev imports |
5 5 | |
6 6 | Imported files which are only modified by Spigot, not upstream. Files here should be completely unmodified aside from trivial changes such as adding throws statements to ensure proper compilation. You may need to add unrelated files in order to ensure a compilable result in the face of synthetic methods. |
7 7 | |
8 + | diff --git a/src/main/java/net/minecraft/server/AdvancementDataWorld.java b/src/main/java/net/minecraft/server/AdvancementDataWorld.java |
9 + | new file mode 100644 |
10 + | index 000000000..5ae0609d8 |
11 + | --- /dev/null |
12 + | +++ b/src/main/java/net/minecraft/server/AdvancementDataWorld.java |
13 + | |
14 + | +package net.minecraft.server; |
15 + | + |
16 + | +import com.google.common.collect.Maps; |
17 + | +import com.google.gson.Gson; |
18 + | +import com.google.gson.GsonBuilder; |
19 + | +import com.google.gson.JsonDeserializationContext; |
20 + | +import com.google.gson.JsonDeserializer; |
21 + | +import com.google.gson.JsonElement; |
22 + | +import com.google.gson.JsonObject; |
23 + | +import com.google.gson.JsonParseException; |
24 + | +import java.io.BufferedReader; |
25 + | +import java.io.File; |
26 + | +import java.io.IOException; |
27 + | +import java.io.Reader; |
28 + | +import java.lang.reflect.Type; |
29 + | +import java.net.URI; |
30 + | +import java.net.URISyntaxException; |
31 + | +import java.net.URL; |
32 + | +import java.nio.charset.StandardCharsets; |
33 + | +import java.nio.file.FileSystem; |
34 + | +import java.nio.file.FileSystems; |
35 + | +import java.nio.file.FileVisitOption; |
36 + | +import java.nio.file.Files; |
37 + | +import java.nio.file.Paths; |
38 + | +import java.util.Collections; |
39 + | +import java.util.HashMap; |
40 + | +import java.util.Iterator; |
41 + | +import java.util.Map; |
42 + | +import javax.annotation.Nullable; |
43 + | +import org.apache.commons.io.FileUtils; |
44 + | +import org.apache.commons.io.FilenameUtils; |
45 + | +import org.apache.commons.io.IOUtils; |
46 + | +import org.apache.logging.log4j.LogManager; |
47 + | +import org.apache.logging.log4j.Logger; |
48 + | + |
49 + | +public class AdvancementDataWorld { |
50 + | + |
51 + | + private static final Logger a = LogManager.getLogger(); |
52 + | + public static final Gson DESERIALIZER = (new GsonBuilder()).registerTypeHierarchyAdapter(Advancement.SerializedAdvancement.class, new JsonDeserializer() { |
53 + | + public Advancement.SerializedAdvancement a(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) throws JsonParseException { |
54 + | + JsonObject jsonobject = ChatDeserializer.m(jsonelement, "advancement"); |
55 + | + |
56 + | + return Advancement.SerializedAdvancement.a(jsonobject, jsondeserializationcontext); |
57 + | + } |
58 + | + |
59 + | + public Object deserialize(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) throws JsonParseException { |
60 + | + return this.a(jsonelement, type, jsondeserializationcontext); |
61 + | + } |
62 + | + }).registerTypeAdapter(AdvancementRewards.class, new AdvancementRewards.a()).registerTypeHierarchyAdapter(IChatBaseComponent.class, new IChatBaseComponent.ChatSerializer()).registerTypeHierarchyAdapter(ChatModifier.class, new ChatModifier.ChatModifierSerializer()).registerTypeAdapterFactory(new ChatTypeAdapterFactory()).create(); |
63 + | + public static final Advancements REGISTRY = new Advancements(); |
64 + | + public final File folder; |
65 + | + private boolean e; |
66 + | + |
67 + | + public AdvancementDataWorld(@Nullable File file) { |
68 + | + this.folder = file; |
69 + | + this.reload(); |
70 + | + } |
71 + | + |
72 + | + public void reload() { |
73 + | + this.e = false; |
74 + | + AdvancementDataWorld.REGISTRY.a(); |
75 + | + Map map = this.d(); |
76 + | + |
77 + | + this.a(map); |
78 + | + AdvancementDataWorld.REGISTRY.a(map); |
79 + | + Iterator iterator = AdvancementDataWorld.REGISTRY.b().iterator(); |
80 + | + |
81 + | + while (iterator.hasNext()) { |
82 + | + Advancement advancement = (Advancement) iterator.next(); |
83 + | + |
84 + | + if (advancement.c() != null) { |
85 + | + AdvancementTree.a(advancement); |
86 + | + } |
87 + | + } |
88 + | + |
89 + | + } |
90 + | + |
91 + | + public boolean b() { |
92 + | + return this.e; |
93 + | + } |
94 + | + |
95 + | + private Map<MinecraftKey, Advancement.SerializedAdvancement> d() { |
96 + | + if (this.folder == null) { |
97 + | + return Maps.newHashMap(); |
98 + | + } else { |
99 + | + HashMap hashmap = Maps.newHashMap(); |
100 + | + |
101 + | + this.folder.mkdirs(); |
102 + | + Iterator iterator = FileUtils.listFiles(this.folder, new String[] { "json"}, true).iterator(); |
103 + | + |
104 + | + while (iterator.hasNext()) { |
105 + | + File file = (File) iterator.next(); |
106 + | + String s = FilenameUtils.removeExtension(this.folder.toURI().relativize(file.toURI()).toString()); |
107 + | + String[] astring = s.split("/", 2); |
108 + | + |
109 + | + if (astring.length == 2) { |
110 + | + MinecraftKey minecraftkey = new MinecraftKey(astring[0], astring[1]); |
111 + | + |
112 + | + try { |
113 + | + Advancement.SerializedAdvancement advancement_serializedadvancement = (Advancement.SerializedAdvancement) ChatDeserializer.a(AdvancementDataWorld.DESERIALIZER, FileUtils.readFileToString(file, StandardCharsets.UTF_8), Advancement.SerializedAdvancement.class); |
114 + | + |
115 + | + if (advancement_serializedadvancement == null) { |
116 + | + AdvancementDataWorld.a.error("Couldn\'t load custom advancement " + minecraftkey + " from " + file + " as it\'s empty or null"); |
117 + | + } else { |
118 + | + hashmap.put(minecraftkey, advancement_serializedadvancement); |
119 + | + } |
120 + | + } catch (IllegalArgumentException | JsonParseException jsonparseexception) { |
121 + | + AdvancementDataWorld.a.error("Parsing error loading custom advancement " + minecraftkey, jsonparseexception); |
122 + | + this.e = true; |
123 + | + } catch (IOException ioexception) { |
124 + | + AdvancementDataWorld.a.error("Couldn\'t read custom advancement " + minecraftkey + " from " + file, ioexception); |
125 + | + this.e = true; |
126 + | + } |
127 + | + } |
128 + | + } |
129 + | + |
130 + | + return hashmap; |
131 + | + } |
132 + | + } |
133 + | + |
134 + | + private void a(Map<MinecraftKey, Advancement.SerializedAdvancement> map) { |
135 + | + FileSystem filesystem = null; |
136 + | + |
137 + | + try { |
138 + | + URL url = AdvancementDataWorld.class.getResource("/assets/.mcassetsroot"); |
139 + | + |
140 + | + if (url == null) { |
141 + | + AdvancementDataWorld.a.error("Couldn\'t find .mcassetsroot"); |
142 + | + this.e = true; |
143 + | + } else { |
144 + | + URI uri = url.toURI(); |
145 + | + java.nio.file.Path java_nio_file_path; |
146 + | + |
147 + | + if ("file".equals(uri.getScheme())) { |
148 + | + java_nio_file_path = Paths.get(CraftingManager.class.getResource("/assets/minecraft/advancements").toURI()); |
149 + | + } else { |
150 + | + if (!"jar".equals(uri.getScheme())) { |
151 + | + AdvancementDataWorld.a.error("Unsupported scheme " + uri + " trying to list all built-in advancements (NYI?)"); |
152 + | + this.e = true; |
153 + | + return; |
154 + | + } |
155 + | + |
156 + | + filesystem = FileSystems.newFileSystem(uri, Collections.emptyMap()); |
157 + | + java_nio_file_path = filesystem.getPath("/assets/minecraft/advancements", new String[0]); |
158 + | + } |
159 + | + |
160 + | + Iterator iterator = Files.walk(java_nio_file_path, new FileVisitOption[0]).iterator(); |
161 + | + |
162 + | + while (iterator.hasNext()) { |
163 + | + java.nio.file.Path java_nio_file_path1 = (java.nio.file.Path) iterator.next(); |
164 + | + |
165 + | + if ("json".equals(FilenameUtils.getExtension(java_nio_file_path1.toString()))) { |
166 + | + java.nio.file.Path java_nio_file_path2 = java_nio_file_path.relativize(java_nio_file_path1); |
167 + | + String s = FilenameUtils.removeExtension(java_nio_file_path2.toString()).replaceAll("\\\\", "/"); |
168 + | + MinecraftKey minecraftkey = new MinecraftKey("minecraft", s); |
169 + | + |
170 + | + if (!map.containsKey(minecraftkey)) { |
171 + | + BufferedReader bufferedreader = null; |
172 + | + |
173 + | + try { |
174 + | + bufferedreader = Files.newBufferedReader(java_nio_file_path1); |
175 + | + Advancement.SerializedAdvancement advancement_serializedadvancement = (Advancement.SerializedAdvancement) ChatDeserializer.a(AdvancementDataWorld.DESERIALIZER, (Reader) bufferedreader, Advancement.SerializedAdvancement.class); |
176 + | + |
177 + | + map.put(minecraftkey, advancement_serializedadvancement); |
178 + | + } catch (JsonParseException jsonparseexception) { |
179 + | + AdvancementDataWorld.a.error("Parsing error loading built-in advancement " + minecraftkey, jsonparseexception); |
180 + | + this.e = true; |
181 + | + } catch (IOException ioexception) { |
182 + | + AdvancementDataWorld.a.error("Couldn\'t read advancement " + minecraftkey + " from " + java_nio_file_path1, ioexception); |
183 + | + this.e = true; |
184 + | + } finally { |
185 + | + IOUtils.closeQuietly(bufferedreader); |
186 + | + } |
187 + | + } |
188 + | + } |
189 + | + } |
190 + | + |
191 + | + } |
192 + | + } catch (IOException | URISyntaxException urisyntaxexception) { |
193 + | + AdvancementDataWorld.a.error("Couldn\'t get a list of all built-in advancement files", urisyntaxexception); |
194 + | + this.e = true; |
195 + | + } finally { |
196 + | + IOUtils.closeQuietly(filesystem); |
197 + | + } |
198 + | + } |
199 + | + |
200 + | + @Nullable |
201 + | + public Advancement a(MinecraftKey minecraftkey) { |
202 + | + return AdvancementDataWorld.REGISTRY.a(minecraftkey); |
203 + | + } |
204 + | + |
205 + | + public Iterable<Advancement> c() { |
206 + | + return AdvancementDataWorld.REGISTRY.c(); |
207 + | + } |
208 + | +} |
8 209 | diff --git a/src/main/java/net/minecraft/server/AttributeRanged.java b/src/main/java/net/minecraft/server/AttributeRanged.java |
9 210 | new file mode 100644 |
10 211 | index 000000000..130597c6e |
11 212 | --- /dev/null |
12 213 | +++ b/src/main/java/net/minecraft/server/AttributeRanged.java |
13 214 | |
14 215 | +package net.minecraft.server; |
15 216 | + |
16 217 | +import javax.annotation.Nullable; |
17 218 | + |