From 3b3f2f7ae22ab34a2199509e4fbd854fcd0c0ade Mon Sep 17 00:00:00 2001 From: Brianna Date: Wed, 29 Jan 2020 12:08:49 -0500 Subject: [PATCH 1/6] Remove duped command. --- .../java/com/songoda/ultimaterepairing/UltimateRepairing.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/songoda/ultimaterepairing/UltimateRepairing.java b/src/main/java/com/songoda/ultimaterepairing/UltimateRepairing.java index 113ec21..52d033d 100644 --- a/src/main/java/com/songoda/ultimaterepairing/UltimateRepairing.java +++ b/src/main/java/com/songoda/ultimaterepairing/UltimateRepairing.java @@ -73,8 +73,7 @@ public class UltimateRepairing extends SongodaPlugin { this.commandManager.addCommand(new CommandUltimateRepairing()) .addSubCommands( new CommandReload(), - new CommandSettings(guiManager), - new CommandURAnvil()); + new CommandSettings(guiManager)); this.commandManager.addCommand(new CommandURAnvil()); Bukkit.getScheduler().runTaskLaterAsynchronously(this, () -> { From 709f8f29afe09fd0369e52b8dbdaea801ef8cc1d Mon Sep 17 00:00:00 2001 From: Brianna Date: Fri, 31 Jan 2020 11:18:09 -0500 Subject: [PATCH 2/6] Remove old unused debugger from 2017. --- .../ultimaterepairing/UltimateRepairing.java | 23 +- .../handlers/ParticleTask.java | 11 +- .../handlers/RepairHandler.java | 288 ++++++++---------- .../listeners/BlockListeners.java | 34 +-- .../listeners/InteractListeners.java | 86 +++--- .../listeners/InventoryListeners.java | 1 - .../ultimaterepairing/utils/Debugger.java | 30 -- 7 files changed, 197 insertions(+), 276 deletions(-) delete mode 100644 src/main/java/com/songoda/ultimaterepairing/utils/Debugger.java diff --git a/src/main/java/com/songoda/ultimaterepairing/UltimateRepairing.java b/src/main/java/com/songoda/ultimaterepairing/UltimateRepairing.java index 52d033d..9519be9 100644 --- a/src/main/java/com/songoda/ultimaterepairing/UltimateRepairing.java +++ b/src/main/java/com/songoda/ultimaterepairing/UltimateRepairing.java @@ -10,7 +10,10 @@ import com.songoda.core.hooks.EconomyManager; import com.songoda.core.hooks.HologramManager; import com.songoda.ultimaterepairing.anvil.AnvilManager; import com.songoda.ultimaterepairing.anvil.UAnvil; -import com.songoda.ultimaterepairing.commands.*; +import com.songoda.ultimaterepairing.commands.CommandReload; +import com.songoda.ultimaterepairing.commands.CommandSettings; +import com.songoda.ultimaterepairing.commands.CommandURAnvil; +import com.songoda.ultimaterepairing.commands.CommandUltimateRepairing; import com.songoda.ultimaterepairing.handlers.ParticleTask; import com.songoda.ultimaterepairing.handlers.RepairHandler; import com.songoda.ultimaterepairing.listeners.BlockListeners; @@ -18,14 +21,14 @@ import com.songoda.ultimaterepairing.listeners.InteractListeners; import com.songoda.ultimaterepairing.listeners.InventoryListeners; import com.songoda.ultimaterepairing.listeners.PlayerListeners; import com.songoda.ultimaterepairing.settings.Settings; -import com.songoda.ultimaterepairing.utils.Debugger; import com.songoda.ultimaterepairing.utils.Methods; -import java.util.Arrays; -import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.plugin.PluginManager; +import java.util.Arrays; +import java.util.List; + public class UltimateRepairing extends SongodaPlugin { private static UltimateRepairing INSTANCE; @@ -57,8 +60,8 @@ public class UltimateRepairing extends SongodaPlugin { // Load Economy & Hologram hooks EconomyManager.load(); HologramManager.load(this); - - this.setLocale(Settings.LANGUGE_MODE.getString(), false); + + this.setLocale(Settings.LANGUGE_MODE.getString(), false); PluginManager pluginManager = getServer().getPluginManager(); @@ -142,12 +145,8 @@ public class UltimateRepairing extends SongodaPlugin { @Override public void onConfigReload() { - try { - this.setLocale(Settings.LANGUGE_MODE.getString(), true); - particleTask.reload(); - } catch (Exception ex) { - Debugger.runReport(ex); - } + this.setLocale(Settings.LANGUGE_MODE.getString(), true); + particleTask.reload(); } public RepairHandler getRepairHandler() { diff --git a/src/main/java/com/songoda/ultimaterepairing/handlers/ParticleTask.java b/src/main/java/com/songoda/ultimaterepairing/handlers/ParticleTask.java index 59daf9d..537e1b6 100644 --- a/src/main/java/com/songoda/ultimaterepairing/handlers/ParticleTask.java +++ b/src/main/java/com/songoda/ultimaterepairing/handlers/ParticleTask.java @@ -3,7 +3,6 @@ package com.songoda.ultimaterepairing.handlers; import com.songoda.core.compatibility.CompatibleParticleHandler; import com.songoda.core.compatibility.CompatibleParticleHandler.ParticleType; import com.songoda.ultimaterepairing.UltimateRepairing; -import com.songoda.ultimaterepairing.utils.Debugger; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.bukkit.scheduler.BukkitTask; @@ -48,12 +47,8 @@ public class ParticleTask implements Listener { public void applyParticles() { if (instance.getAnvilManager().getAnvils().isEmpty()) return; - try { - instance.getAnvilManager().getAnvils().parallelStream() - .filter(anvil -> anvil.isParticles() && anvil.isInLoadedChunk()) - .forEach(anvil -> CompatibleParticleHandler.spawnParticles(type, anvil.getLocation().add(.5, 0, .5), amt, 0.25, 0.25, 0.25)); - } catch (Exception ex) { - Debugger.runReport(ex); - } + instance.getAnvilManager().getAnvils().parallelStream() + .filter(anvil -> anvil.isParticles() && anvil.isInLoadedChunk()) + .forEach(anvil -> CompatibleParticleHandler.spawnParticles(type, anvil.getLocation().add(.5, 0, .5), amt, 0.25, 0.25, 0.25)); } } diff --git a/src/main/java/com/songoda/ultimaterepairing/handlers/RepairHandler.java b/src/main/java/com/songoda/ultimaterepairing/handlers/RepairHandler.java index c367043..703de22 100644 --- a/src/main/java/com/songoda/ultimaterepairing/handlers/RepairHandler.java +++ b/src/main/java/com/songoda/ultimaterepairing/handlers/RepairHandler.java @@ -9,22 +9,18 @@ import com.songoda.ultimaterepairing.anvil.PlayerAnvilData; import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType; import com.songoda.ultimaterepairing.gui.RepairTypeGui; import com.songoda.ultimaterepairing.gui.StartConfirmGui; -import com.songoda.ultimaterepairing.utils.Debugger; import com.songoda.ultimaterepairing.utils.Methods; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.Effect; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + /** * Created by songoda on 2/25/2017. */ @@ -41,56 +37,48 @@ public class RepairHandler { } private void repairType(Player p, Location l) { - try { - if (getDataFor(p).getInRepair()) { - yesNo(p, getDataFor(p).getType(), getDataFor(p).getToBeRepaired()); - } else { - guiManager.showGUI(p, new RepairTypeGui(p, l)); - } - } catch (Exception ex) { - Debugger.runReport(ex); + if (getDataFor(p).getInRepair()) { + yesNo(p, getDataFor(p).getType(), getDataFor(p).getToBeRepaired()); + } else { + guiManager.showGUI(p, new RepairTypeGui(p, l)); } } public void preRepair(Player player, RepairType type, Location anvil) { - try { - ItemStack itemStack = player.getItemInHand(); - player.setItemInHand(null); - Item item = player.getWorld().dropItem(anvil.add(0.5, 2, 0.5), itemStack); + ItemStack itemStack = player.getItemInHand(); + player.setItemInHand(null); + Item item = player.getWorld().dropItem(anvil.add(0.5, 2, 0.5), itemStack); - // Support for EpicHoppers suction. - item.setMetadata("grabbed", new FixedMetadataValue(instance, "true")); + // Support for EpicHoppers suction. + item.setMetadata("grabbed", new FixedMetadataValue(instance, "true")); - item.setMetadata("betterdrops_ignore", new FixedMetadataValue(instance, true)); - Vector vec = player.getEyeLocation().getDirection(); - vec.setX(0); - vec.setY(0); - vec.setZ(0); - item.setVelocity(vec); - item.setPickupDelay(3600); - item.setMetadata("UltimateRepairing", new FixedMetadataValue(instance, "")); + item.setMetadata("betterdrops_ignore", new FixedMetadataValue(instance, true)); + Vector vec = player.getEyeLocation().getDirection(); + vec.setX(0); + vec.setY(0); + vec.setZ(0); + item.setVelocity(vec); + item.setPickupDelay(3600); + item.setMetadata("UltimateRepairing", new FixedMetadataValue(instance, "")); - // Get from Map, put new instance in Map if it doesn't exist - PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData()); - playerData.setItem(item); - playerData.setToBeRepaired(itemStack); - playerData.setLocations(anvil.add(0, -2, 0)); + // Get from Map, put new instance in Map if it doesn't exist + PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData()); + playerData.setItem(item); + playerData.setToBeRepaired(itemStack); + playerData.setLocations(anvil.add(0, -2, 0)); - yesNo(player, type, itemStack); + yesNo(player, type, itemStack); - Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { - if (item.isValid() && !playerData.isBeingRepaired()) { + Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { + if (item.isValid() && !playerData.isBeingRepaired()) { - instance.getLocale().getMessage("event.repair.timeout").sendPrefixedMessage(player); - removeItem(playerData, player); - player.closeInventory(); + instance.getLocale().getMessage("event.repair.timeout").sendPrefixedMessage(player); + removeItem(playerData, player); + player.closeInventory(); - } - }, instance.getConfig().getLong("Main.Time Before Repair Auto Canceled")); - } catch (Exception ex) { - Debugger.runReport(ex); - } + } + }, instance.getConfig().getLong("Main.Time Before Repair Auto Canceled")); } public void initRepair(Player player, Location anvil) { @@ -128,141 +116,127 @@ public class RepairHandler { } private void yesNo(Player p, RepairType type, ItemStack item) { - try { - PlayerAnvilData playerData = getDataFor(p); + PlayerAnvilData playerData = getDataFor(p); - if (playerData.isBeingRepaired()) { - return; - } - - int price = Methods.getCost(type, item); - playerData.setInRepair(true); - playerData.setType(type); - playerData.setPrice(price); - - guiManager.showGUI(p, new StartConfirmGui(playerData.getLocation(), type, p, item)); - - } catch (Exception ex) { - Debugger.runReport(ex); + if (playerData.isBeingRepaired()) { + return; } + + int price = Methods.getCost(type, item); + playerData.setInRepair(true); + playerData.setType(type); + playerData.setPrice(price); + + guiManager.showGUI(p, new StartConfirmGui(playerData.getLocation(), type, p, item)); } public void finish(boolean answer, Player player) { - try { - PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData()); - if (!answer) { - removeItem(playerData, player); - instance.getLocale().getMessage("event.repair.cancelled").sendPrefixedMessage(player); - return; - } - RepairType type = playerData.getType(); - ItemStack players = playerData.getToBeRepaired(); + PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData()); + if (!answer) { + removeItem(playerData, player); + instance.getLocale().getMessage("event.repair.cancelled").sendPrefixedMessage(player); + return; + } + RepairType type = playerData.getType(); + ItemStack players = playerData.getToBeRepaired(); - boolean sold = false; - if (type == RepairType.ECONOMY && EconomyManager.isEnabled()) { - int price = playerData.getPrice(); + boolean sold = false; + if (type == RepairType.ECONOMY && EconomyManager.isEnabled()) { + int price = playerData.getPrice(); - if(EconomyManager.hasBalance(player, price)) { - EconomyManager.withdrawBalance(player, price); - sold = true; - } - } - - int cost = Methods.getCost(type, players); - ItemStack item2 = new ItemStack(Methods.getType(players), cost); - String name = (item2.getType().name().substring(0, 1).toUpperCase() + item2.getType().name().toLowerCase().substring(1)).replace("_", " "); - if (type == RepairType.ITEM && Methods.inventoryContains(player.getInventory(), item2)) { - Methods.removeFromInventory(player.getInventory(), item2); + if (EconomyManager.hasBalance(player, price)) { + EconomyManager.withdrawBalance(player, price); sold = true; } + } - if (type == RepairType.XP && player.getLevel() >= playerData.getPrice() || sold || player.getGameMode() == GameMode.CREATIVE) { - playerData.setBeingRepaired(true); + int cost = Methods.getCost(type, players); + ItemStack item2 = new ItemStack(Methods.getType(players), cost); + String name = (item2.getType().name().substring(0, 1).toUpperCase() + item2.getType().name().toLowerCase().substring(1)).replace("_", " "); + if (type == RepairType.ITEM && Methods.inventoryContains(player.getInventory(), item2)) { + Methods.removeFromInventory(player.getInventory(), item2); + sold = true; + } - Effect effect = Effect.STEP_SOUND; + if (type == RepairType.XP && player.getLevel() >= playerData.getPrice() || sold || player.getGameMode() == GameMode.CREATIVE) { + playerData.setBeingRepaired(true); - Material blockType = Material.REDSTONE_BLOCK; + Effect effect = Effect.STEP_SOUND; - String typeStr = playerData.getToBeRepaired().getType().name().toUpperCase(); + Material blockType = Material.REDSTONE_BLOCK; - if (typeStr.contains("DIAMOND")) { - blockType = Material.DIAMOND_BLOCK; - } else if (typeStr.contains("IRON")) { - blockType = Material.IRON_BLOCK; - } else if (typeStr.contains("GOLD")) { - blockType = Material.GOLD_BLOCK; - } else if (typeStr.contains("STONE")) { - blockType = Material.STONE; - } else if (typeStr.contains("WOOD")) { - blockType = CompatibleMaterial.OAK_WOOD.getMaterial(); - } + String typeStr = playerData.getToBeRepaired().getType().name().toUpperCase(); - final Material blockTypeFinal = blockType; - - Location location = playerData.getLocations(); - player.getWorld().playEffect(location, effect, blockType); - Runnable runnable = () -> player.getWorld().playEffect(location, effect, blockTypeFinal); - Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 5L); - Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { - player.getWorld().playEffect(location, effect, blockTypeFinal); - player.getWorld().playEffect(location, effect, Material.STONE); - CompatibleSound.BLOCK_ANVIL_LAND.play(player); - }, 10L); - Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 15L); - Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 20L); - Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { - CompatibleSound.BLOCK_ANVIL_LAND.play(player); - player.getWorld().playEffect(location, effect, blockTypeFinal); - player.getWorld().playEffect(location, effect, Material.ANVIL); - instance.getLocale().getMessage("event.repair.success").sendPrefixedMessage(player); - - playerData.getToBeRepaired().setDurability((short) 0); - HashMap items = player.getInventory().addItem(playerData.getToBeRepaired()); - for (ItemStack item : items.values()) { - player.getWorld().dropItemNaturally(player.getLocation(), item); - } - - playerData.getItem().remove(); - if (player.getGameMode() != GameMode.CREATIVE && - type == RepairType.XP) { - player.setLevel(player.getLevel() - playerData.getPrice()); - } - this.playerAnvilData.remove(player.getUniqueId()); - player.closeInventory(); - }, 25L); - return; + if (typeStr.contains("DIAMOND")) { + blockType = Material.DIAMOND_BLOCK; + } else if (typeStr.contains("IRON")) { + blockType = Material.IRON_BLOCK; + } else if (typeStr.contains("GOLD")) { + blockType = Material.GOLD_BLOCK; + } else if (typeStr.contains("STONE")) { + blockType = Material.STONE; + } else if (typeStr.contains("WOOD")) { + blockType = CompatibleMaterial.OAK_WOOD.getMaterial(); } - if (type == RepairType.ECONOMY) { - instance.getLocale().getMessage("event.repair.notenough") - .processPlaceholder("type", instance.getLocale().getMessage("interface.repair.eco").getMessage()) - .sendPrefixedMessage(player); - } else if (type == RepairType.XP) - instance.getLocale().getMessage("event.repair.notenough") - .processPlaceholder("type", instance.getLocale().getMessage("interface.repair.xp").getMessage()) - .sendPrefixedMessage(player); - else - instance.getLocale().getMessage("event.repair.notenough") - .processPlaceholder("type", name).sendPrefixedMessage(player); + final Material blockTypeFinal = blockType; - // we've failed to repair, so return the item - removeItem(playerData, player); + Location location = playerData.getLocations(); + player.getWorld().playEffect(location, effect, blockType); + Runnable runnable = () -> player.getWorld().playEffect(location, effect, blockTypeFinal); + Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 5L); + Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { + player.getWorld().playEffect(location, effect, blockTypeFinal); + player.getWorld().playEffect(location, effect, Material.STONE); + CompatibleSound.BLOCK_ANVIL_LAND.play(player); + }, 10L); + Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 15L); + Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 20L); + Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { + CompatibleSound.BLOCK_ANVIL_LAND.play(player); + player.getWorld().playEffect(location, effect, blockTypeFinal); + player.getWorld().playEffect(location, effect, Material.ANVIL); + instance.getLocale().getMessage("event.repair.success").sendPrefixedMessage(player); - } catch (Exception ex) { - Debugger.runReport(ex); + playerData.getToBeRepaired().setDurability((short) 0); + HashMap items = player.getInventory().addItem(playerData.getToBeRepaired()); + for (ItemStack item : items.values()) { + player.getWorld().dropItemNaturally(player.getLocation(), item); + } + + playerData.getItem().remove(); + if (player.getGameMode() != GameMode.CREATIVE && + type == RepairType.XP) { + player.setLevel(player.getLevel() - playerData.getPrice()); + } + this.playerAnvilData.remove(player.getUniqueId()); + player.closeInventory(); + }, 25L); + return; } + + if (type == RepairType.ECONOMY) { + instance.getLocale().getMessage("event.repair.notenough") + .processPlaceholder("type", instance.getLocale().getMessage("interface.repair.eco").getMessage()) + .sendPrefixedMessage(player); + } else if (type == RepairType.XP) + instance.getLocale().getMessage("event.repair.notenough") + .processPlaceholder("type", instance.getLocale().getMessage("interface.repair.xp").getMessage()) + .sendPrefixedMessage(player); + else + instance.getLocale().getMessage("event.repair.notenough") + .processPlaceholder("type", name).sendPrefixedMessage(player); + + // we've failed to repair, so return the item + removeItem(playerData, player); } public void removeItem(PlayerAnvilData playerData, Player player) { - try { - player.getInventory().addItem(playerData.getToBeRepaired()); - playerData.getItem().remove(); + player.getInventory().addItem(playerData.getToBeRepaired()); + playerData.getItem().remove(); - this.playerAnvilData.remove(player.getUniqueId()); - } catch (Exception ex) { - Debugger.runReport(ex); - } + this.playerAnvilData.remove(player.getUniqueId()); } public boolean hasInstance(Player player) { diff --git a/src/main/java/com/songoda/ultimaterepairing/listeners/BlockListeners.java b/src/main/java/com/songoda/ultimaterepairing/listeners/BlockListeners.java index 8a2bd38..6872d67 100644 --- a/src/main/java/com/songoda/ultimaterepairing/listeners/BlockListeners.java +++ b/src/main/java/com/songoda/ultimaterepairing/listeners/BlockListeners.java @@ -2,7 +2,6 @@ package com.songoda.ultimaterepairing.listeners; import com.songoda.ultimaterepairing.UltimateRepairing; import com.songoda.ultimaterepairing.anvil.UAnvil; -import com.songoda.ultimaterepairing.utils.Debugger; import com.songoda.ultimaterepairing.utils.Methods; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -23,33 +22,24 @@ public class BlockListeners implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { - try { - if (!event.getBlockPlaced().getType().name().contains("ANVIL") - || !event.getPlayer().hasPermission("ultimaterepairing.permPlace")) { - return; - } - - instance.getAnvilManager().getAnvil(event.getBlock()).setPermPlaced(true); - - } catch (Exception ex) { - Debugger.runReport(ex); + if (!event.getBlockPlaced().getType().name().contains("ANVIL") + || !event.getPlayer().hasPermission("ultimaterepairing.permPlace")) { + return; } + + instance.getAnvilManager().getAnvil(event.getBlock()).setPermPlaced(true); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { - try { - String loc = Methods.serializeLocation(event.getBlock()); + String loc = Methods.serializeLocation(event.getBlock()); - if (!event.getBlock().getType().name().contains("ANVIL") && !instance.getConfig().contains("data.anvil." + loc)) { - return; - } - - UAnvil anvil = instance.getAnvilManager().getAnvil(event.getBlock()); - anvil.setHologram(false); - instance.getAnvilManager().removeAnvil(event.getBlock().getLocation()); - } catch (Exception ex) { - Debugger.runReport(ex); + if (!event.getBlock().getType().name().contains("ANVIL") && !instance.getConfig().contains("data.anvil." + loc)) { + return; } + + UAnvil anvil = instance.getAnvilManager().getAnvil(event.getBlock()); + anvil.setHologram(false); + instance.getAnvilManager().removeAnvil(event.getBlock().getLocation()); } } \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimaterepairing/listeners/InteractListeners.java b/src/main/java/com/songoda/ultimaterepairing/listeners/InteractListeners.java index f0a368d..32fdc57 100644 --- a/src/main/java/com/songoda/ultimaterepairing/listeners/InteractListeners.java +++ b/src/main/java/com/songoda/ultimaterepairing/listeners/InteractListeners.java @@ -5,15 +5,14 @@ import com.songoda.ultimaterepairing.UltimateRepairing; import com.songoda.ultimaterepairing.anvil.UAnvil; import com.songoda.ultimaterepairing.gui.AnvilSettingsGui; import com.songoda.ultimaterepairing.settings.Settings; -import com.songoda.ultimaterepairing.utils.Debugger; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.Inventory; /** * Created by songoda on 2/25/2017. @@ -31,59 +30,54 @@ public class InteractListeners implements Listener { @EventHandler public void onAnvilClick(PlayerInteractEvent event) { - try { - boolean ourRepair = false; - boolean vanillaRepair = false; - Player player = event.getPlayer(); - if (event.getClickedBlock() == null) return; + boolean ourRepair = false; + boolean vanillaRepair = false; + Player player = event.getPlayer(); + if (event.getClickedBlock() == null) return; - UAnvil anvil1 = null; + UAnvil anvil1 = null; - if (!event.getClickedBlock().getType().name().contains("ANVIL") // don't pay attention if it's not an anvil - // also don't handle if we don't have perms to use this repair anvil - || (Settings.PERMISSION_ANVIL_PLACE.getBoolean() - && !(anvil1 = instance.getAnvilManager().getAnvil(event.getClickedBlock())).isPermPlaced())) { - return; - } - anvil1 = anvil1 != null ? anvil1 : instance.getAnvilManager().getAnvil(event.getClickedBlock()); + if (!event.getClickedBlock().getType().name().contains("ANVIL") // don't pay attention if it's not an anvil + // also don't handle if we don't have perms to use this repair anvil + || (Settings.PERMISSION_ANVIL_PLACE.getBoolean() + && !(anvil1 = instance.getAnvilManager().getAnvil(event.getClickedBlock())).isPermPlaced())) { + return; + } + anvil1 = anvil1 != null ? anvil1 : instance.getAnvilManager().getAnvil(event.getClickedBlock()); // if (anvil1.isInfinity()) { // event.getClickedBlock().setType(Material.AIR); // event.getClickedBlock().setType(Material.ANVIL); //ToDO: This may not work. // } - // check if we should process this as a right click - boolean rightClick = (event.getAction() == Action.RIGHT_CLICK_BLOCK) ^ (Settings.SWAP_LEFT_RIGHT.getBoolean()); - // admin interface? - if(rightClick && player.isSneaking() && player.hasPermission("ultimaterepairing.admin")) { - guiManager.showGUI(player, new AnvilSettingsGui(anvil1)); + // check if we should process this as a right click + boolean rightClick = (event.getAction() == Action.RIGHT_CLICK_BLOCK) ^ (Settings.SWAP_LEFT_RIGHT.getBoolean()); + // admin interface? + if (rightClick && player.isSneaking() && player.hasPermission("ultimaterepairing.admin")) { + guiManager.showGUI(player, new AnvilSettingsGui(anvil1)); + event.setCancelled(true); + } else if (!Settings.ENABLE_ANVIL_DEFAULT_FUNCTION.getBoolean()) { + // if not allowing default anvil, then always use ourRepair + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { event.setCancelled(true); - } else if (!Settings.ENABLE_ANVIL_DEFAULT_FUNCTION.getBoolean()) { - // if not allowing default anvil, then always use ourRepair - if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { - event.setCancelled(true); - } - // replace our functions for vanilla mechanics only - if(!rightClick) { - return; - } - ourRepair = true; - } else if(rightClick) { - // allowing normal repair - vanillaRepair = true; - } else if(!player.isSneaking()) { - // that's us! - ourRepair = true; } + // replace our functions for vanilla mechanics only + if (!rightClick) { + return; + } + ourRepair = true; + } else if (rightClick) { + // allowing normal repair + vanillaRepair = true; + } else if (!player.isSneaking()) { + // that's us! + ourRepair = true; + } - if (ourRepair) { - instance.getRepairHandler().initRepair(player, event.getClickedBlock().getLocation()); - event.setCancelled(true); - } else if (vanillaRepair && anvil1.isInfinity()) { - Inventory inv = Bukkit.createInventory(null, InventoryType.ANVIL, "Repair & Name"); - player.openInventory(inv); - event.setCancelled(true); - } - } catch (Exception ex) { - Debugger.runReport(ex); + if (ourRepair) { + instance.getRepairHandler().initRepair(player, event.getClickedBlock().getLocation()); + event.setCancelled(true); + } else if (vanillaRepair && anvil1.isInfinity()) { + player.openInventory(Bukkit.createInventory(null, InventoryType.ANVIL, ChatColor.DARK_GRAY + "Repair & Name")); + event.setCancelled(true); } } } \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimaterepairing/listeners/InventoryListeners.java b/src/main/java/com/songoda/ultimaterepairing/listeners/InventoryListeners.java index 3145040..9a5d336 100644 --- a/src/main/java/com/songoda/ultimaterepairing/listeners/InventoryListeners.java +++ b/src/main/java/com/songoda/ultimaterepairing/listeners/InventoryListeners.java @@ -21,5 +21,4 @@ public class InventoryListeners implements Listener { if (event.getItem().hasMetadata("UltimateRepairing")) event.setCancelled(true); } - } \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimaterepairing/utils/Debugger.java b/src/main/java/com/songoda/ultimaterepairing/utils/Debugger.java deleted file mode 100644 index 6a456e9..0000000 --- a/src/main/java/com/songoda/ultimaterepairing/utils/Debugger.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.songoda.ultimaterepairing.utils; - -import com.songoda.ultimaterepairing.UltimateRepairing; - -/** - * Created by songoda on 3/21/2017. - */ -public class Debugger { - - - public static void runReport(Exception e) { - if (isDebug()) { - System.out.println("=============================================================="); - System.out.println("The following is an error encountered in UltimateRepairing."); - System.out.println("--------------------------------------------------------------"); - e.printStackTrace(); - System.out.println("=============================================================="); - } - sendReport(e); - } - - public static void sendReport(Exception e) { - - } - - public static boolean isDebug() { - return UltimateRepairing.getInstance().getConfig().getBoolean("System.Debugger Enabled"); - } - -} From 6c28252c3844731756aa387a4ddede7cd83172b0 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 1 Feb 2020 06:59:26 -0500 Subject: [PATCH 3/6] Update language file. --- src/main/resources/en_US.lang | 61 ++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index d98a275..8b029bf 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -1,31 +1,40 @@ -#General Messages +# General Messages -general.nametag.prefix = "&8[&6UltimateRepairing&8]" -general.hologram.click = "Left-Click with an item" -general.hologram.swapclick = "Right-Click with an item" -general.hologram.oneclick = "Click with an item" -general.hologram.torepair = "to &6Repair&r!" +general: + nametag: + prefix: '&8[&6UltimateRepairing&8]' + hologram: + click: Left-Click with an item + swapclick: Right-Click with an item + oneclick: Click with an item + torepair: to &6Repair&r! -#Interface Messages +# Interface Messages -interface.repair.title = "&9How do you want to repair?" -interface.yesno.title = "&9Repair for &a%cost%&9?" -interface.yesno.yes = "&a&lYes" -interface.yesno.no = "&c&lNo" -interface.repair.xp = "&9XP" -interface.repair.xplore = "&7Click to repair with XP." -interface.repair.eco = "&9Economy" -interface.repair.ecolore = "&7Click to repair with Economy." -interface.repair.item = "&9%ITEM%" -interface.repair.itemlore = "&7Click to repair with %item%." +interface: + repair: + title: '&9How do you want to repair?' + xp: '&9XP' + xplore: '&7Click to repair with XP.' + eco: '&9Economy' + ecolore: '&7Click to repair with Economy.' + item: '&9%ITEM%' + itemlore: '&7Click to repair with %item%.' + yesno: + title: '&9Repair for &a%cost%&9?' + 'yes': '&a&lYes' + 'no': '&c&lNo' -#Event Messages +# Event Messages -event.general.nopermission = "&cYou do not have permission to do that." -event.repair.timeout = "&cYour repair timed out..." -event.repair.notdamaged = "&aThis item is not damaged." -event.repair.needspace = "&cYou need to have free space above the anvil!" -event.repair.cantrepair = "&cYou can't repair this!" -event.repair.notenough = "&cYou don't have enough %type% &cto repair this item!" -event.repair.success = "&aYour item has been successfully repaired!" -event.repair.cancelled = "&cCancelled repairing." \ No newline at end of file +event: + general: + nopermission: '&cYou do not have permission to do that.' + repair: + timeout: '&cYour repair timed out...' + notdamaged: '&aThis item is not damaged.' + needspace: '&cYou need to have free space above the anvil!' + cantrepair: '&cYou can''t repair this!' + notenough: '&cYou don''t have enough %type% &cto repair this item!' + success: '&aYour item has been successfully repaired!' + cancelled: '&cCancelled repairing.' From d2dae5e6181cfd86102adb46210f97a23851d06a Mon Sep 17 00:00:00 2001 From: Brianna Date: Mon, 16 Mar 2020 13:22:15 -0400 Subject: [PATCH 4/6] Added public repo --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 2db2494..bfe2058 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,10 @@ private http://repo.songoda.com/artifactory/private/ + + public + https://repo.songoda.com/artifactory/public/ + spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ From 162054326bfae76c0d876db875f0515f2945c576 Mon Sep 17 00:00:00 2001 From: Brianna Date: Fri, 12 Jun 2020 08:43:18 -0500 Subject: [PATCH 5/6] Drop on ground if inventory is full. --- .../songoda/ultimaterepairing/handlers/RepairHandler.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/songoda/ultimaterepairing/handlers/RepairHandler.java b/src/main/java/com/songoda/ultimaterepairing/handlers/RepairHandler.java index 703de22..e7359ef 100644 --- a/src/main/java/com/songoda/ultimaterepairing/handlers/RepairHandler.java +++ b/src/main/java/com/songoda/ultimaterepairing/handlers/RepairHandler.java @@ -4,6 +4,7 @@ import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleSound; import com.songoda.core.gui.GuiManager; import com.songoda.core.hooks.EconomyManager; +import com.songoda.core.utils.PlayerUtils; import com.songoda.ultimaterepairing.UltimateRepairing; import com.songoda.ultimaterepairing.anvil.PlayerAnvilData; import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType; @@ -17,9 +18,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; /** * Created by songoda on 2/25/2017. @@ -233,7 +232,7 @@ public class RepairHandler { } public void removeItem(PlayerAnvilData playerData, Player player) { - player.getInventory().addItem(playerData.getToBeRepaired()); + PlayerUtils.giveItem(player, playerData.getToBeRepaired()); playerData.getItem().remove(); this.playerAnvilData.remove(player.getUniqueId()); From f5f1fb1c4361fc74d2548e506e3be705ad84c867 Mon Sep 17 00:00:00 2001 From: Brianna Date: Fri, 12 Jun 2020 08:43:41 -0500 Subject: [PATCH 6/6] version 1.3.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bfe2058..af4dd77 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda UltimateRepairing 4.0.0 - 1.3.4 + 1.3.5 clean install UltimateRepairing-${project.version}