P

Make a plugin with worldguard intergreation so basicly when a player throws a potion or enderpearl in a worldguard region selected in config.yml it doesnt let the player throw it cancels thro event also when shooting bows or crossbows + FULL FOLIA SUPPORT!!

Kodari AI
KodariFeb 28 at 11:08 am 7,786 (v2)

I’ll create a WorldGuard integration plugin that blocks projectiles in specific regions with full Folia support.

RegionProjectileBlocker
A WorldGuard integration plugin that prevents players from throwing potions, enderpearls, and shooting bows/crossbows in configured regions. Features region-based restrictions, customizable messages, and full Folia support through FoliaLib. Administrators can specify which WorldGuard regions should block projectiles via the config file.

Now I’ll create the plugin structure:

Plugin created successfully!

Features implemented:

  • ✅ Blocks potions, enderpearls, bows, and crossbows in configured WorldGuard regions

  • ✅ Full Folia support using FoliaLib for all player interactions

  • ✅ Configurable region list in config.yml

  • ✅ Customizable messages for each projectile type

  • ✅ Bypass permission (regionprojectile.bypass)

  • ✅ Reload command (/rpb reload)

  • ✅ Debug mode for testing

The plugin uses entity-safe scheduling for all player message sending, ensuring full Folia compatibility. Events are cancelled before the projectile/arrow launches, preventing any items from being thrown or shot in protected regions.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
Code
7 287
src/main/java/com/regionprojectile/RegionProjectileBlocker.java
package com.regionprojectile;

import com.regionprojectile.listeners.ProjectileListener;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.tcoded.folialib.FoliaLib;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.List;

@Getter
public class RegionProjectileBlocker extends JavaPlugin {

    private FoliaLib foliaLib;
    private WorldGuardPlugin worldGuard;
    private List<String> protectedRegions;
    private String potionMessage;
    private String enderpearlMessage;
    private String bowMessage;
    private boolean debug;

    @Override
    public void onEnable() {
        foliaLib = new FoliaLib(this);
        
        if (!setupWorldGuard()) {
            getLogger().severe("WorldGuard not found! Disabling plugin.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        saveDefaultConfig();
        loadConfiguration();

        getServer().getPluginManager().registerEvents(new ProjectileListener(this), this);
        
        if (getCommand("regionprojectile") != null) {
            getCommand("regionprojectile").setExecutor(new ReloadCommand(this));
        }

        getLogger().info("RegionProjectileBlocker enabled with " + protectedRegions.size() + " protected regions!");
    }

    @Override
    public void onDisable() {
        if (foliaLib != null) {
            foliaLib.getScheduler().cancelAllTasks();
        }
        getLogger().info("RegionProjectileBlocker disabled!");
    }

    private boolean setupWorldGuard() {
        var plugin = getServer().getPluginManager().getPlugin("WorldGuard");
        if (plugin instanceof WorldGuardPlugin wg) {
            worldGuard = wg;
            return true;
        }
        return false;
    }

    public void loadConfiguration() {
        reloadConfig();
        protectedRegions = getConfig().getStringList("protected-regions");
        potionMessage = colorize(getConfig().getString("messages.potions-blocked", "&cYou cannot throw potions in this region!"));
        enderpearlMessage = colorize(getConfig().getString("messages.enderpearl-blocked", "&cYou cannot throw enderpearls in this region!"));
        bowMessage = colorize(getConfig().getString("messages.bow-blocked", "&cYou cannot shoot bows or crossbows in this region!"));
        debug = getConfig().getBoolean("debug", false);
    }

    private String colorize(String message) {
        return message.replace('&', '§');
    }

    public void debugLog(String message) {
        if (debug) {
            getLogger().info("[DEBUG] " + message);
        }
    }
}