UI And server manager changes

This commit is contained in:
TadahTech 2016-06-22 17:28:43 -05:00
parent e53b474f3f
commit 50534c3af9
18 changed files with 283 additions and 51 deletions

View File

@ -1,5 +1,7 @@
package mineplex.core.party.ui.menus;
package mineplex.core.anvilMenu;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemBuilder;
@ -19,31 +21,31 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import static sun.audio.AudioPlayer.player;
/**
* This class handles creating inventory GUIs that need a players input to finalize
* A utility class for creating simple and easy Anvil GUI's that require actions based on a users input.
*/
public abstract class PlayerNameActionMenu implements Listener
public abstract class PlayerInputActionMenu implements Listener
{
protected PartyManager _partyManager;
protected MiniPlugin _plugin;
protected Player _player;
protected Inventory _currentInventory;
protected String _itemName = "";
protected boolean _searching;
protected Party _party;
public PlayerNameActionMenu(PartyManager partyManager, Player player, Party party)
public PlayerInputActionMenu(MiniPlugin plugin, Player player, Party party)
{
_player = player;
_partyManager = partyManager;
_plugin = plugin;
_party = party;
player.closeInventory();
_partyManager.registerEvents(this);
_plugin.registerEvents(this);
}
public abstract void onSuccess(String name);
public abstract void onFail(String name);
public abstract void inputReceived(String name);
@EventHandler
public void onInventoryClose(InventoryCloseEvent event)
@ -81,23 +83,7 @@ public abstract class PlayerNameActionMenu implements Listener
if (_itemName.length() > 1 && !_searching)
{
_searching = true;
final String name = _itemName;
_partyManager.getClientManager().checkPlayerName(_player, _itemName, result -> {
_searching = false;
if (result != null)
{
onSuccess(result);
} else
{
onFail(name);
_currentInventory.setItem(2, new ItemBuilder(Material.PAPER)
.setTitle(C.cYellow + "0" + C.cGray + " matches for [" + C.cYellow + name + C.cGray + "]")
.build());
_player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
}
});
inputReceived(_itemName);
} else
{
_player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f);

View File

@ -0,0 +1,50 @@
package mineplex.core.anvilMenu.player;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.anvilMenu.PlayerInputActionMenu;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.Party;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
/**
* A wrapped menu that handles looking for players specifically.
*/
public abstract class PlayerNameMenu extends PlayerInputActionMenu
{
protected CoreClientManager _clientManager;
public PlayerNameMenu(MiniPlugin plugin, CoreClientManager clientManager, Player player, Party party)
{
super(plugin, player, party);
_clientManager = clientManager;
}
public abstract void onSuccess(String name);
public abstract void onFail(String name);
@Override
public void inputReceived(String name)
{
_clientManager.checkPlayerName(_player, _itemName, result -> {
_searching = false;
if (result != null)
{
onSuccess(result);
} else
{
onFail(name);
_currentInventory.setItem(2, new ItemBuilder(Material.PAPER)
.setTitle(C.cYellow + "0" + C.cGray + " matches for [" + C.cYellow + name + C.cGray + "]")
.build());
_player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
}
});
}
}

View File

@ -131,6 +131,8 @@ public class PartyCommand extends CommandBase<PartyManager>
Player possible = Bukkit.getPlayerExact(target);
Party party = Plugin.getParty(caller);
boolean can = Bukkit.getMaxPlayers() < Plugin.getPlugin().getServer().getOnlinePlayers().size();
//Same Server
if (possible != null)
{
@ -159,6 +161,11 @@ public class PartyCommand extends CommandBase<PartyManager>
Lang.PARTY_FULL.send(caller);
return;
}
if(!can)
{
Lang.SERVER_FULL.send(caller);
return;
}
Lang.SUCCESS_INVITE.send(party, caller.getName(), target);
}

View File

@ -18,6 +18,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -89,6 +90,12 @@ public class PartyInviteManager
if (newParty == null)
{
newParty = new Party(possible.getName());
int size = 5;
if(_plugin.getClientManager().Get(possible).GetRank().isDonor())
{
size = 10;
}
newParty.setSize(size);
_plugin.addParty(newParty);
_plugin.addToParty(possible.getUniqueId(), newParty);
}
@ -132,13 +139,6 @@ public class PartyInviteManager
switch (response)
{
case ACCEPTED:
if (party == null)
{
party = new Party(sender);
_plugin.addParty(party);
_plugin.addToParty(player.getUniqueId(), party);
}
party.sendMessage(message);
addToPendingJoin(targetUUID, party.getName());
break;
case EXPIRED:
@ -290,6 +290,11 @@ public class PartyInviteManager
_activeInvites.put(invited, data);
}
public Collection<InviteData> getAllInvites(Player player)
{
return _activeInvites.get(player.getUniqueId());
}
private void sendExpired(String server, String party, String playerName, UUID player)
{
_plugin.getRedisManager().publish(server, RedisMessageType.INVITE_PLAYER_RESPONSE, party, playerName, player.toString(), InviteResponse.EXPIRED.name());

View File

@ -97,7 +97,12 @@ public class PartyJoinManager
}
party.sendMessage(F.main("Party", "Transferring servers..."));
_plugin.getRedisManager().sendPartyInfo(server, party);
party.getMembers().stream().map(Bukkit::getPlayer).forEach(player1 -> _plugin.getPortal().sendPlayerToServer(player1, server));
party.getMembers().stream().map(Bukkit::getPlayer).forEach(player1 ->
{
player.leaveVehicle();
player.eject();
_plugin.getPortal().sendPlayerToServer(player1, server);
});
}
}

View File

@ -1,5 +1,6 @@
package mineplex.core.party.ui;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.button.IconButton;
@ -27,6 +28,12 @@ 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)
.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];
protected static Map<UUID, Menu> MENUS = new HashMap<>();
private String _name;

View File

@ -17,6 +17,7 @@ public class LeavePartyButton extends Button
private static final ItemStack ITEM = new ItemBuilder(Material.REDSTONE_BLOCK)
.setTitle(C.cYellow + "Leave Party")
.setLore(" ", C.cRed + "Shift-Left-Click" + C.cGray + " to leave your party.")
.build();
public LeavePartyButton()
@ -27,6 +28,10 @@ public class LeavePartyButton extends Button
@Override
public void onClick(Player player, ClickType clickType)
{
if(clickType != ClickType.SHIFT_LEFT)
{
return;
}
player.chat("/party leave");
player.closeInventory();
}

View File

@ -1,8 +1,34 @@
package mineplex.core.party.ui.button.tools.invite;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button;
import mineplex.core.party.ui.menus.PartyMainMenu;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
/**
*
*/
public class BackButton
public class BackButton extends Button
{
private static ItemStack ITEM = new ItemBuilder(Material.BED)
.setTitle(ChatColor.GRAY + "\u21FD Go Back")
.build();
public BackButton(PartyManager plugin)
{
super(ITEM, plugin);
}
@Override
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
new PartyMainMenu(getPlugin()).open(player);
}
}

View File

@ -1,8 +1,35 @@
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 mineplex.core.party.ui.Menu;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
/**
*
*/
public class DenyAllButton
public class DenyAllButton extends Button
{
private static final ItemStack ITEM = new ItemBuilder(Material.REDSTONE_BLOCK)
.setTitle(C.cRed + "Delete all Invites")
.setLore(" ", C.cGray + "This will remove all pending invites.")
.build();
public DenyAllButton(PartyManager plugin)
{
super(ITEM, plugin);
}
@Override
public void onClick(Player player, ClickType clickType)
{
getPlugin().getInviteManager().removeAll(player.getUniqueId());
Menu.get(player.getUniqueId()).update(player);
}
}

View File

@ -1,8 +1,52 @@
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 mineplex.core.party.ui.menus.input.InviteFilterMenu;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
/**
*
*/
public class FilterButton
public class FilterButton extends Button
{
private static final ItemStack ITEM = new ItemBuilder(Material.NAME_TAG)
.setTitle(C.cYellow + "Filter Invites")
.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")
.build();
public FilterButton(PartyManager plugin)
{
super(ITEM, plugin);
}
public FilterButton(String filter, PartyManager plugin)
{
super(new ItemBuilder(Material.NAME_TAG)
.setTitle("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")
.setGlow(true)
.build(), plugin);
}
@Override
public void onClick(Player player, ClickType clickType)
{
new InviteFilterMenu(getPlugin(), player, null);
}
}

View File

@ -5,7 +5,6 @@ import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.button.tools.PartyButton;
import mineplex.core.party.ui.menus.PlayerNameActionMenu;
import mineplex.core.party.ui.menus.input.PartyInvitePlayerMenu;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -20,6 +19,7 @@ public class AddPlayerButton extends PartyButton
private static final ItemStack ITEM = new ItemBuilder(Material.SIGN)
.setTitle(C.cYellow + "Invite a Player")
.setLore(" ", C.cGray + "Brings up the Inviting Anvil!", C.cGray + "Simply type a players name", C.cGray + "and click the paper to invite him")
.build();
public AddPlayerButton(PartyManager plugin, Party party)

View File

@ -30,6 +30,6 @@ public class SuggestPlayerButton extends PartyButton
@Override
public void onClick(Player player, ClickType clickType)
{
new PlayerSuggestPlayerMenu(getPlugin(), player, getParty()).openInventory();
new PlayerSuggestPlayerMenu(getPlugin(), player).openInventory();
}
}

View File

@ -3,6 +3,9 @@ package mineplex.core.party.ui.menus;
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 org.bukkit.entity.Player;
/**
@ -11,15 +14,32 @@ import org.bukkit.entity.Player;
public class PartyInvitesMenu extends Menu
{
private String _filterBy;
public PartyInvitesMenu(PartyManager plugin)
{
super("Invites", plugin);
}
public PartyInvitesMenu(PartyManager plugin, String filterBy)
{
this(plugin);
_filterBy = filterBy;
}
@Override
protected Button[] setUp(Player player)
{
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())
{
return addPanes(buttons);
}
return addPanes(buttons);
}
}

View File

@ -0,0 +1,26 @@
package mineplex.core.party.ui.menus.input;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.menus.PartyInvitesMenu;
import mineplex.core.anvilMenu.PlayerInputActionMenu;
import org.bukkit.entity.Player;
/**
*
*/
public class InviteFilterMenu extends PlayerInputActionMenu
{
public InviteFilterMenu(PartyManager partyManager, Player player, Party party)
{
super(partyManager, player, party);
}
@Override
public void inputReceived(String name)
{
_player.closeInventory();
new PartyInvitesMenu((PartyManager) _plugin, name).open(_player);
}
}

View File

@ -1,20 +1,24 @@
package mineplex.core.party.ui.menus.input;
import mineplex.core.anvilMenu.player.PlayerNameMenu;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.menus.PartyOwnerMenu;
import mineplex.core.party.ui.menus.PlayerNameActionMenu;
import mineplex.core.anvilMenu.PlayerInputActionMenu;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
/**
*
*/
public class PartyInvitePlayerMenu extends PlayerNameActionMenu
public class PartyInvitePlayerMenu extends PlayerNameMenu
{
private PartyManager _partyManager;
public PartyInvitePlayerMenu(PartyManager partyManager, Player player)
{
super(partyManager, player, null);
super(partyManager, partyManager.getClientManager(), player, null);
_partyManager = partyManager;
}
@Override

View File

@ -1,22 +1,27 @@
package mineplex.core.party.ui.menus.input;
import mineplex.core.anvilMenu.player.PlayerNameMenu;
import mineplex.core.party.Lang;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.menus.PlayerNameActionMenu;
import mineplex.core.anvilMenu.PlayerInputActionMenu;
import org.bukkit.entity.Player;
/**
*
*/
public class PartyTransferOwnerMenu extends PlayerNameActionMenu
public class PartyTransferOwnerMenu extends PlayerNameMenu
{
private PartyManager _partyManager;
public PartyTransferOwnerMenu(PartyManager partyManager, Player player, Party party)
{
super(partyManager, player, party);
super(partyManager, partyManager.getClientManager(), player, null);
_partyManager = partyManager;
}
@Override
public void onSuccess(String name)
{

View File

@ -1,5 +1,6 @@
package mineplex.core.party.ui.menus.input;
import mineplex.core.anvilMenu.player.PlayerNameMenu;
import mineplex.core.common.jsonchat.ChildJsonMessage;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.HoverEvent;
@ -7,21 +8,23 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.menus.PlayerNameActionMenu;
import mineplex.core.anvilMenu.PlayerInputActionMenu;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
*
*/
public class PlayerSuggestPlayerMenu extends PlayerNameActionMenu
public class PlayerSuggestPlayerMenu extends PlayerNameMenu
{
public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party)
public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player)
{
super(partyManager, player, party);
super(partyManager, partyManager.getClientManager(), player, null);
}
@Override
public void onSuccess(String name)
{

View File

@ -13,6 +13,7 @@ import java.util.Set;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.brawl.fountain.BrawlShopProvider;
import mineplex.core.party.Lang;
import mineplex.core.party.event.PartySelectServerEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -519,8 +520,19 @@ public class ServerManager extends MiniDbClientPlugin<SimpleClanToken> implement
return _partyManager;
}
public void selectServer(org.bukkit.entity.Player player, ServerInfo serverInfo)
public void selectServer(Player player, ServerInfo serverInfo)
{
Party party = _partyManager.getParty(player);
if(party != null)
{
if(!party.getOwner().equalsIgnoreCase(player.getName()))
{
Lang.NOT_OWNER_SERVER.send(player);
return;
}
_partyManager.getJoinManager().requestServerJoin(serverInfo.Name, party);
return;
}
player.leaveVehicle();
player.eject();