Plugin Help! How To Make A Particle/Effect Do Damage

Discussion in 'Plugin Development' started by mkezar, Jul 23, 2014.

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

    mkezar

    Hi. I was playing CrazyCraft when i was playing with 1 of the tools. Then i realized, you know what... i can do this in a minecraft plugin! Then i came to thinking... HOW ON EARTH WOULOD I ACCOMPLISH THIS! So basically, you right click a tool (playerInteractEvent) and it spawns a particle wave in your location, if any entitys are in the particles path, it does damage. I took a video if you can imagine what im typing:



    So now... How would i accomplish this?

    OHQCraft Laxer21117

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

    LCastr0

    Check the entities nearby to the effect location and do the damage
     
  3. Offline

    mkezar

    LCastr0 wouldnt that do damage to ALL of the entities nearby?
     
  4. Offline

    EcMiner

    Well first you need to check if the entity is a LivingEntity as the normal Entity class doesn't have the damage(...) method, and after that you can check if the EntityType of the entity is a certain type, so if you only want to damage zombies for instance you could check if the entity is a zombie and if he is, damage him

    Btw this is definately possible, I have done this for the server I work for as well ( )
     
  5. Offline

    artish1

    mkezar
    Use scheduler's if you want the effect to be exactly like so... unless you want to play the effects all at the same time.

    All this is, is checking if a player right clicked, if so get list of blocks with player.getLineOfSight(null, maxDistance (in this case it would be 2-4 blocks max distance) );


    After that iterate the locations of those blocks, and play your effect. And also check if a player.getLocation.getX() is equal to block.getLocation().getX(), same with the Y, and Z. And if so hurt him.
     
  6. Offline

    CPUSKILLZ

    sup LCastr0! -- Alex from Globe
     
  7. Offline

    mkezar

    artish1 Genius! I appreciate all of your help. I'm in the car at the moment but as soon as I get access to a computer, this will be my goal! THANKS!

    I will probably need some guidance as I'm writing this lol. Thanks :)

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

    LCastr0

    No, just check all the entities in the chunk of the particle, then you get the location of the entity, then, finally, you calculate if the distance between the particle's X and Z are < than 0.5 (could be in the middle of the block), but Y could be < than 2
     
    EcMiner likes this.
  9. Offline

    mkezar

    LCastr0 would i have to get a particle packet/lib to get the block breaking particle?
     
  10. Offline

    LCastr0

    You don't need it, but it's better to use the ParticleLib
     
  11. Offline

    mkezar

    LCastr0 by you saying it's better to use particle lib, do you mean it's easier than doing it from scratch?
     
  12. Offline

    LCastr0

    Yes, very, very easier
     
  13. Offline

    mkezar

    LCastr0 ok thanks. Unfortunately, my laptop just died. I will need to save the programming for later. All I got what the playerinteract event.
     
  14. Offline

    ResultStatic

    mkezar use the BlockIterator class to get the locations or player.getLineOfSight(null, intdistance); spawn the particles in that line and damage any players in that line. it returns a line of blocks from the players head to the distance specified
     
  15. Offline

    fireblast709

    +1 for non depreciated methods. Might be worth noting that it uses a
    Code:
    while(hasNext())
    {
        block = next();
    }
    structure instead of returning a List directly

    LCastr0 I doubt that. Just play Effect.STEP_SOUND using Player#playEffect(Location,Effect,T) ( mkezar where the T is the data, in your case it should be a Material)
     
  16. Offline

    ResultStatic

    fireblast709 maybe he wants to live dangerously and use a deprecated method.
     
  17. Offline

    fireblast709

    ResultStatic There are always people living on the edge ;)
     
  18. Offline

    mkezar

    Alright, thanks! I believe the laptop is charged! Time to write! Wish me luck!!! :)

    Ok!! Heres the finishing code! All i dont have is the particle effect

    Code:java
    1. package plugins.mkezar;
    2.  
    3. import java.util.List;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Damageable;
    7. import org.bukkit.entity.Entity;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Smash extends JavaPlugin implements Listener {
    16. @Override
    17. public void onEnable() {
    18. this.getServer().getPluginManager().registerEvents(this, this);
    19. }
    20. @EventHandler
    21. public void onSwordClick(PlayerInteractEvent event) {
    22. Player player = event.getPlayer();
    23. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    24. if(player.getItemInHand().getType()== Material.DIAMOND_SPADE){
    25. List <Entity> entities = player.getNearbyEntities(4,0,0);
    26. for(Entity e : entities){
    27. if(e.getType().isAlive()) {
    28. Damageable d = (Damageable) e;
    29. d.setHealth(-5);
    30.  
    31.  
    32. }
    33. }
    34. }
    35. }
    36. }
    37. }


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

    DusRonald

    Code:java
    1.  
    2. package plugins.mkezar;
    3.  
    4. import java.util.List;
    5.  
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Damageable;
    8. import org.bukkit.entity.Entity;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Smash extends JavaPlugin implements Listener {
    17. @Override
    18. public void onEnable() {
    19. this.getServer().getPluginManager().registerEvents(this, this);
    20. }
    21. @EventHandler
    22. public void onSwordClick(PlayerInteractEvent event) {
    23. Player player = event.getPlayer();
    24. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    25. if(player.getItemInHand().getType()== Material.DIAMOND_SPADE){
    26. List <Entity> entities = player.getNearbyEntities(4,0,0);
    27. for(Entity e : entities){
    28. if(e.getType().isAlive()) {
    29. Damageable d = (Damageable) e;
    30. d.setHealth(-5);
    31.  
    32.  
    33. }
    34. }
    35. }
    36. }
    37. }
    38. }
    39.  


    Point 1: Use
    Code:java
    1. d.setHealth(d.getHealth() - 5);


    Point 2: Use (Make sure you have a FireworkEffectPlayer added. Click here for topic.)
    Code:java
    1. FireworkEffectPlayer.playFirework(d.getWorld(), d.getLocation, new FireworkEffect().builder().trail(false).with(FireworkEffectType.BURST).withColor(Color.WHITE).withFade(Color.YELLOW).flicker(true).build());
     
  20. Offline

    mkezar

    fireblast709 so would it be like this to spawn the effect?
    Code:java
    1. player.getWorld().playEffect(player.getLocation(), Effect.STEP_SOUND, Material.GRASS);


    in order for me to spawn the particle at the block in front of my location would i have to do, player.getLocation(++) or player.getLocation(+1)

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

    fireblast709

  22. Offline

    LCastr0

    That would make it play the block break sound too...
     
  23. Offline

    fireblast709

    LCastr0 it would do that regardless iirc
     
  24. Offline

    LCastr0

    The particle lib has a version thar doesn't play the sound, I think. Only the effect.
     
  25. Offline

    mkezar

    LCastr0 so will the code posted above,

    will it spawn the grass block breaking effect? heres the code

    player.getWorld().playEffect(player.getLocation(), Effect.STEP_SOUND, Material.GRASS);
     
  26. Offline

    LCastr0

    It will, but with sound... But yes it will. Though in your code will only spawn in the player location, and not do a "path" in front of the player
     
  27. Offline

    mkezar

    LCastr0 im starting small :p what fireblast709 said about the BlockIterator, is that what it i would use to make the path?
     
  28. Offline

    LCastr0

    Yes
     
  29. Offline

    fireblast709

    LCastr0 possible, they do seem to use different packets. Then again, it would be typical Mojang to have two packets where one doesn't have sound
     
  30. Offline

    mkezar

    fireblast709 how would I use the block iterator?

    i got this massive error and i dont know why

    [17:43:50 ERROR]: Could not pass event PlayerInteractEvent to Smash v1.0 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:233) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:203) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:618) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:180) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.ServerConnection.c(ServerConnection.java:81) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:713) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:283) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:576) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:482) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] Caused by: java.lang.IllegalArgumentException: Health must be between 0 and 20.0 at org.bukkit.craftbukkit.v1_7_R3.entity.CraftLivingEntity.setHealth(CraftLivingEntity.java:81) ~[spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at org.bukkit.craftbukkit.v1_7_R3.entity.CraftLivingEntity.setHealth(CraftLivingEntity.java:495) ~[spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] at plugins.mkezar.Smash.onSwordClick(Smash.java:32) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot-1.7.9-R0.1-SNAPSHOT.jar:git-Spigot-1450] ... 16 more


    heres the code:

    Code:java
    1. mport java.util.List;
    2.  
    3.  
    4. import org.bukkit.Effect;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Damageable;
    7. import org.bukkit.entity.Entity;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Smash extends JavaPlugin implements Listener {
    16. @Override
    17. public void onEnable() {
    18. this.getServer().getPluginManager().registerEvents(this, this);
    19. }
    20. @EventHandler
    21. public void onSwordClick(PlayerInteractEvent event) {
    22. Player player = event.getPlayer();
    23. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    24. if(player.getItemInHand().getType()== Material.DIAMOND_SWORD){
    25. List <Entity> entities = player.getNearbyEntities(4,0,0);
    26. for(Entity e : entities) {
    27. System.out.println("THis IS WOrking");
    28. if(e.getType().isAlive()) {
    29. Damageable d = (Damageable) e;
    30. d.setHealth(-5);
    31. player.getWorld().playEffect(player.getLocation(), Effect.STEP_SOUND, Material.GRASS);
    32.  
    33.  
    34. }
    35. }
    36. }
    37. }
    38. }
    39. }


    i did some troubleshooting by putting System.out.println() on the if and for statements. All i know is that after the for loop, it wont print the line.

    people that might be able to help:
    LCastr0
    fireblast709
    OHQCraft
    Laxer21117

    Plz Help :(

    EcMiner any ideas why im getting that huge error?

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

Share This Page