mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-26 02:19:28 +00:00
disguise support
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.bubble;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.data.OnlineUser;
|
||||
@@ -45,11 +44,9 @@ import net.momirealms.customnameplates.paper.mechanic.bubble.image.ItemsAdderIma
|
||||
import net.momirealms.customnameplates.paper.mechanic.bubble.image.OraxenImageImpl;
|
||||
import net.momirealms.customnameplates.paper.mechanic.bubble.provider.*;
|
||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
import net.momirealms.customnameplates.paper.util.DisguiseUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.paper.mechanic.nameplate.tag.listener;
|
||||
|
||||
import me.libraryaddict.disguise.events.DisguiseEvent;
|
||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.unlimited.UnlimitedPlayer;
|
||||
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.unlimited.UnlimitedTagManagerImpl;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DisguiseListener implements Listener {
|
||||
|
||||
private final UnlimitedTagManagerImpl unlimitedTagManager;
|
||||
|
||||
public DisguiseListener(UnlimitedTagManagerImpl unlimitedTagManager) {
|
||||
this.unlimitedTagManager = unlimitedTagManager;
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
public void onDisguise(DisguiseEvent event) {
|
||||
if (this.unlimitedTagManager.getUnlimitedObject(event.getEntity().getUniqueId()) instanceof UnlimitedPlayer player) {
|
||||
CustomNameplatesPlugin.get().getScheduler().runTaskAsyncLater(player::updateVisibility, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
public void onUnDisguise(UndisguiseEvent event) {
|
||||
if (this.unlimitedTagManager.getUnlimitedObject(event.getEntity().getUniqueId()) instanceof UnlimitedPlayer player) {
|
||||
CustomNameplatesPlugin.get().getScheduler().runTaskAsyncLater(player::updateVisibility, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ import net.momirealms.customnameplates.api.mechanic.tag.unlimited.DynamicTextEnt
|
||||
import net.momirealms.customnameplates.api.requirement.Condition;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.PacketManager;
|
||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
import net.momirealms.customnameplates.paper.util.DisguiseUtils;
|
||||
import net.momirealms.customnameplates.paper.util.FakeEntityUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -367,6 +369,9 @@ public class DynamicTextEntityImpl implements DynamicTextEntity {
|
||||
}
|
||||
|
||||
private double getPlayerHeight() {
|
||||
if (CNConfig.hasLibsDisguise && DisguiseUtils.isDisguised(owner.getPlayer()) && DisguiseUtils.getDisguisedType(owner.getPlayer()) != EntityType.PLAYER) {
|
||||
return DisguiseUtils.getDisguisedHeight(owner.getPlayer());
|
||||
}
|
||||
return owner.getPlayer().getHeight();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.NearbyRule;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.StaticTextEntity;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.PacketManager;
|
||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
import net.momirealms.customnameplates.paper.util.DisguiseUtils;
|
||||
import net.momirealms.customnameplates.paper.util.FakeEntityUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -328,7 +330,11 @@ public class StaticTextEntityImpl implements StaticTextEntity {
|
||||
}
|
||||
|
||||
private double getCorrection() {
|
||||
return owner.getEntity().getHeight() - 1.8;
|
||||
double height = owner.getEntity().getHeight();
|
||||
if (CNConfig.hasLibsDisguise && DisguiseUtils.isDisguised(owner.getEntity()) && DisguiseUtils.getDisguisedType(owner.getEntity()) != EntityType.PLAYER) {
|
||||
height = DisguiseUtils.getDisguisedHeight(owner.getEntity());
|
||||
}
|
||||
return height - 1.8;
|
||||
}
|
||||
|
||||
private void viewersToArray() {
|
||||
|
||||
@@ -24,12 +24,11 @@ import net.momirealms.customnameplates.api.mechanic.misc.ViewerText;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.*;
|
||||
import net.momirealms.customnameplates.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.listener.DisguiseListener;
|
||||
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.listener.MagicCosmeticsListener;
|
||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
import net.momirealms.customnameplates.paper.util.DisguiseUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Pose;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@@ -47,6 +46,7 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager {
|
||||
private final ConcurrentHashMap<UUID, UnlimitedEntity> unlimitedEntityMap;
|
||||
private CancellableTask refreshTask;
|
||||
private MagicCosmeticsListener magicCosmeticsListener;
|
||||
private DisguiseListener disguiseListener;
|
||||
private final VehicleChecker vehicleChecker;
|
||||
|
||||
public UnlimitedTagManagerImpl(NameplateManager nameplateManager) {
|
||||
@@ -56,6 +56,9 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager {
|
||||
if (Bukkit.getPluginManager().getPlugin("MagicCosmetics") != null) {
|
||||
this.magicCosmeticsListener = new MagicCosmeticsListener(this);
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("LibsDisguises") != null) {
|
||||
this.disguiseListener = new DisguiseListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
@@ -85,6 +88,9 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager {
|
||||
if (this.magicCosmeticsListener != null) {
|
||||
Bukkit.getPluginManager().registerEvents(magicCosmeticsListener, CustomNameplatesPlugin.get());
|
||||
}
|
||||
if (this.disguiseListener != null) {
|
||||
Bukkit.getPluginManager().registerEvents(disguiseListener, CustomNameplatesPlugin.get());
|
||||
}
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
@@ -98,6 +104,9 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager {
|
||||
if (this.magicCosmeticsListener != null) {
|
||||
HandlerList.unregisterAll(magicCosmeticsListener);
|
||||
}
|
||||
if (this.disguiseListener != null) {
|
||||
HandlerList.unregisterAll(disguiseListener);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -163,7 +172,9 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager {
|
||||
unlimitedPlayer
|
||||
);
|
||||
|
||||
unlimitedPlayer.addNearByPlayerToMap(48);
|
||||
if (player.getGameMode() != GameMode.SPECTATOR) {
|
||||
unlimitedPlayer.addNearByPlayerToMap(48);
|
||||
}
|
||||
return unlimitedPlayer;
|
||||
}
|
||||
|
||||
@@ -244,14 +255,6 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager {
|
||||
public void handlePlayerSneak(Player sneaker, boolean sneaking, boolean flying) {
|
||||
UnlimitedEntity unlimitedEntity = getUnlimitedObject(sneaker.getUniqueId());
|
||||
if (!(unlimitedEntity instanceof UnlimitedPlayer unlimitedPlayer)) return;
|
||||
if ( sneaking
|
||||
&& CNConfig.hasLibsDisguise
|
||||
&& DisguiseUtils.isDisguised(sneaker)
|
||||
&& DisguiseUtils.getDisguisedType(sneaker) != EntityType.PLAYER
|
||||
) {
|
||||
// disguised entities would not sneak
|
||||
return;
|
||||
}
|
||||
unlimitedPlayer.sneak(sneaking, flying);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package net.momirealms.customnameplates.paper.util;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
@@ -27,6 +28,11 @@ public class DisguiseUtils {
|
||||
return DisguiseAPI.isDisguised(entity);
|
||||
}
|
||||
|
||||
public static double getDisguisedHeight(Entity entity) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||
return disguise.getHeight() + disguise.getWatcher().getYModifier() + disguise.getWatcher().getNameYModifier();
|
||||
}
|
||||
|
||||
public static EntityType getDisguisedType(Entity entity) {
|
||||
return DisguiseAPI.getDisguise(entity).getType().getEntityType();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user