diff --git a/README.md b/README.md index 8357af55..b6bd4b34 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Wiki](http://feuerstern.bplaced.net/ressourcen/buttons/Wiki.png)](../../wiki/) [![Issues](http://feuerstern.bplaced.net/ressourcen/buttons/Issues.png)](../../issues/) [![JavaDocs](http://feuerstern.bplaced.net/ressourcen/buttons/JavaDocs.png)](http://feuerstern.bplaced.net/javadocs/dxl/) +[![MCStats](http://feuerstern.bplaced.net/ressourcen/buttons/MCStats.png)](http://mcstats.org/plugin/DungeonsXL/) ![Doge](https://i.imgflip.com/vtpyi.jpg) @@ -30,6 +31,7 @@ DungeonsXL also provides custom game mechanics to make these worlds interesting. * A built-in custom mob system and support for MythicMobs. [Read more...](../../wiki/signs#mob) * A powerful API: [Read more...](../../wiki/api-tutorial) * Different game types allow you to use your maps dynamically for different purposes. [Read more...](../../wiki/game-types) +* Announcements sothat users can join the next match easily. [Read more...](../../wiki/announcements) * ...and many more! @@ -67,7 +69,7 @@ Instead of referencing the internals of the implementation directly, DungeonsXL The shaded version of DXL (standard version) contains this library, while the original version needs it as an external plugin. Have a look at the [installation instructions](../../wiki/getting-started#installation) for detailed information. -DungeonsXL currently uses BRCommons 0.5.2. +DungeonsXL currently uses BRCommons 0.6.2. ### Java 7 and higher diff --git a/pom.xml b/pom.xml index 29d78a52..b0bb7c34 100644 --- a/pom.xml +++ b/pom.xml @@ -53,8 +53,8 @@ - org.bukkit - bukkit + org.spigotmc + spigot-api 1.9.4-R0.1-SNAPSHOT provided @@ -67,7 +67,7 @@ io.github.dre2n commons - 0.5.2 + 0.6.2 io.github.dre2n diff --git a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 260ba62a..053794fd 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -22,6 +22,7 @@ import io.github.dre2n.commons.config.MessageConfig; import io.github.dre2n.commons.javaplugin.BRPlugin; import io.github.dre2n.commons.javaplugin.BRPluginSettings; import io.github.dre2n.commons.util.FileUtil; +import io.github.dre2n.dungeonsxl.announcer.Announcers; import io.github.dre2n.dungeonsxl.command.*; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.DataConfig; @@ -62,6 +63,11 @@ public class DungeonsXL extends BRPlugin { private static DungeonsXL instance; public static final String[] EXCLUDED_FILES = {"config.yml", "uid.dat", "DXLData.data"}; + public static File DUNGEONS; + public static File LANGUAGES; + public static File MAPS; + public static File SCRIPTS; + public static File ANNOUNCERS; private DataConfig dataConfig; private MainConfig mainConfig; @@ -77,6 +83,7 @@ public class DungeonsXL extends BRPlugin { private GlobalProtections protections; private ExternalMobProviders dMobProviders; private DPlayers dPlayers; + private Announcers announcers; private BukkitTask worldUnloadTask; private BukkitTask lazyUpdateTask; @@ -95,7 +102,7 @@ public class DungeonsXL extends BRPlugin { * ####~BRPluginSettings~#### * ########################## * #~Internals~##~~v1_7_R3+~# - * #~SpigotAPI~##~~~false~~~# + * #~SpigotAPI~##~~~~true~~~# * #~~~~UUID~~~##~~~~true~~~# * #~~Economy~~##~~~~true~~~# * #Permissions##~~~~true~~~# @@ -103,7 +110,7 @@ public class DungeonsXL extends BRPlugin { * ########################## */ - settings = new BRPluginSettings(false, true, true, true, true, Internals.andHigher(Internals.v1_7_R3)); + settings = new BRPluginSettings(true, true, true, true, true, Internals.andHigher(Internals.v1_7_R3)); } @Override @@ -112,7 +119,6 @@ public class DungeonsXL extends BRPlugin { instance = this; - // InitFolders initFolders(); // Load Language @@ -121,7 +127,7 @@ public class DungeonsXL extends BRPlugin { loadDataConfig(new File(getDataFolder(), "data.yml")); loadMainConfig(new File(getDataFolder(), "config.yml")); // Load Language 2 - loadMessageConfig(new File(getDataFolder(), "languages/" + mainConfig.getLanguage() + ".yml")); + loadMessageConfig(new File(LANGUAGES, mainConfig.getLanguage() + ".yml")); loadDCommands(); DPermissions.register(); loadGameTypes(); @@ -133,8 +139,10 @@ public class DungeonsXL extends BRPlugin { loadGlobalProtections(); loadExternalMobProviders(); loadDPlayers(); + loadAnnouncers(ANNOUNCERS); manager.registerEvents(new EntityListener(), this); + manager.registerEvents(new GUIListener(), this); manager.registerEvents(new PlayerListener(), this); manager.registerEvents(new BlockListener(), this); manager.registerEvents(new WorldListener(), this); @@ -189,19 +197,29 @@ public class DungeonsXL extends BRPlugin { getDataFolder().mkdir(); } - File dungeons = new File(getDataFolder() + "/dungeons"); - if (!dungeons.exists()) { - dungeons.mkdir(); + DUNGEONS = new File(getDataFolder(), "dungeons"); + if (!DUNGEONS.exists()) { + DUNGEONS.mkdir(); } - File languages = new File(getDataFolder() + "/languages"); - if (!languages.exists()) { - languages.mkdir(); + LANGUAGES = new File(getDataFolder(), "languages"); + if (!LANGUAGES.exists()) { + LANGUAGES.mkdir(); } - File maps = new File(getDataFolder() + "/maps"); - if (!maps.exists()) { - maps.mkdir(); + MAPS = new File(getDataFolder(), "maps"); + if (!MAPS.exists()) { + MAPS.mkdir(); + } + + SCRIPTS = new File(getDataFolder(), "scripts"); + if (!SCRIPTS.exists()) { + SCRIPTS.mkdir(); + } + + ANNOUNCERS = new File(SCRIPTS, "announcers"); + if (!ANNOUNCERS.exists()) { + ANNOUNCERS.mkdir(); } } @@ -317,6 +335,7 @@ public class DungeonsXL extends BRPlugin { new GameCommand(), new GroupCommand(), new InviteCommand(), + new JoinCommand(), new EnterCommand(), new LeaveCommand(), new ListCommand(), @@ -461,6 +480,20 @@ public class DungeonsXL extends BRPlugin { dPlayers = new DPlayers(); } + /** + * @return the loaded instance of Announcers + */ + public Announcers getAnnouncers() { + return announcers; + } + + /** + * load / reload a new instance of Announcers + */ + public void loadAnnouncers(File file) { + announcers = new Announcers(file); + } + /** * @return the worldUnloadTask */ diff --git a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java new file mode 100644 index 00000000..d1c2b56f --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -0,0 +1,313 @@ +/* + * Copyright (C) 2016 Daniel Saukel + * + * 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.announcer; + +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.util.guiutil.GUIUtil; +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.dungeon.Dungeon; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; +import io.github.dre2n.dungeonsxl.player.DGroup; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +/** + * @author Daniel Saukel + */ +public class Announcer { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + private String name; + + private List description; + private List worlds; + + private String dungeonName; + private String mapName; + + private short maxGroupsPerGame; + private int maxPlayersPerGroup; + + private List dGroups; + private List buttons; + + /** + * @param name + * the name of the Announcer + * @param description + * the description messages + * @param worlds + * the names of the worlds where the announcement will be seen or null to broadcast it to all worlds + * @param identifier + * the dungeon identifier + * @param multiFloor + * if the identifier refers to an MFD (true) or an SFD (false) + * @param maxGroupsPerGame + * the amount of groups in one game + * @param maxPlayersPerGame + * the amount of players in one group + */ + public Announcer(String name, List description, List worlds, String identifier, boolean multiFloor, short maxGroupsPerGame, int maxPlayersPerGroup) { + this.name = name; + this.description = description; + this.worlds = worlds; + + if (multiFloor) { + dungeonName = identifier; + + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + if (dungeon != null) { + mapName = dungeon.getConfig().getStartFloor(); + } + + } else { + mapName = identifier; + } + + this.maxGroupsPerGame = maxGroupsPerGame; + this.dGroups = new ArrayList<>(Collections.nCopies(maxGroupsPerGame + 1, (DGroup) null)); + this.maxPlayersPerGroup = maxPlayersPerGroup; + } + + /** + * @return the name of the announcer + */ + public String getName() { + return name; + } + + /** + * @return the description messages + */ + public List getDescription() { + return description; + } + + /** + * @param description + * the description to set + */ + public void setDescription(List description) { + this.description = description; + } + + /** + * @return the names of the worlds where the announcement will be seen or null to broadcast it to all worlds + */ + public List getWorlds() { + return worlds; + } + + /** + * @param worlds + * the worlds to set + */ + public void setWorlds(List worlds) { + this.worlds = worlds; + } + + /** + * @return the name of the dungeon + */ + public String getDungeonName() { + return dungeonName; + } + + /** + * @param dungeonName + * the name of the dungeon to set + */ + public void setDungeonName(String dungeonName) { + this.dungeonName = dungeonName; + } + + /** + * @return the name of the first or only floor + */ + public String getMapName() { + return mapName; + } + + /** + * @param mapName + * the name of the map to set + */ + public void setMapName(String mapName) { + this.mapName = mapName; + } + + /** + * @return the maximum amount of groups per game + */ + public short getMaxGroupsPerGame() { + return maxGroupsPerGame; + } + + /** + * @param amount + * the amount to set + */ + public void setMaxGroupsPerGame(short amount) { + maxGroupsPerGame = amount; + } + + /** + * @return the maximum amount of players per group + */ + public int getMaxPlayersPerGroup() { + return maxPlayersPerGroup; + } + + /** + * @param amount + * the amount to set + */ + public void setMaxPlayersPerGroup(int amount) { + maxPlayersPerGroup = amount; + } + + /** + * Sends the announcement + */ + public void send(Player player) { + for (String message : description) { + MessageUtil.broadcastCenteredMessage(message); + } + + if (CompatibilityHandler.getInstance().isSpigot()) { + ClickEvent onClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl join " + name); + + BaseComponent[] message = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', DMessages.ANNOUNCER_CLICK.getMessage())); + for (BaseComponent slice : message) { + slice.setClickEvent(onClick); + } + + player.spigot().sendMessage(message); + + } else { + MessageUtil.sendCenteredMessage(player, DMessages.ANNOUNCER_CMD.getMessage(getName().toUpperCase())); + } + } + + /** + * Shows the group selection GUI + */ + public void showGUI(Player player) { + updateButtons(); + Inventory gui = GUIUtil.createGUI(plugin, ChatColor.DARK_RED + name, buttons); + plugin.addGUI(gui); + player.closeInventory(); + player.openInventory(gui); + } + + /** + * @param button + * the clicked button + */ + public void clickGroupButton(Player player, ItemStack button) { + DGroup dGroup = getDGroupByButton(button); + DGroup pGroup = DGroup.getByPlayer(player); + + for (DGroup group : dGroups) { + if (dGroups.contains(pGroup) && pGroup != null && pGroup.isCustom() && pGroup.getCaptain() == player) { + dGroups.set(dGroups.indexOf(pGroup), null); + } + + if (group != null && group.getPlayers().contains(player)) { + group.removePlayer(player); + } + } + + if (dGroup != null && pGroup == null) { + if (dGroup.getPlayers().size() < maxPlayersPerGroup) { + dGroup.addPlayer(player); + } + + } else if (dGroup == null && pGroup == null) { + DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.ANNOUNCER); + plugin.getServer().getPluginManager().callEvent(event); + if (!event.isCancelled()) { + dGroups.set(buttons.indexOf(button), new DGroup(player)); + } + + } else if (dGroup == null && pGroup != null) { + dGroups.set(buttons.indexOf(button), pGroup); + + } else if (pGroup != null && dGroups.contains(pGroup) && pGroup != dGroup) { + dGroups.set(dGroups.indexOf(pGroup), null); + dGroups.set(buttons.indexOf(button), pGroup); + } + + showGUI(player); + } + + /** + * Updates the buttons to group changes. + */ + public void updateButtons() { + int groupCount = 0; + + buttons = new ArrayList<>(dGroups.size()); + do { + String name = ChatColor.DARK_GRAY + "EMPTY GROUP"; + int playerCount = 0; + + DGroup dGroup = dGroups.get(groupCount); + if (!plugin.getDGroups().contains(dGroup)) { + dGroups.set(groupCount, null); + + } else if (dGroup != null) { + name = ChatColor.AQUA + dGroup.getName(); + playerCount = dGroup.getPlayers().size(); + } + + boolean full = playerCount >= maxPlayersPerGroup; + + ItemStack button = new ItemStack(Material.WOOL, playerCount, plugin.getMainConfig().getGroupColorPriority().get(groupCount)); + ItemMeta meta = button.getItemMeta(); + meta.setDisplayName(name + (full ? ChatColor.DARK_RED : ChatColor.GREEN) + " [" + playerCount + "/" + maxPlayersPerGroup + "]"); + button.setItemMeta(meta); + buttons.add(button); + + groupCount++; + } while (groupCount != maxGroupsPerGame); + } + + /** + * @param button + * the button + * @return the matching DGroup + */ + public DGroup getDGroupByButton(ItemStack button) { + int index = buttons.indexOf(button); + return dGroups.get(index); + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java new file mode 100644 index 00000000..524c7a27 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcers.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2016 Daniel Saukel + * + * 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.announcer; + +import io.github.dre2n.commons.util.FileUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.task.AnnouncerTask; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.inventory.Inventory; + +/** + * @author Daniel Saukel + */ +public class Announcers { + + private List announcers = new ArrayList<>(); + + public Announcers(File file) { + if (file.isDirectory()) { + for (File script : FileUtil.getFilesForFolder(file)) { + FileConfiguration config = YamlConfiguration.loadConfiguration(script); + + String name = script.getName().substring(0, script.getName().length() - 4); + String identifier = config.getString("identifier"); + List description = config.getStringList("description"); + List worlds = null; + if (config.contains("worlds")) { + worlds = config.getStringList("worlds"); + } + boolean multiFloor = config.getBoolean("multiFloor"); + short maxGroupsPerGame = (short) config.getInt("maxGroupsPerGame"); + int maxPlayersPerGroup = config.getInt("maxPlayersPerGroup"); + + announcers.add(new Announcer(name, description, worlds, identifier, multiFloor, maxGroupsPerGame, maxPlayersPerGroup)); + } + } + + new AnnouncerTask(this).runTaskTimer(DungeonsXL.getInstance(), 0, 200); + } + + /** + * @return the announcer that has the name + */ + public Announcer getByName(String name) { + for (Announcer announcer : announcers) { + if (announcer.getName().equals(name)) { + return announcer; + } + } + + return null; + } + + /** + * @return the announcer that has the GUI + */ + public Announcer getByGUI(Inventory gui) { + for (Announcer announcer : announcers) { + if ((ChatColor.DARK_RED + announcer.getName()).equals(gui.getTitle())) { + return announcer; + } + } + + return null; + } + + /** + * @return the announcers + */ + public List getAnnouncers() { + return announcers; + } + + /** + * @param announcer + * the Announcer to add + */ + public void addAnnouncer(Announcer announcer) { + announcers.add(announcer); + } + + /** + * @param announcer + * the Announcer to remove + */ + public void removeAnnouncer(Announcer announcer) { + announcers.remove(announcer); + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/JoinCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/JoinCommand.java new file mode 100644 index 00000000..8084bb38 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/JoinCommand.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2016 Daniel Saukel + * + * 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.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.announcer.Announcer; +import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; +import io.github.dre2n.dungeonsxl.player.DInstancePlayer; +import io.github.dre2n.dungeonsxl.player.DPermissions; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * @author Daniel Saukel + */ +public class JoinCommand extends BRCommand { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + public JoinCommand() { + setCommand("join"); + setMinArgs(1); + setMaxArgs(1); + setHelp(DMessages.HELP_CMD_JOIN.getMessage()); + setPermission(DPermissions.JOIN.getNode()); + setPlayerCommand(true); + } + + @Override + public void onExecute(String[] args, CommandSender sender) { + DGlobalPlayer player = plugin.getDPlayers().getByPlayer((Player) sender); + if (player instanceof DInstancePlayer) { + MessageUtil.sendMessage(sender, DMessages.ERROR_LEAVE_GAME.getMessage()); + return; + } + + Announcer announcer = plugin.getAnnouncers().getByName(args[1]); + if (announcer != null) { + announcer.showGUI((Player) sender); + } + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java index bc9f9456..0d984a3d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java @@ -82,6 +82,7 @@ public class ReloadCommand extends BRCommand { plugin.loadTriggers(); plugin.loadDSigns(); plugin.loadDungeons(); + plugin.loadAnnouncers(DungeonsXL.ANNOUNCERS); MessageUtil.sendPluginTag(sender, plugin); MessageUtil.sendCenteredMessage(sender, DMessages.CMD_RELOAD_DONE.getMessage()); 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 4b896197..f7894dfe 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -26,6 +26,8 @@ import org.bukkit.configuration.file.YamlConfiguration; */ public enum DMessages implements Messages { + ANNOUNCER_CMD("Announcer_Cmd", "&4&l=> &6USE &4/DXL JOIN &v1 &6TO JOIN &4&l<="), + ANNOUNCER_CLICK("Announcer_Click", "&4&l=> &6CLICK HERE TO JOIN &4&l<="), CMD_BREAK_PROTECTED_MODE("Cmd_Break_ProtectedMode", "&6You may not break blocks protected by DungeonsXL anymore."), CMD_BREAK_BREAK_MODE("Cmd_Break_BreakMode", "&6You may break a block protected by DungeonsXL."), CMD_CHAT_DUNGEON_CHAT("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat"), @@ -101,6 +103,7 @@ public enum DMessages implements Messages { HELP_CMD_GROUP_SHOW("Help_Cmd_GroupShow", "/dxl group show [group] - Shows a group"), HELP_CMD_HELP("Help_Cmd_Help", "/dxl help - Shows the help page"), HELP_CMD_INVITE("Help_Cmd_Invite", "/dxl invite - Invite a player to edit a dungeon"), + HELP_CMD_JOIN("Help_Cmd_Join", "/dxl join [announcement] - Opens the GUI to join a group in an upcoming game"), HELP_CMD_ENTER("Help_Cmd_Enter", "/dxl enter ([joining group]) [target group] - Let the joining group enter the game of the target group"), HELP_CMD_LEAVE("Help_Cmd_Leave", "/dxl leave - Leaves the current dungeon"), HELP_CMD_LIST("Help_Cmd_List", "/dxl list ([dungeon|map|loaded]) ([dungeon]) - Lists all dungeons"), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index 8cb7120e..7cfbc319 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -19,6 +19,7 @@ package io.github.dre2n.dungeonsxl.config; import io.github.dre2n.commons.config.BRConfig; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -29,7 +30,7 @@ import org.bukkit.configuration.ConfigurationSection; */ public class MainConfig extends BRConfig { - public static final int CONFIG_VERSION = 6; + public static final int CONFIG_VERSION = 7; private String language = "en"; private boolean enableEconomy = false; @@ -43,6 +44,7 @@ public class MainConfig extends BRConfig { /* Misc */ private boolean sendFloorTitle = true; private Map externalMobProviders = new HashMap<>(); + private List groupColorPriority = new ArrayList<>(Arrays.asList((short) 11, (short) 14, (short) 4, (short) 5, (short) 10, (short) 1, (short) 0, (short) 15)); /* Secure Mode */ private boolean secureModeEnabled = false; @@ -115,6 +117,13 @@ public class MainConfig extends BRConfig { return externalMobProviders; } + /** + * @return the group colors + */ + public List getGroupColorPriority() { + return groupColorPriority; + } + /** * @return the tutorialEndGroup */ @@ -206,6 +215,10 @@ public class MainConfig extends BRConfig { config.createSection("externalMobProviders"); } + if (!config.contains("groupColorPriority")) { + config.set("groupColorPriority", groupColorPriority); + } + if (!config.contains("secureMode.enabled")) { config.set("secureMode.enabled", secureModeEnabled); } @@ -273,6 +286,10 @@ public class MainConfig extends BRConfig { externalMobProviders = config.getConfigurationSection("externalMobProviders").getValues(false); } + if (config.contains("groupColorPriority")) { + groupColorPriority = config.getShortList("groupColorPriority"); + } + if (config.contains("secureMode.enabled")) { secureModeEnabled = config.getBoolean("secureMode.enabled"); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java b/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java index d6f8e570..5a58f4a9 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java @@ -28,6 +28,7 @@ public class DGroupCreateEvent extends DGroupEvent implements Cancellable { public enum Cause { + ANNOUNCER, COMMAND, GROUP_SIGN, CUSTOM diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java new file mode 100644 index 00000000..36f083f9 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/GUIListener.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 Daniel Saukel + * + * 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.listener; + +import io.github.dre2n.commons.util.guiutil.ButtonClickEvent; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.announcer.Announcer; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +/** + * @author Daniel Saukel + */ +public class GUIListener implements Listener { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + @EventHandler + public void onButtonClick(ButtonClickEvent event) { + Inventory gui = event.getGUI(); + if (!plugin.getGUIs().contains(gui)) { + return; + } + + ItemStack button = event.getGUI().getItem(event.getSlot()); + Announcer announcer = plugin.getAnnouncers().getByGUI(gui); + if (announcer != null) { + announcer.clickGroupButton(event.getPlayer(), button); + } + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 4deff62d..a18c51c8 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -63,6 +63,10 @@ public class DGroup { private List rewards = new ArrayList<>(); private BukkitTask timeIsRunningTask; + public DGroup(Player player) { + this("Group_" + plugin.getDGroups().size(), player); + } + public DGroup(String name, Player player) { plugin.getDGroups().add(this); this.name = name; @@ -440,6 +444,13 @@ public class DGroup { return players.isEmpty(); } + /** + * @return if the group has been customized with a command + */ + public boolean isCustom() { + return !name.matches("Group_[0-9]{1,}"); + } + /* Actions */ /** * Remove the group from the List 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 c8e9db3b..ac106334 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java @@ -49,6 +49,7 @@ public enum DPermissions { IGNORE_TIME_LIMIT("ignoretimelimit", OP), INVITE("invite", OP), INSECURE("insecure", OP), + JOIN("join", TRUE), LEAVE("leave", TRUE), LIST("list", OP), LIVES("lives", TRUE), @@ -65,7 +66,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, LEAVE, LIVES, MAIN), + HALF_PLAYER("halfplayer", TRUE, CHAT, ESCAPE, GAME, HELP, JOIN, LEAVE, LIVES, MAIN), FULL_PLAYER("fullplayer", OP, HALF_PLAYER, GROUP); public static final String PREFIX = "dxl."; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java b/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java new file mode 100644 index 00000000..317dcde3 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2016 Daniel Saukel + * + * 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.task; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.announcer.Announcer; +import io.github.dre2n.dungeonsxl.announcer.Announcers; +import io.github.dre2n.dungeonsxl.player.DInstancePlayer; +import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author Daniel Saukel + */ +public class AnnouncerTask extends BukkitRunnable { + + private List announcers; + int index; + + public AnnouncerTask(Announcers announcers) { + this.announcers = announcers.getAnnouncers(); + index = 0; + } + + @Override + public void run() { + for (Player player : Bukkit.getOnlinePlayers()) { + if (!(DungeonsXL.getInstance().getDPlayers().getByPlayer(player) instanceof DInstancePlayer)) { + announcers.get(index).send(player); + } + } + + index++; + if (index == announcers.size()) { + index = 0; + } + } + +}