Skip to content

Commit

Permalink
Add SkullMetaProvider API
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Feb 5, 2019
1 parent 937d542 commit 2c19c8a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/net/citizensnpcs/api/CitizensAPI.java
Expand Up @@ -120,6 +120,10 @@ public static File getScriptFolder() {
return getImplementation().getScriptFolder();
}

public static SkullMetaProvider getSkullMetaProvider() {
return instance.getSkullMetaProvider();
}

/**
* Gets the current implementation's {@link SpeechFactory}.
*
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/citizensnpcs/api/CitizensPlugin.java
Expand Up @@ -53,6 +53,8 @@ public interface CitizensPlugin extends Plugin {
*/
public File getScriptFolder();

public SkullMetaProvider getSkullMetaProvider();

/**
* Gets the SpeechFactory.
*
Expand All @@ -79,7 +81,7 @@ public interface CitizensPlugin extends Plugin {

/**
* Sets the default NPC data store. Should be set during onEnable.
*
*
* @param The
* new default store
*/
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/citizensnpcs/api/SkullMetaProvider.java
@@ -0,0 +1,9 @@
package net.citizensnpcs.api;

import org.bukkit.inventory.meta.SkullMeta;

public interface SkullMetaProvider {
public String getTexture(SkullMeta meta);

public void setTexture(String string, SkullMeta meta);
}
5 changes: 5 additions & 0 deletions src/main/java/net/citizensnpcs/api/util/ItemStorage.java
Expand Up @@ -35,6 +35,7 @@

import com.google.common.collect.Lists;

import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.CitizensDeserialiseMetaEvent;
import net.citizensnpcs.api.event.CitizensSerialiseMetaEvent;

Expand Down Expand Up @@ -164,6 +165,9 @@ private static void deserialiseMeta(DataKey root, ItemStack res) {
if (root.keyExists("skull.owner") && !root.getString("skull.owner").isEmpty()) {
meta.setOwner(root.getString("skull.owner", ""));
}
if (root.keyExists("skull.texture") && !root.getString("skull.texture").isEmpty()) {
CitizensAPI.getSkullMetaProvider().setTexture(root.getString("skull.texture", ""), meta);
}
res.setItemMeta(meta);
}

Expand Down Expand Up @@ -371,6 +375,7 @@ private static void serialiseMeta(DataKey key, ItemMeta meta) {

if (meta instanceof SkullMeta) {
SkullMeta skull = (SkullMeta) meta;
key.setString("skull.texture", CitizensAPI.getSkullMetaProvider().getTexture(skull));
key.setString("skull.owner", skull.getOwner());
} else {
key.removeKey("skull");
Expand Down

0 comments on commit 2c19c8a

Please sign in to comment.