mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-10 10:28:21 +01:00
Minor code smell reduction
This commit is contained in:
parent
fec43adc35
commit
3e1dc81592
@ -100,7 +100,7 @@ public class BlockInteractionListener extends FlagListener
|
||||
return;
|
||||
}
|
||||
|
||||
if (block.getState() instanceof BrushableBlock bb && BlockInteractionListener.holds(player, Material.BRUSH)) {
|
||||
if (block.getState() instanceof BrushableBlock && BlockInteractionListener.holds(player, Material.BRUSH)) {
|
||||
// Protect this using break blocks flag for now. Maybe in the future it can have its own flag.
|
||||
this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
|
||||
return;
|
||||
|
@ -35,10 +35,9 @@ public class BreakBlocksListener extends FlagListener {
|
||||
Player p = e.getPlayer();
|
||||
Location l = e.getBlock().getLocation();
|
||||
Material m = e.getBlock().getType();
|
||||
switch (m)
|
||||
{
|
||||
case MELON, PUMPKIN -> this.checkIsland(e, p, l, Flags.HARVEST);
|
||||
default -> {
|
||||
if (m.equals(Material.MELON) || m.equals(Material.PUMPKIN)) {
|
||||
this.checkIsland(e, p, l, Flags.HARVEST);
|
||||
} else {
|
||||
// Crops
|
||||
if (Tag.CROPS.isTagged(m)
|
||||
&& !m.equals(Material.MELON_STEM)
|
||||
@ -50,7 +49,6 @@ public class BreakBlocksListener extends FlagListener {
|
||||
checkIsland(e, p, l, Flags.BREAK_BLOCKS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +90,7 @@ public class PVPListener extends FlagListener {
|
||||
user.notify(getFlag(player.getWorld()).getHintReference());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} else if (damager instanceof Projectile && ((Projectile)damager).getShooter() instanceof Player shooter) {
|
||||
} else if (damager instanceof Projectile projectile && projectile.getShooter() instanceof Player shooter) {
|
||||
// Find out who fired the arrow
|
||||
processDamage(e, damager, shooter, hurtEntity, flag);
|
||||
} else if (damager instanceof Firework && firedFireworks.containsKey(damager)) {
|
||||
|
@ -66,7 +66,7 @@ public class ItemParser {
|
||||
try {
|
||||
// Because I am lazy, and do not want to rewrite every parser, I will just add custom data as
|
||||
// parameter and remove that array part form input data.
|
||||
Optional<String> first = Arrays.stream(part).filter(field -> field.matches("(CMD-[0-9]*)")).findFirst();
|
||||
Optional<String> first = Arrays.stream(part).filter(field -> field.matches("(CMD-\\d*)")).findFirst();
|
||||
Integer customModelData = null;
|
||||
|
||||
if (first.isPresent()) {
|
||||
@ -75,7 +75,7 @@ public class ItemParser {
|
||||
int j = 0;
|
||||
|
||||
for (String field : part) {
|
||||
if (!field.matches("(CMD-[0-9]*)")) {
|
||||
if (!field.matches("(CMD-\\d*)")) {
|
||||
copyParts[j++] = field;
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +313,6 @@ public class ClosestSafeSpotTeleport
|
||||
{
|
||||
// Try to teleport player to the highest block.
|
||||
this.asyncTeleport(highestBlock.getLocation().add(new Vector(0.5D, 0D, 0.5D)));
|
||||
return;
|
||||
}
|
||||
else if (!this.plugin.getIWM().inWorld(this.entity.getLocation()))
|
||||
{
|
||||
|
@ -11,7 +11,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -153,7 +152,7 @@ public class AdminTeleportCommandTest {
|
||||
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
when(user.getTranslation(Mockito.anyString(),Mockito.anyString(), Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
when(user.getTranslation(anyString(),anyString(), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Island location
|
||||
Location location = mock(Location.class);
|
||||
@ -215,16 +214,16 @@ public class AdminTeleportCommandTest {
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringUnknownTarget() {
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertFalse(atc.canExecute(user, "tp", Collections.singletonList("tastybento")));
|
||||
assertFalse(atc.canExecute(user, "tp", List.of("tastybento")));
|
||||
verify(user).sendMessage(eq("general.errors.unknown-player"), eq(TextVariables.NAME), eq("tastybento"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetNoIsland() {
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(pm.getUUID("tastybento")).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertFalse(atc.canExecute(user, "tp", Collections.singletonList("tastybento")));
|
||||
assertFalse(atc.canExecute(user, "tp", List.of("tastybento")));
|
||||
verify(user).sendMessage(eq("general.errors.player-has-no-island"));
|
||||
}
|
||||
|
||||
@ -233,12 +232,12 @@ public class AdminTeleportCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetHasIsland() {
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(pm.getUUID("tastybento")).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertTrue(atc.canExecute(user, "tp", Collections.singletonList("tastybento")));
|
||||
assertTrue(atc.execute(user, "tp", Collections.singletonList("tastybento")));
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
assertTrue(atc.canExecute(user, "tp", List.of("tastybento")));
|
||||
assertTrue(atc.execute(user, "tp", List.of("tastybento")));
|
||||
verify(user).getTranslation("commands.admin.tp.manual", "[location]", "0 0 0");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,56 +246,56 @@ public class AdminTeleportCommandTest {
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetHasIslandSpawnPoint() {
|
||||
when(island.getSpawnPoint(any())).thenReturn(spawnPoint);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(pm.getUUID("tastybento")).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertTrue(atc.canExecute(user, "tp", Collections.singletonList("tastybento")));
|
||||
assertTrue(atc.execute(user, "tp", Collections.singletonList("tastybento")));
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
assertTrue(atc.canExecute(user, "tp", List.of("tastybento")));
|
||||
assertTrue(atc.execute(user, "tp", List.of("tastybento")));
|
||||
verify(user).getTranslation("commands.admin.tp.manual", "[location]", "0 0 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetIsTeamMember() {
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(pm.getUUID("tastybento")).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertTrue(atc.canExecute(user, "tp", Collections.singletonList("tastybento")));
|
||||
assertTrue(atc.execute(user, "tp", Collections.singletonList("tastybento")));
|
||||
assertTrue(atc.canExecute(user, "tp", List.of("tastybento")));
|
||||
assertTrue(atc.execute(user, "tp", List.of("tastybento")));
|
||||
verify(iwm, Mockito.never()).getNetherWorld(any());
|
||||
verify(iwm, Mockito.never()).getEndWorld(any());
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
verify(user).getTranslation("commands.admin.tp.manual", "[location]", "0 0 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetHasIslandNether() {
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(pm.getUUID("tastybento")).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tpnether");
|
||||
assertTrue(atc.canExecute(user, "tpnether", Collections.singletonList("tastybento")));
|
||||
assertTrue(atc.execute(user, "tpnether", Collections.singletonList("tastybento")));
|
||||
assertTrue(atc.canExecute(user, "tpnether", List.of("tastybento")));
|
||||
assertTrue(atc.execute(user, "tpnether", List.of("tastybento")));
|
||||
verify(iwm).getNetherWorld(any());
|
||||
verify(iwm, Mockito.never()).getEndWorld(any());
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
verify(user).getTranslation("commands.admin.tp.manual", "[location]", "0 0 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetHasIslandEnd() {
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(pm.getUUID("tastybento")).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tpend");
|
||||
assertTrue(atc.canExecute(user, "tpend", Collections.singletonList("tastybento")));
|
||||
assertTrue(atc.execute(user, "tpend", Collections.singletonList("tastybento")));
|
||||
assertTrue(atc.canExecute(user, "tpend", List.of("tastybento")));
|
||||
assertTrue(atc.execute(user, "tpend", List.of("tastybento")));
|
||||
verify(iwm, Mockito.never()).getNetherWorld(any());
|
||||
verify(iwm).getEndWorld(any());
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
verify(user).getTranslation("commands.admin.tp.manual", "[location]", "0 0 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPermissionsNoRootPermission() {
|
||||
when(p.hasPermission("admin.tp")).thenReturn(true);
|
||||
when(p.hasPermission("admin")).thenReturn(false);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(pm.getUUID("tastybento")).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tpend");
|
||||
assertTrue(atc.canExecute(user, "tpend", List.of("tastybento")));
|
||||
@ -311,7 +310,7 @@ public class AdminTeleportCommandTest {
|
||||
public void testPermissionsHasRootPermission() {
|
||||
when(p.hasPermission("admin.tp")).thenReturn(true);
|
||||
when(p.hasPermission("admin")).thenReturn(true);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(pm.getUUID("tastybento")).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tpend");
|
||||
assertTrue(atc.canExecute(user, "tpend", List.of("tastybento")));
|
||||
|
Loading…
Reference in New Issue
Block a user