Solved Testing for int

Discussion in 'Plugin Development' started by pingpong1999, Apr 16, 2016.

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

    pingpong1999

    Code:
    public void onEvent(EntityDamageByEntityEvent e) {
                Entity Hitter =    e.getDamager();
            Entity victim = e.getEntity();
                ItemStack item = ((HumanEntity) Hitter).getItemInHand();
               
                if (item != null) {
                ItemMeta meta = item.getItemMeta();
               
                if (meta != null) {
    
                List<String> lore = meta.getLore();
                if (lore != null) {
                Random gen = new Random();
                int number = gen.nextInt(100) + 1;
                Hitter.sendMessage("Test");
                if (lore.toString().contains("Poison I")){
                    if(number <= 5){
                    ((LivingEntity) victim).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 1));
                    }
                }else if (lore.toString().contains("Poison II")){
                    if(number <= 10){
                    ((LivingEntity) victim).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 150, 1));
                    }
                }else if (lore.toString().contains("Poison III")){
                    if(number <= 30){
                    ((LivingEntity) victim).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 200, 2));
                    }
                }else if (lore.toString().contains("Poison IV")){
                    if(number <= 40){
                    ((LivingEntity) victim).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 250, 3));
                    }
                }else if (lore.toString().contains("Poison V")){
                    Hitter.sendMessage("test2");
                    if(number <= 70){
                    ((LivingEntity) victim).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 300, 3));
                //Wither
                    }
     
    So I have made a custom enchants plugin It works... but not how I want it to... So as you can see it is a random chance to hit them, it goes up the higher the level is. But the thing is.. Poison I, II, III all default to I since it asks if it contains "Poison I" How can I fix this? I tried lore.toString().equals("Poison I") but that just returns nothing... How can I fix this?!

    Ended up working it out for myself, I just swapped the order around so Poison V comes first etc

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 16, 2016
  2. Offline

    mine-care

    Don't blind-cast. What if the entity isnt a human? What if it is a skeleton?
    Follow naming conventions

    And to wrap it all up, please learn Java before working on bukkit :S
     
  3. Offline

    pingpong1999

    I learnt Java about a year before starting bukkit. lol But I tend to blindcast alot forgetting of the Issues it can cause
     
Thread Status:
Not open for further replies.

Share This Page