Java Code Examples for org.bukkit.event.entity.PlayerDeathEvent#setKeepLevel()
The following examples show how to use
org.bukkit.event.entity.PlayerDeathEvent#setKeepLevel() .
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 |
@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: EffKeepInventory.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event e) { if (e instanceof PlayerDeathEvent) { PlayerDeathEvent event = (PlayerDeathEvent) e; if (keepItems) event.setKeepInventory(true); if (keepExp) event.setKeepLevel(true); } }
Example 3
Source File: PlayerListener.java From WorldGuardExtraFlagsPlugin with MIT License | 5 votes |
@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 4
Source File: PlayerDeathListenerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@Test public void shouldResetExp() { // given Player player = mock(Player.class); given(player.getInventory()).willReturn(mock(PlayerInventory.class)); given(player.getActivePotionEffects()).willReturn(new ArrayList<>()); Location loc = mock(Location.class); World world = mock(World.class); given(player.getLocation()).willReturn(loc); given(loc.getWorld()).willReturn(world); given(world.getName()).willReturn("test"); Group group = mockGroup("test"); given(groupManager.getGroupFromWorld("test")).willReturn(group); List<ItemStack> drops = new ArrayList<>(); PlayerDeathEvent event = new PlayerDeathEvent(player, drops, 5, 5, 5, 5, "Bob died."); event.setKeepLevel(false); // when listener.onPlayerDeath(event); // then verify(player).setExp(5); verify(player).setLevel(5); }
Example 5
Source File: PlayerDeathListenerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@Test public void shouldNotResetExp() { // given Player player = mock(Player.class); given(player.getInventory()).willReturn(mock(PlayerInventory.class)); given(player.getActivePotionEffects()).willReturn(new ArrayList<>()); Location loc = mock(Location.class); World world = mock(World.class); given(player.getLocation()).willReturn(loc); given(loc.getWorld()).willReturn(world); given(world.getName()).willReturn("test"); Group group = mockGroup("test"); given(groupManager.getGroupFromWorld("test")).willReturn(group); List<ItemStack> drops = new ArrayList<>(); PlayerDeathEvent event = new PlayerDeathEvent(player, drops, 5, 5, 5, 5, "Bob died."); event.setKeepLevel(true); // when listener.onPlayerDeath(event); // then verify(player, never()).setExp(5); verify(player, never()).setLevel(5); }
Example 6
Source File: PlayerDeathListenerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@Test public void shouldResetExp() { // given Player player = mock(Player.class); given(player.getInventory()).willReturn(mock(PlayerInventory.class)); given(player.getActivePotionEffects()).willReturn(new ArrayList<>()); Location loc = mock(Location.class); World world = mock(World.class); given(player.getLocation()).willReturn(loc); given(loc.getWorld()).willReturn(world); given(world.getName()).willReturn("test"); Group group = mockGroup("test"); given(groupManager.getGroupFromWorld("test")).willReturn(group); List<ItemStack> drops = new ArrayList<>(); PlayerDeathEvent event = new PlayerDeathEvent(player, drops, 5, 5, 5, 5, "Bob died."); event.setKeepLevel(false); // when listener.onPlayerDeath(event); // then verify(player).setExp(5); verify(player).setLevel(5); }
Example 7
Source File: PlayerDeathListenerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@Test public void shouldNotResetExp() { // given Player player = mock(Player.class); given(player.getInventory()).willReturn(mock(PlayerInventory.class)); given(player.getActivePotionEffects()).willReturn(new ArrayList<>()); Location loc = mock(Location.class); World world = mock(World.class); given(player.getLocation()).willReturn(loc); given(loc.getWorld()).willReturn(world); given(world.getName()).willReturn("test"); Group group = mockGroup("test"); given(groupManager.getGroupFromWorld("test")).willReturn(group); List<ItemStack> drops = new ArrayList<>(); PlayerDeathEvent event = new PlayerDeathEvent(player, drops, 5, 5, 5, 5, "Bob died."); event.setKeepLevel(true); // when listener.onPlayerDeath(event); // then verify(player, never()).setExp(5); verify(player, never()).setLevel(5); }
Example 8
Source File: PlayerEvents.java From askyblock with GNU General Public License v2.0 | 5 votes |
@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); } } }