mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
Merge pull request #14 from HibiscusMC/improve-vanish
Use Vanish Metadata rather than individual APIs
This commit is contained in:
@@ -152,12 +152,4 @@ public abstract class Hook implements Listener {
|
|||||||
public String getEntityString(@NotNull Entity entity) {
|
public String getEntityString(@NotNull Entity entity) {
|
||||||
return null;
|
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,14 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Hooks {
|
public class Hooks {
|
||||||
@@ -30,8 +31,6 @@ public class Hooks {
|
|||||||
private static final HookGeary GEARY_HOOK = new HookGeary();
|
private static final HookGeary GEARY_HOOK = new HookGeary();
|
||||||
private static final HookMythic MYTHIC_HOOK = new HookMythic();
|
private static final HookMythic MYTHIC_HOOK = new HookMythic();
|
||||||
private static final HookDenizen DENIZEN_HOOK = new HookDenizen();
|
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 HookHMCColor HMC_COLOR_HOOK = new HookHMCColor();
|
||||||
private static final HookCMI CMI_HOOK = new HookCMI();
|
private static final HookCMI CMI_HOOK = new HookCMI();
|
||||||
private static final HookLibsDisguises LIBS_DISGUISES_HOOK = new HookLibsDisguises();
|
private static final HookLibsDisguises LIBS_DISGUISES_HOOK = new HookLibsDisguises();
|
||||||
@@ -42,6 +41,8 @@ public class Hooks {
|
|||||||
private static final HookCustomFishing CF_HOOK = new HookCustomFishing();
|
private static final HookCustomFishing CF_HOOK = new HookCustomFishing();
|
||||||
private static final HookGSit GSIT_HOOK = new HookGSit();
|
private static final HookGSit GSIT_HOOK = new HookGSit();
|
||||||
private static final HookCraftEngine CRAFT_ENGINE_HOOK = new HookCraftEngine();
|
private static final HookCraftEngine CRAFT_ENGINE_HOOK = new HookCraftEngine();
|
||||||
|
private static final HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
|
||||||
|
private static final HookSuperVanish SUPER_VANISH_HOOK = new HookSuperVanish();
|
||||||
|
|
||||||
private static boolean allHooksActive = false;
|
private static boolean allHooksActive = false;
|
||||||
|
|
||||||
@@ -53,11 +54,11 @@ public class Hooks {
|
|||||||
return HOOK_POOL.containsKey(id.toLowerCase());
|
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);
|
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) {
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
HookPlaceholderAPI hook = (HookPlaceholderAPI) getHook("PlaceholderAPI");
|
HookPlaceholderAPI hook = (HookPlaceholderAPI) getHook("PlaceholderAPI");
|
||||||
hook.registerPlaceholder(expansion);
|
hook.registerPlaceholder(expansion);
|
||||||
@@ -133,7 +134,7 @@ public class Hooks {
|
|||||||
return hook.getItem(split[1]);
|
return hook.getItem(split[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getStringItem(ItemStack itemStack) {
|
public static String getStringItem(@NotNull ItemStack itemStack) {
|
||||||
for (Hook hook : HOOK_POOL.values()) {
|
for (Hook hook : HOOK_POOL.values()) {
|
||||||
if (hook.isDetected() && hook.hasEnabledItemHook()) {
|
if (hook.isDetected() && hook.hasEnabledItemHook()) {
|
||||||
String stringyItem = hook.getItemString(itemStack);
|
String stringyItem = hook.getItemString(itemStack);
|
||||||
@@ -144,7 +145,7 @@ public class Hooks {
|
|||||||
return itemStack.getType().toString();
|
return itemStack.getType().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getStringEntity(Entity entity) {
|
public static String getStringEntity(@NotNull Entity entity) {
|
||||||
for (Hook hook : HOOK_POOL.values()) {
|
for (Hook hook : HOOK_POOL.values()) {
|
||||||
if (hook.isDetected() && hook.hasEnabledEntityHook()) {
|
if (hook.isDetected() && hook.hasEnabledEntityHook()) {
|
||||||
String stringyEntity = hook.getEntityString(entity);
|
String stringyEntity = hook.getEntityString(entity);
|
||||||
@@ -155,19 +156,22 @@ public class Hooks {
|
|||||||
return entity.getType().toString().toUpperCase();
|
return entity.getType().toString().toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isActiveHook(String id) {
|
public static boolean isActiveHook(@NotNull String id) {
|
||||||
Hook hook = getHook(id);
|
Hook hook = getHook(id);
|
||||||
if (hook == null) return false;
|
if (hook == null) return false;
|
||||||
if (!hook.isDetected()) return false;
|
if (!hook.isDetected()) return false;
|
||||||
return hook.isActive();
|
return hook.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInvisible(UUID uuid) {
|
public static boolean isInvisible(@NotNull UUID uuid) {
|
||||||
for (Hook hook : HOOK_POOL.values()) {
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
if (hook.isDetected()) {
|
if (player == null) return false;
|
||||||
if (hook.isInvisible(uuid)) return true;
|
return isInvisible(player);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
public static boolean isInvisible(@NotNull Player player) {
|
||||||
|
List<MetadataValue> metadataValues = player.getMetadata("vanished");
|
||||||
|
if (metadataValues.isEmpty()) return false;
|
||||||
|
return metadataValues.getFirst().asBoolean();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,11 +34,4 @@ public class HookCMI extends Hook {
|
|||||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
||||||
Bukkit.getPluginManager().callEvent(newEvent);
|
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);
|
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, player);
|
||||||
Bukkit.getPluginManager().callEvent(newEvent);
|
Bukkit.getPluginManager().callEvent(newEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInvisible(UUID uuid) {
|
|
||||||
Player onlinePlayer = Bukkit.getPlayer(uuid);
|
|
||||||
if (onlinePlayer == null) return false;
|
|
||||||
return DisguiseAPI.isDisguised(onlinePlayer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ package me.lojosho.hibiscuscommons.hooks.misc;
|
|||||||
|
|
||||||
import de.myzelyam.api.vanish.PlayerHideEvent;
|
import de.myzelyam.api.vanish.PlayerHideEvent;
|
||||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
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.HibiscusPlayerUnVanishEvent;
|
||||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
||||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -37,13 +34,4 @@ public class HookPremiumVanish extends Hook {
|
|||||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
||||||
Bukkit.getPluginManager().callEvent(newEvent);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,14 @@ package me.lojosho.hibiscuscommons.hooks.misc;
|
|||||||
|
|
||||||
import de.myzelyam.api.vanish.PlayerHideEvent;
|
import de.myzelyam.api.vanish.PlayerHideEvent;
|
||||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
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.HibiscusPlayerUnVanishEvent;
|
||||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
||||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||||
*
|
*
|
||||||
@@ -38,13 +32,4 @@ public class HookSuperVanish extends Hook {
|
|||||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(this, event.getPlayer());
|
||||||
Bukkit.getPluginManager().callEvent(newEvent);
|
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