Need help with my plugin

Discussion in 'Plugin Development' started by Cephot, Aug 27, 2015.

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

    Cephot

    Hi, right now I'm working on creating a plugin kind of like a report/ticket system. A player sends a ticket and it stores it in a data.yml folder, and later on a staff member can list all tickets and choose one they would like to view. Now what I would like to know is how would I make the command store the players name and their message?
     
  2. Offline

    SkyleTyler1337

    @Cephot
    just put it in a hashmap

    Code:
    HashMap<Player,String> reports = new HashMap<>();
    
     
  3. Offline

    Cephot

    @SkyleTyler1337

    I will give it a try and how would I go about sending the staff member the message of the player and string on a command? xD i'm sorta new to bukkit.
     
  4. Offline

    SuperSniper

    Use the HashMap that @SkyleTyler1337 said. It will store the Player, and the report message into the hashmap, and you can check if the hashmap contains the player (in the command) and if it does, send them the message that is put inside the hashmap for that player.

    Code Example:
    Code:
    HashMap<String, String> reports = new HashMap<String, String>();
    
    // on command things
    Player reported = Bukkit.getPlayer(args[0]);
    sender.sendMessage(reports.get(reported));
    
    @Cephot Also, to put in a playername and a report message into the hashmap do this:

    Code Example:
    Code:
    HashMap<String, String> reports = new HashMap<String, String>();
    
    // on command things
    
    StringBuilder sb = new StringBuilder();
    for (int i = 1; i < args.length; i++){
    sb.append(args[i]).append(" ");
    }
    
    String Message = sb.toString().trim();
    Player reported = Bukkit.getPlayer(args[0]);
    reports.put(reported.getName(), Message));
    
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  5. Offline

    Cephot

    @SuperSniper

    Got 1 question, what do I do with reports.set and reports.contain? It says cannot resolve method.
     
  6. Offline

    SuperSniper

    Sorry about that :p Its
    reports.put | not reports.set
    and
    just forget about .contains, it doesn't exist :p
    just use
    reports.get(PlayerName);

    I fixed my previous posts
     
  7. Offline

    SkyleTyler1337

    @Cephot are trying to store them in the hashmap? use
    Code:
     HashMap<Player, String> reports = new HashMap<Player, String>();
    reports.put(player, message);
    
    you can change the K in the hashmap to be a String for the player's name.
     
  8. Offline

    SuperSniper

    You can't use a Player's name inside of a Player object, you need to change it to String,String
     
  9. Offline

    Cephot

    @SuperSniper

    I didn't include my entire code but would it be similar to this?

    Code (open)

    if(args.length >= 2){
    StringBuilder sb = new StringBuilder();
    for (int i = 1; i < args.length; i++){
    sb.append(args).append(" ");
    }

    String Message = sb.toString().trim();
    Player reported = Bukkit.getPlayer(args[0]);
    reports.put(reported.getName(), Message);
    p.sendMessage(ChatColor.GREEN + "Thank you for reporting " + ChatColor.GOLD + args[0] + ChatColor.GREEN + " , your report will be viewed shortly");
    return true;
    }
    if(cmd.getName().equalsIgnoreCase("reportview")){
    reports.get(Bukkit.getName());
    sender.sendMessage(reports.get(reports));
     
    Last edited: Aug 27, 2015
  10. Offline

    SuperSniper

    @Cephot Change
    Code:
    
    if(cmd.getName().equalsIgnoreCase("reportview")){
    reports.get(Bukkit.getName());
    sender.sendMessage(reports.get(reports));
    
    
    to
    Code:
    if(cmd.getName().equalsIgnoreCase("reportview")){
    Player p = Bukkit.getPlayer(args[0]);
    sender.sendMessage(reports.get(p.getName());
    
    
     
  11. Offline

    Cephot

    @SuperSniper

    That works but I get an internal error occured if I don't specify any player, how could I solve that? In the console it says the error is on line 59, which is Player p = Bukkit.getPlayer(args[0]);
     
  12. Offline

    au2001

    @Cephot Check if args isn't empty before getting an argument.
    (hint: checking if it isn't empty = checking if it's length is over 0)
     
  13. Offline

    Cephot

    @au2001

    I'm sorry for asking so many questions about this but I really have no one else to ask. I'm now attempting to add a command that when used, sends the sender a message of all reports made, so like for example he does /listreports, it sends him a list of player names that have been reported, then he can do /viewreports for a certain player. What do I do in the sender.sendMessage() to make it send all the players in the hashmap?
     
  14. Offline

    au2001

    @Cephot You have to loop through the hashmap (or keySet() to be more precise).
     
  15. Offline

    Cephot

    @au2001

    Can I get an example of how do this?
     
  16. Offline

    au2001

    @Cephot
    Code:
    for (Class something : HashMap#keySet()) {
        something.doWhatYouWant();
    }
     
  17. Offline

    SuperSniper

    Code:
    for (String allReports : reports.keySet()) {
        // do stuff
    }
    
    @Cephot
     
  18. Offline

    au2001

  19. Offline

    SuperSniper

    @au2001 Yes, but I just fixed it up a little bit to help him out, since it seems like he's a beginner
     
  20. Offline

    Cephot

    @SuperSniper

    Thank you so much, it's working just how I would like it to now I just have to edit some stuff so that everything works good!
     
  21. Offline

    SuperSniper

    @Cephot You're welcome :D
    I love helping people :)
     
Thread Status:
Not open for further replies.

Share This Page