From 22a438d5c152ca4053dfd5d3313a1d90f3b1db04 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sat, 4 Jun 2016 01:54:17 -0500 Subject: [PATCH 01/53] Party system rewrite init. Barebones frame work: Total time - 2hrs. --- .../src/mineplex/core/party/Party.java | 437 +----------------- .../src/mineplex/core/party/PartyManager.java | 167 +------ .../core/party/command/PartyCommand.java | 83 ++++ .../core/party/commands/PartyCommand.java | 177 ------- .../mineplex/core/party/redis/PartyData.java | 35 ++ .../core/party/redis/PartyDataHandler.java | 27 ++ .../core/party/redis/RedisPartyData.java | 33 -- .../core/party/redis/RedisPartyHandler.java | 30 -- .../src/mineplex/core/party/ui/PartyMenu.java | 8 + .../Mineplex.Hub/src/mineplex/hub/Hub.java | 5 - .../nautilus/game/arcade/ArcadeManager.java | 96 ++-- 11 files changed, 200 insertions(+), 898 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/commands/PartyCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyData.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyData.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyHandler.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/PartyMenu.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 2aa3b2496..4865bb123 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -1,439 +1,30 @@ package mineplex.core.party; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; - -import mineplex.core.common.Rank; -import mineplex.core.common.jsonchat.ChildJsonMessage; -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.common.util.NautHashMap; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilTime; -import mineplex.core.party.redis.RedisPartyData; -import mineplex.serverdata.Region; -import mineplex.serverdata.commands.ServerTransfer; -import mineplex.serverdata.commands.TransferCommand; -import mineplex.serverdata.data.ServerGroup; -import mineplex.serverdata.servers.ServerManager; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Scoreboard; +import java.util.List; +import java.util.Map; +/** + * Uh, yeah, I'll get back to this when it isn't 2 AM + */ public class Party { - private PartyManager _manager; - private boolean _isHub; - private String _creator; - private String _previousServer; + private String _owner; + private List _members; + private Map _invites; - private ArrayList _players = new ArrayList(); - private NautHashMap _invitee = new NautHashMap(); - - private Scoreboard _scoreboard; - private Objective _scoreboardObj; - private ArrayList _scoreboardLast = new ArrayList(); - - private long _partyOfflineTimer = -1; - private long _informNewLeaderTimer = -1; - - public Party(PartyManager manager, RedisPartyData partyData) + public String getOwner() { - this(manager); - - _players = new ArrayList(Arrays.asList(partyData.getPlayers())); - _creator = partyData.getLeader(); - _previousServer = partyData.getPreviousServer(); + return _owner; } - public Party(PartyManager manager) + public List getMembers() { - _manager = manager; - Region region = manager.getPlugin().getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; - String groupName = manager.getPlugin().getConfig().getString("serverstatus.group"); - - ServerGroup serverGroup = ServerManager.getServerRepository(region).getServerGroup(groupName); - - if (serverGroup == null) - return; - - _isHub = !serverGroup.getArcadeGroup(); - - if (_isHub) - { - // Scoreboard - _scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); - _scoreboardObj = _scoreboard.registerNewObjective("Party", "dummy"); - _scoreboardObj.setDisplaySlot(DisplaySlot.SIDEBAR); - - _scoreboard.registerNewTeam(ChatColor.GREEN + "Members"); - - // Scoreboard Ranks - for (Rank rank : Rank.values()) - { - if (rank != Rank.ALL) - _scoreboard.registerNewTeam(rank.Name).setPrefix(rank.getTag(true, false) + ChatColor.RESET + " "); - else - _scoreboard.registerNewTeam(rank.Name).setPrefix(""); - } - - _scoreboard.registerNewTeam("Party").setPrefix(ChatColor.LIGHT_PURPLE + C.Bold + "Party" + ChatColor.RESET + " "); - - // Add Players - for (Player player : Bukkit.getOnlinePlayers()) - { - _scoreboard.getTeam(_manager.GetClients().Get(player).GetRank().Name).addPlayer(player); - } - } + return _members; } - public void JoinParty(Player player) + public Map getInvites() { - // Add Leader - if (_players.isEmpty()) - { - _players.add(player.getName()); - - UtilPlayer.message(player, F.main("Party", "You created a new Party.")); - - _creator = player.getName(); - } - else - { - _players.add(player.getName()); - _invitee.remove(player.getName()); - - Announce(F.elem(player.getName()) + " has joined the party!"); - } - - if (_isHub) - { - _scoreboard.getTeam("Party").addPlayer(player); - } - } - - public void InviteParty(Player player, boolean inviteeInParty) - { - _invitee.put(player.getName(), System.currentTimeMillis()); - - // Decline - if (_players.contains(player.getName())) - { - UtilPlayer.message(player, F.main("Party", F.name(player.getName()) + " is already in the Party.")); - player.playSound(player.getLocation(), Sound.NOTE_BASS, 1f, 1.5f); - } - - // Announce - Announce(F.name(player.getName()) + " has been invited to your Party."); - - // Inform - UtilPlayer.message(player, F.main("Party", F.name(GetLeader()) + " invited you to their Party.")); - - // Instruct - if (inviteeInParty) - { - ChildJsonMessage message = new JsonMessage("").extra(C.mHead + "Party> " + C.mBody + "Type "); - - message.add(F.link("/party leave")).click(ClickEvent.RUN_COMMAND, "/party leave"); - - message.add(C.mBody + " then "); - - message.add(F.link("/party " + GetLeader())).click(ClickEvent.RUN_COMMAND, "/party " + GetLeader()); - - message.add(C.mBody + " to join."); - - message.sendToPlayer(player); - } - else - { - ChildJsonMessage message = new JsonMessage("").extra(C.mHead + "Party> " + C.mBody + "Type "); - - message.add(F.link("/party " + GetLeader())).click(ClickEvent.RUN_COMMAND, "/party " + GetLeader()); - - message.add(C.mBody + " to join."); - - message.sendToPlayer(player); - } - - player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1.5f); - } - - public void LeaveParty(Player player) - { - // Announce - Announce(F.name(player.getName()) + " has left the Party."); - - boolean leader = player.equals(GetLeader()); - - _players.remove(player.getName()); - - if (_isHub) - { - // Set Scoreboard - _scoreboard.getTeam(_manager.GetClients().Get(player).GetRank().Name).addPlayer(player); - } - - if (leader && _players.size() > 0) - { - Announce("Party Leadership passed on to " + F.name(GetLeader()) + "."); - } - } - - public void KickParty(String player) - { - // Announce - Announce(F.name(player) + " was kicked from the Party."); - - _players.remove(player); - } - - public void PlayerJoin(Player player) - { - if (_isHub) - { - // Scoreboard - if (_players.contains(player.getName())) - _scoreboard.getTeam("Party").addPlayer(player); - else if (_manager.GetClients().Get(player) != null) - _scoreboard.getTeam(_manager.GetClients().Get(player).GetRank().Name).addPlayer(player); - } - - if (_creator.equals(player.getName())) - { - _players.remove(player.getName()); - _players.add(0, player.getName()); - - if (_informNewLeaderTimer < System.currentTimeMillis()) - { - Announce("Party Leadership returned to " + F.name(GetLeader()) + "."); - } - - if (_previousServer != null) - { - for (String playerName : _players) - { - Player p = Bukkit.getPlayerExact(playerName); - - if (p != null) - { - continue; - } - - TransferCommand transferCommand = new TransferCommand( - new ServerTransfer(playerName, _manager.getServerName())); - - transferCommand.setTargetServers(_previousServer); - - transferCommand.publish(); - } - - _previousServer = null; - } - } - } - - // Shuffle Leader - public void PlayerQuit(Player player) - { - if (player.getName().equals(GetLeader())) - { - _players.remove(player.getName()); - _players.add(player.getName()); - - if (_informNewLeaderTimer < System.currentTimeMillis()) - { - Announce("Party Leadership passed on to " + F.name(GetLeader()) + "."); - } - } - } - - public void Announce(String message) - { - for (String name : _players) - { - Player player = UtilPlayer.searchExact(name); - - if (player != null && player.isOnline()) - { - UtilPlayer.message(player, F.main("Party", message)); - player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1.5f); - } - } - } - - public void ExpireInvitees() - { - Iterator inviteeIterator = _invitee.keySet().iterator(); - - while (inviteeIterator.hasNext()) - { - String name = inviteeIterator.next(); - - if (UtilTime.elapsed(_invitee.get(name), 60000)) - { - Announce(F.name(name) + " did not respond to the Party invite."); - inviteeIterator.remove(); - } - } - } - - public String GetLeader() - { - if (_players.isEmpty()) - return _creator; - - return _players.get(0); - } - - public Collection GetPlayers() - { - return _players; - } - - public Collection GetPlayersOnline() - { - ArrayList players = new ArrayList(); - - for (String name : _players) - { - Player player = UtilPlayer.searchExact(name); - if (player != null) - players.add(player); - } - - return players; - } - - public Collection GetInvitees() - { - return _invitee.keySet(); - } - - public void UpdateScoreboard() - { - if (_isHub) - { - _scoreboardObj.setDisplayName(GetLeader() + "'s Party"); - - // Clear Past - for (String pastLine : _scoreboardLast) - _scoreboard.resetScores(pastLine); - _scoreboardLast.clear(); - - int i = 16; - - // Add New - for (int j = 0; j < _players.size(); j++) - { - String name = _players.get(j); - Player player = UtilPlayer.searchExact(name); - - ChatColor col = ChatColor.GREEN; - if (player == null) - col = ChatColor.RED; - - String line = col + name; - - if (line.length() > 16) - line = line.substring(0, 16); - - _scoreboardObj.getScore(line).setScore(i); - - _scoreboardLast.add(line); - - i--; - } - - // Add New - for (String name : _invitee.keySet()) - { - int time = 1 + (int) ((60000 - (System.currentTimeMillis() - _invitee.get(name))) / 1000); - - String line = time + " " + ChatColor.GRAY + name; - - if (line.length() > 16) - line = line.substring(0, 16); - - _scoreboardObj.getScore(line).setScore(i); - - _scoreboardLast.add(line); - - i--; - } - - // Set Scoreboard - for (String name : _players) - { - Player player = UtilPlayer.searchExact(name); - - if (player != null) - { - if (!player.getScoreboard().equals(_scoreboard)) - { - player.setScoreboard(_scoreboard); - } - } - } - } - } - - public boolean IsDead() - { - if (_players.size() == 0) - return true; - - if (_players.size() == 1 && _invitee.size() == 0) - return true; - - int online = 0; - for (String name : _players) - { - Player player = UtilPlayer.searchExact(name); - if (player != null) - online++; - } - - // One or Less Members Online - Expirey Countdown - if (online <= 1) - { - if (_partyOfflineTimer == -1) - { - _partyOfflineTimer = System.currentTimeMillis(); - } - else - { - if (UtilTime.elapsed(_partyOfflineTimer, online == 0 ? 5000 : 120000)) // 5 seconds for no players, 2 minutes if - // one player. - { - return true; - } - } - } - else if (_partyOfflineTimer > 0) - { - _partyOfflineTimer = -1; - } - - return false; - } - - public void resetWaitingTime() - { - _partyOfflineTimer = -1; - } - - public void switchedServer() - { - _informNewLeaderTimer = System.currentTimeMillis() + 5000; + return _invites; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index b79283d76..e4d4104c0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -1,181 +1,16 @@ package mineplex.core.party; -import java.util.HashSet; -import java.util.Iterator; - import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.party.commands.PartyCommand; -import mineplex.core.party.redis.RedisPartyData; -import mineplex.core.party.redis.RedisPartyHandler; import mineplex.core.portal.Portal; -import mineplex.core.portal.ServerTransferEvent; import mineplex.core.preferences.PreferencesManager; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.serverdata.commands.ServerCommandManager; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; public class PartyManager extends MiniPlugin { - private CoreClientManager _clientManager; - private PreferencesManager _preferenceManager; - private Portal _portal; - private String _serverName; - - public NautHashMap _partyLeaderMap = new NautHashMap(); public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager) { - super("Party Manager", plugin); - - _portal = portal; - _clientManager = clientManager; - _preferenceManager = preferenceManager; - _serverName = getPlugin().getConfig().getString("serverstatus.name"); - - ServerCommandManager.getInstance().registerCommandType("RedisPartyData", RedisPartyData.class, - new RedisPartyHandler(this)); - } - - @Override - public void addCommands() - { - addCommand(new PartyCommand(this)); - } - - public CoreClientManager GetClients() - { - return _clientManager; - } - - public PreferencesManager getPreferenceManager() - { - return _preferenceManager; - } - - public Party CreateParty(Player player) - { - Party party = new Party(this); - party.JoinParty(player); - _partyLeaderMap.put(player.getName(), party); - - return party; - } - - public String getServerName() - { - return _serverName; - } - - public void addParty(Party party) - { - if (_partyLeaderMap.containsKey(party.GetLeader())) - _partyLeaderMap.get(party.GetLeader()).resetWaitingTime(); - else - _partyLeaderMap.put(party.GetLeader(), party); - } - - @EventHandler - public void serverTransfer(ServerTransferEvent event) - { - if (event.isDraggedByParty()) - return; - - Party party = _partyLeaderMap.get(event.getPlayer().getName()); - - if (party != null) - { - party.switchedServer(); - - RedisPartyData data = new RedisPartyData(party, _serverName); - data.setTargetServers(event.getServer()); - data.publish(); - - for (Player player : party.GetPlayersOnline()) - { - if (player != event.getPlayer()) - { - _portal.sendPlayerToServer(player, event.getServer(), true); - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void PlayerJoin(PlayerJoinEvent event) - { - try - { - for (Party party : _partyLeaderMap.values()) - { - party.PlayerJoin(event.getPlayer()); - } - } - catch (Exception ex) - { - throw ex; - } - } - - @EventHandler - public void PlayerQuit(PlayerQuitEvent event) - { - for (Party party : _partyLeaderMap.values()) - { - party.PlayerQuit(event.getPlayer()); - } - } - - @EventHandler - public void Update(UpdateEvent event) - { - if (event.getType() != UpdateType.FAST) - return; - - ExpireParties(); - - for (Party party : _partyLeaderMap.values()) - { - party.ExpireInvitees(); - party.UpdateScoreboard(); - } - } - - public void ExpireParties() - { - Iterator partyIterator = _partyLeaderMap.values().iterator(); - - while (partyIterator.hasNext()) - { - Party party = partyIterator.next(); - - // Empty Party - if (party.IsDead()) - { - party.Announce("Your Party has been closed."); - partyIterator.remove(); - } - } - } - - public Party GetParty(Player player) - { - for (Party party : _partyLeaderMap.values()) - { - if (party.GetPlayers().contains(player.getName())) - { - return party; - } - } - - return null; + super("Parties", plugin); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java new file mode 100644 index 000000000..d487a2bf2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -0,0 +1,83 @@ +package mineplex.core.party.command; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.party.PartyManager; +import org.bukkit.entity.Player; + +/** + * Command handler for party commands + */ +public class PartyCommand extends CommandBase +{ + + private final String[] HELP = { + C.cDGreenB + C.Strike + "================================", + F.main("Party", "/party help - Shows this help screen."), + F.main("Party", "/party - Brings up the Party UI."), + F.main("Party", "/party invite - Invite a player to your party." + C.cRed + " Must be the owner."), + F.main("Party", "/party accept - Accept an invite to a player's party."), + F.main("Party", "/party deny - Deny an invite to a player's party."), + F.main("Party", "/party leave - Leave your current party."), + F.main("Party", "/party kick/remove - Remove a player from your party." + C.cRed + " Must be the owner."), + F.main("Party", "/party disband - Disband your party." + C.cRed + " Must be the owner."), + C.cDGreenB + C.Strike + "================================", + }; + + public PartyCommand(PartyManager plugin) + { + super(plugin, Rank.ALL, "party"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if(args.length == 0) + { + //Show UI + return; + } + String argument = args[0]; + if(argument.equalsIgnoreCase("help")) + { + //Show this menu + caller.sendMessage(HELP); + return; + } + if(args.length == 1) + { + if(argument.equalsIgnoreCase("leave")) + { + return; + } + if(argument.equalsIgnoreCase("disband")) + { + return; + } + return; + } + if(args.length == 2) + { + String target = args[1]; + if(argument.equalsIgnoreCase("invite")) + { + return; + } + if(argument.equalsIgnoreCase("accept")) + { + return; + } + if(argument.equalsIgnoreCase("deny")) + { + return; + } + if(argument.equalsIgnoreCase("remove") || argument.equalsIgnoreCase("kick")) + { + return; + } + } + } +} + diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/commands/PartyCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/commands/PartyCommand.java deleted file mode 100644 index 1c8fcbfbb..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/commands/PartyCommand.java +++ /dev/null @@ -1,177 +0,0 @@ -package mineplex.core.party.commands; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; -import mineplex.core.common.jsonchat.ChildJsonMessage; -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.common.util.UtilEnt; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.party.Party; -import mineplex.core.party.PartyManager; - -import org.bukkit.Bukkit; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -public class PartyCommand extends CommandBase -{ - public PartyCommand(PartyManager plugin) - { - super(plugin, Rank.ALL, new String[] - { - "party", "z" - }); - } - - @Override - public void Execute(Player caller, String[] args) - { - if (args == null || args.length == 0 || (args[0].equalsIgnoreCase("kick") && args.length < 2)) - { - UtilPlayer.message(caller, F.main("Party", "Listing Party Commands;")); - UtilPlayer.message(caller, F.value(0, "/party ", "Join/Create/Invite Player")); - UtilPlayer.message(caller, F.value(0, "/party leave", "Leave your current Party")); - UtilPlayer.message(caller, F.value(0, "/party kick ", "Kick player from your Party")); - - return; - } - - // Callers Party - Party party = Plugin.GetParty(caller); - - // Leave - if (args[0].equalsIgnoreCase("leave")) - { - if (party == null) - { - UtilPlayer.message(caller, F.main("Party", "You are not in a Party.")); - } - else - { - party.LeaveParty(caller); - } - - return; - } - - // Leave - if (args[0].equalsIgnoreCase("kick")) - { - if (party == null) - { - UtilPlayer.message(caller, F.main("Party", "You are not in a Party.")); - } - else - { - if (party.GetLeader().equals(caller.getName())) - { - String target = UtilPlayer.searchCollection(caller, args[1], party.GetPlayers(), "Party ", true); - if (target == null) - return; - - if (target.equals(caller.getName())) - { - UtilPlayer.message(caller, F.main("Party", "You cannot kick yourself from the Party.")); - return; - } - - party.KickParty(target); - } - else - { - UtilPlayer.message(caller, F.main("Party", "You are not the Party Leader.")); - } - } - - return; - } - - // Main - Player target = UtilPlayer.searchOnline(caller, args[0], true); - if (target == null) - return; - - if (target.equals(caller)) - { - UtilPlayer.message(caller, F.main("Party", "You cannot Party with yourself.")); - return; - } - - // Preference check - if (!Plugin.getPreferenceManager().Get(target).PartyRequests) - { - UtilPlayer.message( - caller, - F.main("Party", "You may not party with " + F.name(UtilEnt.getName(target)) - + "! They are not accepting party requests!")); - return; - } - - // Invite or Suggest - if (party != null) - { - if (party.GetPlayers().size() + party.GetInvitees().size() >= 16) - { - UtilPlayer.message(caller, "Your party cannot be larger than 16 players."); - caller.playSound(caller.getLocation(), Sound.NOTE_BASS, 1f, 1.5f); - } - // Decline - else if (party.GetPlayers().contains(target.getName())) - { - UtilPlayer.message(caller, F.main("Party", F.name(target.getName()) + " is already in the Party.")); - caller.playSound(caller.getLocation(), Sound.NOTE_BASS, 1f, 1.5f); - } - // Decline - else if (party.GetInvitees().contains(target.getName())) - { - UtilPlayer.message(caller, F.main("Party", F.name(target.getName()) + " is already invited to the Party.")); - caller.playSound(caller.getLocation(), Sound.NOTE_BASS, 1f, 1.5f); - } - // Invite - else if (party.GetLeader().equals(caller.getName())) - { - party.InviteParty(target, Plugin.GetParty(target) != null); - } - // Suggest - else - { - party.Announce(F.name(caller.getName()) + " suggested " + F.name(target.getName()) + " be invited to the Party."); - - Player leader = Bukkit.getPlayerExact(party.GetLeader()); - - if (leader != null) - { - ChildJsonMessage message = new JsonMessage("").extra(C.mHead + "Party> " + C.mBody + "Type "); - - message.add(F.link("/party " + target.getName())).click(ClickEvent.RUN_COMMAND, "/party " + target.getName()); - - message.add(C.mBody + " to invite them."); - - message.sendToPlayer(leader); - } - } - } - // Create or Join - else - { - Party targetParty = Plugin.GetParty(target); - - // Try to Join - if (targetParty != null) - { - if (targetParty.GetInvitees().contains(caller.getName())) - { - targetParty.JoinParty(caller); - return; - } - } - - // Create - party = Plugin.CreateParty(caller); - party.InviteParty(target, Plugin.GetParty(target) != null); - } - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyData.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyData.java new file mode 100644 index 000000000..c4b9e9258 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyData.java @@ -0,0 +1,35 @@ +package mineplex.core.party.redis; + +import mineplex.core.party.Party; +import mineplex.serverdata.commands.ServerCommand; + +import java.util.List; + +/** + * Redis party data + */ +public class PartyData extends ServerCommand +{ + + private String _owner; + private List _members; + + public PartyData(Party party) + { + _owner = party.getOwner(); + _members = party.getMembers(); + } + + public String getOwner() + { + return _owner; + } + + public List getMembers() + { + return _members; + } + + + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java new file mode 100644 index 000000000..a0d4804a4 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java @@ -0,0 +1,27 @@ +package mineplex.core.party.redis; + +import mineplex.core.party.PartyManager; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +/** + * Handler for party redis data + */ +public class PartyDataHandler implements CommandCallback +{ + + private final String _currentServer; + private final PartyManager _plugin; + + public PartyDataHandler(String thisServer, PartyManager partyManager) + { + _currentServer = thisServer; + _plugin = partyManager; + } + + @Override + public void run(ServerCommand command) + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyData.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyData.java deleted file mode 100644 index cec09d728..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyData.java +++ /dev/null @@ -1,33 +0,0 @@ -package mineplex.core.party.redis; - -import mineplex.core.party.Party; -import mineplex.serverdata.commands.ServerCommand; - -public class RedisPartyData extends ServerCommand -{ - private String[] _players; - private String _leader; - private String _previousServer; - - public RedisPartyData(Party party, String previousServer) - { - _players = party.GetPlayers().toArray(new String[0]); - _leader = party.GetLeader(); - _previousServer = previousServer; - } - - public String getPreviousServer() - { - return _previousServer; - } - - public String[] getPlayers() - { - return _players; - } - - public String getLeader() - { - return _leader; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyHandler.java deleted file mode 100644 index e88aeb675..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -package mineplex.core.party.redis; - -import mineplex.core.party.Party; -import mineplex.core.party.PartyManager; -import mineplex.serverdata.commands.CommandCallback; -import mineplex.serverdata.commands.ServerCommand; - -public class RedisPartyHandler implements CommandCallback -{ - private PartyManager _partyManager; - - public RedisPartyHandler(PartyManager partyManager) - { - _partyManager = partyManager; - } - - @Override - public void run(ServerCommand command) - { - final RedisPartyData data = (RedisPartyData) command; - - _partyManager.getPlugin().getServer().getScheduler().runTask(_partyManager.getPlugin(), new Runnable() - { - public void run() - { - _partyManager.addParty(new Party(_partyManager, data)); - } - }); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/PartyMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/PartyMenu.java new file mode 100644 index 000000000..a9b09004c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/PartyMenu.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui; + +/** + * The display menu for managing parties + */ +public class PartyMenu +{ +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index ba542f68a..a6e8a0165 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -8,9 +8,6 @@ import mineplex.core.antihack.AntiHack; import mineplex.core.aprilfools.AprilFoolsManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; -import mineplex.core.chatsnap.SnapshotManager; -import mineplex.core.chatsnap.SnapshotPlugin; -import mineplex.core.chatsnap.publishing.SnapshotPublisher; import mineplex.core.command.CommandCenter; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.creature.Creature; @@ -43,8 +40,6 @@ import mineplex.core.profileCache.ProfileCacheManager; import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; import mineplex.core.recharge.Recharge; -import mineplex.core.report.ReportManager; -import mineplex.core.report.ReportPlugin; import mineplex.core.resourcepack.ResourcePackManager; import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.sponsorbranding.BrandingManager; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index f3bd4a08d..42142d492 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -1,37 +1,5 @@ package nautilus.game.arcade; -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockFadeEvent; -import org.bukkit.event.block.BlockSpreadEvent; -import org.bukkit.event.block.LeavesDecayEvent; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; @@ -40,14 +8,7 @@ import mineplex.core.blood.Blood; import mineplex.core.bonuses.BonusManager; import mineplex.core.chat.Chat; import mineplex.core.common.Rank; -import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilGear; -import mineplex.core.common.util.UtilInv; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.*; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.creature.Creature; import mineplex.core.customdata.CustomDataManager; @@ -103,12 +64,7 @@ import mineplex.minecraft.game.core.fire.Fire; import nautilus.game.arcade.addons.SoupAddon; import nautilus.game.arcade.addons.TeamArmorAddon; import nautilus.game.arcade.addons.compass.CompassAddon; -import nautilus.game.arcade.command.DisguiseCommand; -import nautilus.game.arcade.command.GameCmdModeCommand; -import nautilus.game.arcade.command.GameCommand; -import nautilus.game.arcade.command.KitUnlockCommand; -import nautilus.game.arcade.command.RequiredRankCommand; -import nautilus.game.arcade.command.WriteCommand; +import nautilus.game.arcade.command.*; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game.GameState; @@ -116,26 +72,38 @@ import nautilus.game.arcade.game.GameServerConfig; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.event.EventModule; import nautilus.game.arcade.game.games.uhc.UHC; -import nautilus.game.arcade.managers.GameAchievementManager; -import nautilus.game.arcade.managers.GameCreationManager; -import nautilus.game.arcade.managers.GameFlagManager; -import nautilus.game.arcade.managers.GameGemManager; -import nautilus.game.arcade.managers.GameHostManager; -import nautilus.game.arcade.managers.GameLobbyManager; -import nautilus.game.arcade.managers.GameLootManager; -import nautilus.game.arcade.managers.GameManager; -import nautilus.game.arcade.managers.GamePlayerManager; -import nautilus.game.arcade.managers.GameSpectatorManager; -import nautilus.game.arcade.managers.GameStatManager; -import nautilus.game.arcade.managers.GameTestingManager; -import nautilus.game.arcade.managers.GameTournamentManager; -import nautilus.game.arcade.managers.GameWorldManager; -import nautilus.game.arcade.managers.IdleManager; -import nautilus.game.arcade.managers.MiscManager; +import nautilus.game.arcade.managers.*; import nautilus.game.arcade.managers.chat.GameChatManager; import nautilus.game.arcade.player.ArcadePlayer; import nautilus.game.arcade.shop.ArcadeShop; import net.minecraft.server.v1_8_R3.EntityLiving; +import org.bukkit.*; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.server.ServerListPingEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.util.Vector; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashSet; public class ArcadeManager extends MiniPlugin implements IRelation { @@ -276,8 +244,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation _projectileManager = projectileManager; _packetHandler = packetHandler; - - _partyManager = new PartyManager(plugin, portal, _clientManager, preferences); + + _partyManager = new PartyManager(plugin, portal, clientManager, preferences); _statsManager = statsManager; _taskManager = new TaskManager(plugin, clientManager, webAddress); _achievementManager = achievementManager; From 84f428fa99c254a2f83bd8e43ced72cf3d090c55 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sat, 4 Jun 2016 21:13:19 -0500 Subject: [PATCH 02/53] Redis work: Command work: UI work: Total Time: 2.5hrs --- .../src/mineplex/core/party/InviteData.java | 51 +++++ .../src/mineplex/core/party/PartyManager.java | 53 +++++ .../core/party/command/PartyCommand.java | 58 ++++-- .../core/party/redis/PartyDataHandler.java | 10 + .../core/party/redis/locate/LocateType.java | 15 ++ .../party/redis/locate/PartyRedisLocate.java | 47 +++++ .../locate/PartyRedisLocateCallback.java | 56 +++++ .../redis/locate/PartyRedisLocateHandler.java | 116 +++++++++++ .../src/mineplex/core/party/ui/Button.java | 44 ++++ .../src/mineplex/core/party/ui/Menu.java | 191 ++++++++++++++++++ .../mineplex/core/party/ui/MenuListener.java | 45 +++++ .../src/mineplex/core/party/ui/PartyMenu.java | 8 - .../core/party/ui/button/IconButton.java | 25 +++ .../core/party/ui/button/PartyMemberIcon.java | 62 ++++++ .../core/party/ui/menus/PartyMenu.java | 26 +++ 15 files changed, 787 insertions(+), 20 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/LocateType.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocate.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateCallback.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateHandler.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/PartyMenu.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMenu.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java b/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java new file mode 100644 index 000000000..860ad7504 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java @@ -0,0 +1,51 @@ +package mineplex.core.party; + +/** + * Serializable invite data + */ +public class InviteData +{ + + private String _invitedTo; + private String _invitedBy; + private long _timeStamp; + private long _expires; + + public InviteData(String invitedBy, String invitedTo, long timeStamp) + { + _invitedBy = invitedBy; + _invitedTo = invitedTo; + _timeStamp = timeStamp; + _expires = timeStamp + 60000; + } + + public long getTimeRemaining() + { + return _expires - System.currentTimeMillis(); + } + + public boolean hasExpired() + { + return System.currentTimeMillis() >= _expires; + } + + public String getInvitedTo() + { + return _invitedTo; + } + + public String getInvitedBy() + { + return _invitedBy; + } + + public long getTimeStamp() + { + return _timeStamp; + } + + public long getExpires() + { + return _expires; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index e4d4104c0..cd222f1ae 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -1,16 +1,69 @@ package mineplex.core.party; +import com.google.common.collect.Maps; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.Callback; +import mineplex.core.party.redis.locate.LocateType; +import mineplex.core.party.redis.locate.PartyRedisLocate; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import java.util.Map; +import java.util.UUID; + public class PartyManager extends MiniPlugin { + private Portal _portal; + private CoreClientManager _clientManager; + private PreferencesManager _preferencesManager; + + private String _serverName; + + private Map _players = Maps.newHashMap(); + private Map _parties = Maps.newHashMap(); + private Map _pendingInvites = Maps.newHashMap(); + public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager) { super("Parties", plugin); + _portal = portal; + _clientManager = clientManager; + _preferencesManager = preferenceManager; + _serverName = _plugin.getConfig().getString("serverstatus.name"); + } + + public void locatePlayer(String player, Callback callback, LocateType reason) + { + runAsync(() -> { + //locate player + //Find the player and callback with the results + runSync(() -> { + callback.run("SomeServer (TBD when Connor Replies)"); + }); + }); + } + + public Portal getPortal() + { + return _portal; + } + + public CoreClientManager getClientManager() + { + return _clientManager; + } + + public PreferencesManager getPreferencesManager() + { + return _preferencesManager; + } + + public void summon(Player player, String target) + { + new PartyRedisLocate(_serverName, player.getName(), target, LocateType.TRANSFER); } } 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 d487a2bf2..553891dc0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -16,7 +16,7 @@ public class PartyCommand extends CommandBase private final String[] HELP = { C.cDGreenB + C.Strike + "================================", F.main("Party", "/party help - Shows this help screen."), - F.main("Party", "/party - Brings up the Party UI."), + F.main("Party", "/party - Brings up the Party GUI."), F.main("Party", "/party invite - Invite a player to your party." + C.cRed + " Must be the owner."), F.main("Party", "/party accept - Accept an invite to a player's party."), F.main("Party", "/party deny - Deny an invite to a player's party."), @@ -34,50 +34,84 @@ public class PartyCommand extends CommandBase @Override public void Execute(Player caller, String[] args) { - if(args.length == 0) + if (args.length == 0) { //Show UI return; } String argument = args[0]; - if(argument.equalsIgnoreCase("help")) + if (argument.equalsIgnoreCase("help")) { //Show this menu caller.sendMessage(HELP); return; } - if(args.length == 1) + if (args.length == 1) { - if(argument.equalsIgnoreCase("leave")) + if (argument.equalsIgnoreCase("leave")) { + handleLeave(caller); return; } - if(argument.equalsIgnoreCase("disband")) + if (argument.equalsIgnoreCase("disband")) { + handleDisband(caller); return; } return; } - if(args.length == 2) + if (args.length == 2) { String target = args[1]; - if(argument.equalsIgnoreCase("invite")) + if (argument.equalsIgnoreCase("invite")) { + handleInvite(caller, target); return; } - if(argument.equalsIgnoreCase("accept")) + if (argument.equalsIgnoreCase("accept")) { + handleInviteResponse(caller, target, true); return; } - if(argument.equalsIgnoreCase("deny")) + if (argument.equalsIgnoreCase("deny")) { + handleInviteResponse(caller, target, false); return; } - if(argument.equalsIgnoreCase("remove") || argument.equalsIgnoreCase("kick")) + if (argument.equalsIgnoreCase("remove") || argument.equalsIgnoreCase("kick")) { - return; + handleForceRemove(caller, target); } } } + + private void handleInvite(Player caller, String target) + { + + } + + private void handleInviteResponse(Player caller, String target, boolean accept) + { + if(accept) + { + return; + } + + } + + private void handleForceRemove(Player caller, String target) + { + + } + + private void handleLeave(Player caller) + { + + } + + private void handleDisband(Player caller) + { + + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java index a0d4804a4..e1c3bd2fb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java @@ -24,4 +24,14 @@ public class PartyDataHandler implements CommandCallback { } + + public String getCurrentServer() + { + return _currentServer; + } + + public PartyManager getPlugin() + { + return _plugin; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/LocateType.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/LocateType.java new file mode 100644 index 000000000..0032c8180 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/LocateType.java @@ -0,0 +1,15 @@ +package mineplex.core.party.redis.locate; + +/** + * Simplifies the location callback method + */ +public enum LocateType +{ + + LORE, + INVITE_INIT, + INVITE_RESPONSE, + KICK, + TRANSFER, + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocate.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocate.java new file mode 100644 index 000000000..beef6d43e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocate.java @@ -0,0 +1,47 @@ +package mineplex.core.party.redis.locate; + +import mineplex.serverdata.commands.ServerCommand; + +import java.util.UUID; + +public class PartyRedisLocate extends ServerCommand +{ + private String _sender; + private String _sendingServer; + private String _target; + private UUID _uuid = UUID.randomUUID(); + private LocateType _locateType; + + public PartyRedisLocate(String sendingServer, String sender, String target, LocateType locateType) + { + _sender = sender; + _target = target; + _sendingServer = sendingServer; + _locateType = locateType; + } + + public String getSender() + { + return _sender; + } + + public String getServer() + { + return _sendingServer; + } + + public String getTarget() + { + return _target; + } + + public UUID getUUID() + { + return _uuid; + } + + public LocateType getLocateType() + { + return _locateType; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateCallback.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateCallback.java new file mode 100644 index 000000000..973180ed8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateCallback.java @@ -0,0 +1,56 @@ +package mineplex.core.party.redis.locate; + +import mineplex.serverdata.commands.ServerCommand; + +import java.util.UUID; + +public class PartyRedisLocateCallback extends ServerCommand +{ + private String _locatedPlayer; + private String _server; + private String _receivingPlayer; + private UUID _uuid; + private LocateType _locateType; + private String _response; + + public PartyRedisLocateCallback(PartyRedisLocate command, String server, String targetName, LocateType locateType, String response) + { + _uuid = command.getUUID(); + _receivingPlayer = command.getSender(); + _locatedPlayer = targetName; + _server = server; + _locateType = locateType; + _response = response; + setTargetServers(command.getServer()); + } + + public String getLocatedPlayer() + { + return _locatedPlayer; + } + + public String getServer() + { + return _server; + } + + public String getReceivingPlayer() + { + return _receivingPlayer; + } + + public UUID getUUID() + { + return _uuid; + } + + public LocateType getLocateType() + { + return _locateType; + } + + public String getResponse() + { + return _response; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateHandler.java new file mode 100644 index 000000000..edbf4b060 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateHandler.java @@ -0,0 +1,116 @@ +package mineplex.core.party.redis.locate; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.party.PartyManager; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ClickEvent.Action; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class PartyRedisLocateHandler implements CommandCallback +{ + private PartyManager _plugin; + private String _serverName; + + public PartyRedisLocateHandler(PartyManager plugin) + { + _plugin = plugin; + _serverName = _plugin.getPlugin().getConfig().getString("serverstatus.name"); + } + + @Override + public void run(ServerCommand command) + { + if (command instanceof PartyRedisLocate) + { + PartyRedisLocate locate = (PartyRedisLocate) command; + + Player target = Bukkit.getPlayerExact(locate.getTarget()); + + if (target == null) + { + return; + } + handleLocateRequest(locate, target); + return; + } + if (command instanceof PartyRedisLocateCallback) + { + handleLocatedPlayer((PartyRedisLocateCallback) command); + } + } + + public void handleLocateRequest(PartyRedisLocate locate, Player player) + { + LocateType locateType = locate.getLocateType(); + switch (locateType) + { + case INVITE_INIT: + //A requested invite + player.sendMessage(F.main("Party", C.cYellow + locate.getServer() + C.cGray + " has invited you to their party")); + sendAcceptOrDeny(player, locate.getSender()); + break; + case INVITE_RESPONSE: + break; + case KICK: + break; + case LORE: + break; + case TRANSFER: + break; + } + } + + public void handleLocatedPlayer(PartyRedisLocateCallback command) + { + LocateType locateType = command.getLocateType(); + switch (locateType) + { + case INVITE_INIT: + break; + case INVITE_RESPONSE: + break; + case KICK: + break; + case LORE: + break; + case TRANSFER: + break; + } + } + + public void sendAcceptOrDeny(Player player, String arg) + { + TextComponent textComponent = new TextComponent(F.main("Party", "Click one: ")); + + TextComponent accept = new TextComponent("ACCEPT"); + accept.setColor(ChatColor.GREEN); + accept.setBold(true); + accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party accept " + arg)); + accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ + new TextComponent("Click to run /party accept " + arg) + })); + + textComponent.addExtra(accept); + textComponent.addExtra(" "); + + TextComponent deny = new TextComponent("DENY"); + deny.setColor(ChatColor.RED); + deny.setBold(true); + deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party deny " + arg)); + deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ + new TextComponent("Click to run /party deny " + arg) + })); + + textComponent.addExtra(deny); + + player.spigot().sendMessage(textComponent); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java new file mode 100644 index 000000000..f4e8eb954 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java @@ -0,0 +1,44 @@ +package mineplex.core.party.ui; + +import mineplex.core.party.PartyManager; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +/** + * An abstract class for managing buttons inside of menus + */ +public abstract class Button +{ + + private ItemStack _item; + private PartyManager _plugin; + + public Button(ItemStack item, PartyManager plugin) + { + this._item = item; + _plugin = plugin; + } + + /** + * The method called when a players clicks the slot + * + * @param player The player who clicked + */ + public abstract void onClick(Player player); + + public ItemStack getItemStack() + { + return _item; + } + + public void setItemStack(ItemStack item) + { + this._item = item; + } + + public PartyManager getPlugin() + { + return _plugin; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java new file mode 100644 index 000000000..35504e7e5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java @@ -0,0 +1,191 @@ +package mineplex.core.party.ui; + +import mineplex.core.party.ui.button.IconButton; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * A class to manage dynamic creation of GUI's + */ +public abstract class Menu +{ + + protected static final Button[] EMPTY = new Button[45]; + protected static Map MENUS = new HashMap<>(); + private String _name; + protected Button[] _buttons; + + public Menu(String name) + { + _name = name; + _buttons = EMPTY; + } + + 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); + } + + public String getName() + { + return ChatColor.translateAlternateColorCodes('&', _name); + } + + /** + * 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()); + + if (MENUS.get(player.getUniqueId()) != null) + { + MENUS.remove(player.getUniqueId()); + } + + MENUS.put(player.getUniqueId(), this); + + int size = (_buttons.length + 8) / 9 * 9; + Inventory inventory = Bukkit.createInventory(player, size, getName()); + + for (int i = 0; i < _buttons.length; i++) + { + if (_buttons[i] == null) + { + continue; + } + + ItemStack item = _buttons[i].getItemStack(); + + inventory.setItem(i, item); + } + player.openInventory(inventory); + } + + /** + * Set up the GUI with buttons + * + * @return The setup button array + */ + protected abstract Button[] setUp(); + + public Button[] getButtons() + { + return _buttons; + } + + public void setButtons(Button[] buttons) + { + _buttons = buttons; + } + + /** + * 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; + } + } + + /** + * 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); + } + + /** + * 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(); + + if (view == null) + { + return; + } + + if (!view.getTitle().equalsIgnoreCase(getName())) + { + return; + } + + Inventory inventory = view.getTopInventory(); + for (int i = 0; i < _buttons.length; i++) + { + if (_buttons[i] == null) + { + continue; + } + + ItemStack item = _buttons[i].getItemStack(); + + inventory.setItem(i, item); + } + } + + public void setTitle(String title) + { + _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 new file mode 100644 index 000000000..8914d2b4f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java @@ -0,0 +1,45 @@ +package mineplex.core.party.ui; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; + +/** + * Listener for the Menu system + */ +public class MenuListener implements Listener +{ + + @EventHandler + public void onClick(InventoryClickEvent event) + { + String name = event.getInventory().getName(); + Player player = (Player) event.getWhoClicked(); + Menu gui = Menu.get(player.getUniqueId()); + + if (gui == null) + { + return; + } + + if (!gui.getName().equalsIgnoreCase(name)) + { + return; + } + + Button button = gui.getButton(event.getRawSlot()); + + event.setCancelled(true); + event.setResult(Event.Result.DENY); + + if (button == null) + { + return; + } + + button.onClick(player); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/PartyMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/PartyMenu.java deleted file mode 100644 index a9b09004c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/PartyMenu.java +++ /dev/null @@ -1,8 +0,0 @@ -package mineplex.core.party.ui; - -/** - * The display menu for managing parties - */ -public class PartyMenu -{ -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java new file mode 100644 index 000000000..ccbf61506 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java @@ -0,0 +1,25 @@ +package mineplex.core.party.ui.button; + +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +/** + * Representation of a purely cosmetic icon + * IE: When clicked, this button does not execute any action + */ +public class IconButton extends Button +{ + + public IconButton(ItemStack item, PartyManager plugin) + { + super(item, plugin); + } + + @Override + public void onClick(Player player) + { + + } +} 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 new file mode 100644 index 000000000..132cc2dcd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java @@ -0,0 +1,62 @@ +package mineplex.core.party.ui.button; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.party.PartyManager; +import mineplex.core.party.redis.locate.LocateType; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +/** + * The button representing a Party member. + */ +public class PartyMemberIcon extends Button +{ + + private final ItemStack DEFAULT = ItemStackFactory.Instance.CreateStack(Material.INK_SACK, DyeColor.GRAY.getDyeData(), 1, "Locating..."); + + private ItemStack _itemStack; + private String _target; + + public PartyMemberIcon(Player viewer, String player, PartyManager plugin) + { + super(null, plugin); + + _target = player; + + plugin.locatePlayer(player, string -> { + + String[] lore = { + "", + C.cWhite + "Server: " + C.cGreen + string, + "", + C.cGreen + "Click to summon to your server." + }; + + _itemStack = ItemStackFactory.Instance.CreateStack(Material.SKULL_ITEM, (byte) 3, 1, + C.cYellow + player, lore); + + Menu.get(viewer.getUniqueId()).update(viewer); + }, LocateType.LORE); + } + + @Override + public void onClick(Player player) + { + getPlugin().summon(player, _target); + } + + @Override + public ItemStack getItemStack() + { + if(_itemStack == null) + { + return DEFAULT; + } + return _itemStack; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMenu.java new file mode 100644 index 000000000..668c6eab2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMenu.java @@ -0,0 +1,26 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.party.Party; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; + +/** + * The display menu for managing parties + */ +public class PartyMenu extends Menu +{ + + private Party _party; + + public PartyMenu(Party party) + { + super(party.getOwner() + "'s Party"); + _party = party; + } + + @Override + protected Button[] setUp() + { + return new Button[0]; + } +} From bccc11eeaf15a70dcd204ca1eb1683230af4c192 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sat, 4 Jun 2016 22:41:01 -0500 Subject: [PATCH 03/53] Files changed that need to be edited later on with the new Party System. Memory commit --- .../src/mineplex/core/party/PartyManager.java | 2 + .../src/mineplex/hub/HubManager.java | 128 +++++------------- .../src/mineplex/hub/queue/ui/QueuePage.java | 32 +---- .../mineplex/hub/server/ServerManager.java | 42 +----- 4 files changed, 43 insertions(+), 161 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index cd222f1ae..a19a14983 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -4,6 +4,7 @@ import com.google.common.collect.Maps; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.Callback; +import mineplex.core.party.command.PartyCommand; import mineplex.core.party.redis.locate.LocateType; import mineplex.core.party.redis.locate.PartyRedisLocate; import mineplex.core.portal.Portal; @@ -34,6 +35,7 @@ public class PartyManager extends MiniPlugin _clientManager = clientManager; _preferencesManager = preferenceManager; _serverName = _plugin.getConfig().getString("serverstatus.name"); + addCommand(new PartyCommand(this)); } public void locatePlayer(String player, Callback callback, LocateType reason) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 0df7f3c6b..9ec78c1be 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -1,47 +1,5 @@ package mineplex.hub; -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; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -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.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerVelocityEvent; -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 mineplex.core.MiniClientPlugin; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; @@ -52,15 +10,7 @@ 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.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.common.util.*; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; @@ -86,7 +36,6 @@ import mineplex.core.noteblock.event.SongFinishEvent; import mineplex.core.notifier.NotificationManager; import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; -import mineplex.core.party.Party; import mineplex.core.party.PartyManager; import mineplex.core.personalServer.PersonalServerManager; import mineplex.core.pet.PetManager; @@ -103,21 +52,8 @@ 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.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.commands.*; +import mineplex.hub.modules.*; import mineplex.hub.profile.gui.GUIProfile; import mineplex.hub.tutorial.TutorialManager; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; @@ -131,6 +67,36 @@ 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 { @@ -613,32 +579,7 @@ public class HubManager extends MiniClientPlugin 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.GetPlayers()) - { - 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); - } - - return; - } else { TextComponent rankComponent = new TextComponent(rankStr); @@ -741,9 +682,6 @@ public class HubManager extends MiniClientPlugin for (Player player : UtilServer.getPlayers()) { - //Dont Waste Time - if (_partyManager.GetParty(player) != null) - continue; //Return to Main Scoreboard if (!player.getScoreboard().equals(_scoreboards.get(player))) 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 f0a5122cb..99b09283c 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java @@ -1,18 +1,12 @@ package mineplex.hub.queue.ui; -import java.util.ArrayList; -import java.util.List; - import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.UtilPlayer; 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.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -131,31 +125,7 @@ public class QueuePage extends ShopPageBase private void queuePlayer(int gameType, Player player) { - Party party = getPlugin().getPartyManager().GetParty(player); - - if (party != null) - { - if (player.getName().equals(party.GetLeader())) - { - List players = new ArrayList(); - - for (String name : party.GetPlayers()) - { - Player partyPlayer = UtilPlayer.searchExact(name); - - if (partyPlayer == null) - continue; - - players.add(partyPlayer); - } - - getPlugin().queuePlayer(gameType, players.toArray(new Player[]{})); - } - } - else - { - getPlugin().queuePlayer(gameType, player); - } + getPlugin().queuePlayer(gameType, player); buildPage(); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index 66d8f06a4..34424de8b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -510,15 +510,10 @@ public class ServerManager extends MiniDbClientPlugin public void selectServer(org.bukkit.entity.Player player, ServerInfo serverInfo) { - Party party = _partyManager.GetParty(player); - - if (party == null || player.getName().equals(party.GetLeader())) - { - player.leaveVehicle(); - player.eject(); - - _portal.sendPlayerToServer(player, serverInfo.Name); - } + player.leaveVehicle(); + player.eject(); + + _portal.sendPlayerToServer(player, serverInfo.Name); } /** @@ -731,32 +726,9 @@ public class ServerManager extends MiniDbClientPlugin public int getRequiredSlots(Player player, String serverType) { int slots = 0; - - Party party = _partyManager.GetParty(player); - - if (party != null) - { - if (player.getName().equals(party.GetLeader())) - { - for (String name : party.GetPlayers()) - { - Player partyPlayer = UtilPlayer.searchExact(name); - - if (partyPlayer == null) - continue; - - if (_clientManager.Get(partyPlayer).GetRank().has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverType + " ULTRA")) - continue; - - slots++; - } - } - } - else - { - if (!_clientManager.Get(player).GetRank().has(Rank.ULTRA) && !_donationManager.Get(player.getName()).OwnsUnknownPackage(serverType + " ULTRA")) - slots++; - } + + if (!_clientManager.Get(player).GetRank().has(Rank.ULTRA) && !_donationManager.Get(player.getName()).OwnsUnknownPackage(serverType + " ULTRA")) + slots++; return slots; } From e7f4f00433e0e9fcb8202585fe8265e30b10ad67 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sat, 4 Jun 2016 22:56:30 -0500 Subject: [PATCH 04/53] Files changed that need to be edited later on with the new Party System. Memory commit --- .../src/mineplex/hub/queue/ui/QueueShop.java | 13 ++++--------- .../src/mineplex/hub/server/ui/ServerNpcShop.java | 13 ++++--------- .../hub/server/ui/clans/ClanMoveServerShop.java | 10 +++------- .../hub/server/ui/clans/ClansServerShop.java | 10 +++------- 4 files changed, 14 insertions(+), 32 deletions(-) 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 33b2c6bbd..30d5f7de2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java @@ -1,22 +1,17 @@ package mineplex.hub.queue.ui; -import java.util.Iterator; - 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; +import java.util.Iterator; + public class QueueShop extends ShopBase { public QueueShop(QueueManager plugin, CoreClientManager clientManager, mineplex.core.donation.DonationManager donationManager, String name) @@ -33,7 +28,7 @@ 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())) { @@ -41,7 +36,7 @@ public class QueueShop extends ShopBase 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 100a4689d..2abc03971 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java @@ -1,17 +1,12 @@ package mineplex.hub.server.ui; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - 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.entity.Player; public class ServerNpcShop extends ShopBase { @@ -41,15 +36,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())) { 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 e85528ee8..5d139cf3c 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,17 +1,13 @@ package mineplex.hub.server.ui.clans; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - 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.entity.Player; public class ClanMoveServerShop extends ShopBase { @@ -37,14 +33,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 f5590b095..8b49a4bd6 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,16 +1,12 @@ package mineplex.hub.server.ui.clans; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - 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.entity.Player; public class ClansServerShop extends ShopBase { @@ -32,14 +28,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; } From d1fb547d0921a153eddace9e6abc5358e8df5110 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sat, 4 Jun 2016 23:02:02 -0500 Subject: [PATCH 05/53] Files changed that need to be edited later on with the new Party System. Memory commit --- .../arcade/managers/chat/GameChatManager.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) 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 347730a4d..ee878cbb1 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 @@ -1,32 +1,26 @@ package nautilus.game.arcade.managers.chat; -import java.text.DecimalFormat; -import java.util.AbstractMap; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - import mineplex.core.account.CoreClient; import mineplex.core.common.Rank; 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.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.jooq.tools.json.JSONObject; +import java.text.DecimalFormat; +import java.util.*; + public class GameChatManager implements Listener { @@ -122,7 +116,7 @@ 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); @@ -147,7 +141,7 @@ public class GameChatManager implements Listener return; } - } + }*/ event.setFormat(levelStr + rankStr + senderName + " " + C.cWhite + "%2$s"); From 8c3d5f66a263e043cc8143d8afaec45424fabdb5 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sun, 5 Jun 2016 00:03:01 -0500 Subject: [PATCH 06/53] UI work. --- .../src/mineplex/core/party/Party.java | 10 ++++ .../src/mineplex/core/party/PartyManager.java | 2 +- .../core/party/command/PartyCommand.java | 22 +++++---- .../src/mineplex/core/party/ui/Menu.java | 11 +++-- .../core/party/ui/button/PartyMemberIcon.java | 11 ++++- .../core/party/ui/menus/PartyMainMenu.java | 24 ++++++++++ .../core/party/ui/menus/PartyMenu.java | 26 ---------- .../core/party/ui/menus/PartyOwnerMenu.java | 47 +++++++++++++++++++ 8 files changed, 110 insertions(+), 43 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMenu.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 4865bb123..4e8d6da7a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -1,5 +1,8 @@ package mineplex.core.party; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + import java.util.List; import java.util.Map; @@ -13,6 +16,13 @@ public class Party private List _members; private Map _invites; + public Party(String owner) + { + _owner = owner; + _members = Lists.newArrayList(); + _invites = Maps.newHashMap(); + } + public String getOwner() { return _owner; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index a19a14983..ce7dd66ee 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -44,7 +44,7 @@ public class PartyManager extends MiniPlugin //locate player //Find the player and callback with the results runSync(() -> { - callback.run("SomeServer (TBD when Connor Replies)"); + callback.run("SomeServer"); }); }); } 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 553891dc0..f3642b205 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -3,8 +3,9 @@ package mineplex.core.party.command; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; +import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.menus.PartyOwnerMenu; import org.bukkit.entity.Player; /** @@ -15,14 +16,14 @@ public class PartyCommand extends CommandBase private final String[] HELP = { C.cDGreenB + C.Strike + "================================", - F.main("Party", "/party help - Shows this help screen."), - F.main("Party", "/party - Brings up the Party GUI."), - F.main("Party", "/party invite - Invite a player to your party." + C.cRed + " Must be the owner."), - F.main("Party", "/party accept - Accept an invite to a player's party."), - F.main("Party", "/party deny - Deny an invite to a player's party."), - F.main("Party", "/party leave - Leave your current party."), - F.main("Party", "/party kick/remove - Remove a player from your party." + C.cRed + " Must be the owner."), - F.main("Party", "/party disband - Disband your party." + C.cRed + " Must be the owner."), + C.cGray + "/party help - Shows this help screen.", + C.cGray + "/party - Brings up the Party GUI.", + C.cGray + "/party invite - Invite a player to your party." + C.cRed + " Must be the owner.", + C.cGray + "/party accept - Accept an invite to a player's party.", + C.cGray + "/party deny - Deny an invite to a player's party.", + C.cGray + "/party leave - Leave your current party.", + C.cGray + "/party kick/remove - Remove a player from your party." + C.cRed + " Must be the owner.", + C.cGray + "/party disband - Disband your party." + C.cRed + " Must be the owner.", C.cDGreenB + C.Strike + "================================", }; @@ -36,6 +37,7 @@ public class PartyCommand extends CommandBase { if (args.length == 0) { + new PartyOwnerMenu(new Party(caller.getName()), Plugin).open(caller); //Show UI return; } @@ -92,7 +94,7 @@ public class PartyCommand extends CommandBase private void handleInviteResponse(Player caller, String target, boolean accept) { - if(accept) + if (accept) { return; } 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 35504e7e5..d925e5162 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java @@ -1,5 +1,6 @@ package mineplex.core.party.ui; +import mineplex.core.party.PartyManager; import mineplex.core.party.ui.button.IconButton; import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; @@ -22,11 +23,13 @@ public abstract class Menu protected static Map MENUS = new HashMap<>(); private String _name; protected Button[] _buttons; + protected PartyManager _plugin; - public Menu(String name) + public Menu(String name, PartyManager plugin) { _name = name; _buttons = EMPTY; + _plugin = plugin; } public static Menu get(UUID name) @@ -43,7 +46,7 @@ public abstract class Menu */ protected Button create(ItemStack item) { - return new IconButton(item); + return new IconButton(item, _plugin); } public String getName() @@ -59,7 +62,7 @@ public abstract class Menu */ public void open(Player player) { - setButtons(setUp()); + setButtons(setUp(player)); if (MENUS.get(player.getUniqueId()) != null) { @@ -90,7 +93,7 @@ public abstract class Menu * * @return The setup button array */ - protected abstract Button[] setUp(); + protected abstract Button[] setUp(Player player); public Button[] getButtons() { 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 132cc2dcd..5287cfc96 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,6 +1,7 @@ package mineplex.core.party.ui.button; import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.party.PartyManager; import mineplex.core.party.redis.locate.LocateType; @@ -37,10 +38,15 @@ public class PartyMemberIcon extends Button C.cGreen + "Click to summon to your server." }; - _itemStack = ItemStackFactory.Instance.CreateStack(Material.SKULL_ITEM, (byte) 3, 1, - C.cYellow + player, lore); + ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3); + builder.setTitle(C.cYellow + player); + builder.setLore(lore); + builder.setPlayerHead(player); + + _itemStack = builder.build(); Menu.get(viewer.getUniqueId()).update(viewer); + }, LocateType.LORE); } @@ -57,6 +63,7 @@ public class PartyMemberIcon extends Button { return DEFAULT; } + return _itemStack; } } 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 new file mode 100644 index 000000000..208cec155 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java @@ -0,0 +1,24 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; +import org.bukkit.entity.Player; + +/** + * The main GUI for parties. + */ +public class PartyMainMenu extends Menu +{ + + public PartyMainMenu(PartyManager plugin) + { + super("Mineplex Parties", plugin); + } + + @Override + protected Button[] setUp(Player player) + { + return new Button[0]; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMenu.java deleted file mode 100644 index 668c6eab2..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMenu.java +++ /dev/null @@ -1,26 +0,0 @@ -package mineplex.core.party.ui.menus; - -import mineplex.core.party.Party; -import mineplex.core.party.ui.Button; -import mineplex.core.party.ui.Menu; - -/** - * The display menu for managing parties - */ -public class PartyMenu extends Menu -{ - - private Party _party; - - public PartyMenu(Party party) - { - super(party.getOwner() + "'s Party"); - _party = party; - } - - @Override - protected Button[] setUp() - { - return new Button[0]; - } -} 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 new file mode 100644 index 000000000..80625184d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java @@ -0,0 +1,47 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.party.Party; +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 org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +/** + * The display menu for managing parties by the owner + */ +public class PartyOwnerMenu extends Menu +{ + + private Party _party; + + public PartyOwnerMenu(Party party, PartyManager plugin) + { + super(party.getOwner() + "'s Party", plugin); + _party = party; + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[54]; + + //Tools + buttons[1] = create(new ItemStack(Material.SIGN)); + buttons[4] = create(new ItemStack(Material.IRON_AXE)); + buttons[7] = create(new ItemStack(Material.BARRIER)); + buttons[46] = create(new ItemStack(Material.COMPASS)); + buttons[49] = create(new ItemStack(Material.EMERALD_BLOCK)); + buttons[52] = create(new ItemStack(Material.BOOK_AND_QUILL)); + + //Players + for(int i = 18; i < 33; i++) + { + buttons[i] = new PartyMemberIcon(player, player.getName(), _plugin); + } + + return buttons; + } +} From 4ce9c908394de84430e96ca9c694c86d4e6d9ed3 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sun, 5 Jun 2016 00:32:04 -0500 Subject: [PATCH 07/53] Party Redis init. Wrap for 6/4/2016. Total time: 9.3 hrs. --- .../core/party/redis/PartyRedisManager.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java new file mode 100644 index 000000000..bc064413b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java @@ -0,0 +1,58 @@ +package mineplex.core.party.redis; + +import mineplex.core.party.PartyManager; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Redis system for Parties + */ +public class PartyRedisManager +{ + protected static final String CHANNEL_BASE = "party-pubsub"; + protected static final String PLAYER_REQUEST_CHANNEL = "mineplex-player-locater"; + + private PartyManager _plugin; + private JedisPool _writePool; + private JedisPool _readPool; + private String _channel; + private String _serverName; + + public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool) + { + _plugin = plugin; + _serverName = serverName; + _readPool = readPool; + _writePool = writePool; + _channel = CHANNEL_BASE + "-" + serverName; + + plugin.runAsync(() -> { + try (Jedis jedis = readPool.getResource()) + { + jedis.subscribe(new PartyRedisListener(), _channel); + jedis.subscribe(new PlayerFinderListener(), PLAYER_REQUEST_CHANNEL); + } + }); + } + + public void findPlayer(String player) + { + _plugin.runAsync(() -> { + try (Jedis jedis = _writePool.getResource()) + { + jedis.publish(PLAYER_REQUEST_CHANNEL, player + ":" + _serverName); + } + }); + } + + public void publish(String message, String server) + { + _plugin.runAsync(() -> { + try (Jedis jedis = _writePool.getResource()) + { + jedis.publish(CHANNEL_BASE + "-" + server, message); + } + }); + } + +} From 502111ef4ec720c8d7ddc43a425dbac64241420d Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sun, 5 Jun 2016 00:42:22 -0500 Subject: [PATCH 08/53] Redis system needs a shit ton of work. Need to design it better. --- .../src/mineplex/core/party/PartyManager.java | 13 +- .../party/redis/{locate => }/LocateType.java | 2 +- .../mineplex/core/party/redis/PartyData.java | 35 ------ .../core/party/redis/PartyDataHandler.java | 37 ------ .../core/party/redis/PartyRedisManager.java | 58 --------- .../party/redis/locate/PartyRedisLocate.java | 47 ------- .../locate/PartyRedisLocateCallback.java | 56 --------- .../redis/locate/PartyRedisLocateHandler.java | 116 ------------------ .../core/party/ui/button/PartyMemberIcon.java | 2 +- 9 files changed, 6 insertions(+), 360 deletions(-) rename Plugins/Mineplex.Core/src/mineplex/core/party/redis/{locate => }/LocateType.java (76%) delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyData.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocate.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateCallback.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateHandler.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index ce7dd66ee..7be27a47a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -5,8 +5,7 @@ import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.Callback; import mineplex.core.party.command.PartyCommand; -import mineplex.core.party.redis.locate.LocateType; -import mineplex.core.party.redis.locate.PartyRedisLocate; +import mineplex.core.party.redis.LocateType; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import org.bukkit.entity.Player; @@ -22,6 +21,7 @@ public class PartyManager extends MiniPlugin private CoreClientManager _clientManager; private PreferencesManager _preferencesManager; + private String _serverName; private Map _players = Maps.newHashMap(); @@ -40,12 +40,8 @@ public class PartyManager extends MiniPlugin public void locatePlayer(String player, Callback callback, LocateType reason) { - runAsync(() -> { - //locate player - //Find the player and callback with the results - runSync(() -> { - callback.run("SomeServer"); - }); + runSync(() -> { + callback.run("SomeServer"); }); } @@ -66,6 +62,5 @@ public class PartyManager extends MiniPlugin public void summon(Player player, String target) { - new PartyRedisLocate(_serverName, player.getName(), target, LocateType.TRANSFER); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/LocateType.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/LocateType.java similarity index 76% rename from Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/LocateType.java rename to Plugins/Mineplex.Core/src/mineplex/core/party/redis/LocateType.java index 0032c8180..ac006ffd2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/LocateType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/LocateType.java @@ -1,4 +1,4 @@ -package mineplex.core.party.redis.locate; +package mineplex.core.party.redis; /** * Simplifies the location callback method diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyData.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyData.java deleted file mode 100644 index c4b9e9258..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyData.java +++ /dev/null @@ -1,35 +0,0 @@ -package mineplex.core.party.redis; - -import mineplex.core.party.Party; -import mineplex.serverdata.commands.ServerCommand; - -import java.util.List; - -/** - * Redis party data - */ -public class PartyData extends ServerCommand -{ - - private String _owner; - private List _members; - - public PartyData(Party party) - { - _owner = party.getOwner(); - _members = party.getMembers(); - } - - public String getOwner() - { - return _owner; - } - - public List getMembers() - { - return _members; - } - - - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java deleted file mode 100644 index e1c3bd2fb..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyDataHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -package mineplex.core.party.redis; - -import mineplex.core.party.PartyManager; -import mineplex.serverdata.commands.CommandCallback; -import mineplex.serverdata.commands.ServerCommand; - -/** - * Handler for party redis data - */ -public class PartyDataHandler implements CommandCallback -{ - - private final String _currentServer; - private final PartyManager _plugin; - - public PartyDataHandler(String thisServer, PartyManager partyManager) - { - _currentServer = thisServer; - _plugin = partyManager; - } - - @Override - public void run(ServerCommand command) - { - - } - - public String getCurrentServer() - { - return _currentServer; - } - - public PartyManager getPlugin() - { - return _plugin; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java deleted file mode 100644 index bc064413b..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java +++ /dev/null @@ -1,58 +0,0 @@ -package mineplex.core.party.redis; - -import mineplex.core.party.PartyManager; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPool; - -/** - * Redis system for Parties - */ -public class PartyRedisManager -{ - protected static final String CHANNEL_BASE = "party-pubsub"; - protected static final String PLAYER_REQUEST_CHANNEL = "mineplex-player-locater"; - - private PartyManager _plugin; - private JedisPool _writePool; - private JedisPool _readPool; - private String _channel; - private String _serverName; - - public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool) - { - _plugin = plugin; - _serverName = serverName; - _readPool = readPool; - _writePool = writePool; - _channel = CHANNEL_BASE + "-" + serverName; - - plugin.runAsync(() -> { - try (Jedis jedis = readPool.getResource()) - { - jedis.subscribe(new PartyRedisListener(), _channel); - jedis.subscribe(new PlayerFinderListener(), PLAYER_REQUEST_CHANNEL); - } - }); - } - - public void findPlayer(String player) - { - _plugin.runAsync(() -> { - try (Jedis jedis = _writePool.getResource()) - { - jedis.publish(PLAYER_REQUEST_CHANNEL, player + ":" + _serverName); - } - }); - } - - public void publish(String message, String server) - { - _plugin.runAsync(() -> { - try (Jedis jedis = _writePool.getResource()) - { - jedis.publish(CHANNEL_BASE + "-" + server, message); - } - }); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocate.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocate.java deleted file mode 100644 index beef6d43e..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocate.java +++ /dev/null @@ -1,47 +0,0 @@ -package mineplex.core.party.redis.locate; - -import mineplex.serverdata.commands.ServerCommand; - -import java.util.UUID; - -public class PartyRedisLocate extends ServerCommand -{ - private String _sender; - private String _sendingServer; - private String _target; - private UUID _uuid = UUID.randomUUID(); - private LocateType _locateType; - - public PartyRedisLocate(String sendingServer, String sender, String target, LocateType locateType) - { - _sender = sender; - _target = target; - _sendingServer = sendingServer; - _locateType = locateType; - } - - public String getSender() - { - return _sender; - } - - public String getServer() - { - return _sendingServer; - } - - public String getTarget() - { - return _target; - } - - public UUID getUUID() - { - return _uuid; - } - - public LocateType getLocateType() - { - return _locateType; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateCallback.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateCallback.java deleted file mode 100644 index 973180ed8..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateCallback.java +++ /dev/null @@ -1,56 +0,0 @@ -package mineplex.core.party.redis.locate; - -import mineplex.serverdata.commands.ServerCommand; - -import java.util.UUID; - -public class PartyRedisLocateCallback extends ServerCommand -{ - private String _locatedPlayer; - private String _server; - private String _receivingPlayer; - private UUID _uuid; - private LocateType _locateType; - private String _response; - - public PartyRedisLocateCallback(PartyRedisLocate command, String server, String targetName, LocateType locateType, String response) - { - _uuid = command.getUUID(); - _receivingPlayer = command.getSender(); - _locatedPlayer = targetName; - _server = server; - _locateType = locateType; - _response = response; - setTargetServers(command.getServer()); - } - - public String getLocatedPlayer() - { - return _locatedPlayer; - } - - public String getServer() - { - return _server; - } - - public String getReceivingPlayer() - { - return _receivingPlayer; - } - - public UUID getUUID() - { - return _uuid; - } - - public LocateType getLocateType() - { - return _locateType; - } - - public String getResponse() - { - return _response; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateHandler.java deleted file mode 100644 index edbf4b060..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/locate/PartyRedisLocateHandler.java +++ /dev/null @@ -1,116 +0,0 @@ -package mineplex.core.party.redis.locate; - -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.party.PartyManager; -import mineplex.serverdata.commands.CommandCallback; -import mineplex.serverdata.commands.ServerCommand; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ClickEvent.Action; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class PartyRedisLocateHandler implements CommandCallback -{ - private PartyManager _plugin; - private String _serverName; - - public PartyRedisLocateHandler(PartyManager plugin) - { - _plugin = plugin; - _serverName = _plugin.getPlugin().getConfig().getString("serverstatus.name"); - } - - @Override - public void run(ServerCommand command) - { - if (command instanceof PartyRedisLocate) - { - PartyRedisLocate locate = (PartyRedisLocate) command; - - Player target = Bukkit.getPlayerExact(locate.getTarget()); - - if (target == null) - { - return; - } - handleLocateRequest(locate, target); - return; - } - if (command instanceof PartyRedisLocateCallback) - { - handleLocatedPlayer((PartyRedisLocateCallback) command); - } - } - - public void handleLocateRequest(PartyRedisLocate locate, Player player) - { - LocateType locateType = locate.getLocateType(); - switch (locateType) - { - case INVITE_INIT: - //A requested invite - player.sendMessage(F.main("Party", C.cYellow + locate.getServer() + C.cGray + " has invited you to their party")); - sendAcceptOrDeny(player, locate.getSender()); - break; - case INVITE_RESPONSE: - break; - case KICK: - break; - case LORE: - break; - case TRANSFER: - break; - } - } - - public void handleLocatedPlayer(PartyRedisLocateCallback command) - { - LocateType locateType = command.getLocateType(); - switch (locateType) - { - case INVITE_INIT: - break; - case INVITE_RESPONSE: - break; - case KICK: - break; - case LORE: - break; - case TRANSFER: - break; - } - } - - public void sendAcceptOrDeny(Player player, String arg) - { - TextComponent textComponent = new TextComponent(F.main("Party", "Click one: ")); - - TextComponent accept = new TextComponent("ACCEPT"); - accept.setColor(ChatColor.GREEN); - accept.setBold(true); - accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party accept " + arg)); - accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ - new TextComponent("Click to run /party accept " + arg) - })); - - textComponent.addExtra(accept); - textComponent.addExtra(" "); - - TextComponent deny = new TextComponent("DENY"); - deny.setColor(ChatColor.RED); - deny.setBold(true); - deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party deny " + arg)); - deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ - new TextComponent("Click to run /party deny " + arg) - })); - - textComponent.addExtra(deny); - - player.spigot().sendMessage(textComponent); - } - -} 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 5287cfc96..ca8b0ef75 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 @@ -4,7 +4,7 @@ import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.party.PartyManager; -import mineplex.core.party.redis.locate.LocateType; +import mineplex.core.party.redis.LocateType; import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Menu; import org.bukkit.DyeColor; From ee35dd34428382e8b3ba51bb51591ee22fff8f4e Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sun, 5 Jun 2016 19:05:29 -0500 Subject: [PATCH 09/53] Redis system implementation and code refactoring. Total time: 13hr --- .../src/mineplex/core/party/Party.java | 12 + .../src/mineplex/core/party/PartyManager.java | 79 +++++- .../core/party/command/PartyCommand.java | 5 +- .../party/manager/PartyInviteManager.java | 260 ++++++++++++++++++ .../core/party/manager/PartyJoinManager.java | 101 +++++++ .../core/party/manager/PartyRedisManager.java | 98 +++++++ .../mineplex/core/party/redis/LocateType.java | 15 - .../core/party/redis/PartyRedisListener.java | 25 ++ .../core/party/redis/RedisMessageType.java | 69 +++++ .../core/party/ui/button/PartyMemberIcon.java | 32 +-- .../ui/button/tools/AddPlayerButton.java | 8 + .../core/party/ui/menus/PartyMainMenu.java | 4 +- .../core/party/ui/menus/PartyOwnerMenu.java | 2 +- 13 files changed, 650 insertions(+), 60 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/LocateType.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 4e8d6da7a..7bad7d233 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -2,6 +2,7 @@ package mineplex.core.party; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import org.bukkit.Bukkit; import java.util.List; import java.util.Map; @@ -21,6 +22,7 @@ public class Party _owner = owner; _members = Lists.newArrayList(); _invites = Maps.newHashMap(); + _members.add(owner); } public String getOwner() @@ -37,4 +39,14 @@ public class Party { return _invites; } + + public String getName() + { + return _owner; + } + + public void sendMessage(String message) + { + getMembers().stream().map(Bukkit::getPlayer).forEach(player -> player.sendMessage(message)); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index 7be27a47a..6ff8d01bc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -3,11 +3,14 @@ package mineplex.core.party; import com.google.common.collect.Maps; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.Callback; import mineplex.core.party.command.PartyCommand; -import mineplex.core.party.redis.LocateType; +import mineplex.core.party.manager.PartyInviteManager; +import mineplex.core.party.manager.PartyJoinManager; +import mineplex.core.party.manager.PartyRedisManager; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; +import mineplex.serverdata.Utility; +import mineplex.serverdata.servers.ServerManager; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -17,16 +20,17 @@ import java.util.UUID; public class PartyManager extends MiniPlugin { - private Portal _portal; - private CoreClientManager _clientManager; - private PreferencesManager _preferencesManager; + private final Portal _portal; + private final CoreClientManager _clientManager; + private final PreferencesManager _preferencesManager; + private final PartyRedisManager _redisManager; + private final PartyInviteManager _inviteManager; + private final PartyJoinManager _joinManager; + private final String _serverName; - private String _serverName; - - private Map _players = Maps.newHashMap(); - private Map _parties = Maps.newHashMap(); - private Map _pendingInvites = Maps.newHashMap(); + private final Map _players = Maps.newHashMap(); + private final Map _parties = Maps.newHashMap(); public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager) { @@ -35,14 +39,43 @@ public class PartyManager extends MiniPlugin _clientManager = clientManager; _preferencesManager = preferenceManager; _serverName = _plugin.getConfig().getString("serverstatus.name"); + _redisManager = new PartyRedisManager(this, _serverName, + Utility.generatePool(ServerManager.getMasterConnection()), + Utility.generatePool(ServerManager.getSlaveConnection())); + _inviteManager = new PartyInviteManager(this, _redisManager); + _joinManager = new PartyJoinManager(this); addCommand(new PartyCommand(this)); } - public void locatePlayer(String player, Callback callback, LocateType reason) + + public Party getParty(String party) { - runSync(() -> { - callback.run("SomeServer"); - }); + return _parties.get(party); + } + + public Party getParty(Player player) + { + return _players.get(player.getUniqueId()); + } + + public void addParty(Party party) + { + _parties.put(party.getName(), party); + } + + public void addToParty(UUID uuid, Party party) + { + _players.put(uuid, party); + } + + public void removeParty(Party party) + { + _parties.remove(party.getName()); + } + + public void removeFromParty(UUID uuid) + { + _players.remove(uuid); } public Portal getPortal() @@ -60,7 +93,23 @@ public class PartyManager extends MiniPlugin return _preferencesManager; } - public void summon(Player player, String target) + public PartyRedisManager getRedisManager() { + return _redisManager; + } + + public PartyInviteManager getInviteManager() + { + return _inviteManager; + } + + public String getServerName() + { + return _serverName; + } + + public PartyJoinManager getJoinManager() + { + return _joinManager; } } 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 f3642b205..0d5b4afdd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -94,10 +94,6 @@ public class PartyCommand extends CommandBase private void handleInviteResponse(Player caller, String target, boolean accept) { - if (accept) - { - return; - } } @@ -115,5 +111,6 @@ public class PartyCommand extends CommandBase { } + } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java new file mode 100644 index 000000000..466a2c453 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -0,0 +1,260 @@ +package mineplex.core.party.manager; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import mineplex.core.common.util.F; +import mineplex.core.party.InviteData; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ClickEvent.Action; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * + */ +public class PartyInviteManager +{ + + public enum InviteResponse { + + ACCEPTED("{0} has joined the party!"), + DENIED("{0} has declined joining your party."), + EXPIRED("{0} did not respond in time."); + + private String _message; + + InviteResponse(String message) + { + _message = message; + } + + public String format(String target) + { + return String.format(_message, target); + } + } + + private final Map INVITE_FROM_SERVERS = Maps.newHashMap(); + + private final Map> _activeInvites = Maps.newHashMap(); + private final Map _invitedBy = Maps.newHashMap(); + private final Map _awaitingJoin = Maps.newHashMap(); + + private final PartyManager _plugin; + private final PartyRedisManager _partyRedisManager; + + public PartyInviteManager(PartyManager plugin, PartyRedisManager partyRedisManager) + { + _plugin = plugin; + _partyRedisManager = partyRedisManager; + } + + public void invite(String sender, UUID targetUUID) + { + addToInvite(targetUUID, sender, sender, System.currentTimeMillis()); + } + + public void handleInviteRequest(String sender, String target, String serverFrom) + { + Player player = Bukkit.getPlayer(target); + if (player == null) + { + //Shouldn't happen, as a "findPLayer" packet will be sent out first. + return; + } + INVITE_FROM_SERVERS.put(sender, serverFrom); + inviteTo(player.getUniqueId(), sender, sender); + sendAcceptOrDeny(player, sender); + } + + public void handleInviteResponse(String sender, String target, UUID targetUUID, InviteResponse response) + { + remove(sender, targetUUID); + Player player = Bukkit.getPlayer(sender); + if(player == null) + { + return; + } + String message = F.main("Party", response.format(target)); + Party party = _plugin.getParty(sender); + + switch (response) + { + case ACCEPTED: + if(party == null) + { + 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()); + break; + case EXPIRED: + case DENIED: + if(party == null) + { + player.sendMessage(message); + player.sendMessage(F.main("Party", "Party not created.")); + return; + } + party.sendMessage(message); + break; + } + } + + /** + * Get the name of the party who is awaiting this player to join + * + * @param player The player's UUID + * @return The name of the awaiting party. + */ + public String getPartyWaiting(UUID player) + { + return _awaitingJoin.get(player); + } + + /** + * Get the name of the person who has invited the target player + * Used mainly for player locating + * + * @param player The player target + * @return The name, if it exists, of the person who has invited the player. + */ + public String getInvitee(Player player) + { + return _invitedBy.get(player.getUniqueId()); + } + + /** + * Add a player to the active invites map + * + * @param player The player who has been invited + * @param party The party name + */ + public void inviteTo(UUID player, String invitedBy, String party) + { + addToInvite(player, invitedBy, party, System.currentTimeMillis()); + new BukkitRunnable() + { + @Override + public void run() + { + if (!isInvitedTo(player, party)) + { + cancel(); + return; + } + remove(party, player); + } + }.runTaskLater(_plugin.getPlugin(), 20 * 60); + } + + /** + * Checks to see if a player is invited to a specific party + * + * @param player The player who we want to check against + * @param party The name of the party to check + * @return true if the player has an invite to the specific party + */ + public boolean isInvitedTo(UUID player, String party) + { + if (!_activeInvites.containsKey(player)) + { + return false; + } + List dataList = _activeInvites.get(player); + for (InviteData data : dataList) + { + if (data.getInvitedTo().equalsIgnoreCase(party)) + { + return true; + } + } + return false; + } + + /** + * Remove a player's invite to a certain party + * + * @param party The name of the party + * @param invited The UUID of the player + */ + public void remove(String party, UUID invited) + { + List data = _activeInvites.get(invited); + InviteData temp = null; + for (InviteData inviteData : data) + { + if (inviteData.getInvitedTo().equalsIgnoreCase(party)) + { + temp = inviteData; + break; + } + } + if (temp != null) + { + data.remove(temp); + } + _activeInvites.put(invited, data); + } + + private void addToPendingJoin(UUID player, String party) + { + _awaitingJoin.put(player, party); + } + + private void addToInvite(UUID invited, String invitedBy, String party, long currentTime) + { + List inviteDatas = _activeInvites.get(invited); + if (inviteDatas == null) + { + inviteDatas = Lists.newArrayList(); + } + InviteData inviteData = new InviteData(invitedBy, party, currentTime + 1000 * 10); + inviteDatas.add(inviteData); + _invitedBy.put(invited, invitedBy); + + _activeInvites.put(invited, inviteDatas); + } + + + private void sendAcceptOrDeny(Player player, String arg) + { + TextComponent textComponent = new TextComponent(F.main("Party", "Click one: ")); + + TextComponent accept = new TextComponent("ACCEPT"); + accept.setColor(ChatColor.GREEN); + accept.setBold(true); + accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party accept " + arg)); + accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ + new TextComponent("Click to run /party accept " + arg) + })); + + textComponent.addExtra(accept); + textComponent.addExtra(" "); + + TextComponent deny = new TextComponent("DENY"); + deny.setColor(ChatColor.RED); + deny.setBold(true); + deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party deny " + arg)); + deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ + new TextComponent("Click to run /party deny " + arg) + })); + + textComponent.addExtra(deny); + + player.spigot().sendMessage(textComponent); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java new file mode 100644 index 000000000..de2bbdc27 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -0,0 +1,101 @@ +package mineplex.core.party.manager; + +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.redis.RedisMessageType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Manages allocating slots for parties to join + */ +public class PartyJoinManager +{ + + public enum JoinResponseReason + { + CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")),; + + private String _message; + + JoinResponseReason(String message) + { + _message = message; + } + + public String getMessage() + { + return _message; + } + } + + private final PartyManager _plugin; + private final int _maxPLayers; + + public PartyJoinManager(PartyManager plugin) + { + _plugin = plugin; + _maxPLayers = plugin.getPlugin().getServer().getMaxPlayers(); + } + + public void requestServerJoin(String server, Party party) + { + boolean canJoinFull = true; + List players = party.getMembers().stream().map(Bukkit::getPlayer).collect(Collectors.toList()); + for (Player player : players) + { + Rank rank = _plugin.getClientManager().Get(player).GetRank(); + if (rank == Rank.ALL) + { + canJoinFull = false; + break; + } + } + _plugin.getRedisManager().publish(server, RedisMessageType.PREJOIN_SERVER_REQUEST, + _plugin.getServerName(), party.getOwner(), "" + party.getMembers().size(), "" + canJoinFull); + } + + public void handleJoinRequest(String serverFrom, int partySize, String initiator, boolean canJoinFull) + { + int currentPlayers = UtilServer.getPlayers().length; + if (currentPlayers >= _maxPLayers) + { + //Max number of people on. + if (!canJoinFull) + { + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, + initiator, "no", JoinResponseReason.CANNOT_JOIN_FULL.name(), _plugin.getServerName()); + return; + } + } + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, "yes", "none"); + } + + public void handleJoinResponse(String playerSender, String response, String server, JoinResponseReason reason) + { + Player player = Bukkit.getPlayer(playerSender); + if (player == null) + { + return; + } + Party party = _plugin.getParty(player); + if (party == null) + { + return; + } + if (response.equalsIgnoreCase("no")) + { + party.sendMessage(reason.getMessage()); + return; + } + party.sendMessage(F.main("Party", "Transferring servers...")); + 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 new file mode 100644 index 000000000..b0cc94b92 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -0,0 +1,98 @@ +package mineplex.core.party.manager; + +import mineplex.core.party.PartyManager; +import mineplex.core.party.manager.PartyInviteManager.InviteResponse; +import mineplex.core.party.manager.PartyJoinManager.JoinResponseReason; +import mineplex.core.party.redis.PartyRedisListener; +import mineplex.core.party.redis.RedisMessageType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +import java.util.UUID; + +/** + * Redis system for Parties + */ +public class PartyRedisManager +{ + protected static final String CHANNEL_BASE = "party-pubsub"; + + private final PartyManager _plugin; + private final PartyInviteManager _inviteManager; + private JedisPool _writePool; + private String _channel; + private String _serverName; + + public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool) + { + _plugin = plugin; + _inviteManager = plugin.getInviteManager(); + _serverName = serverName; + _writePool = writePool; + _channel = CHANNEL_BASE + "-" + serverName; + + plugin.runAsync(() -> { + try (Jedis jedis = readPool.getResource()) + { + jedis.subscribe(new PartyRedisListener(this), _channel); + } + }); + } + + public void publish(String server, RedisMessageType messageType, String... args) + { + _plugin.runAsync(() -> { + try (Jedis jedis = _writePool.getResource()) + { + jedis.publish(CHANNEL_BASE + "-" + server, messageType.format(args)); + } + }); + } + + public void handle(RedisMessageType messageType, String message) + { + String[] contents = message.split("-"); + if(contents.length < 3) + { + return; + } + String first = contents[0]; + String second = contents[1]; + String third = contents[2]; + switch (messageType) + { + case INVITE_PLAYER_REQUEST: + _inviteManager.handleInviteRequest(second, third, first); + break; + case INVITE_PLAYER_RESPONSE: + _inviteManager.handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase())); + break; + + case PLAYER_FIND_REQUEST: + Player player = Bukkit.getPlayer(second); + if(player == null) + { + return; + } + publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, + _serverName, player.getName(), player.getUniqueId().toString(), second); + break; + case PLAYER_FIND_RESPONSE: + UUID uuid = UUID.fromString(third); + _inviteManager.invite(contents[3], uuid); + publish(first, RedisMessageType.INVITE_PLAYER_REQUEST, _serverName, contents[3], second); + break; + + case PREJOIN_SERVER_REQUEST: + _plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3])); + break; + case PREJOIN_SERVER_RESPONSE: + _plugin.getJoinManager().handleJoinResponse(first, second, contents[3], JoinResponseReason.valueOf(third.toUpperCase())); + break; + } + } + + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/LocateType.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/LocateType.java deleted file mode 100644 index ac006ffd2..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/LocateType.java +++ /dev/null @@ -1,15 +0,0 @@ -package mineplex.core.party.redis; - -/** - * Simplifies the location callback method - */ -public enum LocateType -{ - - LORE, - INVITE_INIT, - INVITE_RESPONSE, - KICK, - TRANSFER, - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java new file mode 100644 index 000000000..6941a03cb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -0,0 +1,25 @@ +package mineplex.core.party.redis; + +import mineplex.core.party.manager.PartyRedisManager; +import redis.clients.jedis.JedisPubSub; + +/** + * Handles incoming messages into the Party Redis System + */ +public class PartyRedisListener extends JedisPubSub +{ + + private PartyRedisManager _redisManager; + + public PartyRedisListener(PartyRedisManager redisManager) + { + _redisManager = redisManager; + } + + @Override + public void onMessage(String channel, String 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 new file mode 100644 index 000000000..3ca54cbc2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -0,0 +1,69 @@ +package mineplex.core.party.redis; + +/** + * Messages sent within the redis messaging system + * And their corresponding arguments + */ +public enum RedisMessageType +{ + + //Message: SERVER_FROM-PLAYER_TARGET-PLAYER_SENDER + PLAYER_FIND_REQUEST(1, "{0}-{1}-{2}"), + //Message: SERVER_ON-PLAYER_TARGET_NAME-PLAYER_TARGET_UUID-PLAYER_SENDER + PLAYER_FIND_RESPONSE(2, "{0}-{1}-{2}-{3}"), + + //Message: SERVER_FROM-PLAYER_SENDER-PLAYER_TARGET + INVITE_PLAYER_REQUEST(3, "{0}-{1}-{2}"), + //Message: PLAYER_SENDER-PLAYER_TARGET_NAME-PLAYER_TARGET_UUID-RESPONSE + INVITE_PLAYER_RESPONSE(4, "{0}-{1}-{2}-{3}"), + + //Message: SERVER_FROM-PLAYER_INITIATING-PARTY_SIZE-_CAN_JOIN_FULL + PREJOIN_SERVER_REQUEST(5, "{0}-{1}-{2}-{3}"), + //Message: PLAYER_INITIATING-RESPONSE-REASON-SERVER + PREJOIN_SERVER_RESPONSE(6, "{0}-{1}-{2}-[3}") + ; + + private int _id; + private String _contents; + + RedisMessageType(int id, String contents) + { + _id = id; + _contents = contents; + } + + public int getId() + { + return _id; + } + + public String format(String... args) + { + return String.format(_contents, args); + } + + public String getContents() + { + return _contents; + } + + public RedisMessageType getResponse(int id) + { + switch (id) { + case 1: + return PLAYER_FIND_RESPONSE; + case 3: + return INVITE_PLAYER_RESPONSE; + case 5: + return PREJOIN_SERVER_RESPONSE; + default: + return null; + } + } + + public RedisMessageType getResponse(RedisMessageType type) + { + return getResponse(type.getId()); + } + +} 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 ca8b0ef75..855055917 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 @@ -4,9 +4,7 @@ import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.party.PartyManager; -import mineplex.core.party.redis.LocateType; import mineplex.core.party.ui.Button; -import mineplex.core.party.ui.Menu; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -23,47 +21,33 @@ public class PartyMemberIcon extends Button private ItemStack _itemStack; private String _target; - public PartyMemberIcon(Player viewer, String player, PartyManager plugin) + public PartyMemberIcon(String player, PartyManager plugin) { super(null, plugin); _target = player; - plugin.locatePlayer(player, string -> { + String[] lore = { - String[] lore = { - "", - C.cWhite + "Server: " + C.cGreen + string, - "", - C.cGreen + "Click to summon to your server." - }; + }; - ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3); - builder.setTitle(C.cYellow + player); - builder.setLore(lore); - builder.setPlayerHead(player); + ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3); + builder.setTitle(C.cYellow + player); + builder.setLore(lore); + builder.setPlayerHead(player); - _itemStack = builder.build(); + _itemStack = builder.build(); - Menu.get(viewer.getUniqueId()).update(viewer); - - }, LocateType.LORE); } @Override public void onClick(Player player) { - getPlugin().summon(player, _target); } @Override public ItemStack getItemStack() { - if(_itemStack == null) - { - return DEFAULT; - } - return _itemStack; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java new file mode 100644 index 000000000..28a4ce5b7 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools; + +/** + * + */ +public class AddPlayerButton +{ +} 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 208cec155..62fdd7a15 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 @@ -19,6 +19,8 @@ public class PartyMainMenu extends Menu @Override protected Button[] setUp(Player player) { - return new Button[0]; + Button[] buttons = new Button[9]; + + 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 80625184d..4e09cb6de 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 @@ -39,7 +39,7 @@ public class PartyOwnerMenu extends Menu //Players for(int i = 18; i < 33; i++) { - buttons[i] = new PartyMemberIcon(player, player.getName(), _plugin); + buttons[i] = new PartyMemberIcon(player.getName(), _plugin); } return buttons; From c577e5827cd2d1f7ca12f3735ca7717a0f4b30c5 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sun, 5 Jun 2016 22:55:06 -0500 Subject: [PATCH 10/53] Heavy UI and Command progress. Time: 4hrs --- .../core/party/command/PartyCommand.java | 102 +++++++++- .../party/manager/PartyInviteManager.java | 54 +++++- .../core/party/manager/PartyRedisManager.java | 53 +++++- .../src/mineplex/core/party/ui/Button.java | 3 +- .../core/party/ui/button/IconButton.java | 3 +- .../core/party/ui/button/PartyMemberIcon.java | 3 +- .../ui/button/tools/AddPlayerButton.java | 28 ++- .../ui/button/tools/LeavePartyButton.java | 34 ++++ .../party/ui/button/tools/PartyButton.java | 26 +++ .../core/party/ui/menus/InvitePlayerMenu.java | 178 ++++++++++++++++++ .../core/party/ui/menus/PartyOwnerMenu.java | 9 +- .../core/party/ui/menus/PartyViewMenu.java | 40 ++++ 12 files changed, 509 insertions(+), 24 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/InvitePlayerMenu.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java 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 0d5b4afdd..6967014a9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -3,11 +3,18 @@ package mineplex.core.party.command; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.core.party.manager.PartyInviteManager; +import mineplex.core.party.ui.menus.PartyMainMenu; import mineplex.core.party.ui.menus.PartyOwnerMenu; +import mineplex.core.party.ui.menus.PartyViewMenu; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.UUID; + /** * Command handler for party commands */ @@ -37,7 +44,18 @@ public class PartyCommand extends CommandBase { if (args.length == 0) { - new PartyOwnerMenu(new Party(caller.getName()), Plugin).open(caller); + Party party = Plugin.getParty(caller); + if(party == null) + { + new PartyMainMenu(Plugin).open(caller); + return; + } + if(party.getOwner().equalsIgnoreCase(caller.getName())) + { + new PartyOwnerMenu(party, Plugin).open(caller); + return; + } + new PartyViewMenu(party, Plugin).open(caller); //Show UI return; } @@ -89,27 +107,107 @@ public class PartyCommand extends CommandBase private void handleInvite(Player caller, String target) { - + Player possible = Bukkit.getPlayer(target); + if(possible != null) + { + UUID uuid = possible.getUniqueId(); + caller.sendMessage(F.main("Party", "Sent an invite to " + target + "...")); + Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName()); + Plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName()); + return; + } + Plugin.getRedisManager().findAndInvite(target, caller.getName()); } private void handleInviteResponse(Player caller, String target, boolean accept) { + PartyInviteManager inviteManager = Plugin.getInviteManager(); + 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))); + return; + } + + inviteManager.respondToInvite(caller, target, accept); } private void handleForceRemove(Player caller, String target) { + Party party = Plugin.getParty(caller); + if(party == null) { + caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); + return; + } + + if(!party.getOwner().equalsIgnoreCase(caller.getName())) + { + caller.sendMessage(F.main("Party", "You must be the leader of the party to do that!")); + return; + } + + Player playerTarget = Bukkit.getPlayer(target); + + if(playerTarget == null) + { + caller.sendMessage(F.main("Party", target + " is not online, and is not in your party!")); + return; + } + + Party targetParty = Plugin.getParty(playerTarget); + + if(targetParty == null || party.getMembers().contains(target)) + { + caller.sendMessage(F.main("Party", target + " is not a member of your party.")); + return; + } + + Plugin.removeFromParty(playerTarget.getUniqueId()); + party.getMembers().remove(target); + + 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.")); } private void handleLeave(Player caller) { + Party party = Plugin.getParty(caller); + if(party == null) { + caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); + 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.")); } private void handleDisband(Player caller) { + Party party = Plugin.getParty(caller); + if(party == null) { + caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); + return; + } + + if(!party.getOwner().equalsIgnoreCase(caller.getName())) + { + caller.sendMessage(F.main("Party", "You must be the leader of the party to do that!")); + 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); } } 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 466a2c453..8d661a9a3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -6,6 +6,7 @@ import mineplex.core.common.util.F; import mineplex.core.party.InviteData; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.core.party.redis.RedisMessageType; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent.Action; @@ -25,7 +26,8 @@ import java.util.UUID; public class PartyInviteManager { - public enum InviteResponse { + public enum InviteResponse + { ACCEPTED("{0} has joined the party!"), DENIED("{0} has declined joining your party."), @@ -49,6 +51,7 @@ public class PartyInviteManager private final Map> _activeInvites = Maps.newHashMap(); private final Map _invitedBy = Maps.newHashMap(); private final Map _awaitingJoin = Maps.newHashMap(); + private final Map _players = Maps.newHashMap(); private final PartyManager _plugin; private final PartyRedisManager _partyRedisManager; @@ -59,9 +62,16 @@ public class PartyInviteManager _partyRedisManager = partyRedisManager; } - public void invite(String sender, UUID targetUUID) + public void respondToInvite(Player player, String party, boolean accept) { - addToInvite(targetUUID, sender, sender, System.currentTimeMillis()); + remove(party, player.getUniqueId()); + + _players.remove(player.getUniqueId()); + + String serverFrom = INVITE_FROM_SERVERS.remove(player.getName()); + + _partyRedisManager.publish(serverFrom, RedisMessageType.INVITE_PLAYER_RESPONSE, party, + player.getName(), player.getUniqueId().toString(), accept ? InviteResponse.ACCEPTED.name() : InviteResponse.DENIED.name()); } public void handleInviteRequest(String sender, String target, String serverFrom) @@ -72,7 +82,8 @@ public class PartyInviteManager //Shouldn't happen, as a "findPLayer" packet will be sent out first. return; } - INVITE_FROM_SERVERS.put(sender, serverFrom); + _players.put(player.getUniqueId(), player.getName()); + INVITE_FROM_SERVERS.put(target, serverFrom); inviteTo(player.getUniqueId(), sender, sender); sendAcceptOrDeny(player, sender); } @@ -81,7 +92,7 @@ public class PartyInviteManager { remove(sender, targetUUID); Player player = Bukkit.getPlayer(sender); - if(player == null) + if (player == null) { return; } @@ -91,7 +102,7 @@ public class PartyInviteManager switch (response) { case ACCEPTED: - if(party == null) + if (party == null) { party = new Party(sender); _plugin.addParty(party); @@ -103,7 +114,7 @@ public class PartyInviteManager break; case EXPIRED: case DENIED: - if(party == null) + if (party == null) { player.sendMessage(message); player.sendMessage(F.main("Party", "Party not created.")); @@ -114,6 +125,17 @@ public class PartyInviteManager } } + /** + * Get the name of the server that this request was initiated from. + * + * @param player The player + * @return The server name + */ + public String getServerInvitedFrom(Player player) + { + return INVITE_FROM_SERVERS.get(player.getName()); + } + /** * Get the name of the party who is awaiting this player to join * @@ -157,6 +179,14 @@ public class PartyInviteManager return; } remove(party, player); + Player possible = Bukkit.getPlayer(player); + String playerName = _players.remove(player); + if (possible != null) + { + playerName = possible.getName(); + possible.sendMessage(F.main("Party", "Your invite to " + party + " has expired")); + } + sendExpired(INVITE_FROM_SERVERS.remove(invitedBy), party, playerName, player); } }.runTaskLater(_plugin.getPlugin(), 20 * 60); } @@ -188,7 +218,7 @@ public class PartyInviteManager /** * Remove a player's invite to a certain party * - * @param party The name of the party + * @param party The name of the party * @param invited The UUID of the player */ public void remove(String party, UUID invited) @@ -210,6 +240,11 @@ public class PartyInviteManager _activeInvites.put(invited, data); } + private void sendExpired(String server, String party, String playerName, UUID player) + { + _plugin.getRedisManager().publish(server, RedisMessageType.INVITE_PLAYER_RESPONSE, party, playerName, player.toString(), InviteResponse.EXPIRED.name()); + } + private void addToPendingJoin(UUID player, String party) { _awaitingJoin.put(player, party); @@ -229,8 +264,7 @@ public class PartyInviteManager _activeInvites.put(invited, inviteDatas); } - - private void sendAcceptOrDeny(Player player, String arg) + public void sendAcceptOrDeny(Player player, String arg) { TextComponent textComponent = new TextComponent(F.main("Party", "Click one: ")); 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 b0cc94b92..6ce50db58 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -1,5 +1,7 @@ package mineplex.core.party.manager; +import com.google.common.collect.Maps; +import mineplex.core.common.util.F; import mineplex.core.party.PartyManager; import mineplex.core.party.manager.PartyInviteManager.InviteResponse; import mineplex.core.party.manager.PartyJoinManager.JoinResponseReason; @@ -7,9 +9,12 @@ import mineplex.core.party.redis.PartyRedisListener; import mineplex.core.party.redis.RedisMessageType; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; +import java.util.Map; import java.util.UUID; /** @@ -18,12 +23,14 @@ import java.util.UUID; public class PartyRedisManager { protected static final String CHANNEL_BASE = "party-pubsub"; + protected static final String FIND_PLAYERS_CHANNEL = "party-player-finder"; + private final Map TASKS = Maps.newHashMap(); private final PartyManager _plugin; private final PartyInviteManager _inviteManager; - private JedisPool _writePool; - private String _channel; - private String _serverName; + private final JedisPool _writePool; + private final String _channel; + private final String _serverName; public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool) { @@ -37,6 +44,7 @@ public class PartyRedisManager try (Jedis jedis = readPool.getResource()) { jedis.subscribe(new PartyRedisListener(this), _channel); + jedis.subscribe(new PartyRedisListener(this), FIND_PLAYERS_CHANNEL); } }); } @@ -66,33 +74,70 @@ public class PartyRedisManager case INVITE_PLAYER_REQUEST: _inviteManager.handleInviteRequest(second, third, first); break; + case INVITE_PLAYER_RESPONSE: _inviteManager.handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase())); break; case PLAYER_FIND_REQUEST: Player player = Bukkit.getPlayer(second); + if(player == null) { return; } + publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), second); break; + case PLAYER_FIND_RESPONSE: UUID uuid = UUID.fromString(third); - _inviteManager.invite(contents[3], uuid); + BukkitTask task = TASKS.remove(second); + + if(task != null) + { + task.cancel(); + } + + _inviteManager.inviteTo(uuid, contents[3], contents[3]); publish(first, RedisMessageType.INVITE_PLAYER_REQUEST, _serverName, contents[3], second); break; case PREJOIN_SERVER_REQUEST: _plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3])); break; + case PREJOIN_SERVER_RESPONSE: _plugin.getJoinManager().handleJoinResponse(first, second, contents[3], JoinResponseReason.valueOf(third.toUpperCase())); break; } } + public void findAndInvite(String player, String sender) + { + TASKS.put(player, new BukkitRunnable() + { + @Override + public void run() + { + Player senderPlayer = Bukkit.getPlayer(sender); + if(senderPlayer == null) + { + return; + } + senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player))); + TASKS.remove(player); + } + }.runTaskLater(_plugin.getPlugin(), 20L * 4)); + + _plugin.runAsync(() -> { + try (Jedis jedis = _writePool.getResource()) + { + jedis.publish(FIND_PLAYERS_CHANNEL, RedisMessageType.PLAYER_FIND_REQUEST.format(_serverName, player, sender)); + } + }); + } + } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java index f4e8eb954..fe5d4468d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java @@ -2,6 +2,7 @@ package mineplex.core.party.ui; import mineplex.core.party.PartyManager; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** @@ -24,7 +25,7 @@ public abstract class Button * * @param player The player who clicked */ - public abstract void onClick(Player player); + public abstract void onClick(Player player, ClickType clickType); public ItemStack getItemStack() { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java index ccbf61506..0e80c09cd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java @@ -3,6 +3,7 @@ package mineplex.core.party.ui.button; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** @@ -18,7 +19,7 @@ public class IconButton extends Button } @Override - public void onClick(Player player) + public void onClick(Player player, ClickType clickType) { } 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 855055917..f01c58870 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 @@ -8,6 +8,7 @@ import mineplex.core.party.ui.Button; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** @@ -41,7 +42,7 @@ public class PartyMemberIcon extends Button } @Override - public void onClick(Player player) + public void onClick(Player player, ClickType clickType) { } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java index 28a4ce5b7..e525f6777 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java @@ -1,8 +1,34 @@ package mineplex.core.party.ui.button.tools; +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.menus.InvitePlayerMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class AddPlayerButton +public class AddPlayerButton extends PartyButton { + + private static final ItemStack ITEM = new ItemBuilder(Material.SIGN) + .setTitle(C.cYellow + "Invite a Player") + .build(); + + public AddPlayerButton(PartyManager plugin, Party party) + { + super(ITEM, party, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new InvitePlayerMenu(getPlugin(), player, getParty()).openInventory(); + } + } 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 new file mode 100644 index 000000000..bcabd4bcf --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java @@ -0,0 +1,34 @@ +package mineplex.core.party.ui.button.tools; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * + */ +public class LeavePartyButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.STAINED_GLASS_PANE) + .setData((byte) 14) + .setTitle(C.cYellow + "Invite a Player") + .build(); + + public LeavePartyButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + player.performCommand("/party leave"); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java new file mode 100644 index 000000000..6625979fb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java @@ -0,0 +1,26 @@ +package mineplex.core.party.ui.button.tools; + +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.inventory.ItemStack; + +/** + * + */ +public abstract class PartyButton extends Button +{ + + private Party _party; + + public PartyButton(ItemStack itemStack, Party party, PartyManager plugin) + { + super(itemStack, plugin); + _party = party; + } + + public Party getParty() + { + return _party; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/InvitePlayerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/InvitePlayerMenu.java new file mode 100644 index 000000000..631abc475 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/InvitePlayerMenu.java @@ -0,0 +1,178 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import net.minecraft.server.v1_8_R3.*; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; + +/** + * + */ +public class InvitePlayerMenu implements Listener +{ + + private PartyManager _partyManager; + private Player _player; + private Inventory _currentInventory; + private String _itemName = ""; + private boolean _searching; + private Party _party; + + public InvitePlayerMenu(PartyManager partyManager, Player player, Party party) + { + _player = player; + _partyManager = partyManager; + _party = party; + + openInventory(); + _partyManager.registerEvents(this); + } + + @EventHandler + public void onInventoryClose(InventoryCloseEvent event) + { + if (event.getPlayer() == _player) + { + unregisterListener(); + } + } + + public void unregisterListener() + { + _currentInventory.clear(); + HandlerList.unregisterAll(this); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + if (event.getPlayer() == _player) + { + unregisterListener(); + } + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) + { + if (event.getRawSlot() < 3) + { + event.setCancelled(true); + + if (event.getRawSlot() == 2) + { + if (_itemName.length() > 1 && !_searching) + { + final String name = _itemName; + + _partyManager.getClientManager().checkPlayerName(_player, _itemName, result -> { + _searching = false; + + if (result != null) + { + _partyManager.getRedisManager().findAndInvite(name, _player.getName()); + _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); + + unregisterListener(); + _player.closeInventory(); + new PartyOwnerMenu(_party, _partyManager).open(_player); + } else + { + _currentInventory.setItem(2, new ItemBuilder(Material.PAPER) + .setTitle(C.cYellow + "0" + C.cGray + " matches for [" + C.cYellow + name + C.cGray + "]") + .build()); + _player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + } + }); + } else + { + _player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + } + } + } else if (event.isShiftClick()) + { + event.setCancelled(true); + } + } + + public void openInventory() + { + _player.closeInventory(); + + EntityPlayer p = ((CraftPlayer) _player).getHandle(); + + AnvilContainer container = new AnvilContainer(p); + int c = p.nextContainerCounter(); + + PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage(Blocks.ANVIL.a() + ".name", new Object[0])); + + UtilPlayer.sendPacket(_player, packet); + + // Set their active container to the container + p.activeContainer = container; + + // Set their active container window id to that counter stuff + p.activeContainer.windowId = c; + + // Add the slot listener + p.activeContainer.addSlotListener(p); // Set the items to the items from the inventory given + _currentInventory = container.getBukkitView().getTopInventory(); + + _currentInventory.setItem(0, new ItemBuilder(Material.PAPER).setRawTitle("Players's Name").build()); + _currentInventory.setItem(2, new ItemBuilder(Material.PAPER).setRawTitle("Search").build()); + } + + private class AnvilContainer extends ContainerAnvil + { + private String n; + + public AnvilContainer(EntityHuman entity) + { + super(entity.inventory, entity.world, new BlockPosition(0, 0, 0), entity); + } + + @Override + public boolean a(EntityHuman entityhuman) + { + return true; + } + + @Override + public void a(String origString) + { + n = origString; + _itemName = origString; + + if (getSlot(2).hasItem()) + { + net.minecraft.server.v1_8_R3.ItemStack itemstack = getSlot(2).getItem(); + + if (StringUtils.isBlank(origString)) + { + itemstack.r(); + } else + { + itemstack.c(this.n); + } + } + + e(); + } + + } + +} 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 4e09cb6de..cd818b98b 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,6 +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.AddPlayerButton; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -19,7 +20,7 @@ public class PartyOwnerMenu extends Menu public PartyOwnerMenu(Party party, PartyManager plugin) { - super(party.getOwner() + "'s Party", plugin); + super("Manage Party", plugin); _party = party; } @@ -29,7 +30,7 @@ public class PartyOwnerMenu extends Menu Button[] buttons = new Button[54]; //Tools - buttons[1] = create(new ItemStack(Material.SIGN)); + buttons[1] = new AddPlayerButton(_plugin, _party); buttons[4] = create(new ItemStack(Material.IRON_AXE)); buttons[7] = create(new ItemStack(Material.BARRIER)); buttons[46] = create(new ItemStack(Material.COMPASS)); @@ -37,9 +38,9 @@ public class PartyOwnerMenu extends Menu buttons[52] = create(new ItemStack(Material.BOOK_AND_QUILL)); //Players - for(int i = 18; i < 33; i++) + for(int i = 18; i < _party.getMembers().size(); i++) { - buttons[i] = new PartyMemberIcon(player.getName(), _plugin); + buttons[i] = new PartyMemberIcon(_party.getMembers().get(i), _plugin); } return 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 new file mode 100644 index 000000000..c13b68e5b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java @@ -0,0 +1,40 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.party.Party; +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.LeavePartyButton; +import org.bukkit.entity.Player; + +/** + * + */ +public class PartyViewMenu extends Menu +{ + + private Party _party; + + public PartyViewMenu(Party party, PartyManager plugin) + { + super(party.getName() + "'s Party", plugin); + _party = party; + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[54]; + //Tools + buttons[4] = new LeavePartyButton(_plugin); + + //Players + for(int i = 18; i < _party.getMembers().size(); i++) + { + buttons[i] = new PartyMemberIcon(_party.getMembers().get(i), _plugin); + } + + return buttons; + } +} From 474a9dc975663226d525ebe75d76b5e0145836d7 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sun, 5 Jun 2016 23:37:08 -0500 Subject: [PATCH 11/53] Heavy UI and Command work. Begin testing Time: 2hrs --- .../core/party/command/PartyCommand.java | 2 +- .../party/manager/PartyInviteManager.java | 32 +++++++++++++++++++ .../core/party/manager/PartyRedisManager.java | 2 +- .../core/party/redis/PartyRedisListener.java | 1 + .../mineplex/core/party/ui/MenuListener.java | 2 +- .../ui/button/tools/LeavePartyButton.java | 5 ++- .../core/party/ui/menus/PartyViewMenu.java | 4 +-- .../src/mineplex/hub/HubManager.java | 15 ++------- 8 files changed, 43 insertions(+), 20 deletions(-) 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 6967014a9..086ab5b0b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -111,7 +111,7 @@ public class PartyCommand extends CommandBase if(possible != null) { UUID uuid = possible.getUniqueId(); - caller.sendMessage(F.main("Party", "Sent an invite to " + target + "...")); + caller.sendMessage(F.main("Party", "Sent an invite to " + possible.getName() + "...")); Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName()); Plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName()); return; 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 8d661a9a3..16813ec79 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -64,10 +64,40 @@ public class PartyInviteManager public void respondToInvite(Player player, String party, boolean accept) { + Player possible = Bukkit.getPlayer(party); + remove(party, player.getUniqueId()); _players.remove(player.getUniqueId()); + if(possible != null) + { + Party newParty = _plugin.getParty(party); + if(!accept) + { + String message = InviteResponse.DENIED.format(player.getName()); + if (newParty == null) + { + player.sendMessage(message); + player.sendMessage(F.main("Party", "Party not created.")); + return; + } + newParty.sendMessage(message); + return; + } + if (newParty == null) + { + 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; + } + String serverFrom = INVITE_FROM_SERVERS.remove(player.getName()); _partyRedisManager.publish(serverFrom, RedisMessageType.INVITE_PLAYER_RESPONSE, party, @@ -97,6 +127,7 @@ public class PartyInviteManager return; } String message = F.main("Party", response.format(target)); + Party party = _plugin.getParty(sender); switch (response) @@ -266,6 +297,7 @@ 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/PartyRedisManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java index 6ce50db58..04114fcb6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -54,7 +54,7 @@ public class PartyRedisManager _plugin.runAsync(() -> { try (Jedis jedis = _writePool.getResource()) { - jedis.publish(CHANNEL_BASE + "-" + server, messageType.format(args)); + jedis.publish(CHANNEL_BASE + "-" + server, messageType.name() + ":" + messageType.format(args)); } }); } 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 6941a03cb..c84b797ab 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -19,6 +19,7 @@ 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/ui/MenuListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java index 8914d2b4f..2ab4197d2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java @@ -39,7 +39,7 @@ public class MenuListener implements Listener return; } - button.onClick(player); + button.onClick(player, event.getClick()); } } 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 bcabd4bcf..c3ef5d12d 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 @@ -15,9 +15,8 @@ import org.bukkit.inventory.ItemStack; public class LeavePartyButton extends Button { - private static final ItemStack ITEM = new ItemBuilder(Material.STAINED_GLASS_PANE) - .setData((byte) 14) - .setTitle(C.cYellow + "Invite a Player") + private static final ItemStack ITEM = new ItemBuilder(Material.BARRIER) + .setTitle(C.cYellow + "Leave Party") .build(); public LeavePartyButton(PartyManager plugin) 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 c13b68e5b..654598c61 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 @@ -30,9 +30,9 @@ public class PartyViewMenu extends Menu buttons[4] = new LeavePartyButton(_plugin); //Players - for(int i = 18; i < _party.getMembers().size(); i++) + for(int i = 0; i < _party.getMembers().size(); i++) { - buttons[i] = new PartyMemberIcon(_party.getMembers().get(i), _plugin); + buttons[i + 18] = new PartyMemberIcon(_party.getMembers().get(i), _plugin); } return buttons; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 9ec78c1be..05f43a5d9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -577,11 +577,10 @@ public class HubManager extends MiniClientPlugin //Rank Prefix String rankStr = ""; if (rank != Rank.ALL) - rankStr = rank.getTag(true, true) + " "; - //Party Chat - - else { + rankStr = rank.getTag(true, true) + " "; + } + TextComponent rankComponent = new TextComponent(rankStr); TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + playerName); TextComponent component = new TextComponent(); @@ -592,11 +591,6 @@ public class HubManager extends MiniClientPlugin component.addExtra(rankComponent); component.addExtra(playerNameText); component.addExtra(" " + ChatColor.WHITE + event.getMessage()); - -// JsonMessage jsonMessage = new JsonMessage(levelStr) -// .extra(JSONObject.escape(rankStr)).hover("show_text", rank.getColor() + rank.getTag(true, true) + ChatColor.WHITE + "\n" + rank.getDescription()) -// .add(JSONObject.escape(C.cYellow + playerName + " " + ChatColor.WHITE + event.getMessage())); - for (Player other : UtilServer.getPlayers()) { if (_tutorialManager.InTutorial(other)) @@ -605,13 +599,10 @@ public class HubManager extends MiniClientPlugin continue; } - // event.setMessage(event.getMessage()); - // event.setFormat(levelStr + rankStr + C.cYellow + playerName + " " + C.cWhite + "%2$s"); if(!event.isCancelled()) other.spigot().sendMessage(component); } event.setCancelled(true); - } } @EventHandler From b75e87753dc178d2ea417671348079a2d575a6b8 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Mon, 20 Jun 2016 22:45:53 -0500 Subject: [PATCH 12/53] Party UI work. --- .../src/mineplex/core/party/PartyManager.java | 2 + .../core/party/command/PartyCommand.java | 26 ++++++----- .../party/manager/PartyInviteManager.java | 3 +- .../core/party/manager/PartyRedisManager.java | 4 +- .../core/party/ui/button/PartyMemberIcon.java | 38 ++++------------ .../ui/button/tools/LeavePartyButton.java | 6 +-- .../ui/button/tools/invite/BackButton.java | 8 ++++ .../ui/button/tools/invite/DenyAllButton.java | 8 ++++ .../ui/button/tools/invite/Filterbutton.java | 8 ++++ .../ui/button/tools/invite/InviteButton.java | 8 ++++ .../button/tools/invite/NextPageButton.java | 8 ++++ .../button/tools/invite/PrevPageButton.java | 8 ++++ .../button/tools/main/InvitePlayerButton.java | 8 ++++ .../button/tools/main/ViewInvitesButton.java | 8 ++++ .../tools/{ => owner}/AddPlayerButton.java | 8 ++-- .../tools/owner/DisbandPartyButton.java | 8 ++++ .../button/tools/owner/KickPlayerButton.java | 8 ++++ .../tools/owner/SelectServerButton.java | 8 ++++ .../tools/owner/TransferOwnerButton.java | 8 ++++ .../tools/view/SuggestPlayerButton.java | 35 +++++++++++++++ .../core/party/ui/menus/PartyInvitesMenu.java | 24 +++++++++++ .../core/party/ui/menus/PartyOwnerMenu.java | 23 +++++++--- .../core/party/ui/menus/PartyViewMenu.java | 14 ++++-- ...yerMenu.java => PlayerNameActionMenu.java} | 29 +++++++------ .../ui/menus/input/PartyInvitePlayerMenu.java | 35 +++++++++++++++ .../menus/input/PlayerSuggestPlayerMenu.java | 43 +++++++++++++++++++ 26 files changed, 313 insertions(+), 73 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java rename Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/{ => owner}/AddPlayerButton.java (68%) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java rename Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/{InvitePlayerMenu.java => PlayerNameActionMenu.java} (87%) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index 6ff8d01bc..77d010ea4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -7,6 +7,7 @@ import mineplex.core.party.command.PartyCommand; import mineplex.core.party.manager.PartyInviteManager; import mineplex.core.party.manager.PartyJoinManager; import mineplex.core.party.manager.PartyRedisManager; +import mineplex.core.party.ui.MenuListener; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.serverdata.Utility; @@ -45,6 +46,7 @@ public class PartyManager extends MiniPlugin _inviteManager = new PartyInviteManager(this, _redisManager); _joinManager = new PartyJoinManager(this); addCommand(new PartyCommand(this)); + getPluginManager().registerEvents(new MenuListener(), getPlugin()); } 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 086ab5b0b..ea99269d5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -22,16 +22,16 @@ public class PartyCommand extends CommandBase { private final String[] HELP = { - C.cDGreenB + C.Strike + "================================", - C.cGray + "/party help - Shows this help screen.", - C.cGray + "/party - Brings up the Party GUI.", - C.cGray + "/party invite - Invite a player to your party." + C.cRed + " Must be the owner.", - C.cGray + "/party accept - Accept an invite to a player's party.", - C.cGray + "/party deny - Deny an invite to a player's party.", - C.cGray + "/party leave - Leave your current party.", - C.cGray + "/party kick/remove - Remove a player from your party." + C.cRed + " Must be the owner.", - C.cGray + "/party disband - Disband your party." + C.cRed + " Must be the owner.", - C.cDGreenB + C.Strike + "================================", + F.main("Party", "Party Commands"), + help("help", "Shows this help screen"), + help("", "Brings up the Party GUI"), + help("invite ", "Invite a player to your party." + C.cRed + " Must be the leader."), + help("accept ", "Accept an invite to a player's party."), + help("deny ", "Deny an invite to a player's party."), + help("leave", "Leave your current party"), + help("kick/remove ", "Remove a player from your party. " + C.cRed + "Must be the leader."), + help("disband", "Disband your party. " + C.cRed + "Must be the leader."), + C.cBlue + "Party> " + C.cWhite + "# " + C.cGray + "- Send a message to the players in your party." }; public PartyCommand(PartyManager plugin) @@ -56,7 +56,6 @@ public class PartyCommand extends CommandBase return; } new PartyViewMenu(party, Plugin).open(caller); - //Show UI return; } String argument = args[0]; @@ -210,5 +209,10 @@ public class PartyCommand extends CommandBase Plugin.removeParty(party); } + private String help(String command, String description) + { + return C.cBlue + "Party> " + C.cWhite + "/party " + command + C.cGray + " - " + description; + } + } 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 16813ec79..82150b8a0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -64,7 +64,7 @@ public class PartyInviteManager public void respondToInvite(Player player, String party, boolean accept) { - Player possible = Bukkit.getPlayer(party); + Player possible = Bukkit.getPlayerExact(party); remove(party, player.getUniqueId()); @@ -79,7 +79,6 @@ public class PartyInviteManager if (newParty == null) { player.sendMessage(message); - player.sendMessage(F.main("Party", "Party not created.")); return; } newParty.sendMessage(message); 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 04114fcb6..9a345660c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -121,13 +121,13 @@ public class PartyRedisManager @Override public void run() { - Player senderPlayer = Bukkit.getPlayer(sender); + TASKS.remove(player); + Player senderPlayer = Bukkit.getPlayerExact(sender); if(senderPlayer == null) { return; } senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player))); - TASKS.remove(player); } }.runTaskLater(_plugin.getPlugin(), 20L * 4)); 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 f01c58870..27dd7ac34 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 @@ -14,41 +14,21 @@ import org.bukkit.inventory.ItemStack; /** * The button representing a Party member. */ -public class PartyMemberIcon extends Button +public class PartyMemberIcon extends IconButton { - private final ItemStack DEFAULT = ItemStackFactory.Instance.CreateStack(Material.INK_SACK, DyeColor.GRAY.getDyeData(), 1, "Locating..."); - - private ItemStack _itemStack; - private String _target; - - public PartyMemberIcon(String player, PartyManager plugin) + public PartyMemberIcon(String player, boolean owner) { - super(null, plugin); - - _target = player; - - String[] lore = { - - }; - - ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3); - builder.setTitle(C.cYellow + player); - builder.setLore(lore); - builder.setPlayerHead(player); - - _itemStack = builder.build(); - + super(new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3) + .setTitle(C.cYellow + player) + .setGlow(owner) + .setPlayerHead(player).build(), null); } - @Override - public void onClick(Player player, ClickType clickType) + public PartyMemberIcon(String player) { + this(player, false); } - @Override - public ItemStack getItemStack() - { - return _itemStack; - } + } 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 c3ef5d12d..2bfa1353f 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 @@ -15,13 +15,13 @@ import org.bukkit.inventory.ItemStack; public class LeavePartyButton extends Button { - private static final ItemStack ITEM = new ItemBuilder(Material.BARRIER) + private static final ItemStack ITEM = new ItemBuilder(Material.REDSTONE_BLOCK) .setTitle(C.cYellow + "Leave Party") .build(); - public LeavePartyButton(PartyManager plugin) + public LeavePartyButton() { - super(ITEM, plugin); + super(ITEM, null); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java new file mode 100644 index 000000000..fadaa503e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.invite; + +/** + * + */ +public class BackButton +{ +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java new file mode 100644 index 000000000..b725893d8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.invite; + +/** + * + */ +public class DenyAllButton +{ +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java new file mode 100644 index 000000000..48ae67294 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.invite; + +/** + * + */ +public class FilterButton +{ +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java new file mode 100644 index 000000000..e80a8433d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.invite; + +/** + * + */ +public class InviteButton +{ +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java new file mode 100644 index 000000000..b857b5163 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.invite; + +/** + * + */ +public class NextPageButton +{ +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java new file mode 100644 index 000000000..05e5a0b4a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.invite; + +/** + * + */ +public class PrevPageButton +{ +} 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 new file mode 100644 index 000000000..48068ea98 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.main; + +/** + * + */ +public class InvitePlayerButton +{ +} 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 new file mode 100644 index 000000000..b5dfbbd74 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.main; + +/** + * + */ +public class ViewInvitesButton +{ +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java similarity index 68% rename from Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java rename to Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java index e525f6777..0a236ce9b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/AddPlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java @@ -1,10 +1,12 @@ -package mineplex.core.party.ui.button.tools; +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.menus.InvitePlayerMenu; +import mineplex.core.party.ui.button.tools.PartyButton; +import mineplex.core.party.ui.menus.PlayerNameActionMenu; +import mineplex.core.party.ui.menus.input.PartyInvitePlayerMenu; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -28,7 +30,7 @@ public class AddPlayerButton extends PartyButton @Override public void onClick(Player player, ClickType clickType) { - new InvitePlayerMenu(getPlugin(), player, getParty()).openInventory(); + new PartyInvitePlayerMenu(getPlugin(), player, getParty()).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 new file mode 100644 index 000000000..53b893c7e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.owner; + +/** + * + */ +public class DisbandPartyButton +{ +} 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 new file mode 100644 index 000000000..0f15e00b5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.owner; + +/** + * + */ +public class KickPlayerButton +{ +} 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 new file mode 100644 index 000000000..82d476ae6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.owner; + +/** + * + */ +public class SelectServerButton +{ +} 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 new file mode 100644 index 000000000..e9aacadc0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java @@ -0,0 +1,8 @@ +package mineplex.core.party.ui.button.tools.owner; + +/** + * + */ +public class TransferOwnerButton +{ +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java new file mode 100644 index 000000000..3c8fa6ce5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java @@ -0,0 +1,35 @@ +package mineplex.core.party.ui.button.tools.view; + +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.PlayerSuggestPlayerMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * + */ +public class SuggestPlayerButton extends PartyButton +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.BOOK_AND_QUILL) + .setTitle(C.cYellow + "Suggest Player") + .setLore(" ", C.cWhite + "Suggest a player for the owner to invite") + .build(); + + public SuggestPlayerButton(Party party, PartyManager plugin) + { + super(ITEM, party, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PlayerSuggestPlayerMenu(getPlugin(), player, getParty()).openInventory(); + } +} 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 new file mode 100644 index 000000000..0e53b7f08 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java @@ -0,0 +1,24 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; +import org.bukkit.entity.Player; + +/** + * + */ +public class PartyInvitesMenu extends Menu +{ + + public PartyInvitesMenu(PartyManager plugin) + { + super("Invites", plugin); + } + + @Override + protected Button[] setUp(Player player) + { + return new Button[0]; + } +} 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 cd818b98b..e9b9204e5 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,8 @@ 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.AddPlayerButton; +import mineplex.core.party.ui.button.tools.owner.AddPlayerButton; +import mineplex.core.party.ui.button.tools.LeavePartyButton; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -31,16 +32,26 @@ public class PartyOwnerMenu extends Menu //Tools buttons[1] = new AddPlayerButton(_plugin, _party); + //Kick player buttons[4] = create(new ItemStack(Material.IRON_AXE)); - buttons[7] = create(new ItemStack(Material.BARRIER)); + //Transfer ownership + buttons[7] = create(new ItemStack(Material.BOOK_AND_QUILL)); + //Go to server buttons[46] = create(new ItemStack(Material.COMPASS)); - buttons[49] = create(new ItemStack(Material.EMERALD_BLOCK)); - buttons[52] = create(new ItemStack(Material.BOOK_AND_QUILL)); + //Leave party + buttons[49] = new LeavePartyButton(); + //Disband + buttons[52] = create(new ItemStack(Material.BARRIER)); + int slot = 20; //Players - for(int i = 18; i < _party.getMembers().size(); i++) + for(int i = 0; i < _party.getMembers().size(); i++) { - buttons[i] = new PartyMemberIcon(_party.getMembers().get(i), _plugin); + if(slot == 25) + { + slot = 29; + } + buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i)); } return 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 654598c61..4f7d36b00 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 @@ -6,6 +6,7 @@ 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.LeavePartyButton; +import mineplex.core.party.ui.button.tools.view.SuggestPlayerButton; import org.bukkit.entity.Player; /** @@ -25,14 +26,21 @@ public class PartyViewMenu extends Menu @Override protected Button[] setUp(Player player) { - Button[] buttons = new Button[54]; + Button[] buttons = new Button[36]; //Tools - buttons[4] = new LeavePartyButton(_plugin); + buttons[1] = new LeavePartyButton(); + //Suggest Player + buttons[4] = new SuggestPlayerButton(_party, _plugin); + int slot = 20; //Players for(int i = 0; i < _party.getMembers().size(); i++) { - buttons[i + 18] = new PartyMemberIcon(_party.getMembers().get(i), _plugin); + if(slot == 25) + { + slot = 29; + } + buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i)); } return buttons; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/InvitePlayerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java similarity index 87% rename from Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/InvitePlayerMenu.java rename to Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java index 631abc475..d4f00a3f6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/InvitePlayerMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java @@ -20,19 +20,19 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; /** - * + * This class handles creating inventory GUIs that need a players input to finalize */ -public class InvitePlayerMenu implements Listener +public abstract class PlayerNameActionMenu implements Listener { - private PartyManager _partyManager; - private Player _player; - private Inventory _currentInventory; - private String _itemName = ""; - private boolean _searching; - private Party _party; + protected PartyManager _partyManager; + protected Player _player; + protected Inventory _currentInventory; + protected String _itemName = ""; + protected boolean _searching; + protected Party _party; - public InvitePlayerMenu(PartyManager partyManager, Player player, Party party) + public PlayerNameActionMenu(PartyManager partyManager, Player player, Party party) { _player = player; _partyManager = partyManager; @@ -42,6 +42,10 @@ public class InvitePlayerMenu implements Listener _partyManager.registerEvents(this); } + public abstract void onSuccess(String name); + + public abstract void onFail(String name); + @EventHandler public void onInventoryClose(InventoryCloseEvent event) { @@ -84,14 +88,11 @@ public class InvitePlayerMenu implements Listener if (result != null) { - _partyManager.getRedisManager().findAndInvite(name, _player.getName()); - _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); - + onSuccess(name); unregisterListener(); - _player.closeInventory(); - new PartyOwnerMenu(_party, _partyManager).open(_player); } else { + onFail(name); _currentInventory.setItem(2, new ItemBuilder(Material.PAPER) .setTitle(C.cYellow + "0" + C.cGray + " matches for [" + C.cYellow + name + C.cGray + "]") .build()); 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 new file mode 100644 index 000000000..b4d480e20 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java @@ -0,0 +1,35 @@ +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; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +/** + * + */ +public class PartyInvitePlayerMenu extends PlayerNameActionMenu +{ + + public PartyInvitePlayerMenu(PartyManager partyManager, Player player, Party party) + { + super(partyManager, player, party); + } + + @Override + public void onSuccess(String name) + { + _partyManager.getRedisManager().findAndInvite(name, _player.getName()); + _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); + _player.closeInventory(); + new PartyOwnerMenu(_party, _partyManager).open(_player); + } + + @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 new file mode 100644 index 000000000..3dff2ecf2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java @@ -0,0 +1,43 @@ +package mineplex.core.party.ui.menus.input; + +import mineplex.core.common.jsonchat.ChildJsonMessage; +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.HoverEvent; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.menus.PlayerNameActionMenu; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +/** + * + */ +public class PlayerSuggestPlayerMenu extends PlayerNameActionMenu +{ + + public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party) + { + super(partyManager, player, party); + } + + @Override + 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."); + 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); + } + + @Override + public void onFail(String name) + { + + } +} From e39326b592a53c66497586cd6e402ef46b6f14f3 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Tue, 21 Jun 2016 00:11:33 -0500 Subject: [PATCH 13/53] Help Command UI. --- .../core/party/command/PartyCommand.java | 61 +++++++++++++------ .../ui/button/tools/LeavePartyButton.java | 2 +- 2 files changed, 43 insertions(+), 20 deletions(-) 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 ea99269d5..ec1ac4284 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -2,6 +2,9 @@ package mineplex.core.party.command; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; +import mineplex.core.common.jsonchat.ChildJsonMessage; +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.Party; @@ -10,6 +13,7 @@ import mineplex.core.party.manager.PartyInviteManager; import mineplex.core.party.ui.menus.PartyMainMenu; import mineplex.core.party.ui.menus.PartyOwnerMenu; import mineplex.core.party.ui.menus.PartyViewMenu; +import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -22,16 +26,16 @@ public class PartyCommand extends CommandBase { private final String[] HELP = { - F.main("Party", "Party Commands"), + F.main("Party", "Party Commands (Click the command!)"), help("help", "Shows this help screen"), help("", "Brings up the Party GUI"), - help("invite ", "Invite a player to your party." + C.cRed + " Must be the leader."), - help("accept ", "Accept an invite to a player's party."), - help("deny ", "Deny an invite to a player's party."), + help("invite ", "Invite a player to your party."), + help("accept ", "Accept an invite to a party."), + help("deny ", "Deny an invite to a party."), help("leave", "Leave your current party"), - help("kick/remove ", "Remove a player from your party. " + C.cRed + "Must be the leader."), - help("disband", "Disband your party. " + C.cRed + "Must be the leader."), - C.cBlue + "Party> " + C.cWhite + "# " + C.cGray + "- Send a message to the players in your 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." }; public PartyCommand(PartyManager plugin) @@ -45,12 +49,12 @@ public class PartyCommand extends CommandBase if (args.length == 0) { Party party = Plugin.getParty(caller); - if(party == null) + if (party == null) { new PartyMainMenu(Plugin).open(caller); return; } - if(party.getOwner().equalsIgnoreCase(caller.getName())) + if (party.getOwner().equalsIgnoreCase(caller.getName())) { new PartyOwnerMenu(party, Plugin).open(caller); return; @@ -61,8 +65,24 @@ public class PartyCommand extends CommandBase String argument = args[0]; if (argument.equalsIgnoreCase("help")) { + caller.sendMessage(HELP[0]); //Show this menu - caller.sendMessage(HELP); + for(int i = 1; i < HELP.length; i++) + { + String s = HELP[i]; + String command = ChatColor.stripColor(s); + ChildJsonMessage jsonMessage = new ChildJsonMessage(s); + if ((i + 1) == HELP.length) + { + command = "#"; + } else + { + command = command.substring(command.indexOf("/"), command.indexOf("-") - 1); + } + jsonMessage.click(ClickEvent.SUGGEST_COMMAND, command); + jsonMessage.sendToPlayer(caller); + } + return; } if (args.length == 1) @@ -107,7 +127,7 @@ public class PartyCommand extends CommandBase private void handleInvite(Player caller, String target) { Player possible = Bukkit.getPlayer(target); - if(possible != null) + if (possible != null) { UUID uuid = possible.getUniqueId(); caller.sendMessage(F.main("Party", "Sent an invite to " + possible.getName() + "...")); @@ -122,7 +142,7 @@ public class PartyCommand extends CommandBase { PartyInviteManager inviteManager = Plugin.getInviteManager(); - if(!inviteManager.isInvitedTo(caller.getUniqueId(), target)) + 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))); @@ -136,12 +156,13 @@ public class PartyCommand extends CommandBase { Party party = Plugin.getParty(caller); - if(party == null) { + if (party == null) + { caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); return; } - if(!party.getOwner().equalsIgnoreCase(caller.getName())) + if (!party.getOwner().equalsIgnoreCase(caller.getName())) { caller.sendMessage(F.main("Party", "You must be the leader of the party to do that!")); return; @@ -149,7 +170,7 @@ public class PartyCommand extends CommandBase Player playerTarget = Bukkit.getPlayer(target); - if(playerTarget == null) + if (playerTarget == null) { caller.sendMessage(F.main("Party", target + " is not online, and is not in your party!")); return; @@ -157,7 +178,7 @@ public class PartyCommand extends CommandBase 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.")); return; @@ -174,7 +195,8 @@ public class PartyCommand extends CommandBase { Party party = Plugin.getParty(caller); - if(party == null) { + if (party == null) + { caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); return; } @@ -189,12 +211,13 @@ public class PartyCommand extends CommandBase { Party party = Plugin.getParty(caller); - if(party == null) { + if (party == null) + { caller.sendMessage(F.main("Party", "You are not in a party! Do /party help to get started.")); return; } - if(!party.getOwner().equalsIgnoreCase(caller.getName())) + if (!party.getOwner().equalsIgnoreCase(caller.getName())) { caller.sendMessage(F.main("Party", "You must be the leader of the party to do that!")); return; 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 2bfa1353f..44cf2f511 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,7 @@ public class LeavePartyButton extends Button @Override public void onClick(Player player, ClickType clickType) { - player.performCommand("/party leave"); + player.performCommand("party leave"); } } From 4d31867e98631b119078534a5d03d7959edfd4e2 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Wed, 22 Jun 2016 00:35:57 -0500 Subject: [PATCH 14/53] PC Party updates. --- .../src/mineplex/core/party/Lang.java | 97 ++++++ .../src/mineplex/core/party/Party.java | 81 +++++ .../core/party/PartyEventListener.java | 99 ++++++ .../src/mineplex/core/party/PartyManager.java | 63 +++- .../core/party/PartyRemoveReason.java | 33 ++ .../core/party/command/PartyCommand.java | 82 +++-- .../party/event/PartyDataReceivedEvent.java | 37 ++ .../party/event/PartyMemberKickGUIEvent.java | 51 +++ .../party/event/PartySelectServerEvent.java | 36 ++ .../party/event/PartyTransferOwnerEvent.java | 65 ++++ .../party/manager/PartyInviteManager.java | 35 +- .../core/party/manager/PartyJoinManager.java | 4 +- .../core/party/manager/PartyRedisManager.java | 68 +++- .../core/party/redis/PartyRedisListener.java | 1 - .../core/party/redis/RedisMessageType.java | 5 +- .../src/mineplex/core/party/ui/Menu.java | 327 ++++++++++-------- .../mineplex/core/party/ui/MenuListener.java | 12 + .../core/party/ui/button/PartyMemberIcon.java | 25 +- .../ui/button/tools/LeavePartyButton.java | 3 +- .../button/tools/main/InvitePlayerButton.java | 28 +- .../button/tools/main/ViewInvitesButton.java | 29 +- .../button/tools/owner/AddPlayerButton.java | 2 +- .../tools/owner/DisbandPartyButton.java | 32 +- .../button/tools/owner/KickPlayerButton.java | 45 ++- .../tools/owner/SelectServerButton.java | 31 +- .../tools/owner/TransferOwnerButton.java | 30 +- .../core/party/ui/menus/PartyInvitesMenu.java | 3 +- .../core/party/ui/menus/PartyMainMenu.java | 5 + .../core/party/ui/menus/PartyOwnerMenu.java | 14 +- .../core/party/ui/menus/PartyViewMenu.java | 14 +- .../party/ui/menus/PlayerNameActionMenu.java | 8 +- .../ui/menus/input/PartyInvitePlayerMenu.java | 11 +- .../menus/input/PartyTransferOwnerMenu.java | 34 ++ .../menus/input/PlayerSuggestPlayerMenu.java | 7 +- .../src/mineplex/hub/HubManager.java | 155 +++++---- .../src/mineplex/hub/modules/NewsManager.java | 8 +- .../src/mineplex/hub/queue/ui/QueuePage.java | 18 +- .../src/mineplex/hub/queue/ui/QueueShop.java | 10 +- .../mineplex/hub/server/ui/ServerNpcShop.java | 10 +- .../server/ui/clans/ClanMoveServerShop.java | 7 +- .../hub/server/ui/clans/ClansServerShop.java | 7 +- .../speedbuilders/data/DemolitionData.java | 17 +- .../arcade/managers/chat/GameChatManager.java | 11 +- 43 files changed, 1326 insertions(+), 334 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyDataReceivedEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyMemberKickGUIEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyTransferOwnerEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyTransferOwnerMenu.java 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"); From 38a13d01f15b6170509b3d70bcbaa0df56c4f1fc Mon Sep 17 00:00:00 2001 From: TadahTech Date: Wed, 22 Jun 2016 00:56:44 -0500 Subject: [PATCH 15/53] Open server menu properly --- .../party/event/PartySelectServerEvent.java | 11 +++++---- .../tools/owner/SelectServerButton.java | 2 +- .../src/mineplex/hub/HubManager.java | 24 +++++++++---------- .../mineplex/hub/server/ServerManager.java | 9 ++++++- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java index a937443c0..c7f97a05c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java @@ -1,6 +1,7 @@ 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; @@ -11,16 +12,16 @@ public class PartySelectServerEvent extends Event { private static final HandlerList HANDLER_LIST = new HandlerList(); - private final Party _party; + private final Player _player; - public PartySelectServerEvent(Party party) + public PartySelectServerEvent(Player player) { - _party = party; + _player = player; } - public Party getParty() + public Player getPLayer() { - return _party; + return _player; } @Override 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 cee97b248..6c400a101 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 @@ -32,6 +32,6 @@ public class SelectServerButton extends PartyButton @Override public void onClick(Player player, ClickType clickType) { - UtilServer.getPluginManager().callEvent(new PartySelectServerEvent(getParty())); + UtilServer.getPluginManager().callEvent(new PartySelectServerEvent(player)); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 18802fd55..2512c393e 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -604,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 @@ -612,12 +612,12 @@ public class HubManager extends MiniClientPlugin //Rank Prefix String rankStr = ""; - if (rank != Rank.ALL) + if (rank != Rank.ALL) rankStr = rank.getTag(true, true) + " "; - //Party Chat +/* //Party Chat if (event.getMessage().charAt(0) == '#') { - Party party = _partyManager.getParty(player); + Party party = _partyManager.GetParty(player); if (party != null) { event.getRecipients().clear(); @@ -625,23 +625,24 @@ public class HubManager extends MiniClientPlugin 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()) + for (String name : party.GetPlayers()) { Player other = UtilPlayer.searchExact(name); if (other != null) - { event.getRecipients().add(other); - } } - } else + } + else { UtilPlayer.message(player, F.main("Party", "You are not in a Party.")); event.setCancelled(true); } - } else - { + return; + } + else + {*/ TextComponent rankComponent = new TextComponent(rankStr); TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + playerName); TextComponent component = new TextComponent(); @@ -661,12 +662,11 @@ public class HubManager extends MiniClientPlugin continue; } - if (!event.isCancelled()) + if(!event.isCancelled()) other.spigot().sendMessage(component); } event.setCancelled(true); // } - } } @EventHandler diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index dfa790891..17770d91c 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -13,6 +13,7 @@ import java.util.Set; import mineplex.core.boosters.BoosterManager; import mineplex.core.brawl.fountain.BrawlShopProvider; +import mineplex.core.party.event.PartySelectServerEvent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -352,7 +353,13 @@ public class ServerManager extends MiniDbClientPlugin implement { return _serverInfoMap.get(serverName); } - + + @EventHandler + public void onClickCompassPartyIcon(PartySelectServerEvent event) + { + _quickShop.attemptShopOpen(event.getPlayer()); + } + @EventHandler public void updatePages(UpdateEvent event) { From ebff8f865b78e97700c729b534a0d1694eade056 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Wed, 22 Jun 2016 00:58:30 -0500 Subject: [PATCH 16/53] Undid a little too much. --- .../Mineplex.Hub/src/mineplex/hub/HubManager.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 2512c393e..be643f6aa 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -614,10 +614,10 @@ public class HubManager extends MiniClientPlugin String rankStr = ""; if (rank != Rank.ALL) rankStr = rank.getTag(true, true) + " "; -/* //Party Chat + //Party Chat if (event.getMessage().charAt(0) == '#') { - Party party = _partyManager.GetParty(player); + Party party = _partyManager.getParty(player); if (party != null) { event.getRecipients().clear(); @@ -625,7 +625,7 @@ public class HubManager extends MiniClientPlugin 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.GetPlayers()) + for (String name : party.getMembers()) { Player other = UtilPlayer.searchExact(name); @@ -639,10 +639,9 @@ public class HubManager extends MiniClientPlugin event.setCancelled(true); } - return; } else - {*/ + { TextComponent rankComponent = new TextComponent(rankStr); TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + playerName); TextComponent component = new TextComponent(); @@ -662,11 +661,11 @@ public class HubManager extends MiniClientPlugin continue; } - if(!event.isCancelled()) + if (!event.isCancelled()) other.spigot().sendMessage(component); } event.setCancelled(true); -// } + } } @EventHandler From e53b474f3fe9d5434cc4006eec8ea03dec00fc76 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Wed, 22 Jun 2016 00:59:22 -0500 Subject: [PATCH 17/53] Fix typo. --- .../src/mineplex/core/party/event/PartySelectServerEvent.java | 2 +- Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java index c7f97a05c..7a994b2c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java @@ -19,7 +19,7 @@ public class PartySelectServerEvent extends Event _player = player; } - public Player getPLayer() + public Player getPlayer() { return _player; } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index 17770d91c..d063d8983 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -580,7 +580,7 @@ public class ServerManager extends MiniDbClientPlugin implement } /** - * @param serverType - the type of server that should be fetched + * @param serverKey - the type of server that should be fetched * @return the best server that a new player should join according to a {@code serverType} constraint. */ public ServerInfo getBestServer(Player player, String serverKey) From 50534c3af95f5d66e0b6b14e021b8c775052bfa3 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Wed, 22 Jun 2016 17:28:43 -0500 Subject: [PATCH 18/53] UI And server manager changes --- .../PlayerInputActionMenu.java} | 40 +++++---------- .../core/anvilMenu/player/PlayerNameMenu.java | 50 +++++++++++++++++++ .../core/party/command/PartyCommand.java | 7 +++ .../party/manager/PartyInviteManager.java | 19 ++++--- .../core/party/manager/PartyJoinManager.java | 7 ++- .../src/mineplex/core/party/ui/Menu.java | 7 +++ .../ui/button/tools/LeavePartyButton.java | 5 ++ .../ui/button/tools/invite/BackButton.java | 28 ++++++++++- .../ui/button/tools/invite/DenyAllButton.java | 29 ++++++++++- .../ui/button/tools/invite/Filterbutton.java | 46 ++++++++++++++++- .../button/tools/owner/AddPlayerButton.java | 2 +- .../tools/view/SuggestPlayerButton.java | 2 +- .../core/party/ui/menus/PartyInvitesMenu.java | 20 ++++++++ .../ui/menus/input/InviteFilterMenu.java | 26 ++++++++++ .../ui/menus/input/PartyInvitePlayerMenu.java | 10 ++-- .../menus/input/PartyTransferOwnerMenu.java | 11 ++-- .../menus/input/PlayerSuggestPlayerMenu.java | 11 ++-- .../mineplex/hub/server/ServerManager.java | 14 +++++- 18 files changed, 283 insertions(+), 51 deletions(-) rename Plugins/Mineplex.Core/src/mineplex/core/{party/ui/menus/PlayerNameActionMenu.java => anvilMenu/PlayerInputActionMenu.java} (77%) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java similarity index 77% rename from Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java rename to Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java index 3c031979e..296c1ebbe 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PlayerNameActionMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java @@ -1,5 +1,7 @@ -package mineplex.core.party.ui.menus; +package mineplex.core.anvilMenu; +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilPlayer; import mineplex.core.itemstack.ItemBuilder; @@ -19,31 +21,31 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; +import static sun.audio.AudioPlayer.player; + /** - * This class handles creating inventory GUIs that need a players input to finalize + * A utility class for creating simple and easy Anvil GUI's that require actions based on a users input. */ -public abstract class PlayerNameActionMenu implements Listener +public abstract class PlayerInputActionMenu implements Listener { - protected PartyManager _partyManager; + protected MiniPlugin _plugin; protected Player _player; protected Inventory _currentInventory; protected String _itemName = ""; protected boolean _searching; protected Party _party; - public PlayerNameActionMenu(PartyManager partyManager, Player player, Party party) + public PlayerInputActionMenu(MiniPlugin plugin, Player player, Party party) { _player = player; - _partyManager = partyManager; + _plugin = plugin; _party = party; player.closeInventory(); - _partyManager.registerEvents(this); + _plugin.registerEvents(this); } - public abstract void onSuccess(String name); - - public abstract void onFail(String name); + public abstract void inputReceived(String name); @EventHandler public void onInventoryClose(InventoryCloseEvent event) @@ -81,23 +83,7 @@ public abstract class PlayerNameActionMenu implements Listener if (_itemName.length() > 1 && !_searching) { _searching = true; - final String name = _itemName; - - _partyManager.getClientManager().checkPlayerName(_player, _itemName, result -> { - _searching = false; - - if (result != null) - { - onSuccess(result); - } else - { - onFail(name); - _currentInventory.setItem(2, new ItemBuilder(Material.PAPER) - .setTitle(C.cYellow + "0" + C.cGray + " matches for [" + C.cYellow + name + C.cGray + "]") - .build()); - _player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f); - } - }); + inputReceived(_itemName); } else { _player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java new file mode 100644 index 000000000..243ed51c5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java @@ -0,0 +1,50 @@ +package mineplex.core.anvilMenu.player; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.anvilMenu.PlayerInputActionMenu; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +/** + * A wrapped menu that handles looking for players specifically. + */ +public abstract class PlayerNameMenu extends PlayerInputActionMenu +{ + + protected CoreClientManager _clientManager; + + public PlayerNameMenu(MiniPlugin plugin, CoreClientManager clientManager, Player player, Party party) + { + super(plugin, player, party); + _clientManager = clientManager; + } + + public abstract void onSuccess(String name); + + public abstract void onFail(String name); + + @Override + public void inputReceived(String name) + { + _clientManager.checkPlayerName(_player, _itemName, result -> { + _searching = false; + + if (result != null) + { + onSuccess(result); + } else + { + onFail(name); + _currentInventory.setItem(2, new ItemBuilder(Material.PAPER) + .setTitle(C.cYellow + "0" + C.cGray + " matches for [" + C.cYellow + name + C.cGray + "]") + .build()); + _player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + } + }); + } +} 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 fadd539ac..f9e2754b8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -131,6 +131,8 @@ public class PartyCommand extends CommandBase Player possible = Bukkit.getPlayerExact(target); Party party = Plugin.getParty(caller); + boolean can = Bukkit.getMaxPlayers() < Plugin.getPlugin().getServer().getOnlinePlayers().size(); + //Same Server if (possible != null) { @@ -159,6 +161,11 @@ public class PartyCommand extends CommandBase Lang.PARTY_FULL.send(caller); return; } + if(!can) + { + Lang.SERVER_FULL.send(caller); + return; + } Lang.SUCCESS_INVITE.send(party, caller.getName(), target); } 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 1e35d6130..a97cc779c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -18,6 +18,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.UUID; @@ -89,6 +90,12 @@ public class PartyInviteManager if (newParty == null) { newParty = new Party(possible.getName()); + int size = 5; + if(_plugin.getClientManager().Get(possible).GetRank().isDonor()) + { + size = 10; + } + newParty.setSize(size); _plugin.addParty(newParty); _plugin.addToParty(possible.getUniqueId(), newParty); } @@ -132,13 +139,6 @@ public class PartyInviteManager switch (response) { case ACCEPTED: - if (party == null) - { - party = new Party(sender); - _plugin.addParty(party); - _plugin.addToParty(player.getUniqueId(), party); - } - party.sendMessage(message); addToPendingJoin(targetUUID, party.getName()); break; case EXPIRED: @@ -290,6 +290,11 @@ public class PartyInviteManager _activeInvites.put(invited, data); } + public Collection getAllInvites(Player player) + { + return _activeInvites.get(player.getUniqueId()); + } + private void sendExpired(String server, String party, String playerName, UUID player) { _plugin.getRedisManager().publish(server, RedisMessageType.INVITE_PLAYER_RESPONSE, party, playerName, player.toString(), InviteResponse.EXPIRED.name()); 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 b0bd8cf53..6f4abc7d7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -97,7 +97,12 @@ public class PartyJoinManager } party.sendMessage(F.main("Party", "Transferring servers...")); _plugin.getRedisManager().sendPartyInfo(server, party); - party.getMembers().stream().map(Bukkit::getPlayer).forEach(player1 -> _plugin.getPortal().sendPlayerToServer(player1, server)); + party.getMembers().stream().map(Bukkit::getPlayer).forEach(player1 -> + { + player.leaveVehicle(); + player.eject(); + _plugin.getPortal().sendPlayerToServer(player1, server); + }); } } 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 bec91ee99..562fe20f4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java @@ -1,5 +1,6 @@ package mineplex.core.party.ui; +import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.button.IconButton; @@ -27,6 +28,12 @@ public abstract class Menu .setData(DyeColor.LIGHT_BLUE.getWoolData()) .build(), null); + protected static final Button PURCHASE_MORE_SLOTS = new IconButton(new ItemBuilder(Material.SKULL_ITEM) + .setTitle(C.cRed + C.Bold + "Locked!") + .setLore(" ", C.cGray + "Purchase a rank @ mineplex.com/shop", C.cGray + "Purchasing a rank increases your", C.cGray + "party size to allow 10 people!") + .setPlayerHead("Mopplebottom") + .build(), null); + protected static final Button[] EMPTY = new Button[45]; protected static Map MENUS = new HashMap<>(); private String _name; 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 1de46988c..083a62d15 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 @@ -17,6 +17,7 @@ public class LeavePartyButton extends Button private static final ItemStack ITEM = new ItemBuilder(Material.REDSTONE_BLOCK) .setTitle(C.cYellow + "Leave Party") + .setLore(" ", C.cRed + "Shift-Left-Click" + C.cGray + " to leave your party.") .build(); public LeavePartyButton() @@ -27,6 +28,10 @@ public class LeavePartyButton extends Button @Override public void onClick(Player player, ClickType clickType) { + if(clickType != ClickType.SHIFT_LEFT) + { + return; + } player.chat("/party leave"); player.closeInventory(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java index fadaa503e..7f385fc1d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java @@ -1,8 +1,34 @@ package mineplex.core.party.ui.button.tools.invite; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.PartyMainMenu; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class BackButton +public class BackButton extends Button { + + private static ItemStack ITEM = new ItemBuilder(Material.BED) + .setTitle(ChatColor.GRAY + "\u21FD Go Back") + .build(); + + public BackButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + player.closeInventory(); + new PartyMainMenu(getPlugin()).open(player); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java index b725893d8..48c0436df 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java @@ -1,8 +1,35 @@ package mineplex.core.party.ui.button.tools.invite; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class DenyAllButton +public class DenyAllButton extends Button { + + private static final ItemStack ITEM = new ItemBuilder(Material.REDSTONE_BLOCK) + .setTitle(C.cRed + "Delete all Invites") + .setLore(" ", C.cGray + "This will remove all pending invites.") + .build(); + + public DenyAllButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + getPlugin().getInviteManager().removeAll(player.getUniqueId()); + Menu.get(player.getUniqueId()).update(player); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java index 48ae67294..4b0e67ad0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java @@ -1,8 +1,52 @@ package mineplex.core.party.ui.button.tools.invite; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.input.InviteFilterMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + /** * */ -public class FilterButton +public class FilterButton extends Button { + + private static final ItemStack ITEM = new ItemBuilder(Material.NAME_TAG) + .setTitle(C.cYellow + "Filter Invites") + .setLore(" ", + C.cGray + "Click to bring up an Anvil GUI", + C.cGray + "where you type and filter", + C.cDGray + "Party invites that contain the", + C.cGray + "inputted characters") + .build(); + + public FilterButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + public FilterButton(String filter, PartyManager plugin) + { + super(new ItemBuilder(Material.NAME_TAG) + .setTitle("Filter Invites") + .setLore(C.cWhite + "Active Filter: " + C.cGreen + filter, " ", + C.cGray + "Click to bring up an Anvil GUI", + C.cGray + "where you type and filter", + C.cDGray + "Party invites that contain the", + C.cGray + "inputted characters") + .setGlow(true) + .build(), plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new InviteFilterMenu(getPlugin(), player, null); + } + } 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 63534ed81..64ae467fe 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 @@ -5,7 +5,6 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.button.tools.PartyButton; -import mineplex.core.party.ui.menus.PlayerNameActionMenu; import mineplex.core.party.ui.menus.input.PartyInvitePlayerMenu; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -20,6 +19,7 @@ public class AddPlayerButton extends PartyButton private static final ItemStack ITEM = new ItemBuilder(Material.SIGN) .setTitle(C.cYellow + "Invite a Player") + .setLore(" ", C.cGray + "Brings up the Inviting Anvil!", C.cGray + "Simply type a players name", C.cGray + "and click the paper to invite him") .build(); public AddPlayerButton(PartyManager plugin, Party party) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java index 3c8fa6ce5..f2ea127ef 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java @@ -30,6 +30,6 @@ public class SuggestPlayerButton extends PartyButton @Override public void onClick(Player player, ClickType clickType) { - new PlayerSuggestPlayerMenu(getPlugin(), player, getParty()).openInventory(); + new PlayerSuggestPlayerMenu(getPlugin(), player).openInventory(); } } 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 984291319..86c746ff9 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 @@ -3,6 +3,9 @@ package mineplex.core.party.ui.menus; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.button.tools.invite.BackButton; +import mineplex.core.party.ui.button.tools.invite.DenyAllButton; +import mineplex.core.party.ui.button.tools.invite.FilterButton; import org.bukkit.entity.Player; /** @@ -11,15 +14,32 @@ import org.bukkit.entity.Player; public class PartyInvitesMenu extends Menu { + private String _filterBy; + public PartyInvitesMenu(PartyManager plugin) { super("Invites", plugin); } + public PartyInvitesMenu(PartyManager plugin, String filterBy) + { + this(plugin); + _filterBy = filterBy; + } + @Override protected Button[] setUp(Player player) { Button[] buttons = new Button[54]; + buttons[0] = new BackButton(_plugin); + buttons[4] = new DenyAllButton(_plugin); + buttons[8] = new FilterButton(_plugin); + + if(_filterBy == null || _filterBy.isEmpty()) + { + return addPanes(buttons); + } + return addPanes(buttons); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java new file mode 100644 index 000000000..fa773ab32 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java @@ -0,0 +1,26 @@ +package mineplex.core.party.ui.menus.input; + +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import mineplex.core.anvilMenu.PlayerInputActionMenu; +import org.bukkit.entity.Player; + +/** + * + */ +public class InviteFilterMenu extends PlayerInputActionMenu +{ + + public InviteFilterMenu(PartyManager partyManager, Player player, Party party) + { + super(partyManager, player, party); + } + + @Override + public void inputReceived(String name) + { + _player.closeInventory(); + new PartyInvitesMenu((PartyManager) _plugin, name).open(_player); + } +} 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 27cfa879d..463345d0f 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,20 +1,24 @@ package mineplex.core.party.ui.menus.input; +import mineplex.core.anvilMenu.player.PlayerNameMenu; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.menus.PartyOwnerMenu; -import mineplex.core.party.ui.menus.PlayerNameActionMenu; +import mineplex.core.anvilMenu.PlayerInputActionMenu; import org.bukkit.Sound; import org.bukkit.entity.Player; /** * */ -public class PartyInvitePlayerMenu extends PlayerNameActionMenu +public class PartyInvitePlayerMenu extends PlayerNameMenu { + private PartyManager _partyManager; + public PartyInvitePlayerMenu(PartyManager partyManager, Player player) { - super(partyManager, player, null); + super(partyManager, partyManager.getClientManager(), player, null); + _partyManager = partyManager; } @Override 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 index ac073d94e..341ce26f9 100644 --- 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 @@ -1,22 +1,27 @@ package mineplex.core.party.ui.menus.input; +import mineplex.core.anvilMenu.player.PlayerNameMenu; import mineplex.core.party.Lang; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; -import mineplex.core.party.ui.menus.PlayerNameActionMenu; +import mineplex.core.anvilMenu.PlayerInputActionMenu; import org.bukkit.entity.Player; /** * */ -public class PartyTransferOwnerMenu extends PlayerNameActionMenu +public class PartyTransferOwnerMenu extends PlayerNameMenu { + private PartyManager _partyManager; + public PartyTransferOwnerMenu(PartyManager partyManager, Player player, Party party) { - super(partyManager, player, party); + super(partyManager, partyManager.getClientManager(), player, null); + _partyManager = partyManager; } + @Override public void onSuccess(String name) { 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 6b4ddccb2..9e1561674 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 @@ -1,5 +1,6 @@ package mineplex.core.party.ui.menus.input; +import mineplex.core.anvilMenu.player.PlayerNameMenu; import mineplex.core.common.jsonchat.ChildJsonMessage; import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.HoverEvent; @@ -7,21 +8,23 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; -import mineplex.core.party.ui.menus.PlayerNameActionMenu; +import mineplex.core.anvilMenu.PlayerInputActionMenu; import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** * */ -public class PlayerSuggestPlayerMenu extends PlayerNameActionMenu +public class PlayerSuggestPlayerMenu extends PlayerNameMenu { - public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party) + + public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player) { - super(partyManager, player, party); + super(partyManager, partyManager.getClientManager(), player, null); } + @Override public void onSuccess(String name) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index d063d8983..38ae6eac3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -13,6 +13,7 @@ import java.util.Set; import mineplex.core.boosters.BoosterManager; import mineplex.core.brawl.fountain.BrawlShopProvider; +import mineplex.core.party.Lang; import mineplex.core.party.event.PartySelectServerEvent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -519,8 +520,19 @@ public class ServerManager extends MiniDbClientPlugin implement return _partyManager; } - public void selectServer(org.bukkit.entity.Player player, ServerInfo serverInfo) + public void selectServer(Player player, ServerInfo serverInfo) { + Party party = _partyManager.getParty(player); + if(party != null) + { + if(!party.getOwner().equalsIgnoreCase(player.getName())) + { + Lang.NOT_OWNER_SERVER.send(player); + return; + } + _partyManager.getJoinManager().requestServerJoin(serverInfo.Name, party); + return; + } player.leaveVehicle(); player.eject(); From 2453f82061913b74cd2894f9af428cc567e4a44c Mon Sep 17 00:00:00 2001 From: Alex-The-Coder Date: Wed, 22 Jun 2016 18:40:12 -0400 Subject: [PATCH 19/53] Rename Filterbutton.java to FilterButton.java --- .../button/tools/invite/{Filterbutton.java => FilterButton.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/{Filterbutton.java => FilterButton.java} (100%) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java similarity index 100% rename from Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/Filterbutton.java rename to Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java From fb6a772eb0357091a2a135390242f1d5b7b0fcf6 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 23 Jun 2016 02:39:05 -0500 Subject: [PATCH 20/53] Fix Party Redis. Improve Party UI. General testing and fixing. --- .../core/anvilMenu/PlayerInputActionMenu.java | 2 +- .../src/mineplex/core/party/InviteData.java | 9 +- .../core/party/command/PartyCommand.java | 11 +- .../party/manager/PartyInviteManager.java | 47 +++--- .../core/party/manager/PartyRedisManager.java | 18 ++- .../core/party/redis/PartyRedisListener.java | 2 + .../core/party/redis/RedisMessageType.java | 31 ++-- .../src/mineplex/core/party/ui/Menu.java | 3 +- .../core/party/ui/button/PartyMemberIcon.java | 4 + .../ui/button/tools/invite/DenyAllButton.java | 3 +- .../ui/button/tools/invite/FilterButton.java | 16 +- .../ui/button/tools/invite/InviteButton.java | 36 ++++- .../button/tools/invite/NextPageButton.java | 38 ++++- .../button/tools/invite/PrevPageButton.java | 42 ++++- .../tools/owner/DisbandPartyButton.java | 1 + .../tools/view/SuggestPlayerButton.java | 2 +- .../core/party/ui/menus/PartyInvitesMenu.java | 147 +++++++++++++++++- .../core/party/ui/menus/PartyOwnerMenu.java | 9 ++ .../ui/menus/input/InviteFilterMenu.java | 4 + 19 files changed, 351 insertions(+), 74 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java index 296c1ebbe..5a28822c3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java @@ -117,7 +117,7 @@ public abstract class PlayerInputActionMenu implements Listener p.activeContainer.addSlotListener(p); // Set the items to the items from the inventory given _currentInventory = container.getBukkitView().getTopInventory(); - _currentInventory.setItem(0, new ItemBuilder(Material.PAPER).setRawTitle("Players's Name").build()); + _currentInventory.setItem(0, new ItemBuilder(Material.PAPER).setRawTitle("Input Text...").build()); _currentInventory.setItem(2, new ItemBuilder(Material.PAPER).setRawTitle("Search").build()); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java b/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java index 860ad7504..63e49fac5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java @@ -10,13 +10,15 @@ public class InviteData private String _invitedBy; private long _timeStamp; private long _expires; + private String _serverFrom; - public InviteData(String invitedBy, String invitedTo, long timeStamp) + public InviteData(String invitedBy, String invitedTo, long timeStamp, String serverFrom) { _invitedBy = invitedBy; _invitedTo = invitedTo; _timeStamp = timeStamp; _expires = timeStamp + 60000; + _serverFrom = serverFrom; } public long getTimeRemaining() @@ -48,4 +50,9 @@ public class InviteData { return _expires; } + + public String getServerFrom() + { + return _serverFrom; + } } 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 f9e2754b8..7a062b2ff 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -138,6 +138,11 @@ public class PartyCommand extends CommandBase { if (party == null) { + if(Plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), caller.getName())) + { + Lang.ALREADY_INVITED.send(caller, target); + return; + } Lang.INVITE_SUCCESS_PLAYER.send(caller, target); } else { @@ -173,7 +178,7 @@ public class PartyCommand extends CommandBase Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName()); - Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName()); + Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName(), Plugin.getServerName()); Plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName()); return; @@ -191,7 +196,7 @@ public class PartyCommand extends CommandBase Lang.NOT_INVITED.send(caller, target); return; } - + caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party."); inviteManager.respondToInvite(caller, target, accept); } @@ -261,7 +266,7 @@ public class PartyCommand extends CommandBase Lang.NOT_OWNER.send(caller); return; } - + caller.sendMessage(F.main("Party", "You have disbanded your party.")); Plugin.disbandParty(party); } 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 a97cc779c..50180b254 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -45,12 +45,10 @@ public class PartyInviteManager public String format(String target) { - return C.mHead + "Party> " + F.name(target) + " " + _message.substring(_message.indexOf("}" + 1)); + return _message.replace("{0}", F.name(target)); } } - private final Map INVITE_FROM_SERVERS = Maps.newHashMap(); - private final Map> _activeInvites = Maps.newHashMap(); private final Map _invitedBy = Maps.newHashMap(); private final Map _awaitingJoin = Maps.newHashMap(); @@ -69,7 +67,7 @@ public class PartyInviteManager { Player possible = Bukkit.getPlayerExact(party); - remove(party, player.getUniqueId()); + InviteData data = remove(party, player.getUniqueId()); _players.remove(player.getUniqueId()); @@ -78,7 +76,7 @@ public class PartyInviteManager Party newParty = _plugin.getParty(party); if(!accept) { - String message = InviteResponse.DENIED.format(player.getName()); + String message = C.mHead + "Party> " + C.mBody + InviteResponse.DENIED.format(player.getName()); if (newParty == null) { possible.sendMessage(message); @@ -103,7 +101,12 @@ public class PartyInviteManager return; } - String serverFrom = INVITE_FROM_SERVERS.remove(player.getName()); + String serverFrom = data.getServerFrom(); + + if(accept) + { + _plugin.getPortal().sendPlayerToServer(player, serverFrom); + } _partyRedisManager.publish(serverFrom, RedisMessageType.INVITE_PLAYER_RESPONSE, party, player.getName(), player.getUniqueId().toString(), accept ? InviteResponse.ACCEPTED.name() : InviteResponse.DENIED.name()); @@ -118,8 +121,7 @@ public class PartyInviteManager return; } _players.put(player.getUniqueId(), player.getName()); - INVITE_FROM_SERVERS.put(target, serverFrom); - inviteTo(player.getUniqueId(), sender, sender); + inviteTo(player.getUniqueId(), sender, sender, serverFrom); Lang.INVITE_RECEIVED.send(player, sender); sendAcceptOrDeny(player, sender); } @@ -165,17 +167,6 @@ public class PartyInviteManager _activeInvites.remove(player); } - /** - * Get the name of the server that this request was initiated from. - * - * @param player The player - * @return The server name - */ - public String getServerInvitedFrom(Player player) - { - return INVITE_FROM_SERVERS.get(player.getName()); - } - /** * Get the name of the party who is awaiting this player to join * @@ -215,9 +206,9 @@ public class PartyInviteManager * @param player The player who has been invited * @param party The party name */ - public void inviteTo(UUID player, String invitedBy, String party) + public void inviteTo(UUID player, String invitedBy, String party, String server) { - addToInvite(player, invitedBy, party, System.currentTimeMillis()); + addToInvite(player, invitedBy, party, System.currentTimeMillis(), server); new BukkitRunnable() { @Override @@ -228,15 +219,15 @@ public class PartyInviteManager cancel(); return; } - remove(party, player); + InviteData data = remove(party, player); Player possible = Bukkit.getPlayer(player); String playerName = _players.remove(player); if (possible != null) { playerName = possible.getName(); - possible.sendMessage(F.main("Party", "Your invite to " + party + " has expired")); + possible.sendMessage(F.main("Party", "Your invite to " + F.name(party) + "'s party has expired")); } - sendExpired(INVITE_FROM_SERVERS.remove(invitedBy), party, playerName, player); + sendExpired(data.getServerFrom(), party, playerName, player); } }.runTaskLater(_plugin.getPlugin(), 20 * 60); } @@ -271,7 +262,7 @@ public class PartyInviteManager * @param party The name of the party * @param invited The UUID of the player */ - public void remove(String party, UUID invited) + public InviteData remove(String party, UUID invited) { List data = _activeInvites.get(invited); InviteData temp = null; @@ -288,6 +279,7 @@ public class PartyInviteManager data.remove(temp); } _activeInvites.put(invited, data); + return temp; } public Collection getAllInvites(Player player) @@ -305,17 +297,16 @@ public class PartyInviteManager _awaitingJoin.put(player, party); } - private void addToInvite(UUID invited, String invitedBy, String party, long currentTime) + private void addToInvite(UUID invited, String invitedBy, String party, long currentTime, String server) { List inviteDatas = _activeInvites.get(invited); if (inviteDatas == null) { inviteDatas = Lists.newArrayList(); } - InviteData inviteData = new InviteData(invitedBy, party, currentTime + 1000 * 10); + InviteData inviteData = new InviteData(invitedBy, party, currentTime, server); inviteDatas.add(inviteData); _invitedBy.put(invited, invitedBy); - _activeInvites.put(invited, inviteDatas); } 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 1e359df51..df9652f17 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -17,9 +17,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; +import org.jooq.util.derby.sys.Sys; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; +import java.util.Arrays; import java.util.Map; import java.util.UUID; @@ -35,7 +37,6 @@ public class PartyRedisManager private final Map TASKS = Maps.newHashMap(); private final PartyManager _plugin; - private final PartyInviteManager _inviteManager; private final JedisPool _writePool; private final String _channel; private final String _serverName; @@ -43,12 +44,12 @@ public class PartyRedisManager public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool) { _plugin = plugin; - _inviteManager = plugin.getInviteManager(); _serverName = serverName; _writePool = writePool; _channel = CHANNEL_BASE + "-" + serverName; plugin.runAsync(() -> { + System.out.println("Redis Started on " + _channel); try (Jedis jedis = readPool.getResource()) { jedis.subscribe(new PartyRedisListener(this), _channel); @@ -59,6 +60,8 @@ public class PartyRedisManager public void publish(String server, RedisMessageType messageType, String... args) { + System.out.println("Sending redis message: " + messageType.name() + " (" + Arrays.toString(args) + ")"); + System.out.println("Sending on channel: " + CHANNEL_BASE + "-" + server); _plugin.runAsync(() -> { try (Jedis jedis = _writePool.getResource()) { @@ -69,7 +72,8 @@ public class PartyRedisManager public void handle(RedisMessageType messageType, String message) { - String[] contents = message.split("-"); + System.out.println("Received packet: " + messageType.name() + " (" + message + ")"); + String[] contents = message.split(","); if (contents.length < 3) { return; @@ -84,11 +88,11 @@ public class PartyRedisManager break; case INVITE_PLAYER_REQUEST: - _inviteManager.handleInviteRequest(second, third, first); + _plugin.getInviteManager().handleInviteRequest(second, third, first); break; case INVITE_PLAYER_RESPONSE: - _inviteManager.handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase())); + _plugin.getInviteManager().handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase())); break; case PLAYER_FIND_REQUEST: @@ -111,7 +115,7 @@ public class PartyRedisManager task.cancel(); } Player inviter = Bukkit.getPlayerExact(contents[3]); - if (_inviteManager.isInvitedTo(uuid, inviter.getName())) + if (_plugin.getInviteManager().isInvitedTo(uuid, inviter.getName())) { Lang.ALREADY_INVITED.send(inviter, second); return; @@ -123,7 +127,7 @@ public class PartyRedisManager { Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second); } - _inviteManager.inviteTo(uuid, inviter.getName(), inviter.getName()); + _plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName()); publish(first, RedisMessageType.INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); break; 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 6941a03cb..3ddfc98ac 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -19,6 +19,8 @@ public class PartyRedisListener extends JedisPubSub @Override public void onMessage(String channel, String message) { + System.out.println("Received Message on " + channel); + System.out.println("Message: " + message); RedisMessageType type = RedisMessageType.valueOf(message.split(":")[0].toUpperCase()); _redisManager.handle(type, message.split(":")[1]); } 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 6cb302507..3e8e2a71e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -7,20 +7,20 @@ package mineplex.core.party.redis; public enum RedisMessageType { - //Message: SERVER_FROM-PLAYER_TARGET-PLAYER_SENDER - PLAYER_FIND_REQUEST(1, "{0}-{1}-{2}"), - //Message: SERVER_ON-PLAYER_TARGET_NAME-PLAYER_TARGET_UUID-PLAYER_SENDER - PLAYER_FIND_RESPONSE(2, "{0}-{1}-{2}-{3}"), + //Message: SERVER_FROM,PLAYER_TARGET,PLAYER_SENDER + PLAYER_FIND_REQUEST(1, "{0},{1},{2}"), + //Message: SERVER_ON,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,PLAYER_SENDER + PLAYER_FIND_RESPONSE(2, "{0},{1},{2},{3}"), - //Message: SERVER_FROM-PLAYER_SENDER-PLAYER_TARGET - INVITE_PLAYER_REQUEST(3, "{0}-{1}-{2}"), - //Message: PLAYER_SENDER-PLAYER_TARGET_NAME-PLAYER_TARGET_UUID-RESPONSE - INVITE_PLAYER_RESPONSE(4, "{0}-{1}-{2}-{3}"), + //Message: SERVER_FROM,PLAYER_SENDER,PLAYER_TARGET + INVITE_PLAYER_REQUEST(3, "{0},{1},{2}"), + //Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE + INVITE_PLAYER_RESPONSE(4, "{0},{1},{2},{3}"), - //Message: SERVER_FROM-PLAYER_INITIATING-PARTY_SIZE-_CAN_JOIN_FULL - PREJOIN_SERVER_REQUEST(5, "{0}-{1}-{2}-{3}"), - //Message: PLAYER_INITIATING-RESPONSE-REASON-SERVER - PREJOIN_SERVER_RESPONSE(6, "{0}-{1}-{2}-[3}"), + //Message: SERVER_FROM,PLAYER_INITIATING,PARTY_SIZE,_CAN_JOIN_FULL + PREJOIN_SERVER_REQUEST(5, "{0},{1},{2},{3}"), + //Message: PLAYER_INITIATING,RESPONSE,REASON,SERVER + PREJOIN_SERVER_RESPONSE(6, "{0},{1},{2},[3}"), //Message: JSON Party PARTY_INFO(7, "{0}") @@ -42,7 +42,12 @@ public enum RedisMessageType public String format(String... args) { - return String.format(_contents, args); + String message = _contents; + for(int i = 0; i < args.length; i++) + { + message = message.replace("{" + i + "}", args[i]); + } + return message; } public String getContents() 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 562fe20f4..b764dba19 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java @@ -28,10 +28,9 @@ public abstract class Menu .setData(DyeColor.LIGHT_BLUE.getWoolData()) .build(), null); - protected static final Button PURCHASE_MORE_SLOTS = new IconButton(new ItemBuilder(Material.SKULL_ITEM) + protected static final Button PURCHASE_MORE_SLOTS = new IconButton(new ItemBuilder(Material.REDSTONE_BLOCK) .setTitle(C.cRed + C.Bold + "Locked!") .setLore(" ", C.cGray + "Purchase a rank @ mineplex.com/shop", C.cGray + "Purchasing a rank increases your", C.cGray + "party size to allow 10 people!") - .setPlayerHead("Mopplebottom") .build(), null); protected static final Button[] EMPTY = new Button[45]; 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 014e7d910..37a0610de 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 @@ -37,6 +37,10 @@ public class PartyMemberIcon extends PartyButton public void onClick(Player clicker, ItemStack clicked) { + if(!getParty().isOwnerKickMode()) + { + return; + } String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); UtilServer.getPluginManager().callEvent(new PartyMemberKickGUIEvent(getParty(), name, clicker)); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java index 48c0436df..24eb05c3a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java @@ -5,6 +5,7 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.menus.PartyInvitesMenu; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -30,6 +31,6 @@ public class DenyAllButton extends Button public void onClick(Player player, ClickType clickType) { getPlugin().getInviteManager().removeAll(player.getUniqueId()); - Menu.get(player.getUniqueId()).update(player); + new PartyInvitesMenu(getPlugin()).open(player); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java index 4b0e67ad0..f2402d537 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java @@ -21,8 +21,9 @@ public class FilterButton extends Button .setLore(" ", C.cGray + "Click to bring up an Anvil GUI", C.cGray + "where you type and filter", - C.cDGray + "Party invites that contain the", - C.cGray + "inputted characters") + C.cGray + "Party invites by their name", + " ", + C.cGreen + "Input \"Clear Filter\" to remove the filter") .build(); public FilterButton(PartyManager plugin) @@ -33,12 +34,13 @@ public class FilterButton extends Button public FilterButton(String filter, PartyManager plugin) { super(new ItemBuilder(Material.NAME_TAG) - .setTitle("Filter Invites") - .setLore(C.cWhite + "Active Filter: " + C.cGreen + filter, " ", + .setTitle(C.cYellow + "Filter Invites") + .setLore(" ", C.cWhite + "Active Filter: " + C.cGreen + filter, " ", C.cGray + "Click to bring up an Anvil GUI", C.cGray + "where you type and filter", - C.cDGray + "Party invites that contain the", - C.cGray + "inputted characters") + C.cGray + "Party invites by their name", + " ", + C.cGreen + "Input \"Clear Filter\" to remove the filter") .setGlow(true) .build(), plugin); } @@ -46,7 +48,7 @@ public class FilterButton extends Button @Override public void onClick(Player player, ClickType clickType) { - new InviteFilterMenu(getPlugin(), player, null); + new InviteFilterMenu(getPlugin(), player, null).openInventory(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java index e80a8433d..5d08d96ef 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java @@ -1,8 +1,42 @@ package mineplex.core.party.ui.button.tools.invite; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + /** * */ -public class InviteButton +public class InviteButton extends Button { + + private String _name; + + public InviteButton(String name, PartyManager plugin) + { + super(new ItemBuilder(Material.SKULL_ITEM) + .setTitle(C.cYellow + name) + .setLore(" ", C.cYellow + "Right-Click " + C.cGray + "to deny the invite", C.cYellow + "Left-Click " + C.cGray + "to accept the invite") + .setData((short) 3) + .setPlayerHead(name) + .build(), plugin); + _name = name; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if(clickType == ClickType.LEFT) + { + player.chat("/party accept " + _name); + } else if(clickType == ClickType.RIGHT) + { + player.chat("/party deny " + _name); + } + player.closeInventory(); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java index b857b5163..cf70be642 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java @@ -1,8 +1,44 @@ package mineplex.core.party.ui.button.tools.invite; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.InviteData; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import java.util.List; + /** * */ -public class NextPageButton +public class NextPageButton extends Button { + + private static final ItemStack ITEM = new ItemBuilder(Material.SIGN).setTitle(C.cYellow + "Next Page").build(); + + private final PartyInvitesMenu _menu; + + public NextPageButton(PartyInvitesMenu menu, PartyManager plugin) + { + super(ITEM, plugin); + _menu = menu; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _menu.setButton(45, new PrevPageButton(_menu, getPlugin())); + _menu.setCurrentPage(_menu.getCurrentPage() + 1); + List data = _menu.getDataForPage(_menu.getCurrentPage()); + for(int i = 0; i < data.size(); i++) + { + _menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin())); + } + _menu.update(player); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java index 05e5a0b4a..01c34624e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java @@ -1,8 +1,48 @@ package mineplex.core.party.ui.button.tools.invite; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.InviteData; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.button.IconButton; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import java.util.List; + /** * */ -public class PrevPageButton +public class PrevPageButton extends Button { + + private static final ItemStack ITEM = new ItemBuilder(Material.SIGN).setTitle(C.cYellow + "Previous Page").build(); + + private final PartyInvitesMenu _menu; + + public PrevPageButton(PartyInvitesMenu menu, PartyManager plugin) + { + super(ITEM, plugin); + _menu = menu; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _menu.setCurrentPage(_menu.getCurrentPage() - 1); + if(_menu.getCurrentPage() == 0) + { + _menu.setButton(45, new IconButton(new ItemStack(Material.AIR), getPlugin())); + } + List data = _menu.getDataForPage(_menu.getCurrentPage()); + for(int i = 0; i < data.size(); i++) + { + _menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin())); + } + _menu.update(player); + } } 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 7cb400541..dae9ec9a7 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 @@ -34,5 +34,6 @@ public class DisbandPartyButton extends Button return; } player.chat("/party disband"); + player.closeInventory(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java index f2ea127ef..95915dc84 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java @@ -19,7 +19,7 @@ public class SuggestPlayerButton extends PartyButton private static final ItemStack ITEM = new ItemBuilder(Material.BOOK_AND_QUILL) .setTitle(C.cYellow + "Suggest Player") - .setLore(" ", C.cWhite + "Suggest a player for the owner to invite") + .setLore(" ", C.cGray + "Suggest a player for the owner to invite") .build(); public SuggestPlayerButton(Party party, PartyManager plugin) 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 86c746ff9..9a94ebdbd 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 @@ -1,19 +1,42 @@ package mineplex.core.party.ui.menus; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.InviteData; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; import mineplex.core.party.ui.Menu; -import mineplex.core.party.ui.button.tools.invite.BackButton; -import mineplex.core.party.ui.button.tools.invite.DenyAllButton; -import mineplex.core.party.ui.button.tools.invite.FilterButton; +import mineplex.core.party.ui.button.IconButton; +import mineplex.core.party.ui.button.tools.invite.*; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.entity.Player; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + /** * */ public class PartyInvitesMenu extends Menu { + private final IconButton NO_INVITES = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) + .setData(DyeColor.RED.getWoolData()) + .setTitle(C.cRedB + "No Invites") + .build(), null); + + private final int SLOTS_PER_PAGE = 27; + private final int STARTING_SLOT = 18; + private int _currentPage; + private Map> _pagesOfData; + private List _data; + private String _filterBy; public PartyInvitesMenu(PartyManager plugin) @@ -30,16 +53,126 @@ public class PartyInvitesMenu extends Menu @Override protected Button[] setUp(Player player) { + boolean showFiltered = false; Button[] buttons = new Button[54]; buttons[0] = new BackButton(_plugin); - buttons[4] = new DenyAllButton(_plugin); - buttons[8] = new FilterButton(_plugin); - if(_filterBy == null || _filterBy.isEmpty()) + List all = (List) _plugin.getInviteManager().getAllInvites(player); + + if (all == null || all.isEmpty()) { + for (int i = 10; i < 44; i++) + { + buttons[i] = NO_INVITES; + } + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); return addPanes(buttons); } - return addPanes(buttons); + buttons[4] = new DenyAllButton(_plugin); + + if (_filterBy == null || _filterBy.isEmpty()) + { + buttons[8] = new FilterButton(_plugin); + } else + { + showFiltered = true; + buttons[8] = new FilterButton(_filterBy, _plugin); + } + + if (showFiltered) + { + all = all.stream().filter(inviteData -> inviteData.getInvitedTo().contains(_filterBy)).collect(Collectors.toList()); + } + + if (showFiltered && all.isEmpty()) + { + for (int i = 10; i < 44; i++) + { + buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) + .setData(DyeColor.RED.getWoolData()) + .setTitle(C.cRedB + "No Invites Found") + .setLore(" ", C.cGray + "The filter " + F.name(_filterBy) + " had no results.") + .build(), _plugin); + } + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + return addPanes(buttons); + } + + _data = all; + + if (all.size() > SLOTS_PER_PAGE) + { + int pagesNeeded = 0; + int size = all.size(); + while (size > SLOTS_PER_PAGE) + { + pagesNeeded++; + size -= SLOTS_PER_PAGE; + } + buttons[53] = new NextPageButton(this, _plugin); + + _pagesOfData = Maps.newHashMap(); + + int page = 0; + + List newData = Lists.newArrayList(); + int total = all.size(); + for (int i = 0; i < pagesNeeded; i++) + { + for (int s = 0; s < total; s++) + { + newData.add(all.remove(i)); + if (i > SLOTS_PER_PAGE) + { + _pagesOfData.put(page++, newData); + newData.clear(); + total -= SLOTS_PER_PAGE; + break; + } + } + } + //Add pages + } else + { + for (int i = 0; i < all.size(); i++) + { + String to = all.get(i).getInvitedTo(); + buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin); + } + } + + + return buttons; + } + + public void setButton(int slot, Button button) + { + getButtons()[slot] = button; + } + + public List getDataForPage(int page) + { + return _pagesOfData.get(page); + } + + public int getStartingSlot() + { + return STARTING_SLOT; + } + + public int getCurrentPage() + { + return _currentPage; + } + + public void setCurrentPage(int currentPage) + { + _currentPage = currentPage; + } + + public List getData() + { + return _data; } } 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 d1f7a29fa..dd40a1e3f 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 @@ -54,6 +54,15 @@ public class PartyOwnerMenu extends Menu buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i), _party); } + if(_party.getSize() == 5) + { + for(int i = 29; i < 34; i++) + { + buttons[i] = PURCHASE_MORE_SLOTS; + } + } + + return addPanes(buttons); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java index fa773ab32..6e7ad24ab 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java @@ -21,6 +21,10 @@ public class InviteFilterMenu extends PlayerInputActionMenu public void inputReceived(String name) { _player.closeInventory(); + if(name.equalsIgnoreCase("Clear Filter")) + { + name = null; + } new PartyInvitesMenu((PartyManager) _plugin, name).open(_player); } } From df53021f7c67dc87e1281bc5e33e016c0a9d75da Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 23 Jun 2016 02:56:42 -0500 Subject: [PATCH 21/53] Fix Party Redis. Improve Party UI. General testing and fixing. (Funny enough, again. --- .../mineplex/core/party/manager/PartyRedisManager.java | 6 +----- .../src/mineplex/core/party/redis/PartyRedisListener.java | 2 -- .../core/party/ui/button/tools/invite/NextPageButton.java | 5 +++++ .../mineplex/core/party/ui/menus/PartyInvitesMenu.java | 8 ++++++++ 4 files changed, 14 insertions(+), 7 deletions(-) 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 df9652f17..2cdb2abdf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -49,7 +49,6 @@ public class PartyRedisManager _channel = CHANNEL_BASE + "-" + serverName; plugin.runAsync(() -> { - System.out.println("Redis Started on " + _channel); try (Jedis jedis = readPool.getResource()) { jedis.subscribe(new PartyRedisListener(this), _channel); @@ -60,8 +59,6 @@ public class PartyRedisManager public void publish(String server, RedisMessageType messageType, String... args) { - System.out.println("Sending redis message: " + messageType.name() + " (" + Arrays.toString(args) + ")"); - System.out.println("Sending on channel: " + CHANNEL_BASE + "-" + server); _plugin.runAsync(() -> { try (Jedis jedis = _writePool.getResource()) { @@ -72,9 +69,8 @@ public class PartyRedisManager public void handle(RedisMessageType messageType, String message) { - System.out.println("Received packet: " + messageType.name() + " (" + message + ")"); String[] contents = message.split(","); - if (contents.length < 3) + if (contents.length < 3 && messageType != RedisMessageType.PARTY_INFO) { return; } 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 3ddfc98ac..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,8 +19,6 @@ public class PartyRedisListener extends JedisPubSub @Override public void onMessage(String channel, String message) { - System.out.println("Received Message on " + channel); - System.out.println("Message: " + message); RedisMessageType type = RedisMessageType.valueOf(message.split(":")[0].toUpperCase()); _redisManager.handle(type, message.split(":")[1]); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java index cf70be642..2ffffff9f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java @@ -5,6 +5,7 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.InviteData; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.button.IconButton; import mineplex.core.party.ui.menus.PartyInvitesMenu; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -34,6 +35,10 @@ public class NextPageButton extends Button { _menu.setButton(45, new PrevPageButton(_menu, getPlugin())); _menu.setCurrentPage(_menu.getCurrentPage() + 1); + if(_menu.getCurrentPage() == _menu.getPagesNeeded()) + { + _menu.setButton(53, new IconButton(new ItemStack(Material.AIR), getPlugin())); + } List data = _menu.getDataForPage(_menu.getCurrentPage()); for(int i = 0; i < data.size(); i++) { 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 9a94ebdbd..d3bd47636 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 @@ -34,6 +34,8 @@ public class PartyInvitesMenu extends Menu private final int SLOTS_PER_PAGE = 27; private final int STARTING_SLOT = 18; private int _currentPage; + private int _pagesNeeded; + private Map> _pagesOfData; private List _data; @@ -112,6 +114,7 @@ public class PartyInvitesMenu extends Menu } buttons[53] = new NextPageButton(this, _plugin); + _pagesNeeded = pagesNeeded; _pagesOfData = Maps.newHashMap(); int page = 0; @@ -175,4 +178,9 @@ public class PartyInvitesMenu extends Menu { return _data; } + + public int getPagesNeeded() + { + return _pagesNeeded; + } } From 33cce620beea5441990f390dfe3d657f508af864 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 23 Jun 2016 03:11:45 -0500 Subject: [PATCH 22/53] Update UI and fix typos --- .../src/mineplex/core/party/PartyEventListener.java | 6 +++++- .../src/mineplex/core/party/PartyManager.java | 9 +++++++++ .../mineplex/core/party/ui/button/PartyMemberIcon.java | 1 + .../party/ui/button/tools/owner/KickPlayerButton.java | 9 +++++---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java index b72ebb424..a65d4bed5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -4,6 +4,7 @@ import mineplex.core.common.Rank; import mineplex.core.party.event.PartyMemberKickGUIEvent; import mineplex.core.party.event.PartyTransferOwnerEvent; import mineplex.core.party.manager.PartyRedisManager; +import mineplex.core.party.ui.Menu; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -93,7 +94,10 @@ public class PartyEventListener implements Listener @EventHandler public void onKick(PartyMemberKickGUIEvent event) { - _plugin.removeFromParty(Bukkit.getPlayerExact(event.getPlayerClicked()), PartyRemoveReason.KICKED); + Player clicked = Bukkit.getPlayerExact(event.getPlayerClicked()); + Lang.REMOVED.send(clicked); + _plugin.removeFromParty(clicked, PartyRemoveReason.KICKED); + Menu.get(event.getOwner().getUniqueId()).update(event.getOwner()); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index 2e54d14e6..a2568119b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -9,6 +9,7 @@ import mineplex.core.party.command.PartyCommand; import mineplex.core.party.manager.PartyInviteManager; import mineplex.core.party.manager.PartyJoinManager; import mineplex.core.party.manager.PartyRedisManager; +import mineplex.core.party.ui.Menu; import mineplex.core.party.ui.MenuListener; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; @@ -95,6 +96,14 @@ public class PartyManager extends MiniPlugin Player player = Bukkit.getPlayer(uuid); party.getMembers().remove(player.getName()); party.onPlayerRemove(player.getName(), reason); + if(player.getOpenInventory() != null) + { + if (Menu.get(player.getUniqueId()) != null) + { + player.closeInventory(); + Menu.remove(player.getUniqueId()); + } + } int size = party.getMembers().size(); if(size <= 1) { 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 37a0610de..4555bc914 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 @@ -8,6 +8,7 @@ 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.Menu; import mineplex.core.party.ui.button.tools.PartyButton; import org.bukkit.ChatColor; import org.bukkit.DyeColor; 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 a8c54a1f6..0565f7c84 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,6 +1,7 @@ package mineplex.core.party.ui.button.tools.owner; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.Party; import mineplex.core.party.ui.Menu; @@ -18,14 +19,14 @@ 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") + .setLore(" ", F.elem("Right-Click") + " to enter " + C.cGreen + "Kick Mode", + C.cGray + "While activated, click on a player's head", C.cGray + "to remove them from 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") + .setLore(" ", F.elem("Right-Click") + " to leave " + C.cRed + "Kick Mode", + C.cGray + "While activated, click on a player's head", C.cGray + "to remove them from the party") .setGlow(true) .build(); From a29b22b8be9ac15c09ee0e3a9fef6958752ef1c3 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 23 Jun 2016 03:12:49 -0500 Subject: [PATCH 23/53] Undo comments. --- .../src/mineplex/hub/modules/NewsManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java index 5654f3b28..1172751de 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 From ce1aab5e112f202d0bef1f037944fa2f2bef8b15 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 23 Jun 2016 21:53:12 -0500 Subject: [PATCH 24/53] Fixes and changes --- .../core/anvilMenu/PlayerInputActionMenu.java | 5 +- .../core/anvilMenu/player/PlayerNameMenu.java | 8 ++ .../src/mineplex/core/party/Lang.java | 4 +- .../src/mineplex/core/party/Party.java | 8 +- .../core/party/PartyEventListener.java | 37 +++++++++- .../core/party/command/PartyCommand.java | 66 +++++++++++++---- .../party/manager/PartyInviteManager.java | 25 +++++-- .../core/party/manager/PartyJoinManager.java | 7 +- .../core/party/manager/PartyRedisManager.java | 9 ++- .../core/party/redis/PartyRedisListener.java | 2 + .../core/party/redis/RedisMessageType.java | 2 +- .../core/party/ui/button/PartyMemberIcon.java | 2 +- .../button/tools/owner/AddPlayerButton.java | 2 +- .../tools/owner/DisbandPartyButton.java | 2 +- .../button/tools/owner/KickPlayerButton.java | 8 +- .../tools/view/SuggestPlayerButton.java | 2 +- .../menus/input/PartyTransferOwnerMenu.java | 2 +- .../menus/input/PlayerSuggestPlayerMenu.java | 15 ++-- .../src/mineplex/core/portal/Portal.java | 74 +++++++------------ .../core/portal/ServerTransferEvent.java | 15 ++++ 20 files changed, 200 insertions(+), 95 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java index 5a28822c3..2976e2b00 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java @@ -58,7 +58,10 @@ public abstract class PlayerInputActionMenu implements Listener public void unregisterListener() { - _currentInventory.clear(); + if(_currentInventory != null) + { + _currentInventory.clear(); + } HandlerList.unregisterAll(this); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java index 243ed51c5..ab4999c54 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java @@ -6,10 +6,13 @@ import mineplex.core.anvilMenu.PlayerInputActionMenu; import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.Party; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; +import static net.minecraft.server.v1_8_R3.PotionBrewer.n; + /** * A wrapped menu that handles looking for players specifically. */ @@ -31,6 +34,11 @@ public abstract class PlayerNameMenu extends PlayerInputActionMenu @Override public void inputReceived(String name) { + if(Bukkit.getPlayer(name) != null) + { + onSuccess(Bukkit.getPlayer(name).getName()); + return; + } _clientManager.checkPlayerName(_player, _itemName, result -> { _searching = false; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java index 219a38ddb..0871da217 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -17,7 +17,7 @@ public enum Lang 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_RECEIVED("You have been invited to {0}'s party! You have 60 seconds to reply."), INVITE_ACCEPT("{0} has joined the party."), INVITE_DENY("{0} declined your invite."), INVITE_EXPIRED("{0} did not respond in time."), @@ -36,7 +36,7 @@ public enum Lang 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."), + ALREADY_IN("Error: You are already in a party!"), 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!"), diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 7f44b8250..5c1733378 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -91,6 +91,7 @@ public class Party { Player bukkitPlayer = Bukkit.getPlayerExact(player); Lang.DISBANDED.send(bukkitPlayer); + bukkitPlayer.closeInventory(); return; } if(_members.size() <= 0) @@ -100,7 +101,7 @@ public class Party if(reason == PartyRemoveReason.LEFT) { Lang.REMOVE_PLAYER.send(this, player); - if(player.equalsIgnoreCase(_owner)) + if(player.equalsIgnoreCase(_owner) && _members.size() > 1) { _owner = _members.get(0); Lang.TRANSFER_OWNER.send(this, player, _owner); @@ -113,7 +114,10 @@ public class Party { return; } - Lang.REMOVE_PLAYER_KICK.send(this, player); + if(reason == PartyRemoveReason.KICKED) + { + Lang.REMOVE_PLAYER_KICK.send(this, player); + } } public boolean isOwnerKickMode() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java index a65d4bed5..de43b50a3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -5,6 +5,7 @@ import mineplex.core.party.event.PartyMemberKickGUIEvent; import mineplex.core.party.event.PartyTransferOwnerEvent; import mineplex.core.party.manager.PartyRedisManager; import mineplex.core.party.ui.Menu; +import mineplex.core.portal.ServerTransferEvent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -35,7 +36,7 @@ public class PartyEventListener implements Listener String partyName = _plugin.getInviteManager().getPartyWaiting(player.getUniqueId()); - if(partyName == null) + if (partyName == null) { return; } @@ -44,13 +45,13 @@ public class PartyEventListener implements Listener Player bukkitPlayer = Bukkit.getPlayerExact(partyName); - if(party == null) + if (party == null) { party = new Party(partyName); int size = 5; - if(bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().isDonor()) + if (bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA)) { size = 10; } @@ -59,6 +60,8 @@ public class PartyEventListener implements Listener _plugin.addParty(party); } + _plugin.getInviteManager().cancelTask(player.getUniqueId()); + _plugin.addToParty(Bukkit.getPlayerExact(partyName), party); _plugin.addToParty(player, party); @@ -100,4 +103,32 @@ public class PartyEventListener implements Listener Menu.get(event.getOwner().getUniqueId()).update(event.getOwner()); } + @EventHandler + public void onTransfer(ServerTransferEvent event) + { + Player player = event.getPlayer(); + Party party = _plugin.getParty(player); + + if (party == null) + { + return; + } + + if(event.isDraggedByParty()) + { + return; + } + + event.setCancel(true); + + if (!party.getOwner().equalsIgnoreCase(player.getName())) + { + Lang.NOT_OWNER_SERVER.send(player); + return; + } + + _plugin.getJoinManager().requestServerJoin(event.getServer(), party); + + } + } 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 7a062b2ff..33dee7efd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -29,25 +29,47 @@ public class PartyCommand extends CommandBase private final String[] HELP = { F.main("Party", "Party Commands (Click the command!)"), - help("help", "Shows this help screen"), + //help("help", "Shows this help screen"), help("", "Brings up the Party GUI"), help("invite ", "Invite a player to your party."), - help("accept ", "Accept an invite to a party."), - help("deny ", "Deny an invite to a party."), - help("leave", "Leave your current party"), - help("kick ", "Kick a player from your party."), - help("disband", "Disband your party."), + //help("accept ", "Accept an invite to a party."), + //help("deny ", "Deny an invite to a party."), + //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 to your party." }; public PartyCommand(PartyManager plugin) { - super(plugin, Rank.ALL, "party"); + super(plugin, Rank.ALL, "party", "z"); } @Override public void Execute(Player caller, String[] args) { + if(_aliasUsed.equalsIgnoreCase("z")) + { + caller.sendMessage(F.main("Party", "That command is no longer allowed! Please use \"/party\"")); + caller.sendMessage(HELP[0]); + //Show this menu + for(int i = 1; i < HELP.length; i++) + { + String s = HELP[i]; + String command = ChatColor.stripColor(s); + ChildJsonMessage jsonMessage = new ChildJsonMessage(s); + if ((i + 1) == HELP.length) + { + command = "#"; + } else + { + command = command.substring(command.indexOf("/"), command.indexOf("-") - 1); + } + jsonMessage.click(ClickEvent.SUGGEST_COMMAND, command); + jsonMessage.sendToPlayer(caller); + } + return; + } if (args.length == 0) { Party party = Plugin.getParty(caller); @@ -131,7 +153,18 @@ public class PartyCommand extends CommandBase Player possible = Bukkit.getPlayerExact(target); Party party = Plugin.getParty(caller); - boolean can = Bukkit.getMaxPlayers() < Plugin.getPlugin().getServer().getOnlinePlayers().size(); + boolean can = Bukkit.getMaxPlayers() >= Plugin.getPlugin().getServer().getOnlinePlayers().size(); + if(!can) + { + Lang.SERVER_FULL.send(caller); + return; + } + + if(!Plugin.getPreferencesManager().Get(target).PartyRequests) + { + caller.sendMessage(F.main("Party> ", F.name(target) + " is not accepting invites at this time.")); + return; + } //Same Server if (possible != null) @@ -166,11 +199,7 @@ public class PartyCommand extends CommandBase Lang.PARTY_FULL.send(caller); return; } - if(!can) - { - Lang.SERVER_FULL.send(caller); - return; - } + Lang.SUCCESS_INVITE.send(party, caller.getName(), target); } @@ -188,6 +217,12 @@ public class PartyCommand extends CommandBase private void handleInviteResponse(Player caller, String target, boolean accept) { + if(Plugin.getParty(caller) != null) + { + Lang.ALREADY_IN.send(caller); + return; + } + PartyInviteManager inviteManager = Plugin.getInviteManager(); if (!inviteManager.isInvitedTo(caller.getUniqueId(), target)) @@ -196,7 +231,10 @@ public class PartyCommand extends CommandBase Lang.NOT_INVITED.send(caller, target); return; } - caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party."); + if(!accept) + { + caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party."); + } inviteManager.respondToInvite(caller, target, accept); } 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 50180b254..3632fccd1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -2,6 +2,7 @@ package mineplex.core.party.manager; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.party.InviteData; @@ -17,6 +18,7 @@ import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import java.util.Collection; import java.util.List; @@ -53,6 +55,7 @@ public class PartyInviteManager private final Map _invitedBy = Maps.newHashMap(); private final Map _awaitingJoin = Maps.newHashMap(); private final Map _players = Maps.newHashMap(); + private final Map _tasks = Maps.newHashMap(); private final PartyManager _plugin; private final PartyRedisManager _partyRedisManager; @@ -70,6 +73,7 @@ public class PartyInviteManager InviteData data = remove(party, player.getUniqueId()); _players.remove(player.getUniqueId()); + cancelTask(player.getUniqueId()); if(possible != null) { @@ -89,7 +93,7 @@ public class PartyInviteManager { newParty = new Party(possible.getName()); int size = 5; - if(_plugin.getClientManager().Get(possible).GetRank().isDonor()) + if(_plugin.getClientManager().Get(possible).GetRank().has(Rank.ULTRA)) { size = 10; } @@ -209,7 +213,7 @@ public class PartyInviteManager public void inviteTo(UUID player, String invitedBy, String party, String server) { addToInvite(player, invitedBy, party, System.currentTimeMillis(), server); - new BukkitRunnable() + _tasks.put(player, new BukkitRunnable() { @Override public void run() @@ -229,7 +233,7 @@ public class PartyInviteManager } sendExpired(data.getServerFrom(), party, playerName, player); } - }.runTaskLater(_plugin.getPlugin(), 20 * 60); + }.runTaskLater(_plugin.getPlugin(), 20 * 60)); } /** @@ -282,6 +286,15 @@ public class PartyInviteManager return temp; } + public void cancelTask(UUID player) + { + BukkitTask task = _tasks.remove(player); + if(task != null) + { + task.cancel(); + } + } + public Collection getAllInvites(Player player) { return _activeInvites.get(player.getUniqueId()); @@ -312,14 +325,14 @@ public class PartyInviteManager public void sendAcceptOrDeny(Player player, String arg) { - TextComponent textComponent = new TextComponent(F.main("Party", "Click one: ")); + TextComponent textComponent = new TextComponent(F.main("Party", "Reply: ")); TextComponent accept = new TextComponent("ACCEPT"); accept.setColor(ChatColor.GREEN); accept.setBold(true); accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party accept " + arg)); accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ - new TextComponent("Click to run /party accept " + arg) + new TextComponent("Click to join " + F.name(arg) + "'s party") })); textComponent.addExtra(accept); @@ -330,7 +343,7 @@ public class PartyInviteManager deny.setBold(true); deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party deny " + arg)); deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ - new TextComponent("Click to run /party deny " + arg) + new TextComponent("Click to decline joining " + F.name(arg) + "'s party") })); textComponent.addExtra(deny); 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 6f4abc7d7..06d68e371 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -20,7 +20,8 @@ public class PartyJoinManager 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!")), + SUCCESS(""); private String _message; @@ -75,7 +76,7 @@ public class PartyJoinManager } } - _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, "yes", "none"); + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, "yes", JoinResponseReason.SUCCESS.name(), "none"); } public void handleJoinResponse(String playerSender, String response, String server, JoinResponseReason reason) @@ -101,7 +102,7 @@ public class PartyJoinManager { player.leaveVehicle(); player.eject(); - _plugin.getPortal().sendPlayerToServer(player1, server); + _plugin.getPortal().sendPlayerToServer(player1, server, true); }); } 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 2cdb2abdf..312823c95 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -49,16 +49,17 @@ public class PartyRedisManager _channel = CHANNEL_BASE + "-" + serverName; plugin.runAsync(() -> { + System.out.println("Listening on " + _channel); try (Jedis jedis = readPool.getResource()) { - jedis.subscribe(new PartyRedisListener(this), _channel); - jedis.subscribe(new PartyRedisListener(this), FIND_PLAYERS_CHANNEL); + jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL); } }); } public void publish(String server, RedisMessageType messageType, String... args) { + System.out.println("Sending " + messageType.name() + " [" + Arrays.toString(args) + "] to " + CHANNEL_BASE + "-" + server); _plugin.runAsync(() -> { try (Jedis jedis = _writePool.getResource()) { @@ -69,6 +70,7 @@ public class PartyRedisManager public void handle(RedisMessageType messageType, String message) { + System.out.println("Message got: " + messageType.name() + " [" + message + "]"); String[] contents = message.split(","); if (contents.length < 3 && messageType != RedisMessageType.PARTY_INFO) { @@ -150,11 +152,12 @@ public class PartyRedisManager { return; } - senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player))); + senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player) + ".")); } }.runTaskLater(_plugin.getPlugin(), 20L * 4)); _plugin.runAsync(() -> { + System.out.println("Locating player " + player + "..."); try (Jedis jedis = _writePool.getResource()) { jedis.publish(FIND_PLAYERS_CHANNEL, RedisMessageType.PLAYER_FIND_REQUEST.format(_serverName, player, sender)); 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 6941a03cb..d10bb672c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -19,6 +19,8 @@ public class PartyRedisListener extends JedisPubSub @Override public void onMessage(String channel, String message) { + System.out.println("Message on " + channel); + System.out.println("Message contents; " + 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 3e8e2a71e..b17073b65 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,7 @@ 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}") 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 4555bc914..a57a25ba3 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 @@ -27,7 +27,7 @@ public class PartyMemberIcon extends PartyButton { super(new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3) .setTitle(C.cYellow + player) - .setGlow(owner) + .setLore(owner ? C.cGreen + "Leader" : "") .setPlayerHead(player).build(), party, null); } 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 64ae467fe..2d1e5c3be 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 @@ -19,7 +19,7 @@ public class AddPlayerButton extends PartyButton private static final ItemStack ITEM = new ItemBuilder(Material.SIGN) .setTitle(C.cYellow + "Invite a Player") - .setLore(" ", C.cGray + "Brings up the Inviting Anvil!", C.cGray + "Simply type a players name", C.cGray + "and click the paper to invite him") + .setLore(" ", C.cGray + "Brings up the Inviting Anvil!", C.cGray + "Simply type a player's name", C.cGray + "and click the paper to invite him") .build(); public AddPlayerButton(PartyManager plugin, Party party) 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 dae9ec9a7..4ba9ba000 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 @@ -18,7 +18,7 @@ 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.") + .setLore(" ", C.cGray + "This will erase your party!", C.cRed + "Shift-Right-Click" + C.cGray + " to disband.") .build(); public DisbandPartyButton(PartyManager plugin) 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 0565f7c84..654bb2599 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 @@ -18,13 +18,13 @@ public class KickPlayerButton extends PartyButton { private static final ItemStack ITEM_OFF = new ItemBuilder(Material.IRON_AXE) - .setTitle(C.cYellow + "Kick Player's") + .setTitle(C.cYellow + "Kick Players") .setLore(" ", F.elem("Right-Click") + " to enter " + C.cGreen + "Kick Mode", C.cGray + "While activated, click on a player's head", C.cGray + "to remove them from the party") .build(); private static final ItemStack ITEM_ON = new ItemBuilder(Material.IRON_AXE) - .setTitle(C.cYellow + "Kick Player's") + .setTitle(C.cYellow + "Kick Players") .setLore(" ", F.elem("Right-Click") + " to leave " + C.cRed + "Kick Mode", C.cGray + "While activated, click on a player's head", C.cGray + "to remove them from the party") .setGlow(true) @@ -39,6 +39,10 @@ public class KickPlayerButton extends PartyButton @Override public void onClick(Player player, ClickType clickType) { + if(clickType != ClickType.RIGHT) + { + return; + } getParty().setOwnerKickMode(!getParty().isOwnerKickMode()); if (getParty().isOwnerKickMode()) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java index 95915dc84..ac093ebcd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java @@ -30,6 +30,6 @@ public class SuggestPlayerButton extends PartyButton @Override public void onClick(Player player, ClickType clickType) { - new PlayerSuggestPlayerMenu(getPlugin(), player).openInventory(); + new PlayerSuggestPlayerMenu(getPlugin(), player, getParty()).openInventory(); } } 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 index 341ce26f9..c5aeecc4a 100644 --- 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 @@ -17,7 +17,7 @@ public class PartyTransferOwnerMenu extends PlayerNameMenu public PartyTransferOwnerMenu(PartyManager partyManager, Player player, Party party) { - super(partyManager, partyManager.getClientManager(), player, null); + super(partyManager, partyManager.getClientManager(), player, party); _partyManager = partyManager; } 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 9e1561674..8d26b5116 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 @@ -6,6 +6,7 @@ import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.HoverEvent; 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.anvilMenu.PlayerInputActionMenu; @@ -19,21 +20,25 @@ public class PlayerSuggestPlayerMenu extends PlayerNameMenu { - public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player) + public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party) { - super(partyManager, partyManager.getClientManager(), player, null); + super(partyManager, partyManager.getClientManager(), player, party); } - @Override public void onSuccess(String name) { + if(_party == null || _party.getOwner() == null) + { + Lang.NO_PARTY.send(_player); + return; + } Player player = Bukkit.getPlayerExact(_party.getOwner()); _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)) + ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Click ")); + message.add(F.link("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"); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java index d5a24913f..813744f5d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java @@ -93,37 +93,33 @@ public class Portal extends MiniPlugin final boolean override = serverName.equalsIgnoreCase("Lobby"); final Rank playerRank = _clientManager.Get(player).GetRank(); - + + if(event.isCancel() && !event.isDraggedByParty()) + { + return; + } + if (override) { sendPlayer(player, serverName); } + else { - runAsync(new Runnable() - { - public void run() - { - final MinecraftServer server = _repository.getServerStatus(serverName); - - if (server == null) - return; - - Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable() + runAsync(() -> { + final MinecraftServer server = _repository.getServerStatus(serverName); + + if (server == null) + return; + + Bukkit.getServer().getScheduler().runTask(_plugin, () -> { + if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.has(Rank.ULTRA)) { - public void run() - { - if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.has(Rank.ULTRA)) - { - sendPlayer(player, serverName); - } - else - UtilPlayer.message( - player, - F.main(getName(), C.cGold + serverName + C.cRed + " is full!")); - } - }); - } + sendPlayer(player, serverName); + } + else + UtilPlayer.message(player, F.main(getName(), C.cGold + serverName + C.cRed + " is full!")); + }); }); } } @@ -140,20 +136,10 @@ public class Portal extends MiniPlugin if (callback == null) return; - Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() - { - public void run() - { - final boolean serverExists = ServerManager.getServerRepository(_region).serverExists(serverName); - - Bukkit.getScheduler().runTask(getPlugin(), new Runnable() - { - public void run() - { - callback.run(serverExists); - } - }); - } + Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), () -> { + final boolean serverExists = ServerManager.getServerRepository(_region).serverExists(serverName); + + Bukkit.getScheduler().runTask(getPlugin(), () -> callback.run(serverExists)); }); } @@ -205,16 +191,8 @@ public class Portal extends MiniPlugin player.sendPluginMessage(getPlugin(), "BungeeCord", b.toByteArray()); _connectingPlayers.add(player.getName()); - getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() - { - public void run() - { - _connectingPlayers.remove(player.getName()); - } - }, 20L); + getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> _connectingPlayers.remove(player.getName()), 20L); - UtilPlayer.message( - player, - F.main(getName(), "You have been sent from " + C.cGold + _serverName + C.cGray + " to " + C.cGold + serverName)); + UtilPlayer.message(player, F.main(getName(), "You have been sent from " + C.cGold + _serverName + C.cGray + " to " + C.cGold + serverName)); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransferEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransferEvent.java index 94262b8d7..e2dc4c667 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransferEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransferEvent.java @@ -11,6 +11,7 @@ public class ServerTransferEvent extends Event private Player _player; private String _server; private boolean _draggedByParty; + private boolean _cancel; public ServerTransferEvent(Player player, String server, boolean draggedByParty) { @@ -24,6 +25,11 @@ public class ServerTransferEvent extends Event return _draggedByParty; } + public void setDraggedByParty(boolean draggedByParty) + { + _draggedByParty = draggedByParty; + } + public HandlerList getHandlers() { return _handlers; @@ -44,4 +50,13 @@ public class ServerTransferEvent extends Event return _server; } + public boolean isCancel() + { + return _cancel; + } + + public void setCancel(boolean cancel) + { + _cancel = cancel; + } } From eeaf9fa49a8779ae1b2a4e5baaabd4dfb742f579 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 23 Jun 2016 23:24:50 -0500 Subject: [PATCH 25/53] Fix chat in arcade --- .../arcade/managers/chat/GameChatManager.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) 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 f182d6ecd..1b34477fc 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 @@ -24,6 +24,9 @@ import java.text.DecimalFormat; import java.util.*; import java.util.stream.Collectors; +import static mineplex.database.routines.Test.playerName; +import static sun.audio.AudioPlayer.player; + public class GameChatManager implements Listener { @@ -119,31 +122,31 @@ public class GameChatManager implements Listener rankStr = rank.getTag(true, true) + " " + C.Reset; } + //Party Chat if (event.getMessage().charAt(0) == '#') { - //Party Chat Party party = _manager.getPartyManager().getParty(sender); - if (party != null) { event.getRecipients().clear(); - rankStr = C.cDPurpleB + "Party " + C.Reset; - event.setMessage(event.getMessage().substring(1, event.getMessage().length())); - event.setFormat(levelStr + rankStr + C.cWhiteB + senderName + " " + C.cPurple + "%2$s"); + event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s"); - format = event.getFormat().split(rankStr)[0]; - 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.getMembers().stream().map(Bukkit::getPlayerExact).collect(Collectors.toList()))) + for (String member : party.getMembers()) { - event.setCancelled(true); - } + Player other = UtilPlayer.searchExact(member); - return; + if (other != null) + event.getRecipients().add(other); + } } + else + { + UtilPlayer.message(sender, F.main("Party", "You are not in a Party.")); + event.setCancelled(true); + } + return; } event.setFormat(levelStr + rankStr + senderName + " " + C.cWhite + "%2$s"); From c204562eb30cc39e24fc53e27b62504667f0a965 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 23 Jun 2016 23:25:26 -0500 Subject: [PATCH 26/53] Fix cross server invites / joining servers. --- .../core/party/command/PartyCommand.java | 2 +- .../core/party/manager/PartyJoinManager.java | 13 ++-- .../core/party/manager/PartyRedisManager.java | 59 ++++++++++++++----- .../core/party/redis/PartyRedisListener.java | 13 ++-- .../core/party/redis/RedisMessageType.java | 3 +- 5 files changed, 59 insertions(+), 31 deletions(-) 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 33dee7efd..195ed59e0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -34,7 +34,7 @@ public class PartyCommand extends CommandBase help("invite ", "Invite a player to your party."), //help("accept ", "Accept an invite to a party."), //help("deny ", "Deny an invite to a party."), - //help("leave", "Leave your current party"), + 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 to your party." 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 06d68e371..78161f58a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -70,13 +70,13 @@ public class PartyJoinManager //Max number of people on. if (!canJoinFull) { - _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, - initiator, "no", JoinResponseReason.CANNOT_JOIN_FULL.name(), _plugin.getServerName()); + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), "no", _plugin.getServerName()); return; } } - _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, "yes", JoinResponseReason.SUCCESS.name(), "none"); + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), "yes", _plugin.getServerName()); + } public void handleJoinResponse(String playerSender, String response, String server, JoinResponseReason reason) @@ -98,12 +98,7 @@ public class PartyJoinManager } party.sendMessage(F.main("Party", "Transferring servers...")); _plugin.getRedisManager().sendPartyInfo(server, party); - party.getMembers().stream().map(Bukkit::getPlayer).forEach(player1 -> - { - player.leaveVehicle(); - player.eject(); - _plugin.getPortal().sendPlayerToServer(player1, server, true); - }); + } } 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 312823c95..e742f878b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -22,9 +22,16 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.UUID; +import static mineplex.core.party.redis.RedisMessageType.INVITE_PLAYER_REQUEST; +import static mineplex.core.party.redis.RedisMessageType.PARTY_INFO; +import static net.minecraft.server.v1_8_R3.PotionBrewer.c; +import static net.minecraft.server.v1_8_R3.PotionBrewer.f; +import static sun.audio.AudioPlayer.player; + /** * Redis system for Parties */ @@ -49,7 +56,6 @@ public class PartyRedisManager _channel = CHANNEL_BASE + "-" + serverName; plugin.runAsync(() -> { - System.out.println("Listening on " + _channel); try (Jedis jedis = readPool.getResource()) { jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL); @@ -59,20 +65,23 @@ public class PartyRedisManager public void publish(String server, RedisMessageType messageType, String... args) { - System.out.println("Sending " + messageType.name() + " [" + Arrays.toString(args) + "] to " + CHANNEL_BASE + "-" + server); _plugin.runAsync(() -> { try (Jedis jedis = _writePool.getResource()) { - jedis.publish(CHANNEL_BASE + "-" + server, messageType.name() + ":" + messageType.format(args)); + jedis.publish(CHANNEL_BASE + "-" + server, messageType.name() + "@" + messageType.format(args)); } }); } public void handle(RedisMessageType messageType, String message) { - System.out.println("Message got: " + messageType.name() + " [" + message + "]"); + if (messageType == PARTY_INFO) + { + handlePartyInfo(message); + return; + } String[] contents = message.split(","); - if (contents.length < 3 && messageType != RedisMessageType.PARTY_INFO) + if (contents.length < 3) { return; } @@ -81,10 +90,6 @@ public class PartyRedisManager String third = contents[2]; switch (messageType) { - case PARTY_INFO: - handlePartyInfo(first); - break; - case INVITE_PLAYER_REQUEST: _plugin.getInviteManager().handleInviteRequest(second, third, first); break; @@ -101,7 +106,7 @@ public class PartyRedisManager 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(), third); break; case PLAYER_FIND_RESPONSE: @@ -112,6 +117,7 @@ public class PartyRedisManager { task.cancel(); } + Player inviter = Bukkit.getPlayerExact(contents[3]); if (_plugin.getInviteManager().isInvitedTo(uuid, inviter.getName())) { @@ -126,7 +132,7 @@ public class PartyRedisManager Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second); } _plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName()); - publish(first, RedisMessageType.INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); + publish(first, INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); break; case PREJOIN_SERVER_REQUEST: @@ -134,7 +140,7 @@ public class PartyRedisManager break; case PREJOIN_SERVER_RESPONSE: - _plugin.getJoinManager().handleJoinResponse(first, second, contents[3], JoinResponseReason.valueOf(third.toUpperCase())); + _plugin.getJoinManager().handleJoinResponse(first, third, contents[3], JoinResponseReason.valueOf(second.toUpperCase())); break; } } @@ -150,14 +156,19 @@ public class PartyRedisManager Player senderPlayer = Bukkit.getPlayerExact(sender); if (senderPlayer == null) { + cancel(); + return; + } + if(Bukkit.getPlayerExact(player) != null) + { + cancel(); return; } senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player) + ".")); } - }.runTaskLater(_plugin.getPlugin(), 20L * 4)); + }.runTaskLater(_plugin.getPlugin(), 20L * 10)); _plugin.runAsync(() -> { - System.out.println("Locating player " + player + "..."); try (Jedis jedis = _writePool.getResource()) { jedis.publish(FIND_PLAYERS_CHANNEL, RedisMessageType.PLAYER_FIND_REQUEST.format(_serverName, player, sender)); @@ -167,9 +178,15 @@ public class PartyRedisManager public void sendPartyInfo(String server, Party party) { - publish(server, RedisMessageType.PARTY_INFO, GSON.toJson(party)); + publish(server, PARTY_INFO, GSON.toJson(party)); + List members = party.getMembers(); + members.stream().map(Bukkit::getPlayer).forEach(player1 -> + { + player1.leaveVehicle(); + player1.eject(); + _plugin.getPortal().sendPlayerToServer(player1, server, true); + }); _plugin.removeParty(party); - party.getMembers().stream().map(Bukkit::getPlayer).forEach(player -> _plugin.removeFromParty(player.getUniqueId(), PartyRemoveReason.OTHER)); } public void handlePartyInfo(String json) @@ -193,4 +210,14 @@ public class PartyRedisManager } }.runTaskLater(_plugin.getPlugin(), 10L); } + + public String getServerName() + { + return _serverName; + } + + public String getFinder() + { + return FIND_PLAYERS_CHANNEL; + } } \ 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 d10bb672c..9737bc2f0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -3,6 +3,8 @@ package mineplex.core.party.redis; import mineplex.core.party.manager.PartyRedisManager; import redis.clients.jedis.JedisPubSub; +import static net.minecraft.server.v1_8_R3.PotionBrewer.m; + /** * Handles incoming messages into the Party Redis System */ @@ -19,9 +21,12 @@ public class PartyRedisListener extends JedisPubSub @Override public void onMessage(String channel, String message) { - System.out.println("Message on " + channel); - System.out.println("Message contents; " + message); - RedisMessageType type = RedisMessageType.valueOf(message.split(":")[0].toUpperCase()); - _redisManager.handle(type, message.split(":")[1]); + if(channel.equalsIgnoreCase(_redisManager.getFinder())) + { + _redisManager.handle(RedisMessageType.PLAYER_FIND_REQUEST, message); + return; + } + 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 b17073b65..30157dc1a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -23,7 +23,8 @@ public enum RedisMessageType PREJOIN_SERVER_RESPONSE(6, "{0},{1},{2},{3}"), //Message: JSON Party - PARTY_INFO(7, "{0}") + PARTY_INFO(7, "{0}"), + TEST_CONN(8, "{0}") ; private int _id; From e71fc291d129424365af56753b51b737924f1601 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Fri, 24 Jun 2016 04:01:51 -0500 Subject: [PATCH 27/53] Fix cross server invites / joining servers. --- .../core/party/command/PartyCommand.java | 21 ++++++++++++------- .../party/manager/PartyInviteManager.java | 7 ++++++- .../core/party/manager/PartyRedisManager.java | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) 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 195ed59e0..739b6a994 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -29,14 +29,14 @@ public class PartyCommand extends CommandBase private final String[] HELP = { F.main("Party", "Party Commands (Click the command!)"), - //help("help", "Shows this help screen"), + help("help", "Shows this help screen"), help("", "Brings up the Party GUI"), help("invite ", "Invite a player to your party."), - //help("accept ", "Accept an invite to a party."), - //help("deny ", "Deny an invite to a party."), + help("accept ", "Accept an invite to a party."), + help("deny ", "Deny an invite to a party."), help("leave", "Leave your current party"), - //help("kick ", "Kick a player from your party."), - //help("disband", "Disband your party."), + help("kick ", "Kick a player from your party."), + help("disband", "Disband your party."), C.cBlue + "Party> " + C.cWhite + "# " + C.cGray + "- Send a message to your party." }; @@ -150,9 +150,15 @@ public class PartyCommand extends CommandBase private void handleInvite(Player caller, String target) { - Player possible = Bukkit.getPlayerExact(target); + Player possible = Bukkit.getPlayer(target); Party party = Plugin.getParty(caller); + if(target.equalsIgnoreCase(caller.getName())) + { + caller.sendMessage(F.main("Party", "You cannot invite yourself!")); + return; + } + boolean can = Bukkit.getMaxPlayers() >= Plugin.getPlugin().getServer().getOnlinePlayers().size(); if(!can) { @@ -176,7 +182,7 @@ public class PartyCommand extends CommandBase Lang.ALREADY_INVITED.send(caller, target); return; } - Lang.INVITE_SUCCESS_PLAYER.send(caller, target); + Lang.INVITE_SUCCESS_PLAYER.send(caller, possible.getName()); } else { if(!party.getOwner().equalsIgnoreCase(caller.getName())) @@ -220,6 +226,7 @@ public class PartyCommand extends CommandBase if(Plugin.getParty(caller) != null) { Lang.ALREADY_IN.send(caller); + caller.sendMessage(F.main("Party", "Please leave your party before joining!")); return; } 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 3632fccd1..bb64590be 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -141,11 +141,16 @@ public class PartyInviteManager String message = F.main("Party", response.format(target)); Party party = _plugin.getParty(sender); + String partyName = sender; + if(party != null) + { + partyName = party.getName(); + } switch (response) { case ACCEPTED: - addToPendingJoin(targetUUID, party.getName()); + addToPendingJoin(targetUUID, partyName); break; case EXPIRED: case DENIED: 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 e742f878b..91f3d4a8a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -147,6 +147,7 @@ public class PartyRedisManager public void findAndInvite(String player, String sender) { + Bukkit.getPlayerExact(sender).sendMessage(F.main("Party", "Locating " + player + "...")); TASKS.put(player, new BukkitRunnable() { @Override From 584c8f50f06edd1d02364796293a9d83af579f55 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Mon, 4 Jul 2016 05:12:02 -0500 Subject: [PATCH 28/53] PC Party bugs and tweaks. --- .../src/mineplex/core/party/Party.java | 17 ++++++++++- .../core/party/PartyEventListener.java | 10 ++++++- .../src/mineplex/core/party/PartyManager.java | 30 +++++++++++++++---- .../core/party/manager/PartyJoinManager.java | 13 +++++++- .../core/party/manager/PartyRedisManager.java | 10 ++----- .../src/mineplex/hub/HubManager.java | 3 -- 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 5c1733378..23e7e98a6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Player; import java.util.List; import java.util.Map; +import java.util.UUID; /** * Uh, yeah, I'll get back to this when it isn't 2 AM @@ -23,6 +24,7 @@ public class Party private String _owner; private List _members; + private List _membersByUUID; private Map _invites; private int size; @@ -37,6 +39,7 @@ public class Party _members = Lists.newArrayList(); _invites = Maps.newHashMap(); _members.add(owner); + _membersByUUID = Lists.newArrayList(); } public String getOwner() @@ -100,14 +103,15 @@ public class Party } if(reason == PartyRemoveReason.LEFT) { - Lang.REMOVE_PLAYER.send(this, player); if(player.equalsIgnoreCase(_owner) && _members.size() > 1) { _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; } + Lang.REMOVE_PLAYER.send(this, player); return; } if(reason == PartyRemoveReason.OTHER) @@ -134,4 +138,15 @@ public class Party { _owner = owner; } + + @Override + public String toString() + { + return "Party: " + _owner; + } + + public List getMembersByUUID() + { + return _membersByUUID; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java index de43b50a3..f993b66d2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -1,6 +1,7 @@ package mineplex.core.party; import mineplex.core.common.Rank; +import mineplex.core.party.event.PartyDataReceivedEvent; import mineplex.core.party.event.PartyMemberKickGUIEvent; import mineplex.core.party.event.PartyTransferOwnerEvent; import mineplex.core.party.manager.PartyRedisManager; @@ -84,7 +85,14 @@ public class PartyEventListener implements Listener return; } - _plugin.removeFromParty(player, PartyRemoveReason.LEFT); + PartyRemoveReason reason = PartyRemoveReason.LEFT; + + if(_plugin.getJoinManager().isTransferring(player)) + { + reason = PartyRemoveReason.OTHER; + } + + _plugin.removeFromParty(player, reason); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index a2568119b..985f00284 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -74,6 +74,10 @@ public class PartyManager extends MiniPlugin _players.put(uuid, party); Player player = Bukkit.getPlayer(uuid); party.onPlayerAdd(player.getName()); + if(!party.getMembersByUUID().contains(uuid)) + { + party.getMembersByUUID().add(uuid); + } } public void addToParty(Player player, Party party) @@ -86,6 +90,17 @@ public class PartyManager extends MiniPlugin _parties.remove(party.getName()); } + public void removeForTransfer(UUID uuid) + { + Party party = _players.remove(uuid); + if(party == null) + { + return; + } + String player = Bukkit.getPlayer(uuid).getName(); + party.onPlayerRemove(player, PartyRemoveReason.OTHER); + } + public void removeFromParty(UUID uuid, PartyRemoveReason reason) { Party party = _players.remove(uuid); @@ -95,6 +110,7 @@ public class PartyManager extends MiniPlugin } Player player = Bukkit.getPlayer(uuid); party.getMembers().remove(player.getName()); + party.getMembersByUUID().remove(uuid); party.onPlayerRemove(player.getName(), reason); if(player.getOpenInventory() != null) { @@ -132,12 +148,11 @@ public class PartyManager extends MiniPlugin 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 -> + if(party == null) { - _players.remove(s.getUniqueId()); - _players.put(s.getUniqueId(), party); - }); + return; + } + _parties.put(newOwner.toLowerCase(), party); party.setOwner(newOwner); party.getMembers().remove(oldOwner); party.getMembers().add(oldOwner); @@ -179,5 +194,8 @@ public class PartyManager extends MiniPlugin return _joinManager; } - + public Map getPlayerParties() + { + return _players; + } } 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 78161f58a..200655799 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -1,5 +1,6 @@ package mineplex.core.party.manager; +import com.google.common.collect.Lists; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilServer; @@ -10,6 +11,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -38,11 +40,13 @@ public class PartyJoinManager private final PartyManager _plugin; private final int _maxPLayers; + private final List _transferring; public PartyJoinManager(PartyManager plugin) { _plugin = plugin; _maxPLayers = plugin.getPlugin().getServer().getMaxPlayers(); + _transferring = Lists.newArrayList(); } public void requestServerJoin(String server, Party party) @@ -98,7 +102,14 @@ public class PartyJoinManager } party.sendMessage(F.main("Party", "Transferring servers...")); _plugin.getRedisManager().sendPartyInfo(server, party); - + _transferring.addAll(party.getMembersByUUID()); } + + public boolean isTransferring(Player player) + { + return _transferring.remove(player.getUniqueId()); + } + + } 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 91f3d4a8a..a7a166a4c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -181,6 +181,7 @@ public class PartyRedisManager { publish(server, PARTY_INFO, GSON.toJson(party)); List members = party.getMembers(); + party.getMembersByUUID().stream().forEach(_plugin::removeForTransfer); members.stream().map(Bukkit::getPlayer).forEach(player1 -> { player1.leaveVehicle(); @@ -199,14 +200,7 @@ public class PartyRedisManager { 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); - } - }); + party.getMembersByUUID().forEach(s -> _plugin.addToParty(s, party)); Bukkit.getServer().getPluginManager().callEvent(new PartyDataReceivedEvent(party)); } }.runTaskLater(_plugin.getPlugin(), 10L); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index d77a78172..7b7378c93 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -705,9 +705,6 @@ public class HubManager extends MiniClientPlugin for (Player player : UtilServer.getPlayers()) { - //Dont Waste Time - if (_partyManager.GetParty(player) != null) - continue; //Return to Main Scoreboard if (!player.getScoreboard().equals(_scoreboards.get(player))) From 0ebddf9f45229b79d98e7d047a92e167f1b98d68 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Mon, 4 Jul 2016 05:43:01 -0500 Subject: [PATCH 29/53] Add UI Item. Add check to make sure player's cant be invited to another party if they're already in one. Bug fixes. --- .../src/mineplex/core/party/Lang.java | 1 + .../core/party/PartyEventListener.java | 18 ++++++++++--- .../src/mineplex/core/party/PartyManager.java | 11 +++++--- .../core/party/command/PartyCommand.java | 13 ++++++++++ .../core/party/ui/button/PartyMemberIcon.java | 26 ++++++++++++------- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java index 0871da217..aa29f2ab6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -45,6 +45,7 @@ public enum Lang 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!"), + PLAYER_IN_DIFFERENT_PARTY("Error: {0} is in a different party.") ; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java index f993b66d2..0e4a8d92d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -8,9 +8,11 @@ import mineplex.core.party.manager.PartyRedisManager; import mineplex.core.party.ui.Menu; import mineplex.core.portal.ServerTransferEvent; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -21,12 +23,10 @@ public class PartyEventListener implements Listener { private final PartyManager _plugin; - private final PartyRedisManager _redisManager; - public PartyEventListener(PartyManager plugin, PartyRedisManager redisManager) + public PartyEventListener(PartyManager plugin) { _plugin = plugin; - _redisManager = redisManager; _plugin.getPluginManager().registerEvents(this, plugin.getPlugin()); } @@ -35,6 +35,8 @@ public class PartyEventListener implements Listener { Player player = event.getPlayer(); + player.getInventory().setItem(PartyManager.INTERFACE_SLOT, PartyManager.INTERFACE_ITEM); + String partyName = _plugin.getInviteManager().getPartyWaiting(player.getUniqueId()); if (partyName == null) @@ -139,4 +141,14 @@ public class PartyEventListener implements Listener } + @EventHandler + public void onClick(PlayerInteractEvent event) + { + if(event.hasItem() && event.getItem().getType() == Material.NAME_TAG) + { + event.setCancelled(true); + event.getPlayer().chat("/party"); + } + } + } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index 985f00284..47539128d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -1,10 +1,10 @@ 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.common.util.C; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.command.PartyCommand; import mineplex.core.party.manager.PartyInviteManager; import mineplex.core.party.manager.PartyJoinManager; @@ -16,7 +16,9 @@ import mineplex.core.preferences.PreferencesManager; import mineplex.serverdata.Utility; import mineplex.serverdata.servers.ServerManager; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import java.util.Map; @@ -25,6 +27,9 @@ import java.util.UUID; public class PartyManager extends MiniPlugin { + public static final ItemStack INTERFACE_ITEM = new ItemBuilder(Material.NAME_TAG).setTitle(C.cGreen + "Parties").build(); + public static final int INTERFACE_SLOT = 5; + private final Portal _portal; private final CoreClientManager _clientManager; private final PreferencesManager _preferencesManager; @@ -51,7 +56,7 @@ public class PartyManager extends MiniPlugin _joinManager = new PartyJoinManager(this); addCommand(new PartyCommand(this)); getPluginManager().registerEvents(new MenuListener(), getPlugin()); - new PartyEventListener(this, _redisManager); + new PartyEventListener(this); } public Party getParty(String party) 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 739b6a994..79d471437 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -1,5 +1,6 @@ package mineplex.core.party.command; +import mineplex.core.chat.Chat; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.jsonchat.ChildJsonMessage; @@ -172,11 +173,18 @@ public class PartyCommand extends CommandBase return; } + + //Same Server if (possible != null) { if (party == null) { + if(Plugin.getParty(target) != null) + { + Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target); + return; + } if(Plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), caller.getName())) { Lang.ALREADY_INVITED.send(caller, target); @@ -200,6 +208,11 @@ public class PartyCommand extends CommandBase Lang.ALREADY_MEMBER.send(caller, target); return; } + if(Plugin.getParty(target) != null) + { + Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target); + return; + } if(party.getMembers().size() >= party.getSize()) { Lang.PARTY_FULL.send(caller); 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 a57a25ba3..abd12d2ef 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 @@ -3,15 +3,10 @@ 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.Menu; 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; import org.bukkit.event.inventory.ClickType; @@ -23,12 +18,25 @@ import org.bukkit.inventory.ItemStack; public class PartyMemberIcon extends PartyButton { + private ItemStack _itemStack; + public PartyMemberIcon(String player, Party party, boolean owner) { - super(new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3) + super(null, party, null); + ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3) .setTitle(C.cYellow + player) - .setLore(owner ? C.cGreen + "Leader" : "") - .setPlayerHead(player).build(), party, null); + .setPlayerHead(player); + if(owner) + { + builder.addLore(" ", C.cGreenB + "Leader"); + } + _itemStack = builder.build(); + } + + @Override + public ItemStack getItemStack() + { + return _itemStack; } public PartyMemberIcon(String player, Party party) @@ -38,7 +46,7 @@ public class PartyMemberIcon extends PartyButton public void onClick(Player clicker, ItemStack clicked) { - if(!getParty().isOwnerKickMode()) + if (!getParty().isOwnerKickMode()) { return; } From 978ee0055a252d31778e0609d80fcffbf9750e73 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Mon, 4 Jul 2016 09:15:47 -0500 Subject: [PATCH 30/53] Bug fixes. --- .../src/mineplex/core/party/PartyManager.java | 4 +++- .../party/ui/button/tools/main/InvitePlayerButton.java | 2 +- .../core/party/ui/button/tools/owner/AddPlayerButton.java | 2 +- .../core/party/ui/menus/input/PartyInvitePlayerMenu.java | 7 ++++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index 47539128d..32f86239b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -21,6 +21,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -146,7 +147,8 @@ public class PartyManager extends MiniPlugin public void disbandParty(Party party) { - party.getMembers().stream().map(Bukkit::getPlayer).forEach(player -> removeFromParty(player.getUniqueId(), PartyRemoveReason.KICKED)); + List members = party.getMembers(); + members.stream().map(Bukkit::getPlayer).forEach(player -> removeFromParty(player.getUniqueId(), PartyRemoveReason.LEFT)); removeParty(party); } 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 bc4146f16..b1f54dea4 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 @@ -29,6 +29,6 @@ public class InvitePlayerButton extends Button @Override public void onClick(Player player, ClickType clickType) { - new PartyInvitePlayerMenu(getPlugin(), player).openInventory(); + new PartyInvitePlayerMenu(getPlugin(), player, null).openInventory(); } } 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 2d1e5c3be..51f9b2a7d 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).openInventory(); + new PartyInvitePlayerMenu(getPlugin(), player, getParty()).openInventory(); } } 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 463345d0f..dddc52a48 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,7 @@ package mineplex.core.party.ui.menus.input; import mineplex.core.anvilMenu.player.PlayerNameMenu; +import mineplex.core.party.Party; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.menus.PartyOwnerMenu; import mineplex.core.anvilMenu.PlayerInputActionMenu; @@ -15,9 +16,9 @@ public class PartyInvitePlayerMenu extends PlayerNameMenu private PartyManager _partyManager; - public PartyInvitePlayerMenu(PartyManager partyManager, Player player) + public PartyInvitePlayerMenu(PartyManager partyManager, Player player, Party party) { - super(partyManager, partyManager.getClientManager(), player, null); + super(partyManager, partyManager.getClientManager(), player, party); _partyManager = partyManager; } @@ -27,7 +28,7 @@ public class PartyInvitePlayerMenu extends PlayerNameMenu _player.chat("/party invite " + name); _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); _player.closeInventory(); - if (_partyManager.getParty(_player) == null) + if (_party == null) { return; } From 9f58e57a670466beb9f62e372f6c5bd478382062 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Tue, 5 Jul 2016 14:35:37 -0500 Subject: [PATCH 31/53] Bug fixes. --- .../src/mineplex/core/party/Lang.java | 6 +-- .../src/mineplex/core/party/Party.java | 30 ++++++++++++++- .../src/mineplex/core/party/PartyManager.java | 29 +++++++++++--- .../core/party/PartyRemoveReason.java | 1 + .../core/party/command/PartyCommand.java | 38 ++++--------------- .../core/party/manager/PartyRedisManager.java | 10 ++--- .../core/party/redis/PartyRedisListener.java | 3 +- .../tools/owner/TransferOwnerButton.java | 2 +- .../menus/input/PlayerSuggestPlayerMenu.java | 7 +++- .../src/nautilus/game/arcade/game/Game.java | 4 +- .../arcade/managers/GamePlayerManager.java | 13 +++---- 11 files changed, 80 insertions(+), 63 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java index aa29f2ab6..cd99d6ae4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -1,11 +1,8 @@ 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; +import org.bukkit.entity.Player; /** * All chat messages for the party system to align with PE @@ -31,6 +28,7 @@ public enum Lang 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."), + DISBANDED_BY_OWNER("Your party has been disbanded!"), REMOVED("You have been removed from the party."), NOT_EXIST("Error: {0} is not in a party right now."), diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 23e7e98a6..fbb2fa396 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -2,12 +2,11 @@ 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.Sound; import org.bukkit.entity.Player; import java.util.List; @@ -27,6 +26,7 @@ public class Party private List _membersByUUID; private Map _invites; private int size; + private boolean _alreadyTeamed; public Party() { @@ -86,6 +86,10 @@ public class Party } _members.add(player); Lang.ADD_MEMBER.send(this, player); + getMembers().stream().forEach(s -> { + Player player1 = Bukkit.getPlayer(s); + player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F); + }); } public void onPlayerRemove(String player, PartyRemoveReason reason) @@ -149,4 +153,26 @@ public class Party { return _membersByUUID; } + + public boolean alreadyTeamed() + { + return _alreadyTeamed; + } + + public void setAlreadyTeamed(boolean alreadyTeamed) + { + _alreadyTeamed = alreadyTeamed; + } + + public boolean contains(String name) + { + for(String s : _members) + { + if(s.equalsIgnoreCase(name)) + { + return true; + } + } + return false; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index 32f86239b..f7a7311d3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -1,5 +1,6 @@ package mineplex.core.party; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; @@ -86,6 +87,11 @@ public class PartyManager extends MiniPlugin } } + public void addToPartyOnTransfer(UUID uuid, Party party) + { + _players.put(uuid, party); + } + public void addToParty(Player player, Party party) { addToParty(player.getUniqueId(), party); @@ -114,10 +120,9 @@ public class PartyManager extends MiniPlugin { return; } + Player player = Bukkit.getPlayer(uuid); - party.getMembers().remove(player.getName()); - party.getMembersByUUID().remove(uuid); - party.onPlayerRemove(player.getName(), reason); + if(player.getOpenInventory() != null) { if (Menu.get(player.getUniqueId()) != null) @@ -126,6 +131,15 @@ public class PartyManager extends MiniPlugin Menu.remove(player.getUniqueId()); } } + + if(reason == PartyRemoveReason.DISBANDED_BY_OWNER) + { + return; + } + party.getMembers().remove(player.getName()); + party.getMembersByUUID().remove(uuid); + party.onPlayerRemove(player.getName(), reason); + int size = party.getMembers().size(); if(size <= 1) { @@ -147,14 +161,17 @@ public class PartyManager extends MiniPlugin public void disbandParty(Party party) { - List members = party.getMembers(); - members.stream().map(Bukkit::getPlayer).forEach(player -> removeFromParty(player.getUniqueId(), PartyRemoveReason.LEFT)); + List members = Lists.newArrayList(party.getMembersByUUID()); + Lang.DISBANDED_BY_OWNER.send(party); + members.stream().forEach(player -> removeFromParty(player, PartyRemoveReason.DISBANDED_BY_OWNER)); + party.getMembers().clear(); + party.getMembersByUUID().clear(); removeParty(party); } public void transferOwner(String newOwner, String oldOwner) { - Party party = _parties.remove(oldOwner.toLowerCase()); + Party party = _parties.remove(oldOwner); if(party == null) { return; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java index a0930d375..b27a6dbfa 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java @@ -9,6 +9,7 @@ public enum PartyRemoveReason LEFT(2, "left"), OTHER(3, "other"), DISBANDED(4, "disbanded"), + DISBANDED_BY_OWNER(5, "disbandedByOwner"), ; private int _id; 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 79d471437..247a5174b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -1,11 +1,9 @@ package mineplex.core.party.command; -import mineplex.core.chat.Chat; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.jsonchat.ChildJsonMessage; 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; @@ -30,14 +28,14 @@ public class PartyCommand extends CommandBase private final String[] HELP = { F.main("Party", "Party Commands (Click the command!)"), - help("help", "Shows this help screen"), + // help("help", "Shows this help screen"), help("", "Brings up the Party GUI"), - help("invite ", "Invite a player to your party."), - help("accept ", "Accept an invite to a party."), - help("deny ", "Deny an invite to a party."), - help("leave", "Leave your current party"), - help("kick ", "Kick a player from your party."), - help("disband", "Disband your party."), + //help("invite ", "Invite a player to your party."), + //help("accept ", "Accept an invite to a party."), + //help("deny ", "Deny an invite to a party."), + //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 to your party." }; @@ -49,28 +47,6 @@ public class PartyCommand extends CommandBase @Override public void Execute(Player caller, String[] args) { - if(_aliasUsed.equalsIgnoreCase("z")) - { - caller.sendMessage(F.main("Party", "That command is no longer allowed! Please use \"/party\"")); - caller.sendMessage(HELP[0]); - //Show this menu - for(int i = 1; i < HELP.length; i++) - { - String s = HELP[i]; - String command = ChatColor.stripColor(s); - ChildJsonMessage jsonMessage = new ChildJsonMessage(s); - if ((i + 1) == HELP.length) - { - command = "#"; - } else - { - command = command.substring(command.indexOf("/"), command.indexOf("-") - 1); - } - jsonMessage.click(ClickEvent.SUGGEST_COMMAND, command); - jsonMessage.sendToPlayer(caller); - } - return; - } if (args.length == 0) { Party party = Plugin.getParty(caller); 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 a7a166a4c..ad3902fa0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -7,7 +7,6 @@ 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; @@ -17,20 +16,15 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -import org.jooq.util.derby.sys.Sys; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.UUID; import static mineplex.core.party.redis.RedisMessageType.INVITE_PLAYER_REQUEST; import static mineplex.core.party.redis.RedisMessageType.PARTY_INFO; -import static net.minecraft.server.v1_8_R3.PotionBrewer.c; -import static net.minecraft.server.v1_8_R3.PotionBrewer.f; -import static sun.audio.AudioPlayer.player; /** * Redis system for Parties @@ -56,6 +50,7 @@ public class PartyRedisManager _channel = CHANNEL_BASE + "-" + serverName; plugin.runAsync(() -> { + System.out.println("Connecting to redis and listening on channel " + _channel); try (Jedis jedis = readPool.getResource()) { jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL); @@ -65,6 +60,7 @@ public class PartyRedisManager public void publish(String server, RedisMessageType messageType, String... args) { + System.out.println("Sending " + messageType.name() + " to " + server); _plugin.runAsync(() -> { try (Jedis jedis = _writePool.getResource()) { @@ -200,7 +196,7 @@ public class PartyRedisManager { Party party = GSON.fromJson(json, Party.class); _plugin.addParty(party); - party.getMembersByUUID().forEach(s -> _plugin.addToParty(s, party)); + party.getMembersByUUID().forEach(s -> _plugin.addToPartyOnTransfer(s, party)); Bukkit.getServer().getPluginManager().callEvent(new PartyDataReceivedEvent(party)); } }.runTaskLater(_plugin.getPlugin(), 10L); 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 9737bc2f0..bf80cb5b8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -3,8 +3,6 @@ package mineplex.core.party.redis; import mineplex.core.party.manager.PartyRedisManager; import redis.clients.jedis.JedisPubSub; -import static net.minecraft.server.v1_8_R3.PotionBrewer.m; - /** * Handles incoming messages into the Party Redis System */ @@ -21,6 +19,7 @@ public class PartyRedisListener extends JedisPubSub @Override public void onMessage(String channel, String message) { + System.out.println("Message on " + channel + " :: " + message); if(channel.equalsIgnoreCase(_redisManager.getFinder())) { _redisManager.handle(RedisMessageType.PLAYER_FIND_REQUEST, message); 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 b936bd526..ecf0eb589 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 @@ -31,6 +31,6 @@ public class TransferOwnerButton extends PartyButton @Override public void onClick(Player player, ClickType clickType) { - new PartyTransferOwnerMenu(getPlugin(), player, getParty()); + new PartyTransferOwnerMenu(getPlugin(), player, getParty()).openInventory(); } } 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 8d26b5116..78b637cdd 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 @@ -9,7 +9,6 @@ import mineplex.core.common.util.F; import mineplex.core.party.Lang; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; -import mineplex.core.anvilMenu.PlayerInputActionMenu; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -33,6 +32,12 @@ public class PlayerSuggestPlayerMenu extends PlayerNameMenu Lang.NO_PARTY.send(_player); return; } + + if(_party.contains(name)) + { + Lang.ALREADY_MEMBER.send(_player, name); + } + Player player = Bukkit.getPlayerExact(_party.getOwner()); _party.sendMessage(C.mHead + "Party> " + F.name(_player.getName()) + " has suggested " + F.name(name) + " be invited."); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 74f0ee8af..15519f5ee 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -9,6 +9,7 @@ import mineplex.core.elo.EloTeam; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.PacketInfo; +import mineplex.core.party.Party; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -1112,8 +1113,7 @@ public abstract class Game implements Listener { return team.GetSize() < PlayersPerTeam; } - return Manager.IsTeamBalance() ? team.GetSize() < Math.max(1, UtilServer.getPlayers().length / GetTeamList().size()) - : true; + return !Manager.IsTeamBalance() || team.GetSize() < Math.max(1, UtilServer.getPlayers().length / GetTeamList().size()); } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java index cef0c62ab..fd20ad17b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java @@ -1,7 +1,5 @@ package nautilus.game.arcade.managers; -import java.util.ArrayList; - import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -23,7 +21,6 @@ import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.ProgressingKit; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -41,6 +38,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.scheduler.BukkitRunnable; +import java.util.ArrayList; + public class GamePlayerManager implements Listener { ArcadeManager Manager; @@ -267,6 +266,7 @@ public class GamePlayerManager implements Listener TeamClick(player, team); } + public void TeamClick(final Player player, final GameTeam team) { if (Manager.GetGame() == null) @@ -301,8 +301,9 @@ public class GamePlayerManager implements Listener } if (!game.GetTeamPreferences().containsKey(team)) - game.GetTeamPreferences().put(team, new ArrayList()); - + { + game.GetTeamPreferences().put(team, new ArrayList<>()); + } game.GetTeamPreferences().get(team).add(player); } @@ -317,8 +318,6 @@ public class GamePlayerManager implements Listener Player player = event.getPlayer(); - - Kit kit = Manager.GetLobby().GetClickedKit(event.getRightClicked()); if (kit == null) From 8c7308add5a53a9d312f3f43489574253eb637da Mon Sep 17 00:00:00 2001 From: TadahTech Date: Fri, 8 Jul 2016 13:08:34 -0500 Subject: [PATCH 32/53] Add documentation. Refactor code. Remove most command backend capabilities to limit user error. Cleanup. --- .../src/mineplex/core/party/Party.java | 129 ++++++- .../core/party/PartyEventListener.java | 13 +- .../src/mineplex/core/party/PartyManager.java | 140 ++------ .../core/party/command/PartyCommand.java | 259 +------------- .../core/party/constants/InviteResponse.java | 27 ++ .../party/constants/JoinResponseReason.java | 26 ++ .../{ => constants}/PartyRemoveReason.java | 2 +- .../party/event/PartySelectServerEvent.java | 1 - .../party/manager/PartyInviteManager.java | 121 +++++-- .../core/party/manager/PartyJoinManager.java | 56 +-- .../party/manager/PartyMethodManager.java | 337 ++++++++++++++++++ .../core/party/manager/PartyRedisManager.java | 47 ++- .../core/party/redis/PartyRedisListener.java | 3 +- .../core/party/redis/RedisMessageType.java | 29 +- .../src/mineplex/core/party/ui/Menu.java | 37 +- .../core/party/ui/button/PartyMemberIcon.java | 15 +- .../ui/button/tools/LeavePartyButton.java | 5 +- .../party/ui/button/tools/PartyButton.java | 2 +- .../ui/button/tools/invite/BackButton.java | 2 +- .../ui/button/tools/invite/DenyAllButton.java | 5 +- .../ui/button/tools/invite/FilterButton.java | 2 +- .../ui/button/tools/invite/InviteButton.java | 6 +- .../button/tools/invite/NextPageButton.java | 2 +- .../button/tools/invite/PrevPageButton.java | 2 +- .../button/tools/main/InvitePlayerButton.java | 2 +- .../button/tools/main/ViewInvitesButton.java | 3 +- .../button/tools/owner/AddPlayerButton.java | 2 +- .../tools/owner/DisbandPartyButton.java | 5 +- .../button/tools/owner/KickPlayerButton.java | 2 +- .../tools/owner/SelectServerButton.java | 4 +- .../tools/owner/TransferOwnerButton.java | 2 +- .../tools/view/SuggestPlayerButton.java | 2 +- .../core/party/ui/menus/PartyInvitesMenu.java | 30 +- .../core/party/ui/menus/PartyMainMenu.java | 11 +- .../core/party/ui/menus/PartyOwnerMenu.java | 54 ++- .../core/party/ui/menus/PartyViewMenu.java | 24 +- .../ui/menus/input/InviteFilterMenu.java | 4 +- .../ui/menus/input/PartyInvitePlayerMenu.java | 5 +- .../menus/input/PartyTransferOwnerMenu.java | 3 +- .../menus/input/PlayerSuggestPlayerMenu.java | 6 +- 40 files changed, 874 insertions(+), 553 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/constants/InviteResponse.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java rename Plugins/Mineplex.Core/src/mineplex/core/party/{ => constants}/PartyRemoveReason.java (90%) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index fbb2fa396..766832098 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -3,6 +3,7 @@ package mineplex.core.party; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import mineplex.core.common.util.UtilServer; +import mineplex.core.party.constants.PartyRemoveReason; import mineplex.core.party.event.PartyTransferOwnerEvent; import mineplex.core.party.event.PartyTransferOwnerEvent.TransferReason; import org.bukkit.Bukkit; @@ -19,20 +20,64 @@ import java.util.UUID; public class Party { + /** + * This is controls whether or not the owner is currently in the menu, and kicking members + */ private transient boolean _ownerKickMode = false; - private String _owner; - private List _members; - private List _membersByUUID; - private Map _invites; - private int size; - private boolean _alreadyTeamed; + /** + * Asserts if this party has already been put into teams in order to prevent the Arcade from reassigning teams + */ + private transient boolean _alreadyTeamed = false; + /** + * The standard _size for parties, for ALL {@code {@link mineplex.core.common.Rank}} + */ + private transient final int PARTY_MIN_SIZE = 5; + + /** + * An upgrade _size for the party, given to donators and staff. + */ + private transient final int PARTY_MAX_SIZE = 10; + + /** + * The current leader of this party + */ + private String _owner; + + /** + * The names of all current party members + */ + private List _members; + + /** + * The UUIDS of all current party members + */ + private List _membersByUUID; + + /** + * All current pending invites + */ + private Map _invites; + + /** + * This party's max size + */ + private int _size; + + /** + * Empty constructor for GSON + */ public Party() { } + /** + * Creates a new fresh party instance + * + * @param owner The owner / leader of the party. + */ public Party(String owner) { _owner = owner; @@ -47,6 +92,11 @@ public class Party return _owner; } + /** + * Get the current members by their IGN + * + * @return The list of named party members + */ public List getMembers() { return _members; @@ -57,11 +107,23 @@ public class Party return _invites; } + /** + * An alternate method to get the owner of the party. + * While this does not have any difference to using {@code getOwner}, it may serve a purpose in the future, should we wish to allow + * donators to name their party something custom. + * + * @return This party's name + */ public String getName() { return _owner; } + /** + * Send's a message to the party + * + * @param message The string message to send to all players in the party + */ public void sendMessage(String message) { getMembers().stream().map(Bukkit::getPlayer).forEach(player -> player.sendMessage(message)); @@ -69,14 +131,24 @@ public class Party public int getSize() { - return size; + return _size; } - public void setSize(int size) + /** + * Set's this party's size cap base off the current players rank + * + * @param increased true if this party should have the increased size + */ + public void setSize(boolean increased) { - this.size = size; + _size = increased ? PARTY_MAX_SIZE : PARTY_MIN_SIZE; } + /** + * Called when a player is added to the party. + * + * @param player The name of the player + */ public void onPlayerAdd(String player) { _invites.remove(player); @@ -92,6 +164,12 @@ public class Party }); } + /** + * Called when a member of the party is removed + * + * @param player The name of the player + * @param reason The reason for his removal. + */ public void onPlayerRemove(String player, PartyRemoveReason reason) { if(reason == PartyRemoveReason.DISBANDED) @@ -128,27 +206,41 @@ public class Party } } + /** + * Gets the current state of whether or not the owner is kicking people in the UI. + * + * @return true if the owner is kicking people + */ public boolean isOwnerKickMode() { return _ownerKickMode; } + /** + * Set's the current state of kicking players + * + * @param ownerKickMode true if the owner is kicking people + */ public void setOwnerKickMode(boolean ownerKickMode) { _ownerKickMode = ownerKickMode; } + /** + * Set's the new owner for this party instance + * + * @param owner The new owner's name + */ public void setOwner(String owner) { _owner = owner; } - @Override - public String toString() - { - return "Party: " + _owner; - } - + /** + * Get a list of all members in the party by their UUID + * + * @return A list of members by UUID + */ public List getMembersByUUID() { return _membersByUUID; @@ -164,6 +256,13 @@ public class Party _alreadyTeamed = alreadyTeamed; } + /** + * Check to see if this party contains a certain player name + * This is case-insensitive + * + * @param name The players name + * @return true If the player is in the party + */ public boolean contains(String name) { for(String s : _members) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java index 0e4a8d92d..b00da493c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -1,10 +1,9 @@ package mineplex.core.party; import mineplex.core.common.Rank; -import mineplex.core.party.event.PartyDataReceivedEvent; +import mineplex.core.party.constants.PartyRemoveReason; import mineplex.core.party.event.PartyMemberKickGUIEvent; import mineplex.core.party.event.PartyTransferOwnerEvent; -import mineplex.core.party.manager.PartyRedisManager; import mineplex.core.party.ui.Menu; import mineplex.core.portal.ServerTransferEvent; import org.bukkit.Bukkit; @@ -52,14 +51,14 @@ public class PartyEventListener implements Listener { party = new Party(partyName); - int size = 5; - if (bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA)) { - size = 10; + party.setSize(true); + } else + { + party.setSize(false); } - party.setSize(size); _plugin.addParty(party); } @@ -110,7 +109,7 @@ public class PartyEventListener implements Listener Player clicked = Bukkit.getPlayerExact(event.getPlayerClicked()); Lang.REMOVED.send(clicked); _plugin.removeFromParty(clicked, PartyRemoveReason.KICKED); - Menu.get(event.getOwner().getUniqueId()).update(event.getOwner()); + Menu.get(event.getOwner().getUniqueId()).resetAndUpdate(event.getOwner()); } @EventHandler diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index f7a7311d3..918d3f8b6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -1,6 +1,5 @@ package mineplex.core.party; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; @@ -9,39 +8,55 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.command.PartyCommand; import mineplex.core.party.manager.PartyInviteManager; import mineplex.core.party.manager.PartyJoinManager; +import mineplex.core.party.manager.PartyMethodManager; import mineplex.core.party.manager.PartyRedisManager; -import mineplex.core.party.ui.Menu; import mineplex.core.party.ui.MenuListener; 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.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; -import java.util.List; import java.util.Map; import java.util.UUID; public class PartyManager extends MiniPlugin { + /** + * The item given to a player in his hotbar to manage the Parties via the new UI. + */ public static final ItemStack INTERFACE_ITEM = new ItemBuilder(Material.NAME_TAG).setTitle(C.cGreen + "Parties").build(); + /** + * The slow to which it goes in. + */ public static final int INTERFACE_SLOT = 5; + //Managers private final Portal _portal; private final CoreClientManager _clientManager; private final PreferencesManager _preferencesManager; private final PartyRedisManager _redisManager; private final PartyInviteManager _inviteManager; private final PartyJoinManager _joinManager; + private final PartyMethodManager _methodManager; + /** + * This local instance's name + */ private final String _serverName; + /** + * A map of player's in parties server wide. + */ private final Map _players = Maps.newHashMap(); + + /** + * A map of owner (name) -> party server wide + */ private final Map _parties = Maps.newHashMap(); public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager) @@ -50,12 +65,17 @@ public class PartyManager extends MiniPlugin _portal = portal; _clientManager = clientManager; _preferencesManager = preferenceManager; + _serverName = _plugin.getConfig().getString("serverstatus.name"); + _redisManager = new PartyRedisManager(this, _serverName, Utility.generatePool(ServerManager.getMasterConnection()), Utility.generatePool(ServerManager.getSlaveConnection())); + _inviteManager = new PartyInviteManager(this, _redisManager); _joinManager = new PartyJoinManager(this); + _methodManager = new PartyMethodManager(this); + addCommand(new PartyCommand(this)); getPluginManager().registerEvents(new MenuListener(), getPlugin()); new PartyEventListener(this); @@ -76,113 +96,11 @@ public class PartyManager extends MiniPlugin _parties.put(party.getName(), party); } - public void addToParty(UUID uuid, Party party) - { - _players.put(uuid, party); - Player player = Bukkit.getPlayer(uuid); - party.onPlayerAdd(player.getName()); - if(!party.getMembersByUUID().contains(uuid)) - { - party.getMembersByUUID().add(uuid); - } - } - - public void addToPartyOnTransfer(UUID uuid, Party party) - { - _players.put(uuid, party); - } - - public void addToParty(Player player, Party party) - { - addToParty(player.getUniqueId(), party); - } - public void removeParty(Party party) { _parties.remove(party.getName()); } - public void removeForTransfer(UUID uuid) - { - Party party = _players.remove(uuid); - if(party == null) - { - return; - } - String player = Bukkit.getPlayer(uuid).getName(); - party.onPlayerRemove(player, PartyRemoveReason.OTHER); - } - - public void removeFromParty(UUID uuid, PartyRemoveReason reason) - { - Party party = _players.remove(uuid); - if(party == null) - { - return; - } - - Player player = Bukkit.getPlayer(uuid); - - if(player.getOpenInventory() != null) - { - if (Menu.get(player.getUniqueId()) != null) - { - player.closeInventory(); - Menu.remove(player.getUniqueId()); - } - } - - if(reason == PartyRemoveReason.DISBANDED_BY_OWNER) - { - return; - } - party.getMembers().remove(player.getName()); - party.getMembersByUUID().remove(uuid); - party.onPlayerRemove(player.getName(), reason); - - int size = party.getMembers().size(); - if(size <= 1) - { - if(size == 0) - { - removeParty(party); - return; - } - _players.remove(Bukkit.getPlayerExact(party.getMembers().get(0)).getUniqueId()); - party.onPlayerRemove(party.getMembers().get(0), PartyRemoveReason.DISBANDED); - removeParty(party); - } - } - - public void removeFromParty(Player player, PartyRemoveReason reason) - { - removeFromParty(player.getUniqueId(), reason); - } - - public void disbandParty(Party party) - { - List members = Lists.newArrayList(party.getMembersByUUID()); - Lang.DISBANDED_BY_OWNER.send(party); - members.stream().forEach(player -> removeFromParty(player, PartyRemoveReason.DISBANDED_BY_OWNER)); - party.getMembers().clear(); - party.getMembersByUUID().clear(); - removeParty(party); - } - - public void transferOwner(String newOwner, String oldOwner) - { - Party party = _parties.remove(oldOwner); - if(party == null) - { - return; - } - _parties.put(newOwner.toLowerCase(), party); - party.setOwner(newOwner); - party.getMembers().remove(oldOwner); - party.getMembers().add(oldOwner); - } - - public Portal getPortal() { return _portal; @@ -218,8 +136,18 @@ public class PartyManager extends MiniPlugin return _joinManager; } + public PartyMethodManager getMethodManager() + { + return _methodManager; + } + public Map getPlayerParties() { return _players; } + + public Map getParties() + { + return _parties; + } } 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 247a5174b..4d8d3b8ec 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -2,24 +2,16 @@ package mineplex.core.party.command; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; -import mineplex.core.common.jsonchat.ChildJsonMessage; -import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.util.C; import mineplex.core.common.util.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.PartyInvitesMenu; import mineplex.core.party.ui.menus.PartyMainMenu; import mineplex.core.party.ui.menus.PartyOwnerMenu; import mineplex.core.party.ui.menus.PartyViewMenu; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.util.UUID; - /** * Command handler for party commands */ @@ -28,20 +20,15 @@ public class PartyCommand extends CommandBase private final String[] HELP = { F.main("Party", "Party Commands (Click the command!)"), - // help("help", "Shows this help screen"), help("", "Brings up the Party GUI"), - //help("invite ", "Invite a player to your party."), - //help("accept ", "Accept an invite to a party."), - //help("deny ", "Deny an invite to a party."), - //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 to your party." + C.cBlue + "Party> " + C.cWhite + "# " + C.cGray + "- Send a message to your party.", + C.cGreenB + "All party functions have been moved to the GUI!", + C.cGreenB + "Click the NameTag in your hotbar to get started!" }; public PartyCommand(PartyManager plugin) { - super(plugin, Rank.ALL, "party", "z"); + super(plugin, Rank.ALL, "party", "z", "partyaccept", "partydeny", "openinvitesmenu", "partyinvite"); } @Override @@ -63,245 +50,31 @@ public class PartyCommand extends CommandBase new PartyViewMenu(party, Plugin).open(caller); return; } - String argument = args[0]; - if (argument.equalsIgnoreCase("help")) + if(_aliasUsed.equalsIgnoreCase("openinvitesmenu")) { - caller.sendMessage(HELP[0]); - //Show this menu - for(int i = 1; i < HELP.length; i++) - { - String s = HELP[i]; - String command = ChatColor.stripColor(s); - ChildJsonMessage jsonMessage = new ChildJsonMessage(s); - if ((i + 1) == HELP.length) - { - command = "#"; - } else - { - command = command.substring(command.indexOf("/"), command.indexOf("-") - 1); - } - jsonMessage.click(ClickEvent.SUGGEST_COMMAND, command); - jsonMessage.sendToPlayer(caller); - } - + new PartyInvitesMenu(Plugin).open(caller); return; } - if (args.length == 1) + if(args.length == 1) { - if (argument.equalsIgnoreCase("leave")) + String arg = args[0]; + if (_aliasUsed.equalsIgnoreCase("partyaccept")) { - handleLeave(caller); + Plugin.getMethodManager().respondToInvite(caller, arg, true); return; } - if (argument.equalsIgnoreCase("disband")) + if (_aliasUsed.equalsIgnoreCase("partydeny")) { - handleDisband(caller); + Plugin.getMethodManager().respondToInvite(caller, arg, false); return; } - return; - } - if (args.length == 2) - { - String target = args[1]; - if (argument.equalsIgnoreCase("invite")) + if(_aliasUsed.equalsIgnoreCase("partyinvite")) { - handleInvite(caller, target); + Plugin.getMethodManager().invite(caller, arg); return; } - if (argument.equalsIgnoreCase("accept")) - { - handleInviteResponse(caller, target, true); - return; - } - if (argument.equalsIgnoreCase("deny")) - { - handleInviteResponse(caller, target, false); - return; - } - if (argument.equalsIgnoreCase("remove") || argument.equalsIgnoreCase("kick")) - { - handleForceRemove(caller, target); - } } - } - - private void handleInvite(Player caller, String target) - { - Player possible = Bukkit.getPlayer(target); - Party party = Plugin.getParty(caller); - - if(target.equalsIgnoreCase(caller.getName())) - { - caller.sendMessage(F.main("Party", "You cannot invite yourself!")); - return; - } - - boolean can = Bukkit.getMaxPlayers() >= Plugin.getPlugin().getServer().getOnlinePlayers().size(); - if(!can) - { - Lang.SERVER_FULL.send(caller); - return; - } - - if(!Plugin.getPreferencesManager().Get(target).PartyRequests) - { - caller.sendMessage(F.main("Party> ", F.name(target) + " is not accepting invites at this time.")); - return; - } - - - - //Same Server - if (possible != null) - { - if (party == null) - { - if(Plugin.getParty(target) != null) - { - Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target); - return; - } - if(Plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), caller.getName())) - { - Lang.ALREADY_INVITED.send(caller, target); - return; - } - Lang.INVITE_SUCCESS_PLAYER.send(caller, possible.getName()); - } else - { - if(!party.getOwner().equalsIgnoreCase(caller.getName())) - { - Lang.NOT_OWNER.send(caller); - return; - } - if(Plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), party.getName())) - { - Lang.ALREADY_INVITED.send(caller, target); - return; - } - if(party.getMembers().contains(target)) - { - Lang.ALREADY_MEMBER.send(caller, target); - return; - } - if(Plugin.getParty(target) != null) - { - Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target); - return; - } - if(party.getMembers().size() >= party.getSize()) - { - Lang.PARTY_FULL.send(caller); - return; - } - - Lang.SUCCESS_INVITE.send(party, caller.getName(), target); - } - - UUID uuid = possible.getUniqueId(); - - Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName()); - - Plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName(), Plugin.getServerName()); - - Plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName()); - return; - } - Plugin.getRedisManager().findAndInvite(target, caller.getName()); - } - - private void handleInviteResponse(Player caller, String target, boolean accept) - { - if(Plugin.getParty(caller) != null) - { - Lang.ALREADY_IN.send(caller); - caller.sendMessage(F.main("Party", "Please leave your party before joining!")); - return; - } - - PartyInviteManager inviteManager = Plugin.getInviteManager(); - - if (!inviteManager.isInvitedTo(caller.getUniqueId(), target)) - { - //He isn't invited to this party. - Lang.NOT_INVITED.send(caller, target); - return; - } - if(!accept) - { - caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party."); - } - inviteManager.respondToInvite(caller, target, accept); - } - - private void handleForceRemove(Player caller, String target) - { - Party party = Plugin.getParty(caller); - - if (party == null) - { - Lang.NO_PARTY.send(caller); - return; - } - - if (!party.getOwner().equalsIgnoreCase(caller.getName())) - { - Lang.NOT_OWNER.send(caller); - return; - } - - Player playerTarget = Bukkit.getPlayerExact(target); - - if (playerTarget == null) - { - Lang.NOT_MEMBER.send(caller, target); - return; - } - - Party targetParty = Plugin.getParty(playerTarget); - - if (targetParty == null ||!party.getMembers().contains(target)) - { - Lang.NOT_MEMBER.send(caller, target); - return; - } - - Plugin.removeFromParty(playerTarget.getUniqueId(), PartyRemoveReason.KICKED); - - Lang.REMOVE_PLAYER_KICK.send(targetParty); - } - - private void handleLeave(Player caller) - { - Party party = Plugin.getParty(caller); - - if (party == null) - { - Lang.NO_PARTY.send(caller); - return; - } - - Plugin.removeFromParty(caller.getUniqueId(), PartyRemoveReason.LEFT); - Lang.LEFT.send(caller); - } - - private void handleDisband(Player caller) - { - Party party = Plugin.getParty(caller); - - if (party == null) - { - Lang.NO_PARTY.send(caller); - return; - } - - if (!party.getOwner().equalsIgnoreCase(caller.getName())) - { - Lang.NOT_OWNER.send(caller); - return; - } - caller.sendMessage(F.main("Party", "You have disbanded your party.")); - Plugin.disbandParty(party); + caller.sendMessage(HELP); } private String help(String command, String description) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/InviteResponse.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/InviteResponse.java new file mode 100644 index 000000000..30212e51d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/InviteResponse.java @@ -0,0 +1,27 @@ +package mineplex.core.party.constants; + +import mineplex.core.common.util.F; + +/** + * + */ +public enum InviteResponse +{ + + ACCEPTED("{0} has joined the party!"), + DENIED("{0} has declined joining your party."), + EXPIRED("{0} did not respond in time."); + + private String _message; + + InviteResponse(String message) + { + _message = message; + } + + public String format(String target) + { + return _message.replace("{0}", F.name(target)); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java new file mode 100644 index 000000000..56cd100e2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java @@ -0,0 +1,26 @@ +package mineplex.core.party.constants; + +import mineplex.core.common.util.F; + +/** + * + */ +public enum JoinResponseReason +{ + + CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")), + SUCCESS(""); + + private String _message; + + JoinResponseReason(String message) + { + _message = message; + } + + public String getMessage() + { + return _message; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java similarity index 90% rename from Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java rename to Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java index b27a6dbfa..14b8b4e44 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyRemoveReason.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java @@ -1,4 +1,4 @@ -package mineplex.core.party; +package mineplex.core.party.constants; /** * diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java index 7a994b2c2..1509dac3c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java @@ -1,6 +1,5 @@ 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; 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 bb64590be..7f433c098 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -9,6 +9,7 @@ import mineplex.core.party.InviteData; import mineplex.core.party.Lang; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.core.party.constants.InviteResponse; import mineplex.core.party.redis.RedisMessageType; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; @@ -31,26 +32,6 @@ import java.util.UUID; public class PartyInviteManager { - public enum InviteResponse - { - - ACCEPTED("{0} has joined the party!"), - DENIED("{0} has declined joining your party."), - EXPIRED("{0} did not respond in time."); - - private String _message; - - InviteResponse(String message) - { - _message = message; - } - - public String format(String target) - { - return _message.replace("{0}", F.name(target)); - } - } - private final Map> _activeInvites = Maps.newHashMap(); private final Map _invitedBy = Maps.newHashMap(); private final Map _awaitingJoin = Maps.newHashMap(); @@ -66,6 +47,13 @@ public class PartyInviteManager _partyRedisManager = partyRedisManager; } + /** + * Responds to an invite, regardless of the server + * + * @param player The player calling + * @param party The party + * @param accept Whether or not the player accepted the invite + */ public void respondToInvite(Player player, String party, boolean accept) { Player possible = Bukkit.getPlayerExact(party); @@ -92,16 +80,17 @@ public class PartyInviteManager if (newParty == null) { newParty = new Party(possible.getName()); - int size = 5; if(_plugin.getClientManager().Get(possible).GetRank().has(Rank.ULTRA)) { - size = 10; + newParty.setSize(true); + } else + { + newParty.setSize(false); } - newParty.setSize(size); _plugin.addParty(newParty); - _plugin.addToParty(possible.getUniqueId(), newParty); + _plugin.getMethodManager().addToParty(possible.getUniqueId(), newParty); } - _plugin.addToParty(player.getUniqueId(), newParty); + _plugin.getMethodManager().addToParty(player.getUniqueId(), newParty); return; } @@ -116,6 +105,13 @@ public class PartyInviteManager player.getName(), player.getUniqueId().toString(), accept ? InviteResponse.ACCEPTED.name() : InviteResponse.DENIED.name()); } + /** + * Handles a received response via redis + * + * @param sender The player sending the request + * @param target The player target + * @param serverFrom The server initiating the request + */ public void handleInviteRequest(String sender, String target, String serverFrom) { Player player = Bukkit.getPlayer(target); @@ -130,6 +126,14 @@ public class PartyInviteManager sendAcceptOrDeny(player, sender); } + /** + * Handles the response returned via redis when an invite is handled cross server + * + * @param sender The player sender + * @param target The player target + * @param targetUUID The player targets UUID + * @param response The response to this invite + */ public void handleInviteResponse(String sender, String target, UUID targetUUID, InviteResponse response) { remove(sender, targetUUID); @@ -197,18 +201,6 @@ public class PartyInviteManager _awaitingJoin.remove(player); } - /** - * Get the name of the person who has invited the target player - * Used mainly for player locating - * - * @param player The player target - * @return The name, if it exists, of the person who has invited the player. - */ - public String getInvitee(Player player) - { - return _invitedBy.get(player.getUniqueId()); - } - /** * Add a player to the active invites map * @@ -291,6 +283,11 @@ public class PartyInviteManager return temp; } + /** + * Stop the player's expired task from running + * + * @param player The UUID of the player + */ public void cancelTask(UUID player) { BukkitTask task = _tasks.remove(player); @@ -300,21 +297,50 @@ public class PartyInviteManager } } + /** + * Retrieves all invites currently pending for a specific player + * @param player The player + * @return All his current pending invites + */ public Collection getAllInvites(Player player) { return _activeInvites.get(player.getUniqueId()); } + /** + * Send an "ExpiredPartyInvite" redis message + * + * @param server The server to + * @param party The party who initiated the request (can also be a player's name) + * @param playerName The name of the invited player + * @param player The invited player's UUID + */ private void sendExpired(String server, String party, String playerName, UUID player) { _plugin.getRedisManager().publish(server, RedisMessageType.INVITE_PLAYER_RESPONSE, party, playerName, player.toString(), InviteResponse.EXPIRED.name()); } + /** + * Marks this player as having an accepted invite + * This is used to control the creation of single player parties, and makes sure a party is created ONLY if a player joins the server successfully. + * + * @param player The UUID of the player + * @param party The name of the party + */ private void addToPendingJoin(UUID player, String party) { _awaitingJoin.put(player, party); } + /** + * Add a pending invite for a player + * + * @param invited The invited players UUUD + * @param invitedBy The person who invited him + * @param party The name of the party invited to + * @param currentTime The time which this invite was initiated + * @param server The server the request is from + */ private void addToInvite(UUID invited, String invitedBy, String party, long currentTime, String server) { List inviteDatas = _activeInvites.get(invited); @@ -328,6 +354,12 @@ public class PartyInviteManager _activeInvites.put(invited, inviteDatas); } + /** + * Sends a Text Componoent clickable message to a player for easier quick responses to invites + * + * @param player The player who received the invite + * @param arg The name of the inviting party + */ public void sendAcceptOrDeny(Player player, String arg) { TextComponent textComponent = new TextComponent(F.main("Party", "Reply: ")); @@ -335,7 +367,7 @@ public class PartyInviteManager TextComponent accept = new TextComponent("ACCEPT"); accept.setColor(ChatColor.GREEN); accept.setBold(true); - accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party accept " + arg)); + accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/partyaccept " + arg)); accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ new TextComponent("Click to join " + F.name(arg) + "'s party") })); @@ -346,12 +378,23 @@ public class PartyInviteManager TextComponent deny = new TextComponent("DENY"); deny.setColor(ChatColor.RED); deny.setBold(true); - deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party deny " + arg)); + deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/partydeny " + arg)); deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ new TextComponent("Click to decline joining " + F.name(arg) + "'s party") })); textComponent.addExtra(deny); + textComponent.addExtra(" "); + + TextComponent view = new TextComponent("VIEW INVITES"); + view.setColor(ChatColor.GOLD); + view.setBold(true); + view.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/openinvitesmenu")); + view.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ + new TextComponent("Click to view all pending invites.") + })); + + textComponent.addExtra(view); player.spigot().sendMessage(textComponent); } 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 200655799..6775dd3fb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -6,6 +6,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilServer; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.core.party.constants.JoinResponseReason; import mineplex.core.party.redis.RedisMessageType; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -20,23 +21,8 @@ import java.util.stream.Collectors; public class PartyJoinManager { - public enum JoinResponseReason - { - CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")), - SUCCESS(""); - - private String _message; - - JoinResponseReason(String message) - { - _message = message; - } - - public String getMessage() - { - return _message; - } - } + private final String CANNOT_JOIN = "no"; + private final String CAN_JOIN = "yes"; private final PartyManager _plugin; private final int _maxPLayers; @@ -49,6 +35,12 @@ public class PartyJoinManager _transferring = Lists.newArrayList(); } + /** + * Initiates a request to join a server for a specific party + * + * @param server The desired server + * @param party The requesting party + */ public void requestServerJoin(String server, Party party) { boolean canJoinFull = true; @@ -66,6 +58,14 @@ public class PartyJoinManager _plugin.getServerName(), party.getOwner(), "" + party.getMembers().size(), "" + canJoinFull); } + /** + * Manages a received request + * + * @param serverFrom The server who initiated the request + * @param partySize The size of the party + * @param initiator The player who sent the request + * @param canJoinFull true if the party contains all donators or staff (full joining able players) + */ public void handleJoinRequest(String serverFrom, int partySize, String initiator, boolean canJoinFull) { int currentPlayers = UtilServer.getPlayers().length; @@ -74,15 +74,23 @@ public class PartyJoinManager //Max number of people on. if (!canJoinFull) { - _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), "no", _plugin.getServerName()); + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), CANNOT_JOIN, _plugin.getServerName()); return; } } - _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), "yes", _plugin.getServerName()); + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), CAN_JOIN, _plugin.getServerName()); } + /** + * Manages a received response + * + * @param playerSender The player who sent the request + * @param response The String response + * @param server The server responding + * @param reason The reason for the response + */ public void handleJoinResponse(String playerSender, String response, String server, JoinResponseReason reason) { Player player = Bukkit.getPlayer(playerSender); @@ -95,7 +103,7 @@ public class PartyJoinManager { return; } - if (response.equalsIgnoreCase("no")) + if (response.equalsIgnoreCase(CANNOT_JOIN)) { party.sendMessage(reason.getMessage()); return; @@ -105,7 +113,13 @@ public class PartyJoinManager _transferring.addAll(party.getMembersByUUID()); } - + /** + * Retrieve whether or not the player is currently transferring servers + * We wont need this information again, so calling a remove works fine. + * + * @param player The player + * @return true if the player is transferring servers + */ public boolean isTransferring(Player player) { return _transferring.remove(player.getUniqueId()); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java new file mode 100644 index 000000000..8001c82d5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java @@ -0,0 +1,337 @@ +package mineplex.core.party.manager; + +import com.google.common.collect.Lists; +import mineplex.core.common.util.F; +import mineplex.core.party.Lang; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.constants.PartyRemoveReason; +import mineplex.core.party.ui.Menu; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.UUID; + +/** + * Contains all methods used by the internal UI system + */ +public class PartyMethodManager +{ + + private PartyManager _plugin; + + public PartyMethodManager(PartyManager plugin) + { + _plugin = plugin; + } + + /** + * Invite a player to either a new party or existing one + * + * @param caller The player who initiated the request + * @param target The player's target + */ + public void invite(Player caller, String target) + { + Player possible = Bukkit.getPlayer(target); + Party party = _plugin.getParty(caller); + + if(target.equalsIgnoreCase(caller.getName())) + { + caller.sendMessage(F.main("Party", "You cannot invite yourself!")); + return; + } + + boolean can = Bukkit.getMaxPlayers() >= _plugin.getPlugin().getServer().getOnlinePlayers().size(); + if(!can) + { + Lang.SERVER_FULL.send(caller); + return; + } + + //Same Server + if (possible != null) + { + + if(!_plugin.getPreferencesManager().Get(possible).PartyRequests) + { + caller.sendMessage(F.main("Party> ", F.name(target) + " is not accepting invites at this time.")); + return; + } + + if (party == null) + { + if(_plugin.getParty(target) != null) + { + Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target); + return; + } + if(_plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), caller.getName())) + { + Lang.ALREADY_INVITED.send(caller, target); + return; + } + Lang.INVITE_SUCCESS_PLAYER.send(caller, possible.getName()); + } else + { + if(!party.getOwner().equalsIgnoreCase(caller.getName())) + { + Lang.NOT_OWNER.send(caller); + return; + } + if(_plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), party.getName())) + { + Lang.ALREADY_INVITED.send(caller, target); + return; + } + if(party.getMembers().contains(target)) + { + Lang.ALREADY_MEMBER.send(caller, target); + return; + } + if(_plugin.getParty(target) != null) + { + Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target); + return; + } + if(party.getMembers().size() >= party.getSize()) + { + Lang.PARTY_FULL.send(caller); + return; + } + + Lang.SUCCESS_INVITE.send(party, caller.getName(), target); + } + + UUID uuid = possible.getUniqueId(); + + Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName()); + + _plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName(), _plugin.getServerName()); + + _plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName()); + return; + } + //Not on the same server + _plugin.getRedisManager().findAndInvite(target, caller.getName()); + } + + /** + * Responds to a pending invite + * + * @param caller The player who initiated the request + * @param target The player's target + * @param accept true If the player has accepted the invite + */ + public void respondToInvite(Player caller, String target, boolean accept) + { + if(_plugin.getParty(caller) != null) + { + Lang.ALREADY_IN.send(caller); + caller.sendMessage(F.main("Party", "Please leave your party before joining!")); + return; + } + + PartyInviteManager inviteManager = _plugin.getInviteManager(); + + if (!inviteManager.isInvitedTo(caller.getUniqueId(), target)) + { + //He isn't invited to this party. + Lang.NOT_INVITED.send(caller, target); + return; + } + if(!accept) + { + caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party."); + } + inviteManager.respondToInvite(caller, target, accept); + } + + /** + * Kicks a player from the callers party + * + * @param caller The player who initiated the request + * @param target The player's target + */ + public void forceRemove(Player caller, String target) + { + Party party = _plugin.getParty(caller); + + if (party == null) + { + Lang.NO_PARTY.send(caller); + return; + } + + if (!party.getOwner().equalsIgnoreCase(caller.getName())) + { + Lang.NOT_OWNER.send(caller); + return; + } + + Player playerTarget = Bukkit.getPlayerExact(target); + + if (playerTarget == null) + { + Lang.NOT_MEMBER.send(caller, target); + return; + } + + Party targetParty = _plugin.getParty(playerTarget); + + if (targetParty == null ||!party.getMembers().contains(target)) + { + Lang.NOT_MEMBER.send(caller, target); + return; + } + + removeFromParty(playerTarget.getUniqueId(), PartyRemoveReason.KICKED); + + Lang.REMOVE_PLAYER_KICK.send(targetParty); + } + + /** + * Leaves the players current party if he is in one + * + * @param caller The player who wishes to leave his party + */ + public void leaveParty(Player caller) + { + Party party = _plugin.getParty(caller); + + if (party == null) + { + Lang.NO_PARTY.send(caller); + return; + } + + removeFromParty(caller.getUniqueId(), PartyRemoveReason.LEFT); + Lang.LEFT.send(caller); + } + + /** + * Disbands a players current party, assuming he is the leader + * + * @param caller The player who wishes to disband his party + */ + public void disband(Player caller) + { + Party party = _plugin.getParty(caller); + + if (party == null) + { + Lang.NO_PARTY.send(caller); + return; + } + + if (!party.getOwner().equalsIgnoreCase(caller.getName())) + { + Lang.NOT_OWNER.send(caller); + return; + } + caller.sendMessage(F.main("Party", "You have disbanded your party.")); + disbandParty(party); + } + + public void addToParty(UUID uuid, Party party) + { + _plugin.getPlayerParties().put(uuid, party); + Player player = Bukkit.getPlayer(uuid); + party.onPlayerAdd(player.getName()); + if(!party.getMembersByUUID().contains(uuid)) + { + party.getMembersByUUID().add(uuid); + } + } + + public void addToPartyOnTransfer(UUID uuid, Party party) + { + _plugin.getPlayerParties().put(uuid, party); + } + + public void addToParty(Player player, Party party) + { + addToParty(player.getUniqueId(), party); + } + + public void removeForTransfer(UUID uuid) + { + Party party = _plugin.getPlayerParties().remove(uuid); + if(party == null) + { + return; + } + String player = Bukkit.getPlayer(uuid).getName(); + party.onPlayerRemove(player, PartyRemoveReason.OTHER); + } + + public void removeFromParty(UUID uuid, PartyRemoveReason reason) + { + Party party = _plugin.getPlayerParties().remove(uuid); + if(party == null) + { + return; + } + + Player player = Bukkit.getPlayer(uuid); + + if(player.getOpenInventory() != null) + { + if (Menu.get(player.getUniqueId()) != null) + { + player.closeInventory(); + Menu.remove(player.getUniqueId()); + } + } + + if(reason == PartyRemoveReason.DISBANDED_BY_OWNER) + { + return; + } + party.getMembers().remove(player.getName()); + party.getMembersByUUID().remove(uuid); + party.onPlayerRemove(player.getName(), reason); + + int size = party.getMembers().size(); + if(size <= 1) + { + if(size == 0) + { + _plugin.removeParty(party); + return; + } + _plugin.getPlayerParties().remove(Bukkit.getPlayerExact(party.getMembers().get(0)).getUniqueId()); + party.onPlayerRemove(party.getMembers().get(0), PartyRemoveReason.DISBANDED); + _plugin.removeParty(party); + } + } + + public void removeFromParty(Player player, PartyRemoveReason reason) + { + removeFromParty(player.getUniqueId(), reason); + } + + public void disbandParty(Party party) + { + List members = Lists.newArrayList(party.getMembersByUUID()); + Lang.DISBANDED_BY_OWNER.send(party); + members.stream().forEach(player -> removeFromParty(player, PartyRemoveReason.DISBANDED_BY_OWNER)); + party.getMembers().clear(); + party.getMembersByUUID().clear(); + _plugin.removeParty(party); + } + + public void transferOwner(String newOwner, String oldOwner) + { + Party party = _plugin.getParties().remove(oldOwner); + if(party == null) + { + return; + } + _plugin.getParties().put(newOwner.toLowerCase(), party); + party.setOwner(newOwner); + party.getMembers().remove(oldOwner); + party.getMembers().add(oldOwner); + } +} 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 ad3902fa0..e15b2595b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -7,9 +7,9 @@ import mineplex.core.common.util.F; import mineplex.core.party.Lang; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.core.party.constants.InviteResponse; +import mineplex.core.party.constants.JoinResponseReason; import mineplex.core.party.event.PartyDataReceivedEvent; -import mineplex.core.party.manager.PartyInviteManager.InviteResponse; -import mineplex.core.party.manager.PartyJoinManager.JoinResponseReason; import mineplex.core.party.redis.PartyRedisListener; import mineplex.core.party.redis.RedisMessageType; import org.bukkit.Bukkit; @@ -50,7 +50,6 @@ public class PartyRedisManager _channel = CHANNEL_BASE + "-" + serverName; plugin.runAsync(() -> { - System.out.println("Connecting to redis and listening on channel " + _channel); try (Jedis jedis = readPool.getResource()) { jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL); @@ -58,9 +57,15 @@ public class PartyRedisManager }); } + /** + * Send a message to a specific server + * + * @param server The destination server + * @param messageType The message to send + * @param args The arguments accompanying the request + */ public void publish(String server, RedisMessageType messageType, String... args) { - System.out.println("Sending " + messageType.name() + " to " + server); _plugin.runAsync(() -> { try (Jedis jedis = _writePool.getResource()) { @@ -69,6 +74,12 @@ public class PartyRedisManager }); } + /** + * Handle a message received on this server + * + * @param messageType The type of message received + * @param message The contents of the request + */ public void handle(RedisMessageType messageType, String message) { if (messageType == PARTY_INFO) @@ -141,6 +152,12 @@ public class PartyRedisManager } } + /** + * Initiates inviting a player who is no on the same server + * + * @param player The player target + * @param sender The sending player + */ public void findAndInvite(String player, String sender) { Bukkit.getPlayerExact(sender).sendMessage(F.main("Party", "Locating " + player + "...")); @@ -156,7 +173,7 @@ public class PartyRedisManager cancel(); return; } - if(Bukkit.getPlayerExact(player) != null) + if (Bukkit.getPlayerExact(player) != null) { cancel(); return; @@ -173,11 +190,17 @@ public class PartyRedisManager }); } + /** + * Serializes and sends a party to another server + * + * @param server The destination server + * @param party The party to be sent + */ public void sendPartyInfo(String server, Party party) { publish(server, PARTY_INFO, GSON.toJson(party)); List members = party.getMembers(); - party.getMembersByUUID().stream().forEach(_plugin::removeForTransfer); + party.getMembersByUUID().stream().forEach(uuid -> _plugin.getMethodManager().removeForTransfer(uuid)); members.stream().map(Bukkit::getPlayer).forEach(player1 -> { player1.leaveVehicle(); @@ -187,6 +210,10 @@ public class PartyRedisManager _plugin.removeParty(party); } + /** + * Deserialize and store a received party's information + * @param json + */ public void handlePartyInfo(String json) { new BukkitRunnable() @@ -196,17 +223,23 @@ public class PartyRedisManager { Party party = GSON.fromJson(json, Party.class); _plugin.addParty(party); - party.getMembersByUUID().forEach(s -> _plugin.addToPartyOnTransfer(s, party)); + party.getMembersByUUID().forEach(s -> _plugin.getMethodManager().addToPartyOnTransfer(s, party)); Bukkit.getServer().getPluginManager().callEvent(new PartyDataReceivedEvent(party)); } }.runTaskLater(_plugin.getPlugin(), 10L); } + /** + * @return This servers name + */ public String getServerName() { return _serverName; } + /** + * @return The channel constant for finding players + */ public String getFinder() { return FIND_PLAYERS_CHANNEL; 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 bf80cb5b8..f4c3b4d20 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -9,7 +9,7 @@ import redis.clients.jedis.JedisPubSub; public class PartyRedisListener extends JedisPubSub { - private PartyRedisManager _redisManager; + private final PartyRedisManager _redisManager; public PartyRedisListener(PartyRedisManager redisManager) { @@ -19,7 +19,6 @@ public class PartyRedisListener extends JedisPubSub @Override public void onMessage(String channel, String message) { - System.out.println("Message on " + channel + " :: " + message); if(channel.equalsIgnoreCase(_redisManager.getFinder())) { _redisManager.handle(RedisMessageType.PLAYER_FIND_REQUEST, message); 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 30157dc1a..073285ed8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -41,6 +41,11 @@ public enum RedisMessageType return _id; } + /** + * Format this message + * @param args The contents to be sent with this message + * @return A formatted message + */ public String format(String... args) { String message = _contents; @@ -51,28 +56,4 @@ public enum RedisMessageType return message; } - public String getContents() - { - return _contents; - } - - public RedisMessageType getResponse(int id) - { - switch (id) { - case 1: - return PLAYER_FIND_RESPONSE; - case 3: - return INVITE_PLAYER_RESPONSE; - case 5: - return PREJOIN_SERVER_RESPONSE; - default: - return null; - } - } - - public RedisMessageType getResponse(RedisMessageType type) - { - return getResponse(type.getId()); - } - } 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 b764dba19..90d8ef852 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java @@ -33,7 +33,7 @@ public abstract class Menu .setLore(" ", C.cGray + "Purchase a rank @ mineplex.com/shop", C.cGray + "Purchasing a rank increases your", C.cGray + "party size to allow 10 people!") .build(), null); - protected static final Button[] EMPTY = new Button[45]; + protected static final Button[] EMPTY = new Button[54]; protected static Map MENUS = new HashMap<>(); private String _name; protected Button[] _buttons; @@ -220,6 +220,41 @@ public abstract class Menu } } + /** + * Reset this players current menu's buttons and refresh the page + * + * @param player The player whose view you wish to update + */ + public void resetAndUpdate(Player player) + { + InventoryView view = player.getOpenInventory(); + + if (view == null) + { + return; + } + + if (!view.getTitle().equalsIgnoreCase(getName())) + { + return; + } + + Inventory inventory = view.getTopInventory(); + Button[] buttons = setUp(player); + for (int i = 0; i < buttons.length; i++) + { + if (buttons[i] == null) + { + continue; + } + + ItemStack item = buttons[i].getItemStack(); + + inventory.setItem(i, item); + } + } + + public void setTitle(String title) { _name = title; 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 abd12d2ef..5be48d2c9 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 @@ -39,17 +39,22 @@ public class PartyMemberIcon extends PartyButton return _itemStack; } - public PartyMemberIcon(String player, Party party) - { - this(player, party, false); - } - + /** + * Called when a player clicks one of the member icons + * + * @param clicker The player who clicked + * @param clicked The itemstack he clicked + */ public void onClick(Player clicker, ItemStack clicked) { if (!getParty().isOwnerKickMode()) { return; } + if(!getParty().getOwner().equalsIgnoreCase(clicker.getName())) + { + return; + } String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); UtilServer.getPluginManager().callEvent(new PartyMemberKickGUIEvent(getParty(), name, clicker)); } 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 083a62d15..05191241a 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 @@ -2,7 +2,6 @@ package mineplex.core.party.ui.button.tools; import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; -import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -10,7 +9,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Leaves a players current party */ public class LeavePartyButton extends Button { @@ -32,7 +31,7 @@ public class LeavePartyButton extends Button { return; } - player.chat("/party leave"); + getPlugin().getMethodManager().leaveParty(player); player.closeInventory(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java index 6625979fb..463754279 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java @@ -6,7 +6,7 @@ import mineplex.core.party.ui.Button; import org.bukkit.inventory.ItemStack; /** - * + * A wrapper for all buttons which need to interact with a specific party */ public abstract class PartyButton extends Button { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java index 7f385fc1d..6ac82bc6a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java @@ -11,7 +11,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Sends a player back to the main page */ public class BackButton extends Button { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java index 24eb05c3a..e39faaca2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java @@ -4,7 +4,6 @@ import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; -import mineplex.core.party.ui.Menu; import mineplex.core.party.ui.menus.PartyInvitesMenu; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -12,7 +11,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Deny's all invites currently pending */ public class DenyAllButton extends Button { @@ -30,7 +29,7 @@ public class DenyAllButton extends Button @Override public void onClick(Player player, ClickType clickType) { - getPlugin().getInviteManager().removeAll(player.getUniqueId()); + getPlugin().getInviteManager().getAllInvites(player).forEach(inviteData -> getPlugin().getMethodManager().respondToInvite(player, inviteData.getInvitedTo(), false)); new PartyInvitesMenu(getPlugin()).open(player); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java index f2402d537..2a2e5d4ff 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java @@ -11,7 +11,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Filters all current pending invites and displays only the results to a player */ public class FilterButton extends Button { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java index 5d08d96ef..edc97abb3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java @@ -9,7 +9,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; /** - * + * Represents an invitation, to which a player can accept or deny */ public class InviteButton extends Button { @@ -32,10 +32,10 @@ public class InviteButton extends Button { if(clickType == ClickType.LEFT) { - player.chat("/party accept " + _name); + getPlugin().getMethodManager().respondToInvite(player, _name, true); } else if(clickType == ClickType.RIGHT) { - player.chat("/party deny " + _name); + getPlugin().getMethodManager().respondToInvite(player, _name, false); } player.closeInventory(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java index 2ffffff9f..1b370911e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java @@ -15,7 +15,7 @@ import org.bukkit.inventory.ItemStack; import java.util.List; /** - * + * Shows the next page of invites for a player */ public class NextPageButton extends Button { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java index 01c34624e..3400a86cd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java @@ -15,7 +15,7 @@ import org.bukkit.inventory.ItemStack; import java.util.List; /** - * + * Shows the previous page of invites for a player */ public class PrevPageButton extends Button { 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 b1f54dea4..162912d7b 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 @@ -11,7 +11,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Invites a player to a new party */ public class InvitePlayerButton extends Button { 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 12d5e7aa8..3ae1c6cf7 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,7 +1,6 @@ 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; @@ -12,7 +11,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Opens the {@code {@link PartyInvitesMenu}} */ public class ViewInvitesButton extends Button { 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 51f9b2a7d..e010089bd 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 @@ -12,7 +12,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Sends an invitation to a specific player */ public class AddPlayerButton extends PartyButton { 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 4ba9ba000..5c6ad0923 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,7 +1,6 @@ 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; @@ -11,7 +10,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Disbands a party */ public class DisbandPartyButton extends Button { @@ -33,7 +32,7 @@ public class DisbandPartyButton extends Button { return; } - player.chat("/party disband"); + getPlugin().getMethodManager().disband(player); player.closeInventory(); } } 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 654bb2599..03f02fed2 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 @@ -12,7 +12,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Toggles {@code {@link Party#isOwnerKickMode()}} */ public class KickPlayerButton extends PartyButton { 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 6c400a101..dbbd0a032 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 @@ -4,9 +4,7 @@ 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; @@ -14,7 +12,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Opens the server selection menu */ public class SelectServerButton extends PartyButton { 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 ecf0eb589..5d49eae44 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 @@ -12,7 +12,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Transfers ownership of a party to another player */ public class TransferOwnerButton extends PartyButton { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java index ac093ebcd..90c2aa8dc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java @@ -12,7 +12,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; /** - * + * Suggest a new player to be invited */ public class SuggestPlayerButton extends PartyButton { 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 d3bd47636..2ba29aad6 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 @@ -21,7 +21,7 @@ import java.util.Map; import java.util.stream.Collectors; /** - * + * The menu showing all pending invites for a player */ public class PartyInvitesMenu extends Menu { @@ -33,6 +33,10 @@ public class PartyInvitesMenu extends Menu private final int SLOTS_PER_PAGE = 27; private final int STARTING_SLOT = 18; + private final int BACK_BUTTON_SLOT = 0; + private final int DENY_ALL_BUTTON_SLOW = 4; + private final int FILTER_BUTTON_SLOT = 8; + private final int NEXT_PAGE_SLOT = 53; private int _currentPage; private int _pagesNeeded; @@ -56,8 +60,8 @@ public class PartyInvitesMenu extends Menu protected Button[] setUp(Player player) { boolean showFiltered = false; - Button[] buttons = new Button[54]; - buttons[0] = new BackButton(_plugin); + + _buttons[BACK_BUTTON_SLOT] = new BackButton(_plugin); List all = (List) _plugin.getInviteManager().getAllInvites(player); @@ -65,21 +69,21 @@ public class PartyInvitesMenu extends Menu { for (int i = 10; i < 44; i++) { - buttons[i] = NO_INVITES; + _buttons[i] = NO_INVITES; } player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); - return addPanes(buttons); + return addPanes(_buttons); } - buttons[4] = new DenyAllButton(_plugin); + _buttons[DENY_ALL_BUTTON_SLOW] = new DenyAllButton(_plugin); if (_filterBy == null || _filterBy.isEmpty()) { - buttons[8] = new FilterButton(_plugin); + _buttons[FILTER_BUTTON_SLOT] = new FilterButton(_plugin); } else { showFiltered = true; - buttons[8] = new FilterButton(_filterBy, _plugin); + _buttons[FILTER_BUTTON_SLOT] = new FilterButton(_filterBy, _plugin); } if (showFiltered) @@ -91,14 +95,14 @@ public class PartyInvitesMenu extends Menu { for (int i = 10; i < 44; i++) { - buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) + _buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) .setData(DyeColor.RED.getWoolData()) .setTitle(C.cRedB + "No Invites Found") .setLore(" ", C.cGray + "The filter " + F.name(_filterBy) + " had no results.") .build(), _plugin); } player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); - return addPanes(buttons); + return addPanes(_buttons); } _data = all; @@ -112,7 +116,7 @@ public class PartyInvitesMenu extends Menu pagesNeeded++; size -= SLOTS_PER_PAGE; } - buttons[53] = new NextPageButton(this, _plugin); + _buttons[NEXT_PAGE_SLOT] = new NextPageButton(this, _plugin); _pagesNeeded = pagesNeeded; _pagesOfData = Maps.newHashMap(); @@ -141,12 +145,12 @@ public class PartyInvitesMenu extends Menu for (int i = 0; i < all.size(); i++) { String to = all.get(i).getInvitedTo(); - buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin); + _buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin); } } - return buttons; + return addPanes(_buttons); } public void setButton(int slot, Button button) 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 225035cc7..619e2f1f7 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 @@ -13,6 +13,11 @@ import org.bukkit.entity.Player; public class PartyMainMenu extends Menu { + private final int INV_SIZE = 9; + + private final int INVITE_PLAYER_BUTTON_SLOT = 3; + private final int VIEW_INVITES_BUTTON_SLOT = 5; + public PartyMainMenu(PartyManager plugin) { super("Mineplex Parties", plugin); @@ -21,10 +26,10 @@ public class PartyMainMenu extends Menu @Override protected Button[] setUp(Player player) { - Button[] buttons = new Button[9]; + Button[] buttons = new Button[INV_SIZE]; - buttons[3] = new InvitePlayerButton(_plugin); - buttons[5] = new ViewInvitesButton(_plugin); + buttons[INVITE_PLAYER_BUTTON_SLOT] = new InvitePlayerButton(_plugin); + buttons[VIEW_INVITES_BUTTON_SLOT] = 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 dd40a1e3f..398cb57e7 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,64 +5,80 @@ 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.*; import mineplex.core.party.ui.button.tools.LeavePartyButton; -import org.bukkit.Material; +import mineplex.core.party.ui.button.tools.owner.AddPlayerButton; +import mineplex.core.party.ui.button.tools.owner.DisbandPartyButton; +import mineplex.core.party.ui.button.tools.owner.KickPlayerButton; +import mineplex.core.party.ui.button.tools.owner.SelectServerButton; +import mineplex.core.party.ui.button.tools.owner.TransferOwnerButton; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; /** * The display menu for managing parties by the owner */ public class PartyOwnerMenu extends Menu { - + + private final int STARTING_SLOT = 20; + private final int CUT_OFF_SLOT = 25; + private final int SKIP_TO_SLOT = 29; + private final int ADD_PLAYER_BUTTON_SLOT = 1; + private final int KICK_PLAYER_BUTTON_SLOT = 4; + private final int TRANSFER_OWNER_BUTTON_SLOT = 7; + private final int SELECT_SERVER_BUTTON_SLOT = 46; + private final int LEAVE_PARTY_BUTTON_SLOT = 49; + private final int DISBAND_PARTY_BUTTON_SLOW = 52; + private Party _party; public PartyOwnerMenu(Party party, PartyManager plugin) { super("Manage Party", plugin); _party = party; + //We want this disabled by default + if(_party.isOwnerKickMode()) + { + _party.setOwnerKickMode(false); + } } @Override protected Button[] setUp(Player player) { - Button[] buttons = new Button[54]; - //Tools - buttons[1] = new AddPlayerButton(_plugin, _party); + _buttons[ADD_PLAYER_BUTTON_SLOT] = new AddPlayerButton(_plugin, _party); //Kick player - buttons[4] = new KickPlayerButton(_party); + _buttons[KICK_PLAYER_BUTTON_SLOT] = new KickPlayerButton(_party); //Transfer ownership - buttons[7] = new TransferOwnerButton(_party, _plugin); + _buttons[TRANSFER_OWNER_BUTTON_SLOT] = new TransferOwnerButton(_party, _plugin); //Go to server - buttons[46] = new SelectServerButton(_party); + _buttons[SELECT_SERVER_BUTTON_SLOT] = new SelectServerButton(_party); //Leave party - buttons[49] = new LeavePartyButton(); + _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(); //Disband - buttons[52] = new DisbandPartyButton(_plugin); + _buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(_plugin); - int slot = 20; + int slot = STARTING_SLOT; //Players - for(int i = 0; i < _party.getMembers().size(); i++) + for (int i = 0; i < _party.getMembers().size(); i++) { - if(slot == 25) + if (slot == CUT_OFF_SLOT) { - slot = 29; + slot = SKIP_TO_SLOT; } - buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i), _party); + String member = _party.getMembers().get(i); + _buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner())); } if(_party.getSize() == 5) { for(int i = 29; i < 34; i++) { - buttons[i] = PURCHASE_MORE_SLOTS; + _buttons[i] = PURCHASE_MORE_SLOTS; } } - return addPanes(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 b15e2b672..c3c182b6d 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 @@ -10,11 +10,17 @@ import mineplex.core.party.ui.button.tools.view.SuggestPlayerButton; import org.bukkit.entity.Player; /** - * + * The menu a player see's when he is a member, and not an owner, of a party. */ public class PartyViewMenu extends Menu { + private final int STARTING_SLOT = 20; + private final int CUT_OFF_SLOT = 25; + private final int SKIP_TO_SLOT = 29; + private final int LEAVE_PARTY_BUTTON_SLOT = 3; + private final int SUGGEST_PLAYER_BUTTON_SLOT = 5; + private Party _party; public PartyViewMenu(Party party, PartyManager plugin) @@ -26,23 +32,23 @@ public class PartyViewMenu extends Menu @Override protected Button[] setUp(Player player) { - Button[] buttons = new Button[54]; //Tools - buttons[3] = new LeavePartyButton(); + _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(); //Suggest Player - buttons[5] = new SuggestPlayerButton(_party, _plugin); + _buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, _plugin); - int slot = 20; + int slot = STARTING_SLOT; //Players for (int i = 0; i < _party.getMembers().size(); i++) { - if (slot == 25) + if (slot == CUT_OFF_SLOT) { - slot = 29; + slot = SKIP_TO_SLOT; } - buttons[slot++] = new PartyMemberIcon(_party.getMembers().get(i), _party); + String member = _party.getMembers().get(i); + _buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner())); } - return addPanes(buttons); + return addPanes(_buttons); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java index 6e7ad24ab..24de3bc87 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java @@ -7,7 +7,7 @@ import mineplex.core.anvilMenu.PlayerInputActionMenu; import org.bukkit.entity.Player; /** - * + * The anvil menu for filtering the players invite menu */ public class InviteFilterMenu extends PlayerInputActionMenu { @@ -21,7 +21,7 @@ public class InviteFilterMenu extends PlayerInputActionMenu public void inputReceived(String name) { _player.closeInventory(); - if(name.equalsIgnoreCase("Clear Filter")) + if(name.equalsIgnoreCase("Clear Filter") || name.equalsIgnoreCase(" ")) { name = null; } 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 dddc52a48..4e30ebc07 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 @@ -4,12 +4,11 @@ import mineplex.core.anvilMenu.player.PlayerNameMenu; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; import mineplex.core.party.ui.menus.PartyOwnerMenu; -import mineplex.core.anvilMenu.PlayerInputActionMenu; import org.bukkit.Sound; import org.bukkit.entity.Player; /** - * + * The anvil menu for inviting a player to a party */ public class PartyInvitePlayerMenu extends PlayerNameMenu { @@ -25,7 +24,7 @@ public class PartyInvitePlayerMenu extends PlayerNameMenu @Override public void onSuccess(String name) { - _player.chat("/party invite " + name); + _partyManager.getMethodManager().invite(_player, name); _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); _player.closeInventory(); if (_party == null) 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 index c5aeecc4a..8f407393b 100644 --- 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 @@ -4,7 +4,6 @@ import mineplex.core.anvilMenu.player.PlayerNameMenu; import mineplex.core.party.Lang; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; -import mineplex.core.anvilMenu.PlayerInputActionMenu; import org.bukkit.entity.Player; /** @@ -25,7 +24,7 @@ public class PartyTransferOwnerMenu extends PlayerNameMenu @Override public void onSuccess(String name) { - _partyManager.transferOwner(name, _player.getName()); + _partyManager.getMethodManager().transferOwner(name, _player.getName()); Lang.TRANSFER_OWNER.send(_party, _player.getName(), name); _player.closeInventory(); _player.chat("/party"); 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 78b637cdd..d6fb40f38 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 @@ -13,12 +13,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** - * + * The Anvil Menu for handling suggestions */ public class PlayerSuggestPlayerMenu extends PlayerNameMenu { - public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party) { super(partyManager, partyManager.getClientManager(), player, party); @@ -36,6 +35,7 @@ public class PlayerSuggestPlayerMenu extends PlayerNameMenu if(_party.contains(name)) { Lang.ALREADY_MEMBER.send(_player, name); + return; } Player player = Bukkit.getPlayerExact(_party.getOwner()); @@ -45,7 +45,7 @@ public class PlayerSuggestPlayerMenu extends PlayerNameMenu ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Click ")); message.add(F.link("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); + .click(ClickEvent.RUN_COMMAND, "/partyinvite " + name); message.add(C.mBody + " to invite them"); message.sendToPlayer(player); From 1313db40710fbde3952f4ca0e34503c7999a0e04 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Fri, 8 Jul 2016 14:06:16 -0500 Subject: [PATCH 33/53] Commit lost file. --- .../src/mineplex/core/party/PartyEventListener.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java index b00da493c..f7e334a84 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -16,7 +16,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; /** - * + * Event handler for Parties */ public class PartyEventListener implements Listener { @@ -64,9 +64,9 @@ public class PartyEventListener implements Listener _plugin.getInviteManager().cancelTask(player.getUniqueId()); - _plugin.addToParty(Bukkit.getPlayerExact(partyName), party); + _plugin.getMethodManager().addToParty(Bukkit.getPlayerExact(partyName), party); - _plugin.addToParty(player, party); + _plugin.getMethodManager().addToParty(player, party); _plugin.getInviteManager().removeFromWaiting(player.getUniqueId()); @@ -93,14 +93,14 @@ public class PartyEventListener implements Listener reason = PartyRemoveReason.OTHER; } - _plugin.removeFromParty(player, reason); + _plugin.getMethodManager().removeFromParty(player, reason); } @EventHandler public void onTransferOwner(PartyTransferOwnerEvent event) { - _plugin.transferOwner(event.getNewOwner(), event.getOldOwner()); + _plugin.getMethodManager().transferOwner(event.getNewOwner(), event.getOldOwner()); } @EventHandler @@ -108,7 +108,7 @@ public class PartyEventListener implements Listener { Player clicked = Bukkit.getPlayerExact(event.getPlayerClicked()); Lang.REMOVED.send(clicked); - _plugin.removeFromParty(clicked, PartyRemoveReason.KICKED); + _plugin.getMethodManager().removeFromParty(clicked, PartyRemoveReason.KICKED); Menu.get(event.getOwner().getUniqueId()).resetAndUpdate(event.getOwner()); } From cbb0fa37fbc2291dcd94d3638003abd59a6ace75 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Fri, 8 Jul 2016 15:32:25 -0500 Subject: [PATCH 34/53] Lang tweaks. --- .../src/mineplex/core/party/Lang.java | 54 ++++++++++++++----- .../src/mineplex/core/party/Party.java | 2 +- .../party/manager/PartyInviteManager.java | 4 +- .../core/party/manager/PartyRedisManager.java | 4 +- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java index cd99d6ae4..c5b6a745c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -4,6 +4,8 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import org.bukkit.entity.Player; +import java.text.MessageFormat; + /** * All chat messages for the party system to align with PE */ @@ -56,40 +58,68 @@ public enum Lang public void send(Player player, String... args) { - String message = _message; - String colored = ""; + String color = C.mBody; + 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++) { - String s = args[i]; - message = message.replace("{" + i + "}", F.elem(s)); - colored = C.mBody + message; + coloredArgs[i] = C.cYellow + args[i] + color; } - player.sendMessage(C.mHead + "Party> " + colored); + + 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) { - String message = _message; - String colored = ""; + String color = C.mBody; + if(args.length == 0) { party.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++) { - String s = args[i]; - message = message.replace("{" + i + "}", F.elem(s)); - colored = C.mBody + message; + coloredArgs[i] = C.cYellow + args[i] + color; } - party.sendMessage(C.mHead + "Party> " + colored); + + String message = MessageFormat.format(_message, coloredArgs); + + String coloredRest = message.substring(firstIndex); + + message = color + message.substring(0, firstIndex) + coloredRest; + + party.sendMessage(C.mHead + "Party> " + message); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 766832098..094435e10 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -15,7 +15,7 @@ import java.util.Map; import java.util.UUID; /** - * Uh, yeah, I'll get back to this when it isn't 2 AM + * The main object for Parites. */ public class Party { 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 7f433c098..cb6195a07 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -386,8 +386,8 @@ public class PartyInviteManager textComponent.addExtra(deny); textComponent.addExtra(" "); - TextComponent view = new TextComponent("VIEW INVITES"); - view.setColor(ChatColor.GOLD); + TextComponent view = new TextComponent("VIEW"); + view.setColor(ChatColor.YELLOW); view.setBold(true); view.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/openinvitesmenu")); view.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ 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 e15b2595b..12f06980d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -160,7 +160,7 @@ public class PartyRedisManager */ public void findAndInvite(String player, String sender) { - Bukkit.getPlayerExact(sender).sendMessage(F.main("Party", "Locating " + player + "...")); + Bukkit.getPlayerExact(sender).sendMessage(F.main("Party", "Locating " + F.elem(player) + "...")); TASKS.put(player, new BukkitRunnable() { @Override @@ -180,7 +180,7 @@ public class PartyRedisManager } senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player) + ".")); } - }.runTaskLater(_plugin.getPlugin(), 20L * 10)); + }.runTaskLater(_plugin.getPlugin(), 20L * 5)); _plugin.runAsync(() -> { try (Jedis jedis = _writePool.getResource()) From 2cac4c9c66fb780c0925ce879cfe8c48f23be0ab Mon Sep 17 00:00:00 2001 From: Timothy Andis Date: Fri, 8 Jul 2016 16:17:48 -0500 Subject: [PATCH 35/53] Remove toLowerCase owner method --- .../src/mineplex/core/party/manager/PartyMethodManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java index 8001c82d5..4d2a5c21e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java @@ -329,7 +329,7 @@ public class PartyMethodManager { return; } - _plugin.getParties().put(newOwner.toLowerCase(), party); + _plugin.getParties().put(newOwner, party); party.setOwner(newOwner); party.getMembers().remove(oldOwner); party.getMembers().add(oldOwner); From 36f2873e1538f81932e891f79deb1bdff04a17d0 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Mon, 18 Jul 2016 19:00:11 -0500 Subject: [PATCH 36/53] Map Parser update. --- .../src/mineplex/mapparser/GameType.java | 2 + .../src/mineplex/mapparser/GameTypeInfo.java | 60 ++ .../src/mineplex/mapparser/MapData.java | 128 ++- .../src/mineplex/mapparser/MapParser.java | 934 ++++-------------- .../src/mineplex/mapparser/Parse.java | 43 +- .../src/mineplex/mapparser/WorldManager.java | 17 +- .../command/AddSplashTextCommand.java | 58 ++ .../mapparser/command/AdminCommand.java | 8 +- .../mapparser/command/AuthorCommand.java | 7 +- .../mapparser/command/CopyCommand.java | 6 +- .../mapparser/command/CreateCommand.java | 39 +- .../command/CurrentlyLiveCommand.java | 38 + .../mapparser/command/DeleteCommand.java | 12 +- .../mapparser/command/GameTypeCommand.java | 10 +- .../mapparser/command/InfoCommand.java | 81 ++ .../mapparser/command/LockCommand.java | 35 + .../mapparser/command/MapCommand.java | 28 +- .../mapparser/command/NameCommand.java | 7 +- .../mapparser/command/ParseCommand200.java | 4 +- .../mapparser/command/ParseCommand400.java | 4 +- .../mapparser/command/ParseCommand600.java | 4 +- .../mapparser/command/PlayerHeadCommand.java | 37 + .../command/RefreshWorldEditCommand.java | 31 + .../mapparser/command/RenameCommand.java | 3 +- .../mapparser/command/SaveCommand.java | 6 +- .../mapparser/command/WarpCommand.java | 82 ++ .../src/mineplex/mapparser/module/Module.java | 50 + .../module/modules/CommandModule.java | 99 ++ .../mapparser/module/modules/EventModule.java | 353 +++++++ .../module/modules/MMMazeModule.java | 127 +++ .../mapparser/module/modules/SignModule.java | 112 +++ .../module/modules/TreeToolModule.java | 119 +++ 32 files changed, 1677 insertions(+), 867 deletions(-) create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java index a6a4c2880..c0deac097 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java @@ -38,6 +38,7 @@ public enum GameType Micro("Micro Battle"), MineStrike("MineStrike"), MineWare("MineWare"), + MinecraftLeague("MCL"), MilkCow("Milk the Cow"), MonsterLeague("MonsterLeague"), MonsterMaze("Monster Maze"), @@ -53,6 +54,7 @@ public enum GameType SmashDomination("Super Smash Mobs Domination", "Super Smash Mobs"), Snake("Snake"), SneakyAssassins("Sneaky Assassins"), + SpeedBuilders("SpeedBuilders"), SnowFight("Snow Fight"), Spleef("Super Spleef"), SpleefTeams("Super Spleef Teams"), diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java new file mode 100644 index 000000000..7ff04194b --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java @@ -0,0 +1,60 @@ +package mineplex.mapparser; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * + */ +public class GameTypeInfo +{ + + private final String LINE = C.cAqua + C.Bold + C.Strike + "========================================"; + + private GameType _gameType; + private List _info; + + public GameTypeInfo(GameType gameType, List info) + { + _gameType = gameType; + _info = info; + } + + public void addInfo(String info) + { + _info.add(info); + } + + public void remove(int index) + { + _info.remove(index); + } + + public List getInfo() + { + return _info; + } + + public void sendInfo(Player player) + { + player.sendMessage(LINE); + player.sendMessage(" "); + player.sendMessage(F.elem(_gameType.GetName())); + player.sendMessage(" "); + for(String s : _info) + { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', s)); + } + player.sendMessage(" "); + player.sendMessage(LINE); + } + + public GameType getGameType() + { + return _gameType; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java index 3248ac842..a87e4e8b9 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java @@ -1,5 +1,11 @@ package mineplex.mapparser; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import mineplex.core.common.util.UtilWorld; +import org.bukkit.Location; +import org.bukkit.entity.Player; + import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; @@ -7,30 +13,39 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; -import java.util.HashSet; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; -import org.bukkit.entity.Player; - -public class MapData +public class MapData { public String MapFolder; + public boolean _currentlyLive; + public boolean _locked; + public Map _warps; public GameType MapGameType = null; public String MapName = "null"; public String MapCreator = "null"; - public HashSet AdminList; - + public Set AdminList; + public MapData(String mapFolder) { MapFolder = mapFolder; - AdminList = new HashSet(); - + AdminList = Sets.newHashSet(); + _warps = Maps.newHashMap(); + _currentlyLive = false; + if ((new File(MapFolder + File.separator + "Map.dat")).exists()) + { Read(); - else + } else + { Write(); + } } public void Read() @@ -43,46 +58,74 @@ public class MapData DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); - while ((line = br.readLine()) != null) + while ((line = br.readLine()) != null) { String[] tokens = line.split(":"); if (tokens.length < 2) + { continue; + } if (tokens[0].length() == 0) + { continue; + } + + if(tokens[0].equalsIgnoreCase("locked")) + { + _locked = tokens[1].equalsIgnoreCase("true"); + continue; + } + + if (tokens[0].equalsIgnoreCase("currentlyLive")) + { + _currentlyLive = tokens[1].equalsIgnoreCase("true"); + continue; + } + + if (tokens[0].equalsIgnoreCase("warps")) + { + for (String s : tokens[1].split(";")) + { + String[] str = s.split("@"); + _warps.put(str[0], UtilWorld.strToLoc(str[1])); + } + continue; + } //Name & Author if (tokens[0].equalsIgnoreCase("MAP_NAME")) { MapName = tokens[1]; + continue; } - else if (tokens[0].equalsIgnoreCase("MAP_AUTHOR")) + + if (tokens[0].equalsIgnoreCase("MAP_AUTHOR")) { MapCreator = tokens[1]; + continue; } - else if (tokens[0].equalsIgnoreCase("GAME_TYPE")) + + if (tokens[0].equalsIgnoreCase("GAME_TYPE")) { try { MapGameType = GameType.valueOf(tokens[1] == null ? "Unknown" : tokens[1]); - } - catch (Exception e) + } catch (Exception e) { MapGameType = GameType.Unknown; } + continue; } - else if (tokens[0].equalsIgnoreCase("ADMIN_LIST") || tokens[0].equalsIgnoreCase("BUILD_LIST")) + if (tokens[0].equalsIgnoreCase("ADMIN_LIST") || tokens[0].equalsIgnoreCase("BUILD_LIST")) { - for (String cur : tokens[1].split(",")) - AdminList.add(cur); + Collections.addAll(AdminList, tokens[1].split(",")); } } in.close(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); System.err.println("Line: " + line); @@ -97,39 +140,60 @@ public class MapData FileWriter fstream = new FileWriter(MapFolder + File.separator + "Map.dat"); BufferedWriter out = new BufferedWriter(fstream); - out.write("MAP_NAME:"+MapName); + out.write("MAP_NAME:" + MapName); out.write("\n"); - out.write("MAP_AUTHOR:"+MapCreator); + out.write("MAP_AUTHOR:" + MapCreator); out.write("\n"); - out.write("GAME_TYPE:"+MapGameType); - + out.write("GAME_TYPE:" + MapGameType); + String adminList = ""; + for (String cur : AdminList) + { adminList += cur + ","; - + } + out.write("\n"); - out.write("ADMIN_LIST:"+adminList); + out.write("ADMIN_LIST:" + adminList); + out.write("\n"); + out.write("currentlyLive:" + _currentlyLive); + out.write("\n"); + out.write("warps:" + warpsToString()); out.close(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); } } - public boolean HasAccess(Player player) + public String warpsToString() + { + StringBuilder builder = new StringBuilder(); + int i = 0; + for (Entry entry : _warps.entrySet()) + { + builder.append(entry.getKey()).append("@").append(UtilWorld.locToStr(entry.getValue())); + if (++i != _warps.size()) + { + builder.append(","); + } + } + return builder.toString(); + } + + public boolean HasAccess(Player player) { return AdminList.contains(player.getName()) || player.isOp(); } - - public boolean CanJoin(Player player) + + public boolean CanJoin(Player player) { - return true; + return !_locked || (player.isOp() || AdminList.contains(player.getName())); } public boolean CanRename(Player player) { - return true; + return !_locked || (player.isOp() || AdminList.contains(player.getName())); } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index 86a7e7b6c..0d4a5c937 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -1,222 +1,138 @@ package mineplex.mapparser; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; -import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEvent; -import mineplex.core.common.util.UtilEvent.ActionType; -import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; -import mineplex.mapparser.command.*; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; +import mineplex.mapparser.command.AddLoreCommand; +import mineplex.mapparser.command.AddSplashTextCommand; +import mineplex.mapparser.command.AdminCommand; +import mineplex.mapparser.command.AuthorCommand; +import mineplex.mapparser.command.ClearLoreCommand; +import mineplex.mapparser.command.CopyCommand; +import mineplex.mapparser.command.CopySchematicsCommand; +import mineplex.mapparser.command.CreateCommand; +import mineplex.mapparser.command.CurrentlyLiveCommand; +import mineplex.mapparser.command.DeleteCommand; +import mineplex.mapparser.command.GameTypeCommand; +import mineplex.mapparser.command.HubCommand; +import mineplex.mapparser.command.InfoCommand; +import mineplex.mapparser.command.ItemNameCommand; +import mineplex.mapparser.command.ListCommand; +import mineplex.mapparser.command.LockCommand; +import mineplex.mapparser.command.MapCommand; +import mineplex.mapparser.command.NameCommand; +import mineplex.mapparser.command.ParseCommand200; +import mineplex.mapparser.command.ParseCommand400; +import mineplex.mapparser.command.ParseCommand600; +import mineplex.mapparser.command.PlayerHeadCommand; +import mineplex.mapparser.command.RefreshWorldEditCommand; +import mineplex.mapparser.command.RenameCommand; +import mineplex.mapparser.command.SaveCommand; +import mineplex.mapparser.command.SetSpawnCommand; +import mineplex.mapparser.command.SpawnCommand; +import mineplex.mapparser.command.WarpCommand; +import mineplex.mapparser.command.WorldsCommand; +import mineplex.mapparser.module.Module; +import mineplex.mapparser.module.modules.CommandModule; +import mineplex.mapparser.module.modules.EventModule; +import mineplex.mapparser.module.modules.MMMazeModule; +import mineplex.mapparser.module.modules.SignModule; +import mineplex.mapparser.module.modules.TreeToolModule; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockFadeEvent; -import org.bukkit.event.block.BlockFormEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; -import org.bukkit.event.block.BlockSpreadEvent; -import org.bukkit.event.block.LeavesDecayEvent; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; -public class MapParser extends JavaPlugin implements Listener +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class MapParser extends JavaPlugin { private WorldManager _worldManager; private Parse _curParse = null; - private HashMap _mapData = new HashMap(); - private HashSet _mapsBeingZipped = new HashSet(); - private List _commands = new ArrayList(); + private final Map, Module> _modules = Maps.newHashMap(); + private final Map _infoMap = Maps.newHashMap(); + private final Map _mapData = Maps.newHashMap(); + public final Set _mapsBeingZipped = Sets.newHashSet(); + private List _additionalText = Lists.newArrayList(); private Location _spawnLocation; - private HashMap _permissionMap = new HashMap(); @Override public void onEnable() { _worldManager = new WorldManager(this); - getServer().getPluginManager().registerEvents(this, this); - getServer().getWorlds().get(0).setSpawnLocation(0, 106, 0); _spawnLocation = new Location(getServer().getWorlds().get(0), 0, 106, 0); //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Ticker(this), 1, 1); - _commands.add(new AuthorCommand(this)); - _commands.add(new AdminCommand(this)); - _commands.add(new CopySchematicsCommand(this)); - _commands.add(new CreateCommand(this)); - _commands.add(new DeleteCommand(this)); - _commands.add(new GameTypeCommand(this)); - _commands.add(new HubCommand(this)); - _commands.add(new ListCommand(this)); - _commands.add(new MapCommand(this)); - _commands.add(new NameCommand(this)); - _commands.add(new ParseCommand200(this)); - _commands.add(new ParseCommand400(this)); - _commands.add(new ParseCommand600(this)); - _commands.add(new RenameCommand(this)); - _commands.add(new SaveCommand(this)); - _commands.add(new WorldsCommand(this)); - _commands.add(new CopyCommand(this)); - _commands.add(new SpawnCommand(this)); - _commands.add(new SetSpawnCommand(this)); - _commands.add(new ItemNameCommand(this)); - _commands.add(new AddLoreCommand(this)); - _commands.add(new ClearLoreCommand(this)); + CommandModule commandModule = new CommandModule(this); + new EventModule(this); + new MMMazeModule(this); + new SignModule(this); + new TreeToolModule(this); + + commandModule.add(new AuthorCommand(this)); + commandModule.add(new AdminCommand(this)); + commandModule.add(new CopySchematicsCommand(this)); + commandModule.add(new CreateCommand(this)); + commandModule.add(new DeleteCommand(this)); + commandModule.add(new GameTypeCommand(this)); + commandModule.add(new HubCommand(this)); + commandModule.add(new ListCommand(this)); + commandModule.add(new MapCommand(this)); + commandModule.add(new NameCommand(this)); + commandModule.add(new ParseCommand200(this)); + commandModule.add(new ParseCommand400(this)); + commandModule.add(new ParseCommand600(this)); + commandModule.add(new RenameCommand(this)); + commandModule.add(new SaveCommand(this)); + commandModule.add(new WorldsCommand(this)); + commandModule.add(new CopyCommand(this)); + commandModule.add(new SpawnCommand(this)); + commandModule.add(new SetSpawnCommand(this)); + commandModule.add(new ItemNameCommand(this)); + commandModule.add(new AddLoreCommand(this)); + commandModule.add(new ClearLoreCommand(this)); + commandModule.add(new InfoCommand(this)); + commandModule.add(new LockCommand(this)); + commandModule.add(new PlayerHeadCommand(this)); + commandModule.add(new RefreshWorldEditCommand(this)); + commandModule.add(new WarpCommand(this)); + commandModule.add(new CurrentlyLiveCommand(this)); + commandModule.add(new AddSplashTextCommand(this)); + loadInfo(); + addSplashText(); } @Override public void onDisable() { - - } - - @EventHandler - public void PlayerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - - player.teleport(getSpawnLocation()); - - ResetInventory(event.getPlayer()); - - DisplayHelp(player); + _infoMap.values().forEach(this::saveInfo); + saveSplashText(); } - @EventHandler - public void permissionUpdate(TickEvent event) + public Parse getCurParse() { - for (Player player : UtilServer.getPlayers()) - { - permissionSet(player); - } - } - - public void permissionSet(Player player) - { - boolean hasPermission = GetData(player.getWorld().getName()).HasAccess(player); - - if (!_permissionMap.containsKey(player) || _permissionMap.get(player) != hasPermission) - { - for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) - { - player.addAttachment(plugin, "worldedit.*", hasPermission); - player.addAttachment(plugin, "voxelsniper.sniper", hasPermission); - player.addAttachment(plugin, "voxelsniper.brush.*", hasPermission); - player.addAttachment(plugin, "coloredsigns.format", hasPermission); - } - - _permissionMap.put(player, hasPermission); - - UtilPlayer.message(player, "Plugin Permissions: " + F.tf(hasPermission)); - } - } - - - public void DisplayHelp(Player player) - { - UtilPlayer.message(player, F.main("Parser", "Listing Commands;")); - UtilPlayer.message(player, F.value("Parameters", "Parameters: = Required, [?] = Optional")); - UtilPlayer.message(player, F.value("/hub", "Return to hub world")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/name ", "Set name for current map")); - UtilPlayer.message(player, F.value("/author ", "Set author for current map")); - UtilPlayer.message(player, F.value("/gametype ", "Set gametype for current map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/admin ", "Toggle admin for player on map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/create [gametype]", "Creates a new map")); - UtilPlayer.message(player, F.value("/delete [gametype]", "Deletes an existing map")); - UtilPlayer.message(player, F.value("/copy ", "Copies an existing map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/list", "List maps")); - UtilPlayer.message(player, F.value("/map [gametype]", "Teleport to a map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, C.cYellow + "Documentation: " + C.cGreen + "http://tinyurl.com/mpxmaps"); - - } - - @EventHandler - public void Command(PlayerCommandPreprocessEvent event) - { - Player player = event.getPlayer(); - - String[] parts = event.getMessage().split(" "); - String commandLabel = parts[0].substring(1); - String[] args = new String[parts.length - 1]; - System.arraycopy(parts, 1, args, 0, parts.length - 1); - - if (_curParse != null) - { - UtilPlayer.message(player, F.main("Parser", "Cannot use commands during Map Parse!")); - return; - } - if (event.getMessage().toLowerCase().startsWith("/help")) - { - event.setCancelled(true); - - DisplayHelp(player); - } - - for (BaseCommand command : _commands) - { - for (String alias : command.getAliases()) - { - if (alias.equalsIgnoreCase(commandLabel)) - { - event.setCancelled(true); - - if (!command.execute(player, commandLabel, args)) - { - UtilPlayer.message(player, F.main("Parser", "Invalid Input.")); - UtilPlayer.message(player, F.elem(command.getUsage())); - } - - return; - } - } - } + return _curParse; } public void sendValidGameTypes(Player player) @@ -233,128 +149,105 @@ public class MapParser extends JavaPlugin implements Listener player.sendMessage(gameTypes); } - @EventHandler - public void ParseUpdate(TickEvent event) + public GameTypeInfo getInfo(GameType type) { - if (_curParse == null) - return; + return _infoMap.get(type); + } - if (_curParse.Update()) + private void addSplashText() + { + File file = new File(getDataFolder(), "join-text.yml"); + if(!file.exists()) { - Announce("Parse Completed!"); - - Announce("Cleaning and Creating ZIP..."); - try { - _worldManager.finalizeParsedWorld(_curParse.getWorld()); - } - catch (Exception e) + file.createNewFile(); + } catch (IOException e) { - Announce("Creating ZIP Failed! Please Try Again!"); e.printStackTrace(); } - - _curParse = null; } - } - - @EventHandler - public void DisableCreatures(EntitySpawnEvent event) - { - if (event.getEntityType() == EntityType.DROPPED_ITEM || event.getEntity() instanceof LivingEntity) - event.setCancelled(true); - } - - @EventHandler - public void DisableBurn(BlockBurnEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void DisableIgnite(BlockIgniteEvent event) - { - if (event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD) - event.setCancelled(true); - } - - @EventHandler - public void DisableFire(BlockSpreadEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void DisableFade(BlockFadeEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void DisableDecay(LeavesDecayEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void DisableIceForm(BlockFormEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void Updates(PlayerMoveEvent event) - { - for (World world : this.getServer().getWorlds()) + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + List messages = config.getStringList("messages"); + if(messages == null) { - if (world.getName().toLowerCase().contains("halloween")) - world.setTime(16000); - else - world.setTime(8000); - world.setStorm(false); + messages = Lists.newArrayList(); } - - - if (event.getPlayer().getGameMode() != GameMode.CREATIVE) - event.getPlayer().setGameMode(GameMode.CREATIVE); + _additionalText = messages; } - @EventHandler - public void SaveUnloadWorlds(TickEvent event) + private void saveSplashText() { - for (final World world : getServer().getWorlds()) + File file = new File(getDataFolder(), "join-text.yml"); + if(!file.exists()) { - if (world.getName().equalsIgnoreCase("world")) - continue; - - if (world.getName().startsWith("parse_")) - continue; - - if (!world.getName().startsWith("map")) - continue; - - if (world.getPlayers().isEmpty()) + try { - Announce("Saving & Closing World: " + F.elem(world.getName())); - MapUtil.UnloadWorld(this, world, true); - - _mapsBeingZipped.add(world.getName()); - System.out.println("Starting backup of " + world); - BackupTask backupTask = new BackupTask(this, world.getName(), new Callback() - { - @Override - public void run(Boolean data) - { - System.out.println("Finished backup of " + world); - _mapsBeingZipped.remove(world.getName()); - } - }); + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); } } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + config.set("messages", _additionalText); + try + { + config.save(file); + } catch (IOException e) + { + e.printStackTrace(); + } } - public void Announce(String msg) + private void loadInfo() + { + File file = new File(getDataFolder(), "info.yml"); + if(!file.exists()) + { + try + { + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + + for(String s : config.getKeys(false)) + { + GameType gameType = GameType.valueOf(s); + List messages = config.getStringList(s); + _infoMap.put(gameType, new GameTypeInfo(gameType, messages)); + } + } + + private void saveInfo(GameTypeInfo info) + { + File file = new File(getDataFolder(), "info.yml"); + if(!file.exists()) + { + try + { + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + config.set(info.getGameType().name(), info.getInfo()); + try + { + config.save(file); + } catch (IOException e) + { + e.printStackTrace(); + } + } + + public void announce(String msg) { for (Player player : UtilServer.getPlayers()) { @@ -364,19 +257,17 @@ public class MapParser extends JavaPlugin implements Listener System.out.println("[Announce] " + msg); } - public boolean DoesMapExist(String mapName, GameType gameType) + public boolean doesMapExist(String mapName, GameType gameType) { - return DoesMapExist(getWorldString(mapName, gameType)); + return doesMapExist(getWorldString(mapName, gameType)); } - public boolean DoesMapExist(String worldName) + public boolean doesMapExist(String worldName) { File file = new File(worldName); - if (file.exists() && file.isDirectory()) - return true; + return file.exists() && file.isDirectory(); - return false; } public String getShortWorldName(String worldName) @@ -389,12 +280,7 @@ public class MapParser extends JavaPlugin implements Listener return worldName; } - public World GetMapWorld(String mapName, GameType gameType) - { - return GetMapWorld(getWorldString(mapName, gameType)); - } - - public World GetMapWorld(String worldName) + public World getMapWorld(String worldName) { for (World world : this.getServer().getWorlds()) { @@ -414,14 +300,14 @@ public class MapParser extends JavaPlugin implements Listener { name = name.toLowerCase(); - List maps = new LinkedList(); + List maps = new LinkedList<>(); boolean matchesExact = false; for (GameType type : GameType.values()) { File mapsFolder = new File("map" + File.separator + type.GetName()); - if (!mapsFolder.exists()) + if (!mapsFolder.exists() || mapsFolder.listFiles() == null) continue; for (File file : mapsFolder.listFiles()) @@ -456,7 +342,7 @@ public class MapParser extends JavaPlugin implements Listener return maps; } - public MapData GetData(String mapName) + public MapData getData(String mapName) { if (_mapData.containsKey(mapName)) return _mapData.get(mapName); @@ -473,17 +359,6 @@ public class MapParser extends JavaPlugin implements Listener return _spawnLocation; } - public void ResetInventory(Player player) - { - // UtilInv.Clear(player); - // - // player.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); - // player.getInventory().addItem(new ItemStack(Material.STONE_SPADE)); - // player.getInventory().addItem(new ItemStack(Material.STONE_PICKAXE)); - // player.getInventory().addItem(new ItemStack(Material.STONE_AXE)); - // player.getInventory().addItem(new ItemStack(Material.WOOD_AXE)); - } - public WorldManager getWorldManager() { return _worldManager; @@ -494,346 +369,12 @@ public class MapParser extends JavaPlugin implements Listener _curParse = parse; } - @EventHandler - public void Chat(AsyncPlayerChatEvent event) - { - event.setCancelled(true); - - String world = C.cDGreen + C.Bold + getShortWorldName(event.getPlayer().getWorld().getName()); - - - - String name = C.cYellow + event.getPlayer().getName(); - if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - name = C.cGreen + event.getPlayer().getName(); - - String grayName = C.cBlue + event.getPlayer().getName(); - String grayWorld = C.cBlue + C.Bold + event.getPlayer().getWorld().getName(); - - for (Player player : UtilServer.getPlayers()) - { - if (player.getWorld().equals(event.getPlayer().getWorld())) - { - player.sendMessage(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage()); - } - else - { - player.sendMessage(grayWorld + ChatColor.RESET + " " + grayName + ChatColor.RESET + " " + C.cGray + event.getMessage()); - } - - } - - System.out.println(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage()); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void InteractCancel(PlayerInteractEvent event) - { - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void commandCancel(PlayerCommandPreprocessEvent event) - { - if (event.getMessage().startsWith("/tp") || - event.getMessage().startsWith("/hub") || - event.getMessage().startsWith("/list") || - event.getMessage().startsWith("/map") || - event.getMessage().startsWith("/create") || - event.getMessage().startsWith("/copy") || - event.getMessage().startsWith("/delete")) - return; - - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), F.main("Parser", "You do not have Build-Access for this Map.")); - event.setCancelled(true); - } - } - - public HashSet getMapsBeingZipped() + public Set getMapsBeingZipped() { return _mapsBeingZipped; } - - @EventHandler - public void Join(PlayerJoinEvent event) - { - event.setJoinMessage(F.sys("Player Join", event.getPlayer().getName())); - } - - @EventHandler - public void Join(PlayerQuitEvent event) - { - event.setQuitMessage(F.sys("Player Quit", event.getPlayer().getName())); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void TeleportCommand(PlayerCommandPreprocessEvent event) - { - if (!event.getMessage().toLowerCase().startsWith("/tp")) - return; - - Player player = event.getPlayer(); - - String[] tokens = event.getMessage().split(" "); - - if (tokens.length != 2) - { - return; - } - - event.setCancelled(true); - - Player target = UtilPlayer.searchOnline(player, tokens[1], true); - if (target != null) - { - UtilPlayer.message(player, F.main("Game", "You teleported to " + F.name(target.getName()) + ".")); - player.teleport(target); - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void FlySpeed(PlayerCommandPreprocessEvent event) - { - if (!event.getMessage().toLowerCase().startsWith("/speed")) - return; - - Player player = event.getPlayer(); - - String[] tokens = event.getMessage().split(" "); - - if (tokens.length != 2) - { - return; - } - - event.setCancelled(true); - - try - { - float speed = Float.parseFloat(tokens[1]); - - player.setFlySpeed(speed); - - UtilPlayer.message(player, F.main("Game", "Fly Speed set to " + F.elem("" + speed) + ".")); - } - catch (Exception e) - { - UtilPlayer.message(player, F.main("Game", "Invalid Speed Input.")); - } - } - - private HashMap>> treeHistory = new HashMap>>(); - - @EventHandler(priority = EventPriority.HIGHEST) - public void treeRemover(PlayerInteractEvent event) - { - if (event.isCancelled()) - return; - - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - return; - } - - Player player = event.getPlayer(); - - if (!UtilGear.isMat(player.getItemInHand(), Material.NETHER_STAR)) - return; - - event.setCancelled(true); - - //Remove - if (event.getAction() == Action.LEFT_CLICK_BLOCK) - { - if (event.getClickedBlock().getType() != Material.LOG) - { - player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); - return; - } - - HashSet toRemove = searchLog(new HashSet(), event.getClickedBlock()); - - if (toRemove.isEmpty()) - { - player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); - return; - } - - HashSet history = new HashSet(); - - for (Block block : toRemove) - { - history.add(new BlockData(block)); - - block.setType(Material.AIR); - } - - if (!treeHistory.containsKey(player)) - treeHistory.put(player, new ArrayList>()); - - treeHistory.get(player).add(0, history); - - player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Removed"); - - while (treeHistory.get(player).size() > 10) - treeHistory.get(player).remove(10); - } - else if (UtilEvent.isAction(event, ActionType.R)) - { - if (!treeHistory.containsKey(player) || treeHistory.get(player).isEmpty()) - { - player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "No Tree History"); - return; - } - - HashSet datas = treeHistory.get(player).remove(0); - - for (BlockData data : datas) - data.restore(); - - player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored"); - } - } - - @EventHandler - public void mmMazeParser(PlayerInteractEvent event) - { - if (event.isCancelled()) - return; - - if (event.getAction() != Action.LEFT_CLICK_BLOCK) return; - - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - return; - } - - Player player = event.getPlayer(); - - if (!UtilGear.isMat(player.getItemInHand(), Material.WEB)) - return; - - event.setCancelled(true); - - // parse - - Block clicked = event.getClickedBlock(); - Location center = clicked.getLocation(); - Location lowestCorner = center.clone().subtract(49, 0, 49); - - // 0 = air or other - // 1 = path - quartz - // 2 = mob spawn - gold - // 3 = safe spawn - stone - - int[][] maze = new int[99][99]; - - /*Iterator iter = blocks.iterator(); - while(iter.hasNext()) - { - Block b = iter.next(); - switch (b.getType()) { - case QUARTZ_BLOCK: - maze[x][y] = 1; - break; - - case GOLD_BLOCK: - maze[x][y] = 2; - break; - - case STONE: - maze[x][y] = 3; - break; - - default: - maze[x][y] = 0; - break; - } - x++; - if(x > 99) - { - y++; - x = 0; - } - if(y > 99) - { - System.out.println("y > 99"); - break; - } - }*/ - - for (int i = 0; i < 99; i++) - for (int j = 0; j < 99; j++) - maze[i][j] = getMMParseValue(lowestCorner.clone().add(j, 0, i).getBlock().getType()); - - //Save - try - { - FileWriter fstream = new FileWriter(GetData(player.getWorld().getName()).MapFolder + File.separator + "Maze.dat"); - BufferedWriter out = new BufferedWriter(fstream); - - out.write("private static final int[][] PARSED_MAZE = {" + System.lineSeparator()); - for (int j[] : maze) - { - out.write("{"); - boolean first = true; - for (int k : j) - { - if(!first) out.write(","); - out.write(k + ""); - - first = false; - } - out.write("}," + System.lineSeparator()); - } - out.write("};" + System.lineSeparator()); - - out.close(); - } - catch (Exception e) - { - player.sendMessage(C.cRed + C.Bold + "MMMazeParse: " + ChatColor.RESET + "An error has occured, see console."); - e.printStackTrace(); - } - player.sendMessage(C.cGreen + C.Bold + "MMMazeParse: " + ChatColor.RESET + "Maze parsed."); - } - private int getMMParseValue(Material m) - { - switch (m) { - case QUARTZ_BLOCK: - return 1; - - case GOLD_BLOCK: - return 2; - - case STONE: - return 3; - - case DIRT: - return 4; - - case COBBLESTONE: - return 5; - - case BRICK: - return 6; - - default: - return 0; - } - } - - private HashSet searchLog(HashSet blocks, Block current) + public Set searchLog(Set blocks, Block current) { //Not Tree if (current.getType() != Material.LOG && current.getType() != Material.LEAVES) @@ -860,110 +401,23 @@ public class MapParser extends JavaPlugin implements Listener return blocks; } - long lastUse = 0; - @EventHandler(priority = EventPriority.LOWEST) - public void leaptest(PlayerInteractEvent event) + public Map, Module> getModules() { - - if (event.getPlayer().getItemInHand() == null) - return; - - if (event.getPlayer().getItemInHand().getType() != Material.FEATHER) - return; - - if (System.currentTimeMillis() - lastUse < 800) - { - Bukkit.broadcastMessage("Cooldown"); - return; - } - - - lastUse = System.currentTimeMillis(); - - Vector vel = event.getPlayer().getLocation().getDirection().multiply(1.2); - vel.add(new Vector(0,0.6,0)); - - event.getPlayer().setVelocity(vel); + return _modules; } - @EventHandler(priority = EventPriority.LOWEST) - public void signChangeLog(SignChangeEvent event) + public void setInfo(GameType gameType, GameTypeInfo info) { - if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - ArrayList text = new ArrayList(); - - text.add("Date: " + UtilTime.now()); - text.add("Player: " + event.getPlayer().getName()); - text.add("Location: " + UtilWorld.locToStrClean(event.getBlock().getLocation())); - for (int i=0 ; i text = new ArrayList(); - - text.add("Date: " + UtilTime.now()); - text.add("Player: " + event.getPlayer().getName()); - text.add("Location: " + UtilWorld.locToStrClean(event.getPlayer().getLocation())); - text.add("Message: " + event.getMessage()); - - writeSignCommandLog(text, event.getPlayer().getWorld()); - } - } - - public void writeSignCommandLog(ArrayList text, World world) - { - try - { - File file = new File(world.getName() + "/" + "command_sign_log.txt"); - if (!file.exists()) - file.createNewFile(); - - FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - BufferedWriter bw = new BufferedWriter(fw); - - bw.write("\n\n"); - for (String line : text) - bw.write("\n" + line); - - bw.close(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public void writeSignLog(ArrayList text, World world) + public List getAdditionalText() { - try - { - File file = new File(world.getName() + "/" + "sign_log.txt"); + return _additionalText; + } - if (!file.exists()) - file.createNewFile(); - - FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - BufferedWriter bw = new BufferedWriter(fw); - - bw.write("\n\n"); - for (String line : text) - bw.write("\n" + line); - - bw.close(); - } - catch (Exception e) - { - e.printStackTrace(); - } + public void addAdditionalText(String s) + { + _additionalText.add(s); } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java index 79d74e141..27184accb 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java @@ -1,16 +1,8 @@ package mineplex.mapparser; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; - import mineplex.core.common.util.F; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -19,6 +11,13 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.material.Wool; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + public class Parse { //Parse Data @@ -59,14 +58,14 @@ public class Parse _size = size; for (String arg : args) - Host.Announce("Parse Arg: " + F.elem(arg)); + Host.announce("Parse Arg: " + F.elem(arg)); Initialize(); } private void Initialize() { - Host.Announce("Commencing Parse of World: " + F.elem(_world.getName())); + Host.announce("Commencing Parse of World: " + F.elem(_world.getName())); //Take BlockID Arguments for (String arg : _args) @@ -77,7 +76,7 @@ public class Parse } catch (Exception e) { - Host.Announce("Invalid Data ID: " + F.elem(arg)); + Host.announce("Invalid Data ID: " + F.elem(arg)); } } @@ -102,7 +101,7 @@ public class Parse _processed++; if (_processed % 10000000 == 0) - Host.Announce("Scanning World: " + F.elem((int)(_processed/1000000) + "M of " + (int)(((_size*2)*(_size*2)*256)/1000000) + "M")); + Host.announce("Scanning World: " + F.elem((int)(_processed/1000000) + "M of " + (int)(((_size*2)*(_size*2)*256)/1000000) + "M")); Block block = _world.getBlockAt(_callLoc.getBlockX()+_x, _y, _callLoc.getBlockZ()+_z); @@ -144,7 +143,7 @@ public class Parse } catch (Exception e) { - Host.Announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); + Host.announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); } //Add @@ -176,21 +175,21 @@ public class Parse if (_cornerA == null) { _cornerA = wool.getLocation(); - Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); + Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); } else if (_cornerB == null) { _cornerB = wool.getLocation(); - Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); + Host.announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); } else { - Host.Announce("More than 2 Corner Markers:"); - Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); - Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); - Host.Announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); + Host.announce("More than 2 Corner Markers:"); + Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); + Host.announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); + Host.announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); } //Remove Blocks @@ -414,7 +413,7 @@ public class Parse if (_cornerA == null || _cornerB == null) { - Host.Announce("Missing Corner Locations! Defaulted to -256 to +256."); + Host.announce("Missing Corner Locations! Defaulted to -256 to +256."); _cornerA = new Location(_world, -256, 0, -256); _cornerB = new Location(_world, 256, 0, 256); @@ -487,12 +486,12 @@ public class Parse } catch (Exception e) { - Host.Announce("Error: File Write Error"); + Host.announce("Error: File Write Error"); e.printStackTrace(); } - Host.Announce("WorldConfig.dat Saved."); + Host.announce("WorldConfig.dat Saved."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java index 8658ae526..56e3b7218 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java @@ -1,18 +1,17 @@ package mineplex.mapparser; +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.ZipUtil; +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldCreator; + import java.io.File; import java.io.IOException; import java.nio.file.Paths; import java.util.ArrayList; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldCreator; - -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.ZipUtil; -import org.apache.commons.io.FileUtils; - public class WorldManager { private MapParser Host; @@ -99,7 +98,7 @@ public class WorldManager FileUtils.deleteQuietly(new File(world.getName() + File.separator + file.getName())); } - MapData data = Host.GetData(world.getName().replace("parse", "map")); + MapData data = Host.getData(world.getName().replace("parse", "map")); GameType gameType = data.MapGameType; String fileName = gameType + "_" + data.MapName + ".zip"; diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java new file mode 100644 index 000000000..652785f33 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java @@ -0,0 +1,58 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.mapparser.MapParser; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.entity.Player; + +/** + * + */ +public class AddSplashTextCommand extends BaseCommand +{ + + public AddSplashTextCommand(MapParser plugin) + { + super(plugin, "addtext"); + setUsage("/addText "); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + if(!player.isOp()) + { + player.sendMessage(C.cRed + "You cannot do this command!"); + return true; + } + + if(args.length == 0) + { + return false; + } + + if(args[0].equalsIgnoreCase("clear")) + { + getPlugin().getAdditionalText().clear(); + player.sendMessage(C.cRed + "Cleared all text."); + return true; + } + + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < args.length; i++) + { + builder.append(args[i]); + if ((i + 1) != args.length) + { + builder.append(" "); + } + } + + getPlugin().addAdditionalText(builder.toString()); + player.sendMessage(C.cGreen + "Added text!"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', builder.toString())); + + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java index 40af0b55b..ad52b7f98 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java @@ -36,7 +36,7 @@ public class AdminCommand extends BaseCommand } //Permission - if (!getPlugin().GetData(world.getName()).HasAccess(player)) + if (!getPlugin().getData(world.getName()).HasAccess(player)) { message(player, "You are not on Admin-List for this Map."); return true; @@ -46,21 +46,21 @@ public class AdminCommand extends BaseCommand if (player != null) { - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.AdminList.contains(other.getName())) { data.AdminList.remove(other.getName()); data.Write(); - getPlugin().Announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(false) + ")"); + getPlugin().announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(false) + ")"); } else { data.AdminList.add(other.getName()); data.Write(); - getPlugin().Announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(true) + ")"); + getPlugin().announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(true) + ")"); } } return true; diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java index 3dabd87c9..c267e7d4d 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java @@ -4,7 +4,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -41,18 +40,18 @@ public class AuthorCommand extends BaseCommand } //Permission - if (!getPlugin().GetData(world.getName()).HasAccess(player)) + if (!getPlugin().getData(world.getName()).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; } - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); data.MapCreator = authorName; data.Write(); - getPlugin().Announce("Map Author for " + F.elem(world.getName()) + " set to " + F.elem(authorName) + "."); + getPlugin().announce("Map Author for " + F.elem(world.getName()) + " set to " + F.elem(authorName) + "."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java index 3448f8545..4354a90a1 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java @@ -50,19 +50,19 @@ public class CopyCommand extends BaseCommand String worldName = getPlugin().getWorldString(originalMapName, originalGametype); String newWorldName = getPlugin().getWorldString(newMapName, newGameType); - if (!getPlugin().DoesMapExist(worldName)) + if (!getPlugin().doesMapExist(worldName)) { message(player, "Could not find a map with the name " + F.elem(originalMapName) + " of type " + F.elem(originalGametype.toString())); return true; } - if (getPlugin().DoesMapExist(newWorldName)) + if (getPlugin().doesMapExist(newWorldName)) { message(player, "Destination map already exists " + F.elem(newMapName) + " of type " + F.elem(newGameType.toString())); return true; } - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); if (world != null) { diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java index 2f44c7558..28ff49418 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java @@ -1,18 +1,16 @@ package mineplex.mapparser.command; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.mapparser.GameType; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; import org.bukkit.entity.Player; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.mapparser.GameType; -import mineplex.mapparser.MapData; -import mineplex.mapparser.MapParser; - /** * Created by Shaun on 8/16/2014. */ @@ -28,7 +26,7 @@ public class CreateCommand extends BaseCommand { if (args.length < 1) { - message(player, "Invalid Input. " + F.elem("/create ")); + message(player, "Invalid Input. " + F.elem("/create [-v]")); return true; } @@ -36,21 +34,38 @@ public class CreateCommand extends BaseCommand String worldName = "map/" + gameType.GetName() + "/" + args[0]; - if (getPlugin().DoesMapExist(worldName)) + if (getPlugin().doesMapExist(worldName)) { message(player, "Map name is already in use!"); return true; } - getPlugin().Announce("Creating World: " + F.elem(worldName)); + boolean voidWorld = false; + + if (args.length == 2) + { + voidWorld = args[1].equalsIgnoreCase("-v"); + } + WorldCreator worldCreator = new WorldCreator(worldName); worldCreator.environment(World.Environment.NORMAL); worldCreator.type(WorldType.FLAT); + if (voidWorld) + { + //Cheeky little trick, saves time and energy. + worldCreator.generatorSettings("3;minecraft:air;2"); + getPlugin().announce("Creating World: " + F.elem(worldName) + " -" + C.cRed + "VOID"); + } + else + { + getPlugin().announce("Creating World: " + F.elem(worldName)); + } + worldCreator.generateStructures(false); World world = Bukkit.getServer().createWorld(worldCreator); - + world.setSpawnLocation(0, 100, 0); message(player, "Teleporting to World: " + F.elem(worldName)); @@ -58,7 +73,7 @@ public class CreateCommand extends BaseCommand player.teleport(world.getSpawnLocation()); //Give Access - MapData mapData = getPlugin().GetData(worldName); + MapData mapData = getPlugin().getData(worldName); mapData.AdminList.add(player.getName()); mapData.MapGameType = gameType; mapData.Write(); diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java new file mode 100644 index 000000000..7244346b9 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java @@ -0,0 +1,38 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import org.bukkit.entity.Player; + +/** + * + */ +public class CurrentlyLiveCommand extends BaseCommand +{ + + public CurrentlyLiveCommand(MapParser plugin, String... aliases) + { + super(plugin, "islive", "setlive"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + MapData data = getPlugin().getData(player.getWorld().getName()); + + if(data == null) + { + player.sendMessage(C.cRed + "There was an error with your map."); + return true; + } + + if(alias.equalsIgnoreCase("setlive")) + { + data._currentlyLive = true; + } + + player.sendMessage(C.cGray + "Currently Live: " + (data._currentlyLive ? C.cGreen + "True" : C.cRed + "False")); + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java index 4128c38e8..59b357c42 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java @@ -44,21 +44,21 @@ public class DeleteCommand extends BaseCommand final String worldName = getPlugin().getWorldString(mapName, gameType); - if (!getPlugin().DoesMapExist(worldName)) + if (!getPlugin().doesMapExist(worldName)) { message(player, "Map does not exist: " + F.elem(worldName)); return true; } - if (!getPlugin().GetData(worldName).HasAccess(player)) + if (!getPlugin().getData(worldName).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; } - if (getPlugin().GetMapWorld(worldName) != null) + if (getPlugin().getMapWorld(worldName) != null) { - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); //Teleport Out for (Player other : world.getPlayers()) @@ -73,9 +73,9 @@ public class DeleteCommand extends BaseCommand boolean deleted = FileUtils.deleteQuietly(new File(worldName)); if (deleted) - getPlugin().Announce("Deleted World: " + F.elem(worldName)); + getPlugin().announce("Deleted World: " + F.elem(worldName)); else - getPlugin().Announce("Failed to delete World: " + F.elem(worldName)); + getPlugin().announce("Failed to delete World: " + F.elem(worldName)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java index 098eed8c3..edf2482a9 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java @@ -2,13 +2,11 @@ package mineplex.mapparser.command; import java.io.File; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.GameType; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -41,7 +39,7 @@ public class GameTypeCommand extends BaseCommand } //Permission - if (!getPlugin().GetData(world.getName()).HasAccess(player)) + if (!getPlugin().getData(world.getName()).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; @@ -59,7 +57,7 @@ public class GameTypeCommand extends BaseCommand return true; } - if (getPlugin().DoesMapExist(getPlugin().getShortWorldName(world.getName()), type)) + if (getPlugin().doesMapExist(getPlugin().getShortWorldName(world.getName()), type)) { message(player, "A world with the same name already exists for the new gametype: " + type.GetName()); return true; @@ -85,11 +83,11 @@ public class GameTypeCommand extends BaseCommand message(player, "Map " + world.getName() + " renamed to " + newName); - MapData data = getPlugin().GetData(newName); + MapData data = getPlugin().getData(newName); data.MapGameType = type; data.Write(); - getPlugin().Announce("GameType for " + F.elem(newName) + " set to " + F.elem(args[0]) + "."); + getPlugin().announce("GameType for " + F.elem(newName) + " set to " + F.elem(args[0]) + "."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java new file mode 100644 index 000000000..f5fa36ac1 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java @@ -0,0 +1,81 @@ +package mineplex.mapparser.command; + +import com.google.common.collect.Lists; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.mapparser.GameType; +import mineplex.mapparser.GameTypeInfo; +import mineplex.mapparser.MapParser; +import org.bukkit.entity.Player; + +/** + * + */ +public class InfoCommand extends BaseCommand +{ + + public InfoCommand(MapParser plugin) + { + super(plugin, "info"); + setUsage("/info & /info addInfo "); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + if (args.length == 1) + { + String gameRaw = args[0]; + GameType gameType; + try + { + gameType = GameType.match(gameRaw); + } catch (Exception e) + { + player.sendMessage(C.cRed + "Invalid Game Type: " + gameRaw); + return true; + } + GameTypeInfo info = getPlugin().getInfo(gameType); + if (info == null) + { + player.sendMessage(C.cRed + "No info found for " + gameType.GetName()); + return true; + } + info.sendInfo(player); + return true; + } + if (args.length >= 3 && args[0].equalsIgnoreCase("addInfo")) + { + String gameRaw = args[1]; + GameType gameType; + try + { + gameType = GameType.match(gameRaw); + } catch (Exception e) + { + player.sendMessage(C.cRed + "Invalid Game Type: " + gameRaw); + return true; + } + GameTypeInfo info = getPlugin().getInfo(gameType); + StringBuilder builder = new StringBuilder(); + for (int i = 2; i < args.length; i++) + { + builder.append(args[i]); + if ((i + 1) != args.length) + { + builder.append(" "); + } + } + if (info == null) + { + info = new GameTypeInfo(gameType, Lists.newArrayList()); + getPlugin().setInfo(gameType, info); + } + + info.addInfo(builder.toString()); + player.sendMessage(C.cGray + "Added new info to " + F.elem(gameRaw)); + return true; + } + return false; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java new file mode 100644 index 000000000..a8dd0082d --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java @@ -0,0 +1,35 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import org.bukkit.entity.Player; + +/** + * + */ +public class LockCommand extends BaseCommand +{ + + public LockCommand(MapParser plugin) + { + super(plugin, "lock"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + MapData data = getPlugin().getData(player.getWorld().getName()); + + if(data == null) + { + player.sendMessage(C.cRed + "There was an error with your map."); + return true; + } + + data._locked = !data._locked; + player.sendMessage(F.tf(data._locked) + " lock for world " + player.getWorld().getName()); + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java index a229e5e07..6c504b634 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java @@ -1,19 +1,18 @@ package mineplex.mapparser.command; -import java.io.File; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.entity.Player; - import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.GameType; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.entity.Player; + +import java.io.File; +import java.util.List; /** * Created by Shaun on 8/15/2014. @@ -45,8 +44,9 @@ public class MapCommand extends BaseCommand if (possibleMaps.size() == 0) { message(player, "No maps found with the name: " + F.elem(args[0])); + return true; } - else if (possibleMaps.size() > 1) + if (possibleMaps.size() > 1) { message(player, "Found more than one possible match:"); for (String s : possibleMaps) @@ -91,10 +91,10 @@ public class MapCommand extends BaseCommand System.out.println("Could not delete uid.dat for " + worldName); } - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); if (world == null) { - if (getPlugin().DoesMapExist(worldName)) + if (getPlugin().doesMapExist(worldName)) { world = Bukkit.createWorld(new WorldCreator(worldName)); } @@ -113,7 +113,7 @@ public class MapCommand extends BaseCommand } //Permission - if (!getPlugin().GetData(world.getName()).CanJoin(player)) + if (!getPlugin().getData(world.getName()).CanJoin(player)) { message(player, "You do not have Join-Access on this Map."); return true; @@ -124,7 +124,7 @@ public class MapCommand extends BaseCommand player.teleport(new Location(world, 0, 106, 0)); - MapData data = getPlugin().GetData(worldName); + MapData data = getPlugin().getData(worldName); UtilPlayer.message(player, F.value("Map Name", data.MapName)); UtilPlayer.message(player, F.value("Author", data.MapCreator)); diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java index 580c088da..a7988c3ff 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java @@ -4,7 +4,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -43,18 +42,18 @@ public class NameCommand extends BaseCommand mapName = mapName.trim(); //Permission - if (!getPlugin().GetData(world.getName()).HasAccess(player)) + if (!getPlugin().getData(world.getName()).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; } - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); data.MapName = mapName; data.Write(); - getPlugin().Announce("Map Name for " + F.elem(world.getName()) + " set to " + F.elem(mapName) + "."); + getPlugin().announce("Map Name for " + F.elem(world.getName()) + " set to " + F.elem(mapName) + "."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java index 91b88a840..9cd58144b 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java @@ -32,7 +32,7 @@ public class ParseCommand200 extends BaseCommand World world = parseLoc.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) { @@ -57,7 +57,7 @@ public class ParseCommand200 extends BaseCommand } //Parse the World - getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 200)); + getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 200)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java index 02f0a0493..d08d60103 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java @@ -32,7 +32,7 @@ public class ParseCommand400 extends BaseCommand World world = parseLoc.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) { @@ -57,7 +57,7 @@ public class ParseCommand400 extends BaseCommand } //Parse the World - getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 400)); + getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 400)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java index 9271553ef..daa28b4fa 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java @@ -32,7 +32,7 @@ public class ParseCommand600 extends BaseCommand World world = parseLoc.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) { @@ -57,7 +57,7 @@ public class ParseCommand600 extends BaseCommand } //Parse the World - getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 600)); + getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 600)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java new file mode 100644 index 000000000..d0a7a485d --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java @@ -0,0 +1,37 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.mapparser.MapParser; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +/** + * + */ +public class PlayerHeadCommand extends BaseCommand +{ + + public PlayerHeadCommand(MapParser plugin, String... aliases) + { + super(plugin, "playerhead"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + if(args.length == 1) { + String name = args[0]; + ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + meta.setOwner(name); + itemStack.setItemMeta(meta); + player.getInventory().addItem(itemStack); + player.sendMessage(C.cGray + "Given " + F.elem(name) + "'s head"); + return true; + } + return false; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java new file mode 100644 index 000000000..8cfbf1c6e --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java @@ -0,0 +1,31 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.F; +import mineplex.mapparser.MapParser; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +/** + * + */ +public class RefreshWorldEditCommand extends BaseCommand +{ + + public RefreshWorldEditCommand(MapParser plugin) + { + super(plugin, "refreshworldedit", "refreshwe", "wefresh"); + setUsage("/refreshwe"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + Bukkit.broadcastMessage(F.name(player.getName()) + " is reloading World Edit"); + Plugin plugin = getPlugin().getServer().getPluginManager().getPlugin("WorldEdit"); + plugin.onDisable(); + plugin.onEnable(); + Bukkit.broadcastMessage(F.name(player.getName()) + " has reloaded World Edit"); + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java index ae95e8ec4..b2e539bb4 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java @@ -2,7 +2,6 @@ package mineplex.mapparser.command; import java.io.File; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -25,7 +24,7 @@ public class RenameCommand extends BaseCommand public boolean execute(Player player, String alias, String[] args) { World world = player.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data == null) { diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java index 4f2658660..c201f152c 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java @@ -48,11 +48,11 @@ public class SaveCommand extends BaseCommand } String worldName = possibleMaps.get(0); - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); if (world != null) { - if (!getPlugin().GetData(worldName).HasAccess(player)) + if (!getPlugin().getData(worldName).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; @@ -71,7 +71,7 @@ public class SaveCommand extends BaseCommand return true; } - getPlugin().Announce("Saved World: " + F.elem(args[0])); + getPlugin().announce("Saved World: " + F.elem(args[0])); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java new file mode 100644 index 000000000..dd533e4d8 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java @@ -0,0 +1,82 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilWorld; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.Map; + +/** + * + */ +public class WarpCommand extends BaseCommand +{ + + public WarpCommand(MapParser plugin) + { + super(plugin, "warp"); + setUsage("/warp & /warp "); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + MapData data = getPlugin().getData(player.getWorld().getName()); + + if(data == null) + { + player.sendMessage(C.cRed + "There was an error with your map."); + return true; + } + + Map warps = data._warps; + + if(args.length == 1) + { + if(args[0].equalsIgnoreCase("list")) + { + for(String s : warps.keySet()) + { + player.sendMessage(F.elem(s) + " @ " + F.elem(UtilWorld.locToStrClean(warps.get(s)))); + } + return true; + } + + Location location = warps.get(args[0].toLowerCase()); + + if(location == null){ + player.sendMessage(C.cRed + "Unknown warp!"); + return true; + } + + player.sendMessage(C.cGray + "Warping to " + F.elem(args[0])); + player.teleport(location); + return true; + } + + if(args.length == 2) + { + if(!args[0].equalsIgnoreCase("set")) + { + player.sendMessage(C.cRed + "Please use " + F.elem("/warp set ") + C.cRed + " to set a warp"); + return true; + } + String warp = args[1].toLowerCase(); + if(warps.containsKey(warp)) + { + player.sendMessage(C.cRed + "That warp already exists!"); + return true; + } + warps.put(warp, player.getLocation()); + player.sendMessage(C.cGray + "Created a new warp: " + F.elem(warp)); + return true; + } + + return false; + } + +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java new file mode 100644 index 000000000..0862b4b3c --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java @@ -0,0 +1,50 @@ +package mineplex.mapparser.module; + +import mineplex.core.common.util.C; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +/** + * + */ +public abstract class Module implements Listener +{ + + private MapParser _plugin; + private String _name; + + public Module(String name, MapParser plugin) { + _name = name; + _plugin = plugin; + register(); + plugin.getModules().put(this.getClass(), this); + } + + public void register() + { + _plugin.getServer().getPluginManager().registerEvents(this, _plugin); + } + + public MapParser getPlugin() + { + return _plugin; + } + + public MapData GetData(String world) + { + return getPlugin().getData(world); + } + + public void displayHelp(Player player) + { + MapData data = GetData(player.getWorld().getName()); + player.sendMessage(C.cGray + "Currently Live: " + (data._currentlyLive ? C.cGreen + "True" : C.cRed + "False")); + for(String s : getPlugin().getAdditionalText()) + { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', s)); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java new file mode 100644 index 000000000..368b24df9 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java @@ -0,0 +1,99 @@ +package mineplex.mapparser.module.modules; + +import com.google.common.collect.Maps; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.command.BaseCommand; +import mineplex.mapparser.module.Module; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.util.Map; + +/** + * + */ +public class CommandModule extends Module +{ + private Map _commands = Maps.newHashMap(); + private Map _commandsByAlias = Maps.newHashMap(); + + public CommandModule(MapParser plugin) + { + super("Commands", plugin); + } + + @EventHandler + public void onCommand(PlayerCommandPreprocessEvent event) + { + Player player = event.getPlayer(); + + String[] parts = event.getMessage().split(" "); + String commandLabel = parts[0].substring(1); + String[] args = new String[parts.length - 1]; + System.arraycopy(parts, 1, args, 0, parts.length - 1); + + if (getPlugin().getCurParse() != null) + { + UtilPlayer.message(player, F.main("Parser", "Cannot use commands during Map Parse!")); + return; + } + if (event.getMessage().toLowerCase().startsWith("/help")) + { + event.setCancelled(true); + + displayHelp(player); + return; + } + + if (commandLabel.equalsIgnoreCase("gmc")) + { + player.setGameMode(GameMode.CREATIVE); + event.setCancelled(true); + return; + } + if (commandLabel.equalsIgnoreCase("gms")) + { + player.setGameMode(GameMode.SURVIVAL); + event.setCancelled(true); + return; + } + if (commandLabel.equalsIgnoreCase("gmsp")) + { + player.setGameMode(GameMode.SPECTATOR); + event.setCancelled(true); + return; + } + + BaseCommand baseCommand = _commands.get(commandLabel.toLowerCase()); + + if (baseCommand == null) + { + baseCommand = _commandsByAlias.get(commandLabel.toLowerCase()); + if (baseCommand == null) + { + return; + } + } + + event.setCancelled(true); + + if (!baseCommand.execute(player, commandLabel, args)) + { + UtilPlayer.message(player, F.main("Parser", "Invalid Input.")); + UtilPlayer.message(player, F.elem(baseCommand.getUsage())); + } + } + + public void add(BaseCommand baseCommand) + { + _commands.put(baseCommand.getAliases().get(0).toLowerCase(), baseCommand); + for (String label : baseCommand.getAliases()) + { + _commandsByAlias.put(label.toLowerCase(), baseCommand); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java new file mode 100644 index 000000000..3b0a05afc --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java @@ -0,0 +1,353 @@ +package mineplex.mapparser.module.modules; + +import com.google.common.collect.Lists; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.mapparser.BackupTask; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.Parse; +import mineplex.mapparser.TickEvent; +import mineplex.mapparser.module.Module; +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.List; + +/** + * + */ +public class EventModule extends Module +{ + + private List _updated = Lists.newArrayList(); + + public EventModule(MapParser plugin) + { + super("Events", plugin); + } + + @EventHandler + public void PlayerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + + player.teleport(getPlugin().getSpawnLocation()); + + displayHelp(player); + } + + @EventHandler + public void onTick(TickEvent event) + { + for (World world : getPlugin().getServer().getWorlds()) + { + if (_updated.contains(world)) + { + continue; + } + if (world.getName().toLowerCase().contains("halloween")) + { + world.setTime(16000); + } else + { + world.setTime(8000); + } + _updated.add(world); + world.setGameRuleValue("doDaylightCycle", "false"); + } + } + + @EventHandler + public void onParseUpdate(TickEvent event) + { + if (getPlugin().getCurParse() == null) + { + return; + } + + Parse parse = getPlugin().getCurParse(); + + if (parse.Update()) + { + getPlugin().announce("Parse Completed!"); + + getPlugin().announce("Cleaning and Creating ZIP..."); + + try + { + getPlugin().getWorldManager().finalizeParsedWorld(parse.getWorld()); + } catch (Exception e) + { + getPlugin().announce("Creating ZIP Failed! Please Try Again!"); + e.printStackTrace(); + } + + getPlugin().setCurrentParse(null); + } + } + + @EventHandler + public void SaveUnloadWorlds(TickEvent event) + { + for (World world : getPlugin().getServer().getWorlds()) + { + if (world.getName().equalsIgnoreCase("world")) + { + continue; + } + + if (world.getName().startsWith("parse_")) + { + continue; + } + + if (!world.getName().startsWith("map")) + { + continue; + } + + if (world.getPlayers().isEmpty()) + { + getPlugin().announce("Saving & Closing World: " + F.elem(world.getName())); + MapUtil.UnloadWorld(getPlugin(), world, true); + _updated.remove(world); + getPlugin()._mapsBeingZipped.add(world.getName()); + System.out.println("Starting backup of " + world); + new BackupTask(getPlugin(), world.getName(), data -> + { + System.out.println("Finished backup of " + world); + getPlugin()._mapsBeingZipped.remove(world.getName()); + }); + } + } + } + + @EventHandler + public void Chat(AsyncPlayerChatEvent event) + { + event.setCancelled(true); + + String world = C.cDGreen + C.Bold + getPlugin().getShortWorldName(event.getPlayer().getWorld().getName()); + + String name = C.cYellow + event.getPlayer().getName(); + if (getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + name = C.cGreen + event.getPlayer().getName(); + } + + String grayName = C.cBlue + event.getPlayer().getName(); + String grayWorld = C.cBlue + C.Bold + event.getPlayer().getWorld().getName(); + + for (Player player : UtilServer.getPlayers()) + { + if (player.getWorld().equals(event.getPlayer().getWorld())) + { + player.sendMessage(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage()); + } else + { + player.sendMessage(grayWorld + ChatColor.RESET + " " + grayName + ChatColor.RESET + " " + C.cGray + event.getMessage()); + } + + } + + System.out.println(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void InteractCancel(PlayerInteractEvent event) + { + if (event.getPlayer().isOp()) + { + return; + } + //Permission + if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void TeleportCommand(PlayerCommandPreprocessEvent event) + { + if (!event.getMessage().toLowerCase().startsWith("/tp")) + { + return; + } + + Player player = event.getPlayer(); + + String[] tokens = event.getMessage().split(" "); + + if (tokens.length != 2) + { + return; + } + + event.setCancelled(true); + + Player target = UtilPlayer.searchOnline(player, tokens[1], true); + if (target != null) + { + MapData data = getPlugin().getData(target.getWorld().getName()); + if(!data.CanJoin(player)) + { + player.sendMessage(C.cRed + "That server is currently locked, and you don't have access to it."); + return; + } + UtilPlayer.message(player, F.main("Game", "You teleported to " + F.name(target.getName()) + ".")); + player.teleport(target); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void commandCancel(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().startsWith("/tp") || + event.getMessage().startsWith("/hub") || + event.getMessage().startsWith("/list") || + event.getMessage().startsWith("/map") || + event.getMessage().startsWith("/create") || + event.getMessage().startsWith("/copy") || + event.getMessage().startsWith("/delete")) + { + return; + } + + //Permission + if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "You do not have Build-Access for this Map.")); + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void FlySpeed(PlayerCommandPreprocessEvent event) + { + if (!event.getMessage().toLowerCase().startsWith("/speed")) + { + return; + } + + Player player = event.getPlayer(); + + String[] tokens = event.getMessage().split(" "); + + if (tokens.length != 2) + { + return; + } + + event.setCancelled(true); + + try + { + float speed = Float.parseFloat(tokens[1]); + + player.setFlySpeed(speed); + + UtilPlayer.message(player, F.main("Game", "Fly Speed set to " + F.elem("" + speed) + ".")); + } catch (Exception e) + { + UtilPlayer.message(player, F.main("Game", "Invalid Speed Input.")); + } + } + + //################################################################################################# + //# # + //# Simple methods # + //# # + //# # + //################################################################################################# + + @EventHandler + public void Join(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + if (player.getName().equalsIgnoreCase("TadahTech")) + { + event.setJoinMessage(C.cGreenB + "Your build server Saviour, TIMOTHY! has arrived, please take a moment to thank him."); + getPlugin().getServer().getOnlinePlayers().forEach(o -> o.playSound(o.getLocation(), Sound.AMBIENCE_THUNDER, 1.0F, 1.0F)); + return; + } + event.setJoinMessage(F.sys("Player Join", event.getPlayer().getName())); + } + + @EventHandler + public void Join(PlayerQuitEvent event) + { + event.setQuitMessage(F.sys("Player Quit", event.getPlayer().getName())); + } + + @EventHandler + public void onDroppedItemSpawn(EntitySpawnEvent event) + { + if (event.getEntityType() != EntityType.ARMOR_STAND) + { + event.setCancelled(true); + } + } + + + @EventHandler + public void DisableBurn(BlockBurnEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void DisableIgnite(BlockIgniteEvent event) + { + if (event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD) + { + event.setCancelled(true); + } + } + + @EventHandler + public void DisableFire(BlockSpreadEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void DisableFade(BlockFadeEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void DisableDecay(LeavesDecayEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void DisableIceForm(BlockFormEvent event) + { + event.setCancelled(true); + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java new file mode 100644 index 000000000..0160c923b --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java @@ -0,0 +1,127 @@ +package mineplex.mapparser.module.modules; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilGear; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.module.Module; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; + +/** + * + */ +public class MMMazeModule extends Module +{ + + public MMMazeModule(MapParser plugin) + { + super("MM-Maze", plugin); + } + + + @EventHandler + public void mmMazeParser(PlayerInteractEvent event) + { + if (event.isCancelled()) + return; + + if (event.getAction() != Action.LEFT_CLICK_BLOCK) return; + + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + return; + } + + Player player = event.getPlayer(); + + if (!UtilGear.isMat(player.getItemInHand(), Material.WEB)) + return; + + event.setCancelled(true); + + // parse + + Block clicked = event.getClickedBlock(); + Location center = clicked.getLocation(); + Location lowestCorner = center.clone().subtract(49, 0, 49); + + // 0 = air or other + // 1 = path - quartz + // 2 = mob spawn - gold + // 3 = safe spawn - stone + + int[][] maze = new int[99][99]; + + for (int i = 0; i < 99; i++) + for (int j = 0; j < 99; j++) + maze[i][j] = getMMParseValue(lowestCorner.clone().add(j, 0, i).getBlock().getType()); + + //Save + try + { + FileWriter fstream = new FileWriter(GetData(player.getWorld().getName()).MapFolder + File.separator + "Maze.dat"); + BufferedWriter out = new BufferedWriter(fstream); + + out.write("private static final int[][] PARSED_MAZE = {" + System.lineSeparator()); + for (int j[] : maze) + { + out.write("{"); + boolean first = true; + for (int k : j) + { + if(!first) out.write(","); + out.write(k + ""); + + first = false; + } + out.write("}," + System.lineSeparator()); + } + out.write("};" + System.lineSeparator()); + + out.close(); + } + catch (Exception e) + { + player.sendMessage(C.cRed + C.Bold + "MMMazeParse: " + ChatColor.RESET + "An error has occured, see console."); + e.printStackTrace(); + } + player.sendMessage(C.cGreen + C.Bold + "MMMazeParse: " + ChatColor.RESET + "Maze parsed."); + } + + private int getMMParseValue(Material m) + { + switch (m) { + case QUARTZ_BLOCK: + return 1; + + case GOLD_BLOCK: + return 2; + + case STONE: + return 3; + + case DIRT: + return 4; + + case COBBLESTONE: + return 5; + + case BRICK: + return 6; + + default: + return 0; + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java new file mode 100644 index 000000000..47e4d5aed --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java @@ -0,0 +1,112 @@ +package mineplex.mapparser.module.modules; + +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilWorld; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.module.Module; +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; + +/** + * + */ +public class SignModule extends Module +{ + public SignModule(MapParser plugin) + { + super("Sign", plugin); + } + + + @EventHandler(priority = EventPriority.LOWEST) + public void signChangeLog(SignChangeEvent event) + { + if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + ArrayList text = new ArrayList<>(); + + text.add("Date: " + UtilTime.now()); + text.add("Player: " + event.getPlayer().getName()); + text.add("Location: " + UtilWorld.locToStrClean(event.getBlock().getLocation())); + for (int i = 0; i < event.getLines().length; i++) + { + text.add("Line " + i + ": " + event.getLines()[i]); + } + writeSignLog(text, event.getPlayer().getWorld()); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void signCommand(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().toLowerCase().contains("set")) + { + ArrayList text = new ArrayList<>(); + + text.add("Date: " + UtilTime.now()); + text.add("Player: " + event.getPlayer().getName()); + text.add("Location: " + UtilWorld.locToStrClean(event.getPlayer().getLocation())); + text.add("Message: " + event.getMessage()); + + writeSignCommandLog(text, event.getPlayer().getWorld()); + } + } + + public void writeSignCommandLog(ArrayList text, World world) + { + try + { + File file = new File(world.getName() + "/" + "command_sign_log.txt"); + + if (!file.exists()) + { + file.createNewFile(); + } + + FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); + BufferedWriter bw = new BufferedWriter(fw); + + bw.write("\n\n"); + for (String line : text) + bw.write("\n" + line); + + bw.close(); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + public void writeSignLog(ArrayList text, World world) + { + try + { + File file = new File(world.getName() + "/" + "sign_log.txt"); + + if (!file.exists()) + { + file.createNewFile(); + } + + FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); + BufferedWriter bw = new BufferedWriter(fw); + + bw.write("\n\n"); + for (String line : text) + bw.write("\n" + line); + + bw.close(); + } catch (Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java new file mode 100644 index 000000000..8e6df1c01 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java @@ -0,0 +1,119 @@ +package mineplex.mapparser.module.modules; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilGear; +import mineplex.mapparser.BlockData; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.module.Module; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +/** + * + */ +public class TreeToolModule extends Module +{ + + private Map>> _treeHistory = Maps.newHashMap(); + + public TreeToolModule(MapParser plugin) + { + super("TreeTool", plugin); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void treeRemover(PlayerInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + + //Permission + if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + return; + } + + Player player = event.getPlayer(); + + if (!UtilGear.isMat(player.getItemInHand(), Material.NETHER_STAR)) + { + return; + } + + event.setCancelled(true); + + //Remove + if (event.getAction() == Action.LEFT_CLICK_BLOCK) + { + if (event.getClickedBlock().getType() != Material.LOG) + { + player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); + return; + } + + Set toRemove = getPlugin().searchLog(Sets.newHashSet(), event.getClickedBlock()); + + if (toRemove.isEmpty()) + { + player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); + return; + } + + Set history = Sets.newHashSet(); + + for (Block block : toRemove) + { + history.add(new BlockData(block)); + + block.setType(Material.AIR); + } + + if (!_treeHistory.containsKey(player.getUniqueId())) + { + _treeHistory.put(player.getUniqueId(), Lists.newArrayList()); + } + + _treeHistory.get(player.getUniqueId()).add(0, history); + + player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Removed"); + + while (_treeHistory.get(player.getUniqueId()).size() > 10) + { + _treeHistory.get(player.getUniqueId()).remove(10); + } + + } else if (UtilEvent.isAction(event, ActionType.R)) + { + if (!_treeHistory.containsKey(player.getUniqueId()) || _treeHistory.get(player.getUniqueId()).isEmpty()) + { + player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "No Tree History"); + return; + } + + Set datas = _treeHistory.get(player.getUniqueId()).remove(0); + + datas.forEach(BlockData::restore); + + player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored"); + } + } + +} From b4aa303923fbd59641414251f6007b81aaad30c2 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Mon, 18 Jul 2016 19:04:02 -0500 Subject: [PATCH 37/53] Bug fixes. --- .../src/mineplex/core/party/command/PartyCommand.java | 8 ++++++++ .../mineplex/core/party/manager/PartyRedisManager.java | 2 +- .../core/party/ui/button/tools/LeavePartyButton.java | 5 +++-- .../src/mineplex/core/party/ui/menus/PartyOwnerMenu.java | 2 +- .../src/mineplex/core/party/ui/menus/PartyViewMenu.java | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) 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 4d8d3b8ec..8eee86d83 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -21,6 +21,8 @@ public class PartyCommand extends CommandBase private final String[] HELP = { F.main("Party", "Party Commands (Click the command!)"), help("", "Brings up the Party GUI"), + help("", "Send an invitation to a player."), + help("leave", "Send an invitation to a player."), C.cBlue + "Party> " + C.cWhite + "# " + C.cGray + "- Send a message to your party.", C.cGreenB + "All party functions have been moved to the GUI!", C.cGreenB + "Click the NameTag in your hotbar to get started!" @@ -73,6 +75,12 @@ public class PartyCommand extends CommandBase Plugin.getMethodManager().invite(caller, arg); return; } + if(arg.equalsIgnoreCase("leave")) { + Plugin.getMethodManager().leaveParty(caller); + return; + } + Plugin.getMethodManager().invite(caller, arg); + return; } caller.sendMessage(HELP); } 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 12f06980d..eb741c152 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -200,7 +200,7 @@ public class PartyRedisManager { publish(server, PARTY_INFO, GSON.toJson(party)); List members = party.getMembers(); - party.getMembersByUUID().stream().forEach(uuid -> _plugin.getMethodManager().removeForTransfer(uuid)); + party.getMembersByUUID().forEach(uuid -> _plugin.getMethodManager().removeForTransfer(uuid)); members.stream().map(Bukkit::getPlayer).forEach(player1 -> { player1.leaveVehicle(); 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 05191241a..1b409a082 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 @@ -2,6 +2,7 @@ package mineplex.core.party.ui.button.tools; import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; import mineplex.core.party.ui.Button; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -19,9 +20,9 @@ public class LeavePartyButton extends Button .setLore(" ", C.cRed + "Shift-Left-Click" + C.cGray + " to leave your party.") .build(); - public LeavePartyButton() + public LeavePartyButton(PartyManager plugin) { - super(ITEM, null); + super(ITEM, plugin); } @Override 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 398cb57e7..2bdf85157 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 @@ -54,7 +54,7 @@ public class PartyOwnerMenu extends Menu //Go to server _buttons[SELECT_SERVER_BUTTON_SLOT] = new SelectServerButton(_party); //Leave party - _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(); + _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(_plugin); //Disband _buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(_plugin); 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 c3c182b6d..80df07b28 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 @@ -33,7 +33,7 @@ public class PartyViewMenu extends Menu protected Button[] setUp(Player player) { //Tools - _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(); + _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(_plugin); //Suggest Player _buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, _plugin); From ce4289fa0036c4b0f38e07857d6850b24a198921 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Mon, 18 Jul 2016 22:13:32 -0500 Subject: [PATCH 38/53] Don't do weather. --- .../src/mineplex/mapparser/module/modules/EventModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java index 3b0a05afc..3f62f9337 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java @@ -75,6 +75,7 @@ public class EventModule extends Module world.setTime(8000); } _updated.add(world); + world.setStorm(false); world.setGameRuleValue("doDaylightCycle", "false"); } } From c32e647d9ef67612da88dca803c60904feead47f Mon Sep 17 00:00:00 2001 From: TadahTech Date: Mon, 18 Jul 2016 22:21:09 -0500 Subject: [PATCH 39/53] Add private messaging system --- .../src/mineplex/mapparser/MapParser.java | 3 ++ .../mineplex/mapparser/command/PMCommand.java | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PMCommand.java diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index 0d4a5c937..9105e8ea6 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -26,6 +26,7 @@ import mineplex.mapparser.command.ListCommand; import mineplex.mapparser.command.LockCommand; import mineplex.mapparser.command.MapCommand; import mineplex.mapparser.command.NameCommand; +import mineplex.mapparser.command.PMCommand; import mineplex.mapparser.command.ParseCommand200; import mineplex.mapparser.command.ParseCommand400; import mineplex.mapparser.command.ParseCommand600; @@ -119,6 +120,8 @@ public class MapParser extends JavaPlugin commandModule.add(new WarpCommand(this)); commandModule.add(new CurrentlyLiveCommand(this)); commandModule.add(new AddSplashTextCommand(this)); + commandModule.add(new PMCommand(this)); + loadInfo(); addSplashText(); } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PMCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PMCommand.java new file mode 100644 index 000000000..82a72b071 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PMCommand.java @@ -0,0 +1,52 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.mapparser.MapParser; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +/** + * + */ +public class PMCommand extends BaseCommand +{ + public PMCommand(MapParser plugin) + { + super(plugin, "m", "message"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + if(!player.isOp()) + { + player.sendMessage(C.cRed + "You are not allowed to do that!"); + return true; + } + + if(args.length == 0) + { + player.sendMessage(C.cRed + "Please put a message in!"); + return true; + } + + StringBuilder builder = new StringBuilder(); + for(String s : args) + { + builder.append(s).append(" "); + } + for(Player ops : UtilServer.getPlayers()) + { + if(!ops.isOp()) + { + continue; + } + ops.sendMessage(F.main("Message", builder.toString().trim())); + ops.playSound(ops.getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f); + } + + return true; + } +} From 136eb078efca5e613b6a8e2c694c1b9d57f1e8c7 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Fri, 15 Jul 2016 00:01:24 -0500 Subject: [PATCH 40/53] PC-426: Update UX for non-premium players: Removes the in game advertisement display when selecting servers. Removes all chat throttling. Adds a message sent on join to the player, promoting the newest sale or promotion. --- .../src/mineplex/hub/HubManager.java | 3 + .../modules/nonpremium/MessageRepository.java | 84 +++++++++++++++++++ .../hub/modules/nonpremium/NPUMCommand.java | 47 +++++++++++ .../modules/nonpremium/NonPremiumManager.java | 84 +++++++++++++++++++ .../nonpremium/UpdateMessageCommand.java | 28 +++++++ .../nonpremium/UpdateMessageHandler.java | 29 +++++++ .../mineplex/hub/server/ServerManager.java | 2 +- .../mineplex/hub/server/ui/ServerNpcPage.java | 4 + 8 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/MessageRepository.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NPUMCommand.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NonPremiumManager.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageCommand.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageHandler.java diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 37a50cbb3..0277ef72b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -56,6 +56,7 @@ import mineplex.core.valentines.ValentinesGiftManager; import mineplex.core.youtube.YoutubeManager; import mineplex.hub.commands.*; import mineplex.hub.modules.*; +import mineplex.hub.modules.nonpremium.NonPremiumManager; import mineplex.hub.profile.gui.GUIProfile; import mineplex.hub.tutorial.TutorialManager; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; @@ -243,6 +244,8 @@ public class HubManager extends MiniClientPlugin _valentinesManager = new ValentinesManager(plugin, clientManager, donationManager); + new NonPremiumManager(plugin, clientManager); + try { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/MessageRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/MessageRepository.java new file mode 100644 index 000000000..d42fcef34 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/MessageRepository.java @@ -0,0 +1,84 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.core.progression.util.SQLStatement; +import mineplex.serverdata.database.DBPool; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * + */ +public class MessageRepository +{ + + private static final String SCHEMA = "CREATE TABLE IF NOT EXISTS nonPremiumJoinMessage (message VARCHAR(256));"; + + private static final String QUERY = "SELECT `message` FROM `nonPremiumJoinMessage`;"; + private static final String UPDATE = "UPDATE `nonPremiumJoinMessage` SET `message` = ?;"; + private static final String INSERT = "INSERT INTO `nonPremiumJoinMessage` VALUES(?);"; + + private final JavaPlugin _plugin; + private String _message; + + public MessageRepository(JavaPlugin plugin) + { + _plugin = plugin; + } + + /** + * Update the message globally. + * + * @param message The new string literal message + */ + public void updateMessage(String message) + { + _message = message; + async(() -> { + try (Connection connection = DBPool.getAccount().getConnection()) + { + ResultSet resultSet = new SQLStatement(QUERY).prepare(connection).executeQuery(); + + if (!resultSet.next()) + { + new SQLStatement(INSERT).set(1, message).prepare(connection).executeUpdate(); + + } else + { + new SQLStatement(UPDATE).set(1, message).prepare(connection).executeUpdate(); + } + } catch (SQLException e) + { + e.printStackTrace(); + } + }); + } + + private void async(Runnable runnable) + { + Bukkit.getScheduler().runTaskAsynchronously(_plugin, runnable); + } + + public String getMessage() + { + if (_message == null) + { + try (Connection connection = DBPool.getAccount().getConnection()) + { + ResultSet resultSet = new SQLStatement(QUERY).prepare(connection).executeQuery(); + if (resultSet == null || !resultSet.next()) + { + return null; + } + _message = resultSet.getString(1); + } catch (SQLException e) + { + e.printStackTrace(); + } + } + return _message; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NPUMCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NPUMCommand.java new file mode 100644 index 000000000..cb4796759 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NPUMCommand.java @@ -0,0 +1,47 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +/** + * + */ +public class NPUMCommand extends CommandBase +{ + + public NPUMCommand(NonPremiumManager plugin) + { + super(plugin, Rank.ADMIN, "updatemessage"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if(!Plugin.getClientManager().Get(caller).GetRank().has(Rank.ADMIN)) { + caller.sendMessage(C.cRed + "No."); + return; + } + + if(args.length == 0) { + caller.sendMessage(F.main("NPUM", "Invalid Command Arguments. Usage: /updatemessage \"Message here\". Use '&' for color codes. Spaces are allowed.")); + return; + } + + StringBuilder message = new StringBuilder(); + + for(int i = 0; i < args.length; i++) { + message.append(args[i]); + if((i + 1) != args.length) { + message.append(" "); + } + } + + Plugin.setMessage(message.toString(), true); + caller.sendMessage(F.main("NPUM", "Non-Premium User message updated. New message: ")); + caller.sendMessage(ChatColor.translateAlternateColorCodes('&', message.toString())); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NonPremiumManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NonPremiumManager.java new file mode 100644 index 000000000..78967ecde --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NonPremiumManager.java @@ -0,0 +1,84 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.serverdata.commands.ServerCommandManager; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * + */ +public class NonPremiumManager extends MiniPlugin +{ + + private static final String LINE = C.cDGreenB + C.Strike + "============================================="; + + private String _message; + private MessageRepository _messageRepository; + private CoreClientManager _clientManager; + + public NonPremiumManager(JavaPlugin plugin, CoreClientManager clientManager) + { + super("NonPremiumPlayerManager", plugin); + addCommand(new NPUMCommand(this)); + _clientManager = clientManager; + _messageRepository = new MessageRepository(plugin); + _message = _messageRepository.getMessage(); + UpdateMessageHandler handler = new UpdateMessageHandler(this); + ServerCommandManager.getInstance().registerCommandType(UpdateMessageCommand.class, handler); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + Rank rank = _clientManager.Get(player).GetRank(); + + if (_message == null) + { + return; + } + + if (rank != Rank.ALL) + { + return; + } + + getPlugin().getServer().getScheduler().runTaskLater(getPlugin(), () -> { + player.sendMessage(" "); + player.sendMessage(LINE); + player.sendMessage(" "); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', _message)); + player.sendMessage(" "); + player.sendMessage(LINE); + player.sendMessage(" "); + player.sendMessage(" "); + }, 5L); + } + + public void setMessage(String message, boolean updateDB) + { + _message = message; + if (!updateDB) + { + return; + } + _messageRepository.updateMessage(message); + ServerCommandManager.getInstance().publishCommand(new UpdateMessageCommand(message, getServer())); + } + + public CoreClientManager getClientManager() + { + return _clientManager; + } + + public String getServer() { + return getPlugin().getConfig().getString("serverstatus.name"); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageCommand.java new file mode 100644 index 000000000..c0033eaf0 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageCommand.java @@ -0,0 +1,28 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.serverdata.commands.ServerCommand; + +/** + * + */ +public class UpdateMessageCommand extends ServerCommand +{ + + private String _message; + private String _from; + + public UpdateMessageCommand(String message, String from) { + _message = message; + _from = from; + } + + public String getMessage() + { + return _message; + } + + public String getFrom() + { + return _from; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageHandler.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageHandler.java new file mode 100644 index 000000000..19b11bf36 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageHandler.java @@ -0,0 +1,29 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +/** + * + */ +public class UpdateMessageHandler implements CommandCallback +{ + + private final NonPremiumManager _manager; + + public UpdateMessageHandler(NonPremiumManager manager) { + _manager = manager; + } + + @Override + public void run(ServerCommand command) + { + if(!(command instanceof UpdateMessageCommand)) { + return; + } + if(_manager.getServer().equalsIgnoreCase(((UpdateMessageCommand) command).getFrom())) { + return; + } + _manager.setMessage(((UpdateMessageCommand) command).getMessage(), false); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index 3e0ac74e7..4a885c432 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -67,7 +67,7 @@ import mineplex.serverdata.data.ServerGroup; public class ServerManager extends MiniDbClientPlugin implements BrawlShopProvider { - private static final Long FREE_PORTAL_TIMER = 20000L; + private static final Long FREE_PORTAL_TIMER = -1L; private static final Long BETA_PORTAL_TIMER = 120000L; private static final Random random = new Random(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java index 34ce492a1..18df137c9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -92,6 +92,10 @@ public class ServerNpcPage extends ShopPageInventory Date: Wed, 20 Jul 2016 16:18:49 -0500 Subject: [PATCH 41/53] Party PR Updates. --- .../src/mineplex/core/party/InviteData.java | 33 +------ .../src/mineplex/core/party/Lang.java | 43 ++------- .../src/mineplex/core/party/Party.java | 11 ++- .../core/party/command/PartyCommand.java | 2 +- .../party/constants/JoinResponseReason.java | 12 ++- .../party/constants/PartyRemoveReason.java | 29 +----- .../party/manager/PartyInviteManager.java | 7 +- .../core/party/manager/PartyJoinManager.java | 9 +- .../core/party/manager/PartyRedisManager.java | 95 ++++++++++--------- 9 files changed, 85 insertions(+), 156 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java b/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java index 63e49fac5..b401da6d1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java @@ -7,50 +7,19 @@ public class InviteData { private String _invitedTo; - private String _invitedBy; - private long _timeStamp; - private long _expires; private String _serverFrom; - public InviteData(String invitedBy, String invitedTo, long timeStamp, String serverFrom) + public InviteData(String invitedTo, String serverFrom) { - _invitedBy = invitedBy; _invitedTo = invitedTo; - _timeStamp = timeStamp; - _expires = timeStamp + 60000; _serverFrom = serverFrom; } - public long getTimeRemaining() - { - return _expires - System.currentTimeMillis(); - } - - public boolean hasExpired() - { - return System.currentTimeMillis() >= _expires; - } - public String getInvitedTo() { return _invitedTo; } - public String getInvitedBy() - { - return _invitedBy; - } - - public long getTimeStamp() - { - return _timeStamp; - } - - public long getExpires() - { - return _expires; - } - public String getServerFrom() { return _serverFrom; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java index c5b6a745c..1132b0ee2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -1,7 +1,6 @@ package mineplex.core.party; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; import org.bukkit.entity.Player; import java.text.MessageFormat; @@ -58,45 +57,21 @@ public enum Lang public void send(Player player, String... args) { - String color = C.mBody; - - 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); + player.sendMessage(C.mHead + "Party> " + getFormatted(args)); } public void send(Party party, String... args) + { + party.sendMessage(C.mHead + "Party> " + getFormatted(args)); + } + + private String getFormatted(String[] args) { String color = C.mBody; if(args.length == 0) { - party.sendMessage(F.main("Party", _message)); - return; + return _message; } if(_message.startsWith("Error:")) @@ -118,9 +93,7 @@ public enum Lang String coloredRest = message.substring(firstIndex); message = color + message.substring(0, firstIndex) + coloredRest; - - party.sendMessage(C.mHead + "Party> " + message); + return message; } - } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index 094435e10..d649d6c5f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -31,14 +31,14 @@ public class Party 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 @@ -158,7 +158,8 @@ public class Party } _members.add(player); Lang.ADD_MEMBER.send(this, player); - getMembers().stream().forEach(s -> { + getMembers().forEach(s -> + { Player player1 = Bukkit.getPlayer(s); player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F); }); 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 8eee86d83..8944428bf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -22,7 +22,7 @@ public class PartyCommand extends CommandBase F.main("Party", "Party Commands (Click the command!)"), help("", "Brings up the Party GUI"), help("", "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 + "# " + C.cGray + "- Send a message to your party.", C.cGreenB + "All party functions have been moved to the GUI!", C.cGreenB + "Click the NameTag in your hotbar to get started!" diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java index 56cd100e2..6a32c3672 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java @@ -8,14 +8,16 @@ import mineplex.core.common.util.F; public enum JoinResponseReason { - CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")), - SUCCESS(""); + CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!"), "no"), + SUCCESS("", "yes"); private String _message; + private String _code; - JoinResponseReason(String message) + JoinResponseReason(String message, String code) { _message = message; + _code = code; } public String getMessage() @@ -23,4 +25,8 @@ public enum JoinResponseReason return _message; } + public String getCode() + { + return _code; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java index 14b8b4e44..bff47e023 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java @@ -5,30 +5,11 @@ package mineplex.core.party.constants; */ public enum PartyRemoveReason { - KICKED(1, "kicked"), - LEFT(2, "left"), - OTHER(3, "other"), - DISBANDED(4, "disbanded"), - DISBANDED_BY_OWNER(5, "disbandedByOwner"), - ; + KICKED, + LEFT, + OTHER, + DISBANDED, + 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; - } } 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 cb6195a07..580701efc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -209,7 +209,7 @@ public class PartyInviteManager */ 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() { @Override @@ -338,17 +338,16 @@ public class PartyInviteManager * @param invited The invited players UUUD * @param invitedBy The person who invited him * @param party The name of the party invited to - * @param currentTime The time which this invite was initiated * @param server The server the request is from */ - private void addToInvite(UUID invited, String invitedBy, String party, long currentTime, String server) + private void addToInvite(UUID invited, String invitedBy, String party, String server) { List inviteDatas = _activeInvites.get(invited); if (inviteDatas == null) { inviteDatas = Lists.newArrayList(); } - InviteData inviteData = new InviteData(invitedBy, party, currentTime, server); + InviteData inviteData = new InviteData(party, server); inviteDatas.add(inviteData); _invitedBy.put(invited, invitedBy); _activeInvites.put(invited, inviteDatas); 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 6775dd3fb..8f8502a83 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -21,9 +21,6 @@ import java.util.stream.Collectors; public class PartyJoinManager { - private final String CANNOT_JOIN = "no"; - private final String CAN_JOIN = "yes"; - private final PartyManager _plugin; private final int _maxPLayers; private final List _transferring; @@ -74,12 +71,12 @@ public class PartyJoinManager //Max number of people on. 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; } } - _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; } - if (response.equalsIgnoreCase(CANNOT_JOIN)) + if (response.equalsIgnoreCase(JoinResponseReason.CANNOT_JOIN_FULL.getCode())) { party.sendMessage(reason.getMessage()); return; 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 eb741c152..7dde209b8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -95,61 +95,64 @@ public class PartyRedisManager String first = contents[0]; String second = contents[1]; String third = contents[2]; - switch (messageType) - { - case INVITE_PLAYER_REQUEST: - _plugin.getInviteManager().handleInviteRequest(second, third, first); - break; + Bukkit.getScheduler().runTask(_plugin.getPlugin(), () -> { + switch (messageType) + { + case INVITE_PLAYER_REQUEST: + _plugin.getInviteManager().handleInviteRequest(second, third, first); + break; - case INVITE_PLAYER_RESPONSE: - _plugin.getInviteManager().handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase())); - break; + case INVITE_PLAYER_RESPONSE: + _plugin.getInviteManager().handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase())); + break; - case PLAYER_FIND_REQUEST: - Player player = Bukkit.getPlayer(second); + case PLAYER_FIND_REQUEST: + Player player = Bukkit.getPlayer(second); - if (player == null) - { - return; - } + if (player == null) + { + return; + } - publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third); - break; + publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third); + break; - case PLAYER_FIND_RESPONSE: - UUID uuid = UUID.fromString(third); - BukkitTask task = TASKS.remove(second); + case PLAYER_FIND_RESPONSE: + UUID uuid = UUID.fromString(third); + BukkitTask task = TASKS.remove(second); - if (task != null) - { - task.cancel(); - } + if (task != null) + { + task.cancel(); + } - Player inviter = Bukkit.getPlayerExact(contents[3]); - if (_plugin.getInviteManager().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); - } - _plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName()); - publish(first, INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); - break; + Player inviter = Bukkit.getPlayerExact(contents[3]); + if (_plugin.getInviteManager().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); + } + _plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName()); + publish(first, INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); + break; - case PREJOIN_SERVER_REQUEST: - _plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3])); - break; + case PREJOIN_SERVER_REQUEST: + _plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3])); + 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; - } } /** From 0fc64c45a8f9ef63a01340896ab509e7bda2972b Mon Sep 17 00:00:00 2001 From: TadahTech Date: Wed, 20 Jul 2016 16:33:26 -0500 Subject: [PATCH 42/53] Update JoinResponseReason --- .../core/party/constants/JoinResponseReason.java | 12 +++--------- .../core/party/manager/PartyJoinManager.java | 9 ++++----- .../core/party/manager/PartyRedisManager.java | 2 +- .../mineplex/core/party/redis/RedisMessageType.java | 4 ++-- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java index 6a32c3672..56cd100e2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java @@ -8,16 +8,14 @@ import mineplex.core.common.util.F; public enum JoinResponseReason { - CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!"), "no"), - SUCCESS("", "yes"); + CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")), + SUCCESS(""); private String _message; - private String _code; - JoinResponseReason(String message, String code) + JoinResponseReason(String message) { _message = message; - _code = code; } public String getMessage() @@ -25,8 +23,4 @@ public enum JoinResponseReason return _message; } - public String getCode() - { - return _code; - } } 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 8f8502a83..9226ce9c6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -71,12 +71,12 @@ public class PartyJoinManager //Max number of people on. if (!canJoinFull) { - _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), JoinResponseReason.CANNOT_JOIN_FULL.getCode(), _plugin.getServerName()); + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), _plugin.getServerName()); return; } } - _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), JoinResponseReason.SUCCESS.getCode(), _plugin.getServerName()); + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), _plugin.getServerName()); } @@ -84,11 +84,10 @@ public class PartyJoinManager * Manages a received response * * @param playerSender The player who sent the request - * @param response The String response * @param server The server responding * @param reason The reason for the response */ - public void handleJoinResponse(String playerSender, String response, String server, JoinResponseReason reason) + public void handleJoinResponse(String playerSender, String server, JoinResponseReason reason) { Player player = Bukkit.getPlayer(playerSender); if (player == null) @@ -100,7 +99,7 @@ public class PartyJoinManager { return; } - if (response.equalsIgnoreCase(JoinResponseReason.CANNOT_JOIN_FULL.getCode())) + if (reason != JoinResponseReason.SUCCESS) { party.sendMessage(reason.getMessage()); return; 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 7dde209b8..d657d3214 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -148,7 +148,7 @@ public class PartyRedisManager break; case PREJOIN_SERVER_RESPONSE: - _plugin.getJoinManager().handleJoinResponse(first, third, contents[3], JoinResponseReason.valueOf(second.toUpperCase())); + _plugin.getJoinManager().handleJoinResponse(first, third, JoinResponseReason.valueOf(second.toUpperCase())); break; } }); 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 073285ed8..341e121a6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -19,8 +19,8 @@ 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}"), + //Message: PLAYER_INITIATING,REASON,SERVER + PREJOIN_SERVER_RESPONSE(6, "{0},{1},{2}"), //Message: JSON Party PARTY_INFO(7, "{0}"), From 14e5928b00c851c0848f6659459c83ee1d98a5e1 Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 20 Jul 2016 17:33:03 -0500 Subject: [PATCH 43/53] Add a pull request template --- .github/PULL_REQUEST_TEMPLATE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE new file mode 100644 index 000000000..bcaa0058b --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE @@ -0,0 +1,21 @@ + +### PR guidelines + +- Everything needs to be tested. This can be done with or without QA as appropriate. When in doubt, _ask_. +- Skim over your diff at least once before submitting. By skimming over the diff, you may catch glaring errors, merge issues, etc. that may otherwise waste time in code review. + +Fill out the form below (replace the space between the brackets with an `x` if the statement is accurate). The provided release notes will appear in #pc-release. + +(You may delete the following divider and everything above it) + +--- + +- [ ] I have tested, to the best of my ability, the changes being submitted. + +Public release notes: +- One +- Two +- Threeee + +Internal / private release notes (if applicable): +- Four From c3b7a817308f927ecd589df5202c811da5e647db Mon Sep 17 00:00:00 2001 From: TadahTech Date: Wed, 20 Jul 2016 17:48:24 -0500 Subject: [PATCH 44/53] Don't show all buttons in all menus. Protected fields != private fields. --- .../src/mineplex/core/party/ui/Menu.java | 2 +- .../core/party/ui/menus/PartyInvitesMenu.java | 23 ++++++++++--------- .../core/party/ui/menus/PartyOwnerMenu.java | 19 +++++++-------- .../core/party/ui/menus/PartyViewMenu.java | 9 ++++---- 4 files changed, 28 insertions(+), 25 deletions(-) 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 90d8ef852..3775d46e9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java @@ -36,7 +36,7 @@ public abstract class Menu protected static final Button[] EMPTY = new Button[54]; protected static Map MENUS = new HashMap<>(); private String _name; - protected Button[] _buttons; + private Button[] _buttons; protected PartyManager _plugin; public Menu(String name, PartyManager plugin) 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 2ba29aad6..eb0e4f626 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 @@ -59,9 +59,10 @@ public class PartyInvitesMenu extends Menu @Override protected Button[] setUp(Player player) { + Button[] buttons = new Button[54]; boolean showFiltered = false; - _buttons[BACK_BUTTON_SLOT] = new BackButton(_plugin); + buttons[BACK_BUTTON_SLOT] = new BackButton(_plugin); List all = (List) _plugin.getInviteManager().getAllInvites(player); @@ -69,21 +70,21 @@ public class PartyInvitesMenu extends Menu { for (int i = 10; i < 44; i++) { - _buttons[i] = NO_INVITES; + buttons[i] = NO_INVITES; } player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); - return addPanes(_buttons); + return addPanes(buttons); } - _buttons[DENY_ALL_BUTTON_SLOW] = new DenyAllButton(_plugin); + buttons[DENY_ALL_BUTTON_SLOW] = new DenyAllButton(_plugin); if (_filterBy == null || _filterBy.isEmpty()) { - _buttons[FILTER_BUTTON_SLOT] = new FilterButton(_plugin); + buttons[FILTER_BUTTON_SLOT] = new FilterButton(_plugin); } else { showFiltered = true; - _buttons[FILTER_BUTTON_SLOT] = new FilterButton(_filterBy, _plugin); + buttons[FILTER_BUTTON_SLOT] = new FilterButton(_filterBy, _plugin); } if (showFiltered) @@ -95,14 +96,14 @@ public class PartyInvitesMenu extends Menu { for (int i = 10; i < 44; i++) { - _buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) + buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) .setData(DyeColor.RED.getWoolData()) .setTitle(C.cRedB + "No Invites Found") .setLore(" ", C.cGray + "The filter " + F.name(_filterBy) + " had no results.") .build(), _plugin); } player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); - return addPanes(_buttons); + return addPanes(buttons); } _data = all; @@ -116,7 +117,7 @@ public class PartyInvitesMenu extends Menu pagesNeeded++; size -= SLOTS_PER_PAGE; } - _buttons[NEXT_PAGE_SLOT] = new NextPageButton(this, _plugin); + buttons[NEXT_PAGE_SLOT] = new NextPageButton(this, _plugin); _pagesNeeded = pagesNeeded; _pagesOfData = Maps.newHashMap(); @@ -145,12 +146,12 @@ public class PartyInvitesMenu extends Menu for (int i = 0; i < all.size(); i++) { String to = all.get(i).getInvitedTo(); - _buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin); + buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin); } } - return addPanes(_buttons); + return addPanes(buttons); } public void setButton(int slot, Button button) 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 2bdf85157..70380082e 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 @@ -45,18 +45,19 @@ public class PartyOwnerMenu extends Menu @Override protected Button[] setUp(Player player) { + Button[] buttons = new Button[54]; //Tools - _buttons[ADD_PLAYER_BUTTON_SLOT] = new AddPlayerButton(_plugin, _party); + buttons[ADD_PLAYER_BUTTON_SLOT] = new AddPlayerButton(_plugin, _party); //Kick player - _buttons[KICK_PLAYER_BUTTON_SLOT] = new KickPlayerButton(_party); + buttons[KICK_PLAYER_BUTTON_SLOT] = new KickPlayerButton(_party); //Transfer ownership - _buttons[TRANSFER_OWNER_BUTTON_SLOT] = new TransferOwnerButton(_party, _plugin); + buttons[TRANSFER_OWNER_BUTTON_SLOT] = new TransferOwnerButton(_party, _plugin); //Go to server - _buttons[SELECT_SERVER_BUTTON_SLOT] = new SelectServerButton(_party); + buttons[SELECT_SERVER_BUTTON_SLOT] = new SelectServerButton(_party); //Leave party - _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(_plugin); + buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(_plugin); //Disband - _buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(_plugin); + buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(_plugin); int slot = STARTING_SLOT; //Players @@ -67,18 +68,18 @@ public class PartyOwnerMenu extends Menu slot = SKIP_TO_SLOT; } String member = _party.getMembers().get(i); - _buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner())); + buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner())); } if(_party.getSize() == 5) { for(int i = 29; i < 34; i++) { - _buttons[i] = PURCHASE_MORE_SLOTS; + buttons[i] = PURCHASE_MORE_SLOTS; } } - return addPanes(_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 80df07b28..5fc4cff5b 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 @@ -32,10 +32,11 @@ public class PartyViewMenu extends Menu @Override protected Button[] setUp(Player player) { + Button[] buttons = new Button[54]; //Tools - _buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(_plugin); + buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(_plugin); //Suggest Player - _buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, _plugin); + buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, _plugin); int slot = STARTING_SLOT; //Players @@ -46,9 +47,9 @@ public class PartyViewMenu extends Menu slot = SKIP_TO_SLOT; } String member = _party.getMembers().get(i); - _buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner())); + buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner())); } - return addPanes(_buttons); + return addPanes(buttons); } } From b136372d1b4226252f518fa483520dad55c76d33 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 20 Jul 2016 17:55:23 -0500 Subject: [PATCH 45/53] Gem fountain changes; increase goal, link to eu --- .../core/brawl/fountain/Fountain.java | 24 ++++++++++--- .../core/brawl/fountain/FountainManager.java | 16 +++++++-- .../brawl/fountain/command/AddCommand.java | 2 +- .../gui/button/FountainAddButton.java | 2 +- .../serverdata/redis/counter/Counter.java | 35 ++++++++++--------- .../redis/counter/CounterRedisRepository.java | 10 ++++-- .../serverdata/redis/counter/GoalCounter.java | 29 +++++++++++---- 7 files changed, 85 insertions(+), 33 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java index a7efd950b..471bfe8e2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java @@ -5,16 +5,20 @@ import mineplex.core.brawl.fountain.gui.FountainShop; import mineplex.core.common.SortedSchematicLoader; import mineplex.core.common.block.schematic.UtilSchematic; import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilText; import mineplex.core.donation.DonationManager; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramManager; import mineplex.core.stats.StatsManager; +import mineplex.core.thread.ThreadPool; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.serverdata.Region; import mineplex.serverdata.redis.counter.GoalCounter; import mineplex.serverdata.redis.counter.GoalCounterListener; +import mineplex.serverdata.servers.ConnectionData; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -49,7 +53,7 @@ public class Fountain implements GoalCounterListener private final FountainShop _shop; - public Fountain(Location location, Location pasteLocation, String name, String dataKey, long goal, FountainManager fountainManager, + public Fountain(ConnectionData writeConnection, ConnectionData readConnection, Region region, Location location, Location pasteLocation, String name, String dataKey, long goal, FountainManager fountainManager, CoreClientManager clientManager, DonationManager donationManager, HologramManager hologramManager, StatsManager statsManager) { @@ -60,7 +64,7 @@ public class Fountain implements GoalCounterListener _dataKey = dataKey; _location = location; _hologram = new Hologram(hologramManager, location.clone().add(4, 3, -3), name).start(); - _counter = new GoalCounter(dataKey, 5000, goal); + _counter = new GoalCounter(writeConnection, readConnection, region, dataKey, goal); _counter.addListener(this); _brawlActive = false; // _blockProgressBar = new BlockProgressBar(_lavaLocation.getBlock(), Material.LAVA, BlockFace.UP); @@ -164,11 +168,16 @@ public class Fountain implements GoalCounterListener } } - public void increment(Player player, long amount) + public void increment(Player player, long amount, Callback callback) { _statsManager.incrementStat(player, getStatName(), amount); - _counter.addAndGet(amount); - updateVisuals(); + _statsManager.runAsync(() -> { + long count = _counter.addAndGet(amount); + _statsManager.runSync(() -> { + updateVisuals(); + if (callback != null) callback.run(count); + }); + }); } public long getAmountAdded(Player player) @@ -243,6 +252,11 @@ public class Fountain implements GoalCounterListener } } + public void updateCounter() + { + _counter.updateCount(); + } + public boolean isBrawlActive() { return _brawlActive; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java index 11e4cf821..2d7444df9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java @@ -14,6 +14,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.Region; import mineplex.serverdata.redis.counter.Counter; +import mineplex.serverdata.servers.ConnectionData; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -51,8 +52,10 @@ public class FountainManager extends MiniPlugin World world = Bukkit.getWorlds().get(0);//-43.5, 66, -38.5 - int goal = !new File("eu.dat").exists() ? 200000000 : 20000000; - _gemFountain = new Fountain(new Location(world, -32.5, 72, -23.5), new Location(world, -43.5, 67, -38.5), + int goal = 70000000;//!new File("eu.dat").exists() ? 200000000 : 20000000; + _gemFountain = new Fountain(new ConnectionData("10.3.203.80", 6379, ConnectionData.ConnectionType.MASTER, "USRedis"), + new ConnectionData("10.3.203.80", 6377, ConnectionData.ConnectionType.SLAVE, "USRedis"), Region.ALL, + new Location(world, -32.5, 72, -23.5), new Location(world, -43.5, 67, -38.5), C.cGreen + "Gem Fountain", "GemFountain_01", goal, this, clientManager, donationManager, _hologramManager, _statsManager); } @@ -72,6 +75,15 @@ public class FountainManager extends MiniPlugin _gemFountain.updateVisuals(); } + @EventHandler + public void updateCounter(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC_05) + return; + + runSync(_gemFountain::updateCounter); + } + @EventHandler public void onInteractAtEntity(PlayerInteractAtEntityEvent event) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java index 1be61d068..cd1bf65a5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java @@ -41,7 +41,7 @@ public class AddCommand extends CommandBase { if (result == TransactionResponse.Success) { - Plugin.getGemFountain().increment(caller, amount); + Plugin.getGemFountain().increment(caller, amount, null); UtilPlayer.message(caller, F.main("Fountain", "Added " + F.elem(amount) + " to the fountain!")); } else if (result == TransactionResponse.InsufficientFunds) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java index 9460025c1..c37c8c551 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java @@ -34,7 +34,7 @@ public class FountainAddButton implements IButton { public void run() { - _page.getPlugin().getGemFountain().increment(player, _gems); + _page.getPlugin().getGemFountain().increment(player, _gems, null); _page.refresh(); } }, _page, _salesPackage, CurrencyType.GEM, player)); diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java index 208491b4b..af6a05043 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java @@ -1,5 +1,8 @@ package mineplex.serverdata.redis.counter; +import mineplex.serverdata.Region; +import mineplex.serverdata.servers.ConnectionData; + import java.util.concurrent.atomic.AtomicLong; /** @@ -14,26 +17,25 @@ public class Counter private final AtomicLong _count = new AtomicLong(0); // The System.currentTimeMillis() when cached count was last updated private volatile long _lastUpdated; - // The maximum time to wait before syncing the count with repository - private final long _syncTime; // The unique key to reference this counter private final String _dataKey; // Redis repository to store the count private final CounterRedisRepository _redisRepository; - public Counter(String dataKey, long syncTime) + public Counter(ConnectionData writeConnection, ConnectionData readConnection, Region region, String dataKey) { _dataKey = dataKey; - _syncTime = syncTime; - _redisRepository = new CounterRedisRepository(dataKey); + _redisRepository = new CounterRedisRepository(writeConnection, readConnection, region, dataKey); } public Counter(String dataKey) { - this(dataKey, 5000); // 5 seconds + _dataKey = dataKey; + _redisRepository = new CounterRedisRepository(dataKey); } + /** * Add a value to the counter and return the new counter value. This method is thread-safe and interacts * directly with the atomic value stored in redis. The value returned from redis is then returned @@ -51,25 +53,26 @@ public class Counter } /** - * Get the latest count of the counter. This will use the last cached value for the counter, or if - * the last cached count hasn't been updated in the {@link #_syncTime} period it will pull the latest - * count from the redis repository and use that value. + * Get the latest cached count from the counter. This value will not be changed until {@link #addAndGet(long)} + * or {@link #updateCount} is called. * * @return The counter count */ public long getCount() { - if (System.currentTimeMillis() - _lastUpdated > _syncTime) - { - updateCount(_redisRepository.getCount()); - } - return _count.get(); } /** - * Reset the counter back to 0. This will take a maximum time of {@link #_syncTime} to propagate - * across all instances of this counter. Immediately updates the redis repository. + * Update the cached count to reflect the count in redis. This should be called async + */ + public void updateCount() + { + updateCount(_redisRepository.getCount()); + } + + /** + * Reset the counter back to 0. Immediately updates the redis repository. * * @return The value of the counter before it was reset */ diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java index 96a1cb0e3..69561aed8 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java @@ -2,6 +2,7 @@ package mineplex.serverdata.redis.counter; import mineplex.serverdata.Region; import mineplex.serverdata.redis.RedisRepository; +import mineplex.serverdata.servers.ConnectionData; import redis.clients.jedis.Jedis; /** @@ -12,13 +13,18 @@ public class CounterRedisRepository extends RedisRepository { private String _dataKey; + public CounterRedisRepository(ConnectionData writeConnection, ConnectionData readConnection, Region region, String dataKey) + { + super(writeConnection, readConnection, region); + + _dataKey = dataKey; + } + public CounterRedisRepository(String dataKey) { super(Region.ALL); _dataKey = dataKey; - -// setNX(); } /** diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/GoalCounter.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/GoalCounter.java index 8d14e56f0..38bb33d1a 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/GoalCounter.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/GoalCounter.java @@ -1,5 +1,8 @@ package mineplex.serverdata.redis.counter; +import mineplex.serverdata.Region; +import mineplex.serverdata.servers.ConnectionData; + import java.util.ArrayList; import java.util.List; @@ -18,17 +21,31 @@ public class GoalCounter extends Counter private List _listeners; - public GoalCounter(String dataKey, long syncTime, long goal) + public GoalCounter(ConnectionData writeConnection, ConnectionData readConnection, Region region, String dataKey, long goal) { - super(dataKey, syncTime); + super(writeConnection, readConnection, region, dataKey); + init(goal); + } + + public GoalCounter(String dataKey, long goal) + { + super(dataKey); + + init(goal); + } + + private void init(long goal) + { _completed = false; _goal = goal; - _listeners = new ArrayList<>(); + + updateCount(); + _lastMilestone = (int) getFillPercent(); - update(); + updateMilestone(); } /** @@ -78,7 +95,7 @@ public class GoalCounter extends Counter /** * Update {@link #_completed} and notify listeners if it has completed */ - private void update() + private void updateMilestone() { int currentMilestone = (int) getFillPercent(); @@ -95,7 +112,7 @@ public class GoalCounter extends Counter { super.updateCount(newCount); - update(); + updateMilestone(); } } From 31d6a2542d30c01809b96c1f070915bc0e3b00d4 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 20 Jul 2016 17:58:36 -0500 Subject: [PATCH 46/53] Replace runSync call with runAsync --- .../src/mineplex/core/brawl/fountain/FountainManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java index 2d7444df9..d141e1997 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java @@ -81,7 +81,7 @@ public class FountainManager extends MiniPlugin if (event.getType() != UpdateType.SEC_05) return; - runSync(_gemFountain::updateCounter); + runAsync(_gemFountain::updateCounter); } @EventHandler From e7da161f351e8e5d7d28d61daeed2f0734da44da Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 20 Jul 2016 20:07:06 -0500 Subject: [PATCH 47/53] Revert "Fixed PC-706" This reverts commit 96d16be5b7365bec86189b7ace2454e0ecfca78c. --- .../game/core/damage/DamageManager.java | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java index 304394625..c679ba060 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java @@ -8,6 +8,24 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.npc.NpcManager; +import mineplex.minecraft.game.core.combat.CombatManager; +import mineplex.minecraft.game.core.condition.ConditionManager; +import mineplex.minecraft.game.core.damage.compatibility.NpcProtectListener; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityLiving; + import org.bukkit.EntityEffect; import org.bukkit.GameMode; import org.bukkit.Location; @@ -30,24 +48,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import mineplex.core.MiniPlugin; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilEvent; -import mineplex.core.common.util.UtilGear; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.disguise.DisguiseManager; -import mineplex.core.npc.NpcManager; -import mineplex.minecraft.game.core.combat.CombatManager; -import mineplex.minecraft.game.core.condition.ConditionManager; -import mineplex.minecraft.game.core.damage.compatibility.NpcProtectListener; -import net.minecraft.server.v1_8_R3.DamageSource; -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityLiving; - public class DamageManager extends MiniPlugin { private CombatManager _combatManager; @@ -545,21 +545,14 @@ public class DamageManager extends MiniPlugin origin = event.GetDamagerEntity(true).getLocation(); if (event.getKnockbackOrigin() != null) origin = event.getKnockbackOrigin(); + else if (event.GetProjectile() != null) + origin = event.GetProjectile().getLocation(); //Vec Vector trajectory = UtilAlg.getTrajectory2d(origin, event.GetDamageeEntity().getLocation()); trajectory.multiply(0.6 * knockback); trajectory.setY(Math.abs(trajectory.getY())); - - //Special handling for projectiles - if(event.GetProjectile() != null && event.getKnockbackOrigin() == null) - { - trajectory = event.GetProjectile().getVelocity(); - trajectory.setY(0); - trajectory.multiply(0.6 * knockback / trajectory.length()); - trajectory.setY(0.5); - } - + //Apply double vel = 0.2 + trajectory.length() * 0.8; From 76ac89266e36392a326fdacf6bd2214fba2b039e Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 21 Jul 2016 02:05:10 -0500 Subject: [PATCH 48/53] -sigh- a hotfix. Won't invite players across servers who are already in parties. Fix transferring ownership to non-party members --- .../src/mineplex/core/party/Lang.java | 2 +- .../core/party/command/PartyCommand.java | 11 +++++---- .../core/party/manager/PartyRedisManager.java | 23 +++++++++++++++++++ .../core/party/redis/RedisMessageType.java | 10 ++++---- .../menus/input/PartyTransferOwnerMenu.java | 5 ++++ 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java index 1132b0ee2..ce270eae8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -71,7 +71,7 @@ public enum Lang if(args.length == 0) { - return _message; + return color + _message; } if(_message.startsWith("Error:")) 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 8944428bf..152a4eeaf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -38,6 +38,11 @@ public class PartyCommand extends CommandBase { if (args.length == 0) { + if(_aliasUsed.equalsIgnoreCase("openinvitesmenu")) + { + new PartyInvitesMenu(Plugin).open(caller); + return; + } Party party = Plugin.getParty(caller); if (party == null) { @@ -52,11 +57,7 @@ public class PartyCommand extends CommandBase new PartyViewMenu(party, Plugin).open(caller); return; } - if(_aliasUsed.equalsIgnoreCase("openinvitesmenu")) - { - new PartyInvitesMenu(Plugin).open(caller); - return; - } + if(args.length == 1) { String arg = args[0]; 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 d657d3214..8fed92286 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -114,9 +114,19 @@ public class PartyRedisManager return; } + if(_plugin.getParty(player) != null) + { + publish(first, RedisMessageType.INVITE_PLAYER_ALREADY_IN_PARTY, _serverName, player.getName(), player.getUniqueId().toString(), third); + return; + } + publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third); break; + case INVITE_PLAYER_ALREADY_IN_PARTY: + handleAlreadyIn(second, contents); + break; + case PLAYER_FIND_RESPONSE: UUID uuid = UUID.fromString(third); BukkitTask task = TASKS.remove(second); @@ -155,6 +165,19 @@ public class PartyRedisManager } + private void handleAlreadyIn(String second, String[] contents) + { + BukkitTask task = TASKS.remove(second); + + if (task != null) + { + task.cancel(); + } + + Player inviter = Bukkit.getPlayerExact(contents[3]); + Lang.ALREADY_IN.send(inviter, second); + } + /** * Initiates inviting a player who is no on the same server * 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 341e121a6..da3d249c4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -16,15 +16,17 @@ public enum RedisMessageType INVITE_PLAYER_REQUEST(3, "{0},{1},{2}"), //Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE INVITE_PLAYER_RESPONSE(4, "{0},{1},{2},{3}"), + //Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE + INVITE_PLAYER_ALREADY_IN_PARTY(5, "{0},{1},{2},{3}"), //Message: SERVER_FROM,PLAYER_INITIATING,PARTY_SIZE,_CAN_JOIN_FULL - PREJOIN_SERVER_REQUEST(5, "{0},{1},{2},{3}"), + PREJOIN_SERVER_REQUEST(6, "{0},{1},{2},{3}"), //Message: PLAYER_INITIATING,REASON,SERVER - PREJOIN_SERVER_RESPONSE(6, "{0},{1},{2}"), + PREJOIN_SERVER_RESPONSE(7, "{0},{1},{2}"), //Message: JSON Party - PARTY_INFO(7, "{0}"), - TEST_CONN(8, "{0}") + PARTY_INFO(8, "{0}"), + TEST_CONN(9, "{0}") ; private int _id; 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 index 8f407393b..91305bfdc 100644 --- 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 @@ -24,6 +24,11 @@ public class PartyTransferOwnerMenu extends PlayerNameMenu @Override public void onSuccess(String name) { + if(!_party.contains(name)) + { + Lang.NOT_MEMBER.send(_player, name); + return; + } _partyManager.getMethodManager().transferOwner(name, _player.getName()); Lang.TRANSFER_OWNER.send(_party, _player.getName(), name); _player.closeInventory(); From 4cab91f2510f05ac291fe4d2a9304e09797f9ee2 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 21 Jul 2016 02:05:37 -0500 Subject: [PATCH 49/53] Use getPlayerExact. --- .../src/mineplex/core/party/manager/PartyRedisManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8fed92286..5a16c5937 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -107,7 +107,7 @@ public class PartyRedisManager break; case PLAYER_FIND_REQUEST: - Player player = Bukkit.getPlayer(second); + Player player = Bukkit.getPlayerExact(second); if (player == null) { From f1b3c4756dd8a694c023c0b5dda10505e8178f1f Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 21 Jul 2016 02:16:26 -0500 Subject: [PATCH 50/53] Use UUID's instead of playernames. --- .../src/mineplex/core/party/manager/PartyRedisManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5a16c5937..ad41f6ca1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -225,7 +225,7 @@ public class PartyRedisManager public void sendPartyInfo(String server, Party party) { publish(server, PARTY_INFO, GSON.toJson(party)); - List members = party.getMembers(); + List members = party.getMembersByUUID(); party.getMembersByUUID().forEach(uuid -> _plugin.getMethodManager().removeForTransfer(uuid)); members.stream().map(Bukkit::getPlayer).forEach(player1 -> { From 9f0f4e00186fb608b4a909301adecafeab05b2ae Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 21 Jul 2016 02:20:02 -0500 Subject: [PATCH 51/53] Fix possible cross server invite spamming. --- .../core/party/manager/PartyRedisManager.java | 23 +++++++++++++++++++ .../core/party/redis/RedisMessageType.java | 2 ++ 2 files changed, 25 insertions(+) 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 ad41f6ca1..4f1d01473 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -120,6 +120,12 @@ public class PartyRedisManager return; } + if(!_plugin.getPreferencesManager().Get(player).PartyRequests) + { + publish(first, RedisMessageType.INVITE_PLAYER_NOT_ACCEPTING_INVITES, _serverName, player.getName(), player.getUniqueId().toString(), third); + return; + } + publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third); break; @@ -127,6 +133,10 @@ public class PartyRedisManager handleAlreadyIn(second, contents); break; + case INVITE_PLAYER_NOT_ACCEPTING_INVITES: + handleNotAccepting(second, contents); + break; + case PLAYER_FIND_RESPONSE: UUID uuid = UUID.fromString(third); BukkitTask task = TASKS.remove(second); @@ -165,6 +175,19 @@ public class PartyRedisManager } + private void handleNotAccepting(String second, String[] contents) + { + BukkitTask task = TASKS.remove(second); + + if (task != null) + { + task.cancel(); + } + + Player inviter = Bukkit.getPlayerExact(contents[3]); + inviter.sendMessage(F.main("Party", F.name(second) + " is not accepting invites at this time.")); + } + private void handleAlreadyIn(String second, String[] contents) { BukkitTask task = TASKS.remove(second); 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 da3d249c4..533f62c75 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -18,6 +18,8 @@ public enum RedisMessageType INVITE_PLAYER_RESPONSE(4, "{0},{1},{2},{3}"), //Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE INVITE_PLAYER_ALREADY_IN_PARTY(5, "{0},{1},{2},{3}"), + //Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE + INVITE_PLAYER_NOT_ACCEPTING_INVITES(5, "{0},{1},{2},{3}"), //Message: SERVER_FROM,PLAYER_INITIATING,PARTY_SIZE,_CAN_JOIN_FULL PREJOIN_SERVER_REQUEST(6, "{0},{1},{2},{3}"), From b734dc4e87ca3fa8958072e815dbd77fa46a3b0e Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 21 Jul 2016 02:59:15 -0500 Subject: [PATCH 52/53] Remove Pay wall for Party sizes --- Plugins/Mineplex.Core/src/mineplex/core/party/Party.java | 5 ++--- .../src/mineplex/core/party/PartyEventListener.java | 4 ++-- .../src/mineplex/core/party/manager/PartyInviteManager.java | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index d649d6c5f..b5eb8ee63 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -137,11 +137,10 @@ public class Party /** * Set's this party's size cap base off the current players rank * - * @param increased true if this party should have the increased size */ - public void setSize(boolean increased) + public void setSize() { - _size = increased ? PARTY_MAX_SIZE : PARTY_MIN_SIZE; + _size = PARTY_MAX_SIZE; } /** diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java index f7e334a84..a6cb19271 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -53,10 +53,10 @@ public class PartyEventListener implements Listener if (bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA)) { - party.setSize(true); + party.setSize(); } else { - party.setSize(false); + party.setSize(); } _plugin.addParty(party); 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 580701efc..27b9dedd0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -82,10 +82,10 @@ public class PartyInviteManager newParty = new Party(possible.getName()); if(_plugin.getClientManager().Get(possible).GetRank().has(Rank.ULTRA)) { - newParty.setSize(true); + newParty.setSize(); } else { - newParty.setSize(false); + newParty.setSize(); } _plugin.addParty(newParty); _plugin.getMethodManager().addToParty(possible.getUniqueId(), newParty); From b48f97fd2e870108cbb53899612582c00a57fe52 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Thu, 21 Jul 2016 03:46:18 -0500 Subject: [PATCH 53/53] Fix stupid JOOQ issue and IntelliJ. --- .../Mineplex.Core/src/mineplex/core/party/Lang.java | 2 +- .../game/arcade/managers/chat/GameChatManager.java | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java index ce270eae8..0cccd2bc9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -15,7 +15,7 @@ public enum Lang 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! You have 60 seconds to reply."), + INVITE_RECEIVED("You have been invited to {0}''s party! You have 60 seconds to reply."), INVITE_ACCEPT("{0} has joined the party."), INVITE_DENY("{0} declined your invite."), INVITE_EXPIRED("{0} did not respond in time."), 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 6c63497ef..996fc364c 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 @@ -11,7 +11,6 @@ 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; @@ -21,11 +20,11 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.jooq.tools.json.JSONObject; import java.text.DecimalFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static mineplex.database.routines.Test.playerName; -import static sun.audio.AudioPlayer.player; +import java.util.AbstractMap; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; public class GameChatManager implements Listener { @@ -131,7 +130,7 @@ public class GameChatManager implements Listener 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"); + event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + event.getPlayer().getName() + " " + C.cPurple + "%2$s"); for (String member : party.getMembers()) {