Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia support. #594

Open
vLuckyyy opened this issue Dec 24, 2023 · 6 comments · May be fixed by #844
Open

Folia support. #594

vLuckyyy opened this issue Dec 24, 2023 · 6 comments · May be fixed by #844
Assignees
Labels
🆕 feature New feature or request 🆘 help wanted Extra attention is needed

Comments

@vLuckyyy
Copy link
Member

No description provided.

@vLuckyyy vLuckyyy added the 🐛 bug Something isn't working label Dec 30, 2023
@vLuckyyy vLuckyyy moved this to 📋 Backlog in EternalCore Jan 13, 2024
@vLuckyyy vLuckyyy added 🆕 feature New feature or request and removed 🐛 bug Something isn't working labels Feb 2, 2024
@vLuckyyy
Copy link
Member Author

I am want to check and analyze what changes will need to be made before implementing the folia.

@vLuckyyy vLuckyyy self-assigned this Feb 17, 2024
@vLuckyyy vLuckyyy added the 🆘 help wanted Extra attention is needed label Feb 17, 2024
@Rollczi
Copy link
Member

Rollczi commented Feb 17, 2024

If you test the folia, remember to activate minimum two folia regions.

@vLuckyyy
Copy link
Member Author

The first question is how to implement the Scheduler well so as not to lose compatibility of the current code.

@vLuckyyy
Copy link
Member Author

I will probably address this as soon as #652 is completed.

@vLuckyyy vLuckyyy linked a pull request Sep 14, 2024 that will close this issue
3 tasks
@vLuckyyy
Copy link
Member Author

vLuckyyy commented Oct 9, 2024

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

Tip

For best results, initiate chat on the files or code changes.

@vLuckyyy, here are some considerations for implementing Folia support while maintaining compatibility with your current code, especially regarding the Scheduler:

  1. Abstract Scheduler Interface: Create an abstraction layer for your Scheduler. By defining a Scheduler interface, you can have different implementations for Bukkit and Folia without changing the core logic of your application.

    // Scheduler interface
    public interface Scheduler {
        void runTask(Runnable task);
        void runTaskAsynchronously(Runnable task);
        // Add other scheduling methods as needed
    }
  2. Bukkit Implementation:

    // Bukkit Scheduler implementation
    public class BukkitScheduler implements Scheduler {
        private final Plugin plugin;
    
        public BukkitScheduler(Plugin plugin) {
            this.plugin = plugin;
        }
    
        @Override
        public void runTask(Runnable task) {
            Bukkit.getScheduler().runTask(plugin, task);
        }
    
        @Override
        public void runTaskAsynchronously(Runnable task) {
            Bukkit.getScheduler().runTaskAsynchronously(plugin, task);
        }
        // Implement other methods
    }
  3. Folia Implementation:

    // Folia Scheduler implementation
    public class FoliaScheduler implements Scheduler {
        private final Plugin plugin;
    
        public FoliaScheduler(Plugin plugin) {
            this.plugin = plugin;
        }
    
        @Override
        public void runTask(Runnable task) {
            // Use Folia-specific scheduling
            plugin.getServer().getGlobalRegionScheduler().run(plugin, task);
        }
    
        @Override
        public void runTaskAsynchronously(Runnable task) {
            // Folia might handle async tasks differently
            CompletableFuture.runAsync(task);
        }
        // Implement other methods
    }
  4. Runtime Selection: Determine which Scheduler implementation to use at runtime based on the server environment.

    // Scheduler factory
    public class SchedulerFactory {
        public static Scheduler getScheduler(Plugin plugin) {
            if (isFolia()) {
                return new FoliaScheduler(plugin);
            } else {
                return new BukkitScheduler(plugin);
            }
        }
    
        private static boolean isFolia() {
            try {
                Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
                return true;
            } catch (ClassNotFoundException e) {
                return false;
            }
        }
    }
  5. Concurrency and Thread Safety: Folia introduces a different concurrency model. Review your code for thread safety, especially when accessing shared data. Ensure that any shared resources are appropriately synchronized or designed using thread-safe patterns.

  6. API Differences: Be mindful of differences between the Bukkit and Folia APIs. Some methods may behave differently or may not be available in Folia. Testing and conditional code may be necessary.

  7. Testing with Multiple Folia Regions: As @Rollczi mentioned, ensure that you activate at least two Folia regions during testing. This will help identify any region-specific issues that might not appear with a single region.

  8. Maintain Compatibility: Keep the existing functionality intact by defaulting to the Bukkit Scheduler when Folia is not detected. This ensures that your plugin remains compatible with servers not running Folia.

  9. Documentation and User Guidance: Update your documentation to inform users about Folia support and any configuration they might need to enable or disable it.

Feel free to let me know if you'd like to delve deeper into any of these areas or if you have specific code you'd like me to review in detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 feature New feature or request 🆘 help wanted Extra attention is needed
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

2 participants