Programming Java Delay?

ne
1

How do I create a delay in a Java class without the execution of a method stopping?

To explain it in more detail: I want to program a Minecraft LabyMod addon. In this, the add-on user should execute a command as soon as e.g. The word "Hello" appears in the chat. The only problem is that the command is executed first, and shortly afterwards the message "Hello" comes into the chat.

That's why I need a delay for the message, but it doesn't stop the event.

e.g. If I were to use Thread.sleep (), the event would also be stopped briefly, which means that the command still comes before the message.

Sn

New java.util.Timer (). Schedule (
new java.util.TimerTask () {
@Override
public void run () {
// your code here
}
},
5000 // delay in milliseconds
);