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

    Henzz SnipsRevival Ok guys. i'll try it later.

    Henzz It doesn't give me an option to import

    Henzz It tells me a solution: rename 'player'

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

    Henzz

    megasaad44
    You've probably done something really wrong, have you learned the basics of Java? Also can you show the code you currently have now?

    Delete what you have now and just paste the code I posted recently under your enabling, disabling and oncommand method.

    PHP:
    package me.bigbadhenz.plugins;
     
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    Main extends JavaPlugin {
     
        public 
    void onEnable() {
            
    getCommand("report").setExecutor(this);
        }
     
        public 
    void onDisable() {
     
        }
     
        public 
    boolean onCommand(CommandSender senderCommand cmdString lblString[] args) {
     
            if (!(
    sender instanceof Player)) {
                
    sender.sendMessage("Use this command in game");
                return 
    true;
            }
     
            if (
    cmd.getName().equalsIgnoreCase("report")) {
         
                if (
    args.length 2) {
                    
    sender.sendMessage("Usage: /report bug <msg>");
                    return 
    true;
                }
                else if (
    args.length 1) {
                    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);
                            }
                        }
                    }
                }
         
            }
     
            return 
    true;
        }
    }
     
  3. Offline

    megasaad44

  4. Offline

    ASHninja1997

    megasaad44
    Here is the full code I tested it out and it works.
    Code:
    package me.LordSaad.reporter;
     
    import java.util.logging.Logger;
     
    import org.apache.commons.lang.StringUtils;
    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 (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 player1 : Bukkit.getOnlinePlayers()) {
                            if (player1.isOp()) {
                                String message = StringUtils.join(args, ' ', 1, args.length);
                                player1.sendMessage(ChatColor.AQUA + "Bug reported by " + ChatColor.BLUE + sender.getName() + ": " + ChatColor.YELLOW + message);
                            }
                        }
                    }
                }
         
            }
            return false;}}
    
     
  5. Offline

    molenzwiebel

    If someone writes the code for you, you will never learn anything.
     
  6. Offline

    megasaad44

    molenzwiebel I know, i didn't ask them for the code xD but oh well. i guess i'll learn from those, this is a fairly hard plugin for a first timer, so i guess i could learn from that, and the code is still incomplete, so i could probably finish it off on my own, but i dont know. lol
     
  7. Offline

    tombath10

    You can do if player has permission blah.op then ...

    Then all ops + anyone with that permission node can receive the message.
     
  8. Offline

    molenzwiebel

    I was talking to ASHninja1997
     
  9. Offline

    megasaad44

    molenzwiebel
    It sounded like you where talking to me. Sorry. But in anycase, this WILL help me no doubt :)

    ASHninja1997 Henzz
    according my console and the yaml parser, the : is wrong.

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

    Henzz

    megasaad44
    The code works perfectly for me, you've done something wrong in your plugin.yml file.
    It should look like this.
    Code:
    name: <pluginname>
    main: me.<name>.<pluginname>.<mainmethod>
    version: 1.0
    commands:
      report:
        description:
        permission: report.use
        permission-message: You do not have <permission>
        
     
  11. Offline

    megasaad44

    Henzz I have it like that....
     
  12. Offline

    ERROR372

    megasaad44

    Why are you running java code through a YAML parser? .java is not .yml and it never will be...
     
  13. Offline

    megasaad44

    ERROR372 Hmmm.... Did not know that. But any case, console gives an error. i'm trying to fix it.

    It's definatly the plugin.yml. Fixing

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

    ERROR372

    megasaad44

    Helps if you give us the error code. Is it a NullPointer, InvalidPlugin, IndexOutofBounds? Paste the error you get in the console to here. The whole thing.
     
  15. Offline

    megasaad44

    Code:
    name: Reporter
    main: me.Reporter.reporter.Reporter
    version: 1.0
    commands:
      reporter:
        description: Opens the help page of reporter
      report bug
        description: Report a bug
      report complaint
        description: Don't like something? Say it!
      report compliment
        description: Want to share your nice thoughts about us? Say it!
      report player
        description: Found a rule breaker? Report them!
      report bug read
        description: Read the bug reports.
      report complaint read
        description: Read complaints.
      report compliment read
        description: Read compliments.
      report player read
        description: Read player reports.
      reporter reload
        description: Reload reporter.
    That is my plugin.yml
    And this is the YAML parser
    Code:
    ERROR:
     
    while scanning a simple key
      in "<unicode string>", line 7, column 3:
          report bug
          ^
    could not found expected ':'
      in "<unicode string>", line 8, column 16:
            description: Report a bug
                      ^
    As for the console:
    Code:
    1:14:06 PM [SEVERE] Could not load 'plugins\Reporter.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
    at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:247)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:132)
    at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugins(CraftServer.java:239)
    at org.bukkit.craftbukkit.v1_6_R2.CraftServer.<init>(CraftServer.java:217)
    at net.minecraft.server.v1_6_R2.PlayerList.<init>(PlayerList.java:56)
    at net.minecraft.server.v1_6_R2.DedicatedPlayerList.<init>(SourceFile:11)
    at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:106)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:391)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.io.FileNotFoundException: Jar does not contain plugin.yml
    ... 9 more
    It's obviously the plugin.yml. Any pointers?

    EDIT:
    It might be that i'm missing a description. Am i right?

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

    ERROR372

    megasaad44

    After each of your commands, you forgot to put a colon. So like... report bug needs a colon, report complaint needs one, so on and so forth. I'm not sure if that will work as you intend it to, but that should fix your plugin.yml issue.
     
  17. Offline

    megasaad44

    Wow. How could i have not noticed that? xD It works now, thanks. I can continue testing now :)

    [​IMG]

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

    Alxlre

  19. Offline

    megasaad44

    Alxlre Lol. Thanks. Didn't think anyone would have read it :p I figured it out a few minutes ago

    Alxlre "this.reload();" is wrong i think, it's this.reloadconfig();
    that is how it was corrected in eclipse




    EDIT: Now it gives me an internal error. ._.

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

    Alxlre

    megasaad44 Use reflection to unload the plugin, then load it again and tadah!
     
  21. Offline

    megasaad44

    Alxlre Now if only i knew how to make a reflection... :p Any tut links or something? i would love to learn this stuff
     
  22. Offline

    Alxlre

    megasaad44 .
    Not really what you want but the same thing can be used with your plugin if you understand it.
     
  23. Offline

    megasaad44

    Alxlre Ok, I'll check it out

    Bad video xD. i'll just google another tut :p thanks anyways.

    Alxlre I've been researching a lot and it seams i'm better off without a reloader... ._.

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

    ASHninja1997

    molenzwiebel
    I gave him the whole code so he can diagnose it and see what commands lines do what. I actually learn that way. If I see the code and plug it in to see if it works then I know what goes together and what doesn't.
     
  25. Offline

    caseif

    Why would he need to use reflection for this? Isn't it possible to just use this code?
    Code:java
    1. plugin.getServer().getPluginManager().disablePlugin(plugin);
    2. plugin.getServer().getPluginManager().enablePlugin(plugin);
     
  26. Offline

    megasaad44

    ASHninja1997 True true. But i think you got it wrong. Your code doesn't send any message to any op ._. But i guess i will try to figure this out. What can i write so that part of the command the player runs, gets sent a messaage to the op?
     
  27. Offline

    SnipsRevival

     
  28. Offline

    megasaad44

    SnipsRevival Thanks! :p i should really start reviewing my posts.

    SnipsRevival Can you explain it please? What i want to know is what do i write and where do i write the thing that sends part of a players text. BASICALLY. This is also for future information ._.

    http://prntscr.com/1gaerc

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

    SnipsRevival

    Add it anywhere after you have checked if(args.length > 1) and then use the message variable in player.sendMessage(message).

    EDIT: you should be using the { and } braces too.
     
  30. Offline

    megasaad44

    SnipsRevival Something i do not get. args.length should be args.length > 2 since the command would be /reporter bug <text> i want to send that text to the op. player.sendmessage sends a message to the player HIMSELF. right?
    and whats the "for" variable for? I never understood its function

    It even says there is an error when i put your code in :/. look at the link above i posted

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page