.

Discussion in 'Plugin Development' started by elementalgodz11, Oct 27, 2013.

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

    elementalgodz11

  2. Offline

    xMakerx

    I can do the Water Bucket exception, the sound effects, and the smoke.

    Code:java
    1. import org.bukkit.Effect;
    2. import org.bukkit.Material;
    3. import org.bukkit.Sound;
    4.  
    5. @EventHandler
    6. public void onItemSpawn(ItemSpawnEvent e) {
    7. ItemStack item = e.getEntity().getItemStack();
    8.  
    9. if(!item.getType().equals(Material.WATER_BUCKET)) {
    10. e.getEntity().remove();
    11. e.getEntity().getWorld().playEffect(e.getLocation(), Effect.SMOKE, 0);
    12. e.getEntity().getWorld().playSound(e.getLocation(), Sound.CLICK, 10F, 10F);
    13. }
    14. }


    Choose a sound and an effect, I thought the smoke and the click sound made sense. I believe the 10F's are the volume and pitch. I tried this code out and didn't get any errors. I hope it works for you too.

    EDIT: I didn't see your edit until I refreshed change this:
    e.getEntity().getWorld().playSound(e.getLocation(), Sound.CLICK, 10F, 10F);

    To:
    e.getEntity().getWorld().playSound(e.getLocation(), Sound.CHICKEN_EGG_POP, 10F, 10F);

    You want it so you can watch Water Buckets disappear and other entitites disappear if you attempt to drop them?

    Is this what you want? The code sees if the item is a water bucket, if it is it'll play the cool effects you want. If not, it'll just vanish without any effects.

    Code:java
    1. @EventHandler
    2. public void onItemSpawn(ItemSpawnEvent e) {
    3. ItemStack item = e.getEntity().getItemStack();
    4. if(item.getType().equals(Material.WATER_BUCKET)) {
    5. e.getEntity().remove();
    6. e.getEntity().getWorld().playEffect(e.getLocation(), Effect.SMOKE, 0);
    7. e.getEntity().getWorld().playSound(e.getLocation(), Sound.CHICKEN_EGG_POP, 10F, 10F);
    8. }else {
    9. e.getEntity().remove();
    10. }
    11. }


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

    Garris0n

    I think he wants a 5 second delay on the water bucket, but as far as that code goes, I would've done the smoke effects if waterbucket and used the same .remove() code (just less code to write).
     
  4. Offline

    xMakerx

    elementalgodz11

    I am currently at work, so I will update the code when I can get home.
     
  5. Offline

    sgavster

    elementalgodz11
    Code:java
    1. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    2. public void run(){
    3. //code
    4. }
    5. }, 100);

    ^^ put that under the
    Code:java
    1. if(item.getType().equals(Material.WATER_BUCKET)) {
     
  6. Offline

    Ad237

    elementalgodz11 Is this what you want? This even allows you to add more items other than the water bucket by putting them inside the {} separated by a comma.

    Note: You need to pass an instance of your main class for this work. If you don't know how to do that then just put this in your main class and change "plugin" to "this".

    Code:java
    1. Material[] allowed = {Material.WATER_BUCKET};
    2.  
    3. @EventHandler
    4. public void onItemSpawn(ItemSpawnEvent event) {
    5. final Entity e = event.getEntity();
    6. ItemStack i = event.getEntity().getItemStack();
    7. for(Material materials : allowed) {
    8. if(materials == i.getType()) {
    9. new BukkitRunnable() {
    10. @Override
    11. public void run() {
    12. e.remove();
    13. e.getWorld().playEffect(e.getLocation(), Effect.SMOKE, 0);
    14. e.getWorld().playSound(e.getLocation(), Sound.CHICKEN_EGG_POP, 10F, 10F);
    15. }
    16. }.runTaskLater(plugin, 100L);
    17. return;
    18. }
    19. }
    20. e.remove();
    21. e.getWorld().playEffect(e.getLocation(), Effect.SMOKE, 0);
    22. e.getWorld().playSound(e.getLocation(), Sound.CHICKEN_EGG_POP, 10F, 10F);
    23. }


    elementalgodz11 I told you in my post. This is where you pass an instance of your main class. If you don't know how to do that then just put the code in your main class and change plugin to this.

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

    sgavster

  8. Offline

    Ad237

    elementalgodz11 Does the smoke appear? Are you registering your events in the main class?

    In your onEnable() you need to put
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
     
  9. Offline

    xTrollxDudex

    elementalgodz11
    Please post the entire class

    elementalgodz11
    Do you only want water buckets removed or something? Cause you're removing any it that is dropped...

    elementalgodz11
    elementalgodz11
    The class doesn't extend JavaPlugin, or you need a plugin variable. I think the latter is the best idea for this situation

    elementalgodz11
    Is that the only class that extends JavaPlugin? Does it implement Listener also? Is it registered?

    elementalgodz11
    Is it the only class that extends JavaPlugin? Is it registered? Are there any other classes?

    elementalgodz11
    There should only be one class that extends JavaPlugin, it should be the class that registers all your events.
    Use this to have a plugin variable: https://gist.github.com/AgentTroll/6382979

    elementalgodz11
    Use "plugin", if you used the constructor example is linked

    elementalgodz11
    Lol. Put 10-12 inside the run()

    elementalgodz11
    elementalgodz11
    Did you use the link I posted, edited the code?

    Please just show the entire class, it would make it much easier

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page