Skip to content

Latest commit

 

History

History
263 lines (189 loc) · 9.2 KB

CONTRIBUTING.md

File metadata and controls

263 lines (189 loc) · 9.2 KB

Contributing to WorldGuardExtraFlagsPlus

Thank you for considering contributing! This document outlines the project structure, patterns, and guidelines to help you submit clean, mergeable PRs.


Project Structure

The project has two Maven modules:

WG/          — WorldGuard / WorldEdit integration (flag declarations, session handlers)
Paper/      — Bukkit server module (config, listeners, plugin lifecycle)
  • Flag declarations go in WG/src/main/java/dev/tins/worldguardextraflagsplus/flags/Flags.java
  • Custom flag types go in WG/src/main/java/dev/tins/worldguardextraflagsplus/flags/helpers/
  • Session handlers go in WG/src/main/java/dev/tins/worldguardextraflagsplus/wg/handlers/
  • Bukkit event listeners go in Paper/src/main/java/dev/tins/worldguardextraflagsplus/listeners/
  • Config is managed via ConfigLib: PluginConfig.java + Config.java
  • Plugin lifecycle (flag registration, listener registration) is in WorldGuardExtraFlagsPlusPlugin.java

How to Add a New Flag

Follow this checklist in order:

1. Declare the flag in Flags.java

Pick the correct type:

Type When to use Example
StateFlag On/off per region (allow / deny) GODMODE, FLY, FROSTWALKER
BooleanFlag True/false per region KEEP_INVENTORY, DISABLE_COLLISION
StringFlag Free-form text value CHAT_PREFIX, CHAT_SUFFIX
SetFlag<...> List of values per region ALLOW_BLOCK_BREAK, DISABLE_COMPLETELY
DoubleFlag Decimal number WALK_SPEED, FLY_SPEED
IntegerFlag Whole number PLAYER_COUNT_LIMIT
LocationFlag World coordinate TELEPORT_ON_ENTRY, JOIN_LOCATION

Example:

public final static StateFlag YOUR_FLAG = new StateFlag("your-flag", true);

The second argument is the default state (true = allow / false = deny).

2. (If needed) Create a custom flag type

If your flag needs special validation or serialization, create a new class in flags/helpers/ extending the appropriate base type (e.g., BlockableItemFlag, ThrowableItemFlag, MaterialFlag).

3. Add a config toggle in PluginConfig.java

In the AllFlagsControl inner class, add a new private boolean field with an optional @Comment:

@Comment({
    "your-flag flag",
    "Description of what it does.",
    "Usage: /rg flag your-flag deny",
    "Default: true"
})
private boolean yourFlag = true;

4. Add a switch case in Config.java

In the isFlagEnabled() method:

case "your-flag": return flags.isYourFlag();

The method name is automatically generated by Lombok's @Getter from the field name (converting camelCase to is-prefixed).

5. Register the flag in onLoad()

In WorldGuardExtraFlagsPlusPlugin.java, inside the try-block:

if (Config.isFlagEnabled("your-flag")) flagRegistry.register(Flags.YOUR_FLAG);

6. (If needed) Create a session handler

If your flag requires per-player session tracking (e.g., fly, godmode, effects), create a handler in wg/handlers/ extending the appropriate base class and register it in onEnable():

if (Config.isFlagEnabled("your-flag"))
    this.sessionManager.registerHandler(YourFlagHandler.FACTORY, null);

7. (If needed) Create a Bukkit listener

If your flag responds to Bukkit events, create a listener class implementing Listener:

package dev.tins.worldguardextraflagsplus.listeners;

import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.session.SessionManager;
import dev.tins.worldguardextraflagsplus.flags.Flags;
import dev.tins.worldguardextraflagsplus.wg.WorldGuardUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;

public class YourFlagListener implements Listener
{
    private final WorldGuardPlugin worldGuardPlugin;
    private final RegionContainer regionContainer;
    private final SessionManager sessionManager;

    public YourFlagListener(WorldGuardPlugin worldGuardPlugin,
                            RegionContainer regionContainer,
                            SessionManager sessionManager)
    {
        this.worldGuardPlugin = worldGuardPlugin;
        this.regionContainer = regionContainer;
        this.sessionManager = sessionManager;
    }

    @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
    public void onEvent(EntityDamageEvent event)
    {
        if (!(event.getEntity() instanceof Player player))
            return;

        LocalPlayer localPlayer = this.worldGuardPlugin.wrapPlayer(player);

        // Folia/Canvas + FAWE: never use localPlayer.getWorld() on the event thread (blocks via FAWE).
        if (WorldGuardUtils.hasBypass(this.sessionManager, localPlayer, player))
            return;

        State state = this.regionContainer.createQuery().queryState(
                BukkitAdapter.adapt(player.getLocation()),
                localPlayer,
                Flags.YOUR_FLAG);

        if (state == State.DENY)
            event.setCancelled(true);
    }
}

8. Register the listener in onEnable()

if (Config.isFlagEnabled("your-flag"))
{
    this.getServer().getPluginManager().registerEvents(
            new YourFlagListener(
                    this.worldGuardPlugin, this.regionContainer, this.sessionManager), this);
}

Use the short class name — the wildcard import dev.tins.worldguardextraflagsplus.listeners.* is already at the top of the file.

9. Add metadata to FlagDescriptions

Every flag must have a human-readable entry in Paper/src/main/java/dev/tins/worldguardextraflagsplus/api/FlagDescriptions.java. Add a line in the static initialiser block:

ALL.put("your-flag", new FlagMeta(
    "Short description of what the flag does.",
    "Accepted value types (e.g. allow/deny, true/false, material names)",
    "/rg flag <region> your-flag example-value"));

This metadata is used by the plugin's own commands and by external GUI plugins (e.g. WG-GUI) to display flag tooltips.


Folia Compatibility

This plugin supports Folia. Follow these rules:

  • DO NOT use Bukkit.getScheduler(), BukkitRunnable, or any deprecated Bukkit scheduling API
  • Use WorldGuardUtils.getScheduler() for all scheduling needs
  • Entity-specific code must run on the entity's owning thread (safe inside Bukkit event handlers)
  • Do not perform cross-world chunk loading or world operations outside proper scheduling
  • Use runNextTick() and runAtLocation() from the FoliaLib scheduler

Code Style

  • Indentation: tabs (not spaces)
  • Opening brace on the same line for class/method signatures, next line for control flow
  • @Override on separate line above method signature
  • No trailing whitespace
  • Use final fields where possible in listener/handler classes

PR Guidelines

  • One commit per feature or fix. Squash your changes before opening the PR.

  • Target the correct branch:

    • master — stable features and fixes ready for release
    • dev-point — experimental or in-progress work
  • Commit messages: Write descriptive commit messages explaining the why:

    feat: add lightning-damage region flag
    
    New StateFlag that allows lightning strikes to appear visually
    in a region while preventing damage to players. Useful for PvP
    arenas wanting the visual effect without environmental damage.
    
    Usage: /rg flag <region> lightning-damage deny
    
  • No personal attributions, watermarks, or trademarks in new files. Clean code only.

  • Test that it compiles before submitting:

    mvn clean package -DskipTests
  • If the PR touches multiple unrelated features, split into separate PRs.

Maintainer-owned (do not change in contributor PRs)

  • Version numbers — Do not bump version in pom.xml, plugin.yml, or README release lines. Maintainers set versions when cutting a release.
  • GitHub release text — Do not edit published release notes or maintainer-only drafts in .local-docs/. Describe the change in the PR title and body instead.
  • README — Keep the in-repo README as a short overview; link to the tinsware Wiki for detailed flag docs unless a maintainer asks for a README update.
  • Branding / startup art — Do not add or change plugin logo or console branding in feature PRs.

Maintainers may cherry-pick or re-implement accepted ideas on their own timeline and credit contributors in release notes.


Building

mvn clean package

The output jar will be in Paper/target/worldguard-extraflagsplus-{version}.jar.

Dependencies

Dependency Required Notes
WorldGuard Yes
WorldEdit Yes
PacketEvents No (optional) Disable-completely spear Lunge protection
ProtocolLib No (optional) Fallback for PacketEvents

Getting Help

  • Open an issue on GitHub for bugs or feature requests
  • Join our Discord for questions