Development Assistance Trying to announce what the player typed in the command

Discussion in 'Plugin Help/Development/Requests' started by PerezHD, Dec 22, 2014.

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

    PerezHD

    Please correct me if I am wrong. Well I see that their are no braces closing
    Code:
                        long lastUsed = 0;
                        if (lastUsage.containsKey(sender.getName())){
                            lastUsed = lastUsage.get(sender.getName());
                      
                            int cdmillis = cTime * 1000;
     
  2. @PerezHD That's right, you need to close that :)
     
  3. Offline

    PerezHD

    well, would I do it be this?
    Code:
                        long lastUsed = 0;
                        if (lastUsage.containsKey(sender.getName())){
                            lastUsed = lastUsage.get(sender.getName());
                      
                            int cdmillis = cTime * 1000;
                            }
    @AdamQpzm

    Okay well, I did this
    Code:
      public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args)
      {
        if (cmd.getName().equalsIgnoreCase("stream")) {
            if (sender instanceof Player){
                Player p = (Player)sender;
                if (p.hasPermission("stream.announce")){
                    if (args.length > 1){
                        sender.sendMessage(stream + ChatColor.RED + "You are adding more arguments then told!");
                        return false;
                    }
                    else if (args.length == 0){
                        sender.sendMessage(stream + ChatColor.RED + "Usage: /stream <twitch>");
                    }
                    else if (args.length == 1){
                        long lastUsed = 0;
                        if (lastUsage.containsKey(sender.getName())){
                            lastUsed = lastUsage.get(sender.getName());
                        }
                      
                            int cdmillis = cTime * 1000;
                            if (System.currentTimeMillis() - lastUsed > cdmillis){
                                Bukkit.broadcastMessage(stream + ChatColor.GREEN + "" + ChatColor.BOLD + p.getName() + " is streaming" + ChatColor.AQUA + "" + ChatColor.BOLD + " Go watch @ www.twitch.tv/" + args[1] + "!");
                                lastUsage.put(sender.getName(), System.currentTimeMillis());
                            }
                            else {
                                int timeLeft = (int) (cTime -((System.currentTimeMillis() - lastUsed)/1000));
                                sender.sendMessage(ChatColor.RED + "You must wait another " + timeLeft + "s.");
                            }
                        }
                    }
            }
        }
        return false;
      }
    And now I am getting an internal error.

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

    nverdier

    Well give us the stack trace!
     
  5. Offline

    PerezHD

    Code:
    [06:24:36] [Server thread/INFO]: PerezHD issued server command: /stream PerezHD
    [06:24:36] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'stream' in plugin FlexUtils v5.4
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1043) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:880) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at com.perezhd.prisonutils.stream.StreamAnnounce.onCommand(StreamAnnounce.java:45) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[minecraft_server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    ... 13 more
     
  6. Offline

    nverdier

    @PerezHD And what is on line 45 in the StreamAnnounce class?
     
  7. Offline

    PerezHD

    Code:
     Bukkit.broadcastMessage(stream + ChatColor.GREEN + "" + ChatColor.BOLD + p.getName() + " is streaming" + ChatColor.AQUA + "" + ChatColor.BOLD + " Go watch @ www.twitch.tv/" + args[1] + "!");
     
  8. Offline

    nverdier

    You put args[1]. It should be args[0].
     
  9. Offline

    PerezHD

    @nverdier @PerezHD

    OMG, Thank you guys so much for helping me solve the issues with this plugin. I really do appreciate you guys taking the time to help me out. I know how much I am a noob and hopefully that would change soon. I am just going to start practicing more. I am tired of being at the bottom of the Bukkit chain! I will rise! Thank you guys. It works!
     
  10. Offline

    Forge_User_45064837 Retired Staff

    Moved to Bukkit Alternates.
     
  11. Offline

    nverdier

    I'm glad it worked but you really need to know WHY it worked. The last thing that I said was to change args[1] to args[0]. In any ArrayList, there is a specific index that is 'attached' to each object in it (args[n], where n is the index). It's just the order of it. The first index is 0, not 1 like you seem to have assumed. If you want to get the first thing in the list, you put args[0].
     
    PerezHD likes this.
Thread Status:
Not open for further replies.

Share This Page