mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Lets check for possible null
This commit is contained in:
parent
804933a294
commit
8601b24ed0
@ -169,7 +169,7 @@ public class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public KeyValues getKeyValue(String myKey, ActionType actionType, String jobName) {
|
public KeyValues getKeyValue(String myKey, ActionType actionType, String jobName) {
|
||||||
|
|
||||||
String type = null;
|
String type = null;
|
||||||
String subType = "";
|
String subType = "";
|
||||||
@ -343,10 +343,10 @@ public class ConfigManager {
|
|||||||
} else if (actionType == ActionType.CRAFT && myKey.startsWith("!")) {
|
} else if (actionType == ActionType.CRAFT && myKey.startsWith("!")) {
|
||||||
type = myKey.substring(1, myKey.length());
|
type = myKey.substring(1, myKey.length());
|
||||||
} else if (actionType == ActionType.DRINK) {
|
} else if (actionType == ActionType.DRINK) {
|
||||||
type = myKey;
|
type = myKey;
|
||||||
PotionType potion = PotionType.valueOf(myKey);
|
PotionType potion = PotionType.valueOf(myKey);
|
||||||
if (potion != null)
|
if (potion != null)
|
||||||
type = potion.name().toUpperCase().replace("_", "").toLowerCase();
|
type = potion.name().toUpperCase().replace("_", "").toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
@ -424,22 +424,22 @@ public class ConfigManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxLevel = jobSection.getInt("max-level", 0);
|
int maxLevel = jobSection.getInt("max-level", 0);
|
||||||
if (jobSection.isInt("max-level") || maxLevel < 0)
|
if (jobSection.isInt("max-level") || maxLevel < 0)
|
||||||
maxLevel = 0;
|
maxLevel = 0;
|
||||||
|
|
||||||
int vipmaxLevel = jobSection.getInt("vip-max-level", 0);
|
int vipmaxLevel = jobSection.getInt("vip-max-level", 0);
|
||||||
if (jobSection.isInt("vip-max-level") || vipmaxLevel < 0)
|
if (jobSection.isInt("vip-max-level") || vipmaxLevel < 0)
|
||||||
vipmaxLevel = 0;
|
vipmaxLevel = 0;
|
||||||
|
|
||||||
Integer maxSlots = jobSection.getInt("slots", 0);
|
Integer maxSlots = jobSection.getInt("slots", 0);
|
||||||
if (jobSection.isInt("slots") || maxSlots.intValue() <= 0)
|
if (jobSection.isInt("slots") || maxSlots.intValue() <= 0)
|
||||||
maxSlots = null;
|
maxSlots = null;
|
||||||
|
|
||||||
Long rejoinCd = jobSection.getLong("rejoinCooldown", 0L);
|
Long rejoinCd = jobSection.getLong("rejoinCooldown", 0L);
|
||||||
if (jobSection.isLong("rejoinCooldown") || rejoinCd < 0L)
|
if (jobSection.isLong("rejoinCooldown") || rejoinCd < 0L)
|
||||||
rejoinCd = 0L;
|
rejoinCd = 0L;
|
||||||
rejoinCd = rejoinCd * 1000L;
|
rejoinCd = rejoinCd * 1000L;
|
||||||
|
|
||||||
String jobShortName = jobSection.getString("shortname", null);
|
String jobShortName = jobSection.getString("shortname", null);
|
||||||
if (jobShortName == null) {
|
if (jobShortName == null) {
|
||||||
@ -543,105 +543,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 subType = "";
|
String subType = "";
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
String meta = "";
|
String meta = "";
|
||||||
|
|
||||||
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)
|
if (material == null)
|
||||||
material = CMIMaterial.get(item.replace(" ", "_").toUpperCase());
|
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().warning("Job " + jobName + " is using GUI item ID: " + item + "!");
|
Jobs.getPluginLogger().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 (material != null)
|
||||||
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 = (EnchantmentStorageMeta) GUIitem.getItemMeta();
|
||||||
GUIitem.setItemMeta(enchantMeta);
|
enchantMeta.addStoredEnchant(Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]), true);
|
||||||
} else {
|
GUIitem.setItemMeta(enchantMeta);
|
||||||
GUIitem.addUnsafeEnchantment(Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]));
|
} else {
|
||||||
}
|
GUIitem.addUnsafeEnchantment(Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[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 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 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
|
} else
|
||||||
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!");
|
skullMeta.setOwner(skullOwner);
|
||||||
}
|
GUIitem.setItemMeta(skullMeta);
|
||||||
|
}
|
||||||
|
} 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<>();
|
||||||
@ -1151,9 +1152,9 @@ public class ConfigManager {
|
|||||||
|
|
||||||
Jobs.consoleMsg("&e[Jobs] Loaded " + Jobs.getJobs().size() + " jobs!");
|
Jobs.consoleMsg("&e[Jobs] Loaded " + Jobs.getJobs().size() + " jobs!");
|
||||||
if (!Jobs.getExplore().isExploreEnabled()) {
|
if (!Jobs.getExplore().isExploreEnabled()) {
|
||||||
Jobs.consoleMsg("&6[Jobs] Explorer jobs manager are not enabled!");
|
Jobs.consoleMsg("&6[Jobs] Explorer jobs manager are not enabled!");
|
||||||
} else
|
} else
|
||||||
Jobs.consoleMsg("&e[Jobs] Explorer job manager registered!");
|
Jobs.consoleMsg("&e[Jobs] Explorer job manager registered!");
|
||||||
//try {
|
//try {
|
||||||
// conf.save(f);
|
// conf.save(f);
|
||||||
//} catch (IOException e) {
|
//} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user