blazecraftyt

make me a 26.3 plugin vip erea to make a vip erea select it with command /vip wand and select the gate/door of vip and the building when your vip rank with luckperms you can go threw gate without a problem but if not vip rank you can't go threw gate and it say in chat your rank is not hig enought to go.

Kodari AI
KodariNov 3 at 6:51 pm 4
VIPAreaProtection
VIPAreaProtection is a Minecraft plugin that creates restricted VIP zones. Players with the /vip wand command select two corners of a building and the gate/door location. Using LuckPerms, the plugin checks if a player has the vip rank. VIP members can pass through the gate freely, while non-VIP players are blocked with a chat message stating their rank is not high enough to enter. The plugin provides visual selection feedback and persistent configuration storage.
  • Select the building’s opposite corners with the VIP wand, then save the area.

  • Select its door or gate separately; LuckPerms’ vip group grants access.

Created the VIP area plugin. It requires LuckPerms and checks membership in the vip group.

  1. Use /vip wand, then left- and right-click opposite corners of the building.

  2. Use /vip save.

  3. Use /vip gate, then click the door or fence gate.

Non-VIP players are blocked from entering and receive a chat message. /vip remove removes the area and gate. Administrators can bypass the restriction with viparea.bypass.

blazecraftyt

its not working when im not vip and open gates it doesn't say you don't have required role or anything

Kodari AI
KodariNov 3 at 7:05 pm 1

The generation was stopped before any content could be produced.

blazecraftyt

ts not working when im not vip and open gates it doesn't say you don't have required role or anything

and i can open gate

Kodari AI
KodariNov 3 at 7:07 pm 2
  • Check LuckPerms group membership directly rather than relying on Bukkit’s group.vip permission.

  • Deny gate interaction for either hand and send the player a message.

Updated the gate check to use LuckPerms group membership and block interaction with either hand.

Operators have viparea.bypass by default, so test with a non-op account that isn’t in the VIP group. Make sure the gate is selected with /vip gate.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 248
src/main/java/com/kodari/viparea/VipAreaPlugin.java
package com.kodari.viparea;

import com.cryptomorin.xseries.XMaterial;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.user.User;
import net.luckperms.api.platform.PlayerAdapter;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.type.Door;
import org.bukkit.block.data.type.Gate;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.Event;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

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

public final class VipAreaPlugin extends JavaPlugin implements Listener {
    private final Map<UUID, Location[]> selections = new HashMap<>();
    private final Set<UUID> selectingGate = new HashSet<>();
    private final Map<UUID, Long> lastMessage = new HashMap<>();
    private NamespacedKey wandKey;

    @Override
    public void onEnable() {
        wandKey = new NamespacedKey(this, "wand");
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("Only players can set up a VIP area.");
            return true;
        }
        if (!player.hasPermission("viparea.admin")) {
            player.sendMessage(ChatColor.RED + "You cannot manage VIP areas.");
            return true;
        }
        if (args.length != 1) {
            player.sendMessage(ChatColor.YELLOW + "/vip wand, /vip save, /vip gate, /vip remove");
            return true;
        }
        switch (args[0].toLowerCase(java.util.Locale.ROOT)) {
            case "wand" -> {
                ItemStack wand = XMaterial.matchXMaterial("BLAZE_ROD").map(XMaterial::parseItem).orElse(null);
                if (wand == null) {
                    player.sendMessage(ChatColor.RED + "Unable to create the wand on this server.");
                    return true;
                }
                ItemMeta meta = wand.getItemMeta();
                meta.setDisplayName(ChatColor.GOLD + "VIP Area Wand");
                meta.getPersistentDataContainer().set(wandKey, PersistentDataType.BYTE, (byte) 1);
                wand.setItemMeta(meta);
                Map<Integer, ItemStack> leftovers = player.getInventory().addItem(wand);
                leftovers.values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
                player.sendMessage(ChatColor.YELLOW + "Left-click and right-click opposite building corners, then use /vip save.");
            }
            case "save" -> {
                Location[] points = selections.get(player.getUniqueId());
                if (points == null || points[0] == null || points[1] == null || !points[0].getWorld().equals(points[1].getWorld())) {
                    player.sendMessage(ChatColor.RED + "Select both corners in the same world first.");
                    return true;
                }
                getConfig().set("area.world", points[0].getWorld().getUID().toString());
                for (int i = 0; i < 2; i++) {
                    String path = "area.pos" + (i + 1) + ".";
                    getConfig().set(path + "x", points[i].getBlockX());
                    getConfig().set(path + "y", points[i].getBlockY());
                    getConfig().set(path + "z", points[i].getBlockZ());
                }
                saveConfig();
                player.sendMessage(ChatColor.GREEN + "VIP area saved. Use /vip gate, then click the door or gate.");
            }
            case "gate" -> {
                selectingGate.add(player.getUniqueId());
                player.sendMessage(ChatColor.YELLOW + "Click the VIP door or fence gate to select it.");
            }
            case "remove" -> {
                getConfig().set("area", null);
                getConfig().set("gate", null);
                saveConfig();
                player.sendMessage(ChatColor.GREEN + "VIP area and gate removed.");
            }
            default -> player.sendMessage(ChatColor.YELLOW + "/vip wand, /vip save, /vip gate, /vip remove");
        }
        return true;
    }

    @EventHandler(priority = EventPriority.HIGH)
    public void onInteract(PlayerInteractEvent event) {
        if (event.getClickedBlock() == null) return;
        Player player = event.getPlayer();
        Block block = event.getClickedBlock();
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK && isGate(block) && !canEnter(player)) {
            event.setCancelled(true);
            event.setUseInteractedBlock(Event.Result.DENY);
            deny(player);
            return;
        }
        if (event.getHand() != EquipmentSlot.HAND) return;
        if (selectingGate.contains(player.getUniqueId()) && player.hasPermission("viparea.admin")) {
            event.setCancelled(true);
            if (!(block.getBlockData() instanceof Door) && !(block.getBlockData() instanceof Gate)) {
                player.sendMessage(ChatColor.RED + "Select a door or fence gate.");
                return;
            }
            if (block.getBlockData() instanceof Door door && door.getHalf() == Bisected.Half.TOP) block = block.getRelative(BlockFace.DOWN);
            getConfig().set("gate.world", block.getWorld().getUID().toString());
            getConfig().set("gate.x", block.getX());
            getConfig().set("gate.y", block.getY());
            getConfig().set("gate.z", block.getZ());
            saveConfig();
            selectingGate.remove(player.getUniqueId());
            player.sendMessage(ChatColor.GREEN + "VIP gate saved.");
            return;
        }
        ItemStack item = event.getItem();
        if (player.hasPermission("viparea.admin") && item != null && item.hasItemMeta()
                && item.getItemMeta().getPersistentDataContainer().has(wandKey, PersistentDataType.BYTE)) {
            int index = event.getAction() == Action.LEFT_CLICK_BLOCK ? 0 : event.getAction() == Action.RIGHT_CLICK_BLOCK ? 1 : -1;
            if (index >= 0) {
                event.setCancelled(true);
                selections.computeIfAbsent(player.getUniqueId(), ignored -> new Location[2])[index] = block.getLocation();
                player.sendMessage(ChatColor.GREEN + "Corner " + (index + 1) + " selected: " + block.getX() + ", " + block.getY() + ", " + block.getZ());
            }
            return;
        }
    }

    private boolean isGate(Block block) {
        if (block.getBlockData() instanceof Door door && door.getHalf() == Bisected.Half.TOP) block = block.getRelative(BlockFace.DOWN);
        return getConfig().isString("gate.world")
                && block.getWorld().getUID().toString().equals(getConfig().getString("gate.world"))
                && block.getX() == getConfig().getInt("gate.x")
                && block.getY() == getConfig().getInt("gate.y")
                && block.getZ() == getConfig().getInt("gate.z");
    }

    private boolean canEnter(Player player) {
        if (player.hasPermission("viparea.bypass")) return true;
        PlayerAdapter<Player> adapter = LuckPermsProvider.get().getPlayerAdapter(Player.class);
        User user = adapter.getUser(player);
        return user.getInheritedGroups(adapter.getQueryOptions(player)).stream()
                .anyMatch(group -> group.getName().equalsIgnoreCase("vip"));
    }

    private boolean inArea(Location location) {
        if (location == null || location.getWorld() == null || !getConfig().isString("area.world")
                || !location.getWorld().getUID().toString().equals(getConfig().getString("area.world"))) return false;
        int x1 = getConfig().getInt("area.pos1.x"), x2 = getConfig().getInt("area.pos2.x");
        int y1 = getConfig().getInt("area.pos1.y"), y2 = getConfig().getInt("area.pos2.y");
        int z1 = getConfig().getInt("area.pos1.z"), z2 = getConfig().getInt("area.pos2.z");
        return location.getBlockX() >= Math.min(x1, x2) && location.getBlockX() <= Math.max(x1, x2)
                && location.getBlockY() >= Math.min(y1, y2) && location.getBlockY() <= Math.max(y1, y2)
                && location.getBlockZ() >= Math.min(z1, z2) && location.getBlockZ() <= Math.max(z1, z2);
    }

    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    public void onMove(PlayerMoveEvent event) {
        if (event instanceof PlayerTeleportEvent || event.getTo() == null || canEnter(event.getPlayer())) return;
        if (!inArea(event.getFrom()) && inArea(event.getTo())) {
            event.setCancelled(true);
            deny(event.getPlayer());
        }
    }

    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    public void onTeleport(PlayerTeleportEvent event) {
        if (!canEnter(event.getPlayer()) && !inArea(event.getFrom()) && inArea(event.getTo())) {
            event.setCancelled(true);
            deny(event.getPlayer());
        }
    }

    private void deny(Player player) {
        long now = System.currentTimeMillis();
        if (now - lastMessage.getOrDefault(player.getUniqueId(), 0L) >= 1500) {
            player.sendMessage(ChatColor.RED + "Your rank is not high enough to go here.");