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

WorldGuard compatibility #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

fastfend
Copy link

@fastfend fastfend commented Feb 1, 2022

This PR adds compatibility with WorldGuard plugin.

When BetterPortals tries to create new portal using NewPortalChecker it checks for WG plugin and if it is enabled checks if player can build in desired location. If somehow player would not be provided default logic of WG is used

@Lauriethefish
Copy link
Owner

Might want to check this post - as far as I know, with how you're doing things right now, if WG is not installed you'll get ClassDefNotFoundErrors.

@Lauriethefish
Copy link
Owner

TL;DR, canBuildInRegion needs to be in an entirely separate class. You can then bind an implementation of that class that always returns true if WG is not installed, and otherwise you should bind the WG version of the class (using Class.forName in order to avoid directly referencing the class)

@fastfend
Copy link
Author

fastfend commented Feb 2, 2022

Hi! In my implementation I use

if(Bukkit.getPluginManager().getPlugin("WorldGuard") == null) { return true; }

This way I never load class related to WG until next steps which ensures that WorldGuard is loaded. The problem you are talking about isn't going to happen because it will never go beyond that point. Java loads classes when necessary that's why it works. Tested and it works without WG (without errors in console). Even though if you want I can rewrite it to other class

@Lauriethefish
Copy link
Owner

Alright, if you're sure it works that's fine.
Could you think about implementing a custom WG flag? I think that'd be better than using block place.

@fastfend
Copy link
Author

fastfend commented Feb 2, 2022

Sure! Definetly it will add more flexibilty for users. Also what do you think about resigning from forcing portal placement if no space was found?
Maybe condition it based on WG apperance too?

@Lauriethefish
Copy link
Owner

Hmm, I'll think about that. Performance is another thing that will need to be thought about - BP can check many thousands of portal positions on each spawn, especially with the new world height limit.

@fastfend
Copy link
Author

Ok, I've added requested stuff. I've also made some performance tests and sadly when there is no space for portal check is running for about 10 sec on 5600X. I know that it's done off thread so world lives, but one core is sucked out of it all juice.
When more portals are ignited at the same time it still uses one core so it just makes search longer. Also there is about 1GB memory spike (mostly consisting of bukkit Location objects, but also BlockPosition).

tldr If portal is being ignited and there is big region which blocks it BetterPortals will use all out of one core

@fastfend
Copy link
Author

fastfend commented Mar 4, 2022

Came up with idea of "optimization". BetterPortals will find candidate for portal position quickly at border of that WG region. To prevent unnecessary work from BP I'm gonna block portal ignition for scaled region (1/8x and 8x etc.). This way BP won't start search if portal is ignited in center of WG region

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants