Skip to content

Commit 73c9933

Browse files
多加点位置
1 parent f7b1c7a commit 73c9933

3 files changed

Lines changed: 50 additions & 33 deletions

File tree

src/main/java/ict/minesunshineone/landmark/gui/LandmarkMenu.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
public class LandmarkMenu implements InventoryHolder {
2828

2929
private static final String LANDMARK_KEY = "landmark_name";
30+
private static final int INVENTORY_COLUMNS = 9;
31+
private static final int MAX_MENU_COLUMNS = 7;
3032
private final LandmarkPlugin plugin;
3133
private final UUID playerId;
3234
private Inventory inventory;
@@ -61,16 +63,20 @@ private void initializeItems() {
6163
private void setupBorder() {
6264
ItemStack border = createBorderItem();
6365

66+
int rows = Math.max(1, inventory.getSize() / INVENTORY_COLUMNS);
67+
int lastRowStart = (rows - 1) * INVENTORY_COLUMNS;
68+
6469
// 设置顶部和底部边框
65-
for (int i = 0; i < 9; i++) {
66-
inventory.setItem(i, border.clone());
67-
inventory.setItem(36 + i, border.clone());
70+
for (int column = 0; column < INVENTORY_COLUMNS; column++) {
71+
inventory.setItem(column, border.clone());
72+
inventory.setItem(lastRowStart + column, border.clone());
6873
}
6974

7075
// 设置左右边框
71-
for (int i = 1; i < 4; i++) {
72-
inventory.setItem(9 * i, border.clone());
73-
inventory.setItem(9 * i + 8, border.clone());
76+
for (int row = 1; row < rows - 1; row++) {
77+
int rowStart = row * INVENTORY_COLUMNS;
78+
inventory.setItem(rowStart, border.clone());
79+
inventory.setItem(rowStart + (INVENTORY_COLUMNS - 1), border.clone());
7480
}
7581
}
7682

@@ -102,24 +108,29 @@ private void setupCurrentLocation() {
102108
}
103109

104110
ItemStack currentLocationItem = createCurrentLocationItem(isAtAnyLandmark, currentLandmark);
105-
inventory.setItem(40, currentLocationItem);
111+
int centerColumn = INVENTORY_COLUMNS / 2;
112+
int centerSlot = (inventory.getSize() - INVENTORY_COLUMNS) + centerColumn;
113+
if (centerSlot >= 0 && centerSlot < inventory.getSize()) {
114+
inventory.setItem(centerSlot, currentLocationItem);
115+
}
106116
}
107117

108118
private void setupLandmarks() {
119+
int maxMenuRow = Math.max(1, (inventory.getSize() / INVENTORY_COLUMNS) - 2);
109120
for (Map.Entry<String, Landmark> entry : plugin.getLandmarkManager().getLandmarks().entrySet()) {
110121
Landmark landmark = entry.getValue();
111122
int row = landmark.getMenuRow();
112123
int col = landmark.getMenuColumn();
113124

114-
// 确保位置在有效范围内(第2-4行,即索引1-3,列1-7)
115-
if (row < 1 || row > 3 || col < 1 || col > 7) {
125+
// 确保位置在有效范围内(第2-倒数第二行,即索引1-maxMenuRow,列1-7)
126+
if (row < 1 || row > maxMenuRow || col < 1 || col > MAX_MENU_COLUMNS) {
116127
plugin.getSLF4JLogger().warn("锚点 {} 的位置 ({}, {}) 超出有效范围,将在下次加载时自动修复",
117128
landmark.getName(), row, col);
118129
continue;
119130
}
120131

121-
// 计算实际槽位(row对应第2-4行
122-
int slot = (row * 9) + col;
132+
// 计算实际槽位(row 为去除边框后的行索引
133+
int slot = (row * INVENTORY_COLUMNS) + col;
123134
boolean isUnlocked = plugin.getLandmarkManager().isLandmarkUnlocked(getPlayer(), entry.getKey());
124135
ItemStack item = createLandmarkItem(landmark, isUnlocked);
125136

src/main/java/ict/minesunshineone/landmark/manager/LandmarkManager.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class LandmarkManager {
2525
private final Map<String, Landmark> landmarks;
2626
private final Map<UUID, Set<String>> unlockedLandmarks;
2727
private final Map<UUID, Long> cooldowns;
28+
private static final int MAX_MENU_COLUMNS = 7;
2829

2930
public LandmarkManager(LandmarkPlugin plugin) {
3031
this.plugin = plugin;
@@ -61,39 +62,26 @@ public void createLandmark(String name, Location location, String description) {
6162
}
6263

6364
private int[] calculateNextMenuPosition() {
64-
int maxRow = 1; // 从第二行开始(索引1)
65-
int maxCol = 1; // 从第一列开始(索引1)
66-
boolean[][] occupied = new boolean[4][9]; // 4行9列的网格,实际使用1-3行,1-7列
65+
int maxRow = getMaxMenuRows();
66+
boolean[][] occupied = new boolean[maxRow + 1][MAX_MENU_COLUMNS + 1];
6767

68-
// 标记已占用的位置
6968
for (Landmark landmark : landmarks.values()) {
7069
int row = landmark.getMenuRow();
7170
int col = landmark.getMenuColumn();
72-
if (row >= 1 && row <= 3 && col >= 1 && col <= 7) { // 修改范围:第2-4行(索引1-3),第1-7列
71+
if (row >= 1 && row <= maxRow && col >= 1 && col <= MAX_MENU_COLUMNS) {
7372
occupied[row][col] = true;
74-
maxRow = Math.max(maxRow, row);
75-
maxCol = Math.max(maxCol, col);
7673
}
7774
}
7875

79-
// 寻找下一个可用位置(从第二行到第四行,第一列到第七列)
80-
for (int row = 1; row <= 3; row++) {
81-
for (int col = 1; col <= 7; col++) {
76+
for (int row = 1; row <= maxRow; row++) {
77+
for (int col = 1; col <= MAX_MENU_COLUMNS; col++) {
8278
if (!occupied[row][col]) {
8379
return new int[]{row, col};
8480
}
8581
}
8682
}
8783

88-
// 如果当前行未满,添加到当前行的下一个位置
89-
if (maxCol < 7) {
90-
return new int[]{maxRow, maxCol + 1};
91-
}
92-
// 如果需要新的一行(最多到第3行,对应实际的第4行)
93-
if (maxRow < 3) {
94-
return new int[]{maxRow + 1, 1}; // 新行从第一列开始
95-
}
96-
// 如果菜单已满,返回默认位置(第1行第1列,对应实际的第2行第1列)
84+
plugin.getSLF4JLogger().warn("锚点菜单已满,使用默认位置 (1,1)");
9785
return new int[]{1, 1};
9886
}
9987

@@ -232,6 +220,16 @@ public final void loadData() {
232220
int menuRow = landmarkSection.getInt("menu_row", 1);
233221
int menuColumn = landmarkSection.getInt("menu_column", 1);
234222

223+
int maxRow = getMaxMenuRows();
224+
if (menuRow < 1 || menuRow > maxRow) {
225+
plugin.getSLF4JLogger().warn("锚点 {} 的菜单行 {} 超出范围,已调整至有效值", key, menuRow);
226+
menuRow = Math.max(1, Math.min(menuRow, maxRow));
227+
}
228+
if (menuColumn < 1 || menuColumn > MAX_MENU_COLUMNS) {
229+
plugin.getSLF4JLogger().warn("锚点 {} 的菜单列 {} 超出范围,已调整至有效值", key, menuColumn);
230+
menuColumn = Math.max(1, Math.min(menuColumn, MAX_MENU_COLUMNS));
231+
}
232+
235233
Landmark landmark = new Landmark(key, location, description, menuRow, menuColumn);
236234
landmarks.put(key.toLowerCase(), landmark);
237235
}
@@ -403,15 +401,22 @@ public void cleanup() {
403401
public void updateMenuPosition(String landmarkName, int newRow, int newColumn) {
404402
Landmark landmark = landmarks.get(landmarkName.toLowerCase());
405403
if (landmark != null) {
406-
// 确保位置在有效范围内(第2-4行,即索引1-3,列1-7)
407-
if (newRow >= 1 && newRow <= 3 && newColumn >= 1 && newColumn <= 7) {
404+
int maxRow = getMaxMenuRows();
405+
// 确保位置在有效范围内(第2-倒数第二行,即索引1-maxRow,列1-7)
406+
if (newRow >= 1 && newRow <= maxRow && newColumn >= 1 && newColumn <= MAX_MENU_COLUMNS) {
408407
landmark.setMenuRow(newRow);
409408
landmark.setMenuColumn(newColumn);
410409
saveData();
411410
}
412411
}
413412
}
414413

414+
private int getMaxMenuRows() {
415+
int guiSize = plugin.getConfigManager().getConfig().getInt("gui.size", 54);
416+
int totalRows = Math.max(1, guiSize / 9);
417+
return Math.max(1, totalRows - 2);
418+
}
419+
415420
// 新增一键解锁所有锚点的方法
416421
public void unlockAllLandmarks(Player player) {
417422
if (!player.hasPermission("landmark.unlock.all")) {

src/main/resources/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ messages:
4646
# GUI设置
4747
gui:
4848
title: '<#c7a3ed><bold>✧ 魔法锚点系统 ✦</bold>'
49-
size: 45
49+
# 菜单总格数 (6 行 x 9 列)
50+
size: 54
5051
border:
5152
material: BLACK_STAINED_GLASS_PANE
5253
name: ' '

0 commit comments

Comments
 (0)