Seismic wave

Discussion in 'Spigot Plugin Development' started by Simagdo, May 15, 2016.

  1. Im recently playing a lot of Warlords on Hypixel and I want to know, how you can create a seismic wave or a ground slam.
    this is, what i tryed so far:
    Code (Text):

    @EventHandler
    public void flyingEarth(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        ArrayList<Block> blockList = new ArrayList();

        if(player.getItemInHand().getType() == Material.DIAMOND_AXE) {
            try {
                if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                    FallingBlock block = player.getWorld().spawnFallingBlock(player.getLocation().add(0, 5, 0), event.getClickedBlock().getType(), (byte) 0);

                }
            } catch (Exception e) {
                System.err.println("Error: " + e);
            }
        }

    }
     
     
  2. Whats the problem?
     
  3. You are only doing it for one block. Try looping through all the surrounding blocks too. Also why is that arraylist there?
     
  4. And edit the falling block entity using nms for this ^^
     
    • Funny Funny x 1
  5. What?
     
    • Like Like x 1
    • Agree Agree x 1
  6. If you want that block didn't spawn you edit le live and die method into the nms entity
     
  7. I never used nms entity, do you know a good tutorial to learn this?
     
  8. NUU NMS, I'll post a solution for this sometime tonight,
    I have to head off to work.
     
  9. Dude what? This is possible with a little math, no NMS needed at all. Don't touch NMS if it isn't needed.
     
    • Agree Agree x 2
  10. Here's what I put together:

    Code (Text):
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin{
        private Wave wave;
       
        @Override
        public void onEnable(){
           
        }
       
        @Override
        public void onDisable(){
           
        }
       
        public boolean onCommand(CommandSender se, Command c, String lbl, String[] args){
            if(se instanceof Player){
                Player p = ((Player)se);
                if(lbl.equalsIgnoreCase("Wave")){
                    if(wave != null){
                        wave.stop();
                    }
                    wave = new Wave(p.getLocation());
                } else {
                   
                }
            }
            return true;
        }
    }


    package me.virusbrandon.wave;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.FallingBlock;
    import org.bukkit.util.Vector;

    public class Wave{
       
        Runnable timer = new Runnable() {
            @SuppressWarnings("deprecation")
            public void run() {
                for(Location loc:getCircle(l,rad,(rad*((int)(Math.PI*2))))){
                    FallingBlock fb = loc.getWorld().spawnFallingBlock(loc, loc.getBlock().getType(),loc.getBlock().getData());
                    fb.setVelocity(new Vector(0,.3,0));
                    loc.getBlock().setType(Material.AIR);
                }
                rad++;
                rad=(((rad%20)==0)?1:rad);
            }  
        };
       
        private Location l;
        private int rad = 1;
        private int id;
       
        public Wave(Location l){
            this.l = l;
            start(2);
        }
       
        /**
         * Return A List Of Locations That
         * Make Up A Circle Using A Provided
         * Center, Radius, And Desired Points.
         *
         * @param center
         * @param radius
         * @param amount
         * @return
         */
        private ArrayList<Location> getCircle(Location center, double radius, int amount){
            World world = center.getWorld();
            double increment = ((2 * Math.PI) / amount);
            ArrayList<Location> locations = new ArrayList<Location>();
            for(int i = 0;i < amount; i++){
                 double angle = i * increment;
                 double x = center.getX() + (radius * Math.cos(angle));
                 double z = center.getZ() + (radius * Math.sin(angle));
                 locations.add(new Location(world, x, center.getY(), z));
            }
            return locations;
        }
       
        /**
         * Starts The Timer
         *
         * @param delay
         *
         *
         */
        private void start(int delay){
            id = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(Main.class), timer, delay, delay);
        }

        /**
         * Stops The Timer
         *
         *
         */
        protected void stop(){
            Bukkit.getScheduler().cancelTask(id);
        }
    }
     

    CREDIT GOES TO FINNBON ABOVE FOR THE getCircle Function!!!! :D
     
    #11 VirusBrandon, May 15, 2016
    Last edited: May 16, 2016
    • Like Like x 1
  11. rip my eyes someone safe me
     
    • Agree Agree x 2
    • Winner Winner x 1
  12. Use the code tags please .-.
     
    • Like Like x 1
    • Agree Agree x 1
  13. ma bad
     
  14. Hand successfully held. ;)
    The code is now readable...
     
    • Friendly Friendly x 1