下面列出了怎么用org.bukkit.advancement.Advancement的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public Advancement loadAdvancement(NamespacedKey key, String advancement) {
if (Bukkit.getAdvancement(key) != null) {
throw new IllegalArgumentException("Advancement " + key + " already exists.");
}
net.minecraft.advancements.Advancement.Builder nms = JsonUtils.gsonDeserialize(AdvancementManager.GSON, advancement, net.minecraft.advancements.Advancement.Builder.class);
if (nms != null) {
AdvancementManager.ADVANCEMENT_LIST.loadAdvancements(Maps.newHashMap(Collections.singletonMap(CraftNamespacedKey.toMinecraft(key), nms)));
Advancement bukkit = Bukkit.getAdvancement(key);
if (bukkit != null) {
File file = new File(MinecraftServer.getServerCB().getAdvancementManager().advancementsDir, key.getNamespace() + 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.getServerCB().getPlayerList().reloadResources();
return bukkit;
}
}
return null;
}
private void grant(NamespacedKey id, Player player) {
Advancement advancement = Bukkit.getAdvancement(id);
AdvancementProgress progress = player.getAdvancementProgress(advancement);
if (!progress.isDone()) {
for (String criteria : progress.getRemainingCriteria()) {
progress.awardCriteria(criteria);
}
}
}
private void revoke(NamespacedKey id, Player player) {
Advancement advancement = Bukkit.getAdvancement(id);
AdvancementProgress progress = player.getAdvancementProgress(advancement);
if (progress.isDone()) {
for (String criteria : progress.getRemainingCriteria()) {
progress.revokeCriteria(criteria);
}
}
}
public PlayerAdvancementDoneEvent(Player who, Advancement advancement) {
super(who);
this.advancement = advancement;
}
@Override
public Advancement getAdvancement() {
return advancement;
}
public PlayerAdvancementCriterionGrantEvent(Player who, Advancement advancement, String criterion) {
super(who);
this.advancement = advancement;
this.criterion = criterion;
}
/** Argument implementations with CommandSyntaxExceptions */
Advancement getAdvancement(CommandContext<?> cmdCtx, String key) throws CommandSyntaxException;
@Override
public Class<?> getPrimitiveType() {
return Advancement.class;
}
@Override
public Advancement getAdvancement(NamespacedKey key) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Iterator<Advancement> advancementIterator() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Advancement getAdvancement(NamespacedKey namespacedKey) {
return null;
}
@Override
public Iterator<Advancement> advancementIterator() {
return null;
}
/**
* Return the player's progression on the specified advancement.
*
* @param advancement advancement
* @return object detailing the player's progress
*/
public AdvancementProgress getAdvancementProgress(Advancement advancement);
/**
* Get the advancement specified by this key.
*
* @param key unique advancement key
* @return advancement or null if not exists
*/
Advancement getAdvancement(NamespacedKey key);
/**
* Get an iterator through all advancements. Advancements cannot be removed
* from this iterator,
*
* @return an advancement iterator
*/
Iterator<Advancement> advancementIterator();
/**
* Get the advancement which has been completed.
*
* @return completed advancement
*/
public Advancement getAdvancement() {
return advancement;
}
/**
* Load an advancement represented by the specified string into the server.
* The advancement format is governed by Minecraft and has no specified
* layout.
* <br>
* It is currently a JSON object, as described by the Minecraft Wiki:
* http://minecraft.gamepedia.com/Advancements
* <br>
* Loaded advancements will be stored and persisted across server restarts
* and reloads.
* <br>
* Callers should be prepared for {@link Exception} to be thrown.
*
* @param key the unique advancement key
* @param advancement representation of the advancement
* @return the loaded advancement or null if an error occurred
*/
Advancement loadAdvancement(NamespacedKey key, String advancement);
/**
* Get the advancement specified by this key.
*
* @param key unique advancement key
* @return advancement or null if not exists
*/
public static Advancement getAdvancement(NamespacedKey key) {
return server.getAdvancement(key);
}
/**
* Get an iterator through all advancements. Advancements cannot be removed
* from this iterator,
*
* @return an advancement iterator
*/
public static Iterator<Advancement> advancementIterator() {
return server.advancementIterator();
}
/**
* Get the advancement which has been affected.
*
* @return affected advancement
*/
public Advancement getAdvancement() {
return advancement;
}