From f5644bffbc75bb17cc28fdd16e1165efd4db07b4 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 6 Jun 2016 15:19:15 +0200 Subject: [PATCH] #83: Basic settings GUI Added basics, the command, listener and a few player buttons. --- .../github/dre2n/dungeonsxl/DungeonsXL.java | 44 ++++++- .../dre2n/dungeonsxl/announcer/Announcer.java | 47 +++++++ .../dungeonsxl/command/SettingsCommand.java | 62 +++++++++ .../dre2n/dungeonsxl/config/DMessages.java | 16 ++- .../dungeonsxl/listener/GUIListener.java | 22 +++- .../dungeonsxl/player/DGlobalPlayer.java | 2 +- .../dre2n/dungeonsxl/player/DPermissions.java | 3 +- .../dre2n/dungeonsxl/settings/Button.java | 49 ++++++++ .../dre2n/dungeonsxl/settings/ButtonType.java | 29 +++++ .../dre2n/dungeonsxl/settings/Settings.java | 118 ++++++++++++++++++ .../settings/ToggleAnnouncementsButton.java | 70 +++++++++++ .../settings/ToggleBreakButton.java | 71 +++++++++++ .../settings/ToggleChatSpyButton.java | 71 +++++++++++ 13 files changed, 597 insertions(+), 7 deletions(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/command/SettingsCommand.java create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/settings/Button.java create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/settings/ButtonType.java create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/settings/Settings.java create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/settings/ToggleAnnouncementsButton.java create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/settings/ToggleBreakButton.java create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/settings/ToggleChatSpyButton.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 0a995af4..ea69f1ae 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -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 */ diff --git a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java index 81b13568..de3e05d8 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -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) { + + } } /** diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/SettingsCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/SettingsCommand.java new file mode 100644 index 00000000..f838c1f1 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/SettingsCommand.java @@ -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 . + */ +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); + } + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 9b2465b3..5bf96064 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -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 - 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 diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java index 613d126e..eda7a212 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java @@ -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); + + } } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index 640fde3f..c90270b0 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -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; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java index c19bb1c1..62a38430 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java @@ -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."; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/settings/Button.java b/src/main/java/io/github/dre2n/dungeonsxl/settings/Button.java new file mode 100644 index 00000000..4ef93b20 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/settings/Button.java @@ -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 . + */ +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); + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/settings/ButtonType.java b/src/main/java/io/github/dre2n/dungeonsxl/settings/ButtonType.java new file mode 100644 index 00000000..3659e1dd --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/settings/ButtonType.java @@ -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 . + */ +package io.github.dre2n.dungeonsxl.settings; + +/** + * @author Daniel Saukel + */ +public enum ButtonType { + + CHAT_INPUT, + FOLDER, + SWITCH, + VOID; + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/settings/Settings.java b/src/main/java/io/github/dre2n/dungeonsxl/settings/Settings.java new file mode 100644 index 00000000..f396869d --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/settings/Settings.java @@ -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 . + */ +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