diff --git a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java index becca971a..943718c6c 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java @@ -1,8 +1,16 @@ package com.gmail.nossr50.commands.player; -import java.util.ArrayList; -import java.util.List; - +import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.StringUtils; +import com.gmail.nossr50.util.commands.CommandUtils; +import com.gmail.nossr50.util.player.UserManager; +import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -10,17 +18,8 @@ import org.bukkit.entity.Player; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.StringUtil; -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.skills.SkillType; -import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask; -import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.StringUtils; -import com.gmail.nossr50.util.commands.CommandUtils; -import com.gmail.nossr50.util.player.UserManager; -import com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.List; public class MctopCommand implements TabExecutor { @Override @@ -91,7 +90,12 @@ public class MctopCommand implements TabExecutor { long cooldownMillis = Math.max(Config.getInstance().getDatabasePlayerCooldown(), 1750); if (mcMMOPlayer.getDatabaseATS() + cooldownMillis > System.currentTimeMillis()) { - sender.sendMessage(LocaleLoader.getString("Commands.Database.Cooldown")); + double seconds = ((mcMMOPlayer.getDatabaseATS() + cooldownMillis) - System.currentTimeMillis()) / 1000; + if (seconds < 1) { + seconds = 1; + } + + sender.sendMessage(LocaleLoader.formatString("Commands.Database.Cooldown", seconds)); return; } diff --git a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java index f33a332b6..d0aa47979 100644 --- a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java +++ b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.events.experience; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; import com.gmail.nossr50.datatypes.skills.SkillType; @@ -63,4 +64,15 @@ public abstract class McMMOPlayerExperienceEvent extends PlayerEvent implements public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } + + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/src/main/java/com/gmail/nossr50/events/skills/salvage/McMMOPlayerSalvageCheckEvent.java b/src/main/java/com/gmail/nossr50/events/skills/salvage/McMMOPlayerSalvageCheckEvent.java new file mode 100644 index 000000000..868a7dd6e --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/skills/salvage/McMMOPlayerSalvageCheckEvent.java @@ -0,0 +1,58 @@ +package com.gmail.nossr50.events.skills.salvage; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.inventory.ItemStack; + +import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent; + +/** + * Called just before a player salvages an item with mcMMO. + */ +public class McMMOPlayerSalvageCheckEvent extends McMMOPlayerSkillEvent implements Cancellable { + private ItemStack salvageItem; + private ItemStack salvageResults; + private ItemStack enchantedBook; + private boolean cancelled; + + public McMMOPlayerSalvageCheckEvent(Player player, ItemStack salvageItem, ItemStack salvageResults, ItemStack enchantedBook) { + super(player, SkillType.SALVAGE); + this.salvageItem = salvageItem; + this.salvageResults = salvageResults; + this.enchantedBook = enchantedBook; + this.cancelled = false; + } + + /** + * @return The item that should get salvaged. + */ + public ItemStack getSalvageItem() { + return salvageItem; + } + + /** + * @return The results that should be dropped after salvaging. + */ + public ItemStack getSalvageResults() { + return salvageResults; + } + + /** + * @return The enchanted book that should drop after salvaging or null if no book should be dropped. + */ + public ItemStack getEnchantedBook() { + return enchantedBook; + } + + /** Following are required for Cancellable **/ + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} 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 3be2f04c8..10efb41ac 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -20,6 +20,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.salvage.Salvage.Tier; 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; @@ -104,17 +105,25 @@ public class SalvageManager extends SkillManager { Map enchants = item.getEnchantments(); + ItemStack enchantBook = null; if (!enchants.isEmpty()) { - ItemStack enchantBook = arcaneSalvageCheck(enchants); - - if (enchantBook != null) { - Misc.dropItem(location, enchantBook); - } + enchantBook = arcaneSalvageCheck(enchants); } byte salvageMaterialMetadata = (salvageable.getSalvageMaterialMetadata() != (byte) -1) ? salvageable.getSalvageMaterialMetadata() : 0; - Misc.dropItems(location, new MaterialData(salvageable.getSalvageMaterial(), salvageMaterialMetadata).toItemStack(salvageableAmount), 1); + ItemStack salvageResults = new MaterialData(salvageable.getSalvageMaterial(), salvageMaterialMetadata).toItemStack(salvageableAmount); + + //Call event + if (EventUtils.callSalvageCheckEvent(player, item, salvageResults, enchantBook).isCancelled()) { + return; + } + + if (enchantBook != null) { + Misc.dropItem(location, enchantBook); + } + + Misc.dropItems(location, salvageResults, 1); // BWONG BWONG BWONG - CLUNK! if (Config.getInstance().getSalvageAnvilUseSoundsEnabled()) { diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index 32db2a072..21ed9929d 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -28,6 +28,7 @@ import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent; import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent; import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityEvent; import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent; +import com.gmail.nossr50.events.skills.salvage.McMMOPlayerSalvageCheckEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.player.UserManager; @@ -278,4 +279,11 @@ public class EventUtils { return event; } + + public static McMMOPlayerSalvageCheckEvent callSalvageCheckEvent(Player player, ItemStack salvageMaterial, ItemStack salvageResults, ItemStack enchantedBook) { + McMMOPlayerSalvageCheckEvent event = new McMMOPlayerSalvageCheckEvent(player, salvageMaterial, salvageResults, enchantedBook); + mcMMO.p.getServer().getPluginManager().callEvent(event); + + return event; + } } diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index be2f646d4..8c21c82e5 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -456,7 +456,7 @@ Commands.Chat.Console=*Console* Commands.Cooldowns.Header=[[GOLD]]--= [[GREEN]]mcMMO Ability Cooldowns[[GOLD]] =-- Commands.Cooldowns.Row.N=\ [[RED]]{0}[[WHITE]] - [[GOLD]]{1} seconds left Commands.Cooldowns.Row.Y=\ [[AQUA]]{0}[[WHITE]] - [[DARK_GREEN]]Ready! -Commands.Database.Cooldown=[[RED]]You must wait 1 second before using this command again. +Commands.Database.Cooldown=[[RED]]You must wait {0} seconds before using this command again. Commands.Database.Processing=[[RED]]Your previous command is still being processed. Please wait. Commands.Disabled=[[RED]]This command is disabled. Commands.DoesNotExist= [[RED]]Player does not exist in the database!