Solved TextComponent Decompiler Exception

Discussion in 'Plugin Development' started by CommonSenze, Jun 20, 2018.

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

    CommonSenze

    [FAT EDIT] I have solved this issue! I managed to find out that I cant use ChatColor in the set text method I ended up doing this:
    Code:java
    1. TextComponent winnersComp = new TextComponent(), losersComp = new TextComponent(), comma = new TextComponent(", "), colon = new TextComponent(": ");
    2. winnersComp.setText("Winners");
    3. losersComp.setText("Losers");
    4. winnersComp.setColor(ChatColor.GREEN);
    5. losersComp.setColor(ChatColor.RED);
    6. colon.setColor(ChatColor.GRAY);
    7. winnersComp.addExtra(colon);
    8. losersComp.addExtra(colon);
    9. comma.setColor(ChatColor.WHITE);
    10.  
    11. for (int i = 0; i < winners.size(); i++) {
    12. Player player = Bukkit.getPlayer(winners.get(i));
    13. plugin.getDuelManager().put(player.getUniqueId(), player.getInventory().getContents());
    14. comp.setText(player.getName());
    15. comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to view "+ player.getName() + "'s inventory").create()));
    16. comp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/duel invsee "+player.getUniqueId().toString()));
    17. comp.setColor(ChatColor.GRAY);
    18. winnersComp.addExtra(comp);
    19. if ((i+1) != winners.size())winnersComp.addExtra(comma);
    20. }
    21.  
    22. for (int i = 0; i < losers.size(); i++) {
    23. Player player = Bukkit.getPlayer(losers.get(i));
    24. plugin.getDuelManager().put(player.getUniqueId(), player.getInventory().getContents());
    25. comp.setText(player.getName());
    26. comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to view "+ player.getName() + "'s inventory").create()));
    27. comp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/duel invsee "+player.getUniqueId().toString()));
    28. comp.setColor(ChatColor.GRAY);
    29. losersComp.addExtra(comp);
    30. if ((i+1) != losers.size())winnersComp.addExtra(comma);
    31. }

    FAT THANKS TO MIGHTYONE FOR TAKING THE TIME THE ASSIST.
    [/FAT EDIT]


    Hello all,

    This issue came from when I was creating a text component in my code for Duels in 1v1s, 2v2s, etc.

    Here's my code:
    Code:java
    1.  
    2. TextComponent winnersComp = new TextComponent(), losersComp = new TextComponent("Losers: "), comma = new TextComponent(", ");
    3. winnersComp.addExtra(new ComponentBuilder("Winners").color(ChatColor.GREEN).append(": ").color(ChatColor.GRAY).toString());
    4. losersComp.addExtra(new ComponentBuilder("Loser").color(ChatColor.RED).append(": ").color(ChatColor.GRAY).toString());
    5. comma.setColor(ChatColor.WHITE);
    6.  
    7. for (int i = 0; i < winners.size(); i++) {
    8. Player player = Bukkit.getPlayer(winners.get(i));
    9. plugin.getDuelManager().put(player.getUniqueId(), player.getInventory().getContents());
    10. comp.setText(player.getName());
    11. comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to view "+ player.getName() + "'s inventory").create()));
    12. comp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/duel invsee "+player.getUniqueId().toString()));
    13. comp.setColor(ChatColor.GRAY);
    14. winnersComp.addExtra(comp);
    15. if ((i+1) != winners.size())winnersComp.addExtra(comma);
    16. }
    17.  
    18.  
    19. for (int i = 0; i < losers.size(); i++) {
    20. Player player = Bukkit.getPlayer(losers.get(i));
    21. plugin.getDuelManager().put(player.getUniqueId(), player.getInventory().getContents());
    22. comp.setText(player.getName());
    23. comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to view "+ player.getName() + "'s inventory").create()));
    24. comp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/duel invsee "+player.getUniqueId().toString()));
    25. comp.setColor(ChatColor.GRAY);
    26. winnersComp.addExtra(comp);
    27. if ((i+1) != losers.size())winnersComp.addExtra(comma);
    28. }
    29.  

    Now everything should be self explanatory, but I'll explain some of it. I start by making 2 main components that will hold the winners Components and the other holding the losers component.

    I also create a comma component to add separation between the player components I create after. I gather all the players names, add a Click Event as well as a Hover Event to each players component and add the comma if needed.

    Now everything works fine here; where it all goes down hill is when I send it to the players. It disconnects the players and sends them the image shown below. Just to clarify so no one ask NO, THERE WASN'T AN ERROR IN CONSOLE.

    Assistance is much needed. Thank you in advance!
     

    Attached Files:

    Last edited: Jun 20, 2018
  2. Offline

    MightyOne

    I think you cannot use ComponentBuilder#toSring(). As you can see just the objects id or something gets put into the json component. I am sure there is a method like ComponentBuilder#build() that will actually return the component as json code.
     
  3. Offline

    CommonSenze

    @MightyOne
    There isn't a ComponentBuilder#build() method but I ended up just making it a literal string. It still doesn't work.
     
  4. Offline

    MightyOne

    but its solved?
     
  5. Offline

    CommonSenze

    @MightyOne
    Yes it is, look at the top of my first comment.
     
Thread Status:
Not open for further replies.

Share This Page