Obsidian scooping was weird with just one bucket.

It's not clear why this was flakey. It might be that the event was being
canceled.

https://github.com/BentoBoxWorld/BentoBox/issues/1683
This commit is contained in:
tastybento 2021-02-14 22:25:08 -08:00
parent bf94e56f78
commit fb4ad90328
2 changed files with 9 additions and 8 deletions

View File

@ -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;
@ -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())
@ -50,14 +52,16 @@ public class ObsidianScoopingListener extends FlagListener {
}
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);

View File

@ -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;
@ -21,7 +20,6 @@ import org.bukkit.World;
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;
@ -83,7 +81,7 @@ public class ObsidianScoopingListenerTest {
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);
@ -280,7 +278,6 @@ public class ObsidianScoopingListenerTest {
// 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());
}
}
}