[UNSOLVED] code not working

Discussion in 'Plugin Development' started by monkeymanboy, Jul 28, 2013.

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

    Technius

    That code hurts my eyes... Please do something like this instead:
    Code:
    Material[] mats = {Material.GOLDEN_APPLE, Material.WOODEN_SWORD /*etc.*/}; // Items you don't want players to make
    for(Material m:mats)
    {
        ItemStack i = new ItemStack(m);
        //Do checks here
    }
    
     
  2. Offline

    monkeymanboy

    I don't think that would change anything though the problem is i want my recipes in one world and the default ones in all the others except the one world
     
  3. Offline

    Technius

    You can try using
    Code:
    event.setResult(vanillaitemstack);
    
    Where vanillaitemstack is the default item created by that recipe.
     
  4. Offline

    savagesun

    What tech said would probably work fine. I've had issues like this before I think what's going on here is that you're creating new instances of these items and then checking to see if the used item is the item instance you just created. The reason it's not returning true is because when you use the .equals(Object) method it is checking hash codes, not what the material is and so forth. So just changing this to check for the material type should work fine.
     
  5. Offline

    monkeymanboy

    I'm new to making plugins this is my first one and I don't get how this would help where would I put it?
     
  6. Offline

    Technius

    savagesun
    Actually, Bukkit added their own .equals(Object) method for ItemStack, so it should work. See here.
     
  7. Offline

    monkeymanboy

    Technius what if on my recipes i added the lore Hard Mode to all of them and as soon as you craft it the lore gets cleared this way it will check if it has the lore and if it does and they are in the hard world it will allow crafting it then lore goes away and its like a normal item would this work?
     
  8. Offline

    Technius

  9. Offline

    monkeymanboy

    it does works right now it allows all things with lore to be crafted in one world and no where else but im having a problem where everything without the lore can be crafted everywhere here is my code
    Code:java
    1. @EventHandler
    2. public void RemoveRecipes(CraftItemEvent e) {
    3. FileConfiguration config = this.getConfig();
    4. HumanEntity p = (HumanEntity) e.getViewers().get(0);
    5. ItemMeta im = e.getRecipe().getResult().getItemMeta();
    6. if (p instanceof Player) {
    7. Player player = (Player) p;
    8. switch (e.getRecipe().getResult().getType()) {
    9. case GOLDEN_APPLE: case SPECKLED_MELON: case WOOD_PICKAXE: case WOOD_AXE:
    10. case WOOD_HOE: case WOOD_SPADE: case WOOD_SWORD: case STONE_PICKAXE:
    11. case STONE_AXE: case STONE_HOE: case STONE_SPADE: case STONE_SWORD:
    12. case IRON_PICKAXE: case IRON_AXE: case IRON_HOE: case IRON_SPADE:
    13. case IRON_SWORD: case GOLD_PICKAXE: case GOLD_AXE: case GOLD_HOE:
    14. case GOLD_SPADE: case GOLD_SWORD: case DIAMOND_PICKAXE: case DIAMOND_AXE:
    15. case DIAMOND_HOE: case DIAMOND_SPADE: case DIAMOND_SWORD: case IRON_HELMET:
    16. case IRON_CHESTPLATE: case IRON_LEGGINGS: case IRON_BOOTS: case GOLD_HELMET:
    17. case GOLD_CHESTPLATE: case GOLD_LEGGINGS: case GOLD_BOOTS: case DIAMOND_HELMET:
    18. case DIAMOND_CHESTPLATE: case DIAMOND_LEGGINGS: case DIAMOND_BOOTS:
    19. if (!(im.getLore() == null)){
    20. if (im.getLore().equals("Hard Mode"))
    21. e.setCancelled(p.getWorld().getName().equals(config.getString("config.Mine Cloud Hard World")));
    22. else
    23. if (!im.getLore().equals("Hard Mode"))
    24. e.setCancelled(!p.getWorld().getName().equals(config.getString("config.Mine Cloud Hard World")));
    25. }
    26. }
    27. }
    28. }
     
Thread Status:
Not open for further replies.

Share This Page