No reason to use the SAME CODE in three different clases.

This commit is contained in:
GJ 2013-02-07 23:59:02 -05:00
parent ea25558ac9
commit 35f243a6e6
4 changed files with 20 additions and 34 deletions

View File

@ -21,6 +21,21 @@ public final class PartyManager {
private PartyManager() {} private PartyManager() {}
public static boolean changeOrJoinParty(McMMOPlayer mcMMOPlayer, Player player, Party oldParty, Party newParty) {
if (mcMMOPlayer.inParty()) {
if (!handlePartyChangeEvent(player, oldParty.getName(), newParty.getName(), EventReason.CHANGED_PARTIES)) {
return false;
}
removeFromParty(player.getName(), oldParty);
}
else if (!handlePartyChangeEvent(player, null, newParty.getName(), EventReason.JOINED_PARTY)) {
return false;
}
return true;
}
/** /**
* Check if two players are in the same party. * Check if two players are in the same party.
* *

View File

@ -6,9 +6,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -16,7 +14,6 @@ import com.gmail.nossr50.util.Users;
public class PartyAcceptCommand implements CommandExecutor { public class PartyAcceptCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
private Player player; private Player player;
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -35,17 +32,9 @@ public class PartyAcceptCommand implements CommandExecutor {
return true; return true;
} }
// Changing parties // Changing parties
if (mcMMOPlayer.inParty()) { if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), mcMMOPlayer.getPartyInvite())) {
playerParty = mcMMOPlayer.getParty();
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), mcMMOPlayer.getPartyInvite().getName(), EventReason.CHANGED_PARTIES)) {
return true;
}
PartyManager.removeFromParty(player.getName(), playerParty);
}
else if (!PartyManager.handlePartyChangeEvent(player, null, mcMMOPlayer.getPartyInvite().getName(), EventReason.JOINED_PARTY)) {
return true; return true;
} }

View File

@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
@ -16,7 +15,6 @@ import com.gmail.nossr50.util.Users;
public class PartyCreateCommand implements CommandExecutor { public class PartyCreateCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
private Player player; private Player player;
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -40,15 +38,7 @@ public class PartyCreateCommand implements CommandExecutor {
mcMMOPlayer = Users.getPlayer(player); mcMMOPlayer = Users.getPlayer(player);
// Changing parties // Changing parties
if (mcMMOPlayer.inParty()) { if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), newParty)) {
playerParty = mcMMOPlayer.getParty();
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), args[1], EventReason.CHANGED_PARTIES)) {
return true;
}
PartyManager.removeFromParty(player.getName(), playerParty);
}
else if (!PartyManager.handlePartyChangeEvent(player, null, args[1], EventReason.JOINED_PARTY)) {
return true; return true;
} }

View File

@ -7,7 +7,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
@ -46,18 +45,11 @@ public class PartyJoinCommand implements CommandExecutor {
} }
// Changing parties // Changing parties
if (mcMMOPlayer.inParty()) { if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, playerParty, targetParty)) {
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), targetParty.getName(), EventReason.CHANGED_PARTIES)) {
return true; return true;
} }
PartyManager.removeFromParty(player.getName(), playerParty); PartyManager.joinParty(player, mcMMOPlayer, playerParty.getName(), password);
}
else if (!PartyManager.handlePartyChangeEvent(player, null, targetParty.getName(), EventReason.JOINED_PARTY)) {
return true;
}
PartyManager.joinParty(player, mcMMOPlayer, targetParty.getName(), password);
return true; return true;
default: default: