Solved Spigot: Cannot find symbol (class)

Discussion in 'Spigot Plugin Help' started by MrNobso, Jan 25, 2020.

  1. Hello there,
    Lately, I have been trying to make a plugin and after two days of coding I recompiled my plugin (i use intelliJ btw) and got the below errors:
    Code (Text):
    Error:(14, 12) java: cannot find symbol
      symbol:   class Region
      location: class com.mrnobso.landclaiming.LandClaiming
    Code (Text):
    Error:(15, 12) java: cannot find symbol
      symbol:   class SLAPI
      location: class com.mrnobso.landclaiming.LandClaiming
    Error:(15, 12) java: cannot find symbol
      symbol:   class SLAPI
      location: class com.mrnobso.landclaiming.LandClaiming
    Error:(21, 22) java: cannot find symbol
      symbol:   class SLAPI
      location: class com.mrnobso.landclaiming.LandClaiming
    Error:(40, 25) java: cannot find symbol
      symbol:   class Region
      location: class com.mrnobso.landclaiming.LandClaiming
    Error:(40, 40) java: cannot find symbol
      symbol:   class Region
      location: class com.mrnobso.landclaiming.LandClaiming
    (Quite a lot of errors)

    I searched for an answer both on google and in the Forums but I did not have any luck
    So can anybody tell me how could I solve these errors
    Here is the code from all my classes
    LandClaiming.java
    Code (Text):
    package com.mrnobso.landclaiming;

    import org.bukkit.Bukkit;
    import org.bukkit.Chunk;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    import com.mrnobso.landclaiming.*;

    public class LandClaiming extends JavaPlugin {

        public Region[] loadedRegions;
        public SLAPI config;

        @Override
        public void onEnable() {
            Bukkit.getLogger().info("LandClaiming Plugin Loaded!");
            loadedRegions = SLAPI.loadRegions( Bukkit.getServer().getWorld("world"));
            config = new SLAPI(this);
            config.init();

        }

        @Override
        public void onDisable() {
            config.save();
        }

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

            if (label.equalsIgnoreCase("claim")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    final Chunk chunk = player.getLocation().getChunk();
                    if (args.length > 2) {

                        if (args[0].equalsIgnoreCase("add") && (!args[1].equalsIgnoreCase("chunk")) && (!args[1].equalsIgnoreCase("player"))) {
                            Region r = new Region(chunk, args[1], player );
                            config.saveRegion(r);
                        }
                    } else {
                        player.sendMessage("Usage: /claim add <RegionName>");
                    }

                }
                return true;
            }
            return false;
        }


    }
     
    SLAPI.java

    Code (Text):
    package com.mrnobso.landclaiming;

    import org.bukkit.Bukkit;
    import org.bukkit.Chunk;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import com.mrnobso.landclaiming.*;
    import org.jetbrains.annotations.NotNull;

    import java.util.UUID;


    public class SLAPI {

        private static LandClaiming instance;

        public SLAPI(LandClaiming plugin) {
            this.instance = plugin;
        }

        public void setPlayerRegion(Player p, String name) {
            instance.getConfig().set(p.getDisplayName(), name);
        }

        public void init() {
            instance.saveConfig();
        }

        public static void saveRegion(Region r) {
            int lastIndex = instance.getConfig().getInt("index");
            Chunk[] chunks = r.listChunks();
            Player[] players = r.listPlayers();
            //instance.getConfig().set("regions."+(lastIndex+1)+"name",r.NAME);
            for (int i=0;i < chunks.length-1; i++) {
                for (Chunk c : chunks) {
                    String index = Integer.toString(i);
                    instance.getConfig().set(r.NAME + ".chunk." + index + ".x", c.getX());
                    instance.getConfig().set(r.NAME + ".chunk." + index + ".z", c.getZ());//loop for x and y and z
                    int lastChunks = instance.getConfig().getInt(r.NAME+"chunks");
                    instance.getConfig().set(r.NAME+"chunks", lastChunks+1 );
                }
            }
            for (int j=0;j < players.length-1; j++) {
                for (Player p : players) {
                    String index = Integer.toString(j);
                    instance.getConfig().set(r.NAME + ".player." + index , p.getUniqueId());
                    int lastChunks = instance.getConfig().getInt(r.NAME+"players");
                    instance.getConfig().set(r.NAME+"players", lastChunks+1 );
                }
            }

            instance.getConfig().set("index", lastIndex+1);
        }


        public static void addChunk(Chunk chunk, Region r) {
            int index = instance.getConfig().getInt(r.NAME+"chunks");
            instance.getConfig().set(r.NAME + ".chunk." + index + ".x", chunk.getX());
            instance.getConfig().set(r.NAME + ".chunk." + index + ".z", chunk.getZ());//loop for x and y and z
            instance.getConfig().set(r.NAME+"chunks", index+1 );
        }
        public static void removeChunk(Chunk chunk, Region r) {
            int index = instance.getConfig().getInt(r.NAME+"chunks");
            instance.getConfig().set(r.NAME + ".chunk." + index, null);
            instance.getConfig().set(r.NAME+"chunks", index-1 );
        }

        public static void addPlayer(@NotNull Player p, @NotNull Region r) {
            int index = instance.getConfig().getInt(r.NAME+"players");
            instance.getConfig().set(r.NAME + ".player." + index , p.getUniqueId());
            instance.getConfig().set(r.NAME+"players", index+1 );
        };

        public static void save() {
            instance.saveConfig();
        }

        public static String path(String p) {
            return instance.getConfig().getString(p);
        }

        @NotNull
        public static Region[] loadRegions(World w) {
            int index = instance.getConfig().getInt("index");
            String regionName;
            Region[] configRegions = new Region[0];
            for (int i=0; i<(index-1);i++) { //i+1 for every region
                regionName = instance.getConfig().getString("regions."+i+"name");
                int chunksNum = instance.getConfig().getInt(regionName+".chunks");
                Chunk[] chunksInRegion = new Chunk[0];
                Player[] playersInRegion = new Player[0];
                for (int j=0; j<(chunksNum-1);j++) {  //j+1 for every chunk > region
                    int x = instance.getConfig().getInt(regionName+".chunk."+j+".x");
                    int z = instance.getConfig().getInt(regionName+".chunk."+j+".z");
                    chunksInRegion[j] = w.getChunkAt(x, z);
                }
                int playersNum = instance.getConfig().getInt(regionName+".players");
                for (int k = 0; k < (playersNum-1); k++ ) {  // k+1 for every player > region
                    playersInRegion[k] = Bukkit.getPlayer(UUID.fromString(instance.getConfig().getString(regionName+".player."+index)));
                }

                configRegions[i] = new Region(chunksInRegion, regionName, playersInRegion);
            }
            return configRegions;
        }

    }

    // index: 1
    // regions:
    //   0:
    //     name: region1
    //
    //
    // region1:
    //  // name: region1
        // chunk:
        //  0:
        //    x:1
        //    z:1
        // player:
        //  0: MrNobso
    //     chunks: 1
    //     players:1
    //
     
    Region.java

    Code (Text):
    package com.mrnobso.landclaiming;

    import org.bukkit.Chunk;
    import org.bukkit.entity.Player;
    import com.mrnobso.landclaiming.*;
    import java.util.HashSet;
    import java.util.Set;

    public class Region {

        public Set<Chunk> region = new HashSet<Chunk>();
        public Set<Player> players = new HashSet<Player>();
        public String NAME;
        public Chunk SPAWN;


        public Region(Chunk chunk, String name, Player player) {
            region.add(chunk);
            players.add(player);
            this.NAME = name;
        }

        public Region(Chunk[] chunks, String name, Player[] ps) {
            for (Chunk c : chunks) {
                region.add(c);
            }
            for (Player p : ps) {
                players.add(p);
            }
            this.NAME = name;
        }

        public Chunk[] listChunks() {
            Chunk[] chunks = new Chunk[0];
            int i = 0;
            for(Chunk c : region) {
                chunks[i] = c;
                i++;
            }
            return chunks;
        }

        public Player[] listPlayers() {
            Player[] playersList = new Player[0];
            int i = 0;
            for(Player p : players) {
                playersList[i] = p;
                i++;
            }
            return playersList;
        }




    }
     
    (You may find that there may be more practical ways to do some things but I am by no means an experienced programmer)
    Thanks
    -MrNobso
     
  2. [Problem solved]
    It was just a very very silly mistake!!!
    The problem was that before I recompiled my project I did not actually build my project (again)