Parties rewrite
Basically everything got changed. Also Portal has a slightly better API now
This commit is contained in:
parent
91773de97e
commit
56d4ed9e11
@ -152,7 +152,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
|
||||
}
|
||||
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)
|
||||
{
|
||||
throw new RuntimeException(exception);
|
||||
exception.initCause(t);
|
||||
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
|
||||
}
|
||||
}, time);
|
||||
}
|
||||
@ -186,7 +188,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new RuntimeException(exception);
|
||||
exception.initCause(t);
|
||||
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
|
||||
}
|
||||
}, time, period);
|
||||
}
|
||||
@ -203,7 +206,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
|
||||
}
|
||||
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)
|
||||
{
|
||||
throw new RuntimeException(exception);
|
||||
exception.initCause(t);
|
||||
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
@ -242,7 +247,8 @@ public abstract class MiniPlugin implements Listener, Lifetimed
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new RuntimeException(exception);
|
||||
exception.initCause(t);
|
||||
throw new RuntimeException("Exception while executing MiniPlugin task", exception);
|
||||
}
|
||||
}, delay, period);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
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.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import mineplex.cache.player.PlayerCache;
|
||||
@ -65,6 +67,8 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
private final Rank WHITELIST_BYPASS;
|
||||
|
||||
private final Set<UUID> _reservedSlots = Sets.newConcurrentHashSet();
|
||||
|
||||
public CoreClientManager(JavaPlugin plugin, String webServer)
|
||||
{
|
||||
this(plugin, webServer, Rank.MODERATOR);
|
||||
@ -254,7 +258,9 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
if (uuid == null)
|
||||
{
|
||||
uuid = UtilGameProfile.getProfileByName(playerName, false, profile -> {}).get().getId();
|
||||
uuid = UtilGameProfile.getProfileByName(playerName, false, profile ->
|
||||
{
|
||||
}).get().getId();
|
||||
}
|
||||
|
||||
String response = "";
|
||||
@ -476,8 +482,10 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
client.SetPlayer(event.getPlayer());
|
||||
|
||||
_reservedSlots.remove(event.getPlayer().getUniqueId());
|
||||
|
||||
// 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))
|
||||
{
|
||||
@ -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
|
||||
public void Kick(PlayerKickEvent event)
|
||||
{
|
||||
|
@ -28,14 +28,14 @@ public class PartyInfoMetadata extends AnticheatMetadata
|
||||
@Override
|
||||
public JsonElement build(UUID player)
|
||||
{
|
||||
Party party = require(PartyManager.class).getPlayerParties().get(player);
|
||||
Party party = require(PartyManager.class).getPartyByPlayer(player);
|
||||
if (party != null)
|
||||
{
|
||||
JsonObject partyData = new JsonObject();
|
||||
partyData.addProperty(KEY_OWNER, party.getOwner());
|
||||
partyData.addProperty(KEY_OWNER, party.getOwnerName());
|
||||
|
||||
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);
|
||||
|
||||
|
@ -34,13 +34,11 @@ public abstract class PlayerInputActionMenu implements Listener
|
||||
protected Inventory _currentInventory;
|
||||
protected String _itemName = "";
|
||||
protected boolean _searching;
|
||||
protected Party _party;
|
||||
|
||||
public PlayerInputActionMenu(MiniPlugin plugin, Player player, Party party)
|
||||
public PlayerInputActionMenu(MiniPlugin plugin, Player player)
|
||||
{
|
||||
_player = player;
|
||||
_plugin = plugin;
|
||||
_party = party;
|
||||
player.closeInventory();
|
||||
_plugin.registerEvents(this);
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static net.minecraft.server.v1_8_R3.PotionBrewer.n;
|
||||
|
||||
/**
|
||||
* A wrapped menu that handles looking for players specifically.
|
||||
*/
|
||||
@ -21,9 +19,9 @@ public abstract class PlayerNameMenu extends PlayerInputActionMenu
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ import mineplex.core.friend.data.FriendData;
|
||||
import mineplex.core.friend.data.FriendStatus;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.itemstack.ItemLayout;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
|
||||
public class FriendsGUI implements Listener
|
||||
@ -302,7 +303,7 @@ public class FriendsGUI implements Listener
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
_plugin.getPortal().sendPlayerToServer(player, serverName);
|
||||
_plugin.getPortal().sendPlayerToServer(player, serverName, Intent.PLAYER_REQUEST);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,27 +1,59 @@
|
||||
package mineplex.core.party;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Serializable invite data
|
||||
*/
|
||||
public class InviteData
|
||||
{
|
||||
private final String _inviterName;
|
||||
private final UUID _inviterUUID;
|
||||
private final UUID _partyUUID;
|
||||
private final String _serverName;
|
||||
|
||||
private String _invitedTo;
|
||||
private String _serverFrom;
|
||||
|
||||
public InviteData(String invitedTo, String serverFrom)
|
||||
public InviteData(String inviterName, UUID inviterUUID, UUID partyUUID, String serverName)
|
||||
{
|
||||
_invitedTo = invitedTo;
|
||||
_serverFrom = serverFrom;
|
||||
_inviterName = inviterName;
|
||||
_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();
|
||||
}
|
||||
}
|
||||
|
@ -1,163 +1,119 @@
|
||||
package mineplex.core.party;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.party.constants.PartyRemoveReason;
|
||||
import mineplex.core.party.event.PartyTransferOwnerEvent;
|
||||
import mineplex.core.party.event.PartyTransferOwnerEvent.TransferReason;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
private static final int PARTY_MAX_SIZE = 16;
|
||||
|
||||
/**
|
||||
* Partners that have already been placed
|
||||
*/
|
||||
private transient final List<UUID> _teamed;
|
||||
private final PartyManager _partyManager = Managers.require(PartyManager.class);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* All current pending invites
|
||||
*/
|
||||
private Map<String, Long> _invites;
|
||||
private List<Player> _members = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* This party's max size
|
||||
*/
|
||||
private int _size;
|
||||
private int _size = PARTY_MAX_SIZE;
|
||||
|
||||
/**
|
||||
* Team preferences
|
||||
*/
|
||||
private Map<UUID, Map<String, String>> _preferences;
|
||||
private List<UUID> _pendingUnrankedMembers = new ArrayList<>();
|
||||
private List<UUID> _pendingMembers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Empty constructor for GSON
|
||||
*/
|
||||
public Party()
|
||||
public Party(PartyTransferRequest request)
|
||||
{
|
||||
_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.
|
||||
*/
|
||||
public Party(String owner)
|
||||
public Party(Player owner)
|
||||
{
|
||||
_owner = owner;
|
||||
_members = Lists.newArrayList();
|
||||
_invites = Maps.newHashMap();
|
||||
_owner = UtilGameProfile.getGameProfile(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current members by their IGN
|
||||
*
|
||||
* @return The list of named party members
|
||||
*/
|
||||
public List<String> getMembers()
|
||||
public Optional<Player> getOwnerAsPlayer()
|
||||
{
|
||||
return _members;
|
||||
return Optional.ofNullable(Bukkit.getPlayer(_owner.getId()));
|
||||
}
|
||||
|
||||
public Map<String, Long> getInvites()
|
||||
public UUID getUniqueId()
|
||||
{
|
||||
return _invites;
|
||||
}
|
||||
|
||||
/**
|
||||
* An alternate method to get the owner of the party.
|
||||
* While this does not have any difference to using {@code getOwner}, it may serve a purpose in the future, should we wish to allow
|
||||
* donators to name their party something custom.
|
||||
*
|
||||
* @return This party's name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
return this._uniqueId;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,9 +123,7 @@ public class Party
|
||||
*/
|
||||
public void sendMessage(String message)
|
||||
{
|
||||
// Todo actually figure out why one of the members is no longer online
|
||||
// probably some desync between players and something
|
||||
_members.stream().map(Bukkit::getPlayer).filter(Objects::nonNull).forEach(player -> player.sendMessage(message));
|
||||
getMembers().forEach(player -> player.sendMessage(message));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player is added to the party.
|
||||
*
|
||||
* @param player The name of the player
|
||||
*/
|
||||
public void onPlayerAdd(String player)
|
||||
public boolean isMember(Player player)
|
||||
{
|
||||
_invites.remove(player);
|
||||
if(_members.contains(player))
|
||||
return _members.contains(player);
|
||||
}
|
||||
|
||||
public void addMember(Player player)
|
||||
{
|
||||
if (_members.contains(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_members.add(player);
|
||||
Lang.ADD_MEMBER.send(this, player);
|
||||
getMembers().forEach(s ->
|
||||
{
|
||||
Player player1 = Bukkit.getPlayer(s);
|
||||
player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F);
|
||||
});
|
||||
_pendingMembers.remove(player.getUniqueId());
|
||||
_pendingUnrankedMembers.remove(player.getUniqueId());
|
||||
Lang.ADD_MEMBER.send(this, player.getName());
|
||||
getMembers().forEach(player1 -> player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a member of the party is removed
|
||||
*
|
||||
* @param player The name of the player
|
||||
* @param reason The reason for his removal.
|
||||
*/
|
||||
public void onPlayerRemove(String player, PartyRemoveReason reason)
|
||||
public List<Player> getMembers()
|
||||
{
|
||||
if(reason == PartyRemoveReason.DISBANDED)
|
||||
{
|
||||
Player bukkitPlayer = Bukkit.getPlayerExact(player);
|
||||
Lang.DISBANDED.send(bukkitPlayer);
|
||||
bukkitPlayer.closeInventory();
|
||||
return;
|
||||
}
|
||||
return Collections.unmodifiableList(_members);
|
||||
}
|
||||
|
||||
if(_members.size() <= 0)
|
||||
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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(reason == PartyRemoveReason.LEFT)
|
||||
{
|
||||
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;
|
||||
}
|
||||
System.out.println("Removing member: " + player.getName() + " "+ player.getUniqueId() + " owner is " + _owner.getId());
|
||||
|
||||
if(reason == PartyRemoveReason.OTHER)
|
||||
if (player.getUniqueId().equals(_owner.getId()) && _members.size() > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(reason == PartyRemoveReason.KICKED)
|
||||
{
|
||||
Lang.REMOVE_PLAYER_KICK.send(this, player);
|
||||
_owner = UtilGameProfile.getGameProfile(_members.get(0));
|
||||
Lang.TRANSFER_OWNER.send(this, player.getName(), _owner.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,66 +213,4 @@ public class Party
|
||||
{
|
||||
_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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +1,55 @@
|
||||
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.util.HashMap;
|
||||
import java.util.Map;
|
||||
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
|
||||
{
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
@ -43,66 +60,73 @@ public class PartyManager extends MiniPlugin
|
||||
private final PartyRedisManager _redisManager;
|
||||
private final PartyInviteManager _inviteManager;
|
||||
private final PartyJoinManager _joinManager;
|
||||
private final PartyMethodManager _methodManager;
|
||||
|
||||
/**
|
||||
* This local instance's name
|
||||
*/
|
||||
private final String _serverName;
|
||||
|
||||
/**
|
||||
* A map of player's in parties server wide.
|
||||
*/
|
||||
private final Map<UUID, Party> _players = Maps.newHashMap();
|
||||
private final Map<UUID, Party> _partiesById = new HashMap<>();
|
||||
private final Map<UUID, Party> _partiesByPlayer = new HashMap<>();
|
||||
|
||||
/**
|
||||
* A map of owner (name) -> party server wide
|
||||
*/
|
||||
private final Map<String, Party> _parties = Maps.newHashMap();
|
||||
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);
|
||||
_portal = portal;
|
||||
_clientManager = clientManager;
|
||||
_preferencesManager = preferenceManager;
|
||||
super("Parties");
|
||||
_portal = require(Portal.class);
|
||||
_clientManager = require(CoreClientManager.class);
|
||||
_preferencesManager = require(PreferencesManager.class);
|
||||
|
||||
_serverName = _plugin.getConfig().getString("serverstatus.name");
|
||||
_serverName = UtilServer.getServerName();
|
||||
|
||||
_redisManager = new PartyRedisManager(this, _serverName,
|
||||
Utility.generatePool(ServerManager.getMasterConnection()),
|
||||
Utility.generatePool(ServerManager.getSlaveConnection()));
|
||||
Utility.generatePool(ServerManager.getMasterConnection()),
|
||||
Utility.generatePool(ServerManager.getSlaveConnection()));
|
||||
|
||||
_inviteManager = new PartyInviteManager(this, _redisManager);
|
||||
_inviteManager = new PartyInviteManager(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;
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_parties.put(party.getName(), party);
|
||||
}
|
||||
|
||||
public void removeParty(Party party)
|
||||
{
|
||||
_parties.remove(party.getName());
|
||||
_partiesById.put(party.getUniqueId(), party);
|
||||
}
|
||||
|
||||
public Portal getPortal()
|
||||
@ -135,29 +159,424 @@ public class PartyManager extends MiniPlugin
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -1,95 +1,54 @@
|
||||
package mineplex.core.party.command;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.core.party.ui.menus.PartyInvitesMenu;
|
||||
import mineplex.core.party.ui.menus.PartyMainMenu;
|
||||
import mineplex.core.party.ui.menus.PartyOwnerMenu;
|
||||
import mineplex.core.party.ui.menus.PartyViewMenu;
|
||||
import java.util.Arrays;
|
||||
|
||||
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
|
||||
*/
|
||||
public class PartyCommand extends CommandBase<PartyManager>
|
||||
public class PartyCommand extends MultiCommandBase<PartyManager>
|
||||
{
|
||||
|
||||
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!"
|
||||
};
|
||||
private final PreferencesManager _preferencesManager = Managers.require(PreferencesManager.class);
|
||||
|
||||
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
|
||||
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);
|
||||
return;
|
||||
String[] newArgs = new String[args.length + 1];
|
||||
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()))
|
||||
{
|
||||
new PartyOwnerMenu(party, Plugin).open(caller);
|
||||
return;
|
||||
}
|
||||
new PartyViewMenu(party, Plugin).open(caller);
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length == 1)
|
||||
else
|
||||
{
|
||||
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;
|
||||
String[] newArgs = new String[1];
|
||||
newArgs[0] = _preferencesManager.get(caller).isActive(Preference.PARTY_DISPLAY_INVENTORY_UI) ? "gui" : "cli";
|
||||
args = newArgs;
|
||||
}
|
||||
caller.sendMessage(HELP);
|
||||
Execute(caller, args);
|
||||
}
|
||||
|
||||
private String help(String command, String description)
|
||||
{
|
||||
return C.cBlue + "Party> " + C.cWhite + "/party " + command + C.cGray + " - " + description;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 + "!"));
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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"));
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -1,173 +1,154 @@
|
||||
package mineplex.core.party.manager;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.party.InviteData;
|
||||
import mineplex.core.party.Lang;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.core.party.constants.InviteResponse;
|
||||
import mineplex.core.party.redis.RedisMessageType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent.Action;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.spigotmc.CaseInsensitiveMap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.party.InviteData;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.PartyManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class manages invites to parties
|
||||
*/
|
||||
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, 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 Map<UUID, BukkitTask> _tasks = new HashMap<>();
|
||||
|
||||
private final PartyManager _plugin;
|
||||
private final PartyRedisManager _partyRedisManager;
|
||||
|
||||
public PartyInviteManager(PartyManager plugin, PartyRedisManager partyRedisManager)
|
||||
public PartyInviteManager(PartyManager plugin)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_partyRedisManager = partyRedisManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds to an invite, regardless of the server
|
||||
*
|
||||
* @param player The player calling
|
||||
* @param party The party
|
||||
* @param accept Whether or not the player accepted the invite
|
||||
*/
|
||||
public void respondToInvite(Player player, String party, boolean accept)
|
||||
public InviteData getInviteBySender(String invitee, String sender)
|
||||
{
|
||||
Player possible = Bukkit.getPlayerExact(party);
|
||||
Set<InviteData> map = _activeInvites.get(invitee);
|
||||
|
||||
InviteData data = remove(party, player.getUniqueId());
|
||||
if (map == null) return null;
|
||||
|
||||
_players.remove(player.getUniqueId());
|
||||
cancelTask(player.getUniqueId());
|
||||
|
||||
if(possible != null)
|
||||
for (InviteData inviteData : map)
|
||||
{
|
||||
Party newParty = _plugin.getParty(party);
|
||||
if(!accept)
|
||||
if (inviteData.getInviterName().equalsIgnoreCase(sender))
|
||||
{
|
||||
String message = C.mHead + "Party> " + C.mBody + InviteResponse.DENIED.format(player.getName());
|
||||
if (newParty == null)
|
||||
{
|
||||
possible.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
newParty.sendMessage(message);
|
||||
return;
|
||||
return inviteData;
|
||||
}
|
||||
if (newParty == null)
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a caller has an invite by a sender's name
|
||||
* @param caller
|
||||
* @param sender
|
||||
* @return
|
||||
*/
|
||||
public boolean hasInviteFrom(Player caller, String sender)
|
||||
{
|
||||
return getInviteBySender(caller.getName(), sender) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a caller has an invite by a party id
|
||||
* @param caller
|
||||
* @param partyId
|
||||
* @return
|
||||
*/
|
||||
public boolean hasInviteTo(String caller, UUID partyId)
|
||||
{
|
||||
Set<InviteData> map = _activeInvites.get(caller);
|
||||
|
||||
if (map == null) return false;
|
||||
|
||||
for (InviteData inviteData : map)
|
||||
{
|
||||
if (inviteData.getPartyUUID().equals(partyId))
|
||||
{
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
_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());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a received response via redis
|
||||
*
|
||||
* @param sender The player sending the request
|
||||
* @param target The player target
|
||||
* @param serverFrom The server initiating the request
|
||||
* Remove a player's invite to a party by id
|
||||
* @param caller
|
||||
* @param partyId
|
||||
* @return
|
||||
*/
|
||||
public void handleInviteRequest(String sender, String target, String serverFrom)
|
||||
public InviteData removeInviteTo(String caller, UUID partyId)
|
||||
{
|
||||
Player player = Bukkit.getPlayerExact(target);
|
||||
if (player == null)
|
||||
Set<InviteData> map = _activeInvites.get(caller);
|
||||
|
||||
if (map == null) return null;
|
||||
|
||||
Iterator<InviteData> itr = map.iterator();
|
||||
|
||||
while (itr.hasNext())
|
||||
{
|
||||
//Shouldn't happen, as a "findPLayer" packet will be sent out first.
|
||||
return;
|
||||
InviteData ent = itr.next();
|
||||
if (ent.getPartyUUID().equals(partyId))
|
||||
{
|
||||
itr.remove();
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
_players.put(player.getUniqueId(), player.getName());
|
||||
inviteTo(player.getUniqueId(), sender, sender, serverFrom);
|
||||
Lang.INVITE_RECEIVED.send(player, sender);
|
||||
sendAcceptOrDeny(player, sender);
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the response returned via redis when an invite is handled cross server
|
||||
*
|
||||
* @param sender The player sender
|
||||
* @param target The player target
|
||||
* @param targetUUID The player targets UUID
|
||||
* @param response The response to this invite
|
||||
* Remove a player's invite to a certain party
|
||||
*/
|
||||
public void handleInviteResponse(String sender, String target, UUID targetUUID, InviteResponse response)
|
||||
public InviteData removeInvite(Player invitee, String inviter)
|
||||
{
|
||||
remove(sender, targetUUID);
|
||||
Player player = Bukkit.getPlayer(sender);
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
String message = F.main("Party", response.format(target));
|
||||
Set<InviteData> map = _activeInvites.get(invitee.getName());
|
||||
|
||||
Party party = _plugin.getParty(sender);
|
||||
String partyName = sender;
|
||||
if(party != null)
|
||||
if (map == null) return null;
|
||||
|
||||
Iterator<InviteData> itr = map.iterator();
|
||||
|
||||
while (itr.hasNext())
|
||||
{
|
||||
partyName = party.getName();
|
||||
InviteData ent = itr.next();
|
||||
if (ent.getInviterName().equalsIgnoreCase(inviter))
|
||||
{
|
||||
itr.remove();
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
|
||||
switch (response)
|
||||
{
|
||||
case ACCEPTED:
|
||||
addToPendingJoin(targetUUID, partyName);
|
||||
break;
|
||||
case EXPIRED:
|
||||
case DENIED:
|
||||
if (party == null)
|
||||
{
|
||||
player.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
party.sendMessage(message);
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,191 +156,65 @@ public class PartyInviteManager
|
||||
*
|
||||
* @param player The player's UUID
|
||||
*/
|
||||
public void removeAll(UUID player)
|
||||
public void removeAll(Player player)
|
||||
{
|
||||
_players.remove(player);
|
||||
_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();
|
||||
}
|
||||
_activeInvites.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all invites currently pending for a specific player
|
||||
*
|
||||
* @param player The player
|
||||
* @return All his current pending invites
|
||||
*/
|
||||
public Collection<InviteData> getAllInvites(Player player)
|
||||
public 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 party The party who initiated the request (can also be a player's name)
|
||||
* @param playerName The name of the invited player
|
||||
* @param player The invited player's UUID
|
||||
* @param inviterName
|
||||
* @param inviterUUID
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Marks this player as having an accepted invite
|
||||
* This is used to control the creation of single player parties, and makes sure a party is created ONLY if a player joins the server successfully.
|
||||
*
|
||||
* @param player The UUID of the player
|
||||
* @param party The name of the party
|
||||
*/
|
||||
private void addToPendingJoin(UUID player, String party)
|
||||
{
|
||||
_awaitingJoin.put(player, party);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a pending invite for a player
|
||||
*
|
||||
* @param invited The invited players UUUD
|
||||
* @param invitedBy The person who invited him
|
||||
* @param party The name of the party invited to
|
||||
* @param server The server the request is from
|
||||
*/
|
||||
private void addToInvite(UUID invited, String invitedBy, String party, String server)
|
||||
{
|
||||
List<InviteData> inviteDatas = _activeInvites.get(invited);
|
||||
if (inviteDatas == null)
|
||||
if (map.add(inviteData))
|
||||
{
|
||||
inviteDatas = Lists.newArrayList();
|
||||
_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);
|
||||
if (possible != null)
|
||||
{
|
||||
Party curParty = _plugin.getPartyByPlayer(possible);
|
||||
if (curParty != null && !curParty.getUniqueId().equals(data.getPartyUUID()))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a Text Componoent clickable message to a player for easier quick responses to invites
|
||||
*
|
||||
* @param player The player who received the invite
|
||||
* @param arg The name of the inviting party
|
||||
* @param arg The name of the inviting party
|
||||
*/
|
||||
public void sendAcceptOrDeny(Player player, String arg)
|
||||
{
|
||||
@ -368,9 +223,9 @@ public class PartyInviteManager
|
||||
TextComponent accept = new TextComponent("ACCEPT");
|
||||
accept.setColor(ChatColor.GREEN);
|
||||
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[]{
|
||||
new TextComponent("Click to join " + F.name(arg) + "'s party")
|
||||
new TextComponent("Click to join " + F.name(arg) + "'s party")
|
||||
}));
|
||||
|
||||
textComponent.addExtra(accept);
|
||||
@ -379,9 +234,9 @@ public class PartyInviteManager
|
||||
TextComponent deny = new TextComponent("DENY");
|
||||
deny.setColor(ChatColor.RED);
|
||||
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[]{
|
||||
new TextComponent("Click to decline joining " + F.name(arg) + "'s party")
|
||||
new TextComponent("Click to decline joining " + F.name(arg) + "'s party")
|
||||
}));
|
||||
|
||||
textComponent.addExtra(deny);
|
||||
@ -390,13 +245,14 @@ public class PartyInviteManager
|
||||
TextComponent view = new TextComponent("VIEW");
|
||||
view.setColor(ChatColor.YELLOW);
|
||||
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[]{
|
||||
new TextComponent("Click to view all pending invites.")
|
||||
new TextComponent("Click to view all pending invites.")
|
||||
}));
|
||||
|
||||
textComponent.addExtra(view);
|
||||
|
||||
player.spigot().sendMessage(textComponent);
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F);
|
||||
}
|
||||
}
|
||||
|
@ -1,137 +1,356 @@
|
||||
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.Maps;
|
||||
|
||||
import mineplex.core.command.CommandCenter;
|
||||
import mineplex.core.common.Rank;
|
||||
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.party.Lang;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.core.party.constants.JoinResponseReason;
|
||||
import mineplex.core.party.redis.RedisMessageType;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import mineplex.core.party.constants.PartyRemoveReason;
|
||||
import mineplex.core.party.rediscommands.PartyTransferRequest;
|
||||
import mineplex.core.party.rediscommands.PartyTransferResponse;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.events.GenericServerTransferEvent;
|
||||
import mineplex.core.portal.events.ServerTransferEvent;
|
||||
import mineplex.core.utils.UtilGameProfile;
|
||||
import mineplex.serverdata.commands.ServerCommandManager;
|
||||
import mineplex.serverdata.data.MinecraftServer;
|
||||
|
||||
/**
|
||||
* Manages allocating slots for parties to join
|
||||
*/
|
||||
public class PartyJoinManager
|
||||
public class PartyJoinManager implements Listener
|
||||
{
|
||||
|
||||
private final PartyManager _plugin;
|
||||
private final int _maxPLayers;
|
||||
private final List<UUID> _transferring;
|
||||
private final int _maxPlayers;
|
||||
|
||||
private final Map<UUID, BukkitTask> _pendingTransfers = new ConcurrentHashMap<>();
|
||||
|
||||
public PartyJoinManager(PartyManager plugin)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_maxPLayers = plugin.getPlugin().getServer().getMaxPlayers();
|
||||
_transferring = Lists.newArrayList();
|
||||
}
|
||||
_maxPlayers = plugin.getPlugin().getServer().getMaxPlayers();
|
||||
|
||||
/**
|
||||
* 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());
|
||||
for (Player player : players)
|
||||
UtilServer.RegisterEvents(this);
|
||||
|
||||
ServerCommandManager.getInstance().registerCommandType(PartyTransferRequest.class, command ->
|
||||
{
|
||||
Rank rank = _plugin.getClientManager().Get(player).GetRank();
|
||||
if (rank == Rank.ALL)
|
||||
if (!command.isSentToThisServer())
|
||||
return;
|
||||
|
||||
_plugin.runSync(() ->
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
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())
|
||||
{
|
||||
_plugin.getClientManager().reserveFor(uuid);
|
||||
}
|
||||
|
||||
Party newParty = new Party(command);
|
||||
|
||||
_plugin.addParty(newParty);
|
||||
|
||||
for (UUID uuid : command.getAllMembers())
|
||||
{
|
||||
_plugin.putIntoPendingJoin(uuid, newParty.getUniqueId());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates a request to join a server for a specific party
|
||||
*
|
||||
* @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);
|
||||
_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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
ServerManager.getServerRepository(_plugin.getRegion()).getServerStatus(_plugin.getServerName()).incrementPlayerCount(partySize);
|
||||
_plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), _plugin.getServerName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (player == null)
|
||||
if (_pendingTransfers.containsKey(party.getUniqueId()))
|
||||
{
|
||||
party.sendMessage(F.main("Party", "Please wait until your current transfer is complete"));
|
||||
return;
|
||||
}
|
||||
Party party = _plugin.getParty(player);
|
||||
|
||||
List<UUID> unranked = new ArrayList<>();
|
||||
List<UUID> all = new ArrayList<>();
|
||||
for (Player player : party.getMembers())
|
||||
{
|
||||
if (_plugin.getClientManager().Get(player).GetRank() == Rank.ALL)
|
||||
{
|
||||
unranked.add(player.getUniqueId());
|
||||
}
|
||||
all.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
_pendingTransfers.put(party.getUniqueId(), _plugin.runSyncLater(() ->
|
||||
{
|
||||
_pendingTransfers.remove(party.getUniqueId());
|
||||
|
||||
if (party.getMembers().size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
party.sendMessage(F.main("Party", "Transferring servers..."));
|
||||
_plugin.getRedisManager().sendPartyInfo(server, party);
|
||||
_transferring.addAll(party.getMembersByUUID());
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (!party.getOwnerName().equalsIgnoreCase(player.getName()))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether or not the player is currently transferring servers
|
||||
* We wont need this information again, so calling a remove works fine.
|
||||
*
|
||||
* @param player The player
|
||||
* @return <code>true</code> if the player is transferring servers
|
||||
*/
|
||||
public boolean isTransferring(Player player)
|
||||
@EventHandler
|
||||
public void onTransfer(ServerTransferEvent event)
|
||||
{
|
||||
return _transferring.remove(player.getUniqueId());
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,296 +1,188 @@
|
||||
package mineplex.core.party.manager;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.party.Lang;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.core.party.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.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static mineplex.core.party.redis.RedisMessageType.INVITE_PLAYER_REQUEST;
|
||||
import static mineplex.core.party.redis.RedisMessageType.PARTY_INFO;
|
||||
import org.bukkit.Bukkit;
|
||||
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
|
||||
{
|
||||
protected final Gson GSON = new GsonBuilder().create();
|
||||
|
||||
protected static final String CHANNEL_BASE = "party-pubsub";
|
||||
protected static final String FIND_PLAYERS_CHANNEL = "party-player-finder";
|
||||
private final Map<String, BukkitTask> TASKS = Maps.newHashMap();
|
||||
private final Map<UUID, Map<String, BukkitTask>> _pendingFindResponse = new HashMap<>();
|
||||
|
||||
private final PartyManager _plugin;
|
||||
private final JedisPool _writePool;
|
||||
private final String _channel;
|
||||
private final String _serverName;
|
||||
|
||||
public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_serverName = serverName;
|
||||
_writePool = writePool;
|
||||
_channel = CHANNEL_BASE + "-" + serverName;
|
||||
|
||||
plugin.runAsync(() -> {
|
||||
try (Jedis jedis = readPool.getResource())
|
||||
{
|
||||
jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(() -> {
|
||||
try (Jedis jedis = _writePool.getResource())
|
||||
{
|
||||
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)
|
||||
ServerCommandManager.getInstance().registerCommandType(PartyCrossServerInviteCommand.class, command ->
|
||||
{
|
||||
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)
|
||||
_plugin.runSync(() ->
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if(_plugin.getParty(player) != null)
|
||||
{
|
||||
publish(first, RedisMessageType.INVITE_PLAYER_ALREADY_IN_PARTY, _serverName, player.getName(), player.getUniqueId().toString(), third);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_plugin.getPreferencesManager().get(player).isActive(Preference.PARTY_REQUESTS))
|
||||
{
|
||||
publish(first, RedisMessageType.INVITE_PLAYER_NOT_ACCEPTING_INVITES, _serverName, player.getName(), player.getUniqueId().toString(), third);
|
||||
return;
|
||||
}
|
||||
|
||||
publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third);
|
||||
break;
|
||||
|
||||
case INVITE_PLAYER_ALREADY_IN_PARTY:
|
||||
handleAlreadyIn(second, contents);
|
||||
break;
|
||||
|
||||
case INVITE_PLAYER_NOT_ACCEPTING_INVITES:
|
||||
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);
|
||||
return;
|
||||
}
|
||||
if (_plugin.getParty(inviter) == null)
|
||||
{
|
||||
Lang.INVITE_SUCCESS_PLAYER.send(inviter, second);
|
||||
} else
|
||||
{
|
||||
Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second);
|
||||
}
|
||||
_plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName());
|
||||
publish(first, INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second);
|
||||
break;
|
||||
|
||||
case PREJOIN_SERVER_REQUEST:
|
||||
_plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3]));
|
||||
break;
|
||||
|
||||
case PREJOIN_SERVER_RESPONSE:
|
||||
_plugin.getJoinManager().handleJoinResponse(first, third, JoinResponseReason.valueOf(second.toUpperCase()));
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void handleNotAccepting(String second, String[] contents)
|
||||
{
|
||||
cancelTask(second);
|
||||
|
||||
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 inviter = Bukkit.getPlayerExact(contents[3]);
|
||||
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) + "..."));
|
||||
TASKS.put(player, new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(!TASKS.containsKey(player))
|
||||
Player player = Bukkit.getPlayerExact(command.getTarget());
|
||||
if (player == null || !player.isOnline())
|
||||
{
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
TASKS.remove(player);
|
||||
Player senderPlayer = Bukkit.getPlayerExact(sender);
|
||||
if (senderPlayer == null)
|
||||
{
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
if (Bukkit.getPlayerExact(player) != null)
|
||||
{
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player) + "."));
|
||||
}
|
||||
}.runTaskLater(_plugin.getPlugin(), 20L * 5));
|
||||
|
||||
_plugin.runAsync(() -> {
|
||||
try (Jedis jedis = _writePool.getResource())
|
||||
if (_plugin.getPartyByPlayer(player) != null)
|
||||
{
|
||||
ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteResponse(PartyCrossServerInviteResponse.Result.TARGET_ALREADY_IN_PARTY, command, player));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_plugin.getPreferencesManager().get(player).isActive(Preference.PARTY_REQUESTS))
|
||||
{
|
||||
ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteResponse(PartyCrossServerInviteResponse.Result.TARGET_NOT_ACCEPTING_INVITES, command, player));
|
||||
return;
|
||||
}
|
||||
|
||||
_plugin.getInviteManager().inviteTo(player.getName(), player.getUniqueId(), command.getRequesterName(), command.getRequesterUUID(), command.getPartyUUID(), command.getFromServer());
|
||||
Lang.INVITE_RECEIVED.send(player, command.getRequesterName());
|
||||
_plugin.getInviteManager().sendAcceptOrDeny(player, command.getRequesterName());
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
|
||||
|
||||
ServerCommandManager.getInstance().publishCommand(new PartyCrossServerInviteResponse(PartyCrossServerInviteResponse.Result.SUCCESS, command, player));
|
||||
});
|
||||
});
|
||||
|
||||
ServerCommandManager.getInstance().registerCommandType(PartyCrossServerInviteResponse.class, command ->
|
||||
{
|
||||
_plugin.runSync(() ->
|
||||
{
|
||||
jedis.publish(FIND_PLAYERS_CHANNEL, RedisMessageType.PLAYER_FIND_REQUEST.format(_serverName, player, sender));
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (!party.getOwnerName().equals(command.getOrigin().getRequesterName()))
|
||||
{
|
||||
//todo wat do
|
||||
}
|
||||
_plugin.getInviteManager().inviteTo(command.getTargetName(), command.getTargetUUID(), command.getOrigin().getRequesterName(), command.getOrigin().getRequesterUUID(), command.getOrigin().getPartyUUID(), _plugin.getServerName());
|
||||
UtilPlayer.message(caller, F.main("Party", "You have invited " + F.elem(command.getTargetName()) + " to your party"));
|
||||
break;
|
||||
case UNKNOWN:
|
||||
UtilPlayer.message(caller, F.main("Party", "Uh oh, something went wrong while inviting " + F.elem(command.getOrigin().getTarget())));
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ServerCommandManager.getInstance().registerCommandType(PartyCrossServerInviteAccept.class, command ->
|
||||
{
|
||||
_plugin.runSync(() ->
|
||||
{
|
||||
Player apparentSender = Bukkit.getPlayer(command.getInviterUUID());
|
||||
if (apparentSender != null && apparentSender.isOnline())
|
||||
{
|
||||
Party partyOfSender = _plugin.getPartyByPlayer(apparentSender);
|
||||
if (partyOfSender == null)
|
||||
{
|
||||
//todo wat do
|
||||
return;
|
||||
}
|
||||
if (!partyOfSender.getUniqueId().equals(command.getPartyUUID()))
|
||||
{
|
||||
//todo wat do
|
||||
return;
|
||||
}
|
||||
|
||||
if (!partyOfSender.getOwnerName().equals(command.getInviterName()))
|
||||
{
|
||||
// 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"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes and sends a party to another server
|
||||
*
|
||||
* @param server The destination server
|
||||
* @param party The party to be sent
|
||||
*/
|
||||
public void sendPartyInfo(String server, Party party)
|
||||
public Map<UUID, Map<String, BukkitTask>> getPendingFindResponse()
|
||||
{
|
||||
publish(server, PARTY_INFO, GSON.toJson(party));
|
||||
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();
|
||||
}
|
||||
return _pendingFindResponse;
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
@ -13,15 +13,8 @@ import org.bukkit.Material;
|
||||
*/
|
||||
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)
|
||||
{
|
||||
super(name, plugin);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,25 @@
|
||||
package mineplex.core.party.ui.button;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.menu.Menu;
|
||||
import mineplex.core.party.Lang;
|
||||
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.utils.UtilGameProfile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
/**
|
||||
* The button representing a Party member.
|
||||
*/
|
||||
@ -20,17 +28,18 @@ public class PartyMemberIcon extends PartyButton
|
||||
|
||||
private ItemStack _itemStack;
|
||||
|
||||
public PartyMemberIcon(String player, Party party, boolean owner)
|
||||
public PartyMemberIcon(GameProfile playerProfile, Party party, boolean owner)
|
||||
{
|
||||
super(null, party, null);
|
||||
ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3)
|
||||
.setTitle(C.cYellow + player)
|
||||
.setPlayerHead(player);
|
||||
.setTitle(C.cYellow + playerProfile.getName());
|
||||
if(owner)
|
||||
{
|
||||
builder.addLore(" ", C.cGreenB + "Leader");
|
||||
}
|
||||
_itemStack = builder.build();
|
||||
|
||||
UtilGameProfile.setGameProfile(playerProfile, _itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,12 +60,16 @@ public class PartyMemberIcon extends PartyButton
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!getParty().getOwner().equalsIgnoreCase(clicker.getName()))
|
||||
if(!getParty().getOwnerName().equalsIgnoreCase(clicker.getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
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
|
||||
|
@ -32,7 +32,7 @@ public class LeavePartyButton extends Button<PartyManager>
|
||||
{
|
||||
return;
|
||||
}
|
||||
getPlugin().getMethodManager().leaveParty(player);
|
||||
getPlugin().leaveParty(player);
|
||||
player.closeInventory();
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
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.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
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
|
||||
*/
|
||||
@ -17,9 +18,9 @@ public class DenyAllButton extends Button<PartyManager>
|
||||
{
|
||||
|
||||
private static final ItemStack ITEM = new ItemBuilder(Material.REDSTONE_BLOCK)
|
||||
.setTitle(C.cRed + "Delete all Invites")
|
||||
.setLore(" ", C.cGray + "This will remove all pending invites.")
|
||||
.build();
|
||||
.setTitle(C.cRed + "Delete all Invites")
|
||||
.setLore(" ", C.cGray + "This will remove all pending invites.")
|
||||
.build();
|
||||
|
||||
public DenyAllButton(PartyManager plugin)
|
||||
{
|
||||
@ -29,7 +30,7 @@ public class DenyAllButton extends Button<PartyManager>
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
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.itemstack.ItemBuilder;
|
||||
import mineplex.core.menu.Button;
|
||||
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
|
||||
@ -19,23 +20,24 @@ public class InviteButton extends Button<PartyManager>
|
||||
public InviteButton(String name, PartyManager plugin)
|
||||
{
|
||||
super(new ItemBuilder(Material.SKULL_ITEM)
|
||||
.setTitle(C.cYellow + name)
|
||||
.setLore(" ", C.cYellow + "Right-Click " + C.cGray + "to deny the invite", C.cYellow + "Left-Click " + C.cGray + "to accept the invite")
|
||||
.setData((short) 3)
|
||||
.setPlayerHead(name)
|
||||
.build(), plugin);
|
||||
.setTitle(C.cYellow + name)
|
||||
.setLore(" ", C.cYellow + "Right-Click " + C.cGray + "to deny the invite", C.cYellow + "Left-Click " + C.cGray + "to accept the invite")
|
||||
.setData((short) 3)
|
||||
.setPlayerHead(name)
|
||||
.build(), plugin);
|
||||
_name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
if(clickType == ClickType.LEFT)
|
||||
if (clickType == ClickType.LEFT)
|
||||
{
|
||||
getPlugin().getMethodManager().respondToInvite(player, _name, true);
|
||||
} else if(clickType == ClickType.RIGHT)
|
||||
getPlugin().acceptInviteBySender(player, _name);
|
||||
}
|
||||
else if (clickType == ClickType.RIGHT)
|
||||
{
|
||||
getPlugin().getMethodManager().respondToInvite(player, _name, false);
|
||||
getPlugin().denyInviteBySender(player, _name);
|
||||
}
|
||||
player.closeInventory();
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class NextPageButton extends Button<PartyManager>
|
||||
List<InviteData> data = _menu.getDataForPage(_menu.getCurrentPage());
|
||||
for(int i = 0; i < data.size(); i++)
|
||||
{
|
||||
_menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin()));
|
||||
_menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInviterName(), getPlugin()));
|
||||
}
|
||||
_menu.update();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class PrevPageButton extends Button<PartyManager>
|
||||
List<InviteData> data = _menu.getDataForPage(_menu.getCurrentPage());
|
||||
for(int i = 0; i < data.size(); i++)
|
||||
{
|
||||
_menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin()));
|
||||
_menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInviterName(), getPlugin()));
|
||||
}
|
||||
_menu.update();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class DisbandPartyButton extends Button<PartyManager>
|
||||
{
|
||||
return;
|
||||
}
|
||||
getPlugin().getMethodManager().disband(player);
|
||||
getPlugin().disband(player);
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
@ -1,15 +1,16 @@
|
||||
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.UtilServer;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.event.PartySelectServerEvent;
|
||||
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
|
||||
@ -18,9 +19,9 @@ public class SelectServerButton extends PartyButton
|
||||
{
|
||||
|
||||
private static final ItemStack ITEM = new ItemBuilder(Material.COMPASS)
|
||||
.setTitle(C.cYellow + "Select Server")
|
||||
.setLore(" ", C.cGray + "Brings up the Server Selection GUI")
|
||||
.build();
|
||||
.setTitle(C.cYellow + "Select Server")
|
||||
.setLore(" ", C.cGray + "Brings up the Server Selection GUI")
|
||||
.build();
|
||||
|
||||
public SelectServerButton(Party party)
|
||||
{
|
||||
|
@ -20,6 +20,8 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@ -69,7 +71,7 @@ public class PartyInvitesMenu extends PartyMenu
|
||||
|
||||
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())
|
||||
{
|
||||
@ -81,6 +83,8 @@ public class PartyInvitesMenu extends PartyMenu
|
||||
return pane(buttons);
|
||||
}
|
||||
|
||||
all.sort(Comparator.comparing(InviteData::getInviterName));
|
||||
|
||||
buttons[DENY_ALL_BUTTON_SLOW] = new DenyAllButton(getPlugin());
|
||||
|
||||
if (_filterBy == null || _filterBy.isEmpty())
|
||||
@ -94,7 +98,7 @@ public class PartyInvitesMenu extends PartyMenu
|
||||
|
||||
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())
|
||||
@ -125,7 +129,7 @@ public class PartyInvitesMenu extends PartyMenu
|
||||
buttons[NEXT_PAGE_SLOT] = new NextPageButton(this, getPlugin());
|
||||
|
||||
_pagesNeeded = pagesNeeded;
|
||||
_pagesOfData = Maps.newHashMap();
|
||||
_pagesOfData = new HashMap<>();
|
||||
|
||||
int page = 0;
|
||||
|
||||
@ -150,7 +154,7 @@ public class PartyInvitesMenu extends PartyMenu
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,24 @@
|
||||
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.Menu;
|
||||
import mineplex.core.menu.builtin.ButtonOpenInventory;
|
||||
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.ViewInvitesButton;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* The main GUI for parties.
|
||||
*/
|
||||
public class PartyMainMenu extends PartyMenu
|
||||
public class PartyMainMenu extends Menu<PartyManager>
|
||||
{
|
||||
|
||||
private final int INV_SIZE = 9;
|
||||
|
||||
private final int INVITE_PLAYER_BUTTON_SLOT = 3;
|
||||
private final int VIEW_INVITES_BUTTON_SLOT = 5;
|
||||
private static final ItemStack VIEW_INVITES_ITEM = new ItemBuilder(Material.BOOK)
|
||||
.setTitle(C.cYellow + "View Invites")
|
||||
.setLore(" ", C.cGray + "Manage invites to parties.")
|
||||
.build();
|
||||
|
||||
public PartyMainMenu(PartyManager plugin)
|
||||
{
|
||||
@ -26,10 +28,10 @@ public class PartyMainMenu extends PartyMenu
|
||||
@Override
|
||||
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[VIEW_INVITES_BUTTON_SLOT] = new ViewInvitesButton(getPlugin());
|
||||
buttons[3] = new InvitePlayerButton(getPlugin());
|
||||
buttons[5] = new ButtonOpenInventory<>(VIEW_INVITES_ITEM, getPlugin(), () -> new PartyInvitesMenu(getPlugin()));
|
||||
|
||||
return buttons;
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
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.party.Party;
|
||||
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.SelectServerButton;
|
||||
import mineplex.core.party.ui.button.tools.owner.TransferOwnerButton;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mineplex.core.utils.UtilGameProfile;
|
||||
|
||||
/**
|
||||
* The display menu for managing parties by the owner
|
||||
@ -44,7 +45,7 @@ public class PartyOwnerMenu extends PartyMenu
|
||||
super("Manage Party", plugin);
|
||||
_party = party;
|
||||
//We want this disabled by default
|
||||
if(_party.isOwnerKickMode())
|
||||
if (_party.isOwnerKickMode())
|
||||
{
|
||||
_party.setOwnerKickMode(false);
|
||||
}
|
||||
@ -67,23 +68,24 @@ public class PartyOwnerMenu extends PartyMenu
|
||||
//Disband
|
||||
buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(getPlugin());
|
||||
|
||||
List<String> members = _party.getMembers();
|
||||
members.remove(_party.getOwner());
|
||||
List<Player> members = new ArrayList<>(_party.getMembers());
|
||||
_party.getOwnerAsPlayer().ifPresent(members::remove);
|
||||
buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true);
|
||||
|
||||
int slot = STARTING_SLOT;
|
||||
//Players
|
||||
for (String member: members)
|
||||
for (Player member : members)
|
||||
{
|
||||
if (slot == CUT_OFF_SLOT)
|
||||
{
|
||||
slot = SKIP_TO_SLOT;
|
||||
} else if (slot == CUT_OFF_SLOT_2)
|
||||
}
|
||||
else if (slot == CUT_OFF_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);
|
||||
|
@ -1,5 +1,10 @@
|
||||
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.party.Party;
|
||||
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.tools.LeavePartyButton;
|
||||
import mineplex.core.party.ui.button.tools.view.SuggestPlayerButton;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mineplex.core.utils.UtilGameProfile;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
super(party.getName() + "'s Party", plugin);
|
||||
super(party.getOwnerName() + "'s Party", plugin);
|
||||
_party = party;
|
||||
}
|
||||
|
||||
@ -46,23 +47,24 @@ public class PartyViewMenu extends PartyMenu
|
||||
//Suggest Player
|
||||
buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, getPlugin());
|
||||
|
||||
List<String> members = _party.getMembers();
|
||||
members.remove(_party.getOwner());
|
||||
List<Player> members = new ArrayList<>(_party.getMembers());
|
||||
_party.getOwnerAsPlayer().ifPresent(members::remove);
|
||||
buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true);
|
||||
|
||||
int slot = STARTING_SLOT;
|
||||
//Players
|
||||
for (String member : members)
|
||||
for (Player member : members)
|
||||
{
|
||||
if (slot == CUT_OFF_SLOT)
|
||||
{
|
||||
slot = SKIP_TO_SLOT;
|
||||
} else if (slot == CUT_OFF_SLOT_2)
|
||||
}
|
||||
else if (slot == CUT_OFF_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);
|
||||
|
@ -14,7 +14,7 @@ public class InviteFilterMenu extends PlayerInputActionMenu
|
||||
|
||||
public InviteFilterMenu(PartyManager partyManager, Player player, Party party)
|
||||
{
|
||||
super(partyManager, player, party);
|
||||
super(partyManager, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,17 +14,19 @@ public class PartyInvitePlayerMenu extends PlayerNameMenu
|
||||
{
|
||||
|
||||
private PartyManager _partyManager;
|
||||
private Party _party;
|
||||
|
||||
public PartyInvitePlayerMenu(PartyManager partyManager, Player player, Party party)
|
||||
{
|
||||
super(partyManager, partyManager.getClientManager(), player, party);
|
||||
super(partyManager, partyManager.getClientManager(), player);
|
||||
_partyManager = partyManager;
|
||||
this._party = party;
|
||||
}
|
||||
|
||||
@Override
|
||||
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.closeInventory();
|
||||
if (_party == null)
|
||||
|
@ -1,10 +1,14 @@
|
||||
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.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 org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -13,23 +17,32 @@ public class PartyTransferOwnerMenu extends PlayerNameMenu
|
||||
{
|
||||
|
||||
private PartyManager _partyManager;
|
||||
private Party _party;
|
||||
|
||||
public PartyTransferOwnerMenu(PartyManager partyManager, Player player, Party party)
|
||||
{
|
||||
super(partyManager, partyManager.getClientManager(), player, party);
|
||||
super(partyManager, partyManager.getClientManager(), player);
|
||||
_partyManager = partyManager;
|
||||
this._party = party;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
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);
|
||||
return;
|
||||
}
|
||||
_partyManager.getMethodManager().transferOwner(name, _player.getName());
|
||||
|
||||
_party.setOwner(player);
|
||||
Lang.TRANSFER_OWNER.send(_party, _player.getName(), name);
|
||||
_player.closeInventory();
|
||||
_player.chat("/party");
|
||||
|
@ -17,35 +17,42 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class PlayerSuggestPlayerMenu extends PlayerNameMenu
|
||||
{
|
||||
private 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
|
||||
public void onSuccess(String name)
|
||||
{
|
||||
if(_party == null || _party.getOwner() == null)
|
||||
if(_party == null || _party.getOwnerName() == null)
|
||||
{
|
||||
Lang.NO_PARTY.send(_player);
|
||||
return;
|
||||
}
|
||||
|
||||
if(_party.contains(name))
|
||||
Player target = Bukkit.getPlayer(name);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
Lang.ALREADY_MEMBER.send(_player, name);
|
||||
return;
|
||||
if (_party.isMember(target))
|
||||
{
|
||||
Lang.ALREADY_MEMBER.send(_player, name);
|
||||
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.");
|
||||
|
||||
ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Click "));
|
||||
message.add(F.link("Invite " + name))
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cGreen + "Clicking this will invite " + C.cYellow + name + C.cGreen + " to the party")
|
||||
.click(ClickEvent.RUN_COMMAND, "/partyinvite " + name);
|
||||
.click(ClickEvent.RUN_COMMAND, "/party gui invite " + name);
|
||||
message.add(C.mBody + " to invite them");
|
||||
message.sendToPlayer(player);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
20
Plugins/Mineplex.Core/src/mineplex/core/portal/Intent.java
Normal file
20
Plugins/Mineplex.Core/src/mineplex/core/portal/Intent.java
Normal 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
|
||||
}
|
@ -1,6 +1,20 @@
|
||||
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.account.CoreClientManager;
|
||||
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.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTabTitle;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.event.PartySendToServerEvent;
|
||||
import mineplex.core.portal.Commands.SendCommand;
|
||||
import mineplex.core.portal.Commands.ServerCommand;
|
||||
import mineplex.core.portal.commands.SendCommand;
|
||||
import mineplex.core.portal.commands.ServerCommand;
|
||||
import mineplex.core.portal.events.GenericServerTransferEvent;
|
||||
import mineplex.core.portal.events.ServerTransferEvent;
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.commands.ServerCommandManager;
|
||||
import mineplex.serverdata.commands.ServerTransfer;
|
||||
import mineplex.serverdata.commands.TransferCommand;
|
||||
import mineplex.serverdata.commands.TransferUUIDCommand;
|
||||
import mineplex.serverdata.data.MinecraftServer;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
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
|
||||
{
|
||||
// The singleton instance of Portal
|
||||
private static Portal instance;
|
||||
public static Portal getInstance() { return instance; }
|
||||
|
||||
private ServerRepository _repository;
|
||||
private CoreClientManager _clientManager;
|
||||
private HashSet<String> _connectingPlayers = new HashSet<String>();
|
||||
|
||||
private Region _region;
|
||||
private String _serverName;
|
||||
|
||||
public Portal(JavaPlugin plugin, CoreClientManager clientManager, String serverName)
|
||||
public static Portal getInstance()
|
||||
{
|
||||
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;
|
||||
_clientManager = clientManager;
|
||||
|
||||
_region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
|
||||
_serverName = serverName;
|
||||
_repository = ServerManager.getServerRepository(_region);
|
||||
_repository = ServerManager.getServerRepository(getPlugin().getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU);
|
||||
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(getPlugin(), "BungeeCord");
|
||||
|
||||
// Register the server command type for future use
|
||||
ServerCommandManager.getInstance().registerCommandType("TransferCommand", TransferCommand.class, new TransferHandler());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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)
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
ServerCommandManager.getInstance().registerCommandType(TransferCommand.class, command ->
|
||||
{
|
||||
sendPlayerToServer(player, serverName);
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void sendPlayerToServer(Player player, String serverName)
|
||||
public void sendAllPlayersToGenericServer(GenericServer hub, Intent kick)
|
||||
{
|
||||
sendPlayerToServer(player, serverName, false);
|
||||
}
|
||||
|
||||
public void sendPlayerToServer(final Player player, final String serverName, boolean draggedByParty)
|
||||
public void sendPlayerToGenericServer(Player player, GenericServer genericServer, Intent intent)
|
||||
{
|
||||
if (_connectingPlayers.contains(player.getName()))
|
||||
return;
|
||||
|
||||
ServerTransferEvent event = new ServerTransferEvent(player, serverName, draggedByParty);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
GenericServerTransferEvent event = new GenericServerTransferEvent(player, genericServer, intent);
|
||||
UtilServer.CallEvent(event);
|
||||
|
||||
final boolean override = serverName.equalsIgnoreCase("Lobby") || serverName.equalsIgnoreCase("ClansHub");
|
||||
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())
|
||||
if (event.isCancelled())
|
||||
{
|
||||
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);
|
||||
|
||||
if (server == null)
|
||||
return;
|
||||
|
||||
Bukkit.getServer().getScheduler().runTask(_plugin, () -> {
|
||||
runSync(() ->
|
||||
{
|
||||
if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.has(Rank.ULTRA))
|
||||
{
|
||||
sendPlayer(player, serverName);
|
||||
}
|
||||
else
|
||||
{
|
||||
UtilPlayer.message(player, F.main(getName(), C.cGold + serverName + C.cRed + " is full!"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ServerTransfer serverTransfer = new ServerTransfer(playerName, serverName);
|
||||
TransferCommand transferCommand = new TransferCommand(serverTransfer);
|
||||
transferCommand.publish();
|
||||
new TransferCommand(playerName, serverName).publish();
|
||||
}
|
||||
|
||||
public static void transferPlayer(UUID playerUUID, String serverName)
|
||||
{
|
||||
new TransferUUIDCommand(playerUUID, serverName).publish();
|
||||
}
|
||||
|
||||
public void doesServerExist(final String serverName, final Callback<Boolean> callback)
|
||||
@ -187,10 +152,10 @@ public class Portal extends MiniPlugin
|
||||
if (callback == null)
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), () -> {
|
||||
final boolean serverExists = ServerManager.getServerRepository(_region).serverExists(serverName);
|
||||
|
||||
Bukkit.getScheduler().runTask(getPlugin(), () -> callback.run(serverExists));
|
||||
runAsync(() ->
|
||||
{
|
||||
boolean result = _repository.serverExists(serverName);
|
||||
runSync(() -> callback.run(result));
|
||||
});
|
||||
}
|
||||
|
||||
@ -200,7 +165,7 @@ public class Portal extends MiniPlugin
|
||||
addCommand(new SendCommand(this));
|
||||
}
|
||||
|
||||
public void sendToHub(Player player, String message)
|
||||
public void sendToHub(Player player, String message, Intent intent)
|
||||
{
|
||||
if (message != null)
|
||||
{
|
||||
@ -210,9 +175,15 @@ public class Portal extends MiniPlugin
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
@ -220,23 +191,11 @@ public class Portal extends MiniPlugin
|
||||
|
||||
try
|
||||
{
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(serverName);
|
||||
out.writeUTF("Connect");
|
||||
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());
|
||||
@ -244,8 +203,22 @@ public class Portal extends MiniPlugin
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.portal.Commands;
|
||||
package mineplex.core.portal.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.portal.Commands;
|
||||
package mineplex.core.portal.commands;
|
||||
|
||||
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.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
|
||||
public class ServerCommand extends CommandBase<Portal>
|
||||
@ -27,7 +28,6 @@ public class ServerCommand extends CommandBase<Portal>
|
||||
{
|
||||
UtilPlayer.message(player,
|
||||
F.main(Plugin.getName(), C.cGray + "You are currently on server: " + C.cGold + serverName));
|
||||
return;
|
||||
}
|
||||
else if (args.length == 1)
|
||||
{
|
||||
@ -58,28 +58,21 @@ public class ServerCommand extends CommandBase<Portal>
|
||||
|
||||
if (servUp.contains("STAFF"))
|
||||
{
|
||||
if (playerRank.has(Rank.HELPER))
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
else
|
||||
if (!playerRank.has(Rank.HELPER))
|
||||
deniedAccess = true;
|
||||
}
|
||||
else if (servUp.contains("TEST"))
|
||||
{
|
||||
if (playerRank.has(Rank.MODERATOR))
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
else
|
||||
if (!playerRank.has(Rank.MODERATOR))
|
||||
deniedAccess = true;
|
||||
}
|
||||
else if (servUp.startsWith("CLANS-"))
|
||||
{
|
||||
if (playerRank.has(Rank.HELPER))
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
else
|
||||
if (!playerRank.has(Rank.HELPER))
|
||||
{
|
||||
UtilPlayer.message(player, F.main(Plugin.getName(), "Clans servers can only be joined via the Clans Hub!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (deniedAccess)
|
||||
@ -88,6 +81,10 @@ public class ServerCommand extends CommandBase<Portal>
|
||||
player,
|
||||
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,
|
||||
F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -24,7 +24,9 @@ public enum Preference
|
||||
SHOW_PLAYERS(true, PreferenceCategory.USER, Material.EYE_OF_ENDER, "Hub Player Visibility"),
|
||||
SHOW_CHAT(true, PreferenceCategory.USER, Material.PAPER, "Player Chat"),
|
||||
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"),
|
||||
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"),
|
||||
|
||||
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();
|
||||
|
@ -24,6 +24,8 @@ import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.portal.GenericServer;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.resourcepack.redis.RedisUnloadResPack;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
@ -187,7 +189,7 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
private void returnHubNoResPack(Player player)
|
||||
{
|
||||
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)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package mineplex.core.status;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.portal.GenericServer;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.commands.CommandCallback;
|
||||
@ -42,7 +44,7 @@ public class SuicideHandler implements CommandCallback
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Portal.getInstance().sendAllPlayers("Lobby");
|
||||
Portal.getInstance().sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
|
||||
}
|
||||
}, 60L);
|
||||
|
||||
|
@ -6,6 +6,8 @@ import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
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.RestartServerCommand;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
@ -79,7 +81,7 @@ public class FileUpdater extends MiniPlugin
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
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()
|
||||
{
|
||||
_portal.sendAllPlayers("Lobby");
|
||||
_portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
|
||||
}
|
||||
}, 60L);
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package mineplex.core.updater;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.portal.GenericServer;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.commands.CommandCallback;
|
||||
@ -60,7 +62,7 @@ public class RestartHandler implements CommandCallback, Listener
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Portal.getInstance().sendAllPlayers("Lobby");
|
||||
Portal.getInstance().sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
|
||||
}
|
||||
}, 60L);
|
||||
|
||||
|
@ -1,16 +1,5 @@
|
||||
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.Modifier;
|
||||
import java.util.UUID;
|
||||
@ -19,6 +8,23 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
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
|
||||
{
|
||||
private static final Cache<UUID, Boolean> TEXTURES = CacheBuilder.newBuilder()
|
||||
@ -28,13 +34,12 @@ public class UtilGameProfile
|
||||
|
||||
/**
|
||||
* 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()
|
||||
*
|
||||
* @param username The username of the player
|
||||
* @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 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
|
||||
* @return The GameProfile - always an unique instance
|
||||
*/
|
||||
public static Future<GameProfile> getProfileByName(String username, boolean nonNull, Consumer<GameProfile> fetched)
|
||||
@ -95,7 +100,6 @@ public class UtilGameProfile
|
||||
* Clones a GameProfile
|
||||
*
|
||||
* @param input The GameProfile to clone
|
||||
*
|
||||
* @return A copy of the GameProfile
|
||||
*/
|
||||
public static GameProfile clone(GameProfile input)
|
||||
@ -112,7 +116,6 @@ public class UtilGameProfile
|
||||
* Convert a string to a legal username equivalent
|
||||
*
|
||||
* @param in The original username
|
||||
*
|
||||
* @returns A legal version of the username (with illegal characters stripped out
|
||||
*/
|
||||
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_ID_FIELD;
|
||||
private static final Field SKULL_META_PROFILE_FIELD;
|
||||
|
||||
static
|
||||
{
|
||||
@ -131,6 +135,8 @@ public class UtilGameProfile
|
||||
GAME_PROFILE_NAME_FIELD.setAccessible(true);
|
||||
GAME_PROFILE_ID_FIELD = GameProfile.class.getDeclaredField("id");
|
||||
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");
|
||||
modifiersField.setAccessible(true);
|
||||
@ -174,4 +180,28 @@ public class UtilGameProfile
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class Clans extends JavaPlugin
|
||||
Give.Initialize(this);
|
||||
|
||||
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());
|
||||
|
||||
ClansBanManager clansBans = new ClansBanManager(this, _clientManager, _donationManager);
|
||||
|
@ -72,6 +72,8 @@ import mineplex.core.movement.Movement;
|
||||
import mineplex.core.npc.NpcManager;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.personalServer.PersonalServerManager;
|
||||
import mineplex.core.portal.GenericServer;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
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"))
|
||||
{
|
||||
Portal.getInstance().sendPlayerToServer(event.getPlayer(), "ClansHub");
|
||||
Portal.getInstance().sendPlayerToGenericServer(event.getPlayer(), GenericServer.CLANS_HUB, Intent.PLAYER_REQUEST);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
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.PlayerTeleportEvent;
|
||||
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.map.MapRenderer;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multisets;
|
||||
@ -46,7 +42,7 @@ import com.google.common.collect.Multisets;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
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.event.UpdateEvent;
|
||||
import mineplex.game.clans.clans.ClansManager;
|
||||
|
@ -13,6 +13,8 @@ import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
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.slack.SlackAPI;
|
||||
import mineplex.core.slack.SlackMessage;
|
||||
@ -143,7 +145,7 @@ public class RestartManager extends MiniPlugin
|
||||
if (System.currentTimeMillis() >= _restartTime)
|
||||
{
|
||||
_restarting = true;
|
||||
Portal.getInstance().sendAllPlayers("ClansHub");
|
||||
Portal.getInstance().sendAllPlayersToGenericServer(GenericServer.CLANS_HUB, Intent.KICK);
|
||||
runSyncLater(() ->
|
||||
{
|
||||
if (!_testServer)
|
||||
|
@ -15,6 +15,8 @@ import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.portal.GenericServer;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
@ -138,7 +140,7 @@ public class TravelPage extends ShopPageBase<ClansManager, TravelShop>
|
||||
{
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
Portal.getInstance().sendPlayerToServer(player, "Lobby");
|
||||
Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.HUB, Intent.PLAYER_REQUEST);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class ClansHub extends JavaPlugin
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
|
||||
new TitanGiveawayManager(this, clientManager, serverStatusManager);
|
||||
|
||||
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName());
|
||||
Portal portal = new Portal();
|
||||
|
||||
AntiHack antiHack = require(AntiHack.class);
|
||||
GuardianManager guardianManager = require(GuardianManager.class);
|
||||
@ -140,7 +140,7 @@ public class ClansHub extends JavaPlugin
|
||||
EloManager eloManager = new EloManager(this, clientManager);
|
||||
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);
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class ClansServerShop extends ShopBase<ClansTransferManager>
|
||||
@Override
|
||||
protected boolean canOpenShop(Player player)
|
||||
{
|
||||
Party party = getPlugin().getPartyManager().getParty(player);
|
||||
Party party = getPlugin().getPartyManager().getPartyByPlayer(player);
|
||||
|
||||
if (party != null)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@ import mineplex.core.npc.event.NpcInteractEntityEvent;
|
||||
import mineplex.core.party.Lang;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
@ -124,21 +125,10 @@ public class ClansTransferManager extends MiniDbClientPlugin<SimpleClanToken>
|
||||
*/
|
||||
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.eject();
|
||||
|
||||
_portal.sendPlayerToServer(player, serverInfo.Name);
|
||||
_portal.sendPlayerToServer(player, serverInfo.Name, Intent.PLAYER_REQUEST);
|
||||
}
|
||||
|
||||
@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);
|
||||
return;
|
||||
}
|
||||
if (_party.getParty(player) != null)
|
||||
if (_party.getPartyByPlayer(player) != null)
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
|
||||
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"))
|
||||
{
|
||||
_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))
|
||||
{
|
||||
_portal.sendToHub(player, "Returning to Mineplex!");
|
||||
_portal.sendToHub(player, "Returning to Mineplex!", Intent.PLAYER_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package mineplex.clanshub;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -99,6 +98,8 @@ import mineplex.core.pet.PetManager;
|
||||
import mineplex.core.playerCount.PlayerCountManager;
|
||||
import mineplex.core.playwire.PlayWireManager;
|
||||
import mineplex.core.poll.PollManager;
|
||||
import mineplex.core.portal.GenericServer;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.Preference;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
@ -293,7 +294,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_portal.sendAllPlayers("Lobby");
|
||||
_portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
|
||||
{
|
||||
@ -332,7 +333,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
|
||||
{
|
||||
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
|
||||
if (event.getMessage().charAt(0) == '#')
|
||||
{
|
||||
Party party = _partyManager.getParty(player);
|
||||
Party party = _partyManager.getPartyByPlayer(player);
|
||||
if (party != null)
|
||||
{
|
||||
event.getRecipients().clear();
|
||||
@ -485,13 +486,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
|
||||
event.setMessage(event.getMessage().substring(1, event.getMessage().length()));
|
||||
event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s");
|
||||
|
||||
for (UUID name : party.getMembersByUUID())
|
||||
{
|
||||
Player other = Bukkit.getPlayer(name);
|
||||
|
||||
if (other != null)
|
||||
event.getRecipients().add(other);
|
||||
}
|
||||
event.getRecipients().addAll(party.getMembers());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -147,7 +147,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
|
||||
new TitanGiveawayManager(this, clientManager, serverStatusManager);
|
||||
|
||||
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName());
|
||||
Portal portal = new Portal();
|
||||
|
||||
AntiHack antiHack = require(AntiHack.class);
|
||||
GuardianManager guardianManager = require(GuardianManager.class);
|
||||
@ -165,7 +165,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
EloManager eloManager = new EloManager(this, clientManager);
|
||||
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);
|
||||
|
||||
|
@ -89,6 +89,8 @@ import mineplex.core.pet.PetManager;
|
||||
import mineplex.core.playerCount.PlayerCountManager;
|
||||
import mineplex.core.playwire.PlayWireManager;
|
||||
import mineplex.core.poll.PollManager;
|
||||
import mineplex.core.portal.GenericServer;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.Preference;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
@ -423,7 +425,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_portal.sendAllPlayers("Lobby");
|
||||
_portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK);
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
|
||||
{
|
||||
@ -484,7 +486,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
{
|
||||
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
|
||||
if (event.getMessage().charAt(0) == '@')
|
||||
{
|
||||
Party party = _partyManager.getParty(player);
|
||||
Party party = _partyManager.getPartyByPlayer(player);
|
||||
if (party != null)
|
||||
{
|
||||
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.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s");
|
||||
|
||||
for (String uuid: party.getMembers())
|
||||
{
|
||||
Player other = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (other != null)
|
||||
event.getRecipients().add(other);
|
||||
}
|
||||
event.getRecipients().addAll(party.getMembers());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -8,14 +8,13 @@ import mineplex.core.shop.item.ShopItem;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.hub.queue.PlayerMatchStatus;
|
||||
import mineplex.hub.queue.QueueManager;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class QueuePage extends ShopPageBase<QueueManager, QueueShop>
|
||||
{
|
||||
@ -130,15 +129,15 @@ public class QueuePage extends ShopPageBase<QueueManager, QueueShop>
|
||||
|
||||
private void queuePlayer(int gameType, Player player)
|
||||
{
|
||||
Party party = getPlugin().getPartyManager().getParty(player);
|
||||
Party party = getPlugin().getPartyManager().getPartyByPlayer(player);
|
||||
if(party == null)
|
||||
{
|
||||
getPlugin().queuePlayer(gameType, player);
|
||||
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()]));
|
||||
}
|
||||
buildPage();
|
||||
|
@ -29,22 +29,6 @@ public class QueueShop extends ShopBase<QueueManager>
|
||||
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
|
||||
public void UpdatePages(UpdateEvent event)
|
||||
{
|
||||
|
@ -20,6 +20,7 @@ import mineplex.core.party.Lang;
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.core.party.event.PartySelectServerEvent;
|
||||
import mineplex.core.portal.Intent;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.shop.ShopBase;
|
||||
import mineplex.core.status.ServerStatusManager;
|
||||
@ -453,21 +454,10 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider
|
||||
|
||||
public void selectServer(Player player, ServerInfo serverInfo)
|
||||
{
|
||||
Party party = _partyManager.getParty(player);
|
||||
if(party != null)
|
||||
{
|
||||
if(!party.getOwner().equalsIgnoreCase(player.getName()))
|
||||
{
|
||||
Lang.NOT_OWNER_SERVER.send(player);
|
||||
return;
|
||||
}
|
||||
_partyManager.getJoinManager().requestServerJoin(serverInfo.Name, party);
|
||||
return;
|
||||
}
|
||||
player.leaveVehicle();
|
||||
player.eject();
|
||||
|
||||
_portal.sendPlayerToServer(player, serverInfo.Name);
|
||||
_portal.sendPlayerToServer(player, serverInfo.Name, Intent.PLAYER_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()
|
||||
{
|
||||
for (ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> page : getPlayerPageMap().values())
|
||||
|
@ -36,7 +36,7 @@ public class ClanMoveServerShop extends ShopBase<ServerManager>
|
||||
@Override
|
||||
protected boolean canOpenShop(Player player)
|
||||
{
|
||||
Party party = getPlugin().getPartyManager().getParty(player);
|
||||
Party party = getPlugin().getPartyManager().getPartyByPlayer(player);
|
||||
|
||||
if (party != null)
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ public class ClansServerShop extends ShopBase<ServerManager>
|
||||
@Override
|
||||
protected boolean canOpenShop(Player player)
|
||||
{
|
||||
Party party = getPlugin().getPartyManager().getParty(player);
|
||||
Party party = getPlugin().getPartyManager().getPartyByPlayer(player);
|
||||
|
||||
if (party != null)
|
||||
{
|
||||
|
@ -28,5 +28,9 @@
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mineplex</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user