diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsXLPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsXLPartyModule.java index efb32c8e..92f89b17 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsXLPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsXLPartyModule.java @@ -1,17 +1,30 @@ package net.Indyuce.mmocore.party.compat; +import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostJoinEvent; +import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostLeaveEvent; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.event.group.GroupDisbandEvent; +import de.erethon.dungeonsxl.api.event.group.GroupPlayerJoinEvent; +import de.erethon.dungeonsxl.api.event.group.GroupPlayerLeaveEvent; import de.erethon.dungeonsxl.api.player.PlayerGroup; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.party.AbstractParty; import net.Indyuce.mmocore.party.PartyModule; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import java.util.ArrayList; import java.util.List; import java.util.UUID; -public class DungeonsXLPartyModule implements PartyModule { +public class DungeonsXLPartyModule implements PartyModule, Listener { + + public DungeonsXLPartyModule() { + Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); + } @Override public AbstractParty getParty(PlayerData playerData) { @@ -19,7 +32,43 @@ public class DungeonsXLPartyModule implements PartyModule { return group == null ? null : new CustomParty(group); } - class CustomParty implements AbstractParty { + @EventHandler + public void onPlayerJoin(GroupPlayerJoinEvent event) { + //We add 1 because this returns the members of the group excluding the player that just joined. + int membersSize = event.getGroup().getMembers().size() + 1; + applyStatBonuses(PlayerData.get(event.getPlayer().getPlayer()), membersSize); + event.getGroup().getMembers().getOnlinePlayers() + .forEach(p -> applyStatBonuses(PlayerData.get(p), membersSize)); + } + + @EventHandler + public void onPlayerLeave(GroupPlayerLeaveEvent event) { + int membersSize = event.getGroup().getMembers().size(); + clearStatBonuses(PlayerData.get(event.getPlayer().getPlayer())); + event.getGroup().getMembers().getOnlinePlayers() + .forEach(p -> applyStatBonuses(PlayerData.get(p), membersSize)); + } + + @EventHandler + public void onGroupDisband(GroupDisbandEvent event) { + event.getGroup().getMembers().getOnlinePlayers().forEach(p -> clearStatBonuses(PlayerData.get(p))); + } + + /** + * Applies party stat bonuses to a specific player + */ + private void applyStatBonuses(PlayerData player, int membersSize) { + MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(membersSize - 1).register(player.getMMOPlayerData())); + } + + /** + * Clear party stat bonuses from a player + */ + private void clearStatBonuses(PlayerData player) { + MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); + } + + class CustomParty implements AbstractParty, Listener { private final PlayerGroup group; public CustomParty(PlayerGroup group) { @@ -48,5 +97,6 @@ public class DungeonsXLPartyModule implements PartyModule { public int countMembers() { return group.getMembers().getUniqueIds().size(); } + } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/McMMOPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/McMMOPartyModule.java index 7283bffa..5da0bf71 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/McMMOPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/McMMOPartyModule.java @@ -2,17 +2,28 @@ package net.Indyuce.mmocore.party.compat; import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.events.party.McMMOPartyChangeEvent; +import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.util.player.UserManager; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.party.AbstractParty; import net.Indyuce.mmocore.party.PartyModule; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -public class McMMOPartyModule implements PartyModule { +public class McMMOPartyModule implements PartyModule, Listener { + + + public McMMOPartyModule() { + Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); + } @Nullable @Override @@ -22,11 +33,53 @@ public class McMMOPartyModule implements PartyModule { return party == null ? null : new CustomParty(party); } - class CustomParty implements AbstractParty { + + @EventHandler + public void onChange(McMMOPartyChangeEvent event) { + if (event.getNewParty() != null) { + Party party = PartyManager.getParty(event.getNewParty()); + if (party != null) { + //This is the size of the party before the player joins=> we increment it by 1. + int membersSize = party.getMembers().size(); + if(membersSize!=1 || party.getOnlineMembers().get(0)!=event.getPlayer()) { + party.getOnlineMembers() + .forEach(p -> applyStatBonuses(PlayerData.get(p), membersSize+1)); + applyStatBonuses(PlayerData.get(event.getPlayer()), membersSize+1); + } + } + } + if (event.getOldParty() != null) { + Party party = PartyManager.getParty(event.getOldParty()); + if (party != null) { + //This is the size of the party before the player leaves=> we decrement it by 1. + int membersSize = party.getMembers().size() - 1; + party.getOnlineMembers() + .forEach(p -> applyStatBonuses(PlayerData.get(p), membersSize)); + clearStatBonuses(PlayerData.get(event.getPlayer().getPlayer())); + } + } + } + + /** + * Applies party stat bonuses to a specific player + */ + private void applyStatBonuses(PlayerData player, int membersSize) { + MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(membersSize - 1).register(player.getMMOPlayerData())); + } + + /** + * Clear party stat bonuses from a player + */ + private void clearStatBonuses(PlayerData player) { + MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); + } + + class CustomParty implements AbstractParty, Listener { private final Party party; public CustomParty(Party party) { this.party = party; + Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); } @Override diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java index 480d5fbd..07edf5da 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java @@ -1,20 +1,29 @@ package net.Indyuce.mmocore.party.compat; import com.alessiodp.parties.api.Parties; +import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostJoinEvent; +import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostLeaveEvent; import com.alessiodp.parties.api.interfaces.PartiesAPI; import com.alessiodp.parties.api.interfaces.Party; import com.alessiodp.parties.api.interfaces.PartyPlayer; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.party.AbstractParty; import net.Indyuce.mmocore.party.PartyModule; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -public class PartiesPartyModule implements PartyModule { +public class PartiesPartyModule implements PartyModule,Listener { + + public PartiesPartyModule(){ + Bukkit.getPluginManager().registerEvents(this,MMOCore.plugin); + } @Nullable @Override @@ -25,7 +34,36 @@ public class PartiesPartyModule implements PartyModule { return party == null ? null : new CustomParty(party); } - class CustomParty implements AbstractParty { + + @EventHandler + public void onPlayerJoin(BukkitPartiesPlayerPostJoinEvent event){ + int membersSize=event.getParty().getMembers().size(); + event.getParty().getOnlineMembers() + .forEach(p-> applyStatBonuses(PlayerData.get(p.getPlayerUUID()),membersSize)); + } + @EventHandler + public void onPlayerLeave(BukkitPartiesPlayerPostLeaveEvent event){ + int membersSize=event.getParty().getMembers().size(); + clearStatBonuses(PlayerData.get(event.getPartyPlayer().getPlayerUUID())); + event.getParty().getOnlineMembers() + .forEach(p-> applyStatBonuses(PlayerData.get(p.getPlayerUUID()),membersSize)); + } + + /** + * Applies party stat bonuses to a specific player + */ + private void applyStatBonuses(PlayerData player,int membersSize) { + MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(membersSize - 1).register(player.getMMOPlayerData())); + } + + /** + * Clear party stat bonuses from a player + */ + private void clearStatBonuses(PlayerData player) { + MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); + } + + class CustomParty implements AbstractParty { private final Party party; public CustomParty(Party party) {