Getting the x of a entity

Discussion in 'Plugin Development' started by RedstoneForDayz, Sep 2, 2014.

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

    RedstoneForDayz

    I need help with my code, I need to find the x of a entity, so when they are at the certain x location, pvp is disabled. Here is my code:
    Code:java
    1. @EventHandler(priority = EventPriority.HIGH)
    2. public void onPvp(EntityDamageByEntityEvent e) {
    3. Entity player = (Entity) e.getEntity();
    4.  
    5. e.setCancelled(true);

    How could I change the e.getEntity(); to e.getX();? I know they are different events, but if there is any possible solution to this, please respond.
     
  2. e.getLocation().getX();
     
  3. Offline

    mine-care

    umm may i ask ( i might be wrong) but doesnt e.getEntity() return Entity object? soo if yes why casting?
    Entityplayer = (Entity) e.getEntity(); --> Entity player = e.getEntity();
    player?
     
  4. Offline

    RedstoneForDayz

    This is what I got after correcting everything:
    Code:java
    1. double p = e.getEntity().getLocation().getX();

    Does this look right?
     
  5. Offline

    AragurLp

    RedstoneForDayz
    Yes it might be right.

    But here is the question if you want just the rounded X Location or the excatly X Location.
    If you just want the rounded you need to do e.getEntity().getLocation().getBlockX();
     
  6. Offline

    RedstoneForDayz

    How would I make it so if the player is at x = 70, then cancel the event?
     
  7. Offline

    xTigerRebornx

  8. Offline

    RedstoneForDayz

    If I want to do something like
    Code:java
    1. if(e.getLocation().getX()){
    it says cant convert a double to a boolean. How should I fix this?
     
  9. Offline

    hintss

    You learn java
     
    AdamQpzm and Zupsub like this.
  10. Offline

    SmooshCakez

    What exactly are you trying to accomplish with this? if (e.getLocation().getX())
     
  11. Offline

    Skionz

    @RedstoneToDayZ
    You can't just do
    Code:
    if(e.getLocation().getX()){
    It has to be comparing X to something like this
    Code:
    if(e.getLocation().getX() == 1.2345){
     
  12. Offline

    Plo124

    RedstoneForDayz if (entity.getLocation().getBlockX() >= 70){
    // Do something
    }
     
  13. Offline

    Zupsub

    Skionz
    Plo124

    Don't spoonfeed if it is totally clear, that the OP hasn't knowledge of basic programming nor java.

    @OP: You can't program a bukkit plugin without knowing java!
     
    AdamQpzm and hintss like this.
Thread Status:
Not open for further replies.

Share This Page