Merge branch 'master' of github.com:mcMMO-Dev/mcMMO into configurable

This commit is contained in:
nossr50
2019-06-26 21:55:41 -07:00
50 changed files with 1771 additions and 1301 deletions

View File

@@ -207,7 +207,7 @@ public class EventUtils {
}
public static boolean handleLevelChangeEvent(Player player, PrimarySkillType skill, int levelsChanged, double xpRemoved, boolean isLevelUp, XPGainReason xpGainReason) {
public static boolean tryLevelChangeEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason) {
McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason);
mcMMO.p.getServer().getPluginManager().callEvent(event);
@@ -220,10 +220,10 @@ public class EventUtils {
profile.addXp(skill, xpRemoved);
}
return !isCancelled;
return isCancelled;
}
public static void handleLevelChangeEventEdit(Player player, PrimarySkillType skill, int levelsChanged, double xpRemoved, boolean isLevelUp, XPGainReason xpGainReason, int oldLevel) {
public static boolean tryLevelEditEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason, int oldLevel) {
McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged - oldLevel, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason);
mcMMO.p.getServer().getPluginManager().callEvent(event);
@@ -236,6 +236,7 @@ public class EventUtils {
profile.addXp(skill, xpRemoved);
}
return isCancelled;
}
/**

View File

@@ -119,40 +119,58 @@ public final class Misc {
/**
* Drop items at a given location.
*
* @param location The location to drop the items at
* @param fromLocation The location to drop the items at
* @param is The items to drop
* @param speed the speed that the item should travel
* @param quantity The amount of items to drop
*/
public static void spawnItemsTowardsLocation(Location location, Location targetLocation, ItemStack is, int quantity) {
public static void spawnItemsTowardsLocation(Location fromLocation, Location toLocation, ItemStack is, int quantity, double speed) {
for (int i = 0; i < quantity; i++) {
spawnItemTowardsLocation(location, targetLocation, is);
spawnItemTowardsLocation(fromLocation, toLocation, is, speed);
}
}
/**
* Drop an item at a given location.
* This method is fairly expensive as it creates clones of everything passed to itself since they are mutable objects
*
* @param spawnLocation The location to drop the item at
* @param itemStack The item to drop
* @param fromLocation The location to drop the item at
* @param toLocation The location the item will travel towards
* @param itemToSpawn The item to spawn
* @param speed the speed that the item should travel
* @return Dropped Item entity or null if invalid or cancelled
*/
public static Item spawnItemTowardsLocation(Location spawnLocation, Location targetLocation, ItemStack itemStack) {
if (itemStack.getType() == Material.AIR) {
public static Item spawnItemTowardsLocation(Location fromLocation, Location toLocation, ItemStack itemToSpawn, double speed) {
if (itemToSpawn.getType() == Material.AIR) {
return null;
}
//Work with fresh copies of everything
ItemStack clonedItem = itemToSpawn.clone();
Location spawnLocation = fromLocation.clone();
Location targetLocation = toLocation.clone();
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(spawnLocation, itemStack);
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(spawnLocation, clonedItem);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
//Something cancelled the event so back out
if (event.isCancelled() || event.getItemStack() == null) {
return null;
}
Item item = spawnLocation.getWorld().dropItem(spawnLocation, itemStack);
Vector vector = targetLocation.toVector().subtract(spawnLocation.toVector()).normalize();
item.setVelocity(vector);
return item;
//Use the item from the event
Item spawnedItem = spawnLocation.getWorld().dropItem(spawnLocation, clonedItem);
Vector vecFrom = spawnLocation.clone().toVector().clone();
Vector vecTo = targetLocation.clone().toVector().clone();
//Vector which is pointing towards out target location
Vector direction = vecTo.subtract(vecFrom).normalize();
//Modify the speed of the vector
direction = direction.multiply(speed);
spawnedItem.setVelocity(direction);
return spawnedItem;
}
public static void profileCleanup(String playerName) {

View File

@@ -64,7 +64,7 @@ public class FormulaManager {
public int[] calculateNewLevel(PrimarySkillType primarySkillType, int experience) {
int newLevel = 0;
int remainder = 0;
int maxLevel = mcMMO.getConfigManager().getConfigLeveling().getLevelCap(primarySkillType);
int maxLevel = mcMMO.getConfigManager().getConfigLeveling().getSkillLevelCap(primarySkillType);
while (experience > 0 && newLevel < maxLevel) {
int experienceToNextLevel = getXPtoNextLevel(newLevel, currentFormula);

View File

@@ -8,17 +8,13 @@ import com.gmail.nossr50.util.Permissions;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
public class PlayerLevelUtils {
private HashMap<PrimarySkillType, Integer> earlyGameBoostCutoffs;
private HashSet<CustomXPPerk> customXpPerkNodes;
public PlayerLevelUtils() {
registerCustomPerkPermissions();
earlyGameBoostCutoffs = new HashMap<>();
calculateEarlyGameBoostCutoffs();
applyConfigPerks();
}
@@ -38,29 +34,14 @@ public class PlayerLevelUtils {
}
/**
* Get the the final level at which players will still receive an early game XP boost
* Note: This doesn't mean early game boosts are enabled on the server, as that is a config toggle
*
* Check if a player is currently qualifying for the early game boosted XP
* Will return false only if a player is above the boost level cutoff, it does not check config settings to see if the early game boost is on
* @param mcMMOPlayer target player
* @param primarySkillType target skill
* @return this skills maximum early game boost level
* @return if the player would qualify for the XP boost if its enabled
*/
public int getEarlyGameCutoff(PrimarySkillType primarySkillType) {
return earlyGameBoostCutoffs.get(primarySkillType);
}
private void calculateEarlyGameBoostCutoffs() {
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
int levelCap = mcMMO.getConfigManager().getConfigLeveling().getLevelCap(primarySkillType);
int cap;
if (levelCap == Integer.MAX_VALUE || levelCap <= 0) {
cap = mcMMO.isRetroModeEnabled() ? 50 : 5;
} else {
cap = (int) (levelCap * mcMMO.getConfigManager().getConfigLeveling().getEarlyGameBoostMultiplier());
}
earlyGameBoostCutoffs.put(primarySkillType, cap);
}
public static boolean qualifiesForEarlyGameBoost(McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType) {
return mcMMOPlayer.getSkillLevel(primarySkillType) < 1;
}
/**
@@ -131,15 +112,4 @@ public class PlayerLevelUtils {
return 1.0;
}
/**
* Check if a player is currently qualifying for the early game boosted XP
* Will return false only if a player is above the boost level cutoff, it does not check config settings to see if the early game boost is on
* @param mcMMOPlayer target player
* @param primarySkillType target skill
* @return if the player would qualify for the XP boost if its enabled
*/
public static boolean qualifiesForEarlyGameBoost(McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType) {
return mcMMOPlayer.getSkillLevel(primarySkillType) < mcMMO.getPlayerLevelUtils().getEarlyGameCutoff(primarySkillType);
}
}

View File

@@ -225,9 +225,13 @@ public final class CombatUtils {
}
double distanceMultiplier = archeryManager.distanceXpBonusMultiplier(target, arrow);
double forceMultiplier = 1.0; //Hacky Fix - some plugins spawn arrows and assign them to players after the ProjectileLaunchEvent fires
if(arrow.hasMetadata(MetadataConstants.BOW_FORCE_METAKEY))
forceMultiplier = arrow.getMetadata(MetadataConstants.BOW_FORCE_METAKEY).get(0).asDouble();
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, PrimarySkillType.ARCHERY, arrow.getMetadata(MetadataConstants.BOW_FORCE_METAKEY).get(0).asDouble() * distanceMultiplier);
startGainXp(mcMMOPlayer, target, PrimarySkillType.ARCHERY, forceMultiplier * distanceMultiplier);
}
/**

View File

@@ -399,7 +399,7 @@ public class RankUtils {
}
//Default to the max level for the skill if any errors were encountered incorrect
return mcMMO.getConfigManager().getConfigLeveling().getLevelCap(subSkillType.getParentSkill());
return mcMMO.getConfigManager().getConfigLeveling().getSkillLevelCap(subSkillType.getParentSkill());
}
public static boolean isPlayerMaxRankInSubSkill(Player player, SubSkillType subSkillType) {

View File

@@ -253,8 +253,7 @@ public class SkillUtils {
* @param maxDamageModifier the amount to adjust the max damage by
*/
public static void handleDurabilityChange(ItemStack itemStack, double durabilityModifier, double maxDamageModifier) {
if((itemStack.getItemMeta().getEnchants().get(Enchantment.DURABILITY) != null && itemStack.getItemMeta().getEnchants().get(Enchantment.DURABILITY) >= 1)
|| (itemStack.getItemMeta() != null && itemStack.getItemMeta().isUnbreakable())) {
if(itemStack.getItemMeta() != null && itemStack.getItemMeta().isUnbreakable()) {
return;
}