Pluging creat help!

Discussion in 'Plugin Development' started by fcbarcelona25, Dec 13, 2016.

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

    fcbarcelona25

    Hey! Could any help my creat an plugin that checks players gamemode?
     
  2. Offline

    timtower Moderator Moderator

    @fcbarcelona25 What do you have already?
    What do you need help with?
     
  3. Offline

    fcbarcelona25

    @timtower
    I created the plugin.yml file, but I dont know to setup the code.
    PS: I sort of knew to plugin development
     
  4. Offline

    timtower Moderator Moderator

    @fcbarcelona25 Sort of new or totally new?
    Do you know the java basics?
    Did you follow the plugin tutorial on the wiki?
     
  5. Offline

    fcbarcelona25

    totally new!
    I know the basics yes
    and I followed the tutorial on the wiki
    @timtower
     
  6. Offline

    timtower Moderator Moderator

    @fcbarcelona25 Then you should be able to create a plugin with a command that says hi to the user.
     
  7. Offline

    fcbarcelona25

    @timtower yes, I made a plugin that show a message!
    This is the one I made:
    Code:
    public boolean onCommand(CommandSender sender, Command command, String label,String[] args) {
    
            if (command.getName().equalsIgnoreCase("testcommand")) {
    
                sender.sendMessage("You ran /testcommand");
    
                return true;
    
            }
    
            return false;
    
        }
    
    }
     
  8. Offline

    timtower Moderator Moderator

  9. Offline

    fcbarcelona25

  10. Offline

    timtower Moderator Moderator

  11. Offline

    fcbarcelona25

    @timtower is this correct?
    Code:
    public boolean onCommand(CommandSender sender, Command command, String label,String[] args) {
    
            Player target = (Bukkit.getServer().getPlayer(args[0]));
    
            if (command.getName().equalsIgnoreCase("testcommand")) {   
    
                sender.sendMessage("You ran /testcommand");
                }
    
            if (target == null){
    
                sender.sendMessage(args[0] + " is not online!");
    
                return true;
    
            }
        } 
    
        return false;
    
    }
     
  12. Offline

    timtower Moderator Moderator

  13. Offline

    fcbarcelona25

    I ran the command without arguments an got "an internal error occured while attempting to perform command"
    @timtower
     
  14. Offline

    timtower Moderator Moderator

  15. Offline

    fcbarcelona25

    is it the Check the arguments length I need to insert?
     
  16. Offline

    timtower Moderator Moderator

    @fcbarcelona25 Based on the ArrayOutOfBoundsException that you are getting: yes
     
  17. Offline

    fcbarcelona25

    @timtower if I want to reload the plugin, and only this plugin. How can I do that?
     
  18. Offline

    Zombie_Striker

    @fcbarcelona25
    If you want to make plugins, you need to know two things: How to write in Java and how to use google. From what you posted and the questions you asked, I don't think you truly know the basics (not encapsulating the command if check, not knowing to post the full error log, not knowing how to solve AOOBEs). I recommend fully understanding how to operate in Java first before working on bukkit, as most of these questions should be covered in any tutorial.

    Also, most of your questions could be answered with a google search. When it comes to trying to learn something new, this is what you should be doing first.

    Your question: There should be no reason you will need to actually reload your plugin. Just reset all the variables inside the plugin. If you really want to reload the plugin, the following should work:
    1. Create a boolean field. This represents if the plugin is being reloaded, or if the server is shutting down. This will automatically by set to false.
    2. use this.getPluginLoader to get the plugin loader.
    3. Unload the plugin.
    4. Then, go into the onDisable. If the boolean is equal to true (it is being reloaded), get the pluginloader again and enable this plugin.
     
  19. Offline

    fcbarcelona25

    @Zombie_Striker @timtower So I have looked at some tutorials on youtube and on google. But I have a pice of code witch goes as following:
    Code:
    if(commandLabel.equalsIgnoreCase("hurt"))
    
                {
    
                    if(Bukkit.getPlayer(args[0]) != null )
    
                    {
    
                        Player playerToHurt = Bukkit.getPlayer(args[0]);
    
                        double damageAmmount = Double.parseDouble(args[1]);
    
                        playerToHurt.damage(damageAmmount);
    
                        playerToHurt.sendMessage(ChatColor.RED + "You were hurt by " + player.getName() );
    
                    }
    
                    else player.sendMessage(ChatColor.RED + "Cant't find player " + args[0]);
    
                }
    
            return true;
    Now the part where its says "Bukkit.getPlayer", I get an error saying:
    "The method getPlayer(String) from the type Bukkit is deprecated" what can I replace that with? Now I know that Mojang have gone over to use UUID since you can change username.
     
    Last edited by a moderator: Dec 14, 2016
  20. Offline

    timtower Moderator Moderator

  21. Offline

    fcbarcelona25

    Well, I ignored the warning, but still cant run the command

    "Caused by: java.lang.ArrayIndexOutOfBoundsException: 0

    at me.ShadowGuardians.Pratice.Main.onCommand(Main.java:38) ~[?:?]"

    I have written everything in the same way as in the tutorial I saw

    EDIT: I fix the problem, I had forgot to enter the command correctly in the plugin.yml xD

    @timtower

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

    mythbusterma

    @fcbarcelona25

    You're likely still going to have the issue.

    That means you're not actually checking to see if the player passed an argument to the command before trying to use the argument.
     
  23. Offline

    fcbarcelona25

    So if check if the player passed an argument it should work?
    @mythbusterma

    EDIT: I saw that I had missed a line of code earlier and added: "if(theSender instanceof Player)" but even adding that still gives me that warning on "Bukkit.getPlayer()"
     
    Last edited: Dec 14, 2016
  24. Offline

    mythbusterma

    @fcbarcelona25

    You can ignore that warning, its just to bring attention to the fact that UUIDs exist.

    Yes, you just need to see if an argument is being passed at all.
     
  25. Offline

    FabeGabeMC

    He's not even checking if there is a second argument.
    Remember, if you plan to become the main developer for a server, there are going to be players that will try to find an exploit or bug in the code.
     
Thread Status:
Not open for further replies.

Share This Page