Notifications and stuffs?
This commit is contained in:
parent
03bd2ed2c1
commit
54d8fe21fb
@ -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<HubClient>
|
||||
|
||||
((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();
|
||||
|
@ -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<PlayerMailData>
|
||||
public class MailManager extends MiniClientPlugin<PlayerMailData> 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<PlayerMailData>
|
||||
});
|
||||
}
|
||||
|
||||
public void openShop(Player player)
|
||||
{
|
||||
_shop.attemptShopOpen(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void AddCommands()
|
||||
{
|
||||
addCommand(new MailCommand(this));
|
||||
}
|
||||
|
||||
public void archive(final MailMessage message, final Callback<Boolean> callback)
|
||||
{
|
||||
if (message.isArchived())
|
||||
@ -83,30 +68,9 @@ public class MailManager extends MiniClientPlugin<PlayerMailData>
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void showNotification(PlayerJoinEvent event)
|
||||
@Override
|
||||
public List<? extends Notification> 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<MailMessage> 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();
|
||||
}
|
||||
}
|
||||
|
@ -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<String> lines = new ArrayList<String>();
|
||||
|
||||
ArrayList<String> 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<Boolean>()
|
||||
{
|
||||
@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<String> formatMessage()
|
||||
{
|
||||
String mailMessage = ChatColor.translateAlternateColorCodes('&', _message); // Color the message
|
||||
|
||||
ArrayList<String> parts = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<MailManager>
|
||||
{
|
||||
public MailShop(MailManager plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
{
|
||||
super(plugin, clientManager, donationManager, "Mail Shop");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<MailManager, ? extends ShopBase<MailManager>> BuildPagesFor(Player player)
|
||||
{
|
||||
return new MailPage(Plugin, this, ClientManager, DonationManager, player);
|
||||
}
|
||||
}
|
@ -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<Boolean>()
|
||||
{
|
||||
@Override
|
||||
public void run(Boolean data)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
_page.Refresh();
|
||||
_player.playSound(_player.getLocation(), Sound.SPLASH, 1, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -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<MailManager, MailShop>
|
||||
{
|
||||
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<MailMessage> 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<String> lines = new ArrayList<String>();
|
||||
|
||||
ArrayList<String> message = formatMessage(mailMessage.getMessage());
|
||||
|
||||
lines.add("From: " + mailMessage.getSender());
|
||||
lines.add(" ");
|
||||
lines.addAll(message);
|
||||
|
||||
return lines.toArray(new String[lines.size()]);
|
||||
}
|
||||
|
||||
private ArrayList<String> formatMessage(String mailMessage)
|
||||
{
|
||||
mailMessage = ChatColor.translateAlternateColorCodes('&', mailMessage); // Color the message
|
||||
|
||||
ArrayList<String> parts = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
}
|
@ -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<Notifier> _notifiers;
|
||||
|
||||
public NotificationManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
{
|
||||
super("Notification", plugin);
|
||||
|
||||
_notifiers = new ArrayList<Notifier>();
|
||||
_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<Notification> getNotifications(Player player)
|
||||
{
|
||||
List<Notification> notifications = new ArrayList<Notification>();
|
||||
|
||||
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<Notification>
|
||||
{
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package mineplex.hub.notification.api;
|
||||
|
||||
public enum NotificationPriority
|
||||
{
|
||||
HIGH, NORMAL, LOW;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package mineplex.hub.notification.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Notifier
|
||||
{
|
||||
public List<? extends Notification> getNotifications(Player player);
|
||||
}
|
@ -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<MailManager>
|
||||
public class NotificationCommand extends CommandBase<NotificationManager>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
@ -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<NotificationManager>
|
||||
{
|
||||
public NotificationShop(NotificationManager plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
{
|
||||
super(plugin, clientManager, donationManager, "Notifications");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<NotificationManager, ? extends ShopBase<NotificationManager>> BuildPagesFor(Player player)
|
||||
{
|
||||
return new NotificationPage(Plugin, this, ClientManager, DonationManager, player);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<NotificationManager, NotificationShop>
|
||||
{
|
||||
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<Notification> 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user