DREAMFIRE Docs ← Back to site
Loading...
Searching...
No Matches
DreamVanish.java
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Dreamfire Studio
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24package com.dreamfirestudios.dreamcore.DreamVanish;
25
26import com.dreamfirestudios.dreamcore.DreamCore;
27import org.bukkit.Bukkit;
28import org.bukkit.entity.Entity;
29import org.bukkit.entity.Player;
30
31import java.util.ArrayList;
32
46public class DreamVanish {
47
53 public static void hideTargetFromViewer(Entity target, Player viewer) {
54 if (target == null || viewer == null) return;
55
56 var hiddenViewers = DreamCore.DreamVanishs.computeIfAbsent(target.getUniqueId(), k -> new ArrayList<>());
57 if (!hiddenViewers.contains(viewer.getUniqueId())) {
58 hiddenViewers.add(viewer.getUniqueId());
59 }
60
61 new VanishHideTargetEvent(target, viewer);
62 }
63
69 public static void showTargetToViewer(Entity target, Player viewer) {
70 if (target == null || viewer == null) return;
71
72 var hiddenViewers = DreamCore.DreamVanishs.get(target.getUniqueId());
73 if (hiddenViewers != null) {
74 hiddenViewers.remove(viewer.getUniqueId());
75 if (hiddenViewers.isEmpty()) {
76 DreamCore.DreamVanishs.remove(target.getUniqueId());
77 }
78 }
79
80 new VanishShowTargetEvent(target, viewer);
81 }
82
89 public static boolean canViewerSeeTarget(Entity target, Player viewer) {
90 if (target == null || viewer == null) return false;
91
92 var hiddenViewers = DreamCore.DreamVanishs.get(target.getUniqueId());
93 return hiddenViewers == null || !hiddenViewers.contains(viewer.getUniqueId());
94 }
95
102 public static void updateVanishOnAllPlayers() {
103 var onlinePlayers = Bukkit.getOnlinePlayers();
104 var viewerHideMatrix = DreamCore.DreamVanishs;
105
106 viewerHideMatrix.forEach((targetUUID, hiddenViewers) -> {
107 var target = Bukkit.getEntity(targetUUID);
108 if (target == null) {
109 viewerHideMatrix.remove(targetUUID);
110 return;
111 }
112
113 for (var viewer : onlinePlayers) {
114 if (viewer.getUniqueId().equals(targetUUID)) continue;
115
116 if (hiddenViewers.contains(viewer.getUniqueId())) {
117 viewer.hideEntity(DreamCore.DreamCore, target);
118 } else {
119 viewer.showEntity(DreamCore.DreamCore, target);
120 }
121 }
122 });
123 }
124}
static final LinkedHashMap< UUID, List< UUID > > DreamVanishs
Static helpers for per-viewer vanish/visibility tracking.
static void updateVanishOnAllPlayers()
Applies the current vanish matrix to all online players (hide/show).
static boolean canViewerSeeTarget(Entity target, Player viewer)
Checks whether a viewer can currently see a target entity.
static void showTargetToViewer(Entity target, Player viewer)
Shows a previously hidden target entity to a specific viewer and fires VanishShowTargetEvent.
static void hideTargetFromViewer(Entity target, Player viewer)
Hides a target entity from a specific viewer and fires VanishHideTargetEvent.
Fired when a target entity is marked hidden from a specific viewer via DreamVanish::hideTargetFromVie...
Fired when a target entity is marked visible to a specific viewer via DreamVanish::showTargetToViewer...