Problem with Events

Discussion in 'Plugin Development' started by RightLegRed, Jan 16, 2011.

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

    Archelaus

    I've got my plugin almost working. It gets loaded, but in game, nothing happens.

    Here's what I'm doing:

    Code:
        public void onBlockPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();
            Block block = event.getBlock();
            player.sendMessage(block.getType().name());
        }
    and

    Code:
        public void onCommand(PlayerChatEvent event){
            Player players = event.getPlayer();
            String message = event.getMessage();
            players.sendMessage("Hello" + players.getName());
            }

    in BlockListener and PlayerListener. In my Civilizations.java I've done this to register the events:

    Code:
    PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);


    Could anyone tell me why, when I place a block or say something, nothing happens?
     
  2. Offline

    redmasq

    I just started plugin writing today and ran into the same problem. I finally got it fixed by assuming that the javadocs were dead wrong and added a 'd' to the event in the listener. Use the following signature:
    public void onBlockPlaced(BlockPlaceEvent event);

    I'm not sure about onCommand, I haven't used it yet. BTW, if anyone sees an onSignChanged event, it'd be appreciated. Meantime, I guess I'll have to reverse engineer the class files or something. I hope its implemented.
     
  3. Offline

    Raphfrk

    They changed the names of the events to the present tense.

    onBlockPlaced -> onBlockPlace

    You may have an older version which still uses the old names.
     
  4. Offline

    Archelaus

    The
    Code:
    public void onBlockPlace(BlockPlaceEvent event);
    is actually from BigBrother. So it should work.


    Also, http://javadoc.lukegb.com/Bukkit/db/d26/interfaceorg_1_1bukkit_1_1block_1_1Sign.html
    --- merged: Jan 16, 2011 5:32 PM ---
    Ah OK, thanks. I'm currently using the latest build.
    --- merged: Jan 16, 2011 5:53 PM ---
    Sorry about this guys. But it gives me this error now

    Code:
    SEVERE: while scanning for the next token; found character      '\t' that cannot
     start any token (Is it up to date?)
    while scanning for the next token
    found character         '\t' that cannot start any token
     in "<reader>", line 3, column 7:
        main:
              ^
    
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.ja
    va:360)
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:18
    3)
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(P
    arserImpl.java:592)
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:163)
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132)
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :230)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:12
    2)
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
    
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseCons
    tructor.java:124)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:264)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:250)
            at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.
    java:24)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:64)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:115)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:80)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:41)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:153)
            at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:140)
            at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:104)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:177)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
    
     
  5. Offline

    redmasq

    I grabbed the jar on the site, but I guess I need to find a source repository or something. Thanks for the pointer to the sign block; I've seen that, however. Specifically, I'm trying to figure out what (if any) event is called when their is an edit of the sign's text. I'm hoping that I don't have to setup polling on another thread and do a custom event push or something silly like that. Sorry for the n00bishness, but new API, so still learning here.
     
  6. Offline

    eisental

    @RightLegRed this error means that you used a tab character in your plugin.yml
    You should use spaces instead.
     
  7. Offline

    Archelaus

    This was the problem, but I had accidentally backspaced the main: part of my .yml.

    Don't worry man, we're all learning. I don't think there are any text changed events at the moment though.


    I'm still experiencing nothing happening when placing a block.

    @redmasq, I think a way round there being no sign changer would be to see if there's something that happens every few ticks (e.g. time change or something) and use that along with "getText" to check the text against an array with the old text values in it.
     
Thread Status:
Not open for further replies.

Share This Page