mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Ask a confirmation when a player tries to repair an enchanted item
This commit is contained in:
parent
b2dd820507
commit
68a7b540c5
@ -28,6 +28,7 @@ Version 1.4.06-dev
|
|||||||
! Changed Berserk to add items to inventory rather than denying pickup
|
! Changed Berserk to add items to inventory rather than denying pickup
|
||||||
! Changed Call of the Wild, newly summoned pet's will have a custom name. (added permission node to disable this)
|
! Changed Call of the Wild, newly summoned pet's will have a custom name. (added permission node to disable this)
|
||||||
! Changed Chimaera Wing's recipe result to use the ingredient Material
|
! Changed Chimaera Wing's recipe result to use the ingredient Material
|
||||||
|
! Changed Repair to ask a confirmation of the player when he tries to repair an enchanted item
|
||||||
! Players will no longer pickup items to their hotbar while using Unarmed
|
! Players will no longer pickup items to their hotbar while using Unarmed
|
||||||
! ExperienceAPI methods will now throw InvalidSkillException if the skill name passed in is invalid.
|
! ExperienceAPI methods will now throw InvalidSkillException if the skill name passed in is invalid.
|
||||||
! Changed default value for recently-hurt cooldown between teleports, this is also fully configurable now
|
! Changed default value for recently-hurt cooldown between teleports, this is also fully configurable now
|
||||||
|
@ -208,6 +208,7 @@ public class Config extends AutoUpdateConfigLoader {
|
|||||||
public int getSalvageAnvilId() { return config.getInt("Skills.Repair.Salvage_Anvil_ID", 41); }
|
public int getSalvageAnvilId() { return config.getInt("Skills.Repair.Salvage_Anvil_ID", 41); }
|
||||||
public boolean getSalvageTools() { return config.getBoolean("Skills.Repair.Salvage_tools", true); }
|
public boolean getSalvageTools() { return config.getBoolean("Skills.Repair.Salvage_tools", true); }
|
||||||
public boolean getSalvageArmor() { return config.getBoolean("Skills.Repair.Salvage_armor", true); }
|
public boolean getSalvageArmor() { return config.getBoolean("Skills.Repair.Salvage_armor", true); }
|
||||||
|
public boolean getRepairConfirmRequired() { return config.getBoolean("Skills.Repair.Confirm_Required", true); }
|
||||||
|
|
||||||
/* Unarmed */
|
/* Unarmed */
|
||||||
public boolean getUnarmedBlockCrackerSmoothbrickToCracked() { return config.getBoolean("Skills.Unarmed.Block_Cracker.SmoothBrick_To_CrackedBrick", true); }
|
public boolean getUnarmedBlockCrackerSmoothbrickToCracked() { return config.getBoolean("Skills.Unarmed.Block_Cracker.SmoothBrick_To_CrackedBrick", true); }
|
||||||
|
@ -70,7 +70,9 @@ public class McMMOPlayer {
|
|||||||
|
|
||||||
private boolean abilityUse = true;
|
private boolean abilityUse = true;
|
||||||
private boolean placedRepairAnvil;
|
private boolean placedRepairAnvil;
|
||||||
|
private int lastRepairClick;
|
||||||
private boolean placedSalvageAnvil;
|
private boolean placedSalvageAnvil;
|
||||||
|
private int lastSalvageClick;
|
||||||
private boolean godMode;
|
private boolean godMode;
|
||||||
|
|
||||||
private Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
|
private Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
|
||||||
@ -369,6 +371,42 @@ public class McMMOPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Repair Anvil Usage
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getLastAnvilUse(int anvilId) {
|
||||||
|
if (anvilId == Repair.repairAnvilId) {
|
||||||
|
return lastRepairClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anvilId == Repair.salvageAnvilId) {
|
||||||
|
return lastSalvageClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastAnvilUse(int anvilId, int value) {
|
||||||
|
if (anvilId == Repair.repairAnvilId) {
|
||||||
|
lastRepairClick = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anvilId == Repair.salvageAnvilId) {
|
||||||
|
lastSalvageClick = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actualizeLastAnvilUse(int anvilId) {
|
||||||
|
if (anvilId == Repair.repairAnvilId) {
|
||||||
|
lastRepairClick = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anvilId == Repair.salvageAnvilId) {
|
||||||
|
lastSalvageClick = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* God Mode
|
* God Mode
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.listeners;
|
package com.gmail.nossr50.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -41,6 +42,7 @@ import com.gmail.nossr50.skills.fishing.FishingManager;
|
|||||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||||
import com.gmail.nossr50.skills.repair.Repair;
|
import com.gmail.nossr50.skills.repair.Repair;
|
||||||
|
import com.gmail.nossr50.skills.repair.RepairManager;
|
||||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||||
import com.gmail.nossr50.skills.unarmed.Unarmed;
|
import com.gmail.nossr50.skills.unarmed.Unarmed;
|
||||||
import com.gmail.nossr50.util.BlockUtils;
|
import com.gmail.nossr50.util.BlockUtils;
|
||||||
@ -306,6 +308,9 @@ public class PlayerListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerInteractLowest(PlayerInteractEvent event) {
|
public void onPlayerInteractLowest(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
Block block = event.getClickedBlock();
|
||||||
|
int blockID = block.getTypeId();
|
||||||
|
ItemStack heldItem = player.getItemInHand();
|
||||||
|
|
||||||
if (Misc.isNPCEntity(player) || player.getGameMode() == GameMode.CREATIVE) {
|
if (Misc.isNPCEntity(player) || player.getGameMode() == GameMode.CREATIVE) {
|
||||||
return;
|
return;
|
||||||
@ -315,21 +320,27 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case RIGHT_CLICK_BLOCK:
|
case RIGHT_CLICK_BLOCK:
|
||||||
Block block = event.getClickedBlock();
|
|
||||||
int blockID = block.getTypeId();
|
|
||||||
ItemStack heldItem = player.getItemInHand();
|
|
||||||
|
|
||||||
/* REPAIR CHECKS */
|
/* REPAIR CHECKS */
|
||||||
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
||||||
UserManager.getPlayer(player).getRepairManager().handleRepair(heldItem);
|
RepairManager repairManager = UserManager.getPlayer(player).getRepairManager();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.updateInventory();
|
|
||||||
|
// Make sure the player knows what he's doing when trying to repair an enchanted item
|
||||||
|
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) {
|
||||||
|
repairManager.handleRepair(heldItem);
|
||||||
|
player.updateInventory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* SALVAGE CHECKS */
|
/* SALVAGE CHECKS */
|
||||||
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
|
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
|
||||||
UserManager.getPlayer(player).getRepairManager().handleSalvage(block.getLocation(), heldItem);
|
RepairManager repairManager = UserManager.getPlayer(player).getRepairManager();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.updateInventory();
|
|
||||||
|
// Make sure the player knows what he's doing when trying to salvage an enchanted item
|
||||||
|
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) {
|
||||||
|
repairManager.handleSalvage(block.getLocation(), heldItem);
|
||||||
|
player.updateInventory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* BLAST MINING CHECK */
|
/* BLAST MINING CHECK */
|
||||||
else if (miningManager.canDetonate()) {
|
else if (miningManager.canDetonate()) {
|
||||||
@ -343,6 +354,20 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LEFT_CLICK_BLOCK:
|
||||||
|
/* REPAIR CHECKS */
|
||||||
|
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
||||||
|
RepairManager repairManager = UserManager.getPlayer(player).getRepairManager();
|
||||||
|
|
||||||
|
// Cancel repairing an enchanted item
|
||||||
|
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
||||||
|
UserManager.getPlayer(player).setLastAnvilUse(Repair.repairAnvilId, 0);
|
||||||
|
player.sendMessage(ChatColor.RED + "Repair cancelled!"); //TODO Locale!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case RIGHT_CLICK_AIR:
|
case RIGHT_CLICK_AIR:
|
||||||
/* BLAST MINING CHECK */
|
/* BLAST MINING CHECK */
|
||||||
if (miningManager.canDetonate()) {
|
if (miningManager.canDetonate()) {
|
||||||
|
@ -3,6 +3,7 @@ package com.gmail.nossr50.skills.repair;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -14,6 +15,7 @@ import org.getspout.spoutapi.SpoutManager;
|
|||||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
|
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
|
||||||
@ -23,6 +25,7 @@ import com.gmail.nossr50.skills.repair.ArcaneForging.Tier;
|
|||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.StringUtils;
|
import com.gmail.nossr50.util.StringUtils;
|
||||||
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||||
|
|
||||||
public class RepairManager extends SkillManager {
|
public class RepairManager extends SkillManager {
|
||||||
@ -193,6 +196,38 @@ public class RepairManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the player has tried to use an Anvil before.
|
||||||
|
*
|
||||||
|
* @return true if the player has confirmed using an Anvil
|
||||||
|
*/
|
||||||
|
public boolean checkConfirmation(int anvilId, boolean actualize) {
|
||||||
|
Player player = getPlayer();
|
||||||
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
|
long LastUse = mcMMOPlayer.getLastAnvilUse(anvilId);
|
||||||
|
|
||||||
|
// Don't use SkillUtils.cooldownOver() here since that also accounts for the cooldown perks
|
||||||
|
if ((((LastUse + 3) * Misc.TIME_CONVERSION_FACTOR) >= System.currentTimeMillis()) || !Config.getInstance().getRepairConfirmRequired()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!actualize) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mcMMOPlayer.actualizeLastAnvilUse(anvilId);
|
||||||
|
|
||||||
|
if (anvilId == Repair.repairAnvilId) {
|
||||||
|
player.sendMessage(ChatColor.GREEN + "Right-click again to confirm " + ChatColor.GOLD + "Repair" + ChatColor.GREEN + ". Left-click to cancel."); //TODO Locale
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anvilId == Repair.salvageAnvilId) {
|
||||||
|
player.sendMessage(ChatColor.GREEN + "Right-click again to confirm " + ChatColor.GOLD + "Salvage" + ChatColor.GREEN + ". Left-click to cancel."); //TODO Locale
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Arcane Forging rank
|
* Gets the Arcane Forging rank
|
||||||
*
|
*
|
||||||
|
@ -174,6 +174,8 @@ Skills:
|
|||||||
Salvage_Anvil_ID: 41
|
Salvage_Anvil_ID: 41
|
||||||
Salvage_tools: true
|
Salvage_tools: true
|
||||||
Salvage_armor: true
|
Salvage_armor: true
|
||||||
|
# Ask for a confirmation when a player tries to repair an enchanted item
|
||||||
|
Confirm_Required: true
|
||||||
Smelting:
|
Smelting:
|
||||||
Level_Cap: 0
|
Level_Cap: 0
|
||||||
Swords:
|
Swords:
|
||||||
|
Loading…
Reference in New Issue
Block a user