org.spongepowered.api.event.block.InteractBlockEvent Java Examples

The following examples show how to use org.spongepowered.api.event.block.InteractBlockEvent. 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: PlayerInteractListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockInteract(final InteractBlockEvent event, @Root final Player player)
{
    //If AIR or NONE then return
    if (event.getTargetBlock() == BlockSnapshot.NONE || event.getTargetBlock().getState().getType() == BlockTypes.AIR)
        return;

    final Optional<Location<World>> optionalLocation = event.getTargetBlock().getLocation();
    if (!optionalLocation.isPresent())
        return;

    final Location<World> blockLocation = optionalLocation.get();

    final ProtectionResult protectionResult = super.getPlugin().getProtectionManager().canInteractWithBlock(blockLocation, player, true);
    if (!protectionResult.hasAccess())
    {
        event.setCancelled(true);
        return;
    }
    else
    {
        if(event instanceof InteractBlockEvent.Secondary && protectionResult.isEagleFeather())
            removeEagleFeather(player);
    }
}
 
Example #2
Source File: InteractPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onInteract(InteractBlockEvent event, @First Player player)
{
	if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	if (player.hasPermission("nations.admin.bypass.perm.interact"))
	{
		return;
	}
	Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);
	if (optItem.isPresent() && (ConfigHandler.isWhitelisted("use", optItem.get().getItem().getId()) || optItem.get().getItem().equals(ItemTypes.GOLDEN_AXE) && ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true)))
		return;
	event.getTargetBlock().getLocation().ifPresent(loc -> {
		if (!DataHandler.getPerm("interact", player.getUniqueId(), loc))
		{
			event.setCancelled(true);
			if (loc.getBlockType() != BlockTypes.STANDING_SIGN && loc.getBlockType() != BlockTypes.WALL_SIGN)
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_INTERACT));
		}
	});
}
 
Example #3
Source File: BlockprotectionListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onInteractSecondary(InteractBlockEvent.Secondary event, @First Player p) {
    ModuleConfig config = Modules.BLOCKPROTECTION.get().getConfig().get();
    if (!config.get().getNode("protections", "allow-interact-secondary").getBoolean()) return;
    if (!event.getTargetBlock().getLocation().isPresent()) return;

    for (Protection prot : GlobalData.get(BlockprotectionKeys.PROTECTIONS).get()) {
        if (prot.getPlayers().contains(p.getUniqueId())) continue;
        if (!prot.getLocations().contains(event.getTargetBlock().getLocation().get())) continue;

        //Check if it should be cancelled
        if (prot.getLocktype().shouldBeCancelled()) {
            event.setCancelled(true);
            p.sendMessage(prot.getLocktype().getErrorMessage(p, prot));
        }
    }
}
 
Example #4
Source File: BlockprotectionListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onInteractPrimary(InteractBlockEvent.Primary event, @First Player p) {
    ModuleConfig config = Modules.BLOCKPROTECTION.get().getConfig().get();
    if (!config.get().getNode("protections", "allow-interact-primary").getBoolean()) return;
    if (!event.getTargetBlock().getLocation().isPresent()) return;

    for (Protection prot : GlobalData.get(BlockprotectionKeys.PROTECTIONS).get()) {
        if (prot.getPlayers().contains(p.getUniqueId())) continue;
        if (!prot.getLocations().contains(event.getTargetBlock().getLocation().get())) continue;

        //Check if it should be cancelled
        if (prot.getLocktype().shouldBeCancelled()) {
            event.setCancelled(true);
            p.sendMessage(prot.getLocktype().getErrorMessage(p, prot));
        }
    }
}
 
Example #5
Source File: SignListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onSignClick(InteractBlockEvent.Secondary event, @Root Player p) {
    if (!event.getTargetBlock().getLocation().isPresent() || !event.getTargetBlock().getLocation().get().getTileEntity().isPresent()) {
        return;
    }
    if (!(event.getTargetBlock().getLocation().get().getTileEntity().get() instanceof Sign)) {
        return;
    }
    Sign sign = (Sign) event.getTargetBlock().getLocation().get().getTileEntity().get();
    for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) {
        if (sign.getSignData().get(0).orElse(Text.of()).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) {
            if (!p.hasPermission(usign.getUsePermission().get())) {
                Messages.send(p, "core.nopermissions");
            }
            SignUseEvent cevent = new SignUseEvent(usign, sign.getLocation(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build()));
            Sponge.getEventManager().post(cevent);
            if (!cevent.isCancelled()) {
                usign.onExecute(p, sign);
            }
        }
    }
}
 
Example #6
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    Location<World> l;

    RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event");

    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName());
    } else {
        l = p.getLocation();
    }

    Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());
    if (r != null) {
        ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p);
        if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
            event.setCancelled(true);
        }
    }
}
 
Example #7
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
private void handleFakePlayerInteractBlockPrimary(InteractBlockEvent event, User user, Object source) {
    final BlockSnapshot clickedBlock = event.getTargetBlock();
    final Location<World> location = clickedBlock.getLocation().orElse(null);
    final GDClaim claim = this.dataStore.getClaimAt(location);
    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_BLOCK_PRIMARY, source, event.getTargetBlock(), user, TrustTypes.BUILDER, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
    }
}
 
Example #8
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
private void handleFakePlayerInteractBlockSecondary(InteractBlockEvent event, User user, Object source) {
    final BlockSnapshot clickedBlock = event.getTargetBlock();
    final Location<World> location = clickedBlock.getLocation().orElse(null);
    final GDClaim claim = this.dataStore.getClaimAt(location);
    final TileEntity tileEntity = clickedBlock.getLocation().get().getTileEntity().orElse(null);
    final TrustType trustType = (tileEntity != null && NMSUtil.getInstance().containsInventory(tileEntity)) ? TrustTypes.CONTAINER : TrustTypes.ACCESSOR;
    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_BLOCK_SECONDARY, source, event.getTargetBlock(), user, trustType, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
    }
}
 
Example #9
Source File: GoldenAxeListener.java    From Nations with MIT License 5 votes vote down vote up
@Listener
public void onPlayerRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player)
{
	if (ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true) == false)
	{
		return ;
	}
	Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);
	if (!optItem.isPresent())
	{
		return;
	}
	if (optItem.get().getItem().equals(ItemTypes.GOLDEN_AXE))
	{
		event.setCancelled(true);
		Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
		if (!optLoc.isPresent())
		{
			return;
		}
		Point secondPoint = new Point(optLoc.get().getExtent(), optLoc.get().getBlockX(), optLoc.get().getBlockZ());
		DataHandler.setSecondPoint(player.getUniqueId(), secondPoint);
		Point firstPoint = DataHandler.getFirstPoint(player.getUniqueId());
		if (firstPoint != null && !firstPoint.getWorld().equals(secondPoint.getWorld()))
		{
			firstPoint = null;
			DataHandler.setFirstPoint(player.getUniqueId(), firstPoint);
		}
		
		String coord = secondPoint.getX() + " " + secondPoint.getY() + ")" + ((firstPoint != null) ? " (" + new Rect(firstPoint, secondPoint).size() + ")" : "");
		player.sendMessage(Text.of(TextColors.AQUA, LanguageHandler.AXE_SECOND.replaceAll("\\{COORD\\}", coord)));
	}
}
 
Example #10
Source File: GoldenAxeListener.java    From Nations with MIT License 5 votes vote down vote up
@Listener
public void onPlayerLeftClick(InteractBlockEvent.Primary.MainHand event, @First Player player)
{
	if (ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true) == false)
	{
		return ;
	}
	Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);
	if (!optItem.isPresent())
	{
		return;
	}
	if (optItem.get().getItem().equals(ItemTypes.GOLDEN_AXE))
	{
		event.setCancelled(true);
		Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
		if (!optLoc.isPresent())
		{
			return;
		}
		Point firstPoint = new Point(optLoc.get().getExtent(), optLoc.get().getBlockX(), optLoc.get().getBlockZ());
		DataHandler.setFirstPoint(player.getUniqueId(), firstPoint);
		Point secondPoint = DataHandler.getSecondPoint(player.getUniqueId());
		if (secondPoint != null && !secondPoint.getWorld().equals(firstPoint.getWorld()))
		{
			secondPoint = null;
			DataHandler.setSecondPoint(player.getUniqueId(), secondPoint);
		}
		
		String coord = firstPoint.getX() + " " + firstPoint.getY() + ")" + ((secondPoint != null) ? " (" + new Rect(secondPoint, firstPoint).size() + ")" : "");
		player.sendMessage(Text.of(TextColors.AQUA, LanguageHandler.AXE_FIRST.replaceAll("\\{COORD\\}", coord)));
	}
}
 
Example #11
Source File: BlockSelectionTask.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onInteract(InteractBlockEvent.Secondary event, @First Player p) {
    if (!consumers.containsKey(p.getUniqueId())) return;
    Location loc = event.getTargetBlock().getLocation().orElse(null);
    if (loc == null) return;
    consumers.remove(p.getUniqueId()).accept(loc);
}
 
Example #12
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST)
public void onInteractLeft(InteractBlockEvent.Primary event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    Location<World> l;

    RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Primary event");

    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Primary event. The block is " + b.getState().getType().getName());
    } else {
        l = p.getLocation();
    }

    ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p);

    String claimmode = RedProtect.get().config.getWorldClaimType(p.getWorld().getName());
    if (event instanceof InteractBlockEvent.Primary.MainHand && itemInHand.getId().equalsIgnoreCase(RedProtect.get().config.configRoot().wands.adminWandID) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.claim"))) {
        if (!RedProtect.get().getUtil().canBuildNear(p, l)) {
            event.setCancelled(true);
            return;
        }
        RedProtect.get().firstLocationSelections.put(p, l);
        p.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("playerlistener.wand1") + RedProtect.get().lang.get("general.color") + " (&e" + l.getBlockX() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockY() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockZ() + RedProtect.get().lang.get("general.color") + ")."));
        event.setCancelled(true);

        //show preview border
        previewSelection(p);
    }
}
 
Example #13
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractPrimBlock(InteractBlockEvent.Primary event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();

    RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent.Primary event");

    if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
        if (b.getState().getType().getName().contains("sign") && !cont.canBreak(p, b)) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.container.breakinside");
            event.setCancelled(true);
        }
    }
}
 
Example #14
Source File: RequiredInteractListener.java    From Prism with MIT License 4 votes vote down vote up
/**
 * Listens for interactions by Players with active inspection wands.
 * <br>
 * This listener is required and does not track any events.
 *
 * @param event  InteractBlockEvent
 * @param player Player
 */
@Listener(order = Order.EARLY)
public void onInteractBlock(InteractBlockEvent event, @First Player player) {
    // Wand support
    if (!Prism.getInstance().getActiveWands().contains(player.getUniqueId())) {
        return;
    }

    event.setCancelled(true);

    // Ignore OffHand events
    if (event instanceof InteractBlockEvent.Primary.OffHand || event instanceof InteractBlockEvent.Secondary.OffHand) {
        return;
    }

    // Verify target block is valid
    if (event.getTargetBlock() == BlockSnapshot.NONE || !event.getTargetBlock().getLocation().isPresent()) {
        return;
    }

    // Location of block
    Location<World> location = event.getTargetBlock().getLocation().get();

    // Secondary click gets location relative to side clicked
    if (event instanceof InteractBlockEvent.Secondary) {
        location = location.getRelative(event.getTargetSide());
    }

    QuerySession session = new QuerySession(player);
    // session.addFlag(Flag.EXTENDED);
    session.addFlag(Flag.NO_GROUP);
    session.newQuery().addCondition(ConditionGroup.from(location));

    player.sendMessage(Text.of(
            Format.prefix(), TextColors.GOLD,
            "--- Inspecting ", Format.item(location.getBlockType().getId(), true),
            " at ", location.getBlockX(), " ", location.getBlockY(), " ", location.getBlockZ(), " ---"));

    // Pass off to an async lookup helper
    AsyncUtil.lookup(session);
}
 
Example #15
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractBlockPrimary(InteractBlockEvent.Primary.MainHand event) {
    final Location<World> location = event.getTargetBlock().getLocation().orElse(null);
    if (location == null) {
        return;
    }

    User user = CauseContextHelper.getEventUser(event);
    final Object source = CauseContextHelper.getEventFakePlayerSource(event);
    final Player player = source instanceof Player ? (Player) source : null;
    if (player == null || NMSUtil.getInstance().isFakePlayer(player)) {
        if (user == null) {
            user = player;
        }

        this.handleFakePlayerInteractBlockPrimary(event, user, source);
        return;
    }

    final HandType handType = event.getHandType();
    final ItemStack itemInHand = player.getItemInHand(handType).orElse(ItemStack.empty());
    if (handleItemInteract(event, player, player.getWorld(), itemInHand).isCancelled()) {
        event.setCancelled(true);
        return;
    }

    final BlockSnapshot clickedBlock = event.getTargetBlock();
    final String id = GDPermissionManager.getInstance().getPermissionIdentifier(clickedBlock);
    final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GDClaim claim = this.dataStore.getClaimAt(location);
    // Handle rent/buy signs
    if (!playerData.claimMode) {
        final GriefDefenderConfig<?> activeConfig = GriefDefenderPlugin.getActiveConfig(location.getExtent().getUniqueId());
        if (activeConfig.getConfig().economy.isSellSignEnabled() ||  activeConfig.getConfig().economy.isRentSignEnabled()) {
            final Sign sign = SignUtil.getSign(location);
            if (sign != null) {
                if (activeConfig.getConfig().economy.isSellSignEnabled() && SignUtil.isSellSign(sign)) {
                    if (claim.getEconomyData() != null && claim.getEconomyData().isForSale()) {
                        event.setCancelled(true);
                        EconomyUtil.getInstance().sellCancelConfirmation(player, claim, sign);
                        return;
                    }
                } else if (GriefDefenderPlugin.getGlobalConfig().getConfig().economy.rentSystem  && activeConfig.getConfig().economy.isRentSignEnabled() && SignUtil.isRentSign(claim, sign)) {
                    if ((claim.getEconomyData() != null && claim.getEconomyData().isForRent()) || claim.getEconomyData().isRented() ) {
                        event.setCancelled(true);
                        EconomyUtil.getInstance().rentCancelConfirmation(player, claim, sign);
                        return;
                    }
                }
            }
        }
    }

    if (playerData.claimMode) {
        return;
    }
    // check give pet
    if (playerData.petRecipientUniqueId != null) {
        playerData.petRecipientUniqueId = null;
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().COMMAND_PET_TRANSFER_CANCEL);
        event.setCancelled(true);
        return;
    }
    if (!GDFlags.INTERACT_BLOCK_PRIMARY || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_BLOCK_PRIMARY.getName(), event.getTargetBlock().getState(), player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.startTimingIfSync();
    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_BLOCK_PRIMARY, source, clickedBlock.getState(), player, TrustTypes.BUILDER, true);
    if (result == Tristate.FALSE) {
        if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.BLOCK_BREAK.getName(), clickedBlock.getState(), player.getWorld().getProperties())) {
            GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
            return;
        }
        if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_BREAK, source, clickedBlock.getState(), player, TrustTypes.BUILDER, true) == Tristate.TRUE) {
            GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
            return;
        }

        // Don't send a deny message if the player is holding an investigation tool
        if (Sponge.getServer().getRunningTimeTicks() != lastInteractItemPrimaryTick || lastInteractItemCancelled != true) {
            if (!PlayerUtil.getInstance().hasItemInOneHand(player, GriefDefenderPlugin.getInstance().investigationTool.getType())) {
                this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData, handType);
            }
        }
        event.setCancelled(true);
        GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
        return;
    }
    GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
}
 
Example #16
Source File: PreventListener.java    From FlexibleLogin with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockInteract(InteractBlockEvent interactBlockEvent, @First Player player) {
    checkLoginStatus(interactBlockEvent, player);
}
 
Example #17
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST)
public void onInteractRight(InteractBlockEvent.Secondary event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    Location<World> l;

    RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Secondary event");

    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Secondary event. The block is " + b.getState().getType().getName());
    } else {
        l = p.getLocation();
    }

    Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());
    ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p);

    String claimmode = RedProtect.get().config.getWorldClaimType(p.getWorld().getName());
    if (event instanceof InteractBlockEvent.Secondary.MainHand && itemInHand.getId().equalsIgnoreCase(RedProtect.get().config.configRoot().wands.adminWandID) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.claim"))) {
        if (!RedProtect.get().getUtil().canBuildNear(p, l)) {
            event.setCancelled(true);
            return;
        }
        RedProtect.get().secondLocationSelections.put(p, l);
        p.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("playerlistener.wand2") + RedProtect.get().lang.get("general.color") + " (&e" + l.getBlockX() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockY() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockZ() + RedProtect.get().lang.get("general.color") + ")."));
        event.setCancelled(true);

        //show preview border
        previewSelection(p);
        return;
    }

    //other blocks and interactions
    if (r != null) {
        if ((itemInHand.equals(ItemTypes.ENDER_PEARL) || itemInHand.getName().equals("minecraft:chorus_fruit")) && !r.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            event.setUseItemResult(Tristate.FALSE);
            event.setCancelled(true);
        } else if ((itemInHand.equals(ItemTypes.BOW) || itemInHand.equals(ItemTypes.SNOWBALL) || itemInHand.equals(ItemTypes.EGG)) && !r.canProtectiles(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            event.setUseItemResult(Tristate.FALSE);
            event.setCancelled(true);
        } else if (itemInHand.equals(ItemTypes.POTION) && !r.usePotions(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            event.setUseItemResult(Tristate.FALSE);
            event.setCancelled(true);
        } else if (itemInHand.equals(ItemTypes.MONSTER_EGG) && !r.canInteractPassives(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            event.setUseItemResult(Tristate.FALSE);
            event.setCancelled(true);
        } else if ((itemInHand.equals(ItemTypes.BOAT) || itemInHand.getType().getName().contains("_minecart")) && !r.canMinecart(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            event.setUseItemResult(Tristate.FALSE);
            event.setCancelled(true);
        }
    }
}
 
Example #18
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEvent e, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is InteractEvent event! Cancelled? " + false);
    if (!e.getInteractionPoint().isPresent()) {
        return;
    }
    Location<World> loc = new Location<>(p.getWorld(), e.getInteractionPoint().get());
    Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName());

    if (!canUse(p, r)) {
        e.setCancelled(true);
        return;
    }

    if (r != null) {
        return;
    }

    if (e instanceof InteractBlockEvent) {
        BlockSnapshot blockSnapshot = ((InteractBlockEvent) e).getTargetBlock();
        if (RedProtect.get().config.needClaimToInteract(p, blockSnapshot)) {
            e.setCancelled(true);
            return;
        }
    }
    if (e instanceof InteractEntityEvent) {
        Entity ent = ((InteractEntityEvent) e).getTargetEntity();
        RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener - Entity: " + ent.getType().getName());
        if (ent instanceof Minecart || ent instanceof Boat) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (ent instanceof Hanging || ent instanceof ArmorStand) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).build && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (ent instanceof Monster && !RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).if_interact_false.entity_monsters && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            return;
        }
        if (ent instanceof Animal || ent instanceof Golem || ent instanceof Ambient || ent instanceof Aquatic) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).if_interact_false.entity_passives && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if ((loc.getBlock().getType().equals(BlockTypes.PUMPKIN_STEM) ||
                loc.getBlock().getType().equals(BlockTypes.MELON_STEM) ||
                loc.getBlock().getType().getName().contains("chorus_") ||
                loc.getBlock().getType().getName().contains("beetroot_") ||
                loc.getBlock().getType().getName().contains("sugar_cane"))
                && !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).allow_crop_trample && !p.hasPermission("redprotect.bypass.world")) {
            e.setCancelled(true);
            return;
        }
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).interact) {
            if (!p.hasPermission("redprotect.world.bypass") && !(ent instanceof Player)) {
                if (!canInteractEntitiesList(p.getWorld(), ent.getType().getName())) {
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }

    if (e instanceof InteractBlockEvent) {
        InteractBlockEvent eb = (InteractBlockEvent) e;
        String bname = eb.getTargetBlock().getState().getType().getName();
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Block: " + bname);
        if (bname.contains("rail") || bname.contains("water")) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
            }
        } else {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).interact) {
                if (!p.hasPermission("redprotect.world.bypass")) {
                    if (!canInteractBlocksList(p.getWorld(), bname)) {
                        e.setCancelled(true);
                        return;
                    }
                }
            }
            if ((!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).build && !p.hasPermission("redprotect.world.bypass"))
                    && bname.contains("leaves")) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example #19
Source File: PlayerInteractListener.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Listener
public void onPlayerInteractBlock(InteractBlockEvent event, @Root Player player)
{
	if (EssentialCmds.frozenPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot interact while frozen."));
		event.setCancelled(true);
		return;
	}

	if (EssentialCmds.jailedPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot interact while jailed."));
		event.setCancelled(true);
		return;
	}

	Optional<Location<World>> optLocation = event.getTargetBlock().getLocation();

	if (optLocation.isPresent() && optLocation.get().getTileEntity().isPresent())
	{
		Location<World> location = optLocation.get();
		TileEntity clickedEntity = location.getTileEntity().get();

		if (event.getTargetBlock().getState().getType().equals(BlockTypes.STANDING_SIGN) || event.getTargetBlock().getState().getType().equals(BlockTypes.WALL_SIGN))
		{
			Optional<SignData> signData = clickedEntity.getOrCreate(SignData.class);

			if (signData.isPresent())
			{
				SignData data = signData.get();
				CommandManager cmdService = Sponge.getGame().getCommandManager();
				String line0 = data.getValue(Keys.SIGN_LINES).get().get(0).toPlain();
				String line1 = data.getValue(Keys.SIGN_LINES).get().get(1).toPlain();
				String command = "warp " + line1;

				if (line0.equals("[Warp]"))
				{
					if (player.hasPermission("essentialcmds.warps.use.sign"))
					{
						cmdService.process(player, command);
					}
					else
					{
						player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to use Warp Signs!"));
					}
				}
			}
		}
	}
}
 
Example #20
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
public InteractEvent handleItemInteract(InteractEvent event, Player player, World world, ItemStack itemInHand) {
    if (lastInteractItemSecondaryTick == Sponge.getServer().getRunningTimeTicks() || lastInteractItemPrimaryTick == Sponge.getServer().getRunningTimeTicks()) {
        // ignore
        return event;
    }

    if (event instanceof InteractItemEvent.Primary) {
        lastInteractItemPrimaryTick = Sponge.getServer().getRunningTimeTicks();
    } else {
        lastInteractItemSecondaryTick = Sponge.getServer().getRunningTimeTicks();
    }

    final ItemType itemType = itemInHand.getType();
    if (itemInHand.isEmpty() || itemType instanceof ItemFood) {
        return event;
    }

    final boolean primaryEvent = event instanceof InteractItemEvent.Primary || event instanceof InteractBlockEvent.Primary;
    if (!GPFlags.INTERACT_ITEM_PRIMARY && primaryEvent || !GPFlags.INTERACT_ITEM_SECONDARY && !primaryEvent || !GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) {
        return event;
    }

    if (primaryEvent && GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ITEM_PRIMARY.toString(), itemInHand.getType(), world.getProperties())) {
        return event;
    }
    if (!primaryEvent && GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ITEM_SECONDARY.toString(), itemInHand.getType(), world.getProperties())) {
        return event;
    }

    final Cause cause = event.getCause();
    final EventContext context = cause.getContext();
    final BlockSnapshot blockSnapshot = context.get(EventContextKeys.BLOCK_HIT).orElse(BlockSnapshot.NONE);
    final Vector3d interactPoint = event.getInteractionPoint().orElse(null);
    final Entity entity = context.get(EventContextKeys.ENTITY_HIT).orElse(null);
    final Location<World> location = entity != null ? entity.getLocation() 
            : blockSnapshot != BlockSnapshot.NONE ? blockSnapshot.getLocation().get() 
                    : interactPoint != null ? new Location<World>(world, interactPoint) 
                            : player.getLocation();

    final String ITEM_PERMISSION = primaryEvent ? GPPermissions.INTERACT_ITEM_PRIMARY : GPPermissions.INTERACT_ITEM_SECONDARY;
    final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    if (!itemInHand.isEmpty() && (itemInHand.getType().equals(GriefPreventionPlugin.instance.modificationTool) ||
            itemInHand.getType().equals(GriefPreventionPlugin.instance.investigationTool))) {
        GPPermissionHandler.addEventLogEntry(event, location, itemInHand, blockSnapshot == null ? entity : blockSnapshot, player, ITEM_PERMISSION, null, Tristate.TRUE);
        if (investigateClaim(event, player, blockSnapshot, itemInHand)) {
            return event;
        }

        onPlayerHandleShovelAction(event, blockSnapshot, player,  ((HandInteractEvent) event).getHandType(), playerData);
        return event;
    }

    final GPClaim claim = this.dataStore.getClaimAtPlayer(location, playerData, true);
    if (GPPermissionHandler.getClaimPermission(event, location, claim, ITEM_PERMISSION, player, itemType, player, TrustType.ACCESSOR, true) == Tristate.FALSE) {
        Text message = GriefPreventionPlugin.instance.messageData.permissionInteractItem
                .apply(ImmutableMap.of(
                "owner", claim.getOwnerName(),
                "item", itemInHand.getType().getId())).build();
        GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
        if (event instanceof InteractItemEvent) {
            if (!SpongeImplHooks.isFakePlayer(((EntityPlayerMP) player)) && itemType == ItemTypes.WRITABLE_BOOK) {
                ((EntityPlayerMP) player).closeScreen();
            }
        }
        event.setCancelled(true);
    }
    return event;
}
 
Example #21
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractBlockPrimary(InteractBlockEvent.Primary.MainHand event, @First Player player) {
    final BlockSnapshot clickedBlock = event.getTargetBlock();
    final HandType handType = event.getHandType();
    final ItemStack itemInHand = player.getItemInHand(handType).orElse(ItemStack.empty());
    // Run our item hook since Sponge no longer fires InteractItemEvent when targetting a non-air block
    if (clickedBlock != BlockSnapshot.NONE && handleItemInteract(event, player, player.getWorld(), itemInHand).isCancelled()) {
        return;
    }

    if (!GPFlags.INTERACT_BLOCK_PRIMARY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_BLOCK_PRIMARY.toString(), event.getTargetBlock().getState(), player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.startTimingIfSync();
    final Location<World> location = clickedBlock.getLocation().orElse(null);
    final Object source = !itemInHand.isEmpty() ? itemInHand : player;
    if (location == null) {
        GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
        return;
    }

    final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(location.getExtent(), player.getUniqueId());
    final GPClaim claim = this.dataStore.getClaimAt(location);
    final Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_BLOCK_PRIMARY, source, clickedBlock.getState(), player, TrustType.BUILDER, true);
    if (result == Tristate.FALSE) {
        if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.BLOCK_BREAK.toString(), clickedBlock.getState(), player.getWorld().getProperties())) {
            GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
            return;
        }
        if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.BLOCK_BREAK, player, clickedBlock.getState(), player, TrustType.BUILDER, true) == Tristate.TRUE) {
            GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
            playerData.setLastInteractData(claim);
            return;
        }

        // Don't send a deny message if the player is holding an investigation tool
        if (!PlayerUtils.hasItemInOneHand(player, GriefPreventionPlugin.instance.investigationTool)) {
            this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData, handType);
        }
        event.setCancelled(true);
        GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
        return;
    }
    playerData.setLastInteractData(claim);
    GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
}
 
Example #22
Source File: WebHookService.java    From Web-API with MIT License 4 votes vote down vote up
@Listener(order = Order.POST)
public void onInteractBlock(InteractBlockEvent event) {
    notifyHooks(WebHookService.WebHookType.INTERACT_BLOCK, event);
}