mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Remove Static Abuse - ShareHandler -> Moved into Party
This commit is contained in:
parent
1260f4e57a
commit
4815bd7d11
@ -1,6 +1,8 @@
|
|||||||
package com.gmail.nossr50.datatypes.party;
|
package com.gmail.nossr50.datatypes.party;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.party.ShareHandler;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||||
@ -18,6 +20,7 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Party {
|
public class Party {
|
||||||
|
private mcMMO pluginRef;
|
||||||
private static final String ONLINE_PLAYER_PREFIX = "⬤";
|
private static final String ONLINE_PLAYER_PREFIX = "⬤";
|
||||||
private static final String OFFLINE_PLAYER_PREFIX = "○";
|
private static final String OFFLINE_PLAYER_PREFIX = "○";
|
||||||
private final LinkedHashMap<UUID, String> members = new LinkedHashMap<>();
|
private final LinkedHashMap<UUID, String> members = new LinkedHashMap<>();
|
||||||
@ -30,6 +33,8 @@ public class Party {
|
|||||||
private int level;
|
private int level;
|
||||||
private double xp;
|
private double xp;
|
||||||
|
|
||||||
|
private ShareHandler shareHandler;
|
||||||
|
|
||||||
private ShareMode xpShareMode = ShareMode.NONE;
|
private ShareMode xpShareMode = ShareMode.NONE;
|
||||||
private ShareMode itemShareMode = ShareMode.NONE;
|
private ShareMode itemShareMode = ShareMode.NONE;
|
||||||
|
|
||||||
@ -43,27 +48,41 @@ public class Party {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Party(PartyLeader leader, String name) {
|
public Party(PartyLeader leader, String name, mcMMO pluginRef) {
|
||||||
|
this.pluginRef = pluginRef;
|
||||||
this.leader = leader;
|
this.leader = leader;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.locked = true;
|
this.locked = true;
|
||||||
this.level = 0;
|
this.level = 0;
|
||||||
|
|
||||||
|
initShareHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Party(PartyLeader leader, String name, String password) {
|
public Party(PartyLeader leader, String name, String password, mcMMO pluginRef)
|
||||||
|
{
|
||||||
|
this.pluginRef = pluginRef;
|
||||||
this.leader = leader;
|
this.leader = leader;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.locked = true;
|
this.locked = true;
|
||||||
this.level = 0;
|
this.level = 0;
|
||||||
|
|
||||||
|
initShareHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Party(PartyLeader leader, String name, String password, boolean locked) {
|
public Party(PartyLeader leader, String name, String password, boolean locked, mcMMO pluginRef) {
|
||||||
|
this.pluginRef = pluginRef;
|
||||||
this.leader = leader;
|
this.leader = leader;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.locked = locked;
|
this.locked = locked;
|
||||||
this.level = 0;
|
this.level = 0;
|
||||||
|
|
||||||
|
initShareHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initShareHandler() {
|
||||||
|
shareHandler = new ShareHandler(pluginRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedHashMap<UUID, String> getMembers() {
|
public LinkedHashMap<UUID, String> getMembers() {
|
||||||
@ -517,4 +536,8 @@ public class Party {
|
|||||||
|
|
||||||
return this.getName().equals(other.getName());
|
return this.getName().equals(other.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ShareHandler getShareHandler() {
|
||||||
|
return shareHandler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class McMMOPlayer {
|
public class McMMOPlayer {
|
||||||
|
private final mcMMO pluginRef;
|
||||||
private final Map<PrimarySkillType, SkillManager> skillManagers = new HashMap<>();
|
private final Map<PrimarySkillType, SkillManager> skillManagers = new HashMap<>();
|
||||||
private final Map<SuperAbilityType, Boolean> abilityMode = new HashMap<>();
|
private final Map<SuperAbilityType, Boolean> abilityMode = new HashMap<>();
|
||||||
private final Map<SuperAbilityType, Boolean> abilityInformed = new HashMap<>();
|
private final Map<SuperAbilityType, Boolean> abilityInformed = new HashMap<>();
|
||||||
@ -85,7 +86,8 @@ public class McMMOPlayer {
|
|||||||
private HashMap<PrimarySkillType, Double> personalXPModifiers;
|
private HashMap<PrimarySkillType, Double> personalXPModifiers;
|
||||||
private String playerName;
|
private String playerName;
|
||||||
|
|
||||||
public McMMOPlayer(Player player, PlayerProfile profile) {
|
public McMMOPlayer(Player player, PlayerProfile profile, mcMMO pluginRef) {
|
||||||
|
this.pluginRef = pluginRef;
|
||||||
this.playerName = player.getName();
|
this.playerName = player.getName();
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
@ -531,7 +533,7 @@ public class McMMOPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return if the experience has been shared
|
// Return if the experience has been shared
|
||||||
if (party != null && ShareHandler.handleXpShare(xp, this, skill, ShareHandler.getSharedXpGainReason(xpGainReason))) {
|
if (party != null && party.getShareHandler().handleXpShare(xp, this, skill, party.getShareHandler().getSharedXpGainReason(xpGainReason))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import com.gmail.nossr50.datatypes.party.Party;
|
|||||||
import com.gmail.nossr50.datatypes.party.ShareMode;
|
import com.gmail.nossr50.datatypes.party.ShareMode;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -17,7 +18,11 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class ShareHandler {
|
public final class ShareHandler {
|
||||||
private ShareHandler() {
|
private mcMMO pluginRef;
|
||||||
|
private Party party;
|
||||||
|
|
||||||
|
public ShareHandler(mcMMO pluginRef) {
|
||||||
|
this.pluginRef = pluginRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,9 +33,7 @@ public final class ShareHandler {
|
|||||||
* @param primarySkillType Skill being used
|
* @param primarySkillType Skill being used
|
||||||
* @return True is the xp has been shared
|
* @return True is the xp has been shared
|
||||||
*/
|
*/
|
||||||
public static boolean handleXpShare(double xp, McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, XPGainReason xpGainReason) {
|
public boolean handleXpShare(double xp, McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, XPGainReason xpGainReason) {
|
||||||
Party party = mcMMOPlayer.getParty();
|
|
||||||
|
|
||||||
if (party.getXpShareMode() != ShareMode.EQUAL) {
|
if (party.getXpShareMode() != ShareMode.EQUAL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -47,7 +50,7 @@ public final class ShareHandler {
|
|||||||
double shareBonus = Math.min(pluginRef.getPartyXPShareSettings().getPartyShareXPBonusBase()
|
double shareBonus = Math.min(pluginRef.getPartyXPShareSettings().getPartyShareXPBonusBase()
|
||||||
+ (partySize * pluginRef.getPartyXPShareSettings().getPartyShareBonusIncrease()),
|
+ (partySize * pluginRef.getPartyXPShareSettings().getPartyShareBonusIncrease()),
|
||||||
pluginRef.getPartyXPShareSettings().getPartyShareBonusCap());
|
pluginRef.getPartyXPShareSettings().getPartyShareBonusCap());
|
||||||
double splitXp = (double) (xp / partySize * shareBonus);
|
double splitXp = (xp / partySize * shareBonus);
|
||||||
|
|
||||||
for (Player member : nearMembers) {
|
for (Player member : nearMembers) {
|
||||||
//Profile not loaded
|
//Profile not loaded
|
||||||
@ -68,7 +71,7 @@ public final class ShareHandler {
|
|||||||
* @param mcMMOPlayer Player who picked up the item
|
* @param mcMMOPlayer Player who picked up the item
|
||||||
* @return True if the item has been shared
|
* @return True if the item has been shared
|
||||||
*/
|
*/
|
||||||
public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) {
|
public boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) {
|
||||||
ItemStack itemStack = drop.getItemStack();
|
ItemStack itemStack = drop.getItemStack();
|
||||||
ItemShareType dropType = ItemShareType.getShareType(itemStack);
|
ItemShareType dropType = ItemShareType.getShareType(itemStack);
|
||||||
|
|
||||||
@ -76,8 +79,6 @@ public final class ShareHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Party party = mcMMOPlayer.getParty();
|
|
||||||
|
|
||||||
if (!party.sharingDrops(dropType)) {
|
if (!party.sharingDrops(dropType)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -156,14 +157,14 @@ public final class ShareHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getItemWeight(Material material) {
|
private int getItemWeight(Material material) {
|
||||||
if (pluginRef.getConfigManager().getConfigParty().getPartyItemShare().getItemShareMap().get(material) == null)
|
if (pluginRef.getConfigManager().getConfigParty().getPartyItemShare().getItemShareMap().get(material) == null)
|
||||||
return 5;
|
return 5;
|
||||||
else
|
else
|
||||||
return pluginRef.getConfigManager().getConfigParty().getPartyItemShare().getItemShareMap().get(material);
|
return pluginRef.getConfigManager().getConfigParty().getPartyItemShare().getItemShareMap().get(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XPGainReason getSharedXpGainReason(XPGainReason xpGainReason) {
|
public XPGainReason getSharedXpGainReason(XPGainReason xpGainReason) {
|
||||||
if (xpGainReason == XPGainReason.PVE) {
|
if (xpGainReason == XPGainReason.PVE) {
|
||||||
return XPGainReason.SHARED_PVE;
|
return XPGainReason.SHARED_PVE;
|
||||||
} else if (xpGainReason == XPGainReason.PVP) {
|
} else if (xpGainReason == XPGainReason.PVP) {
|
||||||
@ -173,7 +174,7 @@ public final class ShareHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void awardDrop(Player winningPlayer, ItemStack drop) {
|
private void awardDrop(Player winningPlayer, ItemStack drop) {
|
||||||
if (winningPlayer.getInventory().addItem(drop).size() != 0) {
|
if (winningPlayer.getInventory().addItem(drop).size() != 0) {
|
||||||
winningPlayer.getWorld().dropItem(winningPlayer.getLocation(), drop);
|
winningPlayer.getWorld().dropItem(winningPlayer.getLocation(), drop);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user