Solved Unknown error..

Discussion in 'Spigot Plugin Development' started by IllegalSloth, Apr 22, 2017.

  1. I have no idea why this won't work...
    Code (Text):
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
           
            if (p.hasPermission("Quantum.newsletter")) {
                p.sendMessage("§8» &fThe &aApril &fnewletter is available to read. Use the command &a/newsletter&f to read!");
            }
        }
     
  2. Care to explain what's the error or output on that?
     
    • check to see if event is actually firing (debug messages)
    • once knowing event fires, make sure player has the permission specified
     
  3. If you try to use /, java will read it as a special character. instead use // so it will ignore it

    *EDIT* sorry thats for \, ignore this
     
  4. he is using forward slash, not back ;)
     
    • Friendly Friendly x 1
  5. The message just doesn't display...
     
  6. yeah, I edited my message. thanks for pointing it out tho!
     
  7. How do i debug the message? My command seems to work fine
     
  8. check if it's firing.

    Code (Java):

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
         System.out.println("event fired");
    }
     
  9. Edit: So... I use \\ for /?
     
  10. no, your command and message output is fine. check if your event is firing.
     
  11. Well to add color to messages you need to either use the ChatColor enum or transalte the whole message to color using ChatColor.translateAlternateColor() (not sure about the exact name, but it takes a char as first parameter it beign the color code denominator & and then as second argument the String to translate)
     
  12. EDIT: The event wont fire... Fix?
     
  13. Did you register the event in your plugin onEnable()?
     
  14. How im using it now works perfectly fine. I've used it in my command
     
  15. OMG ROOKIE MISTAKE ;-;
    Thanks for reminding me ;-;
     
  16. Edit: Solved the issue. ~Thanks
     
  17. register the event. ex:

    Code (Java):

    public class Main extends JavaPlugin {
         
          @Override
          public void onEnable() {
               getServer().getPluginManager().registerEvents(new ListenerClass(), this);
          }
    }

    public class ListenerClass implements Listener {

          @EventHandler
          public void onPlayerJoin(PlayerJoinEvent event) {
                Bukkit.getOnlinePlayers().stream().filter(Player::isOp).forEach(p -> p.sendMessage("you received a message since you were op!");
          }
    }