Add documentation.

Refactor code.
Remove most command backend capabilities to limit user error.
Cleanup.
This commit is contained in:
TadahTech 2016-07-08 13:08:34 -05:00
parent 9f58e57a67
commit 8c7308add5
40 changed files with 874 additions and 553 deletions

View File

@ -3,6 +3,7 @@ package mineplex.core.party;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.event.PartyTransferOwnerEvent; import mineplex.core.party.event.PartyTransferOwnerEvent;
import mineplex.core.party.event.PartyTransferOwnerEvent.TransferReason; import mineplex.core.party.event.PartyTransferOwnerEvent.TransferReason;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -19,20 +20,64 @@ import java.util.UUID;
public class Party public class Party
{ {
/**
* This is controls whether or not the owner is currently in the menu, and kicking members
*/
private transient boolean _ownerKickMode = false; private transient boolean _ownerKickMode = false;
private String _owner; /**
private List<String> _members; * Asserts if this party has already been put into teams in order to prevent the Arcade from reassigning teams
private List<UUID> _membersByUUID; */
private Map<String, Long> _invites; private transient boolean _alreadyTeamed = false;
private int size;
private boolean _alreadyTeamed;
/**
* The standard _size for parties, for ALL {@code {@link mineplex.core.common.Rank}}
*/
private transient final int PARTY_MIN_SIZE = 5;
/**
* An upgrade _size for the party, given to donators and staff.
*/
private transient final int PARTY_MAX_SIZE = 10;
/**
* The current leader of this party
*/
private String _owner;
/**
* The names of all current party members
*/
private List<String> _members;
/**
* The UUIDS of all current party members
*/
private List<UUID> _membersByUUID;
/**
* All current pending invites
*/
private Map<String, Long> _invites;
/**
* This party's max size
*/
private int _size;
/**
* Empty constructor for GSON
*/
public Party() public Party()
{ {
} }
/**
* Creates a new fresh party instance
*
* @param owner The owner / leader of the party.
*/
public Party(String owner) public Party(String owner)
{ {
_owner = owner; _owner = owner;
@ -47,6 +92,11 @@ public class Party
return _owner; return _owner;
} }
/**
* Get the current members by their IGN
*
* @return The list of named party members
*/
public List<String> getMembers() public List<String> getMembers()
{ {
return _members; return _members;
@ -57,11 +107,23 @@ public class Party
return _invites; return _invites;
} }
/**
* An alternate method to get the owner of the party.
* While this does not have any difference to using {@code getOwner}, it may serve a purpose in the future, should we wish to allow
* donators to name their party something custom.
*
* @return This party's name
*/
public String getName() public String getName()
{ {
return _owner; return _owner;
} }
/**
* Send's a message to the party
*
* @param message The string message to send to all players in the party
*/
public void sendMessage(String message) public void sendMessage(String message)
{ {
getMembers().stream().map(Bukkit::getPlayer).forEach(player -> player.sendMessage(message)); getMembers().stream().map(Bukkit::getPlayer).forEach(player -> player.sendMessage(message));
@ -69,14 +131,24 @@ public class Party
public int getSize() public int getSize()
{ {
return size; return _size;
} }
public void setSize(int size) /**
* Set's this party's size cap base off the current players rank
*
* @param increased <code>true</code> if this party should have the increased size
*/
public void setSize(boolean increased)
{ {
this.size = size; _size = increased ? PARTY_MAX_SIZE : PARTY_MIN_SIZE;
} }
/**
* Called when a player is added to the party.
*
* @param player The name of the player
*/
public void onPlayerAdd(String player) public void onPlayerAdd(String player)
{ {
_invites.remove(player); _invites.remove(player);
@ -92,6 +164,12 @@ public class Party
}); });
} }
/**
* Called when a member of the party is removed
*
* @param player The name of the player
* @param reason The reason for his removal.
*/
public void onPlayerRemove(String player, PartyRemoveReason reason) public void onPlayerRemove(String player, PartyRemoveReason reason)
{ {
if(reason == PartyRemoveReason.DISBANDED) if(reason == PartyRemoveReason.DISBANDED)
@ -128,27 +206,41 @@ public class Party
} }
} }
/**
* Gets the current state of whether or not the owner is kicking people in the UI.
*
* @return <code>true</code> if the owner is kicking people
*/
public boolean isOwnerKickMode() public boolean isOwnerKickMode()
{ {
return _ownerKickMode; return _ownerKickMode;
} }
/**
* Set's the current state of kicking players
*
* @param ownerKickMode <code>true</code> if the owner is kicking people
*/
public void setOwnerKickMode(boolean ownerKickMode) public void setOwnerKickMode(boolean ownerKickMode)
{ {
_ownerKickMode = ownerKickMode; _ownerKickMode = ownerKickMode;
} }
/**
* Set's the new owner for this party instance
*
* @param owner The new owner's name
*/
public void setOwner(String owner) public void setOwner(String owner)
{ {
_owner = owner; _owner = owner;
} }
@Override /**
public String toString() * Get a list of all members in the party by their UUID
{ *
return "Party: " + _owner; * @return A list of members by UUID
} */
public List<UUID> getMembersByUUID() public List<UUID> getMembersByUUID()
{ {
return _membersByUUID; return _membersByUUID;
@ -164,6 +256,13 @@ public class Party
_alreadyTeamed = alreadyTeamed; _alreadyTeamed = alreadyTeamed;
} }
/**
* Check to see if this party contains a certain player name
* This is case-insensitive
*
* @param name The players name
* @return <code>true</code> If the player is in the party
*/
public boolean contains(String name) public boolean contains(String name)
{ {
for(String s : _members) for(String s : _members)

View File

@ -1,10 +1,9 @@
package mineplex.core.party; package mineplex.core.party;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.party.event.PartyDataReceivedEvent; import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.event.PartyMemberKickGUIEvent; import mineplex.core.party.event.PartyMemberKickGUIEvent;
import mineplex.core.party.event.PartyTransferOwnerEvent; import mineplex.core.party.event.PartyTransferOwnerEvent;
import mineplex.core.party.manager.PartyRedisManager;
import mineplex.core.party.ui.Menu; import mineplex.core.party.ui.Menu;
import mineplex.core.portal.ServerTransferEvent; import mineplex.core.portal.ServerTransferEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -52,14 +51,14 @@ public class PartyEventListener implements Listener
{ {
party = new Party(partyName); party = new Party(partyName);
int size = 5;
if (bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA)) if (bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA))
{ {
size = 10; party.setSize(true);
} else
{
party.setSize(false);
} }
party.setSize(size);
_plugin.addParty(party); _plugin.addParty(party);
} }
@ -110,7 +109,7 @@ public class PartyEventListener implements Listener
Player clicked = Bukkit.getPlayerExact(event.getPlayerClicked()); Player clicked = Bukkit.getPlayerExact(event.getPlayerClicked());
Lang.REMOVED.send(clicked); Lang.REMOVED.send(clicked);
_plugin.removeFromParty(clicked, PartyRemoveReason.KICKED); _plugin.removeFromParty(clicked, PartyRemoveReason.KICKED);
Menu.get(event.getOwner().getUniqueId()).update(event.getOwner()); Menu.get(event.getOwner().getUniqueId()).resetAndUpdate(event.getOwner());
} }
@EventHandler @EventHandler

View File

@ -1,6 +1,5 @@
package mineplex.core.party; package mineplex.core.party;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
@ -9,39 +8,55 @@ import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.command.PartyCommand; import mineplex.core.party.command.PartyCommand;
import mineplex.core.party.manager.PartyInviteManager; import mineplex.core.party.manager.PartyInviteManager;
import mineplex.core.party.manager.PartyJoinManager; import mineplex.core.party.manager.PartyJoinManager;
import mineplex.core.party.manager.PartyMethodManager;
import mineplex.core.party.manager.PartyRedisManager; import mineplex.core.party.manager.PartyRedisManager;
import mineplex.core.party.ui.Menu;
import mineplex.core.party.ui.MenuListener; import mineplex.core.party.ui.MenuListener;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
import mineplex.serverdata.Utility; import mineplex.serverdata.Utility;
import mineplex.serverdata.servers.ServerManager; import mineplex.serverdata.servers.ServerManager;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class PartyManager extends MiniPlugin public class PartyManager extends MiniPlugin
{ {
/**
* The item given to a player in his hotbar to manage the Parties via the new UI.
*/
public static final ItemStack INTERFACE_ITEM = new ItemBuilder(Material.NAME_TAG).setTitle(C.cGreen + "Parties").build(); public static final ItemStack INTERFACE_ITEM = new ItemBuilder(Material.NAME_TAG).setTitle(C.cGreen + "Parties").build();
/**
* The slow to which it goes in.
*/
public static final int INTERFACE_SLOT = 5; public static final int INTERFACE_SLOT = 5;
//Managers
private final Portal _portal; private final Portal _portal;
private final CoreClientManager _clientManager; private final CoreClientManager _clientManager;
private final PreferencesManager _preferencesManager; private final PreferencesManager _preferencesManager;
private final PartyRedisManager _redisManager; private final PartyRedisManager _redisManager;
private final PartyInviteManager _inviteManager; private final PartyInviteManager _inviteManager;
private final PartyJoinManager _joinManager; private final PartyJoinManager _joinManager;
private final PartyMethodManager _methodManager;
/**
* This local instance's name
*/
private final String _serverName; private final String _serverName;
/**
* A map of player's in parties server wide.
*/
private final Map<UUID, Party> _players = Maps.newHashMap(); private final Map<UUID, Party> _players = Maps.newHashMap();
/**
* A map of owner (name) -> party server wide
*/
private final Map<String, Party> _parties = Maps.newHashMap(); private final Map<String, Party> _parties = Maps.newHashMap();
public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager) public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager)
@ -50,12 +65,17 @@ public class PartyManager extends MiniPlugin
_portal = portal; _portal = portal;
_clientManager = clientManager; _clientManager = clientManager;
_preferencesManager = preferenceManager; _preferencesManager = preferenceManager;
_serverName = _plugin.getConfig().getString("serverstatus.name"); _serverName = _plugin.getConfig().getString("serverstatus.name");
_redisManager = new PartyRedisManager(this, _serverName, _redisManager = new PartyRedisManager(this, _serverName,
Utility.generatePool(ServerManager.getMasterConnection()), Utility.generatePool(ServerManager.getMasterConnection()),
Utility.generatePool(ServerManager.getSlaveConnection())); Utility.generatePool(ServerManager.getSlaveConnection()));
_inviteManager = new PartyInviteManager(this, _redisManager); _inviteManager = new PartyInviteManager(this, _redisManager);
_joinManager = new PartyJoinManager(this); _joinManager = new PartyJoinManager(this);
_methodManager = new PartyMethodManager(this);
addCommand(new PartyCommand(this)); addCommand(new PartyCommand(this));
getPluginManager().registerEvents(new MenuListener(), getPlugin()); getPluginManager().registerEvents(new MenuListener(), getPlugin());
new PartyEventListener(this); new PartyEventListener(this);
@ -76,113 +96,11 @@ public class PartyManager extends MiniPlugin
_parties.put(party.getName(), party); _parties.put(party.getName(), party);
} }
public void addToParty(UUID uuid, Party party)
{
_players.put(uuid, party);
Player player = Bukkit.getPlayer(uuid);
party.onPlayerAdd(player.getName());
if(!party.getMembersByUUID().contains(uuid))
{
party.getMembersByUUID().add(uuid);
}
}
public void addToPartyOnTransfer(UUID uuid, Party party)
{
_players.put(uuid, party);
}
public void addToParty(Player player, Party party)
{
addToParty(player.getUniqueId(), party);
}
public void removeParty(Party party) public void removeParty(Party party)
{ {
_parties.remove(party.getName()); _parties.remove(party.getName());
} }
public void removeForTransfer(UUID uuid)
{
Party party = _players.remove(uuid);
if(party == null)
{
return;
}
String player = Bukkit.getPlayer(uuid).getName();
party.onPlayerRemove(player, PartyRemoveReason.OTHER);
}
public void removeFromParty(UUID uuid, PartyRemoveReason reason)
{
Party party = _players.remove(uuid);
if(party == null)
{
return;
}
Player player = Bukkit.getPlayer(uuid);
if(player.getOpenInventory() != null)
{
if (Menu.get(player.getUniqueId()) != null)
{
player.closeInventory();
Menu.remove(player.getUniqueId());
}
}
if(reason == PartyRemoveReason.DISBANDED_BY_OWNER)
{
return;
}
party.getMembers().remove(player.getName());
party.getMembersByUUID().remove(uuid);
party.onPlayerRemove(player.getName(), reason);
int size = party.getMembers().size();
if(size <= 1)
{
if(size == 0)
{
removeParty(party);
return;
}
_players.remove(Bukkit.getPlayerExact(party.getMembers().get(0)).getUniqueId());
party.onPlayerRemove(party.getMembers().get(0), PartyRemoveReason.DISBANDED);
removeParty(party);
}
}
public void removeFromParty(Player player, PartyRemoveReason reason)
{
removeFromParty(player.getUniqueId(), reason);
}
public void disbandParty(Party party)
{
List<UUID> members = Lists.newArrayList(party.getMembersByUUID());
Lang.DISBANDED_BY_OWNER.send(party);
members.stream().forEach(player -> removeFromParty(player, PartyRemoveReason.DISBANDED_BY_OWNER));
party.getMembers().clear();
party.getMembersByUUID().clear();
removeParty(party);
}
public void transferOwner(String newOwner, String oldOwner)
{
Party party = _parties.remove(oldOwner);
if(party == null)
{
return;
}
_parties.put(newOwner.toLowerCase(), party);
party.setOwner(newOwner);
party.getMembers().remove(oldOwner);
party.getMembers().add(oldOwner);
}
public Portal getPortal() public Portal getPortal()
{ {
return _portal; return _portal;
@ -218,8 +136,18 @@ public class PartyManager extends MiniPlugin
return _joinManager; return _joinManager;
} }
public PartyMethodManager getMethodManager()
{
return _methodManager;
}
public Map<UUID, Party> getPlayerParties() public Map<UUID, Party> getPlayerParties()
{ {
return _players; return _players;
} }
public Map<String, Party> getParties()
{
return _parties;
}
} }

View File

@ -2,24 +2,16 @@ package mineplex.core.party.command;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.ChildJsonMessage;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.PartyRemoveReason; import mineplex.core.party.ui.menus.PartyInvitesMenu;
import mineplex.core.party.manager.PartyInviteManager;
import mineplex.core.party.ui.menus.PartyMainMenu; import mineplex.core.party.ui.menus.PartyMainMenu;
import mineplex.core.party.ui.menus.PartyOwnerMenu; import mineplex.core.party.ui.menus.PartyOwnerMenu;
import mineplex.core.party.ui.menus.PartyViewMenu; import mineplex.core.party.ui.menus.PartyViewMenu;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID;
/** /**
* Command handler for party commands * Command handler for party commands
*/ */
@ -28,20 +20,15 @@ public class PartyCommand extends CommandBase<PartyManager>
private final String[] HELP = { private final String[] HELP = {
F.main("Party", "Party Commands (Click the command!)"), F.main("Party", "Party Commands (Click the command!)"),
// help("help", "Shows this help screen"),
help("", "Brings up the Party GUI"), help("", "Brings up the Party GUI"),
//help("invite <player>", "Invite a player to your party."), C.cBlue + "Party> " + C.cWhite + "#<message> " + C.cGray + "- Send a message to your party.",
//help("accept <party>", "Accept an invite to a party."), C.cGreenB + "All party functions have been moved to the GUI!",
//help("deny <party>", "Deny an invite to a party."), C.cGreenB + "Click the NameTag in your hotbar to get started!"
//help("leave", "Leave your current party"),
//help("kick <player>", "Kick a player from your party."),
//help("disband", "Disband your party."),
C.cBlue + "Party> " + C.cWhite + "#<message> " + C.cGray + "- Send a message to your party."
}; };
public PartyCommand(PartyManager plugin) public PartyCommand(PartyManager plugin)
{ {
super(plugin, Rank.ALL, "party", "z"); super(plugin, Rank.ALL, "party", "z", "partyaccept", "partydeny", "openinvitesmenu", "partyinvite");
} }
@Override @Override
@ -63,245 +50,31 @@ public class PartyCommand extends CommandBase<PartyManager>
new PartyViewMenu(party, Plugin).open(caller); new PartyViewMenu(party, Plugin).open(caller);
return; return;
} }
String argument = args[0]; if(_aliasUsed.equalsIgnoreCase("openinvitesmenu"))
if (argument.equalsIgnoreCase("help"))
{ {
caller.sendMessage(HELP[0]); new PartyInvitesMenu(Plugin).open(caller);
//Show this menu
for(int i = 1; i < HELP.length; i++)
{
String s = HELP[i];
String command = ChatColor.stripColor(s);
ChildJsonMessage jsonMessage = new ChildJsonMessage(s);
if ((i + 1) == HELP.length)
{
command = "#<message>";
} else
{
command = command.substring(command.indexOf("/"), command.indexOf("-") - 1);
}
jsonMessage.click(ClickEvent.SUGGEST_COMMAND, command);
jsonMessage.sendToPlayer(caller);
}
return; return;
} }
if (args.length == 1) if(args.length == 1)
{ {
if (argument.equalsIgnoreCase("leave")) String arg = args[0];
if (_aliasUsed.equalsIgnoreCase("partyaccept"))
{ {
handleLeave(caller); Plugin.getMethodManager().respondToInvite(caller, arg, true);
return; return;
} }
if (argument.equalsIgnoreCase("disband")) if (_aliasUsed.equalsIgnoreCase("partydeny"))
{ {
handleDisband(caller); Plugin.getMethodManager().respondToInvite(caller, arg, false);
return; return;
} }
return; if(_aliasUsed.equalsIgnoreCase("partyinvite"))
}
if (args.length == 2)
{
String target = args[1];
if (argument.equalsIgnoreCase("invite"))
{ {
handleInvite(caller, target); Plugin.getMethodManager().invite(caller, arg);
return; return;
} }
if (argument.equalsIgnoreCase("accept"))
{
handleInviteResponse(caller, target, true);
return;
}
if (argument.equalsIgnoreCase("deny"))
{
handleInviteResponse(caller, target, false);
return;
}
if (argument.equalsIgnoreCase("remove") || argument.equalsIgnoreCase("kick"))
{
handleForceRemove(caller, target);
}
} }
} caller.sendMessage(HELP);
private void handleInvite(Player caller, String target)
{
Player possible = Bukkit.getPlayer(target);
Party party = Plugin.getParty(caller);
if(target.equalsIgnoreCase(caller.getName()))
{
caller.sendMessage(F.main("Party", "You cannot invite yourself!"));
return;
}
boolean can = Bukkit.getMaxPlayers() >= Plugin.getPlugin().getServer().getOnlinePlayers().size();
if(!can)
{
Lang.SERVER_FULL.send(caller);
return;
}
if(!Plugin.getPreferencesManager().Get(target).PartyRequests)
{
caller.sendMessage(F.main("Party> ", F.name(target) + " is not accepting invites at this time."));
return;
}
//Same Server
if (possible != null)
{
if (party == null)
{
if(Plugin.getParty(target) != null)
{
Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target);
return;
}
if(Plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), caller.getName()))
{
Lang.ALREADY_INVITED.send(caller, target);
return;
}
Lang.INVITE_SUCCESS_PLAYER.send(caller, possible.getName());
} else
{
if(!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
if(Plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), party.getName()))
{
Lang.ALREADY_INVITED.send(caller, target);
return;
}
if(party.getMembers().contains(target))
{
Lang.ALREADY_MEMBER.send(caller, target);
return;
}
if(Plugin.getParty(target) != null)
{
Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target);
return;
}
if(party.getMembers().size() >= party.getSize())
{
Lang.PARTY_FULL.send(caller);
return;
}
Lang.SUCCESS_INVITE.send(party, caller.getName(), target);
}
UUID uuid = possible.getUniqueId();
Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName());
Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName(), Plugin.getServerName());
Plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName());
return;
}
Plugin.getRedisManager().findAndInvite(target, caller.getName());
}
private void handleInviteResponse(Player caller, String target, boolean accept)
{
if(Plugin.getParty(caller) != null)
{
Lang.ALREADY_IN.send(caller);
caller.sendMessage(F.main("Party", "Please leave your party before joining!"));
return;
}
PartyInviteManager inviteManager = Plugin.getInviteManager();
if (!inviteManager.isInvitedTo(caller.getUniqueId(), target))
{
//He isn't invited to this party.
Lang.NOT_INVITED.send(caller, target);
return;
}
if(!accept)
{
caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party.");
}
inviteManager.respondToInvite(caller, target, accept);
}
private void handleForceRemove(Player caller, String target)
{
Party party = Plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
if (!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
Player playerTarget = Bukkit.getPlayerExact(target);
if (playerTarget == null)
{
Lang.NOT_MEMBER.send(caller, target);
return;
}
Party targetParty = Plugin.getParty(playerTarget);
if (targetParty == null ||!party.getMembers().contains(target))
{
Lang.NOT_MEMBER.send(caller, target);
return;
}
Plugin.removeFromParty(playerTarget.getUniqueId(), PartyRemoveReason.KICKED);
Lang.REMOVE_PLAYER_KICK.send(targetParty);
}
private void handleLeave(Player caller)
{
Party party = Plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
Plugin.removeFromParty(caller.getUniqueId(), PartyRemoveReason.LEFT);
Lang.LEFT.send(caller);
}
private void handleDisband(Player caller)
{
Party party = Plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
if (!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
caller.sendMessage(F.main("Party", "You have disbanded your party."));
Plugin.disbandParty(party);
} }
private String help(String command, String description) private String help(String command, String description)

View File

@ -0,0 +1,27 @@
package mineplex.core.party.constants;
import mineplex.core.common.util.F;
/**
*
*/
public enum InviteResponse
{
ACCEPTED("{0} has joined the party!"),
DENIED("{0} has declined joining your party."),
EXPIRED("{0} did not respond in time.");
private String _message;
InviteResponse(String message)
{
_message = message;
}
public String format(String target)
{
return _message.replace("{0}", F.name(target));
}
}

View File

@ -0,0 +1,26 @@
package mineplex.core.party.constants;
import mineplex.core.common.util.F;
/**
*
*/
public enum JoinResponseReason
{
CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")),
SUCCESS("");
private String _message;
JoinResponseReason(String message)
{
_message = message;
}
public String getMessage()
{
return _message;
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.party; package mineplex.core.party.constants;
/** /**
* *

View File

@ -1,6 +1,5 @@
package mineplex.core.party.event; package mineplex.core.party.event;
import mineplex.core.party.Party;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;

View File

@ -9,6 +9,7 @@ import mineplex.core.party.InviteData;
import mineplex.core.party.Lang; import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.InviteResponse;
import mineplex.core.party.redis.RedisMessageType; import mineplex.core.party.redis.RedisMessageType;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
@ -31,26 +32,6 @@ import java.util.UUID;
public class PartyInviteManager public class PartyInviteManager
{ {
public enum InviteResponse
{
ACCEPTED("{0} has joined the party!"),
DENIED("{0} has declined joining your party."),
EXPIRED("{0} did not respond in time.");
private String _message;
InviteResponse(String message)
{
_message = message;
}
public String format(String target)
{
return _message.replace("{0}", F.name(target));
}
}
private final Map<UUID, List<InviteData>> _activeInvites = Maps.newHashMap(); private final Map<UUID, List<InviteData>> _activeInvites = Maps.newHashMap();
private final Map<UUID, String> _invitedBy = Maps.newHashMap(); private final Map<UUID, String> _invitedBy = Maps.newHashMap();
private final Map<UUID, String> _awaitingJoin = Maps.newHashMap(); private final Map<UUID, String> _awaitingJoin = Maps.newHashMap();
@ -66,6 +47,13 @@ public class PartyInviteManager
_partyRedisManager = partyRedisManager; _partyRedisManager = partyRedisManager;
} }
/**
* Responds to an invite, regardless of the server
*
* @param player The player calling
* @param party The party
* @param accept Whether or not the player accepted the invite
*/
public void respondToInvite(Player player, String party, boolean accept) public void respondToInvite(Player player, String party, boolean accept)
{ {
Player possible = Bukkit.getPlayerExact(party); Player possible = Bukkit.getPlayerExact(party);
@ -92,16 +80,17 @@ public class PartyInviteManager
if (newParty == null) if (newParty == null)
{ {
newParty = new Party(possible.getName()); newParty = new Party(possible.getName());
int size = 5;
if(_plugin.getClientManager().Get(possible).GetRank().has(Rank.ULTRA)) if(_plugin.getClientManager().Get(possible).GetRank().has(Rank.ULTRA))
{ {
size = 10; newParty.setSize(true);
} else
{
newParty.setSize(false);
} }
newParty.setSize(size);
_plugin.addParty(newParty); _plugin.addParty(newParty);
_plugin.addToParty(possible.getUniqueId(), newParty); _plugin.getMethodManager().addToParty(possible.getUniqueId(), newParty);
} }
_plugin.addToParty(player.getUniqueId(), newParty); _plugin.getMethodManager().addToParty(player.getUniqueId(), newParty);
return; return;
} }
@ -116,6 +105,13 @@ public class PartyInviteManager
player.getName(), player.getUniqueId().toString(), accept ? InviteResponse.ACCEPTED.name() : InviteResponse.DENIED.name()); player.getName(), player.getUniqueId().toString(), accept ? InviteResponse.ACCEPTED.name() : InviteResponse.DENIED.name());
} }
/**
* Handles a received response via redis
*
* @param sender The player sending the request
* @param target The player target
* @param serverFrom The server initiating the request
*/
public void handleInviteRequest(String sender, String target, String serverFrom) public void handleInviteRequest(String sender, String target, String serverFrom)
{ {
Player player = Bukkit.getPlayer(target); Player player = Bukkit.getPlayer(target);
@ -130,6 +126,14 @@ public class PartyInviteManager
sendAcceptOrDeny(player, sender); sendAcceptOrDeny(player, sender);
} }
/**
* Handles the response returned via redis when an invite is handled cross server
*
* @param sender The player sender
* @param target The player target
* @param targetUUID The player targets UUID
* @param response The response to this invite
*/
public void handleInviteResponse(String sender, String target, UUID targetUUID, InviteResponse response) public void handleInviteResponse(String sender, String target, UUID targetUUID, InviteResponse response)
{ {
remove(sender, targetUUID); remove(sender, targetUUID);
@ -197,18 +201,6 @@ public class PartyInviteManager
_awaitingJoin.remove(player); _awaitingJoin.remove(player);
} }
/**
* Get the name of the person who has invited the target player
* Used mainly for player locating
*
* @param player The player target
* @return The name, if it exists, of the person who has invited the player.
*/
public String getInvitee(Player player)
{
return _invitedBy.get(player.getUniqueId());
}
/** /**
* Add a player to the active invites map * Add a player to the active invites map
* *
@ -291,6 +283,11 @@ public class PartyInviteManager
return temp; return temp;
} }
/**
* Stop the player's expired task from running
*
* @param player The UUID of the player
*/
public void cancelTask(UUID player) public void cancelTask(UUID player)
{ {
BukkitTask task = _tasks.remove(player); BukkitTask task = _tasks.remove(player);
@ -300,21 +297,50 @@ public class PartyInviteManager
} }
} }
/**
* Retrieves all invites currently pending for a specific player
* @param player The player
* @return All his current pending invites
*/
public Collection<InviteData> getAllInvites(Player player) public Collection<InviteData> getAllInvites(Player player)
{ {
return _activeInvites.get(player.getUniqueId()); return _activeInvites.get(player.getUniqueId());
} }
/**
* Send an "ExpiredPartyInvite" redis message
*
* @param server The server to
* @param party The party who initiated the request (can also be a player's name)
* @param playerName The name of the invited player
* @param player The invited player's UUID
*/
private void sendExpired(String server, String party, String playerName, UUID player) 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()); _plugin.getRedisManager().publish(server, RedisMessageType.INVITE_PLAYER_RESPONSE, party, playerName, player.toString(), InviteResponse.EXPIRED.name());
} }
/**
* Marks this player as having an accepted invite
* This is used to control the creation of single player parties, and makes sure a party is created ONLY if a player joins the server successfully.
*
* @param player The UUID of the player
* @param party The name of the party
*/
private void addToPendingJoin(UUID player, String party) private void addToPendingJoin(UUID player, String party)
{ {
_awaitingJoin.put(player, party); _awaitingJoin.put(player, party);
} }
/**
* Add a pending invite for a player
*
* @param invited The invited players UUUD
* @param invitedBy The person who invited him
* @param party The name of the party invited to
* @param currentTime The time which this invite was initiated
* @param server The server the request is from
*/
private void addToInvite(UUID invited, String invitedBy, String party, long currentTime, String server) private void addToInvite(UUID invited, String invitedBy, String party, long currentTime, String server)
{ {
List<InviteData> inviteDatas = _activeInvites.get(invited); List<InviteData> inviteDatas = _activeInvites.get(invited);
@ -328,6 +354,12 @@ public class PartyInviteManager
_activeInvites.put(invited, inviteDatas); _activeInvites.put(invited, inviteDatas);
} }
/**
* Sends a Text Componoent clickable message to a player for easier quick responses to invites
*
* @param player The player who received the invite
* @param arg The name of the inviting party
*/
public void sendAcceptOrDeny(Player player, String arg) public void sendAcceptOrDeny(Player player, String arg)
{ {
TextComponent textComponent = new TextComponent(F.main("Party", "Reply: ")); TextComponent textComponent = new TextComponent(F.main("Party", "Reply: "));
@ -335,7 +367,7 @@ public class PartyInviteManager
TextComponent accept = new TextComponent("ACCEPT"); TextComponent accept = new TextComponent("ACCEPT");
accept.setColor(ChatColor.GREEN); accept.setColor(ChatColor.GREEN);
accept.setBold(true); accept.setBold(true);
accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party accept " + arg)); accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/partyaccept " + arg));
accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent("Click to join " + F.name(arg) + "'s party") new TextComponent("Click to join " + F.name(arg) + "'s party")
})); }));
@ -346,12 +378,23 @@ public class PartyInviteManager
TextComponent deny = new TextComponent("DENY"); TextComponent deny = new TextComponent("DENY");
deny.setColor(ChatColor.RED); deny.setColor(ChatColor.RED);
deny.setBold(true); deny.setBold(true);
deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party deny " + arg)); deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/partydeny " + arg));
deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent("Click to decline joining " + F.name(arg) + "'s party") new TextComponent("Click to decline joining " + F.name(arg) + "'s party")
})); }));
textComponent.addExtra(deny); textComponent.addExtra(deny);
textComponent.addExtra(" ");
TextComponent view = new TextComponent("VIEW INVITES");
view.setColor(ChatColor.GOLD);
view.setBold(true);
view.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/openinvitesmenu"));
view.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent("Click to view all pending invites.")
}));
textComponent.addExtra(view);
player.spigot().sendMessage(textComponent); player.spigot().sendMessage(textComponent);
} }

View File

@ -6,6 +6,7 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.JoinResponseReason;
import mineplex.core.party.redis.RedisMessageType; import mineplex.core.party.redis.RedisMessageType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -20,23 +21,8 @@ import java.util.stream.Collectors;
public class PartyJoinManager public class PartyJoinManager
{ {
public enum JoinResponseReason private final String CANNOT_JOIN = "no";
{ private final String CAN_JOIN = "yes";
CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")),
SUCCESS("");
private String _message;
JoinResponseReason(String message)
{
_message = message;
}
public String getMessage()
{
return _message;
}
}
private final PartyManager _plugin; private final PartyManager _plugin;
private final int _maxPLayers; private final int _maxPLayers;
@ -49,6 +35,12 @@ public class PartyJoinManager
_transferring = Lists.newArrayList(); _transferring = Lists.newArrayList();
} }
/**
* Initiates a request to join a server for a specific party
*
* @param server The desired server
* @param party The requesting party
*/
public void requestServerJoin(String server, Party party) public void requestServerJoin(String server, Party party)
{ {
boolean canJoinFull = true; boolean canJoinFull = true;
@ -66,6 +58,14 @@ public class PartyJoinManager
_plugin.getServerName(), party.getOwner(), "" + party.getMembers().size(), "" + canJoinFull); _plugin.getServerName(), party.getOwner(), "" + party.getMembers().size(), "" + canJoinFull);
} }
/**
* Manages a received request
*
* @param serverFrom The server who initiated the request
* @param partySize The size of the party
* @param initiator The player who sent the request
* @param canJoinFull <code>true</code> if the party contains all donators or staff (full joining able players)
*/
public void handleJoinRequest(String serverFrom, int partySize, String initiator, boolean canJoinFull) public void handleJoinRequest(String serverFrom, int partySize, String initiator, boolean canJoinFull)
{ {
int currentPlayers = UtilServer.getPlayers().length; int currentPlayers = UtilServer.getPlayers().length;
@ -74,15 +74,23 @@ public class PartyJoinManager
//Max number of people on. //Max number of people on.
if (!canJoinFull) if (!canJoinFull)
{ {
_plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), "no", _plugin.getServerName()); _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), CANNOT_JOIN, _plugin.getServerName());
return; return;
} }
} }
_plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), "yes", _plugin.getServerName()); _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), CAN_JOIN, _plugin.getServerName());
} }
/**
* Manages a received response
*
* @param playerSender The player who sent the request
* @param response The String response
* @param server The server responding
* @param reason The reason for the response
*/
public void handleJoinResponse(String playerSender, String response, String server, JoinResponseReason reason) public void handleJoinResponse(String playerSender, String response, String server, JoinResponseReason reason)
{ {
Player player = Bukkit.getPlayer(playerSender); Player player = Bukkit.getPlayer(playerSender);
@ -95,7 +103,7 @@ public class PartyJoinManager
{ {
return; return;
} }
if (response.equalsIgnoreCase("no")) if (response.equalsIgnoreCase(CANNOT_JOIN))
{ {
party.sendMessage(reason.getMessage()); party.sendMessage(reason.getMessage());
return; return;
@ -105,7 +113,13 @@ public class PartyJoinManager
_transferring.addAll(party.getMembersByUUID()); _transferring.addAll(party.getMembersByUUID());
} }
/**
* Retrieve whether or not the player is currently transferring servers
* We wont need this information again, so calling a remove works fine.
*
* @param player The player
* @return <code>true</code> if the player is transferring servers
*/
public boolean isTransferring(Player player) public boolean isTransferring(Player player)
{ {
return _transferring.remove(player.getUniqueId()); return _transferring.remove(player.getUniqueId());

View File

@ -0,0 +1,337 @@
package mineplex.core.party.manager;
import com.google.common.collect.Lists;
import mineplex.core.common.util.F;
import mineplex.core.party.Lang;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.ui.Menu;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.UUID;
/**
* Contains all methods used by the internal UI system
*/
public class PartyMethodManager
{
private PartyManager _plugin;
public PartyMethodManager(PartyManager plugin)
{
_plugin = plugin;
}
/**
* Invite a player to either a new party or existing one
*
* @param caller The player who initiated the request
* @param target The player's target
*/
public void invite(Player caller, String target)
{
Player possible = Bukkit.getPlayer(target);
Party party = _plugin.getParty(caller);
if(target.equalsIgnoreCase(caller.getName()))
{
caller.sendMessage(F.main("Party", "You cannot invite yourself!"));
return;
}
boolean can = Bukkit.getMaxPlayers() >= _plugin.getPlugin().getServer().getOnlinePlayers().size();
if(!can)
{
Lang.SERVER_FULL.send(caller);
return;
}
//Same Server
if (possible != null)
{
if(!_plugin.getPreferencesManager().Get(possible).PartyRequests)
{
caller.sendMessage(F.main("Party> ", F.name(target) + " is not accepting invites at this time."));
return;
}
if (party == null)
{
if(_plugin.getParty(target) != null)
{
Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target);
return;
}
if(_plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), caller.getName()))
{
Lang.ALREADY_INVITED.send(caller, target);
return;
}
Lang.INVITE_SUCCESS_PLAYER.send(caller, possible.getName());
} else
{
if(!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
if(_plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), party.getName()))
{
Lang.ALREADY_INVITED.send(caller, target);
return;
}
if(party.getMembers().contains(target))
{
Lang.ALREADY_MEMBER.send(caller, target);
return;
}
if(_plugin.getParty(target) != null)
{
Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target);
return;
}
if(party.getMembers().size() >= party.getSize())
{
Lang.PARTY_FULL.send(caller);
return;
}
Lang.SUCCESS_INVITE.send(party, caller.getName(), target);
}
UUID uuid = possible.getUniqueId();
Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName());
_plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName(), _plugin.getServerName());
_plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName());
return;
}
//Not on the same server
_plugin.getRedisManager().findAndInvite(target, caller.getName());
}
/**
* Responds to a pending invite
*
* @param caller The player who initiated the request
* @param target The player's target
* @param accept <code>true</code> If the player has accepted the invite
*/
public void respondToInvite(Player caller, String target, boolean accept)
{
if(_plugin.getParty(caller) != null)
{
Lang.ALREADY_IN.send(caller);
caller.sendMessage(F.main("Party", "Please leave your party before joining!"));
return;
}
PartyInviteManager inviteManager = _plugin.getInviteManager();
if (!inviteManager.isInvitedTo(caller.getUniqueId(), target))
{
//He isn't invited to this party.
Lang.NOT_INVITED.send(caller, target);
return;
}
if(!accept)
{
caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party.");
}
inviteManager.respondToInvite(caller, target, accept);
}
/**
* Kicks a player from the callers party
*
* @param caller The player who initiated the request
* @param target The player's target
*/
public void forceRemove(Player caller, String target)
{
Party party = _plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
if (!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
Player playerTarget = Bukkit.getPlayerExact(target);
if (playerTarget == null)
{
Lang.NOT_MEMBER.send(caller, target);
return;
}
Party targetParty = _plugin.getParty(playerTarget);
if (targetParty == null ||!party.getMembers().contains(target))
{
Lang.NOT_MEMBER.send(caller, target);
return;
}
removeFromParty(playerTarget.getUniqueId(), PartyRemoveReason.KICKED);
Lang.REMOVE_PLAYER_KICK.send(targetParty);
}
/**
* Leaves the players current party if he is in one
*
* @param caller The player who wishes to leave his party
*/
public void leaveParty(Player caller)
{
Party party = _plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
removeFromParty(caller.getUniqueId(), PartyRemoveReason.LEFT);
Lang.LEFT.send(caller);
}
/**
* Disbands a players current party, assuming he is the leader
*
* @param caller The player who wishes to disband his party
*/
public void disband(Player caller)
{
Party party = _plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
if (!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
caller.sendMessage(F.main("Party", "You have disbanded your party."));
disbandParty(party);
}
public void addToParty(UUID uuid, Party party)
{
_plugin.getPlayerParties().put(uuid, party);
Player player = Bukkit.getPlayer(uuid);
party.onPlayerAdd(player.getName());
if(!party.getMembersByUUID().contains(uuid))
{
party.getMembersByUUID().add(uuid);
}
}
public void addToPartyOnTransfer(UUID uuid, Party party)
{
_plugin.getPlayerParties().put(uuid, party);
}
public void addToParty(Player player, Party party)
{
addToParty(player.getUniqueId(), party);
}
public void removeForTransfer(UUID uuid)
{
Party party = _plugin.getPlayerParties().remove(uuid);
if(party == null)
{
return;
}
String player = Bukkit.getPlayer(uuid).getName();
party.onPlayerRemove(player, PartyRemoveReason.OTHER);
}
public void removeFromParty(UUID uuid, PartyRemoveReason reason)
{
Party party = _plugin.getPlayerParties().remove(uuid);
if(party == null)
{
return;
}
Player player = Bukkit.getPlayer(uuid);
if(player.getOpenInventory() != null)
{
if (Menu.get(player.getUniqueId()) != null)
{
player.closeInventory();
Menu.remove(player.getUniqueId());
}
}
if(reason == PartyRemoveReason.DISBANDED_BY_OWNER)
{
return;
}
party.getMembers().remove(player.getName());
party.getMembersByUUID().remove(uuid);
party.onPlayerRemove(player.getName(), reason);
int size = party.getMembers().size();
if(size <= 1)
{
if(size == 0)
{
_plugin.removeParty(party);
return;
}
_plugin.getPlayerParties().remove(Bukkit.getPlayerExact(party.getMembers().get(0)).getUniqueId());
party.onPlayerRemove(party.getMembers().get(0), PartyRemoveReason.DISBANDED);
_plugin.removeParty(party);
}
}
public void removeFromParty(Player player, PartyRemoveReason reason)
{
removeFromParty(player.getUniqueId(), reason);
}
public void disbandParty(Party party)
{
List<UUID> members = Lists.newArrayList(party.getMembersByUUID());
Lang.DISBANDED_BY_OWNER.send(party);
members.stream().forEach(player -> removeFromParty(player, PartyRemoveReason.DISBANDED_BY_OWNER));
party.getMembers().clear();
party.getMembersByUUID().clear();
_plugin.removeParty(party);
}
public void transferOwner(String newOwner, String oldOwner)
{
Party party = _plugin.getParties().remove(oldOwner);
if(party == null)
{
return;
}
_plugin.getParties().put(newOwner.toLowerCase(), party);
party.setOwner(newOwner);
party.getMembers().remove(oldOwner);
party.getMembers().add(oldOwner);
}
}

View File

@ -7,9 +7,9 @@ import mineplex.core.common.util.F;
import mineplex.core.party.Lang; import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.InviteResponse;
import mineplex.core.party.constants.JoinResponseReason;
import mineplex.core.party.event.PartyDataReceivedEvent; import mineplex.core.party.event.PartyDataReceivedEvent;
import mineplex.core.party.manager.PartyInviteManager.InviteResponse;
import mineplex.core.party.manager.PartyJoinManager.JoinResponseReason;
import mineplex.core.party.redis.PartyRedisListener; import mineplex.core.party.redis.PartyRedisListener;
import mineplex.core.party.redis.RedisMessageType; import mineplex.core.party.redis.RedisMessageType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -50,7 +50,6 @@ public class PartyRedisManager
_channel = CHANNEL_BASE + "-" + serverName; _channel = CHANNEL_BASE + "-" + serverName;
plugin.runAsync(() -> { plugin.runAsync(() -> {
System.out.println("Connecting to redis and listening on channel " + _channel);
try (Jedis jedis = readPool.getResource()) try (Jedis jedis = readPool.getResource())
{ {
jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL); jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL);
@ -58,9 +57,15 @@ public class PartyRedisManager
}); });
} }
/**
* Send a message to a specific server
*
* @param server The destination server
* @param messageType The message to send
* @param args The arguments accompanying the request
*/
public void publish(String server, RedisMessageType messageType, String... args) public void publish(String server, RedisMessageType messageType, String... args)
{ {
System.out.println("Sending " + messageType.name() + " to " + server);
_plugin.runAsync(() -> { _plugin.runAsync(() -> {
try (Jedis jedis = _writePool.getResource()) try (Jedis jedis = _writePool.getResource())
{ {
@ -69,6 +74,12 @@ public class PartyRedisManager
}); });
} }
/**
* Handle a message received on this server
*
* @param messageType The type of message received
* @param message The contents of the request
*/
public void handle(RedisMessageType messageType, String message) public void handle(RedisMessageType messageType, String message)
{ {
if (messageType == PARTY_INFO) if (messageType == PARTY_INFO)
@ -141,6 +152,12 @@ public class PartyRedisManager
} }
} }
/**
* Initiates inviting a player who is no on the same server
*
* @param player The player target
* @param sender The sending player
*/
public void findAndInvite(String player, String sender) public void findAndInvite(String player, String sender)
{ {
Bukkit.getPlayerExact(sender).sendMessage(F.main("Party", "Locating " + player + "...")); Bukkit.getPlayerExact(sender).sendMessage(F.main("Party", "Locating " + player + "..."));
@ -156,7 +173,7 @@ public class PartyRedisManager
cancel(); cancel();
return; return;
} }
if(Bukkit.getPlayerExact(player) != null) if (Bukkit.getPlayerExact(player) != null)
{ {
cancel(); cancel();
return; return;
@ -173,11 +190,17 @@ public class PartyRedisManager
}); });
} }
/**
* Serializes and sends a party to another server
*
* @param server The destination server
* @param party The party to be sent
*/
public void sendPartyInfo(String server, Party party) public void sendPartyInfo(String server, Party party)
{ {
publish(server, PARTY_INFO, GSON.toJson(party)); publish(server, PARTY_INFO, GSON.toJson(party));
List<String> members = party.getMembers(); List<String> members = party.getMembers();
party.getMembersByUUID().stream().forEach(_plugin::removeForTransfer); party.getMembersByUUID().stream().forEach(uuid -> _plugin.getMethodManager().removeForTransfer(uuid));
members.stream().map(Bukkit::getPlayer).forEach(player1 -> members.stream().map(Bukkit::getPlayer).forEach(player1 ->
{ {
player1.leaveVehicle(); player1.leaveVehicle();
@ -187,6 +210,10 @@ public class PartyRedisManager
_plugin.removeParty(party); _plugin.removeParty(party);
} }
/**
* Deserialize and store a received party's information
* @param json
*/
public void handlePartyInfo(String json) public void handlePartyInfo(String json)
{ {
new BukkitRunnable() new BukkitRunnable()
@ -196,17 +223,23 @@ public class PartyRedisManager
{ {
Party party = GSON.fromJson(json, Party.class); Party party = GSON.fromJson(json, Party.class);
_plugin.addParty(party); _plugin.addParty(party);
party.getMembersByUUID().forEach(s -> _plugin.addToPartyOnTransfer(s, party)); party.getMembersByUUID().forEach(s -> _plugin.getMethodManager().addToPartyOnTransfer(s, party));
Bukkit.getServer().getPluginManager().callEvent(new PartyDataReceivedEvent(party)); Bukkit.getServer().getPluginManager().callEvent(new PartyDataReceivedEvent(party));
} }
}.runTaskLater(_plugin.getPlugin(), 10L); }.runTaskLater(_plugin.getPlugin(), 10L);
} }
/**
* @return This servers name
*/
public String getServerName() public String getServerName()
{ {
return _serverName; return _serverName;
} }
/**
* @return The channel constant for finding players
*/
public String getFinder() public String getFinder()
{ {
return FIND_PLAYERS_CHANNEL; return FIND_PLAYERS_CHANNEL;

View File

@ -9,7 +9,7 @@ import redis.clients.jedis.JedisPubSub;
public class PartyRedisListener extends JedisPubSub public class PartyRedisListener extends JedisPubSub
{ {
private PartyRedisManager _redisManager; private final PartyRedisManager _redisManager;
public PartyRedisListener(PartyRedisManager redisManager) public PartyRedisListener(PartyRedisManager redisManager)
{ {
@ -19,7 +19,6 @@ public class PartyRedisListener extends JedisPubSub
@Override @Override
public void onMessage(String channel, String message) public void onMessage(String channel, String message)
{ {
System.out.println("Message on " + channel + " :: " + message);
if(channel.equalsIgnoreCase(_redisManager.getFinder())) if(channel.equalsIgnoreCase(_redisManager.getFinder()))
{ {
_redisManager.handle(RedisMessageType.PLAYER_FIND_REQUEST, message); _redisManager.handle(RedisMessageType.PLAYER_FIND_REQUEST, message);

View File

@ -41,6 +41,11 @@ public enum RedisMessageType
return _id; return _id;
} }
/**
* Format this message
* @param args The contents to be sent with this message
* @return A formatted message
*/
public String format(String... args) public String format(String... args)
{ {
String message = _contents; String message = _contents;
@ -51,28 +56,4 @@ public enum RedisMessageType
return message; return message;
} }
public String getContents()
{
return _contents;
}
public RedisMessageType getResponse(int id)
{
switch (id) {
case 1:
return PLAYER_FIND_RESPONSE;
case 3:
return INVITE_PLAYER_RESPONSE;
case 5:
return PREJOIN_SERVER_RESPONSE;
default:
return null;
}
}
public RedisMessageType getResponse(RedisMessageType type)
{
return getResponse(type.getId());
}
} }

View File

@ -33,7 +33,7 @@ public abstract class Menu
.setLore(" ", C.cGray + "Purchase a rank @ mineplex.com/shop", C.cGray + "Purchasing a rank increases your", C.cGray + "party size to allow 10 people!") .setLore(" ", C.cGray + "Purchase a rank @ mineplex.com/shop", C.cGray + "Purchasing a rank increases your", C.cGray + "party size to allow 10 people!")
.build(), null); .build(), null);
protected static final Button[] EMPTY = new Button[45]; protected static final Button[] EMPTY = new Button[54];
protected static Map<UUID, Menu> MENUS = new HashMap<>(); protected static Map<UUID, Menu> MENUS = new HashMap<>();
private String _name; private String _name;
protected Button[] _buttons; protected Button[] _buttons;
@ -220,6 +220,41 @@ public abstract class Menu
} }
} }
/**
* Reset this players current menu's buttons and refresh the page
*
* @param player The player whose view you wish to update
*/
public void resetAndUpdate(Player player)
{
InventoryView view = player.getOpenInventory();
if (view == null)
{
return;
}
if (!view.getTitle().equalsIgnoreCase(getName()))
{
return;
}
Inventory inventory = view.getTopInventory();
Button[] buttons = setUp(player);
for (int i = 0; i < buttons.length; i++)
{
if (buttons[i] == null)
{
continue;
}
ItemStack item = buttons[i].getItemStack();
inventory.setItem(i, item);
}
}
public void setTitle(String title) public void setTitle(String title)
{ {
_name = title; _name = title;

View File

@ -39,17 +39,22 @@ public class PartyMemberIcon extends PartyButton
return _itemStack; return _itemStack;
} }
public PartyMemberIcon(String player, Party party) /**
{ * Called when a player clicks one of the member icons
this(player, party, false); *
} * @param clicker The player who clicked
* @param clicked The itemstack he clicked
*/
public void onClick(Player clicker, ItemStack clicked) public void onClick(Player clicker, ItemStack clicked)
{ {
if (!getParty().isOwnerKickMode()) if (!getParty().isOwnerKickMode())
{ {
return; return;
} }
if(!getParty().getOwner().equalsIgnoreCase(clicker.getName()))
{
return;
}
String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
UtilServer.getPluginManager().callEvent(new PartyMemberKickGUIEvent(getParty(), name, clicker)); UtilServer.getPluginManager().callEvent(new PartyMemberKickGUIEvent(getParty(), name, clicker));
} }

View File

@ -2,7 +2,6 @@ package mineplex.core.party.ui.button.tools;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Button;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -10,7 +9,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Leaves a players current party
*/ */
public class LeavePartyButton extends Button public class LeavePartyButton extends Button
{ {
@ -32,7 +31,7 @@ public class LeavePartyButton extends Button
{ {
return; return;
} }
player.chat("/party leave"); getPlugin().getMethodManager().leaveParty(player);
player.closeInventory(); player.closeInventory();
} }

View File

@ -6,7 +6,7 @@ import mineplex.core.party.ui.Button;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * A wrapper for all buttons which need to interact with a specific party
*/ */
public abstract class PartyButton extends Button public abstract class PartyButton extends Button
{ {

View File

@ -11,7 +11,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Sends a player back to the main page
*/ */
public class BackButton extends Button public class BackButton extends Button
{ {

View File

@ -4,7 +4,6 @@ import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Button;
import mineplex.core.party.ui.Menu;
import mineplex.core.party.ui.menus.PartyInvitesMenu; import mineplex.core.party.ui.menus.PartyInvitesMenu;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,7 +11,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Deny's all invites currently pending
*/ */
public class DenyAllButton extends Button public class DenyAllButton extends Button
{ {
@ -30,7 +29,7 @@ public class DenyAllButton extends Button
@Override @Override
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
{ {
getPlugin().getInviteManager().removeAll(player.getUniqueId()); getPlugin().getInviteManager().getAllInvites(player).forEach(inviteData -> getPlugin().getMethodManager().respondToInvite(player, inviteData.getInvitedTo(), false));
new PartyInvitesMenu(getPlugin()).open(player); new PartyInvitesMenu(getPlugin()).open(player);
} }
} }

View File

@ -11,7 +11,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Filters all current pending invites and displays only the results to a player
*/ */
public class FilterButton extends Button public class FilterButton extends Button
{ {

View File

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
/** /**
* * Represents an invitation, to which a player can accept or deny
*/ */
public class InviteButton extends Button public class InviteButton extends Button
{ {
@ -32,10 +32,10 @@ public class InviteButton extends Button
{ {
if(clickType == ClickType.LEFT) if(clickType == ClickType.LEFT)
{ {
player.chat("/party accept " + _name); getPlugin().getMethodManager().respondToInvite(player, _name, true);
} else if(clickType == ClickType.RIGHT) } else if(clickType == ClickType.RIGHT)
{ {
player.chat("/party deny " + _name); getPlugin().getMethodManager().respondToInvite(player, _name, false);
} }
player.closeInventory(); player.closeInventory();
} }

View File

@ -15,7 +15,7 @@ import org.bukkit.inventory.ItemStack;
import java.util.List; import java.util.List;
/** /**
* * Shows the next page of invites for a player
*/ */
public class NextPageButton extends Button public class NextPageButton extends Button
{ {

View File

@ -15,7 +15,7 @@ import org.bukkit.inventory.ItemStack;
import java.util.List; import java.util.List;
/** /**
* * Shows the previous page of invites for a player
*/ */
public class PrevPageButton extends Button public class PrevPageButton extends Button
{ {

View File

@ -11,7 +11,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Invites a player to a new party
*/ */
public class InvitePlayerButton extends Button public class InvitePlayerButton extends Button
{ {

View File

@ -1,7 +1,6 @@
package mineplex.core.party.ui.button.tools.main; package mineplex.core.party.ui.button.tools.main;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.inventory.data.Item;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Button;
@ -12,7 +11,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Opens the {@code {@link PartyInvitesMenu}}
*/ */
public class ViewInvitesButton extends Button public class ViewInvitesButton extends Button
{ {

View File

@ -12,7 +12,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Sends an invitation to a specific player
*/ */
public class AddPlayerButton extends PartyButton public class AddPlayerButton extends PartyButton
{ {

View File

@ -1,7 +1,6 @@
package mineplex.core.party.ui.button.tools.owner; package mineplex.core.party.ui.button.tools.owner;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.inventory.data.Item;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Button;
@ -11,7 +10,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Disbands a party
*/ */
public class DisbandPartyButton extends Button public class DisbandPartyButton extends Button
{ {
@ -33,7 +32,7 @@ public class DisbandPartyButton extends Button
{ {
return; return;
} }
player.chat("/party disband"); getPlugin().getMethodManager().disband(player);
player.closeInventory(); player.closeInventory();
} }
} }

View File

@ -12,7 +12,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Toggles {@code {@link Party#isOwnerKickMode()}}
*/ */
public class KickPlayerButton extends PartyButton public class KickPlayerButton extends PartyButton
{ {

View File

@ -4,9 +4,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.event.PartySelectServerEvent; import mineplex.core.party.event.PartySelectServerEvent;
import mineplex.core.party.ui.Button;
import mineplex.core.party.ui.button.tools.PartyButton; import mineplex.core.party.ui.button.tools.PartyButton;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -14,7 +12,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Opens the server selection menu
*/ */
public class SelectServerButton extends PartyButton public class SelectServerButton extends PartyButton
{ {

View File

@ -12,7 +12,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Transfers ownership of a party to another player
*/ */
public class TransferOwnerButton extends PartyButton public class TransferOwnerButton extends PartyButton
{ {

View File

@ -12,7 +12,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* * Suggest a new player to be invited
*/ */
public class SuggestPlayerButton extends PartyButton public class SuggestPlayerButton extends PartyButton
{ {

View File

@ -21,7 +21,7 @@ import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* * The menu showing all pending invites for a player
*/ */
public class PartyInvitesMenu extends Menu public class PartyInvitesMenu extends Menu
{ {
@ -33,6 +33,10 @@ public class PartyInvitesMenu extends Menu
private final int SLOTS_PER_PAGE = 27; private final int SLOTS_PER_PAGE = 27;
private final int STARTING_SLOT = 18; private final int STARTING_SLOT = 18;
private final int BACK_BUTTON_SLOT = 0;
private final int DENY_ALL_BUTTON_SLOW = 4;
private final int FILTER_BUTTON_SLOT = 8;
private final int NEXT_PAGE_SLOT = 53;
private int _currentPage; private int _currentPage;
private int _pagesNeeded; private int _pagesNeeded;
@ -56,8 +60,8 @@ public class PartyInvitesMenu extends Menu
protected Button[] setUp(Player player) protected Button[] setUp(Player player)
{ {
boolean showFiltered = false; boolean showFiltered = false;
Button[] buttons = new Button[54];
buttons[0] = new BackButton(_plugin); _buttons[BACK_BUTTON_SLOT] = new BackButton(_plugin);
List<InviteData> all = (List<InviteData>) _plugin.getInviteManager().getAllInvites(player); List<InviteData> all = (List<InviteData>) _plugin.getInviteManager().getAllInvites(player);
@ -65,21 +69,21 @@ public class PartyInvitesMenu extends Menu
{ {
for (int i = 10; i < 44; i++) for (int i = 10; i < 44; i++)
{ {
buttons[i] = NO_INVITES; _buttons[i] = NO_INVITES;
} }
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
return addPanes(buttons); return addPanes(_buttons);
} }
buttons[4] = new DenyAllButton(_plugin); _buttons[DENY_ALL_BUTTON_SLOW] = new DenyAllButton(_plugin);
if (_filterBy == null || _filterBy.isEmpty()) if (_filterBy == null || _filterBy.isEmpty())
{ {
buttons[8] = new FilterButton(_plugin); _buttons[FILTER_BUTTON_SLOT] = new FilterButton(_plugin);
} else } else
{ {
showFiltered = true; showFiltered = true;
buttons[8] = new FilterButton(_filterBy, _plugin); _buttons[FILTER_BUTTON_SLOT] = new FilterButton(_filterBy, _plugin);
} }
if (showFiltered) if (showFiltered)
@ -91,14 +95,14 @@ public class PartyInvitesMenu extends Menu
{ {
for (int i = 10; i < 44; i++) for (int i = 10; i < 44; i++)
{ {
buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) _buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE)
.setData(DyeColor.RED.getWoolData()) .setData(DyeColor.RED.getWoolData())
.setTitle(C.cRedB + "No Invites Found") .setTitle(C.cRedB + "No Invites Found")
.setLore(" ", C.cGray + "The filter " + F.name(_filterBy) + " had no results.") .setLore(" ", C.cGray + "The filter " + F.name(_filterBy) + " had no results.")
.build(), _plugin); .build(), _plugin);
} }
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
return addPanes(buttons); return addPanes(_buttons);
} }
_data = all; _data = all;
@ -112,7 +116,7 @@ public class PartyInvitesMenu extends Menu
pagesNeeded++; pagesNeeded++;
size -= SLOTS_PER_PAGE; size -= SLOTS_PER_PAGE;
} }
buttons[53] = new NextPageButton(this, _plugin); _buttons[NEXT_PAGE_SLOT] = new NextPageButton(this, _plugin);
_pagesNeeded = pagesNeeded; _pagesNeeded = pagesNeeded;
_pagesOfData = Maps.newHashMap(); _pagesOfData = Maps.newHashMap();
@ -141,12 +145,12 @@ public class PartyInvitesMenu extends Menu
for (int i = 0; i < all.size(); i++) for (int i = 0; i < all.size(); i++)
{ {
String to = all.get(i).getInvitedTo(); String to = all.get(i).getInvitedTo();
buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin); _buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin);
} }
} }
return buttons; return addPanes(_buttons);
} }
public void setButton(int slot, Button button) public void setButton(int slot, Button button)

View File

@ -13,6 +13,11 @@ import org.bukkit.entity.Player;
public class PartyMainMenu extends Menu public class PartyMainMenu extends Menu
{ {
private final int INV_SIZE = 9;
private final int INVITE_PLAYER_BUTTON_SLOT = 3;
private final int VIEW_INVITES_BUTTON_SLOT = 5;
public PartyMainMenu(PartyManager plugin) public PartyMainMenu(PartyManager plugin)
{ {
super("Mineplex Parties", plugin); super("Mineplex Parties", plugin);
@ -21,10 +26,10 @@ public class PartyMainMenu extends Menu
@Override @Override
protected Button[] setUp(Player player) protected Button[] setUp(Player player)
{ {
Button[] buttons = new Button[9]; Button[] buttons = new Button[INV_SIZE];
buttons[3] = new InvitePlayerButton(_plugin); buttons[INVITE_PLAYER_BUTTON_SLOT] = new InvitePlayerButton(_plugin);
buttons[5] = new ViewInvitesButton(_plugin); buttons[VIEW_INVITES_BUTTON_SLOT] = new ViewInvitesButton(_plugin);
return buttons; return buttons;
} }

View File

@ -5,64 +5,80 @@ import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Button;
import mineplex.core.party.ui.Menu; import mineplex.core.party.ui.Menu;
import mineplex.core.party.ui.button.PartyMemberIcon; import mineplex.core.party.ui.button.PartyMemberIcon;
import mineplex.core.party.ui.button.tools.owner.*;
import mineplex.core.party.ui.button.tools.LeavePartyButton; import mineplex.core.party.ui.button.tools.LeavePartyButton;
import org.bukkit.Material; import mineplex.core.party.ui.button.tools.owner.AddPlayerButton;
import mineplex.core.party.ui.button.tools.owner.DisbandPartyButton;
import mineplex.core.party.ui.button.tools.owner.KickPlayerButton;
import mineplex.core.party.ui.button.tools.owner.SelectServerButton;
import mineplex.core.party.ui.button.tools.owner.TransferOwnerButton;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/** /**
* The display menu for managing parties by the owner * The display menu for managing parties by the owner
*/ */
public class PartyOwnerMenu extends Menu public class PartyOwnerMenu extends Menu
{ {
private final int STARTING_SLOT = 20;
private final int CUT_OFF_SLOT = 25;
private final int SKIP_TO_SLOT = 29;
private final int ADD_PLAYER_BUTTON_SLOT = 1;
private final int KICK_PLAYER_BUTTON_SLOT = 4;
private final int TRANSFER_OWNER_BUTTON_SLOT = 7;
private final int SELECT_SERVER_BUTTON_SLOT = 46;
private final int LEAVE_PARTY_BUTTON_SLOT = 49;
private final int DISBAND_PARTY_BUTTON_SLOW = 52;
private Party _party; private Party _party;
public PartyOwnerMenu(Party party, PartyManager plugin) public PartyOwnerMenu(Party party, PartyManager plugin)
{ {
super("Manage Party", plugin); super("Manage Party", plugin);
_party = party; _party = party;
//We want this disabled by default
if(_party.isOwnerKickMode())
{
_party.setOwnerKickMode(false);
}
} }
@Override @Override
protected Button[] setUp(Player player) protected Button[] setUp(Player player)
{ {
Button[] buttons = new Button[54];
//Tools //Tools
buttons[1] = new AddPlayerButton(_plugin, _party); _buttons[ADD_PLAYER_BUTTON_SLOT] = new AddPlayerButton(_plugin, _party);
//Kick player //Kick player
buttons[4] = new KickPlayerButton(_party); _buttons[KICK_PLAYER_BUTTON_SLOT] = new KickPlayerButton(_party);
//Transfer ownership //Transfer ownership
buttons[7] = new TransferOwnerButton(_party, _plugin); _buttons[TRANSFER_OWNER_BUTTON_SLOT] = new TransferOwnerButton(_party, _plugin);
//Go to server //Go to server
buttons[46] = new SelectServerButton(_party); _buttons[SELECT_SERVER_BUTTON_SLOT] = new SelectServerButton(_party);
//Leave party //Leave party
buttons[49] = new LeavePartyButton(); _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton();
//Disband //Disband
buttons[52] = new DisbandPartyButton(_plugin); _buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(_plugin);
int slot = 20; int slot = STARTING_SLOT;
//Players //Players
for(int i = 0; i < _party.getMembers().size(); i++) for (int i = 0; i < _party.getMembers().size(); i++)
{ {
if(slot == 25) if (slot == CUT_OFF_SLOT)
{ {
slot = 29; slot = SKIP_TO_SLOT;
} }
buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i), _party); String member = _party.getMembers().get(i);
_buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner()));
} }
if(_party.getSize() == 5) if(_party.getSize() == 5)
{ {
for(int i = 29; i < 34; i++) for(int i = 29; i < 34; i++)
{ {
buttons[i] = PURCHASE_MORE_SLOTS; _buttons[i] = PURCHASE_MORE_SLOTS;
} }
} }
return addPanes(buttons); return addPanes(_buttons);
} }
} }

View File

@ -10,11 +10,17 @@ import mineplex.core.party.ui.button.tools.view.SuggestPlayerButton;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
* * The menu a player see's when he is a member, and not an owner, of a party.
*/ */
public class PartyViewMenu extends Menu public class PartyViewMenu extends Menu
{ {
private final int STARTING_SLOT = 20;
private final int CUT_OFF_SLOT = 25;
private final int SKIP_TO_SLOT = 29;
private final int LEAVE_PARTY_BUTTON_SLOT = 3;
private final int SUGGEST_PLAYER_BUTTON_SLOT = 5;
private Party _party; private Party _party;
public PartyViewMenu(Party party, PartyManager plugin) public PartyViewMenu(Party party, PartyManager plugin)
@ -26,23 +32,23 @@ public class PartyViewMenu extends Menu
@Override @Override
protected Button[] setUp(Player player) protected Button[] setUp(Player player)
{ {
Button[] buttons = new Button[54];
//Tools //Tools
buttons[3] = new LeavePartyButton(); _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton();
//Suggest Player //Suggest Player
buttons[5] = new SuggestPlayerButton(_party, _plugin); _buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, _plugin);
int slot = 20; int slot = STARTING_SLOT;
//Players //Players
for (int i = 0; i < _party.getMembers().size(); i++) for (int i = 0; i < _party.getMembers().size(); i++)
{ {
if (slot == 25) if (slot == CUT_OFF_SLOT)
{ {
slot = 29; slot = SKIP_TO_SLOT;
} }
buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i), _party); String member = _party.getMembers().get(i);
_buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner()));
} }
return addPanes(buttons); return addPanes(_buttons);
} }
} }

View File

@ -7,7 +7,7 @@ import mineplex.core.anvilMenu.PlayerInputActionMenu;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
* * The anvil menu for filtering the players invite menu
*/ */
public class InviteFilterMenu extends PlayerInputActionMenu public class InviteFilterMenu extends PlayerInputActionMenu
{ {
@ -21,7 +21,7 @@ public class InviteFilterMenu extends PlayerInputActionMenu
public void inputReceived(String name) public void inputReceived(String name)
{ {
_player.closeInventory(); _player.closeInventory();
if(name.equalsIgnoreCase("Clear Filter")) if(name.equalsIgnoreCase("Clear Filter") || name.equalsIgnoreCase(" "))
{ {
name = null; name = null;
} }

View File

@ -4,12 +4,11 @@ import mineplex.core.anvilMenu.player.PlayerNameMenu;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.menus.PartyOwnerMenu; import mineplex.core.party.ui.menus.PartyOwnerMenu;
import mineplex.core.anvilMenu.PlayerInputActionMenu;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
* * The anvil menu for inviting a player to a party
*/ */
public class PartyInvitePlayerMenu extends PlayerNameMenu public class PartyInvitePlayerMenu extends PlayerNameMenu
{ {
@ -25,7 +24,7 @@ public class PartyInvitePlayerMenu extends PlayerNameMenu
@Override @Override
public void onSuccess(String name) public void onSuccess(String name)
{ {
_player.chat("/party invite " + name); _partyManager.getMethodManager().invite(_player, name);
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f);
_player.closeInventory(); _player.closeInventory();
if (_party == null) if (_party == null)

View File

@ -4,7 +4,6 @@ import mineplex.core.anvilMenu.player.PlayerNameMenu;
import mineplex.core.party.Lang; import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.anvilMenu.PlayerInputActionMenu;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
@ -25,7 +24,7 @@ public class PartyTransferOwnerMenu extends PlayerNameMenu
@Override @Override
public void onSuccess(String name) public void onSuccess(String name)
{ {
_partyManager.transferOwner(name, _player.getName()); _partyManager.getMethodManager().transferOwner(name, _player.getName());
Lang.TRANSFER_OWNER.send(_party, _player.getName(), name); Lang.TRANSFER_OWNER.send(_party, _player.getName(), name);
_player.closeInventory(); _player.closeInventory();
_player.chat("/party"); _player.chat("/party");

View File

@ -13,12 +13,11 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
* * The Anvil Menu for handling suggestions
*/ */
public class PlayerSuggestPlayerMenu extends PlayerNameMenu public class PlayerSuggestPlayerMenu extends PlayerNameMenu
{ {
public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party) public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party)
{ {
super(partyManager, partyManager.getClientManager(), player, party); super(partyManager, partyManager.getClientManager(), player, party);
@ -36,6 +35,7 @@ public class PlayerSuggestPlayerMenu extends PlayerNameMenu
if(_party.contains(name)) if(_party.contains(name))
{ {
Lang.ALREADY_MEMBER.send(_player, name); Lang.ALREADY_MEMBER.send(_player, name);
return;
} }
Player player = Bukkit.getPlayerExact(_party.getOwner()); Player player = Bukkit.getPlayerExact(_party.getOwner());
@ -45,7 +45,7 @@ public class PlayerSuggestPlayerMenu extends PlayerNameMenu
ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Click ")); ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Click "));
message.add(F.link("Invite " + name)) message.add(F.link("Invite " + name))
.hover(HoverEvent.SHOW_TEXT, C.cGreen + "Clicking this will invite " + C.cYellow + name + C.cGreen + " to the party") .hover(HoverEvent.SHOW_TEXT, C.cGreen + "Clicking this will invite " + C.cYellow + name + C.cGreen + " to the party")
.click(ClickEvent.RUN_COMMAND, "/party invite " + name); .click(ClickEvent.RUN_COMMAND, "/partyinvite " + name);
message.add(C.mBody + " to invite them"); message.add(C.mBody + " to invite them");
message.sendToPlayer(player); message.sendToPlayer(player);