Need Help with Staff Command

Discussion in 'Plugin Development' started by JeykoExample, Aug 14, 2014.

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

    JeykoExample

    Hey Guys,

    I made a Plugin where you can use /staff to Report Players and to ask Questions to OPs
    and i don't know why this isn't working?

    CommandsClass:
    PHP:
    package de.glorymc.reportstaff;

    import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class 
    Commands implements CommandExecutor {

        @
    SuppressWarnings("unused")
        @
    Override
        
    public boolean onCommand(CommandSender csCommand cmdString labelString[] args) {
        if(
    cs instanceof Player) {     
            if (
    args.length 1){
                
    handleBaseCommand(cs);
            return 
    false;
            }
            
    String s args[0];
            for(
    OfflinePlayer p Bukkit.getOfflinePlayers()){
                if(
    p.getName().equals(s)){
                if (
    args[0].equalsIgnoreCase(s));
                    
    String text "";
                        for (
    int i 1args.lengthi++) {
                                
    text += args[i] + " ";
                                    
    Bukkit.broadcast("§8[§§lcREPORT§r§8] §f"+cs.getName()+"§6§l>>§r §c"+args[0]+"§f:§7 "+text+"§f.""Staff.Read");
                                    return 
    true;
                        }
                
                } else if (!
    args[0].equalsIgnoreCase(null)) {
                
    String text "";
                for (
    int i 0args.lengthi++) {
                        
    text += args[i] + " ";
                        
    Bukkit.broadcast("§8[§c§lQUESTION§r§8] §f"+cs.getName()+": §c"+text+"§f.""Staff.Read");
                return 
    true;
                }
                }
                return 
    false;
            }
            return 
    false;
            }
        return 
    false;
            
        }
            
            private 
    void handleBaseCommand(CommandSender cs){
                
    Player p = (Playercs;
                
    p.sendMessage("§r");
                
    p.sendMessage("§r");
                
    p.sendMessage("§r");
                
    p.sendMessage("§8§l>>");
                
    p.sendMessage(" §aHello, §6"+p.getName()+"§a.");
                
    p.sendMessage(" §aUse §c/staff <§fPlayername§c> <§fReason§c> to");
                
    p.sendMessage(" §areport §6Hackers/Buguser §aor");
                
    p.sendMessage(" §ause §c/staff <§fQuestion§c>§a to");
                
    p.sendMessage(" §asend a §6Question§a to all online");
                
    p.sendMessage(" §6Supporter§a.");
                
    p.sendMessage("§8§l<<");
                return;
            }
    }
    Plugin.yml:
    PHP:
    nameStaff
    author
    GloryMC
    main
    de.glorymc.reportstaff.Main
    version
    1.0

    commands
    :
      
    staff:
        
    descriptionStaff :)
        default: 
    true

    permissions
    :
      
    staff.*:
        
    descriptionSTAFF
        
    default: op
      children
    :
        
    Staff.Readtrue
    I don't know ... I got one Idea: Do I have to add the /staff Playername Reason command to my plugin.yml to? Because i don't know how to add it ?

    Thanks a LOT ! :)
     
  2. Offline

    _LB

    Could you be more specific than "isn't working"? Also, there is no such thing as a "default" command ;p
     
  3. Offline

    JeykoExample

    _LB Oh yeah sorry :) The /staff Command is working well, but if I type in "/staff <My Playername> Reason " or type in "/staff <Question>" nothing happens no Broadcast and no error in console :O

    Gerov Do u have an Idea? Please help me :)

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

    _LB

    What happens if you log a debug message after line 19? Also, use [ syntax=java ] and [ syntax=yaml ] so it is not detected as PHP
     
  5. Offline

    DinosParkour

    JeykoExample
    The problem is that you forgot to add:
    Code:
    if(label.equalsIgnoreCase("staff")){
    Also, your code would look better if you used ChatColor instead of § :)
     
    Gerov likes this.
  6. Offline

    JeykoExample

    _LB I'm now getting a HUGE error:

    PHP:
    [01:21:22 ERROR]: Could not load 'plugins\StaffCommand.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionExceptionInvalid plugin.yml
            at org
    .bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPlug
    inLoader
    .java:160) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]

            
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:133) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    va
    :350) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(CraftServer.java:77
    1
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.Bukkit.reload(Bukkit.java:279) [craftbukkit.jar:git-Bukkit
    -1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    23) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:17
    5
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r
    .java:683) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchServerCommand(Craf
    tServer
    .java:670) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.DedicatedServer.aw(DedicatedServer.java:
    286) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    51
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    Caused byorg.yaml.snakeyaml.scanner.ScannerException: while scanning for the n
    ext token
    found character      '\t' that cannot start any token
            at org
    .yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.ja
    va
    :358) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:17
    9
    ) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(Par
    serImpl
    .java:563) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161) ~
    [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
    ~[
    craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :230) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~
    [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :237) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~
    [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :237) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~
    [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:12
    3
    ) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106)
     ~[
    craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseCons
    tructor
    .java:121) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480) ~[craftbukkit.j
    ar
    :git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:411) ~[craftbukkit.jar:git-Buk
    kit
    -1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.
    java:189) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPlug
    inLoader
    .java:155) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]

            ... 
    13 more
    What? Copy my CommandsClass get that Code and show me?

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

    _Cookie_

  8. Offline

    JeykoExample

    Okay it's working now, but I'm typing in this:

    /staff JeykoExample You are a Hacker

    and it's only broadcasting:

    [REPORT] JeykoExample >> JeykoExample: You.
     
  9. Offline

    DinosParkour

    JeykoExample That's because it's only getting args[0]. You have to get every word the player types, not just the first one
     
  10. Offline

    JeykoExample

    How can i do this? Im a newbie ...
     
  11. Offline

    DinosParkour

    JeykoExample
    Code:
    String text ="";
    for(int i =1; i < args.length; i++){ //you can see i = 1 so instead of messaging "DinosParkour You are a hacker" it will say "You are a hacker" (Skips the first arg)
        String arg = args[i]+" ";
        text = text + arg;
    
     
  12. Offline

    JeykoExample

    DinosParkour It's still wrong :/ and still not working ... Still only the 1 Integer ...
     
  13. Offline

    Necrodoom

    JeykoExample that's because you return inside the for loop, so it will always only run once.
    Also, use a string builder.
    In addition, your top for loop only runs if you report yourself, fix your code logic.
     
  14. Offline

    AlexHH251997

    Like Necrodoom said, use a StringBuilder. It allows you to take all of the arguments, build them intro a String and use them as a String. Pretty much as the name suggests.

    Here's the code:
    Code:java
    1. public boolean onComamnd(CommandSender sender, Command cmd, String label, String[] args){
    2. if(cmd.getName().equalsIgnoreCase("staff")){
    3. String message;
    4. StringBuilder builder = new StringBuilder();
    5. for(int i = 0; i < args.length; i++){
    6. builder.append(args[I]).append(" ");[/I]
    7. [I] }[/I]
    8. [I] message = builder.toString();[/I]
    9.  
    10. [I] Player player = (Player) sender;[/I]
    11. [I] if(sender instanceof Player){[/I]
    12. [I] if(player.hasPermission("permission.node.to.send.report")){[/I]
    13. [I] String playerName = player.getDisplayName();[/I]
    14. [I] for(Player p : Bukkit.getOnlinePlayers()){[/I]
    15. [I] if(p.hasPermission("permission.node.to.recieve.report")){[/I]
    16. [I] p.sendMessage(ChatColor.RED + "[REPORT]" + ChatColor.YELLOW + playerName + ChatColor.GRAY + ": " + ChatColor.YELLOW + message);[/I]
    17. [I] }[/I]
    18. [I] }[/I]
    19. [I] }[/I]
    20. [I] }else{[/I]
    21. [I] sender.sendMessage("[REPORT] Can not report from console.");[/I]
    22. [I] }[/I]
    23. [I] }[/I]
    24. [I] }[/I]


    EDIT: Ignore all the [ /I ]'s I have no idea why they are there... Just remove them from the code [/I]
     
  15. Offline

    Necrodoom

Thread Status:
Not open for further replies.

Share This Page