entity damage entity

Discussion in 'Plugin Development' started by dubknights, Aug 1, 2014.

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

    dubknights

    Im trying to make a sword that sends the player you hit flying towards the direction you hit him, but when i throw this in my entity damaged by entity event, it wont work:

    Code:java
    1. @EventHandler
    2. public void onDamage(EntityDamageByEntityEvent event){
    3. if((event.getEntity() instanceof Player) && (event.getDamager() instanceof Player)){
    4. Player attacker = (Player) event.getDamager();
    5. Player victim = (Player) event.getEntity();
    6. event.setCancelled(true);
    7. if(attacker.getItemInHand().getType() == Material.IRON_SWORD){
    8. if(Econemy.hasEnough(attacker, 15)) {
    9. Econemy.removeShards(attacker, 15);
    10. if (!BarAPI.hasBar(attacker)) {
    11. BarAPI.setMessage(ChatColor.AQUA + "§lBumper Sword", 30);
    12. victim.setVelocity(victim.getLocation().getDirection().multiply(2.5));
    13. victim.setVelocity(new Vector(victim.getVelocity().getX(), 0.3D, victim.getVelocity().getZ()));
    14. Location pl = attacker.getEyeLocation();


    any help?
     
  2. dubknights Check to see if all of the preconditions are met. For example, does the attacker have enough money? Does the attacker not have a bar?
     
  3. Offline

    Esophose

    dubknights
    Did you register your events? Strangely enough this has become a common error :L

    And by not working do you mean nothing is firing? Or are you getting a stacktrace?
     
  4. Offline

    dubknights

    Yeah i have registered all events and i have also set a message to the damager saying if he didn't have enough shards (my currency) @Esophose
    @DJSkepter
     
  5. Offline

    travja

    dubknights Um... first off looking at your code.. that will make the victim fly the direction they are looking. Not sure how to get the direction they are getting hit from... Maybe use the damager and convert their location and the victims location to a vector and then just set the y.. 2nd, try removing the BarAPI check and see if it works.
     
Thread Status:
Not open for further replies.

Share This Page