Open gui before adding to set

This commit is contained in:
Esophose 2020-03-29 17:14:00 -06:00
parent 413f3cf97c
commit 925241c6e2
2 changed files with 18 additions and 22 deletions

View file

@ -4,6 +4,7 @@ import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.manager.LocaleManager; import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.util.NMSUtil; import dev.esophose.playerparticles.util.NMSUtil;
import dev.esophose.playerparticles.util.StringPlaceholders; import dev.esophose.playerparticles.util.StringPlaceholders;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import net.md_5.bungee.api.ChatMessageType; 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 * Initializes all the static values for this class
*/ */
public static void setup() { public static void setup() {
hooks = new HashSet<>(); hooks = Collections.synchronizedSet(new HashSet<>());
if (hookTask != null) if (hookTask != null)
hookTask.cancel(); hookTask.cancel();
hookTask = new PlayerChatHook().runTaskTimer(PlayerParticles.getInstance(), 0, 20); hookTask = new PlayerChatHook().runTaskTimer(PlayerParticles.getInstance(), 0, 20);

View file

@ -26,7 +26,7 @@ public class GuiManager extends Manager implements Listener, Runnable {
public GuiManager(PlayerParticles playerParticles) { public GuiManager(PlayerParticles playerParticles) {
super(playerParticles); super(playerParticles);
this.guiInventories = new ArrayList<>(); this.guiInventories = Collections.synchronizedList(new ArrayList<>());
this.guiTask = null; this.guiTask = null;
Bukkit.getPluginManager().registerEvents(this, this.playerParticles); Bukkit.getPluginManager().registerEvents(this, this.playerParticles);
@ -62,7 +62,7 @@ public class GuiManager extends Manager implements Listener, Runnable {
return; return;
event.setCancelled(true); event.setCancelled(true);
inventory.onClick(event); Bukkit.getScheduler().runTaskAsynchronously(this.playerParticles, () -> inventory.onClick(event));
} }
@EventHandler(priority = EventPriority.HIGH) @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 * @param pplayer The PPlayer to open the GUI screen for
*/ */
public void openDefault(PPlayer pplayer) { public void openDefault(PPlayer pplayer) {
GuiInventory inventoryToOpen; Bukkit.getScheduler().runTask(this.playerParticles, () -> {
if (!Setting.GUI_PRESETS_ONLY.getBoolean()) { GuiInventory inventoryToOpen;
inventoryToOpen = new GuiInventoryDefault(pplayer); if (!Setting.GUI_PRESETS_ONLY.getBoolean()) {
} else { inventoryToOpen = new GuiInventoryDefault(pplayer);
inventoryToOpen = new GuiInventoryLoadPresetGroups(pplayer, true); } else {
} inventoryToOpen = new GuiInventoryLoadPresetGroups(pplayer, true);
}
pplayer.getPlayer().openInventory(inventoryToOpen.getInventory()); pplayer.getPlayer().openInventory(inventoryToOpen.getInventory());
this.guiInventories.add(inventoryToOpen); this.guiInventories.add(inventoryToOpen);
});
} }
/** /**
@ -126,8 +128,10 @@ public class GuiManager extends Manager implements Listener, Runnable {
* @param nextInventory The GuiInventory to transition to * @param nextInventory The GuiInventory to transition to
*/ */
public void transition(GuiInventory nextInventory) { public void transition(GuiInventory nextInventory) {
this.guiInventories.add(nextInventory); Bukkit.getScheduler().runTask(this.playerParticles, () -> {
nextInventory.getPPlayer().getPlayer().openInventory(nextInventory.getInventory()); nextInventory.getPPlayer().getPlayer().openInventory(nextInventory.getInventory());
this.guiInventories.add(nextInventory);
});
} }
/** /**
@ -142,14 +146,5 @@ public class GuiManager extends Manager implements Listener, Runnable {
.findFirst() .findFirst()
.orElse(null); .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()));
}
} }