TSV (Worlds?) Death Messages

ArchivesFeature requests → TSV (Worlds?) Death Messages

CLOSED

Hello everybody. So. Recently I’ve been trying some stuff with death messages and I came up with an idea for redstoner’s death messages. I dont know if it will work on redstoner because of it’s disabled messages and I couldnt really try it myself because I dont have another account to test it with. FYI I’ll try to fix it and edit the thread if it doesnt work with fixed code. So concept is simple and self-explanatory: Death messages are sent only on one world - where player died.

Here’s the code:

import java.util.logging.Logger;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class SWDM extends JavaPlugin

    implements Listener {

    public void Main() {

    }

    public void onEnable() {

        getServer().getPluginManager().registerEvents(this, this);

    }

    public void onDisable() {

    }

    public void onDeath(PlayerDeathEvent event) {

        String name = event.getEntity().getName();
        World world2 = event.getEntity().getWorld();
        getLogger().info((new StringBuilder(String.valueOf(name))).append("Died").toString());
        String message = event.getDeathMessage();
        event.setDeathMessage("");
        Player aplayer[];
        int j = (aplayer = Bukkit.getOnlinePlayers()).length;
        for(int i = 0; i < j; i++)

        {

            Player p = aplayer[i];
            if(p.getWorld().equals(world2))

            {
                p.sendMessage(message);
            }
        }
    }
}
````

They’re not really sendt on one world though, are they? This sends a message to everyone in that world.. Goes for the same I guess.

Anyway, you can use a foreach loop instead since you are just looking through an array.

for(Player p : Bukkit.getOnlinePlayers()){
    if(blah blah blah)
    {
        Message and stuff
    }
}
````

Yeah I know, that’s not really on one world I suppose, but It’s better than nothing I guess? :D The use of this is really good actually, because I dont think that others (i.e players in trusted world see normal (creative world?) survival world death messages and vice versa) care about other world player deaths so I think it does the job.

Yeah, I think I could make use of your suggestion too tho. :P