Factions plugin, Enderpearl

Discussion in 'Plugin Development' started by EliteGuy, Jul 19, 2016.

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

    EliteGuy

    I'm coding a plugin which only allows the Player to throw Enderpearls into the faction WarZone, Wilderness and into his own Faction-land.
    I have no Idea how to get the Players Faction.
    I'm using ProjectileHitEvent, in this Event i cant use e.setCancelled(true); and i dont even know if I'm doing it right.
    I've already added factions and MassiveCraft in Build Path.

    my code:

    @EventHandler
    public void onHit(ProjectileHitEvent e) {
    if(e.getEntity() instanceof EnderPearl) {
    Player p = (Player) e.getEntity().getShooter();
    Location loc = e.getEntity().getLocation();

    int x = (int) loc.getX();
    int y = (int) loc.getY();
    int z = (int) loc.getZ();

    Location loc1 = new Location(Bukkit.getWorld("world"), x, y, z);
    Faction faction = BoardColl.get().getFactionAt(PS.valueOf(loc1));
    if(!faction.getName().equalsIgnoreCase("Wilderness") || (!faction.getName().equalsIgnoreCase("WarZone"))) {
    //I want to cancel the event, but there's no e.setCancelled(true); in ProjectileHitEvent.
    }

    }

    }
     
  2. Offline

    SuperSniper

    Just use PlayerInteractEvent and check if the item is an enderpearl, then cancel it from there
     
  3. Offline

    EliteGuy

    @SuperSniper
    And how do i get the location the Enderpearl would hit the ground?
    And how do I check if the Faction is his own one?
     
  4. Offline

    bcohen9685

  5. Offline

    EliteGuy

    works, thanks.
     
    Last edited: Jul 20, 2016
  6. @EliteGuy I think you need to learn Java more before using an API. Not being mean, just being truthful.

    Things needing to be fixed.
    1, Naming conventions
    2. == not .equals - https://stackoverflow.com/questions/7520432/what-is-the-difference-between-vs-equals-in-java
    3. Why are you making variables that are just not needed?
    4. Why use the double method to get the X then cast to int. Why not just use the int method #getBlockX
    5. Use the reformatter built in to the IDE (Eclipse: Ctrl+Shift+F)

    Your issue is you set something to null then use that.
    https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it
     
Thread Status:
Not open for further replies.

Share This Page