Skip to content

Commit 3ee1a16

Browse files
author
codeHusky
committed
Prevent unneccesary interrupt calls (interrupt should only fire once) and introduce Page#hasInterrupt
1 parent f8ae19d commit 3ee1a16

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

  • src/main/java/com/codehusky/huskyui/states

src/main/java/com/codehusky/huskyui/states/Page.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ public Inventory getPageView(int pagenum) {
289289
.of(this.inventoryArchetype)
290290
.listener(InteractInventoryEvent.class, event -> {
291291
if(event instanceof InteractInventoryEvent.Close){
292-
interrupt();
292+
if(this.interrupt != null) {
293+
interrupt();
294+
}
293295
return;
294296
}
295297
if (!(event instanceof InteractInventoryEvent.Open) && !(event instanceof InteractInventoryEvent.Close)) {
@@ -416,24 +418,36 @@ public void setObserver(final Player observer) {
416418
}
417419

418420
public void interrupt(){
419-
System.out.println("-++-\nINTERRUPT\nInterrupt Is Null: " + (this.interrupt == null) + "\nUpdater Task Is Null: " + (this.updaterTask == null));
420-
if(this.interrupt != null) {
421+
//System.out.println("-++-\nINTERRUPT\nInterrupt Is Null: " + (this.interrupt == null) + "\nUpdater Task Is Null: " + (this.updaterTask == null));
422+
if(hasInterupt()) {
421423
try {
422424
this.interrupt.run();
425+
this.interrupt = null;
426+
System.out.println("Interrupt ran.");
423427
}catch (Exception e){
424428
HuskyUI.getLogger().error("Error occurred while running HuskyUI Page interrupt.");
425429
e.printStackTrace();
426430
}
427-
System.out.println("Interrupt ran.");
431+
432+
}else{
433+
throw new RuntimeException("Interrupt either doen't exist, or has been called already");
428434
}
429435
if(updaterTask != null) {
430436
updaterTask.cancel();
431437
System.out.println("Updater cancelled");
432438
updaterTask = null;
433439
System.out.println("Updater set to null.");
434440
}
441+
if(hasObserver()){
442+
getObserver().closeInventory();
443+
}
435444
}
436445

446+
public boolean hasInterupt() {
447+
return this.interrupt != null;
448+
}
449+
450+
437451
/**
438452
* {@inheritDoc}
439453
*

0 commit comments

Comments
 (0)