mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
No reason to use the SAME CODE in three different clases.
This commit is contained in:
parent
ea25558ac9
commit
35f243a6e6
@ -21,6 +21,21 @@ public final class 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.
|
||||
*
|
||||
|
@ -6,9 +6,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
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.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
@ -16,7 +14,6 @@ import com.gmail.nossr50.util.Users;
|
||||
public class PartyAcceptCommand implements CommandExecutor {
|
||||
private McMMOPlayer mcMMOPlayer;
|
||||
private Player player;
|
||||
private Party playerParty;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
@ -35,17 +32,9 @@ public class PartyAcceptCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Changing parties
|
||||
if (mcMMOPlayer.inParty()) {
|
||||
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)) {
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), mcMMOPlayer.getPartyInvite())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
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;
|
||||
@ -16,7 +15,6 @@ import com.gmail.nossr50.util.Users;
|
||||
public class PartyCreateCommand implements CommandExecutor {
|
||||
private McMMOPlayer mcMMOPlayer;
|
||||
private Player player;
|
||||
private Party playerParty;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
@ -40,15 +38,7 @@ public class PartyCreateCommand implements CommandExecutor {
|
||||
mcMMOPlayer = Users.getPlayer(player);
|
||||
|
||||
// Changing parties
|
||||
if (mcMMOPlayer.inParty()) {
|
||||
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)) {
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), newParty)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
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;
|
||||
@ -46,18 +45,11 @@ public class PartyJoinCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
// Changing parties
|
||||
if (mcMMOPlayer.inParty()) {
|
||||
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), targetParty.getName(), EventReason.CHANGED_PARTIES)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PartyManager.removeFromParty(player.getName(), playerParty);
|
||||
}
|
||||
else if (!PartyManager.handlePartyChangeEvent(player, null, targetParty.getName(), EventReason.JOINED_PARTY)) {
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, playerParty, targetParty)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PartyManager.joinParty(player, mcMMOPlayer, targetParty.getName(), password);
|
||||
PartyManager.joinParty(player, mcMMOPlayer, playerParty.getName(), password);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user