This commit is contained in:
BONNe 2020-07-09 23:25:25 +03:00
parent 6a79351685
commit d3094053eb
1 changed files with 52 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
@ -118,7 +119,7 @@ public class ListLibraryGUI extends CommonGUI
} }
panelBuilder.item(4, this.createDownloadNow()); panelBuilder.item(4, this.createDownloadNow());
panelBuilder.item(44, this.returnButton); panelBuilder.item(44, this.createReturnButton());
panelBuilder.build(); panelBuilder.build();
} }
@ -153,10 +154,16 @@ public class ListLibraryGUI extends CommonGUI
} }
else 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. // add some delay to rebuilding gui.
this.addon.getPlugin().getServer().getScheduler().runTaskLaterAsynchronously( this.updateTask = this.addon.getPlugin().getServer().getScheduler().runTaskLater(
this.addon.getPlugin(), this.addon.getPlugin(),
this::build, this::build,
100L); 100L);
@ -169,6 +176,33 @@ public class ListLibraryGUI extends CommonGUI
} }
/**
* 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. * This method creates button for given library entry.
* @param libraryEntry LibraryEntry which button must be created. * @param libraryEntry LibraryEntry which button must be created.
@ -199,10 +233,20 @@ public class ListLibraryGUI extends CommonGUI
if (this.parentGUI != null) if (this.parentGUI != null)
{ {
if (this.updateTask != null)
{
this.updateTask.cancel();
}
this.parentGUI.build(); this.parentGUI.build();
} }
else else
{ {
if (this.updateTask != null)
{
this.updateTask.cancel();
}
this.user.closeInventory(); this.user.closeInventory();
} }
} }
@ -252,6 +296,11 @@ public class ListLibraryGUI extends CommonGUI
*/ */
private boolean clearCache; private boolean clearCache;
/**
* Stores update task that is triggered.
*/
private BukkitTask updateTask = null;
/** /**
* This variable will protect against spam-click. * This variable will protect against spam-click.
*/ */