mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-23 16:41:42 +01:00
Remove code smells.
This commit is contained in:
parent
ef67079831
commit
21916b5a59
@ -30,15 +30,15 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
*/
|
||||
public class BlockInteractionListener extends FlagListener {
|
||||
|
||||
private static Map<Material, Flag> inHandItems;
|
||||
private final Map<Material, Flag> inHandItems;
|
||||
|
||||
private static Map<Material, Flag> clickedBlocks;
|
||||
private final Map<Material, Flag> clickedBlocks;
|
||||
|
||||
public BlockInteractionListener() {
|
||||
inHandItems = new EnumMap<Material, Flag>(Material.class);
|
||||
inHandItems = new EnumMap<>(Material.class);
|
||||
inHandItems.put(Material.ENDER_PEARL, Flags.ENDER_PEARL);
|
||||
inHandItems.put(Material.BONE_MEAL, Flags.PLACE_BLOCKS);
|
||||
clickedBlocks = new EnumMap<Material, Flag>(Material.class);
|
||||
clickedBlocks = new EnumMap<>(Material.class);
|
||||
clickedBlocks.put(Material.ANVIL, Flags.ANVIL);
|
||||
clickedBlocks.put(Material.CHIPPED_ANVIL, Flags.ANVIL);
|
||||
clickedBlocks.put(Material.DAMAGED_ANVIL, Flags.ANVIL);
|
||||
@ -167,12 +167,10 @@ public class BlockInteractionListener extends FlagListener {
|
||||
// Boats
|
||||
if (e.getItem().getType().name().endsWith("_BOAT")) {
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
return;
|
||||
}
|
||||
// Spawn eggs
|
||||
else if (e.getItem().getType().name().endsWith("_SPAWN_EGG")) {
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.SPAWN_EGGS);
|
||||
return;
|
||||
}
|
||||
// Other items
|
||||
else if (inHandItems.containsKey(e.getItem().getType())) {
|
||||
@ -237,14 +235,14 @@ public class BlockInteractionListener extends FlagListener {
|
||||
/**
|
||||
* @return the inHandItems
|
||||
*/
|
||||
public static Map<Material, Flag> getInHandItems() {
|
||||
public Map<Material, Flag> getInHandItems() {
|
||||
return inHandItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clickedBlocks
|
||||
*/
|
||||
public static Map<Material, Flag> getClickedBlocks() {
|
||||
public Map<Material, Flag> getClickedBlocks() {
|
||||
return clickedBlocks;
|
||||
}
|
||||
}
|
||||
|
@ -34,19 +34,16 @@ public class EntityInteractListener extends FlagListener {
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent e) {
|
||||
if (e.getRightClicked() instanceof Vehicle) {
|
||||
// Animal riding
|
||||
if (e.getRightClicked() instanceof Animals
|
||||
&& !checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.RIDING)) {
|
||||
return;
|
||||
if (e.getRightClicked() instanceof Animals) {
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.RIDING);
|
||||
}
|
||||
// Minecart riding
|
||||
else if (e.getRightClicked() instanceof RideableMinecart
|
||||
&& !checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.MINECART)) {
|
||||
return;
|
||||
else if (e.getRightClicked() instanceof RideableMinecart) {
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.MINECART);
|
||||
}
|
||||
// Boat riding
|
||||
else if (e.getRightClicked() instanceof Boat
|
||||
&& !checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.BOAT)) {
|
||||
return;
|
||||
else if (e.getRightClicked() instanceof Boat) {
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.BOAT);
|
||||
}
|
||||
}
|
||||
// Villager trading
|
||||
|
@ -224,14 +224,14 @@ public class BlockInteractionListenerTest {
|
||||
public void testOnPlayerInteractNothingInHandNotAllowed() {
|
||||
int count = 0;
|
||||
int worldSettingCount = 0;
|
||||
for (Material bm : BlockInteractionListener.getClickedBlocks().keySet()) {
|
||||
for (Material bm : bil.getClickedBlocks().keySet()) {
|
||||
when(clickedBlock.getType()).thenReturn(bm);
|
||||
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
|
||||
bil.onPlayerInteract(e);
|
||||
assertTrue("Failure " + bm, e.useInteractedBlock().equals(Event.Result.DENY));
|
||||
if (BlockInteractionListener.getClickedBlocks().get(bm).getType().equals(Type.PROTECTION)) {
|
||||
if (bil.getClickedBlocks().get(bm).getType().equals(Type.PROTECTION)) {
|
||||
count++;
|
||||
} else if (BlockInteractionListener.getClickedBlocks().get(bm).getType().equals(Type.WORLD_SETTING)) {
|
||||
} else if (bil.getClickedBlocks().get(bm).getType().equals(Type.WORLD_SETTING)) {
|
||||
worldSettingCount++;
|
||||
}
|
||||
verify(notifier, times(count)).notify(any(), eq("protection.protected"));
|
||||
@ -245,12 +245,12 @@ public class BlockInteractionListenerTest {
|
||||
@Test
|
||||
public void testOnPlayerInteractNothingInHandAllowed() {
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
for (Material bm : BlockInteractionListener.getClickedBlocks().keySet()) {
|
||||
for (Material bm : bil.getClickedBlocks().keySet()) {
|
||||
// Allow flags
|
||||
if (BlockInteractionListener.getClickedBlocks().get(bm).getType().equals(Type.PROTECTION)) {
|
||||
when(island.isAllowed(any(), eq(BlockInteractionListener.getClickedBlocks().get(bm)))).thenReturn(true);
|
||||
} else if (BlockInteractionListener.getClickedBlocks().get(bm).getType().equals(Type.WORLD_SETTING)) {
|
||||
BlockInteractionListener.getClickedBlocks().get(bm).setSetting(world, true);
|
||||
if (bil.getClickedBlocks().get(bm).getType().equals(Type.PROTECTION)) {
|
||||
when(island.isAllowed(any(), eq(bil.getClickedBlocks().get(bm)))).thenReturn(true);
|
||||
} else if (bil.getClickedBlocks().get(bm).getType().equals(Type.WORLD_SETTING)) {
|
||||
bil.getClickedBlocks().get(bm).setSetting(world, true);
|
||||
}
|
||||
when(clickedBlock.getType()).thenReturn(bm);
|
||||
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
|
||||
|
Loading…
Reference in New Issue
Block a user