[SOLVED] Interacting With a Button/Lever

Discussion in 'Plugin Development' started by hockeygoalie5, Jun 25, 2012.

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

    hockeygoalie5

    This question has been asked before, and seems to be one of the most difficult problems with the API I've come across. With (seemingly) no method to easily interact with a button or lever, I've resorted to trying to call everything manually. I've written this:
    Code:
    Block block = SurvivalGames.world.getBlockAt(new Location(SurvivalGames.world, rs.getDouble(1), rs.getDouble(2), rs.getDouble(3)));
    if(block instanceof Lever) {
        Lever lever = new Lever(Material.LEVER, block.getData());
        lever.setPowered(true);
        BlockRedstoneEvent toggle = new BlockRedstoneEvent(block, 0, 1);
        SurvivalGames.server.getPluginManager().callEvent(toggle);
        block.setTypeIdAndData(block.getTypeId(), lever.getData(), true);
    } else if (block instanceof Button) {
        Button button = new Button(Material.STONE_BUTTON, block.getData());
        button.setPowered(true);
        BlockRedstoneEvent toggle = new BlockRedstoneEvent(block, 0, 1);
        SurvivalGames.server.getPluginManager().callEvent(toggle);
        block.setTypeIdAndData(block.getTypeId(), button.getData(), true);
    }
    
    It simply does not change it at all. My goal here is to grab the location of the block from a database, and turn it on. Is the only way to do this to call the native BlockLever.interact() method? If it is, how would I go about getting the native methods into my plugin?
     
  2. Offline

    nisovin

    I do it this way:

    Code:
        public void toggleLeverOrButton(Block block) {
            net.minecraft.server.Block.byId[block.getType().getId()].interact(((CraftWorld)block.getWorld()).getHandle(), block.getX(), block.getY(), block.getZ(), null);
        }
    
     
  3. Offline

    hockeygoalie5

    Yes, and I saw other people do it this way as well. How do I get the net.minecraft.server package into my source? It does not come with the library.

    EDIT: I understand that net.minecraft.* is in the CraftBukkit jar, but when I try to use anything from it, I get compile errors and it doesn't work.

    Fixed it m'self, but thanks.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. hockeygoalie5
    You should tell what was the error and how you fixed it tough, it might help someone :)
     
  5. Offline

    hockeygoalie5

    I thought it would be a great idea to import net.minecraft.* rather than org.bukkit.craftbukkit.*
     
Thread Status:
Not open for further replies.

Share This Page