Commands into listeners?

Discussion in 'Plugin Development' started by MrMag518, Oct 28, 2011.

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

    MrMag518

    Ok, so I am new to the command system and how they works, To be honest I am really new to bukkit to.. But This is something of the last "basic" bukkit function I need to learn. I have understood how to make a simple command in the main class, like a command that reloads the config file. But I want a command that enables something I got in one of my listeners(blocklistener).
    I have tried some few diffrent things, but I dont find any tutorial anywhere on this.
    Heres some of my code I ended up with: (It will look very newbie... something it).
    BlockListener:
    Code:
    package me.mrmag518.Test;
    
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockDamageEvent;
    import org.bukkit.event.block.BlockListener;
    
    public class TestBlockListener extends BlockListener {
        public static Test plugin;
        public TestBlockListener(Test instance)
        {
            plugin = instance;
        }
    
        @Override
        public void onBlockDamage(BlockDamageEvent event) {
            Player player = event.getPlayer();
            Block block = event.getBlock();
            Server server = player.getServer();
            World world = player.getWorld();
    
            if(player.performCommand("Superstick")) {
                if(event.getItemInHand().getType() == Material.STICK) {
                    event.setInstaBreak(true);
                } else {
                    //nothing
                }
            }
        }
    }
    And heres the registered command in the plugin.yml:
    Code:
    commands:
      superstick:
        description: Enable the superstick
        usage: "Usage: /<command>"
        aliases: [st]
    What I got out of this was that it first stood "unknown command" thingy, and nothing more.
    then I registered it in the plugin.yml and got: "Usage: /Superstick" and it instantbreaked blocks with the stick. But I hadn't done any command and the usage shit was spamming me.

    Any help please?
     
  2. Offline

    ItsHarry

    Well, use onCommand to get if the players types /superstick
    Log the player into a hashmap.

    When the onBlockDamage event is fired, check if the player who did it is in the hashmap, if he is, setInstaBreak(true), otherwise, don't do anything.
     
  3. Offline

    MrMag518

    @ItsHarry
    1. So im placing the onCommand into the listener?
    2. Little tutorial on Hashmap's pl0x :D

    please?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  4. Offline

    ItsHarry

  5. Offline

    MrMag518

    @ItsHarry
    But I dont know who of them? and where?
     
  6. Offline

    ItsHarry

    Use event.getPlayer();
    and to get the location use event.getPlayer().getLocation();
     
  7. Offline

    MrMag518

    @ItsHarry
    I mean, Where do I place the hashmap and what type of hashmap and where do I place the onCommand thing xD
     
  8. Offline

    ItsHarry

    The onCommand should go in the main class, did you read the tutorial I sent?
    http://wiki.bukkit.org/HUGE_Plugin_Tutorial

    There's also a tutorial on hashmaps in that link
     
  9. Offline

    nisovin

    This is basic Java and general programming stuff, it doesn't really have anything to do with Bukkit itself. You might consider reading some online tutorials, reading a book, taking a class, etc. It would really help you out.
     
Thread Status:
Not open for further replies.

Share This Page