org.spongepowered.api.event.cause.entity.damage.source.DamageSource Java Examples
The following examples show how to use
org.spongepowered.api.event.cause.entity.damage.source.DamageSource.
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: PlayerDisconnectListener.java From EagleFactions with MIT License | 6 votes |
@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 #2
Source File: EntityEventHandler.java From GriefDefender with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityAttack(AttackEntityEvent event, @First DamageSource damageSource) { GDTimings.ENTITY_ATTACK_EVENT.startTimingIfSync(); if (protectEntity(event, event.getTargetEntity(), event.getCause(), damageSource)) { event.setCancelled(true); } GDTimings.ENTITY_ATTACK_EVENT.stopTimingIfSync(); }
Example #3
Source File: EntityEventHandler.java From GriefDefender with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityDamage(DamageEntityEvent event, @First DamageSource damageSource) { GDTimings.ENTITY_DAMAGE_EVENT.startTimingIfSync(); if (protectEntity(event, event.getTargetEntity(), event.getCause(), damageSource)) { event.setCancelled(true); } GDTimings.ENTITY_DAMAGE_EVENT.stopTimingIfSync(); }
Example #4
Source File: DamageSourceView.java From Web-API with MIT License | 5 votes |
public DamageSourceView(DamageSource value) { super(value); this.affectsCreative = value.doesAffectCreative(); this.absolute = value.isAbsolute(); this.bypassingArmour = value.isBypassingArmor(); this.explosive = value.isExplosive(); this.magic = value.isMagic(); this.scaledByDifficulty = value.isScaledByDifficulty(); this.damageType = value.getType(); }
Example #5
Source File: EntityEventHandler.java From GriefPrevention with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityAttack(AttackEntityEvent event, @First DamageSource damageSource) { GPTimings.ENTITY_ATTACK_EVENT.startTimingIfSync(); if (protectEntity(event, event.getTargetEntity(), event.getCause(), damageSource)) { event.setCancelled(true); } GPTimings.ENTITY_ATTACK_EVENT.stopTimingIfSync(); }
Example #6
Source File: EntityEventHandler.java From GriefPrevention with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityDamage(DamageEntityEvent event, @First DamageSource damageSource) { GPTimings.ENTITY_DAMAGE_EVENT.startTimingIfSync(); if (protectEntity(event, event.getTargetEntity(), event.getCause(), damageSource)) { event.setCancelled(true); } GPTimings.ENTITY_DAMAGE_EVENT.stopTimingIfSync(); }
Example #7
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 5 votes |
@Listener(order = Order.FIRST) public void onPlayerDeath(DestructEntityEvent.Death event, @Root DamageSource damageSource) { GPTimings.PLAYER_DEATH_EVENT.startTimingIfSync(); if (!(event.getTargetEntity() instanceof Player) || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetEntity().getWorld().getProperties())) { GPTimings.PLAYER_DEATH_EVENT.stopTimingIfSync(); return; } // FEATURE: prevent death message spam by implementing a "cooldown period" for death messages Player player = (Player) event.getTargetEntity(); GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), event.getTargetEntity().getUniqueId()); long now = Calendar.getInstance().getTimeInMillis(); final String showDeathMessages = player.getWorld().getGameRule("showDeathMessages").orElse(null); if (showDeathMessages != null && showDeathMessages.equalsIgnoreCase("true") && GriefPreventionPlugin.getGlobalConfig().getConfig().spam.monitorEnabled && (now - playerData.lastDeathTimeStamp) < GriefPreventionPlugin.getGlobalConfig().getConfig().spam.deathMessageCooldown * 1000) { event.setMessage(Text.EMPTY); } playerData.lastDeathTimeStamp = now; // these are related to locking dropped items on death to prevent theft World world = event.getTargetEntity().getWorld(); if (world != null) { GriefPreventionConfig<?> activeConfig = GriefPreventionPlugin.getActiveConfig(world.getProperties()); GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation()); if ((claim.pvpRulesApply() && activeConfig.getConfig().pvp.protectItemsOnDeathPvp) || (!claim.isPvpEnabled() && activeConfig.getConfig().general.protectItemsOnDeathNonPvp)) { playerData.dropsAreUnlocked = false; playerData.receivedDropUnlockAdvertisement = false; } } GPTimings.PLAYER_DEATH_EVENT.stopTimingIfSync(); }
Example #8
Source File: EntityEventHandler.java From GriefDefender with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityDropItemDeath(DropItemEvent.Destruct event) { if (!GDFlags.ITEM_DROP || event.getEntities().isEmpty()) { return; } final World world = event.getEntities().get(0).getWorld(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) { return; } Object source = event.getSource(); // If root cause is damage source, look for target as that should be passed instead // Ex. Entity dies and drops an item would be after EntityDamageSource if (source instanceof DamageSource) { final Object target = event.getCause().after(DamageSource.class).orElse(null); if (target != null) { source = target; } } if (!(source instanceof Entity)) { return; } final Entity entity = (Entity) source; if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ITEM_DROP.getName(), entity, world.getProperties())) { return; } GDTimings.ENTITY_DROP_ITEM_DEATH_EVENT.startTimingIfSync(); final User user = CauseContextHelper.getEventUser(event); event.filterEntities(new Predicate<Entity>() { GDClaim targetClaim = null; @Override public boolean test(Entity item) { if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_DROP.getName(), item, world.getProperties())) { return true; } targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(item.getLocation(), targetClaim); if (targetClaim == null) { return true; } if (user == null) { return true; } if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_DROP.getName(), item, world.getProperties())) { return true; } if (GDPermissionManager.getInstance().getFinalPermission(event, item.getLocation(), targetClaim, Flags.ITEM_DROP, entity, item, user, TrustTypes.ACCESSOR, true) == Tristate.FALSE) { return false; } return true; } }); GDTimings.ENTITY_DROP_ITEM_DEATH_EVENT.stopTimingIfSync(); }
Example #9
Source File: EntityServlet.java From Web-API with MIT License | 4 votes |
@PUT @Path("/{entity}") @Permission("modify") @ApiOperation( value = "Modify an entity", notes = "Modify the properties of an existing entity.") public CachedEntity modifyEntity( @PathParam("entity") @ApiParam("The uuid of the entity") UUID uuid, UpdateEntityRequest req) throws NotFoundException, BadRequestException { if (req == null) { throw new BadRequestException("Request body is required"); } Optional<CachedEntity> optEntity = WebAPI.getCacheService().getEntity(uuid); if (!optEntity.isPresent()) { throw new NotFoundException("Entity with UUID '" + uuid + "' could not be found"); } return WebAPI.runOnMain(() -> { Optional<Entity> optLive = optEntity.get().getLive(); if (!optLive.isPresent()) throw new InternalServerErrorException("Could not get live entity"); Entity live = optLive.get(); if (req.getWorld().isPresent()) { Optional<World> optWorld = req.getWorld().get().getLive(); if (!optWorld.isPresent()) throw new InternalServerErrorException("Could not get live world"); if (req.getPosition() != null) { live.transferToWorld(optWorld.get(), req.getPosition()); } else { live.transferToWorld(optWorld.get()); } } else if (req.getPosition() != null) { live.setLocation(new Location<>(live.getWorld(), req.getPosition())); } if (req.getVelocity() != null) { live.setVelocity(req.getVelocity()); } if (req.getRotation() != null) { live.setRotation(req.getRotation()); } if (req.getScale() != null) { live.setRotation(req.getScale()); } if (req.getDamage() != null) { DamageRequest dmgReq = req.getDamage(); DamageSource.Builder builder = DamageSource.builder(); if (dmgReq.getType().isPresent()) { Optional<DamageType> optDmgType = dmgReq.getType().get().getLive(DamageType.class); if (!optDmgType.isPresent()) throw new InternalServerErrorException("Could not get live damage type"); builder.type(optDmgType.get()); } live.damage(req.getDamage().getAmount(), builder.build()); } if (req.hasInventory()) { if (!(live instanceof Carrier)) { throw new BadRequestException("Entity does not have an inventory!"); } try { Inventory inv = ((Carrier) live).getInventory(); for (SlotRequest slotReq : req.getInventory()) { for (Inventory slot : inv.slots()) { Optional<SlotIndex> optIndex = slot.getInventoryProperty(SlotIndex.class); if (!optIndex.isPresent() || !slotReq.getSlotIndex().equals(optIndex.get().getValue())) { continue; } if (slotReq.getStack().isPresent()) { slot.set(slotReq.getStack().get()); } else { slot.clear(); } } } } catch (Exception e) { throw new InternalServerErrorException(e.getMessage()); } } return new CachedEntity(live); }); }
Example #10
Source File: EntityEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityDropItemDeath(DropItemEvent.Destruct event) { if (!GPFlags.ITEM_DROP || event.getEntities().isEmpty()) { return; } final World world = event.getEntities().get(0).getWorld(); if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) { return; } Object source = event.getSource(); // If root cause is damage source, look for target as that should be passed instead // Ex. Entity dies and drops an item would be after EntityDamageSource if (source instanceof DamageSource) { final Object target = event.getCause().after(DamageSource.class).orElse(null); if (target != null) { source = target; } } if (!(source instanceof Entity)) { return; } final Entity entity = (Entity) source; if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), entity, world.getProperties())) { return; } GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.startTimingIfSync(); // special rule for creative worlds: killed entities don't drop items or experience orbs if (GriefPreventionPlugin.instance.claimModeIsActive(entity.getLocation().getExtent().getProperties(), ClaimsMode.Creative)) { event.setCancelled(true); GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.stopTimingIfSync(); return; } final User user = CauseContextHelper.getEventUser(event); event.filterEntities(new Predicate<Entity>() { GPClaim targetClaim = null; @Override public boolean test(Entity item) { if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), item, world.getProperties())) { return true; } targetClaim = GriefPreventionPlugin.instance.dataStore.getClaimAt(item.getLocation(), targetClaim); if (targetClaim == null) { return true; } if (user == null) { return true; } if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), item, world.getProperties())) { return true; } if (GPPermissionHandler.getClaimPermission(event, item.getLocation(), targetClaim, GPPermissions.ITEM_DROP, entity, item, user, TrustType.ACCESSOR, true) == Tristate.FALSE) { return false; } return true; } }); GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.stopTimingIfSync(); }