Search in sources :

Example 1 with RegionQuery

use of com.sk89q.worldguard.bukkit.RegionQuery in project Plot-System by AlpsBTE.

the class EventListener method onPlayerInteractEvent.

@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
        if (event.getItem() != null && event.getItem().equals(CompanionMenu.getMenuItem(event.getPlayer()))) {
            event.getPlayer().performCommand("companion");
        } else if (event.getItem() != null && event.getItem().equals(ReviewMenu.getMenuItem(event.getPlayer()))) {
            event.getPlayer().performCommand("review");
        }
    }
    // Open/Close iron trap door when right-clicking
    if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        if (event.getHand() != EquipmentSlot.OFF_HAND) {
            if (!event.getPlayer().isSneaking()) {
                if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.IRON_TRAPDOOR) {
                    RegionContainer regionContainer = PlotSystem.DependencyManager.getWorldGuard().getRegionContainer();
                    RegionQuery query = regionContainer.createQuery();
                    if (query.testBuild(event.getPlayer().getLocation(), PlotSystem.DependencyManager.getWorldGuard().wrapPlayer(event.getPlayer()), DefaultFlag.INTERACT)) {
                        BlockState state = event.getClickedBlock().getState();
                        TrapDoor tp = (TrapDoor) state.getData();
                        if (!tp.isOpen()) {
                            tp.setOpen(true);
                            event.getPlayer().playSound(event.getClickedBlock().getLocation(), "block.iron_trapdoor.open", 1f, 1f);
                        } else {
                            tp.setOpen(false);
                            event.getPlayer().playSound(event.getClickedBlock().getLocation(), "block.iron_trapdoor.close", 1f, 1f);
                        }
                        state.update();
                    }
                }
            }
        }
    }
}
Also used : TrapDoor(org.bukkit.material.TrapDoor) BlockState(org.bukkit.block.BlockState) RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) RegionQuery(com.sk89q.worldguard.bukkit.RegionQuery) EventHandler(org.bukkit.event.EventHandler)

Example 2 with RegionQuery

use of com.sk89q.worldguard.bukkit.RegionQuery in project Storage by D-x-Z.

the class BlockBreak method onBreaking.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBreaking(@NotNull BlockBreakEvent e) {
    Player p = e.getPlayer();
    String blocks = e.getBlock().getType().toString();
    String items = null;
    NMSAssistant nms = new NMSAssistant();
    LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(p);
    Location loc = new Location(p.getWorld(), e.getBlock().getLocation().getBlockX(), e.getBlock().getLocation().getBlockY(), e.getBlock().getLocation().getBlockZ());
    RegionContainer container = WorldGuardPlugin.inst().getRegionContainer();
    RegionQuery query = container.createQuery();
    if (!query.testState(loc, localPlayer, DefaultFlag.BLOCK_BREAK) && !p.hasPermission("Storage.admin")) {
        e.setCancelled(true);
        return;
    }
    e.getBlock().getDrops().clear();
    if (nms.isVersion(12)) {
        e.setDropItems(false);
    }
    List<String> w = getconfigfile().getStringList("Blacklist-World");
    if (!w.contains(p.getWorld().getName())) {
        if (autoPick(p)) {
            for (String getBlockType : Objects.requireNonNull(getconfigfile().getConfigurationSection("Blocks.")).getKeys(false)) {
                if (blocks.equalsIgnoreCase(getBlockType)) {
                    items = getconfigfile().getString("Blocks." + blocks + ".Name");
                    break;
                }
            }
            if (items == null) {
                return;
            }
            if (getMaxStorage(p, blocks) == 0) {
                setMaxStorage(p, blocks, getconfigfile().getInt("Default_Max_Storage"));
            }
            if (p.getItemInHand() != null && p.getItemInHand().getItemMeta().hasEnchant(Enchantment.LOOT_BONUS_BLOCKS)) {
                if (getRandomInt(getconfigfile().getInt("Fortune.Chance.System.Min"), getconfigfile().getInt("Fortune.Chance.System.Max")) <= (p.getItemInHand().getItemMeta().getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS) * getconfigfile().getInt("Fortune.Chance.Player"))) {
                    int fortune = getRandomInt(getconfigfile().getInt("Fortune.Drop.Min"), getconfigfile().getInt("Fortune.Drop.Max"));
                    addStorage(p, blocks, 1 + fortune);
                } else {
                    addStorage(p, blocks, 1);
                }
            } else {
                addStorage(p, blocks, 1);
            }
        }
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) RegionQuery(com.sk89q.worldguard.bukkit.RegionQuery) NMSAssistant(preponderous.ponder.minecraft.bukkit.nms.NMSAssistant) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with RegionQuery

use of com.sk89q.worldguard.bukkit.RegionQuery in project UltraCosmetics by iSach.

the class FlagManager method categoryFlagCheck.

@Override
protected Set<Category> categoryFlagCheck(Player bukkitPlayer) {
    RegionContainer rc = WGBukkit.getPlugin().getRegionContainer();
    RegionQuery query = rc.createQuery();
    return query.queryValue(bukkitPlayer.getLocation(), bukkitPlayer, CATEGORY_FLAG);
}
Also used : RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) RegionQuery(com.sk89q.worldguard.bukkit.RegionQuery)

Example 4 with RegionQuery

use of com.sk89q.worldguard.bukkit.RegionQuery in project UltraCosmetics by iSach.

the class FlagManager method flagCheck.

@Override
protected boolean flagCheck(StateFlag flag, Player bukkitPlayer) {
    RegionContainer rc = WGBukkit.getPlugin().getRegionContainer();
    RegionQuery query = rc.createQuery();
    return query.testState(bukkitPlayer.getLocation(), bukkitPlayer, flag);
}
Also used : RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) RegionQuery(com.sk89q.worldguard.bukkit.RegionQuery)

Aggregations

RegionContainer (com.sk89q.worldguard.bukkit.RegionContainer)4 RegionQuery (com.sk89q.worldguard.bukkit.RegionQuery)4 EventHandler (org.bukkit.event.EventHandler)2 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 Location (org.bukkit.Location)1 BlockState (org.bukkit.block.BlockState)1 Player (org.bukkit.entity.Player)1 TrapDoor (org.bukkit.material.TrapDoor)1 NMSAssistant (preponderous.ponder.minecraft.bukkit.nms.NMSAssistant)1