当前位置: 首页>>代码示例>>Java>>正文


Java DamageSource类代码示例

本文整理汇总了Java中org.spongepowered.api.event.cause.entity.damage.source.DamageSource的典型用法代码示例。如果您正苦于以下问题:Java DamageSource类的具体用法?Java DamageSource怎么用?Java DamageSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DamageSource类属于org.spongepowered.api.event.cause.entity.damage.source包,在下文中一共展示了DamageSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: canDamage

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
public static boolean canDamage(IActiveCharacter character, Living l) {
	if (character.getPlayer() == l) {
		return false;
	}
	if (l.getType() == EntityTypes.PLAYER) {
		if (character.hasParty()) {
			IActiveCharacter c = globalScope.characterService.getCharacter(l.getUniqueId());
			if (character.getParty().getPlayers().contains(c)) {
				return false;
			}
		}
	}
	DamageSource build = new SpongeDamageSourceBuilder()
			.type(NDamageType.DAMAGE_CHECK)
			.absolute()
			.build();

	return l.damage(0, build);
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:20,代码来源:Utils.java

示例2: onEntityDamage

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void onEntityDamage(DamageEntityEvent event, @Getter(value = "getTargetEntity") Player player, @First DamageSource dmgSrc) {
  if (!isBlockable(dmgSrc)) {
    return;
  }

  Optional<Clause<Integer, Clause<ItemStack, Clause<Integer, Long>>>> optFeatherDetail = getHighestPoweredFeather(player);
  if (!optFeatherDetail.isPresent()) {
    return;
  }

  Clause<Integer, Clause<ItemStack, Clause<Integer, Long>>> featherDetail = optFeatherDetail.get();

  int redQ = featherDetail.getValue().getValue().getKey();
  final double dmg = event.getBaseDamage();
  final int k = (dmg > 80 ? 16 : dmg > 40 ? 8 : dmg > 20 ? 4 : 2);

  final double blockable = redQ * k;
  final double blocked = blockable - (blockable - dmg);

  event.setBaseDamage(Math.max(0, dmg - blocked));

  redQ = (int) ((blockable - blocked) / k);
  updateFeatherPower(featherDetail.getValue().getKey(), redQ, (long) blocked * 75);
  tf(player).inventory.mainInventory.set(featherDetail.getKey(), tf(featherDetail.getValue().getKey()));
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:27,代码来源:RedFeather.java

示例3: onEntityDamageEvent

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onEntityDamageEvent(DamageEntityEvent event) {
  Entity defender = event.getTargetEntity();

  Optional<PatientXInstance> optInst = manager.getApplicableZone(defender);
  if (!optInst.isPresent()) {
    return;
  }

  PatientXInstance inst = optInst.get();

  DamageSource dmgSource = event.getCause().first(DamageSource.class).get();

  if (defender instanceof Player && manager.getBlockedDamage().contains(dmgSource.getType())) {
    // Explosive damage formula: (1 × 1 + 1) × 8 × power + 1
    // Use 49, snowball power is 3
    double ratio = event.getBaseDamage() / 49;

    // Nullify all modifiers
    for (DamageFunction modifier : event.getModifiers()) {
      event.setDamage(modifier.getModifier(), (a) -> 0D);
    }

    event.setBaseDamage(ratio * inst.getDifficulty());
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:27,代码来源:PatientXListener.java

示例4: slap

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Command(desc = "Slaps a player")
public void slap(CommandSource context, Player player, @Optional Integer damage)
{
    damage = damage == null ? 3 : damage;

    if (damage < 1 || damage > 20)
    {
        i18n.send(context, NEGATIVE, "Only damage values from 1 to 20 are allowed!");
        return;
    }

    final Vector3d userDirection = player.getTransform().getRotationAsQuaternion().getDirection().mul(-1);
    Sponge.getCauseStackManager().pushCause(context);
    player.damage(damage, DamageSource.builder().type(DamageTypes.ATTACK).absolute().build());
    player.setVelocity(new Vector3d(userDirection.getX() * damage / 2, userDirection.getY() * damage / 20, userDirection.getZ() * damage / 2));
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:17,代码来源:PlayerCommands.java

示例5: damageCheck

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
/**
 * Attempts to damage the defending LivingEntity, this allows for various protection plugins to
 * cancel damage events.
 *
 * @param attacking  attempting to deal the damage
 * @param defenderLE entity being damaged
 *
 * @return true if the damage check was successful
 */
public static boolean damageCheck(Insentient attacking, Living defenderLE) {
    if (attacking.getEntity().get().equals(defenderLE)) {
        return false;
    }
    if (defenderLE instanceof Player && attacking instanceof Champion) {
        if (!attacking.getWorld().getProperties().isPVPEnabled()) {
            ((Champion) attacking).sendMessage(Texts.of(TextColors.RED, "PVP is disabled!"));
            return false;
        }
    }
    DamageEntityEvent event = SpongeEventFactory
            .createDamageEntityEvent(Cause.of(NamedCause.source(DamageSource.builder().type
                    (DamageTypes.MAGIC))),
                                     ImmutableList.<Tuple<DamageModifier, Function<? super Double, Double>>>of(),
                                     defenderLE, 0);
    Sponge.getEventManager().post(event);
    return event.isCancelled();
}
 
开发者ID:AfterKraft,项目名称:KraftRPG-API,代码行数:28,代码来源:SkillUtils.java

示例6: execute

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
    NumberTag dam = NumberTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
    DamageSource.Builder build = DamageSource.builder();
    if (entry.namedArgs.containsKey("absolute")) {
        BooleanTag abs = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "absolute"));
        if (abs.getInternal()) {
            build.absolute();
        }
    }
    else {
        build.absolute();
    }
    if (entry.namedArgs.containsKey("type")) {
        String typeName = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "type").toString());
        Optional<DamageType> type = Sponge.getRegistry().getType(DamageType.class, typeName);
        if (!type.isPresent()) {
            queue.handleError(entry, "Invalid damage type: '" + typeName + "'!");
            return;
        }
        build.type(type.get());
    }
    else {
        build.type(DamageTypes.GENERIC);
    }
    if (queue.shouldShowGood()) {
        queue.outGood("Hurting " + ColorSet.emphasis + ent.debug() + ColorSet.good
                + " for " + ColorSet.emphasis + dam.debug() + ColorSet.good + " points of damage!");
    }
    ent.getInternal().damage(dam.getInternal(), build.build());
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:33,代码来源:HurtCommand.java

示例7: onPlayerDamage

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Listener
public void onPlayerDamage(DamageEntityEvent event) {
	// C'est un joueur
	if (event.getTargetEntity() instanceof Player) {
		EPlayer player = this.plugin.getEServer().getEPlayer((Player) event.getTargetEntity());
		if (player.isGod()) {
			Optional<DamageSource> damagesource = event.getCause().first(DamageSource.class);
			// Le joueur tombe dans le vide
			if (damagesource.isPresent() && damagesource.get().equals(DamageSources.VOID)) {
				// L'option de téléportation au spwan est activé
				if (this.plugin.getConfigs().isGodTeleportToSpawn()) {
					EEMessages.GOD_TELEPORT.sendTo(player);
					player.teleportSpawn();
					player.heal();
					event.setCancelled(true);
				}
				// Domage normal
			} else {
				player.heal();
				event.setCancelled(true);
			}
		}
	} else if (event.getTargetEntity() instanceof Creature) {
		if (this.plugin.getConfigs().isGameModeKill()) {
			Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
			if (optDamageSource.isPresent() && optDamageSource.get().getSource() instanceof Player) {
				Player killer = (Player) optDamageSource.get().getSource();
				if (killer.get(Keys.IS_SNEAKING).orElse(false) && 
						killer.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL).equals(GameModes.CREATIVE)) {
					Entity entity = event.getTargetEntity();
					event.setBaseDamage(entity.get(Keys.MAX_HEALTH).orElse(Double.MAX_VALUE));
				}
			}
		}
	}
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:37,代码来源:EEPlayerListeners.java

示例8: DamageSourceView

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
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();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:12,代码来源:DamageSourceView.java

示例9: playerDeath

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Listener(order = Order.POST)
public void playerDeath(DestructEntityEvent.Death event, @Getter("getTargetEntity") Player player)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    String key = "death";
    Optional<DamageSource> dmgSrcOpt = event.getCause().first(DamageSource.class);
    if (dmgSrcOpt.isPresent()) {
        key += ":" + dmgSrcOpt.get().getType().getId();
    }

    processEvent(event, player, key);
}
 
开发者ID:BadgeUp,项目名称:badgeup-sponge-client,代码行数:12,代码来源:GeneralEventListener.java

示例10: onEntityAttack

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityAttack(AttackEntityEvent event, @First DamageSource damageSource) {
    if (!GPFlags.ENTITY_DAMAGE || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetEntity().getWorld().getProperties())) {
        return;
    }

    GPTimings.ENTITY_ATTACK_EVENT.startTimingIfSync();
    if (protectEntity(event, event.getTargetEntity(), event.getCause(), damageSource)) {
        event.setCancelled(true);
    }
    GPTimings.ENTITY_ATTACK_EVENT.stopTimingIfSync();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:13,代码来源:EntityEventHandler.java

示例11: onEntityDamage

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent event, @First DamageSource damageSource) {
    if (!GPFlags.ENTITY_DAMAGE || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetEntity().getWorld().getProperties())) {
        return;
    }

    GPTimings.ENTITY_DAMAGE_EVENT.startTimingIfSync();
    if (protectEntity(event, event.getTargetEntity(), event.getCause(), damageSource)) {
        event.setCancelled(true);
    }
    GPTimings.ENTITY_DAMAGE_EVENT.stopTimingIfSync();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:13,代码来源:EntityEventHandler.java

示例12: onPlayerDeath

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@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();

    if (GriefPreventionPlugin.getGlobalConfig().getConfig().spam.monitorEnabled && (now - playerData.lastDeathTimeStamp) < GriefPreventionPlugin.getGlobalConfig().getConfig().spam.deathMessageCooldown * 1000) {
        event.setMessage(Text.of());
    }

    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();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:33,代码来源:PlayerEventHandler.java

示例13: onPlayerDeath

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Listener(order = Order.PRE)
public void onPlayerDeath(DestructEntityEvent.Death event) {
  Optional<DamageSource> optDmgSrc = event.getCause().first(DamageSource.class);
  if (optDmgSrc.isPresent() && event.getTargetEntity() instanceof Player) {
    if (event.getMessage().toPlain().contains(DAMAGE_TYPE.getId())) {
      event.setMessage(Text.of(((Player) event.getTargetEntity()).getName(), " was killed by an ancient enchantment"));
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:10,代码来源:WildernessTeleportCommand.java

示例14: damagePlayers

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
private void damagePlayers() {
  for (Player player : getPlayers(PARTICIPANT)) {
    BlockType blockType = player.getLocation().getBlockType();
    if (blockType == BlockTypes.WATER || blockType == BlockTypes.FLOWING_WATER) {
      // If the game is in progress, damage, otherwise return to the spawn point
      if (state == SkyWarsState.IN_PROGRESS) {
        player.damage(Probability.getRandom(3), DamageSource.builder().type(DamageTypes.DROWN).build());
      } else {
        player.setLocation(startingLocation);
      }
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:14,代码来源:SkyWarsInstance.java

示例15: apply

import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; //导入依赖的package包/类
@Override
public Optional<Instruction<DamagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>>>> apply(
    DamagedCondition damagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>> boss
) {
  Optional<DamageSource> optDmgSource = damagedCondition.getDamageSource();
  if (optDmgSource.isPresent()) {
    if (optDmgSource.get().getType() == DamageTypes.EXPLOSIVE) {
      DamageEntityEvent event = damagedCondition.getEvent();
      EntityHealthUtil.heal(boss.getTargetEntity().get(), event.getFinalDamage());
      event.setCancelled(true);
    }
  }
  return Optional.empty();
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:15,代码来源:HealableInstruction.java


注:本文中的org.spongepowered.api.event.cause.entity.damage.source.DamageSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。