mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 02:04:44 +02:00
Added 4 new API methods for adding XP to a player based on blocks
This commit is contained in:
@ -11,9 +11,12 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -1010,6 +1013,74 @@ public final class ExperienceAPI {
|
||||
return mcMMO.getFormulaManager().getCachedXpToLevel(level, getFormulaType(formulaType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given
|
||||
* @param blockStates the blocks to reward XP for
|
||||
* @param mcMMOPlayer the target player
|
||||
*/
|
||||
public static void addXpFromBlocks(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer)
|
||||
{
|
||||
for(BlockState bs : blockStates)
|
||||
{
|
||||
for(PrimarySkillType skillType : PrimarySkillType.values())
|
||||
{
|
||||
if(ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0)
|
||||
{
|
||||
mcMMOPlayer.addXp(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given if it matches the given skillType
|
||||
* @param blockStates the blocks to reward XP for
|
||||
* @param mcMMOPlayer the target player
|
||||
* @param skillType target primary skill
|
||||
*/
|
||||
public static void addXpFromBlocksBySkill(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType)
|
||||
{
|
||||
for(BlockState bs : blockStates)
|
||||
{
|
||||
if(ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0)
|
||||
{
|
||||
mcMMOPlayer.addXp(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given
|
||||
* @param blockState The target blockstate
|
||||
* @param mcMMOPlayer The target player
|
||||
*/
|
||||
public static void addXpFromBlock(BlockState blockState, McMMOPlayer mcMMOPlayer)
|
||||
{
|
||||
for(PrimarySkillType skillType : PrimarySkillType.values())
|
||||
{
|
||||
if(ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0)
|
||||
{
|
||||
mcMMOPlayer.addXp(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given if it matches the given skillType
|
||||
* @param blockState The target blockstate
|
||||
* @param mcMMOPlayer The target player
|
||||
* @param skillType target primary skill
|
||||
*/
|
||||
public static void addXpFromBlockBySkill(BlockState blockState, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType)
|
||||
{
|
||||
if(ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0)
|
||||
{
|
||||
mcMMOPlayer.addXp(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Utility methods follow.
|
||||
private static void addOfflineXP(UUID playerUniqueId, PrimarySkillType skill, int XP) {
|
||||
PlayerProfile profile = getOfflineProfile(playerUniqueId);
|
||||
|
Reference in New Issue
Block a user