Code Error

Discussion in 'Plugin Development' started by Pocket_LucaYT, Jan 2, 2023.

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

    Pocket_LucaYT

    I wrote this code:
    Code:
    package cl.chunkloader;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Chunk;
    import org.bukkit.World;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    
    public class ChunkLoader implements Listener {
    
    public ChunkLoader(Bukkit plugin) {
    Bukkit.getPluginManager().registerEvents(this, plugin);
    }
    
    public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    Entity entity = event.getRightClicked();
    
    if (entity.getType() == EntityType.VILLAGER && entity.isInsideVehicle()) {
    World world = entity.getWorld();
    Chunk chunk = world.getChunkAt(entity.getLocation());
    chunk.load()
    }
    }
    }
    In the class "ChunkLoader(Bukkit plugin)" "plugin" is marked as an error. When I let the project build, this error comes up: incompatible types: org.bukkit.Bukkit cannot be converted to org.bukkit.plugin.Plugin I have no idea how to fix it. I hope one of you can help me.
     
    Last edited by a moderator: Jan 2, 2023
  2. Offline

    timtower Administrator Administrator Moderator

    @Pocket_LucaYT Then don't pass Bukkit along as your plugin instance?
     
  3. Offline

    DopeBrot

    use ChunkLoader(Plugin plugin)
     
  4. Offline

    Pocket_LucaYT

    That worked, but now the next problem has occurred. When I load the plugin on the server and start it, the plugin is not activated.

    Here is the log from the server:
     

    Attached Files:

    Last edited: Jan 3, 2023
  5. Offline

    DopeBrot

    the class cl.chunkloader.ChunkLoader needs to extend JavaPlugin
    something like this:
    Code:
    public class ChunkLoader extends JavaPlugin {
     
  6. Offline

    Pocket_LucaYT

    Unfortunately this did not work DopeBrot
     
  7. Offline

    DopeBrot

    Your Main class should extend JavaPlugin and register events there, something like this:
    Code:
    public class Main extends JavaPlugin {
    
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(new Foo(),this);
        }
    }
    The class where you have your listener should look something list this:
    Code:
    public class Foo implements Listener {
        public void bar(PlayerJoinEvent event) {
            event.getPlayer().sendMessage("Welcome!");
        }
    }
     
  8. Offline

    Pocket_LucaYT

    The problem is that the main class already says "implements listener". If I replace this with extends JavaPlugin, this in public ChunkLoader is again marked as an error
     
  9. Offline

    timtower Administrator Administrator Moderator

    You can have both...
     
  10. Offline

    Pocket_LucaYT

    That worked but here is the next error:
    Code:
    Could not load 'plugins/ChunkLoader-1.0-SNAPSHOT.jar' in folder 'plugins'>
    org.bukkit.plugin.InvalidPluginException: Abnormal plugin type
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:83) ~[spigot-api-1.19-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:145) ~[spigot-api-1.19-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:394) ~[spigot-api-1.19-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:301) ~[spigot-api-1.19-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.craftbukkit.v1_19_R1.CraftServer.loadPlugins(CraftServer.java:412) ~[spigot-1.19-R0.1-SNAPSHOT.jar:3553-Spigot-14a2382-ef09464]
    at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:224) ~[spigot-1.19-R0.1-SNAPSHOT.jar:3553-Spigot-14a2382-ef09464]
    at net.minecraft.server.MinecraftServer.v(MinecraftServer.java:966) ~[spigot-1.19-R0.1-SNAPSHOT.jar:3553-Spigot-14a2382-ef09464]
    at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:291) ~[spigot-1.19-R0.1-SNAPSHOT.jar:3553-Spigot-14a2382-ef09464]
    at java.lang.Thread.run(Thread.java:833) [?:?]
    Caused by: java.lang.InstantiationException: cl.chunkloader.ChunkLoader
    at java.lang.Class.newInstance(Class.java:639) ~[?:?]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:79) ~[spigot-api-1.19-R0.1-SNAPSHOT.jar:?]
    ... 8 more
    Caused by: java.lang.NoSuchMethodException: cl.chunkloader.ChunkLoader.<init>()
    at java.lang.Class.getConstructor0(Class.java:3585) ~[?:?]
    at java.lang.Class.newInstance(Class.java:626) ~[?:?]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:79) ~[spigot-api-1.19-R0.1-SNAPSHOT.jar:?]
     
    Last edited by a moderator: Jan 6, 2023
  11. Offline

    timtower Administrator Administrator Moderator

    DopeBrot likes this.
Thread Status:
Not open for further replies.

Share This Page