Skip to content

GH-226 Add Lands support. #226

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

GH-226 Add Lands support. #226

wants to merge 3 commits into from

Conversation

vLuckyyy
Copy link
Member

@vLuckyyy vLuckyyy commented May 21, 2025

It's work well with the WorldGuard + Lands. (Two region provider at the same time.)
https://github.com/user-attachments/assets/d2521840-36e6-4395-bc4a-f8b306d3db79

Copy link

coderabbitai bot commented May 21, 2025

Walkthrough

This update adds support for the Lands plugin by introducing new classes and logic for region handling. It removes all PacketEvents references and related code. The build scripts are updated to include the LandsAPI as a dependency and adjust plugin dependencies. The region provider system is improved to support multiple providers at once, allowing both Lands and WorldGuard regions to be recognized together. Several new classes handle region detection and event listening for Lands. No changes were made to public APIs except for some constructor and method signature updates to support the new features.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19ac35a and e75404c.

📒 Files selected for processing (2)
  • eternalcombat-plugin/build.gradle.kts (2 hunks)
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandChunksRegion.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • eternalcombat-plugin/build.gradle.kts
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandChunksRegion.java
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (7)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsBridgeInitializer.java (2)

32-41: Add null check for Lands integration

Consider adding a null check for the Lands integration to handle cases where the Lands plugin might not be properly loaded.

@Override
public void initialize() {
    LandsIntegration lands = LandsIntegration.of(this.plugin);
+   if (lands == null) {
+       this.plugin.getLogger().warning("Failed to initialize Lands integration.");
+       return;
+   }
    this.regionProvider = new LandsRegionProvider(lands);
    this.eventManager.subscribe(new LandsRegionController(
        this.fightManager,
        this.noticeService,
        lands
    ));
}

43-45: Add null check for region provider

The getRegionProvider method should check if the provider is initialized before returning it.

public RegionProvider getRegionProvider() {
+   if (this.regionProvider == null) {
+       throw new IllegalStateException("Region provider not initialized. Call initialize() first.");
+   }
    return this.regionProvider;
}
eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsRegionProvider.java (1)

48-55: Consider using newer Java collections methods

The Collectors.toList() method is deprecated in newer Java versions. Consider using toList() or Collectors.toCollection(ArrayList::new) instead.

@Override
public Collection<Region> getRegions(World world) {
    return this.lands.getLands().stream()
        .map(land -> land.getContainer(world))
        .filter(container -> container != null && !container.getChunks().isEmpty())
        .map(container -> new LandChunksRegion(world, container.getChunks()))
-       .collect(Collectors.toList());
+       .toList();
}
eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/BridgeService.java (4)

51-63: Consider extracting plugin names

Repeating raw strings like "Lands" and "WorldGuard" can invite typos later. A small constant for each name would tidy this up.


78-81: Guard against an empty provider list early

If nothing is found, you fall back to DefaultRegionProvider, which is great.
For clarity, you could return right after adding the default to show there’s no need to continue.


83-88: Freeze the provider list before wrapping

CompositeRegionProvider receives the mutable providers. Locking it in prevents accidental edits later.

-        this.regionProvider = new CompositeRegionProvider(providers);
+        this.regionProvider = new CompositeRegionProvider(List.copyOf(providers));

97-104: Shorten the log message

The info log already states a bridge was initialised; adding the plugin name twice feels redundant. Trimming it keeps logs clean.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b87e640 and b1edd1a.

📒 Files selected for processing (9)
  • buildSrc/src/main/kotlin/eternalcombat-repositories.gradle.kts (1 hunks)
  • eternalcombat-plugin/build.gradle.kts (2 hunks)
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java (3 hunks)
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/BridgeService.java (1 hunks)
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandChunksRegion.java (1 hunks)
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsBridgeInitializer.java (1 hunks)
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsRegionController.java (1 hunks)
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsRegionProvider.java (1 hunks)
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/CompositeRegionProvider.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsRegionController.java (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/notification/NoticeService.java (1)
  • NoticeService (15-48)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsBridgeInitializer.java (2)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/event/EventManager.java (1)
  • EventManager (8-37)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/notification/NoticeService.java (1)
  • NoticeService (15-48)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/BridgeService.java (5)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsBridgeInitializer.java (1)
  • LandsBridgeInitializer (11-46)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/placeholder/FightTagPlaceholder.java (1)
  • FightTagPlaceholder (15-98)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/event/EventManager.java (1)
  • EventManager (8-37)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/notification/NoticeService.java (1)
  • NoticeService (15-48)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/CompositeRegionProvider.java (1)
  • CompositeRegionProvider (11-38)
🔇 Additional comments (15)
buildSrc/src/main/kotlin/eternalcombat-repositories.gradle.kts (1)

16-16: Good addition of JitPack repository.

Adding the JitPack repository is necessary for fetching the Lands API dependency. This is the correct approach.

eternalcombat-plugin/build.gradle.kts (3)

49-50: Correctly added Lands dependency.

The LandsAPI dependency has been properly added as compile-only, which is appropriate for a plugin integration.


55-55: Changed PacketEvents to compileOnly.

Good change to make PacketEvents a compileOnly dependency since it's now a hard dependency of the plugin.


66-71: Updated plugin dependencies correctly.

The changes to dependencies make sense:

  • Simplified soft dependencies to just include Lands
  • Added PacketEvents as a hard dependency

This matches the implementation changes in the code.

eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/CompositeRegionProvider.java (3)

11-18: Good implementation of composite pattern.

The CompositeRegionProvider is well designed to combine multiple region providers. The constructor properly accepts and stores the list of providers.


19-28: Efficient region lookup implementation.

The getRegion method returns the first match found, which is efficient and avoids unnecessary lookups.


30-37: Thorough implementation of getRegions method.

The getRegions method correctly collects all regions from all providers, ensuring no regions are missed.

eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandChunksRegion.java (3)

9-33: Well-implemented region conversion.

The LandChunksRegion class effectively converts Lands chunk coordinates into a region. The constructor correctly calculates the min/max coordinates by iterating through all chunks.

Note on line 31-32: The addition of 15 is correct as it accounts for the full width/length of the last chunk (each chunk is 16x16 blocks).


35-40: Simple and effective center calculation.

The getCenter method provides a reasonable center point at y-level 64, which works well for most situations.


42-50: Proper min/max location implementations.

Both getMin and getMax methods correctly return locations at the boundaries of the region, with appropriate y-levels (0 for min and world max height for max).

eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsRegionController.java (1)

31-61: The player movement event handler looks good!

The event handling logic is correctly implemented to prevent players in combat from entering different Lands regions.

eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java (2)

101-109: Good local variable changes!

The conversion from fields to local variables makes the code cleaner and follows better encapsulation practices.


123-133: Bridge service setup looks good

The updated BridgeService construction with additional parameters helps support the new Lands integration.

eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/lands/LandsRegionProvider.java (1)

25-46: Region retrieval logic looks good

The getRegion method properly handles null checks and empty collections before creating a region.

eternalcombat-plugin/src/main/java/com/eternalcode/combat/bridge/BridgeService.java (1)

27-30: Nice addition of fresh services

Bringing in EventManager, FightManager, and NoticeService keeps the class self-contained. Looks good.

@vLuckyyy vLuckyyy changed the title Add Lands support. GH-226 Add Lands support. May 22, 2025
Copy link
Contributor

@imDMK imDMK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@Rollczi Rollczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wydaje mi się, że tutaj trzeba się wgłębić w temat jak działają te landy. możliwe, że będzie trzeba trochę inaczej traktować te regiony jak są chunkami

import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;

public class LandsRegionController implements Listener {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To wszystko jest do wywalenia, jeśli wysyłasz wiadomości i robisz to co miał robić KnockbackController to raczej problem jest z providerem

import me.angeschossen.lands.api.LandsIntegration;
import org.bukkit.plugin.Plugin;

public class LandsBridgeInitializer implements BridgeInitializer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ta klasa też do wywalenia, wystarczy wszystko w lambda zrobić w BridgeService

int _minX = Integer.MAX_VALUE, _minZ = Integer.MAX_VALUE;
int _maxX = Integer.MIN_VALUE, _maxZ = Integer.MIN_VALUE;

for (ChunkCoordinate chunkCoordinate : chunks) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a to mamy gwarację, że region będzie kwadratowy/prostokątny skoro możemy zajmować chunki? bo nie jestem pewien czy tak zawsze będzie

import java.util.List;
import java.util.Optional;

public class CompositeRegionProvider implements RegionProvider {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fajne rozwiązanie podoba mi się

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.

4 participants