-
-
Notifications
You must be signed in to change notification settings - Fork 8
GH-204 Add Border #204
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
GH-204 Add Border #204
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
07a517a
Implement border
Rollczi 870d3ea
More important changes
Rollczi 557af8e
Add blocks updater
Rollczi 6239e55
Implement it
Rollczi 9564fb9
Include combat limitation for border
Rollczi ca9eff3
Fix knockback
Rollczi c4060a9
Merge branch 'refs/heads/2.0' into border
Rollczi f697298
Fix region resolving
Rollczi c816c45
Remove useless comments
Rollczi 1a9682a
Cleanup code. Add caches for chunk snapshot
Rollczi 0fb26d3
Code style changes
Rollczi 7bc73f3
Add config for the border and the knockback, cleanup
Rollczi 844e917
Merge branch '2.0' into border
Rollczi 09d740d
Bump actions
Rollczi decb3da
Minor configuration adjustments
CitralFlo 260e2a1
Follow Jakubek review
Rollczi ef1c18d
Follow DMK review
Rollczi 38a614f
Merge remote-tracking branch 'origin/border' into border
Rollczi 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
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
66 changes: 66 additions & 0 deletions
66
...nalcombat-plugin/src/main/java/com/eternalcode/combat/border/BorderActivePointsIndex.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,66 @@ | ||
| package com.eternalcode.combat.border; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| class BorderActivePointsIndex { | ||
|
|
||
| private final Map<String, Map<UUID, Set<BorderPoint>>> registry = new ConcurrentHashMap<>(); | ||
|
|
||
| boolean hasPoints(String world, UUID player) { | ||
| Map<UUID, Set<BorderPoint>> worldRegistry = this.registry.get(world); | ||
| if (worldRegistry == null) { | ||
| return false; | ||
| } | ||
|
|
||
| return worldRegistry.containsKey(player); | ||
| } | ||
|
|
||
| Set<BorderPoint> putPoints(String world, UUID player, Set<BorderPoint> points) { | ||
| Map<UUID, Set<BorderPoint>> worldRegistry = this.registry.computeIfAbsent(world, k -> new ConcurrentHashMap<>()); | ||
| Set<BorderPoint> oldPoints = worldRegistry.put(player, points); | ||
| if (oldPoints != null) { | ||
| return calculateRemovedPoints(points, oldPoints); | ||
| } | ||
|
|
||
| return Set.of(); | ||
Rollczi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static Set<BorderPoint> calculateRemovedPoints(Set<BorderPoint> points, Set<BorderPoint> oldPoints) { | ||
| Set<BorderPoint> removed = new HashSet<>(); | ||
| for (BorderPoint oldPoint : oldPoints) { | ||
| if (!points.contains(oldPoint)) { | ||
| removed.add(oldPoint); | ||
| } | ||
| } | ||
| return Collections.unmodifiableSet(removed); | ||
| } | ||
|
|
||
| Set<BorderPoint> getPoints(String world, UUID player) { | ||
| Map<UUID, Set<BorderPoint>> worldRegistry = this.registry.get(world); | ||
| if (worldRegistry == null) { | ||
| return Set.of(); | ||
| } | ||
|
|
||
| return worldRegistry.getOrDefault(player, Set.of()); | ||
| } | ||
|
|
||
| Set<BorderPoint> removePoints(String world, UUID player) { | ||
| Map<UUID, Set<BorderPoint>> worldRegistry = this.registry.get(world); | ||
| if (worldRegistry == null) { | ||
| return Set.of(); | ||
| } | ||
|
|
||
| Set<BorderPoint> remove = worldRegistry.remove(player); | ||
| if (remove == null) { | ||
| return Set.of(); | ||
| } | ||
|
|
||
| return remove; | ||
| } | ||
|
|
||
| } | ||
24 changes: 24 additions & 0 deletions
24
eternalcombat-plugin/src/main/java/com/eternalcode/combat/border/BorderLazyResult.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,24 @@ | ||
| package com.eternalcode.combat.border; | ||
|
|
||
| import dev.rollczi.litecommands.shared.Lazy; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| class BorderLazyResult implements BorderResult { | ||
|
|
||
| private final List<Lazy<List<BorderPoint>>> borderPoints = new ArrayList<>(); | ||
|
|
||
| void addLazyBorderPoints(Lazy<List<BorderPoint>> supplier) { | ||
| borderPoints.add(supplier); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<BorderPoint> collect() { | ||
| return borderPoints.stream() | ||
| .flatMap(result -> result.get().stream()) | ||
| .collect(Collectors.toUnmodifiableSet()); | ||
| } | ||
|
|
||
| } |
19 changes: 19 additions & 0 deletions
19
eternalcombat-plugin/src/main/java/com/eternalcode/combat/border/BorderPoint.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,19 @@ | ||
| package com.eternalcode.combat.border; | ||
|
|
||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public record BorderPoint(int x, int y, int z, @Nullable BorderPoint inclusive) { | ||
|
|
||
| public BorderPoint(int x, int y, int z) { | ||
| this(x, y, z, null); | ||
| } | ||
|
|
||
| public BorderPoint toInclusive() { | ||
| if (inclusive == null) { | ||
| return this; | ||
| } | ||
|
|
||
| return inclusive; | ||
Rollczi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| } | ||
9 changes: 9 additions & 0 deletions
9
eternalcombat-plugin/src/main/java/com/eternalcode/combat/border/BorderResult.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.border; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| public interface BorderResult { | ||
|
|
||
| Set<BorderPoint> collect(); | ||
|
|
||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.