Player to all ops message?

Discussion in 'Plugin Development' started by megasaad44, Jul 16, 2013.

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

    megasaad44

    How do i make it so a player type for ex: /reporter bug <text>
    and so when the player sends that command, It would be sent to ops that they have 1 new bug report and they type for ex: /reporter bug read
    so then they all see that report the player sent. How can i accomplish this?




    p.s: first time trying to make plugins so going to make a lot of posts here :)
     
  2. Offline

    Henzz

    megasaad44
    Iterate through online players and check if player is op, send them a message.
    Or you could use Bukkit.broadcast(message, permission) if you'd like.

    So it would be like

    If cmd.getname.equalsignorecase"report" then
    If args.length < 2
    Return false
    Else if args.length == 2
    If args[0].equalsignorecase("bug") {
    For (player player : bukkit.getonlineplayers()) {
    If (player.isop()) {
    player.sendmessage(args1);
     
  3. Offline

    HackintoshMan

    you can loop through all of the online players and check if each one is op, if they are then send them a message.
     
  4. Offline

    megasaad44

    Henzz and HackintoshMan Can you explain more please? I want a counter. Kinda like how messages work in essentials.
    And categorized.

    I guess i could use if player.isOp but how do i SEND the message the player wrote? And in a categorized manner with a counter so like: you have 1 new bug report
    then /reporter bug read
    it would list all the messages

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

    Henzz

    megasaad44
    Just edited my post just then, I'm on phone so it's a bit messy.
     
  6. Offline

    soulofw0lf

    save the messages to a list<String> named errorList or something, send the ops a message saying "there are " + errorList.size() + " error messages waitting!. when the ops type the read bug report have it grab index 0 and when the op types that it's complete remove that index
     
  7. Offline

    megasaad44

    soulofw0lf Sounds good. Sorry for being noobish here but, how do i make the list?
    in other forms, my plugin is basically:
    player: /report
    *command list pops*
    /report bug
    /report complaint
    /report BLAH BLAH BLAH

    player: /report bug i lost my inv in creative world
    *op joins*
    op: you have 1 report bug
    op: /report bug read
    op: player: i lost my inv in creative world
    op goes to solve the prob
     
  8. Offline

    soulofw0lf

    List<String> errorLogs = new ArrayList<>();
    errorLogs.add("msg");
    errorLogs.get(0);
    errorLogs.remove(0);
     
  9. Offline

    mncat77 Retired Staff

    You could also add a permission node to your plugin that, by default, is assigned to ops and use the second parameter of the .sendMessage(String message, String permission) to send it to all players with the permission (thus all ops).
     
  10. Offline

    megasaad44

    mncat77 Lol. not so advanced it perm nodes yet. I'm trying to dabble a little while i learn this. It's hard e_e
     
  11. Offline

    mncat77 Retired Staff

    If you don't want to do that (it's really not that hard) you can either iterate through all ops and see if they are online or iterate through all players and see if they are ops (you generally want to use the first option on the average server in some cases option two is better though).
     
  12. Offline

    Pawnguy7

    Would this be like Essentials /mail or so? That is, stored past reloads, etc. (well, I think it is, anyway). If so, that would require a config, also.
     
  13. Offline

    megasaad44

    Ok, lets start off in another way. what is the method to let a player send a message to the ops like /reporter bug <text>
    so it would send the ops: [bug report] player: <text>
    the easy part is finding the ops, and im not talking whether they are online or not sooooo .isOp will definatly be included. how will the prefix and the text be added?

    Pawnguy7 ._. Teach me?

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

    Pawnguy7

    http://wiki.bukkit.org/Configuration_API_Reference

    But that is only if it has a config, as in the use case I cited (like essentials mail, stores when server it shut down, etc).

    Adding the prefix is fairly easy.

    String prefixString = ChatColor.BLUE + "[bug report]";

    some_player.sendMessage(prefixString + bugReportString);

    Or using the broadcast with perms, that works as well.
     
  15. Offline

    megasaad44

    Pawnguy7 How would i make the bug reporting string? i'll reply tomorrow

    Ok. So i thought i would make it simpler on myself until i learn more. So how do i let a player send a report to an online op at the moment
    Code:
            if (commandLabel.equalsIgnoreCase("reporter bug"))
                if (args.length == 1)
                    if ()
                    player.sendMessage(ChatColor.AQUA + "Bug report sent!");
                    sender.sendMessage("");
    I'm writing this out, it is incomplete, How do i make it search for online ops and then send the report?

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

    SnipsRevival

    megasaad44
    Code:
    for(Player player : Bukkit.getOnlinePlayers()) {
    if(player.isOp()) {
    player.sendMessage(message);
    }
    }
    This will loop through all online players and send a message to only the ops.
     
  17. Offline

    megasaad44

    SnipsRevival Hmm... Ok "(message)" will this send the /reporter bug <text> the text part?
     
  18. Offline

    SnipsRevival

    megasaad44 put whatever you want as the message.
     
  19. Offline

    megasaad44

    SnipsRevival Thats not the idea. It would send the message the player would type
     
  20. Offline

    SnipsRevival

    megasaad44 use this to create a string from the args a player types in the /report command:

    Code:
    		StringBuilder strBuilder = new StringBuilder();			
    
    		for(int i = 1; i < args.length; i++) {
    			strBuilder.append(args[i] + " ");
    		}
    		String message = strBuilder.toString().trim();
     
  21. Offline

    Henzz

    megasaad44
    Should've read the second post..
    Forgot to check if args 1 equals report lol
     
  22. Offline

    megasaad44

    GUU this is tough for the first time.
    Code:
    package me.LordSaad.reporter;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Reporter extends JavaPlugin{
          public final Logger logger = Logger.getLogger("Minecraft");
          public void onDisable()
          {
            PluginDescriptionFile pdFile = getDescription();
            this.logger.info(pdFile.getName() + " Has been disabled!");
          }
     
          public void onEnable() {
            PluginDescriptionFile pdFile = getDescription();
            this.logger.info(pdFile.getName() + " Version " + pdFile.getVersion() + " Has been enabled!");
          }
     
          public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player)sender;
            if (commandLabel.equalsIgnoreCase("reporter"))
                if (args.length == 0){
                player.sendMessage(ChatColor.DARK_GRAY + "=================[" + ChatColor.GREEN + "Reporter" + ChatColor.DARK_GRAY + "]=================");
                player.sendMessage(ChatColor.GREEN + "/reporter bug <text>" + ChatColor.DARK_GRAY + "Found a bug in a plugin? Report it with this command!");
                player.sendMessage(ChatColor.GREEN + "/reporter help <text>" + ChatColor.DARK_GRAY + "Need help with anything? Ask it with this command!");
                player.sendMessage(ChatColor.GREEN + "/reporter complaint <text>" + ChatColor.DARK_GRAY + "Got a complaint you would like to share? Say it with this command!");
                player.sendMessage(ChatColor.GREEN + "/reporter compliment <text>" + ChatColor.DARK_GRAY + "Want to leave us a nice message? Say it with this command!");
                player.sendMessage(ChatColor.GREEN + "/reporter report <text>" + ChatColor.DARK_GRAY + "Found someone breaking the rules? Report them this command!");
                player.sendMessage(ChatColor.DARK_GRAY + "===============================================");
               
            } else {
                player.sendMessage(ChatColor.RED + "Wrong usage! Type /reporter");
        }
            if (commandLabel.equalsIgnoreCase("reporter bug"))
                if (args.length == 1)
                    for(Player player1 : Bukkit.getOnlinePlayers()) {
                        if(player1.isOp()) {
                        player1.sendMessage(message);
                        }
                        }
                    player.sendMessage(ChatColor.AQUA + "Bug report sent!");
                    sender.sendMessage("");
            return false;
      }
    }
    i feel idiotic

    Henzz i did... i'm taking multiple thoughts.

    Henzz Ok so i put what you said in the report bug section, should work. right?

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

    Henzz

    megasaad44
    I see, I assumed your last post sounded like you were trying to do what I posted.
     
  24. Offline

    megasaad44

    Henzz No. I'm trying yours now
     
  25. Offline

    Henzz

    megasaad44
    Something like this
    PHP:
    if (cmd.getName().equalsIgnoreCase("report")) {
           
                if (
    args.length 2) {
                    
    sender.sendMessage("Usage: /report bug <msg>");
                    return 
    true;
                }
                else if (
    args.length 2) {
                    if (
    args[0].equalsIgnoreCase("bug")) {
                        for (
    Player player Bukkit.getOnlinePlayers()) {
                            if (
    player.isOp()) {
                                
    String message StringUtils.join(args' '1args.length);
                                
    player.sendMessage("Bug reported by " sender.getName() + ": " message);
                            }
                        }
                    }
                }
           
            }
     
  26. Offline

    megasaad44

    Henzz Ahh i see. Thanks. i'll see what happens after i dabble a little
     
  27. Offline

    SnipsRevival

    megasaad44 What Henzz said would work fine assuming you only want to use 1 arg for your message in the command. If you want more than 1 arg for your message, check if args.length > 1 and read my post I sent earlier about creating a message from multiple args.
     
  28. Offline

    Henzz

    megasaad44
    Yeah change args.length == 1 to args.length > 1 lol
     
  29. Offline

    megasaad44

    Henzz hmm.. It tells me that "player" in " for (Player player : Bukkit.getOnlinePlayers()) {"
    is wrong and same for "join"
     
  30. Offline

    Henzz

    megasaad44
    What do you mean wrong? Have you imported them?
     
Thread Status:
Not open for further replies.

Share This Page