Skip to content

Commit db10c46

Browse files
CopilotZoriot
authored andcommitted
fix(tutorial): 🩹 refactor base block handling to support multiple block names and improve readability
1 parent 7565b4e commit db10c46

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

‎src/main/java/com/alpsbte/plotsystem/core/system/tutorial/BeginnerTutorial.java‎

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* The MIT License (MIT)
2+
* The MIT License (MIT)
33
*
4-
* Copyright © 2025, Alps BTE <[email protected]>
4+
* Copyright © 2021-2025, Alps BTE <[email protected]>
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -40,24 +40,44 @@
4040
import com.alpsbte.plotsystem.core.system.tutorial.stage.tasks.message.ChatMessageTask;
4141
import com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils;
4242
import com.alpsbte.plotsystem.utils.Utils;
43-
import com.alpsbte.plotsystem.utils.io.*;
43+
import com.alpsbte.plotsystem.utils.io.ConfigPaths;
44+
import com.alpsbte.plotsystem.utils.io.ConfigUtil;
45+
import com.alpsbte.plotsystem.utils.io.LangPaths;
46+
import com.alpsbte.plotsystem.utils.io.LangUtil;
47+
import com.alpsbte.plotsystem.utils.io.TutorialPaths;
4448
import net.kyori.adventure.text.Component;
4549
import net.kyori.adventure.text.event.ClickEvent;
4650
import net.kyori.adventure.text.event.HoverEvent;
47-
import org.bukkit.*;
51+
import org.bukkit.Bukkit;
52+
import org.bukkit.Location;
53+
import org.bukkit.Material;
54+
import org.bukkit.World;
4855
import org.bukkit.block.data.BlockData;
4956
import org.bukkit.configuration.file.FileConfiguration;
5057
import org.bukkit.entity.Player;
5158
import org.bukkit.util.Vector;
5259

5360
import java.io.IOException;
54-
import java.util.*;
61+
import java.util.ArrayList;
62+
import java.util.Arrays;
63+
import java.util.Collections;
64+
import java.util.HashMap;
65+
import java.util.List;
66+
import java.util.Map;
67+
import java.util.UUID;
5568

56-
import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.*;
69+
import static com.alpsbte.alpslib.utils.AlpsUtils.deserialize;
70+
import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.Delay;
5771
import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.Sound;
72+
import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.TEXT_CLICK_HIGHLIGHT;
73+
import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.TEXT_HIGHLIGHT_END;
74+
import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.TEXT_HIGHLIGHT_START;
75+
import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.getDocumentationLinks;
76+
import static com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils.setBlockAt;
5877
import static net.kyori.adventure.text.Component.text;
59-
import static com.alpsbte.alpslib.utils.AlpsUtils.deserialize;
60-
import static net.kyori.adventure.text.format.NamedTextColor.*;
78+
import static net.kyori.adventure.text.format.NamedTextColor.DARK_GRAY;
79+
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
80+
import static net.kyori.adventure.text.format.NamedTextColor.GREEN;
6181
import static net.kyori.adventure.text.format.TextDecoration.BOLD;
6282

6383
public class BeginnerTutorial extends AbstractPlotTutorial {
@@ -106,7 +126,7 @@ public void onTutorialComplete(UUID playerUUID) {
106126
Bukkit.getScheduler().runTaskLaterAsynchronously(PlotSystem.getPlugin(), () -> {
107127
sendTutorialCompletedTipMessage(getPlayer());
108128
getPlayer().playSound(getPlayer().getLocation(), Utils.SoundUtils.NOTIFICATION_SOUND, 1f, 1f);
109-
}, 20 * 7);
129+
}, 20 * 7L);
110130
}
111131

112132
private static class Stage1 extends AbstractPlotStage {
@@ -312,8 +332,7 @@ public StageTimeline getTimeline() {
312332
}
313333

314334
private static class Stage5 extends AbstractPlotStage {
315-
private final static String BASE_BLOCK = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getString(TutorialPaths.Beginner.BASE_BLOCK);
316-
private final static int BASE_BLOCK_ID = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.BASE_BLOCK_ID);
335+
private static final List<String> BASE_BLOCKS = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getStringList(TutorialPaths.Beginner.BASE_BLOCKS);
317336

318337
protected Stage5(Player player, TutorialPlot plot) {
319338
super(player, 1, plot, 1);
@@ -335,7 +354,7 @@ public List<String> setMessages() {
335354
@Override
336355
protected List<String> setTasks() {
337356
return LangUtil.getInstance().getList(getPlayer(), LangPaths.Tutorials.Beginner.STAGE5_TASKS,
338-
TEXT_HIGHLIGHT_START + "//line " + BASE_BLOCK.toLowerCase() + TEXT_HIGHLIGHT_END);
357+
TEXT_HIGHLIGHT_START + "//line " + BASE_BLOCKS.getFirst() + TEXT_HIGHLIGHT_END);
339358
}
340359

341360
@Override
@@ -364,7 +383,7 @@ public StageTimeline getTimeline() {
364383
}, Sound.NPC_TALK, false)
365384
.delay(Delay.TASK_START)
366385
.addTask(new PlotPermissionChangeTask(getPlayer(), false, true))
367-
.addTask(new LineCmdEventTask(getPlayer(), deserialize(getTasks().getFirst()), BASE_BLOCK, BASE_BLOCK_ID, buildingLinePoints, ((minPoint, maxPoint) -> {
386+
.addTask(new LineCmdEventTask(getPlayer(), deserialize(getTasks().getFirst()), BASE_BLOCKS, buildingLinePoints, ((minPoint, maxPoint) -> {
368387
if (minPoint != null && maxPoint != null) {
369388
buildingLinePoints.remove(minPoint);
370389

@@ -381,8 +400,8 @@ public StageTimeline getTimeline() {
381400
}
382401

383402
private static class Stage6 extends AbstractPlotStage {
384-
private final static int HEIGHT = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.HEIGHT);
385-
private final static int HEIGHT_OFFSET = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.HEIGHT_OFFSET);
403+
private static final int HEIGHT = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.HEIGHT);
404+
private static final int HEIGHT_OFFSET = ConfigUtil.getTutorialInstance().getBeginnerTutorial().getInt(TutorialPaths.Beginner.HEIGHT_OFFSET);
386405

387406
protected Stage6(Player player, TutorialPlot plot) {
388407
super(player, 1, plot, 2);

‎src/main/java/com/alpsbte/plotsystem/core/system/tutorial/stage/tasks/events/commands/LineCmdEventTask.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* The MIT License (MIT)
2+
* The MIT License (MIT)
33
*
4-
* Copyright © 2023, Alps BTE <[email protected]>
4+
* Copyright © 2021-2025, Alps BTE <[email protected]>
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -40,7 +40,9 @@
4040
import org.bukkit.event.player.PlayerInteractEvent;
4141
import org.bukkit.inventory.ItemStack;
4242
import org.bukkit.util.Vector;
43+
import org.jetbrains.annotations.NotNull;
4344

45+
import java.util.List;
4446
import java.util.Map;
4547
import java.util.Objects;
4648

@@ -53,8 +55,8 @@ public class LineCmdEventTask extends AbstractCmdEventTask {
5355
private Vector minPoint;
5456
private Vector maxPoint;
5557

56-
public LineCmdEventTask(Player player, Component assignmentMessage, String blockName, int blockId, Map<Vector, Vector> linePoints, BiTaskAction<Vector, Vector> lineCmdAction) {
57-
super(player, "//line", new String[]{blockName, String.valueOf(blockId)}, assignmentMessage, linePoints.size(), true);
58+
public LineCmdEventTask(Player player, Component assignmentMessage, @NotNull List<String> blocks, @NotNull Map<Vector, Vector> linePoints, BiTaskAction<Vector, Vector> lineCmdAction) {
59+
super(player, "//line", blocks.toArray(new String[0]), assignmentMessage, linePoints.size(), true);
5860
this.linePoints = linePoints;
5961
this.lineCmdAction = lineCmdAction;
6062
}
@@ -83,8 +85,8 @@ protected void onCommand(boolean isValid, String[] args) {
8385

8486
@Override
8587
public void performEvent(Event event) {
86-
if (event instanceof PlayerInteractEvent) {
87-
onPlayerInteractEvent((PlayerInteractEvent) event);
88+
if (event instanceof PlayerInteractEvent playerInteractEvent) {
89+
onPlayerInteractEvent(playerInteractEvent);
8890
} else super.performEvent(event);
8991
}
9092

@@ -108,11 +110,9 @@ private boolean isPointInLine(Vector point) {
108110
}
109111

110112
private boolean drawLine() {
111-
try {
112-
EditSession editSession = WorldEdit.getInstance().newEditSession((new BukkitWorld(player.getWorld())));
113+
try (EditSession editSession = WorldEdit.getInstance().newEditSession((new BukkitWorld(player.getWorld())))) {
113114
editSession.drawLine(Objects.requireNonNull(BlockTypes.WHITE_WOOL).getDefaultState(), BlockVector3.at(minPoint.getX(), minPoint.getY(), minPoint.getZ()),
114115
BlockVector3.at(maxPoint.getX(), maxPoint.getY(), maxPoint.getZ()), 0, false);
115-
editSession.close();
116116
} catch (MaxChangedBlocksException ex) {
117117
PlotSystem.getPlugin().getComponentLogger().error(text("An error occurred while drawing line!"), ex);
118118
return false;

‎src/main/java/com/alpsbte/plotsystem/utils/io/TutorialPaths.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* The MIT License (MIT)
2+
* The MIT License (MIT)
33
*
4-
* Copyright © 2023, Alps BTE <[email protected]>
4+
* Copyright © 2021-2025, Alps BTE <[email protected]>
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -33,8 +33,7 @@ public static final class Beginner {
3333
public static final String POINT_2 = TELEPORT_COORDINATES + "point-2";
3434
public static final String POINT_3 = TELEPORT_COORDINATES + "point-3";
3535
public static final String POINT_4 = TELEPORT_COORDINATES + "point-4";
36-
public static final String BASE_BLOCK = BEGINNER + "base-block";
37-
public static final String BASE_BLOCK_ID = BEGINNER + "base-block-id";
36+
public static final String BASE_BLOCKS = BEGINNER + "base-blocks";
3837
public static final String HEIGHT = BEGINNER + "height";
3938
public static final String HEIGHT_OFFSET = BEGINNER + "height-offset";
4039
public static final String WINDOW_POINTS = BEGINNER + "window-points";

‎src/main/resources/tutorial/tutorial_beginner.yml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ beginner:
6666
point-2: '3693367.0,-4531328.0'
6767
point-3: '3693370.0,-4531337.0'
6868
point-4: '3693357.0,-4531342.0'
69-
# BaseBlock for the building outline
70-
base-block: 'WHITE_WOOL'
71-
base-block-id: 35
69+
# BaseBlocks for the building outline (multiple blocks or legacy id's are supported)
70+
base-blocks: [ 'WHITE_WOOL', 'WHITE', '35' ]
7271
# Height of the plot building, which must be calculated
7372
height: 7
7473
height-offset: 1

0 commit comments

Comments
 (0)