-1

I have an issue with

Cannot make a static reference to the non-static method spawnParticle(blabla)

This is what I call my code..

    public class Particle implements CommandExecutor
    {

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg) {

        if (sender instanceof Player)
        {
            Particle particle = new Particle();
            Player player = (Player) sender;
            double x = ((Player) sender).getLocation().getX();
            double y = ((Player) sender).getLocation().getY();
            double z = ((Player) sender).getLocation().getZ();

            World.spawnParticle(org.bukkit.Particle.TOTEM, x, y, z, 1, 0, 0, 0);

        }
        return false;
    }


}

I already read a lot about non static static issue solving and know what that issue mean, but I really dont know how to solve it here. The Problem extended to that world is an interface and cant be inhanced. A fix is in the comments Thanks for help

qBASHp
  • 21
  • 5

1 Answers1

1

The method is a instance method, wich means you have to instance the object with new and World is an interface, so you can't instance it, you have to instance a class that implements this interface, the player has the world

(don't forget to import the class WorldEvent)

if (sender instanceof Player)
        {
            Particle particle = new Particle();
            Player player = (Player) sender;
            double x = ((Player) sender).getLocation().getX();
            double y = ((Player) sender).getLocation().getY();
            double z = ((Player) sender).getLocation().getZ();
            World w = sender.getWorld();
            w.spawnParticle(org.bukkit.Particle.TOTEM, x, y, z, 1, 0, 0, 0);

        }
developer_hatch
  • 15,898
  • 3
  • 42
  • 75
  • Thanks for the help so far, but it responses that then: 1. Cannot instantiate the type World 2. Line breakpoint:Particle [line: 23] - onCommand(CommandSender, Command, String, String[]) – qBASHp May 14 '17 at 00:14
  • Can you put the World class code also? Is the World class abstract? I mean like public abstract class World... etc? – developer_hatch May 14 '17 at 00:17
  • Well the world class is an imported thing from bukkit Libraries, so unfortantly im not really sure about that - import org.bukkit.World – qBASHp May 14 '17 at 00:22
  • Ok, I updated the answer, you must read the [bukkit web page](https://jd.bukkit.org/org/bukkit/class-use/World.html#org.bukkit.event.world), it says that World is an Interface, and Interface can be instantiated. Instead, you use the class WorlldEvent. – developer_hatch May 14 '17 at 00:27
  • Ok that fixed that issue, but brought me back to "Cannot make a static reference to the non-static method getWorld() from the type WorldEvent" – qBASHp May 14 '17 at 00:38
  • The player has the world! – developer_hatch May 14 '17 at 00:53