Plugins not Working?

Discussion in 'Plugin Development' started by S1ant, Feb 23, 2017.

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

    S1ant

    Ok, to get straight to the point, the plugins I've been making haven't been working, I don't know what it is, they just haven't been working, here is the plugin.yml and the code! There is no error message in console and the command is tabbable so I don't really know what happened! D:
    Code:
    package me.s1ant.diamondchances;
    
    import java.util.Random;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class Main extends JavaPlugin{
    
        public void onEnable(){
    
            saveConfig();
        }
    
        public void onDiable(){
    
            saveConfig();
        }
    
    
    
        public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args){
      
            if(sender.getName().equalsIgnoreCase("diamond")){
                if(args.length == 0){
              
               
                    Random random = new Random();
                    int Chance = random.nextInt(4);
                    if(Chance == 4){
                String c4 = new String(getConfig().getString("command4"));
                    getServer().dispatchCommand(getServer().getConsoleSender(), c4 + " " + sender.getName());
                    sender.sendMessage(ChatColor.RED + "Suprise!");
                    }
                    if(Chance == 3){
                        String c3 = new String(getConfig().getString("command3"));
                        getServer().dispatchCommand(getServer().getConsoleSender(), c3 + sender.getName());
                        sender.sendMessage(ChatColor.RED + "Suprise!");
                    }
                    if(Chance == 2){
                        String c2 = new String(getConfig().getString("command2"));
                        getServer().dispatchCommand(getServer().getConsoleSender(), c2 + sender.getName());
                        sender.sendMessage(ChatColor.RED + "Suprise!");
                    }
                    if(Chance == 1){
                        String c1 = new String(getConfig().getString("command1"));
                        getServer().dispatchCommand(getServer().getConsoleSender(), c1 + sender.getName());
                        sender.sendMessage(ChatColor.RED + "Suprise!");
                    }
                    if(args.length <= 1){
                        if(args[0].equalsIgnoreCase("reload")){
                            if(sender.hasPermission("cfdiamond.reload")){
                                reloadConfig();
                                saveConfig();
                            }
                      
                        }
                  
                  
                    }
          
                }
          
          
            }
      
      
            return true;
        }
    
    }
    
    Then the Plugin.yml:
    Code:
    name: DiamondChances
    main: me.s1ant.diamondchances.Main
    version: 1.0
    author: S1ant
    description: Chances!
    commands:
      diamond:
    I know that this post sounds pretty noob, but I'm really stumped :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 23, 2017
  2. Offline

    Ragnarok_

    I don't know if this is the solution, but I think for the command part, you have sender.cmd, you should probably try cmd().getName
     
  3. Offline

    S1ant

    OMG what was I thinking xD Sorry everyone I know the problem xD I'm so noob like I said lol....
    Ok That hasn't worked either :/
     
    Last edited: Feb 23, 2017
  4. Offline

    Zombie_Striker

    @S1ant
    Order is important. Because you mixed up Command and CommandSender, bukkit is not seeing this as a command. The name and the order of the parameters needs to be correct in order for the command to work.
     
  5. Offline

    S1ant

    So It has to BE:
    Code:
    public Boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
    Is what your saying, because I do it like this all the time....

    I mean I do it the way I did It originally the first time.
     
  6. Offline

    Zombie_Striker

    @S1ant
    Yes. It has to be that way.

    If your problem has been solved, mark this thread as solved.

    BTW:
    Can be easily reduced to:
    Also, all variable names should start with a lower case, so Chance should be "chance"
     
    mehboss likes this.
  7. Offline

    S1ant

    Zombie there is more than one command slot in the config.yml it holds 4 commands. I got it to work then it gives me this error message. I was just learning to read them as I was messing around with my plugin, but I can't exactly crack this one it runs the command fine, but there is something more I'm missing... I can feel it

    Code:
    S1ant issued server command: /diamond
    [19:32:38 INFO]: Âșc THIS STILL WORKS
    [19:32:38 INFO]: CONSOLE issued server command: /bc xD S1ant
    [19:32:38 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'diamond' in plugin DiamondChances v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_73]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_73]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
            at me.s1ant.diamondchances.Main.onCommand(Main.java:52) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            ... 14 more
    ok, I had to use my brain D: but I eventually got it!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 23, 2017
  8. Offline

    Zombie_Striker

    @S1ant
    Why are you still on 1.8? Please read this.

    If your problem has been solved, mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page