From dc846240f3650aaf8db76610db4f0697fe662486 Mon Sep 17 00:00:00 2001 From: Zoriot Date: Wed, 27 Aug 2025 18:38:38 +0200 Subject: [PATCH] =?UTF-8?q?fix(tutorial):=20=F0=9F=A9=B9=20refactor=20base?= =?UTF-8?q?=20block=20handling=20to=20support=20multiple=20block=20names?= =?UTF-8?q?=20and=20improve=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/tutorial/BeginnerTutorial.java | 49 +++++++++++++------ .../events/commands/LineCmdEventTask.java | 18 +++---- .../plotsystem/utils/io/TutorialPaths.java | 7 ++- .../resources/tutorial/tutorial_beginner.yml | 5 +- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/tutorial/BeginnerTutorial.java b/src/main/java/com/alpsbte/plotsystem/core/system/tutorial/BeginnerTutorial.java index d20500ced..a2f9e8535 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/tutorial/BeginnerTutorial.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/tutorial/BeginnerTutorial.java @@ -1,7 +1,7 @@ /* - * The MIT License (MIT) + * The MIT License (MIT) * - * Copyright © 2025, Alps BTE + * Copyright © 2021-2025, Alps BTE * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -40,24 +40,44 @@ import com.alpsbte.plotsystem.core.system.tutorial.stage.tasks.message.ChatMessageTask; import com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils; import com.alpsbte.plotsystem.utils.Utils; -import com.alpsbte.plotsystem.utils.io.*; +import com.alpsbte.plotsystem.utils.io.ConfigPaths; +import com.alpsbte.plotsystem.utils.io.ConfigUtil; +import com.alpsbte.plotsystem.utils.io.LangPaths; +import com.alpsbte.plotsystem.utils.io.LangUtil; +import com.alpsbte.plotsystem.utils.io.TutorialPaths; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.data.BlockData; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; -import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.*; +import static com.alpsbte.alpslib.utils.AlpsUtils.deserialize; +import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.Delay; import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.Sound; +import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.TEXT_CLICK_HIGHLIGHT; +import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.TEXT_HIGHLIGHT_END; +import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.TEXT_HIGHLIGHT_START; +import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.getDocumentationLinks; +import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.setBlockAt; import static net.kyori.adventure.text.Component.text; -import static com.alpsbte.alpslib.utils.AlpsUtils.deserialize; -import static net.kyori.adventure.text.format.NamedTextColor.*; +import static net.kyori.adventure.text.format.NamedTextColor.DARK_GRAY; +import static net.kyori.adventure.text.format.NamedTextColor.GRAY; +import static net.kyori.adventure.text.format.NamedTextColor.GREEN; import static net.kyori.adventure.text.format.TextDecoration.BOLD; public class BeginnerTutorial extends AbstractPlotTutorial { @@ -106,7 +126,7 @@ public void onTutorialComplete(UUID playerUUID) { Bukkit.getScheduler().runTaskLaterAsynchronously(PlotSystem.getPlugin(), () -> { sendTutorialCompletedTipMessage(getPlayer()); getPlayer().playSound(getPlayer().getLocation(), Utils.SoundUtils.NOTIFICATION_SOUND, 1f, 1f); - }, 20 * 7); + }, 20 * 7L); } private static class Stage1 extends AbstractPlotStage { @@ -312,8 +332,7 @@ public StageTimeline getTimeline() { } private static class Stage5 extends AbstractPlotStage { - private final static String BASE_BLOCK = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getString(TutorialPaths.Beginner.BASE_BLOCK); - private final static int BASE_BLOCK_ID = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.BASE_BLOCK_ID); + private static final List BASE_BLOCKS = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getStringList(TutorialPaths.Beginner.BASE_BLOCKS); protected Stage5(Player player, TutorialPlot plot) { super(player, 1, plot, 1); @@ -335,7 +354,7 @@ public List setMessages() { @Override protected List setTasks() { return LangUtil.getInstance().getList(getPlayer(), LangPaths.Tutorials.Beginner.STAGE5_TASKS, - TEXT_HIGHLIGHT_START + "//line " + BASE_BLOCK.toLowerCase() + TEXT_HIGHLIGHT_END); + TEXT_HIGHLIGHT_START + "//line " + BASE_BLOCKS.getFirst() + TEXT_HIGHLIGHT_END); } @Override @@ -364,7 +383,7 @@ public StageTimeline getTimeline() { }, Sound.NPC_TALK, false) .delay(Delay.TASK_START) .addTask(new PlotPermissionChangeTask(getPlayer(), false, true)) - .addTask(new LineCmdEventTask(getPlayer(), deserialize(getTasks().getFirst()), BASE_BLOCK, BASE_BLOCK_ID, buildingLinePoints, ((minPoint, maxPoint) -> { + .addTask(new LineCmdEventTask(getPlayer(), deserialize(getTasks().getFirst()), BASE_BLOCKS, buildingLinePoints, ((minPoint, maxPoint) -> { if (minPoint != null && maxPoint != null) { buildingLinePoints.remove(minPoint); @@ -381,8 +400,8 @@ public StageTimeline getTimeline() { } private static class Stage6 extends AbstractPlotStage { - private final static int HEIGHT = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.HEIGHT); - private final static int HEIGHT_OFFSET = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.HEIGHT_OFFSET); + private static final int HEIGHT = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.HEIGHT); + private static final int HEIGHT_OFFSET = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.HEIGHT_OFFSET); protected Stage6(Player player, TutorialPlot plot) { super(player, 1, plot, 2); diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/tutorial/stage/tasks/events/commands/LineCmdEventTask.java b/src/main/java/com/alpsbte/plotsystem/core/system/tutorial/stage/tasks/events/commands/LineCmdEventTask.java index 048e9a733..55a1653b0 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/tutorial/stage/tasks/events/commands/LineCmdEventTask.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/tutorial/stage/tasks/events/commands/LineCmdEventTask.java @@ -1,7 +1,7 @@ /* - * The MIT License (MIT) + * The MIT License (MIT) * - * Copyright © 2023, Alps BTE + * Copyright © 2021-2025, Alps BTE * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -40,7 +40,9 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -53,8 +55,8 @@ public class LineCmdEventTask extends AbstractCmdEventTask { private Vector minPoint; private Vector maxPoint; - public LineCmdEventTask(Player player, Component assignmentMessage, String blockName, int blockId, Map linePoints, BiTaskAction lineCmdAction) { - super(player, "//line", new String[]{blockName, String.valueOf(blockId)}, assignmentMessage, linePoints.size(), true); + public LineCmdEventTask(Player player, Component assignmentMessage, @NotNull List blocks, @NotNull Map linePoints, BiTaskAction lineCmdAction) { + super(player, "//line", blocks.toArray(new String[0]), assignmentMessage, linePoints.size(), true); this.linePoints = linePoints; this.lineCmdAction = lineCmdAction; } @@ -83,8 +85,8 @@ protected void onCommand(boolean isValid, String[] args) { @Override public void performEvent(Event event) { - if (event instanceof PlayerInteractEvent) { - onPlayerInteractEvent((PlayerInteractEvent) event); + if (event instanceof PlayerInteractEvent playerInteractEvent) { + onPlayerInteractEvent(playerInteractEvent); } else super.performEvent(event); } @@ -108,11 +110,9 @@ private boolean isPointInLine(Vector point) { } private boolean drawLine() { - try { - EditSession editSession = WorldEdit.getInstance().newEditSession((new BukkitWorld(player.getWorld()))); + try (EditSession editSession = WorldEdit.getInstance().newEditSession((new BukkitWorld(player.getWorld())))) { editSession.drawLine(Objects.requireNonNull(BlockTypes.WHITE_WOOL).getDefaultState(), BlockVector3.at(minPoint.getX(), minPoint.getY(), minPoint.getZ()), BlockVector3.at(maxPoint.getX(), maxPoint.getY(), maxPoint.getZ()), 0, false); - editSession.close(); } catch (MaxChangedBlocksException ex) { PlotSystem.getPlugin().getComponentLogger().error(text("An error occurred while drawing line!"), ex); return false; diff --git a/src/main/java/com/alpsbte/plotsystem/utils/io/TutorialPaths.java b/src/main/java/com/alpsbte/plotsystem/utils/io/TutorialPaths.java index 2ef2191b6..3e5e73568 100644 --- a/src/main/java/com/alpsbte/plotsystem/utils/io/TutorialPaths.java +++ b/src/main/java/com/alpsbte/plotsystem/utils/io/TutorialPaths.java @@ -1,7 +1,7 @@ /* - * The MIT License (MIT) + * The MIT License (MIT) * - * Copyright © 2023, Alps BTE + * Copyright © 2021-2025, Alps BTE * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,8 +33,7 @@ public static final class Beginner { public static final String POINT_2 = TELEPORT_COORDINATES + "point-2"; public static final String POINT_3 = TELEPORT_COORDINATES + "point-3"; public static final String POINT_4 = TELEPORT_COORDINATES + "point-4"; - public static final String BASE_BLOCK = BEGINNER + "base-block"; - public static final String BASE_BLOCK_ID = BEGINNER + "base-block-id"; + public static final String BASE_BLOCKS = BEGINNER + "base-blocks"; public static final String HEIGHT = BEGINNER + "height"; public static final String HEIGHT_OFFSET = BEGINNER + "height-offset"; public static final String WINDOW_POINTS = BEGINNER + "window-points"; diff --git a/src/main/resources/tutorial/tutorial_beginner.yml b/src/main/resources/tutorial/tutorial_beginner.yml index e2f063f44..0a79569d3 100644 --- a/src/main/resources/tutorial/tutorial_beginner.yml +++ b/src/main/resources/tutorial/tutorial_beginner.yml @@ -66,9 +66,8 @@ beginner: point-2: '3693367.0,-4531328.0' point-3: '3693370.0,-4531337.0' point-4: '3693357.0,-4531342.0' - # BaseBlock for the building outline - base-block: 'WHITE_WOOL' - base-block-id: 35 + # BaseBlocks for the building outline (multiple blocks or legacy id's are supported) + base-blocks: [ 'WHITE_WOOL', 'WHITE', '35', '35:0' ] # Height of the plot building, which must be calculated height: 7 height-offset: 1