diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java new file mode 100644 index 000000000..219a38ddb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -0,0 +1,97 @@ +package mineplex.core.party; + +import mineplex.core.common.util.C; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.F; + +import static sun.audio.AudioPlayer.player; + +/** + * All chat messages for the party system to align with PE + */ +public enum Lang +{ + + //Party + SUCCESS_SERVER_CONNECT("Sending you and your party to {0}..."), + INVITE_SUCCESS_PLAYER("Successfully invited {0} to the party."), + SUCCESS_INVITE("{0} has invited {1} to the party."), + INVITE_RECEIVED("You have been invited to {0}'s party!"), + INVITE_ACCEPT("{0} has joined the party."), + INVITE_DENY("{0} declined your invite."), + INVITE_EXPIRED("{0} did not respond in time."), + INVITE_EXPIRED_PLAYER("Your invite to {0}'s party has expired."), + + SHOW_MEMBERS("Party members: {0}."), + REMOVE_PLAYER("{0} has left the party."), + REMOVE_PLAYER_KICK("{0} has been removed from the party."), + ADD_MEMBER("{0} has joined the party."), + LEFT("You have left your party."), + PARTY_OWNER_LEAVE("{0} has left the party. {1} is the new party owner."), + TRANSFER_OWNER("{0} has given party leadership to {1}."), + DISBANDED("Your party has been disbanded, due to a lack of players."), + REMOVED("You have been removed from the party."), + + NOT_EXIST("Error: {0} is not in a party right now."), + ALREADY_MEMBER("Error: {0} is already in the party!"), + NO_PARTY("Error: You are not in a party!"), + ALREADY_IN("Error: You are already in a party! Type {0} to leave."), + NOT_MEMBER("Error: {0} is not a member of your party."), + NOT_INVITED("Error: You do not have a pending invite to {0}'s party."), + NOT_OWNER("Error: You must be the party owner to do this!"), + NOT_OWNER_SERVER("Error: You must be the owner to move servers!"), + ALREADY_INVITED("Error: {0} has already been invited."), + PARTY_FULL("Error: Your party is full!"), + SERVER_CLOSED("Error: Your server is closed and you cannot invite players to join it right now!"), + SERVER_FULL("Error: Your server is full and you cannot invite more players to join it right now!"), + + ; + + private String _message; + + Lang(String message) + { + _message = message; + } + + public void send(Player player, String... args) + { + String message = _message; + String colored = ""; + if(args.length == 0) + { + player.sendMessage(F.main("Party", _message)); + return; + } + + for(int i = 0; i < args.length; i++) + { + String s = args[i]; + message = message.replace("{" + i + "}", F.elem(s)); + colored = C.mBody + message; + } + player.sendMessage(C.mHead + "Party> " + colored); + } + + public void send(Party party, String... args) + { + String message = _message; + String colored = ""; + if(args.length == 0) + { + party.sendMessage(F.main("Party", _message)); + return; + } + + for(int i = 0; i < args.length; i++) + { + String s = args[i]; + message = message.replace("{" + i + "}", F.elem(s)); + colored = C.mBody + message; + } + party.sendMessage(C.mHead + "Party> " + colored); + } + + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 7bad7d233..7f44b8250 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -2,7 +2,13 @@ package mineplex.core.party; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import mineplex.core.chat.Chat; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.party.event.PartyTransferOwnerEvent; +import mineplex.core.party.event.PartyTransferOwnerEvent.TransferReason; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import java.util.List; import java.util.Map; @@ -13,9 +19,17 @@ import java.util.Map; public class Party { + private transient boolean _ownerKickMode = false; + private String _owner; private List _members; private Map _invites; + private int size; + + public Party() + { + + } public Party(String owner) { @@ -49,4 +63,71 @@ public class Party { getMembers().stream().map(Bukkit::getPlayer).forEach(player -> player.sendMessage(message)); } + + public int getSize() + { + return size; + } + + public void setSize(int size) + { + this.size = size; + } + + public void onPlayerAdd(String player) + { + _invites.remove(player); + if(_members.contains(player)) + { + return; + } + _members.add(player); + Lang.ADD_MEMBER.send(this, player); + } + + public void onPlayerRemove(String player, PartyRemoveReason reason) + { + if(reason == PartyRemoveReason.DISBANDED) + { + Player bukkitPlayer = Bukkit.getPlayerExact(player); + Lang.DISBANDED.send(bukkitPlayer); + return; + } + if(_members.size() <= 0) + { + return; + } + if(reason == PartyRemoveReason.LEFT) + { + Lang.REMOVE_PLAYER.send(this, player); + if(player.equalsIgnoreCase(_owner)) + { + _owner = _members.get(0); + Lang.TRANSFER_OWNER.send(this, player, _owner); + PartyTransferOwnerEvent event = new PartyTransferOwnerEvent(this, _owner, player, TransferReason.LEFT); + UtilServer.getServer().getPluginManager().callEvent(event); + } + return; + } + if(reason == PartyRemoveReason.OTHER) + { + return; + } + Lang.REMOVE_PLAYER_KICK.send(this, player); + } + + public boolean isOwnerKickMode() + { + return _ownerKickMode; + } + + public void setOwnerKickMode(boolean ownerKickMode) + { + _ownerKickMode = ownerKickMode; + } + + public void setOwner(String owner) + { + _owner = owner; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java new file mode 100644 index 000000000..b72ebb424 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -0,0 +1,99 @@ +package mineplex.core.party; + +import mineplex.core.common.Rank; +import mineplex.core.party.event.PartyMemberKickGUIEvent; +import mineplex.core.party.event.PartyTransferOwnerEvent; +import mineplex.core.party.manager.PartyRedisManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +/** + * + */ +public class PartyEventListener implements Listener +{ + + private final PartyManager _plugin; + private final PartyRedisManager _redisManager; + + public PartyEventListener(PartyManager plugin, PartyRedisManager redisManager) + { + _plugin = plugin; + _redisManager = redisManager; + _plugin.getPluginManager().registerEvents(this, plugin.getPlugin()); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + + String partyName = _plugin.getInviteManager().getPartyWaiting(player.getUniqueId()); + + if(partyName == null) + { + return; + } + + Party party = _plugin.getParty(partyName); + + Player bukkitPlayer = Bukkit.getPlayerExact(partyName); + + if(party == null) + { + party = new Party(partyName); + + int size = 5; + + if(bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().isDonor()) + { + size = 10; + } + + party.setSize(size); + _plugin.addParty(party); + } + + _plugin.addToParty(Bukkit.getPlayerExact(partyName), party); + + _plugin.addToParty(player, party); + + _plugin.getInviteManager().removeFromWaiting(player.getUniqueId()); + + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) + { + Player player = event.getPlayer(); + + Party party = _plugin.getParty(player); + + _plugin.getInviteManager().removeAll(player.getUniqueId()); + + if (party == null) + { + return; + } + + _plugin.removeFromParty(player, PartyRemoveReason.LEFT); + } + + + @EventHandler + public void onTransferOwner(PartyTransferOwnerEvent event) + { + _plugin.transferOwner(event.getNewOwner(), event.getOldOwner()); + } + + @EventHandler + public void onKick(PartyMemberKickGUIEvent event) + { + _plugin.removeFromParty(Bukkit.getPlayerExact(event.getPlayerClicked()), PartyRemoveReason.KICKED); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index 77d010ea4..2e54d14e6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -1,6 +1,8 @@ package mineplex.core.party; import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.party.command.PartyCommand; @@ -12,6 +14,7 @@ import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.serverdata.Utility; import mineplex.serverdata.servers.ServerManager; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -47,9 +50,9 @@ public class PartyManager extends MiniPlugin _joinManager = new PartyJoinManager(this); addCommand(new PartyCommand(this)); getPluginManager().registerEvents(new MenuListener(), getPlugin()); + new PartyEventListener(this, _redisManager); } - public Party getParty(String party) { return _parties.get(party); @@ -68,6 +71,13 @@ public class PartyManager extends MiniPlugin public void addToParty(UUID uuid, Party party) { _players.put(uuid, party); + Player player = Bukkit.getPlayer(uuid); + party.onPlayerAdd(player.getName()); + } + + public void addToParty(Player player, Party party) + { + addToParty(player.getUniqueId(), party); } public void removeParty(Party party) @@ -75,11 +85,56 @@ public class PartyManager extends MiniPlugin _parties.remove(party.getName()); } - public void removeFromParty(UUID uuid) + public void removeFromParty(UUID uuid, PartyRemoveReason reason) { - _players.remove(uuid); + Party party = _players.remove(uuid); + if(party == null) + { + return; + } + Player player = Bukkit.getPlayer(uuid); + party.getMembers().remove(player.getName()); + 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) + { + party.getMembers().stream().map(Bukkit::getPlayer).forEach(player -> removeFromParty(player.getUniqueId(), PartyRemoveReason.KICKED)); + removeParty(party); + } + + public void transferOwner(String newOwner, String oldOwner) + { + Party party = _parties.remove(oldOwner.toLowerCase()); + _parties.put(newOwner.toLowerCase(), party); + party.getMembers().stream().map(Bukkit::getPlayer).forEach(s -> + { + _players.remove(s.getUniqueId()); + _players.put(s.getUniqueId(), party); + }); + party.setOwner(newOwner); + party.getMembers().remove(oldOwner); + party.getMembers().add(oldOwner); + } + + public Portal getPortal() { return _portal; @@ -114,4 +169,6 @@ public class PartyManager extends MiniPlugin { return _joinManager; } + + } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java new file mode 100644 index 000000000..a0930d375 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java @@ -0,0 +1,33 @@ +package mineplex.core.party; + +/** + * + */ +public enum PartyRemoveReason +{ + KICKED(1, "kicked"), + LEFT(2, "left"), + OTHER(3, "other"), + DISBANDED(4, "disbanded"), + ; + + 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; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java index ec1ac4284..fadd539ac 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -7,8 +7,10 @@ import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; 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.PartyRemoveReason; import mineplex.core.party.manager.PartyInviteManager; import mineplex.core.party.ui.menus.PartyMainMenu; import mineplex.core.party.ui.menus.PartyOwnerMenu; @@ -35,7 +37,7 @@ public class PartyCommand extends CommandBase help("leave", "Leave your current party"), help("kick ", "Kick a player from your party."), help("disband", "Disband your party."), - C.cBlue + "Party> " + C.cWhite + "# " + C.cGray + "- Send a message tp your party." + C.cBlue + "Party> " + C.cWhite + "# " + C.cGray + "- Send a message to your party." }; public PartyCommand(PartyManager plugin) @@ -126,12 +128,46 @@ public class PartyCommand extends CommandBase private void handleInvite(Player caller, String target) { - Player possible = Bukkit.getPlayer(target); + Player possible = Bukkit.getPlayerExact(target); + Party party = Plugin.getParty(caller); + + //Same Server if (possible != null) { + if (party == null) + { + Lang.INVITE_SUCCESS_PLAYER.send(caller, target); + } 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(party.getMembers().size() >= party.getSize()) + { + Lang.PARTY_FULL.send(caller); + return; + } + Lang.SUCCESS_INVITE.send(party, caller.getName(), target); + } + UUID uuid = possible.getUniqueId(); - caller.sendMessage(F.main("Party", "Sent an invite to " + possible.getName() + "...")); + + Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName()); + Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName()); + Plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName()); return; } @@ -145,7 +181,7 @@ public class PartyCommand extends CommandBase if (!inviteManager.isInvitedTo(caller.getUniqueId(), target)) { //He isn't invited to this party. - caller.sendMessage(F.main("Party", "You do not have an invitation to " + F.elem(target))); + Lang.NOT_INVITED.send(caller, target); return; } @@ -158,37 +194,35 @@ public class PartyCommand extends CommandBase if (party == null) { - caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); + Lang.NO_PARTY.send(caller); return; } if (!party.getOwner().equalsIgnoreCase(caller.getName())) { - caller.sendMessage(F.main("Party", "You must be the leader of the party to do that!")); + Lang.NOT_OWNER.send(caller); return; } - Player playerTarget = Bukkit.getPlayer(target); + Player playerTarget = Bukkit.getPlayerExact(target); if (playerTarget == null) { - caller.sendMessage(F.main("Party", target + " is not online, and is not in your party!")); + Lang.NOT_MEMBER.send(caller, target); return; } Party targetParty = Plugin.getParty(playerTarget); - if (targetParty == null || party.getMembers().contains(target)) + if (targetParty == null ||!party.getMembers().contains(target)) { - caller.sendMessage(F.main("Party", target + " is not a member of your party.")); + Lang.NOT_MEMBER.send(caller, target); return; } - Plugin.removeFromParty(playerTarget.getUniqueId()); - party.getMembers().remove(target); + Plugin.removeFromParty(playerTarget.getUniqueId(), PartyRemoveReason.KICKED); - targetParty.sendMessage(F.main("Party", "You have been removed from " + party.getName() + ".")); - party.sendMessage(F.main("Party", caller.getName() + " has removed " + target + " from the party.")); + Lang.REMOVE_PLAYER_KICK.send(targetParty); } private void handleLeave(Player caller) @@ -197,14 +231,12 @@ public class PartyCommand extends CommandBase if (party == null) { - caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); + Lang.NO_PARTY.send(caller); return; } - party.getMembers().remove(caller.getName()); - Plugin.removeFromParty(caller.getUniqueId()); - caller.sendMessage(F.main("Party", "You have left " + party.getOwner() + "'s party")); - party.sendMessage(F.main("Party", caller.getName() + " has left the party.")); + Plugin.removeFromParty(caller.getUniqueId(), PartyRemoveReason.LEFT); + Lang.LEFT.send(caller); } private void handleDisband(Player caller) @@ -213,23 +245,17 @@ public class PartyCommand extends CommandBase if (party == null) { - caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); + Lang.NO_PARTY.send(caller); return; } if (!party.getOwner().equalsIgnoreCase(caller.getName())) { - caller.sendMessage(F.main("Party", "You must be the leader of the party to do that!")); + Lang.NOT_OWNER.send(caller); return; } - party.sendMessage(F.main("Party", caller.getName() + " has disbanded the party!")); - - party.getMembers().stream().map(Bukkit::getPlayer).forEach(player -> Plugin.removeFromParty(player.getUniqueId())); - - party.getMembers().clear(); - party.getInvites().clear(); - Plugin.removeParty(party); + Plugin.disbandParty(party); } private String help(String command, String description) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyDataReceivedEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyDataReceivedEvent.java new file mode 100644 index 000000000..d4d25f699 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyDataReceivedEvent.java @@ -0,0 +1,37 @@ +package mineplex.core.party.event; + +import mineplex.core.party.Party; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * An event called when a server receives a PartyPacket containing the information about a party + */ +public class PartyDataReceivedEvent extends Event +{ + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Party _party; + + public PartyDataReceivedEvent(Party party) + { + _party = party; + } + + public Party getParty() + { + return _party; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyMemberKickGUIEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyMemberKickGUIEvent.java new file mode 100644 index 000000000..885567240 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyMemberKickGUIEvent.java @@ -0,0 +1,51 @@ +package mineplex.core.party.event; + +import mineplex.core.party.Party; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * This event is called when an owner clicks a PartyMemberIcon while having Kick mode activated. + */ +public class PartyMemberKickGUIEvent extends Event +{ + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Party _party; + private final String _playerClicked; + private final Player _owner; + + public PartyMemberKickGUIEvent(Party party, String playerClicked, Player owner) + { + _party = party; + _playerClicked = playerClicked; + _owner = owner; + } + + public String getPlayerClicked() + { + return _playerClicked; + } + + public Player getOwner() + { + return _owner; + } + + public Party getParty() + { + return _party; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java new file mode 100644 index 000000000..a937443c0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java @@ -0,0 +1,36 @@ +package mineplex.core.party.event; + +import mineplex.core.party.Party; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * This event is called when a party owner selects the compass icon. + */ +public class PartySelectServerEvent extends Event +{ + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Party _party; + + public PartySelectServerEvent(Party party) + { + _party = party; + } + + public Party getParty() + { + return _party; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyTransferOwnerEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyTransferOwnerEvent.java new file mode 100644 index 000000000..c21abd883 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyTransferOwnerEvent.java @@ -0,0 +1,65 @@ +package mineplex.core.party.event; + +import mineplex.core.party.Party; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * An event called when an owner leaves a party + */ +public class PartyTransferOwnerEvent extends Event +{ + + public enum TransferReason + { + LEFT, + TRANSFER; + } + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Party _party; + private final String _newOwner; + private final String _oldOwner; + private final TransferReason _reason; + + public PartyTransferOwnerEvent(Party party, String newOwner, String oldOwner, TransferReason reason) + { + _party = party; + _newOwner = newOwner; + _oldOwner = oldOwner; + _reason = reason; + } + + public String getNewOwner() + { + return _newOwner; + } + + public String getOldOwner() + { + return _oldOwner; + } + + public TransferReason getReason() + { + return _reason; + } + + public Party getParty() + { + return _party; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java index 82150b8a0..1e35d6130 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -2,8 +2,10 @@ package mineplex.core.party.manager; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.party.InviteData; +import mineplex.core.party.Lang; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; import mineplex.core.party.redis.RedisMessageType; @@ -42,7 +44,7 @@ public class PartyInviteManager public String format(String target) { - return String.format(_message, target); + return C.mHead + "Party> " + F.name(target) + " " + _message.substring(_message.indexOf("}" + 1)); } } @@ -78,7 +80,7 @@ public class PartyInviteManager String message = InviteResponse.DENIED.format(player.getName()); if (newParty == null) { - player.sendMessage(message); + possible.sendMessage(message); return; } newParty.sendMessage(message); @@ -89,10 +91,7 @@ public class PartyInviteManager newParty = new Party(possible.getName()); _plugin.addParty(newParty); _plugin.addToParty(possible.getUniqueId(), newParty); - possible.sendMessage(F.main("Party", "Created a new party!")); } - newParty.getMembers().add(player.getName()); - newParty.sendMessage(F.main("Party", player.getName() + " has joined the party")); _plugin.addToParty(player.getUniqueId(), newParty); return; } @@ -114,6 +113,7 @@ public class PartyInviteManager _players.put(player.getUniqueId(), player.getName()); INVITE_FROM_SERVERS.put(target, serverFrom); inviteTo(player.getUniqueId(), sender, sender); + Lang.INVITE_RECEIVED.send(player, sender); sendAcceptOrDeny(player, sender); } @@ -137,7 +137,6 @@ public class PartyInviteManager party = new Party(sender); _plugin.addParty(party); _plugin.addToParty(player.getUniqueId(), party); - player.sendMessage(F.main("Party", "Created a new party!")); } party.sendMessage(message); addToPendingJoin(targetUUID, party.getName()); @@ -147,7 +146,6 @@ public class PartyInviteManager if (party == null) { player.sendMessage(message); - player.sendMessage(F.main("Party", "Party not created.")); return; } party.sendMessage(message); @@ -155,6 +153,18 @@ public class PartyInviteManager } } + /** + * Remove all references tied with this player + * + * @param player The player's UUID + */ + public void removeAll(UUID player) + { + _players.remove(player); + _invitedBy.remove(player); + _activeInvites.remove(player); + } + /** * Get the name of the server that this request was initiated from. * @@ -177,6 +187,16 @@ public class PartyInviteManager return _awaitingJoin.get(player); } + /** + * Remove the party reference that invited this player + * + * @param player The player's UUID + */ + public void removeFromWaiting(UUID player) + { + _awaitingJoin.remove(player); + } + /** * Get the name of the person who has invited the target player * Used mainly for player locating @@ -296,7 +316,6 @@ public class PartyInviteManager public void sendAcceptOrDeny(Player player, String arg) { - player.sendMessage(F.main("Party", "You have received an invite from " + arg)); TextComponent textComponent = new TextComponent(F.main("Party", "Click one: ")); TextComponent accept = new TextComponent("ACCEPT"); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java index de2bbdc27..b0bd8cf53 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -64,7 +64,7 @@ public class PartyJoinManager public void handleJoinRequest(String serverFrom, int partySize, String initiator, boolean canJoinFull) { int currentPlayers = UtilServer.getPlayers().length; - if (currentPlayers >= _maxPLayers) + if (currentPlayers >= _maxPLayers || (currentPlayers + partySize) >= _maxPLayers) { //Max number of people on. if (!canJoinFull) @@ -74,6 +74,7 @@ public class PartyJoinManager return; } } + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, "yes", "none"); } @@ -95,6 +96,7 @@ public class PartyJoinManager return; } party.sendMessage(F.main("Party", "Transferring servers...")); + _plugin.getRedisManager().sendPartyInfo(server, party); party.getMembers().stream().map(Bukkit::getPlayer).forEach(player1 -> _plugin.getPortal().sendPlayerToServer(player1, server)); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java index 9a345660c..1e359df51 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -1,8 +1,14 @@ package mineplex.core.party.manager; import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; 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.PartyRemoveReason; +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; @@ -22,6 +28,8 @@ import java.util.UUID; */ public class PartyRedisManager { + protected final Gson GSON = new GsonBuilder().create(); + protected static final String CHANNEL_BASE = "party-pubsub"; protected static final String FIND_PLAYERS_CHANNEL = "party-player-finder"; private final Map TASKS = Maps.newHashMap(); @@ -62,7 +70,7 @@ public class PartyRedisManager public void handle(RedisMessageType messageType, String message) { String[] contents = message.split("-"); - if(contents.length < 3) + if (contents.length < 3) { return; } @@ -71,6 +79,10 @@ public class PartyRedisManager String third = contents[2]; switch (messageType) { + case PARTY_INFO: + handlePartyInfo(first); + break; + case INVITE_PLAYER_REQUEST: _inviteManager.handleInviteRequest(second, third, first); break; @@ -82,26 +94,37 @@ public class PartyRedisManager case PLAYER_FIND_REQUEST: Player player = Bukkit.getPlayer(second); - if(player == null) + if (player == null) { return; } - publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, - _serverName, player.getName(), player.getUniqueId().toString(), second); + publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), second); break; case PLAYER_FIND_RESPONSE: UUID uuid = UUID.fromString(third); BukkitTask task = TASKS.remove(second); - if(task != null) + if (task != null) { task.cancel(); } - - _inviteManager.inviteTo(uuid, contents[3], contents[3]); - publish(first, RedisMessageType.INVITE_PLAYER_REQUEST, _serverName, contents[3], second); + Player inviter = Bukkit.getPlayerExact(contents[3]); + if (_inviteManager.isInvitedTo(uuid, inviter.getName())) + { + Lang.ALREADY_INVITED.send(inviter, second); + return; + } + if (_plugin.getParty(inviter) == null) + { + Lang.INVITE_SUCCESS_PLAYER.send(inviter, second); + } else + { + Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second); + } + _inviteManager.inviteTo(uuid, inviter.getName(), inviter.getName()); + publish(first, RedisMessageType.INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); break; case PREJOIN_SERVER_REQUEST: @@ -123,7 +146,7 @@ public class PartyRedisManager { TASKS.remove(player); Player senderPlayer = Bukkit.getPlayerExact(sender); - if(senderPlayer == null) + if (senderPlayer == null) { return; } @@ -139,5 +162,32 @@ public class PartyRedisManager }); } + public void sendPartyInfo(String server, Party party) + { + publish(server, RedisMessageType.PARTY_INFO, GSON.toJson(party)); + _plugin.removeParty(party); + party.getMembers().stream().map(Bukkit::getPlayer).forEach(player -> _plugin.removeFromParty(player.getUniqueId(), PartyRemoveReason.OTHER)); + } + public void handlePartyInfo(String json) + { + new BukkitRunnable() + { + @Override + public void run() + { + Party party = GSON.fromJson(json, Party.class); + _plugin.addParty(party); + party.getMembers().forEach(s -> + { + Player player = Bukkit.getPlayerExact(s); + if (player != null) + { + _plugin.addToParty(player, party); + } + }); + Bukkit.getServer().getPluginManager().callEvent(new PartyDataReceivedEvent(party)); + } + }.runTaskLater(_plugin.getPlugin(), 10L); + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java index c84b797ab..6941a03cb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -19,7 +19,6 @@ public class PartyRedisListener extends JedisPubSub @Override public void onMessage(String channel, String message) { - System.out.println(channel + " - " + message); RedisMessageType type = RedisMessageType.valueOf(message.split(":")[0].toUpperCase()); _redisManager.handle(type, message.split(":")[1]); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java index 3ca54cbc2..6cb302507 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -20,7 +20,10 @@ public enum RedisMessageType //Message: SERVER_FROM-PLAYER_INITIATING-PARTY_SIZE-_CAN_JOIN_FULL PREJOIN_SERVER_REQUEST(5, "{0}-{1}-{2}-{3}"), //Message: PLAYER_INITIATING-RESPONSE-REASON-SERVER - PREJOIN_SERVER_RESPONSE(6, "{0}-{1}-{2}-[3}") + PREJOIN_SERVER_RESPONSE(6, "{0}-{1}-{2}-[3}"), + + //Message: JSON Party + PARTY_INFO(7, "{0}") ; private int _id; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java index d925e5162..bec91ee99 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java @@ -1,9 +1,12 @@ package mineplex.core.party.ui; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.button.IconButton; import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; +import org.bukkit.DyeColor; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; @@ -19,176 +22,210 @@ import java.util.UUID; public abstract class Menu { - protected static final Button[] EMPTY = new Button[45]; - protected static Map MENUS = new HashMap<>(); - private String _name; - protected Button[] _buttons; + protected static final Button PANE = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) + .setTitle(" ") + .setData(DyeColor.LIGHT_BLUE.getWoolData()) + .build(), null); + + protected static final Button[] EMPTY = new Button[45]; + protected static Map MENUS = new HashMap<>(); + private String _name; + protected Button[] _buttons; protected PartyManager _plugin; - public Menu(String name, PartyManager plugin) - { - _name = name; - _buttons = EMPTY; - _plugin = plugin; - } + public Menu(String name, PartyManager plugin) + { + _name = name; + _buttons = EMPTY; + _plugin = plugin; + } - public static Menu get(UUID name) - { - return MENUS.get(name); - } + public static Menu get(UUID name) + { + return MENUS.get(name); + } + /** + * Create an icon (no click action) + * + * @param item The itemstack ti display + * @return The created button + */ + protected Button create(ItemStack item) + { + return new IconButton(item, _plugin); + } - /** - * Create an icon (no click action) - * - * @param item The itemstack ti display - * @return The created button - */ - protected Button create(ItemStack item) - { - return new IconButton(item, _plugin); - } + public String getName() + { + return ChatColor.translateAlternateColorCodes('&', _name); + } - public String getName() - { - return ChatColor.translateAlternateColorCodes('&', _name); - } + public Button[] addPanes(Button[] buttons) + { + for (int i = 0; i < 9; i++) + { + if (buttons[i] == null) + { + buttons[i] = PANE; + } - /** - * Open and setup the inventory for the player to view - * Store a reference to it inside a map for retrieving later - * - * @param player The player who we wish to show the GUI to - */ - public void open(Player player) - { - setButtons(setUp(player)); + if(buttons.length == 9) + { + continue; + } - if (MENUS.get(player.getUniqueId()) != null) - { - MENUS.remove(player.getUniqueId()); - } + if (buttons[i + buttons.length - 9] == null) + { + buttons[i + buttons.length - 9] = PANE; + } - MENUS.put(player.getUniqueId(), this); + if (i == 0 || i == 8) + { + for (int a = 9; a < buttons.length; a += 9) + { + buttons[i + a] = PANE; + } + } + } + return buttons; + } - int size = (_buttons.length + 8) / 9 * 9; - Inventory inventory = Bukkit.createInventory(player, size, getName()); + /** + * Open and setup the inventory for the player to view + * Store a reference to it inside a map for retrieving later + * + * @param player The player who we wish to show the GUI to + */ + public void open(Player player) + { + setButtons(setUp(player)); - for (int i = 0; i < _buttons.length; i++) - { - if (_buttons[i] == null) - { - continue; - } + if (MENUS.get(player.getUniqueId()) != null) + { + MENUS.remove(player.getUniqueId()); + } - ItemStack item = _buttons[i].getItemStack(); + MENUS.put(player.getUniqueId(), this); - inventory.setItem(i, item); - } - player.openInventory(inventory); - } + int size = (_buttons.length + 8) / 9 * 9; + Inventory inventory = Bukkit.createInventory(player, size, getName()); - /** - * Set up the GUI with buttons - * - * @return The setup button array - */ - protected abstract Button[] setUp(Player player); + for (int i = 0; i < _buttons.length; i++) + { + if (_buttons[i] == null) + { + continue; + } - public Button[] getButtons() - { - return _buttons; - } + ItemStack item = _buttons[i].getItemStack(); - public void setButtons(Button[] buttons) - { - _buttons = buttons; - } + inventory.setItem(i, item); + } + player.openInventory(inventory); + } - /** - * Retrieve the button based off the slot - * - * @param slot The slot in the inventory - * @return The button corresponding to that slot - */ - public Button getButton(int slot) - { - try - { - return _buttons[slot]; - } catch (ArrayIndexOutOfBoundsException e) - { - //There isn't a button there, so no need to throw an error - //e.printStackTrace(); - return null; - } - } + /** + * Set up the GUI with buttons + * + * @return The setup button array + */ + protected abstract Button[] setUp(Player player); - /** - * Replace a button, or create a new button dynamically - * Update the players GUI - * - * @param slot The slot to set the new button - * @param button The reference to the button - * @param player The player whose GUI we'll be updating - */ - public void setButton(int slot, Button button, Player player) - { - try - { - _buttons[slot] = button; - } catch (ArrayIndexOutOfBoundsException ignored) - { - ignored.printStackTrace(); - } - update(player); - } + public Button[] getButtons() + { + return _buttons; + } - /** - * Refresh the players view, allows to change what the player sees, without opening and closing the GUI - * - * @param player The player whose view you wish to update - */ - public void update(Player player) - { - InventoryView view = player.getOpenInventory(); + public void setButtons(Button[] buttons) + { + _buttons = buttons; + } - if (view == null) - { - return; - } + /** + * Retrieve the button based off the slot + * + * @param slot The slot in the inventory + * @return The button corresponding to that slot + */ + public Button getButton(int slot) + { + try + { + return _buttons[slot]; + } catch (ArrayIndexOutOfBoundsException e) + { + //There isn't a button there, so no need to throw an error + //e.printStackTrace(); + return null; + } + } - if (!view.getTitle().equalsIgnoreCase(getName())) - { - return; - } + /** + * Replace a button, or create a new button dynamically + * Update the players GUI + * + * @param slot The slot to set the new button + * @param button The reference to the button + * @param player The player whose GUI we'll be updating + */ + public void setButton(int slot, Button button, Player player) + { + try + { + _buttons[slot] = button; + } catch (ArrayIndexOutOfBoundsException ignored) + { + ignored.printStackTrace(); + } + update(player); + } - Inventory inventory = view.getTopInventory(); - for (int i = 0; i < _buttons.length; i++) - { - if (_buttons[i] == null) - { - continue; - } + /** + * Refresh the players view, allows to change what the player sees, without opening and closing the GUI + * + * @param player The player whose view you wish to update + */ + public void update(Player player) + { + InventoryView view = player.getOpenInventory(); - ItemStack item = _buttons[i].getItemStack(); + if (view == null) + { + return; + } - inventory.setItem(i, item); - } - } + if (!view.getTitle().equalsIgnoreCase(getName())) + { + return; + } - public void setTitle(String title) - { - _name = title; - } + Inventory inventory = view.getTopInventory(); + for (int i = 0; i < _buttons.length; i++) + { + if (_buttons[i] == null) + { + continue; + } - public void onClose(Player player) - { - MENUS.remove(player.getUniqueId()); - } + ItemStack item = _buttons[i].getItemStack(); - public static Menu remove(UUID uniqueId) - { - return MENUS.remove(uniqueId); - } + inventory.setItem(i, item); + } + } + + public void setTitle(String title) + { + _name = title; + } + + public void onClose(Player player) + { + MENUS.remove(player.getUniqueId()); + } + + public static Menu remove(UUID uniqueId) + { + return MENUS.remove(uniqueId); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java index 2ab4197d2..fb28a5a7c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java @@ -1,5 +1,7 @@ package mineplex.core.party.ui; +import mineplex.core.party.ui.button.PartyMemberIcon; +import mineplex.core.party.ui.menus.PartyOwnerMenu; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; @@ -39,6 +41,16 @@ public class MenuListener implements Listener return; } + if(button instanceof PartyMemberIcon) + { + if(!(gui instanceof PartyOwnerMenu)) + { + return; + } + ((PartyMemberIcon) button).onClick(player, event.getCurrentItem()); + return; + } + button.onClick(player, event.getClick()); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java index 27dd7ac34..014e7d910 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java @@ -1,10 +1,15 @@ package mineplex.core.party.ui.button; import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.core.party.event.PartyMemberKickGUIEvent; import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.button.tools.PartyButton; +import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -14,21 +19,31 @@ import org.bukkit.inventory.ItemStack; /** * The button representing a Party member. */ -public class PartyMemberIcon extends IconButton +public class PartyMemberIcon extends PartyButton { - public PartyMemberIcon(String player, boolean owner) + public PartyMemberIcon(String player, Party party, boolean owner) { super(new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3) .setTitle(C.cYellow + player) .setGlow(owner) - .setPlayerHead(player).build(), null); + .setPlayerHead(player).build(), party, null); } - public PartyMemberIcon(String player) + public PartyMemberIcon(String player, Party party) { - this(player, false); + this(player, party, false); } + public void onClick(Player clicker, ItemStack clicked) + { + String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); + UtilServer.getPluginManager().callEvent(new PartyMemberKickGUIEvent(getParty(), name, clicker)); + } + @Override + public void onClick(Player player, ClickType clickType) + { + + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java index 44cf2f511..1de46988c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java @@ -27,7 +27,8 @@ public class LeavePartyButton extends Button @Override public void onClick(Player player, ClickType clickType) { - player.performCommand("party leave"); + player.chat("/party leave"); + player.closeInventory(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java index 48068ea98..bc4146f16 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java @@ -1,8 +1,34 @@ package mineplex.core.party.ui.button.tools.main; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.input.PartyInvitePlayerMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class InvitePlayerButton +public class InvitePlayerButton extends Button { + + private static final ItemStack ITEM = new ItemBuilder(Material.NAME_TAG) + .setTitle(C.cYellow + "Invite a Player") + .setLore(" ", C.cGray + "Invites a player to join", C.cGray + "you in a new party.") + .build(); + + public InvitePlayerButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PartyInvitePlayerMenu(getPlugin(), player).openInventory(); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java index b5dfbbd74..12d5e7aa8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java @@ -1,8 +1,35 @@ package mineplex.core.party.ui.button.tools.main; +import mineplex.core.common.util.C; +import mineplex.core.inventory.data.Item; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class ViewInvitesButton +public class ViewInvitesButton extends Button { + + private static final ItemStack ITEM = new ItemBuilder(Material.BOOK) + .setTitle(C.cYellow + "View Invites") + .setLore(" ", C.cGray + "Manage invites to parties.") + .build(); + + public ViewInvitesButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PartyInvitesMenu(getPlugin()).open(player); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java index 0a236ce9b..63534ed81 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java @@ -30,7 +30,7 @@ public class AddPlayerButton extends PartyButton @Override public void onClick(Player player, ClickType clickType) { - new PartyInvitePlayerMenu(getPlugin(), player, getParty()).openInventory(); + new PartyInvitePlayerMenu(getPlugin(), player).openInventory(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java index 53b893c7e..7cb400541 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java @@ -1,8 +1,38 @@ package mineplex.core.party.ui.button.tools.owner; +import mineplex.core.common.util.C; +import mineplex.core.inventory.data.Item; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class DisbandPartyButton +public class DisbandPartyButton extends Button { + + private static final ItemStack ITEM = new ItemBuilder(Material.BARRIER) + .setTitle(C.cRedB + "Disband your party") + .setLore(" ", C.cGray + "This will erase your party!", C.cRed + "Shift-Right-Click " + C.cGray + " to disband.") + .build(); + + public DisbandPartyButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if(clickType != ClickType.SHIFT_RIGHT) + { + return; + } + player.chat("/party disband"); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java index 0f15e00b5..a8c54a1f6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java @@ -1,8 +1,51 @@ package mineplex.core.party.ui.button.tools.owner; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.button.tools.PartyButton; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class KickPlayerButton +public class KickPlayerButton extends PartyButton { + + private static final ItemStack ITEM_OFF = new ItemBuilder(Material.IRON_AXE) + .setTitle(C.cYellow + "Kick Player's") + .setLore(" ", C.cRed + "Right Click to enter " + C.cGreen + "Kick Mode", + C.cGray + "While activated, click on a player's head", C.cGray + "to remove them fro the party") + .build(); + + private static final ItemStack ITEM_ON = new ItemBuilder(Material.IRON_AXE) + .setTitle(C.cYellow + "Kick Player's") + .setLore(" ", C.cGreen + "Right Click to leave " + C.cRed + "Kick Mode", + C.cGray + "While activated, click on a player's head", C.cGray + "to remove them fro the party") + .setGlow(true) + .build(); + + + public KickPlayerButton(Party party) + { + super(ITEM_OFF, party, null); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + getParty().setOwnerKickMode(!getParty().isOwnerKickMode()); + if (getParty().isOwnerKickMode()) + { + setItemStack(ITEM_ON); + } else + { + setItemStack(ITEM_OFF); + } + Menu.get(player.getUniqueId()).update(player); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java index 82d476ae6..cee97b248 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java @@ -1,8 +1,37 @@ package mineplex.core.party.ui.button.tools.owner; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.event.PartySelectServerEvent; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.button.tools.PartyButton; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class SelectServerButton +public class SelectServerButton extends PartyButton { + + private static final ItemStack ITEM = new ItemBuilder(Material.COMPASS) + .setTitle(C.cYellow + "Select Server") + .setLore(" ", C.cGray + "Brings up the Server Selection GUI") + .build(); + + public SelectServerButton(Party party) + { + super(ITEM, party, null); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + UtilServer.getPluginManager().callEvent(new PartySelectServerEvent(getParty())); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java index e9aacadc0..b936bd526 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java @@ -1,8 +1,36 @@ package mineplex.core.party.ui.button.tools.owner; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.button.tools.PartyButton; +import mineplex.core.party.ui.menus.input.PartyTransferOwnerMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class TransferOwnerButton +public class TransferOwnerButton extends PartyButton { + + private static final ItemStack ITEM = new ItemBuilder(Material.BOOK_AND_QUILL) + .setTitle(C.cYellow + "Transfer Ownership") + .setLore(" ", C.cGray + "Transfers ownership of the party", C.cGray + "to another player", + " ", C.cDRed + "This cannot be undone!") + .build(); + + public TransferOwnerButton(Party party, PartyManager plugin) + { + super(ITEM, party, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PartyTransferOwnerMenu(getPlugin(), player, getParty()); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java index 0e53b7f08..984291319 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java @@ -19,6 +19,7 @@ public class PartyInvitesMenu extends Menu @Override protected Button[] setUp(Player player) { - return new Button[0]; + Button[] buttons = new Button[54]; + return addPanes(buttons); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java index 62fdd7a15..225035cc7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java @@ -3,6 +3,8 @@ package mineplex.core.party.ui.menus; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.button.tools.main.InvitePlayerButton; +import mineplex.core.party.ui.button.tools.main.ViewInvitesButton; import org.bukkit.entity.Player; /** @@ -21,6 +23,9 @@ public class PartyMainMenu extends Menu { Button[] buttons = new Button[9]; + buttons[3] = new InvitePlayerButton(_plugin); + buttons[5] = new ViewInvitesButton(_plugin); + return buttons; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java index e9b9204e5..d1f7a29fa 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java @@ -5,7 +5,7 @@ import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Menu; import mineplex.core.party.ui.button.PartyMemberIcon; -import mineplex.core.party.ui.button.tools.owner.AddPlayerButton; +import mineplex.core.party.ui.button.tools.owner.*; import mineplex.core.party.ui.button.tools.LeavePartyButton; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -33,15 +33,15 @@ public class PartyOwnerMenu extends Menu //Tools buttons[1] = new AddPlayerButton(_plugin, _party); //Kick player - buttons[4] = create(new ItemStack(Material.IRON_AXE)); + buttons[4] = new KickPlayerButton(_party); //Transfer ownership - buttons[7] = create(new ItemStack(Material.BOOK_AND_QUILL)); + buttons[7] = new TransferOwnerButton(_party, _plugin); //Go to server - buttons[46] = create(new ItemStack(Material.COMPASS)); + buttons[46] = new SelectServerButton(_party); //Leave party buttons[49] = new LeavePartyButton(); //Disband - buttons[52] = create(new ItemStack(Material.BARRIER)); + buttons[52] = new DisbandPartyButton(_plugin); int slot = 20; //Players @@ -51,9 +51,9 @@ public class PartyOwnerMenu extends Menu { slot = 29; } - buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i)); + buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i), _party); } - return buttons; + return addPanes(buttons); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java index 4f7d36b00..b15e2b672 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java @@ -26,23 +26,23 @@ public class PartyViewMenu extends Menu @Override protected Button[] setUp(Player player) { - Button[] buttons = new Button[36]; + Button[] buttons = new Button[54]; //Tools - buttons[1] = new LeavePartyButton(); + buttons[3] = new LeavePartyButton(); //Suggest Player - buttons[4] = new SuggestPlayerButton(_party, _plugin); + buttons[5] = new SuggestPlayerButton(_party, _plugin); int slot = 20; //Players - for(int i = 0; i < _party.getMembers().size(); i++) + for (int i = 0; i < _party.getMembers().size(); i++) { - if(slot == 25) + if (slot == 25) { slot = 29; } - buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i)); + buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i), _party); } - return buttons; + return addPanes(buttons); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java index d4f00a3f6..3c031979e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java @@ -37,8 +37,7 @@ public abstract class PlayerNameActionMenu implements Listener _player = player; _partyManager = partyManager; _party = party; - - openInventory(); + player.closeInventory(); _partyManager.registerEvents(this); } @@ -81,6 +80,7 @@ public abstract class PlayerNameActionMenu implements Listener { if (_itemName.length() > 1 && !_searching) { + _searching = true; final String name = _itemName; _partyManager.getClientManager().checkPlayerName(_player, _itemName, result -> { @@ -88,8 +88,7 @@ public abstract class PlayerNameActionMenu implements Listener if (result != null) { - onSuccess(name); - unregisterListener(); + onSuccess(result); } else { onFail(name); @@ -112,7 +111,6 @@ public abstract class PlayerNameActionMenu implements Listener public void openInventory() { - _player.closeInventory(); EntityPlayer p = ((CraftPlayer) _player).getHandle(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java index b4d480e20..27cfa879d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java @@ -1,6 +1,5 @@ package mineplex.core.party.ui.menus.input; -import mineplex.core.party.Party; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.menus.PartyOwnerMenu; import mineplex.core.party.ui.menus.PlayerNameActionMenu; @@ -13,17 +12,21 @@ import org.bukkit.entity.Player; public class PartyInvitePlayerMenu extends PlayerNameActionMenu { - public PartyInvitePlayerMenu(PartyManager partyManager, Player player, Party party) + public PartyInvitePlayerMenu(PartyManager partyManager, Player player) { - super(partyManager, player, party); + super(partyManager, player, null); } @Override public void onSuccess(String name) { - _partyManager.getRedisManager().findAndInvite(name, _player.getName()); + _player.chat("/party invite " + name); _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); _player.closeInventory(); + if (_partyManager.getParty(_player) == null) + { + return; + } new PartyOwnerMenu(_party, _partyManager).open(_player); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyTransferOwnerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyTransferOwnerMenu.java new file mode 100644 index 000000000..ac073d94e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyTransferOwnerMenu.java @@ -0,0 +1,34 @@ +package mineplex.core.party.ui.menus.input; + +import mineplex.core.party.Lang; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.menus.PlayerNameActionMenu; +import org.bukkit.entity.Player; + +/** + * + */ +public class PartyTransferOwnerMenu extends PlayerNameActionMenu +{ + + public PartyTransferOwnerMenu(PartyManager partyManager, Player player, Party party) + { + super(partyManager, player, party); + } + + @Override + public void onSuccess(String name) + { + _partyManager.transferOwner(name, _player.getName()); + Lang.TRANSFER_OWNER.send(_party, _player.getName(), name); + _player.closeInventory(); + _player.chat("/party"); + } + + @Override + public void onFail(String name) + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java index 3dff2ecf2..6b4ddccb2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java @@ -26,13 +26,18 @@ public class PlayerSuggestPlayerMenu extends PlayerNameActionMenu public void onSuccess(String name) { Player player = Bukkit.getPlayerExact(_party.getOwner()); - _party.sendMessage(C.mHead + "Party> " + F.name(player.getName()) + " has suggested " + F.name(name) + " be invited."); + + _party.sendMessage(C.mHead + "Party> " + F.name(_player.getName()) + " has suggested " + F.name(name) + " be invited."); + ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Type or click ")); message.add(F.link("/party invite " + name)) .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); message.add(C.mBody + " to invite them"); message.sendToPlayer(player); + + _player.closeInventory(); + _player.chat("/party"); } @Override diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index dd4e3f4dd..18802fd55 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -54,7 +54,15 @@ import mineplex.core.blockrestore.BlockRestore; import mineplex.core.bonuses.BonusManager; import mineplex.core.botspam.BotSpamManager; import mineplex.core.common.Rank; -import mineplex.core.common.util.*; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextBottom; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilWorld; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; @@ -97,8 +105,21 @@ import mineplex.core.treasure.TreasureManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.valentines.ValentinesGiftManager; -import mineplex.hub.commands.*; -import mineplex.hub.modules.*; +import mineplex.hub.commands.DisguiseCommand; +import mineplex.hub.commands.ForcefieldRadius; +import mineplex.hub.commands.GadgetToggle; +import mineplex.hub.commands.GameModeCommand; +import mineplex.hub.commands.NewsCommand; +import mineplex.hub.modules.ForcefieldManager; +import mineplex.hub.modules.HubVisibilityManager; +import mineplex.hub.modules.JumpManager; +import mineplex.hub.modules.KothManager; +import mineplex.hub.modules.NewsManager; +import mineplex.hub.modules.ParkourManager; +import mineplex.hub.modules.SoccerManager; +import mineplex.hub.modules.TextManager; +import mineplex.hub.modules.ValentinesManager; +import mineplex.hub.modules.WorldManager; import mineplex.hub.profile.gui.GUIProfile; import mineplex.hub.tutorial.TutorialManager; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; @@ -112,36 +133,6 @@ import net.md_5.bungee.api.chat.HoverEvent.Action; import net.md_5.bungee.api.chat.TextComponent; import net.minecraft.server.v1_8_R3.EntityInsentient; import net.minecraft.server.v1_8_R3.EntityPlayer; -import org.bukkit.*; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.entity.Egg; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.*; -import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Scoreboard; - -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Random; public class HubManager extends MiniClientPlugin { @@ -197,15 +188,15 @@ public class HubManager extends MiniClientPlugin // Christmas Songs private Random _random = new Random(); private int _lastSong = 0; -// private final String[] _songNames = {"JingleBells.nbs", "TheFirstNoel.nbs", "Hark.nbs", "DeckTheHalls.nbs", "Joy.nbs", "MerryChristmas.nbs"}; + // private final String[] _songNames = {"JingleBells.nbs", "TheFirstNoel.nbs", "Hark.nbs", "DeckTheHalls.nbs", "Joy.nbs", "MerryChristmas.nbs"}; private final ArrayList _songs; - public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, IncognitoManager incognito, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, CustomDataManager customDataManager) + public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, IncognitoManager incognito, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, CustomDataManager customDataManager, BoosterManager boosterManager) { super("Hub Manager", plugin); _incognito = incognito; - + _blockRestore = blockRestore; _clientManager = clientManager; _conditionManager = conditionManager; @@ -237,7 +228,7 @@ public class HubManager extends MiniClientPlugin FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager); _bonusManager = new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, _gadgetManager); - + _treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager, statsManager, _bonusManager.getRewardManager()); new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, _treasureManager, boosterManager); @@ -276,11 +267,11 @@ public class HubManager extends MiniClientPlugin _playerCountManager = new PlayerCountManager(plugin); _customDataManager = new CustomDataManager(plugin, clientManager); - + _songs = new ArrayList(); - + _punishManager = punish; - + _valentinesManager = new ValentinesManager(plugin, clientManager, donationManager); try @@ -440,9 +431,9 @@ public class HubManager extends MiniClientPlugin @EventHandler(priority = EventPriority.LOW) public void login(final PlayerLoginEvent event) { - CoreClient client = _clientManager.Get(event.getPlayer().getName()); + CoreClient client = _clientManager.Get(event.getPlayer().getName()); - // Reserved Slot Check + // Reserved Slot Check if (Bukkit.getOnlinePlayers().size() - Bukkit.getServer().getMaxPlayers() >= 20) { if (!client.GetRank().has(Rank.ULTRA)) @@ -467,13 +458,13 @@ public class HubManager extends MiniClientPlugin { // Give developers operator on their servers boolean testServer = _plugin.getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing"); - + Rank minimum = Rank.OWNER; if (testServer) { minimum = Rank.JNR_DEV; } - + if (_clientManager.Get(event.getPlayer()).GetRank().has(minimum)) event.getPlayer().setOp(true); else @@ -580,7 +571,7 @@ public class HubManager extends MiniClientPlugin event.setCancelled(true); } } - + @EventHandler public void Incog(IncognitoHidePlayerEvent event) { @@ -613,7 +604,7 @@ public class HubManager extends MiniClientPlugin Rank rank = GetClients().Get(player).GetRank(); - if(GetClients().Get(player).isDisguised()) + if (GetClients().Get(player).isDisguised()) rank = GetClients().Get(player).getDisguisedRank(); //Level Prefix @@ -621,11 +612,36 @@ public class HubManager extends MiniClientPlugin //Rank Prefix String rankStr = ""; - if (rank != Rank.ALL) - { + if (rank != Rank.ALL) rankStr = rank.getTag(true, true) + " "; - } + //Party Chat + if (event.getMessage().charAt(0) == '#') + { + Party party = _partyManager.getParty(player); + if (party != null) + { + event.getRecipients().clear(); + event.setMessage(event.getMessage().substring(1, event.getMessage().length())); + event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s"); + + for (String name : party.getMembers()) + { + Player other = UtilPlayer.searchExact(name); + + if (other != null) + { + event.getRecipients().add(other); + } + } + } else + { + UtilPlayer.message(player, F.main("Party", "You are not in a Party.")); + event.setCancelled(true); + } + + } else + { TextComponent rankComponent = new TextComponent(rankStr); TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + playerName); TextComponent component = new TextComponent(); @@ -636,6 +652,7 @@ public class HubManager extends MiniClientPlugin component.addExtra(rankComponent); component.addExtra(playerNameText); component.addExtra(" " + ChatColor.WHITE + event.getMessage()); + for (Player other : UtilServer.getPlayers()) { if (_tutorialManager.InTutorial(other)) @@ -644,10 +661,12 @@ public class HubManager extends MiniClientPlugin continue; } - if(!event.isCancelled()) + if (!event.isCancelled()) other.spigot().sendMessage(component); } event.setCancelled(true); +// } + } } @EventHandler @@ -715,7 +734,7 @@ public class HubManager extends MiniClientPlugin return; int playerCount = _playerCountManager.getPlayerCount(); - + for (Player player : UtilServer.getPlayers()) { @@ -752,7 +771,7 @@ public class HubManager extends MiniClientPlugin obj.getScore(C.cYellow + C.Bold + "Players").setScore(line--); player.getScoreboard().resetScores(_lastPlayerCount + ""); obj.getScore(playerCount + "").setScore(line--); - + //Space obj.getScore(" ").setScore(line--); @@ -768,10 +787,10 @@ public class HubManager extends MiniClientPlugin if (GetClients().Get(player).GetRank().has(Rank.ULTRA)) obj.getScore(GetClients().Get(player).GetRank().Name).setScore(line--); else if (GetDonation().Get(player.getName()).OwnsUnknownPackage("SuperSmashMobs ULTRA") || - GetDonation().Get(player.getName()).OwnsUnknownPackage("Survival Games ULTRA") || - GetDonation().Get(player.getName()).OwnsUnknownPackage("Minigames ULTRA") || - GetDonation().Get(player.getName()).OwnsUnknownPackage("CastleSiege ULTRA") || - GetDonation().Get(player.getName()).OwnsUnknownPackage("Champions ULTRA")) + GetDonation().Get(player.getName()).OwnsUnknownPackage("Survival Games ULTRA") || + GetDonation().Get(player.getName()).OwnsUnknownPackage("Minigames ULTRA") || + GetDonation().Get(player.getName()).OwnsUnknownPackage("CastleSiege ULTRA") || + GetDonation().Get(player.getName()).OwnsUnknownPackage("Champions ULTRA")) obj.getScore("Single Ultra").setScore(line--); else obj.getScore("No Rank").setScore(line--); @@ -785,7 +804,7 @@ public class HubManager extends MiniClientPlugin obj.getScore("www.mineplex.com").setScore(line--); obj.getScore("----------------").setScore(line--); } - + _lastPlayerCount = playerCount; } @@ -852,9 +871,9 @@ public class HubManager extends MiniClientPlugin public PetManager getPetManager() { - return _petManager; + return _petManager; } - + public BonusManager getBonusManager() { return _bonusManager; @@ -879,7 +898,7 @@ public class HubManager extends MiniClientPlugin { return _customDataManager; } - + public Punish getPunishments() { return _punishManager; @@ -889,7 +908,7 @@ public class HubManager extends MiniClientPlugin // { // return _halloweenManager; // } - + @EventHandler(priority = EventPriority.MONITOR) public void gadgetCollide(GadgetCollideEntityEvent event) { @@ -995,7 +1014,7 @@ public class HubManager extends MiniClientPlugin if (entity instanceof EntityInsentient) { EntityInsentient entityMonster = (EntityInsentient)entity; - + if (entityMonster.getGoalTarget() != null && entityMonster.getGoalTarget() instanceof EntityPlayer) { if (((EntityPlayer)entityMonster.getGoalTarget()).playerConnection.isDisconnected()) @@ -1004,7 +1023,7 @@ public class HubManager extends MiniClientPlugin } } } - + @EventHandler public void clearGameMode(PlayerQuitEvent event) { @@ -1027,7 +1046,7 @@ public class HubManager extends MiniClientPlugin public PacketHandler getPacketHandler() { - return _packetHandler; + return _packetHandler; } @EventHandler @@ -1054,17 +1073,17 @@ public class HubManager extends MiniClientPlugin { playNextSong(); } - + @EventHandler public void trackPortalDelayPlayers(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; - + for (Iterator playerNameIterator = _portalTime.keySet().iterator(); playerNameIterator.hasNext();) { String playerName = playerNameIterator.next(); - + if (UtilTime.elapsed(_portalTime.get(playerName), 5000)) { playerNameIterator.remove(); @@ -1076,4 +1095,4 @@ public class HubManager extends MiniClientPlugin { return _incognito; } -} +} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java index 1172751de..5654f3b28 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java @@ -249,7 +249,7 @@ public class NewsManager extends MiniPlugin } } - @EventHandler +/* @EventHandler public void DragonBarUpdate(UpdateEvent event) { if (event.getType() != UpdateType.FASTEST) @@ -296,10 +296,10 @@ public class NewsManager extends MiniPlugin } else if (Manager.Type == HubType.Halloween) { - /** + *//** * @author Mysticate * Myst's sexy ass animation :> - */ + *//* _animationIndex = (_animationIndex + 1) % 147; @@ -457,5 +457,5 @@ public class NewsManager extends MiniPlugin ((MorphWither)gadget).setWitherData(text, healthPercent); } } - } + }*/ } \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java index 99b09283c..7a44aee11 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java @@ -2,16 +2,21 @@ package mineplex.hub.queue.ui; import mineplex.core.account.CoreClientManager; import mineplex.core.donation.DonationManager; +import mineplex.core.party.Party; import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.page.ShopPageBase; import mineplex.hub.queue.PlayerMatchStatus; import mineplex.hub.queue.QueueManager; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +import java.util.List; +import java.util.stream.Collectors; + public class QueuePage extends ShopPageBase { private boolean _closeOnNextUpdate; @@ -125,8 +130,17 @@ public class QueuePage extends ShopPageBase private void queuePlayer(int gameType, Player player) { - getPlugin().queuePlayer(gameType, player); - + Party party = getPlugin().getPartyManager().getParty(player); + if(party == null) + { + getPlugin().queuePlayer(gameType, player); + return; + } + if(party.getOwner().equalsIgnoreCase(player.getName())) + { + List players = party.getMembers().stream().map(Bukkit::getPlayerExact).collect(Collectors.toList()); + getPlugin().queuePlayer(gameType, players.toArray(new Player[players.size()])); + } buildPage(); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java index 30d5f7de2..7f1b163fc 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java @@ -1,12 +1,16 @@ package mineplex.hub.queue.ui; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.party.Party; import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.hub.queue.QueueManager; import org.bukkit.ChatColor; +import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -28,15 +32,15 @@ public class QueueShop extends ShopBase @Override protected boolean canOpenShop(Player player) { -/* Party party = getPlugin().getPartyManager().GetParty(player); + Party party = getPlugin().getPartyManager().getParty(player); - if (party != null && !player.getName().equalsIgnoreCase(party.GetLeader())) + if (party != null && !player.getName().equalsIgnoreCase(party.getOwner())) { player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.sendMessage(F.main("Party", "Only Party Leaders can join games.")); player.sendMessage(F.main("Party", "Type " + C.cGreen + "/party leave" + C.cGray + " if you wish to leave your party.")); return false; - }*/ + } return true; } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java index 2abc03971..491f3ff0e 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java @@ -1,11 +1,15 @@ package mineplex.hub.server.ui; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; +import mineplex.core.party.Party; import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; import mineplex.hub.server.ServerManager; import mineplex.serverdata.data.ServerGroup; +import org.bukkit.Sound; import org.bukkit.entity.Player; public class ServerNpcShop extends ShopBase @@ -36,15 +40,15 @@ public class ServerNpcShop extends ShopBase @Override protected boolean canOpenShop(Player player) { -/* Party party = getPlugin().getPartyManager().GetParty(player); + Party party = getPlugin().getPartyManager().getParty(player); - if (party != null && !player.getName().equalsIgnoreCase(party.GetLeader())) + if (party != null && !player.getName().equalsIgnoreCase(party.getOwner())) { player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.sendMessage(F.main("Party", "Only Party Leaders can join games.")); player.sendMessage(F.main("Party", "Type " + C.cGreen + "/party leave" + C.cGray + " if you wish to leave your party.")); return false; - }*/ + } return true; } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java index 5d139cf3c..84f99ce39 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java @@ -1,12 +1,15 @@ package mineplex.hub.server.ui.clans; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; +import mineplex.core.party.Party; import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; import mineplex.game.clans.core.repository.ClanRepository; import mineplex.game.clans.core.repository.tokens.SimpleClanToken; import mineplex.hub.server.ServerManager; +import org.bukkit.Sound; import org.bukkit.entity.Player; public class ClanMoveServerShop extends ShopBase @@ -33,14 +36,14 @@ public class ClanMoveServerShop extends ShopBase @Override protected boolean canOpenShop(Player player) { -/* Party party = getPlugin().getPartyManager().GetParty(player); + Party party = getPlugin().getPartyManager().getParty(player); if (party != null) { player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.sendMessage(F.main("Party", "You cannot join Clans while in a party.")); return false; - }*/ + } return true; } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java index 8b49a4bd6..6d6926a16 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java @@ -1,11 +1,14 @@ package mineplex.hub.server.ui.clans; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; +import mineplex.core.party.Party; import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; import mineplex.game.clans.core.repository.ClanRepository; import mineplex.hub.server.ServerManager; +import org.bukkit.Sound; import org.bukkit.entity.Player; public class ClansServerShop extends ShopBase @@ -28,14 +31,14 @@ public class ClansServerShop extends ShopBase @Override protected boolean canOpenShop(Player player) { -/* Party party = getPlugin().getPartyManager().GetParty(player); + Party party = getPlugin().getPartyManager().getParty(player); if (party != null) { player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.sendMessage(F.main("Party", "You cannot join Clans while in a party.")); return false; - }*/ + } return true; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/data/DemolitionData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/data/DemolitionData.java index 0f8804aac..f474ce459 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/data/DemolitionData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/data/DemolitionData.java @@ -1,7 +1,7 @@ package nautilus.game.arcade.game.games.speedbuilders.data; -import java.util.ArrayList; - +import mineplex.core.common.util.*; +import mineplex.core.hologram.Hologram; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -13,14 +13,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.material.Bed; import org.bukkit.material.Door; -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilInv; -import mineplex.core.common.util.UtilTime; -import mineplex.core.hologram.Hologram; +import java.util.ArrayList; public class DemolitionData { @@ -65,9 +58,9 @@ public class DemolitionData loc = Blocks.keySet().iterator().next().getLocation().add(0.5, 0.5, 0.5); else if (!Mobs.isEmpty()) loc = UtilAlg.Random(Mobs).getLocation().add(0, 1, 0); - + _hologram = new Hologram(Parent.Game.Manager.getHologramManager(), loc, "3"); - + _hologram.start(); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java index ee878cbb1..f182d6ecd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java @@ -6,10 +6,12 @@ import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.party.Party; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameTeam; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -20,6 +22,7 @@ import org.jooq.tools.json.JSONObject; import java.text.DecimalFormat; import java.util.*; +import java.util.stream.Collectors; public class GameChatManager implements Listener { @@ -116,10 +119,10 @@ public class GameChatManager implements Listener rankStr = rank.getTag(true, true) + " " + C.Reset; } -/* if (event.getMessage().charAt(0) == '@') + if (event.getMessage().charAt(0) == '#') { //Party Chat - Party party = _manager.getPartyManager().GetParty(sender); + Party party = _manager.getPartyManager().getParty(sender); if (party != null) { @@ -134,14 +137,14 @@ public class GameChatManager implements Listener name = C.cWhiteB + sender.getName() + C.Reset; message = event.getFormat().split(sender.getName())[1].replace("%2$s", "") + _manager.GetChat().getFilteredMessage(sender, event.getMessage()); - if(safeSend(sender, format, rankStr, rank, name, message, party.GetPlayersOnline())) + if(safeSend(sender, format, rankStr, rank, name, message, party.getMembers().stream().map(Bukkit::getPlayerExact).collect(Collectors.toList()))) { event.setCancelled(true); } return; } - }*/ + } event.setFormat(levelStr + rankStr + senderName + " " + C.cWhite + "%2$s");