mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-05 23:33:36 +00:00
Merge pull request #153 from FancyInnovations/fix/folia-visibility-issues
fancynpcs: Add enable-folia-visibility-fix feature flag
This commit is contained in:
@@ -10,6 +10,7 @@ dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:$minecraftVersion-R0.1-SNAPSHOT")
|
||||
|
||||
compileOnly(project(":libraries:common"))
|
||||
compileOnly(project(":libraries:config"))
|
||||
compileOnly("de.oliver.FancyAnalytics:logger:0.0.8")
|
||||
|
||||
implementation("org.lushplugins:ChatColorHandler:6.0.0")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.oliver.fancynpcs.api;
|
||||
|
||||
import com.fancyinnovations.config.featureflags.FeatureFlagConfig;
|
||||
import de.oliver.fancyanalytics.logger.ExtendedFancyLogger;
|
||||
import de.oliver.fancylib.serverSoftware.schedulers.FancyScheduler;
|
||||
import de.oliver.fancylib.translations.Translator;
|
||||
@@ -32,8 +33,8 @@ public interface FancyNpcsPlugin {
|
||||
ScheduledExecutorService getNpcThread();
|
||||
|
||||
/**
|
||||
* Creates a new thread with the given name and runnable.
|
||||
* Warning: Do not use this method, it is for internal use only.
|
||||
* Creates a new thread with the given name and runnable.
|
||||
* Warning: Do not use this method, it is for internal use only.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
Thread newThread(String name, Runnable runnable);
|
||||
@@ -44,6 +45,8 @@ public interface FancyNpcsPlugin {
|
||||
|
||||
FancyNpcsConfig getFancyNpcConfig();
|
||||
|
||||
FeatureFlagConfig getFeatureFlagConfig();
|
||||
|
||||
NpcManager getNpcManager();
|
||||
|
||||
AttributeManager getAttributeManager();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.oliver.fancynpcs.api;
|
||||
|
||||
import de.oliver.fancylib.RandomUtils;
|
||||
import de.oliver.fancylib.serverSoftware.ServerSoftware;
|
||||
import de.oliver.fancylib.translations.Translator;
|
||||
import de.oliver.fancynpcs.api.actions.ActionTrigger;
|
||||
import de.oliver.fancynpcs.api.actions.NpcAction;
|
||||
@@ -18,6 +19,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public abstract class Npc {
|
||||
|
||||
@@ -110,6 +112,15 @@ public abstract class Npc {
|
||||
|
||||
if (shouldBeVisible && !wasVisible) {
|
||||
spawn(player);
|
||||
|
||||
// Respawn the npc to fix visibility issues on Folia
|
||||
if (ServerSoftware.isFolia() && FancyNpcsPlugin.get().getFeatureFlagConfig().getFeatureFlag("enable-folia-visibility-fix").isEnabled()) {
|
||||
FancyNpcsPlugin.get().getNpcThread().schedule(() -> {
|
||||
remove(player);
|
||||
spawn(player);
|
||||
}, 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
} else if (!shouldBeVisible && wasVisible) {
|
||||
remove(player);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ public class FancyNpcs extends JavaPlugin implements FancyNpcsPlugin {
|
||||
public static final FeatureFlag PLAYER_NPCS_FEATURE_FLAG = new FeatureFlag("player-npcs", "Every player can only manage the npcs they have created", false);
|
||||
public static final FeatureFlag USE_NATIVE_THREADS_FEATURE_FLAG = new FeatureFlag("use-native-threads", "Use native threads instead of virtual threads.", false);
|
||||
public static final FeatureFlag ENABLE_DEBUG_MODE_FEATURE_FLAG = new FeatureFlag("enable-debug-mode", "Enable debug mode", false);
|
||||
public static final FeatureFlag ENABLE_FOLIA_VISIBILITY_FIX_FEATURE_FLAG = new FeatureFlag("enable-folia-visibility-fix", "When enabled, all npcs will respawn after 100ms when they should spawn", false);
|
||||
public static final FeatureFlag USE_MINECRAFT_USERCACHE_FEATURE_FLAG = new FeatureFlag("use-minecraft-usercache", "Include the content of usercache.json to the username->uuid cache", false);
|
||||
|
||||
private static FancyNpcs instance;
|
||||
@@ -154,6 +155,7 @@ public class FancyNpcs extends JavaPlugin implements FancyNpcsPlugin {
|
||||
featureFlagConfig.addFeatureFlag(PLAYER_NPCS_FEATURE_FLAG);
|
||||
featureFlagConfig.addFeatureFlag(USE_NATIVE_THREADS_FEATURE_FLAG);
|
||||
featureFlagConfig.addFeatureFlag(ENABLE_DEBUG_MODE_FEATURE_FLAG);
|
||||
featureFlagConfig.addFeatureFlag(ENABLE_FOLIA_VISIBILITY_FIX_FEATURE_FLAG);
|
||||
featureFlagConfig.load();
|
||||
|
||||
if (ENABLE_DEBUG_MODE_FEATURE_FLAG.isEnabled()) {
|
||||
@@ -598,6 +600,7 @@ public class FancyNpcs extends JavaPlugin implements FancyNpcsPlugin {
|
||||
return textConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureFlagConfig getFeatureFlagConfig() {
|
||||
return featureFlagConfig;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user