Solved Looking for block and its data.

Discussion in 'Plugin Development' started by Alayathekid, Jun 13, 2015.

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

    Alayathekid

    I have been making several small plugins to help run a server I have, but today I decided to make a flinger where if you stand in a comparator you will get launched the way it is facing. However, I am having trouble getting the block data in an if statement. This is what I have so far. (Also I'm new to programming in java, so if you could send me a good guide then thank you.)
    Code:
       
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
        }
       
        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerMoveEvent(PlayerMoveEvent event) {
        Player player = event.getPlayer();
        if (player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.REDSTONE_COMPARATOR_OFF) //trying to add the block data in here {
             player.setVelocity(new Vector(2, 2, 2));
        }
        }
    }
    Ignore the Vectors please, I'm just trying to get it to work some what right now. Also, would it be .DOWN or .SELF for a comparator?
     
  2. Offline

    Zombie_Striker

    Finally, someone on this forum that wants to learn : Hers the link

    The players location starts at their feet, so if they are standing on the comparator you should just be able to do the following:
    Code:
    if(Player#getLocation().getBlock() != null && Player#getLocation().getBlock().getType == Material.REDSTONE_COMPARATOR_OFF)
    I would suggest that after you have read the link and fully understand Java, you would make a method which returns the vector (this would be cleaner than adding a bunch of if statements in your code).
     
  3. Offline

    Alayathekid

    Hmmm u don't seem to get the question because I'm looking for the blocks data and ur code is practically the same as mine...
     
  4. Offline

    Zombie_Striker

    @Alayathekid
    What you're doing by using the .getRelitive() method is actually getting the block not at your feet, but underneath your feet. So here's an example of what you're doing; If a player is standing on top of a comparator, and the block below the comparator is a stone block, what you're getting is the stone block. Just remove the .getRelitive method and it will work.
     
  5. Offline

    NathanWolf

  6. Offline

    Alayathekid

    thank you NathanWolf I don't think Zombie_Striker understood my actual question...

    Wait one second can you give an example of this?

    Oh, ok I found out how to fix it myself thanks for the... uh... suggestions, but I feel that you guys didn't know what I was trying to do... and weren't very descriptive
     
    Last edited: Jun 19, 2015
  7. Offline

    Zombie_Striker

    @Alayathekid
    Seems I overlooked the "Block Data" part of your question. Yeah, even still the .getRelitive wont' help you and might even break what you're doing. To get the direction a comparator you can use Comparator#getFacing()
     
  8. Offline

    Alayathekid

    i told u i figured it out also .getRelitive works just fine my code is ok so just leave me alone please *cries* any thank you for trying to help
     
Thread Status:
Not open for further replies.

Share This Page