Displaying Heart Particles

Discussion in 'Plugin Development' started by Samthelord1, Aug 24, 2013.

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

    Samthelord1

    Hey, I am trying to play heart particle effects to someone on command, I tried using the wolf heart effect but it didn't work, I'm not too good with Packets, but I might think that they're the only option, but I'm not that sure how to use them, all help is appreciated.
    PHP:
        public boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args) {
            
    Player p = (Playersender;
            if(
    commandLabel.equalsIgnoreCase("love")) {
                if(
    args.length == 0) {
                   
                    for(
    Player on Bukkit.getServer().getOnlinePlayers())
                    if(
    args[0].equals(on)) {
                        
    p.getServer().getPlayer(args[0]);
                        
    Player arg p.getServer().getPlayer(args[0]);
                    
    //code  
     
  2. Offline

    chasechocolate

  3. Offline

    Plo124

    Note: args.length starts at 1, not 0, so use args.length == 1, not 0 :)
     
  4. Offline

    chasechocolate

    Also, do this for getting a player based on a String argument:
    Code:java
    1. Player target = Bukkit.getPlayer(args[0]);
    2.  
    3. if(target != null){
    4. //Display hearts
    5. } else {
    6. //No player found
    7. }
     
  5. Offline

    Samthelord1

    chasechocolate I added the class but I'm not quite sure how I would use it, I thought I could have done something like player.playEffect(ParticleEffect.HEART);
     
  6. Offline

    chasechocolate

    Samthelord1 which class? With the latter, you would use ParticleEffect.HEART.sendToPlayer(...).
     
  7. Offline

    Samthelord1

    chasechocolate with ParticleEffects.HEART.sendToPlayer(target); it says i need player, location, float, float, float, float, int
     
  8. Offline

    chasechocolate

    Samthelord1 assuming you are using eclipse, hit CTRL + space after "sendToPlayer". It will show you what you need to add as arguments.
     
  9. Offline

    Samthelord1

    chasechocolate using netbeans, but it says to use

    ParticleEffects.HEART.sendToPlayer(target, null, offsetX, offsetY, offsetZ, speed, count);
    which throws error on all besides target

    EDIT: should this work? :

    PHP:
    Player target Bukkit.getPlayer(args[0]);
                      if(
    target != null){
                          try {
                              
    ParticleEffects.HEART.sendToPlayer(targettarget.getLocation(), 010510);
                          } catch (
    Exception ex) {
                              
    Logger.getLogger(Main.class.getName()).log(Level.SEVEREnullex);
                          }
     
  10. Offline

    chasechocolate

    Samthelord1 it should as far as I can see. Try it out.
     
  11. Offline

    Samthelord1

    chasechocolate ok, I'm all prepped to love myself lol

    chasechocolate not working, but when doing /love I get a error on line 33 which is

    Player target = Bukkit.getPlayer(args[0]);

    should i change it to
    Player target = Bukkit.getServer.getPlayer(args[0]);

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

    chasechocolate

  13. Offline

    Samthelord1

    chasechocolate eh can't remember,

    EDIT: 05:08:18 [INFO] samthelord1 issued server command: /love
    05:08:18 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'love' in plugin emotation v1.0.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:191)
    at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
    at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:954)
    at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:872)
    at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:829)
    at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
    at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
    at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
    at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    at me.samthelord1.Emotes.Main.onCommand(Main.java:33)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ... 15 more
     
  14. Offline

    xTrollxDudex

  15. Offline

    Samthelord1

  16. Offline

    chasechocolate

    Samthelord1 you need to check the length of the args before accessing an object at an index that couldn't exist:
    Code:java
    1. if(args.length == 1){
    2. //Do stuff
    3. }
     
  17. Offline

    Samthelord1

    chasechocolate wouldn't I be checking if args length is 0?

    chasechocolate i have

    if(commandLabel.equalsIgnoreCase("love")) {
    if(args.length == 0) {


    Player target = Bukkit.getPlayer(args[0]);
    if(target != null){
    try {
    ParticleEffects.HEART.sendToPlayer(target, target.getLocation(), 0, 1, 0, 5, 10);
    } catch (Exception ex) {
    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

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

    chasechocolate

    Samthelord1 change if(args.length == 0) to if(args.length == 1). Arrays start at 0, not 1.
     
  19. Offline

    Samthelord1

    chasechocolate I always thought args started at 0 o.0

    chasechocolate this doesn't work, it says an internal error in chat nothing in console.
    PHP:
    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */
    package me.samthelord1.Emotes;
     
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    /**
    *
    * @author Sam
    */
    public class Main extends JavaPlugin {
       
        public 
    void onEnable() {
     
        }
       
        public 
    boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args) {
            
    Player p = (Playersender;
            if(
    commandLabel.equalsIgnoreCase("love")) {
                if(
    args.length == 1) {
                   
         
                      
    Player target Bukkit.getPlayer(args[1]);
                      if(
    target != null){
                          try {
                              
    ParticleEffects.HEART.sendToPlayer(targettarget.getLocation(), 010510);
                          } catch (
    Exception ex) {
                              
    Logger.getLogger(Main.class.getName()).log(Level.SEVEREnullex);
                          }
    } else {
    p.sendMessage(ChatColor.DARK_PURPLE args[1] + ChatColor.GOLD "is not online!");
    }
     
                       
                 
                   
                   
                }
            }
            return 
    true;
           
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  20. Offline

    chasechocolate

    Samthelord1 args.length returns the size of the array (e.g. 1 object stored = 1, 2 objects stored = 2, etc.). However, if you want to access the first object stored in the array, you would use args[0] as the stored objects start at 0, but the size starts at 1. tl;dr change args[1] to args[0].
     
  21. Offline

    Samthelord1

    chasechocolate confused confused xD I think I might understand though.

    chasechocolate its working :D however, it like plays the hearts on the players body and they go up in a line, any idea how I would change it?

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

    ampayne2

    Play with the x y z offsets and speed :p
     
Thread Status:
Not open for further replies.

Share This Page