Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Commit

Permalink
Fixed texture issues for crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatsmusic99 committed Nov 4, 2018
1 parent 9e9e455 commit 253d75d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public ItemStack getSkull(String s) throws NoSuchFieldException, IllegalAccessEx
SkullMeta sm = (SkullMeta) i.getItemMeta();
GameProfile gm = new GameProfile(UUID.randomUUID(), "HPXHead");
if (getConfig().getBoolean("heads." + st + ".encode")) {
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", getConfig().getString(st + ".texture")).getBytes());
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", getTextures(s)).getBytes());
gm.getProperties().put("textures", new Property("texture", Arrays.toString(encodedData).replaceAll("=", "")));
} else {
gm.getProperties().put("textures", new Property("texture", getConfig().getString("heads." + st + ".texture").replaceAll("=", "")));
gm.getProperties().put("textures", new Property("texture", getTextures(s).replaceAll("=", "")));
}

Field profileField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;

import java.util.ArrayList;
Expand Down Expand Up @@ -76,6 +77,7 @@ private void addEnumToConfig() {
List<String> ingrs = new ArrayList<>();
for (String key2 : crafting.getStringList(key + "." + d.name() + ".ingredients")) {
try {

recipe.addIngredient(Material.getMaterial(key2));
ingrs.add(key2);
} catch (IllegalArgumentException e) {
Expand All @@ -86,7 +88,6 @@ private void addEnumToConfig() {
try {
Bukkit.addRecipe(recipe);
} catch (IllegalStateException e) {

}
}
}
Expand All @@ -97,29 +98,33 @@ private void addEnumToConfig() {
SkullMeta im = (SkullMeta) i.getItemMeta();


if (heads.getStringList(key + ".name").get(0).startsWith("HP#")) {
i = HeadsPlus.getInstance().getHeadsXConfig().getSkull(heads.getStringList(key + ".name").get(0));
im = (SkullMeta) i.getItemMeta();
} else {
im = nms.setSkullOwner(heads.getStringList(key + ".name").get(0), im);
}
i.setItemMeta(im);
SkullMeta ims = (SkullMeta) i.getItemMeta();
if (key.equalsIgnoreCase("sheep")) {
ims = nms.setSkullOwner(heads.getStringList(key + ".name.default").get(0), ims);

} else {
ims = nms.setSkullOwner(heads.getStringList(key + ".name").get(0), ims);
}
i.setItemMeta(ims);


im.setDisplayName(ChatColor.translateAlternateColorCodes('&', heads.getString(key + ".display-name")));
List<String> strs = new ArrayList<>();
for (String str : heads.getStringList(key + ".lore")) {
strs.add(ChatColor.translateAlternateColorCodes('&', str.replaceAll("\\{type}", key).replaceAll("\\{price}", String.valueOf(heads.getDouble(key + ".price")))));
}
im.setLore(strs);
i.setItemMeta(im);
if (heads.getStringList(key + ".name").get(0).startsWith("HP#")) {
i = HeadsPlus.getInstance().getHeadsXConfig().getSkull(heads.getStringList(key + ".name").get(0));
} else {
im = nms.setSkullOwner(heads.getStringList(key + ".name").get(0), im);
i.setItemMeta(im);
SkullMeta ims = (SkullMeta) i.getItemMeta();
if (key.equalsIgnoreCase("sheep")) {
ims = nms.setSkullOwner(heads.getStringList(key + ".name.default").get(0), ims);

} else {
ims = nms.setSkullOwner(heads.getStringList(key + ".name").get(0), ims);
}
i.setItemMeta(ims);
i.setItemMeta(im);
}
i = makeSell(i, key);

ShapelessRecipe recipe = nms.getRecipe(i, "hp" + key);
List<String> ingrs = new ArrayList<>();
for (String key2 : crafting.getStringList(key + ".ingredients")) {
Expand Down Expand Up @@ -154,24 +159,42 @@ private void addEnumToConfig() {
SkullMeta im = (SkullMeta) i.getItemMeta();
if (!(heads.getString(key + ".display-name").equals("")) && !(heads.getStringList(key + ".name").isEmpty())) {
hp.debug("Crafting head for " + key + "...", 3);
im.setDisplayName(ChatColor.translateAlternateColorCodes('&', heads.getString(key + ".display-name")));

im.setDisplayName(ChatColor.translateAlternateColorCodes('&', heads.getString(key + ".display-name")));
List<String> strs = new ArrayList<>();
for (String str : heads.getStringList(key + ".lore")) {
strs.add(ChatColor.translateAlternateColorCodes('&', str.replaceAll("\\{type}", key).replaceAll("\\{price}", String.valueOf(heads.getDouble(key + ".price")))));
}
im.setLore(strs);
i.setItemMeta(im);
if (heads.getStringList(key + ".name").get(0).startsWith("HP#")) {
i = HeadsPlus.getInstance().getHeadsXConfig().getSkull(heads.getStringList(key + ".name").get(0));
im = (SkullMeta) i.getItemMeta();
ItemMeta os = i.getItemMeta();
os.setDisplayName(ChatColor.translateAlternateColorCodes('&', heads.getString(key + ".display-name")));
List<String> strsz = new ArrayList<>();
for (String str : heads.getStringList(key + ".lore")) {
strsz.add(ChatColor.translateAlternateColorCodes('&', str.replaceAll("\\{type}", key).replaceAll("\\{price}", String.valueOf(heads.getDouble(key + ".price")))));
}
os.setLore(strsz);
i.setItemMeta(os);
} else {
im = nms.setSkullOwner(heads.getStringList(key + ".name").get(0), im);
}
i.setItemMeta(im);
SkullMeta ims;
ims = nms.setSkullOwner(heads.getStringList(key + ".name").get(0), im);
i.setItemMeta(im);
SkullMeta ims = (SkullMeta) i.getItemMeta();
if (key.equalsIgnoreCase("sheep")) {
ims = nms.setSkullOwner(heads.getStringList(key + ".name.default").get(0), ims);

i.setItemMeta(ims);
} else {
ims = nms.setSkullOwner(heads.getStringList(key + ".name").get(0), ims);
}
i.setItemMeta(ims);
i.setItemMeta(im);
}
i = makeSell(i, key);
ShapelessRecipe recipe = nms.getRecipe(i, "hp" + key);
List<String> ingrs = new ArrayList<>();
if (crafting.getStringList(key + "I") != null) {
ingrs = crafting.getStringList(key + "I");
if (crafting.getStringList(key + ".ingredients") != null) {
ingrs = crafting.getStringList(key + ".ingredients");
for (String key2 : ingrs) {
try {
recipe.addIngredient(Material.getMaterial(key2));
Expand All @@ -184,7 +207,7 @@ private void addEnumToConfig() {
recipe.addIngredient(nms.getSkull0());
}
} else {
crafting.addDefault(key + "I", ingrs);
crafting.addDefault(key + ".ingredients", ingrs);
}
if (ingrs.size() > 0) {
try {
Expand Down
2 changes: 1 addition & 1 deletion main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main: io.github.thatsmusic99.headsplus.HeadsPlus
name: HeadsPlus
version: 5.2
version: 5.2.1
api-version: 1.13
description: Spawns in heads with extra features.
author: Thatsmusic99
Expand Down

0 comments on commit 253d75d

Please sign in to comment.