Solved Connecting all classes to one main file!!!

Discussion in 'Plugin Development' started by DominicGamesHD, Jun 3, 2016.

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

    DominicGamesHD

    I have made everything in different classes so how do I make it for one main class???????
     
  2. Offline

    Xerox262

    @DominicGamesHD Sorry, what do you mean? You want all classes to be able to access all other classes? Pass instances around.
     
    teej107 likes this.
  3. Offline

    DominicGamesHD

    Like in the plugin.yml it asks for a main file how do I link all of them to one main file?
     
  4. Offline

    I Al Istannen

    @DominicGamesHD
    You can't. There is only ONE main class. That is the point of it actually. Why do you want that?
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. Offline

    DominicGamesHD

  7. Offline

    timtower Administrator Administrator Moderator

  8. Offline

    DominicGamesHD

    @timtower How else would I link all the classes in the plugin.yml then?
     
  9. Offline

    timtower Administrator Administrator Moderator

    @DominicGamesHD You don't need to, that is the beauty of it.
    You only need the main class in the plugin.yml, the rest is handled by Bukkit.
     
  10. Offline

    DominicGamesHD

    So which one would be the main class but surely I would have to connect the command classes to one main one?
     
  11. @DominicGamesHD The main class should extend JavaPlugin. And no, you don't need to connect all of your commands to the main class unless you're using variables/methods from it.
     
  12. Offline

    DominicGamesHD

    After lots of research I cam across the line
    Code:
    getCommand("Command Name").setExecutor(new Class_Name );
    Can someone help me place this???
     
  13. @DominicGamesHD That's what you would need to put on your onEnable. It's pretty explainetory.
     
  14. Offline

    DominicGamesHD

    So I but it in the onEnable and fill it in like this?
    My Main file:
    Code:
    package me.gothdom.cfe.main;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    import me.gothdom.cfe.commands.SpeedAll1;
    
    public class CustomFactionsExtra extends JavaPlugin {
         public void onEnable() {
            getCommand("speed1").setExecutor(new SpeedAll1());
        }
    }
    
    The SpeedAll1 class:
    Code:
    package me.gothdom.cfe.commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class SpeedAll1 extends JavaPlugin {
        public void onEnable(){
             
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            for (Player players : Bukkit.getOnlinePlayers())
            if (cmd.getName().equalsIgnoreCase("speed1")) {
                sender.sendMessage(ChatColor.AQUA + "Given all players Speed 1!");
                players.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000, 1));
                players.sendMessage(ChatColor.RED + "[" + ChatColor.YELLOW + sender.getName() + ChatColor.RED + "]" + " "
                        + ChatColor.AQUA + "Has given you speed 1!");
            }
           
            return false;
        }
    }
    Code:
    package me.gothdom.cfe.commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class SpeedAll1 extends JavaPlugin {
        public void onEnable(){
             
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            for (Player players : Bukkit.getOnlinePlayers())
            if (cmd.getName().equalsIgnoreCase("speed1")) {
                sender.sendMessage(ChatColor.AQUA + "Given all players Speed 1!");
                players.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000, 1));
                players.sendMessage(ChatColor.RED + "[" + ChatColor.YELLOW + sender.getName() + ChatColor.RED + "]" + " "
                        + ChatColor.AQUA + "Has given you speed 1!");
            }
           
            return false;
        }
    }
    Plugin.yml:
    Code:
    name: CustomFactionsExtra
    version: 0.1
    main: me.gothdom.cfe.main.CustomFactionsExtra
    commands:
       speed1:
         description: Gives speed
    Please point out anything I have done wrong! and explain to me why it finds the file and still doesn't work!
     
  15. Well for starters, only your main class needs to extend JavaPlugin. Second, why are you looping through all of the online players and then checking if the command equals "speed1"? Also, your syntax in the loop is completely wrong. Learn Java before learning Bukkit. Why are you returning false?
     
  16. Offline

    DominicGamesHD

    1. I find it easier to learn java by programming stuff like this 2. I have done bukkit api before I am just picking it all up again
     
  17. Offline

    Zombie_Striker

    @DominicGamesHD
    You can only have on class that extends JavaPlugin. Those other classes should implement CommandExecutor, and should not have any onEnable methods.
     
  18. Offline

    DominicGamesHD

    @Zombie_Striker So I do that and then it should work?

    Thanks for all the help guys!!!!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page