Async Entity Add

Discussion in 'Plugin Development' started by ImpaTheImpaler, Sep 17, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    ImpaTheImpaler

    I am trying to make it so you can rename a custom shop in game, but because PlayerChatEvent is deprecated I am using AsyncPlayerChatEvent. The only issue with this is that when you rename your shop it comes up above the chest as a hologram - but holograms are made with armour stands, which are entities and you can't change entities asynchronously. Here is the code for both the function to change the hologram which is in a seperate class, and the AsyncPlayerChatEvent.

    Here is the error log - http://prntscr.com/p7eczl
    Line 780 is where the function is called (changeHologram) in the async event, and line 89 is h.appendTextLine in the actual function itself.

    Code:
    @EventHandler
        public void onChat(AsyncPlayerChatEvent e){
                       if (shop_naming.contains(e.getPlayer().getName())){
                    e.setCancelled(true);
    
                    String msg = e.getMessage();
    
                    shop_naming.remove(e.getPlayer().getName());
    
                    if (msg.equalsIgnoreCase("cancel")){
                        e.getPlayer().sendMessage(ChatColor.DARK_AQUA + "Naming cancelled.");
                    } else {
                        e.getPlayer().sendMessage(ChatColor.DARK_AQUA + "You have successfully renamed your shop.");
                        ShopFunctions.changeHologram(e.getPlayer().getName(), msg);
                    }
                }
    This is the ASync chat event.

    Code:
        public static void changeHologram(String pl, String msg){
            Hologram h = ShopHandler.hologram.get(pl);
            h.appendTextLine(msg);
        }
    This is the function.

    I know it would be easier to just make a command for it but I think it would seem much smoother the way I am trying to do it. If there is no fix then I will use a command but I want to see if there is a way I can do this.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    ImpaTheImpaler

    Nevermind I fixed it by putting a scheduler in the function itself.

    you beat me to replying :) thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
Thread Status:
Not open for further replies.

Share This Page