mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
feat: use vanished metadata rather than apis for each plugin
This commit is contained in:
@@ -89,7 +89,6 @@ allprojects {
|
||||
compileOnly("it.unimi.dsi:fastutil:8.5.15")
|
||||
compileOnly("com.denizenscript:denizen:1.2.7-SNAPSHOT")
|
||||
compileOnly("io.lumine:Mythic-Dist:5.8.0")
|
||||
compileOnly("com.github.LeonMangler:SuperVanish:6.2.17")
|
||||
compileOnly("net.Indyuce:MMOItems-API:6.9.4-SNAPSHOT")
|
||||
compileOnly("com.willfp:eco:6.74.5")
|
||||
compileOnly("me.clip:placeholderapi:2.11.6")
|
||||
|
||||
@@ -152,12 +152,4 @@ public abstract class Hook implements Listener {
|
||||
public String getEntityString(@NotNull Entity entity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the entity is invisible (as defined by the hook)
|
||||
* @return true if the entity is invisible, false otherwise (or if the hook does not support entity invisibility)
|
||||
*/
|
||||
public boolean isInvisible(UUID uuid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,13 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Hooks {
|
||||
@@ -30,8 +30,6 @@ public class Hooks {
|
||||
private static final HookGeary GEARY_HOOK = new HookGeary();
|
||||
private static final HookMythic MYTHIC_HOOK = new HookMythic();
|
||||
private static final HookDenizen DENIZEN_HOOK = new HookDenizen();
|
||||
private static final HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
|
||||
private static final HookSuperVanish SUPER_VANISH_HOOK = new HookSuperVanish();
|
||||
private static final HookHMCColor HMC_COLOR_HOOK = new HookHMCColor();
|
||||
private static final HookCMI CMI_HOOK = new HookCMI();
|
||||
private static final HookLibsDisguises LIBS_DISGUISES_HOOK = new HookLibsDisguises();
|
||||
@@ -53,11 +51,11 @@ public class Hooks {
|
||||
return HOOK_POOL.containsKey(id.toLowerCase());
|
||||
}
|
||||
|
||||
public static void addHook(Hook hook) {
|
||||
public static void addHook(@NotNull Hook hook) {
|
||||
HOOK_POOL.put(hook.getId().toLowerCase(), hook);
|
||||
}
|
||||
|
||||
public static void addPlaceholderAPI(PlaceholderExpansion expansion) {
|
||||
public static void addPlaceholderAPI(@NotNull PlaceholderExpansion expansion) {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
HookPlaceholderAPI hook = (HookPlaceholderAPI) getHook("PlaceholderAPI");
|
||||
hook.registerPlaceholder(expansion);
|
||||
@@ -133,7 +131,7 @@ public class Hooks {
|
||||
return hook.getItem(split[1]);
|
||||
}
|
||||
|
||||
public static String getStringItem(ItemStack itemStack) {
|
||||
public static String getStringItem(@NotNull ItemStack itemStack) {
|
||||
for (Hook hook : HOOK_POOL.values()) {
|
||||
if (hook.isDetected() && hook.hasEnabledItemHook()) {
|
||||
String stringyItem = hook.getItemString(itemStack);
|
||||
@@ -144,7 +142,7 @@ public class Hooks {
|
||||
return itemStack.getType().toString();
|
||||
}
|
||||
|
||||
public static String getStringEntity(Entity entity) {
|
||||
public static String getStringEntity(@NotNull Entity entity) {
|
||||
for (Hook hook : HOOK_POOL.values()) {
|
||||
if (hook.isDetected() && hook.hasEnabledEntityHook()) {
|
||||
String stringyEntity = hook.getEntityString(entity);
|
||||
@@ -155,19 +153,20 @@ public class Hooks {
|
||||
return entity.getType().toString().toUpperCase();
|
||||
}
|
||||
|
||||
public static boolean isActiveHook(String id) {
|
||||
public static boolean isActiveHook(@NotNull String id) {
|
||||
Hook hook = getHook(id);
|
||||
if (hook == null) return false;
|
||||
if (!hook.isDetected()) return false;
|
||||
return hook.isActive();
|
||||
}
|
||||
|
||||
public static boolean isInvisible(UUID uuid) {
|
||||
for (Hook hook : HOOK_POOL.values()) {
|
||||
if (hook.isDetected()) {
|
||||
if (hook.isInvisible(uuid)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public static boolean isInvisible(@NotNull UUID uuid) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
return isInvisible(player);
|
||||
}
|
||||
|
||||
public static boolean isInvisible(@NotNull Player player) {
|
||||
return player.getMetadata("vanished").getFirst().asBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,11 +34,4 @@ public class HookCMI extends Hook {
|
||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvisible(UUID uuid) {
|
||||
Player onlinePlayer = Bukkit.getPlayer(uuid);
|
||||
if (onlinePlayer == null) return false;
|
||||
return CMI.getInstance().getVanishManager().getAllVanished().contains(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,11 +33,4 @@ public class HookLibsDisguises extends Hook {
|
||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, player);
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvisible(UUID uuid) {
|
||||
Player onlinePlayer = Bukkit.getPlayer(uuid);
|
||||
if (onlinePlayer == null) return false;
|
||||
return DisguiseAPI.isDisguised(onlinePlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.misc;
|
||||
|
||||
import de.myzelyam.api.vanish.PlayerHideEvent;
|
||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
||||
import de.myzelyam.api.vanish.VanishAPI;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerUnVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||
*
|
||||
* @implSpec Supervanish and Premium Vanish both use the same api
|
||||
*/
|
||||
public class HookPremiumVanish extends Hook {
|
||||
public HookPremiumVanish() {
|
||||
super("PremiumVanish");
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
|
||||
HibiscusPlayerVanishEvent newEvent = new HibiscusPlayerVanishEvent(this, event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvisible(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.isOnline()) return false;
|
||||
Player player = offlinePlayer.getPlayer();
|
||||
if (player == null) return false;
|
||||
return VanishAPI.isInvisible(player);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.misc;
|
||||
|
||||
import de.myzelyam.api.vanish.PlayerHideEvent;
|
||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
||||
import de.myzelyam.api.vanish.VanishAPI;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerUnVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||
*
|
||||
* @implSpec Supervanish and Premium Vanish both use the same api
|
||||
*/
|
||||
public class HookSuperVanish extends Hook {
|
||||
public HookSuperVanish() {
|
||||
super("SuperVanish");
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
|
||||
HibiscusPlayerVanishEvent newEvent = new HibiscusPlayerVanishEvent(this, event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvisible(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.isOnline()) return false;
|
||||
Player player = offlinePlayer.getPlayer();
|
||||
if (player == null) return false;
|
||||
return VanishAPI.isInvisible(player);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user