Error occurred while enabling Plugin v1.1 (Is it up to date?)

Discussion in 'Plugin Development' started by Tw4n5il, Jan 3, 2021.

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

    Tw4n5il

    Hi, Ive recently started working on plugins, but when I try to update this 1 command, it seems to do this.

    Main Class:
    Code:
    package me.twansil.plugin;
    
    import me.twansil.plugin.commands.Config;
    import me.twansil.plugin.commands.Feed;
    import me.twansil.plugin.commands.Heal;
    import me.twansil.plugin.commands.god.God;
    import me.twansil.plugin.commands.god.GodOff;
    import me.twansil.plugin.events.Death;
    import me.twansil.plugin.events.Join;
    import me.twansil.plugin.events.Leave;
    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;
    
    public final class Plugin extends JavaPlugin {
        @Override
        public void onEnable() {
            // Plugin startup logic
            System.out.println( "The Plugin has started");
            getServer().getPluginManager().registerEvents(new Join(),this);
            getServer().getPluginManager().registerEvents(new Leave(),this);
            getServer().getPluginManager().registerEvents(new Death(), this);
            getCommand("god").setExecutor(new God());
            getCommand("feed").setExecutor(new Feed());
            getCommand("heal").setExecutor(new Heal());
            getCommand("godoff").setExecutor(new GodOff());
            getCommand("Config").setExecutor(new Config());
            getConfig().options().copyDefaults();
            saveDefaultConfig();
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    
            if(command.getName().equals("printMessageFromConfig")) {
                Player player = (Player) sender;
                String food = getConfig().getString("Food");
                int number = getConfig().getInt("Number");
                boolean Boolean = getConfig().getBoolean("Boolean");
                String thirditem = getConfig().getStringList("FoodList").get(2);
                player.sendMessage(ChatColor.DARK_PURPLE + "The food in the config.yml is " + ChatColor.RED + food);
            }else if(command.getName().equals("setFood")) {
                getConfig().set("Food", "Shrimp");
            }
        return false;
        }
    }
    Command Class:
    Code:
    package me.twansil.plugin.commands;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    
    public class Config implements CommandExecutor {
    
        Plugin plugin = me.twansil.plugin.Plugin.getPlugin(me.twansil.plugin.Plugin.class);
    
    
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    
            String food = plugin.getConfig().getString("Food");
    
            Player player = (Player) sender;
            player.sendMessage(food);
    
    
            return false;
        }
    }
    
    plugin.yml:
    Code:
    name: Plugin
    version: 1.1
    main: me.twansil.plugin.Plugin
    authors: [ Twansil ]
    description: Twans Plugin
    
    commands:
      god:
        description: Become invincible
        aliases: [invincible]
      feed:
        description: Feed yourself
        aliases: [food]
      heal:
        description: Heal yourself
        aliases: [health]
      godoff:
        description: Turn god off
        aliases: [nogod]
      printMessageFromConfig:
        description: Print Config message
      setFood:
        description: Set config food
    Config:
      description: Config command
    config.yml:
    Code:
    Food: 'Potato'
    Number: 125
    Boolean: true
    FoodList:
      - 'Pizza'
      - 'Orange'
      - 'Grape'
     
  2. Offline

    CraftCreeper6

    @Tw4n5il
    Why? Use a constructor and pass the instance of the main class instead.

    Also, give your main class a more meaningful and unique name, plugins with the same path to the main class with throw an error.
     
  3. Offline

    Tw4n5il

    I fixed it, kinda new to this whole thing, ty for the advice
     
  4. Offline

    marcelo.mb

    Please mark the thread as solved since your problem is solved.;)
     
Thread Status:
Not open for further replies.

Share This Page