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

Datei anzeigen

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