mirror of
https://github.com/Zrips/Jobs.git
synced 2025-02-01 04:51:26 +01:00
Adds an Item field to GUI
Adds the ability to add the item name instead of using id and data. (Please test this before pulling to verify its functionality) Resolves #233
This commit is contained in:
parent
a3166976df
commit
e764cdd436
@ -546,42 +546,106 @@ public class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gui item
|
// Gui item
|
||||||
ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack();
|
ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack();
|
||||||
if (jobSection.contains("Gui")) {
|
if (jobSection.contains("Gui")) {
|
||||||
ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui");
|
ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui");
|
||||||
if (guiSection.contains("Id") && guiSection.contains("Data") && guiSection.isInt("Id") && guiSection.isInt("Data")) {
|
if (guiSection.contains("Item") && guiSection.isString("Item")) {
|
||||||
GUIitem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack();
|
String item = guiSection.getString("Item");
|
||||||
if (guiSection.contains("Enchantments")) {
|
String type = null;
|
||||||
List<String> enchants = guiSection.getStringList("Enchantments");
|
String subType = "";
|
||||||
if (enchants.size() > 0) {
|
String meta = "";
|
||||||
for (String str4 : enchants) {
|
int id = 0;
|
||||||
String[] id = str4.split(":");
|
|
||||||
if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) {
|
if (item.contains("-")) {
|
||||||
EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta();
|
// uses subType
|
||||||
enchantMeta.addStoredEnchant(Enchantment.getByName(id[0]), Integer.parseInt(id[1]), true);
|
subType = ":" + item.split("-")[1];
|
||||||
GUIitem.setItemMeta(enchantMeta);
|
meta = item.split("-")[1];
|
||||||
} else {
|
item = item.split("-")[0];
|
||||||
GUIitem.addUnsafeEnchantment(Enchantment.getByName(id[0]), Integer.parseInt(id[1]));
|
}
|
||||||
}
|
|
||||||
}
|
CMIMaterial material = CMIMaterial.get(item + (subType));
|
||||||
}
|
|
||||||
}
|
if (material == null) material = CMIMaterial.get(item.replace(" ", "_").toUpperCase());
|
||||||
} else if (guiSection.contains("CustomSkull")) {
|
|
||||||
String skullOwner = guiSection.getString("CustomSkull");
|
if (material == null) {
|
||||||
GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack();
|
// try integer method
|
||||||
SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta();
|
Integer matId = null;
|
||||||
if (skullOwner.length() == 36) {
|
try {
|
||||||
try {
|
matId = Integer.valueOf(item);
|
||||||
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner));
|
} catch (NumberFormatException e) {
|
||||||
skullMeta.setOwner(offPlayer.getName());
|
}
|
||||||
} catch (Exception e) {
|
if (matId != null) {
|
||||||
}
|
material = CMIMaterial.get(matId);
|
||||||
} else
|
if (material != null) {
|
||||||
skullMeta.setOwner(skullOwner);
|
Jobs.getPluginLogger()
|
||||||
GUIitem.setItemMeta(skullMeta);
|
.warning("Job " + jobName + " is using GUI item ID: " + item + "!");
|
||||||
} else
|
Jobs.getPluginLogger()
|
||||||
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!");
|
.warning("Please use the Material name instead: " + material.toString() + "!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GUIitem = material.newItemStack();
|
||||||
|
if (guiSection.contains("Enchantments")) {
|
||||||
|
List<String> enchants = guiSection.getStringList("Enchantments");
|
||||||
|
if (enchants.size() > 0) {
|
||||||
|
for (String str4 : enchants) {
|
||||||
|
String[] enchantid = str4.split(":");
|
||||||
|
if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) {
|
||||||
|
EnchantmentStorageMeta enchantMeta =
|
||||||
|
(EnchantmentStorageMeta) GUIitem.getItemMeta();
|
||||||
|
enchantMeta.addStoredEnchant(
|
||||||
|
Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]), true);
|
||||||
|
GUIitem.setItemMeta(enchantMeta);
|
||||||
|
} else {
|
||||||
|
GUIitem.addUnsafeEnchantment(
|
||||||
|
Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (guiSection.contains("Id")
|
||||||
|
&& guiSection.contains("Data")
|
||||||
|
&& guiSection.isInt("Id")
|
||||||
|
&& guiSection.isInt("Data")) {
|
||||||
|
GUIitem =
|
||||||
|
CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack();
|
||||||
|
if (guiSection.contains("Enchantments")) {
|
||||||
|
List<String> enchants = guiSection.getStringList("Enchantments");
|
||||||
|
if (enchants.size() > 0) {
|
||||||
|
for (String str4 : enchants) {
|
||||||
|
String[] id = str4.split(":");
|
||||||
|
if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) {
|
||||||
|
EnchantmentStorageMeta enchantMeta =
|
||||||
|
(EnchantmentStorageMeta) GUIitem.getItemMeta();
|
||||||
|
enchantMeta.addStoredEnchant(
|
||||||
|
Enchantment.getByName(id[0]), Integer.parseInt(id[1]), true);
|
||||||
|
GUIitem.setItemMeta(enchantMeta);
|
||||||
|
} else {
|
||||||
|
GUIitem.addUnsafeEnchantment(
|
||||||
|
Enchantment.getByName(id[0]), Integer.parseInt(id[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (guiSection.contains("CustomSkull")) {
|
||||||
|
String skullOwner = guiSection.getString("CustomSkull");
|
||||||
|
GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack();
|
||||||
|
SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta();
|
||||||
|
if (skullOwner.length() == 36) {
|
||||||
|
try {
|
||||||
|
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner));
|
||||||
|
skullMeta.setOwner(offPlayer.getName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
} else skullMeta.setOwner(skullOwner);
|
||||||
|
GUIitem.setItemMeta(skullMeta);
|
||||||
|
} else
|
||||||
|
Jobs.getPluginLogger()
|
||||||
|
.warning(
|
||||||
|
"Job "
|
||||||
|
+ jobKey
|
||||||
|
+ " has an invalid Gui property. Please fix this if you want to use it!");
|
||||||
|
}
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
ArrayList<JobPermission> jobPermissions = new ArrayList<>();
|
ArrayList<JobPermission> jobPermissions = new ArrayList<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user