[UNSOLVED] code not working

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

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

    monkeymanboy

    im trying to cancel recipes in one world it cancels it but in all worlds here is my code
    Code:
        @EventHandler
        public void RemoveRecipes(CraftItemEvent e) { int item = e.getRecipe().getResult().getTypeId();
        FileConfiguration config = this.getConfig();
        List<String> enabledWorlds = Arrays.asList(config.getString("config.Mine Cloud Hard World"));
        HumanEntity p = (HumanEntity)e.getViewers().get(0);
        if ((p instanceof Player)) {
            Player player = (Player)p;
            ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE, 1, (short) 0);
            ItemStack glisteringMelon = new ItemStack(Material.SPECKLED_MELON);
            ItemStack woodenPick = new ItemStack(Material.WOOD_PICKAXE);
            ItemStack woodenAxe = new ItemStack(Material.WOOD_AXE);
            ItemStack woodenHoe = new ItemStack(Material.WOOD_HOE);
            ItemStack woodenShovel = new ItemStack(Material.WOOD_SPADE);
            ItemStack woodenSword = new ItemStack(Material.WOOD_SWORD);
            ItemStack stonePick = new ItemStack(Material.STONE_PICKAXE);
            ItemStack stoneAxe = new ItemStack(Material.STONE_AXE);
            ItemStack stoneHoe = new ItemStack(Material.STONE_HOE);
            ItemStack stoneShovel = new ItemStack(Material.STONE_SPADE);
            ItemStack stoneSword = new ItemStack(Material.STONE_SWORD);
            ItemStack ironPick = new ItemStack(Material.IRON_PICKAXE);
            ItemStack ironAxe = new ItemStack(Material.IRON_AXE);
            ItemStack ironHoe = new ItemStack(Material.IRON_HOE);
            ItemStack ironShovel = new ItemStack(Material.IRON_SPADE);
            ItemStack ironSword = new ItemStack(Material.IRON_SWORD);
            ItemStack goldPick = new ItemStack(Material.GOLD_PICKAXE);
            ItemStack goldAxe = new ItemStack(Material.GOLD_AXE);
            ItemStack goldHoe = new ItemStack(Material.GOLD_HOE);
            ItemStack goldShovel = new ItemStack(Material.GOLD_SPADE);
            ItemStack goldSword = new ItemStack(Material.GOLD_SWORD);
            ItemStack diamondPick = new ItemStack(Material.DIAMOND_PICKAXE);
            ItemStack diamondAxe = new ItemStack(Material.DIAMOND_AXE);
            ItemStack diamondHoe = new ItemStack(Material.DIAMOND_HOE);
            ItemStack diamondShovel = new ItemStack(Material.DIAMOND_SPADE);
            ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD);
            ItemStack ironHelmet = new ItemStack(Material.IRON_HELMET);
            ItemStack ironChest = new ItemStack(Material.IRON_CHESTPLATE);
            ItemStack ironLegs = new ItemStack(Material.IRON_LEGGINGS);
            ItemStack ironBoots = new ItemStack(Material.IRON_BOOTS);
            ItemStack goldHelmet = new ItemStack(Material.GOLD_HELMET);
            ItemStack goldChest = new ItemStack(Material.GOLD_CHESTPLATE);
            ItemStack goldLegs = new ItemStack(Material.GOLD_LEGGINGS);
            ItemStack goldBoots = new ItemStack(Material.GOLD_BOOTS);
            ItemStack diamondHelmet = new ItemStack(Material.DIAMOND_HELMET);
            ItemStack diamondChest = new ItemStack(Material.DIAMOND_CHESTPLATE);
            ItemStack diamondLegs = new ItemStack(Material.DIAMOND_LEGGINGS);
            ItemStack diamondBoots = new ItemStack(Material.DIAMOND_BOOTS);
     
            Iterator<Recipe> recipes = Bukkit.recipeIterator();{
                while(recipes.hasNext()) {
                    Recipe recipe = recipes.next();
                    if(enabledWorlds.contains(p.getWorld().getName())){
                        if(recipe.getResult().equals(goldenApple) || recipe.getResult().equals(glisteringMelon) || recipe.getResult().equals(woodenPick) || recipe.getResult().equals(woodenAxe) || recipe.getResult().equals(woodenHoe) || recipe.getResult().equals(woodenShovel) || recipe.getResult().equals(woodenSword) || recipe.getResult().equals(stonePick) || recipe.getResult().equals(stoneAxe) || recipe.getResult().equals(stoneHoe) || recipe.getResult().equals(stoneShovel) || recipe.getResult().equals(stoneSword) || recipe.getResult().equals(ironPick) || recipe.getResult().equals(ironAxe) || recipe.getResult().equals(ironHoe) || recipe.getResult().equals(ironShovel) || recipe.getResult().equals(ironSword) || recipe.getResult().equals(goldPick) || recipe.getResult().equals(goldAxe) || recipe.getResult().equals(goldHoe) || recipe.getResult().equals(goldShovel) || recipe.getResult().equals(goldSword) || recipe.getResult().equals(diamondPick) || recipe.getResult().equals(diamondAxe) || recipe.getResult().equals(diamondHoe) || recipe.getResult().equals(diamondShovel) || recipe.getResult().equals(diamondSword) || recipe.getResult().equals(ironHelmet) || recipe.getResult().equals(ironChest) || recipe.getResult().equals(ironLegs) || recipe.getResult().equals(ironBoots) || recipe.getResult().equals(goldHelmet) || recipe.getResult().equals(goldChest) || recipe.getResult().equals(goldLegs) || recipe.getResult().equals(goldBoots) || recipe.getResult().equals(diamondHelmet) || recipe.getResult().equals(diamondChest) || recipe.getResult().equals(diamondLegs) || recipe.getResult().equals(diamondBoots))
                            e.setCancelled(true);
                    }
                }
            }
        }
        }
     
  2. Offline

    LanteanKnight

    Code:
    if(enabledWorlds.contains(p.getWorld().getName()
    You are getting the world of the player issuing the event, so it will occur in every world. Specify a world like:

    Code:
    if(e.getPlayer().getWorld().getName().equals("Fred"))
     
  3. Offline

    xTrollxDudex

    monkeymanboy
    You can't start a body with an iterator can you? Even if you can a semicolon before will cause errors. And a viewer can only be a player, no need to check there.

    Also did you mean:
    PHP:
    List<StringenabledWorlds config.getList("config.Mine Cloud Hard World");
    Make sure to check that the list is not null.
    LanteanKnight
    There is nothing wrong with that, don't change it.
     
    Xerfox likes this.
  4. Offline

    monkeymanboy

    Well the iterator is working its just doing it in all the worlds and I don't know why also that would not work because my config.Mine Cloud Hard World is not a list
     
  5. Offline

    xTrollxDudex

  6. Offline

    monkeymanboy

    xTrollxDudex
    I don't know why it's not doing it why else would I be asking whats wrong with it
     
  7. Offline

    xTrollxDudex

    monkeymanboy
    I thibk it's because the config doesn't have an array in it... Any errors at all? Can you show me the config?
     
  8. Offline

    monkeymanboy

    No errors here is the config
    Code:
    config:
      Mine Cloud Hard World: MineCloudHard
      Glistering Melon Heal: true
      Glistering Melon Heal Amount(every 1 number is a half heart): 2
    
     
  9. Offline

    xTrollxDudex

    monkeymanboy
    Just do
    PHP:
    if(player.getWorld().getName().equals(config.getString("config.Mine Cloud Hard World"))){
     
  10. Offline

    monkeymanboy

    xTrollxDudex I removed my array and changed my old world checker to this but nothing changed still just not crafting everywhere
     
  11. Offline

    xTrollxDudex

    monkeymanboy
    So what's the iterator for?
    If you are trying to cancel the result, use if(e.getResult().equals(...)) and set it cancelled. Also for your code, did you use p.getWorld().getName().equals(config.getString("config.Mine Cloud Hard World")). And put ' ' around the world in the config,
     
  12. Offline

    monkeymanboy

    I did not put the ' ' in the config and the reason for the iterator is i used to remove those items but switched it to cancel and forgot to remove it

    xTrollxDudex oh thank you now it works after removing the iterator

    xTrollxDudex spoke to soon it's doing the opposite of what I want it to do its preventing it in all worlds EXCEPT the one I want it to do it in so I put ! before it and its doing the same thing still

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

    xTrollxDudex

    monkeymanboy
    PHP:
    if(!(p.getWorld().getName().equals(config.getString("config.Mine Cloud Hard World)))){
     
  14. Offline

    monkeymanboy

    xTrollxDudex thats what I did and it's still preventing every world except the one i want it to prevent it in
    i want it the other way around
     
  15. Offline

    xTrollxDudex

  16. Offline

    monkeymanboy

    Nope same thing still
     
  17. Offline

    xTrollxDudex

    monkeymanboy
    I mean put an else if under what the original code was, and change e.setCancelled(true) to e.setCancelled(false), then under the else, put e.setCancelled(true)
     
  18. Offline

    monkeymanboy

    xTrollxDudex I did that it is allowing crafting everywhere now

    xTrollxDudex Like this right?
    Code:
    if(!(p.getWorld().getName().equals(config.getString("config.Mine Cloud Hard World")))){
                    if(e.getResult().equals(goldenApple) || e.getResult().equals(glisteringMelon) || e.getResult().equals(woodenPick) || e.getResult().equals(woodenAxe) || e.getResult().equals(woodenHoe) || e.getResult().equals(woodenShovel) || e.getResult().equals(woodenSword) || e.getResult().equals(stonePick) || e.getResult().equals(stoneAxe) || e.getResult().equals(stoneHoe) || e.getResult().equals(stoneShovel) || e.getResult().equals(stoneSword) || e.getResult().equals(ironPick) || e.getResult().equals(ironAxe) || e.getResult().equals(ironHoe) || e.getResult().equals(ironShovel) || e.getResult().equals(ironSword) || e.getResult().equals(goldPick) || e.getResult().equals(goldAxe) || e.getResult().equals(goldHoe) || e.getResult().equals(goldShovel) || e.getResult().equals(goldSword) || e.getResult().equals(diamondPick) || e.getResult().equals(diamondAxe) || e.getResult().equals(diamondHoe) || e.getResult().equals(diamondShovel) || e.getResult().equals(diamondSword) || e.getResult().equals(ironHelmet) || e.getResult().equals(ironChest) || e.getResult().equals(ironLegs) || e.getResult().equals(ironBoots) || e.getResult().equals(goldHelmet) || e.getResult().equals(goldChest) || e.getResult().equals(goldLegs) || e.getResult().equals(goldBoots) || e.getResult().equals(diamondHelmet) || e.getResult().equals(diamondChest) || e.getResult().equals(diamondLegs) || e.getResult().equals(diamondBoots))
                        e.setCancelled(true);
                else
                    e.setCancelled(false);
                }
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  19. Offline

    xTrollxDudex

    monkeymanboy
    PHP:
    if(e.getResult().equals(goldenApple) || e.getResult().equals(glisteringMelon) || e.getResult().equals(woodenPick) || e.getResult().equals(woodenAxe) || e.getResult().equals(woodenHoe) || e.getResult().equals(woodenShovel) || e.getResult().equals(woodenSword) || e.getResult().equals(stonePick) || e.getResult().equals(stoneAxe) || e.getResult().equals(stoneHoe) || e.getResult().equals(stoneShovel) || e.getResult().equals(stoneSword) || e.getResult().equals(ironPick) || e.getResult().equals(ironAxe) || e.getResult().equals(ironHoe) || e.getResult().equals(ironShovel) || e.getResult().equals(ironSword) || e.getResult().equals(goldPick) || e.getResult().equals(goldAxe) || e.getResult().equals(goldHoe) || e.getResult().equals(goldShovel) || e.getResult().equals(goldSword) || e.getResult().equals(diamondPick) || e.getResult().equals(diamondAxe) || e.getResult().equals(diamondHoe) || e.getResult().equals(diamondShovel) || e.getResult().equals(diamondSword) || e.getResult().equals(ironHelmet) || e.getResult().equals(ironChest) || e.getResult().equals(ironLegs) || e.getResult().equals(ironBoots) || e.getResult().equals(goldHelmet) || e.getResult().equals(goldChest) || e.getResult().equals(goldLegs) || e.getResult().equals(goldBoots) || e.getResult().equals(diamondHelmet) || e.getResult().equals(diamondChest) || e.getResult().equals(diamondLegs) || e.getResult().equals(diamondBoots)){
    if(
    p.getWorld().getName().equals(config.getString("config.Mine Cloud Hard World"))){
    e.setCancelled(false);
    }else{
    e.setCancelled(true);
    }}
     
  20. Offline

    monkeymanboy

    back to doing the opposite of what I want
     
  21. Offline

    xTrollxDudex

    monkeymanboy
    Switch the true/false in te setCancelled's
     
  22. Offline

    monkeymanboy

    xTrollxDudex
    didn't change anything

    xTrollxDudex
    here is all my code if it helps im thinking that it might be that im removing things with the same item id but different recipes in all worlds except one
    http://pastebin.com/6BpsNL2e

    bump

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

    monkeymanboy

    xTrollxDudex ok so I don't care about the config that much and here is my code without it am I doing it right?
    Code:java
    1. if(e.getResult().equals(goldenApple) || e.getResult().equals(glisteringMelon) || e.getResult().equals(woodenPick) || e.getResult().equals(woodenAxe) || e.getResult().equals(woodenHoe) || e.getResult().equals(woodenShovel) || e.getResult().equals(woodenSword) || e.getResult().equals(stonePick) || e.getResult().equals(stoneAxe) || e.getResult().equals(stoneHoe) || e.getResult().equals(stoneShovel) || e.getResult().equals(stoneSword) || e.getResult().equals(ironPick) || e.getResult().equals(ironAxe) || e.getResult().equals(ironHoe) || e.getResult().equals(ironShovel) || e.getResult().equals(ironSword) || e.getResult().equals(goldPick) || e.getResult().equals(goldAxe) || e.getResult().equals(goldHoe) || e.getResult().equals(goldShovel) || e.getResult().equals(goldSword) || e.getResult().equals(diamondPick) || e.getResult().equals(diamondAxe) || e.getResult().equals(diamondHoe) || e.getResult().equals(diamondShovel) || e.getResult().equals(diamondSword) || e.getResult().equals(ironHelmet) || e.getResult().equals(ironChest) || e.getResult().equals(ironLegs) || e.getResult().equals(ironBoots) || e.getResult().equals(goldHelmet) || e.getResult().equals(goldChest) || e.getResult().equals(goldLegs) || e.getResult().equals(goldBoots) || e.getResult().equals(diamondHelmet) || e.getResult().equals(diamondChest) || e.getResult().equals(diamondLegs) || e.getResult().equals(diamondBoots)){
    2. if(!(p.getWorld().getName().equals("MineCloudHard"))){
    3. e.setCancelled(true);
    4. }else{
    5. e.setCancelled(false);
     
  24. Offline

    afistofirony

  25. Offline

    monkeymanboy

    getting errors under all the material names
     
  26. Offline

    afistofirony

    monkeymanboy Whoops, try e.getRecipe().getResult().getType() in the switch statement's parentheses instead of e.getResult(). :p
     
  27. Offline

    monkeymanboy

    afistofirony
    it works now but the recipes i added cant be crafted there and can be crafted everywhere else now
    but vanilla ones are fine now

    afistofirony I figured out whichever one has a higher priority my recipes and the vanillas will follow that one but how would I make it so that they are seperate?

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

    monkeymanboy

  29. Offline

    monkeymanboy

  30. Offline

    monkeymanboy

Thread Status:
Not open for further replies.

Share This Page