Help with Developing a plugin

Discussion in 'Plugin Development' started by nixcluster, Apr 1, 2017.

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

    nixcluster

    Hey guys
    So i just recently picked up developing and writing plugins, because i want to make a plugin that i haven't really seen done before.

    I figured the best way for me to learn was just to start trying to figure out exactly how to make it.
    I've done a little bit of research but im having a little trouble getting my feet off the ground.

    The plugin i essentially want to create, Spawns a block in front of a dispenser on a red stone trigger, and sends it flying through the air along a calculated path. if the block gets hit with an arrow, The block despawns and a message is sent to the server saying "you hit the target". If its missed, nothing happens and it just hits the ground

    I want to be able to place a dispenser, and use the face of that dispenser as the starting point of my spawned block.
    Then i want to be able to type a command that is the landing point for my block, and then calculate a route between the two with a formula.
    They all need to be unique as well, so i can have multiple dispensers with multiple paths.

    So far..what i have figured out i need to do to make this actually happen is this.

    I need to create a listener to listen for my red stone trigger, but i dont know how to make it so its a unique red stone trigger, as in its triggered off one specific switch or button or WE in mine craft, and not every one in the world.

    I sort of have an idea on how to get the face of the dispenser, but i dont know how to actually spawn a block or entity.

    and i know i need to use vectors..but i know nothing about them.

    Im not asking anyone to write this plugin for me..that kind of defeats the purpose. And im not asking you to hold my hand through the entire process. I guess what im after is a "Generalisation" of how someone would make this plugin...if that makes sense

    I hope im not sounding like a total idiot or asking in the wrong place here. and thank you in advance
     
  2. Offline

    Zombie_Striker

    @nixcluster
    First, make sure you have this link bookmarked. This will make learning bukkit soo much easier.
    https://hub.spigotmc.org/javadocs/bukkit/
    This contains all the classes, events, and methods that bukkit has.

    Here are the steps for achieving what you want:
    1. Listen for BlockRedstoneEvent. This is called whenever a block changed its restone state.
    2. If the block is equal to your dispenser
    3. Cast the block to a dispenser. Locate which direction it is facing, and spawn a new FallingSand entiy using World#spawnFallingBlock
    4. Create a new Vector. This is the direction the block will travel. Vectors use the same coordinate system as Location, so set the XYZ values to be equal to the direction you want it to go.
    5. Set the falling block's velocity to be equal to this new vector.
    6. Now, in another event, listen for ProjectileSpawnEvent.
    7. If the projectile is an arrow, and the person shooting the arrow is a Player, create a Repeating Task.
    8. Inside the task, every tick, loop through all the nearby entities within 1 block of the arrow (using Entity#getNearbyEntities() )
    9. If one of the entities is equal to the falling sand block, announce that it has been hit and cancel the task.
    10. Else, if the block isOnGround, then cancel the event and announce that the projectile missed the target.
     
    shauwk likes this.
  3. Offline

    Side8StarLite

  4. Offline

    nixcluster

    Wow that was fast! Thank you very much for the quicky reply.
    I've started making progress already :) Ill let you guys know what i end up wityh

    Sorry real quick. Step three confuses me a little.
    i decided to go with a BlockDispenseEvent to make life easier, and im just not sure how i get from that stage..to getting the block info of the dispenser

    Okies. So i've come across an error
    I've gotten up to spawning and putting in the vector. And this is what i have so far

    Location newpos = new Location(world, x, y, z);
    FallingBlock block = e.getBlock().getWorld().spawnFallingBlock(newpos, Material.SAND,(byte) 0);
    block.setVelocity(new Vector(vx, vy, vz));

    What im finding that happens. is the block wiill spawn..and then instantly dissapear. And i have no idea why

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

    Zombie_Striker

    @nixcluster
    1. What info do you need?
    2. Try creating a delayed task. After a couple of seconds, use SandBlock#getLocation to figure out where the sand block was last.
     
  6. Offline

    nixcluster

    Sorry about that. i wasnt very clear im sure.

    Hopefully What i post here will help you guys understand a little better.
    https://pastebin.com/jLzihpQH (my code)


    There's my code...which i know isnt probably very good..first thing i've ever tried to make. and a video showing whats happening.
    Hope that helps :)

    Edit:
     
    Last edited: Apr 2, 2017
  7. No use Thread.sleep()!!!!!

    It sleeps the ENTIRE server!!

    Use
    new BukkitRunnable(
    @Overide
    Public void run{
    Code here
    }
    ).runTaskLater(plugin, milliseconds*20)
     
  8. Offline

    nixcluster

    Yeah l learnt quickly that one. Im testing on a little private sever so we good.

    \Edit: Still no luck. I got no idea why my block is acting this way
     
    Last edited: Apr 3, 2017
Thread Status:
Not open for further replies.

Share This Page