org.spongepowered.api.entity.EntityTypes Java Examples

The following examples show how to use org.spongepowered.api.entity.EntityTypes. 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: PvpListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onEntityDamagedByPlayer(DamageEntityEvent event, @All(ignoreEmpty=false) EntityDamageSource[] sources)
{
	if (!ConfigHandler.getNode("worlds").getNode(event.getTargetEntity().getWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	Entity attacker = null;
	for (int i = 0; i < sources.length; i++)
	{
		if (sources[i].getSource().getType() == EntityTypes.PLAYER
				|| (sources[i] instanceof IndirectEntityDamageSource && ((IndirectEntityDamageSource) sources[i]).getIndirectSource().getType() == EntityTypes.PLAYER))
		{
			attacker = sources[i].getSource();
		}
	}
	if (attacker != null && event.getTargetEntity().getType() == EntityTypes.PLAYER)
	{
		if (!DataHandler.getFlag("pvp", attacker.getLocation()) || !DataHandler.getFlag("pvp", event.getTargetEntity().getLocation()))
		{
			event.setCancelled(true);
			return;
		}
	}
}
 
Example #2
Source File: EntityEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
public void onEntityDamageMonitor(DamageEntityEvent event) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetEntity().getWorld().getUniqueId())) {
        return;
    }

    GDTimings.ENTITY_DAMAGE_MONITOR_EVENT.startTimingIfSync();
    //FEATURE: prevent players who very recently participated in pvp combat from hiding inventory to protect it from looting
    //FEATURE: prevent players who are in pvp combat from logging out to avoid being defeated

    if (event.getTargetEntity().getType() != EntityTypes.PLAYER || NMSUtil.getInstance().isEntityMonster(event.getTargetEntity())) {
        GDTimings.ENTITY_DAMAGE_MONITOR_EVENT.stopTimingIfSync();
        return;
    }

    Player defender = (Player) event.getTargetEntity();

    //only interested in entities damaging entities (ignoring environmental damage)
    // the rest is only interested in entities damaging entities (ignoring environmental damage)
    if (!(event.getCause().root() instanceof EntityDamageSource)) {
        GDTimings.ENTITY_DAMAGE_MONITOR_EVENT.stopTimingIfSync();
        return;
    }

    GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(defender.getWorld(), defender.getUniqueId());
    GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, defender.getLocation());
    EntityDamageSource entityDamageSource = (EntityDamageSource) event.getCause().root();
    GDTimings.ENTITY_DAMAGE_MONITOR_EVENT.stopTimingIfSync();
}
 
Example #3
Source File: KittyCannonExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public void spawnEntity(Location<World> location, Vector3d velocity, CommandSource src)
{
	velocity = velocity.mul(5);
	Extent extent = location.getExtent();
	Entity kitten = extent.createEntity(EntityTypes.OCELOT, location.getPosition());
	kitten.offer(Keys.VELOCITY, velocity);
	extent.spawnEntity(kitten, Cause.of(NamedCause.source(SpawnCause.builder().type(SpawnTypes.CUSTOM).build())));
}
 
Example #4
Source File: FireballExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public void spawnEntity(Location<World> location, Vector3d velocity, CommandSource src)
{
	Extent extent = location.getExtent();
	Entity fireball = extent.createEntity(EntityTypes.FIREBALL, location.getPosition());
	fireball.offer(Keys.VELOCITY, velocity);
	extent.spawnEntity(fireball, Cause.of(NamedCause.source(SpawnCause.builder().type(SpawnTypes.CUSTOM).build())));
}
 
Example #5
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onAttemptInteractAS(InteractEntityEvent e, @First Player p) {

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

    if (r == null) {
        //global flags
        if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(l.getExtent().getName()).build) {
                e.setCancelled(true);
                return;
            }
        }
        return;
    }

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

    if (!itemInHand.equals(ItemTypes.NONE) && itemInHand.getType().equals(ItemTypes.ARMOR_STAND)) {
        if (!r.canBuild(p)) {
            e.setCancelled(true);
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
            return;
        }
    }

    //TODO Not working!
    if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
        if (!r.canBuild(p)) {
            if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
                RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantedit");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #6
Source File: WorldUtil.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Removes all item entities in a radius around a given a location.
 *
 * @param location Location center
 * @param radius Integer radius around location
 * @return integer Count of removals
 */
public static int removeItemEntitiesAroundLocation(Location<World> location, int radius) {
    int xMin = location.getBlockX() - radius;
    int xMax = location.getBlockX() + radius;

    int zMin = location.getBlockZ() - radius;
    int zMax = location.getBlockZ() + radius;

    int yMin = location.getBlockY() - radius;
    int yMax = location.getBlockY() + radius;

    Collection<Entity> entities = location.getExtent().getEntities(e -> {
        Location<World> loc = e.getLocation();

        return (e.getType().equals(EntityTypes.ITEM)
                && (loc.getX() > xMin && loc.getX() <= xMax)
                && (loc.getY() > yMin && loc.getY() <= yMax)
                && (loc.getZ() > zMin && loc.getZ() <= zMax)
        );
    });

    if (!entities.isEmpty()) {
        entities.forEach(Entity::remove);
    }

    return entities.size();
}
 
Example #7
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityConstruct(ConstructEntityEvent.Pre event, @Root Object source) {
    lastConstructEntityTick = Sponge.getServer().getRunningTimeTicks();
    if (true || source instanceof ConsoleSource || !GDFlags.ENTITY_SPAWN) {
        return;
    }

    final World world = event.getTransform().getExtent();
    final String entityTypeId = event.getTargetType().getId();
    if (entityTypeId.equals(EntityTypes.EXPERIENCE_ORB.getId())) {
        return;
    }

    final Location<World> location = event.getTransform().getLocation();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ENTITY_SPAWN.getName(), source, world.getProperties())) {
        return;
    }
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ENTITY_CHUNK_SPAWN.getName(), source, world.getProperties())) {
        return;
    }

    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ENTITY_SPAWN.getName(), entityTypeId, world.getProperties())) {
        return;
    }

    GDTimings.ENTITY_SPAWN_PRE_EVENT.startTimingIfSync();
    final User user = CauseContextHelper.getEventUser(event);
    final GDClaim targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location);
    if (targetClaim.isUserTrusted(user, TrustTypes.BUILDER)) {
        GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
        return;
    }

    Flag flag = Flags.ENTITY_SPAWN;
    if (event.getTargetType() == EntityTypes.ITEM) {
        if (user == null) {
            GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
            return;
        }
        if (!GDFlags.ITEM_SPAWN) {
            GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
            return;
        }
        if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_SPAWN.getName(), entityTypeId, world.getProperties())) {
            GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
            return;
        }

        flag = Flags.ITEM_SPAWN;
        if (source instanceof BlockSnapshot) {
            final BlockSnapshot block = (BlockSnapshot) source;
            final Location<World> blockLocation = block.getLocation().orElse(null);
            if (blockLocation != null) {
                if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.BLOCK_BREAK.getName(), block, world.getProperties())) {
                    GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
                    return;
                }
                final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_BREAK, source, block, user, true);
                if (result != Tristate.UNDEFINED) {
                    if (result == Tristate.TRUE) {
                        // Check if item drop is allowed
                        if (GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, flag, source, entityTypeId, user, true) == Tristate.FALSE) {
                            event.setCancelled(true);
                        }
                        GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
                        return;
                    }
                    event.setCancelled(true);
                    GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
                    return;
                }
            }
        }
    }
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, flag, source, entityTypeId, user, true) == Tristate.FALSE) {
        event.setCancelled(true);
    }
    GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
}
 
Example #8
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractEntity(InteractEntityEvent.Secondary event, @First Player player) {
    if (!GPFlags.INTERACT_ENTITY_SECONDARY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }

    final Entity targetEntity = event.getTargetEntity();
    final HandType handType = event.getHandType();
    final ItemStack itemInHand = player.getItemInHand(handType).orElse(ItemStack.empty());
    final Object source = !itemInHand.isEmpty() ? itemInHand : player;
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ENTITY_SECONDARY.toString(), targetEntity, player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.startTimingIfSync();
    Location<World> location = targetEntity.getLocation();
    GPClaim claim = this.dataStore.getClaimAt(location);
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());

    // if entity is living and has an owner, apply special rules
    if (targetEntity instanceof Living) {
        EntityBridge spongeEntity = (EntityBridge) targetEntity;
        Optional<User> owner = ((OwnershipTrackedBridge) spongeEntity).tracked$getOwnerReference();
        if (owner.isPresent()) {
            UUID ownerID = owner.get().getUniqueId();
            // if the player interacting is the owner or an admin in ignore claims mode, always allow
            if (player.getUniqueId().equals(ownerID) || playerData.canIgnoreClaim(claim)) {
                // if giving away pet, do that instead
                if (playerData.petGiveawayRecipient != null) {
                    SpongeEntityType spongeEntityType = (SpongeEntityType) ((Entity) spongeEntity).getType();
                    if (spongeEntityType.equals(EntityTypes.UNKNOWN) || !spongeEntityType.getModId().equalsIgnoreCase("minecraft")) {
                        final Text message = GriefPreventionPlugin.instance.messageData.commandPetInvalid
                                .apply(ImmutableMap.of(
                                "type", spongeEntityType.getId())).build();
                        GriefPreventionPlugin.sendMessage(player, message);
                        playerData.petGiveawayRecipient = null;
                        GPTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync();
                        return;
                    }
                    ((Entity) spongeEntity).setCreator(playerData.petGiveawayRecipient.getUniqueId());
                    if (targetEntity instanceof EntityTameable) {
                        EntityTameable tameable = (EntityTameable) targetEntity;
                        tameable.setOwnerId(playerData.petGiveawayRecipient.getUniqueId());
                    } else if (targetEntity instanceof EntityHorse) {
                        EntityHorse horse = (EntityHorse) targetEntity;
                        horse.setOwnerUniqueId(playerData.petGiveawayRecipient.getUniqueId());
                        horse.setHorseTamed(true);
                    }
                    playerData.petGiveawayRecipient = null;
                    GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.commandPetConfirmation.toText());
                    event.setCancelled(true);
                    this.sendInteractEntityDenyMessage(itemInHand, targetEntity, claim, player, handType);
                }
                GPTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync();
                return;
            }
        }
    }

    if (playerData.canIgnoreClaim(claim)) {
        GPTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync();
        return;
    }

    Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_ENTITY_SECONDARY, source, targetEntity, player, TrustType.ACCESSOR, true);
    if (result == Tristate.TRUE && targetEntity instanceof ArmorStand) {
        result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INVENTORY_OPEN, source, targetEntity, player, TrustType.CONTAINER, false);
    }
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
        this.sendInteractEntityDenyMessage(itemInHand, targetEntity, claim, player, handType);
        GPTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync();
    }
}
 
Example #9
Source File: LightningExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
public void spawnEntity(Location<World> location, CommandSource src)
{
	Extent extent = location.getExtent();
	Entity lightning = extent.createEntity(EntityTypes.LIGHTNING, location.getPosition());
	extent.spawnEntity(lightning, Cause.of(NamedCause.source(SpawnCause.builder().type(SpawnTypes.CUSTOM).build())));
}