From 81a33de33a601cd88a56da29dd92cebddbdc77ba Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Fri, 2 Mar 2018 13:57:36 -0800 Subject: [PATCH] Format and check for null section --- .../massivecraft/factions/cmd/CmdPerm.java | 4 +++- .../massivecraft/factions/cmd/CmdShow.java | 1 - .../zcore/fperms/PermissableAction.java | 22 +++++++++++++------ .../fperms/gui/PermissableActionGUI.java | 4 ++-- .../fperms/gui/PermissableRelationGUI.java | 2 +- .../zcore/fperms/gui/PermissionGUI.java | 1 - .../factions/zcore/persist/MemoryBoard.java | 4 ++-- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java index d98855a8..92f50c68 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java @@ -11,7 +11,9 @@ import com.massivecraft.factions.zcore.fperms.gui.PermissableActionGUI; import com.massivecraft.factions.zcore.fperms.gui.PermissableRelationGUI; import com.massivecraft.factions.zcore.util.TL; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; public class CmdPerm extends FCommand { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java index 91be9390..ce32576e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java @@ -7,7 +7,6 @@ import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TagReplacer; import com.massivecraft.factions.zcore.util.TagUtil; -import me.clip.placeholderapi.PlaceholderAPI; import mkremins.fanciful.FancyMessage; import java.util.ArrayList; diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java index a451e01e..79ac4a40 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; public enum PermissableAction { BAN("ban"), @@ -72,15 +73,21 @@ public enum PermissableAction { // Utility method to build items for F Perm GUI public ItemStack buildItem(FPlayer fme, Permissable permissable) { - final ConfigurationSection ACTION_CONFIG = P.p.getConfig().getConfigurationSection("fperm-gui.action"); + final ConfigurationSection section = P.p.getConfig().getConfigurationSection("fperm-gui.action"); - String displayName = replacePlaceholers(ACTION_CONFIG.getString("placeholder-item.name"), fme, permissable); + if (section == null) { + P.p.log(Level.WARNING, "Attempted to build f perm GUI but config section not present."); + P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config."); + return new ItemStack(Material.AIR); + } + + String displayName = replacePlaceholers(section.getString("placeholder-item.name"), fme, permissable); List lore = new ArrayList<>(); - if (ACTION_CONFIG.getString("materials." + name().toLowerCase().replace('_', '-')) == null) { + if (section.getString("materials." + name().toLowerCase().replace('_', '-')) == null) { return null; } - Material material = Material.matchMaterial(ACTION_CONFIG.getString("materials." + name().toLowerCase().replace('_', '-'))); + Material material = Material.matchMaterial(section.getString("materials." + name().toLowerCase().replace('_', '-'))); if (material == null) { material = Material.STAINED_CLAY; } @@ -91,8 +98,9 @@ public enum PermissableAction { } DyeColor dyeColor = null; try { - dyeColor = DyeColor.valueOf(ACTION_CONFIG.getString("access." + access.name().toLowerCase())); - } catch (Exception exception) {} + dyeColor = DyeColor.valueOf(section.getString("access." + access.name().toLowerCase())); + } catch (Exception exception) { + } ItemStack item = new ItemStack(material); ItemMeta itemMeta = item.getItemMeta(); @@ -101,7 +109,7 @@ public enum PermissableAction { item.setDurability(dyeColor.getWoolData()); } - for (String loreLine : ACTION_CONFIG.getStringList("placeholder-item.lore")) { + for (String loreLine : section.getStringList("placeholder-item.lore")) { lore.add(replacePlaceholers(loreLine, fme, permissable)); } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableActionGUI.java b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableActionGUI.java index 982c313d..10584e33 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableActionGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableActionGUI.java @@ -90,7 +90,7 @@ public class PermissableActionGUI implements InventoryHolder, PermissionGUI { } } - + buildSpecialItems(); buildItems(); } @@ -195,7 +195,7 @@ public class PermissableActionGUI implements InventoryHolder, PermissionGUI { List dummySlots = ACTION_CONFIG.getIntegerList("dummy-items." + key); for (Integer slot : dummySlots) { - if (slot+1 > guiSize || slot < 0) { + if (slot + 1 > guiSize || slot < 0) { P.p.log(Level.WARNING, "Invalid slot: " + slot + " for dummy item: " + key); continue; } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationGUI.java b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationGUI.java index 55ded11a..0c7cf8d2 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationGUI.java @@ -125,7 +125,7 @@ public class PermissableRelationGUI implements InventoryHolder, PermissionGUI { List dummySlots = RELATION_CONFIG.getIntegerList("dummy-items." + key); for (Integer slot : dummySlots) { - if (slot+1 > guiSize || slot < 0) { + if (slot + 1 > guiSize || slot < 0) { P.p.log(Level.WARNING, "Invalid slot: " + slot + " for dummy item: " + key); continue; } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissionGUI.java b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissionGUI.java index 82474b8d..0cfaa4fe 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissionGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissionGUI.java @@ -1,7 +1,6 @@ package com.massivecraft.factions.zcore.fperms.gui; import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryAction; public interface PermissionGUI { diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java index 0483ab53..3a602896 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -284,10 +284,10 @@ public abstract class MemoryBoard extends Board { Faction factionHere = getFactionAt(flocationHere); Relation relation = fplayer.getRelationTo(factionHere); if (factionHere.isWilderness()) { - row.then("-") .color(ChatColor.GRAY); + row.then("-").color(ChatColor.GRAY); // Check for claimat position and if so, let them claim at ;D if (fplayer.getPlayer().hasPermission(Permission.CLAIMAT.node)) { - row.tooltip(TL.CLAIM_CLICK_TO_CLAIM.format(dx, dz)) + row.tooltip(TL.CLAIM_CLICK_TO_CLAIM.format(dx, dz)) .command(String.format("/f claimat %s %d %d", flocation.getWorldName(), dx, dz)); } } else if (factionHere.isSafeZone()) {