Moving party stuff from PlayerProfile to McMMOPlayer

This commit is contained in:
bm01 2013-02-03 16:27:59 +01:00
parent 52bd48cde7
commit 51305118fa
9 changed files with 191 additions and 247 deletions

View File

@ -20,7 +20,7 @@ public final class PartyAPI {
* @return the name of the player's party
*/
public static String getPartyName(Player player) {
return Users.getPlayer(player).getProfile().getParty().getName();
return Users.getPlayer(player).getParty().getName();
}
/**
@ -32,7 +32,7 @@ public final class PartyAPI {
* @return true if the player is in a party, false otherwise
*/
public static boolean inParty(Player player) {
return Users.getPlayer(player).getProfile().inParty();
return Users.getPlayer(player).inParty();
}
/**
@ -77,7 +77,7 @@ public final class PartyAPI {
party.setLeader(playerName);
}
PartyManager.addToParty(playerName, Users.getPlayer(player).getProfile(), party);
PartyManager.addToParty(playerName, Users.getPlayer(player), party);
}
/**
@ -88,7 +88,7 @@ public final class PartyAPI {
* @param player The player to remove
*/
public static void removeFromParty(Player player) {
PartyManager.removeFromParty(player.getName(), Users.getPlayer(player).getProfile().getParty());
PartyManager.removeFromParty(player.getName(), Users.getPlayer(player).getParty());
}
/**

View File

@ -8,14 +8,14 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users;
public class ACommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
McMMOPlayer mcMMOPlayer;
String usage = LocaleLoader.getString("Commands.Usage.1", "a", "<" + LocaleLoader.getString("Commands.Usage.Message") + ">");
if (CommandHelper.noCommandPermissions(sender, "mcmmo.chat.adminchat")) {
@ -25,15 +25,15 @@ public class ACommand implements CommandExecutor {
switch (args.length) {
case 0:
if (sender instanceof Player) {
profile = Users.getProfile((Player) sender);
mcMMOPlayer = Users.getPlayer((Player) sender);
if (profile.getPartyChatMode()) {
profile.togglePartyChat();
if (mcMMOPlayer.getPartyChatMode()) {
mcMMOPlayer.togglePartyChat();
}
profile.toggleAdminChat();
mcMMOPlayer.toggleAdminChat();
if (profile.getAdminChatMode()) {
if (mcMMOPlayer.getAdminChatMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.AdminChat.On"));
}
else {

View File

@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
@ -23,7 +23,7 @@ public class PCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
McMMOPlayer mcMMOPlayer;
String usage = LocaleLoader.getString("Commands.Usage.2", "p", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "<" + LocaleLoader.getString("Commands.Usage.Message") + ">");
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
@ -33,15 +33,15 @@ public class PCommand implements CommandExecutor {
switch (args.length) {
case 0:
if (sender instanceof Player) {
profile = Users.getProfile((Player) sender);
mcMMOPlayer = Users.getPlayer((Player) sender);
if (profile.getAdminChatMode()) {
profile.toggleAdminChat();
if (mcMMOPlayer.getAdminChatMode()) {
mcMMOPlayer.toggleAdminChat();
}
profile.togglePartyChat();
mcMMOPlayer.togglePartyChat();
if (profile.getPartyChatMode()) {
if (mcMMOPlayer.getPartyChatMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.On"));
}
else {
@ -57,7 +57,7 @@ public class PCommand implements CommandExecutor {
default:
if (sender instanceof Player) {
Player player = (Player) sender;
Party party = Users.getProfile(player).getParty();
Party party = Users.getPlayer(player).getParty();
if (party == null) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));

View File

@ -23,6 +23,12 @@ public class McMMOPlayer {
private PlayerProfile profile;
private Party party;
private Party invite;
private Player ptpRequest;
private boolean ptpEnabled = true;
private boolean ptpConfirmRequired = Config.getInstance().getPTPCommandConfirmRequired();
private long ptpTimeout;
private boolean partyChatMode;
private boolean adminChatMode;
public McMMOPlayer (Player player) {
String playerName = player.getName();
@ -204,4 +210,60 @@ public class McMMOPlayer {
public void removeInvite() {
invite = null;
}
public boolean getPtpEnabled() {
return ptpEnabled;
}
public void togglePtpUse() {
ptpEnabled = !ptpEnabled;
}
public Player getPtpRequest() {
return ptpRequest;
}
public void setPtpRequest(Player ptpRequest) {
this.ptpRequest = ptpRequest;
}
public boolean hasPtpRequest() {
return (ptpRequest != null) ? true : false;
}
public void removePtpRequest() {
ptpRequest = null;
}
public boolean getPtpConfirmRequired() {
return ptpConfirmRequired;
}
public void togglePtpConfirmRequired() {
ptpConfirmRequired = !ptpConfirmRequired;
}
public long getPtpTimeout() {
return ptpTimeout;
}
public void actualizePtpTimeout() {
ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
}
public boolean getAdminChatMode() {
return adminChatMode;
}
public void toggleAdminChat() {
adminChatMode = !adminChatMode;
}
public boolean getPartyChatMode() {
return partyChatMode;
}
public void togglePartyChat() {
partyChatMode = !partyChatMode;
}
}

View File

@ -7,13 +7,9 @@ import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.skills.utilities.ToolType;
@ -23,25 +19,16 @@ import com.gmail.nossr50.spout.huds.SpoutHud;
import com.gmail.nossr50.util.Misc;
public class PlayerProfile {
private String playerName;
// HUD
private SpoutHud spoutHud;
private HudType hudType;
// Party Stuff
private Party party;
private Party invite;
private Player ptpRequest;
private boolean ptpEnabled = true;
private boolean ptpConfirmRequired = Config.getInstance().getPTPCommandConfirmRequired();
// Toggles
private boolean loaded;
private boolean placedAnvil;
private boolean placedSalvageAnvil;
private boolean partyChatMode, adminChatMode;
private boolean godMode;
private boolean greenTerraMode, treeFellerMode, superBreakerMode, gigaDrillBreakerMode, serratedStrikesMode, skullSplitterMode, berserkMode;
private boolean greenTerraInformed = true, berserkInformed = true, skullSplitterInformed = true, gigaDrillBreakerInformed = true,
@ -53,7 +40,6 @@ public class PlayerProfile {
// Timestamps
private long recentlyHurt;
private int respawnATS;
private long ptpTimeout;
// mySQL STUFF
private int userId;
@ -67,7 +53,6 @@ public class PlayerProfile {
public PlayerProfile(String playerName, boolean addNew) {
this.playerName = playerName;
party = PartyManager.getPlayerParty(playerName);
if (mcMMO.spoutEnabled) {
hudType = SpoutConfig.getInstance().defaultHudType;
@ -546,26 +531,6 @@ public class PlayerProfile {
this.hudType = hudType;
}
/*
* Chat Stuff
*/
public boolean getAdminChatMode() {
return adminChatMode;
}
public void toggleAdminChat() {
adminChatMode = !adminChatMode;
}
public boolean getPartyChatMode() {
return partyChatMode;
}
public void togglePartyChat() {
partyChatMode = !partyChatMode;
}
/*
* Tools
*/
@ -1172,92 +1137,4 @@ public class PlayerProfile {
/*
* Party Stuff
*/
public void setInvite(Party invite) {
this.invite = invite;
}
public Party getInvite() {
return invite;
}
public boolean hasPartyInvite() {
if (invite != null) {
return true;
}
return false;
}
public void setParty(Party party) {
this.party = party;
}
public Party getParty() {
return party;
}
public boolean inParty() {
if (party != null) {
return true;
}
return false;
}
public void removeParty() {
party = null;
}
public void removeInvite() {
invite = null;
}
/*
* Party Teleportation
*/
public boolean getPtpEnabled() {
return ptpEnabled;
}
public void togglePtpUse() {
ptpEnabled = !ptpEnabled;
}
public void setPtpRequest(Player ptpRequest) {
this.ptpRequest = ptpRequest;
}
public Player getPtpRequest() {
return ptpRequest;
}
public boolean hasPtpRequest() {
if (ptpRequest != null) {
return true;
}
return false;
}
public void removePtpRequest() {
ptpRequest = null;
}
public boolean getPtpConfirmRequired() {
return ptpConfirmRequired;
}
public void togglePtpConfirmRequired() {
ptpConfirmRequired = !ptpConfirmRequired;
}
public long getPtpTimeout() {
return ptpTimeout;
}
public void actualizePtpTimeout() {
ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
}
}

View File

@ -63,15 +63,16 @@ public class PlayerListener implements Listener {
return;
}
PlayerProfile profile = Users.getPlayer(player).getProfile();
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
if (profile.getGodMode() && !Permissions.mcgod(player)) {
profile.toggleGodMode();
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Forbidden"));
}
if (profile.inParty() && !Permissions.party(player)) {
profile.removeParty();
if (mcMMOPlayer.inParty() && !Permissions.party(player)) {
mcMMOPlayer.removeParty();
player.sendMessage(LocaleLoader.getString("Party.Forbidden"));
}
}
@ -334,10 +335,10 @@ public class PlayerListener implements Listener {
return;
}
PlayerProfile profile = Users.getPlayer(player).getProfile();
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
if (profile.getPartyChatMode()) {
Party party = profile.getParty();
if (mcMMOPlayer.getPartyChatMode()) {
Party party = mcMMOPlayer.getParty();
if (party == null) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
@ -347,7 +348,7 @@ public class PlayerListener implements Listener {
ChatManager.handlePartyChat(plugin, party, player.getName(), player.getDisplayName(), event.getMessage());
event.setCancelled(true);
}
else if (profile.getAdminChatMode()) {
else if (mcMMOPlayer.getAdminChatMode()) {
ChatManager.handleAdminChat(plugin, player.getName(), player.getDisplayName(), event.getMessage());
event.setCancelled(true);
}

View File

@ -8,6 +8,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
@ -27,15 +28,15 @@ public final class PartyManager {
* @return true if they are in the same party, false otherwise
*/
public static boolean inSameParty(Player firstPlayer, Player secondPlayer) {
PlayerProfile firstProfile = Users.getProfile(firstPlayer);
PlayerProfile secondProfile = Users.getProfile(secondPlayer);
McMMOPlayer firstMcMMOPlayer = Users.getPlayer(firstPlayer);
McMMOPlayer secondMcMMOPlayer = Users.getPlayer(secondPlayer);
if (firstProfile == null || secondProfile == null) {
if (firstMcMMOPlayer == null || secondMcMMOPlayer == null) {
return false;
}
Party firstParty = firstProfile.getParty();
Party secondParty = secondProfile.getParty();
Party firstParty = firstMcMMOPlayer.getParty();
Party secondParty = secondMcMMOPlayer.getParty();
if (firstParty == null || secondParty == null || firstParty != secondParty) {
return false;
@ -98,7 +99,7 @@ public final class PartyManager {
* @return all the players in the player's party
*/
public static List<String> getAllMembers(Player player) {
Party party = Users.getProfile(player).getParty();
Party party = Users.getPlayer(player).getParty();
if (party == null) {
return null;
@ -197,10 +198,10 @@ public final class PartyManager {
informPartyMembersQuit(playerName, party);
}
PlayerProfile playerProfile = Users.getProfile(playerName);
if (playerProfile != null) {
playerProfile.removeParty();
McMMOPlayer mcMMOPlayer = Users.getPlayer(playerName);
if (mcMMOPlayer != null) {
mcMMOPlayer.removeParty();
}
}
@ -213,10 +214,11 @@ public final class PartyManager {
List<String> members = party.getMembers();
for (String member : party.getMembers()) {
PlayerProfile playerProfile = Users.getProfile(member);
if (playerProfile != null) {
playerProfile.removeParty();
McMMOPlayer mcMMOPlayer = Users.getPlayer(member);
if (mcMMOPlayer != null) {
mcMMOPlayer.removeParty();
}
}
@ -230,11 +232,11 @@ public final class PartyManager {
* Create a new party
*
* @param player The player to add to the party
* @param playerProfile The profile of the player to add to the party
* @param mcMMOPlayer The player to add to the party
* @param partyName The party to add the player to
* @param password the password for this party, null if there was no password
* @param password The password for this party, null if there was no password
*/
public static void createParty(Player player, PlayerProfile playerProfile, String partyName, String password) {
public static void createParty(Player player, McMMOPlayer mcMMOPlayer, String partyName, String password) {
partyName = partyName.replace(".", "");
Party party = getParty(partyName);
String playerName = player.getName();
@ -260,18 +262,18 @@ public final class PartyManager {
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Create", party.getName()));
addToParty(player.getName(), playerProfile, party);
addToParty(player.getName(), mcMMOPlayer, party);
}
/**
* Add a player to a party.
*
* @param player The player to add to the party
* @param playerProfile The profile of the player to add to the party
* @param mcMMOPlayer The player to add to the party
* @param partyName The party to add the player to
* @param password the password for this party, null if there was no password
*/
public static void joinParty(Player player, PlayerProfile playerProfile, String partyName, String password) {
public static void joinParty(Player player, McMMOPlayer mcMMOPlayer, String partyName, String password) {
partyName = partyName.replace(".", "");
Party party = getParty(partyName);
String playerName = player.getName();
@ -294,7 +296,7 @@ public final class PartyManager {
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", party.getName()));
addToParty(player.getName(), playerProfile, party);
addToParty(player.getName(), mcMMOPlayer, party);
}
/**
@ -333,31 +335,31 @@ public final class PartyManager {
/**
* Accept a party invitation
*
* @param player The player to add to the party
* @param playerProfile The profile of the player
* @param Player The plaer to add to the party
* @param mcMMOPlayer The player to add to the party
*/
public static void joinInvitedParty(Player player, PlayerProfile playerProfile) {
Party invite = playerProfile.getInvite();
public static void joinInvitedParty(Player player, McMMOPlayer mcMMOPlayer) {
Party invite = mcMMOPlayer.getInvite();
if (!parties.contains(invite)) {
parties.add(invite);
}
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", invite.getName()));
playerProfile.removeInvite();
addToParty(player.getName(), playerProfile, invite);
mcMMOPlayer.removeInvite();
addToParty(player.getName(), mcMMOPlayer, 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 mcMMOPlayer The player to add to the party
* @param party The party
*/
public static void addToParty(String playerName, PlayerProfile playerProfile, Party party) {
public static void addToParty(String playerName, McMMOPlayer mcMMOPlayer, Party party) {
informPartyMembersJoin(playerName, party);
playerProfile.setParty(party);
mcMMOPlayer.setParty(party);
party.getMembers().add(playerName);
}
@ -402,14 +404,14 @@ public final class PartyManager {
}
/**
* Check if a player can invite others to their party.
* Check if a player can invite others to his party.
*
* @param player The player to check
* @param playerProfile The profile of the given player
* @param mcMMOPlayer The player to check
* @return true if the player can invite
*/
public static boolean canInvite(Player player, PlayerProfile playerProfile) {
Party party = playerProfile.getParty();
public static boolean canInvite(Player player, McMMOPlayer mcMMOPlayer) {
Party party = mcMMOPlayer.getParty();
if (party == null || (party.isLocked() && !party.getLeader().equals(player.getName()))) {
return false;

View File

@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader;
@ -20,8 +20,8 @@ import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.util.Users;
public class PartyCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
private PlayerProfile playerProfile;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -33,8 +33,8 @@ public class PartyCommand implements CommandExecutor {
return true;
}
this.player = (Player) sender;
this.playerProfile = Users.getProfile(player);
player = (Player) sender;
mcMMOPlayer = Users.getPlayer(player);
if (args.length < 1 || args[0].equalsIgnoreCase("info")) {
return party();
@ -53,7 +53,7 @@ public class PartyCommand implements CommandExecutor {
return printHelp();
}
if (playerProfile.inParty()) {
if (mcMMOPlayer.inParty()) {
if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) {
return quit();
}
@ -104,8 +104,8 @@ public class PartyCommand implements CommandExecutor {
}
private boolean party() {
if (playerProfile.inParty()) {
Party party = playerProfile.getParty();
if (mcMMOPlayer.inParty()) {
Party party = mcMMOPlayer.getParty();
Server server = mcMMO.p.getServer();
String leader = party.getLeader();
@ -174,9 +174,6 @@ public class PartyCommand implements CommandExecutor {
return true;
}
String playerName = player.getName();
Party party = playerProfile.getParty();
if (args.length < 2) {
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
return true;
@ -189,7 +186,7 @@ public class PartyCommand implements CommandExecutor {
return false;
}
if (!Users.getProfile(target).inParty()) {
if (!mcMMOPlayer.inParty()) {
player.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", args[1]));
return false;
}
@ -199,7 +196,9 @@ public class PartyCommand implements CommandExecutor {
return true;
}
if (party != null && party.equals(Users.getProfile(target).getParty())) {
Party party = mcMMOPlayer.getParty();
if (party != null && party.equals(Users.getPlayer(target).getParty())) {
player.sendMessage(LocaleLoader.getString("Party.Join.Self"));
return true;
}
@ -210,26 +209,26 @@ public class PartyCommand implements CommandExecutor {
password = args[2];
}
String partyTarget = PartyManager.getPlayerParty(target.getName()).getName();
Party newParty = PartyManager.getParty(args[0]);
Party targetParty = Users.getPlayer(target).getParty();
// Check to see if the party exists, and if it does, can the player join it?
if (newParty != null && !PartyManager.checkJoinability(player, newParty, null)) {
if (targetParty != null && !PartyManager.checkJoinability(player, targetParty, null)) {
return true; // End before any event is fired.
}
// TODO: We shoudln't fire the event before checking if the password is correct
if (party != null) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), partyTarget, EventReason.CHANGED_PARTIES);
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), targetParty.getName(), EventReason.CHANGED_PARTIES);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
PartyManager.removeFromParty(playerName, party);
PartyManager.removeFromParty(player.getName(), party);
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyTarget, EventReason.JOINED_PARTY);
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, targetParty.getName(), EventReason.JOINED_PARTY);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
@ -237,7 +236,8 @@ public class PartyCommand implements CommandExecutor {
}
}
PartyManager.joinParty(player, playerProfile, partyTarget, password);
PartyManager.joinParty(player, mcMMOPlayer, targetParty.getName(), password);
return true;
}
@ -246,10 +246,10 @@ public class PartyCommand implements CommandExecutor {
return true;
}
if (playerProfile.hasPartyInvite()) {
if (playerProfile.inParty()) {
Party party = playerProfile.getParty();
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), playerProfile.getInvite().getName(), EventReason.CHANGED_PARTIES);
if (mcMMOPlayer.hasPartyInvite()) {
if (mcMMOPlayer.inParty()) {
Party party = mcMMOPlayer.getParty();
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), mcMMOPlayer.getInvite().getName(), EventReason.CHANGED_PARTIES);
mcMMO.p.getServer().getPluginManager().callEvent(event);
@ -260,7 +260,7 @@ public class PartyCommand implements CommandExecutor {
PartyManager.removeFromParty(player.getName(), party);
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, playerProfile.getInvite().getName(), EventReason.JOINED_PARTY);
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, mcMMOPlayer.getInvite().getName(), EventReason.JOINED_PARTY);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
@ -268,7 +268,7 @@ public class PartyCommand implements CommandExecutor {
}
}
PartyManager.joinInvitedParty(player, playerProfile);
PartyManager.joinInvitedParty(player, mcMMOPlayer);
}
else {
player.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
@ -283,7 +283,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
if (args.length < 2) {
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
@ -304,7 +304,7 @@ public class PartyCommand implements CommandExecutor {
return true;
}
if (playerProfile.inParty()) {
if (mcMMOPlayer.inParty()) {
String oldPartyName = party.getName();
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, partyname, EventReason.CHANGED_PARTIES);
mcMMO.p.getServer().getPluginManager().callEvent(event);
@ -314,7 +314,7 @@ public class PartyCommand implements CommandExecutor {
}
PartyManager.removeFromParty(playerName, party);
PartyManager.createParty(player, playerProfile, partyname, password);
PartyManager.createParty(player, mcMMOPlayer, partyname, password);
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyname, EventReason.JOINED_PARTY);
@ -324,7 +324,7 @@ public class PartyCommand implements CommandExecutor {
return true;
}
PartyManager.createParty(player, playerProfile, partyname, password);
PartyManager.createParty(player, mcMMOPlayer, partyname, password);
return true;
}
@ -337,7 +337,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
if (party != null) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), null, EventReason.LEFT_PARTY);
@ -361,15 +361,14 @@ public class PartyCommand implements CommandExecutor {
return true;
}
String playerName = player.getName();
PlayerProfile playerProfile = Users.getProfile(player);
Party party = playerProfile.getParty();
if (args.length < 2) {
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "[sharemode]"));
return true;
}
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
if (party.getLeader().equals(playerName)) {
if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("false")) {
party.setXpShareMode(ShareHandler.XpShareMode.NONE);
@ -411,7 +410,7 @@ public class PartyCommand implements CommandExecutor {
switch (args.length) {
case 2:
if (!playerProfile.inParty()) {
if (!mcMMOPlayer.inParty()) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true;
}
@ -423,10 +422,11 @@ public class PartyCommand implements CommandExecutor {
player.sendMessage(LocaleLoader.getString("Party.Player.InSameParty"));
return true;
}
if (PartyManager.canInvite(player, playerProfile)) {
Party party = playerProfile.getParty();
Users.getProfile(target).setInvite(party);
if (PartyManager.canInvite(player, mcMMOPlayer)) {
Party party = mcMMOPlayer.getParty();
Users.getPlayer(target).setInvite(party);
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", party.getName(), player.getName()));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1"));
@ -455,7 +455,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
if (party.getLeader().equals(playerName)) {
if (!party.getMembers().contains(targetName)) {
@ -496,7 +496,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
if (party.getLeader().equals(playerName)) {
for (Player onlineMembers : party.getOnlineMembers()) {
@ -528,7 +528,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
if (args.length < 2) {
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "owner", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
@ -556,7 +556,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
if (party != null) {
if (party.getLeader().equals(playerName)) {
@ -588,7 +588,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
if (party != null) {
if (party.getLeader().equals(playerName)) {
@ -617,7 +617,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
if (!party.getLeader().equals(playerName)) {
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
@ -647,7 +647,7 @@ public class PartyCommand implements CommandExecutor {
}
String playerName = player.getName();
Party party = playerProfile.getParty();
Party party = mcMMOPlayer.getParty();
String leader = party.getLeader();
if (party.getLeader().equals(playerName)) {

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.locale.LocaleLoader;
@ -18,7 +19,7 @@ import com.gmail.nossr50.util.Users;
public class PtpCommand implements CommandExecutor {
private final mcMMO plugin;
private Player player;
private PlayerProfile playerProfile;
private McMMOPlayer mcMMOPlayer;
public PtpCommand(mcMMO instance) {
this.plugin = instance;
@ -38,8 +39,9 @@ public class PtpCommand implements CommandExecutor {
switch (args.length) {
case 1:
this.player = (Player) sender;
this.playerProfile = Users.getProfile(player);
player = (Player) sender;
mcMMOPlayer = Users.getPlayer(player);
PlayerProfile playerProfile = mcMMOPlayer.getProfile();
if (args[0].equalsIgnoreCase("toggle")) {
return togglePartyTeleportation();
@ -86,15 +88,15 @@ public class PtpCommand implements CommandExecutor {
}
if (PartyManager.inSameParty(player, target)) {
PlayerProfile targetProfile = Users.getProfile(target);
McMMOPlayer targetMcMMOPlayer = Users.getPlayer(target);
if (!targetProfile.getPtpEnabled()) {
if (!targetMcMMOPlayer.getPtpEnabled()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", target.getName()));
return true;
}
if (!Users.getProfile(target).getPtpConfirmRequired()) {
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, playerProfile.getParty().getName());
if (!targetMcMMOPlayer.getPtpConfirmRequired()) {
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, mcMMOPlayer.getParty().getName());
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
@ -104,10 +106,10 @@ public class PtpCommand implements CommandExecutor {
player.teleport(target);
player.sendMessage(LocaleLoader.getString("Party.Teleport.Player", player.getName()));
target.sendMessage(LocaleLoader.getString("Party.Teleport.Target", target.getName()));
playerProfile.setRecentlyHurt(System.currentTimeMillis());
mcMMOPlayer.getProfile().setRecentlyHurt(System.currentTimeMillis());
} else {
targetProfile.setPtpRequest(player);
targetProfile.actualizePtpTimeout();
targetMcMMOPlayer.setPtpRequest(player);
targetMcMMOPlayer.actualizePtpTimeout();
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout();
@ -122,20 +124,20 @@ public class PtpCommand implements CommandExecutor {
}
private boolean acceptTeleportRequest() {
if (!playerProfile.hasPtpRequest()) {
if (!mcMMOPlayer.hasPtpRequest()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
return true;
}
int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout();
if ((playerProfile.getPtpTimeout() + ptpRequestExpire) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
playerProfile.removePtpRequest();
if ((mcMMOPlayer.getPtpTimeout() + ptpRequestExpire) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
mcMMOPlayer.removePtpRequest();
player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired"));
return true;
}
Player target = playerProfile.getPtpRequest();
Player target = mcMMOPlayer.getPtpRequest();
if (target == null) {
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
@ -147,7 +149,7 @@ public class PtpCommand implements CommandExecutor {
return true;
}
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, playerProfile.getParty().getName());
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, mcMMOPlayer.getParty().getName());
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
@ -157,31 +159,31 @@ public class PtpCommand implements CommandExecutor {
target.teleport(player);
target.sendMessage(LocaleLoader.getString("Party.Teleport.Player", player.getName()));
player.sendMessage(LocaleLoader.getString("Party.Teleport.Target", target.getName()));
playerProfile.setRecentlyHurt(System.currentTimeMillis());
mcMMOPlayer.getProfile().setRecentlyHurt(System.currentTimeMillis());
return true;
}
private boolean acceptAnyTeleportRequest() {
if (playerProfile.getPtpConfirmRequired()) {
if (mcMMOPlayer.getPtpConfirmRequired()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled"));
}
playerProfile.togglePtpConfirmRequired();
mcMMOPlayer.togglePtpConfirmRequired();
return true;
}
private boolean togglePartyTeleportation() {
if (playerProfile.getPtpEnabled()) {
if (mcMMOPlayer.getPtpEnabled()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
}
playerProfile.togglePtpUse();
mcMMOPlayer.togglePtpUse();
return true;
}
}