[TUTORIAL] Entity Ejection

Discussion in 'Resources' started by FatAussieFatBoy, Nov 16, 2013.

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

    FatAussieFatBoy

    Introdution :
    Hey Everyone, My name is Nicholas/FatAussieFatBoy and I am going to showing you how to make Entities Fly out of your Body. Sounds weird and Difficult but is quite Simple and Easy.

    What I mean by "Make ENTITES Fly out of your Body" :
    Have you every played on the CTF Servers? Then you've probably seen the Blocks of Wool that drop from the Players Head when he/she has the Flag. That is what I will be teaching you all how to do Today.

    STEP 1 [Using Command & EventHandler] :
    First of all we will need to start the Code with a onEnable() & onDisable(). Once done we will need to set our onCommand or EventHandler depending on how you would like the Code to run.

    Once done your Code should look Simular to this.

    Code:java
    1. public class Main extends JavaPlugin implements Listener {
    2.  
    3. PluginManager pm = Bukkit.getServer().getPluginManager();
    4.  
    5. @Override
    6. public void onEnable() {
    7. this.getServer().getLogger().info("Plugin Enabled!");
    8. pm.registerEvents(this, this);
    9. }
    10.  
    11. //Use this if you wish to use onCommand
    12. @Override
    13. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    14. Player p = (Player) sender;
    15. if(cmd.getName().equalsIgnoreCase("Command")) {
    16.  
    17. }
    18. return false;
    19. }
    20.  
    21. //Use this if you wish to use a EventHandler
    22. @EventHandler
    23. public void onPlayerAction(PlayerMoveEvent e) { //NOTE: That PlayerMoveEvent is only a Example and that the onPlayerAction is not limited to only the Move Event
    24.  
    25. }
    26.  
    27. @Override
    28. public void onDisable() {
    29. this.getServer().getLogger().info("Plugin Disabled!");
    30. }
    31.  
    32. }
    33.  


    STEP 2 [Setting the Dropped Item] :
    Next We will need to set the Item that will be Dropped from the Player and how long the Intervals inbetween will be. NOTE: that we will be using a Diamond as the dropped Item, and that we will also be setting the Task Timer to 20 Ticks/1 Second, so the Event runs every 20 Ticks/1 Second.

    Code:java
    1. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { //Place this in either the EventHandler or onCommand after checking any Variables such as Permissions or if a ArrayList contains a Players Name
    2. @Override
    3.  
    4. public void run() {
    5.  
    6. Location loc = p.getEyeLocation();
    7.  
    8. ItemStack item = new ItemStack(Material.DIAMOND);
    9.  
    10. Item drops = loc.getWorld().dropItem(loc, item);
    11.  
    12. Item drops2 = loc.getWorld().dropItem(loc, item);
    13.  
    14. Item drops3 = loc.getWorld().dropItem(loc, item);
    15.  
    16. drops.setPickupDelay(100);
    17.  
    18. drops2.setPickupDelay(100);
    19.  
    20. drops3.setPickupDelay(100);
    21.  
    22. DropDespawnEvent(drops, drops2, drops3); //This piece of code is used in Step 3
    23.  
    24. }
    25. }, 20L, 10L);
    26.  


    STEP 3 [Setting the Drops Despawn time] :
    Now we set the Despawn Timer for the Drops. This is the Easiest and Fastest part of the Code. NOTE: That the "DropDespawnEvent" in the Syntax above is this piece of Code, so please do not worry If you are getting a Error with that section of Code.

    Code:java
    1. public void DropDespawnEvent(final Item drops, final Item drops2, final Item drops3) {
    2.  
    3. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    4.  
    5. @Override
    6.  
    7. public void run() {
    8.  
    9. drops.remove();
    10.  
    11. drops2.remove();
    12.  
    13. drops3.remove();
    14.  
    15. }
    16.  
    17. }, 10L, 10L);
    18.  
    19. }



    We are done!
    I hope that this Tutorial has helped.

    (NOTE : Sorry, The 2nd and 3rd Syntax Codes have A huge gap between each line of Code, no Code is missing just that the Syntax may be Hard to read, Sorry about the weird glitch/problem)

    Here is a Download of a Plugin using this Feature :
    http://forums.bukkit.org/attachments/crybaby-zip.15869/


    - FatAussieFatBoy <3
     

    Attached Files:

  2. Offline

    Ultimate_n00b

  3. Offline

    FatAussieFatBoy

    Technically yes but the DropDespawnEvent, will make the Items Despawn before they can be picked-up by any Players.

    In short the Code will make the Items come out of the Players head and despawn after 1/2 a Second, so by the Time 100Ticks/5 Seconds is up the Item would have already despawned, making it so players cannot Pick-up the Dropped Item.
     
  4. Offline

    BungeeTheCookie

    FatAussieFatBoy
    Nice tutorial. You should call it "[TUTORIAL] Entity Ejection (Make Blocks Fly Out of Your Body)
     
  5. FatAussieFatBoy You can do this yourself. In the upper right corner of your post there should be a "thread tools", click that.
     
  6. Offline

    FatAussieFatBoy

    CaptainBern, Cheers for that I didn't realize that was even there :3
     
    Garris0n and CaptainBern like this.
  7. Offline

    Garris0n

    For the record, I'm pretty sure this isn't what "Entity Ejection" implies...
     
  8. Offline

    xTrollxDudex

  9. Offline

    Garris0n

    ಠ_ಠ
     
  10. Offline

    FatAussieFatBoy

    Garris0n
    xTrollxDudex
    Why would Entity Ejection not sound right for this Tutorial?
    An Entity is literally everything that is not a Block. So PlayerDrops(this), Mobs, Players, etc... are Entities, so This posts name does imply "Entity Ejection" as it uses PlayerDrops and Ejects them from the Players Location.
    - FatAussieFatBoy

    Bump!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  11. Offline

    BungeeTheCookie

    xTrollxDudex
    69 the magical number. Brings life from ***** and ******* if that is what you are thinking from entity ejection....
    FatAussieFatBoy
    Please don't bump a resource, but this was really useful. I will use this in my future plugins :D
     
    FatAussieFatBoy likes this.
  12. Offline

    FatAussieFatBoy

    BungeeTheCookie
    Sorry, I was seeing if it worked or not :p
    Kind of new to the Forums.
     
  13. Offline

    BungeeTheCookie

    That's alright. Everyone was new once :D
     
  14. Offline

    Garris0n

    That would be entity eja-nevermind...
    Anyway, I was thinking of entity.eject() ಠ_ಠ
     
    FatAussieFatBoy likes this.
  15. Offline

    xTrollxDudex

    Not sure if I should continue...

    Ehheh. Love how this is getting so offtopic.
     
    DarkBladee12 and FatAussieFatBoy like this.
  16. Offline

    BungeeTheCookie

    xTrollxDudex
    So do I. It all started because of one little sentence.
     
  17. Offline

    CrazyGuy3000

    omg... so many uses o_o
     
  18. Offline

    PieMan456

    FatAussieFatBoy
    Wait I am confused. Do you make the second scheduler inside the first one?
     
  19. Offline

    Conarnar

    Actually, you don't need a second scheduler. Instead, you can do setTicksLived(6000 - duration); since items despawn after 5 minutes.
     
    Garris0n likes this.
  20. Offline

    FatAussieFatBoy

    Conarnar
    I have tried this method before, and for me at least it doesn't work...

    PieMan456
    A Bukkit Scheduler usually cannot be inside of another so you need to create a public void (like I have) and set the Bukkit Scheduler there, and if you are still having trouble understanding then please do not feel shy to ask me Questions about any problems you get or possible Methods.

    - Cheers
    FatAussieFatBoy
     
  21. Offline

    PieMan456

Thread Status:
Not open for further replies.

Share This Page