#83: Basic settings GUI

Added basics, the command, listener and a few player buttons.
This commit is contained in:
Daniel Saukel 2016-06-06 15:19:15 +02:00
parent 11f67839fe
commit f5644bffbc
13 changed files with 597 additions and 7 deletions

View File

@ -16,6 +16,9 @@
*/
package io.github.dre2n.dungeonsxl;
import io.github.dre2n.dungeonsxl.settings.ToggleAnnouncementsButton;
import io.github.dre2n.dungeonsxl.settings.ToggleBreakButton;
import io.github.dre2n.dungeonsxl.settings.ToggleChatSpyButton;
import io.github.dre2n.caliburn.CaliburnAPI;
import io.github.dre2n.commons.command.BRCommands;
import io.github.dre2n.commons.compatibility.Internals;
@ -44,6 +47,7 @@ import io.github.dre2n.dungeonsxl.player.DSavePlayer;
import io.github.dre2n.dungeonsxl.requirement.RequirementTypes;
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
import io.github.dre2n.dungeonsxl.reward.RewardTypes;
import io.github.dre2n.dungeonsxl.settings.Settings;
import io.github.dre2n.dungeonsxl.sign.DSignTypes;
import io.github.dre2n.dungeonsxl.sign.SignScripts;
import io.github.dre2n.dungeonsxl.task.AnnouncerTask;
@ -95,6 +99,9 @@ public class DungeonsXL extends BRPlugin {
private GlobalProtections protections;
private ExternalMobProviders dMobProviders;
private DPlayers dPlayers;
private Settings editSettings;
private Settings globalSettings;
private Settings playerSettings;
private Announcers announcers;
private DClasses dClasses;
private DMobTypes dMobTypes;
@ -127,7 +134,6 @@ public class DungeonsXL extends BRPlugin {
* ##########################
*/
settings = new BRPluginSettings(true, true, true, true, true, Internals.andHigher(Internals.v1_7_R3));
settings = new BRPluginSettings(true, true, true, true, true, 9488, Internals.andHigher(Internals.v1_7_R3));
}
@ -162,6 +168,7 @@ public class DungeonsXL extends BRPlugin {
loadDClasses(CLASSES);
loadDMobTypes(MOBS);
loadSignScripts(SIGNS);
loadSettings();
manager.registerEvents(new EntityListener(), this);
manager.registerEvents(new GUIListener(), this);
@ -409,6 +416,7 @@ public class DungeonsXL extends BRPlugin {
new DeletePortalCommand(),
new ReloadCommand(),
new SaveCommand(),
new SettingsCommand(),
new TestCommand()
);
@ -541,6 +549,40 @@ public class DungeonsXL extends BRPlugin {
dPlayers = new DPlayers();
}
/**
* @return the settings that represent main config defaults, dungeon config and floor config
*/
public Settings getEditSettings() {
return editSettings;
}
/**
* @return the settings that represents main config
*/
public Settings getGlobalSettings() {
return globalSettings;
}
/**
* @return the settings that represent transient and persistent player data
*/
public Settings getPlayerSettings() {
return playerSettings;
}
/**
* load / reload new instances of Settings
*/
public void loadSettings() {
editSettings = new Settings(DMessages.SETTINGS_TITLE_EDIT.getMessage());
globalSettings = new Settings(DMessages.SETTINGS_TITLE_GLOBAL.getMessage());
playerSettings = new Settings(DMessages.SETTINGS_TITLE_PLAYER.getMessage(),
new ToggleAnnouncementsButton(),
new ToggleBreakButton(),
new ToggleChatSpyButton()
);
}
/**
* @return the loaded instance of Announcers
*/

View File

@ -57,6 +57,9 @@ public class Announcer {
private String dungeonName;
private String mapName;
private int minGroupsPerGame;
private int minPlayersPerGroup;
private short maxGroupsPerGame;
private int maxPlayersPerGroup;
@ -97,6 +100,9 @@ public class Announcer {
mapName = identifier;
}
minGroupsPerGame = config.getInt("minGroupsPerGame");
minPlayersPerGroup = config.getInt("minPlayersPerGroup");
maxGroupsPerGame = (short) config.getInt("maxGroupsPerGame");
dGroups = new ArrayList<>(Collections.nCopies(maxGroupsPerGame + 1, (DGroup) null));
maxPlayersPerGroup = config.getInt("maxPlayersPerGroup");
@ -207,6 +213,36 @@ public class Announcer {
this.mapName = mapName;
}
/**
* @return the minimum amount of filled groups per game
*/
public int getMinGroupsPerGame() {
return minGroupsPerGame;
}
/**
* @param amount
* the amount to set
*/
public void setMinGroupsPerGame(int amount) {
minGroupsPerGame = amount;
}
/**
* @return the minimum amount of filled groups per game
*/
public int getMinPlayersPerGroup() {
return minPlayersPerGroup;
}
/**
* @param amount
* the amount to set
*/
public void setMinPlayersPerGroup(int amount) {
minPlayersPerGroup = amount;
}
/**
* @return the maximum amount of groups per game
*/
@ -314,6 +350,17 @@ public class Announcer {
}
showGUI(player);
int i = 0;
for (DGroup group : dGroups) {
if (group != null && group.getPlayers().size() >= minPlayersPerGroup) {
i++;
}
}
if (i >= minGroupsPerGame) {
}
}
/**

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.commons.command.BRCommand;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author Daniel Saukel
*/
public class SettingsCommand extends BRCommand {
DungeonsXL plugin = DungeonsXL.getInstance();
public SettingsCommand() {
setCommand("settings");
setMinArgs(0);
setMaxArgs(1);
setHelp(DMessages.HELP_CMD_SETTINGS.getMessage());
setPermission(DPermissions.SETTINGS.getNode());
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
String type = "player";
if (args.length == 2) {
type = args[1];
}
if (type.equalsIgnoreCase("edit") || type.equalsIgnoreCase("e")) {
plugin.getEditSettings().showGUI(player);
} else if (type.equalsIgnoreCase("global") || type.equalsIgnoreCase("g")) {
plugin.getGlobalSettings().showGUI(player);
} else if (type.equalsIgnoreCase("player") || type.equalsIgnoreCase("p")) {
plugin.getPlayerSettings().showGUI(player);
}
}
}

View File

@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.config;
import io.github.dre2n.commons.config.Messages;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -114,6 +115,7 @@ public enum DMessages implements Messages {
HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal - Creates a portal that leads into a dungeon"),
HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"),
HELP_CMD_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"),
HELP_CMD_SETTINGS("Help_Cmd_Settings", "/dxl settings ([edit|global|player])- Opens the settings menu"),
HELP_CMD_TEST("Help_Cmd_Test", "/dxl test - Starts the game in test mode"),
HELP_CMD_UNINVITE("Help_Cmd_Uninvite", "/dxl uninvite <player> <dungeon> - Uninvite a player to edit a dungeon"),
GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"),
@ -159,7 +161,17 @@ public enum DMessages implements Messages {
PLAYER_TREASURES("Player_Treasures", "&1Treasures"),
PLAYER_WAIT_FOR_OTHER_PLAYERS("Player_WaitForOtherPlayers", "&6Waiting for teammates..."),
REQUIREMENT_FEE("Requirement_Fee", "&6You have been charged &4&v1 &6for entering the dungeon."),
REWARD_GENERAL("Reward_General", "&6You received &4&v1 &6for finishing the dungeon.");
REWARD_GENERAL("Reward_General", "&6You received &4&v1 &6for finishing the dungeon."),
SETTINGS_ANNOUNCEMENTS_1("Settings_Announcements1", "&fToggles personal"),
SETTINGS_ANNOUNCEMENTS_2("Settings_Announcements2", "&fgame announcements."),
SETTINGS_BREAK_1("Settings_Break1", "&fAllows you to break blocks"),
SETTINGS_BREAK_2("Settings_Break2", "&fprotected by DungeonsXL."),
SETTINGS_CHAT_SPY1("Settings_ChatSpy1", "&fAllows you to receive"),
SETTINGS_CHAT_SPY2("Settings_ChatSpy2", "&fall dungeon chat messages."),
SETTINGS_TITLE("Settings_Title", "&4Settings: &o"),
SETTINGS_TITLE_EDIT("Settings_Title_Edit", "Dungeon Setup"),
SETTINGS_TITLE_GLOBAL("Settings_Title_Global", "Global Configuration"),
SETTINGS_TITLE_PLAYER("Settings_Title_Player", "Player");
private String identifier;
private String message;
@ -176,7 +188,7 @@ public enum DMessages implements Messages {
@Override
public String getMessage() {
return message;
return ChatColor.translateAlternateColorCodes('&', message);
}
@Override

View File

@ -19,6 +19,9 @@ package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.commons.util.guiutil.ButtonClickEvent;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.announcer.Announcer;
import io.github.dre2n.dungeonsxl.config.DMessages;
import java.util.Locale;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
@ -33,15 +36,30 @@ public class GUIListener implements Listener {
@EventHandler
public void onButtonClick(ButtonClickEvent event) {
Player player = event.getPlayer();
Inventory gui = event.getGUI();
if (!plugin.getGUIs().contains(gui)) {
return;
}
ItemStack button = event.getGUI().getItem(event.getSlot());
ItemStack button = gui.getItem(event.getSlot());
Announcer announcer = plugin.getAnnouncers().getByGUI(gui);
if (announcer != null) {
announcer.clickGroupButton(event.getPlayer(), button);
announcer.clickGroupButton(player, button);
} else if (gui.getTitle().startsWith(DMessages.SETTINGS_TITLE.getMessage())) {
if (gui.getTitle().equals(DMessages.SETTINGS_TITLE.getMessage() + DMessages.SETTINGS_TITLE_EDIT.getMessage())) {
plugin.getEditSettings().clickButton(player, button);
} else if (gui.getTitle().equals(DMessages.SETTINGS_TITLE.getMessage() + DMessages.SETTINGS_TITLE_GLOBAL.getMessage())) {
plugin.getGlobalSettings().clickButton(player, button);
} else if (gui.getTitle().equals(DMessages.SETTINGS_TITLE.getMessage() + DMessages.SETTINGS_TITLE_PLAYER.getMessage())) {
plugin.getPlayerSettings().clickButton(player, button);
}
}
}

View File

@ -39,7 +39,7 @@ public class DGlobalPlayer {
private boolean breakMode;
private boolean chatSpyMode;
private DPortal creatingPortal;
private boolean announcerEnabled;
private boolean announcerEnabled = true;
private ItemStack[] respawnInventory;
private ItemStack[] respawnArmor;

View File

@ -59,6 +59,7 @@ public enum DPermissions {
PORTAL("portal", OP),
RELOAD("reload", OP),
SAVE("save", OP),
SETTINGS("settings", TRUE),
SIGN("sign", OP),
TEST("test", OP),
UNINVITE("uninvite", OP),
@ -66,7 +67,7 @@ public enum DPermissions {
ADMINISTRATOR("*", OP),
HALF_EDITOR("halfeditor", OP, ESCAPE, LIST, MESSAGE, SAVE),
FULL_EDITOR("fulleditor", OP, HALF_EDITOR, EDIT, PLAY, SIGN, TEST),
HALF_PLAYER("halfplayer", TRUE, CHAT, ESCAPE, GAME, HELP, JOIN, LEAVE, LIVES, MAIN),
HALF_PLAYER("halfplayer", TRUE, CHAT, ESCAPE, GAME, HELP, JOIN, LEAVE, LIVES, MAIN, SETTINGS),
FULL_PLAYER("fullplayer", OP, HALF_PLAYER, GROUP);
public static final String PREFIX = "dxl.";

View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.settings;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* @author Daniel Saukel
*/
public interface Button {
/* Getters and setters */
/**
* @return the permissions that are required to see the button
*/
public String getRequiredPermission();
/**
* @return the input type
*/
public ButtonType getType();
/* Actions */
/**
* @return the button as an ItemStack
*/
public ItemStack toItemStack(Player player);
/**
* The on click action
*/
public void onClick(Player player);
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.settings;
/**
* @author Daniel Saukel
*/
public enum ButtonType {
CHAT_INPUT,
FOLDER,
SWITCH,
VOID;
}

View File

@ -0,0 +1,118 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.settings;
import io.github.dre2n.commons.util.guiutil.GUIUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* @author Daniel Saukel
*/
public class Settings {
DungeonsXL plugin = DungeonsXL.getInstance();
private String title = DMessages.SETTINGS_TITLE.getMessage();
private List<Button> buttons = new ArrayList<>();
public Settings(String titleSuffix, Button... buttons) {
this.title += titleSuffix;
this.buttons = Arrays.asList(buttons);
}
/* Getters and setters */
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @return the buttons
*/
public List<Button> getButtons() {
return buttons;
}
/**
* @param button
* the Button to add
*/
public void addButton(Button button) {
buttons.add(button);
}
/**
* @param button
* the Button to remove
*/
public void removeButton(Button button) {
buttons.remove(button);
}
/* Actions */
/**
* @param player
* the Player whose data fills the details of the button text
* @return a List of ItemStacks to be used in a inventory GUI
*/
public List<ItemStack> toItemStacks(Player player) {
List<ItemStack> buttons = new ArrayList<>();
for (Button button : this.buttons) {
if (player.hasPermission(button.getRequiredPermission())) {
buttons.add(button.toItemStack(player));
}
}
return buttons;
}
/**
* @param player
* show the GUI to this Player
*/
public void showGUI(Player player) {
Inventory gui = GUIUtil.createGUI(plugin, title, toItemStacks(player));
plugin.addGUI(gui);
player.closeInventory();
player.openInventory(gui);
}
/**
* @param player
* the player who clicked
* @param button
* the clicked button
*/
public void clickButton(Player player, ItemStack button) {
for (Button type : buttons) {
if (type.toItemStack(player).equals(button)) {
type.onClick(player);
}
}
showGUI(player);
}
}

View File

@ -0,0 +1,70 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.settings;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
import java.util.Arrays;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* @author Daniel Saukel
*/
public class ToggleAnnouncementsButton implements Button {
DungeonsXL plugin = DungeonsXL.getInstance();
private String permission = "";
private ButtonType type = ButtonType.SWITCH;
/* Getters and setters */
@Override
public String getRequiredPermission() {
return permission;
}
@Override
public ButtonType getType() {
return type;
}
/* Actions */
@Override
public ItemStack toItemStack(Player player) {
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
ItemStack button = new ItemStack(Material.INK_SACK, 1, (short) (dPlayer.isAnnouncerEnabled() ? 10 : 8));
ItemMeta meta = button.getItemMeta();
meta.setDisplayName((dPlayer.isAnnouncerEnabled() ? ChatColor.GREEN : ChatColor.DARK_RED) + "Toggle Announcements");
meta.setLore(Arrays.asList(DMessages.SETTINGS_ANNOUNCEMENTS_1.getMessage(), DMessages.SETTINGS_ANNOUNCEMENTS_2.getMessage()));
button.setItemMeta(meta);
return button;
}
@Override
public void onClick(Player player) {
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
dPlayer.setAnnouncerEnabled(!dPlayer.isAnnouncerEnabled());
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.settings;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import java.util.Arrays;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* @author Daniel Saukel
*/
public class ToggleBreakButton implements Button {
DungeonsXL plugin = DungeonsXL.getInstance();
private String permission = DPermissions.BREAK.getNode();
private ButtonType type = ButtonType.SWITCH;
/* Getters and setters */
@Override
public String getRequiredPermission() {
return permission;
}
@Override
public ButtonType getType() {
return type;
}
/* Actions */
@Override
public ItemStack toItemStack(Player player) {
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
ItemStack button = new ItemStack(Material.INK_SACK, 1, (short) (dPlayer.isInBreakMode() ? 10 : 8));
ItemMeta meta = button.getItemMeta();
meta.setDisplayName((dPlayer.isInBreakMode() ? ChatColor.GREEN : ChatColor.DARK_RED) + "Break Mode");
meta.setLore(Arrays.asList(DMessages.SETTINGS_BREAK_1.getMessage(), DMessages.SETTINGS_BREAK_2.getMessage()));
button.setItemMeta(meta);
return button;
}
@Override
public void onClick(Player player) {
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
dPlayer.setInBreakMode(!dPlayer.isInBreakMode());
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.settings;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import java.util.Arrays;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* @author Daniel Saukel
*/
public class ToggleChatSpyButton implements Button {
DungeonsXL plugin = DungeonsXL.getInstance();
private String permission = DPermissions.CHAT_SPY.getNode();
private ButtonType type = ButtonType.SWITCH;
/* Getters and setters */
@Override
public String getRequiredPermission() {
return permission;
}
@Override
public ButtonType getType() {
return type;
}
/* Actions */
@Override
public ItemStack toItemStack(Player player) {
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
ItemStack button = new ItemStack(Material.INK_SACK, 1, (short) (dPlayer.isInChatSpyMode() ? 10 : 8));
ItemMeta meta = button.getItemMeta();
meta.setDisplayName((dPlayer.isInChatSpyMode() ? ChatColor.GREEN : ChatColor.DARK_RED) + "Chat Spy Mode");
meta.setLore(Arrays.asList(DMessages.SETTINGS_CHAT_SPY1.getMessage(), DMessages.SETTINGS_CHAT_SPY2.getMessage()));
button.setItemMeta(meta);
return button;
}
@Override
public void onClick(Player player) {
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
dPlayer.setInChatSpyMode(!dPlayer.isInChatSpyMode());
}
}