Removing Default Join Message

Discussion in 'Plugin Development' started by ArcheCane, Oct 13, 2011.

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

    ArcheCane

    Basically, I want to remove the default join message, and replace it with the already made custom message, and I would like it so the custom message sends for op's only and doesn't remove the default join message for non-ops.
    This is my code so far. (Guessing you have to cancel the Join event message somehow... but I'm not sure).

    PlayerListener;
    Code:java
    1. package me.code;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7. import org.bukkit.event.player.PlayerListener;
    8.  
    9. public class StrikePlayerListener extends PlayerListener {
    10.  
    11. public void onPlayerJoin(PlayerJoinEvent event){
    12. event.getPlayer().getWorld().strikeLightningEffect(event.getPlayer().getLocation());
    13. for (Player p : Bukkit.getServer().getOnlinePlayers()) {
    14. p.sendMessage((ChatColor.DARK_RED + p.getName() + ChatColor.GOLD + " has joined the Game with Holy Powers!"));
    15. }
    16. }
    17. }
     
  2. Offline

    bergerkiller

    @ArcheCane simply set the message to null to prevent it from getting displayed.
    Code:
    event.setJoinMessage(null);
    Might be better to use setJoinMessage instead of broadcasting it in the server.
     
  3. Offline

    ArcheCane

    Thanks, I feel stupid for not thinking of using null.
    But how can I make it so it doesn't send the custom message and sends the default message for non-ops.
     
  4. Offline

    wwsean08

    for each player check if they are an op, if they are not, send them the default message, else send them the custom one (there should be a Player.isOp() method to help you with this)
     
  5. Offline

    ArcheCane

    How do you suppose for me to do that? I'm still a newb. D:
    Something like this? Gives a few errors. Oh and I only want the strike effect to send for Op's.
    Code:java
    1. public void onPlayerJoin(PlayerJoinEvent event){
    2. if Player.isOp()); {
    3. event.getPlayer().getWorld().strikeLightningEffect(event.getPlayer().getLocation());
    4. for (Player p : Bukkit.getServer().getOnlinePlayers()) {
    5. p.sendMessage((ChatColor.DARK_RED + p.getName() + ChatColor.GOLD + " has joined the Game with Holy Powers!"));
    6. else; {
    7. }
    8. event.setJoinMessage(null);
    9. }
    10. }
    11. }
    12. }
     
  6. Offline

    wwsean08

    ok, you need to learn the java syntax, i recomend you look up a few java tutorials. Also i misunderstood what you meant, heres the basic code:


    Code:
    public void onPlayerJoin(PlayerJoinEvent event){
        if(event.getPlayer.isOp(){
            event.getPlayer().getWorld().strikeLightningEffect(event.getPlayer().getLocation());
            event.setJoinMessage((ChatColor.DARK_RED + p.getName() + ChatColor.GOLD + " has joined the Game with Holy Powers!"));
    }
    That will do the effect for ops, and display their custom message, and do the normal thing for non-ops (if you want nonops to have no message, then thats simple enough, add an else where you set the message to null)
     
  7. Offline

    ArcheCane

    makes the p in p.getName() a error and if(event.getPlayer.isOp(){ sends syntax and resolving error.
    and I really need to look/watch some tutorials heh.
     
  8. Offline

    wwsean08

    ok it should be event.GetPlayer().isOp, and change p.GetName to event.GetPlayer().getName()

    I just wrote that out freehand so there was bound to be a bug or two (and i didn't bother to check references to your variables).
     
  9. change p to event.getPlayer()
     
  10. Offline

    ArcheCane

    Ok, thanks guys! Everythings set accept getPlayer if(event.getPlayer.isOp()){ is not resolved.
     
  11. Offline

    wwsean08

    like i said, if(event.getPlayer().isOp()){
     
  12. Offline

    ArcheCane

    Alright, everything works... but when I'm not Op it sends the default message but it's black, and when I'm op it works fine but adds a black message above the custom join message.

    Code:java
    1. public void onPlayerJoin(PlayerJoinEvent event){
    2. if(event.getPlayer().isOp()){
    3. event.getPlayer().getWorld().strikeLightningEffect(event.getPlayer().getLocation());
    4. event.setJoinMessage((ChatColor.DARK_RED + event.getPlayer().getName() + ChatColor.GOLD + " has joined the Game with Holy Powers!"));
    5. } else {
    6. event.setJoinMessage(null);
    7. }
    8. }
    9. }
     
  13. Offline

    wwsean08

    I don't see this working, but it's worth a shot:
    PHP:
    public void onPlayerJoin(PlayerJoinEvent event){
        if(
    event.getPlayer().isOp()){
            
    event.setJoinMessage("");
            
    event.getPlayer().getWorld().strikeLightningEffect(event.getPlayer().getLocation());
            
    event.setJoinMessage((ChatColor.DARK_RED event.getPlayer().getName() + ChatColor.GOLD " has joined the Game with Holy Powers!"));
        } else {
            
    event.setJoinMessage("");
    }
    }
     
  14. Offline

    ArcheCane

    Alright, thanks guys.
    Someone on skype told me to remove WE as it causes broadcast problems sometimes... did that... works fine.
     
Thread Status:
Not open for further replies.

Share This Page