-1

I was creating a plugin to MineCraft which needs a list of UUID and I figured to do it this way

public class Freeze extends JavaPlugin implements CommandExecutor {
    public static List<UUID> toggleList = new ArrayList<UUID>();
}

However when I'm using the list in another class it says cannot resolve symbol. Here is the class for using the list not creating it

import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;

public class Toggle implements Listener {
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent evt) {
        Player player = evt.getPlayer();
        if (Freeze.togglelist.contains(player.getUniqueId())){
            Location back = new Location(evt.getFrom().getWorld(), evt.getFrom().getX(), evt.getFrom().getY(), evt.getFrom().getZ());
            evt.getPlayer().teleport(back);
        }
    }
}

how can i get it to recognize it as the list?

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
  • 1
    You are not importing the class `Freeze` – Md Johirul Islam Feb 14 '19 at 19:27
  • Do a static import for the togglelist – Sekar Feb 14 '19 at 20:19
  • Please read error messages. You do not get simply "cannot resolve symbol", you get a short message explaining what exactly was not resolved (or this is clear from context, i.e. the underlined token). If, as in this case, `Freeze` was not found, the obvious solution is to import it. – Salem Feb 19 '19 at 20:06

2 Answers2

0

Static import

Add a static import statement to your Toggle class.

import static my.package.Freeze ;

Or change your line of code to use the fully-qualified name.

if ( my.package.Freeze.togglelist.contains( player.getUniqueId() ) ) {

And if working with retrieved UUID objects, you will need to import that class as well.

import java.util.List ;
import java.util.UUID ;
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
0

No Static Import Required

The reason why your IDE is barking an error is because of a typo. You define toggleList in Freeze, but attempt to reference it with Freeze.togglelist (note that "list" is spelled with a lowercase 'l').

If your classes are in the same package, no further import directives are required. However, if Freeze is in a different package, a regular import (i.e., non-static) of Freeze is required, which is something your IDE should be able to resolve easily.

Frelling
  • 3,287
  • 24
  • 27