From a6ca986f502671dd80ba27dd043093a79155eed7 Mon Sep 17 00:00:00 2001 From: Esophose Date: Mon, 3 Dec 2018 02:45:50 -0700 Subject: [PATCH] Certain icons can be hidden under certain conditions on the main GUI screen now --- .../playerparticles/PlayerParticles.java | 4 -- .../gui/GuiInventoryDefault.java | 58 +++++++++++++------ .../manager/PermissionManager.java | 14 ++++- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/com/esophose/playerparticles/PlayerParticles.java b/src/com/esophose/playerparticles/PlayerParticles.java index d3b1ab5..772019f 100644 --- a/src/com/esophose/playerparticles/PlayerParticles.java +++ b/src/com/esophose/playerparticles/PlayerParticles.java @@ -1,8 +1,4 @@ /* - * TODO: v6.1 - * + Add \n support for GUI messages to break lore onto a new line - * * Make the GUI ignore empty lore lines rather than putting an empty line there - * * TODO: v6.2 * + Add new style 'tornado' * + Add new style 'doubleorbit' diff --git a/src/com/esophose/playerparticles/gui/GuiInventoryDefault.java b/src/com/esophose/playerparticles/gui/GuiInventoryDefault.java index 52087ed..768ce55 100644 --- a/src/com/esophose/playerparticles/gui/GuiInventoryDefault.java +++ b/src/com/esophose/playerparticles/gui/GuiInventoryDefault.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.meta.SkullMeta; import com.esophose.playerparticles.manager.DataManager; import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager.Lang; +import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.manager.SettingManager.GuiIcon; import com.esophose.playerparticles.particles.PPlayer; import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty; @@ -52,8 +53,27 @@ public class GuiInventoryDefault extends GuiInventory { this.inventory.setItem(13, headIcon); + // Define what slots to put the icons at based on what other slots are visible + boolean manageGroupsVisible = PermissionManager.canPlayerSaveGroups(pplayer); + boolean loadPresetGroupVisible = !ParticleGroup.getPresetGroupsForPlayer(pplayer.getPlayer()).isEmpty(); + int manageParticlesSlot = -1, manageGroupsSlot = -1, loadPresetGroupSlot = -1; + + if (!manageGroupsVisible && !loadPresetGroupVisible) { + manageParticlesSlot = 22; + } else if (!manageGroupsVisible) { + manageParticlesSlot = 21; + loadPresetGroupSlot = 23; + } else if (!loadPresetGroupVisible) { + manageParticlesSlot = 21; + manageGroupsSlot = 23; + } else { + manageParticlesSlot = 20; + manageGroupsSlot = 22; + loadPresetGroupSlot = 24; + } + // Manage Your Particles button - GuiActionButton manageYourParticlesButton = new GuiActionButton(20, + GuiActionButton manageYourParticlesButton = new GuiActionButton(manageParticlesSlot, GuiIcon.PARTICLES.get(), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_MANAGE_YOUR_PARTICLES), new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_MANAGE_YOUR_PARTICLES_DESCRIPTION) }, @@ -63,24 +83,28 @@ public class GuiInventoryDefault extends GuiInventory { this.actionButtons.add(manageYourParticlesButton); // Manage Your Groups button - GuiActionButton manageYourGroupsButton = new GuiActionButton(22, - GuiIcon.GROUPS.get(), - LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS), - new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS_DESCRIPTION) }, - (button, isShiftClick) -> { - GuiHandler.transition(new GuiInventoryManageGroups(pplayer)); - }); - this.actionButtons.add(manageYourGroupsButton); + if (manageGroupsVisible) { + GuiActionButton manageYourGroupsButton = new GuiActionButton(manageGroupsSlot, + GuiIcon.GROUPS.get(), + LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS), + new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS_DESCRIPTION) }, + (button, isShiftClick) -> { + GuiHandler.transition(new GuiInventoryManageGroups(pplayer)); + }); + this.actionButtons.add(manageYourGroupsButton); + } // Load Preset Groups - GuiActionButton loadPresetGroups = new GuiActionButton(24, - GuiIcon.PRESET_GROUPS.get(), - LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP), - new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP_DESCRIPTION) }, - (button, isShiftClick) -> { - GuiHandler.transition(new GuiInventoryLoadPresetGroups(pplayer)); - }); - this.actionButtons.add(loadPresetGroups); + if (loadPresetGroupVisible) { + GuiActionButton loadPresetGroups = new GuiActionButton(loadPresetGroupSlot, + GuiIcon.PRESET_GROUPS.get(), + LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP), + new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP_DESCRIPTION) }, + (button, isShiftClick) -> { + GuiHandler.transition(new GuiInventoryLoadPresetGroups(pplayer)); + }); + this.actionButtons.add(loadPresetGroups); + } final ParticlePair editingParticle = pplayer.getPrimaryParticle(); boolean canEditPrimaryStyleAndData = pplayer.getActiveParticle(1) != null; diff --git a/src/com/esophose/playerparticles/manager/PermissionManager.java b/src/com/esophose/playerparticles/manager/PermissionManager.java index a90963e..bf57d9f 100644 --- a/src/com/esophose/playerparticles/manager/PermissionManager.java +++ b/src/com/esophose/playerparticles/manager/PermissionManager.java @@ -16,7 +16,7 @@ public class PermissionManager { private static final String PERMISSION_PREFIX = "playerparticles."; - public enum PPermission { + private enum PPermission { ALL("*"), EFFECT_ALL("effect.*"), @@ -92,6 +92,18 @@ public class PermissionManager { return pplayer.getParticleGroups().size() - 1 >= PSetting.MAX_GROUPS.getInt(); } + /** + * Checks if the given player is able to save groups + * + * @param pplayer The player to check + * @return If the player has permission to save groups + */ + public static boolean canPlayerSaveGroups(PPlayer pplayer) { + if (PPermission.ALL.check(pplayer.getPlayer())) return true; + if (PPermission.GROUPS_UNLIMITED.check(pplayer.getPlayer())) return true; + return PSetting.MAX_GROUPS.getInt() != 0; + } + /** * Checks if the given player has reached the max number of fixed effects *