Two questions. New to Java/Bukkit API.. confused.

Discussion in 'Plugin Development' started by Skullgunner1, Mar 30, 2013.

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

    Skullgunner1

    1. How do I set it so when a player types in a command and left/right clicks on a mob they are now this and that, with permissions.

    2. How do I get that selected mob to detect something in a certain radius. (Say if a player has a certain item.)

    I'm really new to the Bukkit API and I have NO idea what to do whatsoever.
     
  2. Offline

    SugarCraft

    I can help with a few things..
    If a player has an certain item:
    if(player.getInventory().containsAtLeast(item, 1)){
     
  3. Offline

    Skullgunner1

    Then how do you detect if he is in radius, then causing the mob to attack?

    Bump.

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

    the_merciless

    I wrote this up for you to give you most of the info i think u need, You should be able to work it out from here.

    Code:
        @EventHandler (priority = EventPriority.HIGHEST)
        public void onAttack(EntityDamageByEntityEvent e){
         
            Entity victim = e.getEntity();
            Entity attacker = e.getDamager();
         
            if (victim instanceof Creeper){
             
                if (attacker instanceof Player){
                    Player p = (Player) attacker;
                 
                    if (p.getInventory().containsAtLeast(new ItemStack (Material.DIAMOND_SWORD), 1)){
                     
                        if (p.getItemInHand().equals(Material.DIAMOND_SWORD)){
                            p.sendMessage("You just hit a creeper with a diamond sword");                 
                        }                 
                    }
                 
                    for (int i = 0; i < victim.getNearbyEntities(10, 10, 10).size(); i++){ // loops through all entities within a radius of 10 blocks
                        if (victim.getNearbyEntities(10, 10, 10).get(i) instanceof Player){ // checks if the entity is a player
                            Player p2 = (Player) victim.getNearbyEntities(10, 10, 10).get(i); //gets the player
                            if (p2.getInventory().containsAtLeast(new ItemStack (Material.TNT), 1)){ //checks if player has tnt in inventory
                                p2.getWorld().createExplosion(p2.getLocation(), 4F, true); // blows player up.
                            }
                        }
                    }
                }
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page