Skip to content

Commit 46aaa47

Browse files
author
NEZNAMY
committed
[Forge] Add hook into a random Vanish mod for checking vanish status
1 parent 2027e9f commit 46aaa47

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

forge/src/main/java/me/neznamy/tab/platforms/forge/ForgeTabPlayer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.neznamy.tab.platforms.forge;
22

33
import me.neznamy.tab.platforms.forge.hook.LuckPermsAPIHook;
4+
import me.neznamy.tab.platforms.forge.hook.VanishHook;
45
import me.neznamy.tab.shared.backend.BackendTabPlayer;
56
import me.neznamy.tab.shared.chat.component.TabComponent;
67
import net.minecraft.SharedConstants;
@@ -64,6 +65,9 @@ public ForgePlatform getPlatform() {
6465

6566
@Override
6667
public boolean isVanished0() {
68+
if (VanishHook.isInstalled()) {
69+
return VanishHook.isVanished(getPlayer());
70+
}
6771
return false;
6872
}
6973

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package me.neznamy.tab.platforms.forge.hook;
2+
3+
import lombok.SneakyThrows;
4+
import net.minecraft.server.level.ServerPlayer;
5+
import net.minecraft.world.entity.player.Player;
6+
import net.minecraftforge.fml.ModList;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
import java.lang.reflect.Method;
11+
12+
/**
13+
* Vanish hook for Forge.
14+
*/
15+
public class VanishHook {
16+
17+
/** Method for getting vanish status for a player. */
18+
@Nullable
19+
private static Method isVanished;
20+
21+
static {
22+
try {
23+
if (ModList.get().isLoaded("vmod")) {
24+
isVanished = Class.forName("redstonedubstep.mods.vanishmod.VanishUtil").getMethod("isVanished", Player.class);
25+
}
26+
} catch (Exception e) {
27+
e.printStackTrace();
28+
}
29+
}
30+
31+
/**
32+
* Checks if Vanish mod is installed.
33+
*
34+
* @return {@code true} if installed, {@code false} if not
35+
*/
36+
public static boolean isInstalled() {
37+
return isVanished != null;
38+
}
39+
40+
/**
41+
* Check if the player is vanished.
42+
*
43+
* @param player
44+
* Player to check
45+
* @return {@code true} if vanished, {@code false} if not
46+
*/
47+
@SneakyThrows
48+
public static boolean isVanished(@NotNull ServerPlayer player) {
49+
if (isVanished == null) return false;
50+
return (boolean) isVanished.invoke(null, player);
51+
}
52+
}

0 commit comments

Comments
 (0)