Problems with the new Event-System

Discussion in 'Plugin Development' started by Proctor, Jan 24, 2012.

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

    Proctor

    Hi,
    i've some big problems with the event system.
    I've looked before into the wiki-thread for the new event system,
    but 1st it's very confusing & 2nd i've tried a lot & become only some errors..
    (This plugin worked with no problems before the new event-system)

    Here is the mainclass:
    Code:
    /*
    * entity listener class
    *
    * author: Aron Heinecke
    *
    * version: v1.0
    */
    package me.Proctor.SignCommand;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SignCommand extends JavaPlugin {
     
        boolean vote_sun, vote_day, vote_jail;
        Logger log = Logger.getLogger("Minecraft");
     
        public void onEnable() {
            log.info("[blocknet-SignCommand] version "
                    + this.getDescription().getVersion() + "has been enabled.");
            log.info("[blocknet-SignCommand] (c) Aron Heinecke");
            getServer().getPluginManager().registerEvents(new SignCommandBlockListener(this), this);
        }
     
        public void onDisable() {
            log.info("[blocknet-SignCommand] has been disabled.");
        }
    }
    Here the BlockListener:
    Code:
    ยด/*
    * entity listener class
    *
    * author: Aron Heinecke
    *
    * version: v1.0
    */
    package me.Proctor.SignCommand;
     
    import org.bukkit.Material;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.inventory.ItemStack;
     
    public class SignCommandBlockListener implements Listener {
     
        public static SignCommand plugin;
     
        public SignCommandBlockListener(SignCommand instance) {
            plugin = instance;
        }
     
        @EventHandler
        public void onSignChange(final SignChangeEvent event) {
            Player pla;
            pla = event.getPlayer();
            String firstline;
            firstline = event.getLine(0);
            if (firstline.equals("[sc]")) {
                if (pla.hasPermission("signcommand.create")) {
                    event.getPlayer().sendMessage(
                            "[SignCommand] created sign command.");
                } else {
                    event.getBlock().setType(Material.AIR);
                    event.getPlayer()
                            .getWorld()
                            .dropItemNaturally(event.getBlock().getLocation(),
                                    new ItemStack(Material.SIGN, 1));
                    event.getPlayer()
                            .sendMessage(
                                    "[SignCommand] You dont have the permission to create this sign!");
                }
            }
        }
     
        @EventHandler
        public void onBlockBreak(final BlockBreakEvent event) {
            if ((event.getBlock().getState() instanceof Sign)) {
                Sign signObject = (Sign) event.getBlock().getState();
                if (signObject.getLine(0).equals("[sc]")) {
                    if (event.getPlayer().hasPermission("signcommand.delete")) {
                        event.getPlayer().sendMessage(
                                "[SignCommand] You deleted sign");
                    } else {
                        event.setCancelled(true);
                        event.getPlayer()
                                .sendMessage(
                                        "[SignCommand] You dont have the permissions to break this sign!");
                    }
                } else {
                }
            } else {
            }
        }
    }

    Here the PlayerListener:
    Code:
    /*
    * entity listener class
    *
    * author: Aron Heinecke
    *
    * version: v1.0
    */
    package me.Proctor.SignCommand;
     
    import org.bukkit.Material;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
     
    public class SignCommandPlayerListener implements Listener {
     
        public static SignCommand plugin;
     
        public SignCommandPlayerListener(SignCommand instance) {
            plugin = instance;
        }
     
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                Material block = event.getClickedBlock().getType();
                if (block == Material.SIGN_POST) {
                    Sign signObject = (Sign) event.getClickedBlock().getState();
                    if (signObject.getLine(0).equals("[sc]")) {
                        if (event.getPlayer().hasPermission("signcommand.use")) {
                            String command1 = signObject.getLine(1)
                                    + signObject.getLine(2) + signObject.getLine(3);
                            event.getPlayer().sendMessage(
                                    "[" + event.getPlayer().getName() + "] "
                                            + command1);
                            String pl = event.getPlayer().getName();
                            String command = command1.replace("%p%", pl);
                            Player pla = event.getPlayer();
                            pla.getServer().dispatchCommand(
                                    pla.getServer().getConsoleSender(), command);
                            event.getPlayer().sendMessage(
                                    "[SignCommand] executed command " + command);
                        } else {
                            event.getPlayer()
                                    .sendMessage(
                                            "[SignCommand] You dont have the permissions to use these signs!");
                        }
                    }
                }
                return;
            }
            return;
        }
    }
    
    Here the error-log:
    Code:
    2012-01-24 20:16:19 [SEVERE] Error occurred while enabling SignCommand v1.1 (Is it up to date?): org.bukkit.plugin.PluginManager.registerEvents(Lorg/bukkit/event/Listener;Lorg/bukkit/plugin/Plugin;)V
    java.lang.NoSuchMethodError: org.bukkit.plugin.PluginManager.registerEvents(Lorg/bukkit/event/Listener;Lorg/bukkit/plugin/Plugin;)V
        at me.Proctor.SignCommand.SignCommand.onEnable(SignCommand.java:23)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:230)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:970)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:190)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:173)
        at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:355)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:342)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:174)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    
    Please say me what I've to edit.. (I'll then do it into my big projekt too :D)
    I hope you help my, cause i really tried many solutions from the help-site & only seen errors.

    Proc
     
  2. Offline

    stelar7

    something tells me that this is the wrong plugin...
     
  3. Offline

    Proctor

    uh, you'r right, i edited & done right error inside (when the error here is done, i oculd copy the event handler into the (really) bigger plugin from them the error log was too)
     
  4. Offline

    nisovin

    Are you running an old CraftBukkit build?
     
  5. Offline

    stelar7

    the server is running an older build of craftbukkit
     
  6. Offline

    Proctor

    am i an idiot, or what? ( wondering why not seen this), i'll check and post if there is some more error, thanks for help, sry for my idiotic mistake..

    hm, ok no error, but the event isn't handelet/he doesn't interact, what is wrong in the event registration?
    something other, does i've to change something when i've an old "onCommand(..)" class, with th registraion/event? & how do i register more events? cause i've more then only 1 event-class-file and seems that i could only give him 1 by getServer().getPluginManager().registerEvents(..) or can i do for each class this?

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

Share This Page