-
-
Notifications
You must be signed in to change notification settings - Fork 13
GH-180 Add GriefPrevention region support for combat restrictions #423
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
Open
vLuckyyy
wants to merge
1
commit into
master
Choose a base branch
from
grief-prevention-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
34 changes: 34 additions & 0 deletions
34
...in/src/main/java/com/eternalcode/combat/region/griefprevention/GriefPreventionRegion.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,34 @@ | ||
| package com.eternalcode.combat.region.griefprevention; | ||
|
|
||
| import com.eternalcode.combat.region.Point; | ||
| import com.eternalcode.combat.region.Region; | ||
| import me.ryanhamshire.GriefPrevention.Claim; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.World; | ||
|
|
||
| record GriefPreventionRegion(World world, Claim claim) implements Region { | ||
|
|
||
| @Override | ||
| public Point getCenter() { | ||
| Location min = this.claim.getLesserBoundaryCorner(); | ||
| Location max = this.claim.getGreaterBoundaryCorner(); | ||
|
|
||
| double x = (min.getX() + max.getX()) / 2.0; | ||
| double z = (min.getZ() + max.getZ()) / 2.0; | ||
|
|
||
| return new Point(this.world, x, z); | ||
| } | ||
|
|
||
| @Override | ||
| public Location getMin() { | ||
| Location min = this.claim.getLesserBoundaryCorner(); | ||
| return new Location(this.world, min.getBlockX(), this.world.getMinHeight(), min.getBlockZ()); | ||
| } | ||
|
|
||
| @Override | ||
| public Location getMax() { | ||
| Location max = this.claim.getGreaterBoundaryCorner(); | ||
| return new Location(this.world, max.getBlockX(), this.world.getMaxHeight() - 1, max.getBlockZ()); | ||
| } | ||
|
|
||
| } | ||
93 changes: 93 additions & 0 deletions
93
...ain/java/com/eternalcode/combat/region/griefprevention/GriefPreventionRegionProvider.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,93 @@ | ||
| package com.eternalcode.combat.region.griefprevention; | ||
|
|
||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||
| import com.eternalcode.combat.region.Region; | ||
| import com.eternalcode.combat.region.RegionProvider; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.ConcurrentModificationException; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.TreeSet; | ||
| import me.ryanhamshire.GriefPrevention.Claim; | ||
| import me.ryanhamshire.GriefPrevention.GriefPrevention; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.World; | ||
|
|
||
| public class GriefPreventionRegionProvider implements RegionProvider { | ||
|
|
||
| private final TreeSet<String> claims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); | ||
| private final PluginConfig pluginConfig; | ||
|
|
||
| public GriefPreventionRegionProvider(PluginConfig pluginConfig) { | ||
| this.claims.addAll(pluginConfig.regions.blockedRegions); | ||
| this.pluginConfig = pluginConfig; | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Region> getRegion(Location location) { | ||
| Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null); | ||
|
|
||
| if (claim == null || !this.isCombatClaim(claim)) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| return Optional.of(new GriefPreventionRegion(location.getWorld(), claim)); | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<Region> getRegions(World world) { | ||
| List<Region> regions = new ArrayList<>(); | ||
|
|
||
| for (Claim claim : this.snapshotClaims()) { | ||
| if (!world.equals(claim.getLesserBoundaryCorner().getWorld())) { | ||
| continue; | ||
| } | ||
|
|
||
| if (this.isCombatClaim(claim)) { | ||
| regions.add(new GriefPreventionRegion(world, claim)); | ||
| } | ||
| } | ||
|
|
||
| return regions; | ||
| } | ||
|
|
||
| private boolean isCombatClaim(Claim claim) { | ||
| if (this.claims.contains(String.valueOf(claim.getID()))) { | ||
| return true; | ||
| } | ||
|
|
||
| if (!this.pluginConfig.regions.preventPvpInRegions) { | ||
| return false; | ||
| } | ||
|
|
||
| World world = claim.getLesserBoundaryCorner().getWorld(); | ||
| GriefPrevention griefPrevention = GriefPrevention.instance; | ||
|
|
||
| if (world == null || !griefPrevention.pvpRulesApply(world)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!claim.isAdminClaim()) { | ||
| return griefPrevention.config_pvp_noCombatInPlayerLandClaims; | ||
| } | ||
|
|
||
| if (claim.parent == null) { | ||
| return griefPrevention.config_pvp_noCombatInAdminLandClaims; | ||
| } | ||
|
|
||
| return griefPrevention.config_pvp_noCombatInAdminSubdivisions; | ||
| } | ||
|
|
||
| // GriefPrevention returns a live view of its claim list, and the border index reads regions asynchronously. | ||
| // A failed snapshot is retried by the next border index refresh, so an empty result is safe here. | ||
| private List<Claim> snapshotClaims() { | ||
| try { | ||
| return List.copyOf(GriefPrevention.instance.dataStore.getClaims()); | ||
| } | ||
| catch (ConcurrentModificationException exception) { | ||
| return List.of(); | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GriefPrevention's greater boundary corner is inclusive, but
Region.containscompares every coordinate with< getMax(). Consequently, a combat-tagged player standing on a claim's maximum X or Z row is reported by GriefPrevention as inside the claim whileGriefPreventionRegion.containsreports them outside; moves within that row are then handled as attempts to enter and cancelled rather than receiving the normal inside-region knockback. Represent the upper bounds as exclusive or override containment so the greater boundary blocks remain included.Useful? React with 👍 / 👎.