Solved instance of repairable

Discussion in 'Plugin Development' started by 15987632, Aug 30, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    15987632

    The two parts that aren't working are the instanceof repairable and the setting the anvil to a new anvil every time a player right clicks. When i shift right click with any item i want to repair it just give me this line

    player.sendMessage(prefix + ChatColor.RED + "You can't repair that item!");

    the other part i tried to use data to keep the anvils rotation but that didn't work


    here is my code
    Code:java
    1. import net.milkbowl.vault.economy.Economy;
    2. import net.milkbowl.vault.economy.EconomyResponse;
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.Repairable;
    14. import org.bukkit.plugin.RegisteredServiceProvider;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. import java.util.logging.Logger;
    18.  
    19.  
    20. public class RepairingAnvils extends JavaPlugin implements Listener {
    21. Logger myPluginLogger = Bukkit.getLogger();
    22.  
    23. public void onEnable() {
    24. myPluginLogger.info("is started");
    25. getServer().getPluginManager().registerEvents(this, this);
    26. setupEconomy();
    27. if (!setupEconomy()) {
    28. getLogger().severe("PLUGIN REQUIRES VAULT");
    29. Bukkit.getPluginManager().disablePlugin(this);
    30. }
    31. saveDefaultConfig();
    32.  
    33. }
    34.  
    35.  
    36. public static Economy econ = null;
    37.  
    38. private boolean setupEconomy() {
    39. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    40. if (economyProvider != null) {
    41. econ = economyProvider.getProvider();
    42. }
    43.  
    44. return (econ != null);
    45. }
    46.  
    47. @EventHandler
    48. public void onClick(PlayerInteractEvent event) {
    49. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    50. final Player player = event.getPlayer();
    51. if (event.getClickedBlock().getType() == Material.ANVIL) {
    52. if (player.isSneaking() == true) {
    53. //repair items
    54.  
    55. event.setCancelled(true);
    56. String prefix = getConfig().getString("prefix");
    57. ItemStack item = player.getItemInHand();
    58. int price = getConfig().getInt("price");
    59. if (player.getItemInHand() != null && player.getItemInHand().getType() != Material.AIR && player.getItemInHand() instanceof Repairable) {
    60. if (item.getDurability() != item.getType().getMaxDurability()) {
    61. if (econ.getBalance(player) <= price) {
    62. EconomyResponse r = econ.withdrawPlayer(player, price);
    63. if (r.transactionSuccess()){
    64. item.setDurability(item.getType().getMaxDurability());
    65. player.sendMessage(prefix + ChatColor.GREEN + "Your item has been successfully repaired!");
    66. } else {
    67. player.sendMessage(prefix + ChatColor.RED + "There has been an error, please try again!");
    68. }
    69.  
    70. } else {
    71. player.sendMessage(prefix + ChatColor.RED + "You do not have enough points to repair your item.");
    72. }
    73. } else {
    74. player.sendMessage(prefix + ChatColor.RED + "Your item already has its max durability.");
    75. }
    76.  
    77.  
    78. } else {
    79. player.sendMessage(prefix + ChatColor.RED + "You can't repair that item!");
    80. }
    81.  
    82. } else {
    83. //use it normal and set a new one every time for infinite uses
    84.  
    85. Location l = event.getClickedBlock().getLocation();
    86. byte data = event.getClickedBlock().getData();
    87. event.getClickedBlock().setType(Material.ANVIL);
    88. event.getClickedBlock().setData(data);
    89.  
    90. }
    91. }
    92. }
    93. }
    94. }
     
  2. Offline

    TheMintyMate

    Have you tried removing the:
    Code:
    instanceof repariable
    
    You also don't meed to detect if there is air in their hand, as you are already detecting if item in hand is null.
    See what happens...

    Hope this helps,
    - Minty
     
  3. Offline

    15987632

    TheMintyMate ok i removed the check for if its repairable and now its saying i dont have enough money when i know i do :/
     
  4. Offline

    JustinsCool15

    15987632
    You're using a "<" symbol in your balance check, you should be using a ">" symbol.
     
    TheMintyMate likes this.
  5. Offline

    15987632

    JustinsCool15 oh that was my bad stupid mistake :p

    ok i got that part completely working now but how do i make an anvil infinite by resetting it a bunch. Is there an event for anvildamage or something?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  6. Offline

    JustinsCool15

    15987632
    I'm not exactly sure but try this,
    Code:java
    1. event.getClickedBlock().setType(Material.ANVIL);
     
  7. Offline

    15987632

  8. Offline

    JustinsCool15

    15987632
    Maybe try this :oops:
    Code:java
    1. event.getClickedBlock().getState().setType(Material.ANVIL);
     
  9. Offline

    15987632

  10. Offline

    jpjunho

    15987632
    Try doing b.setData(0);
    (b is your anvil)
     
  11. Offline

    15987632

  12. Offline

    jpjunho

    15987632
    I'm glad it worked out! Remember to mark the thread as solved
     
Thread Status:
Not open for further replies.

Share This Page