Solved Factions onPlayerJoin

Discussion in 'Plugin Development' started by WizKhalifa, Mar 22, 2013.

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

    WizKhalifa

    Hey, i am fairly new to bukkit, but know my share of the java language.

    I am trying to make a plugin when a faction member joins, it notifies each online faction member that the player has joined, and not the whole server. This is what I have so far, any guidance would be loved!

    Code:
    public void onPlayerJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            FPlayer fplayer = FPlayers.i.get(player);
            for (Player fPlayer: fplayer.getFaction().getOnlinePlayers())
          {
                fPlayer.sendMessage(player.getName() + " is now online!");
          }
        }
     
  2. Offline

    Faith

    What problem are you having?
     
  3. Offline

    WizKhalifa

    its not sending the faction members a message when the player joins. Would it have to do with the eventpriority? Thanks!
     
  4. Offline

    Faith

    Send me your entire code, can't see anything wrong here. PM me it if you don't feel comfortable releasing it ;).
    I might have a bit of a delayed response.
     
  5. Offline

    WizKhalifa

    Messaged you, thanks faith :)
     
    Faith likes this.
  6. Offline

    PogoStick29

    When you tested, does the player that logged in have a faction?
     
  7. Offline

    WizKhalifa

    Yes, I got it working! Thanks for the help.

    Now I am trying to make it so it notifies your faction members when you get attacked by another player. This is what I have so far...

    Code:
        @EventHandler
        public void onPlayerDamage(EntityDamageByEntityEvent event){
            Player player = ((OfflinePlayer) event).getPlayer();
            FPlayer fplayer = FPlayers.i.get(player);
            for (Player fPlayer: fplayer.getFaction().getOnlinePlayers())
            {
     
            if(event.getDamager() instanceof Player && event.getEntity() instanceof Player && event.getCause() == DamageCause.ENTITY_ATTACK){
                Player damager = (Player) event.getDamager();
                Player hurt = (Player) event.getEntity();
             
                if(hurt.getHealth() - event.getDamage() ==10){
                    fPlayer.sendMessage(damager + " Is attacking " + player);
                }
            }
        }
        }
    This is the error I get:
    http://pastebin.com/AJE2UnVH

    If anyone could help, that would be great!
     
  8. Offline

    PogoStick29


    You are casting the attacked entity to OfflinePlayer, then checking. Do this:

    Code:
        @EventHandler
        public void onPlayerDamage(EntityDamageByEntityEvent event){
        if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
                Player damager = (Player) event.getDamager();
                Player hurt = (Player) event.getEntity();
            for (Player fPlayer: FPlayers.i.get(hurt).getFaction().getOnlinePlayers())
            {
                    fPlayer.sendMessage(damager + " Is attacking " + player);
            }
            }
        }
        }
    Wrote without IDE; hope it works.
     
  9. Offline

    WizKhalifa

    Thanks, really helpful!!

    If i were to get rid of this, I would create a an iterator? Also, to get rid of the CraftPlayer is attacking name=cats12, would I get the displayname? Thanks again for all the help!
     
  10. Offline

    PogoStick29

    Use player.getName() or player.getDisplayName() and you will be good.
     
  11. Offline

    WizKhalifa

    Ok, not sure what I would put player.getDisplayName(). with player?
     
Thread Status:
Not open for further replies.

Share This Page