mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
More work on parties
This commit is contained in:
parent
393ac886e2
commit
cbaf2f8370
@ -12,6 +12,7 @@ Version 1.3.09
|
||||
+ Added several permission nodes to give individual users special perks (Double/Triple/Quadruple XP)
|
||||
+ Added API for plugins to add custom tools directly via Spout - repair / abilities do not work ATM
|
||||
+ Added offline party members to the list displayed by /party
|
||||
+ Added possibility to kick offline members from parties
|
||||
= Fixed /mcremove being applied only after a reload
|
||||
= Fixed Archery PVE disablement not working properly
|
||||
= Fixed possible NPE when a projectile is shot by a dispenser or doesn't have any shooter
|
||||
|
@ -68,7 +68,7 @@ public final class PartyAPI {
|
||||
* @param partyName The party to add the player to
|
||||
*/
|
||||
public static void addToParty(Player player, String partyName) {
|
||||
PartyManager.getInstance().addToParty(player, Users.getProfile(player), partyName, null);
|
||||
PartyManager.getInstance().addToParty(player.getName(), Users.getProfile(player), PartyManager.getInstance().getParty(partyName)); //TODO this will throw a NPE if the party doesn't exist
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +79,7 @@ public final class PartyAPI {
|
||||
* @param player The player to remove
|
||||
*/
|
||||
public static void removeFromParty(Player player) {
|
||||
PartyManager.getInstance().removeFromParty(player, Users.getProfile(player));
|
||||
PartyManager.getInstance().removeFromParty(player.getName(), Users.getProfile(player).getParty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ public final class PartyAPI {
|
||||
* @param player The player to set as leader
|
||||
*/
|
||||
public static void setPartyLeader(String partyName, String player) {
|
||||
PartyManager.getInstance().setPartyLeader(partyName, player);
|
||||
PartyManager.getInstance().setPartyLeader(player, PartyManager.getInstance().getParty(partyName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,7 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
@ -32,23 +33,25 @@ public class AcceptCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
PlayerProfile PP = Users.getProfile(player);
|
||||
PlayerProfile playerProfile = Users.getProfile(player);
|
||||
|
||||
if (PP.hasPartyInvite()) {
|
||||
if (playerProfile.hasPartyInvite()) {
|
||||
PartyManager partyManagerInstance = PartyManager.getInstance();
|
||||
|
||||
if (PP.inParty()) {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, PP.getParty().getName(), PP.getInvite().getName(), EventReason.CHANGED_PARTIES);
|
||||
if (playerProfile.inParty()) {
|
||||
Party party = playerProfile.getParty();
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), playerProfile.getInvite().getName(), EventReason.CHANGED_PARTIES);
|
||||
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
partyManagerInstance.removeFromParty(player, PP);
|
||||
partyManagerInstance.removeFromParty(player.getName(), party);
|
||||
}
|
||||
else {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, PP.getInvite().getName(), EventReason.JOINED_PARTY);
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, playerProfile.getInvite().getName(), EventReason.JOINED_PARTY);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
@ -56,7 +59,7 @@ public class AcceptCommand implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
partyManagerInstance.addToInvitedParty(player, PP, PP.getInvite());
|
||||
partyManagerInstance.joinInvitedParty(player, playerProfile);
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.gmail.nossr50.commands.party;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -49,15 +51,22 @@ public class PartyCommand implements CommandExecutor {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
||||
}
|
||||
else {
|
||||
String tempList = ChatColor.GOLD + party.getLeader() + " ";
|
||||
Server server = plugin.getServer();
|
||||
String leader = party.getLeader();
|
||||
StringBuffer tempList = new StringBuffer();
|
||||
|
||||
for (String otherPlayerName : party.getMembers()) {
|
||||
if (plugin.getServer().getPlayer(otherPlayerName) == null) {
|
||||
tempList += ChatColor.GRAY + otherPlayerName + " ";
|
||||
if (leader.equals(otherPlayerName)) {
|
||||
tempList.append(ChatColor.GOLD);
|
||||
}
|
||||
else if (!party.getLeader().equals(otherPlayerName)){
|
||||
tempList += ChatColor.WHITE + otherPlayerName + " ";
|
||||
else if (server.getPlayer(otherPlayerName) != null) {
|
||||
tempList.append(ChatColor.WHITE);
|
||||
}
|
||||
else {
|
||||
tempList.append(ChatColor.GRAY);
|
||||
}
|
||||
|
||||
tempList.append(otherPlayerName + " ");
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.InParty", new Object[] {party.getName()}));
|
||||
@ -76,7 +85,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
partyManagerInstance.removeFromParty(player, playerProfile);
|
||||
partyManagerInstance.removeFromParty(playerName, party);
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
|
||||
}
|
||||
else {
|
||||
@ -138,7 +147,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
partyManagerInstance.removeFromParty(player, playerProfile);
|
||||
partyManagerInstance.removeFromParty(playerName, party);
|
||||
}
|
||||
else {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY);
|
||||
@ -149,7 +158,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
partyManagerInstance.addToParty(player, playerProfile, args[0], null);
|
||||
partyManagerInstance.joinParty(player, playerProfile, args[0], null);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -168,33 +177,23 @@ public class PartyCommand implements CommandExecutor {
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("kick")) {
|
||||
if (party.getLeader().equals(playerName)) {
|
||||
//TODO allow to kick offline players
|
||||
Player target = plugin.getServer().getPlayer(args[1]);
|
||||
List<String> members = party.getMembers();
|
||||
|
||||
if (target == null) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
|
||||
if (!members.contains(args[1])) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {args[1]}));
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerProfile otherPlayerProfile = Users.getProfile(target);
|
||||
String targetName = target.getName();
|
||||
|
||||
if (!partyManagerInstance.inSameParty(player, target)) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {targetName}));
|
||||
return true;
|
||||
}
|
||||
|
||||
else {
|
||||
String partyName = party.getName();
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, null, EventReason.KICKED_FROM_PARTY);
|
||||
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
partyManagerInstance.removeFromParty(target, otherPlayerProfile);
|
||||
target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", new Object[] {partyName}));
|
||||
partyManagerInstance.removeFromParty(args[1], party);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -203,28 +202,16 @@ public class PartyCommand implements CommandExecutor {
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("owner")) {
|
||||
if (party.getLeader().equals(playerName)) {
|
||||
//TODO allow to set the ownership to offline players
|
||||
OfflinePlayer target = plugin.getServer().getOfflinePlayer(args[1]);
|
||||
List<String> members = party.getMembers();
|
||||
|
||||
if (target == null) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
|
||||
if (!members.contains(args[1])) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {args[1]}));
|
||||
return true;
|
||||
}
|
||||
|
||||
String targetName = target.getName();
|
||||
|
||||
if (!partyManagerInstance.inSameParty(player, target)) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {targetName}));
|
||||
return true;
|
||||
}
|
||||
|
||||
else {
|
||||
partyManagerInstance.setPartyLeader(party.getName(), targetName);
|
||||
partyManagerInstance.setPartyLeader(args[1], party);
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), args[0], EventReason.CHANGED_PARTIES);
|
||||
@ -234,8 +221,8 @@ public class PartyCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
partyManagerInstance.removeFromParty(player, playerProfile);
|
||||
partyManagerInstance.addToParty(player, playerProfile, args[0], args[1]);
|
||||
partyManagerInstance.removeFromParty(playerName, party);
|
||||
partyManagerInstance.joinParty(player, playerProfile, args[0], args[1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -246,7 +233,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
partyManagerInstance.addToParty(player, playerProfile, args[0], args[1]);
|
||||
partyManagerInstance.joinParty(player, playerProfile, args[0], args[1]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -4,10 +4,8 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -55,41 +53,16 @@ public class PartyManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if two players are in the same party.
|
||||
*
|
||||
* @param firstPlayer The first player
|
||||
* @param secondPlayer The second player
|
||||
* @return true if they are in the same party, false otherwise
|
||||
*/
|
||||
public boolean inSameParty(OfflinePlayer firstPlayer, OfflinePlayer secondPlayer) {
|
||||
PlayerProfile firstProfile = Users.getProfile(firstPlayer);
|
||||
PlayerProfile secondProfile = Users.getProfile(secondPlayer);
|
||||
|
||||
if (firstProfile == null || secondProfile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Party firstParty = firstProfile.getParty();
|
||||
Party secondParty = secondProfile.getParty();
|
||||
|
||||
if (firstParty == null || secondParty == null || firstParty != secondParty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify party members when a player joins
|
||||
*
|
||||
* @param player The player that joins
|
||||
* @param playerName The name of the player that joins
|
||||
* @param party The concerned party
|
||||
*/
|
||||
private void informPartyMembersJoin(Player player, Party party) {
|
||||
private void informPartyMembersJoin(String playerName, Party party) {
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
if (member != player) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", new Object[] {player.getName()}));
|
||||
if (member.getName().equals(playerName)) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", new Object[] {playerName}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,13 +70,13 @@ public class PartyManager {
|
||||
/**
|
||||
* Notify party members when a party member quits.
|
||||
*
|
||||
* @param player The player that quits
|
||||
* @param playerName The name of the player that quits
|
||||
* @param party The concerned party
|
||||
*/
|
||||
private void informPartyMembersQuit(Player player, Party party) {
|
||||
private void informPartyMembersQuit(String playerName, Party party) {
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
if (member != player) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", new Object[] {player.getName()}));
|
||||
if (member.getName().equals(playerName)) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", new Object[] {playerName}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,7 +91,7 @@ public class PartyManager {
|
||||
Party party = Users.getProfile(player).getParty();
|
||||
|
||||
if (party == null) {
|
||||
return Collections.emptyList();
|
||||
return null;
|
||||
}
|
||||
|
||||
return party.getMembers();
|
||||
@ -221,30 +194,30 @@ public class PartyManager {
|
||||
/**
|
||||
* Remove a player from a party.
|
||||
*
|
||||
* @param player The player to remove
|
||||
* @param playerProfile The profile of the player to remove
|
||||
* @param playerName The name of the player to remove
|
||||
* @param party The party
|
||||
*/
|
||||
public void removeFromParty(Player player, PlayerProfile playerProfile) {
|
||||
String playerName = player.getName();
|
||||
Party party = playerProfile.getParty();
|
||||
public void removeFromParty(String playerName, Party party) {
|
||||
List<String> members = party.getMembers();
|
||||
|
||||
if (members.contains(playerName)) {
|
||||
members.remove(playerName);
|
||||
members.remove(playerName);
|
||||
|
||||
if (members.isEmpty()) {
|
||||
parties.remove(party);
|
||||
if (members.isEmpty()) {
|
||||
parties.remove(party);
|
||||
}
|
||||
else {
|
||||
if (party.getLeader().equals(playerName)) {
|
||||
party.setLocked(false);
|
||||
}
|
||||
else {
|
||||
if (party.getLeader().equals(playerName) && party.isLocked()) {
|
||||
party.setLocked(false);
|
||||
}
|
||||
|
||||
informPartyMembersQuit(player, party);
|
||||
}
|
||||
informPartyMembersQuit(playerName, party);
|
||||
}
|
||||
|
||||
playerProfile.removeParty();
|
||||
PlayerProfile playerProfile = Users.getProfile(playerName);
|
||||
|
||||
if (playerProfile != null) {
|
||||
playerProfile.removeParty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -255,7 +228,7 @@ public class PartyManager {
|
||||
* @param partyName The party to add the player to
|
||||
* @param password the password for this party, null if there was no password
|
||||
*/
|
||||
public void addToParty(Player player, PlayerProfile playerProfile, String partyName, String password) {
|
||||
public void joinParty(Player player, PlayerProfile playerProfile, String partyName, String password) {
|
||||
partyName = partyName.replace(".", "");
|
||||
Party party = getParty(partyName);
|
||||
String playerName = player.getName();
|
||||
@ -273,32 +246,45 @@ public class PartyManager {
|
||||
|
||||
parties.add(party);
|
||||
}
|
||||
else {
|
||||
//Don't care about passwords if it isn't locked
|
||||
if (party.isLocked()) {
|
||||
String partyPassword = party.getPassword();
|
||||
else if (!checkJoinability(player, playerProfile, party, password)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (partyPassword != null) {
|
||||
if (password == null) {
|
||||
player.sendMessage("This party requires a password. Use /party <party> <password> to join it."); //TODO: Needs more locale.
|
||||
return;
|
||||
}
|
||||
else if (!password.equalsIgnoreCase(partyPassword)) {
|
||||
player.sendMessage("Party password incorrect."); //TODO: Needs more locale.
|
||||
return;
|
||||
}
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", new Object[]{party.getName()}));
|
||||
addToParty(player.getName(), playerProfile, party);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player can join a party
|
||||
*
|
||||
* @param player The player trying to join a party
|
||||
* @param playerProfile The profile of the player
|
||||
* @param party The party
|
||||
* @param password The password provided by the player
|
||||
* @return true if the player can join the party
|
||||
*/
|
||||
private boolean checkJoinability(Player player, PlayerProfile playerProfile, Party party, String password) {
|
||||
//Don't care about passwords if it isn't locked
|
||||
if (party.isLocked()) {
|
||||
String partyPassword = party.getPassword();
|
||||
|
||||
if (partyPassword != null) {
|
||||
if (password == null) {
|
||||
player.sendMessage("This party requires a password. Use /party <party> <password> to join it."); //TODO: Needs more locale.
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Party is locked."); //TODO: Needs more locale.
|
||||
return;
|
||||
else if (!password.equals(partyPassword)) {
|
||||
player.sendMessage("Party password incorrect."); //TODO: Needs more locale.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Party is locked."); //TODO: Needs more locale.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", new Object[]{partyName}));
|
||||
informPartyMembersJoin(player, party);
|
||||
playerProfile.setParty(party);
|
||||
party.getMembers().add(player.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,18 +292,30 @@ public class PartyManager {
|
||||
*
|
||||
* @param player The player to add to the party
|
||||
* @param playerProfile The profile of the player
|
||||
* @param party The party
|
||||
*/
|
||||
public void addToInvitedParty(Player player, PlayerProfile playerProfile, Party party) {
|
||||
if (!parties.contains(party)) {
|
||||
parties.add(party);
|
||||
public void joinInvitedParty(Player player, PlayerProfile playerProfile) {
|
||||
Party invite = playerProfile.getInvite();
|
||||
|
||||
if (!parties.contains(invite)) {
|
||||
parties.add(invite);
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", new Object[]{party.getName()}));
|
||||
informPartyMembersJoin(player, party);
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", new Object[]{invite.getName()}));
|
||||
playerProfile.removeInvite();
|
||||
addToParty(player.getName(), playerProfile, invite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to a party
|
||||
*
|
||||
* @param playerName The name of the player to add to a party
|
||||
* @param playerProfile The profile of the player
|
||||
* @param party The party
|
||||
*/
|
||||
public void addToParty(String playerName, PlayerProfile playerProfile, Party party) {
|
||||
informPartyMembersJoin(playerName, party);
|
||||
playerProfile.setParty(party);
|
||||
party.getMembers().add(player.getName());
|
||||
party.getMembers().add(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -339,16 +337,10 @@ public class PartyManager {
|
||||
/**
|
||||
* Set the leader of a party.
|
||||
*
|
||||
* @param partyName The party name
|
||||
* @param playerName The name of the player to set as leader
|
||||
* @param party The party
|
||||
*/
|
||||
public void setPartyLeader(String partyName, String playerName) {
|
||||
Party party = getParty(partyName);
|
||||
|
||||
if (party == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void setPartyLeader(String playerName, Party party) {
|
||||
String leaderName = party.getLeader();
|
||||
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
@ -371,7 +363,7 @@ public class PartyManager {
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param playerProfile The profile of the given player
|
||||
* @return true if the player can invite, false otherwise
|
||||
* @return true if the player can invite
|
||||
*/
|
||||
public boolean canInvite(Player player, PlayerProfile playerProfile) {
|
||||
Party party = playerProfile.getParty();
|
||||
|
Loading…
Reference in New Issue
Block a user