44import com .comphenix .protocol .wrappers .WrappedChatComponent ;
55import com .sentropic .guiapi .GUIAPI ;
66import com .sentropic .guiapi .packet .WrapperPlayServerTitle ;
7- import org .bukkit .configuration .ConfigurationSection ;
87import org .bukkit .entity .Player ;
98import org .jetbrains .annotations .NotNull ;
109
@@ -20,6 +19,7 @@ public class GUI {
2019 private boolean changed = true ;
2120 private final WrapperPlayServerTitle packet ;
2221 private boolean debug = false ;
22+ private long lastSend = 0 ;
2323
2424 public GUI (Player player ) {
2525 this .player = player ;
@@ -102,37 +102,12 @@ public boolean removeIf(Predicate<GUIComponent> predicate) {
102102
103103 public boolean isDebugging () { return debug ; }
104104
105- private static final String ID_DEBUG = "debug:" ;
105+ public static final String ID_DEBUG = "debug:" ;
106106
107107 public void setDebug (boolean debug ) {
108108 if (this .debug == debug ) { return ; } else { this .debug = debug ; }
109109 if (debug ) {
110- List <GUIComponent > debugComponents = new ArrayList <>();
111- ConfigurationSection debugSection = GUIAPI .getPlugin ().getConfig ().getConfigurationSection ("debug" );
112- if (debugSection == null ) { return ; }
113- for (String componentKey : debugSection .getKeys (false )) {
114- try {
115- ConfigurationSection componentSection = Objects .requireNonNull (debugSection .getConfigurationSection (componentKey ));
116- ConfigurationSection fontSection = Objects .requireNonNull (componentSection .getConfigurationSection ("font" ));
117-
118- String id = ID_DEBUG +componentKey ;
119- int offset = componentSection .getInt ("offset" );
120- String text = Objects .requireNonNull (componentSection .getString ("text" ));
121- int width = componentSection .getInt ("width" , -1 );
122-
123- Font font = new Font (Objects .requireNonNull (fontSection .getString ("id" )),
124- fontSection .getInt ("height" ));
125- Alignment alignment = Alignment .valueOf (Objects .requireNonNull (componentSection .getString ("alignment" )).toUpperCase ());
126- boolean scale = componentSection .getBoolean ("scale" , true );
127-
128- GUIComponent component ;
129- if (width == -1 ) { component = new GUIComponent (id , offset , text , font , alignment , scale ); } else {
130- component = new GUIComponent (id , offset , text , width , font , alignment );
131- }
132- debugComponents .add (component );
133- } catch (NullPointerException | IllegalArgumentException ignored ) { }
134- }
135- for (GUIComponent component : debugComponents ) { putOnTop (component ); }
110+ for (GUIComponent component : GUIAPI .getGUIConfig ().getDebugComponents ()) { putOnTop (component ); }
136111 } else { removeIf (component -> component .getID ().startsWith (ID_DEBUG )); }
137112 }
138113
@@ -176,10 +151,15 @@ public String getRawJson() {
176151 }
177152
178153 public void play () {
179- if (changed ) { build (); }
180- sendingPacket = true ;
181- packet .sendPacket (player );
182- sendingPacket = false ;
154+ long time = System .currentTimeMillis ();
155+ boolean play = changed || time -lastSend >= GUIAPI .getGUIConfig ().getSendPeriod ();
156+ if (play ) {
157+ lastSend = time ;
158+ if (changed ) { build (); }
159+ sendingPacket = true ;
160+ packet .sendPacket (player );
161+ sendingPacket = false ;
162+ }
183163 }
184164
185165 public static String spacesOf (int amount ) {
0 commit comments