Fix remainder of parties bugs

This commit is contained in:
samczsun 2016-12-24 21:06:47 -05:00 committed by cnr
parent 56d4ed9e11
commit 4fd92a3402
10 changed files with 170 additions and 153 deletions

View File

@ -32,11 +32,6 @@ public class Party implements Listener
private final PartyManager _partyManager = Managers.require(PartyManager.class);
/**
* This is controls whether or not the owner is currently in the menu, and kicking members
*/
private boolean _ownerKickMode = false;
/**
* The unique ID assigned to this party
*/
@ -193,24 +188,4 @@ public class Party implements Listener
Lang.TRANSFER_OWNER.send(this, player.getName(), _owner.getName());
}
}
/**
* Gets the current state of whether or not the owner is kicking people in the UI.
*
* @return <code>true</code> if the owner is kicking people
*/
public boolean isOwnerKickMode()
{
return _ownerKickMode;
}
/**
* Set's the current state of kicking players
*
* @param ownerKickMode <code>true</code> if the owner is kicking people
*/
public void setOwnerKickMode(boolean ownerKickMode)
{
_ownerKickMode = ownerKickMode;
}
}

View File

@ -16,6 +16,9 @@ import com.google.common.collect.Maps;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.jsonchat.ChildJsonMessage;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.HoverEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilItem;
@ -318,7 +321,16 @@ public class PartyManager extends MiniPlugin
if (!party.getOwnerName().equalsIgnoreCase(caller.getName()))
{
Lang.NOT_OWNER.send(caller);
party.sendMessage(F.main("Party", F.elem(caller.getName()) + " has suggested " + F.elem(target) + " be invited"));
party.getOwnerAsPlayer().ifPresent(owner ->
{
ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Click "));
message.add(F.link("Invite " + target))
.hover(HoverEvent.SHOW_TEXT, C.cGreen + "Clicking this will invite " + C.cYellow + target + C.cGreen + " to the party")
.click(ClickEvent.RUN_COMMAND, "/party gui invite " + target);
message.add(C.mBody + " to invite them");
message.sendToPlayer(owner);
});
return;
}
if (party.getMembers().size() >= party.getSize())

View File

@ -1,8 +1,10 @@
package mineplex.core.party.command;
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.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.command.MultiCommandBase;
@ -42,26 +44,115 @@ public class PartyCLICommand extends MultiCommandBase<PartyManager>
protected void Help(Player caller, String[] args)
{
Party party = Plugin.getPartyByPlayer(caller);
if (args.length > 0)
{
UtilPlayer.message(caller, F.main("Party", "That is not a valid command! Try " + F.elem("/party help") + "!"));
return;
}
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 + ", "));
ComponentBuilder builder = new ComponentBuilder("")
.append("[", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.AQUA)
.append("?", ComponentBuilder.FormatRetention.NONE)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to view Party Help").create()))
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/z help"))
.append("]", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.AQUA)
.bold(true)
.append("===========", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.AQUA)
.bold(true)
.strikethrough(true)
.append("[", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.AQUA)
.bold(true)
.append("Your Party", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.WHITE)
.bold(true)
.append("]", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.AQUA)
.bold(true)
.append("==============", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.AQUA)
.bold(true)
.strikethrough(true)
.append("\n\n", ComponentBuilder.FormatRetention.NONE);
UtilPlayer.message(caller, F.main("Party", "Members: " + members));
builder.append("Leader")
.color(party.getOwnerAsPlayer() == null ? ChatColor.GRAY : ChatColor.LIGHT_PURPLE)
.bold(true)
.append(" ", ComponentBuilder.FormatRetention.NONE)
.append(party.getOwnerName())
.append("\n");
for (Player member : party.getMembers())
{
if (member.getUniqueId().equals(party.getOwner().getId()))
continue;
builder.append("Member")
.color(ChatColor.DARK_PURPLE)
.bold(true)
.append(" ", ComponentBuilder.FormatRetention.NONE)
.append(member.getName());
if (party.isOwner(caller))
{
builder.append(" ", ComponentBuilder.FormatRetention.NONE)
.append("", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.RED)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Kick " + member.getName() + " from your party").color(ChatColor.RED).create()))
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/z cli kick " + member.getName()))
.append(" ", ComponentBuilder.FormatRetention.NONE)
.append("", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.GOLD)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Transfer party to " + member.getName()).color(ChatColor.GOLD).create()))
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/z cli tr " + member.getName()));
}
builder.append("\n", ComponentBuilder.FormatRetention.NONE);
}
builder.append("\n", ComponentBuilder.FormatRetention.NONE);
builder.append("Toggle GUI")
.color(ChatColor.GREEN)
.bold(true)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Switch to the chest GUI instead of chat").color(ChatColor.GREEN).create()))
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/z t"))
.append(" - ", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.GRAY)
.append("Leave")
.color(ChatColor.RED)
.bold(true)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Leave your party").color(ChatColor.RED).create()))
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/z cli leave"));
if (party.isOwner(caller))
{
builder
.append(" - ")
.color(ChatColor.GRAY)
.append("Disband")
.color(ChatColor.DARK_RED)
.bold(true)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Disband your party").color(ChatColor.DARK_RED).create()))
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/z cli disband"));
}
builder.append("\n", ComponentBuilder.FormatRetention.NONE)
.append("======================================")
.color(ChatColor.AQUA)
.bold(true)
.strikethrough(true);
caller.spigot().sendMessage(builder.create());
}
}

View File

@ -117,12 +117,14 @@ public class PartyInvitesCommand extends CommandBase<PartyManager>
.append("Accept")
.color(ChatColor.GREEN)
.bold(true)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to accept this invite").color(ChatColor.GREEN).create()))
.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 HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to deny this invite").color(ChatColor.RED).create()))
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/party cli d " + data.getInviterName()))
.append(" - ", ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.WHITE)

View File

@ -6,6 +6,7 @@ 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 PartyGUIInviteCommand extends CommandBase<PartyManager>

View File

@ -5,12 +5,10 @@ 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;
@ -25,9 +23,8 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.spigotmc.CaseInsensitiveMap;
import com.google.common.collect.Maps;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.InviteData;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
@ -68,6 +65,7 @@ public class PartyInviteManager
/**
* Checks if a caller has an invite by a sender's name
*
* @param caller
* @param sender
* @return
@ -79,6 +77,7 @@ public class PartyInviteManager
/**
* Checks if a caller has an invite by a party id
*
* @param caller
* @param partyId
* @return
@ -102,6 +101,7 @@ public class PartyInviteManager
/**
* Remove a player's invite to a party by id
*
* @param caller
* @param partyId
* @return
@ -199,11 +199,15 @@ public class PartyInviteManager
Player possible = Bukkit.getPlayer(targetUUID);
if (possible != null)
{
Party curParty = _plugin.getPartyByPlayer(possible);
if (curParty != null && !curParty.getUniqueId().equals(data.getPartyUUID()))
Party curParty = _plugin.getPartyById(partyId);
if (curParty != null)
{
possible.sendMessage(F.main("Party", "Your invite to " + F.name(inviterName) + "'s party has expired"));
}
else
{
UtilPlayer.message(possible, F.main("Party", "Your invite to " + F.name(inviterName) + "'s party has expired. Fortunately, that party no longer exists"));
}
}
}
}, 20 * 60));

View File

@ -1,5 +1,13 @@
package mineplex.core.party.ui.button;
import org.bukkit.Bukkit;
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;
import mineplex.core.Managers;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
@ -11,35 +19,34 @@ 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.
*/
public class PartyMemberIcon extends PartyButton
{
private final String _name;
private ItemStack _itemStack;
public PartyMemberIcon(GameProfile playerProfile, Party party, boolean owner)
public PartyMemberIcon(GameProfile playerProfile, Party party, boolean owner, boolean isOwnerView)
{
super(null, party, null);
ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3)
.setTitle(C.cYellow + playerProfile.getName());
if(owner)
.setTitle(C.cYellow + playerProfile.getName());
if (owner)
{
builder.addLore(" ", C.cGreenB + "Leader");
}
if (!owner && isOwnerView)
{
builder.addLore(" ", C.cRed + "Shift-Right-Click to kick");
}
_itemStack = builder.build();
UtilGameProfile.setGameProfile(playerProfile, _itemStack);
_name = playerProfile.getName();
}
@Override
@ -48,33 +55,23 @@ public class PartyMemberIcon extends PartyButton
return _itemStack;
}
/**
* Called when a player clicks one of the member icons
*
* @param clicker The player who clicked
* @param clicked The itemstack he clicked
*/
public void onClick(Player clicker, ItemStack clicked)
{
if (!getParty().isOwnerKickMode())
{
return;
}
if(!getParty().getOwnerName().equalsIgnoreCase(clicker.getName()))
{
return;
}
String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
Player target = Bukkit.getPlayerExact(name);
Lang.REMOVED.send(target);
Managers.require(PartyManager.class).removeFromParty(target, PartyRemoveReason.KICKED);
Menu.get(clicker.getUniqueId()).resetAndUpdate();
}
@Override
public void onClick(Player player, ClickType clickType)
{
if (!getParty().getOwnerName().equalsIgnoreCase(player.getName()))
{
return;
}
if (clickType == ClickType.SHIFT_RIGHT)
{
Player target = Bukkit.getPlayerExact(_name);
if (target != null && !getParty().isOwner(target) && target != player && getParty().isMember(target))
{
Lang.REMOVED.send(target);
Managers.require(PartyManager.class).removeFromParty(target, PartyRemoveReason.KICKED);
Menu.get(player.getUniqueId()).resetAndUpdate();
}
}
}
}

View File

@ -1,56 +0,0 @@
package mineplex.core.party.ui.button.tools.owner;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.Party;
import mineplex.core.party.ui.PartyMenu;
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;
/**
* Toggles {@code {@link Party#isOwnerKickMode()}}
*/
public class KickPlayerButton extends PartyButton
{
private static final ItemStack ITEM_OFF = new ItemBuilder(Material.IRON_AXE)
.setTitle(C.cYellow + "Kick Players")
.setLore(" ", F.elem("Right-Click") + " to enter " + C.cGreen + "Kick Mode",
C.cGray + "While activated, click on a player's head", C.cGray + "to remove them from the party")
.build();
private static final ItemStack ITEM_ON = new ItemBuilder(Material.IRON_AXE)
.setTitle(C.cYellow + "Kick Players")
.setLore(" ", F.elem("Right-Click") + " to leave " + C.cRed + "Kick Mode",
C.cGray + "While activated, click on a player's head", C.cGray + "to remove them from the party")
.setGlow(true)
.build();
public KickPlayerButton(Party party)
{
super(ITEM_OFF, party, null);
}
@Override
public void onClick(Player player, ClickType clickType)
{
if(clickType != ClickType.RIGHT)
{
return;
}
getParty().setOwnerKickMode(!getParty().isOwnerKickMode());
if (getParty().isOwnerKickMode())
{
setItemStack(ITEM_ON);
} else
{
setItemStack(ITEM_OFF);
}
PartyMenu.get(player.getUniqueId()).update();
}
}

View File

@ -13,7 +13,6 @@ import mineplex.core.party.ui.button.PartyMemberIcon;
import mineplex.core.party.ui.button.tools.LeavePartyButton;
import mineplex.core.party.ui.button.tools.owner.AddPlayerButton;
import mineplex.core.party.ui.button.tools.owner.DisbandPartyButton;
import mineplex.core.party.ui.button.tools.owner.KickPlayerButton;
import mineplex.core.party.ui.button.tools.owner.SelectServerButton;
import mineplex.core.party.ui.button.tools.owner.TransferOwnerButton;
import mineplex.core.utils.UtilGameProfile;
@ -32,7 +31,6 @@ public class PartyOwnerMenu extends PartyMenu
private final int SKIP_TO_SLOT = 29;
private final int SKIP_TO_SLOT_2 = 38;
private final int ADD_PLAYER_BUTTON_SLOT = 1;
private final int KICK_PLAYER_BUTTON_SLOT = 4;
private final int TRANSFER_OWNER_BUTTON_SLOT = 7;
private final int SELECT_SERVER_BUTTON_SLOT = 46;
private final int LEAVE_PARTY_BUTTON_SLOT = 49;
@ -44,11 +42,6 @@ public class PartyOwnerMenu extends PartyMenu
{
super("Manage Party", plugin);
_party = party;
//We want this disabled by default
if (_party.isOwnerKickMode())
{
_party.setOwnerKickMode(false);
}
}
@Override
@ -57,8 +50,6 @@ public class PartyOwnerMenu extends PartyMenu
Button[] buttons = new Button[INV_SIZE];
//Tools
buttons[ADD_PLAYER_BUTTON_SLOT] = new AddPlayerButton(getPlugin(), _party);
//Kick player
buttons[KICK_PLAYER_BUTTON_SLOT] = new KickPlayerButton(_party);
//Transfer ownership
buttons[TRANSFER_OWNER_BUTTON_SLOT] = new TransferOwnerButton(_party, getPlugin());
//Go to server
@ -70,7 +61,7 @@ public class PartyOwnerMenu extends PartyMenu
List<Player> members = new ArrayList<>(_party.getMembers());
_party.getOwnerAsPlayer().ifPresent(members::remove);
buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true);
buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true, true);
int slot = STARTING_SLOT;
//Players
@ -85,7 +76,7 @@ public class PartyOwnerMenu extends PartyMenu
slot = SKIP_TO_SLOT_2;
}
buttons[slot++] = new PartyMemberIcon(UtilGameProfile.getGameProfile(member), _party, false);
buttons[slot++] = new PartyMemberIcon(UtilGameProfile.getGameProfile(member), _party, false, true);
}
return pane(buttons);

View File

@ -49,7 +49,7 @@ public class PartyViewMenu extends PartyMenu
List<Player> members = new ArrayList<>(_party.getMembers());
_party.getOwnerAsPlayer().ifPresent(members::remove);
buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true);
buttons[OWNER_HEAD_SLOT] = new PartyMemberIcon(_party.getOwner(), _party, true, false);
int slot = STARTING_SLOT;
//Players
@ -64,7 +64,7 @@ public class PartyViewMenu extends PartyMenu
slot = SKIP_TO_SLOT_2;
}
buttons[slot++] = new PartyMemberIcon(UtilGameProfile.getGameProfile(member), _party, false);
buttons[slot++] = new PartyMemberIcon(UtilGameProfile.getGameProfile(member), _party, false, false);
}
return pane(buttons);