本文整理汇总了Java中org.spongepowered.api.event.entity.DamageEntityEvent.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java DamageEntityEvent.setCancelled方法的具体用法?Java DamageEntityEvent.setCancelled怎么用?Java DamageEntityEvent.setCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.event.entity.DamageEntityEvent
的用法示例。
在下文中一共展示了DamageEntityEvent.setCancelled方法的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);
}
}
}
示例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);
}
}
}
示例3: 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;
}
}
}
示例4: 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!"));
}
}
}
示例5: 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);
}
}
}
示例6: 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;
}
}
}
示例7: 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);
}
}
}
示例8: onDamage
import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onDamage(DamageEntityEvent event) {
if (!(event.getTargetEntity() instanceof Player)) {
return;
}
Player p = (Player) event.getTargetEntity();
UltimateUser up = UltimateCore.get().getUserService().getUser(p);
if (up.get(GodKeys.GOD).orElse(false)) {
event.setCancelled(true);
//Send error message to player trying to hit, if player
Player t = event.getCause().first(Player.class).orElse(null);
if (t != null && t.getUniqueId() != p.getUniqueId()) {
Messages.send(t, "god.onhit");
}
}
}
示例9: onEntityDamage
import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityDamage(final DamageEntityEvent event) {
if (event.getTargetEntity() instanceof Player) {
Player player = (Player) event.getTargetEntity();
if (player.get(BedrockKeys.IS_INVINCIBLE).orElse(false)) {
event.setCancelled(true);
}
}
}
示例10: onEntityDamaged
import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityDamaged(DamageEntityEvent evt) {
EntityDamagedScriptEvent event = (EntityDamagedScriptEvent) clone();
event.internal = evt;
event.entity = new EntityTag(evt.getTargetEntity());
event.damage = new NumberTag(evt.getFinalDamage());
event.cancelled = evt.isCancelled();
// TODO: Cause viewing
event.run();
evt.setCancelled(event.cancelled);
}
示例11: onEntityKilled
import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityKilled(DamageEntityEvent evt) {
if (!evt.willCauseDeath()) {
return;
}
EntityKilledScriptEvent event = (EntityKilledScriptEvent) clone();
event.internal = evt;
event.entity = new EntityTag(evt.getTargetEntity());
event.damage = new NumberTag(evt.getFinalDamage());
event.cancelled = evt.isCancelled();
// TODO: Cause viewing
event.run();
evt.setCancelled(event.cancelled);
}
示例12: onDamageEntity
import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onDamageEntity(DamageEntityEvent event) {
if (event.getTargetEntity().getType() == EntityTypes.PLAYER) {
if (Main.getMinigame().getChallenger(event.getTargetEntity().getUniqueId()).isPresent()) {
event.setCancelled(true);
}
}
}
示例13: onDamageEntity
import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.LAST)
public void onDamageEntity(DamageEntityEvent event) {
java.util.Optional<Player> damager = event.getCause().first(Player.class);
if (!damager.isPresent()) {
return; // not a player, so return
}
Optional<Challenger> chal = CommonCore.getChallenger(event.getTargetEntity().getUniqueId());
Optional<Challenger> damChal = CommonCore.getChallenger(damager.get().getUniqueId());
// cancel if either of the players is spectating
if (chal.isPresent() && chal.get().isSpectating() || (damChal.isPresent() && damChal.get().isSpectating())) {
event.setCancelled(true);
return;
}
// check whether both are in a round
if (chal.isPresent() && damChal.isPresent()) {
// check whether they're in the same round
if (chal.get().getRound() == damChal.get().getRound()) {
// check whether damage is disabled entirely in the round, or if they're on the same team
if (!chal.get().getRound().getConfigValue(ConfigNode.ALLOW_DAMAGE)
|| (!chal.get().getRound().getConfigValue(ConfigNode.ALLOW_FRIENDLY_FIRE)
&& chal.get().getTeam().orNull() == damChal.get().getTeam().orNull())) {
event.setCancelled(true);
}
} else {
event.setCancelled(true);
}
} else if (chal.isPresent() != damChal.isPresent()) {
event.setCancelled(true); // one's in a round and one's not
}
}
示例14: onPlayerDamage
import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的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));
}
}
}
}
}
示例15: onAttackEntity
import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onAttackEntity(DamageEntityEvent event) {
if (event.isCancelled()) return;
if (!(event.getTargetEntity() instanceof Living)) return;
Living target = (Living)event.getTargetEntity();
if (VillagerShops.isNPCused(target)) event.setCancelled(true);
}