Solved Launch a block with a vector

Discussion in 'Plugin Development' started by TheNewTao, Dec 8, 2015.

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


    I have been thinking of how do launch a web block with a vector so it looks something like this:

    At 0:40

    I tried to google but I didn't really find much. I was thinking of using LibsDisguises to launch an entity with the vector and disguising it as a block, but I don't know if that is possible with LibsDisguises. I would greatly appreciate any suggestions.

    Thank you
  2. Offline


    You just spawn in a falling block (and set the type to spiderweb) then you can set the velocity (fallingBlock.setVelocity).
  3. Offline


  4. @TheNewTao any block type can be a falling block.
  5. Offline


    @TheNewTao Here, I had written this a long time ago. You may have this :)
    It throws a cobweb item and when it hits the ground it gets rid of the item and puts down a cobweb.

    public class Trapper extends JavaPlugin implements Listener {
        Trapper plugin;
        //Getting cobweb on ground scheduler
        int getCobwebOnGround;
        //Where cooldowns are stored
        public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
        //Cooldown times. Could easily be replaced with a double for decimal numbers
        int cooldownTime = 10;
            public Trapper getPlugin(){
                //Instantiating plugin
                return plugin;
            public void onEnable(){
                getServer().getPluginManager().registerEvents(this, this);
            public void onDisable(){
                //Prevents memory leaks on disable
            //Make sure the player cannot PLACE cobwebs
            public void onBlockPlaceAttempt(BlockPlaceEvent e){
                Player p = e.getPlayer();
                if(e.getBlockPlaced() == new ItemStack(Material.WEB)){
                    //Well, if the placed block isn't a cobweb, then you shouldn't have to do anything!
            //If a trapped player can just break out then what's the point of this kit?
            //A player would most likely be too busy getting beat up / defending themselves to escape, anyways
            public void onBlockBreakAttempt(BlockBreakEvent e){
                if(e.getBlock() == new ItemStack(Material.WEB)){
            private void onPlayerInteract(final PlayerInteractEvent e) {
            Player p = e.getPlayer();
                    //If any action besides left click a block or air occurs it will be ignored
                    if (!(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)) return;
                    //If any item is used besides cobweb, it will be ignored in this case
                    if (!(e.getItem().getType() == Material.WEB)) return;
                    //Cooldown times. Registers after the first interaction fires
                   /**if(cooldowns.containsKey(p.getName())) {
                        //We divide the cooldown in milliseconds to seconds
                        //long secondsLeft = ((cooldowns.get(p.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
                        //If the cooldown is still busy
                        //if(secondsLeft>0) {
                        //p.sendMessage("You can't do this for another "+ secondsLeft +" seconds!");
                        // No cooldown found or cooldown has expired, save new cooldown
                        //cooldowns.put(p.getName(), System.currentTimeMillis());
                        World world = p.getWorld();
                    //Spawning a cobweb dropped item
                    final Item cobweb = world.dropItem(p.getLocation().add(new Vector(0, 2, 0)), new ItemStack(Material.WEB, 1));
                    //Setting pickup delay to 400 ticks, or about 25 seconds. Item is killed before player can pick it up
                  //Throwing the item by multiplying where the player is looking by two, then setting velocity above
                    //Getting amount of item
                    int amount = p.getItemInHand().getAmount();
                    //Deplete an item with each throw
                      //Make sure the item actually gets removed from the inventory when there's one left and it is thrown
                    getCobwebOnGround = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
                        public void run() {
                            //Seeing if the cobweb's Y velocity is more than 0.1, less than -0.1, or 0. Basically, if it's on a block
                            if(cobweb.getVelocity().getY() >= 0.1 || cobweb.getVelocity().getY() <= -0.1 || cobweb.getVelocity().getY() == 0){
                                //Making sure the block is any material BUT air or grass, since it will just replace those
                                if(cobweb.getLocation().getBlock().getRelative(0,-1,0).getType() != Material.AIR ||
                                    cobweb.getLocation().getBlock().getRelative(0,-1,0).getType() == Material.GRASS){
                                    //Creating the cobweb at the item's location
                                    //Remove the item once it strikes a surface
                                    //Stop this task
                }, 0, 1);
  6. Offline



    I appreciate your code, but you are using an ItemStack. I want to launch an actual cobweb block. I'll try spawning a falling block and see if it works.
Thread Status:
Not open for further replies.

Share This Page