Trigger change event for party create/disband (#4620)

This commit is contained in:
PikaMug 2021-09-22 18:05:41 -04:00 committed by GitHub
parent 280eb0ba51
commit 162c605dac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.party;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
@ -15,13 +16,14 @@ public class PartyDisbandCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
if (UserManager.getPlayer((Player) sender) == null) {
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
if (mcMMOPlayer == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
String partyName = playerParty.getName();
final Party playerParty = mcMMOPlayer.getParty();
final String partyName = playerParty.getName();
for (Player member : playerParty.getOnlineMembers()) {
if (!PartyManager.handlePartyChangeEvent(member, partyName, null, EventReason.KICKED_FROM_PARTY)) {
@ -31,7 +33,7 @@ public class PartyDisbandCommand implements CommandExecutor {
member.sendMessage(LocaleLoader.getString("Party.Disband"));
}
PartyManager.disbandParty(playerParty);
PartyManager.disbandParty(mcMMOPlayer, playerParty);
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "disband"));

View File

@ -53,6 +53,16 @@ public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable {
* A list of reasons why the event may have been fired
*/
public enum EventReason {
/**
* Created a party.
*/
CREATED_PARTY,
/**
* Disbanded a party.
*/
DISBANDED_PARTY,
/**
* Joined a party for the first time.
*/

View File

@ -347,10 +347,20 @@ public final class PartyManager {
* Disband a party. Kicks out all members and removes the party.
*
* @param party The party to remove
* @deprecated Use {@link #disbandParty(McMMOPlayer, Party)}
*/
public static void disbandParty(Party party) {
disbandParty(null, party);
}
/**
* Disband a party. Kicks out all members and removes the party.
*
* @param party The party to remove
*/
public static void disbandParty(McMMOPlayer mcMMOPlayer, Party party) {
//TODO: Potential issues with unloaded profile?
for (Player member : party.getOnlineMembers()) {
for (final Player member : party.getOnlineMembers()) {
//Profile not loaded
if(UserManager.getPlayer(member) == null)
{
@ -366,6 +376,9 @@ public final class PartyManager {
}
parties.remove(party);
if (mcMMOPlayer != null) {
handlePartyChangeEvent(mcMMOPlayer.getPlayer(), party.getName(), null, EventReason.DISBANDED_PARTY);
}
}
/**
@ -388,6 +401,7 @@ public final class PartyManager {
player.sendMessage(LocaleLoader.getString("Commands.Party.Create", party.getName()));
addToParty(mcMMOPlayer, party);
handlePartyChangeEvent(player, null, partyName, EventReason.CREATED_PARTY);
}
/**