Adds optional ability to reforge anvils #15
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
This commit is contained in:
@ -114,7 +114,7 @@ public class BlacksmithTrait extends Trait {
|
||||
coolDowns.remove(playerId);
|
||||
}
|
||||
//Deny if permission is missing
|
||||
if (!player.hasPermission("blacksmith.reforge")) {
|
||||
if (!player.hasPermission("blacksmith.use")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -157,8 +157,8 @@ public class BlacksmithTrait extends Trait {
|
||||
if (session.isRunning()) {
|
||||
int timeRemaining = (int) ((session.getFinishTime() - System.currentTimeMillis()) / 1000);
|
||||
boolean showExactTime = BlacksmithPlugin.getInstance().getSettings().getShowExactTime();
|
||||
sendNPCMessage(this.npc, player, StringFormatter.replacePlaceholder(config.getBusyReforgingMessage(), "{time}",
|
||||
TimeFormatter.formatTime(showExactTime, timeRemaining)));
|
||||
sendNPCMessage(this.npc, player, StringFormatter.replacePlaceholder(config.getBusyReforgingMessage(),
|
||||
"{time}", TimeFormatter.formatTime(showExactTime, timeRemaining)));
|
||||
return;
|
||||
}
|
||||
if (session.endSession()) {
|
||||
@ -179,14 +179,15 @@ public class BlacksmithTrait extends Trait {
|
||||
ItemStack hand = player.getInventory().getItemInMainHand();
|
||||
//Refuse if not repairable, or if reforge-able items is set, but doesn't include the held item
|
||||
List<Material> reforgeAbleItems = config.getReforgeAbleItems();
|
||||
if (!isRepairable(hand) || (!reforgeAbleItems.isEmpty() && !reforgeAbleItems.contains(hand.getType()))) {
|
||||
if ((!this.config.getRepairAnvils() || !ItemHelper.isAnvil(hand.getType(), false)) &&
|
||||
(!isRepairable(hand) || (!reforgeAbleItems.isEmpty() && !reforgeAbleItems.contains(hand.getType())))) {
|
||||
String invalidMessage = StringFormatter.replacePlaceholder(config.getInvalidItemMessage(),
|
||||
"{title}", config.getBlacksmithTitle());
|
||||
sendNPCMessage(this.npc, player, invalidMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ItemHelper.getDamage(hand) == 0) {
|
||||
if (ItemHelper.getDamage(hand) == 0 && !ItemHelper.isAnvil(hand.getType(), true)) {
|
||||
sendNPCMessage(this.npc, player, config.getNotDamagedMessage());
|
||||
return;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import net.knarcraft.blacksmith.config.NPCSettings;
|
||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -129,6 +130,11 @@ public class ReforgeSession implements Runnable {
|
||||
// Remove any damage done to the item
|
||||
updateDamage(itemToReforge, 0);
|
||||
|
||||
//Replace damaged anvils with a normal anvil
|
||||
if (ItemHelper.isAnvil(itemToReforge.getType(), true)) {
|
||||
itemToReforge.setType(Material.ANVIL);
|
||||
}
|
||||
|
||||
// Add random enchantments
|
||||
int roll = random.nextInt(100);
|
||||
if (!(roll < config.getExtraEnchantmentChance() &&
|
||||
|
Reference in New Issue
Block a user