anshu_here07

make a plugin by which if we select a perticular region it give minecraft:water_breathing unlimted when we out from region it disable the effect this effects when we write //sticks permission needed by stick we select a perticular region and we write /night it allow nightvision no perms needed and unlimted everyone

Kodari AI
KodariNov 1 at 6:09 am 1
RegionEffects
RegionEffects is a Minecraft plugin that grants unlimited water breathing and night vision effects based on player location. Using a stick item, players with the required permission can select a region via WorldEdit-style selection. When inside the selected region, players receive infinite water breathing. Leaving the region removes the effect. Additionally, any player can use the /night command to gain unlimited night vision regardless of permissions. The plugin continuously monitors player positions, applies or removes effects dynamically, and supports multiple regions. It integrates with WorldEdit for region selection and provides seamless effect management for enhanced gameplay.
  1. Create a Paper-compatible plugin scaffold and persist one selected region.

  2. Add permission-gated stick selection and automatic water breathing inside the region.

  3. Add /night as a permission-free, player-toggleable unlimited night-vision effect.

Created the RegionBreath plugin. Players with regionbreath.select use /sticks, then left-click and right-click blocks to set the region; players inside receive continuous water breathing, removed when they leave. /night toggles continuous night vision for any player without a permission requirement. The selected region is saved across restarts.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 263
src/main/java/com/kodari/regionbreath/RegionBreathPlugin.java
package com.kodari.regionbreath;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.scheduler.BukkitTask;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class RegionBreathPlugin extends JavaPlugin implements Listener {
    private final Map<UUID, Location> firstCorners = new HashMap<>();
    private final Map<UUID, Location> secondCorners = new HashMap<>();
    private final Set<UUID> nightVisionEnabled = new HashSet<>();
    private final Set<UUID> managedWaterBreathing = new HashSet<>();
    private final Set<UUID> managedNightVision = new HashSet<>();
    private String regionWorld;
    private int minX;
    private int minY;
    private int minZ;
    private int maxX;
    private int maxY;
    private int maxZ;
    private BukkitTask effectTask;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadRegion();
        getServer().getPluginManager().registerEvents(this, this);
        effectTask = getServer().getScheduler().runTaskTimer(this, this::updateEffects, 0L, 20L);
    }

    @Override
    public void onDisable() {
        if (effectTask != null) {
            effectTask.cancel();
        }
        for (Player player : getServer().getOnlinePlayers()) {
            removeManagedEffect(player, "WATER_BREATHING", managedWaterBreathing);
            removeManagedEffect(player, "NIGHT_VISION", managedNightVision);
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("sticks")) {
            if (!(sender instanceof Player player)) {
                sender.sendMessage(ChatColor.RED + "Only players can use this command.");
                return true;
            }
            if (!player.hasPermission("regionbreath.select")) {
                player.sendMessage(ChatColor.RED + "You do not have permission to select the region.");
                return true;
            }
            ItemStack wand = XMaterial.matchXMaterial("STICK").map(XMaterial::parseItem).orElse(null);
            if (wand == null) {
                player.sendMessage(ChatColor.RED + "Could not create the selection stick.");
                return true;
            }
            ItemMeta meta = wand.getItemMeta();
            if (meta != null) {
                meta.setDisplayName(ChatColor.AQUA + "Region Selection Stick");
                wand.setItemMeta(meta);
            }
            player.getInventory().addItem(wand);
            player.sendMessage(ChatColor.GREEN + "Left-click a block for corner 1 and right-click for corner 2.");
            return true;
        }

        if (command.getName().equalsIgnoreCase("night")) {
            if (!(sender instanceof Player player)) {
                sender.sendMessage(ChatColor.RED + "Only players can use this command.");
                return true;
            }
            UUID playerId = player.getUniqueId();
            if (nightVisionEnabled.remove(playerId)) {
                removeManagedEffect(player, "NIGHT_VISION", managedNightVision);
                player.sendMessage(ChatColor.YELLOW + "Night vision disabled.");
            } else {
                nightVisionEnabled.add(playerId);
                player.sendMessage(ChatColor.GREEN + "Night vision enabled.");
                applyManagedEffect(player, "NIGHT_VISION", managedNightVision);
            }
            return true;
        }
        return false;
    }

    @EventHandler
    public void onSelectionStickUse(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        if (!player.hasPermission("regionbreath.select") || event.getItem() == null
                || !event.getItem().getType().name().equals("STICK")) {
            return;
        }
        Action action = event.getAction();
        if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK) {
            return;
        }
        if (event.getClickedBlock() == null) {
            return;
        }

        Location selected = event.getClickedBlock().getLocation();
        UUID playerId = player.getUniqueId();
        if (action == Action.LEFT_CLICK_BLOCK) {
            firstCorners.put(playerId, selected);
            player.sendMessage(ChatColor.GREEN + "First region corner selected.");
        } else {
            secondCorners.put(playerId, selected);
            player.sendMessage(ChatColor.GREEN + "Second region corner selected.");
        }

        Location first = firstCorners.get(playerId);
        Location second = secondCorners.get(playerId);
        if (first == null || second == null) {
            return;
        }
        if (!first.getWorld().equals(second.getWorld())) {
            player.sendMessage(ChatColor.RED + "Both corners must be in the same world.");
            return;
        }
        saveRegion(first, second);
        player.sendMessage(ChatColor.GREEN + "Water-breathing region saved.");
    }

    private void loadRegion() {
        regionWorld = getConfig().getString("region.world", "");
        minX = getConfig().getInt("region.min.x");
        minY = getConfig().getInt("region.min.y");
        minZ = getConfig().getInt("region.min.z");
        maxX = getConfig().getInt("region.max.x");
        maxY = getConfig().getInt("region.max.y");
        maxZ = getConfig().getInt("region.max.z");
    }

    private void saveRegion(Location first, Location second) {
        World world = first.getWorld();
        regionWorld = world.getName();
        minX = Math.min(first.getBlockX(), second.getBlockX());
        minY = Math.min(first.getBlockY(), second.getBlockY());
        minZ = Math.min(first.getBlockZ(), second.getBlockZ());
        maxX = Math.max(first.getBlockX(), second.getBlockX());
        maxY = Math.max(first.getBlockY(), second.getBlockY());
        maxZ = Math.max(first.getBlockZ(), second.getBlockZ());
        getConfig().set("region.world", regionWorld);
        getConfig().set("region.min.x", minX);
        getConfig().set("region.min.y", minY);
        getConfig().set("region.min.z", minZ);
        getConfig().set("region.max.x", maxX);
        getConfig().set("region.max.y", maxY);
        getConfig().set("region.max.z", maxZ);
        saveConfig();
    }

    private void updateEffects() {
        for (Player player : getServer().getOnlinePlayers()) {
            if (isInsideRegion(player.getLocation())) {
                applyManagedEffect(player, "WATER_BREATHING", managedWaterBreathing);
            } else {
                removeManagedEffect(player, "WATER_BREATHING", managedWaterBreathing);
            }

            if (nightVisionEnabled.contains(player.getUniqueId())) {
                applyManagedEffect(player, "NIGHT_VISION", managedNightVision);
            }
        }
    }

    private boolean isInsideRegion(Location location) {
        return regionWorld != null && !regionWorld.isEmpty()
                && location.getWorld().getName().equals(regionWorld)
                && location.getBlockX() >= minX && location.getBlockX() <= maxX
                && location.getBlockY() >= minY && location.getBlockY() <= maxY
                && location.getBlockZ() >= minZ && location.getBlockZ() <= maxZ;
    }

    private void applyManagedEffect(Player player, String potionName, Set<UUID> managedPlayers) {
        XPotion.matchXPotion(potionName).map(potion -> potion.buildPotionEffect(80, 0)).ifPresent(effect -> {
            UUID playerId = player.getUniqueId();
            if (managedPlayers.contains(playerId)) {
                player.addPotionEffect(effect, true);
            } else if (!player.hasPotionEffect(effect.getType())) {