Skip to content

Commit

Permalink
Obsidian scooping was weird with just one bucket.
Browse files Browse the repository at this point in the history
It's not clear why this was flakey. It might be that the event was being
canceled.

#1683
  • Loading branch information
tastybento committed Feb 15, 2021
1 parent bf94e56 commit fb4ad90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package world.bentobox.bentobox.listeners.flags.worldsettings;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
Expand Down Expand Up @@ -30,7 +32,7 @@ public class ObsidianScoopingListener extends FlagListener {
* @param e event
* @return false if obsidian not scooped, true if scooped
*/
@EventHandler(priority = EventPriority.NORMAL)
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public boolean onPlayerInteract(final PlayerInteractEvent e) {
if (!getIWM().inWorld(e.getPlayer().getLocation())
|| !Flags.OBSIDIAN_SCOOPING.isSetForWorld(e.getPlayer().getWorld())
Expand All @@ -50,14 +52,16 @@ public boolean onPlayerInteract(final PlayerInteractEvent e) {
}

user.sendMessage("protection.flags.OBSIDIAN_SCOOPING.scooping");
e.setCancelled(true);
if (e.getItem().getAmount() == 1) {
// Needs some special handling when there is only 1 bucket in the stack
e.getItem().setType(Material.LAVA_BUCKET);
Bukkit.getScheduler().runTask(getPlugin(), () -> e.getItem().setType(Material.LAVA_BUCKET));
} else {
// Remove one empty bucket and add a lava bucket to the player's inventory
e.getItem().setAmount(e.getItem().getAmount() - 1);
e.getPlayer().getInventory().addItem(new ItemStack(Material.LAVA_BUCKET));
HashMap<Integer, ItemStack> map = e.getPlayer().getInventory().addItem(new ItemStack(Material.LAVA_BUCKET));
if (!map.isEmpty()) {
map.values().forEach(i -> e.getPlayer().getWorld().dropItem(e.getPlayer().getLocation(), i));
}
}

e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ITEM_BUCKET_FILL_LAVA, 1F, 1F);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package world.bentobox.bentobox.listeners.flags.worldsettings;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -21,7 +20,6 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerInteractEvent;
Expand Down Expand Up @@ -83,7 +81,7 @@ public void setUp() throws Exception {
when(server.getWorld("world")).thenReturn(world);
when(server.getVersion()).thenReturn("BSB_Mocking");

PowerMockito.mockStatic(Bukkit.class);
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
PluginManager pluginManager = mock(PluginManager.class);
when(Bukkit.getPluginManager()).thenReturn(pluginManager);

Expand Down Expand Up @@ -280,7 +278,6 @@ private void testEvent() {
// Test where the area is free of obby
when(world.getBlockAt(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(airBlock);
assertTrue(listener.onPlayerInteract(event));
assertEquals(Result.DENY, event.useInteractedBlock());
}
}
}

0 comments on commit fb4ad90

Please sign in to comment.