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


Java DamageEntityEvent类代码示例

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


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

示例1: onPlayerDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Listener
public void onPlayerDamage(DamageEntityEvent event) {
	if (!Config.Values.Synchronize.getEnableHealth())
		return;

	Entity player = event.getTargetEntity();

	if (!(player instanceof Player))
		return;

	synchronized (waitingPlayers) {
		if (waitingPlayers.containsKey(player.getUniqueId())) {
			event.setCancelled(true);
		}
	}
}
 
开发者ID:AuraDevelopmentTeam,项目名称:InvSync,代码行数:17,代码来源:PlayerEvents.java

示例2: handleDamageEntity

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
public void handleDamageEntity(DamageEntityEvent event, Player victim, Player damager) {
    ClanPlayerImpl victimClanPlayer = ClansImpl.getInstance().getClanPlayer(victim.getUniqueId());
    ClanPlayerImpl damagerClanPlayer = ClansImpl.getInstance().getClanPlayer(damager.getUniqueId());
    if (victimClanPlayer == null || damagerClanPlayer == null)
        return;
    if (victimClanPlayer.getClan() == null || damagerClanPlayer.getClan() == null)
        return;
    if (Utils.isWorldBlockedFromAllowingFriendlyFireProtection(victim.getWorld().getName())) {
        return;
    }
    if (victim.getUniqueId().equals(damager.getUniqueId())) {
        return;
    }

    ClanImpl victimPlayerClan = victimClanPlayer.getClan();
    ClanImpl damagerPlayerClan = damagerClanPlayer.getClan();
    if (victimPlayerClan.isPlayerFriendlyToThisClan(damagerClanPlayer)) {
        if (victimClanPlayer.isFfProtected() && victimPlayerClan.isFfProtected() && damagerPlayerClan.isFfProtected()) {
            event.setCancelled(true);
            Messages.sendWarningMessage(damager, Messages.FRIENDLY_FIRE_IS_OFF);
        }
    }
}
 
开发者ID:iLefty,项目名称:mcClans,代码行数:24,代码来源:FriendlyFireListener.java

示例3: onDamageEntity

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void onDamageEntity(DamageEntityEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }
    Optional<Player> damagerOpt = event.getCause().first(Player.class);
    if (!damagerOpt.isPresent()) {
        return;
    }

    Player victim = (Player) event.getTargetEntity();
    Player damager = damagerOpt.get();

    ClanPlayerImpl victimClanPlayer = ClansImpl.getInstance().getClanPlayer(victim.getUniqueId());

    if (victimClanPlayer == null) {
        victimClanPlayer = ClansImpl.getInstance().createClanPlayer(victim.getUniqueId(), victim.getName());
    }

    victimClanPlayer.setLastPlayerDamage(damager.getUniqueId());
}
 
开发者ID:iLefty,项目名称:mcClans,代码行数:25,代码来源:UpdateLastPlayerDamageListener.java

示例4: onEntityDamagedByPlayer

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@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;
		}
	}
}
 
开发者ID:Arckenver,项目名称:Nations,代码行数:26,代码来源:PvpListener.java

示例5: onEntityDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Listener
public void onEntityDamage(DamageEntityEvent event, @Root EntityDamageSource dmgSource) {
    if(dmgSource.getSource() instanceof Player) {
        Player player = (Player)dmgSource.getSource();
        EntityType entityType = event.getTargetEntity().getType();
        String entityId = entityType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.entity.damage." + entityId + ".deal")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to damage " + entityType.getName() + "s!"));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:17,代码来源:DamageEntityListener.java

示例6: onPlayerDamaged

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Listener
public void onPlayerDamaged(DamageEntityEvent event)
{
	if (event.getTargetEntity() instanceof Player)
	{
		Player player = (Player) event.getTargetEntity();

		if (Utils.isTeleportCooldownEnabled() && EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
		{
			EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
			player.sendMessage(Text.of(TextColors.RED, "Teleportation canceled due to damage."));
		}

		if (EssentialCmds.godPlayers.contains(player.getUniqueId()))
		{
			event.setBaseDamage(0);
			event.setCancelled(true);
		}
	}
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:21,代码来源:PlayerDamageListener.java

示例7: onPlayerDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Listener
public void onPlayerDamage(DamageEntityEvent event) {

    Entity entity = event.getTargetEntity();
    if (!(entity instanceof Player)) {
        return;
    }
    Player player = (Player) entity;

    if (!event.willCauseDeath()) {
        return;
    }

    for (SurvivalGame survivalGame : SurvivalGameRepository.values()) {
        if (survivalGame.getPlayerUUIDs().contains(player.getUniqueId())) {
            performDeadPlayer(survivalGame, player, event.getCause());
            event.setCancelled(true);
            break;
        }
    }
}
 
开发者ID:m0pt0pmatt,项目名称:SurvivalGames,代码行数:22,代码来源:PlayerDeathListener.java

示例8: onFrameAndBoatBrake

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFrameAndBoatBrake(DamageEntityEvent e) {
	
	RedProtect.get().logger.debug("blocks","Is BlockListener - DamageEntityEvent event");
	Entity ent = e.getTargetEntity();
	Location<World> l = e.getTargetEntity().getLocation();
	    
	Region r = RedProtect.get().rm.getTopRegion(l);
	
	if (ent instanceof Hanging && e.getCause().first(Monster.class).isPresent()) {    		
		if (r != null && !r.canFire()){
			e.setCancelled(true);
    		return;
		}
    }   
	
	if (ent instanceof Boat && e.getCause().first(Player.class).isPresent()){
		Player p = e.getCause().first(Player.class).get();
		if (!r.canMinecart(p)){
			RPLang.sendMessage(p, "blocklistener.region.cantbreak");
			e.setCancelled(true);
        }
	}
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:25,代码来源:RPBlockListener.java

示例9: testDynamicListener

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Test
public void testDynamicListener() throws Exception {
	Class.forName("jdk.nashorn.api.scripting.NashornScriptEngineFactory");
	ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine();
	ClassGenerator classGenerator = new ClassGenerator();
	try (InputStreamReader rs = new InputStreamReader(new FileInputStream(new File("./src/main/test/testfiles/js/eventgen/test.js")))) {
		engine.eval(rs);
		HashMap map = (HashMap) engine.get("events");
		Object o = classGenerator.generateDynamicListener(map);
		DamageEntityEvent mock = mock(DamageEntityEvent.class);
		o.getClass().getMethod("onDamageEntityEvent", DamageEntityEvent.class).invoke(o, mock);
		MoveEntityEvent mock2 = mock(MoveEntityEvent.class);
		o.getClass().getMethod("onDisplaceEntityEvent", MoveEntityEvent.class).invoke(o, mock2);
	} catch (ScriptException | IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:18,代码来源:Tests.java

示例10: onEntityDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onEntityDamage(DamageEntityEvent event) {
	if (event.isCancelled() || event.getFinalDamage() == 0) {
		return;
	}
	if (event.getTargetEntity().getType() == EntityTypes.PLAYER) {
		UUID id = event.getTargetEntity().getUniqueId();
		IActiveCharacter character = characterService.getCharacter(id);
		IEffectContainer container = character.getEffect(name);
		if (container == null)
			return;
		if (!event.getCause().first(SoulBindEffect.class).isPresent()) {
			event.setBaseDamage(event.getBaseDamage() * .5);
			SoulBindEffect effect = (SoulBindEffect) container;
			SkillDamageSourceBuilder builder = new SkillDamageSourceBuilder();

			if (effect.getConsumer() == character) {
				effect.getTarget().getEntity().damage(event.getBaseDamage(), builder.build());
			} else {
				effect.getConsumer().getEntity().damage(event.getBaseDamage(), builder.build());
			}
		}
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:25,代码来源:SkillSoulbind.java

示例11: onEntityDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的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

示例12: run

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Override
public void run(Living owner, Living attacker, DamageEntityEvent event) {
  notify(owner, Text.of(TextColors.YELLOW, "Your armor releases a burst of energy."));
  notify(owner, Text.of(TextColors.YELLOW, "You are healed by an ancient force."));

  final double attackDamage = event.getBaseDamage();
  EntityHealthUtil.heal(owner, attackDamage);

  getTargetEntities(owner).stream().filter(e -> e instanceof Living).forEach(e -> {
    if (e.equals(owner)) {
      return;
    }

    if (e.getType() == owner.getType()) {
      EntityHealthUtil.heal((Living) e, attackDamage);
      notify((Living) e, Text.of(TextColors.YELLOW, "You are healed by an ancient force."));
    } else if (!(owner instanceof Player) || e instanceof Monster) {
      e.setVelocity(new Vector3d(
          Probability.getRangedRandom(-1.5, 1.5),
          Probability.getRandom(2.5),
          Probability.getRangedRandom(-1.5, 1.5)
      ));
      e.offer(Keys.FIRE_TICKS, Probability.getRandom(20 * 60));
    }
  });
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:27,代码来源:PowerBurst.java

示例13: run

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
  int duration = (int) (EntityHealthUtil.getHealth(owner) * 20);

  Optional<PotionEffectData> optPotionEffectData = target.getOrCreate(PotionEffectData.class);
  if (optPotionEffectData.isPresent()) {
    PotionEffectData potionEffectData = optPotionEffectData.get();

    potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.BLINDNESS, 1, duration));

    target.offer(potionEffectData);
  }

  target.offer(Keys.FIRE_TICKS, duration);

  notify(owner, Text.of(TextColors.YELLOW, "Your sword releases a deadly blaze."));
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:18,代码来源:FearBlaze.java

示例14: run

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
  int duration = (int) Math.min(20 * 60 * 5, EntityHealthUtil.getHealth(owner) * 18);

  Optional<PotionEffectData> optOwnerPotionEffectData = owner.getOrCreate(PotionEffectData.class);
  if (optOwnerPotionEffectData.isPresent()) {
    PotionEffectData ownerPotionEffectData = optOwnerPotionEffectData.get();
    ownerPotionEffectData.addElement(PotionEffect.of(PotionEffectTypes.SPEED, 2, duration));
    owner.offer(ownerPotionEffectData);
  }

  Optional<PotionEffectData> optTargetPotionEffectData = target.getOrCreate(PotionEffectData.class);
  if (optTargetPotionEffectData.isPresent()) {
    PotionEffectData targetPotionEffectData = optTargetPotionEffectData.get();
    targetPotionEffectData.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 2, duration));
    target.offer(targetPotionEffectData);
  }

  if (optOwnerPotionEffectData.isPresent() || optTargetPotionEffectData.isPresent()) {
    notify(owner, Text.of(TextColors.YELLOW, "You gain an agile advantage over your opponent."));
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:23,代码来源:Agility.java

示例15: run

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
  Optional<PotionEffectData> optPotionEffectData = target.getOrCreate(PotionEffectData.class);
  if (!optPotionEffectData.isPresent()) {
    return;
  }

  PotionEffectData potionEffectData = optPotionEffectData.get();

  int duration = (int) (EntityHealthUtil.getHealth(owner) * 18);
  potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 2, duration));
  potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.WEAKNESS, 2, duration));

  target.offer(potionEffectData);

  notify(owner, Text.of(TextColors.YELLOW, "Your bow slows its victim."));
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:18,代码来源:MagicChain.java


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