Help in code please!

Discussion in 'Spigot Plugin Development' started by Ognjen-123, Jul 1, 2018.

  1. Hello guys i'm a bit new in coding so i wanted to ask for help for one thing...
    I want to make a plugin that allows player when he enters a command (/card nation human) to set a spawnpoint for him only on specific coordinates..
    One more thing...When i do that it just block off the command from a real plugin here is a pictures :
    This is a what shoud look like when command /card is entered:
    Screenshot_1.png
    http://prntscr.com/k1bsz2
    But when i do it with my plugin that sets an custom spawn point when command /card nation human is entered it does nothing...
    here is a picture of my code: Screenshot_2.png http://prntscr.com/k1bsvy
    So if anybody could help me i would appreciate a lot!
     
  2. First of all; do you have a Main class that runs the onEnable method? Do you have a plugin.yml and did you register your command? By the way you'll need to implement CommandExecutor in the 'custom' class to be able to register your command.

    EDIT: I see this class extends JavaPlugin, so I kinda understand why it's not working. Run the onEnable method in where you register the command. Don't forget about the plugin.yml! It's required to make this work.
     
  3. Hello...Thank you for your fast replay...First what do i need onenable method for this type of thing and yes i have plugin.yml and registered command there and can you show me where can i found a tutorial about commandexecutor
     
  4. Tutorials about Spigot plugin development can be found in the wiki section and on YouTube of course. Here's one: Bukkit Coding - Commands


    You'll need the onEnable() method for every spigot plugin. Else you're not able to load and run classes, make commands work or listen to events.
     
  5. Thanks for your help!
     
    • Friendly Friendly x 1
  6. This is not needed in all cases. This is one of those cases (the onCommand method is in the main class).

    This is important, yes. But you don't have to register the command in onEnable if the main class has the onCommand.

    The "custom" class is the main class (see it extends JavaPlugin?). He does not need a CommandExecutor because JavaPlugin already extends it, which is why it has an onCommand method. And as stated, it doesn't need to be registered to a different executor because the main class has already registered it.

    What? This is all wrong information.. See above ^

    This is the only thing correct in your entire post. ;)

    @Ognjen-123 you dont need to check the command name if this is your only command registered in plugin.yml. It would be wise to also show your plugin.yml so we can verify it has no issues. You code looks fine, otherwise. I'm curious why you think it's not working? You dont have the command output anything to the CommandSender as feedback. All it does is change the world's spawn point. How do you know it wasn't set?
     
    • Informative Informative x 1
  7. Haha I didn't know you didn't need to register the commands if you're running them in your main class, as I'm used to using different classes to manage commands and events.

    "He does not need a CommandExecutor because JavaPlugin already extends it, which is why it has an onCommand method." Ahhh
     
  8. Hey! Thanks for the replay...I test it out but i think i made a mistake somewhere so if you could check it out here is a pictures:
    Screenshot_3.png

    and when i type in chat /card it does not pop up anything not even a blank line..
    Screenshot_4.png
    EDIT: Also i tried removing the plugin and typing /card its working just fine like its meant to..I am thinking its broken because command card is used by 2 diffrent plugins and my question was can i make a command work with both plugins
     
  9. Thats because you didnt code it to output anything. If you want the command to send some feedback you have to use something like this:

    Code (Java):
    sender.sendMessage("World spawn set.");
     
  10. Tried that too..but still it is not working..
    EDIT: it is not outputing anything...like nothing at all
     
  11. It looks like you used 4 spaces in the plugin.yml instead of 2. That could be the reason why it isn't working, but I guess you should've received an error too then. Or I am blind.

    I'm not sure how to give a certain plugin priority on executing a command, but once you got to that, you can make the plugin with priority run the command in the other plugin by using the Player.performCommand(name) method. Run the command "/<pluginname>:command" and you're good.
     
    #11 sd_master92, Jul 1, 2018
    Last edited: Jul 1, 2018

  12. No errors at console..And as i'm considered i think you need to use tab which is 4 spaces (but tab won't work at plugin.yml so i just pressed space 4 times)
     
  13. Show your updated code and plugin.yml. Use [ code ] blocks instead of screenshots, please.

    Number of spaces doesnt really matter either, as long as they are uniform and not tabs. 2 is the "normal" thing, but its not a requirement.
     
    • Informative Informative x 1
  14. More new info :D
     
  15. Code (Text):

    name: Custom
    main: ogi.custom
    version: 1.0
    authors: [ogi]
    description: >
    commands:
        card:
            description: random
            usage: /<command>
    ]

    And class


    package ogi;

    import org.bukkit.Bukkit;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    import net.minecraft.server.v1_12_R1.AdvancementProgress.a;

    public class custom extends JavaPlugin {
       

        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

                if(cmd.getName().equalsIgnoreCase("card")) {
                    World world = Bukkit.getWorlds().get(0);
                    world.setSpawnLocation(100, 100, 100);
                    sender.sendMessage("World spawn set.");
                    return true;
                }

            return true;
        }
    }
     
  16. Whats the deal with that? Seems like this would prevent the plugin from loading. Have you checked the startup log for errors on boot? Or checked /plugins command to see if your plugin is successfully loaded?
     
  17. Actually it says description: random
    and yes i double checked console and checked plugins too...
     
  18. That's not what our eyes see ;p
     
  19. don't know why ....
    Screenshot_5.png
     
  20. Sorry, I seem to be misunderstanding something... Is the plugin actually loading? Like when you reload the server the plugin is activating and enabling? If so, how do you know?

    Earlier you mentioned how the first plugin might break when you do the command because the same command is being used in two places. Have you tried an EventHandler I think it is something like PlayerCommandPreProcessEvent or something like that? If you try listening to when a player uses a command and you check that the command is equal to "card" you can then run the code without having to worry about conflicting with another plugin.