I have been messing around with a plugin for a while and I've come across this issue where when I type a command with a argument (that becomes a player (target variable in the code)) instead of replacing the value in the config of the actual player it creates a new one called CraftPlayer{name=RisenAngel} Heres the code: https://pastebin.com/rgVBY3uw
When you try to print a Player, the method: toString() is called. And for the player the toString() return Code (Text): CraftPlayer{name=RisenAngel} So if you want the name of the player you have to do like this: Code (Text): player.getName(); or player.getDisplayName();
That looks like the result of toString(), which is called when you try to save an object as a string. Use the player's UUID instead.
Im getting an error on this string: Code (Text): target = Bukkit.getServer().getPlayer(args[0]).getUniqueId(); Heres my whole new code: https://pastebin.com/tvzi0Cy9
You can't add anything but Strings, numeric values and ConfigurationSerializables (and maybe one or two things I don't have in mind at the moment) to a config. You have to get other objects like players by one of these things. So, you can't add a UUID to your config, neither. Fortunately, a UUID can easily be fetched from a String. String string = player.getUniqueId().toString(); UUID uuid = UUID.fromString(string);
You don't need to change anything.. it's just a "mistake" here: Code (Text): if (cmd.getName().equalsIgnoreCase("reset")) { target = Bukkit.getServer().getPlayer(args[0]); if (target == null) { sender.sendMessage(ChatColor.RED + "Cannot find player '" + args[0] + "'."); return true; } if(args.length == 1){ blocksTraveled.put(target.getName(), 0); // HERE HERE HERE p.sendMessage("Reseted."); target.sendMessage("Your stats have been reseted."); } }
Remove and replace the config file? Probably that Code (Text): getConfig().set(p.getName() +".traveled", blocksTraveled.get(p)); Your have an HashMap<String, Integer>. So to get an element you need to set a string as parameter. blockTraveled.get(p.getName())
Code (Text): if(args.length == 1){ getConfig().set(p.getName() +".traveled", 0); p.sendMessage(Double.toString(getConfig().getDouble(p.getName() +".traveled"))); p.sendMessage("Reseted."); target.sendMessage("Your stats have been reseted."); } But for some reason it sends 0.0 but the number doesnt change in the config (I fixed the CraftPlayer thing by using my old code)