diff --git a/README.md b/README.md index 771f2388..7ca5fe05 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,8 @@ building can start! * Powerful navigator which allows for an overview of all worlds. Extra GUIs for: - **_Not Started_**, **_In Progress_**, **_Almost Finished_** and **_Finished_** maps - Maps that have been put to the **_Archive_** - - **_Private_** player maps: Each player can create their own map, if a map with their name - doesn't exist + - **_Private_** player maps: Each player can create their own map, if a map with their name + doesn't exist * **Create worlds with ease**: When creating a world, choose from: - **_Predefined worlds_** _or_ - **_Custom generators_** provided by 3rd party plugins _or_ diff --git a/buildSrc/src/main/kotlin/CommonConfig.kt b/buildSrc/src/main/kotlin/CommonConfig.kt index 98e2de25..53699f6e 100644 --- a/buildSrc/src/main/kotlin/CommonConfig.kt +++ b/buildSrc/src/main/kotlin/CommonConfig.kt @@ -1,4 +1,3 @@ -import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.tasks.compile.JavaCompile @@ -12,7 +11,6 @@ fun Project.applyCommonConfiguration() { version = rootProject.version repositories { - mavenLocal() mavenCentral() maven { name = "Spigot" @@ -26,13 +24,11 @@ fun Project.applyCommonConfiguration() { name = "OSS Sonatype Snapshots" url = uri("https://oss.sonatype.org/content/repositories/snapshots/") } + mavenLocal() } plugins.withId("java") { the().apply { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - toolchain { languageVersion.set(JavaLanguageVersion.of(21)) } diff --git a/buildsystem-abstraction/adapter-1_20/src/main/java/de/eintosti/buildsystem/version/v1_20_R1/CustomBlocks_1_20_R1.java b/buildsystem-abstraction/adapter-1_20/src/main/java/de/eintosti/buildsystem/version/v1_20_R1/CustomBlocks_1_20_R1.java index 73799859..b3aadacd 100644 --- a/buildsystem-abstraction/adapter-1_20/src/main/java/de/eintosti/buildsystem/version/v1_20_R1/CustomBlocks_1_20_R1.java +++ b/buildsystem-abstraction/adapter-1_20/src/main/java/de/eintosti/buildsystem/version/v1_20_R1/CustomBlocks_1_20_R1.java @@ -28,7 +28,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Furnace; -import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Directional; import org.bukkit.block.data.Lightable; import org.bukkit.block.data.MultipleFacing; @@ -37,7 +36,6 @@ import org.bukkit.block.data.type.HangingSign; import org.bukkit.block.data.type.Sign; import org.bukkit.block.data.type.Slab; -import org.bukkit.entity.EntityType; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -182,17 +180,20 @@ public void setBlock(BlockPlaceEvent event, String key) { @EventHandler public void onInvisibleItemFramePlacement(HangingPlaceEvent event) { - if (event.getEntity().getType() != EntityType.ITEM_FRAME) { + if (!(event.getEntity() instanceof ItemFrame itemFrame)) { return; } ItemStack itemStack = event.getItemStack(); + if (itemStack == null) { + return; + } + ItemMeta itemMeta = itemStack.getItemMeta(); - if (!itemMeta.getPersistentDataContainer().has(this.invisibleFrameKey, PersistentDataType.BYTE)) { + if (itemMeta == null || !itemMeta.getPersistentDataContainer().has(this.invisibleFrameKey, PersistentDataType.BYTE)) { return; } - ItemFrame itemFrame = (ItemFrame) event.getEntity(); itemFrame.setVisible(false); } @@ -217,8 +218,7 @@ public void setPlant(PlayerInteractEvent event) { } adjacent.setType(material); MultipleFacing multipleFacing = (MultipleFacing) adjacent.getBlockData(); - Arrays.stream(DirectionUtil.BLOCK_SIDES) - .forEach(blockFace -> multipleFacing.setFace(blockFace, blockFace == toPlace)); + Arrays.stream(DirectionUtil.BLOCK_SIDES).forEach(blockFace -> multipleFacing.setFace(blockFace, blockFace == toPlace)); adjacent.setBlockData(multipleFacing); break; default: @@ -230,11 +230,10 @@ public void setPlant(PlayerInteractEvent event) { @Override public void modifySlab(PlayerInteractEvent event) { Block block = event.getClickedBlock(); - if (block == null || !(block.getBlockData() instanceof Slab)) { + if (block == null || !(block.getBlockData() instanceof Slab slab)) { return; } - Slab slab = (Slab) block.getBlockData(); if (slab.getType() != Slab.Type.DOUBLE) { return; } @@ -283,38 +282,30 @@ private void open(Block block) { @Override public void rotateBlock(Block block, Player player, BlockFace direction) { - BlockData blockData = block.getBlockData(); - - if (blockData instanceof Directional) { - Directional directional = (Directional) blockData; - directional.setFacing(direction); - block.setBlockData(directional); - } else if (blockData instanceof Orientable) { - Orientable orientable = (Orientable) blockData; - Axis axis; - switch (direction) { - case UP: - case DOWN: - axis = Axis.Y; - break; - case EAST: - case WEST: - axis = Axis.X; - break; - default: - axis = Axis.Z; - break; + switch (block.getBlockData()) { + case Directional directional -> { + directional.setFacing(direction); + block.setBlockData(directional); + } + case Orientable orientable -> { + Axis axis = switch (direction) { + case UP, DOWN -> Axis.Y; + case EAST, WEST -> Axis.X; + default -> Axis.Z; + }; + orientable.setAxis(axis); + block.setBlockData(orientable); + } + case Sign sign -> { + sign.setRotation(direction); + block.setBlockData(sign); + } + case HangingSign hangingSign -> { + hangingSign.setRotation(direction); + block.setBlockData(hangingSign); + } + default -> { } - orientable.setAxis(axis); - block.setBlockData(orientable); - } else if (blockData instanceof Sign) { - Sign sign = (Sign) blockData; - sign.setRotation(direction); - block.setBlockData(sign); - } else if (blockData instanceof HangingSign) { - HangingSign hangingSign = (HangingSign) blockData; - hangingSign.setRotation(direction); - block.setBlockData(hangingSign); } } } \ No newline at end of file diff --git a/buildsystem-abstraction/common/src/main/java/de/eintosti/buildsystem/version/util/DirectionUtil.java b/buildsystem-abstraction/common/src/main/java/de/eintosti/buildsystem/version/util/DirectionUtil.java index 5dc22187..546bf093 100644 --- a/buildsystem-abstraction/common/src/main/java/de/eintosti/buildsystem/version/util/DirectionUtil.java +++ b/buildsystem-abstraction/common/src/main/java/de/eintosti/buildsystem/version/util/DirectionUtil.java @@ -34,40 +34,24 @@ public static BlockFace getPlayerDirection(Player player) { yaw %= 360; int i = (int) ((yaw + 8) / 22.5); - switch (i) { - case 1: - return BlockFace.SOUTH_SOUTH_WEST; - case 2: - return BlockFace.SOUTH_WEST; - case 3: - return BlockFace.WEST_SOUTH_WEST; - case 4: - return BlockFace.WEST; - case 5: - return BlockFace.WEST_NORTH_WEST; - case 6: - return BlockFace.NORTH_WEST; - case 7: - return BlockFace.NORTH_NORTH_WEST; - case 8: - return BlockFace.NORTH; - case 9: - return BlockFace.NORTH_NORTH_EAST; - case 10: - return BlockFace.NORTH_EAST; - case 11: - return BlockFace.EAST_NORTH_EAST; - case 12: - return BlockFace.EAST; - case 13: - return BlockFace.EAST_SOUTH_EAST; - case 14: - return BlockFace.SOUTH_EAST; - case 15: - return BlockFace.SOUTH_SOUTH_EAST; - default: - return BlockFace.SOUTH; - } + return switch (i) { + case 1 -> BlockFace.SOUTH_SOUTH_WEST; + case 2 -> BlockFace.SOUTH_WEST; + case 3 -> BlockFace.WEST_SOUTH_WEST; + case 4 -> BlockFace.WEST; + case 5 -> BlockFace.WEST_NORTH_WEST; + case 6 -> BlockFace.NORTH_WEST; + case 7 -> BlockFace.NORTH_NORTH_WEST; + case 8 -> BlockFace.NORTH; + case 9 -> BlockFace.NORTH_NORTH_EAST; + case 10 -> BlockFace.NORTH_EAST; + case 11 -> BlockFace.EAST_NORTH_EAST; + case 12 -> BlockFace.EAST; + case 13 -> BlockFace.EAST_SOUTH_EAST; + case 14 -> BlockFace.SOUTH_EAST; + case 15 -> BlockFace.SOUTH_SOUTH_EAST; + default -> BlockFace.SOUTH; + }; } /** @@ -100,29 +84,12 @@ public static BlockFace getCardinalDirection(Player player) { yaw %= 360; int i = (int) ((yaw + 8) / 22.5); - switch (i) { - case 15: - case 0: - case 1: - case 2: - return BlockFace.NORTH; - case 3: - case 4: - case 5: - case 6: - return BlockFace.EAST; - case 7: - case 8: - case 9: - case 10: - return BlockFace.SOUTH; - case 11: - case 12: - case 13: - case 14: - return BlockFace.WEST; - } + return switch (i) { + case 3, 4, 5, 6 -> BlockFace.EAST; + case 7, 8, 9, 10 -> BlockFace.SOUTH; + case 11, 12, 13, 14 -> BlockFace.WEST; + default -> BlockFace.NORTH; + }; - return BlockFace.NORTH; } } \ No newline at end of file diff --git a/buildsystem-api/build.gradle.kts b/buildsystem-api/build.gradle.kts index d3fd8ed9..45fba7a5 100644 --- a/buildsystem-api/build.gradle.kts +++ b/buildsystem-api/build.gradle.kts @@ -23,7 +23,7 @@ tasks { opt.overview("javadoc/overview.html") opt.encoding("UTF-8") opt.charSet("UTF-8") - opt.links("https://docs.oracle.com/javase/8/docs/api/") + opt.links("https://docs.oracle.com/javase/21/docs/api/") opt.links("https://hub.spigotmc.org/javadocs/spigot/") opt.links("https://javadoc.io/static/org.jetbrains/annotations/24.1.0/") opt.isLinkSource = true diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldEvent.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldEvent.java index 3894d3c1..fa4fca1a 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldEvent.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldEvent.java @@ -20,7 +20,7 @@ import de.eintosti.buildsystem.api.world.BuildWorld; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.ApiStatus.Internal; import org.jetbrains.annotations.NotNull; /** @@ -34,7 +34,7 @@ public class BuildWorldEvent extends Event { private final BuildWorld buildWorld; - @ApiStatus.Internal + @Internal public BuildWorldEvent(BuildWorld buildWorld) { this.buildWorld = buildWorld; } diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldLoadEvent.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldLoadEvent.java index 76b80dd0..80a9e30d 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldLoadEvent.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldLoadEvent.java @@ -19,7 +19,7 @@ import de.eintosti.buildsystem.api.world.BuildWorld; import org.bukkit.event.Cancellable; -import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.ApiStatus.Internal; /** * Called when a {@link BuildWorld} is loaded. @@ -30,7 +30,7 @@ public class BuildWorldLoadEvent extends BuildWorldEvent implements Cancellable private boolean cancelled = false; - @ApiStatus.Internal + @Internal public BuildWorldLoadEvent(BuildWorld buildWorld) { super(buildWorld); } diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldPostLoadEvent.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldPostLoadEvent.java index a926ebe7..2603c26d 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldPostLoadEvent.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldPostLoadEvent.java @@ -18,7 +18,7 @@ package de.eintosti.buildsystem.api.event.world; import de.eintosti.buildsystem.api.world.BuildWorld; -import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.ApiStatus.Internal; /** * Called after a {@link BuildWorld} has loaded. @@ -27,7 +27,7 @@ */ public class BuildWorldPostLoadEvent extends BuildWorldEvent { - @ApiStatus.Internal + @Internal public BuildWorldPostLoadEvent(BuildWorld buildWorld) { super(buildWorld); } diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldPostUnloadEvent.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldPostUnloadEvent.java index f6124a90..7d131511 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldPostUnloadEvent.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldPostUnloadEvent.java @@ -18,7 +18,7 @@ package de.eintosti.buildsystem.api.event.world; import de.eintosti.buildsystem.api.world.BuildWorld; -import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.ApiStatus.Internal; /** * Called after a {@link BuildWorld} has unloaded. @@ -27,7 +27,7 @@ */ public class BuildWorldPostUnloadEvent extends BuildWorldEvent { - @ApiStatus.Internal + @Internal public BuildWorldPostUnloadEvent(BuildWorld buildWorld) { super(buildWorld); } diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldUnloadEvent.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldUnloadEvent.java index 51e7df7f..c292be87 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldUnloadEvent.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/event/world/BuildWorldUnloadEvent.java @@ -19,7 +19,7 @@ import de.eintosti.buildsystem.api.world.BuildWorld; import org.bukkit.event.Cancellable; -import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.ApiStatus.Internal; /** * Called when a {@link BuildWorld} is unloaded. @@ -30,7 +30,7 @@ public class BuildWorldUnloadEvent extends BuildWorldEvent implements Cancellabl private boolean cancelled = false; - @ApiStatus.Internal + @Internal public BuildWorldUnloadEvent(BuildWorld buildWorld) { super(buildWorld); } diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/NavigatorType.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/NavigatorType.java index 11f0c5b1..ce5567af 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/NavigatorType.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/NavigatorType.java @@ -24,5 +24,5 @@ */ public enum NavigatorType { OLD, - NEW; + NEW } \ No newline at end of file diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldFilter.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldFilter.java index 46be9d4a..d470a4ba 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldFilter.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldFilter.java @@ -19,7 +19,6 @@ import de.eintosti.buildsystem.api.world.BuildWorld; import java.util.function.Predicate; -import org.jetbrains.annotations.ApiStatus.Internal; /** * Interface for a world filter that restricts which {@link BuildWorld}s are shown to a user in the navigator. @@ -29,33 +28,18 @@ public interface WorldFilter { enum Mode { - NONE("world_filter_mode_none"), - STARTS_WITH("world_filter_mode_starts_with"), - CONTAINS("world_filter_mode_contains"), - MATCHES("world_filter_mode_matches"); - - private final String loreKey; - - Mode(String loreKey) { - this.loreKey = loreKey; - } - - @Internal - public String getLoreKey() { - return loreKey; - } + NONE, + STARTS_WITH, + CONTAINS, + MATCHES; public Mode getNext() { - switch (this) { - case STARTS_WITH: - return CONTAINS; - case CONTAINS: - return MATCHES; - case MATCHES: - return NONE; - default: // NONE - return STARTS_WITH; - } + return switch (this) { + case NONE -> STARTS_WITH; + case STARTS_WITH -> CONTAINS; + case CONTAINS -> MATCHES; + case MATCHES -> NONE; + }; } } diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldSort.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldSort.java index d02e9a99..4177a921 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldSort.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldSort.java @@ -17,7 +17,12 @@ */ package de.eintosti.buildsystem.api.navigator.settings; -import org.jetbrains.annotations.ApiStatus.Internal; +import de.eintosti.buildsystem.api.world.BuildWorld; +import de.eintosti.buildsystem.api.world.data.BuildWorldStatus; +import de.eintosti.buildsystem.api.world.display.Displayable; +import de.eintosti.buildsystem.api.world.display.Folder; +import java.util.Comparator; +import java.util.Locale; /** * Represents the sorting options for worlds in the navigator. @@ -29,52 +34,73 @@ public enum WorldSort { /** * Sort worlds by name in ascending order. */ - NAME_A_TO_Z("world_sort_name_az"), + NAME_A_TO_Z(Comparator.comparing(WorldSort::getNameSortKey)), /** * Sort worlds by name in descending order. */ - NAME_Z_TO_A("world_sort_name_za"), + NAME_Z_TO_A(NAME_A_TO_Z.getComparator().reversed()), /** * Sort worlds by project in ascending order. */ - PROJECT_A_TO_Z("world_sort_project_az"), + PROJECT_A_TO_Z(Comparator.comparing(WorldSort::getProjectSortKey)), /** * Sort worlds by project in descending order. */ - PROJECT_Z_TO_A("world_sort_project_za"), + PROJECT_Z_TO_A(PROJECT_A_TO_Z.getComparator().reversed()), /** - * Sort worlds by status ("Not Started" -> "Finished"). + * Sort worlds by status ({@link BuildWorldStatus#NOT_STARTED} -> {@link BuildWorldStatus#FINISHED}). */ - STATUS_NOT_STARTED("world_sort_status_not_started"), + STATUS_NOT_STARTED(Comparator.comparingInt(WorldSort::getStatusSortKey)), /** - * Sort worlds by status ("Finished" -> "Not Started"). + * Sort worlds by status ({@link BuildWorldStatus#FINISHED} -> {@link BuildWorldStatus#NOT_STARTED}). */ - STATUS_FINISHED("world_sort_status_finished"), + STATUS_FINISHED(STATUS_NOT_STARTED.getComparator().reversed()), + + /** + * Sort worlds by creation date in ascending order (oldest first). + */ + OLDEST_FIRST(Comparator.comparingLong(Displayable::getCreation)), /** * Sort worlds by creation date in descending order (newest first). */ - NEWEST_FIRST("world_sort_date_newest"), + NEWEST_FIRST(OLDEST_FIRST.getComparator().reversed()); + + private final Comparator comparator; + + WorldSort(Comparator comparator) { + this.comparator = comparator; + } /** - * Sort worlds by creation date in ascending order (oldest first). + * Gets the pre-configured comparator for this sort order. */ - OLDEST_FIRST("world_sort_date_oldest"); + public Comparator getComparator() { + return this.comparator; + } - private final String messageKey; + private static String getNameSortKey(Displayable displayable) { + return displayable.getName().toLowerCase(Locale.ROOT); + } - WorldSort(String messageKey) { - this.messageKey = messageKey; + private static String getProjectSortKey(Displayable displayable) { + return switch (displayable) { + case BuildWorld world -> world.getData().project().get().toLowerCase(Locale.ROOT); + case Folder folder -> folder.getProject().toLowerCase(Locale.ROOT); + default -> ""; + }; } - @Internal - public String getMessageKey() { - return messageKey; + private static int getStatusSortKey(Displayable displayable) { + if (displayable instanceof BuildWorld buildWorld) { + return buildWorld.getData().status().get().getStage(); + } + return BuildWorldStatus.FINISHED.getStage(); } public static WorldSort matchWorldSort(String type) { diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/player/LogoutLocation.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/player/LogoutLocation.java index 41c1fdd8..d78caf89 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/player/LogoutLocation.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/player/LogoutLocation.java @@ -28,7 +28,7 @@ @Internal public interface LogoutLocation { - String getWorldName(); + String worldName(); - Location getLocation(); + Location location(); } \ No newline at end of file diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/creation/generator/CustomGenerator.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/creation/generator/CustomGenerator.java index 445bde9c..5ac9a72b 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/creation/generator/CustomGenerator.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/creation/generator/CustomGenerator.java @@ -31,12 +31,12 @@ public interface CustomGenerator { * * @return The name */ - String getName(); + String name(); /** * Gets the chunk generator. * * @return The chunk generator */ - ChunkGenerator getChunkGenerator(); + ChunkGenerator chunkGenerator(); } \ No newline at end of file diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldStatus.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldStatus.java index fbd3b6ed..6793fc04 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldStatus.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldStatus.java @@ -19,7 +19,6 @@ import de.eintosti.buildsystem.api.world.BuildWorld; import java.util.Locale; -import org.jetbrains.annotations.ApiStatus.Internal; /** * @since 3.0.0 @@ -29,53 +28,41 @@ public enum BuildWorldStatus { /** * Represent a world that has not been modified. */ - NOT_STARTED("status_not_started", 1), + NOT_STARTED(1), /** * Represents a world that is currently being built. *

* The status is automatically switched to this when a block is placed/broken. */ - IN_PROGRESS("status_in_progress", 2), + IN_PROGRESS(2), /** * Represents a world that has almost been completed. */ - ALMOST_FINISHED("status_almost_finished", 3), + ALMOST_FINISHED(3), /** * Represents a world that has completed its building phase. */ - FINISHED("status_finished", 4), + FINISHED(4), /** * Represents an old world that has been finished for a while. Blocks cannot be placed/broken in archived worlds. */ - ARCHIVE("status_archive", 5), + ARCHIVE(5), /** * Represents a world not shown in the navigator. */ - HIDDEN("status_hidden", 6); + HIDDEN(6); - private final String messageKey; private final int stage; - BuildWorldStatus(String messageKey, int stage) { - this.messageKey = messageKey; + BuildWorldStatus(int stage) { this.stage = stage; } - /** - * Gets the display name of the status. - * - * @return The type's display name - */ - @Internal - public String getMessageKey() { - return messageKey; - } - /** * Gets the permission needed to change the status. * diff --git a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldType.java b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldType.java index a78ee2d5..ac30d326 100644 --- a/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldType.java +++ b/buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldType.java @@ -18,8 +18,6 @@ package de.eintosti.buildsystem.api.world.data; import org.bukkit.World.Environment; -import org.jetbrains.annotations.ApiStatus.Internal; -import org.jetbrains.annotations.Nullable; /** * @since 3.0.0 @@ -29,67 +27,50 @@ public enum BuildWorldType { /** * The equivalent to a default Minecraft world with {@link Environment#NORMAL}. */ - NORMAL("type_normal"), + NORMAL(), /** * The equivalent to a super-flat Minecraft world. */ - FLAT("type_flat"), + FLAT(), /** * The equivalent to a default Minecraft world with {@link Environment#NETHER}. */ - NETHER("type_nether"), + NETHER(), /** * The equivalent to a default Minecraft world with {@link Environment#THE_END}. */ - END("type_end"), + END(), /** * A completely empty world with no blocks at all, except the block a player spawns on. */ - VOID("type_void"), + VOID(), /** * A world which is an identical copy of a provided template. */ - TEMPLATE("type_template"), + TEMPLATE(), /** * A world which by default cannot be modified by any player except for the creator. */ - PRIVATE("type_private"), + PRIVATE(), /** * A world which was not created by BuildSystem but was imported, so it can be used by the plugin. */ - IMPORTED(null), + IMPORTED(), /** * A world with a custom chunk generator */ - CUSTOM("type_custom"), + CUSTOM(), /** * A world with an unknown type. */ - UNKNOWN(null); - - private final String messageKey; - - BuildWorldType(String messageKey) { - this.messageKey = messageKey; - } - - /** - * Get the message key for the {@link BuildWorldType}'s display name. - * - * @return The type's display name message key, or {@code null} for {@link #IMPORTED} and {@link #UNKNOWN} - */ - @Internal - @Nullable - public String getMessageKey() { - return messageKey; - } + UNKNOWN() } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/Messages.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/Messages.java index 8e48bd0c..548eb17e 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/Messages.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/Messages.java @@ -17,6 +17,8 @@ */ package de.eintosti.buildsystem; +import de.eintosti.buildsystem.api.world.data.BuildWorldStatus; +import de.eintosti.buildsystem.api.world.data.BuildWorldType; import de.eintosti.buildsystem.util.color.ColorAPI; import java.io.File; import java.io.FileOutputStream; @@ -999,6 +1001,43 @@ public static List getStringList(String key, @Nullable Player player, Fu .collect(Collectors.toList()); } + /** + * Gets the message key for the {@link BuildWorldStatus}'s display name. + * + * @return The type's display name message key + */ + public static String getMessageKey(BuildWorldStatus status) { + return switch (status) { + case NOT_STARTED -> "status_not_started"; + case IN_PROGRESS -> "status_in_progress"; + case ALMOST_FINISHED -> "status_almost_finished"; + case FINISHED -> "status_finished"; + case ARCHIVE -> "status_archive"; + case HIDDEN -> "status_hidden"; + }; + } + + /** + * Get the message key for the {@link BuildWorldType}'s display name. + * + * @return The type's display name message key, or {@code null} for {@link BuildWorldType#IMPORTED} and {@link BuildWorldType#UNKNOWN} + */ + @Nullable + public static String getMessageKey(BuildWorldType type) { + return switch (type) { + case NORMAL -> "type_normal"; + case FLAT -> "type_flat"; + case NETHER -> "type_nether"; + case END -> "type_end"; + case VOID -> "type_void"; + case TEMPLATE -> "type_template"; + case PRIVATE -> "type_private"; + case IMPORTED -> null; // No message key for imported worlds + case CUSTOM -> "type_custom"; + case UNKNOWN -> null; // No message key for unknown worlds + }; + } + @SafeVarargs private static String replacePlaceholders(String query, Map.Entry... placeholders) { if (placeholders.length == 0) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BackCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BackCommand.java index 306b9090..c397747f 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BackCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BackCommand.java @@ -44,12 +44,11 @@ public BackCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.back")) { Messages.sendPermissionError(player); return true; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BlocksCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BlocksCommand.java index 6d50ca3b..2ca1a416 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BlocksCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BlocksCommand.java @@ -36,12 +36,11 @@ public BlocksCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.blocks")) { Messages.sendPermissionError(player); return true; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildCommand.java index 282e1338..2ae812c9 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildCommand.java @@ -23,7 +23,7 @@ import de.eintosti.buildsystem.api.player.BuildPlayer; import de.eintosti.buildsystem.api.player.CachedValues; import de.eintosti.buildsystem.api.player.PlayerService; -import java.util.AbstractMap; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -46,12 +46,11 @@ public BuildCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.build")) { Messages.sendPermissionError(player); return true; @@ -102,8 +101,8 @@ private void toggleBuildMode(Player target, Player sender, boolean self) { Messages.sendMessage(target, "build_deactivated_self"); } else { XSound.ENTITY_EXPERIENCE_ORB_PICKUP.play(sender); - Messages.sendMessage(sender, "build_deactivated_other_sender", new AbstractMap.SimpleEntry<>("%target%", target.getName())); - Messages.sendMessage(target, "build_deactivated_other_target", new AbstractMap.SimpleEntry<>("%sender%", sender.getName())); + Messages.sendMessage(sender, "build_deactivated_other_sender", Map.entry("%target%", target.getName())); + Messages.sendMessage(target, "build_deactivated_other_target", Map.entry("%sender%", sender.getName())); } } else { playerService.getBuildModePlayers().add(targetUuid); @@ -116,8 +115,8 @@ private void toggleBuildMode(Player target, Player sender, boolean self) { Messages.sendMessage(target, "build_activated_self"); } else { XSound.ENTITY_EXPERIENCE_ORB_PICKUP.play(sender); - Messages.sendMessage(sender, "build_activated_other_sender", new AbstractMap.SimpleEntry<>("%target%", target.getName())); - Messages.sendMessage(target, "build_activated_other_target", new AbstractMap.SimpleEntry<>("%sender%", sender.getName())); + Messages.sendMessage(sender, "build_activated_other_sender", Map.entry("%target%", target.getName())); + Messages.sendMessage(target, "build_activated_other_target", Map.entry("%sender%", sender.getName())); } } } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java index c809307f..e03a9e2c 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildSystemCommand.java @@ -41,12 +41,11 @@ public BuildSystemCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.help.buildsystem")) { Messages.sendPermissionError(player); return true; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/ExplosionsCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/ExplosionsCommand.java index 545e5d62..8c901fa0 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/ExplosionsCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/ExplosionsCommand.java @@ -23,7 +23,7 @@ import de.eintosti.buildsystem.api.world.data.WorldData; import de.eintosti.buildsystem.storage.WorldStorageImpl; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.Command; @@ -45,12 +45,11 @@ public ExplosionsCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; String worldName = args.length == 0 ? player.getWorld().getName() : args[0]; BuildWorld buildWorld = worldStorage.getBuildWorld(worldName); if (WorldPermissionsImpl.of(buildWorld).canPerformCommand(player, "buildsystem.explosions")) { @@ -88,10 +87,10 @@ private void toggleExplosions(Player player, World bukkitWorld) { WorldData worldData = buildWorld.getData(); if (!worldData.explosions().get()) { worldData.explosions().set(true); - Messages.sendMessage(player, "explosions_activated", new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())); + Messages.sendMessage(player, "explosions_activated", Map.entry("%world%", buildWorld.getName())); } else { worldData.explosions().set(false); - Messages.sendMessage(player, "explosions_deactivated", new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())); + Messages.sendMessage(player, "explosions_deactivated", Map.entry("%world%", buildWorld.getName())); } } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/GamemodeCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/GamemodeCommand.java index 33e0fcf1..da8dec7a 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/GamemodeCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/GamemodeCommand.java @@ -19,8 +19,8 @@ import de.eintosti.buildsystem.BuildSystemPlugin; import de.eintosti.buildsystem.Messages; -import java.util.AbstractMap; import java.util.Locale; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.command.Command; @@ -40,12 +40,11 @@ public GamemodeCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (args.length == 0) { sendUsageMessage(player); return true; @@ -105,7 +104,7 @@ private void setPlayerGamemode(Player player, GameMode gameMode, String gameMode } player.setGameMode(gameMode); - Messages.sendMessage(player, "gamemode_set_self", new AbstractMap.SimpleEntry<>("%gamemode%", gameModeName)); + Messages.sendMessage(player, "gamemode_set_self", Map.entry("%gamemode%", gameModeName)); } private void setTargetGamemode(Player player, String[] args, GameMode gameMode, String gameModeName) { @@ -121,10 +120,10 @@ private void setTargetGamemode(Player player, String[] args, GameMode gameMode, } target.setGameMode(gameMode); - Messages.sendMessage(target, "gamemode_set_self", new AbstractMap.SimpleEntry<>("%gamemode%", gameModeName)); + Messages.sendMessage(target, "gamemode_set_self", Map.entry("%gamemode%", gameModeName)); Messages.sendMessage(player, "gamemode_set_other", - new AbstractMap.SimpleEntry<>("%target%", target.getName()), - new AbstractMap.SimpleEntry<>("%gamemode%", gameModeName) + Map.entry("%target%", target.getName()), + Map.entry("%gamemode%", gameModeName) ); } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/NoAICommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/NoAICommand.java index 705a54b6..102c24f9 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/NoAICommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/NoAICommand.java @@ -24,7 +24,7 @@ import de.eintosti.buildsystem.storage.WorldStorageImpl; import de.eintosti.buildsystem.util.EntityAIManager; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.Command; @@ -48,12 +48,11 @@ public NoAICommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; String worldName = args.length == 0 ? player.getWorld().getName() : args[0]; BuildWorld buildWorld = worldStorage.getBuildWorld(worldName); if (WorldPermissionsImpl.of(buildWorld).canPerformCommand(player, "buildsystem.noai")) { @@ -91,16 +90,16 @@ private void toggleAI(Player player, World bukkitWorld) { WorldData worldData = buildWorld.getData(); if (worldData.mobAi().get()) { worldData.mobAi().set(false); - Messages.sendMessage(player, "noai_activated", new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())); + Messages.sendMessage(player, "noai_activated", Map.entry("%world%", buildWorld.getName())); } else { worldData.mobAi().set(true); - Messages.sendMessage(player, "noai_deactivated", new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())); + Messages.sendMessage(player, "noai_deactivated", Map.entry("%world%", buildWorld.getName())); } boolean mobAI = worldData.mobAi().get(); for (Entity entity : bukkitWorld.getEntities()) { - if (entity instanceof LivingEntity) { - EntityAIManager.setAIEnabled((LivingEntity) entity, mobAI); + if (entity instanceof LivingEntity livingEntity) { + EntityAIManager.setAIEnabled(livingEntity, mobAI); } } } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PagedCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PagedCommand.java index e5be68d4..4b06a7d9 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PagedCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PagedCommand.java @@ -18,9 +18,9 @@ package de.eintosti.buildsystem.command; import de.eintosti.buildsystem.Messages; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.IntStream; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -85,7 +85,7 @@ protected TextComponent createComponent(Player player, String command, String co commandComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); commandComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder(Messages.getString(this.permissionTemplate, player, new AbstractMap.SimpleEntry<>("%permission%", permission))).create() + new ComponentBuilder(Messages.getString(this.permissionTemplate, player, Map.entry("%permission%", permission))).create() )); commandComponent.addExtra(textComponent); return commandComponent; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PhysicsCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PhysicsCommand.java index c621146d..bc28bbed 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PhysicsCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/PhysicsCommand.java @@ -23,7 +23,7 @@ import de.eintosti.buildsystem.api.world.data.WorldData; import de.eintosti.buildsystem.storage.WorldStorageImpl; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.Command; @@ -45,12 +45,11 @@ public PhysicsCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; String worldName = args.length == 0 ? player.getWorld().getName() : args[0]; BuildWorld buildWorld = worldStorage.getBuildWorld(worldName); if (WorldPermissionsImpl.of(buildWorld).canPerformCommand(player, "buildsystem.physics")) { @@ -93,10 +92,10 @@ private void togglePhysics(Player player, World bukkitWorld) { WorldData worldData = buildWorld.getData(); if (!worldData.physics().get()) { worldData.physics().set(true); - Messages.sendMessage(player, "physics_activated", new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())); + Messages.sendMessage(player, "physics_activated", Map.entry("%world%", buildWorld.getName())); } else { worldData.physics().set(false); - Messages.sendMessage(player, "physics_deactivated", new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())); + Messages.sendMessage(player, "physics_deactivated", Map.entry("%world%", buildWorld.getName())); } } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SettingsCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SettingsCommand.java index c3293ebb..8778ff71 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SettingsCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SettingsCommand.java @@ -36,12 +36,11 @@ public SettingsCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.settings")) { Messages.sendPermissionError(player); return true; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SetupCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SetupCommand.java index a8ad8a95..8b0834bb 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SetupCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SetupCommand.java @@ -36,12 +36,11 @@ public SetupCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.setup")) { Messages.sendPermissionError(player); return true; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SkullCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SkullCommand.java index 6cb8e652..0a47e179 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SkullCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SkullCommand.java @@ -21,7 +21,7 @@ import de.eintosti.buildsystem.BuildSystemPlugin; import de.eintosti.buildsystem.Messages; import de.eintosti.buildsystem.util.InventoryUtils; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -39,12 +39,11 @@ public SkullCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.skull")) { Messages.sendPermissionError(player); return true; @@ -53,7 +52,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N switch (args.length) { case 0: addSkull(player, "§b" + player.getName(), Profileable.of(player)); - Messages.sendMessage(player, "skull_player_received", new AbstractMap.SimpleEntry<>("%player%", player.getName())); + Messages.sendMessage(player, "skull_player_received", Map.entry("%player%", player.getName())); break; case 1: String identifier = args[0]; @@ -62,7 +61,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N Messages.sendMessage(player, "skull_custom_received"); } else { addSkull(player, "§b" + identifier, Profileable.detect(identifier)); - Messages.sendMessage(player, "skull_player_received", new AbstractMap.SimpleEntry<>("%player%", identifier)); + Messages.sendMessage(player, "skull_player_received", Map.entry("%player%", identifier)); } break; default: diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SpawnCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SpawnCommand.java index 1caae337..33e6b2bb 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SpawnCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SpawnCommand.java @@ -22,8 +22,8 @@ import de.eintosti.buildsystem.api.world.BuildWorld; import de.eintosti.buildsystem.storage.WorldStorageImpl; import de.eintosti.buildsystem.world.SpawnManager; -import java.util.AbstractMap; import java.util.Locale; +import java.util.Map; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.Command; @@ -47,13 +47,11 @@ public SpawnCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; - switch (args.length) { case 0: if (!spawnManager.teleport(player)) { @@ -86,10 +84,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N spawnManager.set(playerLocation, buildWorld.getName()); Messages.sendMessage(player, "spawn_set", - new AbstractMap.SimpleEntry<>("%x%", round(playerLocation.getX())), - new AbstractMap.SimpleEntry<>("%y%", round(playerLocation.getY())), - new AbstractMap.SimpleEntry<>("%z%", round(playerLocation.getZ())), - new AbstractMap.SimpleEntry<>("%world%", playerLocation.getWorld().getName()) + Map.entry("%x%", round(playerLocation.getX())), + Map.entry("%y%", round(playerLocation.getY())), + Map.entry("%z%", round(playerLocation.getZ())), + Map.entry("%world%", playerLocation.getWorld().getName()) ); break; case "remove": diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SpeedCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SpeedCommand.java index a6a84be0..4c5e5b37 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SpeedCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/SpeedCommand.java @@ -20,7 +20,7 @@ import com.cryptomorin.xseries.XSound; import de.eintosti.buildsystem.BuildSystemPlugin; import de.eintosti.buildsystem.Messages; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -29,6 +29,8 @@ public class SpeedCommand implements CommandExecutor { + private static final float INVALID_SPEED = -1.0f; + private final BuildSystemPlugin plugin; public SpeedCommand(BuildSystemPlugin plugin) { @@ -38,12 +40,11 @@ public SpeedCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.speed")) { Messages.sendPermissionError(player); return true; @@ -56,26 +57,21 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N break; case 1: String speedString = args[0]; - switch (speedString) { - case "1": - setSpeed(player, 0.2f, speedString); - break; - case "2": - setSpeed(player, 0.4f, speedString); - break; - case "3": - setSpeed(player, 0.6f, speedString); - break; - case "4": - setSpeed(player, 0.8f, speedString); - break; - case "5": - setSpeed(player, 1.0f, speedString); - break; - default: - Messages.sendMessage(player, "speed_usage"); - break; + float speed = switch (speedString) { + case "1" -> 0.2f; + case "2" -> 0.4f; + case "3" -> 0.6f; + case "4" -> 0.8f; + case "5" -> 1.0f; + default -> INVALID_SPEED; + }; + + if (speed == INVALID_SPEED) { + Messages.sendMessage(player, "speed_usage"); + return true; } + + setSpeed(player, speed, speedString); break; default: Messages.sendMessage(player, "speed_usage"); @@ -88,10 +84,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N private void setSpeed(Player player, float speed, String speedString) { if (player.isFlying()) { player.setFlySpeed(speed - 0.1f); - Messages.sendMessage(player, "speed_set_flying", new AbstractMap.SimpleEntry<>("%speed%", speedString)); + Messages.sendMessage(player, "speed_set_flying", Map.entry("%speed%", speedString)); } else { player.setWalkSpeed(speed); - Messages.sendMessage(player, "speed_set_walking", new AbstractMap.SimpleEntry<>("%speed%", speedString)); + Messages.sendMessage(player, "speed_set_walking", Map.entry("%speed%", speedString)); } } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/TimeCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/TimeCommand.java index 47ac946c..5eae75b6 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/TimeCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/TimeCommand.java @@ -22,8 +22,8 @@ import de.eintosti.buildsystem.api.world.BuildWorld; import de.eintosti.buildsystem.api.world.util.WorldPermissions; import de.eintosti.buildsystem.config.ConfigValues; -import java.util.AbstractMap; import java.util.Locale; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.Command; @@ -46,12 +46,11 @@ public TimeCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; String worldName = args.length == 0 ? player.getWorld().getName() : args[0]; World world = Bukkit.getWorld(worldName); if (world == null) { @@ -73,7 +72,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N case 0: case 1: world.setTime(configValues.getNoonTime()); - Messages.sendMessage(player, "day_set", new AbstractMap.SimpleEntry<>("%world%", world.getName())); + Messages.sendMessage(player, "day_set", Map.entry("%world%", world.getName())); break; default: Messages.sendMessage(player, "day_usage"); @@ -92,7 +91,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N case 0: case 1: world.setTime(configValues.getNightTime()); - Messages.sendMessage(player, "night_set", new AbstractMap.SimpleEntry<>("%world%", world.getName())); + Messages.sendMessage(player, "night_set", Map.entry("%world%", world.getName())); break; default: Messages.sendMessage(player, "night_usage"); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/TopCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/TopCommand.java index 7528dd14..5e0ec755 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/TopCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/TopCommand.java @@ -44,12 +44,11 @@ public TopCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.top")) { Messages.sendPermissionError(player); return true; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/WorldsCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/WorldsCommand.java index b5210309..eddb233b 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/WorldsCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/WorldsCommand.java @@ -60,11 +60,10 @@ public WorldsCommand(BuildSystemPlugin plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { plugin.getLogger().warning(Messages.getString("sender_not_player", null)); return true; } - Player player = (Player) sender; if (args.length == 0) { if (!player.hasPermission("buildsystem.navigator")) { @@ -83,100 +82,33 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N return true; } - // Most command use the structure /worlds <...> which is why we assume that args[1] is the world name + // Most commands use the structure /worlds <...> which is why we assume that args[1] is the world name // Make sure to change if this is not the case for any specific command String worldName = args.length >= 2 ? args[1] : player.getWorld().getName(); - SubCommand subCommand; - switch (argument) { - case ADD_BUILDER: { - subCommand = new AddBuilderSubCommand(plugin, player.getWorld().getName()); - break; - } - case BUILDERS: { - subCommand = new BuildersSubCommand(plugin, worldName); - break; - } - case DELETE: { - subCommand = new DeleteSubCommand(plugin, worldName); - break; - } - case EDIT: { - subCommand = new EditSubCommand(plugin, worldName); - break; - } - case FOLDER: { - subCommand = new FolderSubCommand(plugin); - break; - } - case HELP: { - subCommand = new HelpSubCommand(plugin); - break; - } - case IMPORT_ALL: { - subCommand = new ImportAllSubCommand(plugin); - break; - } - case IMPORT: { - subCommand = new ImportSubCommand(plugin, worldName); - break; - } - case INFO: { - subCommand = new InfoSubCommand(plugin, worldName); - break; - } - case ITEM: { - subCommand = new ItemSubCommand(plugin); - break; - } - case REMOVE_BUILDER: { - subCommand = new RemoveBuilderSubCommand(plugin, player.getWorld().getName()); - break; - } - case REMOVE_SPAWN: { - subCommand = new RemoveSpawnSubCommand(plugin); - break; - } - case RENAME: { - subCommand = new RenameSubCommand(plugin, worldName); - break; - } - case SET_CREATOR: { - subCommand = new SetCreatorSubCommand(plugin, worldName); - break; - } - case SET_ITEM: { - subCommand = new SetItemSubCommand(plugin, worldName); - break; - } - case SET_PERMISSION: { - subCommand = new SetPermissionSubCommand(plugin, worldName); - break; - } - case SET_PROJECT: { - subCommand = new SetProjectSubCommand(plugin, worldName); - break; - } - case SET_SPAWN: { - subCommand = new SetSpawnSubCommand(plugin); - break; - } - case SET_STATUS: { - subCommand = new SetStatusSubCommand(plugin, worldName); - break; - } - case TP: { - subCommand = new TeleportSubCommand(plugin); - break; - } - case UNIMPORT: { - subCommand = new UnimportSubCommand(plugin, worldName); - break; - } - default: { - throw new IllegalArgumentException("Could not find subcommand: " + argument.getName()); - } - } + SubCommand subCommand = switch (argument) { + case ADD_BUILDER -> new AddBuilderSubCommand(plugin, player.getWorld().getName()); + case BUILDERS -> new BuildersSubCommand(plugin, worldName); + case DELETE -> new DeleteSubCommand(plugin, worldName); + case EDIT -> new EditSubCommand(plugin, worldName); + case FOLDER -> new FolderSubCommand(plugin); + case HELP -> new HelpSubCommand(); + case IMPORT_ALL -> new ImportAllSubCommand(plugin); + case IMPORT -> new ImportSubCommand(plugin, worldName); + case INFO -> new InfoSubCommand(plugin, worldName); + case ITEM -> new ItemSubCommand(plugin); + case REMOVE_BUILDER -> new RemoveBuilderSubCommand(plugin, player.getWorld().getName()); + case REMOVE_SPAWN -> new RemoveSpawnSubCommand(plugin); + case RENAME -> new RenameSubCommand(plugin, worldName); + case SET_CREATOR -> new SetCreatorSubCommand(plugin, worldName); + case SET_ITEM -> new SetItemSubCommand(plugin, worldName); + case SET_PERMISSION -> new SetPermissionSubCommand(plugin, worldName); + case SET_PROJECT -> new SetProjectSubCommand(plugin, worldName); + case SET_SPAWN -> new SetSpawnSubCommand(plugin); + case SET_STATUS -> new SetStatusSubCommand(plugin, worldName); + case TP -> new TeleportSubCommand(plugin); + case UNIMPORT -> new UnimportSubCommand(plugin, worldName); + }; subCommand.execute(player, args); return true; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/AddBuilderSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/AddBuilderSubCommand.java index e7c25d32..86cb7e85 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/AddBuilderSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/AddBuilderSubCommand.java @@ -30,7 +30,7 @@ import de.eintosti.buildsystem.util.PlayerChatInput; import de.eintosti.buildsystem.util.UUIDFetcher; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -106,7 +106,7 @@ private void addBuilder(Player player, BuildWorld buildWorld, String builderName builders.addBuilder(builder); XSound.ENTITY_PLAYER_LEVELUP.play(player); Messages.sendMessage(player, "worlds_addbuilder_added", - new AbstractMap.SimpleEntry<>("%builder%", builderName) + Map.entry("%builder%", builderName) ); if (closeInventory) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/FolderSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/FolderSubCommand.java index f3aafbb4..95f72f93 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/FolderSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/FolderSubCommand.java @@ -30,8 +30,8 @@ import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete.WorldsArgument; import de.eintosti.buildsystem.util.PlayerChatInput; import de.eintosti.buildsystem.world.WorldServiceImpl; -import java.util.AbstractMap; import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -110,8 +110,8 @@ private void handleWorldFolderOperation(Player player, Folder folder, String ope return; } - Entry folderPlaceholder = new AbstractMap.SimpleEntry<>("%folder%", folder.getName()); - Entry worldPlaceholder = new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()); + Entry folderPlaceholder = Map.entry("%folder%", folder.getName()); + Entry worldPlaceholder = Map.entry("%world%", buildWorld.getName()); switch (operation) { case "add": @@ -132,8 +132,8 @@ private void handleWorldFolderOperation(Player player, Folder folder, String ope if (folder.getCategory() != NavigatorCategory.of(buildWorld)) { Messages.sendMessage(player, "worlds_folder_world_category_mismatch", - new AbstractMap.SimpleEntry<>("%folder_category%", folder.getCategory().name()), - new AbstractMap.SimpleEntry<>("%world_category%", NavigatorCategory.of(buildWorld).name()) + Map.entry("%folder_category%", folder.getCategory().name()), + Map.entry("%world_category%", NavigatorCategory.of(buildWorld).name()) ); return; } @@ -170,7 +170,7 @@ private void handlePermissionInput(Player player, Folder folder) { XSound.ENTITY_PLAYER_LEVELUP.play(player); Messages.sendMessage(player, "worlds_folder_permission_set", - new AbstractMap.SimpleEntry<>("%folder%", folder.getName()) + Map.entry("%folder%", folder.getName()) ); }); } @@ -186,7 +186,7 @@ private void handleProjectInput(Player player, Folder folder) { XSound.ENTITY_PLAYER_LEVELUP.play(player); Messages.sendMessage(player, "worlds_folder_project_set", - new AbstractMap.SimpleEntry<>("%folder%", folder.getName()) + Map.entry("%folder%", folder.getName()) ); }); } @@ -205,7 +205,7 @@ private void handleIconChange(Player player, Folder folder) { folder.setIcon(XMaterial.matchXMaterial(itemStack)); Messages.sendMessage(player, "worlds_folder_item_set", - new AbstractMap.SimpleEntry<>("%folder%", folder.getName()) + Map.entry("%folder%", folder.getName()) ); } @@ -217,14 +217,14 @@ private void handleDeletion(Player player, Folder folder) { if (folder.getWorldCount() > 0) { Messages.sendMessage(player, "worlds_folder_not_empty", - new AbstractMap.SimpleEntry<>("%folder%", folder.getName()) + Map.entry("%folder%", folder.getName()) ); return; } this.folderStorage.removeFolder(folder); Messages.sendMessage(player, "worlds_folder_deleted", - new AbstractMap.SimpleEntry<>("%folder%", folder.getName()) + Map.entry("%folder%", folder.getName()) ); XSound.ENTITY_PLAYER_LEVELUP.play(player); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/HelpSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/HelpSubCommand.java index a5dc8e77..1a4a1978 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/HelpSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/HelpSubCommand.java @@ -18,7 +18,6 @@ package de.eintosti.buildsystem.command.subcommand.worlds; import com.google.common.collect.Lists; -import de.eintosti.buildsystem.BuildSystemPlugin; import de.eintosti.buildsystem.Messages; import de.eintosti.buildsystem.command.PagedCommand; import de.eintosti.buildsystem.command.subcommand.Argument; @@ -30,11 +29,8 @@ public class HelpSubCommand extends PagedCommand implements SubCommand { - private final BuildSystemPlugin plugin; - - public HelpSubCommand(BuildSystemPlugin plugin) { + public HelpSubCommand() { super("worlds_help_title_with_page", "worlds_help_permission"); - this.plugin = plugin; } @Override diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/ImportSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/ImportSubCommand.java index d43ffd0f..18373be5 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/ImportSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/ImportSubCommand.java @@ -30,8 +30,8 @@ import de.eintosti.buildsystem.util.UUIDFetcher; import de.eintosti.buildsystem.world.WorldServiceImpl; import java.io.File; -import java.util.AbstractMap; import java.util.Locale; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -74,8 +74,8 @@ public void execute(Player player, String[] args) { String invalidChar = StringCleaner.firstInvalidChar(worldName); if (invalidChar != null) { Messages.sendMessage(player, "worlds_import_invalid_character", - new AbstractMap.SimpleEntry<>("%world%", worldName), - new AbstractMap.SimpleEntry<>("%char%", invalidChar) + Map.entry("%world%", worldName), + Map.entry("%char%", invalidChar) ); return; } @@ -131,7 +131,7 @@ public void execute(Player player, String[] args) { } Messages.sendMessage(player, "worlds_import_started", - new AbstractMap.SimpleEntry<>("%world%", worldName) + Map.entry("%world%", worldName) ); if (worldService.importWorld(player, worldName, creator, worldType, generator, generatorName, true)) { Messages.sendMessage(player, "worlds_import_finished"); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/InfoSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/InfoSubCommand.java index e988a5d0..738babb8 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/InfoSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/InfoSubCommand.java @@ -27,7 +27,7 @@ import de.eintosti.buildsystem.command.subcommand.SubCommand; import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -62,27 +62,27 @@ public void execute(Player player, String[] args) { Builders builders = buildWorld.getBuilders(); WorldData worldData = buildWorld.getData(); Messages.sendMessage(player, "world_info", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()), - new AbstractMap.SimpleEntry<>("%creator%", getCreator(builders)), - new AbstractMap.SimpleEntry<>("%item%", worldData.material().get().name()), - new AbstractMap.SimpleEntry<>("%type%", Messages.getString(buildWorld.getType().getMessageKey(), player)), - new AbstractMap.SimpleEntry<>("%private%", worldData.privateWorld().get()), - new AbstractMap.SimpleEntry<>("%builders_enabled%", worldData.buildersEnabled().get()), - new AbstractMap.SimpleEntry<>("%builders%", builders.asPlaceholder(player)), - new AbstractMap.SimpleEntry<>("%block_breaking%", worldData.blockBreaking().get()), - new AbstractMap.SimpleEntry<>("%block_placement%", worldData.blockPlacement().get()), - new AbstractMap.SimpleEntry<>("%status%", Messages.getString(worldData.status().get().getMessageKey(), player)), - new AbstractMap.SimpleEntry<>("%project%", worldData.project().get()), - new AbstractMap.SimpleEntry<>("%permission%", worldData.permission().get()), - new AbstractMap.SimpleEntry<>("%time%", buildWorld.getWorldTime()), - new AbstractMap.SimpleEntry<>("%creation%", Messages.formatDate(buildWorld.getCreation())), - new AbstractMap.SimpleEntry<>("%physics%", worldData.physics().get()), - new AbstractMap.SimpleEntry<>("%explosions%", worldData.explosions().get()), - new AbstractMap.SimpleEntry<>("%mobai%", worldData.mobAi().get()), - new AbstractMap.SimpleEntry<>("%custom_spawn%", getCustomSpawn(buildWorld)), - new AbstractMap.SimpleEntry<>("%lastedited%", Messages.formatDate(worldData.lastEdited().get())), - new AbstractMap.SimpleEntry<>("%lastloaded%", Messages.formatDate(worldData.lastLoaded().get())), - new AbstractMap.SimpleEntry<>("%lastunloaded%", Messages.formatDate(worldData.lastUnloaded().get())) + Map.entry("%world%", buildWorld.getName()), + Map.entry("%creator%", getCreator(builders)), + Map.entry("%item%", worldData.material().get().name()), + Map.entry("%type%", Messages.getString(Messages.getMessageKey(buildWorld.getType()), player)), + Map.entry("%private%", worldData.privateWorld().get()), + Map.entry("%builders_enabled%", worldData.buildersEnabled().get()), + Map.entry("%builders%", builders.asPlaceholder(player)), + Map.entry("%block_breaking%", worldData.blockBreaking().get()), + Map.entry("%block_placement%", worldData.blockPlacement().get()), + Map.entry("%status%", Messages.getString(Messages.getMessageKey(worldData.status().get()), player)), + Map.entry("%project%", worldData.project().get()), + Map.entry("%permission%", worldData.permission().get()), + Map.entry("%time%", buildWorld.getWorldTime()), + Map.entry("%creation%", Messages.formatDate(buildWorld.getCreation())), + Map.entry("%physics%", worldData.physics().get()), + Map.entry("%explosions%", worldData.explosions().get()), + Map.entry("%mobai%", worldData.mobAi().get()), + Map.entry("%custom_spawn%", getCustomSpawn(buildWorld)), + Map.entry("%lastedited%", Messages.formatDate(worldData.lastEdited().get())), + Map.entry("%lastloaded%", Messages.formatDate(worldData.lastLoaded().get())), + Map.entry("%lastunloaded%", Messages.formatDate(worldData.lastUnloaded().get())) ); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/RemoveBuilderSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/RemoveBuilderSubCommand.java index ef70936c..67858727 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/RemoveBuilderSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/RemoveBuilderSubCommand.java @@ -29,7 +29,7 @@ import de.eintosti.buildsystem.util.PlayerChatInput; import de.eintosti.buildsystem.util.UUIDFetcher; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -101,7 +101,7 @@ private void removeBuilder(Player player, BuildWorld buildWorld, String builderN builders.removeBuilder(builderId); XSound.ENTITY_PLAYER_LEVELUP.play(player); - Messages.sendMessage(player, "worlds_removebuilder_removed", new AbstractMap.SimpleEntry<>("%builder%", builderName)); + Messages.sendMessage(player, "worlds_removebuilder_removed", Map.entry("%builder%", builderName)); player.closeInventory(); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/RemoveSpawnSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/RemoveSpawnSubCommand.java index 979ad0ef..bc66b027 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/RemoveSpawnSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/RemoveSpawnSubCommand.java @@ -24,7 +24,7 @@ import de.eintosti.buildsystem.command.subcommand.SubCommand; import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.entity.Player; public class RemoveSpawnSubCommand implements SubCommand { @@ -50,7 +50,7 @@ public void execute(Player player, String[] args) { buildWorld.getData().customSpawn().set(null); Messages.sendMessage(player, "worlds_removespawn_world_spawn_removed", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()) + Map.entry("%world%", buildWorld.getName()) ); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetCreatorSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetCreatorSubCommand.java index c8a53b72..3e811d4e 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetCreatorSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetCreatorSubCommand.java @@ -28,7 +28,7 @@ import de.eintosti.buildsystem.util.PlayerChatInput; import de.eintosti.buildsystem.util.UUIDFetcher; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.entity.Player; public class SetCreatorSubCommand implements SubCommand { @@ -69,7 +69,7 @@ public void execute(Player player, String[] args) { plugin.getPlayerService().forceUpdateSidebar(buildWorld); XSound.ENTITY_PLAYER_LEVELUP.play(player); Messages.sendMessage(player, "worlds_setcreator_set", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()) + Map.entry("%world%", buildWorld.getName()) ); player.closeInventory(); }); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetItemSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetItemSubCommand.java index 4254342a..0bd21883 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetItemSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetItemSubCommand.java @@ -25,7 +25,7 @@ import de.eintosti.buildsystem.command.subcommand.SubCommand; import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -65,7 +65,7 @@ public void execute(Player player, String[] args) { buildWorld.getData().material().set(XMaterial.matchXMaterial(itemStack)); Messages.sendMessage(player, "worlds_setitem_set", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()) + Map.entry("%world%", buildWorld.getName()) ); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetPermissionSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetPermissionSubCommand.java index baceb47f..ab3de398 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetPermissionSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetPermissionSubCommand.java @@ -26,7 +26,7 @@ import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete; import de.eintosti.buildsystem.util.PlayerChatInput; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.entity.Player; public class SetPermissionSubCommand implements SubCommand { @@ -66,7 +66,7 @@ public void getPermissionInput(Player player, BuildWorld buildWorld, boolean clo XSound.ENTITY_PLAYER_LEVELUP.play(player); Messages.sendMessage(player, "worlds_setpermission_set", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()) + Map.entry("%world%", buildWorld.getName()) ); if (closeInventory) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetProjectSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetProjectSubCommand.java index 0129968c..5de51da6 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetProjectSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetProjectSubCommand.java @@ -26,7 +26,7 @@ import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete; import de.eintosti.buildsystem.util.PlayerChatInput; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.entity.Player; public class SetProjectSubCommand implements SubCommand { @@ -66,7 +66,7 @@ public void getProjectInput(Player player, BuildWorld buildWorld, boolean closeI XSound.ENTITY_PLAYER_LEVELUP.play(player); Messages.sendMessage(player, "worlds_setproject_set", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()) + Map.entry("%world%", buildWorld.getName()) ); if (closeInventory) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetSpawnSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetSpawnSubCommand.java index 288a6649..cfe153dc 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetSpawnSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/SetSpawnSubCommand.java @@ -24,7 +24,7 @@ import de.eintosti.buildsystem.command.subcommand.SubCommand; import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -54,7 +54,7 @@ public void execute(Player player, String[] args) { playerLocation.getX(), playerLocation.getY(), playerLocation.getZ(), playerLocation.getYaw(), playerLocation.getPitch() )); Messages.sendMessage(player, "worlds_setspawn_world_spawn_set", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()) + Map.entry("%world%", buildWorld.getName()) ); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/UnimportSubCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/UnimportSubCommand.java index 1bf5f44e..8961c410 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/UnimportSubCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/UnimportSubCommand.java @@ -24,7 +24,7 @@ import de.eintosti.buildsystem.command.subcommand.SubCommand; import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.entity.Player; public class UnimportSubCommand implements SubCommand { @@ -56,7 +56,7 @@ public void execute(Player player, String[] args) { plugin.getWorldService().unimportWorld(player, buildWorld, true); Messages.sendMessage(player, "worlds_unimport_finished", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()) + Map.entry("%world%", buildWorld.getName()) ); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/event/EventDispatcher.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/event/EventDispatcher.java index 1982e38e..f9ffdb4e 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/event/EventDispatcher.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/event/EventDispatcher.java @@ -27,8 +27,6 @@ /** * Manages the dispatching of custom events related to build world manipulations. - * - * @since TODO */ public class EventDispatcher { @@ -64,11 +62,11 @@ public void dispatchManipulationEventIfPlayerInBuildWorld(Player player, Cancell return; } - BuildWorld world = worldStorage.getBuildWorld(player.getWorld()); - if (world == null) { + BuildWorld buildWorld = worldStorage.getBuildWorld(player.getWorld()); + if (buildWorld == null) { return; } - Bukkit.getPluginManager().callEvent(new BuildWorldManipulationEvent(parentEvent, player, world)); + Bukkit.getPluginManager().callEvent(new BuildWorldManipulationEvent(parentEvent, player, buildWorld)); } } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/event/world/BuildWorldManipulationEvent.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/event/world/BuildWorldManipulationEvent.java index 15c11dc0..1fd09ce9 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/event/world/BuildWorldManipulationEvent.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/event/world/BuildWorldManipulationEvent.java @@ -19,6 +19,7 @@ import de.eintosti.buildsystem.api.event.world.BuildWorldEvent; import de.eintosti.buildsystem.api.world.BuildWorld; +import de.eintosti.buildsystem.listener.WorldManipulateListener; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.jetbrains.annotations.NotNull; @@ -33,10 +34,9 @@ *

  • Other modification-related stuff
  • * * Cancelling this event will affect the parent-Event, which has caused the ManipulationEvent to fire. - *

    Expect the manipulation event to be cancelled at {@link org.bukkit.event.EventPriority#LOW} if the player is not allowed to interact with the world.

    + *

    Expect the manipulation event to be canceled at {@link org.bukkit.event.EventPriority#LOW} if the player is not allowed to interact with the world.

    * - * @see de.eintosti.buildsystem.listener.WorldManipulateListener - * @since TODO + * @see WorldManipulateListener */ public class BuildWorldManipulationEvent extends BuildWorldEvent implements Cancellable { @@ -49,17 +49,11 @@ public BuildWorldManipulationEvent(Cancellable parentEvent, @NotNull Player play this.player = player; } - /** - * @return whether the parent event has been cancelled - */ @Override public boolean isCancelled() { return parentEvent.isCancelled(); } - /** - * @param cancelled true if the parent event should be cancelled. - */ @Override public void setCancelled(boolean cancelled) { parentEvent.setCancelled(cancelled); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/expansion/placeholderapi/PlaceholderApiExpansion.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/expansion/placeholderapi/PlaceholderApiExpansion.java index 630c2097..d228d4cf 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/expansion/placeholderapi/PlaceholderApiExpansion.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/expansion/placeholderapi/PlaceholderApiExpansion.java @@ -76,8 +76,8 @@ public boolean canRegister() { } /** - * The placeholder identifier should go here. This is what tells PlaceholderAPI to call our onRequest method to obtain a value if a placeholder starts with our identifier. This - * must be unique and can not contain % or _ + * The placeholder identifier should go here. This is what tells PlaceholderAPI to call our onRequest method to get a value if a placeholder starts with our identifier. This + * must be unique and cannot contain % or _ * * @return The identifier in {@code %_%} as String. */ @@ -87,11 +87,11 @@ public boolean canRegister() { } /** - * This is the version of the expansion. You don't have to use numbers, since it is set as a String. + * This is the version of the expansion. You don't have to use numbers since it is set as a String. *

    * For convenience do we return the version from the plugin.yml * - * @return The version as a String. + * @return The version as a string. */ @Override public @NotNull String getVersion() { @@ -99,12 +99,11 @@ public boolean canRegister() { } /** - * This is the method called when a placeholder with our identifier is found and needs a value. We specify the value identifier in this method. Since version 2.9.1 can you use - * OfflinePlayers in your requests. + * This is the method called when a placeholder with our identifier is found and needs a value. We specify the value identifier in this method. * - * @param player A Player. - * @param identifier A String containing the identifier/value. - * @return possibly-null String of the requested identifier. + * @param player The player for which the placeholder is requested. + * @param identifier The identifier of the placeholder + * @return The value of the placeholder as a string, or {@code null} if the identifier is not recognized. */ @Override public String onPlaceholderRequest(Player player, @NotNull String identifier) { @@ -120,62 +119,46 @@ public String onPlaceholderRequest(Player player, @NotNull String identifier) { } /** - * This is the method called when a placeholder with the identifier {@code %buildsystem_settings_%} is found + * This is the method called when a placeholder with the identifier {@code %buildsystem_settings_%} is found. * - * @param player A Player. - * @param identifier A String containing the identifier/value. - * @return possibly null String of the requested identifier. + * @param player The player for which the placeholder is requested + * @param identifier The identifier + * @return The requested setting as a string, or {@code null} if the setting is not recognized */ @Nullable private String parseSettingsPlaceholder(Player player, String identifier) { Settings settings = settingsManager.getSettings(player); String settingIdentifier = identifier.split("_")[1]; - switch (settingIdentifier.toLowerCase(Locale.ROOT)) { - case "navigatortype": - return settings.getNavigatorType().toString(); - case "glasscolor": - return settings.getDesignColor().toString(); - case "worldsort": - return settings.getWorldDisplay().getWorldSort().toString(); - case "clearinventory": - return String.valueOf(settings.isClearInventory()); - case "disableinteract": - return String.valueOf(settings.isDisableInteract()); - case "hideplayers": - return String.valueOf(settings.isHidePlayers()); - case "instantplacesigns": - return String.valueOf(settings.isInstantPlaceSigns()); - case "keepnavigator": - return String.valueOf(settings.isKeepNavigator()); - case "nightvision": - return String.valueOf(settings.isNightVision()); - case "noclip": - return String.valueOf(settings.isNoClip()); - case "placeplants": - return String.valueOf(settings.isPlacePlants()); - case "scoreboard": - return String.valueOf(settings.isScoreboard()); - case "slabbreaking": - return String.valueOf(settings.isSlabBreaking()); - case "spawnteleport": - return String.valueOf(settings.isSpawnTeleport()); - case "opentrapdoors": - return String.valueOf(settings.isOpenTrapDoors()); - default: - return null; - } + return switch (settingIdentifier.toLowerCase(Locale.ROOT)) { + case "navigatortype" -> settings.getNavigatorType().toString(); + case "glasscolor" -> settings.getDesignColor().toString(); + case "worldsort" -> settings.getWorldDisplay().getWorldSort().toString(); + case "clearinventory" -> String.valueOf(settings.isClearInventory()); + case "disableinteract" -> String.valueOf(settings.isDisableInteract()); + case "hideplayers" -> String.valueOf(settings.isHidePlayers()); + case "instantplacesigns" -> String.valueOf(settings.isInstantPlaceSigns()); + case "keepnavigator" -> String.valueOf(settings.isKeepNavigator()); + case "nightvision" -> String.valueOf(settings.isNightVision()); + case "noclip" -> String.valueOf(settings.isNoClip()); + case "placeplants" -> String.valueOf(settings.isPlacePlants()); + case "scoreboard" -> String.valueOf(settings.isScoreboard()); + case "slabbreaking" -> String.valueOf(settings.isSlabBreaking()); + case "spawnteleport" -> String.valueOf(settings.isSpawnTeleport()); + case "opentrapdoors" -> String.valueOf(settings.isOpenTrapDoors()); + default -> null; + }; } /** - * This is the method called when a placeholder with the identifier needed for {@link PlaceholderApiExpansion#parseSettingsPlaceholder(Player, String)} is not found + * This is the method called when a placeholder with the identifier needed for {@link PlaceholderApiExpansion#parseSettingsPlaceholder(Player, String)} is not found. *

    * The default layout for a world placeholder is {@code %buildsystem_%}. If a world is not specified by using the format {@code %buildsystem__%} then the * world the player is currently in will be used. * - * @param player A Player. - * @param identifier A String containing the identifier/value. - * @return possibly-null String of the requested identifier. + * @param player The player for which the placeholder is requested + * @param identifier The identifier + * @return The requested value as a string, or {@code null} if the identifier is not recognized or the world does not exist */ @Nullable private String parseBuildWorldPlaceholder(Player player, String identifier) { @@ -193,55 +176,31 @@ private String parseBuildWorldPlaceholder(Player player, String identifier) { Builders builders = buildWorld.getBuilders(); WorldData worldData = buildWorld.getData(); - switch (identifier.toLowerCase(Locale.ROOT)) { - case "blockbreaking": - return String.valueOf(worldData.blockBreaking().get()); - case "blockplacement": - return String.valueOf(worldData.blockPlacement().get()); - case "builders": - return builders.asPlaceholder(player); - case "buildersenabled": - return String.valueOf(worldData.buildersEnabled().get()); - case "creation": - return Messages.formatDate(buildWorld.getCreation()); - case "creator": - return builders.hasCreator() ? builders.getCreator().getName() : "-"; - case "creatorid": - return builders.hasCreator() ? String.valueOf(builders.getCreator().getUniqueId()) : "-"; - case "explosions": - return String.valueOf(worldData.explosions().get()); - case "lastedited": - return Messages.formatDate(worldData.lastEdited().get()); - case "lastloaded": - return Messages.formatDate(worldData.lastLoaded().get()); - case "lastunloaded": - return Messages.formatDate(worldData.lastUnloaded().get()); - case "loaded": - return String.valueOf(buildWorld.isLoaded()); - case "material": - return worldData.material().get().name(); - case "mobai": - return String.valueOf(worldData.mobAi().get()); - case "permission": - return worldData.permission().get(); - case "private": - return String.valueOf(worldData.privateWorld().get()); - case "project": - return worldData.project().get(); - case "physics": - return String.valueOf(worldData.physics().get()); - case "spawn": - return worldData.customSpawn().get(); - case "status": - return Messages.getString(worldData.status().get().getMessageKey(), player); - case "time": - return buildWorld.getWorldTime(); - case "type": - return Messages.getString(buildWorld.getType().getMessageKey(), player); - case "world": - return buildWorld.getName(); - default: - return null; - } + return switch (identifier.toLowerCase(Locale.ROOT)) { + case "blockbreaking" -> String.valueOf(worldData.blockBreaking().get()); + case "blockplacement" -> String.valueOf(worldData.blockPlacement().get()); + case "builders" -> builders.asPlaceholder(player); + case "buildersenabled" -> String.valueOf(worldData.buildersEnabled().get()); + case "creation" -> Messages.formatDate(buildWorld.getCreation()); + case "creator" -> builders.hasCreator() ? builders.getCreator().getName() : "-"; + case "creatorid" -> builders.hasCreator() ? String.valueOf(builders.getCreator().getUniqueId()) : "-"; + case "explosions" -> String.valueOf(worldData.explosions().get()); + case "lastedited" -> Messages.formatDate(worldData.lastEdited().get()); + case "lastloaded" -> Messages.formatDate(worldData.lastLoaded().get()); + case "lastunloaded" -> Messages.formatDate(worldData.lastUnloaded().get()); + case "loaded" -> String.valueOf(buildWorld.isLoaded()); + case "material" -> worldData.material().get().name(); + case "mobai" -> String.valueOf(worldData.mobAi().get()); + case "permission" -> worldData.permission().get(); + case "private" -> String.valueOf(worldData.privateWorld().get()); + case "project" -> worldData.project().get(); + case "physics" -> String.valueOf(worldData.physics().get()); + case "spawn" -> worldData.customSpawn().get(); + case "status" -> Messages.getString(Messages.getMessageKey(worldData.status().get()), player); + case "time" -> buildWorld.getWorldTime(); + case "type" -> Messages.getString(Messages.getMessageKey(buildWorld.getType()), player); + case "world" -> buildWorld.getName(); + default -> null; + }; } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/AsyncPlayerPreLoginListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/AsyncPlayerPreLoginListener.java index c1402f11..7fc9f3af 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/AsyncPlayerPreLoginListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/AsyncPlayerPreLoginListener.java @@ -64,7 +64,7 @@ public void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) { return; } - BuildWorld buildWorld = worldStorage.getBuildWorld(logoutLocation.getWorldName()); + BuildWorld buildWorld = worldStorage.getBuildWorld(logoutLocation.worldName()); if (buildWorld == null) { buildPlayer.setLogoutLocation(null); } else { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/BlockPhysicsListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/BlockPhysicsListener.java index 8cd0dd52..80a1dfe7 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/BlockPhysicsListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/BlockPhysicsListener.java @@ -60,8 +60,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) { return; } - XMaterial xMaterial = XMaterial.matchXMaterial(block.getType()); - switch (xMaterial) { + switch (XMaterial.matchXMaterial(block.getType())) { case REDSTONE_BLOCK: for (BlockFace blockFace : DirectionUtil.BLOCK_SIDES) { if (isCustomRedstoneLamp(block.getRelative(blockFace))) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/BuildModePreventationListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/BuildModePreventationListener.java index fa437850..fcfa35ad 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/BuildModePreventationListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/BuildModePreventationListener.java @@ -66,11 +66,10 @@ public void onInventoryClick(InventoryClickEvent event) { return; } - if (!(event.getWhoClicked() instanceof Player)) { + if (!(event.getWhoClicked() instanceof Player player)) { return; } - Player player = (Player) event.getWhoClicked(); if (!playerManager.isInBuildMode(player)) { return; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/FoodLevelChangeListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/FoodLevelChangeListener.java index 508f7d10..4bbd0198 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/FoodLevelChangeListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/FoodLevelChangeListener.java @@ -37,11 +37,10 @@ public FoodLevelChangeListener(BuildSystemPlugin plugin) { @EventHandler public void onFoodLevelChangeEvent(FoodLevelChangeEvent event) { - if (!(event.getEntity() instanceof Player)) { + if (!(event.getEntity() instanceof Player player)) { return; } - Player player = (Player) event.getEntity(); BuildWorld buildWorld = worldStorage.getBuildWorld(player.getWorld()); if (buildWorld != null && buildWorld.getData().status().get() == BuildWorldStatus.ARCHIVE) { event.setCancelled(true); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/InventoryCloseListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/InventoryCloseListener.java index 400c7893..fe3bd080 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/InventoryCloseListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/InventoryCloseListener.java @@ -24,6 +24,9 @@ import de.eintosti.buildsystem.api.world.data.BuildWorldStatus; import de.eintosti.buildsystem.api.world.data.BuildWorldType; import de.eintosti.buildsystem.world.display.CustomizableIcons; +import java.util.Map; +import java.util.Optional; +import java.util.function.BiConsumer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -33,10 +36,27 @@ public class InventoryCloseListener implements Listener { - private final CustomizableIcons worldIcon; + private static final Map CREATE_ITEM_SLOTS = Map.of( + BuildWorldType.NORMAL, 11, + BuildWorldType.FLAT, 12, + BuildWorldType.NETHER, 13, + BuildWorldType.END, 14, + BuildWorldType.VOID, 15 + ); + + private static final Map STATUS_ITEM_SLOTS = Map.of( + BuildWorldStatus.NOT_STARTED, 29, + BuildWorldStatus.IN_PROGRESS, 30, + BuildWorldStatus.ALMOST_FINISHED, 31, + BuildWorldStatus.FINISHED, 32, + BuildWorldStatus.ARCHIVE, 33, + BuildWorldStatus.HIDDEN, 34 + ); + + private final CustomizableIcons icons; public InventoryCloseListener(BuildSystemPlugin plugin) { - this.worldIcon = plugin.getCustomizableIcons(); + this.icons = plugin.getCustomizableIcons(); plugin.getServer().getPluginManager().registerEvents(this, plugin); } @@ -46,48 +66,26 @@ public void onSetupInventoryClose(InventoryCloseEvent event) { if (!title.equals(Messages.getString("setup_title", (Player) event.getPlayer()))) { return; } - saveItems(event.getInventory()); - } - - private void saveItems(Inventory inventory) { - ItemStack normalCreateItem = inventory.getItem(11); - ItemStack flatCreateItem = inventory.getItem(12); - ItemStack netherCreateItem = inventory.getItem(13); - ItemStack endCreateItem = inventory.getItem(14); - ItemStack voidCreateItem = inventory.getItem(15); - worldIcon.setIcon(BuildWorldType.NORMAL, normalCreateItem != null ? XMaterial.matchXMaterial(normalCreateItem) : null); - worldIcon.setIcon(BuildWorldType.FLAT, flatCreateItem != null ? XMaterial.matchXMaterial(flatCreateItem) : null); - worldIcon.setIcon(BuildWorldType.NETHER, netherCreateItem != null ? XMaterial.matchXMaterial(netherCreateItem) : null); - worldIcon.setIcon(BuildWorldType.END, endCreateItem != null ? XMaterial.matchXMaterial(endCreateItem) : null); - worldIcon.setIcon(BuildWorldType.VOID, voidCreateItem != null ? XMaterial.matchXMaterial(voidCreateItem) : null); - - ItemStack normalDefaultItem = inventory.getItem(20); - ItemStack flatDefaultItem = inventory.getItem(21); - ItemStack netherDefaultItem = inventory.getItem(22); - ItemStack endDefaultItem = inventory.getItem(23); - ItemStack voidDefaultItem = inventory.getItem(24); - ItemStack importedDefaultItem = inventory.getItem(25); - - worldIcon.setIcon(BuildWorldType.NORMAL, normalDefaultItem != null ? XMaterial.matchXMaterial(normalDefaultItem) : null); - worldIcon.setIcon(BuildWorldType.FLAT, flatDefaultItem != null ? XMaterial.matchXMaterial(flatDefaultItem) : null); - worldIcon.setIcon(BuildWorldType.NETHER, netherDefaultItem != null ? XMaterial.matchXMaterial(netherDefaultItem) : null); - worldIcon.setIcon(BuildWorldType.END, endDefaultItem != null ? XMaterial.matchXMaterial(endDefaultItem) : null); - worldIcon.setIcon(BuildWorldType.VOID, voidDefaultItem != null ? XMaterial.matchXMaterial(voidDefaultItem) : null); - worldIcon.setIcon(BuildWorldType.IMPORTED, importedDefaultItem != null ? XMaterial.matchXMaterial(importedDefaultItem) : null); + Inventory inventory = event.getInventory(); + processIconMapping(inventory, CREATE_ITEM_SLOTS, icons::setIcon); + processIconMapping(inventory, STATUS_ITEM_SLOTS, icons::setIcon); + } - ItemStack notStartedStatusItem = inventory.getItem(29); - ItemStack inProgressStatusItem = inventory.getItem(30); - ItemStack almostFinishedStatusItem = inventory.getItem(31); - ItemStack finishedStatusItem = inventory.getItem(32); - ItemStack archiveStatusItem = inventory.getItem(33); - ItemStack hiddenStatusItem = inventory.getItem(34); + /** + * A generic helper method that iterates over a map of Enum-to-Slot, extracts the {@link ItemStack}, and sets the corresponding icon. + * + * @param inventory The inventory to get items from + * @param slotMapping A map from an Enum constant to its inventory slot index + * @param The type of the Enum (e.g., {@link BuildWorldType}, {@link BuildWorldStatus}) + */ + private > void processIconMapping(Inventory inventory, Map slotMapping, BiConsumer setter) { + slotMapping.forEach((enumConstant, slot) -> { + XMaterial material = Optional.ofNullable(inventory.getItem(slot)) + .map(XMaterial::matchXMaterial) + .orElse(null); - worldIcon.setIcon(BuildWorldStatus.NOT_STARTED, notStartedStatusItem != null ? XMaterial.matchXMaterial(notStartedStatusItem) : null); - worldIcon.setIcon(BuildWorldStatus.IN_PROGRESS, inProgressStatusItem != null ? XMaterial.matchXMaterial(inProgressStatusItem) : null); - worldIcon.setIcon(BuildWorldStatus.ALMOST_FINISHED, almostFinishedStatusItem != null ? XMaterial.matchXMaterial(almostFinishedStatusItem) : null); - worldIcon.setIcon(BuildWorldStatus.FINISHED, finishedStatusItem != null ? XMaterial.matchXMaterial(finishedStatusItem) : null); - worldIcon.setIcon(BuildWorldStatus.ARCHIVE, archiveStatusItem != null ? XMaterial.matchXMaterial(archiveStatusItem) : null); - worldIcon.setIcon(BuildWorldStatus.HIDDEN, hiddenStatusItem != null ? XMaterial.matchXMaterial(hiddenStatusItem) : null); + setter.accept(enumConstant, material); + }); } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/NavigatorListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/NavigatorListener.java index 2777754b..459dee77 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/NavigatorListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/NavigatorListener.java @@ -33,6 +33,7 @@ import de.eintosti.buildsystem.config.ConfigValues; import de.eintosti.buildsystem.navigator.ArmorStandManager; import de.eintosti.buildsystem.navigator.inventory.ArchivedWorldsInventory; +import de.eintosti.buildsystem.navigator.inventory.DisplayablesInventory; import de.eintosti.buildsystem.navigator.inventory.PrivateWorldsInventory; import de.eintosti.buildsystem.navigator.inventory.PublicWorldsInventory; import de.eintosti.buildsystem.player.PlayerServiceImpl; @@ -193,25 +194,19 @@ public void manageNewNavigatorInteraction(PlayerInteractAtEntityEvent event) { return; } - NavigatorCategory inventoryType = ArmorStandManager.matchNavigatorCategory(player, customName); - if (inventoryType == null) { + NavigatorCategory category = ArmorStandManager.matchNavigatorCategory(player, customName); + if (category == null) { return; } - switch (inventoryType) { - case PUBLIC: - XSound.BLOCK_CHEST_OPEN.play(player); - new PublicWorldsInventory(plugin, player).openInventory(); - break; - case ARCHIVE: - XSound.BLOCK_CHEST_OPEN.play(player); - new ArchivedWorldsInventory(plugin, player).openInventory(); - break; - case PRIVATE: - XSound.BLOCK_CHEST_OPEN.play(player); - new PrivateWorldsInventory(plugin, player).openInventory(); - break; - } + DisplayablesInventory inventory = switch (category) { + case PUBLIC -> new PublicWorldsInventory(plugin, player); + case ARCHIVE -> new ArchivedWorldsInventory(plugin, player); + case PRIVATE -> new PrivateWorldsInventory(plugin, player); + }; + + XSound.BLOCK_CHEST_OPEN.play(player); + inventory.openInventory(); } } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerChangedWorldListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerChangedWorldListener.java index 028105a1..8693ba95 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerChangedWorldListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerChangedWorldListener.java @@ -29,7 +29,6 @@ import de.eintosti.buildsystem.player.PlayerServiceImpl; import de.eintosti.buildsystem.player.settings.SettingsManager; import de.eintosti.buildsystem.storage.WorldStorageImpl; -import java.util.AbstractMap; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -88,7 +87,7 @@ public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { BuildWorld newWorld = worldStorage.getBuildWorld(worldName); if (newWorld != null && !newWorld.getData().physics().get() && player.hasPermission("buildsystem.physics.message")) { - Messages.sendMessage(player, "physics_deactivated_in_world", new AbstractMap.SimpleEntry<>("%world%", newWorld.getName())); + Messages.sendMessage(player, "physics_deactivated_in_world", Map.entry("%world%", newWorld.getName())); } removeOldNavigator(player); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerJoinListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerJoinListener.java index 8ab659ef..928e778c 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerJoinListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerJoinListener.java @@ -35,7 +35,7 @@ import de.eintosti.buildsystem.util.UpdateChecker; import de.eintosti.buildsystem.world.SpawnManager; import io.papermc.lib.PaperLib; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -72,7 +72,7 @@ public PlayerJoinListener(BuildSystemPlugin plugin) { public void sendPlayerJoinMessage(PlayerJoinEvent event) { Player player = event.getPlayer(); String message = plugin.getConfigValues().isJoinQuitMessages() - ? Messages.getString("player_join", player, new AbstractMap.SimpleEntry<>("%player%", player.getName())) + ? Messages.getString("player_join", player, Map.entry("%player%", player.getName())) : null; event.setJoinMessage(message); } @@ -94,7 +94,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (buildWorld != null) { WorldData worldData = buildWorld.getData(); if (!worldData.physics().get() && player.hasPermission("buildsystem.physics.message")) { - Messages.sendMessage(player, "physics_deactivated_in_world", new AbstractMap.SimpleEntry<>("%world%", worldName)); + Messages.sendMessage(player, "physics_deactivated_in_world", Map.entry("%world%", worldName)); } if (configValues.isArchiveVanish() && worldData.status().get() == BuildWorldStatus.ARCHIVE) { @@ -130,14 +130,14 @@ private void teleportToCorrectLocation(Player player, BuildPlayer buildPlayer) { return; } - BuildWorld buildWorld = worldStorage.getBuildWorld(logoutLocation.getWorldName()); + BuildWorld buildWorld = worldStorage.getBuildWorld(logoutLocation.worldName()); if (buildWorld == null) { return; } int delay = buildWorld.isLoaded() ? 0 : 20; Bukkit.getScheduler().runTaskLater(plugin, () -> { - Location location = logoutLocation.getLocation(); + Location location = logoutLocation.location(); if (location != null) { PaperLib.teleportAsync(player, location); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerQuitListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerQuitListener.java index 917a76f5..ebdb16ae 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerQuitListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerQuitListener.java @@ -25,7 +25,7 @@ import de.eintosti.buildsystem.player.LogoutLocationImpl; import de.eintosti.buildsystem.player.PlayerServiceImpl; import de.eintosti.buildsystem.player.settings.SettingsManager; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -50,7 +50,7 @@ public PlayerQuitListener(BuildSystemPlugin plugin) { public void sendPlayerQuitMessage(PlayerQuitEvent event) { Player player = event.getPlayer(); String message = plugin.getConfigValues().isJoinQuitMessages() - ? Messages.getString("player_quit", player, new AbstractMap.SimpleEntry<>("%player%", player.getName())) + ? Messages.getString("player_quit", player, Map.entry("%player%", player.getName())) : null; event.setQuitMessage(message); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerTeleportListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerTeleportListener.java index 0335c2db..c9075d64 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerTeleportListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/PlayerTeleportListener.java @@ -65,7 +65,7 @@ public void onPlayerTeleport(PlayerTeleportEvent event) { } // Users can always teleport to the main server world - if (Bukkit.getWorlds().get(0).equals(toWorld)) { + if (Bukkit.getWorlds().getFirst().equals(toWorld)) { return; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/SettingsInteractListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/SettingsInteractListener.java index 7cefe696..21fe75ef 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/SettingsInteractListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/SettingsInteractListener.java @@ -375,7 +375,7 @@ private boolean isValid(PlayerInteractEvent event) { } /** - * Stop {@link Player} from opening {@link Inventory} because the event should be cancelled as it was fired due to an interaction caused in + * Stop {@link Player} from opening {@link Inventory} because the event should be canceled as it was fired due to an interaction caused in * {@link SettingsInteractListener#manageDisabledInteractSetting} */ @EventHandler diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/WorldManipulateListener.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/WorldManipulateListener.java index fecf001b..89c33aed 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/WorldManipulateListener.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/listener/WorldManipulateListener.java @@ -133,9 +133,9 @@ private WorldData.Type getRelatedWorldSetting(Cancellable event, WorldD } private void denyPlayerInteraction(Event event) { - if (event instanceof PlayerInteractEvent) { - ((PlayerInteractEvent) event).setUseItemInHand(Event.Result.DENY); - ((PlayerInteractEvent) event).setUseInteractedBlock(Event.Result.DENY); + if (event instanceof PlayerInteractEvent interactEvent) { + interactEvent.setUseItemInHand(Event.Result.DENY); + interactEvent.setUseInteractedBlock(Event.Result.DENY); } } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/ArmorStandManager.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/ArmorStandManager.java index b5d93a58..d059a22a 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/ArmorStandManager.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/ArmorStandManager.java @@ -77,12 +77,12 @@ private Location calculatePosition(Player player, float angle) { } @SuppressWarnings("deprecation") - private ArmorStand spawnArmorStand(Player player, Location location, NavigatorCategory inventoryType, boolean customSkull, String skullUrl) { + private ArmorStand spawnArmorStand(Player player, Location location, NavigatorCategory category, boolean customSkull, String skullUrl) { location.setY(location.getY() - 0.1); ArmorStand armorStand = location.getWorld().spawn(location, ArmorStand.class); armorStand.setVisible(false); - armorStand.setCustomName(player.getName() + " × " + ARMOR_STAND_NAMES.get(inventoryType)); + armorStand.setCustomName(player.getName() + " × " + ARMOR_STAND_NAMES.get(category)); armorStand.setCustomNameVisible(false); armorStand.setGravity(false); armorStand.setCanPickupItems(false); @@ -130,8 +130,8 @@ public void removeArmorStands(Player player) { continue; } - for (NavigatorCategory inventoryType : NavigatorCategory.values()) { - if (customName.equals(playerName + " × " + ARMOR_STAND_NAMES.get(inventoryType))) { + for (NavigatorCategory category : NavigatorCategory.values()) { + if (customName.equals(playerName + " × " + ARMOR_STAND_NAMES.get(category))) { armorStand.remove(); break; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/DisplayablesInventory.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/DisplayablesInventory.java index 5687defb..3a3b9d4d 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/DisplayablesInventory.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/DisplayablesInventory.java @@ -8,6 +8,7 @@ import de.eintosti.buildsystem.Messages; import de.eintosti.buildsystem.api.navigator.settings.WorldDisplay; import de.eintosti.buildsystem.api.navigator.settings.WorldFilter; +import de.eintosti.buildsystem.api.navigator.settings.WorldFilter.Mode; import de.eintosti.buildsystem.api.navigator.settings.WorldSort; import de.eintosti.buildsystem.api.player.settings.Settings; import de.eintosti.buildsystem.api.world.BuildWorld; @@ -22,20 +23,18 @@ import de.eintosti.buildsystem.player.settings.SettingsManager; import de.eintosti.buildsystem.storage.FolderStorageImpl; import de.eintosti.buildsystem.storage.WorldStorageImpl; -import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete; +import de.eintosti.buildsystem.tabcomplete.WorldsTabComplete.WorldsArgument; import de.eintosti.buildsystem.util.InventoryUtils; import de.eintosti.buildsystem.util.PaginatedInventory; import de.eintosti.buildsystem.util.PlayerChatInput; import de.eintosti.buildsystem.util.StringCleaner; import de.eintosti.buildsystem.util.StringUtils; import de.eintosti.buildsystem.world.WorldServiceImpl; -import de.eintosti.buildsystem.world.creation.CreateInventory; -import java.util.AbstractMap; +import de.eintosti.buildsystem.world.creation.CreateInventory.Page; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.List; -import java.util.Locale; +import java.util.Map; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -203,12 +202,12 @@ private void initializeInventories() { Collection folders = collectFolders(); List standaloneWorlds = filterWorlds(collectWorlds(), worldDisplay).stream() .filter(world -> !folderStorage.isAssignedToAnyFolder(world)) - .collect(Collectors.toList()); + .toList(); List displayables = new ArrayList<>(); displayables.addAll(folders); displayables.addAll(standaloneWorlds); - displayables.sort(createDisplayOrderComparator(worldDisplay.getWorldSort())); + displayables.sort(worldDisplay.getWorldSort().getComparator()); return displayables; } @@ -269,72 +268,6 @@ private boolean isWorldValidForDisplay(@NotNull BuildWorld buildWorld) { return Bukkit.getWorld(buildWorld.getName()) != null || !buildWorld.isLoaded(); } - /** - * Creates a comparator for sorting {@link Displayable}s based on the specified {@link WorldSort} order. - * - * @param worldSort The desired sorting order. - * @return The comparator - */ - @NotNull - protected Comparator createDisplayOrderComparator(@NotNull WorldSort worldSort) { - Comparator comparator; - switch (worldSort) { - case OLDEST_FIRST: - comparator = Comparator.comparingLong(Displayable::getCreation); - break; - case NEWEST_FIRST: - comparator = Comparator.comparingLong(Displayable::getCreation).reversed(); - break; - case PROJECT_A_TO_Z: - comparator = Comparator.comparing((Displayable displayable) -> { - if (displayable instanceof BuildWorld) { - return ((BuildWorld) displayable).getData().project().get().toLowerCase(Locale.ROOT); - } else if (displayable instanceof Folder) { - return ((Folder) displayable).getProject().toLowerCase(Locale.ROOT); - } else { - return ""; - } - }); - break; - case PROJECT_Z_TO_A: - comparator = Comparator.comparing((Displayable displayable) -> { - if (displayable instanceof BuildWorld) { - return ((BuildWorld) displayable).getData().project().get().toLowerCase(Locale.ROOT); - } else if (displayable instanceof Folder) { - return ((Folder) displayable).getProject().toLowerCase(Locale.ROOT); - } else { - return ""; - } - }).reversed(); - break; - case STATUS_NOT_STARTED: - comparator = Comparator.comparingInt((Displayable displayable) -> { - if (displayable instanceof BuildWorld) { - return ((BuildWorld) displayable).getData().status().get().getStage(); - } else { - return BuildWorldStatus.FINISHED.getStage(); - } - }); - break; - case STATUS_FINISHED: - comparator = Comparator.comparingInt((Displayable displayable) -> { - if (displayable instanceof BuildWorld) { - return ((BuildWorld) displayable).getData().status().get().getStage(); - } else { - return BuildWorldStatus.FINISHED.getStage(); - } - }).reversed(); - break; - case NAME_Z_TO_A: - comparator = Comparator.comparing((Displayable displayable) -> displayable.getName().toLowerCase(Locale.ROOT)).reversed(); - break; - default: // NAME_A_TO_Z - comparator = Comparator.comparing((Displayable displayable) -> displayable.getName().toLowerCase(Locale.ROOT)); - break; - } - return comparator; - } - /** * Adds the world sorting item to the inventory. * @@ -343,7 +276,19 @@ protected Comparator createDisplayOrderComparator(@NotNull WorldSor private void addWorldSortItem(@NotNull Inventory inventory) { Settings settings = settingsManager.getSettings(player); WorldSort worldSort = settings.getWorldDisplay().getWorldSort(); - inventory.setItem(45, InventoryUtils.createItem(XMaterial.BOOK, Messages.getString("world_sort_title", player), Messages.getString(worldSort.getMessageKey(), player))); + + String messageKey = switch (worldSort) { + case NAME_A_TO_Z -> "world_sort_name_az"; + case NAME_Z_TO_A -> "world_sort_name_za"; + case PROJECT_A_TO_Z -> "world_sort_project_az"; + case PROJECT_Z_TO_A -> "world_sort_project_za"; + case STATUS_NOT_STARTED -> "world_sort_status_not_started"; + case STATUS_FINISHED -> "world_sort_status_finished"; + case NEWEST_FIRST -> "world_sort_date_newest"; + case OLDEST_FIRST -> "world_sort_date_oldest"; + }; + + inventory.setItem(45, InventoryUtils.createItem(XMaterial.BOOK, Messages.getString("world_sort_title", player), Messages.getString(messageKey, player))); } /** @@ -355,8 +300,15 @@ private void addWorldFilterItem(@NotNull Inventory inventory) { Settings settings = settingsManager.getSettings(player); WorldFilter worldFilter = settings.getWorldDisplay().getWorldFilter(); + String loreKey = switch (worldFilter.getMode()) { + case NONE -> "world_filter_mode_none"; + case STARTS_WITH -> "world_filter_mode_starts_with"; + case CONTAINS -> "world_filter_mode_contains"; + case MATCHES -> "world_filter_mode_matches"; + }; + List lore = new ArrayList<>(); - lore.add(Messages.getString(worldFilter.getMode().getLoreKey(), player, new AbstractMap.SimpleEntry<>("%text%", worldFilter.getText()))); + lore.add(Messages.getString(loreKey, player, Map.entry("%text%", worldFilter.getText()))); lore.addAll(Messages.getStringList("world_filter_lore", player)); inventory.setItem(46, InventoryUtils.createItem(XMaterial.HOPPER, Messages.getString("world_filter_title", player), lore)); @@ -415,7 +367,7 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { } Folder folder = createFolder(sanitizedName); - Messages.sendMessage(player, "worlds_folder_created", new AbstractMap.SimpleEntry<>("%folder%", folder.getName())); + Messages.sendMessage(player, "worlds_folder_created", Map.entry("%folder%", folder.getName())); openInventory(); }); return; @@ -442,7 +394,7 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { } protected void beginWorldCreation() { - this.plugin.getCreateInventory().openInventory(this.player, CreateInventory.Page.PREDEFINED, this.requiredVisibility, null); + this.plugin.getCreateInventory().openInventory(this.player, Page.PREDEFINED, this.requiredVisibility, null); } protected Folder createFolder(String folderName) { @@ -464,10 +416,10 @@ protected void returnToPreviousInventory() { */ private void handleFilterClick(@NotNull InventoryClickEvent event, @NotNull WorldDisplay worldDisplay) { WorldFilter worldFilter = worldDisplay.getWorldFilter(); - WorldFilter.Mode currentMode = worldFilter.getMode(); + Mode currentMode = worldFilter.getMode(); if (event.isShiftClick()) { - worldFilter.setMode(WorldFilter.Mode.NONE); + worldFilter.setMode(Mode.NONE); worldFilter.setText(""); } else if (event.isLeftClick()) { player.closeInventory(); @@ -548,24 +500,16 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { * @return The next sort in the sequence */ private WorldSort getNextSort(WorldSort currentSort) { - switch (currentSort) { - case NEWEST_FIRST: - return WorldSort.OLDEST_FIRST; - case OLDEST_FIRST: - return WorldSort.NAME_A_TO_Z; - case PROJECT_A_TO_Z: - return WorldSort.PROJECT_Z_TO_A; - case PROJECT_Z_TO_A: - return WorldSort.STATUS_NOT_STARTED; - case STATUS_NOT_STARTED: - return WorldSort.STATUS_FINISHED; - case STATUS_FINISHED: - return WorldSort.NEWEST_FIRST; - case NAME_Z_TO_A: - return WorldSort.PROJECT_A_TO_Z; - default: // NAME_A_TO_Z - return WorldSort.NAME_Z_TO_A; - } + return switch (currentSort) { + case NEWEST_FIRST -> WorldSort.OLDEST_FIRST; + case OLDEST_FIRST -> WorldSort.NAME_A_TO_Z; + case PROJECT_A_TO_Z -> WorldSort.PROJECT_Z_TO_A; + case PROJECT_Z_TO_A -> WorldSort.STATUS_NOT_STARTED; + case STATUS_NOT_STARTED -> WorldSort.STATUS_FINISHED; + case STATUS_FINISHED -> WorldSort.NEWEST_FIRST; + case NAME_A_TO_Z -> WorldSort.NAME_Z_TO_A; + case NAME_Z_TO_A -> WorldSort.PROJECT_A_TO_Z; + }; } /** @@ -575,24 +519,16 @@ private WorldSort getNextSort(WorldSort currentSort) { * @return The previous sort in the sequence. */ public WorldSort getPreviousSort(WorldSort currentSort) { - switch (currentSort) { - case NEWEST_FIRST: - return WorldSort.STATUS_FINISHED; - case OLDEST_FIRST: - return WorldSort.NEWEST_FIRST; - case PROJECT_A_TO_Z: - return WorldSort.NAME_Z_TO_A; - case PROJECT_Z_TO_A: - return WorldSort.PROJECT_A_TO_Z; - case STATUS_NOT_STARTED: - return WorldSort.PROJECT_Z_TO_A; - case STATUS_FINISHED: - return WorldSort.STATUS_NOT_STARTED; - case NAME_Z_TO_A: - return WorldSort.NAME_A_TO_Z; - default: // NAME_A_TO_Z - return WorldSort.OLDEST_FIRST; - } + return switch (currentSort) { + case NEWEST_FIRST -> WorldSort.STATUS_FINISHED; + case OLDEST_FIRST -> WorldSort.NEWEST_FIRST; + case PROJECT_A_TO_Z -> WorldSort.NAME_Z_TO_A; + case PROJECT_Z_TO_A -> WorldSort.PROJECT_A_TO_Z; + case STATUS_NOT_STARTED -> WorldSort.PROJECT_Z_TO_A; + case STATUS_FINISHED -> WorldSort.STATUS_NOT_STARTED; + case NAME_A_TO_Z -> WorldSort.OLDEST_FIRST; + case NAME_Z_TO_A -> WorldSort.NAME_A_TO_Z; + }; } /** @@ -602,7 +538,7 @@ public WorldSort getPreviousSort(WorldSort currentSort) { * @return The extracted world. */ private @Nullable BuildWorld parseWorld(@NotNull String displayName) { - String template = Messages.getString("world_item_title", player, new AbstractMap.SimpleEntry<>("%world%", "")); + String template = Messages.getString("world_item_title", player, Map.entry("%world%", "")); String worldName = StringUtils.difference(template, displayName); return worldStorage.getBuildWorld(worldName); } @@ -614,7 +550,7 @@ public WorldSort getPreviousSort(WorldSort currentSort) { * @return The extracted folder. */ private @Nullable Folder parseFolder(@NotNull String displayName) { - String template = Messages.getString("folder_item_title", player, new AbstractMap.SimpleEntry<>("%folder%", "")); + String template = Messages.getString("folder_item_title", player, Map.entry("%folder%", "")); String folderName = StringUtils.difference(template, displayName); return folderStorage.getFolder(folderName); } @@ -626,7 +562,7 @@ public WorldSort getPreviousSort(WorldSort currentSort) { * @param buildWorld The BuildWorld associated with the clicked item. */ private void manageWorldItemClick(@NotNull InventoryClickEvent event, @NotNull BuildWorld buildWorld) { - if (event.isLeftClick() || !buildWorld.getPermissions().canPerformCommand(player, WorldsTabComplete.WorldsArgument.EDIT.getPermission())) { + if (event.isLeftClick() || !buildWorld.getPermissions().canPerformCommand(player, WorldsArgument.EDIT.getPermission())) { performNonEditClick(buildWorld); return; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/FolderContentInventory.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/FolderContentInventory.java index 91fe62db..f93299f1 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/FolderContentInventory.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/FolderContentInventory.java @@ -81,7 +81,7 @@ public FolderContentInventory( List displayables = new ArrayList<>(); displayables.addAll(folders); displayables.addAll(buildWorlds); - displayables.sort(createDisplayOrderComparator(worldDisplay.getWorldSort())); + displayables.sort(worldDisplay.getWorldSort().getComparator()); return displayables; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/settings/WorldFilterImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/settings/WorldFilterImpl.java index 84fefe14..3cac378f 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/settings/WorldFilterImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/settings/WorldFilterImpl.java @@ -57,15 +57,11 @@ public void setText(String text) { @Override public Predicate apply() { - switch (mode) { - case STARTS_WITH: - return buildWorld -> buildWorld.getName().startsWith(text); - case CONTAINS: - return buildWorld -> buildWorld.getName().contains(text); - case MATCHES: - return buildWorld -> buildWorld.getName().matches(text); - default: - return buildWorld -> true; - } + return switch (mode) { + case STARTS_WITH -> buildWorld -> buildWorld.getName().startsWith(text); + case CONTAINS -> buildWorld -> buildWorld.getName().contains(text); + case MATCHES -> buildWorld -> buildWorld.getName().matches(text); + default -> buildWorld -> true; + }; } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/LogoutLocationImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/LogoutLocationImpl.java index ad6b3e26..0f7ab4e2 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/LogoutLocationImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/LogoutLocationImpl.java @@ -46,12 +46,12 @@ public LogoutLocationImpl(String worldName, double x, double y, double z, float } @Override - public String getWorldName() { + public String worldName() { return worldName; } @Override - public Location getLocation() { + public Location location() { return new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/PlayerServiceImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/PlayerServiceImpl.java index c4374043..a517b8c4 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/PlayerServiceImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/PlayerServiceImpl.java @@ -263,12 +263,12 @@ private void checkForEntity() { BuildPlayer buildPlayer = playerStorage.getBuildPlayer(player.getUniqueId()); double lookedPosition = player.getEyeLocation().getDirection().getY(); if (lookedPosition >= MIN_LOOK_HEIGHT && lookedPosition <= MAX_LOOK_HEIGHT) { - NavigatorCategory inventoryType = ArmorStandManager.matchNavigatorCategory(player, getEntityName(player)); + NavigatorCategory category = ArmorStandManager.matchNavigatorCategory(player, getEntityName(player)); NavigatorCategory lastLookedAt = buildPlayer.getLastLookedAt(); - if (lastLookedAt == null || lastLookedAt != inventoryType) { - buildPlayer.setLastLookedAt(inventoryType); - sendTypeInfo(player, inventoryType); + if (lastLookedAt == null || lastLookedAt != category) { + buildPlayer.setLastLookedAt(category); + sendTypeInfo(player, category); } } else { ActionBar.clearActionBar(player); @@ -323,24 +323,17 @@ private String getEntityName(Player player) { return entity.getCustomName(); } - private void sendTypeInfo(Player player, NavigatorCategory inventoryType) { - if (inventoryType == null) { + private void sendTypeInfo(Player player, NavigatorCategory category) { + if (category == null) { ActionBar.clearActionBar(player); return; } - String message; - switch (inventoryType) { - case ARCHIVE: - message = "new_navigator_world_archive"; - break; - case PRIVATE: - message = "new_navigator_private_worlds"; - break; - default: - message = "new_navigator_world_navigator"; - break; - } + String message = switch (category) { + case PUBLIC -> "new_navigator_world_navigator"; + case ARCHIVE -> "new_navigator_world_archive"; + case PRIVATE -> "new_navigator_private_worlds"; + }; ActionBar.sendActionBar(player, Messages.getString(message, player)); XSound.ENTITY_CHICKEN_EGG.play(player); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SettingsManager.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SettingsManager.java index 7eed5c38..bfb6488a 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SettingsManager.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SettingsManager.java @@ -27,7 +27,6 @@ import de.eintosti.buildsystem.version.util.MinecraftVersion; import de.eintosti.buildsystem.world.WorldServiceImpl; import fr.mrmicky.fastboard.FastBoard; -import java.util.AbstractMap; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -141,15 +140,15 @@ private Map.Entry[] getPlaceholders(String originalString, Playe BuildWorld buildWorld = worldService.getWorldStorage().getBuildWorld(worldName); return new Map.Entry[]{ - new AbstractMap.SimpleEntry<>("%world%", worldName), - new AbstractMap.SimpleEntry<>("%status%", parseWorldInformation(player, buildWorld, "%status%")), - new AbstractMap.SimpleEntry<>("%permission%", parseWorldInformation(player, buildWorld, "%permission%")), - new AbstractMap.SimpleEntry<>("%project%", parseWorldInformation(player, buildWorld, "%project%")), - new AbstractMap.SimpleEntry<>("%creator%", parseWorldInformation(player, buildWorld, "%creator%")), - new AbstractMap.SimpleEntry<>("%creation%", parseWorldInformation(player, buildWorld, "%creation%")), - new AbstractMap.SimpleEntry<>("%lastedited%", parseWorldInformation(player, buildWorld, "%lastedited%")), - new AbstractMap.SimpleEntry<>("%lastloaded%", parseWorldInformation(player, buildWorld, "%lastloaded%")), - new AbstractMap.SimpleEntry<>("%lastunloaded%", parseWorldInformation(player, buildWorld, "%lastunloaded%")) + Map.entry("%world%", worldName), + Map.entry("%status%", parseWorldInformation(player, buildWorld, "%status%")), + Map.entry("%permission%", parseWorldInformation(player, buildWorld, "%permission%")), + Map.entry("%project%", parseWorldInformation(player, buildWorld, "%project%")), + Map.entry("%creator%", parseWorldInformation(player, buildWorld, "%creator%")), + Map.entry("%creation%", parseWorldInformation(player, buildWorld, "%creation%")), + Map.entry("%lastedited%", parseWorldInformation(player, buildWorld, "%lastedited%")), + Map.entry("%lastloaded%", parseWorldInformation(player, buildWorld, "%lastloaded%")), + Map.entry("%lastunloaded%", parseWorldInformation(player, buildWorld, "%lastunloaded%")) }; } @@ -161,26 +160,17 @@ private String parseWorldInformation(Player player, BuildWorld buildWorld, Strin Builders builders = buildWorld.getBuilders(); WorldData worldData = buildWorld.getData(); - switch (input) { - case "%status%": - return Messages.getString(worldData.status().get().getMessageKey(), player); - case "%permission%": - return worldData.permission().get(); - case "%project%": - return worldData.project().get(); - case "%creator%": - return builders.hasCreator() ? builders.getCreator().getName() : "-"; - case "%creation%": - return Messages.formatDate(buildWorld.getCreation()); - case "%lastedited%": - return Messages.formatDate(worldData.lastEdited().get()); - case "%lastloaded%": - return Messages.formatDate(worldData.lastLoaded().get()); - case "%lastunloaded%": - return Messages.formatDate(worldData.lastUnloaded().get()); - default: - return "§f-"; - } + return switch (input) { + case "%status%" -> Messages.getString(Messages.getMessageKey(worldData.status().get()), player); + case "%permission%" -> worldData.permission().get(); + case "%project%" -> worldData.project().get(); + case "%creator%" -> builders.hasCreator() ? builders.getCreator().getName() : "-"; + case "%creation%" -> Messages.formatDate(buildWorld.getCreation()); + case "%lastedited%" -> Messages.formatDate(worldData.lastEdited().get()); + case "%lastloaded%" -> Messages.formatDate(worldData.lastLoaded().get()); + case "%lastunloaded%" -> Messages.formatDate(worldData.lastUnloaded().get()); + default -> "§f-"; + }; } private void stopScoreboard(Player player, Settings settings) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SpeedInventory.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SpeedInventory.java index a8b181a5..d1dc5229 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SpeedInventory.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SpeedInventory.java @@ -22,7 +22,7 @@ import de.eintosti.buildsystem.BuildSystemPlugin; import de.eintosti.buildsystem.Messages; import de.eintosti.buildsystem.util.InventoryUtils; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -32,10 +32,7 @@ public class SpeedInventory implements Listener { - private final BuildSystemPlugin plugin; - public SpeedInventory(BuildSystemPlugin plugin) { - this.plugin = plugin; plugin.getServer().getPluginManager().registerEvents(this, plugin); } @@ -101,10 +98,10 @@ public void oInventoryClick(InventoryClickEvent event) { private void setSpeed(Player player, float speed, int num) { if (player.isFlying()) { player.setFlySpeed(speed - 0.1f); - Messages.sendMessage(player, "speed_set_flying", new AbstractMap.SimpleEntry<>("%speed%", num)); + Messages.sendMessage(player, "speed_set_flying", Map.entry("%speed%", num)); } else { player.setWalkSpeed(speed); - Messages.sendMessage(player, "speed_set_walking", new AbstractMap.SimpleEntry<>("%speed%", num)); + Messages.sendMessage(player, "speed_set_walking", Map.entry("%speed%", num)); } } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/FolderStorageImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/FolderStorageImpl.java index 4468cf9e..93aa7d32 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/FolderStorageImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/FolderStorageImpl.java @@ -24,7 +24,6 @@ import de.eintosti.buildsystem.api.world.display.Folder; import de.eintosti.buildsystem.api.world.display.NavigatorCategory; import de.eintosti.buildsystem.world.display.FolderImpl; -import java.util.AbstractMap; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -51,7 +50,7 @@ public FolderStorageImpl(BuildSystemPlugin plugin) { .collect(Collectors.toMap(Folder::getName, Function.identity())); this.worldToFolderMap = this.foldersByName.values().stream() .flatMap(folder -> folder.getWorldUUIDs().stream() - .map(world -> new AbstractMap.SimpleEntry<>(world, folder.getName()))) + .map(world -> Map.entry(world, folder.getName()))) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/WorldStorageImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/WorldStorageImpl.java index bb45d8b9..8dd63b5d 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/WorldStorageImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/WorldStorageImpl.java @@ -145,16 +145,11 @@ public List getBuildWorldsCreatedByPlayer(Player player, Visibility * @return {@code true} if the world's visibility is equal to the given visibility, otherwise {@code false} */ public boolean isCorrectVisibility(boolean privateWorld, Visibility visibility) { - switch (visibility) { - case PRIVATE: - return privateWorld; - case PUBLIC: - return !privateWorld; - case IGNORE: - return true; - default: - return false; - } + return switch (visibility) { + case PRIVATE -> privateWorld; + case PUBLIC -> !privateWorld; + case IGNORE -> true; + }; } public void loadWorlds() { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlFolderStorage.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlFolderStorage.java index 107c1222..90b0624b 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlFolderStorage.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlFolderStorage.java @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -85,7 +84,7 @@ private void saveFile() { serializedFolder.put("material", folder.getIcon().name()); serializedFolder.put("permission", folder.getPermission()); serializedFolder.put("project", folder.getProject()); - serializedFolder.put("worlds", folder.getWorldUUIDs().stream().map(UUID::toString).collect(Collectors.toList())); + serializedFolder.put("worlds", folder.getWorldUUIDs().stream().map(UUID::toString).toList()); return serializedFolder; } @@ -121,7 +120,7 @@ private Set loadFolderKeys() { if (!file.exists()) { config.options().copyDefaults(true); saveFile(); - return new HashSet<>(); + return Set.of(); } try { @@ -132,7 +131,7 @@ private Set loadFolderKeys() { ConfigurationSection section = config.getConfigurationSection(FOLDERS_KEY); if (section == null) { - return new HashSet<>(); + return Set.of(); } return section.getKeys(false); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlPlayerStorage.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlPlayerStorage.java index 5deedc39..4dfa0fc7 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlPlayerStorage.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlPlayerStorage.java @@ -37,7 +37,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -144,7 +143,7 @@ private Set loadPlayerKeys() { if (!file.exists()) { config.options().copyDefaults(true); saveFile(); - return new HashSet<>(); + return Set.of(); } try { @@ -155,7 +154,7 @@ private Set loadPlayerKeys() { ConfigurationSection section = config.getConfigurationSection(PLAYERS_KEY); if (section == null) { - return new HashSet<>(); + return Set.of(); } return section.getKeys(false); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlWorldStorage.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlWorldStorage.java index 191a364e..be68fc8d 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlWorldStorage.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/storage/yaml/YamlWorldStorage.java @@ -35,7 +35,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -99,7 +98,7 @@ private void saveFile() { world.put("date", buildWorld.getCreation()); world.put("builders", serializeBuilders(builders.getAllBuilders())); if (buildWorld.getCustomGenerator() != null) { - world.put("chunk-generator", buildWorld.getCustomGenerator().getName()); + world.put("chunk-generator", buildWorld.getCustomGenerator().name()); } return world; @@ -116,7 +115,7 @@ private String serializeBuilders(Collection builders) { for (Builder builder : builders) { builderList.append(";").append(builder.toString()); } - return builderList.length() > 0 ? builderList.substring(1) : builderList.toString(); + return !builderList.isEmpty() ? builderList.substring(1) : builderList.toString(); } @Override @@ -135,7 +134,7 @@ private Set loadWorldKeys() { if (!file.exists()) { config.options().copyDefaults(true); saveFile(); - return new HashSet<>(); + return Set.of(); } try { @@ -146,7 +145,7 @@ private Set loadWorldKeys() { ConfigurationSection section = config.getConfigurationSection(WORLDS_KEY); if (section == null) { - return new HashSet<>(); + return Set.of(); } return section.getKeys(false); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/ArgumentSorter.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/ArgumentSorter.java index 7885d454..9988f376 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/ArgumentSorter.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/ArgumentSorter.java @@ -23,7 +23,7 @@ abstract class ArgumentSorter { public void addArgument(String input, String argument, List arrayList) { - if (input.equals("") || StringUtils.startsWithIgnoreCase(argument, input)) { + if (input.isEmpty() || StringUtils.startsWithIgnoreCase(argument, input)) { arrayList.add(argument); } } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/BuildTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/BuildTabComplete.java index 32b261eb..938a026f 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/BuildTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/BuildTabComplete.java @@ -36,20 +36,16 @@ public BuildTabComplete(BuildSystemPlugin plugin) { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { ArrayList arrayList = new ArrayList<>(); - - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { return arrayList; } - Player player = (Player) sender; if (!player.hasPermission("buildsystem.build")) { return arrayList; } - if (args.length == 1) { - if (!player.hasPermission("buildsystem.build.other")) { - Bukkit.getOnlinePlayers().forEach(pl -> addArgument(args[0], pl.getName(), arrayList)); - } + if (args.length == 1 && !player.hasPermission("buildsystem.build.other")) { + Bukkit.getOnlinePlayers().forEach(pl -> addArgument(args[0], pl.getName(), arrayList)); } return arrayList; diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/GamemodeTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/GamemodeTabComplete.java index 8b404e90..7c0d8b28 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/GamemodeTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/GamemodeTabComplete.java @@ -39,44 +39,25 @@ public GamemodeTabComplete(BuildSystemPlugin plugin) { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { ArrayList arrayList = new ArrayList<>(); - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { return arrayList; } - Player player = (Player) sender; if (args.length == 1) { Arrays.stream(GameMode.values()) .map(gameMode -> gameMode.name().toLowerCase(Locale.ROOT)) .filter(gameModeName -> player.hasPermission(String.format("buildsystem.gamemode.%s", gameModeName))) .forEach(gameModeName -> addArgument(args[0], gameModeName, arrayList)); } else if (args.length == 2) { - String gameModeName; - switch (args[0].toLowerCase(Locale.ROOT)) { - case "survival": - case "s": - case "0": - gameModeName = GameMode.SURVIVAL.name().toLowerCase(Locale.ROOT); - break; - case "creative": - case "c": - case "1": - gameModeName = GameMode.CREATIVE.name().toLowerCase(Locale.ROOT); - break; - case "adventure": - case "a": - case "2": - gameModeName = GameMode.ADVENTURE.name().toLowerCase(Locale.ROOT); - break; - case "spectator": - case "sp": - case "3": - gameModeName = GameMode.SPECTATOR.name().toLowerCase(Locale.ROOT); - break; - default: - return arrayList; - } + String gameModeName = switch (args[0].toLowerCase(Locale.ROOT)) { + case "survival", "s", "0" -> GameMode.SURVIVAL.name().toLowerCase(Locale.ROOT); + case "creative", "c", "1" -> GameMode.CREATIVE.name().toLowerCase(Locale.ROOT); + case "adventure", "a", "2" -> GameMode.ADVENTURE.name().toLowerCase(Locale.ROOT); + case "spectator", "sp", "3" -> GameMode.SPECTATOR.name().toLowerCase(Locale.ROOT); + default -> null; + }; - if (player.hasPermission(String.format("buildsystem.gamemode.%s.other", gameModeName))) { + if (gameModeName != null && player.hasPermission(String.format("buildsystem.gamemode.%s.other", gameModeName))) { Bukkit.getOnlinePlayers().forEach(pl -> addArgument(args[1], pl.getName(), arrayList)); } } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/PhysicsTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/PhysicsTabComplete.java index 5ae38a31..3c684f94 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/PhysicsTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/PhysicsTabComplete.java @@ -39,12 +39,10 @@ public PhysicsTabComplete(BuildSystemPlugin plugin) { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { ArrayList arrayList = new ArrayList<>(); - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { return arrayList; } - Player player = (Player) sender; - if (args.length == 1) { worldStorage.getBuildWorlds().stream() .filter(world -> world.getPermissions().canPerformCommand(player, "buildsystem.physics")) diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/SpawnTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/SpawnTabComplete.java index c73f3422..a8037bff 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/SpawnTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/SpawnTabComplete.java @@ -35,11 +35,9 @@ public SpawnTabComplete(BuildSystemPlugin plugin) { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { ArrayList arrayList = new ArrayList<>(); - - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { return arrayList; } - Player player = (Player) sender; if (player.hasPermission("buildsystem.spawn")) { for (Argument argument : Argument.values()) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/TimeTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/TimeTabComplete.java index 18fb573b..53452e93 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/TimeTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/TimeTabComplete.java @@ -41,11 +41,10 @@ public TimeTabComplete(BuildSystemPlugin plugin) { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { ArrayList arrayList = new ArrayList<>(); - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { return arrayList; } - Player player = (Player) sender; String labelLowerCase = label.toLowerCase(Locale.ROOT); switch (labelLowerCase) { case "day": diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java index 49ed2bd3..1e4235e6 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/WorldsTabComplete.java @@ -34,7 +34,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -62,11 +61,9 @@ public WorldsTabComplete(BuildSystemPlugin plugin) { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { ArrayList arrayList = new ArrayList<>(); - - if (!(sender instanceof Player)) { + if (!(sender instanceof Player player)) { return arrayList; } - Player player = (Player) sender; switch (args.length) { case 1: { @@ -176,14 +173,11 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman default: switch (args[0].toLowerCase(Locale.ROOT)) { case "import": { - Map> arguments = new HashMap>() {{ - put("-g", Arrays.stream(Generator.values()).filter(generator -> generator != Generator.CUSTOM) - .map(Enum::name) - .collect(Collectors.toList()) - ); - put("-c", Lists.newArrayList()); - put("-t", Arrays.stream(BuildWorldType.values()).map(Enum::name).collect(Collectors.toList())); - }}; + Map> arguments = Map.of( + "-g", Arrays.stream(Generator.values()).filter(generator -> generator != Generator.CUSTOM).map(Enum::name).collect(Collectors.toList()), + "-c", Lists.newArrayList(), + "-t", Arrays.stream(BuildWorldType.values()).map(Enum::name).collect(Collectors.toList()) + ); if (args.length % 2 == 1) { arguments.keySet().stream() @@ -203,14 +197,14 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman case "folder": { switch (args.length) { case 3: - Map subCommands = new HashMap() {{ - put("add", "buildsystem.folder.add"); - put("remove", "buildsystem.folder.remove"); - put("delete", "buildsystem.folder.delete"); - put("setPermission", "buildsystem.folder.setpermission"); - put("setProject", "buildsystem.folder.setproject"); - put("setItem", "buildsystem.folder.setitem"); - }}; + Map subCommands = Map.of( + "add", "buildsystem.folder.add", + "remove", "buildsystem.folder.remove", + "delete", "buildsystem.folder.delete", + "setPermission", "buildsystem.folder.setpermission", + "setProject", "buildsystem.folder.setproject", + "setItem", "buildsystem.folder.setitem" + ); subCommands.entrySet().stream() .filter(entry -> player.hasPermission(entry.getKey())) .forEach(entry -> addArgument(args[2], entry.getKey(), arrayList)); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/util/MaterialUtils.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/util/MaterialUtils.java index e9446e0b..96a5f42e 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/util/MaterialUtils.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/util/MaterialUtils.java @@ -38,328 +38,44 @@ private MaterialUtils() { * @return {@code true} if this material can be interacted with. */ public static boolean isInteractable(XMaterial material) { - switch (material) { - case ACACIA_BUTTON: - case ACACIA_DOOR: - case ACACIA_FENCE: - case ACACIA_FENCE_GATE: - case ACACIA_HANGING_SIGN: - case ACACIA_SIGN: - case ACACIA_STAIRS: - case ACACIA_TRAPDOOR: - case ACACIA_WALL_HANGING_SIGN: - case ACACIA_WALL_SIGN: - case ANDESITE_STAIRS: - case ANVIL: - case BAMBOO_BUTTON: - case BAMBOO_DOOR: - case BAMBOO_FENCE: - case BAMBOO_FENCE_GATE: - case BAMBOO_HANGING_SIGN: - case BAMBOO_MOSAIC_STAIRS: - case BAMBOO_SIGN: - case BAMBOO_STAIRS: - case BAMBOO_TRAPDOOR: - case BAMBOO_WALL_HANGING_SIGN: - case BAMBOO_WALL_SIGN: - case BARREL: - case BEACON: - case BEEHIVE: - case BEE_NEST: - case BELL: - case BIRCH_BUTTON: - case BIRCH_DOOR: - case BIRCH_FENCE: - case BIRCH_FENCE_GATE: - case BIRCH_HANGING_SIGN: - case BIRCH_SIGN: - case BIRCH_STAIRS: - case BIRCH_TRAPDOOR: - case BIRCH_WALL_HANGING_SIGN: - case BIRCH_WALL_SIGN: - case BLACKSTONE_STAIRS: - case BLACK_BED: - case BLACK_CANDLE: - case BLACK_CANDLE_CAKE: - case BLACK_SHULKER_BOX: - case BLAST_FURNACE: - case BLUE_BED: - case BLUE_CANDLE: - case BLUE_CANDLE_CAKE: - case BLUE_SHULKER_BOX: - case BREWING_STAND: - case BRICK_STAIRS: - case BROWN_BED: - case BROWN_CANDLE: - case BROWN_CANDLE_CAKE: - case BROWN_SHULKER_BOX: - case CAKE: - case CAMPFIRE: - case CANDLE: - case CANDLE_CAKE: - case CARTOGRAPHY_TABLE: - case CAULDRON: - case CAVE_VINES: - case CAVE_VINES_PLANT: - case CHAIN_COMMAND_BLOCK: - case CHERRY_BUTTON: - case CHERRY_DOOR: - case CHERRY_FENCE: - case CHERRY_FENCE_GATE: - case CHERRY_HANGING_SIGN: - case CHERRY_SIGN: - case CHERRY_STAIRS: - case CHERRY_TRAPDOOR: - case CHERRY_WALL_HANGING_SIGN: - case CHERRY_WALL_SIGN: - case CHEST: - case CHIPPED_ANVIL: - case CHISELED_BOOKSHELF: - case COBBLED_DEEPSLATE_STAIRS: - case COBBLESTONE_STAIRS: - case COMMAND_BLOCK: - case COMPARATOR: - case COMPOSTER: - case CRAFTING_TABLE: - case CRIMSON_BUTTON: - case CRIMSON_DOOR: - case CRIMSON_FENCE: - case CRIMSON_FENCE_GATE: - case CRIMSON_HANGING_SIGN: - case CRIMSON_SIGN: - case CRIMSON_STAIRS: - case CRIMSON_TRAPDOOR: - case CRIMSON_WALL_HANGING_SIGN: - case CRIMSON_WALL_SIGN: - case CUT_COPPER_STAIRS: - case CYAN_BED: - case CYAN_CANDLE: - case CYAN_CANDLE_CAKE: - case CYAN_SHULKER_BOX: - case DAMAGED_ANVIL: - case DARK_OAK_BUTTON: - case DARK_OAK_DOOR: - case DARK_OAK_FENCE: - case DARK_OAK_FENCE_GATE: - case DARK_OAK_HANGING_SIGN: - case DARK_OAK_SIGN: - case DARK_OAK_STAIRS: - case DARK_OAK_TRAPDOOR: - case DARK_OAK_WALL_HANGING_SIGN: - case DARK_OAK_WALL_SIGN: - case DARK_PRISMARINE_STAIRS: - case DAYLIGHT_DETECTOR: - case DEEPSLATE_BRICK_STAIRS: - case DEEPSLATE_REDSTONE_ORE: - case DEEPSLATE_TILE_STAIRS: - case DIORITE_STAIRS: - case DISPENSER: - case DRAGON_EGG: - case DROPPER: - case ENCHANTING_TABLE: - case ENDER_CHEST: - case END_STONE_BRICK_STAIRS: - case EXPOSED_CUT_COPPER_STAIRS: - case FLETCHING_TABLE: - case FLOWER_POT: - case FURNACE: - case GRANITE_STAIRS: - case GRAY_BED: - case GRAY_CANDLE: - case GRAY_CANDLE_CAKE: - case GRAY_SHULKER_BOX: - case GREEN_BED: - case GREEN_CANDLE: - case GREEN_CANDLE_CAKE: - case GREEN_SHULKER_BOX: - case GRINDSTONE: - case HOPPER: - case IRON_DOOR: - case IRON_TRAPDOOR: - case JIGSAW: - case JUKEBOX: - case JUNGLE_BUTTON: - case JUNGLE_DOOR: - case JUNGLE_FENCE: - case JUNGLE_FENCE_GATE: - case JUNGLE_HANGING_SIGN: - case JUNGLE_SIGN: - case JUNGLE_STAIRS: - case JUNGLE_TRAPDOOR: - case JUNGLE_WALL_HANGING_SIGN: - case JUNGLE_WALL_SIGN: - case LAVA_CAULDRON: - case LECTERN: - case LEVER: - case LIGHT: - case LIGHT_BLUE_BED: - case LIGHT_BLUE_CANDLE: - case LIGHT_BLUE_CANDLE_CAKE: - case LIGHT_BLUE_SHULKER_BOX: - case LIGHT_GRAY_BED: - case LIGHT_GRAY_CANDLE: - case LIGHT_GRAY_CANDLE_CAKE: - case LIGHT_GRAY_SHULKER_BOX: - case LIME_BED: - case LIME_CANDLE: - case LIME_CANDLE_CAKE: - case LIME_SHULKER_BOX: - case LOOM: - case MAGENTA_BED: - case MAGENTA_CANDLE: - case MAGENTA_CANDLE_CAKE: - case MAGENTA_SHULKER_BOX: - case MANGROVE_BUTTON: - case MANGROVE_DOOR: - case MANGROVE_FENCE: - case MANGROVE_FENCE_GATE: - case MANGROVE_HANGING_SIGN: - case MANGROVE_SIGN: - case MANGROVE_STAIRS: - case MANGROVE_TRAPDOOR: - case MANGROVE_WALL_HANGING_SIGN: - case MANGROVE_WALL_SIGN: - case MOSSY_COBBLESTONE_STAIRS: - case MOSSY_STONE_BRICK_STAIRS: - case MOVING_PISTON: - case MUD_BRICK_STAIRS: - case NETHER_BRICK_FENCE: - case NETHER_BRICK_STAIRS: - case NOTE_BLOCK: - case OAK_BUTTON: - case OAK_DOOR: - case OAK_FENCE: - case OAK_FENCE_GATE: - case OAK_HANGING_SIGN: - case OAK_SIGN: - case OAK_STAIRS: - case OAK_TRAPDOOR: - case OAK_WALL_HANGING_SIGN: - case OAK_WALL_SIGN: - case ORANGE_BED: - case ORANGE_CANDLE: - case ORANGE_CANDLE_CAKE: - case ORANGE_SHULKER_BOX: - case OXIDIZED_CUT_COPPER_STAIRS: - case PINK_BED: - case PINK_CANDLE: - case PINK_CANDLE_CAKE: - case PINK_SHULKER_BOX: - case POLISHED_ANDESITE_STAIRS: - case POLISHED_BLACKSTONE_BRICK_STAIRS: - case POLISHED_BLACKSTONE_BUTTON: - case POLISHED_BLACKSTONE_STAIRS: - case POLISHED_DEEPSLATE_STAIRS: - case POLISHED_DIORITE_STAIRS: - case POLISHED_GRANITE_STAIRS: - case POTTED_ACACIA_SAPLING: - case POTTED_ALLIUM: - case POTTED_AZALEA_BUSH: - case POTTED_AZURE_BLUET: - case POTTED_BAMBOO: - case POTTED_BIRCH_SAPLING: - case POTTED_BLUE_ORCHID: - case POTTED_BROWN_MUSHROOM: - case POTTED_CACTUS: - case POTTED_CHERRY_SAPLING: - case POTTED_CORNFLOWER: - case POTTED_CRIMSON_FUNGUS: - case POTTED_CRIMSON_ROOTS: - case POTTED_DANDELION: - case POTTED_DARK_OAK_SAPLING: - case POTTED_DEAD_BUSH: - case POTTED_FERN: - case POTTED_FLOWERING_AZALEA_BUSH: - case POTTED_JUNGLE_SAPLING: - case POTTED_LILY_OF_THE_VALLEY: - case POTTED_MANGROVE_PROPAGULE: - case POTTED_OAK_SAPLING: - case POTTED_ORANGE_TULIP: - case POTTED_OXEYE_DAISY: - case POTTED_PINK_TULIP: - case POTTED_POPPY: - case POTTED_RED_MUSHROOM: - case POTTED_RED_TULIP: - case POTTED_SPRUCE_SAPLING: - case POTTED_TORCHFLOWER: - case POTTED_WARPED_FUNGUS: - case POTTED_WARPED_ROOTS: - case POTTED_WHITE_TULIP: - case POTTED_WITHER_ROSE: - case POWDER_SNOW_CAULDRON: - case PRISMARINE_BRICK_STAIRS: - case PRISMARINE_STAIRS: - case PUMPKIN: - case PURPLE_BED: - case PURPLE_CANDLE: - case PURPLE_CANDLE_CAKE: - case PURPLE_SHULKER_BOX: - case PURPUR_STAIRS: - case QUARTZ_STAIRS: - case REDSTONE_ORE: - case REDSTONE_WIRE: - case RED_BED: - case RED_CANDLE: - case RED_CANDLE_CAKE: - case RED_NETHER_BRICK_STAIRS: - case RED_SANDSTONE_STAIRS: - case RED_SHULKER_BOX: - case REPEATER: - case REPEATING_COMMAND_BLOCK: - case RESPAWN_ANCHOR: - case SANDSTONE_STAIRS: - case SHULKER_BOX: - case SMITHING_TABLE: - case SMOKER: - case SMOOTH_QUARTZ_STAIRS: - case SMOOTH_RED_SANDSTONE_STAIRS: - case SMOOTH_SANDSTONE_STAIRS: - case SOUL_CAMPFIRE: - case SPRUCE_BUTTON: - case SPRUCE_DOOR: - case SPRUCE_FENCE: - case SPRUCE_FENCE_GATE: - case SPRUCE_HANGING_SIGN: - case SPRUCE_SIGN: - case SPRUCE_STAIRS: - case SPRUCE_TRAPDOOR: - case SPRUCE_WALL_HANGING_SIGN: - case SPRUCE_WALL_SIGN: - case STONECUTTER: - case STONE_BRICK_STAIRS: - case STONE_BUTTON: - case STONE_STAIRS: - case STRUCTURE_BLOCK: - case SWEET_BERRY_BUSH: - case TNT: - case TRAPPED_CHEST: - case WARPED_BUTTON: - case WARPED_DOOR: - case WARPED_FENCE: - case WARPED_FENCE_GATE: - case WARPED_HANGING_SIGN: - case WARPED_SIGN: - case WARPED_STAIRS: - case WARPED_TRAPDOOR: - case WARPED_WALL_HANGING_SIGN: - case WARPED_WALL_SIGN: - case WATER_CAULDRON: - case WAXED_CUT_COPPER_STAIRS: - case WAXED_EXPOSED_CUT_COPPER_STAIRS: - case WAXED_OXIDIZED_CUT_COPPER_STAIRS: - case WAXED_WEATHERED_CUT_COPPER_STAIRS: - case WEATHERED_CUT_COPPER_STAIRS: - case WHITE_BED: - case WHITE_CANDLE: - case WHITE_CANDLE_CAKE: - case WHITE_SHULKER_BOX: - case YELLOW_BED: - case YELLOW_CANDLE: - case YELLOW_CANDLE_CAKE: - case YELLOW_SHULKER_BOX: - return true; - default: - return false; - } + return switch (material) { + case ACACIA_BUTTON, ACACIA_DOOR, ACACIA_FENCE, ACACIA_FENCE_GATE, ACACIA_HANGING_SIGN, ACACIA_SIGN, ACACIA_STAIRS, ACACIA_TRAPDOOR, ACACIA_WALL_HANGING_SIGN, + ACACIA_WALL_SIGN, ANDESITE_STAIRS, ANVIL, BAMBOO_BUTTON, BAMBOO_DOOR, BAMBOO_FENCE, BAMBOO_FENCE_GATE, BAMBOO_HANGING_SIGN, BAMBOO_MOSAIC_STAIRS, BAMBOO_SIGN, + BAMBOO_STAIRS, BAMBOO_TRAPDOOR, BAMBOO_WALL_HANGING_SIGN, BAMBOO_WALL_SIGN, BARREL, BEACON, BEEHIVE, BEE_NEST, BELL, BIRCH_BUTTON, BIRCH_DOOR, BIRCH_FENCE, + BIRCH_FENCE_GATE, BIRCH_HANGING_SIGN, BIRCH_SIGN, BIRCH_STAIRS, BIRCH_TRAPDOOR, BIRCH_WALL_HANGING_SIGN, BIRCH_WALL_SIGN, BLACKSTONE_STAIRS, BLACK_BED, + BLACK_CANDLE, BLACK_CANDLE_CAKE, BLACK_SHULKER_BOX, BLAST_FURNACE, BLUE_BED, BLUE_CANDLE, BLUE_CANDLE_CAKE, BLUE_SHULKER_BOX, BREWING_STAND, BRICK_STAIRS, + BROWN_BED, BROWN_CANDLE, BROWN_CANDLE_CAKE, BROWN_SHULKER_BOX, CAKE, CAMPFIRE, CANDLE, CANDLE_CAKE, CARTOGRAPHY_TABLE, CAULDRON, CAVE_VINES, CAVE_VINES_PLANT, + CHAIN_COMMAND_BLOCK, CHERRY_BUTTON, CHERRY_DOOR, CHERRY_FENCE, CHERRY_FENCE_GATE, CHERRY_HANGING_SIGN, CHERRY_SIGN, CHERRY_STAIRS, CHERRY_TRAPDOOR, + CHERRY_WALL_HANGING_SIGN, CHERRY_WALL_SIGN, CHEST, CHIPPED_ANVIL, CHISELED_BOOKSHELF, COBBLED_DEEPSLATE_STAIRS, COBBLESTONE_STAIRS, COMMAND_BLOCK, COMPARATOR, + COMPOSTER, CRAFTING_TABLE, CRIMSON_BUTTON, CRIMSON_DOOR, CRIMSON_FENCE, CRIMSON_FENCE_GATE, CRIMSON_HANGING_SIGN, CRIMSON_SIGN, CRIMSON_STAIRS, CRIMSON_TRAPDOOR, + CRIMSON_WALL_HANGING_SIGN, CRIMSON_WALL_SIGN, CUT_COPPER_STAIRS, CYAN_BED, CYAN_CANDLE, CYAN_CANDLE_CAKE, CYAN_SHULKER_BOX, DAMAGED_ANVIL, DARK_OAK_BUTTON, + DARK_OAK_DOOR, DARK_OAK_FENCE, DARK_OAK_FENCE_GATE, DARK_OAK_HANGING_SIGN, DARK_OAK_SIGN, DARK_OAK_STAIRS, DARK_OAK_TRAPDOOR, DARK_OAK_WALL_HANGING_SIGN, + DARK_OAK_WALL_SIGN, DARK_PRISMARINE_STAIRS, DAYLIGHT_DETECTOR, DEEPSLATE_BRICK_STAIRS, DEEPSLATE_REDSTONE_ORE, DEEPSLATE_TILE_STAIRS, DIORITE_STAIRS, DISPENSER, + DRAGON_EGG, DROPPER, ENCHANTING_TABLE, ENDER_CHEST, END_STONE_BRICK_STAIRS, EXPOSED_CUT_COPPER_STAIRS, FLETCHING_TABLE, FLOWER_POT, FURNACE, GRANITE_STAIRS, + GRAY_BED, GRAY_CANDLE, GRAY_CANDLE_CAKE, GRAY_SHULKER_BOX, GREEN_BED, GREEN_CANDLE, GREEN_CANDLE_CAKE, GREEN_SHULKER_BOX, GRINDSTONE, HOPPER, IRON_DOOR, + IRON_TRAPDOOR, JIGSAW, JUKEBOX, JUNGLE_BUTTON, JUNGLE_DOOR, JUNGLE_FENCE, JUNGLE_FENCE_GATE, JUNGLE_HANGING_SIGN, JUNGLE_SIGN, JUNGLE_STAIRS, JUNGLE_TRAPDOOR, + JUNGLE_WALL_HANGING_SIGN, JUNGLE_WALL_SIGN, LAVA_CAULDRON, LECTERN, LEVER, LIGHT, LIGHT_BLUE_BED, LIGHT_BLUE_CANDLE, LIGHT_BLUE_CANDLE_CAKE, + LIGHT_BLUE_SHULKER_BOX, LIGHT_GRAY_BED, LIGHT_GRAY_CANDLE, LIGHT_GRAY_CANDLE_CAKE, LIGHT_GRAY_SHULKER_BOX, LIME_BED, LIME_CANDLE, LIME_CANDLE_CAKE, + LIME_SHULKER_BOX, LOOM, MAGENTA_BED, MAGENTA_CANDLE, MAGENTA_CANDLE_CAKE, MAGENTA_SHULKER_BOX, MANGROVE_BUTTON, MANGROVE_DOOR, MANGROVE_FENCE, MANGROVE_FENCE_GATE, + MANGROVE_HANGING_SIGN, MANGROVE_SIGN, MANGROVE_STAIRS, MANGROVE_TRAPDOOR, MANGROVE_WALL_HANGING_SIGN, MANGROVE_WALL_SIGN, MOSSY_COBBLESTONE_STAIRS, + MOSSY_STONE_BRICK_STAIRS, MOVING_PISTON, MUD_BRICK_STAIRS, NETHER_BRICK_FENCE, NETHER_BRICK_STAIRS, NOTE_BLOCK, OAK_BUTTON, OAK_DOOR, OAK_FENCE, OAK_FENCE_GATE, + OAK_HANGING_SIGN, OAK_SIGN, OAK_STAIRS, OAK_TRAPDOOR, OAK_WALL_HANGING_SIGN, OAK_WALL_SIGN, ORANGE_BED, ORANGE_CANDLE, ORANGE_CANDLE_CAKE, ORANGE_SHULKER_BOX, + OXIDIZED_CUT_COPPER_STAIRS, PINK_BED, PINK_CANDLE, PINK_CANDLE_CAKE, PINK_SHULKER_BOX, POLISHED_ANDESITE_STAIRS, POLISHED_BLACKSTONE_BRICK_STAIRS, + POLISHED_BLACKSTONE_BUTTON, POLISHED_BLACKSTONE_STAIRS, POLISHED_DEEPSLATE_STAIRS, POLISHED_DIORITE_STAIRS, POLISHED_GRANITE_STAIRS, POTTED_ACACIA_SAPLING, + POTTED_ALLIUM, POTTED_AZALEA_BUSH, POTTED_AZURE_BLUET, POTTED_BAMBOO, POTTED_BIRCH_SAPLING, POTTED_BLUE_ORCHID, POTTED_BROWN_MUSHROOM, POTTED_CACTUS, + POTTED_CHERRY_SAPLING, POTTED_CORNFLOWER, POTTED_CRIMSON_FUNGUS, POTTED_CRIMSON_ROOTS, POTTED_DANDELION, POTTED_DARK_OAK_SAPLING, POTTED_DEAD_BUSH, POTTED_FERN, + POTTED_FLOWERING_AZALEA_BUSH, POTTED_JUNGLE_SAPLING, POTTED_LILY_OF_THE_VALLEY, POTTED_MANGROVE_PROPAGULE, POTTED_OAK_SAPLING, POTTED_ORANGE_TULIP, + POTTED_OXEYE_DAISY, POTTED_PINK_TULIP, POTTED_POPPY, POTTED_RED_MUSHROOM, POTTED_RED_TULIP, POTTED_SPRUCE_SAPLING, POTTED_TORCHFLOWER, POTTED_WARPED_FUNGUS, + POTTED_WARPED_ROOTS, POTTED_WHITE_TULIP, POTTED_WITHER_ROSE, POWDER_SNOW_CAULDRON, PRISMARINE_BRICK_STAIRS, PRISMARINE_STAIRS, PUMPKIN, PURPLE_BED, PURPLE_CANDLE, + PURPLE_CANDLE_CAKE, PURPLE_SHULKER_BOX, PURPUR_STAIRS, QUARTZ_STAIRS, REDSTONE_ORE, REDSTONE_WIRE, RED_BED, RED_CANDLE, RED_CANDLE_CAKE, RED_NETHER_BRICK_STAIRS, + RED_SANDSTONE_STAIRS, RED_SHULKER_BOX, REPEATER, REPEATING_COMMAND_BLOCK, RESPAWN_ANCHOR, SANDSTONE_STAIRS, SHULKER_BOX, SMITHING_TABLE, SMOKER, + SMOOTH_QUARTZ_STAIRS, SMOOTH_RED_SANDSTONE_STAIRS, SMOOTH_SANDSTONE_STAIRS, SOUL_CAMPFIRE, SPRUCE_BUTTON, SPRUCE_DOOR, SPRUCE_FENCE, SPRUCE_FENCE_GATE, + SPRUCE_HANGING_SIGN, SPRUCE_SIGN, SPRUCE_STAIRS, SPRUCE_TRAPDOOR, SPRUCE_WALL_HANGING_SIGN, SPRUCE_WALL_SIGN, STONECUTTER, STONE_BRICK_STAIRS, STONE_BUTTON, + STONE_STAIRS, STRUCTURE_BLOCK, SWEET_BERRY_BUSH, TNT, TRAPPED_CHEST, WARPED_BUTTON, WARPED_DOOR, WARPED_FENCE, WARPED_FENCE_GATE, WARPED_HANGING_SIGN, WARPED_SIGN, + WARPED_STAIRS, WARPED_TRAPDOOR, WARPED_WALL_HANGING_SIGN, WARPED_WALL_SIGN, WATER_CAULDRON, WAXED_CUT_COPPER_STAIRS, WAXED_EXPOSED_CUT_COPPER_STAIRS, + WAXED_OXIDIZED_CUT_COPPER_STAIRS, WAXED_WEATHERED_CUT_COPPER_STAIRS, WEATHERED_CUT_COPPER_STAIRS, WHITE_BED, WHITE_CANDLE, WHITE_CANDLE_CAKE, WHITE_SHULKER_BOX, + YELLOW_BED, YELLOW_CANDLE, YELLOW_CANDLE_CAKE, YELLOW_SHULKER_BOX -> true; + default -> false; + }; } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/BuildWorldImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/BuildWorldImpl.java index 9eec7df4..cf35abd4 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/BuildWorldImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/BuildWorldImpl.java @@ -37,7 +37,6 @@ import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; import de.eintosti.buildsystem.world.util.WorldTeleporterImpl; import de.eintosti.buildsystem.world.util.WorldUnloaderImpl; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -154,23 +153,23 @@ public void setIcon(XMaterial material) { @Override public String getDisplayName(Player player) { return Messages.getString("world_item_title", player, - new AbstractMap.SimpleEntry<>("%world%", this.name) + Map.entry("%world%", this.name) ); } @Override public List getLore(Player player) { @SuppressWarnings("unchecked") - Map.Entry[] placeholders = new Map.Entry[]{ - new AbstractMap.SimpleEntry<>("%status%", Messages.getString(worldData.status().get().getMessageKey(), player)), - new AbstractMap.SimpleEntry<>("%project%", worldData.project().get()), - new AbstractMap.SimpleEntry<>("%permission%", worldData.permission().get()), - new AbstractMap.SimpleEntry<>("%creator%", builders.hasCreator() ? builders.getCreator().getName() : "-"), - new AbstractMap.SimpleEntry<>("%creation%", Messages.formatDate(getCreation())), - new AbstractMap.SimpleEntry<>("%lastedited%", Messages.formatDate(worldData.lastEdited().get())), - new AbstractMap.SimpleEntry<>("%lastloaded%", Messages.formatDate(worldData.lastLoaded().get())), - new AbstractMap.SimpleEntry<>("%lastunloaded%", Messages.formatDate(worldData.lastUnloaded().get())) - }; + Map.Entry[] placeholders = List.of( + Map.entry("%status%", Messages.getString(Messages.getMessageKey(worldData.status().get()), player)), + Map.entry("%project%", worldData.project().get()), + Map.entry("%permission%", worldData.permission().get()), + Map.entry("%creator%", builders.hasCreator() ? builders.getCreator().getName() : "-"), + Map.entry("%creation%", Messages.formatDate(getCreation())), + Map.entry("%lastedited%", Messages.formatDate(worldData.lastEdited().get())), + Map.entry("%lastloaded%", Messages.formatDate(worldData.lastLoaded().get())), + Map.entry("%lastunloaded%", Messages.formatDate(worldData.lastUnloaded().get())) + ).toArray(Map.Entry[]::new); List messageList = getPermissions().canPerformCommand(player, WorldsTabComplete.WorldsArgument.EDIT.getPermission()) ? Messages.getStringList("world_item_lore_edit", player, placeholders) @@ -191,7 +190,7 @@ public List getLore(Player player) { } // Replace the placeholder in the first line only - lore.add(line.replace("%builders%", builderLines.get(0).trim())); + lore.add(line.replace("%builders%", builderLines.getFirst().trim())); // Add any additional lines for (int i = 1; i < builderLines.size(); i++) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/WorldServiceImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/WorldServiceImpl.java index 0cf4ed40..919e50b1 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/WorldServiceImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/WorldServiceImpl.java @@ -38,9 +38,9 @@ import de.eintosti.buildsystem.world.creation.generator.CustomGeneratorImpl; import io.papermc.lib.PaperLib; import java.io.File; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import org.bukkit.Bukkit; @@ -121,7 +121,7 @@ private void startCustomGeneratorInput(Player player, String worldName, String t } CustomGeneratorImpl customGenerator = new CustomGeneratorImpl(generatorInfo[0], chunkGenerator); - plugin.getLogger().info("Using custom world generator: " + customGenerator.getName()); + plugin.getLogger().info("Using custom world generator: " + customGenerator.name()); createWorld(player, worldName, BuildWorldType.CUSTOM, customGenerator, template, privateWorld, folder); }); } @@ -175,7 +175,7 @@ public boolean importWorld(Player player, String worldName, Builder creator, Bui if (worldCreator.isDataVersionTooHigh()) { String key = single ? "import" : "importall"; Messages.sendMessage(player, "worlds_" + key + "_newer_version", - new AbstractMap.SimpleEntry<>("%world%", worldName) + Map.entry("%world%", worldName) ); return false; } @@ -189,10 +189,10 @@ public void importWorlds(Player player, String[] worldList, Generator generator, int delay = configValues.getImportDelay(); Messages.sendMessage(player, "worlds_importall_started", - new AbstractMap.SimpleEntry<>("%amount%", String.valueOf(worlds)) + Map.entry("%amount%", String.valueOf(worlds)) ); Messages.sendMessage(player, "worlds_importall_delay", - new AbstractMap.SimpleEntry<>("%delay%", String.valueOf(delay)) + Map.entry("%delay%", String.valueOf(delay)) ); importingAllWorlds = true; @@ -211,7 +211,7 @@ public void run() { String worldName = worldList[i]; if (worldStorage.worldExists(worldName)) { Messages.sendMessage(player, "worlds_importall_world_already_imported", - new AbstractMap.SimpleEntry<>("%world%", worldName) + Map.entry("%world%", worldName) ); return; } @@ -219,14 +219,14 @@ public void run() { String invalidChar = StringCleaner.firstInvalidChar(worldName); if (invalidChar != null) { Messages.sendMessage(player, "worlds_importall_invalid_character", - new AbstractMap.SimpleEntry<>("%world%", worldName), - new AbstractMap.SimpleEntry<>("%char%", invalidChar) + Map.entry("%world%", worldName), + Map.entry("%char%", invalidChar) ); return; } if (importWorld(player, worldName, creator, BuildWorldType.IMPORTED, generator, null, false)) { - Messages.sendMessage(player, "worlds_importall_world_imported", new AbstractMap.SimpleEntry<>("%world%", worldName)); + Messages.sendMessage(player, "worlds_importall_world_imported", Map.entry("%world%", worldName)); } } }.runTaskTimer(plugin, 0, 20L * delay); @@ -274,7 +274,7 @@ public void deleteWorld(Player player, BuildWorld buildWorld) { assignedFolder.removeWorld(buildWorld); } - Messages.sendMessage(player, "worlds_delete_started", new AbstractMap.SimpleEntry<>("%world%", worldName)); + Messages.sendMessage(player, "worlds_delete_started", Map.entry("%world%", worldName)); removePlayersFromWorld(worldName, Messages.getString("worlds_delete_players_world", player)); Bukkit.getScheduler().runTaskLater(plugin, () -> { unimportWorld(player, buildWorld, false); @@ -364,8 +364,8 @@ public void renameWorld(Player player, BuildWorld buildWorld, String newName) { } Messages.sendMessage(player, "worlds_rename_set", - new AbstractMap.SimpleEntry<>("%oldName%", oldName), - new AbstractMap.SimpleEntry<>("%newName%", sanitizedNewName) + Map.entry("%oldName%", oldName), + Map.entry("%newName%", sanitizedNewName) ); } @@ -378,7 +378,7 @@ private List removePlayersFromWorld(String worldName, String message) { } SpawnManager spawnManager = plugin.getSpawnManager(); - Location spawnLocation = Bukkit.getWorlds().get(0).getSpawnLocation().add(0.5, 0, 0.5); + Location spawnLocation = Bukkit.getWorlds().getFirst().getSpawnLocation().add(0.5, 0, 0.5); Bukkit.getOnlinePlayers().forEach(player -> { World playerWorld = player.getWorld(); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/builder/BuilderInventory.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/builder/BuilderInventory.java index 3b0dd816..3221e764 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/builder/BuilderInventory.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/builder/BuilderInventory.java @@ -31,8 +31,8 @@ import de.eintosti.buildsystem.util.PaginatedInventory; import de.eintosti.buildsystem.util.StringUtils; import de.eintosti.buildsystem.util.UUIDFetcher; -import java.util.AbstractMap; import java.util.Collection; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -80,7 +80,7 @@ private void addCreatorInfoItem(Inventory inventory, Builders builders, Player p } else { creatorInfoItem = InventoryUtils.createSkull(Messages.getString("worldeditor_builders_creator_item", player), Profileable.of(creator.getUniqueId()), Messages.getString("worldeditor_builders_creator_lore", player, - new AbstractMap.SimpleEntry<>("%creator%", builders.getCreator()) + Map.entry("%creator%", builders.getCreator()) ) ); } @@ -111,7 +111,7 @@ private void addItems(BuildWorld buildWorld, Player player) { for (Builder builder : builders) { inventory.setItem(columnSkull++, InventoryUtils.createSkull( Messages.getString("worldeditor_builders_builder_item", player, - new AbstractMap.SimpleEntry<>("%builder%", builder.getName()) + Map.entry("%builder%", builder.getName()) ), Profileable.username(builder.getName()), Messages.getStringList("worldeditor_builders_builder_lore", player) @@ -189,7 +189,7 @@ public void onInventoryClick(InventoryClickEvent event) { return; } - String template = Messages.getString("worldeditor_builders_builder_item", player, new AbstractMap.SimpleEntry<>("%builder%", "")); + String template = Messages.getString("worldeditor_builders_builder_item", player, Map.entry("%builder%", "")); String builderName = StringUtils.difference(template, itemStack.getItemMeta().getDisplayName()); UUID builderId = UUIDFetcher.getUUID(builderName); if (builderId == null) { @@ -201,7 +201,7 @@ public void onInventoryClick(InventoryClickEvent event) { buildWorld.getBuilders().removeBuilder(builderId); XSound.ENTITY_ENDERMAN_TELEPORT.play(player); - Messages.sendMessage(player, "worlds_removebuilder_removed", new AbstractMap.SimpleEntry<>("%builder%", builderName)); + Messages.sendMessage(player, "worlds_removebuilder_removed", Map.entry("%builder%", builderName)); } XSound.ENTITY_CHICKEN_EGG.play(player); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/BuildWorldCreatorImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/BuildWorldCreatorImpl.java index abcc7f29..a423b5c1 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/BuildWorldCreatorImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/BuildWorldCreatorImpl.java @@ -38,8 +38,8 @@ import dev.dewy.nbt.tags.primitive.IntTag; import java.io.File; import java.io.IOException; -import java.util.AbstractMap; import java.util.Locale; +import java.util.Map; import java.util.logging.Level; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -166,8 +166,8 @@ public void importWorld(Player player, boolean teleport) { */ private boolean createWorldFromGenerator(Player player) { Messages.sendMessage(player, "worlds_world_creation_started", - new AbstractMap.SimpleEntry<>("%world%", worldName), - new AbstractMap.SimpleEntry<>("%type%", Messages.getString(worldType.getMessageKey(), player)) + Map.entry("%world%", worldName), + Map.entry("%type%", Messages.getString(Messages.getMessageKey(worldType), player)) ); BuildWorld buildWorld = createAndRegisterBuildWorld(player); @@ -189,8 +189,8 @@ private boolean createWorldFromTemplate(Player player) { } Messages.sendMessage(player, "worlds_template_creation_started", - new AbstractMap.SimpleEntry<>("%world%", worldName), - new AbstractMap.SimpleEntry<>("%template%", template) + Map.entry("%world%", worldName), + Map.entry("%template%", template) ); File worldFile = new File(Bukkit.getWorldContainer(), worldName); @@ -276,7 +276,7 @@ private WorldCreator createBukkitWorldCreator() { break; case CUSTOM: if (customGenerator != null) { - worldCreator.generator(customGenerator.getChunkGenerator()); + worldCreator.generator(customGenerator.chunkGenerator()); } // Fall-through to NORMAL for default settings default: // NORMAL diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/CreateInventory.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/CreateInventory.java index b4a0ba64..3eb735f4 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/CreateInventory.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/CreateInventory.java @@ -31,8 +31,8 @@ import de.eintosti.buildsystem.world.WorldServiceImpl; import java.io.File; import java.io.FileFilter; -import java.util.AbstractMap; import java.util.Locale; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -147,7 +147,7 @@ private void addTemplates(Player player, Page page) { for (File templateFile : templateFiles) { inventory.setItem(columnTemplate++, InventoryUtils.createItem(XMaterial.FILLED_MAP, Messages.getString("create_template", player, - new AbstractMap.SimpleEntry<>("%template%", templateFile.getName())) + Map.entry("%template%", templateFile.getName())) ) ); @@ -188,19 +188,12 @@ public void onInventoryClick(InventoryClickEvent event) { return; } - CreateInventory.Page newPage = null; - - switch (event.getSlot()) { - case 12: - newPage = CreateInventory.Page.PREDEFINED; - break; - case 13: - newPage = CreateInventory.Page.GENERATOR; - break; - case 14: - newPage = CreateInventory.Page.TEMPLATES; - break; - } + CreateInventory.Page newPage = switch (event.getSlot()) { + case 12 -> Page.PREDEFINED; + case 13 -> Page.GENERATOR; + case 14 -> Page.TEMPLATES; + default -> null; + }; if (newPage != null) { openInventory(player, newPage, this.visibility, this.folder); @@ -217,25 +210,14 @@ public void onInventoryClick(InventoryClickEvent event) { switch (Page.getCurrentPage(inventory)) { case PREDEFINED: { - BuildWorldType worldType = null; - - switch (slot) { - case 29: - worldType = BuildWorldType.NORMAL; - break; - case 30: - worldType = BuildWorldType.FLAT; - break; - case 31: - worldType = BuildWorldType.NETHER; - break; - case 32: - worldType = BuildWorldType.END; - break; - case 33: - worldType = BuildWorldType.VOID; - break; - } + BuildWorldType worldType = switch (slot) { + case 29 -> BuildWorldType.NORMAL; + case 30 -> BuildWorldType.FLAT; + case 31 -> BuildWorldType.NETHER; + case 32 -> BuildWorldType.END; + case 33 -> BuildWorldType.VOID; + default -> null; + }; if (worldType == null || !player.hasPermission("buildsystem.create.type." + worldType.name().toLowerCase(Locale.ROOT))) { XSound.ENTITY_ITEM_BREAK.play(player); diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/generator/CustomGeneratorImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/generator/CustomGeneratorImpl.java index e8ebfb19..152c23ba 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/generator/CustomGeneratorImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/creation/generator/CustomGeneratorImpl.java @@ -20,21 +20,6 @@ import de.eintosti.buildsystem.api.world.creation.generator.CustomGenerator; import org.bukkit.generator.ChunkGenerator; -public class CustomGeneratorImpl implements CustomGenerator { +public record CustomGeneratorImpl(String name, ChunkGenerator chunkGenerator) implements CustomGenerator { - private final String name; - private final ChunkGenerator chunkGenerator; - - public CustomGeneratorImpl(String name, ChunkGenerator chunkGenerator) { - this.name = name; - this.chunkGenerator = chunkGenerator; - } - - public String getName() { - return name; - } - - public ChunkGenerator getChunkGenerator() { - return chunkGenerator; - } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/data/StatusInventory.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/data/StatusInventory.java index 30a5cbb7..af68b36f 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/data/StatusInventory.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/data/StatusInventory.java @@ -28,7 +28,7 @@ import de.eintosti.buildsystem.api.world.data.BuildWorldStatus; import de.eintosti.buildsystem.player.PlayerServiceImpl; import de.eintosti.buildsystem.util.InventoryUtils; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -58,7 +58,7 @@ private Inventory getInventory(Player player) { selectedWorldName = "N/A"; } - String title = Messages.getString("status_title", player, new AbstractMap.SimpleEntry<>("%world%", selectedWorldName)); + String title = Messages.getString("status_title", player, Map.entry("%world%", selectedWorldName)); Inventory inventory = Bukkit.createInventory(null, 27, title); fillGuiWithGlass(player, inventory); @@ -87,7 +87,7 @@ private void fillGuiWithGlass(Player player, Inventory inventory) { private void addStatusItem(Player player, Inventory inventory, int position, BuildWorldStatus status) { XMaterial material = plugin.getCustomizableIcons().getIcon(status); - String displayName = Messages.getString(status.getMessageKey(), player); + String displayName = Messages.getString(Messages.getMessageKey(status), player); if (!player.hasPermission(status.getPermission())) { material = XMaterial.BARRIER; @@ -116,7 +116,7 @@ public void onInventoryClick(InventoryClickEvent event) { return; } - String statusTitle = Messages.getString("status_title", player, new AbstractMap.SimpleEntry<>("%world%", selectedWorldName)); + String statusTitle = Messages.getString("status_title", player, Map.entry("%world%", selectedWorldName)); if (!XInventoryView.of(event.getView()).getTitle().equals(statusTitle)) { return; } @@ -160,8 +160,8 @@ public void onInventoryClick(InventoryClickEvent event) { XSound.ENTITY_CHICKEN_EGG.play(player); Messages.sendMessage(player, "worlds_setstatus_set", - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()), - new AbstractMap.SimpleEntry<>("%status%", Messages.getString(status.getMessageKey(), player)) + Map.entry("%world%", buildWorld.getName()), + Map.entry("%status%", Messages.getString(Messages.getMessageKey(status), player)) ); } @@ -172,21 +172,14 @@ public void onInventoryClick(InventoryClickEvent event) { * @return The status which is represented by the item at the given slot */ private BuildWorldStatus getStatusFromSlot(int slot) { - switch (slot) { - case 10: - return BuildWorldStatus.NOT_STARTED; - case 11: - return BuildWorldStatus.IN_PROGRESS; - case 12: - return BuildWorldStatus.ALMOST_FINISHED; - case 13: - return BuildWorldStatus.FINISHED; - case 14: - return BuildWorldStatus.ARCHIVE; - case 16: - return BuildWorldStatus.HIDDEN; - default: - throw new IllegalArgumentException("Slot " + slot + " does not correspond to status"); - } + return switch (slot) { + case 10 -> BuildWorldStatus.NOT_STARTED; + case 11 -> BuildWorldStatus.IN_PROGRESS; + case 12 -> BuildWorldStatus.ALMOST_FINISHED; + case 13 -> BuildWorldStatus.FINISHED; + case 14 -> BuildWorldStatus.ARCHIVE; + case 16 -> BuildWorldStatus.HIDDEN; + default -> throw new IllegalArgumentException("Slot " + slot + " does not correspond to status"); + }; } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/display/CustomizableIcons.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/display/CustomizableIcons.java index c5498f43..f249aec7 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/display/CustomizableIcons.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/display/CustomizableIcons.java @@ -44,15 +44,16 @@ public CustomizableIcons(BuildSystemPlugin plugin) { } private Map loadTypeIcons() { - Map typeIcons = new EnumMap<>(BuildWorldType.class); - typeIcons.put(BuildWorldType.NORMAL, XMaterial.OAK_LOG); - typeIcons.put(BuildWorldType.FLAT, XMaterial.GRASS_BLOCK); - typeIcons.put(BuildWorldType.NETHER, XMaterial.NETHERRACK); - typeIcons.put(BuildWorldType.END, XMaterial.END_STONE); - typeIcons.put(BuildWorldType.VOID, XMaterial.GLASS); - typeIcons.put(BuildWorldType.CUSTOM, XMaterial.FILLED_MAP); - typeIcons.put(BuildWorldType.TEMPLATE, XMaterial.FILLED_MAP); - typeIcons.put(BuildWorldType.IMPORTED, XMaterial.FURNACE); + Map typeIcons = new EnumMap<>(Map.ofEntries( + Map.entry(BuildWorldType.NORMAL, XMaterial.OAK_LOG), + Map.entry(BuildWorldType.FLAT, XMaterial.GRASS_BLOCK), + Map.entry(BuildWorldType.NETHER, XMaterial.NETHERRACK), + Map.entry(BuildWorldType.END, XMaterial.END_STONE), + Map.entry(BuildWorldType.VOID, XMaterial.GLASS), + Map.entry(BuildWorldType.CUSTOM, XMaterial.FILLED_MAP), + Map.entry(BuildWorldType.TEMPLATE, XMaterial.FILLED_MAP), + Map.entry(BuildWorldType.IMPORTED, XMaterial.FURNACE) + )); Map loadedIcons = this.setupConfig.loadIcons(IconType.TYPE, type -> BuildWorldType.valueOf(type.toUpperCase(Locale.ROOT))); if (loadedIcons != null) { @@ -64,13 +65,14 @@ private Map loadTypeIcons() { } private Map loadStatusIcons() { - Map statusIcon = new EnumMap<>(BuildWorldStatus.class); - statusIcon.put(BuildWorldStatus.NOT_STARTED, XMaterial.RED_DYE); - statusIcon.put(BuildWorldStatus.IN_PROGRESS, XMaterial.ORANGE_DYE); - statusIcon.put(BuildWorldStatus.ALMOST_FINISHED, XMaterial.LIME_DYE); - statusIcon.put(BuildWorldStatus.FINISHED, XMaterial.GREEN_DYE); - statusIcon.put(BuildWorldStatus.ARCHIVE, XMaterial.CYAN_DYE); - statusIcon.put(BuildWorldStatus.HIDDEN, XMaterial.BONE_MEAL); + Map statusIcon = new EnumMap<>(Map.ofEntries( + Map.entry(BuildWorldStatus.NOT_STARTED, XMaterial.RED_DYE), + Map.entry(BuildWorldStatus.IN_PROGRESS, XMaterial.ORANGE_DYE), + Map.entry(BuildWorldStatus.ALMOST_FINISHED, XMaterial.LIME_DYE), + Map.entry(BuildWorldStatus.FINISHED, XMaterial.GREEN_DYE), + Map.entry(BuildWorldStatus.ARCHIVE, XMaterial.CYAN_DYE), + Map.entry(BuildWorldStatus.HIDDEN, XMaterial.BONE_MEAL) + )); Map loadedIcons = this.setupConfig.loadIcons(IconType.STATUS, type -> BuildWorldStatus.valueOf(type.toUpperCase(Locale.ROOT))); if (loadedIcons != null) { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/display/FolderImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/display/FolderImpl.java index 749905e9..2f8c09fa 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/display/FolderImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/display/FolderImpl.java @@ -26,10 +26,10 @@ import de.eintosti.buildsystem.api.world.util.WorldPermissions; import de.eintosti.buildsystem.storage.FolderStorageImpl; import de.eintosti.buildsystem.world.util.WorldPermissionsImpl; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.UUID; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -141,7 +141,7 @@ public int getWorldCount() { @Override public String getDisplayName(Player player) { return Messages.getString("folder_item_title", player, - new AbstractMap.SimpleEntry<>("%folder%", name) + Map.entry("%folder%", name) ); } @@ -198,9 +198,9 @@ public boolean canView(Player player) { @Override public List getLore(Player player) { return new ArrayList<>(Messages.getStringList("folder_item_lore", player, - new AbstractMap.SimpleEntry<>("%permission%", this.permission), - new AbstractMap.SimpleEntry<>("%project%", this.project), - new AbstractMap.SimpleEntry<>("%worlds%", String.valueOf(getWorldCount()))) + Map.entry("%permission%", this.permission), + Map.entry("%project%", this.project), + Map.entry("%worlds%", String.valueOf(getWorldCount()))) ); } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/modification/DeleteInventory.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/modification/DeleteInventory.java index 39e67756..05a5183c 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/modification/DeleteInventory.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/modification/DeleteInventory.java @@ -23,7 +23,7 @@ import de.eintosti.buildsystem.Messages; import de.eintosti.buildsystem.api.world.BuildWorld; import de.eintosti.buildsystem.util.InventoryUtils; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -48,7 +48,7 @@ private Inventory getInventory(Player player, BuildWorld buildWorld) { Messages.getString("delete_world_confirm", player)) ); inventory.setItem(13, InventoryUtils.createItem(XMaterial.FILLED_MAP, - Messages.getString("delete_world_name", player, new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())), + Messages.getString("delete_world_name", player, Map.entry("%world%", buildWorld.getName())), Messages.getStringList("delete_world_name_lore", player)) ); inventory.setItem(15, InventoryUtils.createItem(XMaterial.RED_DYE, @@ -100,7 +100,7 @@ public void onInventoryClick(InventoryClickEvent event) { } else if (slot == 15) { XSound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR.play(player); player.closeInventory(); - Messages.sendMessage(player, "worlds_delete_canceled", new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())); + Messages.sendMessage(player, "worlds_delete_canceled", Map.entry("%world%", buildWorld.getName())); } } } \ No newline at end of file diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/modification/EditInventory.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/modification/EditInventory.java index b90f6cfc..6e0d3323 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/modification/EditInventory.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/modification/EditInventory.java @@ -33,9 +33,9 @@ import de.eintosti.buildsystem.player.PlayerServiceImpl; import de.eintosti.buildsystem.util.InventoryUtils; import de.eintosti.buildsystem.world.data.WorldDataImpl; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import org.bukkit.Bukkit; @@ -112,17 +112,17 @@ public Inventory getInventory(Player player, BuildWorld buildWorld) { addDifficultyItem(player, inventory, buildWorld); inventory.setItem(40, InventoryUtils.createItem(plugin.getCustomizableIcons().getIcon(worldData.status().get()), Messages.getString("worldeditor_status_item", player), Messages.getStringList("worldeditor_status_lore", player, - new AbstractMap.SimpleEntry<>("%status%", Messages.getString(buildWorld.getData().status().get().getMessageKey(), player)) + Map.entry("%status%", Messages.getString(Messages.getMessageKey(buildWorld.getData().status().get()), player)) ) )); inventory.setItem(41, InventoryUtils.createItem(XMaterial.ANVIL, Messages.getString("worldeditor_project_item", player), Messages.getStringList("worldeditor_project_lore", player, - new AbstractMap.SimpleEntry<>("%project%", buildWorld.getData().project().get()) + Map.entry("%project%", buildWorld.getData().project().get()) ) )); inventory.setItem(42, InventoryUtils.createItem(XMaterial.PAPER, Messages.getString("worldeditor_permission_item", player), Messages.getStringList("worldeditor_permission_lore", player, - new AbstractMap.SimpleEntry<>("%permission%", buildWorld.getData().permission().get()) + Map.entry("%permission%", buildWorld.getData().permission().get()) ) )); @@ -140,7 +140,7 @@ private void fillGuiWithGlass(Player player, Inventory inventory) { } private void addBuildWorldInfoItem(Player player, Inventory inventory, BuildWorld buildWorld) { - String displayName = Messages.getString("worldeditor_world_item", player, new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName())); + String displayName = Messages.getString("worldeditor_world_item", player, Map.entry("%world%", buildWorld.getName())); XMaterial material = buildWorld.getData().material().get(); if (material == XMaterial.PLAYER_HEAD) { @@ -190,7 +190,7 @@ private void addTimeItem(Player player, Inventory inventory, BuildWorld buildWor } inventory.setItem(23, InventoryUtils.createItem(xMaterial, Messages.getString("worldeditor_time_item", player), - Messages.getStringList("worldeditor_time_lore", player, new AbstractMap.SimpleEntry<>("%time%", value)) + Messages.getStringList("worldeditor_time_lore", player, Map.entry("%time%", value)) )); } @@ -246,26 +246,17 @@ private void addVisibilityItem(Player player, Inventory inventory, BuildWorld bu } private void addDifficultyItem(Player player, Inventory inventory, BuildWorld buildWorld) { - XMaterial xMaterial; - switch (buildWorld.getData().difficulty().get()) { - case EASY: - xMaterial = XMaterial.GOLDEN_HELMET; - break; - case NORMAL: - xMaterial = XMaterial.IRON_HELMET; - break; - case HARD: - xMaterial = XMaterial.DIAMOND_HELMET; - break; - default: - xMaterial = XMaterial.LEATHER_HELMET; - break; - } - - inventory.setItem(39, InventoryUtils.createItem(xMaterial, + XMaterial material = switch (buildWorld.getData().difficulty().get()) { + case EASY -> XMaterial.GOLDEN_HELMET; + case NORMAL -> XMaterial.IRON_HELMET; + case HARD -> XMaterial.DIAMOND_HELMET; + default -> XMaterial.LEATHER_HELMET; + }; + + inventory.setItem(39, InventoryUtils.createItem(material, Messages.getString("worldeditor_difficulty_item", player), Messages.getStringList("worldeditor_difficulty_lore", player, - new AbstractMap.SimpleEntry<>("%difficulty%", getDifficultyName(buildWorld, player)) + Map.entry("%difficulty%", getDifficultyName(buildWorld, player)) ) )); } @@ -274,22 +265,16 @@ private void addDifficultyItem(Player player, Inventory inventory, BuildWorld bu * Get the display name of a {@link Difficulty}. * * @param player The player to parse the placeholders against - * @return the difficulty's display name + * @return The difficulty's display name * @see WorldDataImpl#difficulty() */ private String getDifficultyName(BuildWorld buildWorld, Player player) { - switch (buildWorld.getData().difficulty().get()) { - case PEACEFUL: - return Messages.getString("difficulty_peaceful", player); - case EASY: - return Messages.getString("difficulty_easy", player); - case NORMAL: - return Messages.getString("difficulty_normal", player); - case HARD: - return Messages.getString("difficulty_hard", player); - default: - return "-"; - } + return switch (buildWorld.getData().difficulty().get()) { + case PEACEFUL -> Messages.getString("difficulty_peaceful", player); + case EASY -> Messages.getString("difficulty_easy", player); + case NORMAL -> Messages.getString("difficulty_normal", player); + case HARD -> Messages.getString("difficulty_hard", player); + }; } @EventHandler @@ -467,7 +452,7 @@ private void removeEntities(Player player, BuildWorld buildWorld) { }); player.closeInventory(); - Messages.sendMessage(player, "worldeditor_butcher_removed", new AbstractMap.SimpleEntry<>("%amount%", entitiesRemoved.get())); + Messages.sendMessage(player, "worldeditor_butcher_removed", Map.entry("%amount%", entitiesRemoved.get())); } public enum Time { diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/util/WorldLoaderImpl.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/util/WorldLoaderImpl.java index 9a7fe1dc..20e489c6 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/util/WorldLoaderImpl.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/world/util/WorldLoaderImpl.java @@ -25,7 +25,7 @@ import de.eintosti.buildsystem.api.world.BuildWorld; import de.eintosti.buildsystem.api.world.util.WorldLoader; import de.eintosti.buildsystem.world.creation.BuildWorldCreatorImpl; -import java.util.AbstractMap; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -54,7 +54,7 @@ public void loadForPlayer(Player player) { player.closeInventory(); Titles.sendTitle(player, 5, 70, 20, " ", Messages.getString("loading_world", player, - new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()) + Map.entry("%world%", buildWorld.getName()) ) );