SteamWar/BauSystem2.0
Archiviert
12
0
Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-05-02 16:11:47 +02:00
Ursprung 23aa8c94a9
Commit 1fa3015b36
2 geänderte Dateien mit 29 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -52,6 +53,7 @@ import java.util.Map;
@Linked(LinkageType.LISTENER)
public class BauGuiEditor implements Listener {
@Getter
private static final List<Player> open_Edits = new ArrayList<>();
public static void openGuiEditor(Player p, ItemStack cursor) {
@ -78,6 +80,7 @@ public class BauGuiEditor implements Listener {
p.openInventory(inv);
p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor);
open_Edits.add(p);
BauGuiMapping.startWatchdog();
}
private static ItemStack addId(ItemStack itemStack, int id) {
@ -180,7 +183,9 @@ public class BauGuiEditor implements Listener {
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if (open_Edits.contains(event.getWhoClicked())) {
event.setCancelled(true);
if (event.getRawSlots().stream().anyMatch(integer -> event.getView().getInventory(integer) == event.getWhoClicked().getInventory())) {
event.setCancelled(true);
}
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.util.*;
@ -31,10 +32,28 @@ public class BauGuiMapping {
private static final HashMap<UUID, BauGuiMapping> fromUUID = new HashMap<>();
private static final List<BauGuiMapping> mappings = new ArrayList<>();
static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
mappings.forEach(BauGuiMapping::tick);
}, 1, 1);
private static BukkitTask task;
public static void startWatchdog() {
if (task == null) {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
mappings.forEach(BauGuiMapping::tick);
if (BauGuiEditor.getOpen_Edits().isEmpty()) {
bukkitTask.cancel();
task = null;
}
}, 1, 1);
}
}
public static BauGuiMapping getGuiMapping(Player p) {
BauGuiMapping mapping = fromUUID.get(p.getUniqueId());
if (mapping == null) {
mapping = TempClass.DEFAULT_GUI.apply(p.getUniqueId());
}
return mapping;
}
@Getter
@ -61,16 +80,6 @@ public class BauGuiMapping {
mappings.add(this);
}
public static BauGuiMapping getGuiMapping(Player p) {
BauGuiMapping mapping = fromUUID.get(p.getUniqueId());
if (mapping == null) {
mapping = TempClass.DEFAULT_GUI.apply(p.getUniqueId());
}
return mapping;
}
public boolean isShown(int id) {
if (!mapping.containsKey(id)) {
return false;