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

This commit is contained in:
nossr50
2019-06-21 09:19:03 -07:00
7 changed files with 80 additions and 28 deletions

View File

@ -66,11 +66,10 @@ public class InspectCommand implements TabExecutor {
Player target = mcMMOPlayer.getPlayer();
if (CommandUtils.hidden(sender, target, Permissions.inspectHidden(sender))) {
if (!Permissions.inspectOffline(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true;
}
} else if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true;
}
else if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
return true;
}

View File

@ -63,7 +63,7 @@ public class PlayerProfileLoadingTask extends BukkitRunnable {
// Increment attempt counter and try
attempt++;
new PlayerProfileLoadingTask(player, attempt).runTaskLaterAsynchronously(mcMMO.p, 100);
new PlayerProfileLoadingTask(player, attempt).runTaskLaterAsynchronously(mcMMO.p, (100 + (attempt * 100)));
}
private class ApplySuccessfulProfile extends BukkitRunnable {

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.skills.salvage;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
@ -88,16 +87,14 @@ public class SalvageManager extends SkillManager {
return;
}
int maxAmountSalvageable = Salvage.calculateSalvageableAmount(item.getDurability(), salvageable.getMaximumDurability(), salvageable.getMaximumQuantity());
int potentialSalvageYield = Salvage.calculateSalvageableAmount(item.getDurability(), salvageable.getMaximumDurability(), salvageable.getMaximumQuantity());
int salvageableAmount = maxAmountSalvageable;
if (salvageableAmount == 0) {
if (potentialSalvageYield <= 0) {
mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Salvage.Skills.TooDamaged");
return;
}
salvageableAmount = Math.min(salvageableAmount, getSalvageableAmount()); // Always get at least something back, if you're capable of salvaging it.
potentialSalvageYield = Math.min(potentialSalvageYield, getSalvageLimit()); // Always get at least something back, if you're capable of salvaging it.
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
location.add(0.5, 1, 0.5);
@ -114,7 +111,7 @@ public class SalvageManager extends SkillManager {
int lotteryResults = 1;
int chanceOfSuccess = 99;
for(int x = 0; x < salvageableAmount-1; x++) {
for(int x = 0; x < potentialSalvageYield-1; x++) {
if(RandomChanceUtil.rollDice(chanceOfSuccess, 100)) {
chanceOfSuccess-=2;
@ -124,9 +121,9 @@ public class SalvageManager extends SkillManager {
}
}
if(lotteryResults == salvageableAmount && salvageableAmount != 1 && RankUtils.isPlayerMaxRankInSubSkill(player, SubSkillType.SALVAGE_ARCANE_SALVAGE)) {
if(lotteryResults == potentialSalvageYield && potentialSalvageYield != 1 && RankUtils.isPlayerMaxRankInSubSkill(player, SubSkillType.SALVAGE_ARCANE_SALVAGE)) {
mcMMO.getNotificationManager().sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Perfect", String.valueOf(lotteryResults), StringUtils.getPrettyItemString(item.getType()));
} else if(RankUtils.isPlayerMaxRankInSubSkill(player, SubSkillType.SALVAGE_ARCANE_SALVAGE) || salvageableAmount == 1) {
} else if(salvageable.getMaximumQuantity() == 1 || getSalvageLimit() >= salvageable.getMaximumQuantity()) {
mcMMO.getNotificationManager().sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Normal", String.valueOf(lotteryResults), StringUtils.getPrettyItemString(item.getType()));
} else {
mcMMO.getNotificationManager().sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Untrained", String.valueOf(lotteryResults), StringUtils.getPrettyItemString(item.getType()));
@ -143,7 +140,7 @@ public class SalvageManager extends SkillManager {
Misc.dropItem(location, enchantBook);
}
Misc.dropItems(location, salvageResults, 1);
Misc.spawnItemTowardsLocation(location, player.getLocation().add(0, 0.25, 0), salvageResults);
// BWONG BWONG BWONG - CLUNK!
if (mcMMO.getConfigManager().getConfigSalvage().getGeneral().isAnvilUseSounds()) {
@ -159,8 +156,8 @@ public class SalvageManager extends SkillManager {
return Math.min((((Salvage.salvageMaxPercentage / Salvage.salvageMaxPercentageLevel) * getSkillLevel()) / 100.0D), Salvage.salvageMaxPercentage / 100.0D);
}*/
public int getSalvageableAmount() {
return (RankUtils.getRank(getPlayer(), SubSkillType.SALVAGE_ARCANE_SALVAGE));
public int getSalvageLimit() {
return (RankUtils.getRank(getPlayer(), SubSkillType.SALVAGE_SCRAP_COLLECTOR));
}
/**

View File

@ -10,6 +10,7 @@ import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.Collection;
import java.util.Random;
@ -115,6 +116,45 @@ public final class Misc {
return location.getWorld().dropItemNaturally(location, itemStack);
}
/**
* Drop items at a given location.
*
* @param location The location to drop the items at
* @param is The items to drop
* @param quantity The amount of items to drop
*/
public static void spawnItemsTowardsLocation(Location location, Location targetLocation, ItemStack is, int quantity) {
for (int i = 0; i < quantity; i++) {
spawnItemTowardsLocation(location, targetLocation, is);
}
}
/**
* Drop an item at a given location.
*
* @param spawnLocation The location to drop the item at
* @param itemStack The item to drop
* @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) {
return null;
}
// 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);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;
}
Item item = spawnLocation.getWorld().dropItem(spawnLocation, itemStack);
Vector vector = targetLocation.toVector().subtract(spawnLocation.toVector()).normalize();
item.setVelocity(vector);
return item;
}
public static void profileCleanup(String playerName) {
Player player = mcMMO.p.getServer().getPlayerExact(playerName);

View File

@ -35,12 +35,14 @@ public final class CommandUtils {
}
public static boolean tooFar(CommandSender sender, Player target, boolean hasPermission) {
if (sender instanceof Player
&& mcMMO.getConfigManager().getConfigCommands().isLimitInspectRange()
&& !hasPermission
&& !Misc.isNear(((Player) sender).getLocation(),
target.getLocation(),
mcMMO.getConfigManager().getConfigCommands().getInspectCommandMaxDistance())) {
if(!target.isOnline() && !hasPermission) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true;
} else if (mcMMO.getConfigManager().getConfigCommands().isLimitInspectRange()
&& sender instanceof Player
&& !Misc.isNear(((Player) sender).getLocation(), target.getLocation(),
mcMMO.getConfigManager().getConfigCommands().getInspectCommandMaxDistance())
&& !hasPermission) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}