本文整理汇总了Java中org.bukkit.event.entity.EntityDamageEvent.DamageCause类的典型用法代码示例。如果您正苦于以下问题:Java DamageCause类的具体用法?Java DamageCause怎么用?Java DamageCause使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DamageCause类属于org.bukkit.event.entity.EntityDamageEvent包,在下文中一共展示了DamageCause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EntityDamageByEntityListener
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void EntityDamageByEntityListener(EntityDamageByEntityEvent e) {
if (!GameManager.getGameSituation()) {
e.setCancelled(true);
}
if (e.getDamager() instanceof Player) {
if (e.getEntity() instanceof Player) {
Player damager = (Player) e.getDamager();
Player victim = (Player) e.getEntity();
if (SettingsManager.shotinfo) {
if (e.getCause() == DamageCause.PROJECTILE) {
if(victim.getLocation().distance(damager.getLocation()) < 20) {
Bukkit.broadcastMessage(SettingsManager.niceshot.replace("%s", victim.getName()).replace("%s", damager.getName()).replace("%d", String.valueOf(victim.getLocation().distance(damager.getLocation()))));
}
}
}
}
}
}
示例2: call
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@Override
public void call(Event event) {
if (event instanceof EntityDamageEvent) {
final EntityDamageEvent ede = (EntityDamageEvent) event;
final DamageCause cause = ede.getCause();
if (cause == DamageCause.FIRE || cause == DamageCause.CONTACT) {
final Player player = profile.getPlayer();
if (cause == DamageCause.FIRE && player.getFoodLevel() < 20) {
// The AntiFire cheat only works when the hunger bar is
// full.
return;
}
final double previousHealth = player.getHealth();
// Check a little later.
Bukkit.getScheduler().runTaskLater(Crescent.getInstance(), () -> {
if (player.getHealth() > previousHealth - ede.getDamage()) {
callback(true);
}
}, 2L);
}
}
}
示例3: inflictDamage
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
/**
* Inflicts the given damage on an entity.
*
* This method will call the appropriate damage method and fire an {@link EntityDamageEvent}.
*
* @param entity Entity to inflict damage upon
* @param damage Amount of half-hearts of damage to inflict
* @param info {@link DamageInfo} object that details the type of damage
* @return the final {@link Damage} object (never null)
*
* @throws NullPointerException if entity or info is null
* throws IllegalArgumentExcpetion if hearts is less than zero
*/
public static @Nonnull
Damage inflictDamage(@Nonnull LivingEntity entity, int damage, @Nonnull DamageInfo info) {
Preconditions.checkNotNull(entity, "living entity");
Preconditions.checkArgument(damage >= 0, "damage must be greater than or equal to zero");
Preconditions.checkNotNull(info, "damage info");
DamageAPIHelper helper = DamageAPIHelper.get();
EntityDamageEvent event = new EntityDamageEvent(entity, DamageCause.CUSTOM, damage);
helper.setEventDamageInfo(event, info);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
return null;
}
entity.damage(event.getDamage());
helper.setEventDamageInfo(event, null);
return helper.getOurEvent(event).toDamageObject();
}
示例4: resolve
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(damageEvent instanceof EntityDamageByEntityEvent && damageEvent.getCause() == DamageCause.ENTITY_ATTACK) {
EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) damageEvent;
if(entityEvent.getDamager() instanceof LivingEntity) {
LivingEntity attacker = (LivingEntity) entityEvent.getDamager();
Material weaponMaterial;
ItemStack held = attacker.getEquipment().getItemInMainHand();
if(held != null) {
weaponMaterial = held.getType();
} else {
weaponMaterial = Material.AIR;
}
return new SimpleMeleeDamageInfo(attacker, weaponMaterial);
}
}
return null;
}
示例5: callEntityDamageEvent
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) {
EntityDamageEvent event;
if (damager != null) {
event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
} else {
event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
}
callEvent(event);
if (!event.isCancelled()) {
event.getEntity().setLastDamageCause(event);
}
return event;
}
示例6: onItemDamage
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void onItemDamage(EntityDamageEvent event) {
if (event.getEntityType() == EntityType.DROPPED_ITEM && (event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.FIRE_TICK || event.getCause() == DamageCause.FIRE)) {
Vector v = Vector.getRandom().normalize();
v = v.setX(v.getX() - 0.5f);
v = v.setZ(v.getZ() - 0.5f);
v = v.multiply(0.35);
if (v.getX() > 0 && v.getX() < 0.10)
v.setX(0.10);
if (v.getZ() > 0 && v.getZ() < 0.10)
v.setZ(0.10);
if (v.getX() < 0 && v.getX() > -0.10)
v.setX(-0.10);
if (v.getZ() < 0 && v.getZ() > -0.10)
v.setZ(-0.10);
v.setY(0.3);
event.getEntity().setVelocity(v);
event.setCancelled(true);
RScheduler.schedule(plugin, () -> {
event.getEntity().setFireTicks(0);
}, RTicks.seconds(1));
}
if (event.getEntityType() == EntityType.ARMOR_STAND && (event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.FIRE_TICK || event.getCause() == DamageCause.FIRE)) {
event.setCancelled(true);
}
}
示例7: parse
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
public static DisableDamageModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
SetMultimap<DamageCause, PlayerRelation> causes = HashMultimap.create();
for(Element damageCauseElement : doc.getRootElement().getChildren("disabledamage")) {
for(Element damageEl : damageCauseElement.getChildren("damage")) {
DamageCause cause = XMLUtils.parseEnum(damageEl, DamageCause.class, "damage type");
for(PlayerRelation damagerType : PlayerRelation.values()) {
// Legacy syntax used "other" instead of "neutral"
String attrName = damagerType.name().toLowerCase();
Node attr = damagerType == PlayerRelation.NEUTRAL ? Node.fromAttr(damageEl, attrName, "other")
: Node.fromAttr(damageEl, attrName);
if(XMLUtils.parseBoolean(attr, true)) {
causes.put(cause, damagerType);
// Bukkit 1.7.10 changed TNT from BLOCK_EXPLOSION to ENTITY_EXPLOSION,
// so we include them both to keep old maps working.
if(cause == DamageCause.BLOCK_EXPLOSION) {
causes.put(DamageCause.ENTITY_EXPLOSION, damagerType);
}
}
}
}
}
return new DisableDamageModule(causes);
}
示例8: onAttack
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
if(event.isCancelled()) return;
if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
{
Player player = (Player)event.getDamager();
ItemStack mainItem = player.getInventory().getItemInMainHand();
LivingEntity enemy = (LivingEntity)event.getEntity();
if(mainItem.getType() == Material.GOLD_SPADE)
{
enemy.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 100, 0, false));
enemy.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 0, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 48, 2, true));
Location particleLoc = player.getLocation();
particleLoc.setY(particleLoc.getY() + 2);
ParticleEffect.HEART.display(0.5f, 0, 0.5f, 1, 2, particleLoc, 64);
}
}
}
示例9: onAttack
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
if(event.isCancelled()) return;
if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
{
Player player = (Player)event.getDamager();
ItemStack mainItem = player.getInventory().getItemInMainHand();
LivingEntity enemy = (LivingEntity)event.getEntity();
Random rand = new Random();
if(mainItem.getType() == Material.GOLD_AXE)
{
enemy.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 480, 2, false));
enemy.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 480, 0, false));
enemy.getLocation().getWorld().playSound(enemy.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
}
}
}
示例10: onEntityDamage
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageEvent e) {
Entity ent = e.getEntity();
if(ent instanceof Player) {
if (!hasIgnorePermission((Player) ent)) {
if (inLobbyWorld((Player) ent) && SkyWarsReloaded.getCfg().LobbyFallDamageDisabled()) {
if (e.getCause().equals(DamageCause.FALL)) {
e.setCancelled(true);
}
}
if (inLobbyWorld((Player) ent) && SkyWarsReloaded.getCfg().damageDisabled()) {
if (!e.getCause().equals(DamageCause.VOID)) {
e.setCancelled(true);
}
}
}
}
}
示例11: damage
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@Override
public void damage(double amount)
{
Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class);
modifiers.put(DamageModifier.BASE, 1.0);
Map<DamageModifier, Function<Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class);
modifierFunctions.put(DamageModifier.BASE, damage -> damage);
EntityDamageEvent event = new EntityDamageEvent(this, DamageCause.CUSTOM, modifiers, modifierFunctions);
event.setDamage(amount);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled())
{
setHealth(health - amount);
}
}
示例12: Stomper
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void Stomper(EntityDamageEvent e) {
if (e.getEntity() instanceof Player) {
Player p = (Player) e.getEntity();
if (Kit.getKit(p).getName().equalsIgnoreCase("stomper")) {
if (e.getCause() == DamageCause.FALL) {
List<Entity> nearbyEntities = e.getEntity()
.getNearbyEntities(5, 5, 5);
for (Entity target : nearbyEntities) {
if (target instanceof Player) {
Player t = (Player) target;
if (Team.getTeam(p) == Team.getTeam(t))
continue;
if (t.isSneaking())
t.damage(e.getDamage() / 2, e.getEntity());
else
t.damage(e.getDamage(), e.getEntity());
}
}
e.setDamage(0);
}
}
}
}
示例13: onPlayerDamage
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player))
return;
event.setCancelled(true);
if (event.getCause()==DamageCause.VOID) {
Location l = event.getEntity().getWorld().getSpawnLocation();
l.setX(14.5);
l.setY(10.5);
l.setZ(-795.5);
l.setPitch(0.5F);
l.setYaw(90 * RandomUtil.between(1, 4));
event.getEntity().teleport(l);
}
}
示例14: onCancell
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void onCancell(EntityDamageEvent event){
Entity e = event.getEntity();
if(!(e instanceof Player)){
return;
}
Player p = (Player)e;
Arena a = new ArenaManager().getArena(p);
if(a==null){
event.setCancelled(true);
return;
}
if(a.isEnd()){
event.setCancelled(true);
}
if(a.fallMode()==true){
if(event.getCause() == DamageCause.FALL||event.getCause() == DamageCause.VOID){
event.setCancelled(true);
}
}
}
示例15: onAthenaDeath
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
/**
* Suppress regular death messages, replacing them with custom ones local to the player's Match
*/
@EventHandler
public void onAthenaDeath(AthenaDeathEvent event) {
DamageCause cause = event.getPlayer().getLastDamageCause().getCause();
if (event.isPvP()) {
switch (cause) {
case FALL:
handleGroundFall(event);
break;
case PROJECTILE:
handleProjectile(event);
break;
case VOID:
handleVoid(event);
break;
default:
broadcast(event, event.getDeathEvent().getDeathMessage());
}
} else {
broadcast(event, event.getDeathEvent().getDeathMessage());
}
event.getDeathEvent().setDeathMessage(null); //disable vanilla death broadcast
}