Why won't this work.

Discussion in 'Plugin Development' started by Sean0402, Aug 25, 2014.

Thread Status:
Not open for further replies.
  1. Hi this is not working as I expected.. I want it so when they have the permission node it says the join msg.. But for some reason it doing it without the permission and everyone gets the join message? I cannot seem to find out why this isn't working.

    Code:java
    1. package me.sean0402.join;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import org.bukkit.event.player.PlayerQuitEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public final class Join extends JavaPlugin implements Listener {
    12.  
    13. public void onEnable() {
    14. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    15. saveDefaultConfig();
    16. }
    17.  
    18. @EventHandler
    19. public void onJoin(PlayerJoinEvent event){
    20. for (Player player: Bukkit.getServer().getOnlinePlayers()) {
    21.  
    22. if (player.hasPermission("joinmessage.join")) {
    23. event.setJoinMessage(getConfig().getString("test").replace("&", "§").replace("%player%", player.getDisplayName()));
    24. } else {
    25. event.setJoinMessage("");
    26. }
    27. }
    28.  
    29. }
    30.  
    31. @EventHandler
    32. public void onQuit(PlayerQuitEvent event) {
    33. event.setQuitMessage("");
    34. }
    35.  
    36. }
     
  2. Offline

    AoH_Ruthless

    Sean0402
    The Event join message can't be changed for some players but not others. You have to set the join message to "" at the beginning, then loop through all players, if they have permission send them a message with Player#sendMessage()
     
  3. Offline

    AoH_Ruthless

    Sean0402
    You already know how because you have done it already in your code.
     
  4. AoH_Ruthless My friend done this for me and I tried to find out why it don't work.. but I cant

    Code:java
    1. package me.sean0402.join;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import org.bukkit.event.player.PlayerQuitEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public final class Join extends JavaPlugin implements Listener {
    12.  
    13. public void onEnable() {
    14. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    15. saveDefaultConfig();
    16. }
    17.  
    18. @EventHandler
    19. public void onJoin(PlayerJoinEvent event){
    20. for (Player player: Bukkit.getServer().getOnlinePlayers()) {
    21. event.setJoinMessage("");
    22. if (player.hasPermission("joinmessage.join")) {
    23. event.setJoinMessage(getConfig().getString("test").replace("&", "§").replace("%player%", player.getDisplayName()));
    24. } else {
    25. event.setJoinMessage("");
    26. }
    27. }
    28.  
    29. }
    30.  
    31. @EventHandler
    32. public void onQuit(PlayerQuitEvent event) {
    33. event.setQuitMessage("");
    34. }
    35.  
    36. }
     
  5. Offline

    macboinc

    You don't need the for loop... e.setJoinMessage("") already broadcasts it to all the players.
     
  6. Offline

    AoH_Ruthless

  7. Offline

    macboinc

    This also might be an error, but at the top of your event where the EventHandler annotation is, do:

    Code:java
    1. @EventHandler(priority = EventPriority.MONITOR)


    Gosh you reply fast...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  8. Offline

    shawshark


    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent event){
    3.  
    4. for (Player player: getServer().getOnlinePlayers()) {
    5. if (player.hasPermission("this.person.has.permission")) {
    6. player.sendMessage(getConfig().getString("test").replace("&", "§").replace("%player%", player.getDisplayName()));
    7. }
    8. }
    9. event.setJoinMessage(null);
    10. }

    Set the join message to null then loop though all the players online and see if player 'player' has the permission node "this.person.has.permission" if they do send them the join message.
     
  9. Still doesn't work.. :/

    Code:java
    1. package me.sean0402.join;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.EventPriority;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import org.bukkit.event.player.PlayerQuitEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public final class Join extends JavaPlugin implements Listener {
    13.  
    14. public void onEnable() {
    15. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    16. saveDefaultConfig();
    17. }
    18.  
    19. @EventHandler(priority = EventPriority.MONITOR)
    20. public void onJoin(PlayerJoinEvent event){
    21. for (Player player: Bukkit.getServer().getOnlinePlayers()) {
    22. if (player.hasPermission("joinmessage.join")) {
    23. event.setJoinMessage(getConfig().getString("test").replace("&", "§").replace("%player%", player.getDisplayName()));
    24. }
    25. event.setJoinMessage(null);
    26. }
    27. }
    28.  
    29.  
    30. @EventHandler
    31. public void onQuit(PlayerQuitEvent event) {
    32. event.setQuitMessage("");
    33. }
    34.  
    35. }
     

  10. well look good what shawshark sad on line 5
    Code:java
    1. if (player.hasPermission("this.person.has.permission"))
     
  11. Offline

    SmooshCakez

    1. You're using EventPriority.MONITOR incorrectly. This is explained here.
    2. Why is your class final? Try removing the final modifier.
    3. You're getting string "test" from the config. You never specified any defaults, so it isn't there unless you added it manually.
    4. If 1 person online has the permission, you're setting the join message to that for every player. setJoinMessage sets the join message for everybody. Use player.sendMessage();.
     
  12. wolfs25 are you talking about the player.sendmessage? I need it to be a join message.. So say a donator joins "[Pro+] Sean0402 Has Joined The Hub!"

    SmooshCakez is there a way to make it work? With Event.setjoinmessage so it only works for my donators..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  13. Offline

    SmooshCakez

    No, there isn't. event.setJoinMessage(); sets the message to all players. Try looping through the players with the permission and sending them the join message with player.sendMessage();

    If you mean to make it so that the join message is displayed to everyone if the player who joined has the permission, check if they have the permission and then use event.setJoinMessage();
     
  14. wel u can also can use essentials on config.yml line 367 change "{PLAYER} &ejoined the game" just saying
     
  15. SmooshCakez that is checking if they have the perms isn't it? Then sending the join msg?

    wolfs25 yes but how do I make it so it only says it for donors?
     
  16. Offline

    fireblast709

    Sean0402 Player has a convenient sendMessage(String) method for sending messages. Just loop over all Players online, check if they have the perm, and if so, send the join message. Also, set the join message to null to prevent it from sending to people in general, to prevent duplicate join messages. Moreover, use ChatColor.translateAlternateColorCodes('&', message) for colouring your messages.
    SmooshCakez final classes wouldn't cause any issues. Moreover, it's his main class, why would he need to be able to extend it in the first place.
     
Thread Status:
Not open for further replies.

Share This Page