Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42b2a857b0 |
No files matched your search
@@ -1,13 +1,12 @@
|
||||
package net.craftingstore.bukkit.inventory;
|
||||
|
||||
import net.craftingstore.bukkit.CraftingStoreBukkit;
|
||||
import net.craftingstore.bukkit.util.VersionUtil;
|
||||
import net.craftingstore.bukkit.util.XMaterial;
|
||||
import net.craftingstore.core.CraftingStore;
|
||||
import net.craftingstore.core.models.api.inventory.CraftingStoreInventory;
|
||||
import net.craftingstore.core.models.api.inventory.InventoryItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -55,6 +54,9 @@ public class InventoryBuilder {
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
if (VersionUtil.isCustomModalDataAvailable() && inventoryItem.getIcon().getCustomModelData() != null) {
|
||||
meta.setCustomModelData(inventoryItem.getIcon().getCustomModelData());
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
inventory.setItem(inventoryItem.getIndex(), itemStack);
|
||||
}
|
||||
|
||||
@@ -5,18 +5,9 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class ChatColorUtil {
|
||||
private static final Pattern HEX_PATTERN = Pattern.compile("&#(\\w{5}[0-9a-f])");
|
||||
private static boolean hasHexAvailable = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("net.md_5.bungee.api.ChatColor").getMethod("of", String.class);
|
||||
hasHexAvailable = true;
|
||||
} catch (NoSuchMethodException | ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static String translate(String textToTranslate) {
|
||||
if (hasHexAvailable) {
|
||||
if (VersionUtil.isHexAvailable()) {
|
||||
return translateHexCodes(textToTranslate);
|
||||
}
|
||||
return org.bukkit.ChatColor.translateAlternateColorCodes('&', textToTranslate);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.craftingstore.bukkit.util;
|
||||
|
||||
public class VersionUtil {
|
||||
private static boolean hexAvailable = false;
|
||||
private static boolean customModalDataAvailable = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("net.md_5.bungee.api.ChatColor").getMethod("of", String.class);
|
||||
hexAvailable = true;
|
||||
} catch (NoSuchMethodException | ClassNotFoundException ignored) {
|
||||
}
|
||||
try {
|
||||
Class.forName("org.bukkit.inventory.meta.ItemMeta").getMethod("hasCustomModelData");
|
||||
customModalDataAvailable = true;
|
||||
} catch (NoSuchMethodException | ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isHexAvailable() {
|
||||
return hexAvailable;
|
||||
}
|
||||
|
||||
public static boolean isCustomModalDataAvailable() {
|
||||
return customModalDataAvailable;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,6 @@ import org.apache.http.util.EntityUtils;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
+6
-1
@@ -2,7 +2,8 @@ package net.craftingstore.core.models.api.inventory;
|
||||
|
||||
public class InventoryItemIcon {
|
||||
private String material;
|
||||
private int amount;
|
||||
private Integer amount;
|
||||
private int customModelData;
|
||||
private InventoryItemEnhancement[] enhancements;
|
||||
|
||||
public String getMaterial() {
|
||||
@@ -13,6 +14,10 @@ public class InventoryItemIcon {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Integer getCustomModelData() {
|
||||
return customModelData;
|
||||
}
|
||||
|
||||
public InventoryItemEnhancement[] getEnhancements() {
|
||||
return enhancements;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user