How to do this?

Discussion in 'Plugin Development' started by football70500, Jul 23, 2015.

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

    football70500

    I made a /report command for my server and it works fine, but I want to make it so that every time someone gets reported, if they were previously reported, it would show up as like (2x) (3x) etc at the end of each report. How would I go about doing this?

    Code:java
    1.  
    2. if (cmd.getName().equalsIgnoreCase("report")) {
    3. if (cooldown.contains(sender)) {
    4. sender.sendMessage(ChatColor.RED
    5. + "You can only report someone every 2 minutes!");
    6. } else {
    7. if (args.length < 2) {
    8. sender.sendMessage(ChatColor.RED
    9. + "/Report <Name> <Message>");
    10. return true;
    11. } else {
    12. target = Bukkit.getServer().getPlayer(args[0]);
    13. if (target != null) {
    14. if (sender.hasPermission("report.report")) {
    15. if (target != sender) {
    16. sender.sendMessage(ChatColor.GREEN
    17. + "Your report has been sent! Thank you.");
    18. for (Player online : Bukkit.getOnlinePlayers()) {
    19. if (online.hasPermission("hr.getmessage")) {
    20. online.sendMessage(ChatColor.BLUE
    21. + "[Report] "
    22. + ChatColor.YELLOW
    23. + sender2.getName()
    24. + ChatColor.RED
    25. + " has reported "
    26. + ChatColor.YELLOW
    27. + target.getName()
    28. + ChatColor.RED + " for "
    29. + ChatColor.GREEN + message);
    30. getLogger().info(sender2.getName() + " has reported " + target.getName() + " for " + message);
    31. cooldown.add(sender2);
    32. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    33. public void run() {
    34. cooldown.remove(sender2);
    35. }
    36. }, 2400);
    37. //20 TICKS = 1 SECOND SO 20 X (# OF SECOND) = VALUE FOR THIS
    38.  
    39. }
    40. }
    41. } else {
    42. sender.sendMessage(ChatColor.RED
    43. + "You can't report yourself!");
    44. }
    45. } else {
    46. sender.sendMessage(ChatColor.RED
    47. + "You do not have permission to use /report!");
    48. }
    49. } else {
    50. sender.sendMessage(ChatColor.YELLOW
    51. + target.getDisplayName() + " is not online.");
    52.  
    53. return true;
    54. }
    55. }
    56. }
    57. }
    58.  
     
  2. Offline

    567legodude

    @football70500 Just keep a number somewhere of how many times they are reported, and every time they are reported, increase that number by 1.
     
  3. Offline

    TheDiamond06

    @567legodude @football70500
    Try looking into HashMaps you can store the player's name along with the number of times they are reported.
    There is a flaw to this because HashMaps don't go through server restarts so you would have to store this data in a file and load it back in when the server starts.
     
  4. Offline

    Eos

    Store into a config with the players unique id as the identifier then on config create set the default value which is mostly like zero. Every time the user gets reported add a point

    Code:
    getConfig().getInt("Warnings", + 1);
    This is how I get the user's uniqueID

    Code:
        UUID u;
        File UserFile;
        FileConfiguration UserConfig;
    
        //        UserDataHandler user = new UserDataHandler(player.getUniqueId()); // Make sure that you have the player.getUniqueId()
    
        public UserDataHandler(UUID u){
    
            this.u = u;
    
            UserFile = new File("plugins/CryptLibrary/data/" + u + ".yml");
    
            UserConfig = YamlConfiguration.loadConfiguration(UserFile);
    
        }
     
    Last edited: Jul 23, 2015
Thread Status:
Not open for further replies.

Share This Page