Minecraft Java Plugin, message is output twice?

Is
- in Worlds
9

If (e.getRightClicked (). GetType (). Equals (EntityType.PLAYER) && (v.getCustomName (). Contains ("Kirito" {

Bukkit.getScheduler (). RunTaskLater (Bukkit.getPluginManager (). GetPlugin ("Tutorial"), () → {
p.sendMessage ("§2Green Player §7Kirito §8 | §7Hi" + p.getName () + ". §7You have just entered this world for the first time. Do you want me to explain how everything works?");

}, 3L);

}

If you interact with the NPC, the message will be output twice, but it should only be output once.

an

Everything looks right there.

Are you sure that the incomplete method will be called twice?

Do a sout and see if it is really only spent once.

System.out.println ("Test 1");

if (e.getRightClicked (). GetType (). Equals (EntityType.PLAYER) && (v.getCustomName (). Contains ("Kirito" {

System.out.println ("Test 2");

Bukkit.getScheduler (). RunTaskLater (Bukkit.getPluginManager (). GetPlugin ("Tutorial"), () → {
p.sendMessage ("§2Green Player §7Kirito §8 | §7Hi" + p.getName () + ". §7You have just entered this world for the first time. Do you want me to explain how everything works?");
}, 3L);
}

"Test 1" and "Test 2" should only be output once.

Is

"Test 1" and "Test 2" are output twice in the following order:

[22:30:12] [Server thread / INFO]: Test 1

[22:30:12] [Server thread / INFO]: Test 2

[22:30:12] [Server thread / INFO]: Test 1

[22:30:12] [Server thread / INFO]: Test 2

an

Jo, then the problem is not with the code you posted in the question.

But about it. The method in which your code is located is called twice.

Please send in the rest of the code.

Is

an

Ah, that's why.

PlayerInteractEntityEvent fires twice - once for each hand of the player (left & right)

Do this into your code here:

@EventHandler
public void onInteract (PlayerInteractEntityEvent e) {
if (! Event.getHand (). Equals (EquipmentSlot.HAND)) return; // This is new. Simply insert this line of code at the point.
// … Just leave the rest of the code as it is

Is

Then comes an error message: event can't be resolved

an

Oh my bad.

Write "e" instead of "event". You called it e. I missed it.

if (! E.getHand (). Equals (EquipmentSlot.HAND)) return;

Is

@ MrAmazing2 Ok it works now.

an

Great, glad that I could help you, please.