Solved Currency & ChatManger Help

Discussion in 'Plugin Development' started by ItsJorden, Apr 20, 2015.

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

    Koobaczech

    Well, cast p to a Player. Then..mm..you can try getConfig().getString() or p.getUniqueId().toString or getConfig().getInt

    Do .toString()

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  2. Offline

    ItsJorden

    Last edited: Apr 30, 2015
  3. Offline

    Msrules123

    @ItsJorden Then make the UUID a string... #toString()
     
  4. Offline

    ItsJorden

    @Msrules123
    It still refuses to accept an UUID as a string.
    Code:
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
                p = e.getPlayer();
                if (p.getUniqueId().toString(p.getUniqueId())==null) { //This is where the problem lies
                    getConfig().set(p.getUniqueId()+".Coins", 0);
                    //money.put(p.getUniqueId(), 0);
                    saveConfig();
                    p.sendMessage("All your moneys are belong to server");
                }
        }
    Nevermind, might as well abandon this project.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  5. Offline

    Msrules123

  6. Offline

    ItsJorden

    @Msrules123 I use that advice wisely :p

    This is what I currently have in my Main.java:
    Code:
    package me.ItsJorden.ChatManager;
    import java.util.HashMap;
    import java.util.UUID;
    import java.util.Map.Entry;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.MemorySection;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Chat extends JavaPlugin implements Listener {
        private Player p;
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
        public void onDisable() {
            saveConfig();
        }
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
                p = e.getPlayer();
                if (p.getUniqueId().toString(p.getUniqueId())==null) {
                    getConfig().set(p.getUniqueId()+".Coins", 0);
                    //money.put(p.getUniqueId(), 0);
                    saveConfig();
                    p.sendMessage("All your moneys are belong to server");
                }
        }
    
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("coins")) {
                if (args.length==3) {
                    try {
                      Integer.parseInt(args[2]);
                      } catch(NumberFormatException e) {
                            sender.sendMessage("" + ChatColor.GOLD + ChatColor.BOLD + "CC ->" + ChatColor.YELLOW + "Please use a number");
                            return false;
                      }       
                    Player target = getServer().getPlayer(args[1]);
                    if (target!=null&&target.isOnline()) {
                        if (args[0].equalsIgnoreCase("add")) {
                            if (Integer.parseInt(args[2])<0) {
                              sender.sendMessage("" + ChatColor.GOLD + ChatColor.BOLD + "CC -> " + ChatColor.YELLOW + "Please use a non-negative number");
                                  return true;
                              }
                              getConfig().set(target.getUniqueId()+".Coins", getConfig().getInt(target.getUniqueId()+".Coins")+Integer.parseInt(args[2]));
                              target.sendMessage("" + ChatColor.GOLD + ChatColor.BOLD + "CC ->" + ChatColor.YELLOW + "You have recieved " + ChatColor.RED + Integer.parseInt(args[2]) + ChatColor.YELLOW + " coins!");
                              saveConfig();
                          }       
        
                          else if (args[0].equalsIgnoreCase("remove")) {
                              if (getConfig().getInt(target.getUniqueId()+".Coins")-Integer.parseInt(args[2])<=0) {
                                  getConfig().set(target.getUniqueId()+".Coins", 0);
                                  target.sendMessage("" + ChatColor.GOLD + ChatColor.BOLD + "CC ->" + ChatColor.RED + "You have lost all your coins");
                                  saveConfig();
                                  return true;
                              }
                              else
                              getConfig().set(target.getUniqueId()+".Coins", getConfig().getInt(target.getUniqueId()+".Coins")-Integer.parseInt(args[2]));
                              target.sendMessage("" + ChatColor.GOLD + ChatColor.BOLD + "CC ->" + ChatColor.YELLOW + "You have lost "+ ChatColor.RED +Integer.parseInt(args[2])+ ChatColor.YELLOW + " coins");
                              saveConfig();
                          }
                
        
                          else if (args[0].equalsIgnoreCase("set")) {
                              if (Integer.parseInt(args[2])<0) {
                                  sender.sendMessage("" + ChatColor.GOLD + ChatColor.BOLD + "CC ->" + ChatColor.RED + "Please use a non-negative number");
                                  return true;
                              }
                              getConfig().set(target.getUniqueId().toString()+".Coins", Integer.parseInt(args[2]));
                              target.sendMessage("" + ChatColor.GOLD + ChatColor.BOLD + "CC ->" + " Your coin balance has been set to "+Integer.parseInt(args[2]));
                              saveConfig();
                          } 
                    }
                  }
                  else
                      sender.sendMessage("" + ChatColor.YELLOW + ChatColor.BOLD + "Chat Coins");
                      sender.sendMessage("" + ChatColor.AQUA + ChatColor.BOLD + ChatColor.STRIKETHROUGH + "------------------");
                      sender.sendMessage("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Main Command:" + ChatColor.GOLD + " /coins");
                      sender.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "Args:" + ChatColor.BLUE + " add|remove|set" + ChatColor.GRAY + " [PlayerName] [Amount]");
                  return true;
              }
        
            return false;            
        }
       
        @EventHandler
        public void onChat(AsyncPlayerChatEvent event) {
            // p is not identified as a player D:
            if (event.getPlayer().hasPermission("chat.normal")) {
                event.setFormat("" + ChatColor.RED + "» " + ChatColor.YELLOW + getConfig().getInt(p.getUniqueId()+".Coins") + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "%s" + ChatColor.AQUA + " » " + ChatColor.WHITE + "%s");
            }
            if (event.getPlayer().hasPermission("chat.donor")) {
                event.setFormat("" + ChatColor.RED + "» " + ChatColor.YELLOW + getConfig().getInt(p.getUniqueId()+".Coins") + ChatColor.DARK_GRAY + " | " + ChatColor.AQUA + "Donor" + ChatColor.DARK_GRAY + " | " + ChatColor.DARK_AQUA + "%s" + ChatColor.AQUA + " » " + ChatColor.WHITE + "%s");
            }
            if (event.getPlayer().hasPermission("chat.mod")) {
                event.setFormat("" + ChatColor.RED + "» " + ChatColor.YELLOW + getConfig().getInt(p.getUniqueId()+".Coins") + ChatColor.DARK_GRAY + " | " + ChatColor.GREEN + "Mod" + ChatColor.DARK_GRAY + " | " + ChatColor.DARK_GREEN + "%s" + ChatColor.AQUA + " » " + ChatColor.WHITE + "%s");
            }
            if (event.getPlayer().hasPermission("chat.admin")) {
                event.setFormat("" + ChatColor.RED + "» " + ChatColor.YELLOW + getConfig().getInt(p.getUniqueId()+".Coins") + ChatColor.DARK_GRAY + " | " + ChatColor.DARK_RED + "Admin" + ChatColor.DARK_GRAY + " | " + ChatColor.RED + "%s" + ChatColor.AQUA + " » " + ChatColor.WHITE + "%s");
            }
            if (event.getPlayer().hasPermission("chat.owner")) {
                event.setFormat("" + ChatColor.RED + "» " + ChatColor.YELLOW + getConfig().getInt(p.getUniqueId()+".Coins") + ChatColor.DARK_GRAY + " | " + ChatColor.RED + "Owner" + " | " + ChatColor.DARK_RED + "%s" + ChatColor.AQUA + " » " + ChatColor.WHITE + "%s");
            }
        }
    }
    It still give me the same error that shows. "The method toString() in the type UUID is not applicable for the arguments (UUID)"

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  7. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page