Solved java.lang.ClassCastException in Plugin

Discussion in 'Plugin Development' started by vemacs, Oct 27, 2012.

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

    vemacs

    Hello,

    I've just written my first plugin, and it would seem to work (except for the PlayerChatEvent deprecation, but it should still work), but I get this in the console when it tries to start:

    Code:
    Could not load 'plugins\GamemodeDetector.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassCastException: class com.vemacs.GamemodeDetector.GamemodeDetector
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:154)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:227)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:203)
        at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
        at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
        at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:378)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.ClassCastException: class com.vemacs.GamemodeDetector.GamemodeDetector
        at java.lang.Class.asSubclass(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:144)
        ... 9 more
    Here's my plugin source (ignore the fact that I don't own vemacs.com, I just want to get it working):
    Code:
    package com.vemacs.GamemodeDetector;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChatEvent;
     
    @SuppressWarnings("deprecation")
    public class GamemodeDetector implements Listener {
     
        private GamemodeDetector plugin;
     
        public GamemodeDetector(GamemodeDetector instance) {
            plugin = instance;
        }
     
            @EventHandler
        public void onPlayerMessage(PlayerChatEvent E) {
                Player player = E.getPlayer();
                String playerName = player.getName();
                String message = E.getMessage().toLowerCase();
                if(message.contains("/gamemode")){
                Bukkit.broadcastMessage( playerName + "used the /gamemode command!");
            }
    }
    }
    And here's my plugin.yml:
    Code:
    name: GamemodeDetector
    main: com.vemacs.GamemodeDetector.GamemodeDetector
    version: 1.0
    The plugin.yml is in the package tree, not in the source tree. What's going wrong?
    Thanks for the help. I'm running the latest craftbukkit recommended.

    The project is attached (gamemodedetector.zip).
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    Your plugin is not a java plugin,
    Please refer to the documentation. Specifically you failed here
     
Thread Status:
Not open for further replies.

Share This Page