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

The following examples show how to use org.bukkit.event.entity.PlayerDeathEvent#setDroppedExp() . 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: PlayerEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeath(PlayerDeathEvent event) {
    final Player player = event.getEntity();
    GDCauseStackManager.getInstance().pushCause(player);
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
    Tristate keepInventory = Tristate.UNDEFINED;
    if (GDOptions.isOptionEnabled(Options.PLAYER_KEEP_INVENTORY)) {
        keepInventory = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Tristate.class), playerData.getSubject(), Options.PLAYER_KEEP_INVENTORY, claim);
    }
    Tristate keepLevel = Tristate.UNDEFINED;
    if (GDOptions.isOptionEnabled(Options.PLAYER_KEEP_LEVEL)) {
        keepLevel = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Tristate.class), playerData.getSubject(), Options.PLAYER_KEEP_LEVEL, claim);
    }
    if (keepInventory != Tristate.UNDEFINED) {
        event.setKeepInventory(keepInventory.asBoolean());
        if (keepInventory == Tristate.TRUE) {
            event.getDrops().clear();
        }
    }
    if (keepLevel != Tristate.UNDEFINED) {
        event.setKeepLevel(keepLevel.asBoolean());
        if (keepLevel == Tristate.TRUE) {
            event.setDroppedExp(0);
        }
    }
}
 
Example 2
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerDeathEvent(PlayerDeathEvent event)
{
	Player player = event.getEntity();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	
	Boolean keepInventory = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.KEEP_INVENTORY);
	if (keepInventory != null)
	{
		event.setKeepInventory(keepInventory);
		
		if (keepInventory)
		{
			event.getDrops().clear();
		}
	}
	
	Boolean keepExp = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.KEEP_EXP);
	if (keepExp != null)
	{
		event.setKeepLevel(keepExp);

		if (keepExp)
		{
			event.setDroppedExp(0);
		}
	}
}
 
Example 3
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 4
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 5
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 6
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();
        }
    }
}