api: add timestamps to message nodes, expose message id

This commit is contained in:
Adam
2018-12-12 13:39:45 -05:00
parent 92d91b09ff
commit ed13fd3039
4 changed files with 51 additions and 0 deletions

View File

@@ -29,6 +29,13 @@ package net.runelite.api;
*/
public interface MessageNode
{
/**
* Get the id for this message node
*
* @return
*/
int getId();
/**
* Gets the type of message.
*
@@ -95,4 +102,18 @@ public interface MessageNode
* @param runeLiteFormatMessage the new message format
*/
void setRuneLiteFormatMessage(String runeLiteFormatMessage);
/**
* Get the timestamp for the message, in seconds from the unix epoch.
*
* @return
*/
int getTimestamp();
/**
* Set the timestamp of the message
*
* @param timestamp
*/
void setTimestamp(int timestamp);
}

View File

@@ -36,4 +36,8 @@ public class SetMessage
* The new message value.
*/
private String value;
/**
* Timestamp of the message.
*/
private int timestamp;
}

View File

@@ -42,15 +42,21 @@ public abstract class RSMessageNodeMixin implements RSMessageNode
@Inject
private String runeLiteFormatMessage;
@Inject
private int rl$timestamp;
@Inject
RSMessageNodeMixin()
{
rl$timestamp = (int) (System.currentTimeMillis() / 1000L);
final SetMessage setMessage = new SetMessage();
setMessage.setMessageNode(this);
setMessage.setType(getType());
setMessage.setName(getName());
setMessage.setSender(getSender());
setMessage.setValue(getValue());
setMessage.setTimestamp(rl$timestamp);
client.getCallbacks().post(setMessage);
}
@@ -75,6 +81,20 @@ public abstract class RSMessageNodeMixin implements RSMessageNode
this.runeLiteFormatMessage = runeLiteFormatMessage;
}
@Inject
@Override
public int getTimestamp()
{
return rl$timestamp;
}
@Inject
@Override
public void setTimestamp(int timestamp)
{
this.rl$timestamp = timestamp;
}
@Inject
@MethodHook(value = "setMessage", end = true)
public void setMessage(int type, String name, String sender, String value)
@@ -82,6 +102,7 @@ public abstract class RSMessageNodeMixin implements RSMessageNode
// Message nodes get reused after a time by calling setMessage.
// Clear the runelite formatted message then.
runeLiteFormatMessage = null;
rl$timestamp = (int) (System.currentTimeMillis() / 1000L);
final SetMessage setMessage = new SetMessage();
setMessage.setMessageNode(this);
@@ -89,6 +110,7 @@ public abstract class RSMessageNodeMixin implements RSMessageNode
setMessage.setName(name);
setMessage.setSender(sender);
setMessage.setValue(value);
setMessage.setTimestamp(rl$timestamp);
client.getCallbacks().post(setMessage);
}
}

View File

@@ -29,6 +29,10 @@ import net.runelite.mapping.Import;
public interface RSMessageNode extends MessageNode
{
@Import("id")
@Override
int getId();
@Import("type")
int getRSType();