Skip to content

Commit

Permalink
fix: HealsFromEntityAbility会在最近的Folia版本上报 "Accessing LegacyRandomSour…
Browse files Browse the repository at this point in the history
…ce from multiple threads"

misc: 只在检测到热重载时尝试对生物AI进行恢复,我们不需要在服务器关闭的时候这么做
  • Loading branch information
MATRIX-feather committed Feb 11, 2025
1 parent 21a2e25 commit 17e7020
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class FeatherMorphBootstrap implements PluginBootstrap
public boolean bootstrapLoaded = false;

static final AtomicBoolean pluginDisabled = new AtomicBoolean(false);
static boolean muteHotReloadWarning = false;

@Override
public void bootstrap(@NotNull BootstrapContext context)
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/xyz/nifeather/morph/FeatherMorphMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import xiamomc.pluginbase.XiaMoJavaPlugin;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

public final class FeatherMorphMain extends XiaMoJavaPlugin
{
Expand Down Expand Up @@ -139,7 +140,6 @@ protected void enable()
"Please use %s instead!".formatted(primaryVersion)
);

FeatherMorphBootstrap.muteHotReloadWarning = true;
pluginManager.disablePlugin(this);
return;
}
Expand Down Expand Up @@ -263,16 +263,21 @@ protected void enable()
clientHandler.reAuthPlayers(Bukkit.getOnlinePlayers());
});

pluginEnableDone.set(true);

//Init GUI IconLookup
IconLookup.instance();
}

private final AtomicBoolean pluginEnableDone = new AtomicBoolean(false);

@Override
public void disable()
{
if (!getServer().isStopping())
var serverStopping = getServer().isStopping();
if (!serverStopping)
{
if (!FeatherMorphBootstrap.muteHotReloadWarning)
if (pluginEnableDone.get())
{
printImportantWarning(true,
"HEY, THERE!",
Expand All @@ -282,15 +287,22 @@ public void disable()
}
}

FeatherMorphBootstrap.muteHotReloadWarning = false;
FeatherMorphBootstrap.pluginDisabled.set(true);

//调用super.onDisable后依赖管理器会被清空
//需要在调用前先把一些东西处理好
try
{
if (entityProcessor != null)
if (!serverStopping
&& entityProcessor.currentlyDoModifyAI()
&& pluginEnableDone.get())
{
printImportantWarning(true,
"Are you disabling/reloading FeatherMorph while modifying AI is enabled?",
"While we try to recover the modifications, still, you are on your own risk.");

entityProcessor.recoverGoals();
}

if (morphManager != null)
morphManager.onPluginDisable();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/xyz/nifeather/morph/MorphManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ public static List<DisguiseProvider> getProviders()
@NotNull
public static DisguiseProvider getProvider(String id)
{
if (id == null) return null;
if (id == null)
return fallbackProvider;

id += ":";
var splitedId = id.split(":", 2);
Expand Down Expand Up @@ -1602,7 +1603,6 @@ public boolean grantMorphToPlayer(Player player, String disguiseIdentifier)
var locale = MessageUtils.getLocale(player);

var meta = data.getDisguiseMeta(disguiseIdentifier);
assert meta != null; // 这里不会出现meta是null的情况,除非抽了

var message = MessageUtils.prefixes(player, MorphStrings.morphUnlockedString()
.withLocale(locale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import xiamomc.pluginbase.Annotations.Resolved;

import java.util.Map;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class HealsFromEntityAbility extends MorphAbility<HealsFromEntityOption>
{
Expand All @@ -45,7 +47,7 @@ public class HealsFromEntityAbility extends MorphAbility<HealsFromEntityOption>
return new HealsFromEntityOption();
}

private final RandomSource random = RandomSource.create();
private final Random random = ThreadLocalRandom.current();

private static final String PROPERTY_ID = "morph:HFEA_BEAM_TARGET";

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/xyz/nifeather/morph/events/EntityProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class EntityProcessor extends MorphPluginObject implements Listener
private final boolean doModifyAI;
private final Bindable<Boolean> debugOutput = new Bindable<>(false);

public boolean currentlyDoModifyAI()
{
return doModifyAI;
}

public EntityProcessor()
{
doModifyAI = config.get(Boolean.class, ConfigOption.DO_MODIFY_AI);
Expand Down

0 comments on commit 17e7020

Please sign in to comment.