Fix & improve announcers

This commit is contained in:
Daniel Saukel 2019-02-26 16:32:33 +01:00
parent cb26c414bd
commit 57247ef96a
6 changed files with 44 additions and 41 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.erethon</groupId> <groupId>de.erethon</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.17.5-SNAPSHOT</version> <version>0.17.5</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>DungeonsXL</name> <name>DungeonsXL</name>
<url>https://dre2n.github.io</url> <url>https://dre2n.github.io</url>

View File

@ -23,10 +23,7 @@ import de.erethon.commons.config.MessageConfig;
import de.erethon.commons.javaplugin.DREPlugin; import de.erethon.commons.javaplugin.DREPlugin;
import de.erethon.commons.javaplugin.DREPluginSettings; import de.erethon.commons.javaplugin.DREPluginSettings;
import de.erethon.commons.misc.FileUtil; import de.erethon.commons.misc.FileUtil;
import de.erethon.dungeonsxl.announcer.Announcer;
import de.erethon.dungeonsxl.announcer.AnnouncerCache; import de.erethon.dungeonsxl.announcer.AnnouncerCache;
import de.erethon.dungeonsxl.announcer.AnnouncerListener;
import de.erethon.dungeonsxl.announcer.AnnouncerTask;
import de.erethon.dungeonsxl.command.DCommandCache; import de.erethon.dungeonsxl.command.DCommandCache;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.config.MainConfig; import de.erethon.dungeonsxl.config.MainConfig;
@ -216,7 +213,7 @@ public class DungeonsXL extends DREPlugin {
protections = new GlobalProtectionCache(this); protections = new GlobalProtectionCache(this);
dMobProviders = new ExternalMobProviderCache(this); dMobProviders = new ExternalMobProviderCache(this);
dPlayers = new DPlayerCache(this); dPlayers = new DPlayerCache(this);
announcers = new AnnouncerCache(); announcers = new AnnouncerCache(this);
dClasses = new DClassCache(this); dClasses = new DClassCache(this);
signScripts = new SignScriptCache(); signScripts = new SignScriptCache();
dCommands = new DCommandCache(this); dCommands = new DCommandCache(this);
@ -235,7 +232,7 @@ public class DungeonsXL extends DREPlugin {
globalData.load(); globalData.load();
dMobProviders.init(); dMobProviders.init();
dPlayers.init(); dPlayers.init();
initAnnouncerCache(ANNOUNCERS); announcers.init(ANNOUNCERS);
dClasses.init(CLASSES); dClasses.init(CLASSES);
Bukkit.getPluginManager().registerEvents(new DMobListener(), this); Bukkit.getPluginManager().registerEvents(new DMobListener(), this);
signScripts.init(SIGNS); signScripts.init(SIGNS);
@ -367,18 +364,6 @@ public class DungeonsXL extends DREPlugin {
return announcers; return announcers;
} }
private void initAnnouncerCache(File file) {
if (file.isDirectory()) {
for (File script : FileUtil.getFilesForFolder(file)) {
announcers.addAnnouncer(new Announcer(this, script));
}
}
if (!announcers.getAnnouncers().isEmpty()) {
announcers.setAnnouncerTask(new AnnouncerTask(this).runTaskTimer(this, mainConfig.getAnnouncmentInterval(), mainConfig.getAnnouncmentInterval()));
}
Bukkit.getPluginManager().registerEvents(new AnnouncerListener(this), this);
}
/** /**
* @return the loaded instance of DClassCache * @return the loaded instance of DClassCache
*/ */

View File

@ -41,7 +41,6 @@ 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.
@ -351,7 +350,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()); DColor color = DColor.getByWoolType(plugin.getCaliburn().getExItem(button));
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) {

View File

@ -16,11 +16,13 @@
*/ */
package de.erethon.dungeonsxl.announcer; package de.erethon.dungeonsxl.announcer;
import de.erethon.dungeonsxl.DungeonsXL;
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;
/** /**
* Announcer instance manager. * Announcer instance manager.
@ -29,10 +31,27 @@ import org.bukkit.scheduler.BukkitTask;
*/ */
public class AnnouncerCache { public class AnnouncerCache {
private BukkitTask announcerTask; private DungeonsXL plugin;
private List<Announcer> announcers = new ArrayList<>(); private List<Announcer> announcers = new ArrayList<>();
public AnnouncerCache(DungeonsXL plugin) {
this.plugin = plugin;
}
public void init(File folder) {
if (!folder.exists()) {
folder.mkdir();
}
for (File file : folder.listFiles()) {
addAnnouncer(new Announcer(plugin, file));
}
if (!announcers.isEmpty()) {
new AnnouncerTask(plugin).runTaskTimer(plugin, plugin.getMainConfig().getAnnouncmentInterval(), plugin.getMainConfig().getAnnouncmentInterval());
}
Bukkit.getPluginManager().registerEvents(new AnnouncerListener(plugin), plugin);
}
/** /**
* @param name the name * @param name the name
* @return the announcer that has the name * @return the announcer that has the name
@ -82,18 +101,4 @@ public class AnnouncerCache {
announcers.remove(announcer); announcers.remove(announcer);
} }
/**
* @return the AnnouncerTask
*/
public BukkitTask getAnnouncerTask() {
return announcerTask;
}
/**
* @param announcerTask the AnnouncerTask to set
*/
public void setAnnouncerTask(BukkitTask announcerTask) {
this.announcerTask = announcerTask;
}
} }

View File

@ -16,6 +16,7 @@
*/ */
package de.erethon.dungeonsxl.announcer; package de.erethon.dungeonsxl.announcer;
import de.erethon.caliburn.category.Category;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -23,7 +24,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Wool;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
@ -46,7 +46,7 @@ public class AnnouncerListener implements Listener {
Inventory gui = event.getInventory(); Inventory gui = event.getInventory();
ItemStack button = event.getCurrentItem(); ItemStack button = event.getCurrentItem();
Announcer announcer = announcers.getByGUI(gui); Announcer announcer = announcers.getByGUI(gui);
if (announcer != null && button != null && button.getData() instanceof Wool) { if (announcer != null && button != null && Category.WOOL.containsMaterial(button.getType())) {
announcer.clickGroupButton(player, button); announcer.clickGroupButton(player, button);
} }
} }

View File

@ -16,6 +16,7 @@
*/ */
package de.erethon.dungeonsxl.util; package de.erethon.dungeonsxl.util;
import de.erethon.caliburn.item.ExItem;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.compatibility.Version; import de.erethon.commons.compatibility.Version;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -92,6 +93,19 @@ public enum DColor {
return woolMaterial; return woolMaterial;
} }
/**
* @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;
}
/** /**
* @param color the DyeColor to check * @param color the DyeColor to check
* @return the matching DColor or null * @return the matching DColor or null
@ -106,12 +120,12 @@ public enum DColor {
} }
/** /**
* @param color the ChatColor to check * @param wool the wool item to check
* @return the matching DColor or null * @return the matching DColor or null
*/ */
public static DColor getByChatColor(ChatColor color) { public static DColor getByWoolType(ExItem wool) {
for (DColor dColor : values()) { for (DColor dColor : values()) {
if (dColor.chat == color) { if (dColor.woolMaterial == wool) {
return dColor; return dColor;
} }
} }