org.spongepowered.api.event.filter.cause.Root Java Examples

The following examples show how to use org.spongepowered.api.event.filter.cause.Root. 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: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFramePlace(SpawnEntityEvent event, @Root Player p) {
    for (Entity e : event.getEntities()) {
        if (e == null || RedProtect.get().rm.getTopRegion(e.getLocation(), this.getClass().getName()) != null) {
            continue;
        }

        if (event instanceof DropItemEvent) {
            continue;
        }

        if (e instanceof Hanging) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(e.getWorld().getName()).build && !p.hasPermission("redprotect.world.bypass")) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example #2
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onPickupItem(ChangeInventoryEvent.Pickup event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (SlotTransaction transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
			}
		}
	}
}
 
Example #3
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onDropItem(DropItemEvent.Dispense event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		event.filterEntities(e -> {
			if (e.get(RepresentedItemData.class).isPresent())
			{
				RepresentedItemData itemData = e.get(RepresentedItemData.class).get();
				boolean blacklisted = Utils.getBlacklistItems().contains(itemData.item().get().getType().getId());

				if (blacklisted)
				{
					if (Utils.areBlacklistMsgsEnabled())
						player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, itemData.item().get().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
				}

				return !blacklisted;
			}
			return false;
		});
	}
}
 
Example #4
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onBreakBlock(ChangeBlockEvent.Break event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (Transaction<BlockSnapshot> transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getOriginal().getState().getType().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				event.setCancelled(true);
			}
		}
	}
}
 
Example #5
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onPlaceBlock(ChangeBlockEvent.Place event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (Transaction<BlockSnapshot> transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getFinal().getState().getType().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				event.setCancelled(true);
			}
		}
	}
}
 
Example #6
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onChangeEquipment(ChangeInventoryEvent.Equipment event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (SlotTransaction transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
			}
		}
	}
}
 
Example #7
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onChangeHeldItem(ChangeInventoryEvent.Held event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (SlotTransaction transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
			}
		}
	}
}
 
Example #8
Source File: CommandSentListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onCommandSent(SendCommandEvent event, @Root CommandSource src)
{
	if (src instanceof Player && Utils.isPlayerCommandLoggingEnabled())
	{
		EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments());
	}
	else if (src instanceof ConsoleSource && Utils.isConsoleCommandLoggingEnabled())
	{
		EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments());
	}
	else if (src instanceof CommandBlockSource && Utils.isCommandBlockCommandLoggingEnabled())
	{
		EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments());
	}
	else if (Utils.isOtherCommandLoggingEnabled())
	{
		EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments());
	}
}
 
Example #9
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryClose(InteractInventoryEvent.Close event, @Root Player player) {
    final ItemStackSnapshot cursor = event.getCursorTransaction().getOriginal();
    if (cursor == ItemStackSnapshot.NONE || !GPFlags.ITEM_DROP || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), cursor, player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.startTimingIfSync();
    final Location<World> location = player.getLocation();
    final GPClaim claim = this.dataStore.getClaimAt(location);
    if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_DROP, player, cursor, player, TrustType.ACCESSOR, true) == Tristate.FALSE) {
        Text message = GriefPreventionPlugin.instance.messageData.permissionItemDrop
                .apply(ImmutableMap.of(
                "owner", claim.getOwnerName(),
                "item", cursor.getType().getId())).build();
        GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }

    GPTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.stopTimingIfSync();
}
 
Example #10
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGlobal(ChangeBlockEvent.Break e, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is BlockBreakEvent event! Cancelled? " + false);

    BlockSnapshot bt = e.getTransactions().get(0).getOriginal();
    Region r = RedProtect.get().rm.getTopRegion(bt.getLocation().get(), this.getClass().getName());
    if (r != null) {
        return;
    }

    if (!RedProtect.get().getUtil().canBuildNear(p, bt.getLocation().get())) {
        e.setCancelled(true);
        return;
    }

    if (!bypassBuild(p, bt, 2)) {
        e.setCancelled(true);
        RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't Break!");
    }
}
 
Example #11
Source File: SignListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener(order = Order.EARLY)
public void onSignCreate(ChangeSignEvent event, @Root Player p) {
    //Sign colors
    List<Text> lines = event.getText().lines().get();
    lines.set(0, TextUtil.replaceColors(lines.get(0), p, "uc.sign"));
    lines.set(1, TextUtil.replaceColors(lines.get(1), p, "uc.sign"));
    lines.set(2, TextUtil.replaceColors(lines.get(2), p, "uc.sign"));
    lines.set(3, TextUtil.replaceColors(lines.get(3), p, "uc.sign"));
    event.getText().setElements(lines);

    //Registered signs
    for (UCSign sign : UltimateCore.get().getSignService().get().getRegisteredSigns()) {
        if (event.getText().get(0).orElse(Text.of()).toPlain().equalsIgnoreCase("[" + sign.getIdentifier() + "]")) {
            if (!p.hasPermission(sign.getCreatePermission().get())) {
                Messages.send(p, "core.nopermissions");
            }
            SignCreateEvent cevent = new SignCreateEvent(sign, event.getTargetTile().getLocation(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build()));
            Sponge.getEventManager().post(cevent);
            if (!cevent.isCancelled() && sign.onCreate(p, event)) {
                //Color sign
                event.getTargetTile().offer(Keys.SIGN_LINES, event.getText().setElement(0, Text.of(TextColors.AQUA, "[" + StringUtil.firstUpperCase(sign.getIdentifier()) + "]")).asList());
                Messages.send(p, "sign.create", "%sign%", sign.getIdentifier());
            }
        }
    }
}
 
Example #12
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 #13
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryClose(InteractInventoryEvent.Close event, @Root Player player) {
    final ItemStackSnapshot cursor = event.getCursorTransaction().getOriginal();
    if (cursor == ItemStackSnapshot.NONE || !GDFlags.ITEM_DROP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_DROP.getName(), cursor, player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.startTimingIfSync();
    final Location<World> location = player.getLocation();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_DROP, player, cursor, player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ITEM_DROP,
                ImmutableMap.of(
                "player", claim.getOwnerName(),
                "item", cursor.getType().getId()));
        GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.stopTimingIfSync();
}
 
Example #14
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.LAST, beforeModifications = true)
public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
    if (!GDFlags.ITEM_PICKUP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_PICKUP.getName(), event.getTargetEntity(), player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync();
    final World world = player.getWorld();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId());
    Location<World> location = player.getLocation();
    GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_PICKUP, player, event.getTargetEntity(), player, true) == Tristate.FALSE) {
        event.setCancelled(true);
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
}
 
Example #15
Source File: InventoryListener.java    From Prism with MIT License 6 votes vote down vote up
/**
 * Saves event records when a player picks up an item off of the ground.
 *
 * @param event  ChangeInventoryEvent.Pickup
 * @param player Player
 */
@Listener(order = Order.POST)
public void onChangeInventoryPickup(ChangeInventoryEvent.Pickup event, @Root Player player) {
    if (event.getTransactions().isEmpty() || !Prism.getInstance().getConfig().getEventCategory().isItemPickup()) {
        return;
    }

    for (SlotTransaction transaction : event.getTransactions()) {
        ItemStackSnapshot itemStack = transaction.getFinal();
        int quantity = itemStack.getQuantity();
        if (transaction.getOriginal().getType() != ItemTypes.NONE) {
            quantity -= transaction.getOriginal().getQuantity();
        }

        Prism.getInstance().getLogger().debug("Inventory pickup - {} x{}", itemStack.getType().getId(), quantity);

        PrismRecord.create()
                .source(event.getCause())
                .event(PrismEvents.ITEM_PICKUP)
                .itemStack(itemStack, quantity)
                .location(player.getLocation())
                .buildAndSave();
    }
}
 
Example #16
Source File: InventoryListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
@Exclude({ClickInventoryEvent.Close.class, ClickInventoryEvent.Open.class})
public void onInteract(ClickInventoryEvent event, @Root Player p) {
    try {
        //Get target inventory owner
        Inventory inv = event.getTargetInventory();
        if (!(inv instanceof CarriedInventory)) return;
        CarriedInventory cinv = (CarriedInventory) inv;
        if (!cinv.getCarrier().isPresent() || !(cinv.getCarrier().get() instanceof User)) return;
        User t = (User) cinv.getCarrier().get();

        //Check if player is in invsee & Cancel event if player doesn't have permission
        UltimateUser up = UltimateCore.get().getUserService().getUser(p);
        if (up.get(InventoryKeys.INVSEE_TARGET).isPresent() && up.get(InventoryKeys.INVSEE_TARGET).get().equals(t.getUniqueId())) {
            if (!p.hasPermission("uc.inventory.invsee.modify")) {
                event.getCursorTransaction().setValid(false);
                event.setCancelled(true);
            }
        }
    } catch (Exception ignore) {
    }
}
 
Example #17
Source File: SignListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onSignDestroy(ChangeBlockEvent.Break event, @Root Player p) {
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockSnapshot snapshot = transaction.getOriginal();
        if (snapshot.supports(Keys.SIGN_LINES) && snapshot.getLocation().isPresent()) {
            List<Text> texts = snapshot.get(Keys.SIGN_LINES).get();
            //Checking for sign contents
            for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) {
                if (texts.get(0).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) {
                    if (!p.hasPermission(usign.getDestroyPermission().get())) {
                        Messages.send(p, "core.nopermissions");
                    }
                    SignDestroyEvent cevent = new SignDestroyEvent(usign, snapshot.getLocation().get(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build()));
                    Sponge.getEventManager().post(cevent);
                    if (!cevent.isCancelled() && usign.onDestroy(p, event, texts)) {
                        Messages.send(p, "sign.destroy", "%sign%", usign.getIdentifier());
                    }
                }
            }
        }
    }
}
 
Example #18
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 #19
Source File: PlayerInteractListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityInteract(final InteractEntityEvent event, @Root final Player player)
{
    final Entity targetEntity = event.getTargetEntity();
    final Optional<Vector3d> optionalInteractionPoint = event.getInteractionPoint();

    if((targetEntity instanceof Living) && !(targetEntity instanceof ArmorStand))
        return;

    final Vector3d blockPosition = optionalInteractionPoint.orElseGet(() -> targetEntity.getLocation().getPosition());
    final Location<World> location = new Location<>(targetEntity.getWorld(), blockPosition);
    boolean canInteractWithEntity = super.getPlugin().getProtectionManager().canInteractWithBlock(location, player, true).hasAccess();
    if(!canInteractWithEntity)
    {
        event.setCancelled(true);
        return;
    }
}
 
Example #20
Source File: PlayerDisconnectListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.POST)
public void onDisconnect(ClientConnectionEvent.Disconnect event, @Root Player player)
{
    if (super.getPlugin().getPVPLogger().isActive() && EagleFactionsPlugin.getPlugin().getPVPLogger().isPlayerBlocked(player))
    {
        player.damage(1000, DamageSource.builder().type(DamageTypes.ATTACK).build());
        super.getPlugin().getPVPLogger().removePlayer(player);
    }

    EagleFactionsPlugin.REGEN_CONFIRMATION_MAP.remove(player.getUniqueId());

    final Optional<Faction> optionalFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
    optionalFaction.ifPresent(faction -> getPlugin().getFactionLogic().setLastOnline(faction, Instant.now()));

    //TODO: Unload player cache...
    FactionsCache.removePlayer(player.getUniqueId());
}
 
Example #21
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is ChangeBlockEvent event! Cancelled? " + false);

    BlockSnapshot b = e.getTransactions().get(0).getFinal();
    ItemType item = RedProtect.get().getVersionHelper().getItemInHand(p);
    Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get(), this.getClass().getName());

    if (r != null) {
        return;
    }

    if (!RedProtect.get().getUtil().canBuildNear(p, b.getLocation().get())) {
        e.setCancelled(true);
        return;
    }

    if (item.getName().contains("minecart") || item.getName().contains("boat")) {
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't place minecart/boat!");
        }
    } else {
        if (!bypassBuild(p, b, 1)) {
            e.setCancelled(true);
            RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't Build!");
        }
    }
}
 
Example #22
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onItemPickup(CollideEntityEvent event, @Root Player p) {
    for (Entity ent : event.getEntities()) {
        if (!(ent instanceof Item)) {
            continue;
        }
        Region r = RedProtect.get().rm.getTopRegion(ent.getLocation(), this.getClass().getName());
        if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_canpickup && !p.hasPermission("redprotect.world.bypass")) {
            event.setCancelled(true);
        }
    }
}
 
Example #23
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBucketUse(UseItemStackEvent.Start e, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBucketUse event");

    Location<World> l = p.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());

    if (!canUse(p, r)) {
        e.setCancelled(true);
    }
}
 
Example #24
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void PlayerDropItem(DropItemEvent.Dispense e, @Root Player p) {
    for (Entity ent : e.getEntities()) {
        Location<World> l = ent.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());

        if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_candrop && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
        }
    }
}
 
Example #25
Source File: CommandListener.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Listener
public void onPlayerSendCommand(SendCommandEvent event, @Root Player player)
{
	if(EssentialCmds.jailedPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You may not execute commands while in jail!"));
		event.setCancelled(true);
	}
}
 
Example #26
Source File: EntityListener.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Saves event records when a player executes a command.
 *
 * @param event SendCommandEvent
 */
@Listener(order = Order.POST)
public void onSendCommand(SendCommandEvent event, @Root Player player) {
    if (!Prism.getInstance().getConfig().getEventCategory().isCommandExecute()) {
        return;
    }

    PrismRecord.create()
            .source(event.getCause())
            .event(PrismEvents.COMMAND_EXECUTE)
            .location(player.getLocation())
            .target(event.getCommand())
            .buildAndSave();
}
 
Example #27
Source File: ChangeBlockListener.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Listener
public void onPlayerChangeBlock(ChangeBlockEvent event, @Root Player player)
{
	if(EssentialCmds.jailedPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You may not modify blocks while in jail!"));
		event.setCancelled(true);
	}
}
 
Example #28
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onItemPickup(CollideEntityEvent event, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.PLAYER, "Is CollideEntityEvent(ItemPickup) event.");
    for (Entity ent : event.getEntities()) {
        if (!(ent instanceof Item)) {
            continue;
        }
        Region r = RedProtect.get().rm.getTopRegion(ent.getLocation(), this.getClass().getName());
        if (r != null && ((!r.canEnter(p) && !r.canPickup(p) || !r.canPickup(p)))) {
            event.setCancelled(true);
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantpickup");
            return;
        }
    }
}
 
Example #29
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void PlayerDropItemGui(DropItemEvent.Pre e, @Root Player p) {
    e.getDroppedItems().forEach(item -> {
        if (RedProtect.get().getUtil().isGuiItem(item.createStack())) {
            RedProtect.get().getVersionHelper().removeGuiItem(p);
            e.setCancelled(true);
        }
    });
}
 
Example #30
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void PlayerDropItem(DropItemEvent.Dispense e, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.PLAYER, "Is DropItemEvent.Dispense event.");

    for (Entity ent : e.getEntities()) {
        Location<World> l = ent.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());

        if (r != null && ((!r.canExit(p) && !r.canDrop(p)) || !r.canDrop(p))) {
            e.setCancelled(true);
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantdrop");
        }
    }
}