mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 12:29:15 +00:00
refactor structure
This commit is contained in:
@@ -10,7 +10,6 @@ public class CraftEngineReloadEvent extends Event {
|
||||
private final BukkitCraftEngine plugin;
|
||||
|
||||
public CraftEngineReloadEvent(BukkitCraftEngine plugin) {
|
||||
super(true);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemKeys;
|
||||
import net.momirealms.craftengine.core.loot.LootTable;
|
||||
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
@@ -60,7 +60,7 @@ public class BlockEventListener implements Listener {
|
||||
player.swingHand(event.getHand());
|
||||
}
|
||||
// send sound if the placed block's sounds are removed
|
||||
if (ConfigManager.enableSoundSystem()) {
|
||||
if (Config.enableSoundSystem()) {
|
||||
Block block = event.getBlock();
|
||||
Object blockState = BlockStateUtils.blockDataToBlockState(block.getBlockData());
|
||||
Object ownerBlock = BlockStateUtils.getBlockOwner(blockState);
|
||||
@@ -171,7 +171,7 @@ public class BlockEventListener implements Listener {
|
||||
});
|
||||
}
|
||||
// sound system
|
||||
if (ConfigManager.enableSoundSystem()) {
|
||||
if (Config.enableSoundSystem()) {
|
||||
Object ownerBlock = BlockStateUtils.getBlockOwner(blockState);
|
||||
if (this.manager.isBlockSoundRemoved(ownerBlock)) {
|
||||
try {
|
||||
@@ -243,7 +243,7 @@ public class BlockEventListener implements Listener {
|
||||
if (!BlockStateUtils.isVanillaBlock(stateId)) {
|
||||
ImmutableBlockState state = manager.getImmutableBlockStateUnsafe(stateId);
|
||||
player.playSound(playerLocation, state.sounds().stepSound().id().toString(), SoundCategory.BLOCKS, state.sounds().stepSound().volume(), state.sounds().stepSound().pitch());
|
||||
} else if (ConfigManager.enableSoundSystem()) {
|
||||
} else if (Config.enableSoundSystem()) {
|
||||
Object ownerBlock = BlockStateUtils.getBlockOwner(blockState);
|
||||
if (manager.isBlockSoundRemoved(ownerBlock)) {
|
||||
try {
|
||||
|
||||
@@ -23,7 +23,7 @@ import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
@@ -251,8 +251,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
return Collections.unmodifiableCollection(this.cachedSuggestions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSuggestions() {
|
||||
private void initSuggestions() {
|
||||
this.cachedSuggestions.clear();
|
||||
this.namespacesInUse.clear();
|
||||
Set<String> states = new HashSet<>();
|
||||
@@ -269,7 +268,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
}
|
||||
|
||||
public Set<String> namespacesInUse() {
|
||||
return Collections.unmodifiableSet(namespacesInUse);
|
||||
return Collections.unmodifiableSet(this.namespacesInUse);
|
||||
}
|
||||
|
||||
public ImmutableMap<Key, List<Integer>> blockAppearanceArranger() {
|
||||
@@ -501,7 +500,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
byId.put(id, block);
|
||||
|
||||
// generate mod assets
|
||||
if (ConfigManager.generateModAssets()) {
|
||||
if (Config.generateModAssets()) {
|
||||
for (ImmutableBlockState state : block.variantProvider().states()) {
|
||||
Key realBlockId = BlockStateUtils.getBlockOwnerIdFromState(state.customBlockState());
|
||||
modBlockStates.put(realBlockId, tempVanillaBlockStateModels.get(state.vanillaBlockState().registryId()));
|
||||
@@ -650,7 +649,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
private void loadMappingsAndAdditionalBlocks() {
|
||||
this.plugin.logger().info("Loading mappings.yml.");
|
||||
File mappingFile = new File(plugin.dataFolderFile(), "mappings.yml");
|
||||
YamlDocument mappings = ConfigManager.instance().loadOrCreateYamlData("mappings.yml");
|
||||
YamlDocument mappings = Config.instance().loadOrCreateYamlData("mappings.yml");
|
||||
Map<String, String> blockStateMappings = loadBlockStateMappings(mappings);
|
||||
this.validateBlockStateMappings(mappingFile, blockStateMappings);
|
||||
Map<Integer, String> stateMap = new HashMap<>();
|
||||
@@ -663,7 +662,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
this.blockAppearanceMapper = ImmutableMap.copyOf(appearanceMapper);
|
||||
this.blockAppearanceArranger = ImmutableMap.copyOf(appearanceArranger);
|
||||
this.plugin.logger().info("Freed " + this.blockAppearanceMapper.size() + " block state appearances.");
|
||||
YamlDocument additionalYaml = ConfigManager.instance().loadOrCreateYamlData("additional-real-blocks.yml");
|
||||
YamlDocument additionalYaml = Config.instance().loadOrCreateYamlData("additional-real-blocks.yml");
|
||||
this.registeredRealBlockSlots = this.buildRegisteredRealBlockSlots(blockTypeCounter, additionalYaml);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
import net.momirealms.craftengine.core.loot.LootTable;
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.sound.SoundData;
|
||||
@@ -305,8 +305,8 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
return;
|
||||
}
|
||||
// Remove the entity if it's not a valid furniture
|
||||
if (ConfigManager.removeInvalidFurniture()) {
|
||||
if (ConfigManager.furnitureToRemove().isEmpty() || ConfigManager.furnitureToRemove().contains(id)) {
|
||||
if (Config.removeInvalidFurniture()) {
|
||||
if (Config.furnitureToRemove().isEmpty() || Config.furnitureToRemove().contains(id)) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.font.AbstractFontManager;
|
||||
import net.momirealms.craftengine.core.font.FontManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.util.CharacterUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -48,20 +48,20 @@ public class BukkitFontManager extends AbstractFontManager implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onChat(AsyncChatDecorateEvent event) {
|
||||
if (!ConfigManager.filterChat()) return;
|
||||
if (!Config.filterChat()) return;
|
||||
this.processChatEvent(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onChatCommand(AsyncChatCommandDecorateEvent event) {
|
||||
if (!ConfigManager.filterChat()) return;
|
||||
if (!Config.filterChat()) return;
|
||||
this.processChatEvent(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onCommand(PlayerCommandPreprocessEvent event) {
|
||||
if (!ConfigManager.filterCommand()) return;
|
||||
if (!Config.filterCommand()) return;
|
||||
if (!this.isDefaultFontInUse()) return;
|
||||
if (event.getPlayer().hasPermission(FontManager.BYPASS_COMMAND)) {
|
||||
return;
|
||||
|
||||
@@ -26,7 +26,7 @@ import net.momirealms.craftengine.core.pack.model.*;
|
||||
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
|
||||
import net.momirealms.craftengine.core.pack.model.select.ChargeTypeSelectProperty;
|
||||
import net.momirealms.craftengine.core.pack.model.select.TrimMaterialSelectProperty;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
@@ -352,12 +352,12 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
|
||||
if (ConfigManager.packMaxVersion() > 21.39f) {
|
||||
if (Config.packMaxVersion() > 21.39f) {
|
||||
TreeMap<Integer, ItemModel> map = modernOverrides.computeIfAbsent(materialId, k -> new TreeMap<>());
|
||||
map.put(customModelData, model);
|
||||
}
|
||||
|
||||
if (ConfigManager.packMinVersion() < 21.39f) {
|
||||
if (Config.packMinVersion() < 21.39f) {
|
||||
List<LegacyOverridesModel> legacyOverridesModels = new ArrayList<>();
|
||||
processModelRecursively(model, new LinkedHashMap<>(), legacyOverridesModels, materialId, customModelData);
|
||||
TreeSet<LegacyOverridesModel> lom = legacyOverrides.computeIfAbsent(materialId, k -> new TreeSet<>());
|
||||
@@ -372,11 +372,11 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
|
||||
if (ConfigManager.packMaxVersion() > 21.39f) {
|
||||
if (Config.packMaxVersion() > 21.39f) {
|
||||
modernItemModels1_21_4.put(itemModelKey, model);
|
||||
}
|
||||
|
||||
if (ConfigManager.packMaxVersion() > 21.19f && ConfigManager.packMinVersion() < 21.39f) {
|
||||
if (Config.packMaxVersion() > 21.19f && Config.packMinVersion() < 21.39f) {
|
||||
List<LegacyOverridesModel> legacyOverridesModels = new ArrayList<>();
|
||||
processModelRecursively(model, new LinkedHashMap<>(), legacyOverridesModels, materialId, 0);
|
||||
if (!legacyOverridesModels.isEmpty()) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import net.momirealms.craftengine.core.item.recipe.Recipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.*;
|
||||
import net.momirealms.craftengine.core.item.recipe.vanilla.*;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.HeptaFunction;
|
||||
@@ -284,7 +284,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
if (VersionHelper.isVersionNewerThan1_21_2()) {
|
||||
try {
|
||||
this.stolenFeatureFlagSet = Reflections.field$RecipeManager$featureflagset.get(nmsRecipeManager);
|
||||
@@ -422,7 +422,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSyncTasks() {
|
||||
public void runDelayedSyncTasks() {
|
||||
try {
|
||||
// run delayed tasks
|
||||
for (Runnable r : this.delayedTasksOnMainThread) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.momirealms.craftengine.core.item.recipe.OptimizedIDItem;
|
||||
import net.momirealms.craftengine.core.item.recipe.Recipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.CraftingInput;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -39,7 +39,7 @@ public class CrafterEventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onCrafting(CrafterCraftEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
CraftingRecipe recipe = event.getRecipe();
|
||||
if (!(event.getBlock().getState() instanceof Crafter crafter)) {
|
||||
return;
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.momirealms.craftengine.core.item.recipe.*;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.CraftingInput;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.SingleItemInput;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.SmithingInput;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
@@ -261,7 +261,7 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onFurnaceInventoryOpen(InventoryOpenEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
if (!(event.getInventory() instanceof FurnaceInventory furnaceInventory)) {
|
||||
return;
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public class RecipeEventListener implements Listener {
|
||||
// for 1.20.1-1.21.1
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
if (VersionHelper.isVersionNewerThan1_21_2()) return;
|
||||
Block block = event.getBlock();
|
||||
Material material = block.getType();
|
||||
@@ -295,7 +295,7 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlaceBlock(BlockPlaceEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
Block block = event.getBlock();
|
||||
Material material = block.getType();
|
||||
if (material == Material.FURNACE || material == Material.BLAST_FURNACE || material == Material.SMOKER) {
|
||||
@@ -322,7 +322,7 @@ public class RecipeEventListener implements Listener {
|
||||
// for 1.21.2+
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPutItemOnCampfire(PlayerInteractEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
if (!VersionHelper.isVersionNewerThan1_21_2()) return;
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Block clicked = event.getClickedBlock();
|
||||
@@ -373,7 +373,7 @@ public class RecipeEventListener implements Listener {
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onCampfireCook(CampfireStartEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
if (!VersionHelper.isVersionNewerThan1_21_2()) return;
|
||||
CampfireRecipe recipe = event.getRecipe();
|
||||
Key recipeId = new Key(recipe.getKey().namespace(), recipe.getKey().value());
|
||||
@@ -404,7 +404,7 @@ public class RecipeEventListener implements Listener {
|
||||
// for 1.21.2+
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onCampfireCook(BlockCookEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
if (!VersionHelper.isVersionNewerThan1_21_2()) return;
|
||||
Material type = event.getBlock().getType();
|
||||
if (type != Material.CAMPFIRE && type != Material.SOUL_CAMPFIRE) return;
|
||||
@@ -743,7 +743,7 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onCraftingRecipe(PrepareItemCraftEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
org.bukkit.inventory.Recipe recipe = event.getRecipe();
|
||||
if (recipe == null)
|
||||
return;
|
||||
@@ -836,7 +836,7 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onSmithingTransform(PrepareSmithingEvent event) {
|
||||
if (!ConfigManager.enableRecipeSystem()) return;
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
SmithingInventory inventory = event.getInventory();
|
||||
if (!(inventory.getRecipe() instanceof SmithingTransformRecipe recipe)) return;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.pack.AbstractPackManager;
|
||||
import net.momirealms.craftengine.core.pack.host.HostMode;
|
||||
import net.momirealms.craftengine.core.pack.host.ResourcePackHost;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.network.ConnectionState;
|
||||
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
@@ -52,7 +52,7 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
// for 1.20.1 servers, not recommended to use
|
||||
if (ConfigManager.sendPackOnJoin() && !VersionHelper.isVersionNewerThan1_20_2()) {
|
||||
if (Config.sendPackOnJoin() && !VersionHelper.isVersionNewerThan1_20_2()) {
|
||||
this.sendResourcePack(plugin.networkManager().getUser(event.getPlayer()), null);
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onResourcePackStatus(PlayerResourcePackStatusEvent event) {
|
||||
// for 1.20.1 servers, not recommended to use
|
||||
if (ConfigManager.sendPackOnJoin() && ConfigManager.kickOnDeclined() && !VersionHelper.isVersionNewerThan1_20_2()) {
|
||||
if (Config.sendPackOnJoin() && Config.kickOnDeclined() && !VersionHelper.isVersionNewerThan1_20_2()) {
|
||||
if (event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED || event.getStatus() == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD) {
|
||||
event.getPlayer().kick();
|
||||
}
|
||||
@@ -73,34 +73,34 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
|
||||
// update server properties
|
||||
if (VersionHelper.isVersionNewerThan1_20_2()) {
|
||||
if (ConfigManager.hostMode() == HostMode.SELF_HOST) {
|
||||
if (Config.hostMode() == HostMode.SELF_HOST) {
|
||||
if (Files.exists(resourcePackPath())) {
|
||||
updateResourcePackSettings(super.packUUID, ResourcePackHost.instance().url(), super.packHash, ConfigManager.kickOnDeclined(), ConfigManager.resourcePackPrompt());
|
||||
updateResourcePackSettings(super.packUUID, ResourcePackHost.instance().url(), super.packHash, Config.kickOnDeclined(), Config.resourcePackPrompt());
|
||||
}
|
||||
} else if (ConfigManager.hostMode() == HostMode.EXTERNAL_HOST) {
|
||||
updateResourcePackSettings(ConfigManager.externalPackUUID(), ConfigManager.externalPackUrl(), ConfigManager.externalPackSha1(), ConfigManager.kickOnDeclined(), ConfigManager.resourcePackPrompt());
|
||||
} else if (Config.hostMode() == HostMode.EXTERNAL_HOST) {
|
||||
updateResourcePackSettings(Config.externalPackUUID(), Config.externalPackUrl(), Config.externalPackSha1(), Config.kickOnDeclined(), Config.resourcePackPrompt());
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigManager.sendPackOnReload()) {
|
||||
if (Config.sendPackOnReload()) {
|
||||
if (this.previousHostMode == HostMode.SELF_HOST) {
|
||||
this.previousHostUUID = super.packUUID;
|
||||
}
|
||||
// unload packs if user changed to none host
|
||||
if (ConfigManager.hostMode() == HostMode.NONE && this.previousHostMode != HostMode.NONE) {
|
||||
if (Config.hostMode() == HostMode.NONE && this.previousHostMode != HostMode.NONE) {
|
||||
unloadResourcePackForOnlinePlayers(this.previousHostUUID);
|
||||
}
|
||||
// load new external resource pack on reload
|
||||
if (ConfigManager.hostMode() == HostMode.EXTERNAL_HOST) {
|
||||
if (Config.hostMode() == HostMode.EXTERNAL_HOST) {
|
||||
if (this.previousHostMode == HostMode.NONE) {
|
||||
updateResourcePackForOnlinePlayers(null);
|
||||
} else {
|
||||
updateResourcePackForOnlinePlayers(this.previousHostUUID);
|
||||
}
|
||||
// record previous host uuid here
|
||||
this.previousHostUUID = ConfigManager.externalPackUUID();
|
||||
this.previousHostUUID = Config.externalPackUUID();
|
||||
}
|
||||
if (ConfigManager.hostMode() == HostMode.SELF_HOST && this.previousHostMode != HostMode.SELF_HOST) {
|
||||
if (Config.hostMode() == HostMode.SELF_HOST && this.previousHostMode != HostMode.SELF_HOST) {
|
||||
if (ReloadCommand.RELOAD_PACK_FLAG) {
|
||||
ReloadCommand.RELOAD_PACK_FLAG = false;
|
||||
if (this.previousHostMode == HostMode.NONE) {
|
||||
@@ -111,7 +111,7 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.previousHostMode = ConfigManager.hostMode();
|
||||
this.previousHostMode = Config.hostMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,12 +134,12 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
super.generateResourcePack();
|
||||
// update server properties
|
||||
if (VersionHelper.isVersionNewerThan1_20_2()) {
|
||||
if (ConfigManager.hostMode() == HostMode.SELF_HOST) {
|
||||
updateResourcePackSettings(super.packUUID, ResourcePackHost.instance().url(), super.packHash, ConfigManager.kickOnDeclined(), ConfigManager.resourcePackPrompt());
|
||||
if (Config.hostMode() == HostMode.SELF_HOST) {
|
||||
updateResourcePackSettings(super.packUUID, ResourcePackHost.instance().url(), super.packHash, Config.kickOnDeclined(), Config.resourcePackPrompt());
|
||||
}
|
||||
}
|
||||
// resend packs
|
||||
if (ConfigManager.hostMode() == HostMode.SELF_HOST && ConfigManager.sendPackOnReload()) {
|
||||
if (Config.hostMode() == HostMode.SELF_HOST && Config.sendPackOnReload()) {
|
||||
updateResourcePackForOnlinePlayers(this.previousHostUUID);
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
}
|
||||
|
||||
private void updateResourcePackSettings(UUID uuid, String url, String sha1, boolean required, Component prompt) {
|
||||
if (!ConfigManager.sendPackOnJoin()) {
|
||||
if (!Config.sendPackOnJoin()) {
|
||||
resetResourcePackSettings();
|
||||
return;
|
||||
}
|
||||
@@ -182,36 +182,36 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
}
|
||||
|
||||
public void sendResourcePack(NetWorkUser user, @Nullable UUID previousPack) {
|
||||
if (ConfigManager.hostMode() == HostMode.NONE) return;
|
||||
if (Config.hostMode() == HostMode.NONE) return;
|
||||
String url;
|
||||
String sha1;
|
||||
UUID uuid;
|
||||
if (ConfigManager.hostMode() == HostMode.SELF_HOST) {
|
||||
if (Config.hostMode() == HostMode.SELF_HOST) {
|
||||
url = ResourcePackHost.instance().url();
|
||||
sha1 = super.packHash;
|
||||
uuid = super.packUUID;
|
||||
if (!Files.exists(resourcePackPath())) return;
|
||||
} else {
|
||||
url = ConfigManager.externalPackUrl();
|
||||
sha1 = ConfigManager.externalPackSha1();
|
||||
uuid = ConfigManager.externalPackUUID();
|
||||
url = Config.externalPackUrl();
|
||||
sha1 = Config.externalPackSha1();
|
||||
uuid = Config.externalPackUUID();
|
||||
if (uuid.equals(previousPack)) return;
|
||||
}
|
||||
|
||||
Object packPrompt = ComponentUtils.adventureToMinecraft(ConfigManager.resourcePackPrompt());
|
||||
Object packPrompt = ComponentUtils.adventureToMinecraft(Config.resourcePackPrompt());
|
||||
try {
|
||||
Object packPacket;
|
||||
if (VersionHelper.isVersionNewerThan1_20_5()) {
|
||||
packPacket = Reflections.constructor$ClientboundResourcePackPushPacket.newInstance(
|
||||
uuid, url, sha1, ConfigManager.kickOnDeclined(), Optional.of(packPrompt)
|
||||
uuid, url, sha1, Config.kickOnDeclined(), Optional.of(packPrompt)
|
||||
);
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_3()) {
|
||||
packPacket = Reflections.constructor$ClientboundResourcePackPushPacket.newInstance(
|
||||
uuid, url, sha1, ConfigManager.kickOnDeclined(), packPrompt
|
||||
uuid, url, sha1, Config.kickOnDeclined(), packPrompt
|
||||
);
|
||||
} else {
|
||||
packPacket = Reflections.constructor$ClientboundResourcePackPushPacket.newInstance(
|
||||
url + uuid, sha1, ConfigManager.kickOnDeclined(), packPrompt
|
||||
url + uuid, sha1, Config.kickOnDeclined(), packPrompt
|
||||
);
|
||||
}
|
||||
if (user.decoderState() == ConnectionState.PLAY) {
|
||||
|
||||
@@ -29,7 +29,7 @@ import net.momirealms.craftengine.core.item.ItemManager;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.classpath.ReflectionClassPathAppender;
|
||||
import net.momirealms.craftengine.core.plugin.command.sender.SenderFactory;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.Dependencies;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.Dependency;
|
||||
import net.momirealms.craftengine.core.plugin.gui.category.ItemBrowserManagerImpl;
|
||||
@@ -65,17 +65,20 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
private boolean hasPlaceholderAPI;
|
||||
|
||||
public BukkitCraftEngine(JavaPlugin bootstrap) {
|
||||
VersionHelper.init(serverVersion());
|
||||
super((p) -> {
|
||||
CraftEngineReloadEvent event = new CraftEngineReloadEvent((BukkitCraftEngine) p);
|
||||
EventUtils.fireAndForget(event);
|
||||
});
|
||||
instance = this;
|
||||
this.bootstrap = bootstrap;
|
||||
super.classPathAppender = new ReflectionClassPathAppender(this);
|
||||
super.scheduler = new BukkitSchedulerAdapter(this);
|
||||
super.logger = new JavaPluginLogger(bootstrap.getLogger());
|
||||
// find mod class if present
|
||||
Class<?> modClass = ReflectionUtils.getClazz(MOD_CLASS);
|
||||
if (modClass != null) {
|
||||
Field isSuccessfullyRegistered = ReflectionUtils.getDeclaredField(modClass, "isSuccessfullyRegistered");
|
||||
try {
|
||||
assert isSuccessfullyRegistered != null;
|
||||
requiresRestart = !(boolean) isSuccessfullyRegistered.get(null);
|
||||
hasMod = true;
|
||||
} catch (Exception ignore) {
|
||||
@@ -84,13 +87,11 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
public void onPluginLoad() {
|
||||
super.onPluginLoad();
|
||||
Reflections.init();
|
||||
BukkitInjector.init();
|
||||
super.networkManager = new BukkitNetworkManager(this);
|
||||
super.networkManager.init();
|
||||
// load mappings and inject blocks
|
||||
super.blockManager = new BukkitBlockManager(this);
|
||||
super.furnitureManager = new BukkitFurnitureManager(this);
|
||||
this.successfullyLoaded = true;
|
||||
@@ -105,8 +106,8 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
if (successfullyEnabled) {
|
||||
public void onPluginEnable() {
|
||||
if (this.successfullyEnabled) {
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
@@ -154,8 +155,37 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
super.worldManager = new BukkitWorldManager(this);
|
||||
super.soundManager = new BukkitSoundManager(this);
|
||||
super.vanillaLootManager = new BukkitVanillaLootManager(this);
|
||||
this.fontManager = new BukkitFontManager(this);
|
||||
super.enable();
|
||||
super.fontManager = new BukkitFontManager(this);
|
||||
super.onPluginEnable();
|
||||
// compatibility
|
||||
// register expansion
|
||||
if (this.isPluginEnabled("PlaceholderAPI")) {
|
||||
PlaceholderAPIUtils.registerExpansions(this);
|
||||
this.hasPlaceholderAPI = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
super.onPluginDisable();
|
||||
if (this.tickTask != null) this.tickTask.cancel();
|
||||
if (!Bukkit.getServer().isStopping()) {
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
logger().severe("Please do not disable plugins at runtime.");
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
Bukkit.getServer().shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void platformDelayedEnable() {
|
||||
if (Config.metrics()) {
|
||||
new Metrics(this.bootstrap(), 24333);
|
||||
}
|
||||
// tick task
|
||||
if (VersionHelper.isFolia()) {
|
||||
this.tickTask = this.scheduler().sync().runRepeating(() -> {
|
||||
@@ -172,45 +202,6 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
}
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
// compatibility
|
||||
// register expansion
|
||||
if (this.isPluginEnabled("PlaceholderAPI")) {
|
||||
PlaceholderAPIUtils.registerExpansions(this);
|
||||
this.hasPlaceholderAPI = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
super.disable();
|
||||
if (this.tickTask != null) this.tickTask.cancel();
|
||||
if (!Bukkit.getServer().isStopping()) {
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
logger().severe("Please do not disable plugins at runtime.");
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
logger().severe(" ");
|
||||
Bukkit.getServer().shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
scheduler.async().execute(() -> {
|
||||
CraftEngineReloadEvent event = new CraftEngineReloadEvent(this);
|
||||
EventUtils.fireAndForget(event);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delayedEnable() {
|
||||
if (ConfigManager.metrics()) {
|
||||
new Metrics(this.bootstrap(), 24333);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,7 @@ import net.momirealms.craftengine.core.item.recipe.OptimizedIDItem;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.SingleItemInput;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -623,14 +623,14 @@ public class BukkitInjector {
|
||||
CESection section = holder.ceSection();
|
||||
if (BlockStateUtils.isVanillaBlock(stateId)) {
|
||||
section.setBlockState(x, y, z, EmptyBlock.INSTANCE.defaultState());
|
||||
if (ConfigManager.enableLightSystem() && ConfigManager.forceUpdateLight()) {
|
||||
if (Config.enableLightSystem() && Config.forceUpdateLight()) {
|
||||
updateLightIfChanged(holder, previousState, newState, null, y, z, x);
|
||||
}
|
||||
} else {
|
||||
ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockStateUnsafe(stateId);
|
||||
section.setBlockState(x, y, z, immutableBlockState);
|
||||
if (!immutableBlockState.isEmpty()) {
|
||||
if (ConfigManager.enableLightSystem()) {
|
||||
if (Config.enableLightSystem()) {
|
||||
updateLightIfChanged(holder, previousState, newState, immutableBlockState.vanillaBlockState().handle(), y, z, x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,20 +37,21 @@ import java.util.function.BiConsumer;
|
||||
|
||||
public class BukkitNetworkManager implements NetworkManager, Listener, PluginMessageListener {
|
||||
private static BukkitNetworkManager instance;
|
||||
private static final Map<Class<?>, TriConsumer<NetWorkUser, NMSPacketEvent, Object>> nmsPacketFunctions = new HashMap<>();
|
||||
private static final Map<Integer, BiConsumer<NetWorkUser, ByteBufPacketEvent>> byteBufPacketFunctions = new HashMap<>();
|
||||
private static final Map<Class<?>, TriConsumer<NetWorkUser, NMSPacketEvent, Object>> NMS_PACKET_HANDLERS = new HashMap<>();
|
||||
private static final Map<Integer, BiConsumer<NetWorkUser, ByteBufPacketEvent>> BYTE_BUFFER_PACKET_HANDLERS = new HashMap<>();
|
||||
|
||||
private static void registerNMSPacketConsumer(final TriConsumer<NetWorkUser, NMSPacketEvent, Object> function, @Nullable Class<?> packet) {
|
||||
if (packet == null) return;
|
||||
nmsPacketFunctions.put(packet, function);
|
||||
NMS_PACKET_HANDLERS.put(packet, function);
|
||||
}
|
||||
|
||||
private static void registerByteBufPacketConsumer(final BiConsumer<NetWorkUser, ByteBufPacketEvent> function, int id) {
|
||||
byteBufPacketFunctions.put(id, function);
|
||||
BYTE_BUFFER_PACKET_HANDLERS.put(id, function);
|
||||
}
|
||||
|
||||
private final BiConsumer<Object, List<Object>> packetsConsumer;
|
||||
private final BiConsumer<Object, Object> delayedPacketConsumer;
|
||||
private final BiConsumer<Object, List<Object>> immediatePacketsConsumer;
|
||||
private final BiConsumer<Object, Object> packetConsumer;
|
||||
private final BiConsumer<Object, Object> immediatePacketConsumer;
|
||||
private final BukkitCraftEngine plugin;
|
||||
|
||||
@@ -67,35 +68,22 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
private static final String PACKET_ENCODER = "craftengine_encoder";
|
||||
private static final String PACKET_DECODER = "craftengine_decoder";
|
||||
|
||||
private boolean active;
|
||||
private boolean init;
|
||||
private static boolean hasModelEngine;
|
||||
|
||||
public static boolean hasModelEngine() {
|
||||
return hasModelEngine;
|
||||
}
|
||||
|
||||
public BukkitNetworkManager(BukkitCraftEngine plugin) {
|
||||
instance = this;
|
||||
hasModelEngine = Bukkit.getPluginManager().getPlugin("ModelEngine") != null;
|
||||
this.plugin = plugin;
|
||||
if (VersionHelper.isVersionNewerThan1_21_5()) {
|
||||
this.packetIds = new PacketIds1_21_5();
|
||||
} else if (VersionHelper.isVersionNewerThan1_21_2()) {
|
||||
this.packetIds = new PacketIds1_21_2();
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_5()) {
|
||||
this.packetIds = new PacketIds1_20_5();
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_3()) {
|
||||
this.packetIds = new PacketIds1_20_3();
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_2()) {
|
||||
this.packetIds = new PacketIds1_20_2();
|
||||
} else {
|
||||
this.packetIds = new PacketIds1_20();
|
||||
}
|
||||
this.registerConsumers();
|
||||
// set up packet id
|
||||
this.packetIds = setupPacketIds();
|
||||
// register packet handlers
|
||||
this.registerPacketHandlers();
|
||||
// set up packet senders
|
||||
this.packetConsumer = FastNMS.INSTANCE::sendPacket;
|
||||
this.packetsConsumer = ((serverPlayer, packets) -> {
|
||||
Object bundle = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets);
|
||||
FastNMS.INSTANCE.sendPacket(serverPlayer, bundle);
|
||||
packetConsumer.accept(serverPlayer, bundle);
|
||||
});
|
||||
this.delayedPacketConsumer = FastNMS.INSTANCE::sendPacket;
|
||||
this.immediatePacketConsumer = (serverPlayer, packet) -> {
|
||||
try {
|
||||
Reflections.method$Connection$sendPacketImmediate.invoke(FastNMS.INSTANCE.field$Player$connection$connection(serverPlayer), packet, null, true);
|
||||
@@ -103,12 +91,47 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
plugin.logger().warn("Failed to invoke send packet", e);
|
||||
}
|
||||
};
|
||||
this.active = true;
|
||||
hasModelEngine = Bukkit.getPluginManager().getPlugin("ModelEngine") != null;
|
||||
instance = this;
|
||||
this.immediatePacketsConsumer = (serverPlayer, packets) -> {
|
||||
Object bundle = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets);
|
||||
this.immediatePacketConsumer.accept(serverPlayer, bundle);
|
||||
};
|
||||
// set up mod channel
|
||||
this.plugin.bootstrap().getServer().getMessenger().registerIncomingPluginChannel(this.plugin.bootstrap(), MOD_CHANNEL, this);
|
||||
this.plugin.bootstrap().getServer().getMessenger().registerOutgoingPluginChannel(this.plugin.bootstrap(), MOD_CHANNEL);
|
||||
// Inject server channel
|
||||
try {
|
||||
Object server = Reflections.method$MinecraftServer$getServer.invoke(null);
|
||||
Object serverConnection = Reflections.field$MinecraftServer$connection.get(server);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ChannelFuture> channels = (List<ChannelFuture>) Reflections.field$ServerConnectionListener$channels.get(serverConnection);
|
||||
ListMonitor<ChannelFuture> monitor = new ListMonitor<>(channels, (future) -> {
|
||||
Channel channel = future.channel();
|
||||
injectServerChannel(channel);
|
||||
this.injectedChannels.add(channel);
|
||||
}, (object) -> {});
|
||||
Reflections.field$ServerConnectionListener$channels.set(serverConnection, monitor);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
this.plugin.logger().warn("Failed to init server connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerConsumers() {
|
||||
private PacketIds setupPacketIds() {
|
||||
if (VersionHelper.isVersionNewerThan1_21_5()) {
|
||||
return new PacketIds1_21_5();
|
||||
} else if (VersionHelper.isVersionNewerThan1_21_2()) {
|
||||
return new PacketIds1_21_2();
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_5()) {
|
||||
return new PacketIds1_20_5();
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_3()) {
|
||||
return new PacketIds1_20_3();
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_2()) {
|
||||
return new PacketIds1_20_2();
|
||||
} else {
|
||||
return new PacketIds1_20();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerPacketHandlers() {
|
||||
registerNMSPacketConsumer(PacketConsumers.LEVEL_CHUNK_WITH_LIGHT, Reflections.clazz$ClientboundLevelChunkWithLightPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.PLAYER_ACTION, Reflections.clazz$ServerboundPlayerActionPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SWING_HAND, Reflections.clazz$ServerboundSwingPacket);
|
||||
@@ -150,7 +173,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Channel channel = getChannel(player);
|
||||
@@ -170,40 +193,17 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
return this.onlineUserArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
// 保留仅注册入频道用
|
||||
@Override
|
||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte @NotNull [] message) {}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (init) return;
|
||||
try {
|
||||
this.plugin.bootstrap().getServer().getMessenger().registerIncomingPluginChannel(this.plugin.bootstrap(), MOD_CHANNEL, this);
|
||||
this.plugin.bootstrap().getServer().getMessenger().registerOutgoingPluginChannel(this.plugin.bootstrap(), MOD_CHANNEL);
|
||||
Object server = Reflections.method$MinecraftServer$getServer.invoke(null);
|
||||
Object serverConnection = Reflections.field$MinecraftServer$connection.get(server);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ChannelFuture> channels = (List<ChannelFuture>) Reflections.field$ServerConnectionListener$channels.get(serverConnection);
|
||||
ListMonitor<ChannelFuture> monitor = new ListMonitor<>(channels, (future) -> {
|
||||
if (!this.active) return;
|
||||
Channel channel = future.channel();
|
||||
injectServerChannel(channel);
|
||||
this.injectedChannels.add(channel);
|
||||
}, (object) -> {});
|
||||
Reflections.field$ServerConnectionListener$channels.set(serverConnection, monitor);
|
||||
this.init = true;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
this.plugin.logger().warn("Failed to init server connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin.bootstrap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
public void disable() {
|
||||
HandlerList.unregisterAll(this);
|
||||
for (Channel channel : injectedChannels) {
|
||||
uninjectServerChannel(channel);
|
||||
@@ -212,7 +212,6 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
handleDisconnection(getChannel(player));
|
||||
}
|
||||
injectedChannels.clear();
|
||||
active = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,16 +258,26 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(@NotNull NetWorkUser player, Object packet, boolean immediately) {
|
||||
if (immediately) {
|
||||
this.immediatePacketConsumer.accept(player.serverPlayer(), packet);
|
||||
} else {
|
||||
this.delayedPacketConsumer.accept(player.serverPlayer(), packet);
|
||||
this.packetConsumer.accept(player.serverPlayer(), packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPackets(@NotNull NetWorkUser player, List<Object> packet) {
|
||||
this.packetsConsumer.accept(player.serverPlayer(), packet);
|
||||
@Override
|
||||
public void sendPackets(@NotNull NetWorkUser player, List<Object> packet, boolean immediately) {
|
||||
if (immediately) {
|
||||
this.immediatePacketsConsumer.accept(player.serverPlayer(), packet);
|
||||
} else {
|
||||
this.packetsConsumer.accept(player.serverPlayer(), packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasModelEngine() {
|
||||
return hasModelEngine;
|
||||
}
|
||||
|
||||
public void receivePacket(@NotNull NetWorkUser player, Object packet) {
|
||||
@@ -543,13 +552,13 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
}
|
||||
|
||||
protected void handleNMSPacket(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
||||
Optional.ofNullable(nmsPacketFunctions.get(packet.getClass()))
|
||||
Optional.ofNullable(NMS_PACKET_HANDLERS.get(packet.getClass()))
|
||||
.ifPresent(function -> function.accept(user, event, packet));
|
||||
}
|
||||
|
||||
protected void handleByteBufPacket(NetWorkUser user, ByteBufPacketEvent event) {
|
||||
int packetID = event.packetID();
|
||||
Optional.ofNullable(byteBufPacketFunctions.get(packetID))
|
||||
Optional.ofNullable(BYTE_BUFFER_PACKET_HANDLERS.get(packetID))
|
||||
.ifPresent(function -> function.accept(user, event));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
||||
import net.momirealms.craftengine.core.font.FontManager;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.network.ConnectionState;
|
||||
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
|
||||
import net.momirealms.craftengine.core.plugin.network.NetworkManager;
|
||||
@@ -300,7 +300,7 @@ public class PacketConsumers {
|
||||
int stateId = BlockStateUtils.blockStateToId(blockState);
|
||||
// not a custom block
|
||||
if (BlockStateUtils.isVanillaBlock(stateId)) {
|
||||
if (ConfigManager.enableSoundSystem()) {
|
||||
if (Config.enableSoundSystem()) {
|
||||
Object blockOwner = Reflections.field$StateHolder$owner.get(blockState);
|
||||
if (BukkitBlockManager.instance().isBlockSoundRemoved(blockOwner)) {
|
||||
player.startMiningBlock(world, pos, blockState, false, null);
|
||||
@@ -626,7 +626,7 @@ public class PacketConsumers {
|
||||
if (furniture != null) {
|
||||
user.furnitureView().computeIfAbsent(furniture.baseEntityId(), k -> new ArrayList<>()).addAll(furniture.fakeEntityIds());
|
||||
user.sendPacket(furniture.spawnPacket((Player) user.platformPlayer()), false);
|
||||
if (ConfigManager.hideBaseEntity() && !furniture.hasExternalModel()) {
|
||||
if (Config.hideBaseEntity() && !furniture.hasExternalModel()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -774,7 +774,7 @@ public class PacketConsumers {
|
||||
// we handle it on packet level to prevent it from being captured by plugins
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> RENAME_ITEM = (user, event, packet) -> {
|
||||
try {
|
||||
if (!ConfigManager.filterAnvil()) return;
|
||||
if (!Config.filterAnvil()) return;
|
||||
String message = (String) Reflections.field$ServerboundRenameItemPacket$name.get(packet);
|
||||
if (message != null && !message.isEmpty()) {
|
||||
FontManager manager = CraftEngine.instance().imageManager();
|
||||
@@ -799,7 +799,7 @@ public class PacketConsumers {
|
||||
// we handle it on packet level to prevent it from being captured by plugins
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SIGN_UPDATE = (user, event, packet) -> {
|
||||
try {
|
||||
if (!ConfigManager.filterSign()) return;
|
||||
if (!Config.filterSign()) return;
|
||||
String[] lines = (String[]) Reflections.field$ServerboundSignUpdatePacket$lines.get(packet);
|
||||
FontManager manager = CraftEngine.instance().imageManager();
|
||||
if (!manager.isDefaultFontInUse()) return;
|
||||
@@ -826,7 +826,7 @@ public class PacketConsumers {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> EDIT_BOOK = (user, event, packet) -> {
|
||||
try {
|
||||
if (!ConfigManager.filterBook()) return;
|
||||
if (!Config.filterBook()) return;
|
||||
FontManager manager = CraftEngine.instance().imageManager();
|
||||
if (!manager.isDefaultFontInUse()) return;
|
||||
// check bypass
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.item.recipe.OptimizedIDItem;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.SingleItemInput;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.Direction;
|
||||
@@ -77,14 +77,14 @@ public class InteractUtils {
|
||||
return false;
|
||||
});
|
||||
register(BlockKeys.SOUL_CAMPFIRE, (player, item, blockState, result) -> {
|
||||
if (!ConfigManager.enableRecipeSystem()) return false;
|
||||
if (!Config.enableRecipeSystem()) return false;
|
||||
Optional<Holder.Reference<Key>> optional = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(item.id());
|
||||
return optional.filter(keyReference -> BukkitRecipeManager.instance().recipeByInput(RecipeTypes.CAMPFIRE_COOKING, new SingleItemInput<>(new OptimizedIDItem<>(
|
||||
keyReference, item.getItem()
|
||||
))) != null).isPresent();
|
||||
});
|
||||
register(BlockKeys.CAMPFIRE, (player, item, blockState, result) -> {
|
||||
if (!ConfigManager.enableRecipeSystem()) return false;
|
||||
if (!Config.enableRecipeSystem()) return false;
|
||||
Optional<Holder.Reference<Key>> optional = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(item.id());
|
||||
return optional.filter(keyReference -> BukkitRecipeManager.instance().recipeByInput(RecipeTypes.CAMPFIRE_COOKING, new SingleItemInput<>(new OptimizedIDItem<>(
|
||||
keyReference, item.getItem()
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
|
||||
public class NoteBlockChainUpdateUtils {
|
||||
|
||||
private NoteBlockChainUpdateUtils() {}
|
||||
|
||||
public static void noteBlockChainUpdate(Object level, Object chunkSource, Object direction, Object blockPos, int times) throws ReflectiveOperationException {
|
||||
if (times >= ConfigManager.maxChainUpdate()) return;
|
||||
if (times >= Config.maxChainUpdate()) return;
|
||||
Object relativePos = Reflections.method$BlockPos$relative.invoke(blockPos, direction);
|
||||
Object state = FastNMS.INSTANCE.method$BlockGetter$getBlockState(level, relativePos);
|
||||
if (BlockStateUtils.isClientSideNoteBlock(state)) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.world;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.util.LightUtils;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.util.SectionPosUtils;
|
||||
import net.momirealms.craftengine.core.world.CEWorld;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
@@ -20,7 +20,7 @@ public class BukkitCEWorld extends CEWorld {
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (ConfigManager.enableLightSystem()) {
|
||||
if (Config.enableLightSystem()) {
|
||||
LightUtils.updateChunkLight((org.bukkit.World) world.platformWorld(), SectionPosUtils.toMap(super.updatedSectionPositions, world.worldHeight().getMinSection() - 1, world.worldHeight().getMaxSection() + 1));
|
||||
super.updatedSectionPositions.clear();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.scheduler.SchedulerTask;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.world.CEWorld;
|
||||
@@ -265,7 +265,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
|
||||
plugin.logger().warn("Failed to write chunk tag at " + chunk.getX() + " " + chunk.getZ(), e);
|
||||
return;
|
||||
} finally {
|
||||
if (ConfigManager.restoreVanillaBlocks()) {
|
||||
if (Config.restoreVanillaBlocks()) {
|
||||
CESection[] ceSections = ceChunk.sections();
|
||||
Object worldServer = FastNMS.INSTANCE.field$CraftChunk$worldServer(chunk);
|
||||
Object chunkSource = FastNMS.INSTANCE.method$ServerLevel$getChunkSource(worldServer);
|
||||
@@ -313,7 +313,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
|
||||
for (int i = 0; i < ceSections.length; i++) {
|
||||
CESection ceSection = ceSections[i];
|
||||
Object section = sections[i];
|
||||
if (ConfigManager.syncCustomBlocks()) {
|
||||
if (Config.syncCustomBlocks()) {
|
||||
Object statesContainer = FastNMS.INSTANCE.field$LevelChunkSection$states(section);
|
||||
Object data = Reflections.varHandle$PalettedContainer$data.get(statesContainer);
|
||||
Object palette = Reflections.field$PalettedContainer$Data$palette.get(data);
|
||||
@@ -362,7 +362,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ConfigManager.restoreCustomBlocks()) {
|
||||
if (Config.restoreCustomBlocks()) {
|
||||
if (!ceSection.statesContainer().isEmpty()) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
@@ -378,7 +378,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
|
||||
}
|
||||
BukkitInjector.injectLevelChunkSection(section, ceSection, ceWorld, new SectionPos(pos.x, ceChunk.sectionY(i), pos.z));
|
||||
}
|
||||
if (ConfigManager.enableRecipeSystem()) {
|
||||
if (Config.enableRecipeSystem()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Object, Object> blockEntities = (Map<Object, Object>) FastNMS.INSTANCE.field$ChunkAccess$blockEntities(levelChunk);
|
||||
for (Object blockEntity : blockEntities.values()) {
|
||||
|
||||
Reference in New Issue
Block a user