Fixed announcers

This commit is contained in:
Daniel Saukel 2017-10-05 16:45:10 +02:00
parent 704caef70b
commit a3e890d704
4 changed files with 50 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import io.github.dre2n.dungeonsxl.config.DMessage;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.util.DColor;
import io.github.dre2n.dungeonsxl.util.GUIUtil; import io.github.dre2n.dungeonsxl.util.GUIUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -42,6 +43,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Wool;
/** /**
* Represents a game announcement. * Represents a game announcement.
@ -356,7 +358,6 @@ public class Announcer {
updateButtons(); updateButtons();
Inventory gui = GUIUtil.createGUI(plugin, ChatColor.DARK_RED + name, buttons); Inventory gui = GUIUtil.createGUI(plugin, ChatColor.DARK_RED + name, buttons);
plugin.addGUI(gui); plugin.addGUI(gui);
player.closeInventory();
player.openInventory(gui); player.openInventory(gui);
} }
@ -367,6 +368,7 @@ public class Announcer {
public void clickGroupButton(Player player, ItemStack button) { public void clickGroupButton(Player player, ItemStack button) {
DGroup dGroup = getDGroupByButton(button); DGroup dGroup = getDGroupByButton(button);
DGroup pGroup = DGroup.getByPlayer(player); DGroup pGroup = DGroup.getByPlayer(player);
DColor color = DColor.getByDyeColor(((Wool) button.getData()).getColor());
for (DGroup group : dGroups) { for (DGroup group : dGroups) {
if (dGroups.contains(pGroup) && pGroup != null && pGroup.isCustom() && pGroup.getCaptain() == player) { 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); DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.ANNOUNCER);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) { 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) { } else if (dGroup == null && pGroup != null) {
pGroup.setName(color);
dGroups.set(buttons.indexOf(button), pGroup); dGroups.set(buttons.indexOf(button), pGroup);
} else if (pGroup != null && dGroups.contains(pGroup) && pGroup != dGroup) { } else if (pGroup != null && dGroups.contains(pGroup) && pGroup != dGroup) {
dGroups.set(dGroups.indexOf(pGroup), null); dGroups.set(dGroups.indexOf(pGroup), null);
pGroup.setName(color);
dGroups.set(buttons.indexOf(button), pGroup); dGroups.set(buttons.indexOf(button), pGroup);
} }

View File

@ -21,6 +21,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -45,6 +46,7 @@ public class AnnouncerCache {
} }
} }
startAnnouncerTask(plugin.getMainConfig().getAnnouncmentInterval()); startAnnouncerTask(plugin.getMainConfig().getAnnouncmentInterval());
Bukkit.getPluginManager().registerEvents(new AnnouncerListener(), plugin);
} }
/** /**

View File

@ -77,7 +77,11 @@ public class DGroup {
private int lives = -1; private int lives = -1;
public DGroup(Player player) { 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) { public DGroup(String name, Player player) {
@ -189,6 +193,14 @@ public class DGroup {
this.name = name; this.name = name;
} }
/**
* @param name
* the name to set
*/
public void setName(DColor color) {
name = color.toString().replace("_", " ");
}
/** /**
* @return the captain * @return the captain
*/ */

View File

@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.util;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.inventory.ItemStack;
/** /**
* Links different color types together. * Links different color types together.
@ -79,4 +80,32 @@ public enum DColor {
return dye.getWoolData(); 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;
}
} }