mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-02-11 03:29:53 +00:00
Open gui before adding to set
This commit is contained in:
parent
413f3cf97c
commit
925241c6e2
2 changed files with 18 additions and 22 deletions
|
@ -4,6 +4,7 @@ import dev.esophose.playerparticles.PlayerParticles;
|
|||
import dev.esophose.playerparticles.manager.LocaleManager;
|
||||
import dev.esophose.playerparticles.util.NMSUtil;
|
||||
import dev.esophose.playerparticles.util.StringPlaceholders;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
|
@ -25,7 +26,7 @@ public class PlayerChatHook extends BukkitRunnable implements Listener {
|
|||
* Initializes all the static values for this class
|
||||
*/
|
||||
public static void setup() {
|
||||
hooks = new HashSet<>();
|
||||
hooks = Collections.synchronizedSet(new HashSet<>());
|
||||
if (hookTask != null)
|
||||
hookTask.cancel();
|
||||
hookTask = new PlayerChatHook().runTaskTimer(PlayerParticles.getInstance(), 0, 20);
|
||||
|
|
|
@ -26,7 +26,7 @@ public class GuiManager extends Manager implements Listener, Runnable {
|
|||
public GuiManager(PlayerParticles playerParticles) {
|
||||
super(playerParticles);
|
||||
|
||||
this.guiInventories = new ArrayList<>();
|
||||
this.guiInventories = Collections.synchronizedList(new ArrayList<>());
|
||||
this.guiTask = null;
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this.playerParticles);
|
||||
|
@ -62,7 +62,7 @@ public class GuiManager extends Manager implements Listener, Runnable {
|
|||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
inventory.onClick(event);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.playerParticles, () -> inventory.onClick(event));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
|
@ -109,15 +109,17 @@ public class GuiManager extends Manager implements Listener, Runnable {
|
|||
* @param pplayer The PPlayer to open the GUI screen for
|
||||
*/
|
||||
public void openDefault(PPlayer pplayer) {
|
||||
GuiInventory inventoryToOpen;
|
||||
if (!Setting.GUI_PRESETS_ONLY.getBoolean()) {
|
||||
inventoryToOpen = new GuiInventoryDefault(pplayer);
|
||||
} else {
|
||||
inventoryToOpen = new GuiInventoryLoadPresetGroups(pplayer, true);
|
||||
}
|
||||
Bukkit.getScheduler().runTask(this.playerParticles, () -> {
|
||||
GuiInventory inventoryToOpen;
|
||||
if (!Setting.GUI_PRESETS_ONLY.getBoolean()) {
|
||||
inventoryToOpen = new GuiInventoryDefault(pplayer);
|
||||
} else {
|
||||
inventoryToOpen = new GuiInventoryLoadPresetGroups(pplayer, true);
|
||||
}
|
||||
|
||||
pplayer.getPlayer().openInventory(inventoryToOpen.getInventory());
|
||||
this.guiInventories.add(inventoryToOpen);
|
||||
pplayer.getPlayer().openInventory(inventoryToOpen.getInventory());
|
||||
this.guiInventories.add(inventoryToOpen);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,8 +128,10 @@ public class GuiManager extends Manager implements Listener, Runnable {
|
|||
* @param nextInventory The GuiInventory to transition to
|
||||
*/
|
||||
public void transition(GuiInventory nextInventory) {
|
||||
this.guiInventories.add(nextInventory);
|
||||
nextInventory.getPPlayer().getPlayer().openInventory(nextInventory.getInventory());
|
||||
Bukkit.getScheduler().runTask(this.playerParticles, () -> {
|
||||
nextInventory.getPPlayer().getPlayer().openInventory(nextInventory.getInventory());
|
||||
this.guiInventories.add(nextInventory);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,13 +147,4 @@ public class GuiManager extends Manager implements Listener, Runnable {
|
|||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a GuiInventory from guiInventories by a PPlayer
|
||||
*
|
||||
* @param pplayer The PPlayer who owns the GuiInventory
|
||||
*/
|
||||
private void removeGuiInventory(PPlayer pplayer) {
|
||||
this.guiInventories.removeIf(x -> x.getPPlayer().getUniqueId().equals(pplayer.getUniqueId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue