Tazmania Posted January 2, 2016 Share Posted January 2, 2016 Hi, I have been searching round the API but can't seems to find a listener I could implement that gets executed when a game event (like A magical force stops you from moving) appears on the game log. Or is there some other way of reading these? Quote Link to comment Share on other sites More sharing options...
Vilius Posted January 2, 2016 Share Posted January 2, 2016 (edited) You need to get a message listener, the method is onMessage() if I recall correctly. EDIT: I.e private void onMessage(String message) { if(message.contains("You get some oak logs.")) { itemsMade ++; } } You can make specific message type listeners too: if you put that in the onMessage method if(getType().equals(Message.MessageType.GAME)) { // game message } if(getType().equals(Message.MessageType.PLAYER)) { // player message } and in the onStart() method: getBot().addMessageListener(this); Edited January 2, 2016 by Vilius Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted January 2, 2016 Share Posted January 2, 2016 Script implements all listeners: abstract class Script extends MethodProvider implements Painter, MessageListener, ConfigListener, LoginResponseCodeListener, AudioListener So you just need to override public void onMessage(Message m) in your script Quote Link to comment Share on other sites More sharing options...
Explv Posted January 2, 2016 Share Posted January 2, 2016 (edited) Hi, I have been searching round the API but can't seems to find a listener I could implement that gets executed when a game event (like A magical force stops you from moving) appears on the game log. Or is there some other way of reading these? You need to get a message listener, the method is onMessage() if I recall correctly. private void onMessage(String message) { if(message.contains("You get some oak logs.")) { itemsMade ++; } } You can do this, but this example is incorrect, the argument is not a String. It should be: @Override public void onMessage(Message message){ if(e.getType() == Message.MessageType.GAME && e.getMessage().equals("A magical force stops you from moving")){ // do something } } Edited January 2, 2016 by Explv 1 Quote Link to comment Share on other sites More sharing options...
Vilius Posted January 2, 2016 Share Posted January 2, 2016 You can do this, but this example is incorrect, the argument is not a String. It should be: @Override public void onMessage(Message message){ if(e.getType() == Message.MessageType.GAME && e.getMessage().equals("A magical force stops you from moving")){ // do something } } Ah yes, been some time when I used message listeners :x Quote Link to comment Share on other sites More sharing options...
Tazmania Posted January 3, 2016 Author Share Posted January 3, 2016 (edited) Brilliant guys thanks, also one last thing so I don't open an other thread, do you know how you can fetch if a player is skulled or not? NVM got it from Player.getSkullIcon() Edited January 3, 2016 by Tazmania Quote Link to comment Share on other sites More sharing options...