diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/BukkitCompatibilityManager.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/BukkitCompatibilityManager.java index 56248a777..a341e41fe 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/BukkitCompatibilityManager.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/BukkitCompatibilityManager.java @@ -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 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 diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/CraftEngineItemDrop.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDrop.java similarity index 93% rename from bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/CraftEngineItemDrop.java rename to bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDrop.java index 9c582cf1d..8b151df79 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/CraftEngineItemDrop.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDrop.java @@ -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 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 customItem) { + public MythicItemDrop(String line, MythicLineConfig config, CustomItem customItem) { super(line, config); this.customItem = customItem; } diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicMobsListener.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDropListener.java similarity index 83% rename from bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicMobsListener.java rename to bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDropListener.java index 22101993b..96cacc0b7 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicMobsListener.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDropListener.java @@ -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)); }); } } diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/SkillHelper.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicSkillHelper.java similarity index 81% rename from bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/SkillHelper.java rename to bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicSkillHelper.java index 32162b6d2..8ac5a7356 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/SkillHelper.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicSkillHelper.java @@ -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); } } diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java index b03240f25..476e6370c 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java @@ -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 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; } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorldManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorldManager.java index 61aa6dabb..bd04de0e4 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorldManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorldManager.java @@ -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 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 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") diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/compatibility/CompatibilityManager.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/compatibility/CompatibilityManager.java index 9459acdfc..f38d30c1f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/compatibility/CompatibilityManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/compatibility/CompatibilityManager.java @@ -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); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/MythicMobsSkillFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/MythicMobsSkillFunction.java index bb4a61c85..031ed08da 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/MythicMobsSkillFunction.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/MythicMobsSkillFunction.java @@ -23,7 +23,7 @@ public class MythicMobsSkillFunction 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); }); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/world/WorldManager.java b/core/src/main/java/net/momirealms/craftengine/core/world/WorldManager.java index 5c83b592b..d6a746cbd 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/world/WorldManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/world/WorldManager.java @@ -13,6 +13,8 @@ public interface WorldManager extends Manageable { CEWorld getWorld(UUID uuid); + CEWorld[] getWorlds(); + void loadWorld(World world); void loadWorld(CEWorld world); diff --git a/gradle.properties b/gradle.properties index 1e4e87a6e..2c126627e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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