Java Code Examples for org.spongepowered.api.entity.Entity#getWorld()

The following examples show how to use org.spongepowered.api.entity.Entity#getWorld() . 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 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 2
Source File: EntityEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityMount(RideEntityEvent.Mount event) {
    if (!GDFlags.ENTITY_RIDING) {
        return;
    }

    final Entity entity = event.getTargetEntity();
    final World world = entity.getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ENTITY_RIDING.getName(), entity, world.getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ENTITY_RIDING.getName(), entity, world.getUniqueId())) {
        return;
    }

    GDTimings.ENTITY_MOUNT_EVENT.startTiming();
    final Object source = event.getSource();
    Player player = source instanceof Player ? (Player) source : null;
    final Location<World> location = entity.getLocation();
    final GDClaim targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location);

    if (GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.ENTITY_RIDING, source, entity, player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) {
        if (player != null) {
            //sendInteractEntityDenyMessage(targetClaim, player, null, entity);
        }
        event.setCancelled(true);
    }

    GDTimings.ENTITY_MOUNT_EVENT.stopTiming();
}
 
Example 3
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDispenseItem(DropItemEvent.Dispense event, @Root Entity spawncause) {
    if (!GDFlags.ITEM_DROP || !(spawncause instanceof User)) {
        return;
    }

    final User user = (User) spawncause;
    final World world = spawncause.getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) {
        return;
    }

    GDTimings.PLAYER_DISPENSE_ITEM_EVENT.startTimingIfSync();
    Player player = user instanceof Player ? (Player) user : null;
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, user.getUniqueId());

    for (Entity entityItem : event.getEntities()) {
        if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_DROP.toString(), entityItem, world.getProperties())) {
            continue;
        }

        Location<World> location = entityItem.getLocation();
        GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
        if (claim != null) {
            if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_DROP, user, entityItem, user, TrustTypes.ACCESSOR, true) == Tristate.FALSE) {
                event.setCancelled(true);
                if (spawncause instanceof Player) {
                    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ITEM_DROP,
                            ImmutableMap.of(
                            "player", claim.getOwnerName(),
                            "item", entityItem.getType().getId()));
                    GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message);
                }
                GDTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
                return;
            }
        }
    }
    GDTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
}
 
Example 4
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDispenseItem(DropItemEvent.Dispense event, @Root Entity spawncause) {
    if (!GPFlags.ITEM_DROP || !(spawncause instanceof User)) {
        return;
    }

    final User user = (User) spawncause;
    final World world = spawncause.getWorld();
    if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) {
        return;
    }

    // in creative worlds, dropping items is blocked
    if (GriefPreventionPlugin.instance.claimModeIsActive(world.getProperties(), ClaimsMode.Creative)) {
        event.setCancelled(true);
        return;
    }

    GPTimings.PLAYER_DISPENSE_ITEM_EVENT.startTimingIfSync();
    Player player = user instanceof Player ? (Player) user : null;
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, user.getUniqueId());

    // FEATURE: players in PvP combat, can't throw items on the ground to hide
    // them or give them away to other players before they are defeated

    // if in combat, don't let him drop it
    if (player != null && !GriefPreventionPlugin.getActiveConfig(world.getProperties()).getConfig().pvp.allowCombatItemDrops && playerData.inPvpCombat(player.getWorld())) {
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.pvpNoItemDrop.toText());
        event.setCancelled(true);
        GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
        return;
    }

    for (Entity entityItem : event.getEntities()) {
        if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), entityItem, world.getProperties())) {
            continue;
        }

        Location<World> location = entityItem.getLocation();
        GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
        if (claim != null) {
            final Tristate override = GPPermissionHandler.getFlagOverride(event, location, claim, GPPermissions.ITEM_DROP,  user, entityItem, user, playerData, true);
            if (override != Tristate.UNDEFINED) {
                if (override == Tristate.TRUE) {
                    GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
                    return;
                }

                event.setCancelled(true);
                GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
                return;
            }

            // allow trusted users
            if (claim.isUserTrusted(user, TrustType.ACCESSOR)) {
                GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
                return;
            }

            Tristate perm = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_DROP, user, entityItem, user);
            if (perm == Tristate.TRUE) {
                GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
                return;
            } else if (perm == Tristate.FALSE) {
                event.setCancelled(true);
                if (spawncause instanceof Player) {
                    final Text message = GriefPreventionPlugin.instance.messageData.permissionItemDrop
                            .apply(ImmutableMap.of(
                            "owner", claim.getOwnerName(),
                            "item", entityItem.getType().getId())).build();
                    GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
                }
                GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
                return;
            }
        }
    }
    GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
}