Skip to content

Commit 3675b1d

Browse files
committed
1.15.2に仮対応
1 parent 040d8af commit 3675b1d

File tree

7 files changed

+170
-46
lines changed

7 files changed

+170
-46
lines changed

pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,39 @@
104104
<artifactId>mariadb-java-client</artifactId>
105105
<version>3.5.3</version>
106106
</dependency>
107+
<dependency>
108+
<groupId>net.azisaba</groupId>
109+
<artifactId>EnderChestPlus</artifactId>
110+
<version>1.3.1</version>
111+
<scope>provided</scope>
112+
</dependency>
113+
あなた:
114+
scopeは?
115+
116+
117+
ChatGPT:
118+
いい質問にゃ!MavenやGradleで adventure-api や adventure-platform-bukkit を使う場合、スコープ(scope or configuration)は compile または implementation にする必要があるにゃ。
119+
120+
理由は:
107121

122+
Spigot/Paper 1.16.5 環境では Adventure ライブラリが標準で含まれていないため、自分のプラグインにAdventureを内蔵する必要があるから。
123+
124+
✅ Maven の場合
125+
xml
126+
コピーする
127+
編集する
128+
<dependency>
129+
<groupId>net.kyori</groupId>
130+
<artifactId>adventure-api</artifactId>
131+
<version>4.14.0</version>
132+
<scope>compile</scope> <!-- ここ! -->
133+
</dependency>
134+
<dependency>
135+
<groupId>net.kyori</groupId>
136+
<artifactId>adventure-platform-bukkit</artifactId>
137+
<version>4.3.0</version>
138+
<scope>compile</scope>
139+
</dependency>
108140
</dependencies>
109141

110142
<distributionManagement>

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ BetterStorageは外部プラグインから `GroupData`, `InventoryData` など
5353

5454
MIT License(予定)
5555

56+
注意EnderChestPlusのimportはEnderChestPlus側の不具合で、セーブして一定時間が経過するまでデータが保存されないため使えなくした後にImportすることをお勧めします!!
57+

src/main/java/dev/felnull/DataIO/DataIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ public static InventoryData getLatestInventoryData(UUID groupUUID, String pageId
607607

608608
if (invData != null) {
609609
// データが見つかればそのまま返す
610-
Bukkit.getLogger().info("Loaded latest inventory data for pageId: " + pageId);
610+
//Bukkit.getLogger().info("Loaded latest inventory data for pageId: " + pageId);
611611
return invData;
612612
} else {
613613
// pageIdが見つからない場合

src/main/java/dev/felnull/DataIO/TableInitializer.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ public static void initTables() {
2323
"group_name VARCHAR(255) UNIQUE NOT NULL, " + // 論理名(内部参照に使う)
2424
"display_name VARCHAR(255), " + // 表示名(ユーザー向け)
2525
"is_private BOOLEAN NOT NULL, " + // 非公開グループかどうか
26-
"owner_plugin VARCHAR(255)" + // このグループを扱うプラグイン名
26+
"owner_plugin VARCHAR(255), " + // このグループを扱うプラグイン名
2727
");"
2828
);
2929

30+
3031
// グループに所属するメンバー情報
3132
stmt.executeUpdate(
3233
"CREATE TABLE IF NOT EXISTS group_member_table (" +
@@ -182,6 +183,17 @@ public static void initTables() {
182183
");"
183184
);
184185

186+
//グループデータの削除履歴
187+
stmt.executeUpdate(
188+
"CREATE TABLE IF NOT EXISTS deleted_group_history (" +
189+
"group_uuid VARCHAR(255) NOT NULL, " + // 削除対象のグループUUID
190+
"group_name VARCHAR(255), " + // グループの名前(表示用)
191+
"deletion_timestamp DATETIME NOT NULL, " + // 削除された時刻
192+
"executed_by VARCHAR(64), " + // 実行者(UUID or 名前)
193+
"PRIMARY KEY (group_uuid, deletion_timestamp)" + // 主キー制約
194+
");"
195+
);
196+
185197
LOGGER.info("[BetterStorage] 全テーブルの初期化が完了しました。");
186198

187199
} catch (SQLException e) {
@@ -271,5 +283,26 @@ private static String getTableNameFromIndex(String indexName) {
271283
}
272284
}
273285

286+
/**
287+
* 指定したテーブルに指定カラムが存在しない場合、自動で追加するにゃ。
288+
*
289+
* @param conn DB接続
290+
* @param tableName 対象テーブル名(例: "group_table")
291+
* @param columnName 追加したいカラム名(例: "ecp_imported")
292+
* @param columnDefinition カラムの定義(例: "BOOLEAN NOT NULL DEFAULT FALSE")
293+
*/
294+
private static void addColumnIfNotExists(Connection conn, String tableName, String columnName, String columnDefinition) {
295+
try (ResultSet rs = conn.getMetaData().getColumns(null, null, tableName, columnName)) {
296+
if (!rs.next()) {
297+
try (Statement stmt = conn.createStatement()) {
298+
stmt.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnName + " " + columnDefinition);
299+
LOGGER.info("[BetterStorage] " + tableName + " にカラム '" + columnName + "' を追加したにゃ!");
300+
}
301+
}
302+
} catch (SQLException e) {
303+
LOGGER.warning("[BetterStorage] " + tableName + " のカラム '" + columnName + "' チェック中にエラーが起きたにゃ: " + e.getMessage());
304+
}
305+
}
306+
274307

275308
}
Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,127 @@
11
package dev.felnull.api;
22

3+
import dev.felnull.BetterStorage;
34
import dev.felnull.Data.GroupPermENUM;
45
import dev.felnull.Data.InventoryData;
56
import dev.felnull.Data.StorageData;
7+
import jp.azisaba.lgw.ecplus.EnderChestPlus;
8+
import jp.azisaba.lgw.ecplus.InventoryLoader;
69
import org.bukkit.Bukkit;
710
import org.bukkit.Material;
811
import org.bukkit.configuration.ConfigurationSection;
912
import org.bukkit.configuration.file.YamlConfiguration;
1013
import org.bukkit.inventory.ItemStack;
14+
import org.bukkit.plugin.Plugin;
1115

1216
import java.io.File;
17+
import java.lang.reflect.Field;
18+
import java.lang.reflect.Method;
19+
import java.sql.Connection;
20+
import java.sql.PreparedStatement;
21+
import java.sql.ResultSet;
22+
import java.sql.SQLException;
1323
import java.util.*;
1424

15-
1625
public class EcpImporter {
1726

1827
public static StorageData importFromUUID(UUID playerUUID, UUID groupUUID) {
28+
try (Connection conn = BetterStorage.BSPlugin.getDatabaseManager().getConnection();
29+
PreparedStatement ps = conn.prepareStatement(
30+
"SELECT ecp_imported FROM group_table WHERE group_uuid = ?")) {
31+
ps.setString(1, groupUUID.toString());
32+
try (ResultSet rs = ps.executeQuery()) {
33+
if (rs.next() && rs.getBoolean("ecp_imported")) {
34+
Bukkit.getLogger().warning("[BetterStorage] このグループはすでにECPからインポートされていますにゃ!");
35+
return null;
36+
}
37+
}
38+
} catch (SQLException e) {
39+
throw new RuntimeException(e);
40+
}
41+
// EnderChestPlusのファイルパス
1942
File file = new File(Bukkit.getPluginManager().getPlugin("BetterStorage")
2043
.getDataFolder().getParent(), "EnderChestPlus/Inventories/" + playerUUID + ".yml");
2144

2245
if (!file.exists()) return null;
2346

24-
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
47+
YamlConfiguration config;
48+
try {
49+
config = YamlConfiguration.loadConfiguration(file);
50+
} catch (Exception ex) {
51+
Bukkit.getLogger().warning("[BetterStorage] ECPインポート時にファイルの読み込みに失敗したにゃ: " + ex.getMessage());
52+
return null;
53+
}
54+
55+
Plugin plugin = Bukkit.getPluginManager().getPlugin("EnderChestPlus");
56+
57+
if (plugin != null && plugin.isEnabled() && plugin instanceof EnderChestPlus) {
58+
EnderChestPlus ecp = (EnderChestPlus) plugin;
59+
InventoryLoader loader = ecp.getLoader();
60+
61+
if (loader != null) {
62+
loader.saveAllInventoryData(false); // false = 非同期ではない
63+
Bukkit.getLogger().info("[BetterStorage] EnderChestPlus のセーブを実行したにゃ");
64+
} else {
65+
Bukkit.getLogger().warning("[BetterStorage] EnderChestPlus の loader が null だったにゃ");
66+
}
67+
}
2568

69+
// バンク権限(ストレージ全体にアクセスするための最低限の権限)
2670
Set<String> bankPerms = new HashSet<>();
2771
bankPerms.add(GroupPermENUM.MEMBER.getPermName());
72+
73+
// ページID → InventoryData
2874
Map<String, InventoryData> inventoryMap = new HashMap<>();
2975

3076
for (String pageId : config.getKeys(false)) {
3177
ConfigurationSection pageSection = config.getConfigurationSection(pageId);
78+
if (pageSection == null) continue;
3279

3380
Map<Integer, ItemStack> itemMap = new HashMap<>();
3481
for (String slotKey : pageSection.getKeys(false)) {
35-
int slot = Integer.parseInt(slotKey);
36-
ItemStack item = pageSection.getItemStack(slotKey);
37-
if (item != null && item.getType() != Material.AIR) {
38-
itemMap.put(slot, item);
82+
try {
83+
int slot = Integer.parseInt(slotKey);
84+
if (slot < 0 || slot >= 57) continue; // スロット番号チェック追加
85+
ItemStack item = pageSection.getItemStack(slotKey);
86+
if (item != null && item.getType() != Material.AIR) {
87+
itemMap.put(slot, item);
88+
}
89+
} catch (NumberFormatException ex) {
90+
continue; // 無効なスロットキーはスキップ
3991
}
4092
}
4193

94+
// ページ権限
4295
Set<String> pagePerms = new HashSet<>();
4396
pagePerms.add(GroupPermENUM.MEMBER.getPermName());
4497

45-
InventoryData inv = new InventoryData("ECPページ #" + pageId, 57, pagePerms, itemMap);
46-
inv.addUserTag("ecp-imported");
98+
int displayPageId;
99+
try {
100+
displayPageId = Integer.parseInt(pageId);
101+
} catch (NumberFormatException ex) {
102+
displayPageId = 0; // fallback
103+
}
104+
105+
// InventoryDataを作成
106+
InventoryData inv = new InventoryData("ECPページ #" + (displayPageId + 1), 57, pagePerms, itemMap);
47107

48-
inventoryMap.put(pageId, inv);
108+
inventoryMap.put(pageId, inv); // 内部IDはそのまま(ズレ防止)
49109
}
50110

111+
// ストレージデータ構築
51112
StorageData storageData = new StorageData(bankPerms, inventoryMap, 0.0);
52113
storageData.groupUUID = groupUUID;
53114

115+
try (Connection conn = BetterStorage.BSPlugin.getDatabaseManager().getConnection();
116+
PreparedStatement ps = conn.prepareStatement(
117+
"UPDATE group_table SET ecp_imported = TRUE WHERE group_uuid = ?")) {
118+
ps.setString(1, groupUUID.toString());
119+
ps.executeUpdate();
120+
} catch (SQLException e) {
121+
throw new RuntimeException(e);
122+
}
123+
54124
return storageData;
55125
}
56-
}
126+
127+
}

src/main/java/dev/felnull/commands/BetterStorageCommand.java

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package dev.felnull.commands;
22

33
import dev.felnull.BetterStorage;
4-
import dev.felnull.Data.DeletedGroupBackup;
54
import dev.felnull.Data.DeletedGroupInfo;
65
import dev.felnull.Data.GroupData;
76
import dev.felnull.DataIO.*;
8-
import dev.felnull.task.ItemLogSummaryTask;
9-
import net.kyori.adventure.text.Component;
10-
import net.kyori.adventure.text.event.ClickEvent;
11-
import net.kyori.adventure.text.event.HoverEvent;
127
import net.kyori.adventure.text.format.NamedTextColor;
138
import org.bukkit.Bukkit;
149
import org.bukkit.ChatColor;
@@ -115,14 +110,9 @@ public void run() {
115110
sender.sendMessage("[ " + nameOrGroup + " ] のログ一覧:");
116111
for (LocalDateTime log : logs) {
117112
String formatted = log.format(FORMATTER);
118-
Component msg = Component.text(" - [ ")
119-
.append(Component.text(formatted)
120-
.color(NamedTextColor.AQUA)
121-
.clickEvent(ClickEvent.suggestCommand("/bstorage rollback " + nameOrGroup + " \"" + formatted + "\""))
122-
123-
.hoverEvent(HoverEvent.showText(Component.text("クリックでロールバックコマンドをチャット欄に入力"))))
124-
.append(Component.text(" ]"));
125-
sender.sendMessage(msg);
113+
String command = "/bstorage rollback " + nameOrGroup + " \"" + formatted + "\"";
114+
String hover = "クリックでロールバックコマンドをチャット欄に入力";
115+
ComponentUtil.sendClickableMessage(sender, formatted, command, hover);
126116
}
127117
});
128118
}
@@ -214,27 +204,19 @@ public void run() {
214204
if (combined.isEmpty()) {
215205
sender.sendMessage("ログは見つかりませんでした。");
216206
} else {
217-
sender.sendMessage(Component.text("[ " + nameOrGroup + " ] のログ一覧:").color(NamedTextColor.YELLOW));
207+
ComponentUtil.sendPlainMessage(sender, "[ " + nameOrGroup + " ] のログ一覧:", NamedTextColor.YELLOW);
218208
for (LocalDateTime log : combined) {
219209
String formatted = log.format(FORMATTER);
220210
boolean isSnapshot = snapshots.contains(log);
221211

222-
NamedTextColor color = isSnapshot ? NamedTextColor.GREEN : NamedTextColor.AQUA;
223212
String command = isSnapshot
224-
? "/bstorage rollback " + nameOrGroup + " " + formatted
225-
: "/bstorage diff " + nameOrGroup + " " + formatted;
213+
? "/bstorage rollback " + nameOrGroup + " \"" + formatted + "\""
214+
: "/bstorage diff " + nameOrGroup + " \"" + formatted + "\"";
226215
String hoverText = isSnapshot
227216
? "クリックでロールバックコマンドを入力"
228217
: "クリックで差分表示コマンドを入力";
229218

230-
Component msg = Component.text(" - [ ")
231-
.append(Component.text(formatted)
232-
.color(color)
233-
.clickEvent(ClickEvent.suggestCommand(command))
234-
.hoverEvent(HoverEvent.showText(Component.text(hoverText))))
235-
.append(Component.text(" ]"));
236-
237-
sender.sendMessage(msg);
219+
ComponentUtil.sendClickableMessage(sender, formatted, command, hoverText);
238220
}
239221
}
240222
});
@@ -386,22 +368,18 @@ public void run() {
386368
}
387369

388370
Bukkit.getScheduler().runTask(BetterStorage.BSPlugin, () -> {
389-
sender.sendMessage(Component.text("削除されたグループ一覧:").color(NamedTextColor.YELLOW));
371+
ComponentUtil.sendPlainMessage(sender, "削除されたグループ一覧:", NamedTextColor.YELLOW);
390372

391373
for (DeletedGroupInfo info : deletedGroups) {
392374
String label = info.displayName != null ? info.displayName : info.groupName;
393375
String uuid = info.groupUUID.toString();
394376
String time = info.timestamp.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
395377

396-
Component msg = Component.text(" - [ ")
397-
.append(Component.text(label + " (" + time + ")")
398-
.color(NamedTextColor.AQUA)
399-
.clickEvent(ClickEvent.suggestCommand("/bstorage recover " + uuid))
400-
.hoverEvent(HoverEvent.showText(Component.text("クリックで復元コマンドを入力"))))
401-
.append(Component.text(" ]"))
402-
.color(NamedTextColor.GRAY);
378+
String text = label + " (" + time + ")";
379+
String command = "/bstorage recover " + uuid;
380+
String hover = "クリックで復元コマンドを入力";
403381

404-
sender.sendMessage(msg);
382+
ComponentUtil.sendClickableMessage(sender, text, command, hover);
405383
}
406384
});
407385
}
@@ -575,4 +553,10 @@ public void run() {
575553
// 第3引数以降の補完は提供しない
576554
return suggestions;
577555
}
556+
557+
// 共通形式で置換するメソッド
558+
private String buildInteractiveMessage(String label, String commandHint) {
559+
return ChatColor.GRAY + " - [ " + ChatColor.AQUA + label + ChatColor.GRAY + " ] " + ChatColor.DARK_GRAY + "(「" + commandHint + "」を手動で入力してください)";
560+
}
561+
578562
}

src/main/resources/plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ main: dev.felnull.BetterStorage
44
api-version: '1.16'
55
depend:
66
- BetterGUI
7+
softdepend:
8+
- EnderChestPlus
79
commands:
810
bstorage:
911
description: BetterStorageの管理用コマンド

0 commit comments

Comments
 (0)