From c6d604bbbcb3e789c2c234c4220878fd8be554c0 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 21 Jun 2019 08:05:57 -0700 Subject: [PATCH] Inspect, Salvage, and Locale fixes --- Changelog.txt | 14 +++++++ pom.xml | 2 +- .../commands/player/InspectCommand.java | 6 +-- .../player/PlayerProfileLoadingTask.java | 2 +- .../skills/salvage/SalvageManager.java | 25 +++++------- .../java/com/gmail/nossr50/util/Misc.java | 40 +++++++++++++++++++ .../com/gmail/nossr50/util/Permissions.java | 1 - .../nossr50/util/commands/CommandUtils.java | 5 ++- .../resources/locale/locale_en_US.properties | 8 ++-- 9 files changed, 76 insertions(+), 27 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 803e8ffc5..14dc6b7c5 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,17 @@ +Version 2.1.86 + Players will no longer be told they got a perfect result when salvaging if they are below max skill level + Salvage results will now travel towards the player instead of moving in a random direction + (FIX) You cannot view stats of players who are offline if your server limits the range on inspect for you via permissions or settings + (FIX) Players will no longer be told they lack skill in salvage if they already qualify for the best possible result for the item + (FIX) Fixed a bug where arcane salvage was being used to calculate salvage results instead of scrap collector + Added the missing locale color for 'Commands.Party.Commands' + Modified colors used in locale strings 'Salvage.Skills.Lottery.Normal', 'Salvage.Skills.Lottery.Perfect', and 'Profile.Loading.FailurePlayer' + When failing to load a profile mcMMO will increase the amount of time it waits before reattempting to load the profile for each failure + + NOTES: + You can (and always have been able) to turn off the inspect range check by setting it to 0 in the config + 2.2 is around the corner, most things are functional, still a lot of work left to do. + Version 2.1.85 Fixed a nearly 6 year old bug where Super Repair was not included as a child permission under Repair ability permission nodes (which meant some players would not have access to this skill) Fixed a bug that could prevent salvage from working for certain players diff --git a/pom.xml b/pom.xml index 554065870..d61cf1d82 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.85 + 2.1.86-SNAPSHOT mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java index f8f4e5e49..89560bb0f 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java @@ -66,10 +66,8 @@ 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; - } + sender.sendMessage(LocaleLoader.getString("Inspect.Offline")); + return true; } else if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) { return true; diff --git a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java index 5ec5f1dd2..50f960b95 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java @@ -65,7 +65,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 { diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index d7e10de68..ae778e74b 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -11,10 +11,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; -import com.gmail.nossr50.util.EventUtils; -import com.gmail.nossr50.util.Misc; -import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.StringUtils; +import com.gmail.nossr50.util.*; import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.random.RandomChanceSkillStatic; import com.gmail.nossr50.util.random.RandomChanceUtil; @@ -91,16 +88,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) { NotificationManager.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); @@ -117,7 +112,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; @@ -127,9 +122,9 @@ public class SalvageManager extends SkillManager { } } - if(lotteryResults == salvageableAmount && salvageableAmount != 1) { + if(lotteryResults == potentialSalvageYield && potentialSalvageYield != 1 && RankUtils.isPlayerMaxRankInSubSkill(player, SubSkillType.SALVAGE_ARCANE_SALVAGE)) { NotificationManager.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()) { NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Normal", String.valueOf(lotteryResults), StringUtils.getPrettyItemString(item.getType())); } else { NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Untrained", String.valueOf(lotteryResults), StringUtils.getPrettyItemString(item.getType())); @@ -146,7 +141,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 (Config.getInstance().getSalvageAnvilUseSoundsEnabled()) { @@ -163,8 +158,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) * 1); + public int getSalvageLimit() { + return (RankUtils.getRank(getPlayer(), SubSkillType.SALVAGE_SCRAP_COLLECTOR)); } /** diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index c3a69c65e..99dbf057d 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -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; @@ -117,6 +118,45 @@ public final class Misc { return location.getWorld().dropItem(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); diff --git a/src/main/java/com/gmail/nossr50/util/Permissions.java b/src/main/java/com/gmail/nossr50/util/Permissions.java index cd5118e3b..0e3d6e632 100644 --- a/src/main/java/com/gmail/nossr50/util/Permissions.java +++ b/src/main/java/com/gmail/nossr50/util/Permissions.java @@ -55,7 +55,6 @@ public final class Permissions { public static boolean inspect(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect")); } public static boolean inspectFar(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.far")); } public static boolean inspectHidden(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.hidden")); } - public static boolean inspectOffline(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.offline")); } public static boolean kraken(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.kraken"); } public static boolean krakenOthers(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.kraken.others"); } diff --git a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java index b9568a1b2..e48adeafd 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java @@ -34,7 +34,10 @@ public final class CommandUtils { } public static boolean tooFar(CommandSender sender, Player target, boolean hasPermission) { - if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), Config.getInstance().getInspectDistance()) && !hasPermission) { + if(!target.isOnline() && !hasPermission) { + sender.sendMessage(LocaleLoader.getString("Inspect.Offline")); + return true; + } else if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), Config.getInstance().getInspectDistance()) && !hasPermission) { sender.sendMessage(LocaleLoader.getString("Inspect.TooFar")); return true; } diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 05d92949a..74cc5cce9 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -393,8 +393,8 @@ Salvage.Skills.ArcaneSuccess=[[GREEN]]You able to extract all of the knowledge c Salvage.Listener.Anvil=[[DARK_RED]]You have placed a Salvage anvil, use this to Salvage tools and armor. Salvage.Listener=Salvage: Salvage.SkillName=SALVAGE -Salvage.Skills.Lottery.Normal=[[GOLD]]You were able to salvage [[GREEN]]{0}[[GOLD]] materials from [[DARK_AQUA]]{1}[[GOLD]]. -Salvage.Skills.Lottery.Perfect=[[GREEN]][[BOLD]]Perfect![[RESET]][[GOLD]] You salvaged [[GREEN]]{1}[[GOLD]] effortlessly, retrieving [[DARK_AQUA]]{0}[[GOLD]] materials. +Salvage.Skills.Lottery.Normal=[[GOLD]]You were able to salvage [[DARK_AQUA]]{0}[[GOLD]] materials from [[YELLOW]]{1}[[GOLD]]. +Salvage.Skills.Lottery.Perfect=[[GREEN]][[BOLD]]Perfect![[RESET]][[GOLD]] You salvaged [[DARK_AQUA]]{1}[[GOLD]] effortlessly, retrieving [[DARK_AQUA]]{0}[[GOLD]] materials. Salvage.Skills.Lottery.Untrained=[[GRAY]]You aren't properly trained in salvaging. You were only able to recover [[RED]]{0}[[GRAY]] materials from [[GREEN]]{1}[[GRAY]]. #Anvil (Shared between SALVAGE and REPAIR) Anvil.Unbreakable=This item is unbreakable! @@ -635,7 +635,7 @@ Commands.Party.MembersNear=[[DARK_GRAY]]NEAR YOU [[DARK_AQUA]]{0}[[DARK_GRAY]]/[ Commands.Party.Accept=[[GREEN]]- Accept party invite Commands.Party.Chat.Off=Party Chat only [[RED]]Off Commands.Party.Chat.On=Party Chat only [[GREEN]]On -Commands.Party.Commands=---[][[GREEN]]PARTY COMMANDS[[RED]][]--- +Commands.Party.Commands=[[RED]]---[][[GREEN]]PARTY COMMANDS[[RED]][]--- Commands.Party.Invite.0=[[RED]]ALERT: [[GREEN]]You have received a party invite for {0} from {1} Commands.Party.Invite.1=[[YELLOW]]Type [[GREEN]]/party accept[[YELLOW]] to accept the invite Commands.Party.Invite=[[GREEN]]- Send party invite @@ -1087,7 +1087,7 @@ Scoreboard.Misc.Ability=Ability #DATABASE RECOVERY Profile.PendingLoad=[[RED]]Your mcMMO player data has not yet been loaded. Profile.Loading.Success=[[GREEN]]Your mcMMO profile has been loaded. -Profile.Loading.FailurePlayer=[[RED]]mcMMO is having trouble loading your data, we have attempted to load it [[GREEN]]{0}[[RED]] times.[[LIGHT_GRAY]] You may want to contact the server admins about this issue. mcMMO will attempt to load your data until you disconnect, you will not gain XP or be able to use skills while the data is not loaded. +Profile.Loading.FailurePlayer=[[RED]]mcMMO is having trouble loading your data, we have attempted to load it [[GREEN]]{0}[[RED]] times.[[RED]] You may want to contact the server admins about this issue. mcMMO will attempt to load your data until you disconnect, you will not gain XP or be able to use skills while the data is not loaded. Profile.Loading.FailureNotice=[[DARK_RED]][A][[RED]] mcMMO was unable to load the player data for [[YELLOW]]{0}[[RED]]. [[LIGHT_PURPLE]]Please inspect your database setup. Attempts made so far {1}. #Holiday Holiday.AprilFools.Levelup=[[GOLD]]{0} is now level [[GREEN]]{1}[[GOLD]]!