Outputting something than expected!

Discussion in 'Plugin Development' started by DJ_Amos123, Jul 7, 2013.

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

    DJ_Amos123

    It should say '[PW] SnowBallGuy has hit HitPlayer'
    but it says:
    'HitPlayer has died'
    '[PW] CraftPlayer{name=RealNameHere} has hit HitPlayer'

    1. How do I get the 'CraftPlayer{name=RealNameHere}' to become JustTheirName.
    2. Stop double message. Sometimes this becomes 3 messages...
    Updated on 08/07/2013: http://screencloud.net/v/yLU8

    UPDATE: Added your code TheTrixsta, but now it doesn't print anything out in-game.
    No errors. It just does nothing. (Updated code below in GitHub)

    Here's the GitPage:
    https://github.com/MrAmos123/PaintballWarfare/blob/master/src/me/MrAmos123/PW/PW.java#L22-L30
    (I'm new at Java so please make 'easy-to-follow' help :))
    Thanks, Amos.
     
  2. Offline

    TheTrixsta

    Cancel the death message through the PlayerDeathEvent, then just set the death message to null.

    Where does the '0.0' come from?

    Edit: Ok I see

    Code:java
    1.  
    2. @EventHandler
    3. public void onPaintballHit(EntityDamageByEntityEvent event) {
    4. if (e.getEntity() instanceof Player && e.getDamager() instanceof Snowball) {
    5. Player ent = (Player) e.getEntity();
    6. Snowball damager = (Player) e.getDamager();
    7. if (damager.getShooter() instanceof Player) {
    8. Player shooter = (Player) damager.getShooter();
    9. ent.setHealth(0);
    10. ent.getServer().broadcastMessage(ChatColor.GREEN + "[PW]" + ChatColor.RED + shooter.getName() + ChatColor.GRAY + " Has hit " + ChatColor.RED + ent.getName());
    11. }
    12. }
    13. }
    14.  
     
  3. Offline

    DJ_Amos123

    The 0.0 used to come from the get.Damage() I fixed it, by replacing it with get.Damager()

    Got a fix for the 'CraftSnowBall' issue?
     
  4. Offline

    TheTrixsta

    what do you want to do with CraftSnowBall? Why not just use Snowball
     
    Minnymin3 likes this.
  5. Offline

    DJ_Amos123

    I want it to say somthing like:
    [PW] DJ_Amos123 has hit The_Ms
    But 'DJ_Amos123' is replaced with CraftSnowBall, I have no idea why..
     
  6. Offline

    Chinwe

    Instead of e.getDamager() you need to do something along the lines of e.getDamager().getType().toString() which should give you 'snowball'

    To get the thrower's name, you need projectile.getShooter().getName() (after making sure the shooter is in fact a player)
     
  7. Offline

    DJ_Amos123

  8. Offline

    DJ_Amos123

  9. You could also set the death message to what you are trying to broadcast.
    For the problem that it prints Craftplayer{etc}, that shouldn't happen and might be a bug in bukkit ?

    You should also register your class as a listener like this in your onEnable method:
    Code:
    this.getServer().getPluginManager().registerEvents(this, this);
    EDIT: I send a pull request on github that will probably solve your problems. (not sure though, it has been a while since I actively developed plugins)
     
  10. Offline

    DJ_Amos123

    blackwolf12333
    Thanks man, plugin works perfectly.
    Couldn't have done it without ya' :)
     
Thread Status:
Not open for further replies.

Share This Page