本文整理汇总了Java中org.bukkit.event.entity.EntityDeathEvent类的典型用法代码示例。如果您正苦于以下问题:Java EntityDeathEvent类的具体用法?Java EntityDeathEvent怎么用?Java EntityDeathEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityDeathEvent类属于org.bukkit.event.entity包,在下文中一共展示了EntityDeathEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MagicMobDeathEvent
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
public MagicMobDeathEvent(MageController controller, EntityData entityData, EntityDeathEvent deathEvent) {
this.controller = controller;
this.entityData = entityData;
this.deathEvent = deathEvent;
LivingEntity killed = deathEvent.getEntity();
EntityDamageEvent damageEvent = killed.getLastDamageCause();
if (damageEvent instanceof EntityDamageByEntityEvent)
{
EntityDamageByEntityEvent damageByEvent = (EntityDamageByEntityEvent)damageEvent;
Entity damagingEntity = damageByEvent.getDamager();
if (damagingEntity instanceof Projectile) {
Projectile projectile = (Projectile)damagingEntity;
damagingEntity = (LivingEntity)projectile.getShooter();
}
if (damagingEntity != null && damagingEntity instanceof Player)
{
player = (Player)damagingEntity;
mage = controller.getRegisteredMage(player.getUniqueId().toString());
}
}
}
示例2: onEndermanDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
/**
* Drops the Enderman's block when he dies if he has one
*
* @param e
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEndermanDeath(final EntityDeathEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (!Settings.endermanDeathDrop)
return;
if (!Util.inWorld(e.getEntity())) {
return;
}
if (!(e.getEntity() instanceof Enderman)) {
// plugin.getLogger().info("Not an Enderman!");
return;
}
// Get the block the enderman is holding
Enderman ender = (Enderman) e.getEntity();
MaterialData m = ender.getCarriedMaterial();
if (m != null && !m.getItemType().equals(Material.AIR)) {
// Drop the item
// plugin.getLogger().info("Dropping item " + m.toString());
e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), m.toItemStack(1));
}
}
示例3: onMobDie
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@EventHandler
public void onMobDie(EntityDeathEvent e){
AllItems items = new AllItems();
Location l = e.getEntity().getLocation();
World w = l.getWorld();
e.getDrops().clear();
e.setDroppedExp(0);
if (e.getEntity() instanceof Zombie){
if (new Random().nextInt(5) >= 3){
w.dropItemNaturally(l, new ItemMaker(Material.EMERALD).setAmount(new Random().nextInt(4) + 1).build());
if (new Random().nextBoolean()){
w.dropItemNaturally(l, items.weapons.get(new Random().nextInt(items.weapons.size())));
} else {
w.dropItemNaturally(l, items.health.get(new Random().nextInt(items.health.size())));
}
}
}
if (e.getEntity() instanceof Giant){
if (new Random().nextInt(5) > 3){
w.dropItemNaturally(l, new ItemMaker(Material.NETHER_STAR).setAmount(new Random().nextInt(4) + 1).build());
}
}
}
示例4: onEntityDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
/**
* Utilizes a random chance to either spawn a skeleton with gold armor or resources.
*
* @param event The event
*/
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Sheep) {
double chance = Math.random();
if (0.25 > chance) {
Skeleton skeleton = entity.getWorld().spawn(entity.getLocation(), Skeleton.class);
skeleton.getEquipment().setArmorContents(
new ItemStack[]{
new ItemStack(Material.GOLD_HELMET),
new ItemStack(Material.GOLD_CHESTPLATE),
new ItemStack(Material.GOLD_LEGGINGS),
new ItemStack(Material.GOLD_BOOTS)
}
);
} else if (0.5 > chance) {
event.getDrops().add(new ItemStack(Material.IRON_INGOT));
} else if (0.75 > chance) {
event.getDrops().add(new ItemStack(Material.GOLD_INGOT));
} else {
event.getDrops().add(new ItemStack(Material.DIAMOND));
}
}
}
示例5: onEntityDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
/**
* Drop cooked food
*
* @param event Event
*/
@EventHandler
public void onEntityDeath(EntityDeathEvent event)
{
LivingEntity entity = event.getEntity();
List<ItemStack> newDrops = null;
if (this.drops.containsKey(entity.getType()))
{
newDrops = new ArrayList<>();
for (ConfigurationBuilder.IRapidFoodHook rapidFoodHook : this.drops.get(entity.getType()))
newDrops.addAll(rapidFoodHook.getDrops(event.getDrops(), this.random));
}
if (newDrops != null && !newDrops.isEmpty())
{
event.getDrops().clear();
event.getDrops().addAll(newDrops);
}
event.setDroppedExp(event.getDroppedExp() * 2);
}
示例6: onEntityDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@EventHandler
public void onEntityDeath(EntityDeathEvent evt) { // If a pinata is killed, have a 12% chance of dropping something extra.
if (evt.getEntity() instanceof Zombie && getArena().contains(evt.getEntity().getLocation()) && Utils.randChance(8))
evt.getDrops().add(Utils.randElement(
ItemManager.createItem(Material.DIAMOND, ChatColor.AQUA + "Rock Candy", "So delicious, so rare."),
ItemManager.createItem(Material.CAKE, ChatColor.LIGHT_PURPLE + "Birthday Cake", "Happy 3rd Anniversary, Kineticraft!"),
ItemManager.createItem(Material.SEA_LANTERN, ChatColor.RED + "Jaw Breaker", "Suck it, Piñatas!"),
ItemManager.createItem(Material.IRON_BLOCK, ChatColor.RED + "Hershey's Kiss", "Mmmm, so chocolatey."),
ItemManager.createItem(Material.TNT, ChatColor.LIGHT_PURPLE + "Pop Rocks", "An explosion for your taste buds."),
ItemManager.createItem(Material.MAGMA_CREAM, ChatColor.RED + "Atomic Fireball", "It burns so good."),
ItemManager.createItem(Material.EXP_BOTTLE, ChatColor.AQUA + "Soda", "Refreshing and fizzy."),
ItemManager.createItem(Material.SLIME_BALL, ChatColor.AQUA + "Taffy", "Chewy...careful not to glue your teeth together!"),
ItemManager.createItem(Material.NETHER_STALK, ChatColor.RED + "Twizzlers", "Gimme some sugar."),
ItemManager.createItem(Material.MYCEL, ChatColor.RED + "Fudge", "What the fudge!?"),
ItemManager.createItem(Material.WEB, ChatColor.LIGHT_PURPLE + "Cotton Candy", "So fluffy!"),
ItemManager.createItem(Material.RAW_FISH, (byte) 1, ChatColor.LIGHT_PURPLE + "Swedish Fish", "A yummy, gummy candy."),
ItemManager.createItem(Material.RED_ROSE, (byte) 2, ChatColor.AQUA + "Lollipop", "I'm a sucker for puns."),
ItemManager.createItem(Material.COOKIE, ChatColor.YELLOW + "Birthday Cookie", "You're one smart cookie!"),
ItemManager.createItem(Material.BLAZE_ROD, ChatColor.RED + "Hot Tamale", "You're one hot Tamale!"),
ItemManager.createItem(Material.PUMPKIN_PIE, ChatColor.GOLD + "Seasonal Treat", "Pumpkin Spice flavor ALL THE THINGS!"),
ItemManager.createItem(Material.EMERALD, ChatColor.GREEN + "Gumball", "I chews you! <3"),
ItemManager.createItem(Material.GOLDEN_APPLE, ChatColor.GOLD + "Caramel Apple", "...and we lived apple-y ever after <3"),
ItemManager.createItem(Material.HUGE_MUSHROOM_2, ChatColor.RED + "Strawberry Bon Bon", "You're the berry best."),
evt.getEntity().getEquipment().getHelmet(),
evt.getEntity().getEquipment().getItemInMainHand()));
}
示例7: onEntityDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onEntityDeath(EntityDeathEvent event) {
double amount = event.getDroppedExp();
Player killer = event.getEntity().getKiller();
if (killer != null && amount > 0) {
ItemStack stack = killer.getItemInHand();
if (stack != null && stack.getType() != Material.AIR) {
int enchantmentLevel = stack.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS);
if (enchantmentLevel > 0L) {
double multiplier = enchantmentLevel * SettingsYML.EXP_MULTIPLIER_LOOTING_PER_LEVEL;
int result = (int) Math.ceil(amount * multiplier);
event.setDroppedExp(result);
}
}
}
}
示例8: onEntityDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@EventHandler
public void onEntityDeath(EntityDeathEvent e) {
if (e.getEntity() instanceof Monster && e.getEntity().getKiller() instanceof Player) {
TOAUser u = TOA.getPlayer(e.getEntity().getKiller());
String name = e.getEntity().getCustomName().split(" ")[1];
int level = Utils.isInt(name) ? Integer.parseInt(name) : 0;
new Experience(u).addExp(Mob.getXP(level));
e.getDrops().clear();
e.setDroppedExp(0);
Drop.drop(MobType.parseMobType(e.getEntityType()), u.getUserData().getKit()).forEach(d -> {
BagEvents.addItem(u, d);
u.sendSound(Sounds.ITEM_PICKUP);
});
if (plugin.getSpawnTask().getCount() == 0) return;
plugin.getSpawnTask().setCount(plugin.getSpawnTask().getCount() - 1);
}
}
示例9: onMobDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@EventHandler
public void onMobDeath(EntityDeathEvent event) {
if(event.getEntity() instanceof Entity){
Entity e = (Entity) event.getEntity();
if(e.hasMetadata("challenge")){
event.getDrops().clear();
String[] meta = e.getMetadata("challenge").get(0).asString().split(", ");
final String player = meta[1];
plugin.getChallenges().addKill(Bukkit.getPlayer(player));
Bukkit.getPlayer(player).setLevel(plugin.getChallenges().getKillsLeft(Bukkit.getPlayer(player)));
if(e.getType().equals(EntityType.MAGMA_CUBE) || e.getType().equals(EntityType.SLIME)) {
e.remove();
}
if(plugin.getChallenges().getKillsLeft(Bukkit.getPlayer(player)) == 0){
plugin.getChallenges().finishChallenge(Bukkit.getPlayer(player), false);
}
}
}
}
示例10: onDragonDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@EventHandler
public void onDragonDeath(EntityDeathEvent event) {
if (!(event.getEntity() instanceof EnderDragon)) return;
EnderDragon dragon = (EnderDragon) event.getEntity();
DragonBattle dragonBattle = plugin.getNMSAbstract().getEnderDragonBattleFromDragon(dragon);
World world = event.getEntity().getWorld();
EndWorldWrapper worldWrapper = plugin.getDEDManager().getWorldWrapper(world);
BattleStateChangeEvent bscEventCrystals = new BattleStateChangeEvent(dragonBattle, dragon, BattleState.BATTLE_COMMENCED, BattleState.BATTLE_END);
Bukkit.getPluginManager().callEvent(bscEventCrystals);
new BukkitRunnable() {
@Override
public void run() {
if (plugin.getNMSAbstract().getEnderDragonDeathAnimationTime(dragon) >= 185) { // Dragon is dead at 200
new DragonDeathRunnable(plugin, worldWrapper, dragon);
this.cancel();
}
}
}.runTaskTimer(plugin, 0L, 1L);
}
示例11: kill
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void kill(EntityDeathEvent e) {
// 殺されたエンティティ
LivingEntity entity = e.getEntity();
// エンティティを殺したプレイヤー
Player player = entity.getKiller();
// null=プレイヤーが殺したのではないなら
if (player == null) {
return; // 何もしない
}
// 出力する
player.sendMessage("このMOBはスポナーから沸いたMOB" +
(isSpawnerSpawn(entity) ? "です。" : "ではありません。")); // <-三項演算子、説明は要らないよね?
}
示例12: getAttacker
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
private static Object getAttacker(final Event e) {
if (e instanceof EntityDamageByEntityEvent) {
if (((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
return ((Projectile) ((EntityDamageByEntityEvent) e).getDamager()).getShooter();
}
return ((EntityDamageByEntityEvent) e).getDamager();
} else if (e instanceof EntityDamageByBlockEvent) {
return ((EntityDamageByBlockEvent) e).getDamager();
} else if (e instanceof EntityDeathEvent) {
return getAttacker(((EntityDeathEvent) e).getEntity().getLastDamageCause());
} else if (e instanceof VehicleDamageEvent) {
return ((VehicleDamageEvent) e).getAttacker();
} else if (e instanceof VehicleDestroyEvent) {
return ((VehicleDestroyEvent) e).getAttacker();
}
return null;
}
示例13: init
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
if (!ScriptLoader.isCurrentEvent(EntityDamageEvent.class, EntityDeathEvent.class)) {
Skript.error("The expression 'victim' can only be used in a damage or death event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
final String type = parser.regexes.size() == 0 ? null : parser.regexes.get(0).group();
if (type == null) {
this.type = EntityData.fromClass(Entity.class);
} else {
final EntityData<?> t = EntityData.parse(type);
if (t == null) {
Skript.error("'" + type + "' is not an entity type", ErrorQuality.NOT_AN_EXPRESSION);
return false;
}
this.type = t;
}
return true;
}
示例14: getAttacker
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@Nullable
private static Entity getAttacker(final @Nullable Event e) {
if (e == null)
return null;
if (e instanceof EntityDamageByEntityEvent) {
if (((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
final Object o = ProjectileUtils.getShooter((Projectile) ((EntityDamageByEntityEvent) e).getDamager());
if (o instanceof Entity)
return (Entity) o;
return null;
}
return ((EntityDamageByEntityEvent) e).getDamager();
// } else if (e instanceof EntityDamageByBlockEvent) {
// return ((EntityDamageByBlockEvent) e).getDamager();
} else if (e instanceof EntityDeathEvent) {
return getAttacker(((EntityDeathEvent) e).getEntity().getLastDamageCause());
} else if (e instanceof VehicleDamageEvent) {
return ((VehicleDamageEvent) e).getAttacker();
} else if (e instanceof VehicleDestroyEvent) {
return ((VehicleDestroyEvent) e).getAttacker();
}
return null;
}
示例15: onEntityDeath
import org.bukkit.event.entity.EntityDeathEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDeath(EntityDeathEvent event) {
Entity killedEntity = event.getEntity();
if (killedEntity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity)killedEntity;
Player killer = livingEntity.getKiller();
if (killer != null && getPlayer() == killer) {
if (entityIds.contains(EntityUtilities.getEntityId(livingEntity)) &&
(getZone() == null || getZone().isInside(livingEntity.getLocation()))) {
advance();
}
}
}
}