Help squashing bugs!

Discussion in 'Plugin Development' started by Birdytrap, Feb 1, 2013.

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

    Birdytrap

    Hello there! After a lot of time and you guys help, I finally finished my plugin... But... Its full with bugs :(
    I squashed 3-4 bugs, but these are some I don't understand...

    Bug #1: [Most annoying] When I place an item like wood, stonebricks, wool (all the items with the ##:1)
    it changes to another item with the same ID, but a different sub ID. For instance: If I place red wool, it turn into orange wool. The same thing also happens with potions. If I want to use a speed potion, it turns into a regeneration potion... (Im 100% its my plugin because if I unload it, everything turns back normal.

    Bug #2: If you look at the code: (Listener, @Eventhander) you will see that the code is supposed to work only when the item in your hand is a stick with 100 durability. It however works with every item. (exmple: When I right click with a piece of dirt the same thing will happen: The particles appear, the dirt gets a lore).

    Bug #3: If you look at the code: (Plugin, @Override) you will get that the recipe "recipepipewithweed1" is supposed to work only if the wheat has a durability of "1", same with the stick. The wheat doesn't give any problems though, if I craft normal wheat with a stick, nothing happens. The stick gives the problems. The recipe *does* work even if its a normal stick.

    Code (open)

    Well, I have not posted all of my code, this is just everything where I think there could be bugs.

    Plugin:
    Code:java
    1.  
    2. ShapedRecipe recipePipe, recipePipeweed;
    3.  
    4. ShapelessRecipe recipepipewithweed1;
    5.  
    6. public void onEnable() {
    7. Bukkit.addRecipe(recipePipe = new ShapedRecipe(new ItemStack(Material.STICK, 1)).shape(" "," #","@@@").setIngredient('@', Material.STICK).setIngredient('#', Material.WOOD));
    8. Bukkit.addRecipe(recipePipeweed = new ShapedRecipe(new ItemStack(Material.WHEAT, 1)).shape("@#@","#@#","@#@").setIngredient('@', Material.WHEAT).setIngredient('#', Material.SEEDS));
    9. Bukkit.addRecipe(recipepipewithweed1 = new ShapelessRecipe(new ItemStack(Material.STICK, 1)).addIngredient(1, Material.STICK, 1).addIngredient(1, Material.WHEAT, 1));
    10. Bukkit.getScheduler().runTaskTimer(this, this, 20, 20);


    Listener:

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(final PlayerInteractEvent event) {
    4. final Player player = event.getPlayer();
    5. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
    6. if (player.getInventory().getItemInHand().equals(Material.STICK))
    7. if (player.getInventory().getItemInHand().getDurability() == 100);
    8. player.sendMessage("§7You started smoking your pipe filled with §aLongbottom leaf");
    9. ItemStack hand = player.getItemInHand();
    10. ItemMeta meta = hand.getItemMeta();
    11. ArrayList<String> lore = new ArrayList<String>();
    12. lore.clear();
    13. lore.add(ChatColor.GOLD + "" + ChatColor.ITALIC + "Test.");
    14. meta.setLore(lore);
    15. hand.setItemMeta(meta);
    16. player.getItemInHand().setDurability((short)1);
    17.  
    18. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 0);
    19. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 1);
    20. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 2);
    21. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 3);
    22. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 4);
    23. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 5);
    24. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 6);
    25. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 7);
    26. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 8);
    27. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
    28. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
    29. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 2);
    30. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 3);
    31. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 4);
    32. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 5);
    33. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 6);
    34. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 7);
    35. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES,8);

    And:
    Code:java
    1.  
    2. if (recipe instanceof ShapedRecipe) {
    3. ShapedRecipe sRecipe = (ShapedRecipe)recipe;
    4. if (recipeMatches(sRecipe, plugin.recipePipeweed)) {
    5. ItemStack result = new ItemStack(Material.WHEAT, 1, (short)1);
    6. ItemMeta meta = result.getItemMeta();
    7. meta.setDisplayName(ChatColor.GREEN + "Longbottom Leaf");
    8. meta.setLore(Arrays.asList(PipeweedPlugin.LongbottomLore));
    9. meta.addEnchant(Enchantment.DURABILITY, 1, false);
    10. result.setItemMeta(meta);
    11.  
    12. inv.setResult(result);
    13. }
    14. }
    15.  
    16. if (recipe instanceof ShapedRecipe) {
    17. ShapedRecipe sRecipe = (ShapedRecipe)recipe;
    18. if (recipeMatches(sRecipe, plugin.recipePipe)) {
    19. ItemStack result = new ItemStack(Material.STICK, 1, (short)1);
    20. ItemMeta meta = result.getItemMeta();
    21. meta.setDisplayName(ChatColor.DARK_PURPLE + "Pipe");
    22. meta.setLore(Arrays.asList(PipeweedPlugin.PipeLore));
    23. meta.addEnchant(Enchantment.ARROW_INFINITE, 1, false);
    24. result.setItemMeta(meta);
    25.  
    26. inv.setResult(result);
    27. }
    28. }
    29.  
    30.  
    31.  
     
  2. Offline

    Frazz86

    bug 2 would be fixed by changing: if(player.getInventory().getItemInHand().getDurability()==100);
    It should be
    if(player.getInventory().getItemInHand().getDurability()==100)
    {

    }

    Obviously, you need to wrap that around the whole method :)
     
  3. Offline

    Birdytrap

    Thank you. This fixes bug all the bugs! Only, it creates another one... Even with the correct stick (With 100 durability) Nothing happens :(
     
  4. Offline

    Frazz86

    if(player.getInventory().getItemInHand().equals(Material.STICK))

    Just for the sake of testing try:
    if(player.getInventory().getItemInHand().equals(Material.STICK))
    {

    }

    Also i think getDurability isn't gonna work too well due to the fact that the stick doesn't really have a set durability and getDurability actually gets how much durability it is from that items maximum durability.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  5. Offline

    Birdytrap

    Frazz86

    I removed the if(player.getInventory().getItemInHand().getDurability()==100);

    But still even with a normal stick, nothing works :(
     
  6. Offline

    Birdytrap

    Well, I tried server things, even asked someone else (Someone on the server I play and knows a bit about java) but we could not fix the problem, since we dont know whats wrong at all! I would we terrified if this isnt fixable, since I have put lots and lots of time into this...
     
Thread Status:
Not open for further replies.

Share This Page