From a3e890d70455bd413cc6b6835807ee596b1d5200 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 5 Oct 2017 16:45:10 +0200 Subject: [PATCH] Fixed announcers --- .../dre2n/dungeonsxl/announcer/Announcer.java | 8 +++-- .../dungeonsxl/announcer/AnnouncerCache.java | 2 ++ .../dre2n/dungeonsxl/player/DGroup.java | 14 ++++++++- .../github/dre2n/dungeonsxl/util/DColor.java | 29 +++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) 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 0940a521..5fd5e2c8 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -24,6 +24,7 @@ import io.github.dre2n.dungeonsxl.config.DMessage; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.player.DGroup; +import io.github.dre2n.dungeonsxl.util.DColor; import io.github.dre2n.dungeonsxl.util.GUIUtil; import java.io.File; import java.util.ArrayList; @@ -42,6 +43,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.material.Wool; /** * Represents a game announcement. @@ -356,7 +358,6 @@ public class Announcer { updateButtons(); Inventory gui = GUIUtil.createGUI(plugin, ChatColor.DARK_RED + name, buttons); plugin.addGUI(gui); - player.closeInventory(); player.openInventory(gui); } @@ -367,6 +368,7 @@ public class Announcer { public void clickGroupButton(Player player, ItemStack button) { DGroup dGroup = getDGroupByButton(button); DGroup pGroup = DGroup.getByPlayer(player); + DColor color = DColor.getByDyeColor(((Wool) button.getData()).getColor()); for (DGroup group : dGroups) { if (dGroups.contains(pGroup) && pGroup != null && pGroup.isCustom() && pGroup.getCaptain() == player) { @@ -387,14 +389,16 @@ public class Announcer { DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.ANNOUNCER); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { - dGroups.set(buttons.indexOf(button), new DGroup(player)); + dGroups.set(buttons.indexOf(button), new DGroup(player, color)); } } else if (dGroup == null && pGroup != null) { + pGroup.setName(color); dGroups.set(buttons.indexOf(button), pGroup); } else if (pGroup != null && dGroups.contains(pGroup) && pGroup != dGroup) { dGroups.set(dGroups.indexOf(pGroup), null); + pGroup.setName(color); dGroups.set(buttons.indexOf(button), pGroup); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerCache.java b/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerCache.java index e9333779..d64a04f3 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerCache.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerCache.java @@ -21,6 +21,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import java.io.File; import java.util.ArrayList; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.inventory.Inventory; import org.bukkit.scheduler.BukkitTask; @@ -45,6 +46,7 @@ public class AnnouncerCache { } } startAnnouncerTask(plugin.getMainConfig().getAnnouncmentInterval()); + Bukkit.getPluginManager().registerEvents(new AnnouncerListener(), plugin); } /** 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 00b24d69..f10df5c4 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -77,7 +77,11 @@ public class DGroup { private int lives = -1; public DGroup(Player player) { - this(DungeonsXL.getInstance().getMainConfig().getGroupColorPriority().get(DungeonsXL.getInstance().getDGroups().size()).toString(), player); + this("Group " + DungeonsXL.getInstance().getDGroups().size(), player); + } + + public DGroup(Player player, DColor color) { + this(color.toString().replace("_", " "), player); } public DGroup(String name, Player player) { @@ -189,6 +193,14 @@ public class DGroup { this.name = name; } + /** + * @param name + * the name to set + */ + public void setName(DColor color) { + name = color.toString().replace("_", " "); + } + /** * @return the captain */ diff --git a/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java b/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java index b683e056..b087c522 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/util/DColor.java @@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.util; import org.bukkit.ChatColor; import org.bukkit.DyeColor; +import org.bukkit.inventory.ItemStack; /** * Links different color types together. @@ -79,4 +80,32 @@ public enum DColor { return dye.getWoolData(); } + /** + * @param color + * the DyeColor to check + * @return the matching DColor or null + */ + public static DColor getByDyeColor(DyeColor color) { + for (DColor dColor : values()) { + if (dColor.dye == color) { + return dColor; + } + } + return null; + } + + /** + * @param color + * the ChatColor to check + * @return the matching DColor or null + */ + public static DColor getByChatColor(ChatColor color) { + for (DColor dColor : values()) { + if (dColor.chat == color) { + return dColor; + } + } + return null; + } + }