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