use of net.minecraft.advancements.critereon.DeserializationContext in project Mohist by MohistMC.
the class CraftMagicNumbers method loadAdvancement.
@Override
public Advancement loadAdvancement(NamespacedKey key, String advancement) {
if (Bukkit.getAdvancement(key) != null) {
throw new IllegalArgumentException("Advancement " + key + " already exists.");
}
ResourceLocation minecraftkey = CraftNamespacedKey.toMinecraft(key);
JsonElement jsonelement = ServerAdvancementManager.GSON.fromJson(advancement, JsonElement.class);
JsonObject jsonobject = GsonHelper.convertToJsonObject(jsonelement, "advancement");
net.minecraft.advancements.Advancement.Builder nms = net.minecraft.advancements.Advancement.Builder.fromJson(jsonobject, new DeserializationContext(minecraftkey, MinecraftServer.getServer().getPredicateManager()));
if (nms != null) {
MinecraftServer.getServer().getAdvancements().advancements.add(Maps.newHashMap(Collections.singletonMap(minecraftkey, nms)));
Advancement bukkit = Bukkit.getAdvancement(key);
if (bukkit != null) {
File file = new File(getBukkitDataPackFolder(), "data" + File.separator + key.getNamespace() + File.separator + "advancements" + File.separator + key.getKey() + ".json");
file.getParentFile().mkdirs();
try {
Files.write(advancement, file, Charsets.UTF_8);
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error saving advancement " + key, ex);
}
MinecraftServer.getServer().getPlayerList().reloadResources();
return bukkit;
}
}
return null;
}
use of net.minecraft.advancements.critereon.DeserializationContext in project blueprint by team-abnormals.
the class AdvancementModificationManager method apply.
@Override
protected void apply(Map<ResourceLocation, JsonElement> map, ResourceManager resourceManager, ProfilerFiller profiler) {
this.reset();
SelectionSpace unmodifiedAdvancements = this.getUnmodifiedEntries();
for (Map.Entry<ResourceLocation, JsonElement> entry : map.entrySet()) {
ResourceLocation resourcelocation = entry.getKey();
if (resourcelocation.getPath().startsWith("_"))
continue;
try {
TargetedModifier<Builder, Void, DeserializationContext> targetedAdvancementModifier = TargetedModifier.deserialize(entry.getValue().getAsJsonObject(), "advancement", new DeserializationContext(resourcelocation, this.lootPredicateManager), AdvancementModifiers.REGISTRY, true);
this.addModifiers(targetedAdvancementModifier.getTargetSelector().getTargetNames(unmodifiedAdvancements), targetedAdvancementModifier.getPriority(), targetedAdvancementModifier.getConfiguredModifiers());
} catch (IllegalArgumentException | JsonParseException jsonparseexception) {
Blueprint.LOGGER.error("Parsing error loading Advancement Modifier: {}", resourcelocation, jsonparseexception);
}
}
Blueprint.LOGGER.info("Advancement Modification Manager has assigned {} sets of modifiers", this.size());
}
Aggregations