From 016c82fa858819642a4588cd1d885ad0cf389e06 Mon Sep 17 00:00:00 2001 From: Driftay Date: Mon, 30 Dec 2019 23:56:59 -0500 Subject: [PATCH] FAudit Slots & Materials Configurable Fixed IllegalPluginAccessException onDisable --- .../factions/cmd/audit/FAuditMenu.java | 2 +- .../factions/cmd/audit/FLogType.java | 45 +++++++++---------- .../massivecraft/factions/zcore/MPlugin.java | 24 +++++----- .../zcore/fupgrades/FUpgradesGUI.java | 1 - .../zcore/persist/json/JSONFPlayers.java | 1 - src/main/resources/config.yml | 26 +++++------ src/main/resources/plugin.yml | 1 + 7 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/audit/FAuditMenu.java b/src/main/java/com/massivecraft/factions/cmd/audit/FAuditMenu.java index 5573798e..28ef15ca 100644 --- a/src/main/java/com/massivecraft/factions/cmd/audit/FAuditMenu.java +++ b/src/main/java/com/massivecraft/factions/cmd/audit/FAuditMenu.java @@ -57,7 +57,7 @@ public class FAuditMenu extends GUIMenu { lore.add(""); if (logsLeft > 0) lore.add(CC.Yellow + "Left-Click " + CC.Gray + "to view more logs"); lore.add(CC.Yellow + "Right-Click " + CC.Gray + "to toggle timestamps"); - setItem(index++, (new ClickableItemStack((new ItemBuilder(type.getDisplayMaterial())).name(CC.GreenB + type.getDisplayName()).lore(lore).build())).setClickCallback((click) -> { + setItem(index++, (new ClickableItemStack((new ItemBuilder(type.getMaterial())).name(CC.GreenB + type.getDisplayName()).lore(lore).build())).setClickCallback((click) -> { click.setCancelled(true); if (click.getClick() == ClickType.RIGHT) { showTimestamps = !showTimestamps; diff --git a/src/main/java/com/massivecraft/factions/cmd/audit/FLogType.java b/src/main/java/com/massivecraft/factions/cmd/audit/FLogType.java index 1a3ca41f..6d3aa666 100644 --- a/src/main/java/com/massivecraft/factions/cmd/audit/FLogType.java +++ b/src/main/java/com/massivecraft/factions/cmd/audit/FLogType.java @@ -2,7 +2,6 @@ package com.massivecraft.factions.cmd.audit; import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.XMaterial; -import com.massivecraft.factions.zcore.fperms.PermissableAction; import org.bukkit.Material; /** @@ -10,22 +9,21 @@ import org.bukkit.Material; */ public enum FLogType { - INVITES("Roster Edits", XMaterial.WRITABLE_BOOK.parseMaterial(), "&e%s&7 &a%s&7 &e%s", 3), - BANS("Player Bans", XMaterial.ANVIL.parseMaterial(), "&e%s&7 &e%s&6 &e%s", 3), - CHUNK_CLAIMS("Claim Edits", XMaterial.WOODEN_AXE.parseMaterial(), "&e%s&7 %s&7 &e%s&7 near &e%s", 3), - PERM_EDIT_DEFAULTS("Default Perm Edits", XMaterial.WRITTEN_BOOK.parseMaterial(), "&e%s&7 %s&7 %s for &e%s", 4), - BANK_EDIT("/f money Edits", XMaterial.GOLD_INGOT.parseMaterial(), "&e%s&7 %s &e&l$&e%s", 3), - FCHEST_EDIT("/f chest Edits", XMaterial.CHEST.parseMaterial(), "&e%s&7 %s &f%s", 3), - RELATION_CHANGE("Relation Edits", XMaterial.GOLDEN_SWORD.parseMaterial(), "&e%s %s&e'd %s", 3), - FTAG_EDIT("/f tag Edits", XMaterial.NAME_TAG.parseMaterial(), "&e%s&7 set to &e'%s'", 2), - FDESC_EDIT("/f desc Edits", XMaterial.PAPER.parseMaterial(), "&e%s&7 set to &e'%s'", 2), - ROLE_PERM_EDIT("/f promote Edits", XMaterial.WRITTEN_BOOK.parseMaterial(), "&e%s&7&e %s &e%s &7to &e%s", 4), - SPAWNER_EDIT("Spawner Edits", XMaterial.SPAWNER.parseMaterial(), "&e%s&7 %s &e%s&7 %s", 4), - RANK_EDIT("Rank Edits", XMaterial.GOLDEN_HELMET.parseMaterial(), "&e%s&7 set &e%s&7 to %s", 3), - F_TNT("/f tnt Edits", XMaterial.TNT.parseMaterial(), "&e%s&7 %s &e%s", 3); + INVITES("Roster Edits", "&e%s&7 &a%s&7 &e%s", 3), + BANS("Player Bans", "&e%s&7 &e%s&6 &e%s", 3), + CHUNK_CLAIMS("Claim Edits", "&e%s&7 %s&7 &e%s&7 near &e%s", 3), + PERM_EDIT_DEFAULTS("Default Perm Edits", "&e%s&7 %s&7 %s for &e%s", 4), + BANK_EDIT("Money Edits", "&e%s&7 %s &e&l$&e%s", 3), + FCHEST_EDIT("Chest Edits", "&e%s&7 %s &f%s", 3), + RELATION_CHANGE("Relation Edits", "&e%s %s&e'd %s", 3), + FTAG_EDIT("Tag Edits", "&e%s&7 set to &e'%s'", 2), + FDESC_EDIT("Desc Edits", "&e%s&7 set to &e'%s'", 2), + ROLE_PERM_EDIT("Promotional Edits", "&e%s&7&e %s &e%s &7to &e%s", 4), + SPAWNER_EDIT("Spawner Edits", "&e%s&7 %s &e%s&7 %s", 4), + RANK_EDIT("Rank Edits", "&e%s&7 set &e%s&7 to %s", 3), + F_TNT("Tnt Edits", "&e%s&7 %s &e%s", 3); private String displayName; - private Material displayMaterial; private String msg; private int requiredArgs; @@ -47,15 +45,17 @@ public enum FLogType { } return null; } - public int getSlot() { - return FactionsPlugin.getInstance().getConfig().getInt("faudit-gui.slots." + this.displayName.toLowerCase()); + + @Override + public String toString() { return name(); } + + public int getSlot() { return FactionsPlugin.getInstance().getConfig().getInt("faudit-gui.slots." + name().toLowerCase()); } + + public Material getMaterial(){ + return XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("faudit-gui.materials." + name().toLowerCase())).parseMaterial(); } - public Material getDisplayMaterial() { - return this.displayMaterial; - } - public String getMsg() { return this.msg; } @@ -64,9 +64,8 @@ public enum FLogType { return this.requiredArgs; } - FLogType(String displayName, Material displayMaterial, String msg, int requiredArgs) { + FLogType(String displayName, String msg, int requiredArgs) { this.displayName = displayName; - this.displayMaterial = displayMaterial; this.msg = msg; this.requiredArgs = requiredArgs; } diff --git a/src/main/java/com/massivecraft/factions/zcore/MPlugin.java b/src/main/java/com/massivecraft/factions/zcore/MPlugin.java index 914ba015..97677d21 100644 --- a/src/main/java/com/massivecraft/factions/zcore/MPlugin.java +++ b/src/main/java/com/massivecraft/factions/zcore/MPlugin.java @@ -15,6 +15,7 @@ import com.massivecraft.factions.zcore.util.TextUtil; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.IllegalPluginAccessException; import org.bukkit.plugin.java.JavaPlugin; import java.io.*; @@ -177,17 +178,20 @@ public abstract class MPlugin extends JavaPlugin { } public void onDisable() { - if (saveTask != null) { - this.getServer().getScheduler().cancelTask(saveTask); - saveTask = null; + try { + if (saveTask != null) { + this.getServer().getScheduler().cancelTask(saveTask); + saveTask = null; + } + // only save data if plugin actually loaded successfully + if (loadSuccessful) { + Factions.getInstance().forceSave(); + FPlayers.getInstance().forceSave(); + Board.getInstance().forceSave(); + } + log("Disabled"); + } catch (IllegalPluginAccessException e){ } - // only save data if plugin actually loaded successfully - if (loadSuccessful) { - Factions.getInstance().forceSave(); - FPlayers.getInstance().forceSave(); - Board.getInstance().forceSave(); - } - log("Disabled"); } // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java index bd14782d..6eb56104 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java @@ -378,7 +378,6 @@ public class FUpgradesGUI implements Listener { } itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); cropItem.setItemMeta(itemMeta); - cropItem.setAmount(cropLevel); } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFPlayers.java b/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFPlayers.java index 831ab481..b223d65c 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFPlayers.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFPlayers.java @@ -54,7 +54,6 @@ public class JSONFPlayers extends MemoryFPlayers { entitiesThatShouldBeSaved.put(entity.getId(), (JSONFPlayer) entity); } } - saveCore(file, entitiesThatShouldBeSaved, sync); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7f41ae7d..c42cea04 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1291,19 +1291,19 @@ faudit-gui: rank_edit: 11 f_tnt: 12 materials: - invites: 0 - bans: 1 - chunk_claims: 2 - perm_edit_defaults: 3 - bank_edit: 4 - fchest_edit: 5 - relation_change: 6 - ftag_edit: 7 - fdesc_edit: 8 - role_perm_edit: 9 - spawner_edit: 10 - rank_edit: 11 - f_tnt: 12 + invites: WRITABLE_BOOK + bans: ANVIL + chunk_claims: WOODEN_AXE + perm_edit_defaults: WRITTEN_BOOK + bank_edit: GOLD_INGOT + fchest_edit: CHEST + relation_change: GOLDEN_SWORD + ftag_edit: NAME_TAG + fdesc_edit: PAPER + role_perm_edit: WRITTEN_BOOK + spawner_edit: SPAWNER + rank_edit: GOLDEN_HELMET + f_tnt: TNT ############################################################ # +------------------------------------------------------+ # diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ff3f2c70..777aeee4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -65,6 +65,7 @@ permissions: factions.kit.halfplayer: description: Can do all but create factions. children: + factions.audit: true factions.drain: true factions.wild: true factions.missions: true