Simple Help Just Intrested

Discussion in 'Plugin Development' started by FreeMotion45, Oct 7, 2015.

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

    FreeMotion45

    Hey,

    I don't know if this does matter or not but I got this code :

    Code:
    @EventHandler
        public void onChat(PlayerChatEvent event){
            String msg = event.getMessage();
            if(msg.startsWith("Hey")){
                Bukkit.broadcastMessage("Hello");
            }
        }
    And the PlayerChatEvent is lined through. And it says PlayerChatEvent is deprecated.
    Just for the interest, what does that mean ?
    Will it effect my future commands, events etc ?
     
  2. Offline

    timtower Moderator Moderator

    @FreeMotion45 That it shouldn't be used anymore due to future changes.
     
  3. Offline

    FabeGabeMC

  4. Offline

    mythbusterma

    @FreeMotion45

    It's fine and probably won't ever be removed. It was made asynchronous for performance reasons (a terrible decision on Bukkit's part because nobody who writes code for Bukkit actually knows what 'asynchronous' actually means). But it's still the only really "safe" way of doing chat, per se.
     
    teej107 likes this.
  5. Offline

    boomboompower

    @mythbusterma I find that using PlayerChatEvent is easier than using AsyncPlayerChatEvent. It is very simple ;p
     
    DoggyCode™ and mythbusterma like this.
  6. Offline

    DoggyCode™

    I read the doc on both, isn't it the same? How come it be a better alternative?
     
  7. Offline

    Scimiguy

    ASync runs asynchronously -- on a separate thread to the core Minecraft.

    It offers performance improvements for the core, but since it's misused by unwary programmers, the net effect is worse.
     
    boomboompower likes this.
  8. Offline

    boomboompower

    DoggyCode™ likes this.
  9. Offline

    DoggyCode™

  10. Offline

    FreeMotion45

    Thanks for the help.

    But now I have a strange problem. I saw people did this and it all was good for them.
    Code:
    @EventHandler
    public void onDeath(PlayerDeathEvent e)
    {
    Player player  = e.getPlayer
    player.sendMessage("Test Message")
    }
    
    How ever this part:
    Code:
    Player player  = e.getPlayer();
    Results as an error. I tried using EntityDeathEvent but then nothing would happen.
    I did register the event, but again I get an error on the Player player = e.getPlayer();

    Thanks for all the help :)
     
  11. Offline

    timtower Moderator Moderator

    @FreeMotion45 Difference:
    PlayerDeathEvent and EntityDeathEvent
     
  12. Offline

    FreeMotion45

    But I got the error if I use PlayerDeathEvent.

    IF I use PlayerDeathEvent there is an error if I use Player p = e.getPlayer();
     
  13. Offline

    boomboompower

    @FreeMotion45 because the entity in EntityDeathEvent isn't always a player :p
    can be any mob.
     
  14. Offline

    Langsdorf

    Maybe i help you:

    Code:
      
    @EventHandler
        public void a(PlayerDeathEvent e) {
            if (e.getEntity() instanceof Player) {
                Player p = e.getEntity();
                p.sendMessage("§c=(");
            }
            //or
          
            Player p = e.getEntity();
            p.sendMessage("§c=(");
        }
      
        @EventHandler
        public void b(EntityDeathEvent e) {
            if (e.getEntity() instanceof Player) {
                Player p = (Player)e.getEntity();
                p.sendMessage("§c=(");
            }
        }
      
        @EventHandler
        public void c(EntityDamageByEntityEvent e) {
            if (e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
                Player p = (Player)e.getEntity();
                Player p2 = (Player)e.getDamager();
                p.sendMessage("§c=(");
                p2.sendMessage("§a=)");
            }
        }
     
    Last edited: Oct 8, 2015
Thread Status:
Not open for further replies.

Share This Page