More code cleanup and using new switch syntax

This commit is contained in:
tastybento 2022-11-26 23:43:33 -08:00
parent 942749ff20
commit cc2f757da8
6 changed files with 56 additions and 229 deletions

View File

@ -141,7 +141,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>3.11.1</version> <version>4.8.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -216,7 +216,7 @@ public class AdvancementsManager {
/** /**
* Get the score for this advancement * Get the score for this advancement
* @param key - advancement key as stored in the config file * @param string - advancement key as stored in the config file
* @return score of advancement, or default values if the key is not in the file * @return score of advancement, or default values if the key is not in the file
*/ */
public int getScore(String string) { public int getScore(String string) {

View File

@ -29,7 +29,7 @@ import world.bentobox.boxed.listeners.AdvancementListener;
import world.bentobox.boxed.listeners.EnderPearlListener; import world.bentobox.boxed.listeners.EnderPearlListener;
/** /**
* Main Boxed class - provides an survival game inside a box * Main Boxed class - provides a survival game inside a box
* @author tastybento * @author tastybento
*/ */
public class Boxed extends GameModeAddon { public class Boxed extends GameModeAddon {

View File

@ -54,7 +54,7 @@ public class BoxedChunkGenerator extends ChunkGenerator {
} }
/** /**
* @param chunk the chunk to set * @param chunks the chunks to set
*/ */
public void setChunks(Map<Pair<Integer, Integer>, ChunkSnapshot> chunks) { public void setChunks(Map<Pair<Integer, Integer>, ChunkSnapshot> chunks) {
this.chunks = chunks; this.chunks = chunks;
@ -91,16 +91,10 @@ public class BoxedChunkGenerator extends ChunkGenerator {
} else { } else {
// Handle liquids and default blocks // Handle liquids and default blocks
switch (m) { switch (m) {
case WATER: case WATER, LAVA, NETHERRACK, STONE, END_STONE -> cd.setBlock(x, y, z, m);
case LAVA: default ->
case NETHERRACK:
case STONE:
case END_STONE:
cd.setBlock(x, y, z, m);
break;
default:
// Most other blocks // Most other blocks
cd.setBlock(x, y, z, isGround(m) ? Material.STONE: Material.AIR); cd.setBlock(x, y, z, isGround(m) ? Material.STONE : Material.AIR);
} }
} }
} }
@ -111,7 +105,7 @@ public class BoxedChunkGenerator extends ChunkGenerator {
/** /**
* Calculates the repeating value for a given size * Calculates the repeating value for a given size
* @param chunkCoord chunk coord * @param chunkCoord chunk coord
* @param size * @param s size
* @return mapped chunk coord * @return mapped chunk coord
*/ */
public static int repeatCalc(int chunkCoord, int s) { public static int repeatCalc(int chunkCoord, int s) {
@ -132,223 +126,56 @@ public class BoxedChunkGenerator extends ChunkGenerator {
} }
private static boolean isInWater(Material m) { private static boolean isInWater(Material m) {
switch (m) { return switch (m) {
// Underwater plants // Underwater plants
case KELP: case KELP, KELP_PLANT, SEAGRASS, BUBBLE_COLUMN, BUBBLE_CORAL, BUBBLE_CORAL_BLOCK, BUBBLE_CORAL_FAN,
case KELP_PLANT: BUBBLE_CORAL_WALL_FAN, DEAD_BRAIN_CORAL, DEAD_BRAIN_CORAL_BLOCK, DEAD_BRAIN_CORAL_FAN,
case SEAGRASS: DEAD_BRAIN_CORAL_WALL_FAN, DEAD_BUBBLE_CORAL, DEAD_BUBBLE_CORAL_BLOCK, DEAD_BUBBLE_CORAL_FAN,
case BUBBLE_COLUMN: DEAD_BUBBLE_CORAL_WALL_FAN, DEAD_BUSH, DEAD_FIRE_CORAL, DEAD_FIRE_CORAL_BLOCK, DEAD_FIRE_CORAL_FAN,
case BUBBLE_CORAL: DEAD_FIRE_CORAL_WALL_FAN, DEAD_HORN_CORAL, DEAD_HORN_CORAL_BLOCK, DEAD_HORN_CORAL_FAN,
case BUBBLE_CORAL_BLOCK: DEAD_HORN_CORAL_WALL_FAN, DEAD_TUBE_CORAL, DEAD_TUBE_CORAL_BLOCK, DEAD_TUBE_CORAL_FAN,
case BUBBLE_CORAL_FAN: DEAD_TUBE_CORAL_WALL_FAN, FIRE_CORAL, FIRE_CORAL_BLOCK, FIRE_CORAL_FAN, FIRE_CORAL_WALL_FAN,
case BUBBLE_CORAL_WALL_FAN: HORN_CORAL, HORN_CORAL_BLOCK, HORN_CORAL_FAN, HORN_CORAL_WALL_FAN, TUBE_CORAL, TUBE_CORAL_BLOCK,
case DEAD_BRAIN_CORAL: TUBE_CORAL_FAN, TUBE_CORAL_WALL_FAN, TALL_SEAGRASS -> true;
case DEAD_BRAIN_CORAL_BLOCK: default -> false;
case DEAD_BRAIN_CORAL_FAN: };
case DEAD_BRAIN_CORAL_WALL_FAN:
case DEAD_BUBBLE_CORAL:
case DEAD_BUBBLE_CORAL_BLOCK:
case DEAD_BUBBLE_CORAL_FAN:
case DEAD_BUBBLE_CORAL_WALL_FAN:
case DEAD_BUSH:
case DEAD_FIRE_CORAL:
case DEAD_FIRE_CORAL_BLOCK:
case DEAD_FIRE_CORAL_FAN:
case DEAD_FIRE_CORAL_WALL_FAN:
case DEAD_HORN_CORAL:
case DEAD_HORN_CORAL_BLOCK:
case DEAD_HORN_CORAL_FAN:
case DEAD_HORN_CORAL_WALL_FAN:
case DEAD_TUBE_CORAL:
case DEAD_TUBE_CORAL_BLOCK:
case DEAD_TUBE_CORAL_FAN:
case DEAD_TUBE_CORAL_WALL_FAN:
case FIRE_CORAL:
case FIRE_CORAL_BLOCK:
case FIRE_CORAL_FAN:
case FIRE_CORAL_WALL_FAN:
case HORN_CORAL:
case HORN_CORAL_BLOCK:
case HORN_CORAL_FAN:
case HORN_CORAL_WALL_FAN:
case TUBE_CORAL:
case TUBE_CORAL_BLOCK:
case TUBE_CORAL_FAN:
case TUBE_CORAL_WALL_FAN:
case TALL_SEAGRASS:
return true;
default:
return false;
}
} }
private static boolean isGround(Material m) { private static boolean isGround(Material m) {
if (m.isAir() || m.isBurnable() || !m.isSolid()) return false; if (m.isAir() || m.isBurnable() || !m.isSolid()) return false;
switch (m) { return switch (m) {
case ANDESITE: case ANDESITE, BEDROCK, CALCITE, CLAY, COAL_ORE, COARSE_DIRT, COBBLESTONE, COPPER_ORE, DEEPSLATE,
case BEDROCK: DEEPSLATE_COAL_ORE, DEEPSLATE_COPPER_ORE, DEEPSLATE_DIAMOND_ORE, DEEPSLATE_EMERALD_ORE,
case CALCITE: DEEPSLATE_GOLD_ORE, DEEPSLATE_IRON_ORE, DEEPSLATE_LAPIS_ORE, DEEPSLATE_REDSTONE_ORE, DIAMOND_ORE,
case CLAY: DIORITE, DIRT, DIRT_PATH, DRIPSTONE_BLOCK, EMERALD_ORE, END_STONE, FARMLAND, GLOWSTONE, GOLD_ORE,
case COAL_ORE: GRANITE, GRASS_BLOCK, IRON_ORE, MAGMA_BLOCK, MYCELIUM, NETHERITE_BLOCK, NETHERRACK, RED_SAND,
case COARSE_DIRT: RED_SANDSTONE, ROOTED_DIRT, SAND, SANDSTONE, SOUL_SAND, SOUL_SOIL, STONE, TERRACOTTA, AMETHYST_BLOCK,
case COBBLESTONE: AMETHYST_CLUSTER, AMETHYST_SHARD, BASALT, BLACKSTONE, BLACK_CONCRETE, BLACK_GLAZED_TERRACOTTA,
case COPPER_ORE: BLACK_TERRACOTTA, BLUE_CONCRETE, BLUE_GLAZED_TERRACOTTA, BLUE_TERRACOTTA, BONE_BLOCK, BROWN_CONCRETE,
case DEEPSLATE: BROWN_GLAZED_TERRACOTTA, BROWN_TERRACOTTA, BUDDING_AMETHYST, CHISELED_DEEPSLATE,
case DEEPSLATE_COAL_ORE: CHISELED_NETHER_BRICKS, CHISELED_POLISHED_BLACKSTONE, CHISELED_QUARTZ_BLOCK, CHISELED_RED_SANDSTONE,
case DEEPSLATE_COPPER_ORE: CHISELED_SANDSTONE, CHISELED_STONE_BRICKS, COAL_BLOCK, COBBLED_DEEPSLATE, CRYING_OBSIDIAN,
case DEEPSLATE_DIAMOND_ORE: CUT_RED_SANDSTONE, CUT_RED_SANDSTONE_SLAB, CUT_SANDSTONE, CUT_SANDSTONE_SLAB, CYAN_CONCRETE,
case DEEPSLATE_EMERALD_ORE: CYAN_GLAZED_TERRACOTTA, CYAN_TERRACOTTA, DEEPSLATE_BRICKS, DIAMOND_BLOCK, ECHO_SHARD, EMERALD_BLOCK,
case DEEPSLATE_GOLD_ORE: GOLD_BLOCK, GRAVEL, GRAY_CONCRETE, GRAY_GLAZED_TERRACOTTA, GRAY_TERRACOTTA, GREEN_CONCRETE,
case DEEPSLATE_IRON_ORE: GREEN_GLAZED_TERRACOTTA, GREEN_TERRACOTTA, INFESTED_CHISELED_STONE_BRICKS, INFESTED_COBBLESTONE,
case DEEPSLATE_LAPIS_ORE: INFESTED_CRACKED_STONE_BRICKS, INFESTED_DEEPSLATE, INFESTED_MOSSY_STONE_BRICKS, INFESTED_STONE,
case DEEPSLATE_REDSTONE_ORE: INFESTED_STONE_BRICKS, LAPIS_ORE, LARGE_AMETHYST_BUD, LIGHT_BLUE_CONCRETE,
case DIAMOND_ORE: LIGHT_BLUE_GLAZED_TERRACOTTA, LIGHT_BLUE_TERRACOTTA, LIGHT_GRAY_CONCRETE,
case DIORITE: LIGHT_GRAY_GLAZED_TERRACOTTA, LIGHT_GRAY_TERRACOTTA, LIME_CONCRETE, LIME_GLAZED_TERRACOTTA,
case DIRT: LIME_TERRACOTTA, MAGENTA_CONCRETE, MAGENTA_GLAZED_TERRACOTTA, MAGENTA_TERRACOTTA, MOSSY_COBBLESTONE,
case DIRT_PATH: MUD, NETHERITE_SCRAP, NETHER_GOLD_ORE, NETHER_QUARTZ_ORE, OBSIDIAN, ORANGE_CONCRETE,
case DRIPSTONE_BLOCK: ORANGE_GLAZED_TERRACOTTA, ORANGE_TERRACOTTA, PACKED_MUD, PINK_CONCRETE, PINK_GLAZED_TERRACOTTA,
case EMERALD_ORE: PINK_TERRACOTTA, PODZOL, POLISHED_ANDESITE, POLISHED_BASALT, POLISHED_BLACKSTONE,
case END_STONE: POLISHED_DEEPSLATE, POLISHED_DIORITE, POLISHED_GRANITE, PURPLE_CONCRETE, PURPLE_GLAZED_TERRACOTTA,
case FARMLAND: PURPLE_TERRACOTTA, PURPUR_BLOCK, QUARTZ_BLOCK, RAW_COPPER_BLOCK, RAW_GOLD_BLOCK, RAW_IRON_BLOCK,
case GLOWSTONE: REDSTONE_BLOCK, REDSTONE_ORE, RED_CONCRETE, RED_GLAZED_TERRACOTTA, RED_TERRACOTTA, SMOOTH_BASALT,
case GOLD_ORE: SMOOTH_QUARTZ, SMOOTH_RED_SANDSTONE, SMOOTH_SANDSTONE, SMOOTH_STONE, TUFF, WARPED_HYPHAE,
case GRANITE: WARPED_NYLIUM, WHITE_CONCRETE, WHITE_GLAZED_TERRACOTTA, WHITE_TERRACOTTA, YELLOW_CONCRETE,
case GRASS_BLOCK: YELLOW_GLAZED_TERRACOTTA, YELLOW_TERRACOTTA -> true;
case IRON_ORE: default -> false;
case MAGMA_BLOCK: };
case MYCELIUM:
case NETHERITE_BLOCK:
case NETHERRACK:
case RED_SAND:
case RED_SANDSTONE:
case ROOTED_DIRT:
case SAND:
case SANDSTONE:
case SOUL_SAND:
case SOUL_SOIL:
case STONE:
case TERRACOTTA:
case AMETHYST_BLOCK:
case AMETHYST_CLUSTER:
case AMETHYST_SHARD:
case BASALT:
case BLACKSTONE:
case BLACK_CONCRETE:
case BLACK_GLAZED_TERRACOTTA:
case BLACK_TERRACOTTA:
case BLUE_CONCRETE:
case BLUE_GLAZED_TERRACOTTA:
case BLUE_TERRACOTTA:
case BONE_BLOCK:
case BROWN_CONCRETE:
case BROWN_GLAZED_TERRACOTTA:
case BROWN_TERRACOTTA:
case BUDDING_AMETHYST:
case CHISELED_DEEPSLATE:
case CHISELED_NETHER_BRICKS:
case CHISELED_POLISHED_BLACKSTONE:
case CHISELED_QUARTZ_BLOCK:
case CHISELED_RED_SANDSTONE:
case CHISELED_SANDSTONE:
case CHISELED_STONE_BRICKS:
case COAL_BLOCK:
case COBBLED_DEEPSLATE:
case CRYING_OBSIDIAN:
case CUT_RED_SANDSTONE:
case CUT_RED_SANDSTONE_SLAB:
case CUT_SANDSTONE:
case CUT_SANDSTONE_SLAB:
case CYAN_CONCRETE:
case CYAN_GLAZED_TERRACOTTA:
case CYAN_TERRACOTTA:
case DEEPSLATE_BRICKS:
case DIAMOND_BLOCK:
case ECHO_SHARD:
case EMERALD_BLOCK:
case GOLD_BLOCK:
case GRAVEL:
case GRAY_CONCRETE:
case GRAY_GLAZED_TERRACOTTA:
case GRAY_TERRACOTTA:
case GREEN_CONCRETE:
case GREEN_GLAZED_TERRACOTTA:
case GREEN_TERRACOTTA:
case INFESTED_CHISELED_STONE_BRICKS:
case INFESTED_COBBLESTONE:
case INFESTED_CRACKED_STONE_BRICKS:
case INFESTED_DEEPSLATE:
case INFESTED_MOSSY_STONE_BRICKS:
case INFESTED_STONE:
case INFESTED_STONE_BRICKS:
case LAPIS_ORE:
case LARGE_AMETHYST_BUD:
case LIGHT_BLUE_CONCRETE:
case LIGHT_BLUE_GLAZED_TERRACOTTA:
case LIGHT_BLUE_TERRACOTTA:
case LIGHT_GRAY_CONCRETE:
case LIGHT_GRAY_GLAZED_TERRACOTTA:
case LIGHT_GRAY_TERRACOTTA:
case LIME_CONCRETE:
case LIME_GLAZED_TERRACOTTA:
case LIME_TERRACOTTA:
case MAGENTA_CONCRETE:
case MAGENTA_GLAZED_TERRACOTTA:
case MAGENTA_TERRACOTTA:
case MOSSY_COBBLESTONE:
case MUD:
case NETHERITE_SCRAP:
case NETHER_GOLD_ORE:
case NETHER_QUARTZ_ORE:
case OBSIDIAN:
case ORANGE_CONCRETE:
case ORANGE_GLAZED_TERRACOTTA:
case ORANGE_TERRACOTTA:
case PACKED_MUD:
case PINK_CONCRETE:
case PINK_GLAZED_TERRACOTTA:
case PINK_TERRACOTTA:
case PODZOL:
case POLISHED_ANDESITE:
case POLISHED_BASALT:
case POLISHED_BLACKSTONE:
case POLISHED_DEEPSLATE:
case POLISHED_DIORITE:
case POLISHED_GRANITE:
case PURPLE_CONCRETE:
case PURPLE_GLAZED_TERRACOTTA:
case PURPLE_TERRACOTTA:
case PURPUR_BLOCK:
case QUARTZ_BLOCK:
case RAW_COPPER_BLOCK:
case RAW_GOLD_BLOCK:
case RAW_IRON_BLOCK:
case REDSTONE_BLOCK:
case REDSTONE_ORE:
case RED_CONCRETE:
case RED_GLAZED_TERRACOTTA:
case RED_TERRACOTTA:
case SMOOTH_BASALT:
case SMOOTH_QUARTZ:
case SMOOTH_RED_SANDSTONE:
case SMOOTH_SANDSTONE:
case SMOOTH_STONE:
case TUFF:
case WARPED_HYPHAE:
case WARPED_NYLIUM:
case WHITE_CONCRETE:
case WHITE_GLAZED_TERRACOTTA:
case WHITE_TERRACOTTA:
case YELLOW_CONCRETE:
case YELLOW_GLAZED_TERRACOTTA:
case YELLOW_TERRACOTTA:
return true;
default:
return false;
}
} }
@Override @Override

View File

@ -123,7 +123,7 @@ public class AdvancementListener implements Listener {
/** /**
* Synchronize the player's advancements to that of the island. * Synchronize the player's advancements to that of the island.
* Player's advancements should be cleared before calling this othewise they will get add the island ones as well. * Player's advancements should be cleared before calling this otherwise they will get add the island ones as well.
* @param user - user * @param user - user
*/ */
public void syncAdvancements(User user) { public void syncAdvancements(User user) {

View File

@ -321,7 +321,7 @@ boxed:
LOCK: LOCK:
name: Lock player box name: Lock player box
OFFLINE_REDSTONE: OFFLINE_REDSTONE:
description: "&a When disabled, redstone\n&a will not operate in boxs\n&a\ description: "&a When disabled, redstone\n&a will not operate in boxes\n&a\
\ where all members are offline.\n&a May help reduce lag. " \ where all members are offline.\n&a May help reduce lag. "
PISTON_PUSH: PISTON_PUSH:
description: |- description: |-