Skip to content

Commit b5468f8

Browse files
committed
バックアップ部分修正完了
1 parent 670e6c8 commit b5468f8

13 files changed

+816
-269
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package dev.felnull.Data;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.OfflinePlayer;
5+
6+
import java.util.*;
7+
import java.util.stream.Collectors;
8+
9+
public class DeletedGroupBackup {
10+
public String groupName;
11+
public UUID groupUUID;
12+
public String displayName;
13+
public boolean isPrivate;
14+
public String ownerPlugin;
15+
public List<GroupMemberData> memberList; // GroupMemberData で役職を含めて管理
16+
public StorageDataBackup storageData; // GZIP+JSONで保存
17+
18+
public DeletedGroupBackup(GroupData groupData, StorageDataBackup storageData) {
19+
this.groupName = groupData.groupName;
20+
this.groupUUID = groupData.groupUUID;
21+
this.displayName = groupData.displayName;
22+
this.isPrivate = groupData.isPrivate;
23+
this.ownerPlugin = groupData.ownerPlugin;
24+
this.storageData = storageData;
25+
26+
// そのままコピー(deep copy したいなら new GroupMemberData(...) に変換してもいい)
27+
this.memberList = new ArrayList<>(groupData.playerList);
28+
}
29+
30+
31+
/** GroupData に復元する */
32+
public GroupData toGroupData() {
33+
List<GroupMemberData> members = new ArrayList<>();
34+
for (GroupMemberData m : memberList) {
35+
members.add(new GroupMemberData(m.memberUUID, m.role.clone()));
36+
}
37+
38+
StorageData sd = storageData.toStorageData(); // 復元用メソッド
39+
return new GroupData(groupName, displayName, members, isPrivate, sd, ownerPlugin, groupUUID);
40+
}
41+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package dev.felnull.Data;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.UUID;
5+
6+
public class DeletedGroupInfo {
7+
public UUID groupUUID;
8+
public String groupName;
9+
public String displayName;
10+
public LocalDateTime timestamp;
11+
12+
public DeletedGroupInfo(UUID groupUUID, String groupName, String displayName, LocalDateTime timestamp) {
13+
this.groupUUID = groupUUID;
14+
this.groupName = groupName;
15+
this.displayName = displayName;
16+
this.timestamp = timestamp;
17+
}
18+
}

src/main/java/dev/felnull/Data/GroupData.java

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,31 @@
22

33
import dev.felnull.DataIO.DataIO;
44
import dev.felnull.DataIO.GroupManager;
5+
import org.bukkit.Bukkit;
56
import org.bukkit.OfflinePlayer;
67
import org.jetbrains.annotations.NotNull;
78
import org.jetbrains.annotations.Nullable;
89

910
import java.util.*;
11+
import java.util.stream.Collectors;
1012

1113
public class GroupData {
1214
public final String groupName; // グループ名(表示用・識別用)
1315
public final UUID groupUUID; // グループ固有のUUID(内部識別子)
1416
public String displayName;
15-
public Set<OfflinePlayer> playerList; // 所属プレイヤー
16-
public Map<OfflinePlayer, String[]> playerPermission; // 役職
17+
public List<GroupMemberData> playerList; // 所属プレイヤーと役職
1718
public boolean isPrivate; // 個人グループか
1819
public StorageData storageData; // ストレージ情報
1920
public String ownerPlugin;
2021

21-
// コンストラクタ(グループ新規作成用)
22-
public GroupData(@NotNull String groupName, @NotNull String displayName, @NotNull Set<OfflinePlayer> playerList,
23-
@NotNull Map<OfflinePlayer, String[]> playerPermission, boolean isPrivate,
24-
StorageData storageData, String ownerPlugin, @Nullable UUID groupUUID) {
22+
// コンストラクタ(新規作成)
23+
public GroupData(@NotNull String groupName, @NotNull String displayName, @NotNull List<GroupMemberData> playerList,
24+
boolean isPrivate, StorageData storageData, String ownerPlugin, @Nullable UUID groupUUID) {
2525
this.groupName = groupName;
2626
this.displayName = displayName;
2727
this.playerList = playerList;
28-
this.playerPermission = playerPermission;
2928
this.isPrivate = isPrivate;
3029
this.ownerPlugin = ownerPlugin;
31-
3230
this.groupUUID = groupUUID != null ? groupUUID : UUID.randomUUID();
3331

3432
this.storageData = storageData;
@@ -38,20 +36,18 @@ public GroupData(@NotNull String groupName, @NotNull String displayName, @NotNul
3836
}
3937
}
4038

41-
// 個人用グループ生成用(UUID自動生成)
39+
// 個人用グループ作成
4240
public GroupData(@NotNull OfflinePlayer player, StorageData storageData, String ownerPlugin) {
4341
this.groupName = player.getUniqueId().toString();
4442
this.groupUUID = UUID.randomUUID();
45-
this.displayName = player.getName(); // 任意で変更可能
46-
47-
this.playerList = new HashSet<>();
48-
this.playerPermission = new HashMap<>();
49-
this.playerList.add(player);
50-
this.playerPermission.put(player, new String[]{GroupPermENUM.OWNER.getPermName()});
43+
this.displayName = player.getName();
5144
this.isPrivate = true;
5245
this.ownerPlugin = ownerPlugin;
53-
5446
this.storageData = storageData;
47+
48+
this.playerList = new ArrayList<>();
49+
this.playerList.add(new GroupMemberData(player.getUniqueId(), new String[]{ GroupPermENUM.OWNER.getPermName() }));
50+
5551
if (this.storageData != null) {
5652
this.storageData.groupUUID = this.groupUUID;
5753
this.storageData.groupData = this;
@@ -62,42 +58,61 @@ public GroupData(@NotNull OfflinePlayer player, StorageData storageData, String
6258
// === GroupManagerラッパー ===
6359
// ===============================
6460

65-
/** groupName → UUID */
6661
public static @Nullable UUID resolveUUID(String groupName) {
6762
GroupData data = DataIO.loadGroupData(groupName);
6863
return data != null ? data.groupUUID : null;
6964
}
7065

71-
/** groupUUID → groupName */
7266
public static @Nullable String resolveName(UUID groupUUID) {
7367
GroupData data = DataIO.loadGroupData(groupUUID);
7468
return data != null ? data.groupName : null;
7569
}
7670

77-
/** groupUUID → GroupData */
7871
public static @Nullable GroupData resolveByUUID(UUID groupUUID) {
7972
return DataIO.loadGroupData(groupUUID);
8073
}
8174

82-
/** groupName → GroupData */
8375
public static @Nullable GroupData resolveByName(String groupName) {
8476
return DataIO.loadGroupData(groupName);
8577
}
8678

87-
/**
88-
* 指定されたプレイヤーが所属している全 GroupData を返すラッパー(DataIOベース)。
89-
*/
9079
public static List<GroupData> getGroupsOfPlayer(OfflinePlayer player) {
9180
return DataIO.loadGroupsByPlayer(player);
9281
}
9382

9483
public GroupData deepClone(StorageData storageData) {
95-
// ここではdeepClone時に groupData は引数で渡される
96-
Set<OfflinePlayer> clonedPlayerList = new HashSet<>(this.playerList);
97-
Map<OfflinePlayer, String[]> clonedPlayerPermission = new HashMap<>(this.playerPermission);
84+
List<GroupMemberData> clonedList = this.playerList.stream()
85+
.map(gm -> new GroupMemberData(gm.memberUUID, gm.role.clone()))
86+
.collect(Collectors.toList());
87+
88+
return new GroupData(this.groupName, this.displayName, clonedList, this.isPrivate, storageData, this.ownerPlugin, this.groupUUID);
89+
}
9890

99-
return new GroupData(this.groupName, this.displayName, clonedPlayerList, clonedPlayerPermission, this.isPrivate, storageData, this.ownerPlugin, this.groupUUID);
91+
/**
92+
* 指定UUIDのプレイヤーの役職を取得(存在しない場合 null)
93+
*/
94+
public @Nullable String[] getRoles(UUID playerUUID) {
95+
for (GroupMemberData member : playerList) {
96+
if (member.memberUUID.equals(playerUUID)) {
97+
return member.role;
98+
}
99+
}
100+
return null;
100101
}
101102

103+
/**
104+
* 指定UUIDのプレイヤーがメンバーに含まれているか
105+
*/
106+
public boolean contains(UUID playerUUID) {
107+
return playerList.stream().anyMatch(m -> m.memberUUID.equals(playerUUID));
108+
}
102109

103-
}
110+
/**
111+
* OfflinePlayerのリストを取得(必要な場合のみ)
112+
*/
113+
public Set<OfflinePlayer> getOfflinePlayerSet() {
114+
return playerList.stream()
115+
.map(m -> Bukkit.getOfflinePlayer(m.memberUUID))
116+
.collect(Collectors.toSet());
117+
}
118+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dev.felnull.Data;
2+
3+
import java.util.UUID;
4+
5+
public class GroupMemberData {
6+
public UUID memberUUID;
7+
public String[] role; // ← String にしないよう注意
8+
9+
public GroupMemberData(UUID memberUUID, String[] role) {
10+
this.memberUUID = memberUUID;
11+
this.role = role;
12+
}
13+
}

src/main/java/dev/felnull/Data/GroupStorageBackup.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/dev/felnull/Data/InventoryDataBackup.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public InventoryDataBackup(InventoryData original) {
2121

2222
for (Map.Entry<Integer, ItemStack> entry : original.itemStackSlot.entrySet()) {
2323
String base64 = ItemSerializer.serializeToBase64(entry.getValue());
24-
itemStackBase64.put(entry.getKey(), base64);
24+
if (base64 != null) {
25+
itemStackBase64.put(entry.getKey(), base64);
26+
}
2527
}
2628
}
2729

0 commit comments

Comments
 (0)