1. This forum is for making tests threads and posts. Feel free to experiment with our XenForo forum software.

    BB code examples and usage can be found here.
  2. Welcome to the Brawl website! Feel free to look around our forums. Join our growing community by typing /register in-game!

Guns/Grenades

Discussion in 'Test Posts' started by Algelier, Sep 20, 2016.

Thread Status:
Please be aware that this thread is more than 30 days old. Do not post unless the topic can still be discussed. Read more...
  1. Algelier

    Algelier Former Staff Member.

    Joined:
    Sep 29, 2013
    Messages:
    1,811
    Ratings:
    +1,108
    Code:
    ---Java---
    
    package fr.algelier.Pluginjava;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Snowball;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Guns extends JavaPlugin implements Listener {
    
        public Guns(Pluginjava pluginjava) {}
      
        @Override
        public void onEnable(){
            Bukkit.getPluginManager().registerEvents(this, this);
            super.onEnable();
          
        }
      
      
        @EventHandler
        public void onGrenadeLaunch(PlayerInteractEvent e){
          
            Player player = e.getPlayer();
            ItemStack it = e.getItem();
          
            if(it != null){
                if(it.getType() == Material.SLIME_BALL){
                    if(it.getType()== Material.BLAZE_POWDER){
                        if(it.getType()== Material.FLINT){
                      
                  
                    player.getInventory().removeItem(new ItemStack(Material.SLIME_BALL, 1));
                    player.updateInventory();
                    player.getInventory().removeItem(new ItemStack(Material.BLAZE_POWDER, 1));
                    player.updateInventory();
                    player.getInventory().removeItem(new ItemStack(Material.FLINT, 1));
                    player.updateInventory();
                  
                final Item ball = player.getWorld().dropItem(player.getLocation(), new ItemStack (Material.SLIME_BALL, 1));
                ball.setVelocity(player.getEyeLocation().getDirection());
                final Item ball2 = player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.BLAZE_POWDER,1 ));
                ball2.setVelocity(player.getEyeLocation().getDirection());
                final Item ball3 = player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.FLINT));
                ball3.setVelocity(player.getEyeLocation().getDirection());
              
              
              
                Bukkit.getScheduler().runTaskLater(this, new Runnable (){
    
                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        ball.getWorld().createExplosion(ball.getLocation(), 5f);
                        ball.getWorld().playEffect(ball.getLocation(),Effect.LARGE_SMOKE, 20);
                        ball2.getWorld().playEffect(ball2.getLocation(),Effect.LARGE_SMOKE, 20);
                        ball3.getWorld().playEffect(ball3.getLocation(),Effect.LARGE_SMOKE, 50);
                  
                  
                        for(Entity entities : ball.getNearbyEntities(5.0, 5.0, 5.0)){
                            if(entities instanceof Player){
                                Player p = (Player) entities;
                                p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 120, 5));
                              
                                for(Entity entities1 : ball2.getNearbyEntities(5.0, 5.0, 5.0)){
                                    if(entities1 instanceof Player){
                                        p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 120, 2));
                                      
                                      
                                        for(Entity entites2 : ball3.getNearbyEntities(6.0, 6.0, 6.0)){
                                            if(entites2 instanceof Player){
                                                p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 120, 2));
                                              
                                              
                                              
                                            }
                                        }
                                    }
                                  
                                }
                            }
                        }
                      
                        ball.remove();
                        ball2.remove();
                        ball3.remove();
                      
                    }
                  
                },100);
              
          
              
              
              
                }}}}
          
          
          
          
                    }
      
      
    
    
        @EventHandler
        public void onDamage(EntityDamageByEntityEvent e){
        if(e.getDamager() instanceof Snowball){
            Snowball s = (Snowball) e.getDamager();
          
            if(s.getShooter() instanceof Player){
                Player shooter = (Player) s.getShooter();
              
                if(shooter.getItemInHand().getType() == Material.DIAMOND_HOE){
                    e.setDamage(10);
                }
                  
            }
          
        }
        }
      
      
        @EventHandler
        public void onPInteract(PlayerInteractEvent e){
            Player p = e.getPlayer();
            if(e.getItem()!= null){
            if(e.getItem().getType() == Material.DIAMOND_HOE){
              
        if(e.getAction() == Action.RIGHT_CLICK_AIR){
        if(p.getInventory().contains(Material.SNOW_BALL)){
            p.launchProjectile(Snowball.class);
            p.getInventory().removeItem(new ItemStack(Material.DIAMOND, 1));
        p.updateInventory();
      
        }else{
                p.sendMessage("Out of §4Ammo !");
            }
        }
        }
        }
      
          
            if(e.getAction() == Action.LEFT_CLICK_AIR){
                if(p.hasPotionEffect(PotionEffectType.SLOW)){
                    p.removePotionEffect(PotionEffectType.SLOW);
                }else {
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 999999, 15));
                }
              
            }
        }
      
      
      
    
    }
    
    
    
    
     
  2. Hitchens

    Hitchens Well-Known Member

    Joined:
    Oct 21, 2013
    Messages:
    1,392
    Ratings:
    +413
    I read this on my phone, so it was kinda painfull as i am sure you can imagine.

    I'll read this again on my pc tomorrow and give some more tips tomorrow, but heres one:
    The damage the snowball makes is determined based on the item the shooter has in hand when the snowball hits. This isnt optimal beacuse of obvious reasons. I would recommend setting metadata to the snowball in the OnPInteract eventhandler (onplayerinteractevent). You could then read the metadata when the snowball hits.

    Edit: anotha one:
    What if a player hits something instead of just right/leftclicking air. Scoping or shooting wont work. Add || action.LEFT_CLICK_(cant remember what)|| / action.RIGHT_CLICK_(cant remember what) to the if statements.
     
    #2 Hitchens, Sep 20, 2016
    Last edited: Sep 20, 2016
Thread Status:
Please be aware that this thread is more than 30 days old. Do not post unless the topic can still be discussed. Read more...