From 54d8fe21fb84aa4f592dae625a4692f87f2d12cd Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 4 Dec 2014 22:48:54 -0600 Subject: [PATCH] Notifications and stuffs? --- .../src/mineplex/hub/HubManager.java | 4 +- .../src/mineplex/hub/mail/MailManager.java | 58 ++------- .../src/mineplex/hub/mail/MailMessage.java | 122 +++++++++++++++++- .../src/mineplex/hub/mail/MailRepository.java | 8 +- .../src/mineplex/hub/mail/gui/MailShop.java | 25 ---- .../hub/mail/gui/button/MailButton.java | 50 ------- .../mineplex/hub/mail/gui/page/MailPage.java | 87 ------------- .../hub/notification/NotificationManager.java | 112 ++++++++++++++++ .../hub/notification/api/Notification.java | 21 +++ .../api/NotificationPriority.java | 6 + .../hub/notification/api/Notifier.java | 10 ++ .../command/NotificationCommand.java} | 16 +-- .../notification/gui/NotificationShop.java | 25 ++++ .../gui/button/NotificationButton.java | 37 ++++++ .../gui/page/NotificationPage.java | 51 ++++++++ 15 files changed, 407 insertions(+), 225 deletions(-) delete mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/MailShop.java delete mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/button/MailButton.java delete mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/page/MailPage.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/notification/NotificationManager.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/Notification.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/NotificationPriority.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/Notifier.java rename Plugins/Mineplex.Hub/src/mineplex/hub/{mail/command/MailCommand.java => notification/command/NotificationCommand.java} (50%) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/NotificationShop.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/button/NotificationButton.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/page/NotificationPage.java diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 5f999f500..0e790db34 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -92,6 +92,7 @@ import mineplex.hub.modules.TextManager; import mineplex.hub.modules.UHCManager; import mineplex.hub.modules.VisibilityManager; import mineplex.hub.modules.WorldManager; +import mineplex.hub.notification.NotificationManager; import mineplex.hub.party.Party; import mineplex.hub.party.PartyManager; import mineplex.hub.poll.PollManager; @@ -193,7 +194,8 @@ public class HubManager extends MiniClientPlugin ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true; - new MailManager(_plugin, _clientManager, _donationManager); + NotificationManager notificationManager = new NotificationManager(plugin, clientManager, donationManager); + new MailManager(_plugin, notificationManager); _ruleBook = ItemStackFactory.Instance.CreateStack(Material.WRITTEN_BOOK, (byte)0, 1, ChatColor.GREEN + "Rule Book", new String[] { }); BookMeta meta = (BookMeta)_ruleBook.getItemMeta(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java index fc9c167e8..a5fd6ebb4 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java @@ -5,30 +5,26 @@ import java.util.List; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniClientPlugin; -import mineplex.core.account.CoreClientManager; -import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.Callback; -import mineplex.core.donation.DonationManager; -import mineplex.hub.mail.command.MailCommand; -import mineplex.hub.mail.gui.MailShop; +import mineplex.hub.notification.NotificationManager; +import mineplex.hub.notification.api.Notification; +import mineplex.hub.notification.api.Notifier; -public class MailManager extends MiniClientPlugin +public class MailManager extends MiniClientPlugin implements Notifier { private MailRepository _repository; - private MailShop _shop; - public MailManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) + public MailManager(JavaPlugin plugin, NotificationManager notificationManager) { super("Mail", plugin); - _repository = new MailRepository(plugin); - _shop = new MailShop(this, clientManager, donationManager); - } + _repository = new MailRepository(plugin, this); + notificationManager.addNotifier(this); + } @Override protected PlayerMailData AddPlayer(String player) @@ -49,17 +45,6 @@ public class MailManager extends MiniClientPlugin }); } - public void openShop(Player player) - { - _shop.attemptShopOpen(player); - } - - @Override - public void AddCommands() - { - addCommand(new MailCommand(this)); - } - public void archive(final MailMessage message, final Callback callback) { if (message.isArchived()) @@ -83,30 +68,9 @@ public class MailManager extends MiniClientPlugin }); } - @EventHandler - public void showNotification(PlayerJoinEvent event) + @Override + public List getNotifications(Player player) { - final Player player = event.getPlayer(); - - runSyncLater(new Runnable() - { - @Override - public void run() - { - if (player.isOnline()) - { - PlayerMailData mailData = Get(player); - if (mailData != null) - { - List unreadMessages = mailData.getUnreadMessages(); - if (unreadMessages.size() > 0) - { - JsonMessage message = new JsonMessage("You have unread notifications. Click here to read them!"); - message.color("red"); - } - } - } - } - }, 20 * 8); + return Get(player).getUnreadMessages(); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailMessage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailMessage.java index 857294ba0..f33baf42a 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailMessage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailMessage.java @@ -1,9 +1,25 @@ package mineplex.hub.mail; import java.sql.Timestamp; +import java.util.ArrayList; -public class MailMessage +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UtilTime; +import mineplex.hub.notification.api.Notification; +import mineplex.hub.notification.api.NotificationPriority; + +public class MailMessage implements Notification { + private MailManager _manager; + private int _messageId; private String _sender; private String _message; @@ -11,8 +27,10 @@ public class MailMessage private boolean _deleted; private Timestamp _timeSent; - public MailMessage(int messageId, String sender, String message, boolean archived, boolean deleted, Timestamp timeSent) + public MailMessage(MailManager manager, int messageId, String sender, String message, boolean archived, boolean deleted, Timestamp timeSent) { + _manager = manager; + _messageId = messageId; _sender = sender; _message = message; @@ -80,4 +98,104 @@ public class MailMessage { _timeSent = timeSent; } + + @Override + public String getTitle() + { + return "Mail Message"; + } + + @Override + public String[] getText() + { + ArrayList lines = new ArrayList(); + + ArrayList message = formatMessage(); + + long timeDifference = System.currentTimeMillis() - getTime(); + + + lines.add(ChatColor.RESET + C.cYellow + "From: " + C.cWhite + _sender); + lines.add(ChatColor.RESET + C.cYellow + "Sent: " + C.cWhite + UtilTime.convertString(timeDifference, 0, UtilTime.TimeUnit.FIT) + " Ago"); + lines.add(" "); + lines.addAll(message); + + return lines.toArray(new String[lines.size()]); + } + + @Override + public long getTime() + { + return _timeSent.getTime(); + } + + @Override + public Material getMaterial() + { + return Material.PAPER; + } + + @Override + public byte getData() + { + return 0; + } + + @Override + public void clicked(final InventoryClickEvent event) + { + if (event.getClick() == ClickType.SHIFT_RIGHT) + { + _manager.archive(this, new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + { + Player player = (Player) event.getWhoClicked(); + player.playSound(player.getLocation(), Sound.SPLASH, 1, 0); + } + } + }); + } + } + + @Override + public NotificationPriority getPriority() + { + return NotificationPriority.NORMAL; + } + + private ArrayList formatMessage() + { + String mailMessage = ChatColor.translateAlternateColorCodes('&', _message); // Color the message + + ArrayList parts = new ArrayList(); + int breakIndex = 0; + int charCount = 0; + + for (String s : mailMessage.split("\\\\n")) + { + for (int currIndex = 0; currIndex < s.length(); currIndex++) + { + charCount++; + char c = s.charAt(currIndex); + + if ((charCount >= 36 && c == ' ') || c == '\n') + { + // New Line + parts.add(ChatColor.RESET + s.substring(breakIndex, currIndex).trim()); + breakIndex = currIndex; + charCount = 0; + } + } + // Add final part + parts.add(ChatColor.RESET + s.substring(breakIndex).trim()); + charCount = 0; + breakIndex = 0; + } + + return parts; + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java index ff94cb24e..5754a9a41 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java @@ -17,9 +17,13 @@ import org.jooq.impl.DSL; public class MailRepository extends RepositoryBase { - public MailRepository(JavaPlugin plugin) + private MailManager _manager; + + public MailRepository(JavaPlugin plugin, MailManager manager) { super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh"); + + _manager = manager; } @Override @@ -63,7 +67,7 @@ public class MailRepository extends RepositoryBase private MailMessage createMessage(MailRecord record) { - return new MailMessage(record.getId(), record.getSender(), record.getMessage(), (record.getArchived() & 0x01) != 0, (record.getDeleted() & 0x01) != 0, record.getTimeSent()); + return new MailMessage(_manager, record.getId(), record.getSender(), record.getMessage(), (record.getArchived() & 0x01) != 0, (record.getDeleted() & 0x01) != 0, record.getTimeSent()); } public boolean archive(MailMessage mailMessage) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/MailShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/MailShop.java deleted file mode 100644 index 1bb0bde48..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/MailShop.java +++ /dev/null @@ -1,25 +0,0 @@ -package mineplex.hub.mail.gui; - -import org.bukkit.entity.Player; - -import mineplex.core.account.CoreClientManager; -import mineplex.core.common.CurrencyType; -import mineplex.core.donation.DonationManager; -import mineplex.core.shop.ShopBase; -import mineplex.core.shop.page.ShopPageBase; -import mineplex.hub.mail.MailManager; -import mineplex.hub.mail.gui.page.MailPage; - -public class MailShop extends ShopBase -{ - public MailShop(MailManager plugin, CoreClientManager clientManager, DonationManager donationManager) - { - super(plugin, clientManager, donationManager, "Mail Shop"); - } - - @Override - protected ShopPageBase> BuildPagesFor(Player player) - { - return new MailPage(Plugin, this, ClientManager, DonationManager, player); - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/button/MailButton.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/button/MailButton.java deleted file mode 100644 index d322c77c5..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/button/MailButton.java +++ /dev/null @@ -1,50 +0,0 @@ -package mineplex.hub.mail.gui.button; - -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import mineplex.core.common.util.Callback; -import mineplex.core.shop.item.IButton; -import mineplex.hub.mail.MailManager; -import mineplex.hub.mail.MailMessage; -import mineplex.hub.mail.gui.page.MailPage; - -public class MailButton implements IButton -{ - private MailManager _manager; - private MailPage _page; - private MailMessage _message; - - private Player _player; - - public MailButton(MailManager manager, Player player, MailPage page, MailMessage message) - { - _manager = manager; - _page = page; - _message = message; - _player = player; - } - - @Override - public void ClickedLeft(Player player) - { - - } - - @Override - public void ClickedRight(Player player) - { - _manager.archive(_message, new Callback() - { - @Override - public void run(Boolean data) - { - if (data) - { - _page.Refresh(); - _player.playSound(_player.getLocation(), Sound.SPLASH, 1, 0); - } - } - }); - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/page/MailPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/page/MailPage.java deleted file mode 100644 index ba44f2a9f..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/gui/page/MailPage.java +++ /dev/null @@ -1,87 +0,0 @@ -package mineplex.hub.mail.gui.page; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import mineplex.core.account.CoreClientManager; -import mineplex.core.donation.DonationManager; -import mineplex.core.shop.item.ShopItem; -import mineplex.core.shop.page.ShopPageBase; -import mineplex.hub.mail.MailManager; -import mineplex.hub.mail.MailMessage; -import mineplex.hub.mail.gui.MailShop; -import mineplex.hub.mail.gui.button.MailButton; - -public class MailPage extends ShopPageBase -{ - public MailPage(MailManager plugin, MailShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) - { - super(plugin, shop, clientManager, donationManager, "Mail", player); - - Refresh(); - } - - @Override - protected void BuildPage() - { - List messages = Plugin.Get(Player.getName()).getMessages(); - - for (int i = 0; i < messages.size(); i++) - { - MailMessage message = messages.get(i); - - ShopItem item = getItem(message); - System.out.println(message.getMessage()); - - AddButton(i, item, new MailButton(Plugin, Player, this, message)); - } - } - - private ShopItem getItem(MailMessage message) - { - ShopItem shopItem = new ShopItem(Material.PAPER, "Mail Message", parseMessage(message), 1, false); - - return shopItem; - } - - private String[] parseMessage(MailMessage mailMessage) - { - ArrayList lines = new ArrayList(); - - ArrayList message = formatMessage(mailMessage.getMessage()); - - lines.add("From: " + mailMessage.getSender()); - lines.add(" "); - lines.addAll(message); - - return lines.toArray(new String[lines.size()]); - } - - private ArrayList formatMessage(String mailMessage) - { - mailMessage = ChatColor.translateAlternateColorCodes('&', mailMessage); // Color the message - - ArrayList parts = new ArrayList(); - int breakIndex = 0; - int charCount = 0; - - for (int currIndex = 0; currIndex < mailMessage.length(); currIndex++) - { - charCount++; - char c = mailMessage.charAt(currIndex); - - if ((charCount >= 50 && c == ' ') || c == '\n') - { - // New Line - parts.add(mailMessage.substring(breakIndex, currIndex)); - breakIndex = currIndex; - } - } - - return parts; - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/notification/NotificationManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/NotificationManager.java new file mode 100644 index 000000000..49d5cd4b3 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/NotificationManager.java @@ -0,0 +1,112 @@ +package mineplex.hub.notification; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.Color; +import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.donation.DonationManager; +import mineplex.hub.notification.api.Notification; +import mineplex.hub.notification.api.Notifier; +import mineplex.hub.notification.command.NotificationCommand; +import mineplex.hub.notification.gui.NotificationShop; + +public class NotificationManager extends MiniPlugin +{ + private static NotificationComparator COMPARATOR = new NotificationComparator(); + + private NotificationShop _shop; + private List _notifiers; + + public NotificationManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super("Notification", plugin); + + _notifiers = new ArrayList(); + _shop = new NotificationShop(this, clientManager, donationManager); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + final Player player = event.getPlayer(); + + runSyncLater(new Runnable() + { + @Override + public void run() + { + if (player.isOnline()) + { + if (getNotifications(player).size() > 0) + { + JsonMessage message = new JsonMessage("You have unread notifications. Click here to read them!"); + message.color(Color.RED).click(ClickEvent.RUN_COMMAND, "/notifications"); + message.send(JsonMessage.MessageType.SYSTEM_MESSAGE, player); + } + } + } + }, 20 * 8); + } + + public List getNotifications(Player player) + { + List notifications = new ArrayList(); + + for (Notifier notifier : _notifiers) + { + notifications.addAll(notifier.getNotifications(player)); + } + + notifications.sort(COMPARATOR); + + return notifications; + } + + public void addNotifier(Notifier notifier) + { + _notifiers.add(notifier); + } + + public void clearNotifiers() + { + _notifiers.clear(); + } + + public void openShop(Player caller) + { + _shop.attemptShopOpen(caller); + } + + @Override + public void AddCommands() + { + addCommand(new NotificationCommand(this)); + } + + private static class NotificationComparator implements Comparator + { + @Override + public int compare(Notification n1, Notification n2) + { + if (n1.getPriority() == n2.getPriority()) + { + return (int) (n1.getTime() - n2.getTime()); + } + else + { + return n1.getPriority().ordinal() - n2.getPriority().ordinal(); + } + } + + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/Notification.java b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/Notification.java new file mode 100644 index 000000000..5e2997dc3 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/Notification.java @@ -0,0 +1,21 @@ +package mineplex.hub.notification.api; + +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryClickEvent; + +public interface Notification +{ + public String getTitle(); + + public String[] getText(); + + public long getTime(); + + public Material getMaterial(); + + public byte getData(); + + public void clicked(InventoryClickEvent event); + + public NotificationPriority getPriority(); +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/NotificationPriority.java b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/NotificationPriority.java new file mode 100644 index 000000000..79ac9723b --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/NotificationPriority.java @@ -0,0 +1,6 @@ +package mineplex.hub.notification.api; + +public enum NotificationPriority +{ + HIGH, NORMAL, LOW; +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/Notifier.java b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/Notifier.java new file mode 100644 index 000000000..51c61b235 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/api/Notifier.java @@ -0,0 +1,10 @@ +package mineplex.hub.notification.api; + +import java.util.List; + +import org.bukkit.entity.Player; + +public interface Notifier +{ + public List getNotifications(Player player); +} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/command/MailCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/command/NotificationCommand.java similarity index 50% rename from Plugins/Mineplex.Hub/src/mineplex/hub/mail/command/MailCommand.java rename to Plugins/Mineplex.Hub/src/mineplex/hub/notification/command/NotificationCommand.java index b9a57b351..789a9896c 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/command/MailCommand.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/command/NotificationCommand.java @@ -1,4 +1,4 @@ -package mineplex.hub.mail.command; +package mineplex.hub.notification.command; import org.bukkit.entity.Player; @@ -7,24 +7,18 @@ import mineplex.core.common.Rank; import mineplex.hub.mail.MailManager; import mineplex.hub.mail.MailMessage; import mineplex.hub.mail.PlayerMailData; +import mineplex.hub.notification.NotificationManager; -public class MailCommand extends CommandBase +public class NotificationCommand extends CommandBase { - public MailCommand(MailManager plugin) + public NotificationCommand(NotificationManager plugin) { - super(plugin, Rank.ALL, "mail"); + super(plugin, Rank.ALL, "notifications"); } @Override public void Execute(Player caller, String[] args) { - PlayerMailData mailData = Plugin.Get(caller); - - for (MailMessage message : mailData.getMessages()) - { - caller.sendMessage(message.getMessage()); - } - Plugin.openShop(caller); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/NotificationShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/NotificationShop.java new file mode 100644 index 000000000..20a7a1745 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/NotificationShop.java @@ -0,0 +1,25 @@ +package mineplex.hub.notification.gui; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.hub.mail.MailManager; +import mineplex.hub.notification.NotificationManager; +import mineplex.hub.notification.gui.page.NotificationPage; + +public class NotificationShop extends ShopBase +{ + public NotificationShop(NotificationManager plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Notifications"); + } + + @Override + protected ShopPageBase> BuildPagesFor(Player player) + { + return new NotificationPage(Plugin, this, ClientManager, DonationManager, player); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/button/NotificationButton.java b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/button/NotificationButton.java new file mode 100644 index 000000000..e5a9e5afa --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/button/NotificationButton.java @@ -0,0 +1,37 @@ +package mineplex.hub.notification.gui.button; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; + +import mineplex.core.common.util.Callback; +import mineplex.core.shop.item.IButton; +import mineplex.hub.mail.MailManager; +import mineplex.hub.mail.MailMessage; +import mineplex.hub.notification.NotificationManager; +import mineplex.hub.notification.api.Notification; +import mineplex.hub.notification.gui.page.NotificationPage; + +public class NotificationButton implements IButton +{ + private NotificationManager _manager; + private NotificationPage _page; + private Notification _notification; + + private Player _player; + + public NotificationButton(NotificationManager manager, Player player, NotificationPage page, Notification notification) + { + _manager = manager; + _page = page; + _notification = notification; + _player = player; + } + + @Override + public void Clicked(InventoryClickEvent event) + { + _notification.clicked(event); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/page/NotificationPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/page/NotificationPage.java new file mode 100644 index 000000000..02d9e918e --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/notification/gui/page/NotificationPage.java @@ -0,0 +1,51 @@ +package mineplex.hub.notification.gui.page; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilTime; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.hub.mail.MailManager; +import mineplex.hub.mail.MailMessage; +import mineplex.hub.notification.NotificationManager; +import mineplex.hub.notification.api.Notification; +import mineplex.hub.notification.gui.NotificationShop; +import mineplex.hub.notification.gui.button.NotificationButton; + +public class NotificationPage extends ShopPageBase +{ + public NotificationPage(NotificationManager plugin, NotificationShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) + { + super(plugin, shop, clientManager, donationManager, "Notifications", player); + + Refresh(); + } + + @Override + protected void BuildPage() + { + List notifications = Plugin.getNotifications(Player); + + for (int i = 0; i < notifications.size(); i++) + { + Notification message = notifications.get(i); + + ShopItem item = getItem(message); + + AddButton(i, item, new NotificationButton(Plugin, Player, this, message)); + } + } + + private ShopItem getItem(Notification notification) + { + return new ShopItem(notification.getMaterial(), notification.getData(), notification.getTitle(), notification.getTitle(), notification.getText(), 1, false, false); + } +}