timers and fake items

Discussion in 'Plugin Development' started by Niv200, Jul 25, 2013.

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

    Niv200

    hello!
    im trying to make plugin that will let you shoot item (with custom name so its wont be every item..)
    and make the item explode with effect after X ticks... this is the code that i have at the moment :
    Code:java
    1.  
    2. @EventHandler
    3. public void onShoot(EntityShootBowEvent e) {
    4. if (((e.getEntity() instanceof Player)) &&
    5. (e.getBow().hasItemMeta()) &&
    6. (e.getBow().getItemMeta().getDisplayName().equals(ChatColor.RESET + "Spray Painter"))){
    7. e.setCancelled(true);
    8. Player player = (Player)e.getEntity();
    9. Location loc = player.getLocation();
    10. Location eyeloc = player.getEyeLocation();
    11. Entity pro = e.getProjectile();
    12. Vector v = pro.getVelocity();
    13. World world = player.getWorld();
    14. Entity item = world.dropItemNaturally(eyeloc, new ItemStack(pop));
    15. item.setVelocity(v.multiply(0.2));
    16. player.getWorld().playSound(loc, Sound.STEP_WOOL, 10.0F, 0.8F);
    17. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    18. public void run() {
    19. }
    20.  
    21. }, 40L);
    22. }
    23. }
    24. }
    25.  

    now, for the questions! :D
    1. how do i make the item play effect after X ticks
    2. how do i make the item despawn after X ticks
    3. how can i disable the item pickup event? (only for item named pop...)
    i tried with player pick item event but it didnt work... :/
    i have set all the "pop" and Spray Painter items alredy :)
    thx ! :)

    bump? i didnt found any rule that say about bumping time...
    how much time i need per bump? XD

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

    Rocoty

    Niv200 Preferably 24 hours I'd say. People will find your thread even on the 2nd and 3rd pages.
     
  3. Offline

    Niv200

    ok ty ;)
     
  4. Offline

    Niv200

    bump! (idk what time is it .. compare to my time its 22:26... idk what about bukkit)
     
  5. Offline

    nrs23

    bump, Id quite like an answer to this aswell
     
  6. Offline

    TryB4

    nrs23
    that necro
    Niv200, nrs23
    here you go:

    Code:java
    1. @EventHandler
    2. public void entityShootBow(EntityShootBowEvent e){
    3. if(e.getEntity() instanceof Player){
    4. Player p = (Player)e.getEntity();
    5. if(p.getItemInHand() != null){
    6. if(p.getItemInHand().getItemMeta() != null){
    7. if(p.getItemInHand().getItemMeta().getDisplayName() != null){
    8. if(p.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("whatever")){
    9. final Item i = p.getWorld().dropItem(p.getLocation().add(0,2,0), p.getItemInHand());//spawn it a bit higher than the arrow
    10. i.setPickupDelay(9999);//disable pickup
    11. i.setVelocity(e.getProjectile().getVelocity());
    12. e.setProjectile(i);
    13. new BukkitRunnable() {
    14. int c = 30; //or how many seconds you'd like to wait
    15. public void run() {
    16. if(c != 0){
    17. c--;
    18. }else{
    19. //do whatever you want to do after x seconds has passed.
    20. i.getWorld().playSound(i.getLocation(), Sound.STEP_WOOL, 1, 1);
    21. i.remove(); // despawns it
    22. this.cancel();
    23. }
    24. }
    25. }.runTaskTimer(this, 9, 9);
    26. }
    27. }
    28. }
    29. }
    30. }
    31. }
     
  7. Offline

    nrs23

Thread Status:
Not open for further replies.

Share This Page