Skip to content

Commit

Permalink
fix: 无法在其他世界进行伪装
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Nov 1, 2023
1 parent 0d94bdc commit b12da22
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/main/java/xiamomc/morph/utilities/EntityTypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xiamomc.morph.MorphPlugin;
import xiamomc.morph.misc.DisguiseTypes;
import xiamomc.pluginbase.Exceptions.NullDependencyException;

import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;

public class EntityTypeUtils
{
Expand Down Expand Up @@ -64,21 +67,34 @@ public static SoundInfo getSoundEvent(EntityType bukkitType)
var cache = typeSoundMap.getOrDefault(bukkitType, null);
if (cache != null) return cache;

var nmsType = getNmsType(bukkitType);
try
{
var nmsType = getNmsType(bukkitType);
if (nmsType == null)
throw new NullPointerException("Null NMSType for BukkitType " + bukkitType);

var serverWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
var entity = nmsType.create(serverWorld, null, e -> e.remove(Entity.RemovalReason.DISCARDED), BlockPos.ZERO, MobSpawnType.COMMAND, false, false);
var serverWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();

if (entity instanceof Mob mob)
{
var source = mob.getSoundSource();
var sound = mob.getAmbientSound0();
var interval = mob.getAmbientSoundInterval();
AtomicReference<Entity> entity = new AtomicReference<>();
Bukkit.getRegionScheduler().execute(MorphPlugin.getInstance(), Bukkit.getWorlds().get(0), 0, 0, () ->
entity.set(nmsType.create(serverWorld, null, e -> e.remove(Entity.RemovalReason.DISCARDED), BlockPos.ZERO, MobSpawnType.COMMAND, false, false)));

var rec = new SoundInfo(sound, source, interval, mob.getSoundVolume());
typeSoundMap.put(bukkitType, rec);
if (entity.get() instanceof Mob mob)
{
var source = mob.getSoundSource();
var sound = mob.getAmbientSound0();
var interval = mob.getAmbientSoundInterval();

return rec;
var rec = new SoundInfo(sound, source, interval, mob.getSoundVolume());
typeSoundMap.put(bukkitType, rec);

return rec;
}
}
catch (Throwable t)
{
MorphPlugin.getInstance().getSLF4JLogger().error("Unable to get SoundInfo for " + bukkitType);
t.printStackTrace();
}

return new SoundInfo(null, SoundSource.PLAYERS, Integer.MAX_VALUE, 1);
Expand Down

0 comments on commit b12da22

Please sign in to comment.