valueEntry : map.get(entryValues.getKey()).entrySet()) {
627 | valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
628 | allSkipped = false;
629 | }
630 | if (!allSkipped) {
631 | reallyAllSkipped = false;
632 | valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
633 | }
634 | }
635 | if (reallyAllSkipped) {
636 | // Null = skip the chart
637 | return null;
638 | }
639 | return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
640 | }
641 | }
642 |
643 | /**
644 | * An extremely simple JSON builder.
645 | *
646 | * While this class is neither feature-rich nor the most performant one, it's sufficient enough
647 | * for its use-case.
648 | */
649 | public static class JsonObjectBuilder {
650 |
651 | private StringBuilder builder = new StringBuilder();
652 |
653 | private boolean hasAtLeastOneField = false;
654 |
655 | public JsonObjectBuilder() {
656 | builder.append("{");
657 | }
658 |
659 | /**
660 | * Appends a null field to the JSON.
661 | *
662 | * @param key The key of the field.
663 | * @return A reference to this object.
664 | */
665 | public JsonObjectBuilder appendNull(String key) {
666 | appendFieldUnescaped(key, "null");
667 | return this;
668 | }
669 |
670 | /**
671 | * Appends a string field to the JSON.
672 | *
673 | * @param key The key of the field.
674 | * @param value The value of the field.
675 | * @return A reference to this object.
676 | */
677 | public JsonObjectBuilder appendField(String key, String value) {
678 | if (value == null) {
679 | throw new IllegalArgumentException("JSON value must not be null");
680 | }
681 | appendFieldUnescaped(key, "\"" + escape(value) + "\"");
682 | return this;
683 | }
684 |
685 | /**
686 | * Appends an integer field to the JSON.
687 | *
688 | * @param key The key of the field.
689 | * @param value The value of the field.
690 | * @return A reference to this object.
691 | */
692 | public JsonObjectBuilder appendField(String key, int value) {
693 | appendFieldUnescaped(key, String.valueOf(value));
694 | return this;
695 | }
696 |
697 | /**
698 | * Appends an object to the JSON.
699 | *
700 | * @param key The key of the field.
701 | * @param object The object.
702 | * @return A reference to this object.
703 | */
704 | public JsonObjectBuilder appendField(String key, JsonObject object) {
705 | if (object == null) {
706 | throw new IllegalArgumentException("JSON object must not be null");
707 | }
708 | appendFieldUnescaped(key, object.toString());
709 | return this;
710 | }
711 |
712 | /**
713 | * Appends a string array to the JSON.
714 | *
715 | * @param key The key of the field.
716 | * @param values The string array.
717 | * @return A reference to this object.
718 | */
719 | public JsonObjectBuilder appendField(String key, String[] values) {
720 | if (values == null) {
721 | throw new IllegalArgumentException("JSON values must not be null");
722 | }
723 | String escapedValues =
724 | Arrays.stream(values)
725 | .map(value -> "\"" + escape(value) + "\"")
726 | .collect(Collectors.joining(","));
727 | appendFieldUnescaped(key, "[" + escapedValues + "]");
728 | return this;
729 | }
730 |
731 | /**
732 | * Appends an integer array to the JSON.
733 | *
734 | * @param key The key of the field.
735 | * @param values The integer array.
736 | * @return A reference to this object.
737 | */
738 | public JsonObjectBuilder appendField(String key, int[] values) {
739 | if (values == null) {
740 | throw new IllegalArgumentException("JSON values must not be null");
741 | }
742 | String escapedValues =
743 | Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
744 | appendFieldUnescaped(key, "[" + escapedValues + "]");
745 | return this;
746 | }
747 |
748 | /**
749 | * Appends an object array to the JSON.
750 | *
751 | * @param key The key of the field.
752 | * @param values The integer array.
753 | * @return A reference to this object.
754 | */
755 | public JsonObjectBuilder appendField(String key, JsonObject[] values) {
756 | if (values == null) {
757 | throw new IllegalArgumentException("JSON values must not be null");
758 | }
759 | String escapedValues =
760 | Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
761 | appendFieldUnescaped(key, "[" + escapedValues + "]");
762 | return this;
763 | }
764 |
765 | /**
766 | * Appends a field to the object.
767 | *
768 | * @param key The key of the field.
769 | * @param escapedValue The escaped value of the field.
770 | */
771 | private void appendFieldUnescaped(String key, String escapedValue) {
772 | if (builder == null) {
773 | throw new IllegalStateException("JSON has already been built");
774 | }
775 | if (key == null) {
776 | throw new IllegalArgumentException("JSON key must not be null");
777 | }
778 | if (hasAtLeastOneField) {
779 | builder.append(",");
780 | }
781 | builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
782 | hasAtLeastOneField = true;
783 | }
784 |
785 | /**
786 | * Builds the JSON string and invalidates this builder.
787 | *
788 | * @return The built JSON string.
789 | */
790 | public JsonObject build() {
791 | if (builder == null) {
792 | throw new IllegalStateException("JSON has already been built");
793 | }
794 | JsonObject object = new JsonObject(builder.append("}").toString());
795 | builder = null;
796 | return object;
797 | }
798 |
799 | /**
800 | * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
801 | *
802 | *
This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
803 | * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
804 | *
805 | * @param value The value to escape.
806 | * @return The escaped value.
807 | */
808 | private static String escape(String value) {
809 | final StringBuilder builder = new StringBuilder();
810 | for (int i = 0; i < value.length(); i++) {
811 | char c = value.charAt(i);
812 | if (c == '"') {
813 | builder.append("\\\"");
814 | } else if (c == '\\') {
815 | builder.append("\\\\");
816 | } else if (c <= '\u000F') {
817 | builder.append("\\u000").append(Integer.toHexString(c));
818 | } else if (c <= '\u001F') {
819 | builder.append("\\u00").append(Integer.toHexString(c));
820 | } else {
821 | builder.append(c);
822 | }
823 | }
824 | return builder.toString();
825 | }
826 |
827 | /**
828 | * A super simple representation of a JSON object.
829 | *
830 | *
This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
831 | * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
832 | * JsonObject)}.
833 | */
834 | public static class JsonObject {
835 |
836 | private final String value;
837 |
838 | private JsonObject(String value) {
839 | this.value = value;
840 | }
841 |
842 | @Override
843 | public String toString() {
844 | return value;
845 | }
846 | }
847 | }
848 | }
--------------------------------------------------------------------------------
/src/main/java/com/bghddevelopment/LuckPemsGUI/util/OpenGUI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) BGHDDevelopment.
3 | * Please refer to the plugin page or GitHub page for our open-source license.
4 | * If you have any questions please email ceo@bghddevelopment or reach us on Discord
5 | */
6 |
7 | package com.bghddevelopment.LuckPemsGUI.util;
8 |
9 | import org.bukkit.Bukkit;
10 | import org.bukkit.ChatColor;
11 | import org.bukkit.Material;
12 | import org.bukkit.entity.Player;
13 | import org.bukkit.inventory.Inventory;
14 | import org.bukkit.inventory.ItemStack;
15 |
16 | import java.util.Arrays;
17 |
18 | public class OpenGUI {
19 |
20 | public static void openGUI(Player sender) {
21 | Inventory myInventory = Bukkit.createInventory(null, 9, ChatColor.AQUA + "LuckPerms");
22 | Tools.onAsync(() -> {
23 | ItemStack button1 = Tools.button(Material.ANVIL, "&6Groups", Arrays.asList("&eSelect to edit groups"), 1);
24 | ItemStack button2 = Tools.button(Material.ANVIL, "&6Users", Arrays.asList("&eSelect to edit online users"), 1);
25 | ItemStack button3 = Tools.button(Material.ANVIL, "&6Tracks", Arrays.asList("&eSelect to edit tracks"), 1);
26 |
27 | myInventory.setItem(2, button1);
28 | myInventory.setItem(4, button2);
29 | myInventory.setItem(6, button3);
30 | });
31 | sender.openInventory(myInventory);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/bghddevelopment/LuckPemsGUI/util/Tools.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) BGHDDevelopment.
3 | * Please refer to the plugin page or GitHub page for our open-source license.
4 | * If you have any questions please email ceo@bghddevelopment or reach us on Discord
5 | */
6 |
7 | package com.bghddevelopment.LuckPemsGUI.util;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.Map.Entry;
12 | import java.util.Random;
13 |
14 | import com.bghddevelopment.LuckPemsGUI.LuckPermsGUI;
15 | import net.luckperms.api.context.ContextSet;
16 | import org.bukkit.Bukkit;
17 | import org.bukkit.ChatColor;
18 | import org.bukkit.Material;
19 | import org.bukkit.entity.Player;
20 | import org.bukkit.inventory.ItemStack;
21 | import org.bukkit.inventory.meta.ItemMeta;
22 | import org.bukkit.inventory.meta.SkullMeta;
23 |
24 | public class Tools {
25 |
26 | public static ItemStack button(Material material, String pavadinimas, List lore, int amount) {
27 | ItemStack item = new ItemStack(material, amount);
28 | ItemMeta meta = item.getItemMeta();
29 | meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', pavadinimas));
30 | meta.setLore(ctranslate(lore));
31 | item.setItemMeta(meta);
32 | return item;
33 | }
34 |
35 | public static ItemStack head(String owner, String pavadinimas, List lore, int amount) {
36 | ItemStack item = new ItemStack(Material.SKULL_ITEM, amount);
37 | SkullMeta meta = (SkullMeta) item.getItemMeta();
38 | meta.setOwner(owner);
39 | meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', pavadinimas));
40 | meta.setLore(ctranslate(lore));
41 | item.setItemMeta(meta);
42 | return item;
43 | }
44 |
45 | private static List ctranslate(List lore) {
46 | List lore2 = new ArrayList<>();
47 | for (String eilute : lore)
48 | lore2.add(ChatColor.translateAlternateColorCodes('&', eilute));
49 | return lore2;
50 | }
51 |
52 | public static int randInt(int min, int max) {
53 | Random rand = new Random();
54 | return rand.nextInt((max - min) + 1) + min;
55 | }
56 |
57 | public static void sendMessage(Player p, String message) {
58 | p.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
59 | }
60 |
61 |
62 | public static void onAsync(Runnable runnable) {
63 | Bukkit.getScheduler().runTaskAsynchronously(LuckPermsGUI.getInstance(), runnable);
64 | }
65 |
66 | public static void sendCommand(Player p, String command) {
67 | //THIS SENDS THE DEV THE COMMAND THE GUI IS RUNNING FOR DEBUGGING AND OTHER DEVELOPMENT NEEDS
68 | if (p.getName().equalsIgnoreCase("Noodles_YT")) {
69 | p.sendMessage(ChatColor.RED + "[DEBUG] " + command);
70 | }
71 | Bukkit.getScheduler().scheduleSyncDelayedTask(LuckPermsGUI.getInstance(), () -> {
72 | Bukkit.dispatchCommand(p, command);
73 | });
74 | }
75 |
76 | // Not usable doesn't send the correct context's anymore
77 | public static String contextConverter(ContextSet contextSet) {
78 | StringBuilder eilute = new StringBuilder();
79 | for (Entry entry : contextSet.toFlattenedMap().entrySet()) {
80 | if (eilute.length() != 0)
81 | eilute.append(" ");
82 | eilute.append(entry.getKey()).append("=").append(entry.getValue());
83 | }
84 | return eilute.toString();
85 | }
86 |
87 | public static String getTime(long time) {
88 | time = time - System.currentTimeMillis();
89 |
90 | long tempSec = time/(1000);
91 | long min = (tempSec /60) % 60;
92 | long hour = (tempSec /(60*60)) % 24;
93 | long temphour = (tempSec /(60*60));
94 | int days = 0;
95 | while (temphour >= 24) {
96 | days++;
97 | temphour -= 24;
98 | }
99 |
100 | return days+"d. "+hour+"h. "+min+"min.";
101 | }
102 |
103 | public static boolean isOnline(String name) {
104 | return Bukkit.getPlayerExact(name) != null;
105 | }
106 |
107 | public static void sendConsole(String string) {
108 | Bukkit.getScheduler().scheduleSyncDelayedTask(LuckPermsGUI.getInstance(), () -> {
109 | Bukkit.dispatchCommand(Bukkit.getConsoleSender(), string);
110 | });
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | name: LuckPermsGUI
2 | main: com.bghddevelopment.LuckPemsGUI.LuckPermsGUI
3 | version: 4.6
4 | author: BGHDDevelopmentLLC
5 | website: https://bghddevelopment.com
6 | depend: [LuckPerms]
7 | permissions:
8 | luckperms.gui:
9 | description: GUI LuckPerms
10 | default: op
11 | commands:
12 | lpgui:
13 | description: Opens LuckPerms GUI
14 | usage: /
--------------------------------------------------------------------------------