22
33import com .comphenix .protocol .wrappers .EnumWrappers ;
44import com .comphenix .protocol .wrappers .WrappedChatComponent ;
5+ import com .sentropic .guiapi .GUIAPI ;
56import com .sentropic .guiapi .packet .WrapperPlayServerTitle ;
7+ import org .apache .commons .lang .ObjectUtils ;
8+ import org .bukkit .configuration .ConfigurationSection ;
69import org .bukkit .entity .Player ;
710import org .jetbrains .annotations .NotNull ;
811
@@ -17,6 +20,7 @@ public class GUI {
1720 private String rawJson ;
1821 private boolean changed = true ;
1922 private final WrapperPlayServerTitle packet ;
23+ private boolean debug = false ;
2024
2125 public GUI (Player player ) {
2226 this .player = player ;
@@ -27,23 +31,23 @@ public GUI(Player player) {
2731 public Player getPlayer () { return player ; }
2832
2933 public void putOnTop (@ NotNull GUIComponent guiComponent ) {
30- remove (guiComponent .getId ());
34+ remove (guiComponent .getID ());
3135 guiComponents .add (guiComponent );
3236 changed = true ;
3337 }
3438
3539 public void putUnderneath (@ NotNull GUIComponent guiComponent ) {
36- remove (guiComponent .getId ());
40+ remove (guiComponent .getID ());
3741 guiComponents .add (0 , guiComponent );
3842 changed = true ;
3943 }
4044
4145 public boolean update (@ NotNull GUIComponent guiComponent ) {
4246 boolean success = false ;
43- String id = guiComponent .getId ();
47+ String id = guiComponent .getID ();
4448 for (ListIterator <GUIComponent > iterator = guiComponents .listIterator (); iterator .hasNext (); ) {
4549 GUIComponent component = iterator .next ();
46- if (component .getId ().equals (id )) {
50+ if (component .getID ().equals (id )) {
4751 iterator .set (guiComponent );
4852 changed = true ;
4953 success = true ;
@@ -55,11 +59,11 @@ public boolean update(@NotNull GUIComponent guiComponent) {
5559
5660 public boolean putAfter (String after , @ NotNull GUIComponent guiComponent ) {
5761 boolean success = false ;
58- remove (guiComponent .getId ());
62+ remove (guiComponent .getID ());
5963 int i = 0 ;
6064 for (GUIComponent component : guiComponents ) {
6165 i ++;
62- if (component .getId ().equals (after )) {
66+ if (component .getID ().equals (after )) {
6367 guiComponents .add (i , guiComponent );
6468 changed = true ;
6569 success = true ;
@@ -71,11 +75,11 @@ public boolean putAfter(String after, @NotNull GUIComponent guiComponent) {
7175
7276 public boolean putBefore (String before , @ NotNull GUIComponent guiComponent ) {
7377 boolean success = false ;
74- remove (guiComponent .getId ());
78+ remove (guiComponent .getID ());
7579 int i = -1 ;
7680 for (GUIComponent component : guiComponents ) {
7781 i ++;
78- if (component .getId ().equals (before )) {
82+ if (component .getID ().equals (before )) {
7983 guiComponents .add (i , guiComponent );
8084 changed = true ;
8185 success = true ;
@@ -86,7 +90,7 @@ public boolean putBefore(String before, @NotNull GUIComponent guiComponent) {
8690 }
8791
8892 public boolean remove (String id ) {
89- boolean success = guiComponents .removeIf (guiComponent -> guiComponent .getId ().equals (id ));
93+ boolean success = guiComponents .removeIf (guiComponent -> guiComponent .getID ().equals (id ));
9094 changed = success || changed ;
9195 return success ;
9296 }
@@ -95,6 +99,36 @@ public boolean removeIf(Predicate<GUIComponent> predicate) {
9599 return guiComponents .removeIf (predicate );
96100 }
97101
102+ public boolean isDebugging () { return debug ; }
103+
104+ private static final String ID_DEBUG = "debug:" ;
105+ public void setDebug (boolean debug ) {
106+ if (this .debug == debug ) { return ; }
107+ else { this .debug = debug ; }
108+ if (debug ) {
109+ List <GUIComponent > debugComponents = new ArrayList <>();
110+ ConfigurationSection debugSection = GUIAPI .getPlugin ().getConfig ().getConfigurationSection ("debug" );
111+ if (debugSection == null ) { return ; }
112+ for (String componentKey : debugSection .getKeys (false )) {
113+ try {
114+ ConfigurationSection componentSection = Objects .requireNonNull (debugSection .getConfigurationSection (componentKey ));
115+ ConfigurationSection fontSection = Objects .requireNonNull (componentSection .getConfigurationSection ("font" ));
116+
117+ String id = ID_DEBUG +componentKey ;
118+ int offset = componentSection .getInt ("offset" );
119+ String text = Objects .requireNonNull (componentSection .getString ("text" ));
120+ Font font = new Font (Objects .requireNonNull (fontSection .getString ("id" )),
121+ fontSection .getInt ("height" ));
122+ Alignment alignment = Alignment .valueOf (Objects .requireNonNull (componentSection .getString ("alignment" )).toUpperCase ());
123+ boolean scale = componentSection .getBoolean ("scale" , true );
124+
125+ debugComponents .add (new GUIComponent (id , offset , text , font , alignment , scale ));
126+ } catch (NullPointerException | IllegalArgumentException ignored ) { }
127+ }
128+ for (GUIComponent component : debugComponents ) { putOnTop (component ); }
129+ } else { removeIf (component -> component .getID ().startsWith (ID_DEBUG )); }
130+ }
131+
98132 private void build () {
99133 StringBuilder builder = new StringBuilder ("[{\" text\" :\" " );
100134 int offset = 0 ;
0 commit comments