Uses a different method to fix the database.

https://github.com/BentoBoxWorld/BentoBox/issues/1556
This commit is contained in:
tastybento 2020-11-01 17:29:18 -08:00
parent 774b57b168
commit 916ba5d999
2 changed files with 43 additions and 20 deletions

View File

@ -1517,6 +1517,7 @@ public class IslandsManager {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
Map<UUID, Island> owners = new HashMap<>();
Map<UUID, Integer> freq = new HashMap<>();
Map<UUID, List<Island>> memberships = new HashMap<>();
handler.loadObjects()
.stream().filter(i -> i.getOwner() != null)
.filter(i -> i.getWorld().equals(world))
@ -1527,28 +1528,50 @@ public class IslandsManager {
user.sendMessage("commands.admin.team.fix.duplicate-owner" , TextVariables.NAME, plugin.getPlayers().getName(i.getOwner()));
} else {
owners.put(i.getOwner(), i);
i.getMemberSet().forEach(u ->
// Place into membership
memberships.computeIfAbsent(u, k -> new ArrayList<>()).add(i));
}
});
freq.entrySet().stream().filter(en -> en.getValue() > 1).forEach(en -> {
user.sendMessage("commands.admin.team.fix.player-has", TextVariables.NAME, plugin.getPlayers().getName(en.getKey()), TextVariables.NUMBER, String.valueOf(en.getValue()));
});
owners.entrySet().stream().forEach(en -> {
en.getValue().getMemberSet().stream()
// Filter out owners
.filter(u-> owners.containsKey(u) && !owners.get(u).equals(en.getValue()))
.forEach(u -> {
user.sendMessage("commands.admin.team.fix.member-and-owner", TextVariables.NAME, plugin.getPlayers().getName(u));
user.sendMessage("commands.admin.team.fix.member-of", "[xyz]", Util.xyz(en.getValue().getCenter().toVector()));
user.sendMessage("commands.admin.team.fix.owner-of", "[xyz]", Util.xyz(owners.get(u).getCenter().toVector()));
// Remove membership of this island
Island i = islandCache.getIslandById(en.getValue().getUniqueId());
i.removeMember(u);
// Correct island cache
islandCache.setOwner(islandCache.getIslandById(owners.get(u).getUniqueId()), u);
// Save to database
handler.saveObjectAsync(i).thenRun(() -> user.sendMessage("commands.admin.team.fix.fixed"));
// Check for players in multiple teams
memberships.entrySet().stream()
.filter(en -> en.getValue().size() > 1)
.forEach(en -> {
// Get the islands
String ownerName = plugin.getPlayers().getName(en.getKey());
user.sendMessage("commands.admin.team.fix.duplicate-member", TextVariables.NAME, ownerName);
int highestRank = 0;
Island highestIsland = null;
for (Island i : en.getValue()) {
int rankValue = i.getRank(en.getKey());
String rank = plugin.getRanksManager().getRank(rankValue);
if (rankValue > highestRank || highestIsland == null) {
highestRank = rankValue;
highestIsland = i;
}
String xyz = Util.xyz(i.getCenter().toVector());
user.sendMessage("commands.admin.team.fix.rank-on-island", TextVariables.RANK, user.getTranslation(rank), "[xyz]", xyz);
}
// Fix island ownership in cache
// Correct island cache
if (highestRank == RanksManager.OWNER_RANK) {
islandCache.setOwner(islandCache.getIslandById(highestIsland.getUniqueId()), en.getKey());
}
// Fix all the entries that are not the highest
for (Island island : en.getValue()) {
if (!island.equals(highestIsland)) {
// Get the actual island being used in the cache
Island i = islandCache.getIslandById(island.getUniqueId());
// Remove membership of this island
i.removeMember(en.getKey());
// Save to database
handler.saveObjectAsync(i).thenRun(() -> user.sendMessage("commands.admin.team.fix.fixed"));
}
}
});
});
user.sendMessage("commands.admin.team.fix.done");
r.complete(true);

View File

@ -118,11 +118,11 @@ commands:
scanning: "Scanning database..."
duplicate-owner: "&c Player owns more than one island in database: [name]"
player-has: "&c Player [name] has [number] islands"
member-and-owner: "&c Cross-membership found: Player [name] is an island owner and member"
owner-of: "&c Owner of island at [xyz]"
member-of: "&c Member of island at [xyz]"
duplicate-member: "&c Player [name] is a member of more than one island in the database"
player-has: "&c Player [name] has [number] islands"
rank-on-island: "&c [rank] on island at [xyz]"
fixed: "&a Fixed"
done: "&a Scan completed"
done: "&a Scan"
kick:
parameters: "<team player>"
description: "kick a player from a team"