Setting UUID from Player Name [Command]

Discussion in 'Plugin Development' started by Epicballzy, Aug 14, 2014.

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

    Epicballzy

    Hey guys, I've bee stumped on 1 little part. I've been trying to make a command where you set the player as a premium player. (/setpremium <playername>) But I'm stuck on being able to get the players uuid from the name you type in.

    The player has a time limit (as a trial) and when that time is up, the player cant player no more. Unless, you type a command (/setpremium), and that will have them be able to play and do whatever.

    I'd like to be able to have this work with buycraft or enjin when donating... There would be a command for it which is /setpremium {Name} but it has to work when the player is also offline. Everything is set into a config.

    I'm just stuck at the OfflinePlayer part. Heres my code:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("setpremium")) {
    2. if(args.length == 0) {
    3. MessageManager.getInstance().msg(player, ChatColor.RED + "/setpremium <player>");
    4. return true;
    5. } else if(args.length == 1) {
    6. String playerName = args[0];
    7.  
    8. Methods.setPremium(/*WhatName?*/);//This is the part I need help with
    9.  
    10. MessageManager.getInstance().msg(player, ChatColor.GREEN + "Set player " + ChatColor.RED + playerName + ChatColor.GREEN + " to be Premium!");
    11. }
    12. }


    This is my "setPremium" method:
    Code:java
    1. public static void setPremium(OfflinePlayer pName) {
    2. Files.users.set(pName.getUniqueId() + ".premium", true);
    3. stopTimer();
    4. Files.saveUsers();
    5. }


    All help is appreciated!
    If you need any other info, just let me know and I'll provide as much as I can!
     
  2. Offline

    Epicballzy

  3. Offline

    thijs_a

    Code:java
    1. OfflinePlayer offline = Bukkit.getOfflinePlayer(name)
     
  4. Epicballzy Oh right okay. You'll want to look at the getOfflinePlayer() method - that can take a player's name
     
  5. Offline

    Epicballzy

    thijs_a AdamQpzm
    When I do:
    Code:java
    1. public static void setPremium(OfflinePlayer pName) {
    2. Files.users.set(pName.getUniqueId() + ".premium", true);
    3. Files.saveUsers();
    4. }

    Command:
    Code:java
    1. String playerName = args[0];
    2. @SuppressWarnings("deprecation")
    3. OfflinePlayer oPlayer = Bukkit.getPlayer(playerName);
    4. Methods.setPremium(oPlayer);

    I get a nullpointer on lines 45 and 32.
    45: Files.users.set(pName.getUniqueId() + ".premium", true);
    32: Methods.setPremium(oPlayer);
    I think its because its not finding the players name I'm typing in? I really have no clue
     
  6. Offline

    thijs_a

    When im on my computer im gonna look at it, but at line 32 you must use Bukkit.Getofflineplayer(playerName)
     
  7. Offline

    Dragonphase

    Epicballzy

    Two things:

    1. You're invoking all of this code in a static context. Does it need to be static? Why not create one instance of the class somewhere and invoke the methods in a non-static context through the instance.
    2. Either your OfflinePlayer (pName and oPlayer) or users is null.
     
Thread Status:
Not open for further replies.

Share This Page