本文整理汇总了Java中org.bukkit.event.entity.EntityDamageByEntityEvent.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java EntityDamageByEntityEvent.setCancelled方法的具体用法?Java EntityDamageByEntityEvent.setCancelled怎么用?Java EntityDamageByEntityEvent.setCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.entity.EntityDamageByEntityEvent
的用法示例。
在下文中一共展示了EntityDamageByEntityEvent.setCancelled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EntityDamageByEntityListener
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的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: onEntityDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player == false)
return;
PetInstance pet = PetInstance.get(event.getEntity());
if (pet == null)
return;
event.setCancelled(true);
if (pet.getOwner().equalsIgnoreCase(((Player) event.getDamager()).getName())) {
Chat.player((Player) event.getDamager(), "&2[Pets] &aYou have removed your pet. Spawn it with &b/pet spawn");
pet.despawn();
pet.setToSpawn(false);
}
else {
Chat.player((Player) event.getDamager(), "&2[Pets] &cBuy pets at www.mczone.co/shop");
}
}
示例3: onDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Player player = (Player) event.getEntity();
Player damager = (Player) event.getDamager();
Profile playerProfile = Chambers.getInstance().getProfileManager().getProfileByUuid(player.getUniqueId());
Profile damagerProfile = Chambers.getInstance().getProfileManager().getProfileByUuid(damager.getUniqueId());
if (playerProfile.getTeam() == null || damagerProfile.getTeam() == null || playerProfile.getProfileStatus() != ProfileStatus.PLAYING || damagerProfile.getProfileStatus() != ProfileStatus.PLAYING) {
event.setCancelled(true);
damager.sendMessage(ChatColor.RED + "You cannot do this in your current state.");
return;
}
if (playerProfile.getTeam() == damagerProfile.getTeam()) {
event.setCancelled(true);
damager.sendMessage(ChatColor.YELLOW + "You cannot hurt " + damagerProfile.getTeam().getColor() + player.getName() + ChatColor.YELLOW + ".");
}
}
}
示例4: onPvP
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onPvP(EntityDamageByEntityEvent evt) {
if (Parties.isParty(evt.getDamager()))
return;
Player attacker = evt.getDamager() instanceof Player ? (Player) evt.getDamager() :
(evt.getDamager() instanceof Projectile && ((Projectile) evt.getDamager()).getShooter() instanceof Player
? (Player) ((Projectile) evt.getDamager()).getShooter() : null); // Yuck, maybe we can make a method for this later.
if (attacker == null || !(evt.getEntity() instanceof Player))
return; // One or both of the combatants isn't a player.
boolean outgoingFail = !getToggle(attacker, Toggle.PVP);
boolean incomingFail = !getToggle(evt.getEntity(), Toggle.PVP);
if (outgoingFail || incomingFail) {
attacker.sendMessage(ChatColor.RED + (outgoingFail ? "You have PvP disabled. (/togglepvp)"
: evt.getEntity().getName() + " has PvP disabled."));
evt.setCancelled(true);
evt.getEntity().setFireTicks(-1); // Disable fire damage.
}
}
示例5: onAttack
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onAttack(EntityDamageByEntityEvent e) {
if(!(e.getEntity() instanceof Player)) return;
if(e.getDamager() instanceof Player || e.getDamager() instanceof Projectile) {
if(mayPvP) {
if(e.getDamager() instanceof Projectile) {
handleShooting(e);
} else {
handleMelee(e);
}
} else {
e.setCancelled(true);
return;
}
} else {
return;
}
}
示例6: ArmorStandDestroy
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void ArmorStandDestroy(EntityDamageByEntityEvent e) {
if (DEBUG) {
plugin.getLogger().info("1.8 " + "IslandGuard New " + e.getEventName());
}
if (!(e.getEntity() instanceof LivingEntity)) {
return;
}
if (!Util.inWorld(e.getEntity())) {
return;
}
final LivingEntity livingEntity = (LivingEntity) e.getEntity();
if (!livingEntity.getType().equals(EntityType.ARMOR_STAND)) {
return;
}
if (e.getDamager() instanceof Player) {
Player p = (Player) e.getDamager();
if (p.isOp() || VaultHelper.hasPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
// Check if on island
if (plugin.getIslands().playerIsOnIsland(p)) {
return;
}
// Check island
Island island = plugin.getIslands().getIslandAt(e.getEntity().getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
}
if (island != null && island.getFlag(SettingsFlag.BREAK_BLOCKS)) {
return;
}
Util.sendMessage(p, plugin.getLocale(p.getUniqueId()).get("island.protected"));
e.setCancelled(true);
}
}
示例7: onEntityDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
e.setCancelled(true);
if(e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
GamePlayer damager = Absorption.getPlayer((Player) e.getDamager());
GamePlayer player = Absorption.getPlayer((Player) e.getEntity());
if(damager == null || player == null) return;
player.hitByPlayer(damager);
}
}
示例8: onEntityDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof EnderCrystal) || event.getEntity().getWorld().getEnvironment() != Environment.THE_END
|| !entity.isInvulnerable()) return;
event.setCancelled(true);
}
示例9: onDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onDamageByEntity(EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Game game = Chambers.getInstance().getGameManager().getGame();
if (game.getInvincibilityTime() > 0) {
Player damager = (Player) event.getDamager();
damager.sendMessage(ChatColor.RED + "The invincibility timer is still on.");
event.setCancelled(true);
}
}
}
示例10: onDamage
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
// Cancelling team damage
if(event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
Player victim = (Player) event.getEntity();
Player damager = (Player) event.getDamager();
if(!Utility.canAttack(victim, damager)){
event.setCancelled(true);
}
}
}
示例11: onEntityDamageEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
Entity ent = e.getEntity();
Entity damager = e.getDamager();
if(ent instanceof Player && damager instanceof Player) {
if (!hasIgnorePermission((Player) damager)) {
if (inLobbyWorld((Player) ent) && SkyWarsReloaded.getCfg().pvpDisabled()) {
e.setCancelled(true);
}
}
}
}
示例12: onItemFrameAttack
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true) // Prevent hitting item frames.
public void onItemFrameAttack(EntityDamageByEntityEvent evt) {
evt.setCancelled(evt.getEntity() instanceof ItemFrame && preventEdit(evt.getDamager()));
}
示例13: customDeath
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.HIGHEST)
public void customDeath(EntityDamageByEntityEvent e){
if(e.isCancelled())return;
if(e.getEntity() instanceof Player && e.getDamager() instanceof Player){
Player p = (Player) e.getEntity();
if(e.getFinalDamage() >= p.getHealth()){
Player killer = (Player) e.getDamager();
String uuid2 = killer.getUniqueId().toString();
e.setCancelled(true);
if(! p.getName().equals(killer.getName())){ // if they were killed by someone else, not themselves
setTokens(uuid2, getTokens(uuid2)+2);
killer.sendMessage(tag + ChatColor.BLUE + "You have received " + ChatColor.GOLD + "2" +
ChatColor.BLUE + " tokens for killing " + p.getName());
}
Bukkit.getServer().broadcastMessage(ChatColor.GRAY + killer.getName() + " destroyed " + p.getName());
// Set statistics
//killer.setStatistic(Statistic.KILL_ENTITY, killer.getStatistic(Statistic.KILL_ENTITY) + 1);
//p.setStatistic(Statistic.DEATHS, p.getStatistic(Statistic.DEATHS) + 1);
// Reset health, so they dont die
p.setHealth(p.getMaxHealth());
// Inventory clearing
p.getInventory().clear();
ItemStack air = new ItemStack(Material.AIR);
p.getInventory().setHelmet(air);
p.getInventory().setChestplate(air);
p.getInventory().setLeggings(air);
p.getInventory().setBoots(air);
// Drop emerald at death location
ItemStack reward = new ItemStack(Material.EMERALD);
p.getWorld().dropItemNaturally(p.getLocation(), reward);
// Clear potion effects
for(PotionEffect pe : p.getActivePotionEffects()){
p.removePotionEffect(pe.getType());
}
// Stop infinite kill glitch
p.setGameMode(GameMode.SPECTATOR);
p.setGameMode(GameMode.ADVENTURE);
// Send them to the SPAWN of the world
p.teleport(p.getWorld().getSpawnLocation());
p.setFireTicks(0);
}
}
}
示例14: onEntityDamaged
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamaged(EntityDamageByEntityEvent event) {
if(event.getDamager().getUniqueId() == player.getUniqueId())
event.setCancelled(true);
}
示例15: onLingeringPotionDamage
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) {
if (DEBUG) {
plugin.getLogger().info("1.9 lingering potion damage " + e.getEventName());
plugin.getLogger().info("1.9 lingering potion entity = " + e.getEntity());
plugin.getLogger().info("1.9 lingering potion entity type = " + e.getEntityType());
plugin.getLogger().info("1.9 lingering potion cause = " + e.getCause());
plugin.getLogger().info("1.9 lingering potion damager = " + e.getDamager());
}
if (!Util.inWorld(e.getEntity().getLocation())) {
return;
}
if (e.getEntity() == null || e.getEntity().getUniqueId() == null) {
return;
}
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
UUID attacker = thrownPotions.get(e.getDamager().getEntityId());
// Self damage
if (attacker.equals(e.getEntity().getUniqueId())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Self damage from lingering potion!");
return;
}
Island island = plugin.getIslands().getIslandAt(e.getEntity().getLocation());
boolean inNether = false;
if (e.getEntity().getWorld().equals(IslandWorld.getNetherWorld())) {
inNether = true;
}
// Monsters being hurt
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime || e.getEntity() instanceof Squid) {
// Normal island check
if (island != null && island.getMembers().contains(attacker)) {
// Members always allowed
return;
}
if (actionAllowed(attacker, e.getEntity().getLocation(), SettingsFlag.HURT_MONSTERS)) {
return;
}
// Not allowed
e.setCancelled(true);
return;
}
// Mobs being hurt
if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman
|| e.getEntity() instanceof Villager) {
if (island != null && (island.getFlag(SettingsFlag.HURT_ANIMALS) || island.getMembers().contains(attacker))) {
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
e.setCancelled(true);
return;
}
// Establish whether PVP is allowed or not.
boolean pvp = false;
if ((inNether && island != null && island.getFlag(SettingsFlag.PVP_NETHER) || (!inNether && island != null && island.getFlag(SettingsFlag.PVP_OVERWORLD)))) {
if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed");
pvp = true;
}
// Players being hurt PvP
if (e.getEntity() instanceof Player) {
if (!pvp) {
if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed");
e.setCancelled(true);
}
}
}
}