Party PR Updates.

This commit is contained in:
TadahTech 2016-07-20 16:18:49 -05:00
parent 67a185acc9
commit 96261c1a6d
9 changed files with 85 additions and 156 deletions

View File

@ -7,50 +7,19 @@ public class InviteData
{ {
private String _invitedTo; private String _invitedTo;
private String _invitedBy;
private long _timeStamp;
private long _expires;
private String _serverFrom; private String _serverFrom;
public InviteData(String invitedBy, String invitedTo, long timeStamp, String serverFrom) public InviteData(String invitedTo, String serverFrom)
{ {
_invitedBy = invitedBy;
_invitedTo = invitedTo; _invitedTo = invitedTo;
_timeStamp = timeStamp;
_expires = timeStamp + 60000;
_serverFrom = serverFrom; _serverFrom = serverFrom;
} }
public long getTimeRemaining()
{
return _expires - System.currentTimeMillis();
}
public boolean hasExpired()
{
return System.currentTimeMillis() >= _expires;
}
public String getInvitedTo() public String getInvitedTo()
{ {
return _invitedTo; return _invitedTo;
} }
public String getInvitedBy()
{
return _invitedBy;
}
public long getTimeStamp()
{
return _timeStamp;
}
public long getExpires()
{
return _expires;
}
public String getServerFrom() public String getServerFrom()
{ {
return _serverFrom; return _serverFrom;

View File

@ -1,7 +1,6 @@
package mineplex.core.party; package mineplex.core.party;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -58,45 +57,21 @@ public enum Lang
public void send(Player player, String... args) public void send(Player player, String... args)
{ {
String color = C.mBody; player.sendMessage(C.mHead + "Party> " + getFormatted(args));
if(args.length == 0)
{
player.sendMessage(F.main("Party", _message));
return;
}
if(_message.startsWith("Error:"))
{
color = C.cRed;
}
int firstIndex = _message.indexOf("{");
String[] coloredArgs = new String[args.length];
for(int i = 0; i < args.length; i++)
{
coloredArgs[i] = C.cYellow + args[i] + color;
}
String message = MessageFormat.format(_message, coloredArgs);
String coloredRest = message.substring(firstIndex);
message = color + message.substring(0, firstIndex) + coloredRest;
player.sendMessage(C.mHead + "Party> " + message);
} }
public void send(Party party, String... args) public void send(Party party, String... args)
{
party.sendMessage(C.mHead + "Party> " + getFormatted(args));
}
private String getFormatted(String[] args)
{ {
String color = C.mBody; String color = C.mBody;
if(args.length == 0) if(args.length == 0)
{ {
party.sendMessage(F.main("Party", _message)); return _message;
return;
} }
if(_message.startsWith("Error:")) if(_message.startsWith("Error:"))
@ -118,9 +93,7 @@ public enum Lang
String coloredRest = message.substring(firstIndex); String coloredRest = message.substring(firstIndex);
message = color + message.substring(0, firstIndex) + coloredRest; message = color + message.substring(0, firstIndex) + coloredRest;
return message;
party.sendMessage(C.mHead + "Party> " + message);
} }
} }

View File

@ -31,14 +31,14 @@ public class Party
private transient boolean _alreadyTeamed = false; private transient boolean _alreadyTeamed = false;
/** /**
* The standard _size for parties, for ALL {@code {@link mineplex.core.common.Rank}} * The standard size for parties, for ALL {@code {@link mineplex.core.common.Rank}}
*/ */
private transient final int PARTY_MIN_SIZE = 5; private static final int PARTY_MIN_SIZE = 5;
/** /**
* An upgrade _size for the party, given to donators and staff. * An upgraded size for the party, given to donators and staff.
*/ */
private transient final int PARTY_MAX_SIZE = 10; private static final int PARTY_MAX_SIZE = 10;
/** /**
* The current leader of this party * The current leader of this party
@ -158,7 +158,8 @@ public class Party
} }
_members.add(player); _members.add(player);
Lang.ADD_MEMBER.send(this, player); Lang.ADD_MEMBER.send(this, player);
getMembers().stream().forEach(s -> { getMembers().forEach(s ->
{
Player player1 = Bukkit.getPlayer(s); Player player1 = Bukkit.getPlayer(s);
player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F); player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F);
}); });

View File

@ -22,7 +22,7 @@ public class PartyCommand extends CommandBase<PartyManager>
F.main("Party", "Party Commands (Click the command!)"), F.main("Party", "Party Commands (Click the command!)"),
help("", "Brings up the Party GUI"), help("", "Brings up the Party GUI"),
help("<player>", "Send an invitation to a player."), help("<player>", "Send an invitation to a player."),
help("leave", "Send an invitation to a player."), help("leave", "Leave your current party."),
C.cBlue + "Party> " + C.cWhite + "#<message> " + C.cGray + "- Send a message to your party.", C.cBlue + "Party> " + C.cWhite + "#<message> " + C.cGray + "- Send a message to your party.",
C.cGreenB + "All party functions have been moved to the GUI!", C.cGreenB + "All party functions have been moved to the GUI!",
C.cGreenB + "Click the NameTag in your hotbar to get started!" C.cGreenB + "Click the NameTag in your hotbar to get started!"

View File

@ -8,14 +8,16 @@ import mineplex.core.common.util.F;
public enum JoinResponseReason public enum JoinResponseReason
{ {
CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")), CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!"), "no"),
SUCCESS(""); SUCCESS("", "yes");
private String _message; private String _message;
private String _code;
JoinResponseReason(String message) JoinResponseReason(String message, String code)
{ {
_message = message; _message = message;
_code = code;
} }
public String getMessage() public String getMessage()
@ -23,4 +25,8 @@ public enum JoinResponseReason
return _message; return _message;
} }
public String getCode()
{
return _code;
}
} }

View File

@ -5,30 +5,11 @@ package mineplex.core.party.constants;
*/ */
public enum PartyRemoveReason public enum PartyRemoveReason
{ {
KICKED(1, "kicked"), KICKED,
LEFT(2, "left"), LEFT,
OTHER(3, "other"), OTHER,
DISBANDED(4, "disbanded"), DISBANDED,
DISBANDED_BY_OWNER(5, "disbandedByOwner"), DISBANDED_BY_OWNER,;
;
private int _id;
private String _name;
PartyRemoveReason(int id, String name)
{
_id = id;
_name = name;
}
public int getId()
{
return _id;
}
public String getName()
{
return _name;
}
} }

View File

@ -209,7 +209,7 @@ public class PartyInviteManager
*/ */
public void inviteTo(UUID player, String invitedBy, String party, String server) public void inviteTo(UUID player, String invitedBy, String party, String server)
{ {
addToInvite(player, invitedBy, party, System.currentTimeMillis(), server); addToInvite(player, invitedBy, party, server);
_tasks.put(player, new BukkitRunnable() _tasks.put(player, new BukkitRunnable()
{ {
@Override @Override
@ -338,17 +338,16 @@ public class PartyInviteManager
* @param invited The invited players UUUD * @param invited The invited players UUUD
* @param invitedBy The person who invited him * @param invitedBy The person who invited him
* @param party The name of the party invited to * @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 * @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, String server)
{ {
List<InviteData> inviteDatas = _activeInvites.get(invited); List<InviteData> inviteDatas = _activeInvites.get(invited);
if (inviteDatas == null) if (inviteDatas == null)
{ {
inviteDatas = Lists.newArrayList(); inviteDatas = Lists.newArrayList();
} }
InviteData inviteData = new InviteData(invitedBy, party, currentTime, server); InviteData inviteData = new InviteData(party, server);
inviteDatas.add(inviteData); inviteDatas.add(inviteData);
_invitedBy.put(invited, invitedBy); _invitedBy.put(invited, invitedBy);
_activeInvites.put(invited, inviteDatas); _activeInvites.put(invited, inviteDatas);

View File

@ -21,9 +21,6 @@ import java.util.stream.Collectors;
public class PartyJoinManager public class PartyJoinManager
{ {
private final String CANNOT_JOIN = "no";
private final String CAN_JOIN = "yes";
private final PartyManager _plugin; private final PartyManager _plugin;
private final int _maxPLayers; private final int _maxPLayers;
private final List<UUID> _transferring; private final List<UUID> _transferring;
@ -74,12 +71,12 @@ 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(), CANNOT_JOIN, _plugin.getServerName()); _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), JoinResponseReason.CANNOT_JOIN_FULL.getCode(), _plugin.getServerName());
return; return;
} }
} }
_plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), CAN_JOIN, _plugin.getServerName()); _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), JoinResponseReason.SUCCESS.getCode(), _plugin.getServerName());
} }
@ -103,7 +100,7 @@ public class PartyJoinManager
{ {
return; return;
} }
if (response.equalsIgnoreCase(CANNOT_JOIN)) if (response.equalsIgnoreCase(JoinResponseReason.CANNOT_JOIN_FULL.getCode()))
{ {
party.sendMessage(reason.getMessage()); party.sendMessage(reason.getMessage());
return; return;

View File

@ -95,61 +95,64 @@ public class PartyRedisManager
String first = contents[0]; String first = contents[0];
String second = contents[1]; String second = contents[1];
String third = contents[2]; String third = contents[2];
switch (messageType) Bukkit.getScheduler().runTask(_plugin.getPlugin(), () -> {
{ switch (messageType)
case INVITE_PLAYER_REQUEST: {
_plugin.getInviteManager().handleInviteRequest(second, third, first); case INVITE_PLAYER_REQUEST:
break; _plugin.getInviteManager().handleInviteRequest(second, third, first);
break;
case INVITE_PLAYER_RESPONSE: case INVITE_PLAYER_RESPONSE:
_plugin.getInviteManager().handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase())); _plugin.getInviteManager().handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase()));
break; break;
case PLAYER_FIND_REQUEST: case PLAYER_FIND_REQUEST:
Player player = Bukkit.getPlayer(second); Player player = Bukkit.getPlayer(second);
if (player == null) if (player == null)
{ {
return; return;
} }
publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third); publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third);
break; break;
case PLAYER_FIND_RESPONSE: case PLAYER_FIND_RESPONSE:
UUID uuid = UUID.fromString(third); UUID uuid = UUID.fromString(third);
BukkitTask task = TASKS.remove(second); BukkitTask task = TASKS.remove(second);
if (task != null) if (task != null)
{ {
task.cancel(); task.cancel();
} }
Player inviter = Bukkit.getPlayerExact(contents[3]); Player inviter = Bukkit.getPlayerExact(contents[3]);
if (_plugin.getInviteManager().isInvitedTo(uuid, inviter.getName())) if (_plugin.getInviteManager().isInvitedTo(uuid, inviter.getName()))
{ {
Lang.ALREADY_INVITED.send(inviter, second); Lang.ALREADY_INVITED.send(inviter, second);
return; return;
} }
if (_plugin.getParty(inviter) == null) if (_plugin.getParty(inviter) == null)
{ {
Lang.INVITE_SUCCESS_PLAYER.send(inviter, second); Lang.INVITE_SUCCESS_PLAYER.send(inviter, second);
} else } else
{ {
Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second); Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second);
} }
_plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName()); _plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName());
publish(first, INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); publish(first, INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second);
break; break;
case PREJOIN_SERVER_REQUEST: case PREJOIN_SERVER_REQUEST:
_plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3])); _plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3]));
break; break;
case PREJOIN_SERVER_RESPONSE:
_plugin.getJoinManager().handleJoinResponse(first, third, contents[3], JoinResponseReason.valueOf(second.toUpperCase()));
break;
}
});
case PREJOIN_SERVER_RESPONSE:
_plugin.getJoinManager().handleJoinResponse(first, third, contents[3], JoinResponseReason.valueOf(second.toUpperCase()));
break;
}
} }
/** /**