mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Fix & improve announcers
This commit is contained in:
parent
cb26c414bd
commit
57247ef96a
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.erethon</groupId>
|
||||
<artifactId>dungeonsxl</artifactId>
|
||||
<version>0.17.5-SNAPSHOT</version>
|
||||
<version>0.17.5</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>DungeonsXL</name>
|
||||
<url>https://dre2n.github.io</url>
|
||||
|
@ -23,10 +23,7 @@ import de.erethon.commons.config.MessageConfig;
|
||||
import de.erethon.commons.javaplugin.DREPlugin;
|
||||
import de.erethon.commons.javaplugin.DREPluginSettings;
|
||||
import de.erethon.commons.misc.FileUtil;
|
||||
import de.erethon.dungeonsxl.announcer.Announcer;
|
||||
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.config.DMessage;
|
||||
import de.erethon.dungeonsxl.config.MainConfig;
|
||||
@ -216,7 +213,7 @@ public class DungeonsXL extends DREPlugin {
|
||||
protections = new GlobalProtectionCache(this);
|
||||
dMobProviders = new ExternalMobProviderCache(this);
|
||||
dPlayers = new DPlayerCache(this);
|
||||
announcers = new AnnouncerCache();
|
||||
announcers = new AnnouncerCache(this);
|
||||
dClasses = new DClassCache(this);
|
||||
signScripts = new SignScriptCache();
|
||||
dCommands = new DCommandCache(this);
|
||||
@ -235,7 +232,7 @@ public class DungeonsXL extends DREPlugin {
|
||||
globalData.load();
|
||||
dMobProviders.init();
|
||||
dPlayers.init();
|
||||
initAnnouncerCache(ANNOUNCERS);
|
||||
announcers.init(ANNOUNCERS);
|
||||
dClasses.init(CLASSES);
|
||||
Bukkit.getPluginManager().registerEvents(new DMobListener(), this);
|
||||
signScripts.init(SIGNS);
|
||||
@ -367,18 +364,6 @@ public class DungeonsXL extends DREPlugin {
|
||||
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
|
||||
*/
|
||||
|
@ -41,7 +41,6 @@ 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.
|
||||
@ -351,7 +350,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());
|
||||
DColor color = DColor.getByWoolType(plugin.getCaliburn().getExItem(button));
|
||||
|
||||
for (DGroup group : dGroups) {
|
||||
if (dGroups.contains(pGroup) && pGroup != null && pGroup.isCustom() && pGroup.getCaptain() == player) {
|
||||
|
@ -16,11 +16,13 @@
|
||||
*/
|
||||
package de.erethon.dungeonsxl.announcer;
|
||||
|
||||
import de.erethon.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;
|
||||
|
||||
/**
|
||||
* Announcer instance manager.
|
||||
@ -29,10 +31,27 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
*/
|
||||
public class AnnouncerCache {
|
||||
|
||||
private BukkitTask announcerTask;
|
||||
private DungeonsXL plugin;
|
||||
|
||||
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
|
||||
* @return the announcer that has the name
|
||||
@ -82,18 +101,4 @@ public class AnnouncerCache {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package de.erethon.dungeonsxl.announcer;
|
||||
|
||||
import de.erethon.caliburn.category.Category;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -23,7 +24,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Wool;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
@ -46,7 +46,7 @@ public class AnnouncerListener implements Listener {
|
||||
Inventory gui = event.getInventory();
|
||||
ItemStack button = event.getCurrentItem();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package de.erethon.dungeonsxl.util;
|
||||
|
||||
import de.erethon.caliburn.item.ExItem;
|
||||
import de.erethon.caliburn.item.VanillaItem;
|
||||
import de.erethon.commons.compatibility.Version;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -92,6 +93,19 @@ public enum DColor {
|
||||
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
|
||||
* @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
|
||||
*/
|
||||
public static DColor getByChatColor(ChatColor color) {
|
||||
public static DColor getByWoolType(ExItem wool) {
|
||||
for (DColor dColor : values()) {
|
||||
if (dColor.chat == color) {
|
||||
if (dColor.woolMaterial == wool) {
|
||||
return dColor;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user