Java Code Examples for br.net.fabiozumbi12.RedProtect.Bukkit.Region#canTeleport()

The following examples show how to use br.net.fabiozumbi12.RedProtect.Bukkit.Region#canTeleport() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onConsume(PlayerItemConsumeEvent e) {
    if (e.getItem() == null) {
        return;
    }

    Player p = e.getPlayer();
    //deny potion
    if (p == null) {
        return;
    }

    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (r != null && e.getItem().getType().equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
        e.setCancelled(true);
    }
}
 
Example 2
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    Block b = event.getClickedBlock();
    ItemStack itemInHand = event.getItem();

    Location l;

    if (b != null) {
        l = b.getLocation();
        RedProtect.get().logger.debug(LogLevel.DEFAULT, "PlayerListener - Is PlayerInteractEvent event. The block is " + b.getType().name());
    } else {
        l = p.getLocation();
    }

    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }

    if (itemInHand != null && (event.getAction().name().equals("RIGHT_CLICK_BLOCK") || b == null)) {
        Material hand = itemInHand.getType();
        Region r = RedProtect.get().rm.getTopRegion(l);
        // Deny chorus teleport
        if (r != null && hand.equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            event.setCancelled(true);
            event.setUseItemInHand(Event.Result.DENY);
        }
        // Deny glide boost
        if (r == null && p.isGliding() && itemInHand.getType().name().contains("FIREWORK") && !p.hasPermission("redprotect.bypass.glide") &&
                !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_glide.allow_boost) {
            event.setUseItemInHand(Event.Result.DENY);
            event.setCancelled(true);
            RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantboost");
        }
    }
}
 
Example 3
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {

    final Player p = e.getPlayer();
    Location lfrom = e.getFrom();
    Location lto = e.getTo();

    if (e.getCause().equals(PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT)) {
        final Region rfrom = RedProtect.get().rm.getTopRegion(lfrom);
        final Region rto = RedProtect.get().rm.getTopRegion(lto);

        if (rfrom != null && !rfrom.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            e.setCancelled(true);
        }
        if (rto != null && !rto.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            e.setCancelled(true);
        }
    }

    if (p.getInventory().getChestplate() != null &&
            p.getInventory().getChestplate().getType().equals(Material.ELYTRA) &&
            !RedProtect.get().config.globalFlagsRoot().worlds.get(lto.getWorld().getName()).player_glide.allow_elytra) {
        RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantworld");
        e.setCancelled(true);
    }
}