Java Code Examples for org.bukkit.event.entity.PlayerDeathEvent#setDeathMessage()

The following examples show how to use org.bukkit.event.entity.PlayerDeathEvent#setDeathMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QAListener.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDeathChat(PlayerDeathEvent e){
	if(QAMain.changeDeathMessages){
		if(e.getEntity().getKiller()!=null && e.getEntity().getKiller() instanceof Player){
			Player killer = e.getEntity().getKiller();
			if(e.getDeathMessage().contains(" using ")){
				CustomBaseObject base = IronsightsHandler.getGunUsed(killer);
				if(base instanceof Gun){
					e.setDeathMessage(((Gun) base).getDeathMessage()
							.replaceAll("%player%",e.getEntity().getDisplayName())
							.replaceAll("%killer%",killer.getDisplayName())
							.replaceAll("%name%",base.getDisplayName())
					);
				}
			}
		}
	}
}
 
Example 2
Source File: PlayerDeath.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeath(PlayerDeathEvent event) {
	String msg = event.getDeathMessage();
	if(msg!=null) {
		Debug.saySuper("Original Death Message: " + msg);
		for (CustomItem cItem : AdditionsAPI.getAllCustomItems()) {
			if (msg.contains(cItem.getDisplayName())) {
				msg.replaceFirst(LangFileUtils.get("death_message").replaceFirst("CustomItem", cItem.getDisplayName()),
						"");
				Debug.saySuper("Replaced " + cItem.getDisplayName());
				break;
			}
		}
		Debug.saySuper("Final Death Message: " + msg);
		event.setDeathMessage(msg);
	}	
}
 
Example 3
Source File: ListenerDamageDeath.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onDeath(PlayerDeathEvent e) {
    Player player = e.getEntity();
    if(player.hasMetadata("NPC")) return;
    
    NPCManager npcManager = this.expansion.getNPCManager();
    YamlConfiguration data = npcManager.getData(player);
    String deathMessage = data.getString("citizens-compatibility.last-death-message");
    if(deathMessage == null) return;
    
    e.setDeathMessage(null);
    player.sendMessage(deathMessage);
    
    data.set("citizens-compatibility.last-death-message", null);
    npcManager.setData(player, data);
}
 
Example 4
Source File: PlayerDeathListener.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onDeath2(final PlayerDeathEvent v2) {
      final GameMap gameMap = MatchManager.get().getPlayerMap(v2.getEntity());

      if (gameMap == null) {
          return;
      }
       
      final Player player = v2.getEntity();
      v2.getEntity().getInventory().clear();
      v2.getEntity().getInventory().setArmorContents(null);
      
      DamageCause damageCause = DamageCause.CUSTOM;
if (v2.getEntity().getLastDamageCause() != null) {
	damageCause = v2.getEntity().getLastDamageCause().getCause();
} 
final DamageCause dCause = damageCause;
v2.setDeathMessage("");

      MatchManager.get().playerLeave(player, dCause, false, true, true);
  }
 
Example 5
Source File: GameListeners.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void DeathListener(PlayerDeathEvent event)
{
	String message = "";
	Player player = event.getEntity();
	Player killer = player.getKiller();
	
	if(Game.isGameRunning())
	{
		AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
		if(p != null)
		{
			if(killer != null)
			{
				AnniPlayer k = AnniPlayer.getPlayer(killer.getUniqueId());
				if(k != null)
				{
					PlayerKilledEvent e = new PlayerKilledEvent(k,p);//TODO--------This should be created earlier, then the message should be based off of attributes computed by the event
					
					message = p.getTeam().getColor()+player.getName()+"("+p.getKit().getName()+") "+Lang.DEATHPHRASE.toString()+" "+k.getTeam().getColor()+killer.getName()+"("+k.getKit().getName()+")";
					
					if(e.getAttributes().contains(KillAttribute.REMEMBRANCE))
						message += " "+Lang.REMEMBRANCE.toString();
					else if(e.getAttributes().contains(KillAttribute.NEXUSDEFENSE))
						message += " "+Lang.NEXUSKILL.toString();
						
					AnniEvent.callEvent(e);
					if(!e.shouldDropXP())
						event.setDroppedExp(0);
				}	
			}
			else 
				event.setDroppedExp(0);
			event.setDeathMessage(message);
		}
	}
}
 
Example 6
Source File: PlayerDeathMessageByEliteMob.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {

    if (isDeadPlayer(event.getEntity())) {
        event.setDeathMessage(deadPlayerList.get(event.getEntity()));
        removeDeadPlayer(event.getEntity());
    }

}
 
Example 7
Source File: ListenerCustomDeath.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onDeath(PlayerDeathEvent e) {
    Player player = e.getEntity();
    UUID uuid = player.getUniqueId();
    if(!customDeathList.contains(uuid)) return;

    FileConfiguration config = this.plugin.getConfig("config.yml");
    List<String> customDeathMessageList = config.getStringList("punishments.custom-death-messages");
    if(customDeathMessageList.isEmpty()) return;

    int random = ThreadLocalRandom.current().nextInt(customDeathMessageList.size());
    String message = customDeathMessageList.get(random).replace("{name}", player.getName());
    e.setDeathMessage(message);
    remove(player);
}
 
Example 8
Source File: ModifiedDeathMessagesModule.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void on(PlayerDeathEvent event) {
    if (!isEnabled()) return;

    final StringWriter writer = new StringWriter();
    template.execute(writer, new DeathContext(event));

    event.setDeathMessage(writer.getBuffer().toString());
}
 
Example 9
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVistorDeath(final PlayerDeathEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    // Mute death messages
    if (Settings.muteDeathMessages) {
        e.setDeathMessage(null);
    }
    // If visitors will keep items and their level on death
    // This will override any global settings
    if (Settings.allowVisitorKeepInvOnDeath) {
        // If the player is not a visitor then they die and lose everything -
        // sorry :-(
        Island island = plugin.getGrid().getProtectedIslandAt(e.getEntity().getLocation());
        if (island != null && !island.getMembers().contains(e.getEntity().getUniqueId())) {
            // They are a visitor
            InventorySave.getInstance().savePlayerInventory(e.getEntity());
            e.getDrops().clear();
            e.setKeepLevel(true);
            e.setDroppedExp(0);
        }
    }
}
 
Example 10
Source File: TitleRespawn.java    From CardinalPGM with MIT License 5 votes vote down vote up
private void killPlayer(final Player player, Player killer, EntityDamageEvent.DamageCause cause) {
    if (deadPlayers.containsKey(player.getUniqueId())) return;
    this.deadPlayers.put(player.getUniqueId(), System.currentTimeMillis());

    CardinalDeathEvent cardinalDeathEvent = new CardinalDeathEvent(player, killer, cause);
    Bukkit.getServer().getPluginManager().callEvent(cardinalDeathEvent);

    dropInventory(player, true);

    PlayerDeathEvent deathEvent = new PlayerDeathEvent(player, new ArrayList<ItemStack>(), player.getExpToLevel(), 0, 0, 0, null);
    deathEvent.setDeathMessage(null);
    Bukkit.getServer().getPluginManager().callEvent(deathEvent);

    if (!isDeadUUID(player.getUniqueId())) return;

    Players.setObserver(player);

    PlayerNameUpdateEvent nameUpdateEvent = new PlayerNameUpdateEvent(player);
    Bukkit.getServer().getPluginManager().callEvent(nameUpdateEvent);

    sendTitle(player);

    player.setGameMode(GameMode.CREATIVE);

    setBlood(player, true);
    playDeathAnimation(player);

    if (!this.spectate) sendArmorStandPacket(player);

    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 0, true, false), false);
    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, this.blackout ? Integer.MAX_VALUE : 20, 0, true, false), false);

    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Cardinal.getInstance(), new Runnable() {
        public void run() {
            GameHandler.getGameHandler().getMatch().getModules().getModule(Visibility.class).showOrHide(player);
        }
    }, 15L);
    if (this.auto) hasLeftClicked.add(player.getUniqueId());
}
 
Example 11
Source File: DeathMessageMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onVanillaDeath(final PlayerDeathEvent event) {
  event.setDeathMessage(null);
}
 
Example 12
Source File: DeathMessageMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onVanillaDeath(final PlayerDeathEvent event) {
    event.setDeathMessage(null);
}
 
Example 13
Source File: QAListener.java    From QualityArmory with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent e) {
	if (QAMain.reloadingTasks.containsKey(e.getEntity().getUniqueId())) {
		for (GunRefillerRunnable r : QAMain.reloadingTasks.get(e.getEntity().getUniqueId())) {
			if(e.getEntity().getGameMode()!=GameMode.CREATIVE){
				Gun gun = QualityArmory.getGun(r.getItem());
				if(gun != null){
					Ammo ammotype = gun.getAmmoType();
					if(ammotype !=null){
						ItemStack ammo = QualityArmory.getCustomItemAsItemStack(ammotype);
						ammo.setAmount(r.getAddedAmount());
						e.getDrops().add(ammo);
					}
				}
			}
			r.getTask().cancel();
			DEBUG("Canceling reload task " + r.getTask().getTaskId());
		}
	}
	QAMain.reloadingTasks.remove(e.getEntity().getUniqueId());

	for (ItemStack is : new ArrayList<>(e.getDrops())) {
		if(is==null)
			continue;
		if (QualityArmory.isIronSights(is)) {
			e.getDrops().remove(is);
			DEBUG("Removing IronSights");
		}else if (is.hasItemMeta() && is.getItemMeta().hasDisplayName() && is.getItemMeta().getDisplayName().contains(QAMain.S_RELOADING_MESSAGE)) {
			Gun g = QualityArmory.getGun(is);
			ItemMeta im = is.getItemMeta();
			im.setDisplayName(g.getDisplayName());
			is.setItemMeta(im);
			DEBUG("Removed Reloading suffix");
		}
	}

	if (e.getDeathMessage() != null
			&& e.getDeathMessage().contains(QualityArmory.getIronSightsItemStack().getItemMeta().getDisplayName())) {
		try {
			e.setDeathMessage(e.getDeathMessage().replace(QualityArmory.getIronSightsItemStack().getItemMeta().getDisplayName(),
					e.getEntity().getKiller().getInventory().getItemInOffHand().getItemMeta().getDisplayName()));
			DEBUG("Removing ironsights from death message and replaced with gun's name");
		} catch (Error | Exception e34) {
		}
	}
	BulletWoundHandler.bleedoutMultiplier.remove(e.getEntity().getUniqueId());
	BulletWoundHandler.bloodLevel.put(e.getEntity().getUniqueId(), QAMain.bulletWound_initialbloodamount);

	if (e.getEntity().getKiller() instanceof Player) {
		Player killer = e.getEntity().getKiller();
		if (QualityArmory.isGun(killer.getItemInHand()) || QualityArmory.isIronSights(killer.getItemInHand())) {
			DEBUG("This player \"" + e.getEntity().getName() + "\" was killed by a player with a gun");
		} else if (QualityArmory.isCustomItem(e.getEntity().getItemInHand())) {
			DEBUG("This player \"" + e.getEntity().getName() + "\" was killed by a player, but not with a gun");
		}
	}
}
 
Example 14
Source File: SilentNightListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler (priority = EventPriority.LOW)
public void onPlayerDeath(PlayerDeathEvent e){
    if (nightMode){
        e.setDeathMessage(null);
    }
}
 
Example 15
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerDie(PlayerDeathEvent pde) {
  final Player player = pde.getEntity();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() == GameState.RUNNING) {
    pde.setDroppedExp(0);
    pde.setDeathMessage(null);

    if (!BedwarsRel.getInstance().getBooleanConfig("player-drops", false)) {
      pde.getDrops().clear();
    }

    try {
      if (!BedwarsRel.getInstance().isSpigot()) {
        Class<?> clazz = null;
        try {
          clazz = Class.forName("io.github.bedwarsrel.com."
              + BedwarsRel.getInstance().getCurrentVersion().toLowerCase()
              + ".PerformRespawnRunnable");
        } catch (ClassNotFoundException ex) {
          BedwarsRel.getInstance().getBugsnag().notify(ex);
          clazz = Class
              .forName("io.github.bedwarsrel.com.fallback.PerformRespawnRunnable");
        }

        BukkitRunnable respawnRunnable =
            (BukkitRunnable) clazz.getDeclaredConstructor(Player.class).newInstance(player);
        respawnRunnable.runTaskLater(BedwarsRel.getInstance(), 20L);
      } else {
        new BukkitRunnable() {

          @Override
          public void run() {
            player.spigot().respawn();
          }
        }.runTaskLater(BedwarsRel.getInstance(), 20L);
      }

    } catch (Exception e) {
      BedwarsRel.getInstance().getBugsnag().notify(e);
      e.printStackTrace();
    }

    pde.setKeepInventory(
        BedwarsRel.getInstance().getBooleanConfig("keep-inventory-on-death", false));

    Player killer = player.getKiller();
    if (killer == null) {
      killer = game.getPlayerDamager(player);
    }

    game.getCycle().onPlayerDies(player, killer);
  }
}
 
Example 16
Source File: PlayerDeath.java    From ZombieEscape with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onDeath(PlayerDeathEvent event) {
    event.setDeathMessage(null);
    event.getDrops().clear();
    event.setDroppedExp(0);
    final Player player = event.getEntity();
    player.setHealth(20); // Do not show the respawn screen
    player.getInventory().clear();

    final GameArena gameArena = PLUGIN.getGameArena();

    if (!gameArena.isGameRunning()) {
        player.teleport(PLUGIN.getServerSpawn());
        return;
    }

    if (gameArena.isHuman(player)) {
        gameArena.addZombie(player);
        player.getInventory().setHelmet(new ItemStack(Material.JACK_O_LANTERN));
        gameArena.giveKit(player);

        if (player.getKiller() != null) {
            Profile zombieProfile = PLUGIN.getProfile(player.getKiller());
            if (zombieProfile != null) {
                zombieProfile.setHumanKills(zombieProfile.getHumanKills() + 1);
            }
        }
    } else if (gameArena.isZombie(player)) {
        new BukkitRunnable() {
            @Override
            public void run() {
                gameArena.teleportCheckpoint(player);
                gameArena.giveKit(player);
                player.setFireTicks(0);
                player.setHealth(20);
            }
        }.runTaskLater(PLUGIN, 10);
    }

    if (gameArena.isGameRunning()) {
        if (gameArena.shouldEnd()) {
            gameArena.endGame();
        }
    }
}