Create knockback and particle effect on right click with stick.

Discussion in 'Plugin Development' started by Geekhellmc, Aug 5, 2014.

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

    Geekhellmc

    I am trying to make an airbending wand using a stick. When a player right clicks a stick, it knockbacks all players that are 3 blocks away z,y,x and create a 2 sec gray particle effect. Can anyone help me with it? Here is my code:
    Code:java
    1. public enum Wand {
    2.  
    3. FIRE("Fire Blast", ChatColor.RED, new WandRunnable(){
    4. public void run(PlayerInteractEvent e){
    5. Fireball fb = e.getPlayer().launchProjectile(Fireball.class);
    6. fb.setIsIncendiary(false);
    7. fb.setYield(0F);
    8. }
    9. }),
    10.  
    11. AIR("Air Blast", ChatColor.GRAY, new WandRunnable() {
    12. public void run(PlayerInteractEvent e) {
    13. for (Entity en : e.getPlayer().getNearbyEntities(3, 3, 3)) {
    14. if (en instanceof Player) {
    15. }
    16. }
    17. }
    18. }),
    19. NATURE("NaturePoison", ChatColor.DARK_GREEN, new WandRunnable() {
    20. public void run(PlayerInteractEvent e) {
    21. for (Entity en : e.getPlayer().getNearbyEntities(3, 3, 3)) {
    22. if (en instanceof Player) {
    23. ((Player) en).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20 * 5, 1));
    24. MessageManager.getInstance().msg((Player) en, MessageTypie.INFO, ChatColor.DARK_PURPLE + "You have been poisoned by " + e.getPlayer().getName() + "!");
    25. MessageManager.getInstance().msg(e.getPlayer(), MessageTypie.INFO, ChatColor.DARK_PURPLE + "You have poisoned " + ((Player) en).getName() + "!");
    26. }
    27. }
    28. }
    29. });


    EDIT: I already made a code that will give the player the wand(stick) with the element.

    Ok I figured out on creating the knockback and here is code if anyone needs it
    Code:java
    1. for (Entity entity : e.getPlayer().getNearbyEntities(5D, 5D, 5D)){
    2. entity.setVelocity(new Vector(0.0, 1.5, 0.0));

    But I still need help in creating the smoke effect

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

    candyfloss20

    Geekhellmc, Spawn Smoke effect at the entity(s) location + the Velocity, No?
     
  3. Offline

    Geekhellmc

    candyfloss20 exactly, It's some sort of
    p.getLocation, Effect.SMOKE, 2;
    But I don't know how to do it exactly.
     
  4. Offline

    hankered

    Kinda irrelevant, but that's pretty cool you're making a TLA/TLOK plugin. Send me a link when you finish it?
     
  5. Offline

    Geekhellmc

    hankered The idea came from these kids tv series but it's more like a Super Smash Benders plugin :D
     
  6. Offline

    unon1100

    Use vector subtraction (Vector v = loc1.toVector().subtract(loc2.toVector()); ) to create a vector that is from the player to the target. From there, if you want to make it so that it is a specific length, do v.normalize() to make the vector length = 1, and then you can multiply the vector to make it a specific length that isn't 1.
     
  7. Offline

    Geekhellmc

    unon1100 well that looks something thx. And you are from MCPZ XD!
     
  8. Offline

    CraftBang

    Geekhellmc I was looking at your code and I was interested about it :p.
    Do you mind if you share the class WandRunnable, I want to look what you did and how it works :p.

    For the effects I used a plugin called EffectLib.
     
  9. Offline

    Geekhellmc

    CraftBang I know EffectLib but the effect I need is already implemented in Bukkit not some sort of citcular fire effect.
    And I am happy to share all the Wand class.
    Code:
    package me.Geekhellmc.SSB;
     
    import java.util.Arrays;
     
    import me.Geekhellmc.SSB.MessageManager.MessageTypie;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Fireball;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.util.Vector;
     
    public enum Wand {
     
        FIRE("Fire Blast", ChatColor.RED, new WandRunnable(){
            public void run(PlayerInteractEvent e){
                Fireball fb = e.getPlayer().launchProjectile(Fireball.class);
                fb.setIsIncendiary(false);
                fb.setYield(0F);
            }
        }),
     
        AIR("Air Blast", ChatColor.GRAY, new WandRunnable() {
            public void run(PlayerInteractEvent e) {
                for (Entity en : e.getPlayer().getNearbyEntities(3, 3, 3)) {
                    if (en instanceof Player) {
                        for (Entity entity : e.getPlayer().getNearbyEntities(5D, 5D, 5D)){
                            entity.setVelocity(new Vector(0.0, 1.5, 0.0));
                        }
                    }
                }
            }
        }),
        NATURE("Nature Poison", ChatColor.DARK_GREEN, new WandRunnable() {
            public void run(PlayerInteractEvent e) {
                for (Entity en : e.getPlayer().getNearbyEntities(3, 3, 3)) {
                    if (en instanceof Player) {
                        ((Player) en).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20 * 5, 1));
                        MessageManager.getInstance().msg((Player) en, MessageTypie.INFO, ChatColor.DARK_PURPLE + "You have been poisoned by " + e.getPlayer().getName() + "!");
                        MessageManager.getInstance().msg(e.getPlayer(), MessageTypie.INFO, ChatColor.DARK_PURPLE + "You have poisoned " + ((Player) en).getName() + "!");
                    }
                }
            }
        });
     
        private String name;
        private ChatColor color;
        private WandRunnable run;
     
        Wand(String name, ChatColor color, WandRunnable run){
            this.name = name;
            this.color = color;
            this.run = run;
        }
     
        public String getName(){
            return name;
        }
     
        public ChatColor getColor(){
            return color;
        }
     
        public String getFullName(){
            return color + name;
        }
     
        public void run(PlayerInteractEvent e){
            run.run(e);
        }
     
        public ItemStack createItemStack(){
            ItemStack i = new ItemStack(Material.STICK, 1);
     
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(getFullName());
            im.setLore(Arrays.asList("A magic wand!"));
     
            i.setItemMeta(im);
     
            return i;
        }
     
        public static Wand forName(String name){
            for (Wand w : Wand.values()){
                if (w.getName().equalsIgnoreCase(name)) return w;
            }
     
            return null;
        }
     
    }
     
    abstract class WandRunnable {public abstract void run(PlayerInteractEvent e); }
    I will take another check on EffectLiv
     
  10. Offline

    candyfloss20

    Geekhellmc i sent you my skype in a pm i can help you more there, (if you still need help)
    unon1100 kind of did a good job tell you how to do it
     
  11. Offline

    Geekhellmc

  12. Offline

    PogoStick29

    Feel free to merge this with MagicBattle if you want to contribute the wands you made.
     
    CraftBang likes this.
  13. Offline

    Geekhellmc

    PogoStick29 MagicBattle? I will take a look at that. Maybe it could help.
     
  14. Offline

    PogoStick29

    This code looks exactly like the Wand enum in MagicBattle.
     
    HeavyMine13 likes this.
  15. Offline

    HeavyMine13

  16. Offline

    Geekhellmc

    PogoStick29 I found this wand class code ina thread I don't remember. I swear I didn't copy from your codes if I didn't know!
     
  17. Offline

    PogoStick29

    I'm not mad and I never wanted to insinuate that. I was just letting you know that if you wanted to contribute it, it would be appreciated. I assumed that you took the initial code from MagicBattle which is why I said that.
     
  18. Offline

    Geekhellmc

Thread Status:
Not open for further replies.

Share This Page