-
-
Notifications
You must be signed in to change notification settings - Fork 10
GH-184 Refactor Knockback Mechanic and Add Support for Deny Entry flag #184
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
05f7d83
Initial commit
CitralFlo ac494e7
fix spaces
CitralFlo 2a6de72
fix spaces
CitralFlo 2a4252f
Add Kamicjusz's changes. Normalize knockback vector, fix message.
CitralFlo ba7eca8
Set cooldown for messages
CitralFlo 1b244e5
Resolve half of suggestions
CitralFlo 6d6f604
Remove delay and add PVP regions blockade.
CitralFlo e1b795f
Improve performance of WorldGuardRegionProvider.
Rollczi 82e6ba1
Merge branch 'refs/heads/master' into worldguard-pvp
CitralFlo 00953b8
Use lambda
Rollczi 85fa981
Merge remote-tracking branch 'origin/worldguard-pvp' into worldguard-pvp
Rollczi 3e70921
Resolve @vLuckyyy review
CitralFlo 7458936
Remove bait class :P
CitralFlo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
eternalcombat-api/src/main/java/com/eternalcode/combat/region/Region.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.eternalcode.combat.region; | ||
|
|
||
| import org.bukkit.Location; | ||
|
|
||
| public interface Region { | ||
|
|
||
| Location getCenter(); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
eternalcombat-api/src/main/java/com/eternalcode/combat/region/RegionProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| package com.eternalcode.combat.region; | ||
|
|
||
| import java.util.Optional; | ||
| import org.bukkit.Location; | ||
|
|
||
| public interface RegionProvider { | ||
|
|
||
| boolean isInRegion(Location location); | ||
| Optional<Region> getRegion(Location location); | ||
|
|
||
| Location getRegionCenter(Location location); | ||
| default boolean isInRegion(Location location) { | ||
| return getRegion(location).isPresent(); | ||
| } | ||
|
|
||
| } |
82 changes: 44 additions & 38 deletions
82
eternalcombat-api/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,69 +1,75 @@ | ||
| package com.eternalcode.combat.region; | ||
|
|
||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||
| import com.sk89q.worldedit.bukkit.BukkitAdapter; | ||
| import com.sk89q.worldedit.math.BlockVector3; | ||
| import com.sk89q.worldguard.WorldGuard; | ||
| import com.sk89q.worldguard.protection.ApplicableRegionSet; | ||
| import com.sk89q.worldguard.protection.flags.Flags; | ||
| import com.sk89q.worldguard.protection.flags.StateFlag; | ||
| import com.sk89q.worldguard.protection.regions.ProtectedRegion; | ||
| import com.sk89q.worldguard.protection.regions.RegionContainer; | ||
| import com.sk89q.worldguard.protection.regions.RegionQuery; | ||
| import java.util.Optional; | ||
| import java.util.TreeSet; | ||
| import org.bukkit.Location; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class WorldGuardRegionProvider implements RegionProvider { | ||
|
|
||
| private final List<String> regions; | ||
| private final RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer(); | ||
| private final TreeSet<String> regions = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); | ||
| private final PluginConfig pluginConfig; | ||
|
|
||
| public WorldGuardRegionProvider(List<String> regions) { | ||
| this.regions = regions; | ||
| public WorldGuardRegionProvider(List<String> regions, PluginConfig pluginConfig) { | ||
| this.regions.addAll(regions); | ||
| this.pluginConfig = pluginConfig; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isInRegion(Location location) { | ||
| return this.regions.stream().anyMatch(region -> this.isInCombatRegion(location, region)); | ||
| } | ||
|
|
||
| @Override | ||
| public Location getRegionCenter(Location location) { | ||
| RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer(); | ||
| RegionQuery regionQuery = regionContainer.createQuery(); | ||
| public Optional<Region> getRegion(Location location) { | ||
| RegionQuery regionQuery = this.regionContainer.createQuery(); | ||
| ApplicableRegionSet applicableRegions = regionQuery.getApplicableRegions(BukkitAdapter.adapt(location)); | ||
|
|
||
| double minX = 0; | ||
| double maxX = 0; | ||
| double minZ = 0; | ||
| double maxZ = 0; | ||
|
|
||
| for (ProtectedRegion region : applicableRegions.getRegions()) { | ||
| BlockVector3 min = region.getMinimumPoint(); | ||
| BlockVector3 max = region.getMaximumPoint(); | ||
|
|
||
| if (min.getX() < minX) { | ||
| minX = min.getX(); | ||
| } | ||
| if (max.getX() > maxX) { | ||
| maxX = max.getX(); | ||
| } | ||
| if (min.getZ() < minZ) { | ||
| minZ = min.getZ(); | ||
| } | ||
| if (max.getZ() > maxZ) { | ||
| maxZ = max.getZ(); | ||
| if (!isCombatRegion(region)) { | ||
| continue; | ||
| } | ||
|
|
||
| return Optional.of(new RegionImpl(location, region)); | ||
| } | ||
|
|
||
| return Optional.empty(); | ||
| } | ||
|
|
||
| private boolean isCombatRegion(ProtectedRegion region) { | ||
| if (this.regions.contains(region.getId())) { | ||
| return true; | ||
| } | ||
|
|
||
| double x = (maxX - minX) / 2 + minX; | ||
| double z = (maxZ - minZ) / 2 + minZ; | ||
| if (this.pluginConfig.settings.shouldPreventPvpRegions) { | ||
| StateFlag.State flag = region.getFlag(Flags.PVP); | ||
|
|
||
| if (flag != null) { | ||
| return flag.equals(StateFlag.State.DENY); | ||
| } | ||
| } | ||
|
|
||
| return new Location(location.getWorld(), x, location.getY(), z); | ||
| return false; | ||
| } | ||
|
|
||
| private boolean isInCombatRegion(Location location, String regionName) { | ||
| RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer(); | ||
| RegionQuery regionQuery = regionContainer.createQuery(); | ||
| ApplicableRegionSet applicableRegions = regionQuery.getApplicableRegions(BukkitAdapter.adapt(location)); | ||
| private record RegionImpl(Location contextLocation, ProtectedRegion region) implements Region { | ||
| @Override | ||
| public Location getCenter() { | ||
| BlockVector3 min = region.getMinimumPoint(); | ||
| BlockVector3 max = region.getMaximumPoint(); | ||
|
|
||
| return applicableRegions.getRegions().stream().anyMatch(region -> region.getId().equalsIgnoreCase(regionName)); | ||
| double x = (double) (min.getX() + max.getX()) / 2; | ||
| double z = (double) (min.getZ() + max.getZ()) / 2; | ||
|
|
||
| return new Location(contextLocation.getWorld(), x, contextLocation.getY(), z); | ||
| } | ||
| } | ||
|
Rollczi marked this conversation as resolved.
|
||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.