Skip to content

Commit

Permalink
Fixes #239
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Jul 9, 2020
1 parent 6a79351 commit d309405
Showing 1 changed file with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;

import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
Expand Down Expand Up @@ -118,7 +119,7 @@ else if (this.pageIndex > (libraryEntries.size() / MAX_ELEMENTS))
}

panelBuilder.item(4, this.createDownloadNow());
panelBuilder.item(44, this.returnButton);
panelBuilder.item(44, this.createReturnButton());

panelBuilder.build();
}
Expand Down Expand Up @@ -153,10 +154,16 @@ private PanelItem createDownloadNow()
}
else
{
this.addon.getWebManager().requestCatalogGitHubData(false);
this.addon.getWebManager().requestCatalogGitHubData(this.clearCache);

// Fix multiclick issue.
if (this.updateTask != null)
{
this.updateTask.cancel();
}

// add some delay to rebuilding gui.
this.addon.getPlugin().getServer().getScheduler().runTaskLaterAsynchronously(
this.updateTask = this.addon.getPlugin().getServer().getScheduler().runTaskLater(
this.addon.getPlugin(),
this::build,
100L);
Expand All @@ -169,6 +176,33 @@ private PanelItem createDownloadNow()
}


/**
* This creates return button, that allows to exist or return to parent gui,
* @return PanelItem for return button.
*/
private PanelItem createReturnButton()
{
return new PanelItemBuilder().
name(this.user.getTranslation("challenges.gui.buttons.return")).
icon(Material.OAK_DOOR).
clickHandler((panel, user1, clickType, i) -> {
if (this.updateTask != null)
{
this.updateTask.cancel();
}

if (this.parentGUI == null)
{
this.user.closeInventory();
return true;
}

this.parentGUI.build();
return true;
}).build();
}


/**
* This method creates button for given library entry.
* @param libraryEntry LibraryEntry which button must be created.
Expand Down Expand Up @@ -199,10 +233,20 @@ private PanelItem createEntryIcon(LibraryEntry libraryEntry)

if (this.parentGUI != null)
{
if (this.updateTask != null)
{
this.updateTask.cancel();
}

this.parentGUI.build();
}
else
{
if (this.updateTask != null)
{
this.updateTask.cancel();
}

this.user.closeInventory();
}
}
Expand Down Expand Up @@ -252,6 +296,11 @@ private List<String> generateEntryDescription(LibraryEntry entry)
*/
private boolean clearCache;

/**
* Stores update task that is triggered.
*/
private BukkitTask updateTask = null;

/**
* This variable will protect against spam-click.
*/
Expand Down

0 comments on commit d309405

Please sign in to comment.