1.8.8 i cant hooking my Api

Discussion in 'Spigot Plugin Development' started by woxz, Oct 23, 2020.

  1. First i wanna say sorry for my bad english,

    im trying make my custom api but i cant hooked.

    Error;
    Error:(15,41) java: package com.mjava.mixer.titanapi.titanapi does not exist
    Code (Java):
    import com.mixer.titan.titan.TitanAnti.*;
    import com.mixer.titan.titan.TitanAnti.Crash.A1;
    import com.mixer.titan.titan.TitanAnti.Crash.A2;
    import com.mixer.titan.titan.TitanAnti.Crash.A3;
    import com.mixer.titan.titan.TitanAnti.Crash.A4;
    import com.mixer.titan.titan.TitanManager.*;
    import com.mixer.titan.titan.TitanCommands.Operators;
    import com.mixer.titan.titan.TitanCommands.TAnnouncer.TitanAnnouncerMain;
    import com.mixer.titan.titan.TitanRunTasks.TpsCount;
    import com.mixer.titan.titan.TitanStaff.ChatClear;
    import com.mixer.titan.titan.TitanStaff.StaffChat;
    import com.mixer.titan.titan.TitanSubCommands.*;
    import com.mjava.mixer.titanapi.titanapi.TitanAPI;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.InvalidConfigurationException;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scheduler.BukkitTask;
    import org.bukkit.event.Listener;

    import java.io.File;
    import java.io.IOException;
    import java.util.List;

    public final class Titan extends JavaPlugin implements Listener {

        private TitanAPI api = (TitanAPI) Bukkit.getServer().getPluginManager().getPlugin("TitanAPI");
     
  2. 1. Is the API a valid standalone project?
    2. did you make sure that the API is loaded before the plugin?
    3. did you add the API to your classpath?
     
  3. 1. Yes, is that my project
    2. no im not sure
    3. Yes im sure
     
  4. Are you using a Build-tool like Maven or Gradle? If so, a lot of people can help you, if not, you should :p
     
  5. Is that an error from the server console or IDE/Compiler?
     
  6. You need to make sure the classes from the api you're using are visible to the classloader of your plugin.
    More concretely this means you need to either:
    • put those classes on the classpath
    • put those classes on the module path
    • put them in another plugin
    • bundle them with your own plugin (this process is known as 'shading' if you're using a build tool such as Maven or Gradle)
     
  7. From Ide/Compiler
     
  8. Your IDE says the package “does not exist.” The IDE only knows about the libraries and classes that you tell it to use.

    The Java library is called the JDK (to be more precise, it is bundled or it comes with the JDK, but in this case the difference doesn’t matter). Generally, many IDEs will know about the JDK that you installed on your computer or they might bundle the JDK along with the IDE download. The JDK classes are automatically added by your IDE, which is why you can use “import java.io.File,” for example.

    I noticed you also have some Bukkit imports. Does your IDE tell you those imports exist? If so, you must have added the Spigot API somehow to your project’s dependencies. You need to follow the same process for your API. Add a dependency to your API through the IDE’s project settings. You can look up how to do this in your IDE’s documentation (again, it is the same process for including the Spigot API. If you are following the same steps, it means you are on the right track).

    As other commenters have suggested, you may also want to take a look at using Maven or Gradle. These are build systems that allow you to manage your dependencies more effectively.
     
  9. Try defining the api in your onEnable method.

    The onEnable method of plugins you depend on will be called before the onEnable of your plugin, but classes do not. Therefore, your plugin is probably trying to load an unloaded plugin, which, naturally, does not work.

    Startup sequence in a nutshell:
    1. Loading 'main' classes (class pointed to from the plugin.ym of all pluginsl).
    2. Checking which plugins have to be loaded first.
    3. Call the onEnable method for all classes in a specific order.