Fix Party Redis. Improve Party UI. General testing and fixing.

This commit is contained in:
TadahTech 2016-06-23 02:39:05 -05:00
parent 2453f82061
commit fb6a772eb0
19 changed files with 351 additions and 74 deletions

View File

@ -117,7 +117,7 @@ public abstract class PlayerInputActionMenu implements Listener
p.activeContainer.addSlotListener(p); // Set the items to the items from the inventory given
_currentInventory = container.getBukkitView().getTopInventory();
_currentInventory.setItem(0, new ItemBuilder(Material.PAPER).setRawTitle("Players's Name").build());
_currentInventory.setItem(0, new ItemBuilder(Material.PAPER).setRawTitle("Input Text...").build());
_currentInventory.setItem(2, new ItemBuilder(Material.PAPER).setRawTitle("Search").build());
}

View File

@ -10,13 +10,15 @@ public class InviteData
private String _invitedBy;
private long _timeStamp;
private long _expires;
private String _serverFrom;
public InviteData(String invitedBy, String invitedTo, long timeStamp)
public InviteData(String invitedBy, String invitedTo, long timeStamp, String serverFrom)
{
_invitedBy = invitedBy;
_invitedTo = invitedTo;
_timeStamp = timeStamp;
_expires = timeStamp + 60000;
_serverFrom = serverFrom;
}
public long getTimeRemaining()
@ -48,4 +50,9 @@ public class InviteData
{
return _expires;
}
public String getServerFrom()
{
return _serverFrom;
}
}

View File

@ -138,6 +138,11 @@ public class PartyCommand extends CommandBase<PartyManager>
{
if (party == null)
{
if(Plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), caller.getName()))
{
Lang.ALREADY_INVITED.send(caller, target);
return;
}
Lang.INVITE_SUCCESS_PLAYER.send(caller, target);
} else
{
@ -173,7 +178,7 @@ public class PartyCommand extends CommandBase<PartyManager>
Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName());
Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName());
Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName(), Plugin.getServerName());
Plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName());
return;
@ -191,7 +196,7 @@ public class PartyCommand extends CommandBase<PartyManager>
Lang.NOT_INVITED.send(caller, target);
return;
}
caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party.");
inviteManager.respondToInvite(caller, target, accept);
}
@ -261,7 +266,7 @@ public class PartyCommand extends CommandBase<PartyManager>
Lang.NOT_OWNER.send(caller);
return;
}
caller.sendMessage(F.main("Party", "You have disbanded your party."));
Plugin.disbandParty(party);
}

View File

@ -45,12 +45,10 @@ public class PartyInviteManager
public String format(String target)
{
return C.mHead + "Party> " + F.name(target) + " " + _message.substring(_message.indexOf("}" + 1));
return _message.replace("{0}", F.name(target));
}
}
private final Map<String, String> INVITE_FROM_SERVERS = Maps.newHashMap();
private final Map<UUID, List<InviteData>> _activeInvites = Maps.newHashMap();
private final Map<UUID, String> _invitedBy = Maps.newHashMap();
private final Map<UUID, String> _awaitingJoin = Maps.newHashMap();
@ -69,7 +67,7 @@ public class PartyInviteManager
{
Player possible = Bukkit.getPlayerExact(party);
remove(party, player.getUniqueId());
InviteData data = remove(party, player.getUniqueId());
_players.remove(player.getUniqueId());
@ -78,7 +76,7 @@ public class PartyInviteManager
Party newParty = _plugin.getParty(party);
if(!accept)
{
String message = InviteResponse.DENIED.format(player.getName());
String message = C.mHead + "Party> " + C.mBody + InviteResponse.DENIED.format(player.getName());
if (newParty == null)
{
possible.sendMessage(message);
@ -103,7 +101,12 @@ public class PartyInviteManager
return;
}
String serverFrom = INVITE_FROM_SERVERS.remove(player.getName());
String serverFrom = data.getServerFrom();
if(accept)
{
_plugin.getPortal().sendPlayerToServer(player, serverFrom);
}
_partyRedisManager.publish(serverFrom, RedisMessageType.INVITE_PLAYER_RESPONSE, party,
player.getName(), player.getUniqueId().toString(), accept ? InviteResponse.ACCEPTED.name() : InviteResponse.DENIED.name());
@ -118,8 +121,7 @@ public class PartyInviteManager
return;
}
_players.put(player.getUniqueId(), player.getName());
INVITE_FROM_SERVERS.put(target, serverFrom);
inviteTo(player.getUniqueId(), sender, sender);
inviteTo(player.getUniqueId(), sender, sender, serverFrom);
Lang.INVITE_RECEIVED.send(player, sender);
sendAcceptOrDeny(player, sender);
}
@ -165,17 +167,6 @@ public class PartyInviteManager
_activeInvites.remove(player);
}
/**
* Get the name of the server that this request was initiated from.
*
* @param player The player
* @return The server name
*/
public String getServerInvitedFrom(Player player)
{
return INVITE_FROM_SERVERS.get(player.getName());
}
/**
* Get the name of the party who is awaiting this player to join
*
@ -215,9 +206,9 @@ public class PartyInviteManager
* @param player The player who has been invited
* @param party The party name
*/
public void inviteTo(UUID player, String invitedBy, String party)
public void inviteTo(UUID player, String invitedBy, String party, String server)
{
addToInvite(player, invitedBy, party, System.currentTimeMillis());
addToInvite(player, invitedBy, party, System.currentTimeMillis(), server);
new BukkitRunnable()
{
@Override
@ -228,15 +219,15 @@ public class PartyInviteManager
cancel();
return;
}
remove(party, player);
InviteData data = remove(party, player);
Player possible = Bukkit.getPlayer(player);
String playerName = _players.remove(player);
if (possible != null)
{
playerName = possible.getName();
possible.sendMessage(F.main("Party", "Your invite to " + party + " has expired"));
possible.sendMessage(F.main("Party", "Your invite to " + F.name(party) + "'s party has expired"));
}
sendExpired(INVITE_FROM_SERVERS.remove(invitedBy), party, playerName, player);
sendExpired(data.getServerFrom(), party, playerName, player);
}
}.runTaskLater(_plugin.getPlugin(), 20 * 60);
}
@ -271,7 +262,7 @@ public class PartyInviteManager
* @param party The name of the party
* @param invited The UUID of the player
*/
public void remove(String party, UUID invited)
public InviteData remove(String party, UUID invited)
{
List<InviteData> data = _activeInvites.get(invited);
InviteData temp = null;
@ -288,6 +279,7 @@ public class PartyInviteManager
data.remove(temp);
}
_activeInvites.put(invited, data);
return temp;
}
public Collection<InviteData> getAllInvites(Player player)
@ -305,17 +297,16 @@ public class PartyInviteManager
_awaitingJoin.put(player, party);
}
private void addToInvite(UUID invited, String invitedBy, String party, long currentTime)
private void addToInvite(UUID invited, String invitedBy, String party, long currentTime, String server)
{
List<InviteData> inviteDatas = _activeInvites.get(invited);
if (inviteDatas == null)
{
inviteDatas = Lists.newArrayList();
}
InviteData inviteData = new InviteData(invitedBy, party, currentTime + 1000 * 10);
InviteData inviteData = new InviteData(invitedBy, party, currentTime, server);
inviteDatas.add(inviteData);
_invitedBy.put(invited, invitedBy);
_activeInvites.put(invited, inviteDatas);
}

View File

@ -17,9 +17,11 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.jooq.util.derby.sys.Sys;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
@ -35,7 +37,6 @@ public class PartyRedisManager
private final Map<String, BukkitTask> TASKS = Maps.newHashMap();
private final PartyManager _plugin;
private final PartyInviteManager _inviteManager;
private final JedisPool _writePool;
private final String _channel;
private final String _serverName;
@ -43,12 +44,12 @@ public class PartyRedisManager
public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool)
{
_plugin = plugin;
_inviteManager = plugin.getInviteManager();
_serverName = serverName;
_writePool = writePool;
_channel = CHANNEL_BASE + "-" + serverName;
plugin.runAsync(() -> {
System.out.println("Redis Started on " + _channel);
try (Jedis jedis = readPool.getResource())
{
jedis.subscribe(new PartyRedisListener(this), _channel);
@ -59,6 +60,8 @@ public class PartyRedisManager
public void publish(String server, RedisMessageType messageType, String... args)
{
System.out.println("Sending redis message: " + messageType.name() + " (" + Arrays.toString(args) + ")");
System.out.println("Sending on channel: " + CHANNEL_BASE + "-" + server);
_plugin.runAsync(() -> {
try (Jedis jedis = _writePool.getResource())
{
@ -69,7 +72,8 @@ public class PartyRedisManager
public void handle(RedisMessageType messageType, String message)
{
String[] contents = message.split("-");
System.out.println("Received packet: " + messageType.name() + " (" + message + ")");
String[] contents = message.split(",");
if (contents.length < 3)
{
return;
@ -84,11 +88,11 @@ public class PartyRedisManager
break;
case INVITE_PLAYER_REQUEST:
_inviteManager.handleInviteRequest(second, third, first);
_plugin.getInviteManager().handleInviteRequest(second, third, first);
break;
case INVITE_PLAYER_RESPONSE:
_inviteManager.handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase()));
_plugin.getInviteManager().handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase()));
break;
case PLAYER_FIND_REQUEST:
@ -111,7 +115,7 @@ public class PartyRedisManager
task.cancel();
}
Player inviter = Bukkit.getPlayerExact(contents[3]);
if (_inviteManager.isInvitedTo(uuid, inviter.getName()))
if (_plugin.getInviteManager().isInvitedTo(uuid, inviter.getName()))
{
Lang.ALREADY_INVITED.send(inviter, second);
return;
@ -123,7 +127,7 @@ public class PartyRedisManager
{
Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second);
}
_inviteManager.inviteTo(uuid, inviter.getName(), inviter.getName());
_plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName());
publish(first, RedisMessageType.INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second);
break;

View File

@ -19,6 +19,8 @@ public class PartyRedisListener extends JedisPubSub
@Override
public void onMessage(String channel, String message)
{
System.out.println("Received Message on " + channel);
System.out.println("Message: " + message);
RedisMessageType type = RedisMessageType.valueOf(message.split(":")[0].toUpperCase());
_redisManager.handle(type, message.split(":")[1]);
}

View File

@ -7,20 +7,20 @@ package mineplex.core.party.redis;
public enum RedisMessageType
{
//Message: SERVER_FROM-PLAYER_TARGET-PLAYER_SENDER
PLAYER_FIND_REQUEST(1, "{0}-{1}-{2}"),
//Message: SERVER_ON-PLAYER_TARGET_NAME-PLAYER_TARGET_UUID-PLAYER_SENDER
PLAYER_FIND_RESPONSE(2, "{0}-{1}-{2}-{3}"),
//Message: SERVER_FROM,PLAYER_TARGET,PLAYER_SENDER
PLAYER_FIND_REQUEST(1, "{0},{1},{2}"),
//Message: SERVER_ON,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,PLAYER_SENDER
PLAYER_FIND_RESPONSE(2, "{0},{1},{2},{3}"),
//Message: SERVER_FROM-PLAYER_SENDER-PLAYER_TARGET
INVITE_PLAYER_REQUEST(3, "{0}-{1}-{2}"),
//Message: PLAYER_SENDER-PLAYER_TARGET_NAME-PLAYER_TARGET_UUID-RESPONSE
INVITE_PLAYER_RESPONSE(4, "{0}-{1}-{2}-{3}"),
//Message: SERVER_FROM,PLAYER_SENDER,PLAYER_TARGET
INVITE_PLAYER_REQUEST(3, "{0},{1},{2}"),
//Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE
INVITE_PLAYER_RESPONSE(4, "{0},{1},{2},{3}"),
//Message: SERVER_FROM-PLAYER_INITIATING-PARTY_SIZE-_CAN_JOIN_FULL
PREJOIN_SERVER_REQUEST(5, "{0}-{1}-{2}-{3}"),
//Message: PLAYER_INITIATING-RESPONSE-REASON-SERVER
PREJOIN_SERVER_RESPONSE(6, "{0}-{1}-{2}-[3}"),
//Message: SERVER_FROM,PLAYER_INITIATING,PARTY_SIZE,_CAN_JOIN_FULL
PREJOIN_SERVER_REQUEST(5, "{0},{1},{2},{3}"),
//Message: PLAYER_INITIATING,RESPONSE,REASON,SERVER
PREJOIN_SERVER_RESPONSE(6, "{0},{1},{2},[3}"),
//Message: JSON Party
PARTY_INFO(7, "{0}")
@ -42,7 +42,12 @@ public enum RedisMessageType
public String format(String... args)
{
return String.format(_contents, args);
String message = _contents;
for(int i = 0; i < args.length; i++)
{
message = message.replace("{" + i + "}", args[i]);
}
return message;
}
public String getContents()

View File

@ -28,10 +28,9 @@ public abstract class Menu
.setData(DyeColor.LIGHT_BLUE.getWoolData())
.build(), null);
protected static final Button PURCHASE_MORE_SLOTS = new IconButton(new ItemBuilder(Material.SKULL_ITEM)
protected static final Button PURCHASE_MORE_SLOTS = new IconButton(new ItemBuilder(Material.REDSTONE_BLOCK)
.setTitle(C.cRed + C.Bold + "Locked!")
.setLore(" ", C.cGray + "Purchase a rank @ mineplex.com/shop", C.cGray + "Purchasing a rank increases your", C.cGray + "party size to allow 10 people!")
.setPlayerHead("Mopplebottom")
.build(), null);
protected static final Button[] EMPTY = new Button[45];

View File

@ -37,6 +37,10 @@ public class PartyMemberIcon extends PartyButton
public void onClick(Player clicker, ItemStack clicked)
{
if(!getParty().isOwnerKickMode())
{
return;
}
String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
UtilServer.getPluginManager().callEvent(new PartyMemberKickGUIEvent(getParty(), name, clicker));
}

View File

@ -5,6 +5,7 @@ import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button;
import mineplex.core.party.ui.Menu;
import mineplex.core.party.ui.menus.PartyInvitesMenu;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -30,6 +31,6 @@ public class DenyAllButton extends Button
public void onClick(Player player, ClickType clickType)
{
getPlugin().getInviteManager().removeAll(player.getUniqueId());
Menu.get(player.getUniqueId()).update(player);
new PartyInvitesMenu(getPlugin()).open(player);
}
}

View File

@ -21,8 +21,9 @@ public class FilterButton extends Button
.setLore(" ",
C.cGray + "Click to bring up an Anvil GUI",
C.cGray + "where you type and filter",
C.cDGray + "Party invites that contain the",
C.cGray + "inputted characters")
C.cGray + "Party invites by their name",
" ",
C.cGreen + "Input \"Clear Filter\" to remove the filter")
.build();
public FilterButton(PartyManager plugin)
@ -33,12 +34,13 @@ public class FilterButton extends Button
public FilterButton(String filter, PartyManager plugin)
{
super(new ItemBuilder(Material.NAME_TAG)
.setTitle("Filter Invites")
.setLore(C.cWhite + "Active Filter: " + C.cGreen + filter, " ",
.setTitle(C.cYellow + "Filter Invites")
.setLore(" ", C.cWhite + "Active Filter: " + C.cGreen + filter, " ",
C.cGray + "Click to bring up an Anvil GUI",
C.cGray + "where you type and filter",
C.cDGray + "Party invites that contain the",
C.cGray + "inputted characters")
C.cGray + "Party invites by their name",
" ",
C.cGreen + "Input \"Clear Filter\" to remove the filter")
.setGlow(true)
.build(), plugin);
}
@ -46,7 +48,7 @@ public class FilterButton extends Button
@Override
public void onClick(Player player, ClickType clickType)
{
new InviteFilterMenu(getPlugin(), player, null);
new InviteFilterMenu(getPlugin(), player, null).openInventory();
}
}

View File

@ -1,8 +1,42 @@
package mineplex.core.party.ui.button.tools.invite;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
/**
*
*/
public class InviteButton
public class InviteButton extends Button
{
private String _name;
public InviteButton(String name, PartyManager plugin)
{
super(new ItemBuilder(Material.SKULL_ITEM)
.setTitle(C.cYellow + name)
.setLore(" ", C.cYellow + "Right-Click " + C.cGray + "to deny the invite", C.cYellow + "Left-Click " + C.cGray + "to accept the invite")
.setData((short) 3)
.setPlayerHead(name)
.build(), plugin);
_name = name;
}
@Override
public void onClick(Player player, ClickType clickType)
{
if(clickType == ClickType.LEFT)
{
player.chat("/party accept " + _name);
} else if(clickType == ClickType.RIGHT)
{
player.chat("/party deny " + _name);
}
player.closeInventory();
}
}

View File

@ -1,8 +1,44 @@
package mineplex.core.party.ui.button.tools.invite;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.InviteData;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button;
import mineplex.core.party.ui.menus.PartyInvitesMenu;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
*
*/
public class NextPageButton
public class NextPageButton extends Button
{
private static final ItemStack ITEM = new ItemBuilder(Material.SIGN).setTitle(C.cYellow + "Next Page").build();
private final PartyInvitesMenu _menu;
public NextPageButton(PartyInvitesMenu menu, PartyManager plugin)
{
super(ITEM, plugin);
_menu = menu;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_menu.setButton(45, new PrevPageButton(_menu, getPlugin()));
_menu.setCurrentPage(_menu.getCurrentPage() + 1);
List<InviteData> data = _menu.getDataForPage(_menu.getCurrentPage());
for(int i = 0; i < data.size(); i++)
{
_menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin()));
}
_menu.update(player);
}
}

View File

@ -1,8 +1,48 @@
package mineplex.core.party.ui.button.tools.invite;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.InviteData;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button;
import mineplex.core.party.ui.button.IconButton;
import mineplex.core.party.ui.menus.PartyInvitesMenu;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
*
*/
public class PrevPageButton
public class PrevPageButton extends Button
{
private static final ItemStack ITEM = new ItemBuilder(Material.SIGN).setTitle(C.cYellow + "Previous Page").build();
private final PartyInvitesMenu _menu;
public PrevPageButton(PartyInvitesMenu menu, PartyManager plugin)
{
super(ITEM, plugin);
_menu = menu;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_menu.setCurrentPage(_menu.getCurrentPage() - 1);
if(_menu.getCurrentPage() == 0)
{
_menu.setButton(45, new IconButton(new ItemStack(Material.AIR), getPlugin()));
}
List<InviteData> data = _menu.getDataForPage(_menu.getCurrentPage());
for(int i = 0; i < data.size(); i++)
{
_menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin()));
}
_menu.update(player);
}
}

View File

@ -34,5 +34,6 @@ public class DisbandPartyButton extends Button
return;
}
player.chat("/party disband");
player.closeInventory();
}
}

View File

@ -19,7 +19,7 @@ public class SuggestPlayerButton extends PartyButton
private static final ItemStack ITEM = new ItemBuilder(Material.BOOK_AND_QUILL)
.setTitle(C.cYellow + "Suggest Player")
.setLore(" ", C.cWhite + "Suggest a player for the owner to invite")
.setLore(" ", C.cGray + "Suggest a player for the owner to invite")
.build();
public SuggestPlayerButton(Party party, PartyManager plugin)

View File

@ -1,19 +1,42 @@
package mineplex.core.party.ui.menus;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.InviteData;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button;
import mineplex.core.party.ui.Menu;
import mineplex.core.party.ui.button.tools.invite.BackButton;
import mineplex.core.party.ui.button.tools.invite.DenyAllButton;
import mineplex.core.party.ui.button.tools.invite.FilterButton;
import mineplex.core.party.ui.button.IconButton;
import mineplex.core.party.ui.button.tools.invite.*;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*
*/
public class PartyInvitesMenu extends Menu
{
private final IconButton NO_INVITES = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE)
.setData(DyeColor.RED.getWoolData())
.setTitle(C.cRedB + "No Invites")
.build(), null);
private final int SLOTS_PER_PAGE = 27;
private final int STARTING_SLOT = 18;
private int _currentPage;
private Map<Integer, List<InviteData>> _pagesOfData;
private List<InviteData> _data;
private String _filterBy;
public PartyInvitesMenu(PartyManager plugin)
@ -30,16 +53,126 @@ public class PartyInvitesMenu extends Menu
@Override
protected Button[] setUp(Player player)
{
boolean showFiltered = false;
Button[] buttons = new Button[54];
buttons[0] = new BackButton(_plugin);
buttons[4] = new DenyAllButton(_plugin);
buttons[8] = new FilterButton(_plugin);
if(_filterBy == null || _filterBy.isEmpty())
List<InviteData> all = (List<InviteData>) _plugin.getInviteManager().getAllInvites(player);
if (all == null || all.isEmpty())
{
for (int i = 10; i < 44; i++)
{
buttons[i] = NO_INVITES;
}
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
return addPanes(buttons);
}
return addPanes(buttons);
buttons[4] = new DenyAllButton(_plugin);
if (_filterBy == null || _filterBy.isEmpty())
{
buttons[8] = new FilterButton(_plugin);
} else
{
showFiltered = true;
buttons[8] = new FilterButton(_filterBy, _plugin);
}
if (showFiltered)
{
all = all.stream().filter(inviteData -> inviteData.getInvitedTo().contains(_filterBy)).collect(Collectors.toList());
}
if (showFiltered && all.isEmpty())
{
for (int i = 10; i < 44; i++)
{
buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE)
.setData(DyeColor.RED.getWoolData())
.setTitle(C.cRedB + "No Invites Found")
.setLore(" ", C.cGray + "The filter " + F.name(_filterBy) + " had no results.")
.build(), _plugin);
}
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
return addPanes(buttons);
}
_data = all;
if (all.size() > SLOTS_PER_PAGE)
{
int pagesNeeded = 0;
int size = all.size();
while (size > SLOTS_PER_PAGE)
{
pagesNeeded++;
size -= SLOTS_PER_PAGE;
}
buttons[53] = new NextPageButton(this, _plugin);
_pagesOfData = Maps.newHashMap();
int page = 0;
List<InviteData> newData = Lists.newArrayList();
int total = all.size();
for (int i = 0; i < pagesNeeded; i++)
{
for (int s = 0; s < total; s++)
{
newData.add(all.remove(i));
if (i > SLOTS_PER_PAGE)
{
_pagesOfData.put(page++, newData);
newData.clear();
total -= SLOTS_PER_PAGE;
break;
}
}
}
//Add pages
} else
{
for (int i = 0; i < all.size(); i++)
{
String to = all.get(i).getInvitedTo();
buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin);
}
}
return buttons;
}
public void setButton(int slot, Button button)
{
getButtons()[slot] = button;
}
public List<InviteData> getDataForPage(int page)
{
return _pagesOfData.get(page);
}
public int getStartingSlot()
{
return STARTING_SLOT;
}
public int getCurrentPage()
{
return _currentPage;
}
public void setCurrentPage(int currentPage)
{
_currentPage = currentPage;
}
public List<InviteData> getData()
{
return _data;
}
}

View File

@ -54,6 +54,15 @@ public class PartyOwnerMenu extends Menu
buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i), _party);
}
if(_party.getSize() == 5)
{
for(int i = 29; i < 34; i++)
{
buttons[i] = PURCHASE_MORE_SLOTS;
}
}
return addPanes(buttons);
}
}

View File

@ -21,6 +21,10 @@ public class InviteFilterMenu extends PlayerInputActionMenu
public void inputReceived(String name)
{
_player.closeInventory();
if(name.equalsIgnoreCase("Clear Filter"))
{
name = null;
}
new PartyInvitesMenu((PartyManager) _plugin, name).open(_player);
}
}