9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

也许修复了FAWE?

This commit is contained in:
XiaoMoMi
2025-07-20 21:23:32 +08:00
parent 1c59fb5ebf
commit bee6d258b4
10 changed files with 103 additions and 89 deletions

View File

@@ -10,8 +10,8 @@ import net.momirealms.craftengine.bukkit.compatibility.leveler.*;
import net.momirealms.craftengine.bukkit.compatibility.model.bettermodel.BetterModelModel;
import net.momirealms.craftengine.bukkit.compatibility.model.modelengine.ModelEngineModel;
import net.momirealms.craftengine.bukkit.compatibility.model.modelengine.ModelEngineUtils;
import net.momirealms.craftengine.bukkit.compatibility.mythicmobs.MythicMobsListener;
import net.momirealms.craftengine.bukkit.compatibility.mythicmobs.SkillHelper;
import net.momirealms.craftengine.bukkit.compatibility.mythicmobs.MythicItemDropListener;
import net.momirealms.craftengine.bukkit.compatibility.mythicmobs.MythicSkillHelper;
import net.momirealms.craftengine.bukkit.compatibility.papi.PlaceholderAPIUtils;
import net.momirealms.craftengine.bukkit.compatibility.permission.LuckPermsEventListeners;
import net.momirealms.craftengine.bukkit.compatibility.skript.SkriptHook;
@@ -40,7 +40,7 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
private final Map<String, LevelerProvider> levelerProviders;
private boolean hasPlaceholderAPI;
private boolean hasViaVersion;
private SkillHelper skillExecute;
private MythicSkillHelper skillExecute;
public BukkitCompatibilityManager(BukkitCraftEngine plugin) {
this.plugin = plugin;
@@ -133,14 +133,14 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
}
if (this.isPluginEnabled("MythicMobs")) {
BukkitItemManager.instance().registerExternalItemSource(new MythicMobsSource());
new MythicMobsListener(this.plugin);
new MythicItemDropListener(this.plugin);
logHook("MythicMobs");
}
}
@Override
public void skillExecute(String skill, float power, Player player) {
SkillHelper.execute(skill, power, player);
public void executeMMSkill(String skill, float power, Player player) {
MythicSkillHelper.execute(skill, power, player);
}
@Override

View File

@@ -21,12 +21,12 @@ import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Constructor;
public class CraftEngineItemDrop extends ItemDrop implements IItemDrop {
public class MythicItemDrop extends ItemDrop implements IItemDrop {
private final CustomItem<ItemStack> customItem;
private static final Constructor<?> constructor$BukkitItemStack = ReflectionUtils.getConstructor(BukkitItemStack.class, ItemStack.class);
private static final boolean useReflection = constructor$BukkitItemStack != null;
public CraftEngineItemDrop(String line, MythicLineConfig config, CustomItem<ItemStack> customItem) {
public MythicItemDrop(String line, MythicLineConfig config, CustomItem<ItemStack> customItem) {
super(line, config);
this.customItem = customItem;
}

View File

@@ -8,10 +8,10 @@ import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class MythicMobsListener implements Listener {
public class MythicItemDropListener implements Listener {
private final BukkitCraftEngine plugin;
public MythicMobsListener(BukkitCraftEngine plugin) {
public MythicItemDropListener(BukkitCraftEngine plugin) {
this.plugin = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin.javaPlugin());
}
@@ -24,7 +24,7 @@ public class MythicMobsListener implements Listener {
this.plugin.itemManager().getCustomItem(itemId).ifPresent(customItem -> {
String line = event.getContainer().getConfigLine();
MythicLineConfig config = event.getConfig();
event.register(new CraftEngineItemDrop(line, config, customItem));
event.register(new MythicItemDrop(line, config, customItem));
});
}
}

View File

@@ -10,7 +10,7 @@ import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SkillHelper {
public final class MythicSkillHelper {
public static void execute(String skill, float power, Player player) {
org.bukkit.entity.Player casterPlayer = (org.bukkit.entity.Player) player.platformPlayer();
@@ -22,8 +22,6 @@ public class SkillHelper {
targets.add(target);
locations = List.of(target.getLocation());
}
try (MythicBukkit mm = MythicBukkit.inst()) {
mm.getAPIHelper().castSkill(casterPlayer, skill, casterPlayer, location, targets, locations, power);
}
MythicBukkit.inst().getAPIHelper().castSkill(casterPlayer, skill, casterPlayer, location, targets, locations, power);
}
}

View File

@@ -1,9 +1,12 @@
package net.momirealms.craftengine.bukkit.compatibility.worldedit;
import com.fastasyncworldedit.bukkit.FaweBukkitWorld;
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
import com.fastasyncworldedit.bukkit.adapter.FaweAdapter;
import com.fastasyncworldedit.bukkit.adapter.NMSAdapter;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.processor.ExtentBatchProcessorHolder;
import com.fastasyncworldedit.core.math.IntPair;
import com.fastasyncworldedit.core.util.ExtentTraverser;
import com.fastasyncworldedit.core.util.ProcessorTraverser;
import com.sk89q.worldedit.EditSession;
@@ -24,6 +27,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.injector.WorldStorageInjector;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.core.block.EmptyBlock;
@@ -41,6 +45,8 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import static java.util.Objects.requireNonNull;
@@ -89,12 +95,14 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
if (levelChunk != null) {
Object[] sections = FastNMS.INSTANCE.method$ChunkAccess$getSections(levelChunk);
CESection[] ceSections = ceChunk.sections();
for (int i = 0; i < ceSections.length; i++) {
CESection ceSection = ceSections[i];
Object section = sections[i];
int finalI = i;
WorldStorageInjector.injectLevelChunkSection(section, ceSection, ceChunk, new SectionPos(pos.x, ceChunk.sectionY(i), pos.z),
(injected) -> sections[finalI] = injected);
synchronized (sections) {
for (int i = 0; i < ceSections.length; i++) {
CESection ceSection = ceSections[i];
Object section = sections[i];
int finalI = i;
WorldStorageInjector.injectLevelChunkSection(section, ceSection, ceChunk, new SectionPos(pos.x, ceChunk.sectionY(i), pos.z),
(injected) -> sections[finalI] = injected);
}
}
}
}
@@ -174,18 +182,18 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
@Override
public @Nullable Operation commit() {
Operation operation = super.commit();
saveAllChunks();
Operation operation = super.commit();
List<ChunkPos> chunks = new ArrayList<>(this.brokenChunks);
this.brokenChunks.clear();
Object worldServer = this.ceWorld.world().serverWorld();
Object chunkSource = FastNMS.INSTANCE.method$ServerLevel$getChunkSource(worldServer);
for (ChunkPos chunk : chunks) {
CEChunk loaded = this.ceWorld.getChunkAtIfLoaded(chunk.longKey());
// only inject loaded chunks
if (loaded == null) continue;
injectLevelChunk(chunkSource, loaded);
}
Object worldServer = this.ceWorld.world().serverWorld();
Object chunkSource = FastNMS.INSTANCE.method$ServerLevel$getChunkSource(worldServer);
for (ChunkPos chunk : chunks) {
CEChunk loaded = this.ceWorld.getChunkAtIfLoaded(chunk.longKey());
// only inject loaded chunks
if (loaded == null) continue;
injectLevelChunk(chunkSource, loaded);
}
return operation;
}

View File

@@ -88,6 +88,11 @@ public class BukkitWorldManager implements WorldManager, Listener {
}
}
@Override
public CEWorld[] getWorlds() {
return this.worldArray;
}
private void resetWorldArray() {
this.worldArray = this.worlds.values().toArray(new CEWorld[0]);
}
@@ -218,7 +223,6 @@ public class BukkitWorldManager implements WorldManager, Listener {
this.lastVisitedUUID = null;
}
this.resetWorldArray();
} finally {
this.worldMapLock.writeLock().unlock();
}
@@ -328,74 +332,76 @@ public class BukkitWorldManager implements WorldManager, Listener {
Object chunkSource = FastNMS.INSTANCE.method$ServerLevel$getChunkSource(worldServer);
Object levelChunk = FastNMS.INSTANCE.method$ServerChunkCache$getChunkAtIfLoadedMainThread(chunkSource, chunk.getX(), chunk.getZ());
Object[] sections = FastNMS.INSTANCE.method$ChunkAccess$getSections(levelChunk);
for (int i = 0; i < ceSections.length; i++) {
CESection ceSection = ceSections[i];
Object section = sections[i];
if (Config.syncCustomBlocks()) {
Object statesContainer = FastNMS.INSTANCE.field$LevelChunkSection$states(section);
Object data = CoreReflections.varHandle$PalettedContainer$data.get(statesContainer);
Object palette = CoreReflections.field$PalettedContainer$Data$palette.get(data);
boolean requiresSync = false;
if (CoreReflections.clazz$SingleValuePalette.isInstance(palette)) {
Object onlyBlockState = CoreReflections.field$SingleValuePalette$value.get(palette);
if (BlockStateUtils.isCustomBlock(onlyBlockState)) {
synchronized (sections) {
for (int i = 0; i < ceSections.length; i++) {
CESection ceSection = ceSections[i];
Object section = sections[i];
if (Config.syncCustomBlocks()) {
Object statesContainer = FastNMS.INSTANCE.field$LevelChunkSection$states(section);
Object data = CoreReflections.varHandle$PalettedContainer$data.get(statesContainer);
Object palette = CoreReflections.field$PalettedContainer$Data$palette.get(data);
boolean requiresSync = false;
if (CoreReflections.clazz$SingleValuePalette.isInstance(palette)) {
Object onlyBlockState = CoreReflections.field$SingleValuePalette$value.get(palette);
if (BlockStateUtils.isCustomBlock(onlyBlockState)) {
requiresSync = true;
}
} else if (CoreReflections.clazz$LinearPalette.isInstance(palette)) {
Object[] blockStates = (Object[]) CoreReflections.field$LinearPalette$values.get(palette);
for (Object blockState : blockStates) {
if (blockState != null) {
if (BlockStateUtils.isCustomBlock(blockState)) {
requiresSync = true;
break;
}
}
}
} else if (CoreReflections.clazz$HashMapPalette.isInstance(palette)) {
Object biMap = CoreReflections.field$HashMapPalette$values.get(palette);
Object[] blockStates = (Object[]) CoreReflections.field$CrudeIncrementalIntIdentityHashBiMap$keys.get(biMap);
for (Object blockState : blockStates) {
if (blockState != null) {
if (BlockStateUtils.isCustomBlock(blockState)) {
requiresSync = true;
break;
}
}
}
} else {
requiresSync = true;
}
} else if (CoreReflections.clazz$LinearPalette.isInstance(palette)) {
Object[] blockStates = (Object[]) CoreReflections.field$LinearPalette$values.get(palette);
for (Object blockState : blockStates) {
if (blockState != null) {
if (BlockStateUtils.isCustomBlock(blockState)) {
requiresSync = true;
break;
}
}
}
} else if (CoreReflections.clazz$HashMapPalette.isInstance(palette)) {
Object biMap = CoreReflections.field$HashMapPalette$values.get(palette);
Object[] blockStates = (Object[]) CoreReflections.field$CrudeIncrementalIntIdentityHashBiMap$keys.get(biMap);
for (Object blockState : blockStates) {
if (blockState != null) {
if (BlockStateUtils.isCustomBlock(blockState)) {
requiresSync = true;
break;
}
}
}
} else {
requiresSync = true;
}
if (requiresSync) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) {
Object mcState = FastNMS.INSTANCE.method$LevelChunkSection$getBlockState(section, x, y, z);
Optional<ImmutableBlockState> optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(mcState);
if (optionalCustomState.isPresent()) {
ceSection.setBlockState(x, y, z, optionalCustomState.get());
if (requiresSync) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) {
Object mcState = FastNMS.INSTANCE.method$LevelChunkSection$getBlockState(section, x, y, z);
Optional<ImmutableBlockState> optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(mcState);
if (optionalCustomState.isPresent()) {
ceSection.setBlockState(x, y, z, optionalCustomState.get());
}
}
}
}
}
}
}
if (Config.restoreCustomBlocks()) {
if (!ceSection.statesContainer().isEmpty()) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) {
ImmutableBlockState customState = ceSection.getBlockState(x, y, z);
if (!customState.isEmpty() && customState.customBlockState() != null) {
FastNMS.INSTANCE.method$LevelChunkSection$setBlockState(section, x, y, z, customState.customBlockState().handle(), false);
if (Config.restoreCustomBlocks()) {
if (!ceSection.statesContainer().isEmpty()) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) {
ImmutableBlockState customState = ceSection.getBlockState(x, y, z);
if (!customState.isEmpty() && customState.customBlockState() != null) {
FastNMS.INSTANCE.method$LevelChunkSection$setBlockState(section, x, y, z, customState.customBlockState().handle(), false);
}
}
}
}
}
}
int finalI = i;
WorldStorageInjector.injectLevelChunkSection(section, ceSection, ceChunk, new SectionPos(pos.x, ceChunk.sectionY(i), pos.z),
(injected) -> sections[finalI] = injected);
}
int finalI = i;
WorldStorageInjector.injectLevelChunkSection(section, ceSection, ceChunk, new SectionPos(pos.x, ceChunk.sectionY(i), pos.z),
(injected) -> sections[finalI] = injected);
}
if (Config.enableRecipeSystem()) {
@SuppressWarnings("unchecked")

View File

@@ -35,5 +35,5 @@ public interface CompatibilityManager {
int getPlayerProtocolVersion(UUID uuid);
void skillExecute(String skill, float power, Player player);
void executeMMSkill(String skill, float power, Player player);
}

View File

@@ -23,7 +23,7 @@ public class MythicMobsSkillFunction<CTX extends Context> extends AbstractCondit
@Override
protected void runInternal(CTX ctx) {
ctx.getOptionalParameter(DirectContextParameters.PLAYER).ifPresent(it -> {
CraftEngine.instance().compatibilityManager().skillExecute(this.skill, this.power, it);
CraftEngine.instance().compatibilityManager().executeMMSkill(this.skill, this.power, it);
});
}

View File

@@ -13,6 +13,8 @@ public interface WorldManager extends Manageable {
CEWorld getWorld(UUID uuid);
CEWorld[] getWorlds();
void loadWorld(World world);
void loadWorld(CEWorld world);

View File

@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.60.4
project_version=0.0.60.5
config_version=43
lang_version=22
project_group=net.momirealms