wormy
wormy
JCHJava Community | Help. Code. Learn.
Created by wormy on 12/9/2024 in #java-help
Minecraft plugin that displays text above a player's head
I have the queue, display, and deletion working, the only issue is that there can be multiple ArmorStands/Messages at once, regardless of the fact that I have a Map associating a single armor stand with a player. When the display function is called, it checks if there is an associated armor stand, and deletes it (before i get queue working, i want there to be one message displayed at a time)
public final Map<Player, ArmorStand> playerArmorStand = new HashMap<>();

public void messageDisplay(Player p, String m){
if (playerArmorStand.containsKey(p)) {
ArmorStand existingStand = playerArmorStand.get(p);
existingStand.remove();
playerArmorStand.remove(p);
}

// Set variables to be used
Location loc = p.getLocation();
World world = p.getWorld();
ArmorStand chat = world.spawn(loc, ArmorStand.class);

// Associate a specific armor stand with the player
playerArmorStand.put(p, chat);
...
public final Map<Player, ArmorStand> playerArmorStand = new HashMap<>();

public void messageDisplay(Player p, String m){
if (playerArmorStand.containsKey(p)) {
ArmorStand existingStand = playerArmorStand.get(p);
existingStand.remove();
playerArmorStand.remove(p);
}

// Set variables to be used
Location loc = p.getLocation();
World world = p.getWorld();
ArmorStand chat = world.spawn(loc, ArmorStand.class);

// Associate a specific armor stand with the player
playerArmorStand.put(p, chat);
...
7 replies