Parties rewrite

Basically everything got changed. Also Portal has a slightly better API
now
This commit is contained in:
samczsun 2016-12-03 10:50:29 -05:00 committed by cnr
parent 91773de97e
commit 56d4ed9e11
122 changed files with 3272 additions and 2708 deletions

View File

@ -152,7 +152,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
} }
catch (Throwable t) catch (Throwable t)
{ {
throw new RuntimeException(exception); exception.initCause(t);
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
} }
}); });
} }
@ -169,7 +170,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
} }
catch (Throwable t) catch (Throwable t)
{ {
throw new RuntimeException(exception); exception.initCause(t);
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
} }
}, time); }, time);
} }
@ -186,7 +188,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
} }
catch (Throwable t) catch (Throwable t)
{ {
throw new RuntimeException(exception); exception.initCause(t);
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
} }
}, time, period); }, time, period);
} }
@ -203,7 +206,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
} }
catch (Throwable t) catch (Throwable t)
{ {
throw new RuntimeException(exception); exception.initCause(t);
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
} }
}); });
} }
@ -220,7 +224,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
} }
catch (Throwable t) catch (Throwable t)
{ {
throw new RuntimeException(exception); exception.initCause(t);
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
} }
}, delay); }, delay);
} }
@ -242,7 +247,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
} }
catch (Throwable t) catch (Throwable t)
{ {
throw new RuntimeException(exception); exception.initCause(t);
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
} }
}, delay, period); }, delay, period);
} }

View File

@ -8,6 +8,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -26,6 +27,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Sets;
import com.google.gson.Gson; import com.google.gson.Gson;
import mineplex.cache.player.PlayerCache; import mineplex.cache.player.PlayerCache;
@ -65,6 +67,8 @@ public class CoreClientManager extends MiniPlugin
private final Rank WHITELIST_BYPASS; private final Rank WHITELIST_BYPASS;
private final Set<UUID> _reservedSlots = Sets.newConcurrentHashSet();
public CoreClientManager(JavaPlugin plugin, String webServer) public CoreClientManager(JavaPlugin plugin, String webServer)
{ {
this(plugin, webServer, Rank.MODERATOR); this(plugin, webServer, Rank.MODERATOR);
@ -254,7 +258,9 @@ public class CoreClientManager extends MiniPlugin
if (uuid == null) if (uuid == null)
{ {
uuid = UtilGameProfile.getProfileByName(playerName, false, profile -> {}).get().getId(); uuid = UtilGameProfile.getProfileByName(playerName, false, profile ->
{
}).get().getId();
} }
String response = ""; String response = "";
@ -476,8 +482,10 @@ public class CoreClientManager extends MiniPlugin
client.SetPlayer(event.getPlayer()); client.SetPlayer(event.getPlayer());
_reservedSlots.remove(event.getPlayer().getUniqueId());
// Reserved Slot Check // Reserved Slot Check
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getServer().getMaxPlayers()) if (Bukkit.getOnlinePlayers().size() + _reservedSlots.size() >= Bukkit.getServer().getMaxPlayers())
{ {
if (client.GetRank().has(event.getPlayer(), Rank.ULTRA, false)) if (client.GetRank().has(event.getPlayer(), Rank.ULTRA, false))
{ {
@ -490,6 +498,16 @@ public class CoreClientManager extends MiniPlugin
} }
} }
public void reserveFor(UUID player)
{
this._reservedSlots.add(player);
}
public void unreserve(UUID uuid)
{
_reservedSlots.remove(uuid);
}
@EventHandler @EventHandler
public void Kick(PlayerKickEvent event) public void Kick(PlayerKickEvent event)
{ {

View File

@ -28,14 +28,14 @@ public class PartyInfoMetadata extends AnticheatMetadata
@Override @Override
public JsonElement build(UUID player) public JsonElement build(UUID player)
{ {
Party party = require(PartyManager.class).getPlayerParties().get(player); Party party = require(PartyManager.class).getPartyByPlayer(player);
if (party != null) if (party != null)
{ {
JsonObject partyData = new JsonObject(); JsonObject partyData = new JsonObject();
partyData.addProperty(KEY_OWNER, party.getOwner()); partyData.addProperty(KEY_OWNER, party.getOwnerName());
JsonArray members = new JsonArray(); JsonArray members = new JsonArray();
party.getMembers().forEach(m -> members.add(new JsonPrimitive(m))); party.getMembers().forEach(m -> members.add(new JsonPrimitive(m.getName())));
partyData.add(KEY_MEMBERS, members); partyData.add(KEY_MEMBERS, members);

View File

@ -34,13 +34,11 @@ public abstract class PlayerInputActionMenu implements Listener
protected Inventory _currentInventory; protected Inventory _currentInventory;
protected String _itemName = ""; protected String _itemName = "";
protected boolean _searching; protected boolean _searching;
protected Party _party;
public PlayerInputActionMenu(MiniPlugin plugin, Player player, Party party) public PlayerInputActionMenu(MiniPlugin plugin, Player player)
{ {
_player = player; _player = player;
_plugin = plugin; _plugin = plugin;
_party = party;
player.closeInventory(); player.closeInventory();
_plugin.registerEvents(this); _plugin.registerEvents(this);
} }

View File

@ -11,8 +11,6 @@ import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import static net.minecraft.server.v1_8_R3.PotionBrewer.n;
/** /**
* A wrapped menu that handles looking for players specifically. * A wrapped menu that handles looking for players specifically.
*/ */
@ -21,9 +19,9 @@ public abstract class PlayerNameMenu extends PlayerInputActionMenu
protected CoreClientManager _clientManager; protected CoreClientManager _clientManager;
public PlayerNameMenu(MiniPlugin plugin, CoreClientManager clientManager, Player player, Party party) public PlayerNameMenu(MiniPlugin plugin, CoreClientManager clientManager, Player player)
{ {
super(plugin, player, party); super(plugin, player);
_clientManager = clientManager; _clientManager = clientManager;
} }

View File

@ -34,6 +34,7 @@ import mineplex.core.friend.data.FriendData;
import mineplex.core.friend.data.FriendStatus; import mineplex.core.friend.data.FriendStatus;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.itemstack.ItemLayout; import mineplex.core.itemstack.ItemLayout;
import mineplex.core.portal.Intent;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
public class FriendsGUI implements Listener public class FriendsGUI implements Listener
@ -302,7 +303,7 @@ public class FriendsGUI implements Listener
@Override @Override
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
{ {
_plugin.getPortal().sendPlayerToServer(player, serverName); _plugin.getPortal().sendPlayerToServer(player, serverName, Intent.PLAYER_REQUEST);
} }
}); });
} }

View File

@ -0,0 +1,28 @@
package mineplex.core.menu.builtin;
import java.util.function.Supplier;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.MiniPlugin;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
public abstract class ButtonOpenAnvilInput<T extends MiniPlugin> extends Button<T>
{
private final Supplier<Menu<T>> _menuSupplier;
public ButtonOpenAnvilInput(T plugin, ItemStack item, Supplier<Menu<T>> menu)
{
super(item, plugin);
_menuSupplier = menu;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_menuSupplier.get().open(player);
}
}

View File

@ -0,0 +1,28 @@
package mineplex.core.menu.builtin;
import java.util.function.Supplier;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.MiniPlugin;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
public class ButtonOpenInventory<T extends MiniPlugin> extends Button<T>
{
private final Supplier<Menu<T>> _menuSupplier;
public ButtonOpenInventory(ItemStack item, T plugin, Supplier<Menu<T>> menu)
{
super(item, plugin);
_menuSupplier = menu;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_menuSupplier.get().open(player);
}
}

View File

@ -1,27 +1,59 @@
package mineplex.core.party; package mineplex.core.party;
import java.util.UUID;
/** /**
* Serializable invite data * Serializable invite data
*/ */
public class InviteData public class InviteData
{ {
private final String _inviterName;
private final UUID _inviterUUID;
private final UUID _partyUUID;
private final String _serverName;
private String _invitedTo; public InviteData(String inviterName, UUID inviterUUID, UUID partyUUID, String serverName)
private String _serverFrom;
public InviteData(String invitedTo, String serverFrom)
{ {
_invitedTo = invitedTo; _inviterName = inviterName;
_serverFrom = serverFrom; _inviterUUID = inviterUUID;
_partyUUID = partyUUID;
_serverName = serverName;
} }
public String getInvitedTo() public String getInviterName()
{ {
return _invitedTo; return _inviterName;
} }
public String getServerFrom() public UUID getInviterUUID()
{ {
return _serverFrom; return _inviterUUID;
}
public UUID getPartyUUID()
{
return _partyUUID;
}
public String getServerName()
{
return _serverName;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InviteData that = (InviteData) o;
return _partyUUID.equals(that._partyUUID);
}
@Override
public int hashCode()
{
return _partyUUID.hashCode();
} }
} }

View File

@ -1,163 +1,119 @@
package mineplex.core.party; package mineplex.core.party;
import com.google.common.collect.Lists; import java.util.ArrayList;
import com.google.common.collect.Maps; import java.util.Collections;
import mineplex.core.common.util.UtilServer; import java.util.List;
import mineplex.core.party.constants.PartyRemoveReason; import java.util.Optional;
import mineplex.core.party.event.PartyTransferOwnerEvent; import java.util.UUID;
import mineplex.core.party.event.PartyTransferOwnerEvent.TransferReason;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import java.util.List; import com.google.common.collect.Lists;
import java.util.Map; import com.mojang.authlib.GameProfile;
import java.util.Objects;
import java.util.UUID; import mineplex.core.Managers;
import mineplex.core.common.util.UtilServer;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.rediscommands.PartyTransferRequest;
import mineplex.core.utils.UtilGameProfile;
/** /**
* The main object for Parites. * The main object for Parites.
*/ */
public class Party public class Party implements Listener
{ {
/**
* This is controls whether or not the owner is currently in the menu, and kicking members
*/
private transient boolean _ownerKickMode = false;
/**
* 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 maximum amount of players a party can have. * The maximum amount of players a party can have.
*/ */
private static final int PARTY_MAX_SIZE = 16; private static final int PARTY_MAX_SIZE = 16;
/** private final PartyManager _partyManager = Managers.require(PartyManager.class);
* Partners that have already been placed
*/
private transient final List<UUID> _teamed;
/** /**
* The current leader of this party * This is controls whether or not the owner is currently in the menu, and kicking members
*/ */
private String _owner; private boolean _ownerKickMode = false;
/** /**
* The names of all current party members * The unique ID assigned to this party
*/ */
private List<String> _members; private UUID _uniqueId = UUID.randomUUID();
/** /**
* The UUIDS of all current party members * Metadata related to the current owner of this party, stored in serializable form for transferring
*/ */
private List<UUID> _membersByUUID; private GameProfile _owner;
/** private List<Player> _members = Lists.newArrayList();
* All current pending invites
*/
private Map<String, Long> _invites;
/** /**
* This party's max size * This party's max size
*/ */
private int _size; private int _size = PARTY_MAX_SIZE;
/** private List<UUID> _pendingUnrankedMembers = new ArrayList<>();
* Team preferences private List<UUID> _pendingMembers = new ArrayList<>();
*/
private Map<UUID, Map<String, String>> _preferences;
/** public Party(PartyTransferRequest request)
* Empty constructor for GSON
*/
public Party()
{ {
_teamed = Lists.newArrayList(); _uniqueId = request.getPartyUUID();
_owner = request.getOwnerGameProfile();
_pendingMembers.addAll(request.getAllMembers());
_pendingUnrankedMembers.addAll(request.getUnrankedMembers());
_partyManager.runSyncLater(() ->
{
// No one joined :(
for (UUID uuid : _pendingUnrankedMembers)
{
_partyManager.getClientManager().unreserve(uuid);
}
for (UUID uuid : _pendingMembers)
{
_partyManager.removePendingJoin(uuid);
}
// No one joined :(
if (_pendingMembers.size() == request.getAllMembers().size())
{
_partyManager.removeParty(Party.this);
}
}, 20 * 10L);
} }
/** /**
* Creates a new fresh party instance * Creates a new party instance
* *
* @param owner The owner / leader of the party. * @param owner The owner / leader of the party.
*/ */
public Party(String owner) public Party(Player owner)
{ {
_owner = owner; _owner = UtilGameProfile.getGameProfile(owner);
_members = Lists.newArrayList();
_invites = Maps.newHashMap();
_members.add(owner); _members.add(owner);
_teamed = Lists.newArrayList();
_membersByUUID = Lists.newArrayList();
_preferences = Maps.newHashMap();
_membersByUUID.add(Bukkit.getPlayerExact(owner).getUniqueId());
} }
public String getOwner() public String getOwnerName()
{
return _owner.getName();
}
public GameProfile getOwner()
{ {
return _owner; return _owner;
} }
/** public Optional<Player> getOwnerAsPlayer()
* Get the current members by their IGN
*
* @return The list of named party members
*/
public List<String> getMembers()
{ {
return _members; return Optional.ofNullable(Bukkit.getPlayer(_owner.getId()));
} }
public Map<String, Long> getInvites() public UUID getUniqueId()
{ {
return _invites; return this._uniqueId;
}
/**
* 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;
}
/**
* Gets the players preferred teammate for a game
*
* @param player The player's UUID
* @return His team preference
*/
public String getPartner(UUID player, String game)
{
Map<String, String> prefs = _preferences.get(player);
if (prefs == null)
{
prefs = Maps.newHashMap();
_preferences.put(player, prefs);
return null;
}
return prefs.get(game);
}
/**
* Set a player's partner preference
*
* @param player The player
* @param game The name of the game
* @param partner The name of his partner
*/
public void setPartner(Player player, String game, String partner)
{
Map<String, String> prefs = _preferences.getOrDefault(player.getUniqueId(), Maps.newHashMap());
prefs.put(game, partner);
_preferences.put(player.getUniqueId(), prefs);
} }
/** /**
@ -167,9 +123,7 @@ public class Party
*/ */
public void sendMessage(String message) public void sendMessage(String message)
{ {
// Todo actually figure out why one of the members is no longer online getMembers().forEach(player -> player.sendMessage(message));
// probably some desync between players and something
_members.stream().map(Bukkit::getPlayer).filter(Objects::nonNull).forEach(player -> player.sendMessage(message));
} }
public int getSize() public int getSize()
@ -178,78 +132,65 @@ public class Party
} }
/** /**
* Set's this party's size cap base off the current players rank * Set's the new owner for this party instance
* *
* @param owner The new owner's name
*/ */
public void setSize() public void setOwner(Player owner)
{ {
_size = PARTY_MAX_SIZE; _owner = UtilGameProfile.getGameProfile(owner);
} }
/** public boolean isMember(Player player)
* Called when a player is added to the party. {
* return _members.contains(player);
* @param player The name of the player }
*/
public void onPlayerAdd(String player) public void addMember(Player player)
{ {
_invites.remove(player);
if (_members.contains(player)) if (_members.contains(player))
{ {
return; return;
} }
_members.add(player); _members.add(player);
Lang.ADD_MEMBER.send(this, player); _pendingMembers.remove(player.getUniqueId());
getMembers().forEach(s -> _pendingUnrankedMembers.remove(player.getUniqueId());
{ Lang.ADD_MEMBER.send(this, player.getName());
Player player1 = Bukkit.getPlayer(s); getMembers().forEach(player1 -> player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F));
player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F);
});
} }
/** public List<Player> getMembers()
* 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) return Collections.unmodifiableList(_members);
{
Player bukkitPlayer = Bukkit.getPlayerExact(player);
Lang.DISBANDED.send(bukkitPlayer);
bukkitPlayer.closeInventory();
return;
} }
public boolean isOwner(Player caller)
{
return caller.getUniqueId().equals(this._owner.getId());
}
public void clear()
{
_owner = null;
_members.clear();
UtilServer.Unregister(this);
}
public void removeMember(Player player)
{
_members.remove(player);
if (_members.size() <= 0) if (_members.size() <= 0)
{ {
return; return;
} }
if(reason == PartyRemoveReason.LEFT) System.out.println("Removing member: " + player.getName() + " "+ player.getUniqueId() + " owner is " + _owner.getId());
{
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) if (player.getUniqueId().equals(_owner.getId()) && _members.size() > 0)
{ {
return; _owner = UtilGameProfile.getGameProfile(_members.get(0));
} Lang.TRANSFER_OWNER.send(this, player.getName(), _owner.getName());
if(reason == PartyRemoveReason.KICKED)
{
Lang.REMOVE_PLAYER_KICK.send(this, player);
} }
} }
@ -272,66 +213,4 @@ public class Party
{ {
_ownerKickMode = ownerKickMode; _ownerKickMode = ownerKickMode;
} }
/**
* Set's the new owner for this party instance
*
* @param owner The new owner's name
*/
public void setOwner(String owner)
{
_owner = owner;
}
/**
* Get a list of all members in the party by their UUID
*
* @return A list of members by UUID
*/
public List<UUID> getMembersByUUID()
{
return _membersByUUID;
}
public boolean alreadyTeamed()
{
return _alreadyTeamed;
}
public void setAlreadyTeamed(boolean alreadyTeamed)
{
_alreadyTeamed = alreadyTeamed;
}
/**
* Check to see if this party contains a certain player name
* This is case-insensitive
*
* @param name The players name
* @return <code>true</code> If the player is in the party
*/
public boolean contains(String name)
{
for (UUID member : _membersByUUID)
{
if (Bukkit.getPlayer(member).getName().equalsIgnoreCase(name))
{
return true;
}
}
return false;
}
public boolean isAlreadyTeamed(UUID uuid)
{
return _teamed.contains(uuid);
}
public void setTeamed(Player... players)
{
for (Player player : players)
{
_teamed.add(player.getUniqueId());
}
}
} }

View File

@ -1,167 +0,0 @@
package mineplex.core.party;
import mineplex.core.common.Rank;
import mineplex.core.menu.Menu;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.event.PartyMemberKickGUIEvent;
import mineplex.core.party.event.PartySendToServerEvent;
import mineplex.core.party.event.PartyTransferOwnerEvent;
import mineplex.core.portal.ServerTransferEvent;
import mineplex.serverdata.data.MinecraftServer;
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;
/**
* Event handler for Parties
*/
public class PartyEventListener implements Listener
{
private final PartyManager _plugin;
public PartyEventListener(PartyManager plugin)
{
_plugin = plugin;
_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);
if (bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA))
{
party.setSize();
} else
{
party.setSize();
}
_plugin.addParty(party);
}
_plugin.getInviteManager().cancelTask(player.getUniqueId());
_plugin.getMethodManager().addToParty(Bukkit.getPlayerExact(partyName), party);
_plugin.getMethodManager().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;
}
PartyRemoveReason reason = PartyRemoveReason.LEFT;
if(_plugin.getJoinManager().isTransferring(player))
{
reason = PartyRemoveReason.OTHER;
}
_plugin.getMethodManager().removeFromParty(player, reason);
}
@EventHandler
public void onTransferOwner(PartyTransferOwnerEvent event)
{
_plugin.getMethodManager().transferOwner(event.getNewOwner(), event.getOldOwner());
}
@EventHandler
public void onKick(PartyMemberKickGUIEvent event)
{
Player clicked = Bukkit.getPlayerExact(event.getPlayerClicked());
Lang.REMOVED.send(clicked);
_plugin.getMethodManager().removeFromParty(clicked, PartyRemoveReason.KICKED);
Menu.get(event.getOwner().getUniqueId()).resetAndUpdate();
}
@EventHandler
public void onTransfer(ServerTransferEvent event)
{
Player player = event.getPlayer();
Party party = _plugin.getParty(player);
if (party == null)
{
return;
}
if(event.isDraggedByParty())
{
return;
}
event.setParty(party);
event.setCancel(true);
if (!party.getOwner().equalsIgnoreCase(player.getName()))
{
Lang.NOT_OWNER_SERVER.send(player);
return;
}
String server = event.getServer();
if(server.equalsIgnoreCase("Lobby"))
{
return;
}
_plugin.getJoinManager().requestServerJoin(event.getServer(), party);
}
@EventHandler
public void onSend(PartySendToServerEvent event)
{
Party party = event.getParty();
MinecraftServer server = event.getMinecraftServer();
_plugin.getRedisManager().sendPartyInfo(server.getName(), party);
}
@EventHandler
public void onClick(PlayerInteractEvent event)
{
if(event.hasItem() && event.getItem().getType() == Material.NAME_TAG)
{
event.setCancelled(true);
event.getPlayer().chat("/party");
}
}
}

View File

@ -1,38 +1,55 @@
package mineplex.core.party; package mineplex.core.party;
import com.google.common.collect.Maps;
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;
import mineplex.core.party.manager.PartyMethodManager;
import mineplex.core.party.manager.PartyRedisManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.servers.ServerManager;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import com.google.common.collect.Maps;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.menu.Menu;
import mineplex.core.party.command.PartyCommand;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.manager.PartyInviteManager;
import mineplex.core.party.manager.PartyJoinManager;
import mineplex.core.party.manager.PartyRedisManager;
import mineplex.core.party.rediscommands.PartyCrossServerInviteAccept;
import mineplex.core.party.rediscommands.PartyCrossServerInviteCommand;
import mineplex.core.party.rediscommands.PartyCrossServerInviteDeny;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.servers.ServerManager;
public class PartyManager extends MiniPlugin public class PartyManager extends MiniPlugin
{ {
/** /**
* The item given to a player in his hotbar to manage the Parties via the new UI. * The item given to a player in his hotbar to manage the Parties via the new UI.
*/ */
public static final ItemStack INTERFACE_ITEM = new ItemBuilder(Material.NAME_TAG).setTitle(C.cGreen + "Parties").build(); public static final ItemStack INTERFACE_ITEM = new ItemBuilder(Material.NAME_TAG)
.setTitle(C.cGreen + "Parties")
.build();
/** /**
* The slow to which it goes in. * The slot to which it goes in.
*/ */
public static final int INTERFACE_SLOT = 5; public static final int INTERFACE_SLOT = 5;
@ -43,66 +60,73 @@ public class PartyManager extends MiniPlugin
private final PartyRedisManager _redisManager; private final PartyRedisManager _redisManager;
private final PartyInviteManager _inviteManager; private final PartyInviteManager _inviteManager;
private final PartyJoinManager _joinManager; private final PartyJoinManager _joinManager;
private final PartyMethodManager _methodManager;
/** /**
* This local instance's name * This local instance's name
*/ */
private final String _serverName; private final String _serverName;
/** private final Map<UUID, Party> _partiesById = new HashMap<>();
* A map of player's in parties server wide. private final Map<UUID, Party> _partiesByPlayer = new HashMap<>();
*/
private final Map<UUID, Party> _players = Maps.newHashMap();
/**
* A map of owner (name) -> party server wide
*/
private final Map<String, Party> _parties = Maps.newHashMap();
private final Region _region; private final Region _region;
/**
* Maps UUID of player to UUID of party that they're supposed to join
*/
private final Map<UUID, UUID> _pendingJoinMap = new HashMap<>();
public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager)
public PartyManager()
{ {
super("Parties", plugin); super("Parties");
_portal = portal; _portal = require(Portal.class);
_clientManager = clientManager; _clientManager = require(CoreClientManager.class);
_preferencesManager = preferenceManager; _preferencesManager = require(PreferencesManager.class);
_serverName = _plugin.getConfig().getString("serverstatus.name"); _serverName = UtilServer.getServerName();
_redisManager = new PartyRedisManager(this, _serverName, _redisManager = new PartyRedisManager(this, _serverName,
Utility.generatePool(ServerManager.getMasterConnection()), Utility.generatePool(ServerManager.getMasterConnection()),
Utility.generatePool(ServerManager.getSlaveConnection())); Utility.generatePool(ServerManager.getSlaveConnection()));
_inviteManager = new PartyInviteManager(this, _redisManager); _inviteManager = new PartyInviteManager(this);
_joinManager = new PartyJoinManager(this); _joinManager = new PartyJoinManager(this);
_methodManager = new PartyMethodManager(this);
addCommand(new PartyCommand(this));
new PartyEventListener(this);
_region = !new File("eu.dat").exists() ? Region.US : Region.EU; _region = !new File("eu.dat").exists() ? Region.US : Region.EU;
} }
public Party getParty(String party) @Deprecated
public void putIntoPendingJoin(UUID player, UUID party)
{ {
return _parties.get(party); _pendingJoinMap.put(player, party);
} }
public Party getParty(Player player) @Override
public void addCommands()
{ {
return _players.get(player.getUniqueId()); addCommand(new PartyCommand(this));
}
public Party getPartyByPlayer(UUID playerId)
{
return _partiesByPlayer.get(playerId);
}
public Party getPartyById(UUID playerId)
{
return _partiesById.get(playerId);
}
public Party getPartyByPlayer(Player player)
{
return _partiesByPlayer.get(player.getUniqueId());
} }
public void addParty(Party party) public void addParty(Party party)
{ {
_parties.put(party.getName(), party); _partiesById.put(party.getUniqueId(), party);
}
public void removeParty(Party party)
{
_parties.remove(party.getName());
} }
public Portal getPortal() public Portal getPortal()
@ -135,29 +159,424 @@ public class PartyManager extends MiniPlugin
return _serverName; return _serverName;
} }
public PartyJoinManager getJoinManager()
{
return _joinManager;
}
public PartyMethodManager getMethodManager()
{
return _methodManager;
}
public Map<UUID, Party> getPlayerParties()
{
return _players;
}
public Map<String, Party> getParties()
{
return _parties;
}
public Region getRegion() public Region getRegion()
{ {
return _region; return _region;
} }
public void denyInviteBySender(Player caller, String senderName)
{
PartyInviteManager inviteManager = getInviteManager();
if (!inviteManager.hasInviteFrom(caller, senderName))
{
UtilPlayer.message(caller, F.main("Party", "You do not have a pending invite to " + F.elem(senderName) + "'s party."));
return;
}
InviteData invite = inviteManager.getInviteBySender(caller.getName(), senderName);
inviteManager.removeInvite(caller, senderName);
if (invite.getServerName().equals(_serverName))
{
Player senderPlayer = Bukkit.getPlayerExact(senderName);
if (senderPlayer == null)
{
UtilPlayer.message(caller, F.main("Party", "You have denied your invite to " + F.elem(senderName) + "'s party, but it seems that " + F.elem(senderName) + " is no longer in this server"));
return;
}
Party partyBySender = getPartyByPlayer(senderPlayer);
if (partyBySender == null)
{
// todo send cancelled invitation msg when party is disbanded
UtilPlayer.message(caller, F.main("Party", "You have denied your invite to " + F.elem(senderPlayer.getName()) + "'s party, but it seems that " + F.elem(senderPlayer.getName()) + " has disbanded his party as well"));
return;
}
UtilPlayer.message(caller, F.main("Party", "You have denied your invite to " + F.elem(senderPlayer.getName()) + "'s party"));
UtilPlayer.message(senderPlayer, F.main("Party", F.elem(caller.getName()) + " has denied your invite"));
}
else
{
Player senderPlayer = Bukkit.getPlayerExact(senderName);
if (senderPlayer != null)
{
UtilPlayer.message(caller, F.main("Party", "You have denied your invite to " + F.elem(senderPlayer.getName()) + "'s party, but it seems that " + F.elem(senderPlayer.getName()) + " has joined you in this server"));
return;
}
UtilPlayer.message(caller, F.main("Party", "You have denied your invite to " + F.elem(senderName) + "'s party"));
ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteDeny(
caller.getName(),
caller.getUniqueId(),
invite.getInviterName(),
invite.getInviterUUID(),
invite.getPartyUUID()
));
}
}
public void acceptInviteBySender(Player caller, String senderName)
{
if (getPartyByPlayer(caller) != null)
{
caller.sendMessage(F.main("Party", "Please leave your party before accepting another invite!"));
return;
}
PartyInviteManager inviteManager = getInviteManager();
if (!inviteManager.hasInviteFrom(caller, senderName))
{
UtilPlayer.message(caller, F.main("Party", "You do not have a pending invite to " + F.elem(senderName) + "'s party."));
return;
}
InviteData invite = inviteManager.getInviteBySender(caller.getName(), senderName);
inviteManager.removeInvite(caller, senderName);
if (invite.getServerName().equals(_serverName))
{
Player senderPlayer = Bukkit.getPlayerExact(senderName);
if (senderPlayer == null)
{
UtilPlayer.message(caller, F.main("Party", "It seems that " + F.elem(senderName) + " is no longer in this server"));
return;
}
Party partyBySender = getPartyByPlayer(senderPlayer);
if (partyBySender == null)
{
// todo send cancelled invitation msg when party is disbanded
UtilPlayer.message(caller, F.main("Party", "It seems that " + F.elem(senderName) + " has disbanded his party. Shucks!"));
return;
}
addToParty(caller, partyBySender);
}
else
{
Player senderPlayer = Bukkit.getPlayerExact(senderName);
if (senderPlayer != null)
{
// todo maybe auto create party (if there are no new desync issues)
UtilPlayer.message(caller, F.main("Party", "Strange. It seems that " + F.elem(senderName) + " has preemptively joined you in this server. They'll need to resend an invitation"));
return;
}
UtilPlayer.message(caller, F.main("Party", "Please wait while I attempt to locate " + F.elem(invite.getInviterName()) + "..."));
ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteAccept(
caller.getName(),
caller.getUniqueId(),
invite.getInviterName(),
invite.getInviterUUID(),
invite.getPartyUUID()
));
runSyncLater(() ->
{
if (!caller.isOnline())
{
return;
}
UtilPlayer.message(caller, F.main("Party", "Uh oh. It looks like " + F.elem(invite.getInviterName()) + " has left the network - I couldn't find them!"));
}, 20 * 5L);
}
}
/**
* @param caller The player who initiated the request
* @param target The player's target
*/
public void invite(Player caller, String target)
{
if (target.equalsIgnoreCase(caller.getName()))
{
caller.sendMessage(F.main("Party", "You cannot invite yourself!"));
return;
}
Player possible = Bukkit.getPlayerExact(target);
Party party = getPartyByPlayer(caller);
// preemptively create party - it might be a slight inconvenience but it saves a lot of untangling work
if (party == null)
{
UtilPlayer.message(caller, F.main("Party", "You don't seem to have a party, so I've created a new one for you!"));
party = new Party(caller);
_partiesById.put(party.getUniqueId(), party);
addToParty(caller, party);
}
if (!party.getOwnerName().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
if (party.getMembers().size() >= party.getSize())
{
Lang.PARTY_FULL.send(caller);
return;
}
if (possible != null && party.isMember(possible))
{
Lang.ALREADY_MEMBER.send(caller, target);
return;
}
if (getInviteManager().getInviteBySender(target, caller.getName()) != null)
{
Lang.ALREADY_INVITED.send(caller, target);
return;
}
if (possible != null && getPartyByPlayer(possible) != null)
{
Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target);
return;
}
//Same Server
if (possible != null)
{
if (!getPreferencesManager().get(possible).isActive(Preference.PARTY_REQUESTS))
{
caller.sendMessage(F.main("Party", F.name(target) + " is not accepting invites at this time."));
return;
}
Lang.SUCCESS_INVITE.send(party, caller.getName(), target);
Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName());
getInviteManager().inviteTo(possible.getName(), possible.getUniqueId(), caller.getName(), caller.getUniqueId(), party.getUniqueId(), getServerName());
getInviteManager().sendAcceptOrDeny(possible, caller.getName());
}
else
{
findAndInvite(caller, target, party);
}
}
/**
* Initiates inviting a player who is no on the same server
*/
private void findAndInvite(Player caller, String target, Party destParty)
{
Map<String, BukkitTask> pendingInvites = getRedisManager().getPendingFindResponse().computeIfAbsent(caller.getUniqueId(), key -> new HashMap<>());
if (!pendingInvites.containsKey(target))
{
caller.sendMessage(F.main("Party", "Attempting to invite " + F.elem(target) + "..."));
pendingInvites.put(target, runSyncLater(new BukkitRunnable()
{
@Override
public void run()
{
if (!pendingInvites.containsKey(target))
{
return;
}
pendingInvites.remove(target);
if (!caller.isOnline())
{
return;
}
Player targetPlayer = Bukkit.getPlayerExact(target);
if (targetPlayer != null)
{
UtilPlayer.message(caller, F.main("Party", "Huh. We couldn't find " + F.elem(target) + ", but it seems they've joined you in your server"));
return;
}
caller.sendMessage(F.main("Party", "Could not locate " + F.elem(target) + "."));
}
}, 20L * 5));
ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteCommand(caller, target, destParty));
}
else
{
caller.sendMessage(F.main("Party", "Please wait until the previous invite has completed"));
}
}
public Party getPendingParty(Player player)
{
UUID partyUUID = _pendingJoinMap.get(player.getUniqueId());
if (partyUUID == null) return null;
for (Party party : _partiesById.values())
{
if (party.getUniqueId().equals(partyUUID))
return party;
}
return null;
}
public boolean hasPendingJoin(Player player)
{
return _pendingJoinMap.containsKey(player.getUniqueId());
}
public void removePendingJoin(Player player)
{
_pendingJoinMap.remove(player.getUniqueId());
}
public void removePendingJoin(UUID player)
{
_pendingJoinMap.remove(player);
}
/**
* Kicks a player from the callers party
*
* @param caller The player who initiated the request
* @param target The player's target
*/
public void kickPlayer(Player caller, String target)
{
Party party = getPartyByPlayer(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
if (!party.isOwner(caller))
{
Lang.NOT_OWNER.send(caller);
return;
}
Player playerTarget = Bukkit.getPlayerExact(target);
if (playerTarget == null)
{
Lang.NOT_MEMBER.send(caller, target);
return;
}
if (!party.isMember(playerTarget))
{
Lang.NOT_MEMBER.send(caller, target);
return;
}
removeFromParty(playerTarget, PartyRemoveReason.KICKED);
}
public void addToParty(Player player, Party party)
{
_partiesByPlayer.put(player.getUniqueId(), party);
party.addMember(player);
}
/**
* 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 = getPartyByPlayer(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
removeFromParty(caller, PartyRemoveReason.LEFT);
Lang.LEFT.send(caller);
}
public void removeFromParty(Player player, PartyRemoveReason reason)
{
Party party = _partiesByPlayer.remove(player.getUniqueId());
if (party == null)
{
return;
}
if (player.getOpenInventory() != null)
{
if (Menu.get(player.getUniqueId()) != null)
{
player.closeInventory();
Menu.remove(player.getUniqueId());
}
}
switch (reason)
{
case KICKED:
Lang.REMOVE_PLAYER_KICK.send(party, player.getName());
break;
case LEFT:
Lang.REMOVE_PLAYER.send(party, player.getName());
break;
case OTHER:
break;
case DISBANDED:
break;
case DISBANDED_BY_OWNER:
break;
}
party.removeMember(player);
if (party.getMembers().size() == 0)
{
removeParty(party);
}
}
/**
* Disbands a player's current party
*
* @param caller The player who wishes to disband his party
*/
public void disband(Player caller)
{
Party party = getPartyByPlayer(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
if (!party.isOwner(caller))
{
Lang.NOT_OWNER.send(caller);
return;
}
caller.sendMessage(F.main("Party", "You have disbanded your party."));
Lang.DISBANDED_BY_OWNER.send(party);
removeParty(party);
}
public void removeParty(Party party)
{
_joinManager.removePendingJoin(party);
_partiesById.remove(party.getUniqueId());
_partiesByPlayer.entrySet().removeIf(ent -> ent.getValue().equals(party));
party.clear();
}
public void giveItemIfNotExists(Player player)
{
if (!UtilItem.isSimilar(player.getInventory().getItem(INTERFACE_SLOT), INTERFACE_ITEM, UtilItem.ItemAttribute.NAME, UtilItem.ItemAttribute.MATERIAL))
{
player.getInventory().setItem(PartyManager.INTERFACE_SLOT, PartyManager.INTERFACE_ITEM);
}
}
} }

View File

@ -0,0 +1,67 @@
package mineplex.core.party.command;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.command.cli.PartyAcceptCommand;
import mineplex.core.party.command.cli.PartyDenyCommand;
import mineplex.core.party.command.cli.PartyDisbandCommand;
import mineplex.core.party.command.cli.PartyHelpCommand;
import mineplex.core.party.command.cli.PartyInviteCommand;
import mineplex.core.party.command.cli.PartyInvitesCommand;
import mineplex.core.party.command.cli.PartyKickCommand;
import mineplex.core.party.command.cli.PartyLeaveCommand;
import mineplex.core.party.command.cli.PartyTransferOwnerCommand;
public class PartyCLICommand extends MultiCommandBase<PartyManager>
{
public PartyCLICommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "cli", "c");
AddCommand(new PartyAcceptCommand(plugin));
AddCommand(new PartyDenyCommand(plugin));
AddCommand(new PartyDisbandCommand(plugin));
AddCommand(new PartyInviteCommand(plugin));
AddCommand(new PartyInvitesCommand(plugin));
AddCommand(new PartyKickCommand(plugin));
AddCommand(new PartyLeaveCommand(plugin));
AddCommand(new PartyTransferOwnerCommand(plugin));
AddCommand(new PartyHelpCommand(plugin));
}
@Override
protected void Help(Player caller, String[] args)
{
Party party = Plugin.getPartyByPlayer(caller);
if (party == null)
{
UtilPlayer.message(caller, F.main("Party", "You're not in a party! Try " + F.elem("/party help") + "!"));
return;
}
if (party.getOwner().getId().equals(caller.getUniqueId()))
{
UtilPlayer.message(caller, F.main("Party", "You are in your own party!"));
}
else
{
UtilPlayer.message(caller, F.main("Party", "You are in " + F.elem(party.getOwnerName()) + "'s party!"));
}
if (party.getOwnerAsPlayer() == null)
{
UtilPlayer.message(caller, F.main("Party", "This party has no owner because " + F.elem(party.getOwnerName()) + " has not connected yet"));
}
String members = party.getMembers().stream().filter(p -> !p.getUniqueId().equals(party.getOwner().getId())).map(Player::getName).map(F::elem).collect(Collectors.joining(ChatColor.RESET + ", "));
UtilPlayer.message(caller, F.main("Party", "Members: " + members));
}
}

View File

@ -1,95 +1,54 @@
package mineplex.core.party.command; package mineplex.core.party.command;
import mineplex.core.command.CommandBase; import java.util.Arrays;
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.PartyInvitesMenu;
import mineplex.core.party.ui.menus.PartyMainMenu;
import mineplex.core.party.ui.menus.PartyOwnerMenu;
import mineplex.core.party.ui.menus.PartyViewMenu;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.Managers;
import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
/** /**
* Command handler for party commands * Command handler for party commands
*/ */
public class PartyCommand extends CommandBase<PartyManager> public class PartyCommand extends MultiCommandBase<PartyManager>
{ {
private final PreferencesManager _preferencesManager = Managers.require(PreferencesManager.class);
private final String[] HELP = {
F.main("Party", "Party Commands (Click the command!)"),
help("", "Brings up the Party GUI"),
help("<player>", "Send an invitation to a player."),
help("leave", "Leave your current party."),
C.cBlue + "Party> " + C.cWhite + "#<message> " + C.cGray + "- Send a message to your party.",
C.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) public PartyCommand(PartyManager plugin)
{ {
super(plugin, Rank.ALL, "party", "z", "partyaccept", "partydeny", "openinvitesmenu", "partyinvite"); super(plugin, Rank.ALL, "party", "z");
AddCommand(new PartyGuiCommand(plugin));
AddCommand(new PartyCLICommand(plugin));
AddCommand(new PartyToggleCommand(plugin));
} }
@Override @Override
public void Execute(Player caller, String[] args) protected void Help(Player caller, String[] args)
{ {
if (args.length == 0) if (args.length > 0)
{ {
if(_aliasUsed.equalsIgnoreCase("openinvitesmenu")) if (!args[0].equalsIgnoreCase("cli") && !args[0].equalsIgnoreCase("gui"))
{ {
new PartyInvitesMenu(Plugin).open(caller); String[] newArgs = new String[args.length + 1];
return; System.arraycopy(args, 0, newArgs, 1, args.length);
newArgs[0] = _preferencesManager.get(caller).isActive(Preference.PARTY_DISPLAY_INVENTORY_UI) ? "gui" : "cli";
args = newArgs;
} }
Party party = Plugin.getParty(caller);
if (party == null)
{
new PartyMainMenu(Plugin).open(caller);
return;
} }
if (party.getOwner().equalsIgnoreCase(caller.getName())) else
{ {
new PartyOwnerMenu(party, Plugin).open(caller); String[] newArgs = new String[1];
return; newArgs[0] = _preferencesManager.get(caller).isActive(Preference.PARTY_DISPLAY_INVENTORY_UI) ? "gui" : "cli";
args = newArgs;
}
Execute(caller, args);
} }
new PartyViewMenu(party, Plugin).open(caller);
return;
}
if(args.length == 1)
{
String arg = args[0];
if (_aliasUsed.equalsIgnoreCase("partyaccept"))
{
Plugin.getMethodManager().respondToInvite(caller, arg, true);
return;
}
if (_aliasUsed.equalsIgnoreCase("partydeny"))
{
Plugin.getMethodManager().respondToInvite(caller, arg, false);
return;
}
if(_aliasUsed.equalsIgnoreCase("partyinvite"))
{
Plugin.getMethodManager().invite(caller, arg);
return;
}
if(arg.equalsIgnoreCase("leave")) {
Plugin.getMethodManager().leaveParty(caller);
return;
}
Plugin.getMethodManager().invite(caller, arg);
return;
}
caller.sendMessage(HELP);
}
private String help(String command, String description)
{
return C.cBlue + "Party> " + C.cWhite + "/party " + command + C.cGray + " - " + description;
}
} }

View File

@ -0,0 +1,56 @@
package mineplex.core.party.command;
import org.bukkit.entity.Player;
import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.command.gui.PartyGUIAcceptInviteCommand;
import mineplex.core.party.command.gui.PartyGUIDenyInviteCommand;
import mineplex.core.party.command.gui.PartyGUIInviteCommand;
import mineplex.core.party.command.gui.PartyGUILeaveCommand;
import mineplex.core.party.command.gui.PartyOpenInviteMenuCommand;
import mineplex.core.party.ui.menus.PartyMainMenu;
import mineplex.core.party.ui.menus.PartyOwnerMenu;
import mineplex.core.party.ui.menus.PartyViewMenu;
public class PartyGuiCommand extends MultiCommandBase<PartyManager>
{
public PartyGuiCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "gui", "g");
AddCommand(new PartyOpenInviteMenuCommand(plugin));
AddCommand(new PartyGUIAcceptInviteCommand(plugin));
AddCommand(new PartyGUIDenyInviteCommand(plugin));
AddCommand(new PartyGUIInviteCommand(plugin));
AddCommand(new PartyGUILeaveCommand(plugin));
}
// a hacky method for a hacky original system
@Override
protected void Help(Player caller, String[] args)
{
if (args.length == 0)
{
Party party = Plugin.getPartyByPlayer(caller);
if (party == null)
{
new PartyMainMenu(Plugin).open(caller);
}
else if (party.getOwnerName().equalsIgnoreCase(caller.getName()))
{
new PartyOwnerMenu(party, Plugin).open(caller);
}
else
{
new PartyViewMenu(party, Plugin).open(caller);
}
}
else if (args.length == 1)
{
Plugin.invite(caller, args[0]);
}
}
}

View File

@ -0,0 +1,37 @@
package mineplex.core.party.command;
import org.bukkit.entity.Player;
import mineplex.core.Managers;
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.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
public class PartyToggleCommand extends CommandBase<PartyManager>
{
private final PreferencesManager _preferencesManager = Managers.require(PreferencesManager.class);
public PartyToggleCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "toggle", "t");
}
@Override
public void Execute(Player caller, String[] args)
{
_preferencesManager.get(caller).toggle(Preference.PARTY_DISPLAY_INVENTORY_UI);
if (_preferencesManager.get(caller).isActive(Preference.PARTY_DISPLAY_INVENTORY_UI))
{
UtilPlayer.message(caller, F.main("Party", "The Party GUI is now " + C.cGreen + "enabled" + C.mBody + "!"));
}
else
{
UtilPlayer.message(caller, F.main("Party", "The Party GUI is now " + C.cRed + "disabled" + C.mBody + "!"));
}
}
}

View File

@ -1,167 +0,0 @@
package mineplex.core.party.command;
import com.google.common.collect.Maps;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.game.GameDisplay;
import mineplex.core.party.Lang;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Map;
import java.util.UUID;
/**
* Unused for now.
*/
public class TeamPreferenceCommand extends CommandBase<PartyManager>
{
private static final String[] ARGS = {
"teampref",
"teamprefs",
"teamp",
"tprefs",
"teampreferences"
};
private final String ACCEPT = "accept";
private final String DENY = "deny";
private final String ACCEPT_COMMAND = "/teamprefs accept ";
private final String DENY_COMMAND = "/teamprefs deny ";
private final String HEADER = "Partners";
//Player, Partner, GameName
private Map<UUID, Map<String, String>> INVITES = Maps.newHashMap();
public TeamPreferenceCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, ARGS);
}
@Override
public void Execute(Player player, String[] args)
{
if (args.length < 2)
{
Lang.PARTNER_USAGE.sendHeader(player, HEADER);
return;
}
String arg = args[0];
if (arg.equalsIgnoreCase(ACCEPT) || arg.equalsIgnoreCase(DENY))
{
Party party = Plugin.getParty(player);
if (party == null)
{
Lang.NO_PARTY.send(player);
return;
}
String inviter = args[1];
boolean accept = arg.equalsIgnoreCase(ACCEPT);
Player inviterPlayer = Bukkit.getPlayerExact(inviter);
if (inviterPlayer == null)
{
Lang.PARTNER_NOT_ONLINE.sendHeader(player, HEADER, inviter);
return;
}
Map<String, String> sent = INVITES.get(inviterPlayer.getUniqueId());
if (sent == null || sent.isEmpty())
{
Lang.PARTNER_PLAYER_NOT_REQUESTED.sendHeader(player, HEADER, inviter);
return;
}
if (sent.get(player.getName()) == null)
{
Lang.PARTNER_PLAYER_NOT_REQUESTED.sendHeader(player, HEADER, inviter);
return;
}
String gameName = sent.remove(player.getName());
if (!accept)
{
Lang.PARTNER_REQUEST_DENIED_PLAYER.send(player, inviterPlayer.getName(), gameName);
Lang.PARTNER_REQUEST_DENIED_SENDER.send(inviterPlayer, player.getName(), gameName);
return;
}
Lang.PARTNER_REQUEST_ACCEPT_PLAYER.send(player, inviterPlayer.getName(), gameName);
Lang.PARTNER_REQUEST_ACCEPT_SENDER.send(inviterPlayer, player.getName(), gameName);
party.setPartner(player, gameName, inviterPlayer.getName());
party.setPartner(inviterPlayer, gameName, player.getName());
return;
}
Player target = Bukkit.getPlayerExact(arg);
String gameName = "";
String[] game = new String[args.length - 2];
System.arraycopy(args, 2, game, 0, game.length);
for (String s : game)
{
gameName += s + " ";
}
gameName = gameName.trim();
GameDisplay gameDisplay = GameDisplay.matchName(gameName);
if (gameDisplay == null)
{
Lang.PARTNER_NO_GAME.sendHeader(player, HEADER, gameName);
return;
}
gameName = gameDisplay.getName();
if (alreadyInvited(player, gameName, target.getName()))
{
Lang.PARTNER_ALREADY_INVITED.sendHeader(player, HEADER, target.getName(), gameName);
return;
}
sendRequest(player, gameName, target);
}
private void sendRequest(Player player, String game, Player partner)
{
invite(player, game, partner);
String gameName = C.cGreen + (game);
String playerName = C.cGreen + (player.getName());
String partnerName = C.cGreen + (partner.getName());
String acceptCommand = ACCEPT_COMMAND + player.getName();
String declineCommand = DENY_COMMAND + player.getName();
String acceptText = Lang.PARTNER_HOVER_TEXT_ACCEPT.toString(playerName, gameName);
String declineText = Lang.PARTNER_HOVER_TEXT_DENY.toString(playerName, gameName);
Lang.PARTNER_REQUEST_SENT.sendHeader(player, HEADER, partnerName, gameName);
Lang.PARTNER_REQUEST_RECEIVED.sendHeader(partner, HEADER, playerName, gameName);
UtilPlayer.sendAcceptOrDeny(partner, HEADER, acceptCommand, acceptText, declineCommand, declineText, null, null);
}
private boolean alreadyInvited(Player player, String game, String partner)
{
Map<String, String> sent = INVITES.get(player.getUniqueId());
return !(sent == null || sent.isEmpty()) && sent.get(partner).equalsIgnoreCase(game);
}
private void invite(Player player, String game, Player partner)
{
Map<String, String> sent = INVITES.getOrDefault(player.getUniqueId(), Maps.newHashMap());
sent.put(partner.getName(), game);
INVITES.put(player.getUniqueId(), sent);
}
}

View File

@ -0,0 +1,30 @@
package mineplex.core.party.command.cli;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
public class PartyAcceptCommand extends CommandBase<PartyManager>
{
public PartyAcceptCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "accept", "a");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main("Party", "Oops. You didn't specify whose invite you're accepting!"));
return;
}
Plugin.acceptInviteBySender(caller, args[0]);
}
}

View File

@ -0,0 +1,21 @@
package mineplex.core.party.command.cli;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.party.PartyManager;
public class PartyBlockCommand extends CommandBase<PartyManager>
{
public PartyBlockCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "block", "b");
}
@Override
public void Execute(Player caller, String[] args)
{
}
}

View File

@ -0,0 +1,28 @@
package mineplex.core.party.command.cli;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
public class PartyDenyCommand extends CommandBase<PartyManager>
{
public PartyDenyCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "deny", "d");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main("Party", "Oops. You didn't specify whose invite you're denying!"));
return;
}
Plugin.denyInviteBySender(caller, args[0]);
}
}

View File

@ -0,0 +1,21 @@
package mineplex.core.party.command.cli;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.party.PartyManager;
public class PartyDisbandCommand extends CommandBase<PartyManager>
{
public PartyDisbandCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "disband", "db");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.disband(caller);
}
}

View File

@ -0,0 +1,34 @@
package mineplex.core.party.command.cli;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
public class PartyHelpCommand extends CommandBase<PartyManager>
{
public PartyHelpCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "help", "h");
}
@Override
public void Execute(Player caller, String[] args)
{
UtilPlayer.message(caller, F.main("Party", "Parties Help"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [help/h]") + " - Shows this help dialog"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [invite/i] [player]") + " - Invite [player] to your party"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [invites/is] (page)") + " - List your current pending invitations"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [kick/k] [player]") + " - Kick [player] from your party"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [accept/a] [player]") + " - Accept your invitation to [player]'s party"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [deny/d] [player]") + " - Deny your invitation to [player]'s party"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [leave/l]") + " - Leave your current party"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [disband/db]") + " - Disband your current party"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [transfer/tr] [player]") + " - Transfers ownership of the party to another player"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [gui/g]") + " - Opens the party GUI"));
UtilPlayer.message(caller, F.main("Party", F.elem("/party [toggle/t]") + " - Toggles between the GUI and the chat"));
}
}

View File

@ -0,0 +1,28 @@
package mineplex.core.party.command.cli;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
public class PartyInviteCommand extends CommandBase<PartyManager>
{
public PartyInviteCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "invite", "i");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main("Party", "Oops. You didn't specify who to invite!"));
return;
}
Plugin.invite(caller, args[0]);
}
}

View File

@ -0,0 +1,198 @@
package mineplex.core.party.command.cli;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;
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.common.util.UtilPlayer;
import mineplex.core.party.InviteData;
import mineplex.core.party.PartyManager;
public class PartyInvitesCommand extends CommandBase<PartyManager>
{
private static int boostCount = 0;
public PartyInvitesCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "invites", "is");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 2 && args[0].equals("boost"))
{
boostCount = Integer.parseInt(args[1]);
return;
}
List<InviteData> invites = Plugin.getInviteManager().getAllInvites(caller);
invites.sort(Comparator.comparing(InviteData::getInviterName));
if (boostCount != 0)
{
invites = new ArrayList<>();
for (int i = 0; i < boostCount; i++)
{
invites.add(new InviteData("Player" + i, UUID.randomUUID(), UUID.randomUUID(), "Server" + i));
}
}
if (invites == null || invites.isEmpty())
{
UtilPlayer.message(caller, F.main("Party", "You have no pending invites!"));
return;
}
int totalPages = (int) Math.ceil(invites.size() / 8.0);
int page = 0;
if (args.length != 0)
{
try
{
page = Integer.parseInt(args[0]);
}
catch (NumberFormatException ex)
{
UtilPlayer.message(caller, F.main("Party", F.elem(args[0]) + " is not a number!"));
return;
}
page = page - 1;
if (page < 0)
{
UtilPlayer.message(caller, F.main("Party", "Page numbers must be greater than zero!"));
return;
}
else if (page >= totalPages)
{
UtilPlayer.message(caller, F.main("Party", "You only have " + F.elem(totalPages) + " pages of invites, that number is too big!"));
return;
}
}
String header = "[" +
ChatColor.RESET + C.cWhite + C.Bold + "Party Invites (" + (page + 1) + "/" + totalPages + ")" +
ChatColor.RESET + C.cAqua + C.Strike + "]";
int headerChars = ChatColor.stripColor(header).length();
int numEqualsInHeader = (50 - headerChars) / 2;
header = C.cAqua + C.Strike + StringUtils.repeat("=", numEqualsInHeader) + header + StringUtils.repeat("=", numEqualsInHeader);
caller.sendMessage(header);
int start = page * 8;
List<InviteData> subList = start < invites.size() ? invites.subList(start, Math.min(invites.size(), start + 8)) : Collections.emptyList();
for (InviteData data : subList)
{
BaseComponent[] hover = new ComponentBuilder("")
.append("Server: ")
.color(ChatColor.YELLOW)
.append(data.getServerName(), ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.WHITE)
.create();
ComponentBuilder builder = new ComponentBuilder("")
.append("Accept")
.color(ChatColor.GREEN)
.bold(true)
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/party cli a " + data.getInviterName()))
.append(" - ", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.WHITE)
.append("Deny")
.color(ChatColor.RED)
.bold(true)
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/party cli d " + data.getInviterName()))
.append(" - ", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.WHITE)
.append(data.getInviterName() + " invited you to their party")
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))
.color(ChatColor.GRAY);
caller.spigot().sendMessage(builder.create());
}
int chars = ChatColor.stripColor(header).length();
int numEquals = (chars - 5) / 2; // 5 chars: " < > "
ComponentBuilder pageSwitch = new ComponentBuilder("")
.append(StringUtils.repeat("=", numEquals) + "[")
.strikethrough(true)
.color(ChatColor.AQUA)
.append(" ", ComponentBuilder.FormatRetention.NONE)
.append("<", ComponentBuilder.FormatRetention.NONE)
.bold(true);
if (page > 0)
{
BaseComponent[] prev = new ComponentBuilder("")
.append("Go to page " + page)
.color(ChatColor.GREEN)
.create();
pageSwitch
.color(ChatColor.GREEN)
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/party is " + (page)))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, prev));
}
else
{
pageSwitch
.color(ChatColor.GRAY);
}
pageSwitch.append(" ", ComponentBuilder.FormatRetention.NONE)
.append(">", ComponentBuilder.FormatRetention.NONE)
.bold(true);
if (page + 1 < totalPages)
{
BaseComponent[] next = new ComponentBuilder("")
.append("Go to page " + (page + 2))
.color(ChatColor.GREEN)
.create();
pageSwitch
.color(ChatColor.GREEN)
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/party is " + (page + 2)))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, next));
}
else
{
pageSwitch
.color(ChatColor.GRAY);
}
pageSwitch
.append(" ", ComponentBuilder.FormatRetention.NONE)
.append("]" + StringUtils.repeat("=", numEquals), ComponentBuilder.FormatRetention.NONE)
.strikethrough(true)
.color(ChatColor.AQUA);
caller.spigot().sendMessage(pageSwitch.create());
}
}

View File

@ -0,0 +1,29 @@
package mineplex.core.party.command.cli;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
public class PartyKickCommand extends CommandBase<PartyManager>
{
public PartyKickCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "kick", "k");
}
@Override
public void Execute(Player caller, String[] args)
{
Party party = Plugin.getPartyByPlayer(caller);
if (party != null)
{
if (party.getOwnerName().equals(caller.getName()))
{
Plugin.kickPlayer(caller, args[0]);
}
}
}
}

View File

@ -0,0 +1,21 @@
package mineplex.core.party.command.cli;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.party.PartyManager;
public class PartyLeaveCommand extends CommandBase<PartyManager>
{
public PartyLeaveCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "leave", "l");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.leaveParty(caller);
}
}

View File

@ -0,0 +1,60 @@
package mineplex.core.party.command.cli;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.Lang;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
public class PartyTransferOwnerCommand extends CommandBase<PartyManager>
{
public PartyTransferOwnerCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "transfer", "tr");
}
@Override
public void Execute(Player caller, String[] args)
{
Party playerParty = Plugin.getPartyByPlayer(caller);
if (playerParty == null)
{
UtilPlayer.message(caller, F.main("Party", "Oops. You're not in a party!"));
return;
}
if (!playerParty.getOwner().getId().equals(caller.getUniqueId()))
{
UtilPlayer.message(caller, F.main("Party", "Oops. You're not the owner of the party!"));
return;
}
if (args.length == 0)
{
UtilPlayer.message(caller, F.main("Party", "Oops. You didn't specify who you're transferring the party to!"));
return;
}
Player player = Bukkit.getPlayer(args[0]);
if (player == null)
{
UtilPlayer.message(caller, F.main("Party", "Could not find " + F.elem(args[0]) + "!"));
return;
}
if (!playerParty.isMember(player))
{
UtilPlayer.message(caller, F.main("Party", "Oops. " + F.elem(player.getName())+ " is not in your party!"));
return;
}
playerParty.setOwner(player);
Lang.TRANSFER_OWNER.send(playerParty, caller.getName(), player.getName());
}
}

View File

@ -0,0 +1,29 @@
package mineplex.core.party.command.gui;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
public class PartyGUIAcceptInviteCommand extends CommandBase<PartyManager>
{
public PartyGUIAcceptInviteCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "partyaccept", "accept", "a");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main("Party", "Oops. You didn't specify whose invite you're accepting!"));
return;
}
Plugin.acceptInviteBySender(caller, args[0]);
}
}

View File

@ -0,0 +1,28 @@
package mineplex.core.party.command.gui;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
public class PartyGUIDenyInviteCommand extends CommandBase<PartyManager>
{
public PartyGUIDenyInviteCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "partydeny", "deny", "d");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main("Party", "Oops. You didn't specify whose invite you're denying!"));
return;
}
Plugin.denyInviteBySender(caller, args[0]);
}
}

View File

@ -0,0 +1,28 @@
package mineplex.core.party.command.gui;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
public class PartyGUIInviteCommand extends CommandBase<PartyManager>
{
public PartyGUIInviteCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "partyinvite", "invite", "i");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main("Party", "Oops. You didn't specify who to invite!"));
return;
}
Plugin.invite(caller, args[0]);
}
}

View File

@ -0,0 +1,23 @@
package mineplex.core.party.command.gui;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.PartyManager;
public class PartyGUILeaveCommand extends CommandBase<PartyManager>
{
public PartyGUILeaveCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "leave", "l");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.leaveParty(caller);
}
}

View File

@ -0,0 +1,22 @@
package mineplex.core.party.command.gui;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.menus.PartyInvitesMenu;
public class PartyOpenInviteMenuCommand extends CommandBase<PartyManager>
{
public PartyOpenInviteMenuCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, "openinvitesmenu", "invitesmenu", "im", "invites", "is");
}
@Override
public void Execute(Player caller, String[] args)
{
new PartyInvitesMenu(Plugin).open(caller);
}
}

View File

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

View File

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

View File

@ -1,37 +0,0 @@
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;
}
}

View File

@ -1,51 +0,0 @@
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;
}
}

View File

@ -1,44 +0,0 @@
package mineplex.core.party.event;
import mineplex.core.party.Party;
import mineplex.serverdata.data.MinecraftServer;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
*
*/
public class PartySendToServerEvent extends Event
{
private static final HandlerList HANDLER_LIST = new HandlerList();
private final Party _party;
private final MinecraftServer _minecraftServer;
public PartySendToServerEvent(Party party, MinecraftServer minecraftServer)
{
_party = party;
_minecraftServer = minecraftServer;
}
public Party getParty()
{
return _party;
}
@Override
public HandlerList getHandlers()
{
return HANDLER_LIST;
}
public static HandlerList getHandlerList()
{
return HANDLER_LIST;
}
public MinecraftServer getMinecraftServer()
{
return _minecraftServer;
}
}

View File

@ -1,65 +0,0 @@
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;
}
}

View File

@ -1,358 +1,213 @@
package mineplex.core.party.manager; package mineplex.core.party.manager;
import com.google.common.collect.Lists; import java.util.ArrayList;
import com.google.common.collect.Maps; import java.util.Collections;
import mineplex.core.common.Rank; import java.util.HashMap;
import mineplex.core.common.util.C; import java.util.HashSet;
import mineplex.core.common.util.F; import java.util.Iterator;
import mineplex.core.party.InviteData; import java.util.LinkedHashMap;
import mineplex.core.party.Lang; import java.util.List;
import mineplex.core.party.Party; import java.util.Map;
import mineplex.core.party.PartyManager; import java.util.Set;
import mineplex.core.party.constants.InviteResponse; import java.util.UUID;
import mineplex.core.party.redis.RedisMessageType; import java.util.stream.Collectors;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ClickEvent.Action; import net.md_5.bungee.api.chat.ClickEvent.Action;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.spigotmc.CaseInsensitiveMap;
import java.util.Collection; import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map; import mineplex.core.common.util.F;
import java.util.UUID; import mineplex.core.party.InviteData;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
/** /**
* * This class manages invites to parties
*/ */
public class PartyInviteManager public class PartyInviteManager
{ {
// Map of Player Name (invitee) to invites (inviter)
private final Map<String, Set<InviteData>> _activeInvites = new CaseInsensitiveMap<>();
private final Map<UUID, List<InviteData>> _activeInvites = Maps.newHashMap(); private final Map<UUID, BukkitTask> _tasks = new HashMap<>();
private final Map<UUID, String> _invitedBy = Maps.newHashMap();
private final Map<UUID, String> _awaitingJoin = Maps.newHashMap();
private final Map<UUID, String> _players = Maps.newHashMap();
private final Map<UUID, BukkitTask> _tasks = Maps.newHashMap();
private final PartyManager _plugin; private final PartyManager _plugin;
private final PartyRedisManager _partyRedisManager;
public PartyInviteManager(PartyManager plugin, PartyRedisManager partyRedisManager) public PartyInviteManager(PartyManager plugin)
{ {
_plugin = plugin; _plugin = plugin;
_partyRedisManager = partyRedisManager; }
public InviteData getInviteBySender(String invitee, String sender)
{
Set<InviteData> map = _activeInvites.get(invitee);
if (map == null) return null;
for (InviteData inviteData : map)
{
if (inviteData.getInviterName().equalsIgnoreCase(sender))
{
return inviteData;
}
}
return null;
} }
/** /**
* Responds to an invite, regardless of the server * Checks if a caller has an invite by a sender's name
* * @param caller
* @param player The player calling * @param sender
* @param party The party * @return
* @param accept Whether or not the player accepted the invite
*/ */
public void respondToInvite(Player player, String party, boolean accept) public boolean hasInviteFrom(Player caller, String sender)
{ {
Player possible = Bukkit.getPlayerExact(party); return getInviteBySender(caller.getName(), sender) != null;
InviteData data = remove(party, player.getUniqueId());
_players.remove(player.getUniqueId());
cancelTask(player.getUniqueId());
if(possible != null)
{
Party newParty = _plugin.getParty(party);
if(!accept)
{
String message = C.mHead + "Party> " + C.mBody + InviteResponse.DENIED.format(player.getName());
if (newParty == null)
{
possible.sendMessage(message);
return;
}
newParty.sendMessage(message);
return;
}
if (newParty == null)
{
newParty = new Party(possible.getName());
if(_plugin.getClientManager().Get(possible).GetRank().has(Rank.ULTRA))
{
newParty.setSize();
} else
{
newParty.setSize();
}
_plugin.addParty(newParty);
_plugin.getMethodManager().addToParty(possible.getUniqueId(), newParty);
}
_plugin.getMethodManager().addToParty(player.getUniqueId(), newParty);
return;
}
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());
} }
/** /**
* Handles a received response via redis * Checks if a caller has an invite by a party id
* * @param caller
* @param sender The player sending the request * @param partyId
* @param target The player target * @return
* @param serverFrom The server initiating the request
*/ */
public void handleInviteRequest(String sender, String target, String serverFrom) public boolean hasInviteTo(String caller, UUID partyId)
{ {
Player player = Bukkit.getPlayerExact(target); Set<InviteData> map = _activeInvites.get(caller);
if (player == null)
if (map == null) return false;
for (InviteData inviteData : map)
{ {
//Shouldn't happen, as a "findPLayer" packet will be sent out first. if (inviteData.getPartyUUID().equals(partyId))
return; {
return true;
} }
_players.put(player.getUniqueId(), player.getName()); }
inviteTo(player.getUniqueId(), sender, sender, serverFrom);
Lang.INVITE_RECEIVED.send(player, sender); return false;
sendAcceptOrDeny(player, sender);
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
} }
/** /**
* Handles the response returned via redis when an invite is handled cross server * Remove a player's invite to a party by id
* * @param caller
* @param sender The player sender * @param partyId
* @param target The player target * @return
* @param targetUUID The player targets UUID
* @param response The response to this invite
*/ */
public void handleInviteResponse(String sender, String target, UUID targetUUID, InviteResponse response) public InviteData removeInviteTo(String caller, UUID partyId)
{ {
remove(sender, targetUUID); Set<InviteData> map = _activeInvites.get(caller);
Player player = Bukkit.getPlayer(sender);
if (player == null)
{
return;
}
String message = F.main("Party", response.format(target));
Party party = _plugin.getParty(sender); if (map == null) return null;
String partyName = sender;
if(party != null) Iterator<InviteData> itr = map.iterator();
while (itr.hasNext())
{ {
partyName = party.getName(); InviteData ent = itr.next();
if (ent.getPartyUUID().equals(partyId))
{
itr.remove();
return ent;
}
} }
switch (response) return null;
{
case ACCEPTED:
addToPendingJoin(targetUUID, partyName);
break;
case EXPIRED:
case DENIED:
if (party == null)
{
player.sendMessage(message);
return;
} }
party.sendMessage(message);
break; /**
* Remove a player's invite to a certain party
*/
public InviteData removeInvite(Player invitee, String inviter)
{
Set<InviteData> map = _activeInvites.get(invitee.getName());
if (map == null) return null;
Iterator<InviteData> itr = map.iterator();
while (itr.hasNext())
{
InviteData ent = itr.next();
if (ent.getInviterName().equalsIgnoreCase(inviter))
{
itr.remove();
return ent;
} }
} }
return null;
}
/** /**
* Remove all references tied with this player * Remove all references tied with this player
* *
* @param player The player's UUID * @param player The player's UUID
*/ */
public void removeAll(UUID player) public void removeAll(Player player)
{ {
_players.remove(player); _activeInvites.remove(player.getName());
_invitedBy.remove(player);
_activeInvites.remove(player);
}
/**
* 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);
}
/**
* Remove the party reference that invited this player
*
* @param player The player's UUID
*/
public void removeFromWaiting(UUID player)
{
_awaitingJoin.remove(player);
}
/**
* 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, String server)
{
addToInvite(player, invitedBy, party, server);
_tasks.put(player, new BukkitRunnable()
{
@Override
public void run()
{
if (!isInvitedTo(player, party))
{
cancel();
return;
}
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 " + F.name(party) + "'s party has expired"));
}
sendExpired(data.getServerFrom(), party, playerName, 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 <code>true</code> if the player has an invite to the specific party
*/
public boolean isInvitedTo(UUID player, String party)
{
if (!_activeInvites.containsKey(player))
{
return false;
}
List<InviteData> 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 InviteData remove(String party, UUID invited)
{
List<InviteData> 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);
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);
if(task != null)
{
task.cancel();
}
} }
/** /**
* Retrieves all invites currently pending for a specific player * Retrieves all invites currently pending for a specific player
*
* @param player The player * @param player The player
* @return All his current pending invites * @return All his current pending invites
*/ */
public Collection<InviteData> getAllInvites(Player player) public List<InviteData> getAllInvites(Player player)
{ {
return _activeInvites.get(player.getUniqueId()); return new ArrayList<>(_activeInvites.getOrDefault(player.getName(), Collections.emptySet()));
} }
/** /**
* Send an "ExpiredPartyInvite" redis message * Add a playerUUID to the active invites map
* *
* @param server The server to * @param inviterName
* @param party The party who initiated the request (can also be a player's name) * @param inviterUUID
* @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) public void inviteTo(String targetName, UUID targetUUID, String inviterName, UUID inviterUUID, UUID partyId, String server)
{ {
_plugin.getRedisManager().publish(server, RedisMessageType.INVITE_PLAYER_RESPONSE, party, playerName, player.toString(), InviteResponse.EXPIRED.name()); Set<InviteData> map = _activeInvites.computeIfAbsent(targetName, key -> new HashSet<>());
} InviteData inviteData = new InviteData(inviterName, inviterUUID, partyId, server);
/** if (map.add(inviteData))
* 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); _tasks.put(targetUUID, _plugin.runSyncLater(new BukkitRunnable()
{
@Override
public void run()
{
if (!hasInviteTo(targetName, partyId))
{
cancel();
return;
} }
InviteData data = removeInviteTo(targetName, partyId);
/** Player possible = Bukkit.getPlayer(targetUUID);
* Add a pending invite for a player if (possible != null)
*
* @param invited The invited players UUUD
* @param invitedBy The person who invited him
* @param party The name of the party invited to
* @param server The server the request is from
*/
private void addToInvite(UUID invited, String invitedBy, String party, String server)
{ {
List<InviteData> inviteDatas = _activeInvites.get(invited); Party curParty = _plugin.getPartyByPlayer(possible);
if (inviteDatas == null) if (curParty != null && !curParty.getUniqueId().equals(data.getPartyUUID()))
{ {
inviteDatas = Lists.newArrayList(); possible.sendMessage(F.main("Party", "Your invite to " + F.name(inviterName) + "'s party has expired"));
}
}
}
}, 20 * 60));
} }
InviteData inviteData = new InviteData(party, server);
inviteDatas.add(inviteData);
_invitedBy.put(invited, invitedBy);
_activeInvites.put(invited, inviteDatas);
} }
/** /**
@ -368,7 +223,7 @@ public class PartyInviteManager
TextComponent accept = new TextComponent("ACCEPT"); TextComponent accept = new TextComponent("ACCEPT");
accept.setColor(ChatColor.GREEN); accept.setColor(ChatColor.GREEN);
accept.setBold(true); accept.setBold(true);
accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/partyaccept " + arg)); accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party cli a " + arg));
accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent("Click to join " + F.name(arg) + "'s party") new TextComponent("Click to join " + F.name(arg) + "'s party")
})); }));
@ -379,7 +234,7 @@ public class PartyInviteManager
TextComponent deny = new TextComponent("DENY"); TextComponent deny = new TextComponent("DENY");
deny.setColor(ChatColor.RED); deny.setColor(ChatColor.RED);
deny.setBold(true); deny.setBold(true);
deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/partydeny " + arg)); deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party cli d " + arg));
deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent("Click to decline joining " + F.name(arg) + "'s party") new TextComponent("Click to decline joining " + F.name(arg) + "'s party")
})); }));
@ -390,7 +245,7 @@ public class PartyInviteManager
TextComponent view = new TextComponent("VIEW"); TextComponent view = new TextComponent("VIEW");
view.setColor(ChatColor.YELLOW); view.setColor(ChatColor.YELLOW);
view.setBold(true); view.setBold(true);
view.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/openinvitesmenu")); view.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party is"));
view.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ view.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent("Click to view all pending invites.") new TextComponent("Click to view all pending invites.")
})); }));
@ -398,5 +253,6 @@ public class PartyInviteManager
textComponent.addExtra(view); textComponent.addExtra(view);
player.spigot().sendMessage(textComponent); player.spigot().sendMessage(textComponent);
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F);
} }
} }

View File

@ -1,57 +1,140 @@
package mineplex.core.party.manager; package mineplex.core.party.manager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitTask;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import mineplex.core.command.CommandCenter;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.JoinResponseReason; import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.redis.RedisMessageType; import mineplex.core.party.rediscommands.PartyTransferRequest;
import mineplex.serverdata.servers.ServerManager; import mineplex.core.party.rediscommands.PartyTransferResponse;
import org.bukkit.Bukkit; import mineplex.core.portal.Intent;
import org.bukkit.entity.Player; import mineplex.core.portal.events.GenericServerTransferEvent;
import mineplex.core.portal.events.ServerTransferEvent;
import java.util.List; import mineplex.core.utils.UtilGameProfile;
import java.util.UUID; import mineplex.serverdata.commands.ServerCommandManager;
import java.util.stream.Collectors; import mineplex.serverdata.data.MinecraftServer;
/** /**
* Manages allocating slots for parties to join * Manages allocating slots for parties to join
*/ */
public class PartyJoinManager public class PartyJoinManager implements Listener
{ {
private final PartyManager _plugin; private final PartyManager _plugin;
private final int _maxPLayers; private final int _maxPlayers;
private final List<UUID> _transferring;
private final Map<UUID, BukkitTask> _pendingTransfers = new ConcurrentHashMap<>();
public PartyJoinManager(PartyManager plugin) public PartyJoinManager(PartyManager plugin)
{ {
_plugin = plugin; _plugin = plugin;
_maxPLayers = plugin.getPlugin().getServer().getMaxPlayers(); _maxPlayers = plugin.getPlugin().getServer().getMaxPlayers();
_transferring = Lists.newArrayList();
UtilServer.RegisterEvents(this);
ServerCommandManager.getInstance().registerCommandType(PartyTransferRequest.class, command ->
{
if (!command.isSentToThisServer())
return;
_plugin.runSync(() ->
{
int currentPlayers = UtilServer.getPlayersCollection().size();
if (currentPlayers + command.getUnrankedMembers().size() > _maxPlayers && !command.isCanJoinFullServers())
{
ServerCommandManager.getInstance().publishCommand(new PartyTransferResponse(command, PartyTransferResponse.Result.NOT_ENOUGH_ROOM));
return;
} }
/** for (UUID uuid : command.getUnrankedMembers())
* Scans through the party to check if all players are some form of VIP
* If the party contains even 1 non-vip, the party cannot be sent to a full server
*
* @param party The party
* @return <code>true</code> if the party contains all VIP's <code>false</code> if it contains even 1 non-vip
*/
public boolean canJoinFullServer(Party party)
{ {
List<Player> players = party.getMembersByUUID().stream().map(Bukkit::getPlayer).collect(Collectors.toList()); _plugin.getClientManager().reserveFor(uuid);
for (Player player : players)
{
Rank rank = _plugin.getClientManager().Get(player).GetRank();
if (rank == Rank.ALL)
{
return false;
} }
Party newParty = new Party(command);
_plugin.addParty(newParty);
for (UUID uuid : command.getAllMembers())
{
_plugin.putIntoPendingJoin(uuid, newParty.getUniqueId());
} }
return true;
ServerCommandManager.getInstance().publishCommand(new PartyTransferResponse(command, PartyTransferResponse.Result.SUCCESS));
});
});
ServerCommandManager.getInstance().registerCommandType(PartyTransferResponse.class, command ->
{
if (!command.getOrigin().wasSentFromThisServer())
return;
_plugin.runSync(() ->
{
BukkitTask task = _pendingTransfers.get(command.getOrigin().getPartyUUID());
if (task == null)
{
return;
}
task.cancel();
Party party = _plugin.getPartyById(command.getOrigin().getPartyUUID());
switch (command.getResult())
{
case NOT_ENOUGH_ROOM:
_pendingTransfers.remove(command.getOrigin().getPartyUUID());
party.sendMessage(F.main("Party", "Sorry, there wasn't enough room for your party in " + F.elem(command.getFromServer()) + "."));
break;
case SUCCESS:
party.sendMessage(F.main("Party", "Success! I've reserved some room for you in " + F.elem(command.getFromServer()) + "."));
party.sendMessage(F.main("Party", "You will be transferred shortly."));
List<Player> members = new ArrayList<>(party.getMembers());
// Clear the party first.
// We've already got a duplicate on the remote server so let's get rid of this one ASAP
party.clear();
_plugin.removeParty(party);
for (Player player : members)
{
_plugin.getPortal().sendPlayer(player, command.getFromServer());
}
break;
case UNKNOWN:
_pendingTransfers.remove(command.getOrigin().getPartyUUID());
party.sendMessage(F.main("Party", "Uh... something went wrong?"));
break;
}
});
});
} }
/** /**
@ -60,78 +143,214 @@ public class PartyJoinManager
* @param server The desired server * @param server The desired server
* @param party The requesting party * @param party The requesting party
*/ */
public void requestServerJoin(String server, Party party) private void requestServerJoin(String server, Party party)
{ {
boolean canJoinFull = canJoinFullServer(party); if (_pendingTransfers.containsKey(party.getUniqueId()))
_plugin.getRedisManager().publish(server, RedisMessageType.PREJOIN_SERVER_REQUEST,
_plugin.getServerName(), party.getOwner(), "" + party.getMembers().size(), "" + canJoinFull);
}
/**
* Manages a received request
*
* @param serverFrom The server who initiated the request
* @param partySize The size of the party
* @param initiator The player who sent the request
* @param canJoinFull <code>true</code> if the party contains all donators or staff (full joining able players)
*/
public void handleJoinRequest(String serverFrom, int partySize, String initiator, boolean canJoinFull)
{ {
int currentPlayers = UtilServer.getPlayers().length; party.sendMessage(F.main("Party", "Please wait until your current transfer is complete"));
if (currentPlayers >= _maxPLayers || (currentPlayers + partySize) >= _maxPLayers)
{
//Max number of people on.
if (!canJoinFull)
{
_plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), _plugin.getServerName());
return; return;
} }
}
ServerManager.getServerRepository(_plugin.getRegion()).getServerStatus(_plugin.getServerName()).incrementPlayerCount(partySize);
_plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), _plugin.getServerName());
} List<UUID> unranked = new ArrayList<>();
List<UUID> all = new ArrayList<>();
/** for (Player player : party.getMembers())
* Manages a received response
*
* @param playerSender The player who sent the request
* @param server The server responding
* @param reason The reason for the response
*/
public void handleJoinResponse(String playerSender, String server, JoinResponseReason reason)
{ {
Player player = Bukkit.getPlayer(playerSender); if (_plugin.getClientManager().Get(player).GetRank() == Rank.ALL)
if (player == null) {
unranked.add(player.getUniqueId());
}
all.add(player.getUniqueId());
}
_pendingTransfers.put(party.getUniqueId(), _plugin.runSyncLater(() ->
{
_pendingTransfers.remove(party.getUniqueId());
if (party.getMembers().size() == 0)
{ {
return; return;
} }
Party party = _plugin.getParty(player);
party.sendMessage(F.main("Party", "Aww, the destination server didn't respond :("));
}, 20 * 5L));
System.out.println("Sending transfer request to " + server + " for " + party.getUniqueId() + " " + party.getMembers());
party.sendMessage(F.main("Party", "Please wait while I check whether " + F.elem(server) + " has enough room for this party."));
ServerCommandManager.getInstance().publishCommand(new PartyTransferRequest(party.getUniqueId(), UtilGameProfile.getGameProfile(party.getOwnerAsPlayer().get()), all, unranked, unranked.size() == 0, server));
}
@EventHandler
public void onTransferToGenericServer(GenericServerTransferEvent event)
{
Player player = event.getPlayer();
Party party = _plugin.getPartyByPlayer(player);
if (party == null) if (party == null)
{ {
return; return;
} }
if (reason != JoinResponseReason.SUCCESS)
// If the server wants to kick the player, let's not stop it
if (event.getIntent() == Intent.KICK || event.getIntent() == Intent.FORCE_TRANSFER)
{ {
party.sendMessage(reason.getMessage()); _plugin.removeFromParty(event.getPlayer(), PartyRemoveReason.KICKED);
return; return;
} }
party.sendMessage(F.main("Party", "Transferring servers..."));
_plugin.getRedisManager().sendPartyInfo(server, party);
_transferring.addAll(party.getMembersByUUID());
}
/** event.setCancelled(true);
* Retrieve whether or not the player is currently transferring servers
* We wont need this information again, so calling a remove works fine. if (!party.getOwnerName().equalsIgnoreCase(player.getName()))
*
* @param player The player
* @return <code>true</code> if the player is transferring servers
*/
public boolean isTransferring(Player player)
{ {
return _transferring.remove(player.getUniqueId()); Lang.NOT_OWNER_SERVER.send(player);
return;
} }
MinecraftServer best = null;
int lowest = Integer.MAX_VALUE;
List<MinecraftServer> serverList = Lists.newArrayList(_plugin.getPortal().getRepository().getServersByGroup(event.getServer().getName()));
for (MinecraftServer server : serverList)
{
int playercount = server.getPlayerCount();
if (playercount < 20)
{
continue;
}
if (playercount < lowest)
{
lowest = playercount;
if (best == null)
{
best = server;
}
}
}
if (best == null)
{
best = serverList.get(new Random().nextInt(serverList.size()));
}
party.sendMessage(F.main("Party", F.elem(player.getName()) + " is moving the party to " + F.elem(best.getName())));
requestServerJoin(best.getName(), party);
}
@EventHandler
public void onTransfer(ServerTransferEvent event)
{
Player player = event.getPlayer();
Party party = _plugin.getPartyByPlayer(player);
if (party == null)
{
return;
}
// If the server wants to kick the player, let's not stop it
if (event.getIntent() == Intent.KICK || event.getIntent() == Intent.FORCE_TRANSFER)
{
_plugin.removeFromParty(event.getPlayer(), PartyRemoveReason.KICKED);
return;
}
if (_pendingTransfers.containsKey(party.getUniqueId()))
{
return;
}
event.setCancelled(true);
if (event.getServer().toUpperCase().startsWith("CLANS-"))
{
party.sendMessage(F.main("Party", "You cannot join a Clans server while in a party!"));
return;
}
if (!party.getOwnerName().equalsIgnoreCase(player.getName()))
{
Lang.NOT_OWNER_SERVER.send(player);
return;
}
party.sendMessage(F.main("Party", F.elem(player.getName()) + " is moving the party to " + F.elem(event.getServer())));
requestServerJoin(event.getServer(), party);
}
public void removePendingJoin(Party party)
{
_pendingTransfers.remove(party.getUniqueId());
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
if (_plugin.hasPendingJoin(player))
{
Party pendingParty = _plugin.getPendingParty(player);
_plugin.removePendingJoin(player);
if (pendingParty == null)
{
UtilPlayer.message(player, F.main("Party", "Uh oh. It seems that in the time it took for you to join this server, your inviter has disbanded their party"));
return;
}
if (pendingParty.getOwner().getId().equals(event.getPlayer().getUniqueId()))
{
UtilPlayer.message(player, F.main("Party", "Welcome back! Your party is just as you've left it!"));
}
else
{
UtilPlayer.message(player, F.main("Party", "Welcome! Adding you to " + F.elem(pendingParty.getOwnerName()) + "'s party!"));
}
_plugin.addToParty(player, pendingParty);
}
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
Player player = event.getPlayer();
Party party = _plugin.getPartyByPlayer(player);
_plugin.getInviteManager().removeAll(player);
if (party == null)
{
return;
}
PartyRemoveReason reason = PartyRemoveReason.LEFT;
_plugin.removeFromParty(player, reason);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onInteract(PlayerInteractEntityEvent event)
{
if (UtilItem.isSimilar(event.getPlayer().getItemInHand(), PartyManager.INTERFACE_ITEM, UtilItem.ItemAttribute.NAME))
{
event.setCancelled(true);
event.getPlayer().updateInventory();
CommandCenter.getCommands().get("party").Execute(event.getPlayer(), new String[0]);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onClick(PlayerInteractEvent event)
{
if (UtilItem.isSimilar(event.getItem(), PartyManager.INTERFACE_ITEM, UtilItem.ItemAttribute.NAME))
{
event.setCancelled(true);
CommandCenter.getCommands().get("party").Execute(event.getPlayer(), new String[0]);
}
}
} }

View File

@ -1,347 +0,0 @@
package mineplex.core.party.manager;
import com.google.common.collect.Lists;
import mineplex.core.common.util.F;
import mineplex.core.menu.Menu;
import mineplex.core.party.Lang;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.preferences.Preference;
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;
}
if(party != null)
{
if(!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
if(possible != null && _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;
}
}
//Same Server
if (possible != null)
{
if(!_plugin.getPreferencesManager().get(possible).isActive(Preference.PARTY_REQUESTS))
{
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
{
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;
}
//Only perform this when I actually need to.
boolean can = Bukkit.getMaxPlayers() >= _plugin.getPlugin().getServer().getOnlinePlayers().size();
if(!can)
{
Lang.SERVER_FULL.send(caller);
return;
}
//Not on the same server
_plugin.getRedisManager().findAndInvite(target, caller.getName());
}
/**
* Responds to a pending invite
*
* @param caller The player who initiated the request
* @param target The player's target
* @param accept <code>true</code> If the player has accepted the invite
*/
public void respondToInvite(Player caller, String target, boolean accept)
{
if(_plugin.getParty(caller) != null)
{
Lang.ALREADY_IN.send(caller);
caller.sendMessage(F.main("Party", "Please leave your party before joining!"));
return;
}
PartyInviteManager inviteManager = _plugin.getInviteManager();
if (!inviteManager.isInvitedTo(caller.getUniqueId(), target))
{
//He isn't invited to this party.
Lang.NOT_INVITED.send(caller, target);
return;
}
if(!accept)
{
caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party.");
}
inviteManager.respondToInvite(caller, target, accept);
}
/**
* Kicks a player from the callers party
*
* @param caller The player who initiated the request
* @param target The player's target
*/
public void forceRemove(Player caller, String target)
{
Party party = _plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
if (!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
Player playerTarget = Bukkit.getPlayerExact(target);
if (playerTarget == null)
{
Lang.NOT_MEMBER.send(caller, target);
return;
}
Party targetParty = _plugin.getParty(playerTarget);
if (targetParty == null ||!party.getMembers().contains(target))
{
Lang.NOT_MEMBER.send(caller, target);
return;
}
removeFromParty(playerTarget.getUniqueId(), PartyRemoveReason.KICKED);
Lang.REMOVE_PLAYER_KICK.send(targetParty);
}
/**
* Leaves the players current party if he is in one
*
* @param caller The player who wishes to leave his party
*/
public void leaveParty(Player caller)
{
Party party = _plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
removeFromParty(caller.getUniqueId(), PartyRemoveReason.LEFT);
Lang.LEFT.send(caller);
}
/**
* Disbands a players current party, assuming he is the leader
*
* @param caller The player who wishes to disband his party
*/
public void disband(Player caller)
{
Party party = _plugin.getParty(caller);
if (party == null)
{
Lang.NO_PARTY.send(caller);
return;
}
if (!party.getOwner().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
return;
}
caller.sendMessage(F.main("Party", "You have disbanded your party."));
disbandParty(party);
}
public void addToParty(UUID uuid, Party party)
{
_plugin.getPlayerParties().put(uuid, party);
Player player = Bukkit.getPlayer(uuid);
party.onPlayerAdd(player.getName());
if(!party.getMembersByUUID().contains(uuid))
{
party.getMembersByUUID().add(uuid);
}
}
public void addToPartyOnTransfer(UUID uuid, Party party)
{
_plugin.getPlayerParties().put(uuid, party);
}
public void addToParty(Player player, Party party)
{
addToParty(player.getUniqueId(), party);
}
public void removeForTransfer(UUID uuid)
{
Party party = _plugin.getPlayerParties().remove(uuid);
if(party == null)
{
return;
}
String player = Bukkit.getPlayer(uuid).getName();
party.onPlayerRemove(player, PartyRemoveReason.OTHER);
}
public void removeFromParty(UUID uuid, PartyRemoveReason reason)
{
Party party = _plugin.getPlayerParties().remove(uuid);
if(party == null)
{
return;
}
Player player = Bukkit.getPlayer(uuid);
if(player.getOpenInventory() != null)
{
if (Menu.get(player.getUniqueId()) != null)
{
player.closeInventory();
Menu.remove(player.getUniqueId());
}
}
if(reason == PartyRemoveReason.DISBANDED_BY_OWNER)
{
return;
}
party.getMembers().remove(player.getName());
party.getMembersByUUID().remove(uuid);
party.onPlayerRemove(player.getName(), reason);
int size = party.getMembers().size();
if(size <= 1)
{
if(size == 0)
{
_plugin.removeParty(party);
return;
}
_plugin.getPlayerParties().remove(Bukkit.getPlayerExact(party.getMembers().get(0)).getUniqueId());
party.onPlayerRemove(party.getMembers().get(0), PartyRemoveReason.DISBANDED);
_plugin.removeParty(party);
}
}
public void removeFromParty(Player player, PartyRemoveReason reason)
{
removeFromParty(player.getUniqueId(), reason);
}
public void disbandParty(Party party)
{
List<UUID> members = Lists.newArrayList(party.getMembersByUUID());
Lang.DISBANDED_BY_OWNER.send(party);
members.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, party);
party.setOwner(newOwner);
party.getMembers().remove(oldOwner);
party.getMembers().add(oldOwner);
UUID uuid = Bukkit.getPlayerExact(oldOwner).getUniqueId();
party.getMembersByUUID().remove(uuid);
party.getMembersByUUID().add(uuid);
}
}

View File

@ -1,296 +1,188 @@
package mineplex.core.party.manager; package mineplex.core.party.manager;
import com.google.common.collect.Maps; import java.util.HashMap;
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.constants.InviteResponse;
import mineplex.core.party.constants.JoinResponseReason;
import mineplex.core.party.event.PartyDataReceivedEvent;
import mineplex.core.party.redis.PartyRedisListener;
import mineplex.core.party.redis.RedisMessageType;
import mineplex.core.preferences.Preference;
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.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import static mineplex.core.party.redis.RedisMessageType.INVITE_PLAYER_REQUEST; import org.bukkit.Bukkit;
import static mineplex.core.party.redis.RedisMessageType.PARTY_INFO; import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import com.google.common.collect.Maps;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.Lang;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.rediscommands.PartyCrossServerInviteAccept;
import mineplex.core.party.rediscommands.PartyCrossServerInviteCommand;
import mineplex.core.party.rediscommands.PartyCrossServerInviteDeny;
import mineplex.core.party.rediscommands.PartyCrossServerInviteResponse;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.Preference;
import mineplex.serverdata.commands.ServerCommandManager;
import redis.clients.jedis.JedisPool;
/**
* Redis system for Parties
*/
public class PartyRedisManager public class PartyRedisManager
{ {
protected final Gson GSON = new GsonBuilder().create(); private final Map<UUID, Map<String, BukkitTask>> _pendingFindResponse = new HashMap<>();
protected static final String CHANNEL_BASE = "party-pubsub";
protected static final String FIND_PLAYERS_CHANNEL = "party-player-finder";
private final Map<String, BukkitTask> TASKS = Maps.newHashMap();
private final PartyManager _plugin; private final PartyManager _plugin;
private final JedisPool _writePool;
private final String _channel;
private final String _serverName; private final String _serverName;
public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool) public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool)
{ {
_plugin = plugin; _plugin = plugin;
_serverName = serverName; _serverName = serverName;
_writePool = writePool;
_channel = CHANNEL_BASE + "-" + serverName;
plugin.runAsync(() -> { ServerCommandManager.getInstance().registerCommandType(PartyCrossServerInviteCommand.class, command ->
try (Jedis jedis = readPool.getResource())
{ {
jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL); _plugin.runSync(() ->
}
});
}
/**
* 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)
{ {
_plugin.runAsync(() -> { Player player = Bukkit.getPlayerExact(command.getTarget());
try (Jedis jedis = _writePool.getResource()) if (player == null || !player.isOnline())
{
jedis.publish(CHANNEL_BASE + "-" + server, messageType.name() + "@" + messageType.format(args));
}
});
}
/**
* 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)
{
handlePartyInfo(message);
return;
}
String[] contents = message.split(",");
if (contents.length < 3)
{
return;
}
String first = contents[0];
String second = contents[1];
String third = contents[2];
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 PLAYER_FIND_REQUEST:
Player player = Bukkit.getPlayerExact(second);
if (player == null)
{ {
return; return;
} }
if(_plugin.getParty(player) != null) if (_plugin.getPartyByPlayer(player) != null)
{ {
publish(first, RedisMessageType.INVITE_PLAYER_ALREADY_IN_PARTY, _serverName, player.getName(), player.getUniqueId().toString(), third); ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteResponse(PartyCrossServerInviteResponse.Result.TARGET_ALREADY_IN_PARTY, command, player));
return; return;
} }
if (!_plugin.getPreferencesManager().get(player).isActive(Preference.PARTY_REQUESTS)) if (!_plugin.getPreferencesManager().get(player).isActive(Preference.PARTY_REQUESTS))
{ {
publish(first, RedisMessageType.INVITE_PLAYER_NOT_ACCEPTING_INVITES, _serverName, player.getName(), player.getUniqueId().toString(), third); ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteResponse(PartyCrossServerInviteResponse.Result.TARGET_NOT_ACCEPTING_INVITES, command, player));
return; return;
} }
publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third); _plugin.getInviteManager().inviteTo(player.getName(), player.getUniqueId(), command.getRequesterName(), command.getRequesterUUID(), command.getPartyUUID(), command.getFromServer());
break; Lang.INVITE_RECEIVED.send(player, command.getRequesterName());
_plugin.getInviteManager().sendAcceptOrDeny(player, command.getRequesterName());
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
case INVITE_PLAYER_ALREADY_IN_PARTY: ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteResponse(PartyCrossServerInviteResponse.Result.SUCCESS, command, player));
handleAlreadyIn(second, contents); });
break; });
case INVITE_PLAYER_NOT_ACCEPTING_INVITES: ServerCommandManager.getInstance().registerCommandType(PartyCrossServerInviteResponse.class, command ->
handleNotAccepting(second, contents);
break;
case PLAYER_FIND_RESPONSE:
UUID uuid = UUID.fromString(third);
cancelTask(second);
Player inviter = Bukkit.getPlayerExact(contents[3]);
if (_plugin.getInviteManager().isInvitedTo(uuid, inviter.getName()))
{ {
Lang.ALREADY_INVITED.send(inviter, second); _plugin.runSync(() ->
{
Map<String, BukkitTask> pendingTasks = _pendingFindResponse.get(command.getOrigin().getRequesterUUID());
if (pendingTasks == null)
return;
BukkitTask alertTask = pendingTasks.remove(command.getOrigin().getTarget());
if (alertTask == null)
return;
alertTask.cancel();
Player caller = Bukkit.getPlayer(command.getOrigin().getRequesterUUID());
if (caller == null || !caller.isOnline())
return;
switch (command.getResult())
{
case TARGET_ALREADY_IN_PARTY:
UtilPlayer.message(caller, F.main("Party", "The player " + F.elem(command.getOrigin().getTarget()) + " is already in a party!"));
break;
case TARGET_NOT_ACCEPTING_INVITES:
UtilPlayer.message(caller, F.main("Party", "The player " + F.elem(command.getOrigin().getTarget()) + " is not accepting invites!"));
break;
case SUCCESS:
Party party = _plugin.getPartyByPlayer(command.getOrigin().getRequesterUUID());
if (party == null)
{
// todo wat do
return; return;
} }
if (_plugin.getParty(inviter) == null) if (!party.getOwnerName().equals(command.getOrigin().getRequesterName()))
{ {
Lang.INVITE_SUCCESS_PLAYER.send(inviter, second); //todo wat do
} else
{
Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second);
} }
_plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName()); _plugin.getInviteManager().inviteTo(command.getTargetName(), command.getTargetUUID(), command.getOrigin().getRequesterName(), command.getOrigin().getRequesterUUID(), command.getOrigin().getPartyUUID(), _plugin.getServerName());
publish(first, INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); UtilPlayer.message(caller, F.main("Party", "You have invited " + F.elem(command.getTargetName()) + " to your party"));
break; break;
case UNKNOWN:
case PREJOIN_SERVER_REQUEST: UtilPlayer.message(caller, F.main("Party", "Uh oh, something went wrong while inviting " + F.elem(command.getOrigin().getTarget())));
_plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3]));
break;
case PREJOIN_SERVER_RESPONSE:
_plugin.getJoinManager().handleJoinResponse(first, third, JoinResponseReason.valueOf(second.toUpperCase()));
break; break;
} }
}); });
});
} ServerCommandManager.getInstance().registerCommandType(PartyCrossServerInviteAccept.class, command ->
private void handleNotAccepting(String second, String[] contents)
{ {
cancelTask(second); _plugin.runSync(() ->
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)
{ {
cancelTask(second); Player apparentSender = Bukkit.getPlayer(command.getInviterUUID());
Player inviter = Bukkit.getPlayerExact(contents[3]); if (apparentSender != null && apparentSender.isOnline())
Lang.ALREADY_IN.send(inviter, second);
}
/**
* 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 " + F.elem(player) + "...")); Party partyOfSender = _plugin.getPartyByPlayer(apparentSender);
TASKS.put(player, new BukkitRunnable() if (partyOfSender == null)
{ {
@Override //todo wat do
public void run()
{
if(!TASKS.containsKey(player))
{
cancel();
return; return;
} }
TASKS.remove(player); if (!partyOfSender.getUniqueId().equals(command.getPartyUUID()))
Player senderPlayer = Bukkit.getPlayerExact(sender);
if (senderPlayer == null)
{ {
cancel(); //todo wat do
return; return;
} }
if (Bukkit.getPlayerExact(player) != null)
{
cancel();
return;
}
senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player) + "."));
}
}.runTaskLater(_plugin.getPlugin(), 20L * 5));
_plugin.runAsync(() -> { if (!partyOfSender.getOwnerName().equals(command.getInviterName()))
try (Jedis jedis = _writePool.getResource())
{ {
jedis.publish(FIND_PLAYERS_CHANNEL, RedisMessageType.PLAYER_FIND_REQUEST.format(_serverName, player, sender)); // todo ignore for now but wat do
} }
// we good
_plugin.putIntoPendingJoin(command.getPlayerUUID(), partyOfSender.getUniqueId());
Portal.transferPlayer(command.getPlayerName(), _serverName);
}
});
});
ServerCommandManager.getInstance().registerCommandType(PartyCrossServerInviteDeny.class, command ->
{
_plugin.runSync(() ->
{
Player apparentSender = Bukkit.getPlayer(command.getInviterUUID());
if (apparentSender != null && apparentSender.isOnline())
{
Party partyOfSender = _plugin.getPartyByPlayer(apparentSender);
if (partyOfSender == null)
{
UtilPlayer.message(apparentSender, F.main("Party", F.elem(command.getPlayerName()) + " has denied your invite, but it seems you don't have a party anymore"));
return;
}
if (!partyOfSender.getUniqueId().equals(command.getPartyUUID()))
{
UtilPlayer.message(apparentSender, F.main("Party", F.elem(command.getPlayerName()) + " has denied your invite, but it seems that you've made a new party in the meantime"));
return;
}
if (!partyOfSender.getOwnerName().equals(command.getInviterName()))
{
UtilPlayer.message(apparentSender, F.main("Party", F.elem(command.getPlayerName()) + " has denied your invite, but it seems that you are not the owner of the party anymore"));
return;
}
UtilPlayer.message(apparentSender, F.main("Party", F.elem(command.getPlayerName()) + " has denied your invite"));
}
});
}); });
} }
/** public Map<UUID, Map<String, BukkitTask>> getPendingFindResponse()
* 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)); return _pendingFindResponse;
List<UUID> members = party.getMembersByUUID();
party.getMembersByUUID().forEach(uuid -> _plugin.getMethodManager().removeForTransfer(uuid));
members.stream().map(Bukkit::getPlayer).forEach(player1 ->
{
player1.leaveVehicle();
player1.eject();
_plugin.getPortal().sendPlayer(player1, server);
});
_plugin.removeParty(party);
}
/**
* Deserialize and store a received party's information
* @param json
*/
public void handlePartyInfo(String json)
{
new BukkitRunnable()
{
@Override
public void run()
{
Party party = GSON.fromJson(json, Party.class);
_plugin.addParty(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;
}
public void cancelTask(String player)
{
BukkitTask task = TASKS.remove(player);
if (task != null)
{
task.cancel();
}
} }
} }

View File

@ -1,30 +0,0 @@
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 final PartyRedisManager _redisManager;
public PartyRedisListener(PartyRedisManager redisManager)
{
_redisManager = redisManager;
}
@Override
public void onMessage(String channel, String message)
{
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]);
}
}

View File

@ -1,63 +0,0 @@
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: 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}"),
//Message: PLAYER_INITIATING,REASON,SERVER
PREJOIN_SERVER_RESPONSE(7, "{0},{1},{2}"),
//Message: JSON Party
PARTY_INFO(8, "{0}"),
TEST_CONN(9, "{0}")
;
private int _id;
private String _contents;
RedisMessageType(int id, String contents)
{
_id = id;
_contents = contents;
}
public int getId()
{
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;
for(int i = 0; i < args.length; i++)
{
message = message.replace("{" + i + "}", args[i]);
}
return message;
}
}

View File

@ -0,0 +1,50 @@
package mineplex.core.party.rediscommands;
import java.util.UUID;
import mineplex.serverdata.commands.ServerCommand;
public class PartyCrossServerInviteAccept extends ServerCommand
{
private final String _playerName;
private final UUID _playerUUID;
private final String _inviterName;
private final UUID _inviterUUID;
private final UUID _partyUUID;
public PartyCrossServerInviteAccept(String playerName, UUID playerUUID, String inviterName, UUID inviterUUID, UUID partyUUID)
{
_playerName = playerName;
_playerUUID = playerUUID;
_inviterName = inviterName;
_inviterUUID = inviterUUID;
_partyUUID = partyUUID;
}
public String getPlayerName()
{
return _playerName;
}
public UUID getPlayerUUID()
{
return _playerUUID;
}
public String getInviterName()
{
return _inviterName;
}
public UUID getInviterUUID()
{
return _inviterUUID;
}
public UUID getPartyUUID()
{
return _partyUUID;
}
}

View File

@ -0,0 +1,44 @@
package mineplex.core.party.rediscommands;
import java.util.UUID;
import org.bukkit.entity.Player;
import mineplex.core.party.Party;
import mineplex.serverdata.commands.ServerCommand;
public class PartyCrossServerInviteCommand extends ServerCommand
{
private final String _requesterName;
private final UUID _requesterUUID;
private final String _target;
private final UUID _partyUUID;
public PartyCrossServerInviteCommand(Player caller, String target, Party destParty)
{
_target = target;
_requesterName = caller.getName();
_requesterUUID = caller.getUniqueId();
_partyUUID = destParty.getUniqueId();
}
public String getTarget()
{
return _target;
}
public String getRequesterName()
{
return _requesterName;
}
public UUID getRequesterUUID()
{
return _requesterUUID;
}
public UUID getPartyUUID()
{
return _partyUUID;
}
}

View File

@ -0,0 +1,50 @@
package mineplex.core.party.rediscommands;
import java.util.UUID;
import mineplex.serverdata.commands.ServerCommand;
public class PartyCrossServerInviteDeny extends ServerCommand
{
private final String _playerName;
private final UUID _playerUUID;
private final String _inviterName;
private final UUID _inviterUUID;
private final UUID _partyUUID;
public PartyCrossServerInviteDeny(String playerName, UUID playerUUID, String inviterName, UUID inviterUUID, UUID partyUUID)
{
_playerName = playerName;
_playerUUID = playerUUID;
_inviterName = inviterName;
_inviterUUID = inviterUUID;
_partyUUID = partyUUID;
}
public String getPlayerName()
{
return _playerName;
}
public UUID getPlayerUUID()
{
return _playerUUID;
}
public String getInviterName()
{
return _inviterName;
}
public UUID getInviterUUID()
{
return _inviterUUID;
}
public UUID getPartyUUID()
{
return _partyUUID;
}
}

View File

@ -0,0 +1,58 @@
package mineplex.core.party.rediscommands;
import java.util.UUID;
import org.bukkit.entity.Player;
import com.google.gson.annotations.SerializedName;
import mineplex.serverdata.commands.ServerCommand;
public class PartyCrossServerInviteResponse extends ServerCommand
{
private final Result _result;
private final PartyCrossServerInviteCommand _origin;
private final String _targetName;
private final UUID _targetUUID;
public PartyCrossServerInviteResponse(Result result, PartyCrossServerInviteCommand origin, Player target)
{
_result = result;
_origin = origin;
_targetName = target.getName();
_targetUUID = target.getUniqueId();
}
public Result getResult()
{
return _result == null ? Result.UNKNOWN : _result;
}
public PartyCrossServerInviteCommand getOrigin()
{
return _origin;
}
public String getTargetName()
{
return _targetName;
}
public UUID getTargetUUID()
{
return _targetUUID;
}
public enum Result
{
@SerializedName("already-in-party")
TARGET_ALREADY_IN_PARTY,
@SerializedName("not-accepting-invites")
TARGET_NOT_ACCEPTING_INVITES,
@SerializedName("success")
SUCCESS,
UNKNOWN
}
}

View File

@ -0,0 +1,53 @@
package mineplex.core.party.rediscommands;
import java.util.List;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import mineplex.serverdata.commands.ServerCommand;
public class PartyTransferRequest extends ServerCommand
{
private final UUID _partyUUID;
private final List<UUID> _allMembers;
private final List<UUID> _unrankedMembers;
private final boolean _canJoinFullServers;
private final GameProfile _ownerGameProfile;
public PartyTransferRequest(UUID partyUUID, GameProfile ownerGameProfile, List<UUID> allMembers, List<UUID> unrankedMembers, boolean canJoinFullServers, String destServer)
{
super(destServer);
_partyUUID = partyUUID;
_ownerGameProfile = ownerGameProfile;
_allMembers = allMembers;
_unrankedMembers = unrankedMembers;
_canJoinFullServers = canJoinFullServers;
}
public UUID getPartyUUID()
{
return _partyUUID;
}
public List<UUID> getAllMembers()
{
return _allMembers;
}
public List<UUID> getUnrankedMembers()
{
return _unrankedMembers;
}
public boolean isCanJoinFullServers()
{
return _canJoinFullServers;
}
public GameProfile getOwnerGameProfile()
{
return _ownerGameProfile;
}
}

View File

@ -0,0 +1,36 @@
package mineplex.core.party.rediscommands;
import com.google.gson.annotations.SerializedName;
import mineplex.serverdata.commands.ServerCommand;
public class PartyTransferResponse extends ServerCommand
{
private final PartyTransferRequest _origin;
private final Result _result;
public PartyTransferResponse(PartyTransferRequest origin, Result result)
{
_origin = origin;
_result = result;
}
public PartyTransferRequest getOrigin()
{
return _origin;
}
public Result getResult()
{
return _result;
}
public enum Result
{
@SerializedName("not-enough-room")
NOT_ENOUGH_ROOM,
@SerializedName("success")
SUCCESS,
UNKNOWN
}
}

View File

@ -13,15 +13,8 @@ import org.bukkit.Material;
*/ */
public abstract class PartyMenu extends Menu<PartyManager> public abstract class PartyMenu extends Menu<PartyManager>
{ {
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!")
.build());
public PartyMenu(String name, PartyManager plugin) public PartyMenu(String name, PartyManager plugin)
{ {
super(name, plugin); super(name, plugin);
} }
} }

View File

@ -1,17 +1,25 @@
package mineplex.core.party.ui.button; package mineplex.core.party.ui.button;
import mineplex.core.Managers;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.menu.Menu;
import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.event.PartyMemberKickGUIEvent; import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.ui.button.tools.PartyButton; import mineplex.core.party.ui.button.tools.PartyButton;
import mineplex.core.utils.UtilGameProfile;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.mojang.authlib.GameProfile;
/** /**
* The button representing a Party member. * The button representing a Party member.
*/ */
@ -20,17 +28,18 @@ public class PartyMemberIcon extends PartyButton
private ItemStack _itemStack; private ItemStack _itemStack;
public PartyMemberIcon(String player, Party party, boolean owner) public PartyMemberIcon(GameProfile playerProfile, Party party, boolean owner)
{ {
super(null, party, null); super(null, party, null);
ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3) ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3)
.setTitle(C.cYellow + player) .setTitle(C.cYellow + playerProfile.getName());
.setPlayerHead(player);
if(owner) if(owner)
{ {
builder.addLore(" ", C.cGreenB + "Leader"); builder.addLore(" ", C.cGreenB + "Leader");
} }
_itemStack = builder.build(); _itemStack = builder.build();
UtilGameProfile.setGameProfile(playerProfile, _itemStack);
} }
@Override @Override
@ -51,12 +60,16 @@ public class PartyMemberIcon extends PartyButton
{ {
return; return;
} }
if(!getParty().getOwner().equalsIgnoreCase(clicker.getName())) if(!getParty().getOwnerName().equalsIgnoreCase(clicker.getName()))
{ {
return; return;
} }
String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
UtilServer.getPluginManager().callEvent(new PartyMemberKickGUIEvent(getParty(), name, clicker));
Player target = Bukkit.getPlayerExact(name);
Lang.REMOVED.send(target);
Managers.require(PartyManager.class).removeFromParty(target, PartyRemoveReason.KICKED);
Menu.get(clicker.getUniqueId()).resetAndUpdate();
} }
@Override @Override

View File

@ -32,7 +32,7 @@ public class LeavePartyButton extends Button<PartyManager>
{ {
return; return;
} }
getPlugin().getMethodManager().leaveParty(player); getPlugin().leaveParty(player);
player.closeInventory(); player.closeInventory();
} }

View File

@ -1,15 +1,16 @@
package mineplex.core.party.ui.button.tools.invite; package mineplex.core.party.ui.button.tools.invite;
import mineplex.core.common.util.C;
import mineplex.core.menu.Button;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.menus.PartyInvitesMenu;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.menu.Button;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.menus.PartyInvitesMenu;
/** /**
* Deny's all invites currently pending * Deny's all invites currently pending
*/ */
@ -29,7 +30,7 @@ public class DenyAllButton extends Button<PartyManager>
@Override @Override
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
{ {
getPlugin().getInviteManager().getAllInvites(player).forEach(inviteData -> getPlugin().getMethodManager().respondToInvite(player, inviteData.getInvitedTo(), false)); getPlugin().getInviteManager().getAllInvites(player).forEach(inviteData -> getPlugin().denyInviteBySender(player, inviteData.getInviterName()));
new PartyInvitesMenu(getPlugin()).open(player); new PartyInvitesMenu(getPlugin()).open(player);
} }
} }

View File

@ -1,12 +1,13 @@
package mineplex.core.party.ui.button.tools.invite; package mineplex.core.party.ui.button.tools.invite;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.menu.Button; import mineplex.core.menu.Button;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
/** /**
* Represents an invitation, to which a player can accept or deny * Represents an invitation, to which a player can accept or deny
@ -32,10 +33,11 @@ public class InviteButton extends Button<PartyManager>
{ {
if (clickType == ClickType.LEFT) if (clickType == ClickType.LEFT)
{ {
getPlugin().getMethodManager().respondToInvite(player, _name, true); getPlugin().acceptInviteBySender(player, _name);
} else if(clickType == ClickType.RIGHT) }
else if (clickType == ClickType.RIGHT)
{ {
getPlugin().getMethodManager().respondToInvite(player, _name, false); getPlugin().denyInviteBySender(player, _name);
} }
player.closeInventory(); player.closeInventory();
} }

View File

@ -42,7 +42,7 @@ public class NextPageButton extends Button<PartyManager>
List<InviteData> data = _menu.getDataForPage(_menu.getCurrentPage()); List<InviteData> data = _menu.getDataForPage(_menu.getCurrentPage());
for(int i = 0; i < data.size(); i++) for(int i = 0; i < data.size(); i++)
{ {
_menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin())); _menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInviterName(), getPlugin()));
} }
_menu.update(); _menu.update();
} }

View File

@ -41,7 +41,7 @@ public class PrevPageButton extends Button<PartyManager>
List<InviteData> data = _menu.getDataForPage(_menu.getCurrentPage()); List<InviteData> data = _menu.getDataForPage(_menu.getCurrentPage());
for(int i = 0; i < data.size(); i++) for(int i = 0; i < data.size(); i++)
{ {
_menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin())); _menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInviterName(), getPlugin()));
} }
_menu.update(); _menu.update();
} }

View File

@ -32,7 +32,7 @@ public class DisbandPartyButton extends Button<PartyManager>
{ {
return; return;
} }
getPlugin().getMethodManager().disband(player); getPlugin().disband(player);
player.closeInventory(); player.closeInventory();
} }
} }

View File

@ -1,15 +1,16 @@
package mineplex.core.party.ui.button.tools.owner; package mineplex.core.party.ui.button.tools.owner;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.event.PartySelectServerEvent; import mineplex.core.party.event.PartySelectServerEvent;
import mineplex.core.party.ui.button.tools.PartyButton; 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;
/** /**
* Opens the server selection menu * Opens the server selection menu

View File

@ -20,6 +20,8 @@ import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -69,7 +71,7 @@ public class PartyInvitesMenu extends PartyMenu
buttons[BACK_BUTTON_SLOT] = new BackButton(getPlugin()); buttons[BACK_BUTTON_SLOT] = new BackButton(getPlugin());
List<InviteData> all = (List<InviteData>) getPlugin().getInviteManager().getAllInvites(player); List<InviteData> all = getPlugin().getInviteManager().getAllInvites(player);
if (all == null || all.isEmpty()) if (all == null || all.isEmpty())
{ {
@ -81,6 +83,8 @@ public class PartyInvitesMenu extends PartyMenu
return pane(buttons); return pane(buttons);
} }
all.sort(Comparator.comparing(InviteData::getInviterName));
buttons[DENY_ALL_BUTTON_SLOW] = new DenyAllButton(getPlugin()); buttons[DENY_ALL_BUTTON_SLOW] = new DenyAllButton(getPlugin());
if (_filterBy == null || _filterBy.isEmpty()) if (_filterBy == null || _filterBy.isEmpty())
@ -94,7 +98,7 @@ public class PartyInvitesMenu extends PartyMenu
if (showFiltered) if (showFiltered)
{ {
all = all.stream().filter(inviteData -> inviteData.getInvitedTo().contains(_filterBy)).collect(Collectors.toList()); all = all.stream().filter(inviteData -> inviteData.getInviterName().contains(_filterBy)).collect(Collectors.toList());
} }
if (showFiltered && all.isEmpty()) if (showFiltered && all.isEmpty())
@ -125,7 +129,7 @@ public class PartyInvitesMenu extends PartyMenu
buttons[NEXT_PAGE_SLOT] = new NextPageButton(this, getPlugin()); buttons[NEXT_PAGE_SLOT] = new NextPageButton(this, getPlugin());
_pagesNeeded = pagesNeeded; _pagesNeeded = pagesNeeded;
_pagesOfData = Maps.newHashMap(); _pagesOfData = new HashMap<>();
int page = 0; int page = 0;
@ -150,7 +154,7 @@ public class PartyInvitesMenu extends PartyMenu
{ {
for (int i = 0; i < all.size(); i++) for (int i = 0; i < all.size(); i++)
{ {
String to = all.get(i).getInvitedTo(); String to = all.get(i).getInviterName();
buttons[STARTING_SLOT + i] = new InviteButton(to, getPlugin()); buttons[STARTING_SLOT + i] = new InviteButton(to, getPlugin());
} }
} }

View File

@ -1,22 +1,24 @@
package mineplex.core.party.ui.menus; package mineplex.core.party.ui.menus;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.menu.Button; import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
import mineplex.core.menu.builtin.ButtonOpenInventory;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.PartyMenu;
import mineplex.core.party.ui.button.tools.main.InvitePlayerButton; import mineplex.core.party.ui.button.tools.main.InvitePlayerButton;
import mineplex.core.party.ui.button.tools.main.ViewInvitesButton; import mineplex.core.party.ui.button.tools.main.ViewInvitesButton;
import org.bukkit.entity.Player;
/** public class PartyMainMenu extends Menu<PartyManager>
* The main GUI for parties.
*/
public class PartyMainMenu extends PartyMenu
{ {
private static final ItemStack VIEW_INVITES_ITEM = new ItemBuilder(Material.BOOK)
private final int INV_SIZE = 9; .setTitle(C.cYellow + "View Invites")
.setLore(" ", C.cGray + "Manage invites to parties.")
private final int INVITE_PLAYER_BUTTON_SLOT = 3; .build();
private final int VIEW_INVITES_BUTTON_SLOT = 5;
public PartyMainMenu(PartyManager plugin) public PartyMainMenu(PartyManager plugin)
{ {
@ -26,10 +28,10 @@ public class PartyMainMenu extends PartyMenu
@Override @Override
protected Button[] setUp(Player player) protected Button[] setUp(Player player)
{ {
Button[] buttons = new Button[INV_SIZE]; Button[] buttons = new Button[9];
buttons[INVITE_PLAYER_BUTTON_SLOT] = new InvitePlayerButton(getPlugin()); buttons[3] = new InvitePlayerButton(getPlugin());
buttons[VIEW_INVITES_BUTTON_SLOT] = new ViewInvitesButton(getPlugin()); buttons[5] = new ButtonOpenInventory<>(VIEW_INVITES_ITEM, getPlugin(), () -> new PartyInvitesMenu(getPlugin()));
return buttons; return buttons;
} }

View File

@ -1,5 +1,10 @@
package mineplex.core.party.ui.menus; package mineplex.core.party.ui.menus;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import mineplex.core.menu.Button; import mineplex.core.menu.Button;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
@ -11,11 +16,7 @@ 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.KickPlayerButton;
import mineplex.core.party.ui.button.tools.owner.SelectServerButton; import mineplex.core.party.ui.button.tools.owner.SelectServerButton;
import mineplex.core.party.ui.button.tools.owner.TransferOwnerButton; import mineplex.core.party.ui.button.tools.owner.TransferOwnerButton;
import org.bukkit.Bukkit; import mineplex.core.utils.UtilGameProfile;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.UUID;
/** /**
* The display menu for managing parties by the owner * The display menu for managing parties by the owner
@ -67,23 +68,24 @@ public class PartyOwnerMenu extends PartyMenu
//Disband //Disband
buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(getPlugin()); buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(getPlugin());
List<String> members = _party.getMembers(); List<Player> members = new ArrayList<>(_party.getMembers());
members.remove(_party.getOwner()); _party.getOwnerAsPlayer().ifPresent(members::remove);
buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true); buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true);
int slot = STARTING_SLOT; int slot = STARTING_SLOT;
//Players //Players
for (String member: members) for (Player member : members)
{ {
if (slot == CUT_OFF_SLOT) if (slot == CUT_OFF_SLOT)
{ {
slot = SKIP_TO_SLOT; slot = SKIP_TO_SLOT;
} else if (slot == CUT_OFF_SLOT_2) }
else if (slot == CUT_OFF_SLOT_2)
{ {
slot = SKIP_TO_SLOT_2; slot = SKIP_TO_SLOT_2;
} }
buttons[slot++] = new PartyMemberIcon(Bukkit.getPlayerExact(member).getName(), _party, false); buttons[slot++] = new PartyMemberIcon(UtilGameProfile.getGameProfile(member), _party, false);
} }
return pane(buttons); return pane(buttons);

View File

@ -1,5 +1,10 @@
package mineplex.core.party.ui.menus; package mineplex.core.party.ui.menus;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import mineplex.core.menu.Button; import mineplex.core.menu.Button;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
@ -7,11 +12,7 @@ import mineplex.core.party.ui.PartyMenu;
import mineplex.core.party.ui.button.PartyMemberIcon; import mineplex.core.party.ui.button.PartyMemberIcon;
import mineplex.core.party.ui.button.tools.LeavePartyButton; import mineplex.core.party.ui.button.tools.LeavePartyButton;
import mineplex.core.party.ui.button.tools.view.SuggestPlayerButton; import mineplex.core.party.ui.button.tools.view.SuggestPlayerButton;
import org.bukkit.Bukkit; import mineplex.core.utils.UtilGameProfile;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.UUID;
/** /**
* The menu a player see's when he is a member, and not an owner, of a party. * The menu a player see's when he is a member, and not an owner, of a party.
@ -33,7 +34,7 @@ public class PartyViewMenu extends PartyMenu
public PartyViewMenu(Party party, PartyManager plugin) public PartyViewMenu(Party party, PartyManager plugin)
{ {
super(party.getName() + "'s Party", plugin); super(party.getOwnerName() + "'s Party", plugin);
_party = party; _party = party;
} }
@ -46,23 +47,24 @@ public class PartyViewMenu extends PartyMenu
//Suggest Player //Suggest Player
buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, getPlugin()); buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, getPlugin());
List<String> members = _party.getMembers(); List<Player> members = new ArrayList<>(_party.getMembers());
members.remove(_party.getOwner()); _party.getOwnerAsPlayer().ifPresent(members::remove);
buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true); buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true);
int slot = STARTING_SLOT; int slot = STARTING_SLOT;
//Players //Players
for (String member : members) for (Player member : members)
{ {
if (slot == CUT_OFF_SLOT) if (slot == CUT_OFF_SLOT)
{ {
slot = SKIP_TO_SLOT; slot = SKIP_TO_SLOT;
} else if (slot == CUT_OFF_SLOT_2) }
else if (slot == CUT_OFF_SLOT_2)
{ {
slot = SKIP_TO_SLOT_2; slot = SKIP_TO_SLOT_2;
} }
buttons[slot++] = new PartyMemberIcon(Bukkit.getPlayer(member).getName(), _party, false); buttons[slot++] = new PartyMemberIcon(UtilGameProfile.getGameProfile(member), _party, false);
} }
return pane(buttons); return pane(buttons);

View File

@ -14,7 +14,7 @@ public class InviteFilterMenu extends PlayerInputActionMenu
public InviteFilterMenu(PartyManager partyManager, Player player, Party party) public InviteFilterMenu(PartyManager partyManager, Player player, Party party)
{ {
super(partyManager, player, party); super(partyManager, player);
} }
@Override @Override

View File

@ -14,17 +14,19 @@ public class PartyInvitePlayerMenu extends PlayerNameMenu
{ {
private PartyManager _partyManager; private PartyManager _partyManager;
private Party _party;
public PartyInvitePlayerMenu(PartyManager partyManager, Player player, Party party) public PartyInvitePlayerMenu(PartyManager partyManager, Player player, Party party)
{ {
super(partyManager, partyManager.getClientManager(), player, party); super(partyManager, partyManager.getClientManager(), player);
_partyManager = partyManager; _partyManager = partyManager;
this._party = party;
} }
@Override @Override
public void onSuccess(String name) public void onSuccess(String name)
{ {
_partyManager.getMethodManager().invite(_player, name); _partyManager.invite(_player, name);
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f);
_player.closeInventory(); _player.closeInventory();
if (_party == null) if (_party == null)

View File

@ -1,10 +1,14 @@
package mineplex.core.party.ui.menus.input; package mineplex.core.party.ui.menus.input;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.anvilMenu.player.PlayerNameMenu; import mineplex.core.anvilMenu.player.PlayerNameMenu;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.Lang; import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import org.bukkit.entity.Player;
/** /**
* *
@ -13,23 +17,32 @@ public class PartyTransferOwnerMenu extends PlayerNameMenu
{ {
private PartyManager _partyManager; private PartyManager _partyManager;
private Party _party;
public PartyTransferOwnerMenu(PartyManager partyManager, Player player, Party party) public PartyTransferOwnerMenu(PartyManager partyManager, Player player, Party party)
{ {
super(partyManager, partyManager.getClientManager(), player, party); super(partyManager, partyManager.getClientManager(), player);
_partyManager = partyManager; _partyManager = partyManager;
this._party = party;
} }
@Override @Override
public void onSuccess(String name) public void onSuccess(String name)
{ {
if(!_party.contains(name)) Player player = Bukkit.getPlayer(name);
if (player == null)
{
UtilPlayer.message(_player, F.main("Party", "Could not find " + F.elem(name) + "!"));
return;
}
if (!_party.isMember(player))
{ {
Lang.NOT_MEMBER.send(_player, name); Lang.NOT_MEMBER.send(_player, name);
return; return;
} }
_partyManager.getMethodManager().transferOwner(name, _player.getName());
_party.setOwner(player);
Lang.TRANSFER_OWNER.send(_party, _player.getName(), name); Lang.TRANSFER_OWNER.send(_party, _player.getName(), name);
_player.closeInventory(); _player.closeInventory();
_player.chat("/party"); _player.chat("/party");

View File

@ -17,35 +17,42 @@ import org.bukkit.entity.Player;
*/ */
public class PlayerSuggestPlayerMenu extends PlayerNameMenu public class PlayerSuggestPlayerMenu extends PlayerNameMenu
{ {
private Party _party;
public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party) public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party)
{ {
super(partyManager, partyManager.getClientManager(), player, party); super(partyManager, partyManager.getClientManager(), player);
this._party = party;
} }
@Override @Override
public void onSuccess(String name) public void onSuccess(String name)
{ {
if(_party == null || _party.getOwner() == null) if(_party == null || _party.getOwnerName() == null)
{ {
Lang.NO_PARTY.send(_player); Lang.NO_PARTY.send(_player);
return; return;
} }
if(_party.contains(name)) Player target = Bukkit.getPlayer(name);
if (target != null)
{
if (_party.isMember(target))
{ {
Lang.ALREADY_MEMBER.send(_player, name); Lang.ALREADY_MEMBER.send(_player, name);
return; return;
} }
}
Player player = Bukkit.getPlayerExact(_party.getOwner()); Player player = Bukkit.getPlayerExact(_party.getOwnerName());
_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", "Click ")); ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Click "));
message.add(F.link("Invite " + name)) message.add(F.link("Invite " + name))
.hover(HoverEvent.SHOW_TEXT, C.cGreen + "Clicking this will invite " + C.cYellow + name + C.cGreen + " to the party") .hover(HoverEvent.SHOW_TEXT, C.cGreen + "Clicking this will invite " + C.cYellow + name + C.cGreen + " to the party")
.click(ClickEvent.RUN_COMMAND, "/partyinvite " + name); .click(ClickEvent.RUN_COMMAND, "/party gui invite " + name);
message.add(C.mBody + " to invite them"); message.add(C.mBody + " to invite them");
message.sendToPlayer(player); message.sendToPlayer(player);

View File

@ -0,0 +1,28 @@
package mineplex.core.portal;
/**
* Groups of servers with no specific id
*/
public enum GenericServer
{
/**
* The Hubs, such as Lobby-1
*/
HUB("Lobby"),
/**
* The Clans Hubs, such as ClansHub-1
*/
CLANS_HUB("ClansHub");
private final String _name;
GenericServer(String name)
{
this._name = name;
}
public String getName()
{
return _name;
}
}

View File

@ -0,0 +1,20 @@
package mineplex.core.portal;
/**
* The intention for transferring a player. Different intents will cause different behaviours to occur
*/
public enum Intent
{
/**
* Requested by a player (i.e. /server)
*/
PLAYER_REQUEST,
/**
* Forcibly kicked by the server (i.e. MPS kick)
*/
KICK,
/**
* A transfer was initiated from a remote server (i.e. /send)
*/
FORCE_TRANSFER
}

View File

@ -1,6 +1,20 @@
package mineplex.core.portal; package mineplex.core.portal;
import com.google.common.collect.Lists; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
@ -8,178 +22,129 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTabTitle; import mineplex.core.common.util.UtilTabTitle;
import mineplex.core.party.Party; import mineplex.core.portal.commands.SendCommand;
import mineplex.core.party.event.PartySendToServerEvent; import mineplex.core.portal.commands.ServerCommand;
import mineplex.core.portal.Commands.SendCommand; import mineplex.core.portal.events.GenericServerTransferEvent;
import mineplex.core.portal.Commands.ServerCommand; import mineplex.core.portal.events.ServerTransferEvent;
import mineplex.serverdata.Region; import mineplex.serverdata.Region;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.commands.ServerTransfer;
import mineplex.serverdata.commands.TransferCommand; import mineplex.serverdata.commands.TransferCommand;
import mineplex.serverdata.commands.TransferUUIDCommand;
import mineplex.serverdata.data.MinecraftServer; import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.servers.ServerManager; import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository; import mineplex.serverdata.servers.ServerRepository;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
public class Portal extends MiniPlugin public class Portal extends MiniPlugin
{ {
// The singleton instance of Portal // The singleton instance of Portal
private static Portal instance; private static Portal instance;
public static Portal getInstance() { return instance; }
private ServerRepository _repository; public static Portal getInstance()
private CoreClientManager _clientManager;
private HashSet<String> _connectingPlayers = new HashSet<String>();
private Region _region;
private String _serverName;
public Portal(JavaPlugin plugin, CoreClientManager clientManager, String serverName)
{ {
super("Portal", plugin); return instance;
}
private final CoreClientManager _clientManager = require(CoreClientManager.class);
private final ServerRepository _repository;
private final Set<String> _connectingPlayers = Collections.synchronizedSet(new HashSet<>());
public Portal()
{
super("Portal");
instance = this; instance = this;
_clientManager = clientManager;
_region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; _repository = ServerManager.getServerRepository(getPlugin().getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU);
_serverName = serverName;
_repository = ServerManager.getServerRepository(_region);
Bukkit.getMessenger().registerOutgoingPluginChannel(getPlugin(), "BungeeCord"); Bukkit.getMessenger().registerOutgoingPluginChannel(getPlugin(), "BungeeCord");
// Register the server command type for future use ServerCommandManager.getInstance().registerCommandType(TransferCommand.class, command ->
ServerCommandManager.getInstance().registerCommandType("TransferCommand", TransferCommand.class, new TransferHandler()); {
Player player = Bukkit.getPlayerExact(command.getPlayerName());
if (player != null && player.isOnline())
{
sendPlayerToServer(player, command.getTargetServer(), Intent.FORCE_TRANSFER);
}
});
ServerCommandManager.getInstance().registerCommandType(TransferUUIDCommand.class, command ->
{
Player player = Bukkit.getPlayer(command.getPlayerUUID());
if (player != null && player.isOnline())
{
sendPlayerToServer(player, command.getTargetServer(), Intent.FORCE_TRANSFER);
}
});
} }
@EventHandler public void sendAllPlayersToGenericServer(GenericServer hub, Intent kick)
public void join(PlayerJoinEvent event)
{ {
Player player = event.getPlayer();
//Player List
String serverName = _plugin.getConfig().getString("serverstatus.name");
UtilTabTitle.setHeaderAndFooter(player, C.Bold + "Mineplex Network " + C.cGreen + serverName, "Visit " + C.cGreen + "www.mineplex.com" + ChatColor.RESET + " for News, Forums and Shop");
} }
public void sendAllPlayers(String serverName) public void sendPlayerToGenericServer(Player player, GenericServer genericServer, Intent intent)
{
for (Player player : Bukkit.getOnlinePlayers())
{
sendPlayerToServer(player, serverName);
}
}
public void sendPlayerToServer(Player player, String serverName)
{
sendPlayerToServer(player, serverName, false);
}
public void sendPlayerToServer(final Player player, final String serverName, boolean draggedByParty)
{ {
if (_connectingPlayers.contains(player.getName())) if (_connectingPlayers.contains(player.getName()))
return; return;
ServerTransferEvent event = new ServerTransferEvent(player, serverName, draggedByParty); GenericServerTransferEvent event = new GenericServerTransferEvent(player, genericServer, intent);
Bukkit.getPluginManager().callEvent(event); UtilServer.CallEvent(event);
final boolean override = serverName.equalsIgnoreCase("Lobby") || serverName.equalsIgnoreCase("ClansHub"); if (event.isCancelled())
final Rank playerRank = _clientManager.Get(player).GetRank();
if (event.getParty() != null && override)
{
Party party = event.getParty();
if(!party.getOwner().equalsIgnoreCase(player.getName()))
{
return;
}
sendParty(party);
return;
}
if (event.getParty() != null && serverName.toUpperCase().startsWith("CLANS-"))
{
event.getParty().sendMessage(F.main(getName(), "You cannot join Clans while in a party!"));
return;
}
if (override)
{
sendPlayer(player, serverName);
return;
}
if (event.isCancel())
{ {
return; return;
} }
runAsync(() -> { sendPlayer(player, genericServer.getName());
}
public void sendPlayerToServer(Player player, String serverName, Intent intent)
{
if (_connectingPlayers.contains(player.getName()))
return;
ServerTransferEvent event = new ServerTransferEvent(player, serverName, intent);
UtilServer.CallEvent(event);
if (event.isCancelled())
{
return;
}
Rank playerRank = _clientManager.Get(player).GetRank();
runAsync(() ->
{
final MinecraftServer server = _repository.getServerStatus(serverName); final MinecraftServer server = _repository.getServerStatus(serverName);
if (server == null) if (server == null)
return; return;
Bukkit.getServer().getScheduler().runTask(_plugin, () -> { runSync(() ->
{
if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.has(Rank.ULTRA)) if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.has(Rank.ULTRA))
{ {
sendPlayer(player, serverName); sendPlayer(player, serverName);
} }
else else
{
UtilPlayer.message(player, F.main(getName(), C.cGold + serverName + C.cRed + " is full!")); UtilPlayer.message(player, F.main(getName(), C.cGold + serverName + C.cRed + " is full!"));
}
}); });
}); });
} }
private void sendParty(Party party)
{
ServerRepository repository = ServerManager.getServerRepository(_region);
MinecraftServer best = null;
List<MinecraftServer> serverList = Lists.newArrayList(repository.getServersByGroup("Lobby"));
int lowest = Integer.MAX_VALUE;
for (MinecraftServer server : serverList)
{
int playercount = server.getPlayerCount();
if (playercount < 20)
{
continue;
}
if (playercount < lowest)
{
lowest = playercount;
if (best == null)
{
best = server;
}
}
}
if (best == null)
{
//Well, fuck.
best = serverList.get(new Random().nextInt(serverList.size()));
}
PartySendToServerEvent serverEvent = new PartySendToServerEvent(party, best);
getPluginManager().callEvent(serverEvent);
}
public static void transferPlayer(String playerName, String serverName) public static void transferPlayer(String playerName, String serverName)
{ {
ServerTransfer serverTransfer = new ServerTransfer(playerName, serverName); new TransferCommand(playerName, serverName).publish();
TransferCommand transferCommand = new TransferCommand(serverTransfer); }
transferCommand.publish();
public static void transferPlayer(UUID playerUUID, String serverName)
{
new TransferUUIDCommand(playerUUID, serverName).publish();
} }
public void doesServerExist(final String serverName, final Callback<Boolean> callback) public void doesServerExist(final String serverName, final Callback<Boolean> callback)
@ -187,10 +152,10 @@ public class Portal extends MiniPlugin
if (callback == null) if (callback == null)
return; return;
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), () -> { runAsync(() ->
final boolean serverExists = ServerManager.getServerRepository(_region).serverExists(serverName); {
boolean result = _repository.serverExists(serverName);
Bukkit.getScheduler().runTask(getPlugin(), () -> callback.run(serverExists)); runSync(() -> callback.run(result));
}); });
} }
@ -200,7 +165,7 @@ public class Portal extends MiniPlugin
addCommand(new SendCommand(this)); addCommand(new SendCommand(this));
} }
public void sendToHub(Player player, String message) public void sendToHub(Player player, String message, Intent intent)
{ {
if (message != null) if (message != null)
{ {
@ -210,9 +175,15 @@ public class Portal extends MiniPlugin
} }
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f); player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
sendPlayerToServer(player, "Lobby"); sendPlayerToGenericServer(player, GenericServer.HUB, intent);
} }
/**
* Directly sends a player to the provided server name, bypassing all validation
*
* @param player The player to send
* @param serverName The destination server
*/
public void sendPlayer(final Player player, String serverName) public void sendPlayer(final Player player, String serverName)
{ {
ByteArrayOutputStream b = new ByteArrayOutputStream(); ByteArrayOutputStream b = new ByteArrayOutputStream();
@ -223,20 +194,8 @@ public class Portal extends MiniPlugin
out.writeUTF("Connect"); out.writeUTF("Connect");
out.writeUTF(serverName); out.writeUTF(serverName);
} }
catch (IOException e) catch (IOException ignored)
{ {
// Can never happen
}
finally
{
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
} }
player.sendPluginMessage(getPlugin(), "BungeeCord", b.toByteArray()); player.sendPluginMessage(getPlugin(), "BungeeCord", b.toByteArray());
@ -244,8 +203,22 @@ public class Portal extends MiniPlugin
getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> _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 + UtilServer.getServerName() + C.cGray + " to " + C.cGold + serverName));
} }
@EventHandler
private void setTabHeaderAndFooterOnJoin(PlayerJoinEvent event)
{
UtilTabTitle.setHeaderAndFooter(
event.getPlayer(),
C.Bold + "Mineplex Network " + C.cGreen + UtilServer.getServerName(),
"Visit " + C.cGreen + "www.mineplex.com" + ChatColor.RESET + " for News, Forums and Shop"
);
}
public ServerRepository getRepository()
{
return _repository;
}
} }

View File

@ -1,74 +0,0 @@
package mineplex.core.portal;
import mineplex.core.party.Party;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class ServerTransferEvent extends Event
{
private static final HandlerList _handlers = new HandlerList();
private Player _player;
private String _server;
private Party _party;
private boolean _draggedByParty;
private boolean _cancel;
public ServerTransferEvent(Player player, String server, boolean draggedByParty)
{
_player = player;
_server = server;
_draggedByParty = draggedByParty;
}
public boolean isDraggedByParty()
{
return _draggedByParty;
}
public void setDraggedByParty(boolean draggedByParty)
{
_draggedByParty = draggedByParty;
}
public HandlerList getHandlers()
{
return _handlers;
}
public static HandlerList getHandlerList()
{
return _handlers;
}
public Player getPlayer()
{
return _player;
}
public String getServer()
{
return _server;
}
public boolean isCancel()
{
return _cancel;
}
public void setCancel(boolean cancel)
{
_cancel = cancel;
}
public Party getParty()
{
return _party;
}
public void setParty(Party party)
{
_party = party;
}
}

View File

@ -1,27 +0,0 @@
package mineplex.core.portal;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
import mineplex.serverdata.commands.ServerTransfer;
import mineplex.serverdata.commands.TransferCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class TransferHandler implements CommandCallback
{
public void run(ServerCommand command)
{
if (command instanceof TransferCommand)
{
TransferCommand transferCommand = (TransferCommand) command;
ServerTransfer transfer = transferCommand.getTransfer();
Player player = Bukkit.getPlayerExact(transfer.getPlayerName());
if (player != null && player.isOnline())
{
Portal.getInstance().sendPlayerToServer(player, transfer.getServerName());
}
}
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.portal.Commands; package mineplex.core.portal.commands;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package mineplex.core.portal.Commands; package mineplex.core.portal.commands;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -8,6 +8,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
public class ServerCommand extends CommandBase<Portal> public class ServerCommand extends CommandBase<Portal>
@ -27,7 +28,6 @@ public class ServerCommand extends CommandBase<Portal>
{ {
UtilPlayer.message(player, UtilPlayer.message(player,
F.main(Plugin.getName(), C.cGray + "You are currently on server: " + C.cGold + serverName)); F.main(Plugin.getName(), C.cGray + "You are currently on server: " + C.cGold + serverName));
return;
} }
else if (args.length == 1) else if (args.length == 1)
{ {
@ -58,28 +58,21 @@ public class ServerCommand extends CommandBase<Portal>
if (servUp.contains("STAFF")) if (servUp.contains("STAFF"))
{ {
if (playerRank.has(Rank.HELPER)) if (!playerRank.has(Rank.HELPER))
Plugin.sendPlayerToServer(player, args[0]);
else
deniedAccess = true; deniedAccess = true;
} }
else if (servUp.contains("TEST")) else if (servUp.contains("TEST"))
{ {
if (playerRank.has(Rank.MODERATOR)) if (!playerRank.has(Rank.MODERATOR))
Plugin.sendPlayerToServer(player, args[0]);
else
deniedAccess = true; deniedAccess = true;
} }
else if (servUp.startsWith("CLANS-")) else if (servUp.startsWith("CLANS-"))
{ {
if (playerRank.has(Rank.HELPER)) if (!playerRank.has(Rank.HELPER))
Plugin.sendPlayerToServer(player, args[0]);
else
UtilPlayer.message(player, F.main(Plugin.getName(), "Clans servers can only be joined via the Clans Hub!"));
}
else
{ {
Plugin.sendPlayerToServer(player, args[0]); UtilPlayer.message(player, F.main(Plugin.getName(), "Clans servers can only be joined via the Clans Hub!"));
return;
}
} }
if (deniedAccess) if (deniedAccess)
@ -88,6 +81,10 @@ public class ServerCommand extends CommandBase<Portal>
player, player,
F.main(Plugin.getName(), C.cRed + "You don't have permission to join " + C.cGold + args[0])); F.main(Plugin.getName(), C.cRed + "You don't have permission to join " + C.cGold + args[0]));
} }
else
{
Plugin.sendPlayerToServer(player, args[0], Intent.PLAYER_REQUEST);
}
} }
}); });
} }
@ -96,7 +93,6 @@ public class ServerCommand extends CommandBase<Portal>
{ {
UtilPlayer.message(player, UtilPlayer.message(player,
F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
} }
} }
} }

View File

@ -0,0 +1,65 @@
package mineplex.core.portal.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
public class GenericServerTransferEvent extends Event implements Cancellable
{
private static final HandlerList HANDLER_LIST = new HandlerList();
private Player _player;
private GenericServer _server;
private boolean _cancel = false;
private Intent _intent;
public GenericServerTransferEvent(Player player, GenericServer server, Intent intent)
{
_player = player;
_server = server;
_intent = intent;
}
public Player getPlayer()
{
return _player;
}
public GenericServer getServer()
{
return _server;
}
public Intent getIntent()
{
return _intent;
}
@Override
public boolean isCancelled()
{
return this._cancel;
}
@Override
public void setCancelled(boolean b)
{
this._cancel = b;
}
public HandlerList getHandlers()
{
return HANDLER_LIST;
}
public static HandlerList getHandlerList()
{
return HANDLER_LIST;
}
}

View File

@ -0,0 +1,64 @@
package mineplex.core.portal.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.core.portal.Intent;
public class ServerTransferEvent extends Event implements Cancellable
{
private static final HandlerList HANDLER_LIST = new HandlerList();
private Player _player;
private String _server;
private boolean _cancel = false;
private Intent _intent;
public ServerTransferEvent(Player player, String server, Intent intent)
{
_player = player;
_server = server;
_intent = intent;
}
public Player getPlayer()
{
return _player;
}
public String getServer()
{
return _server;
}
public Intent getIntent()
{
return _intent;
}
@Override
public boolean isCancelled()
{
return this._cancel;
}
@Override
public void setCancelled(boolean b)
{
this._cancel = b;
}
public HandlerList getHandlers()
{
return HANDLER_LIST;
}
public static HandlerList getHandlerList()
{
return HANDLER_LIST;
}
}

View File

@ -24,7 +24,9 @@ public enum Preference
SHOW_PLAYERS(true, PreferenceCategory.USER, Material.EYE_OF_ENDER, "Hub Player Visibility"), SHOW_PLAYERS(true, PreferenceCategory.USER, Material.EYE_OF_ENDER, "Hub Player Visibility"),
SHOW_CHAT(true, PreferenceCategory.USER, Material.PAPER, "Player Chat"), SHOW_CHAT(true, PreferenceCategory.USER, Material.PAPER, "Player Chat"),
PRIVATE_MESSAGING(true, PreferenceCategory.USER, Material.MAP, "Private Messaging"), PRIVATE_MESSAGING(true, PreferenceCategory.USER, Material.MAP, "Private Messaging"),
PARTY_REQUESTS(true, PreferenceCategory.USER, Material.SKULL_ITEM, "Party Requests"),
// TIM WHY DID YOU MAKE THE ID ORDINAL YOU DHAJDHJGHADJHGFAJHFSJDHAJDHSJHJA
PARTY_REQUESTS(true, PreferenceCategory.SOCIAL, Material.SKULL_ITEM, "Party Requests"),
INVISIBILITY(false, PreferenceCategory.EXCLUSIVE, Material.NETHER_STAR, "Hub Invisibility & Flight"), INVISIBILITY(false, PreferenceCategory.EXCLUSIVE, Material.NETHER_STAR, "Hub Invisibility & Flight"),
FORCE_FIELD(false, PreferenceCategory.EXCLUSIVE, Material.SLIME_BALL, "Hub Forcefield"), FORCE_FIELD(false, PreferenceCategory.EXCLUSIVE, Material.SLIME_BALL, "Hub Forcefield"),
@ -43,6 +45,8 @@ public enum Preference
COUNTDOWN_ON_CLICK(false, PreferenceCategory.GAME_PLAY, Material.WATCH, "Countdown to Join", "See that fancy text when you're out?", "If you click it, and this is enabled", "a 15 second time will countdown", "until you are sent to a new game"), COUNTDOWN_ON_CLICK(false, PreferenceCategory.GAME_PLAY, Material.WATCH, "Countdown to Join", "See that fancy text when you're out?", "If you click it, and this is enabled", "a 15 second time will countdown", "until you are sent to a new game"),
COMMUNITY_INVITES(true, PreferenceCategory.SOCIAL, Material.BOOK, "Show Community Invites"), COMMUNITY_INVITES(true, PreferenceCategory.SOCIAL, Material.BOOK, "Show Community Invites"),
PARTY_DISPLAY_INVENTORY_UI(true, PreferenceCategory.SOCIAL, Material.CHEST, "Display Parties GUI")
; ;
private static final Map<Integer, Preference> PREFERENCE_MAP = Maps.newHashMap(); private static final Map<Integer, Preference> PREFERENCE_MAP = Maps.newHashMap();

View File

@ -24,6 +24,8 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.resourcepack.redis.RedisUnloadResPack; import mineplex.core.resourcepack.redis.RedisUnloadResPack;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ -187,7 +189,7 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
private void returnHubNoResPack(Player player) private void returnHubNoResPack(Player player)
{ {
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f); player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
_portal.sendPlayerToServer(player, "Lobby"); _portal.sendPlayerToGenericServer(player, GenericServer.HUB, Intent.KICK);
} }
private void returnHubNoResPack(Player player, String message) private void returnHubNoResPack(Player player, String message)

View File

@ -1,6 +1,8 @@
package mineplex.core.status; package mineplex.core.status;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.serverdata.Region; import mineplex.serverdata.Region;
import mineplex.serverdata.commands.CommandCallback; import mineplex.serverdata.commands.CommandCallback;
@ -42,7 +44,7 @@ public class SuicideHandler implements CommandCallback
{ {
public void run() public void run()
{ {
Portal.getInstance().sendAllPlayers("Lobby"); Portal.getInstance().sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
} }
}, 60L); }, 60L);

View File

@ -6,6 +6,8 @@ import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.updater.command.BuildVersionCommand; import mineplex.core.updater.command.BuildVersionCommand;
import mineplex.core.updater.command.RestartServerCommand; import mineplex.core.updater.command.RestartServerCommand;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -79,7 +81,7 @@ public class FileUpdater extends MiniPlugin
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
player.sendMessage(F.main("Updater", message)); player.sendMessage(F.main("Updater", message));
_portal.sendPlayerToServer(player, "Lobby"); _portal.sendPlayerToGenericServer(player, GenericServer.HUB, Intent.KICK);
} }
} }
} }
@ -108,7 +110,7 @@ public class FileUpdater extends MiniPlugin
{ {
public void run() public void run()
{ {
_portal.sendAllPlayers("Lobby"); _portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
} }
}, 60L); }, 60L);

View File

@ -1,6 +1,8 @@
package mineplex.core.updater; package mineplex.core.updater;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.serverdata.Region; import mineplex.serverdata.Region;
import mineplex.serverdata.commands.CommandCallback; import mineplex.serverdata.commands.CommandCallback;
@ -60,7 +62,7 @@ public class RestartHandler implements CommandCallback, Listener
{ {
public void run() public void run()
{ {
Portal.getInstance().sendAllPlayers("Lobby"); Portal.getInstance().sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
} }
}, 60L); }, 60L);

View File

@ -1,16 +1,5 @@
package mineplex.core.utils; package mineplex.core.utils;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.mojang.authlib.GameProfile;
import mineplex.core.Managers;
import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.thread.ThreadPool;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.UUID; import java.util.UUID;
@ -19,6 +8,23 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.mojang.authlib.GameProfile;
import mineplex.core.Managers;
import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.thread.ThreadPool;
public class UtilGameProfile public class UtilGameProfile
{ {
private static final Cache<UUID, Boolean> TEXTURES = CacheBuilder.newBuilder() private static final Cache<UUID, Boolean> TEXTURES = CacheBuilder.newBuilder()
@ -28,13 +34,12 @@ public class UtilGameProfile
/** /**
* Get a {@link GameProfile} given a username. * Get a {@link GameProfile} given a username.
* * <p>
* If you desperately must block the current thread, you may pass a null Consumer and use Future.get() * If you desperately must block the current thread, you may pass a null Consumer and use Future.get()
* *
* @param username The username of the player * @param username The username of the player
* @param nonNull If true, an OfflinePlayer GameProfile will be returned should the username not be valid * @param nonNull If true, an OfflinePlayer GameProfile will be returned should the username not be valid
* @param fetched The Consumer which will receive the GameProfile instance. This Consumer will not be called on the main thread * @param fetched The Consumer which will receive the GameProfile instance. This Consumer will not be called on the main thread
*
* @return The GameProfile - always an unique instance * @return The GameProfile - always an unique instance
*/ */
public static Future<GameProfile> getProfileByName(String username, boolean nonNull, Consumer<GameProfile> fetched) public static Future<GameProfile> getProfileByName(String username, boolean nonNull, Consumer<GameProfile> fetched)
@ -95,7 +100,6 @@ public class UtilGameProfile
* Clones a GameProfile * Clones a GameProfile
* *
* @param input The GameProfile to clone * @param input The GameProfile to clone
*
* @return A copy of the GameProfile * @return A copy of the GameProfile
*/ */
public static GameProfile clone(GameProfile input) public static GameProfile clone(GameProfile input)
@ -112,7 +116,6 @@ public class UtilGameProfile
* Convert a string to a legal username equivalent * Convert a string to a legal username equivalent
* *
* @param in The original username * @param in The original username
*
* @returns A legal version of the username (with illegal characters stripped out * @returns A legal version of the username (with illegal characters stripped out
*/ */
public static String legalize(String in) public static String legalize(String in)
@ -122,6 +125,7 @@ public class UtilGameProfile
private static final Field GAME_PROFILE_NAME_FIELD; private static final Field GAME_PROFILE_NAME_FIELD;
private static final Field GAME_PROFILE_ID_FIELD; private static final Field GAME_PROFILE_ID_FIELD;
private static final Field SKULL_META_PROFILE_FIELD;
static static
{ {
@ -131,6 +135,8 @@ public class UtilGameProfile
GAME_PROFILE_NAME_FIELD.setAccessible(true); GAME_PROFILE_NAME_FIELD.setAccessible(true);
GAME_PROFILE_ID_FIELD = GameProfile.class.getDeclaredField("id"); GAME_PROFILE_ID_FIELD = GameProfile.class.getDeclaredField("id");
GAME_PROFILE_ID_FIELD.setAccessible(true); GAME_PROFILE_ID_FIELD.setAccessible(true);
SKULL_META_PROFILE_FIELD = Class.forName("org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaSkull").getDeclaredField("profile");
SKULL_META_PROFILE_FIELD.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers"); Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true); modifiersField.setAccessible(true);
@ -174,4 +180,28 @@ public class UtilGameProfile
{ {
return clone(((CraftPlayer) player).getProfile()); return clone(((CraftPlayer) player).getProfile());
} }
public static void setGameProfile(Player player, ItemStack stack)
{
setGameProfile(getGameProfile(player), stack);
}
public static void setGameProfile(GameProfile profile, ItemStack stack)
{
ItemMeta meta = stack.getItemMeta();
if (meta instanceof SkullMeta)
{
SkullMeta skullMeta = (SkullMeta) meta;
try
{
SKULL_META_PROFILE_FIELD.set(skullMeta, profile);
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
stack.setItemMeta(skullMeta);
}
}
} }

View File

@ -132,7 +132,7 @@ public class Clans extends JavaPlugin
Give.Initialize(this); Give.Initialize(this);
Teleport teleport = new Teleport(this, _clientManager); Teleport teleport = new Teleport(this, _clientManager);
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); Portal portal = new Portal();
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
ClansBanManager clansBans = new ClansBanManager(this, _clientManager, _donationManager); ClansBanManager clansBans = new ClansBanManager(this, _clientManager, _donationManager);

View File

@ -72,6 +72,8 @@ import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager; import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketHandler;
import mineplex.core.personalServer.PersonalServerManager; import mineplex.core.personalServer.PersonalServerManager;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
import mineplex.core.projectile.ProjectileManager; import mineplex.core.projectile.ProjectileManager;
@ -1269,7 +1271,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{ {
if (event.getMessage().toLowerCase().equals("/lobby") || event.getMessage().toLowerCase().equals("/hub") || event.getMessage().toLowerCase().equals("/leave")) if (event.getMessage().toLowerCase().equals("/lobby") || event.getMessage().toLowerCase().equals("/hub") || event.getMessage().toLowerCase().equals("/leave"))
{ {
Portal.getInstance().sendPlayerToServer(event.getPlayer(), "ClansHub"); Portal.getInstance().sendPlayerToGenericServer(event.getPlayer(), GenericServer.CLANS_HUB, Intent.PLAYER_REQUEST);
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

@ -24,7 +24,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerItemHeldEvent;
@ -32,13 +31,10 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.map.MapRenderer; import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView; import org.bukkit.map.MapView;
import com.google.common.base.Objects;
import com.google.common.collect.HashMultiset; import com.google.common.collect.HashMultiset;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Multisets; import com.google.common.collect.Multisets;
@ -46,7 +42,7 @@ import com.google.common.collect.Multisets;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.portal.ServerTransferEvent; import mineplex.core.portal.events.ServerTransferEvent;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;

View File

@ -13,6 +13,8 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.slack.SlackAPI; import mineplex.core.slack.SlackAPI;
import mineplex.core.slack.SlackMessage; import mineplex.core.slack.SlackMessage;
@ -143,7 +145,7 @@ public class RestartManager extends MiniPlugin
if (System.currentTimeMillis() >= _restartTime) if (System.currentTimeMillis() >= _restartTime)
{ {
_restarting = true; _restarting = true;
Portal.getInstance().sendAllPlayers("ClansHub"); Portal.getInstance().sendAllPlayersToGenericServer(GenericServer.CLANS_HUB, Intent.KICK);
runSyncLater(() -> runSyncLater(() ->
{ {
if (!_testServer) if (!_testServer)

View File

@ -15,6 +15,8 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilBlock;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
@ -138,7 +140,7 @@ public class TravelPage extends ShopPageBase<ClansManager, TravelShop>
{ {
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
{ {
Portal.getInstance().sendPlayerToServer(player, "Lobby"); Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.HUB, Intent.PLAYER_REQUEST);
} }
}); });
} }

View File

@ -122,7 +122,7 @@ public class ClansHub extends JavaPlugin
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
new TitanGiveawayManager(this, clientManager, serverStatusManager); new TitanGiveawayManager(this, clientManager, serverStatusManager);
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); Portal portal = new Portal();
AntiHack antiHack = require(AntiHack.class); AntiHack antiHack = require(AntiHack.class);
GuardianManager guardianManager = require(GuardianManager.class); GuardianManager guardianManager = require(GuardianManager.class);
@ -140,7 +140,7 @@ public class ClansHub extends JavaPlugin
EloManager eloManager = new EloManager(this, clientManager); EloManager eloManager = new EloManager(this, clientManager);
AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager);
PartyManager partyManager = new PartyManager(this, portal, clientManager, preferenceManager); PartyManager partyManager = new PartyManager();
CustomDataManager customDataManager = new CustomDataManager(this, clientManager); CustomDataManager customDataManager = new CustomDataManager(this, clientManager);

View File

@ -29,7 +29,7 @@ public class ClansServerShop extends ShopBase<ClansTransferManager>
@Override @Override
protected boolean canOpenShop(Player player) protected boolean canOpenShop(Player player)
{ {
Party party = getPlugin().getPartyManager().getParty(player); Party party = getPlugin().getPartyManager().getPartyByPlayer(player);
if (party != null) if (party != null)
{ {

View File

@ -19,6 +19,7 @@ import mineplex.core.npc.event.NpcInteractEntityEvent;
import mineplex.core.party.Lang; import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
@ -124,21 +125,10 @@ public class ClansTransferManager extends MiniDbClientPlugin<SimpleClanToken>
*/ */
public void selectServer(Player player, ServerInfo serverInfo) public void selectServer(Player player, ServerInfo serverInfo)
{ {
Party party = _party.getParty(player);
if (party != null)
{
if(!party.getOwner().equalsIgnoreCase(player.getName()))
{
Lang.NOT_OWNER_SERVER.send(player);
return;
}
_party.getJoinManager().requestServerJoin(serverInfo.Name, party);
return;
}
player.leaveVehicle(); player.leaveVehicle();
player.eject(); player.eject();
_portal.sendPlayerToServer(player, serverInfo.Name); _portal.sendPlayerToServer(player, serverInfo.Name, Intent.PLAYER_REQUEST);
} }
@EventHandler @EventHandler
@ -192,7 +182,7 @@ public class ClansTransferManager extends MiniDbClientPlugin<SimpleClanToken>
UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), _hub.GetSpawn()), 1, true, 0.5, 0, 1.0, true); UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), _hub.GetSpawn()), 1, true, 0.5, 0, 1.0, true);
return; return;
} }
if (_party.getParty(player) != null) if (_party.getPartyByPlayer(player) != null)
{ {
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
player.sendMessage(F.main("Party", "You cannot join Clans while in a party.")); player.sendMessage(F.main("Party", "You cannot join Clans while in a party."));
@ -235,7 +225,7 @@ public class ClansTransferManager extends MiniDbClientPlugin<SimpleClanToken>
} }
if (event.getNpc().getName().contains("Return")) if (event.getNpc().getName().contains("Return"))
{ {
_portal.sendToHub(event.getPlayer(), "Returning to Mineplex!"); _portal.sendToHub(event.getPlayer(), "Returning to Mineplex!", Intent.PLAYER_REQUEST);
} }
} }
@ -254,7 +244,7 @@ public class ClansTransferManager extends MiniDbClientPlugin<SimpleClanToken>
} }
if (event.getNpc().getName().contains("Return") && Recharge.Instance.use(player, "Return to Mineplex", 1000, false, false)) if (event.getNpc().getName().contains("Return") && Recharge.Instance.use(player, "Return to Mineplex", 1000, false, false))
{ {
_portal.sendToHub(player, "Returning to Mineplex!"); _portal.sendToHub(player, "Returning to Mineplex!", Intent.PLAYER_REQUEST);
} }
} }

View File

@ -3,7 +3,6 @@ package mineplex.clanshub;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -99,6 +98,8 @@ import mineplex.core.pet.PetManager;
import mineplex.core.playerCount.PlayerCountManager; import mineplex.core.playerCount.PlayerCountManager;
import mineplex.core.playwire.PlayWireManager; import mineplex.core.playwire.PlayWireManager;
import mineplex.core.poll.PollManager; import mineplex.core.poll.PollManager;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.preferences.Preference; import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
@ -293,7 +294,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
{ {
public void run() public void run()
{ {
_portal.sendAllPlayers("Lobby"); _portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable() Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
{ {
@ -332,7 +333,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
{ {
public void run() public void run()
{ {
_portal.sendPlayerToServer(event.getPlayer(), "ClansHub"); _portal.sendPlayerToGenericServer(event.getPlayer(), GenericServer.CLANS_HUB, Intent.KICK);
} }
}); });
@ -477,7 +478,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
//Party Chat //Party Chat
if (event.getMessage().charAt(0) == '#') if (event.getMessage().charAt(0) == '#')
{ {
Party party = _partyManager.getParty(player); Party party = _partyManager.getPartyByPlayer(player);
if (party != null) if (party != null)
{ {
event.getRecipients().clear(); event.getRecipients().clear();
@ -485,13 +486,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
event.setMessage(event.getMessage().substring(1, event.getMessage().length())); 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 + playerName + " " + C.cPurple + "%2$s");
for (UUID name : party.getMembersByUUID()) event.getRecipients().addAll(party.getMembers());
{
Player other = Bukkit.getPlayer(name);
if (other != null)
event.getRecipients().add(other);
}
} }
else else
{ {

View File

@ -147,7 +147,7 @@ public class Hub extends JavaPlugin implements IRelation
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
new TitanGiveawayManager(this, clientManager, serverStatusManager); new TitanGiveawayManager(this, clientManager, serverStatusManager);
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); Portal portal = new Portal();
AntiHack antiHack = require(AntiHack.class); AntiHack antiHack = require(AntiHack.class);
GuardianManager guardianManager = require(GuardianManager.class); GuardianManager guardianManager = require(GuardianManager.class);
@ -165,7 +165,7 @@ public class Hub extends JavaPlugin implements IRelation
EloManager eloManager = new EloManager(this, clientManager); EloManager eloManager = new EloManager(this, clientManager);
AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager);
PartyManager partyManager = new PartyManager(this, portal, clientManager, preferenceManager); PartyManager partyManager = new PartyManager();
SkillConditionManager conditionManager = new SkillConditionManager(this); SkillConditionManager conditionManager = new SkillConditionManager(this);

View File

@ -89,6 +89,8 @@ import mineplex.core.pet.PetManager;
import mineplex.core.playerCount.PlayerCountManager; import mineplex.core.playerCount.PlayerCountManager;
import mineplex.core.playwire.PlayWireManager; import mineplex.core.playwire.PlayWireManager;
import mineplex.core.poll.PollManager; import mineplex.core.poll.PollManager;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.preferences.Preference; import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
@ -423,7 +425,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
{ {
public void run() public void run()
{ {
_portal.sendAllPlayers("Lobby"); _portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable() Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
{ {
@ -484,7 +486,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
{ {
public void run() public void run()
{ {
_portal.sendPlayerToServer(event.getPlayer(), "Lobby"); _portal.sendPlayerToGenericServer(event.getPlayer(), GenericServer.HUB, Intent.KICK);
} }
}); });
@ -623,7 +625,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
//Party Chat //Party Chat
if (event.getMessage().charAt(0) == '@') if (event.getMessage().charAt(0) == '@')
{ {
Party party = _partyManager.getParty(player); Party party = _partyManager.getPartyByPlayer(player);
if (party != null) if (party != null)
{ {
event.getRecipients().clear(); event.getRecipients().clear();
@ -631,13 +633,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
event.setMessage(event.getMessage().substring(1, event.getMessage().length())); 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 + playerName + " " + C.cPurple + "%2$s");
for (String uuid: party.getMembers()) event.getRecipients().addAll(party.getMembers());
{
Player other = Bukkit.getPlayer(uuid);
if (other != null)
event.getRecipients().add(other);
}
} }
else else
{ {

View File

@ -8,14 +8,13 @@ import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.queue.PlayerMatchStatus; import mineplex.hub.queue.PlayerMatchStatus;
import mineplex.hub.queue.QueueManager; import mineplex.hub.queue.QueueManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class QueuePage extends ShopPageBase<QueueManager, QueueShop> public class QueuePage extends ShopPageBase<QueueManager, QueueShop>
{ {
@ -130,15 +129,15 @@ public class QueuePage extends ShopPageBase<QueueManager, QueueShop>
private void queuePlayer(int gameType, Player player) private void queuePlayer(int gameType, Player player)
{ {
Party party = getPlugin().getPartyManager().getParty(player); Party party = getPlugin().getPartyManager().getPartyByPlayer(player);
if(party == null) if(party == null)
{ {
getPlugin().queuePlayer(gameType, player); getPlugin().queuePlayer(gameType, player);
return; return;
} }
if(party.getOwner().equalsIgnoreCase(player.getName())) if(party.getOwnerName().equalsIgnoreCase(player.getName()))
{ {
List<Player> players = party.getMembers().stream().map(Bukkit::getPlayer).collect(Collectors.toList()); List<Player> players = party.getMembers();
getPlugin().queuePlayer(gameType, players.toArray(new Player[players.size()])); getPlugin().queuePlayer(gameType, players.toArray(new Player[players.size()]));
} }
buildPage(); buildPage();

View File

@ -29,22 +29,6 @@ public class QueueShop extends ShopBase<QueueManager>
return new QueuePage(getPlugin(), this, getClientManager(), getDonationManager(), " " + ChatColor.UNDERLINE + "Queuer 9001", player); return new QueuePage(getPlugin(), this, getClientManager(), getDonationManager(), " " + ChatColor.UNDERLINE + "Queuer 9001", player);
} }
@Override
protected boolean canOpenShop(Player player)
{
Party party = getPlugin().getPartyManager().getParty(player);
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;
}
@EventHandler @EventHandler
public void UpdatePages(UpdateEvent event) public void UpdatePages(UpdateEvent event)
{ {

View File

@ -20,6 +20,7 @@ import mineplex.core.party.Lang;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
import mineplex.core.party.event.PartySelectServerEvent; import mineplex.core.party.event.PartySelectServerEvent;
import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.shop.ShopBase; import mineplex.core.shop.ShopBase;
import mineplex.core.status.ServerStatusManager; import mineplex.core.status.ServerStatusManager;
@ -453,21 +454,10 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider
public void selectServer(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.leaveVehicle();
player.eject(); player.eject();
_portal.sendPlayerToServer(player, serverInfo.Name); _portal.sendPlayerToServer(player, serverInfo.Name, Intent.PLAYER_REQUEST);
} }
/** /**

View File

@ -37,22 +37,6 @@ public class ServerNpcShop extends ShopBase<ServerManager>
} }
@Override
protected boolean canOpenShop(Player player)
{
Party party = getPlugin().getPartyManager().getParty(player);
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;
}
public void UpdatePages() public void UpdatePages()
{ {
for (ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> page : getPlayerPageMap().values()) for (ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> page : getPlayerPageMap().values())

View File

@ -36,7 +36,7 @@ public class ClanMoveServerShop extends ShopBase<ServerManager>
@Override @Override
protected boolean canOpenShop(Player player) protected boolean canOpenShop(Player player)
{ {
Party party = getPlugin().getPartyManager().getParty(player); Party party = getPlugin().getPartyManager().getPartyByPlayer(player);
if (party != null) if (party != null)
{ {

View File

@ -27,7 +27,7 @@ public class ClansServerShop extends ShopBase<ServerManager>
@Override @Override
protected boolean canOpenShop(Player player) protected boolean canOpenShop(Player player)
{ {
Party party = getPlugin().getPartyManager().getParty(player); Party party = getPlugin().getPartyManager().getPartyByPlayer(player);
if (party != null) if (party != null)
{ {

View File

@ -28,5 +28,9 @@
<groupId>redis.clients</groupId> <groupId>redis.clients</groupId>
<artifactId>jedis</artifactId> <artifactId>jedis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.mineplex</groupId>
<artifactId>spigot</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

Some files were not shown because too many files have changed in this diff Show More