1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Update ConfigManager.java

This commit is contained in:
montlikadani 2018-10-08 16:46:52 +02:00 committed by GitHub
parent e764cdd436
commit fa0c45dc1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -545,107 +545,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("Item") && guiSection.isString("Item")) { if (guiSection.contains("Item") && guiSection.isString("Item")) {
String item = guiSection.getString("Item"); String item = guiSection.getString("Item");
String type = null; String subType = "";
String subType = ""; @SuppressWarnings("unused")
String meta = ""; String meta = "";
int id = 0;
if (item.contains("-")) { if (item.contains("-")) {
// uses subType // uses subType
subType = ":" + item.split("-")[1]; subType = ":" + item.split("-")[1];
meta = item.split("-")[1]; meta = item.split("-")[1];
item = item.split("-")[0]; item = item.split("-")[0];
} }
CMIMaterial material = CMIMaterial.get(item + (subType)); CMIMaterial material = CMIMaterial.get(item + (subType));
if (material == null) material = CMIMaterial.get(item.replace(" ", "_").toUpperCase()); if (material == null)
material = CMIMaterial.get(item.replace(" ", "_").toUpperCase());
if (material == null) { if (material == null) {
// try integer method // try integer method
Integer matId = null; Integer matId = null;
try { try {
matId = Integer.valueOf(item); matId = Integer.valueOf(item);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
if (matId != null) { if (matId != null) {
material = CMIMaterial.get(matId); material = CMIMaterial.get(matId);
if (material != null) { if (material != null) {
Jobs.getPluginLogger() Jobs.getPluginLogger().warning("Job " + jobName + " is using GUI item ID: " + item + "!");
.warning("Job " + jobName + " is using GUI item ID: " + item + "!"); Jobs.getPluginLogger().warning("Please use the Material name instead: " + material.toString() + "!");
Jobs.getPluginLogger() }
.warning("Please use the Material name instead: " + material.toString() + "!"); }
} }
} GUIitem = material.newItemStack();
} if (guiSection.contains("Enchantments")) {
GUIitem = material.newItemStack(); List<String> enchants = guiSection.getStringList("Enchantments");
if (guiSection.contains("Enchantments")) { if (enchants.size() > 0) {
List<String> enchants = guiSection.getStringList("Enchantments"); for (String str4 : enchants) {
if (enchants.size() > 0) { String[] enchantid = str4.split(":");
for (String str4 : enchants) { if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) {
String[] enchantid = str4.split(":"); EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta();
if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { enchantMeta.addStoredEnchant(Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]), true);
EnchantmentStorageMeta enchantMeta = GUIitem.setItemMeta(enchantMeta);
(EnchantmentStorageMeta) GUIitem.getItemMeta(); } else {
enchantMeta.addStoredEnchant( GUIitem.addUnsafeEnchantment(Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]));
Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]), true); }
GUIitem.setItemMeta(enchantMeta); }
} else { }
GUIitem.addUnsafeEnchantment( } else if (guiSection.contains("CustomSkull")) {
Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1])); String skullOwner = guiSection.getString("CustomSkull");
} GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack();
} SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta();
} if (skullOwner.length() == 36) {
} try {
} else if (guiSection.contains("Id") OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner));
&& guiSection.contains("Data") skullMeta.setOwner(offPlayer.getName());
&& guiSection.isInt("Id") } catch (Exception e) {
&& guiSection.isInt("Data")) { }
GUIitem = } else
CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack(); skullMeta.setOwner(skullOwner);
if (guiSection.contains("Enchantments")) { GUIitem.setItemMeta(skullMeta);
List<String> enchants = guiSection.getStringList("Enchantments"); } else
if (enchants.size() > 0) { Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!");
for (String str4 : enchants) { } else if (guiSection.contains("Id") && guiSection.contains("Data") && guiSection.isInt("Id") && guiSection.isInt("Data")) {
String[] id = str4.split(":"); GUIitem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack();
if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { if (guiSection.contains("Enchantments")) {
EnchantmentStorageMeta enchantMeta = List<String> enchants = guiSection.getStringList("Enchantments");
(EnchantmentStorageMeta) GUIitem.getItemMeta(); if (enchants.size() > 0) {
enchantMeta.addStoredEnchant( for (String str4 : enchants) {
Enchantment.getByName(id[0]), Integer.parseInt(id[1]), true); String[] id = str4.split(":");
GUIitem.setItemMeta(enchantMeta); if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) {
} else { EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta();
GUIitem.addUnsafeEnchantment( enchantMeta.addStoredEnchant(Enchantment.getByName(id[0]), Integer.parseInt(id[1]), true);
Enchantment.getByName(id[0]), Integer.parseInt(id[1])); GUIitem.setItemMeta(enchantMeta);
} } else {
} GUIitem.addUnsafeEnchantment(Enchantment.getByName(id[0]), Integer.parseInt(id[1]));
} }
} }
} else if (guiSection.contains("CustomSkull")) { }
String skullOwner = guiSection.getString("CustomSkull"); } else if (guiSection.contains("CustomSkull")) {
GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack(); String skullOwner = guiSection.getString("CustomSkull");
SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta(); GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack();
if (skullOwner.length() == 36) { SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta();
try { if (skullOwner.length() == 36) {
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner)); try {
skullMeta.setOwner(offPlayer.getName()); OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner));
} catch (Exception e) { skullMeta.setOwner(offPlayer.getName());
} } catch (Exception e) {
} else skullMeta.setOwner(skullOwner); }
GUIitem.setItemMeta(skullMeta); } else
} else skullMeta.setOwner(skullOwner);
Jobs.getPluginLogger() GUIitem.setItemMeta(skullMeta);
.warning( } else
"Job " Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!");
+ 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<>();