Solved onPortalCreate

Discussion in 'Plugin Development' started by Vaughan, Nov 8, 2012.

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


    package me.amphios.amphiportal;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    public class AmphiPortalListener implements Listener
        public AmphiPortal plugin;
        public AmphiPortalListener(AmphiPortal p)
            plugin  = p;
        /*A Block array and String array are created with a size of 1*/
        public Block[] block = new Block[1];
        public String[] player = new String[1];
        /*Lister to PlayerInteractEvent*/
        public void onPlayerInteractEvent(PlayerInteractEvent e) {
          /*Check if player right clicked a block*/
          if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
            /*Check if player is holding flint and steel*/
            if(e.getPlayer().getItemInHand().getTypeId() == 259) {
              Block b = e.getClickedBlock();
              /*Check if block is obsidian*/
              if(b.getTypeId() == 49) {
                /*Set the first element of the array you created earlier*/
                block[0] = b;
                player[0] = e.getPlayer().getName();
                /*Create a delayed task that sets the arrays to null, so that there are no false positive when a portal is created*/
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                  public void run() {
                    block[0] = null;
                    player[0] = null;
        /*Listen to PortalCreateEvent*/
        public void onPortalCreateEvent(PortalCreateEvent e) {
          /*Check if the blocks involved in this event contain the block you added to the array in the previous event*/
          if(e.getBlocks().contains(block[0])) {
            /*Broadcasts the message with the players name*/
            Bukkit.broadcastMessage(ChatColor.DARK_RED + player[0] + " created a portal");
    one4me This is the Listener.
  2. Offline


    Now I'm not sure. I just copied your classes exactly how you posted them, compiled a new jar and it ran fine.
    Vaughan likes this.
  3. Offline


    Perhaps it's another plugin that's messing with it.. I'll disable all my other ones and try it.

    one4me Okay that's weird, I took all my plugins out apart from AmphiPortal and it worked, I started to put them back in one by one to see which one was causing the conflict but they're all fine and working together.. So. I haven't the foggyest but it works! Thank you very much dude!

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

Share This Page