public static void JoinSpecGame(Player p, String game, String map) not working

Discussion in 'Plugin Development' started by ProSl3nderMan, Nov 3, 2015.

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

    ProSl3nderMan

    Hey guys, when ever I do a variable from another class using args[] it doesn't work. So what I'm doing is putting in a variable from another class using a public called JoinSpecGame that picks up the variables and uses them to get in a config. The problem is, I don't think the variables are actually working because in the first if command (that uses string game and string map), it results in null. Here's my code:

    Public JoinSpecMap code:
    Code:
    public static void JoinSpecMap(Player p, String game, String map) {
            if (Main.plugin.getMS().getInt("games." + map + game + ".playeramount") < 4) {
                if (Main.plugin.getMS().getString("games." + map  + game + ".settings.private").equalsIgnoreCase("true")) {
                    p.sendMessage(ChatColor.RED + "This is a private game! Invitation is required.");
                } else {
                    p.setGameMode(GameMode.ADVENTURE);
                    List<String> players = Main.plugin.getMS().getStringList("games." + map  + game + ".players");
                    players.add(p.getName());
                    Main.plugin.getMS().set("games." + map  + game + ".players", players);
                    Main.plugin.srMS();
                    Main.plugin.getPlayers().set("players." + p.getPlayer().getUniqueId() + ".game", game);
                    Main.plugin.srPlayers();
                    int x = Main.plugin.getMS().getInt("games." + map  + game + ".lobbyspawn.x");
                    int y = Main.plugin.getMS().getInt("games." + map  + game + ".lobbyspawn.y");
                    int z = Main.plugin.getMS().getInt("games." + map  + game + ".lobbyspawn.z");
                    p.teleport(new Location(Bukkit.getWorld(Main.plugin.getMaps().getString("maps.town.world")), x, y, z));
                    p.sendMessage(ChatColor.RED + "You have just joined game " + ChatColor.DARK_RED + game
                            + ChatColor.RED + "! Please wait patiently until three people have ready up.");
                }
            } else {
                p.sendMessage(ChatColor.RED + "The game " + ChatColor.DARK_RED + game + ChatColor.RED
                        + " already has 4 players! Please pick another game or do /boz join town random.");
            }
        }
    Command boolean using the public code:
    Code:
    if (args[0].equalsIgnoreCase("join")) {
                if (!Main.plugin.getPlayers().getString("players." + p.getPlayer().getUniqueId() + ".game").equalsIgnoreCase("lobby")) {
                    p.sendMessage(ChatColor.RED + "You are already in a game! Do /boz leave to leave the game.");
                    return false;
                }
                if (args[1].equalsIgnoreCase("town")) {
                    List<String> ogmlist = Main.plugin.getTM().getStringList("games.opengames");
                    if (args[2].equalsIgnoreCase("random")) {
                        MapManager.JoinRandMap(p, args[1]);
                    } else if (ogmlist.contains(args[2])) {
                        MapManager.JoinSpecMap(p, args[2], args[1]);
                    } else if (!ogmlist.contains(args[2])) {
                        p.sendMessage(ChatColor.RED + "The game " + ChatColor.DARK_RED + args[2] + ChatColor.RED
                                + " does not exist or is not online at the moment. Please pick another game or "
                                + "do /boz join town random." );
                    }
                    ogmlist.clear();
                }
                return true;
            }
    So I guess what I'm asking is, what did I do wrong? Am I using the public in the wrong way?
     
  2. What variables are returning null? View my signature
     
  3. Offline

    ProSl3nderMan

    It's on line 2 of joinspecmap, in the if command. The variables map and game are the same so therefore it doesn't matter which one.
     
  4. Offline

    Scimiguy

    @ProSl3nderMan
    That doesn't really clear anything up at all.

    Are you getting an error?
    If you can't solve it yourself, post us the error.
    And because you neglected to give us your full class, you'll have to provide that too
     
  5. Offline

    Gamesareme

    @ProSl3nderMan Have you added a '.' between the map and game? If not then the code will be getting this.

    Map is "test" and game is "hello"
    "testhello"

    What you want is this

    test:
    hello

    You do this simply by using this code.

    Code:
    if (Main.plugin.getMS().getInt("games." + map + "." + game + ".playeramount") < 4) {
    You will need to add the '.' to all your code.
     
  6. Offline

    mcdorli

    Thats not a command, it's a statement. It matters when you try to explain things to others. And I don't know what you mean under "command boolean".
     
  7. Offline

    DoggyCode™

    Try using setters and getters for the args method instead of making it static.
     
  8. Offline

    mcdorli

    @ProSl3nderMan static should be only used for final variables or constructor like methods.
     
Thread Status:
Not open for further replies.

Share This Page