Compare commits
3 Commits
56481ac6d0
...
8b15888968
Author | SHA1 | Date |
---|---|---|
tastybento | 8b15888968 | |
tastybento | 12b08aacc6 | |
tastybento | 37b43b6cc1 |
|
@ -13,6 +13,7 @@ import java.util.Objects;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -291,7 +292,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
this.world = island.getWorld();
|
||||
this.bonusRanges.addAll(island.getBonusRanges());
|
||||
this.primaries.addAll(island.getPrimaries());
|
||||
BentoBox.getInstance().logDebug("Constructor copy");
|
||||
this.setChanged();
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void addMember(@NonNull UUID playerUUID) {
|
||||
if (getRank(playerUUID) != RanksManager.MEMBER_RANK) {
|
||||
setRank(playerUUID, RanksManager.MEMBER_RANK);
|
||||
BentoBox.getInstance().logDebug("Add member");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +328,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
setRank(target, RanksManager.BANNED_RANK);
|
||||
log(new LogEntry.Builder("BAN").data("player", target.toString()).data("issuer", issuer.toString())
|
||||
.build());
|
||||
BentoBox.getInstance().logDebug("Ban");
|
||||
setChanged();
|
||||
}
|
||||
return true;
|
||||
|
@ -619,7 +617,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public int getMaxEverProtectionRange() {
|
||||
if (maxEverProtectionRange > this.getRange()) {
|
||||
maxEverProtectionRange = this.getRange();
|
||||
BentoBox.getInstance().logDebug("get max ever protect");
|
||||
setChanged();
|
||||
}
|
||||
return Math.max(this.getProtectionRange(), maxEverProtectionRange);
|
||||
|
@ -639,7 +636,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
if (maxEverProtectionRange > this.range) {
|
||||
this.maxEverProtectionRange = this.range;
|
||||
}
|
||||
BentoBox.getInstance().logDebug("setMaxEverProtectionRange");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1017,7 +1013,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void removeMember(UUID playerUUID) {
|
||||
if (members.remove(playerUUID) != null) {
|
||||
BentoBox.getInstance().logDebug("removeMember");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1029,7 +1024,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
if (this.center == null || !center.getWorld().equals(this.center.getWorld()) || !center.equals(this.center)) {
|
||||
this.world = center.getWorld();
|
||||
this.center = center;
|
||||
BentoBox.getInstance().logDebug("setCenter");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1040,7 +1034,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setCreatedDate(long createdDate) {
|
||||
if (this.createdDate != createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
BentoBox.getInstance().logDebug("setCreatedDate");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1067,7 +1060,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setFlag(Flag flag, int value, boolean doSubflags) {
|
||||
if (flags.containsKey(flag.getID()) && flags.get(flag.getID()) != value) {
|
||||
flags.put(flag.getID(), value);
|
||||
BentoBox.getInstance().logDebug("setFlag " + flag);
|
||||
setChanged();
|
||||
}
|
||||
// Subflag support
|
||||
|
@ -1082,7 +1074,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setFlags(Map<String, Integer> flags) {
|
||||
this.flags = flags;
|
||||
BentoBox.getInstance().logDebug("setFlags ");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1108,7 +1099,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setMembers(Map<UUID, Integer> members) {
|
||||
this.members = members;
|
||||
BentoBox.getInstance().logDebug("setMembers");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1122,7 +1112,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setName(String name) {
|
||||
if (name == null || !name.equals(this.name)) {
|
||||
this.name = (name != null && !name.equals("")) ? name : null;
|
||||
BentoBox.getInstance().logDebug("setName");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1149,7 +1138,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
}
|
||||
}
|
||||
setRank(owner, RanksManager.OWNER_RANK);
|
||||
BentoBox.getInstance().logDebug("setOwner");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1160,7 +1148,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
if (this.protectionRange != protectionRange) {
|
||||
this.protectionRange = protectionRange;
|
||||
this.updateMaxEverProtectionRange();
|
||||
BentoBox.getInstance().logDebug("setProtectionRange");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1196,7 +1183,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setPurgeProtected(boolean purgeProtected) {
|
||||
if (this.purgeProtected != purgeProtected) {
|
||||
this.purgeProtected = purgeProtected;
|
||||
BentoBox.getInstance().logDebug("setPurgeProtected");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1214,7 +1200,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setRange(int range) {
|
||||
if (this.range != range) {
|
||||
this.range = range;
|
||||
BentoBox.getInstance().logDebug("setRange");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1237,26 +1222,38 @@ public class Island implements DataObject, MetaDataAble {
|
|||
* @param rank rank value
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setRank(@Nullable UUID uuid, int rank) {
|
||||
public void setRank(@Nullable UUID uuid, int newRank) {
|
||||
// Early return if the UUID is null, to avoid unnecessary processing.
|
||||
if (uuid == null) {
|
||||
return; // Defensive code
|
||||
return;
|
||||
}
|
||||
members.compute(uuid, (key, value) -> {
|
||||
if (value == null || !value.equals(rank)) {
|
||||
setChanged(); // Call setChanged only if the value is updated.
|
||||
BentoBox.getInstance().logDebug("Set rank for " + uuid + " to " + rank);
|
||||
return rank;
|
||||
|
||||
// Use an AtomicBoolean to track if the member's rank has been changed.
|
||||
AtomicBoolean isRankChanged = new AtomicBoolean(false);
|
||||
|
||||
// Attempt to update the member's rank, if necessary.
|
||||
members.compute(uuid, (key, existingRank) -> {
|
||||
// If the member does not exist or their rank is different, update the rank.
|
||||
if (existingRank == null || existingRank != newRank) {
|
||||
isRankChanged.set(true);
|
||||
return newRank; // Update the rank.
|
||||
}
|
||||
return value;
|
||||
// No change needed; return the existing rank.
|
||||
return existingRank;
|
||||
});
|
||||
|
||||
// If the rank was changed, notify the change and log the update.
|
||||
if (isRankChanged.get()) {
|
||||
setChanged(); // Notify that a change has occurred.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ranks the ranks to set
|
||||
*/
|
||||
public void setRanks(Map<UUID, Integer> ranks) {
|
||||
members = ranks;
|
||||
BentoBox.getInstance().logDebug("setRanks");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1281,7 +1278,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
setFlag(Flags.LOCK, RanksManager.VISITOR_RANK);
|
||||
}
|
||||
log(new LogEntry.Builder("SPAWN").data("value", String.valueOf(isSpawn)).build());
|
||||
BentoBox.getInstance().logDebug("setSpawn");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1303,7 +1299,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setSpawnPoint(Map<Environment, Location> spawnPoint) {
|
||||
this.spawnPoint = spawnPoint;
|
||||
BentoBox.getInstance().logDebug("setSpawnPoint");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1324,7 +1319,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
BentoBox.getInstance().logDebug("setWorld");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1349,7 +1343,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
if (flag.getType().equals(Flag.Type.SETTING) || flag.getType().equals(Flag.Type.WORLD_SETTING)) {
|
||||
setSettingsFlag(flag, newToggleValue, doSubflags);
|
||||
}
|
||||
BentoBox.getInstance().logDebug("toggleFlag " + flag);
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1381,7 +1374,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
flag.getSubflags().forEach(subflag -> setSettingsFlag(subflag, state, true));
|
||||
}
|
||||
}
|
||||
BentoBox.getInstance().logDebug("setSettingsFlag " + flag);
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1419,7 +1411,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void removeRank(Integer rank) {
|
||||
if (members.values().removeIf(rank::equals)) {
|
||||
BentoBox.getInstance().logDebug("removeRank");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1440,7 +1431,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void log(LogEntry logEntry) {
|
||||
history.add(logEntry);
|
||||
BentoBox.getInstance().logDebug("log");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1451,7 +1441,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setHistory(List<LogEntry> history) {
|
||||
this.history = history;
|
||||
BentoBox.getInstance().logDebug("setHistory");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1467,7 +1456,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setDoNotLoad(boolean doNotLoad) {
|
||||
this.doNotLoad = doNotLoad;
|
||||
BentoBox.getInstance().logDebug("setDoNotLoad");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1483,7 +1471,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
BentoBox.getInstance().logDebug("setDeleted");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1574,7 +1561,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
return true;
|
||||
}
|
||||
if (cooldowns.remove(flag.getID()) != null) {
|
||||
BentoBox.getInstance().logDebug("isCooldown");
|
||||
setChanged();
|
||||
}
|
||||
return false;
|
||||
|
@ -1587,7 +1573,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setCooldown(Flag flag) {
|
||||
cooldowns.put(flag.getID(), flag.getCooldown() * 1000L + System.currentTimeMillis());
|
||||
BentoBox.getInstance().logDebug("setCooldown");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1603,7 +1588,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setCooldowns(Map<String, Long> cooldowns) {
|
||||
this.cooldowns = cooldowns;
|
||||
BentoBox.getInstance().logDebug("setCooldowns");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1619,7 +1603,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setCommandRanks(Map<String, Integer> commandRanks) {
|
||||
this.commandRanks = commandRanks;
|
||||
BentoBox.getInstance().logDebug("setCommandRanks");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1691,7 +1674,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setReserved(boolean reserved) {
|
||||
if (this.reserved != reserved) {
|
||||
this.reserved = reserved;
|
||||
BentoBox.getInstance().logDebug("setReserved");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1715,7 +1697,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
@Override
|
||||
public void setMetaData(Map<String, MetaDataValue> metaData) {
|
||||
this.metaData = metaData;
|
||||
BentoBox.getInstance().logDebug("setMetaData");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1771,7 +1752,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
}
|
||||
this.location = location;
|
||||
this.updateMaxEverProtectionRange();
|
||||
BentoBox.getInstance().logDebug("setProtectionCenter");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1830,7 +1810,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
}
|
||||
}
|
||||
getHomes().put(name.toLowerCase(), location);
|
||||
BentoBox.getInstance().logDebug("addHome");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1901,7 +1880,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setMaxHomes(@Nullable Integer maxHomes) {
|
||||
if (this.maxHomes != maxHomes) {
|
||||
this.maxHomes = maxHomes;
|
||||
BentoBox.getInstance().logDebug("setMaxHomes");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1924,7 +1902,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setMaxMembers(Map<Integer, Integer> maxMembers) {
|
||||
if (this.maxMembers != maxMembers) {
|
||||
this.maxMembers = maxMembers;
|
||||
BentoBox.getInstance().logDebug("setMaxMembers");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1975,7 +1952,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setBonusRanges(List<BonusRangeRecord> bonusRanges) {
|
||||
this.bonusRanges = bonusRanges;
|
||||
BentoBox.getInstance().logDebug("setBonusRanges");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -2012,7 +1988,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void addBonusRange(String id, int range, String message) {
|
||||
this.getBonusRanges().add(new BonusRangeRecord(id, range, message));
|
||||
setMaxEverProtectionRange(this.getProtectionRange());
|
||||
BentoBox.getInstance().logDebug("addBonusRange");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -2023,7 +1998,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void clearBonusRange(String id) {
|
||||
if (this.getBonusRanges().removeIf(r -> r.getUniqueId().equals(id))) {
|
||||
BentoBox.getInstance().logDebug("clearBonusRange");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -2033,7 +2007,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void clearAllBonusRanges() {
|
||||
this.getBonusRanges().clear();
|
||||
BentoBox.getInstance().logDebug("clearAllBonusRanges");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -2050,7 +2023,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setPrimary(UUID userID) {
|
||||
if (getPrimaries().add(userID)) {
|
||||
BentoBox.getInstance().logDebug("setPrimary");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -2061,7 +2033,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void removePrimary(UUID userID) {
|
||||
if (getPrimaries().remove(userID)) {
|
||||
BentoBox.getInstance().logDebug("removePrimary");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -2118,7 +2089,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setPrimaries(Set<UUID> primaries) {
|
||||
this.primaries = primaries;
|
||||
BentoBox.getInstance().logDebug("setPrimaries");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -2127,9 +2097,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
return Objects.hash(uniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Islands are equal if they have the same uniqueId
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
|
@ -2142,4 +2109,5 @@ public class Island implements DataObject, MetaDataAble {
|
|||
return Objects.equals(uniqueId, other.uniqueId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -119,14 +119,6 @@ public class IslandsManager {
|
|||
islandCache.addIsland(island);
|
||||
}
|
||||
});
|
||||
// Remove islands
|
||||
MultiLib.onString(plugin, "bentobox-deleteIsland", id -> {
|
||||
BentoBox.getInstance().logDebug("Delete island " + id);
|
||||
Island island = handler.loadObject(id);
|
||||
if (island != null) {
|
||||
islandCache.removeIsland(island);
|
||||
}
|
||||
});
|
||||
// Set or clear spawn
|
||||
MultiLib.onString(plugin, "bentobox-setspawn", sp -> {
|
||||
String[] split = sp.split(",");
|
||||
|
@ -275,6 +267,7 @@ public class IslandsManager {
|
|||
* @param involvedPlayer - player related to the island deletion, if any
|
||||
*/
|
||||
public void deleteIsland(@NonNull Island island, boolean removeBlocks, @Nullable UUID involvedPlayer) {
|
||||
BentoBox.getInstance().logDebug("Deleting island " + island.getUniqueId() + " remove blocks = " + removeBlocks);
|
||||
// Fire event
|
||||
IslandBaseEvent event = IslandEvent.builder().island(island).involvedPlayer(involvedPlayer)
|
||||
.reason(Reason.DELETE).build();
|
||||
|
@ -284,19 +277,18 @@ public class IslandsManager {
|
|||
// Set the owner of the island to no one.
|
||||
island.setOwner(null);
|
||||
island.setFlag(Flags.LOCK, RanksManager.VISITOR_RANK);
|
||||
island.setDeleted(true);
|
||||
if (removeBlocks) {
|
||||
// Remove island from the cache
|
||||
islandCache.deleteIslandFromCache(island);
|
||||
// Delete the island
|
||||
handler.deleteObject(island);
|
||||
// Inform other servers
|
||||
MultiLib.notify("bentobox-deletedIsland", island.getUniqueId());
|
||||
// Remove players from island
|
||||
removePlayersFromIsland(island);
|
||||
if (!plugin.getSettings().isKeepPreviousIslandOnReset()) {
|
||||
// Remove blocks from world
|
||||
plugin.getIslandDeletionManager().getIslandChunkDeletionManager().add(new IslandDeletion(island));
|
||||
}
|
||||
// Delete the island from the database
|
||||
handler.deleteObject(island);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -508,7 +500,6 @@ public class IslandsManager {
|
|||
if (island.getOwner() == null) {
|
||||
// No owner, no rank settings
|
||||
island.setMaxMembers(null);
|
||||
BentoBox.getInstance().logDebug("getMaxMembers no owner, no rank settings");
|
||||
updateIsland(island);
|
||||
return 0;
|
||||
}
|
||||
|
@ -533,7 +524,6 @@ public class IslandsManager {
|
|||
Integer change = islandMax == worldDefault ? null : islandMax;
|
||||
if (island.getMaxMembers().get(rank) != change) {
|
||||
island.setMaxMembers(rank, change);
|
||||
BentoBox.getInstance().logDebug("getMaxMembers");
|
||||
updateIsland(island);
|
||||
}
|
||||
return islandMax;
|
||||
|
@ -576,7 +566,6 @@ public class IslandsManager {
|
|||
Integer change = islandMax == plugin.getIWM().getMaxHomes(island.getWorld()) ? null : islandMax;
|
||||
if (island.getMaxHomes() != change) {
|
||||
island.setMaxHomes(change);
|
||||
BentoBox.getInstance().logDebug("getMaxHomes");
|
||||
updateIsland(island);
|
||||
}
|
||||
return islandMax;
|
||||
|
@ -768,7 +757,6 @@ public class IslandsManager {
|
|||
public boolean setHomeLocation(@Nullable Island island, Location location, String name) {
|
||||
if (island != null && (island.getHome(name) == null || !island.getHome(name).equals(location))) {
|
||||
island.addHome(name, location);
|
||||
BentoBox.getInstance().logDebug("setHomeLocation");
|
||||
updateIsland(island);
|
||||
return true;
|
||||
}
|
||||
|
@ -1480,7 +1468,6 @@ public class IslandsManager {
|
|||
teamIsland.addMember(playerUUID);
|
||||
islandCache.addPlayer(playerUUID, teamIsland);
|
||||
// Save the island
|
||||
BentoBox.getInstance().logDebug("setJoinTeam");
|
||||
updateIsland(teamIsland);
|
||||
}
|
||||
|
||||
|
@ -1629,7 +1616,6 @@ public class IslandsManager {
|
|||
island.clearChanged();
|
||||
handler.saveObjectAsync(island)
|
||||
.thenAccept(b -> MultiLib.notify("bentobox-updateIsland", island.getUniqueId()));
|
||||
BentoBox.getInstance().logDebug("Saved island " + island.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -56,23 +57,149 @@ public class IslandCache {
|
|||
|
||||
/**
|
||||
* Replace the island we have with this one
|
||||
* @param island island
|
||||
* @param newIsland island
|
||||
*/
|
||||
public void updateIsland(@NonNull Island island) {
|
||||
if (islandsByLocation.put(island.getCenter(), island) == null) {
|
||||
BentoBox.getInstance().logDebug("islandsByLocation failed to update");
|
||||
public void updateIsland(@NonNull Island newIsland) {
|
||||
if (newIsland.isDeleted()) {
|
||||
this.deleteIslandFromCache(newIsland);
|
||||
return;
|
||||
}
|
||||
if (islandsById.put(island.getUniqueId(), island) == null) {
|
||||
BentoBox.getInstance().logDebug("islandsById failed to update");
|
||||
// Get the old island
|
||||
Island oldIsland = islandsById.get(newIsland.getUniqueId());
|
||||
compareIslands(oldIsland, newIsland);
|
||||
Set<UUID> newMembers = newIsland.getMembers().keySet();
|
||||
if (oldIsland != null) {
|
||||
Set<UUID> oldMembers = oldIsland.getMembers().keySet();
|
||||
// Remove any members who are not in the new island
|
||||
for (UUID oldMember : oldMembers) {
|
||||
if (!newMembers.contains(oldMember)) {
|
||||
// Member has been removed - remove island
|
||||
islandsByUUID.computeIfAbsent(oldMember, k -> new HashSet<>()).remove(oldIsland);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Update the members with the new island object
|
||||
for (UUID newMember : newMembers) {
|
||||
Set<Island> set = islandsByUUID.computeIfAbsent(newMember, k -> new HashSet<>());
|
||||
set.remove(oldIsland);
|
||||
set.add(newIsland);
|
||||
islandsByUUID.put(newMember, set);
|
||||
}
|
||||
|
||||
// Only add islands to this map if they are owned
|
||||
if (island.getOwner() != null) {
|
||||
Set<Island> set = islandsByUUID.computeIfAbsent(island.getOwner(), k -> new HashSet<>());
|
||||
if (!set.remove(island)) {
|
||||
BentoBox.getInstance().logDebug("islandsByUUID failed to remove");
|
||||
}
|
||||
set.add(island);
|
||||
if (islandsByLocation.put(newIsland.getCenter(), newIsland) == null) {
|
||||
BentoBox.getInstance().logError("islandsByLocation failed to update");
|
||||
|
||||
}
|
||||
if (islandsById.put(newIsland.getUniqueId(), newIsland) == null) {
|
||||
BentoBox.getInstance().logError("islandsById failed to update");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void compareIslands(Island island1, Island island2) {
|
||||
if (island1 == null || island2 == null) {
|
||||
BentoBox.getInstance().logDebug("One or both islands are null. Cannot compare.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!island1.getUniqueId().equals(island2.getUniqueId())) {
|
||||
BentoBox.getInstance().logDebug("Island unique IDs are different.");
|
||||
}
|
||||
|
||||
if (island1.isDeleted() != island2.isDeleted()) {
|
||||
BentoBox.getInstance().logDebug("Island deleted states are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getCenter(), island2.getCenter())) {
|
||||
BentoBox.getInstance().logDebug("Island centers are different.");
|
||||
}
|
||||
|
||||
if (island1.getRange() != island2.getRange()) {
|
||||
BentoBox.getInstance().logDebug("Island ranges are different.");
|
||||
}
|
||||
|
||||
if (island1.getProtectionRange() != island2.getProtectionRange()) {
|
||||
BentoBox.getInstance().logDebug("Island protection ranges are different.");
|
||||
}
|
||||
|
||||
if (!island1.getBonusRanges().equals(island2.getBonusRanges())) {
|
||||
BentoBox.getInstance().logDebug("Island bonus ranges are different.");
|
||||
}
|
||||
|
||||
if (island1.getMaxEverProtectionRange() != island2.getMaxEverProtectionRange()) {
|
||||
BentoBox.getInstance().logDebug("Island max ever protection ranges are different.");
|
||||
}
|
||||
|
||||
if (!island1.getWorld().equals(island2.getWorld())) {
|
||||
BentoBox.getInstance().logDebug("Island worlds are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getGameMode(), island2.getGameMode())) {
|
||||
BentoBox.getInstance().logDebug("Island game modes are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getName(), island2.getName())) {
|
||||
BentoBox.getInstance().logDebug("Island names are different.");
|
||||
}
|
||||
|
||||
if (island1.getCreatedDate() != island2.getCreatedDate()) {
|
||||
BentoBox.getInstance().logDebug("Island created dates are different.");
|
||||
}
|
||||
|
||||
if (island1.getUpdatedDate() != island2.getUpdatedDate()) {
|
||||
BentoBox.getInstance().logDebug("Island updated dates are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getOwner(), island2.getOwner())) {
|
||||
BentoBox.getInstance().logDebug("Island owners are different.");
|
||||
}
|
||||
|
||||
if (!island1.getMembers().equals(island2.getMembers())) {
|
||||
BentoBox.getInstance().logDebug("Island members are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getMaxMembers(), island2.getMaxMembers())) {
|
||||
BentoBox.getInstance().logDebug("Island max members are different.");
|
||||
}
|
||||
|
||||
if (island1.isSpawn() != island2.isSpawn()) {
|
||||
BentoBox.getInstance().logDebug("Island spawn states are different.");
|
||||
}
|
||||
|
||||
if (!island1.getFlags().equals(island2.getFlags())) {
|
||||
BentoBox.getInstance().logDebug("Island flags are different.");
|
||||
}
|
||||
|
||||
if (!island1.getHistory().equals(island2.getHistory())) {
|
||||
BentoBox.getInstance().logDebug("Island histories are different.");
|
||||
}
|
||||
|
||||
if (!island1.getSpawnPoint().equals(island2.getSpawnPoint())) {
|
||||
BentoBox.getInstance().logDebug("Island spawn points are different.");
|
||||
}
|
||||
|
||||
if (island1.isDoNotLoad() != island2.isDoNotLoad()) {
|
||||
BentoBox.getInstance().logDebug("Island do not load states are different.");
|
||||
}
|
||||
|
||||
if (!island1.getCooldowns().equals(island2.getCooldowns())) {
|
||||
BentoBox.getInstance().logDebug("Island cooldowns are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getCommandRanks(), island2.getCommandRanks())) {
|
||||
BentoBox.getInstance().logDebug("Island command ranks are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getMetaData(), island2.getMetaData())) {
|
||||
BentoBox.getInstance().logDebug("Island metadata are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getHomes(), island2.getHomes())) {
|
||||
BentoBox.getInstance().logDebug("Island homes are different.");
|
||||
}
|
||||
|
||||
if (!Objects.equals(island1.getMaxHomes(), island2.getMaxHomes())) {
|
||||
BentoBox.getInstance().logDebug("Island max homes are different.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,6 +261,7 @@ public class IslandCache {
|
|||
*/
|
||||
public boolean deleteIslandFromCache(@NonNull Island island) {
|
||||
if (!islandsByLocation.remove(island.getCenter(), island)) {
|
||||
// Already deleted
|
||||
return false;
|
||||
}
|
||||
islandsById.remove(island.getUniqueId());
|
||||
|
@ -402,27 +530,6 @@ public class IslandCache {
|
|||
return islandsById.get(uniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an island from the cache completely without altering the island
|
||||
* object
|
||||
*
|
||||
* @param island - island to remove
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public void removeIsland(@NonNull Island island) {
|
||||
islandsByLocation.values().removeIf(island::equals);
|
||||
islandsById.values().removeIf(island::equals);
|
||||
islandsByUUID.values().forEach(s -> s.removeIf(island::equals));
|
||||
World w = Util.getWorld(island.getWorld());
|
||||
if (w == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (grids.containsKey(w)) {
|
||||
grids.get(w).removeFromGrid(island);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all islands in this game mode to default flag settings
|
||||
*
|
||||
|
|
|
@ -3,7 +3,6 @@ package world.bentobox.bentobox.managers.island;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
/**
|
||||
|
@ -34,10 +33,8 @@ class IslandGrid {
|
|||
TreeMap<Integer, String> zEntry = grid.get(island.getMinX());
|
||||
if (zEntry.containsKey(island.getMinZ())) {
|
||||
if (island.getUniqueId().equals(zEntry.get(island.getMinZ()))) {
|
||||
BentoBox.getInstance().logDebug("I already know about this island");
|
||||
return true;
|
||||
}
|
||||
BentoBox.getInstance().logDebug("Overlapping island");
|
||||
return false;
|
||||
} else {
|
||||
// Add island
|
||||
|
@ -59,31 +56,23 @@ class IslandGrid {
|
|||
* @return true if island existed and was deleted, false if there was nothing to delete
|
||||
*/
|
||||
public boolean removeFromGrid(Island island) {
|
||||
// Remove from grid
|
||||
if (island != null) {
|
||||
int x = island.getMinX();
|
||||
int z = island.getMinZ();
|
||||
if (grid.containsKey(x)) {
|
||||
TreeMap<Integer, String> zEntry = grid.get(x);
|
||||
if (zEntry.containsKey(z)) {
|
||||
// Island exists - delete it
|
||||
zEntry.remove(z);
|
||||
grid.put(x, zEntry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
String id = island.getUniqueId();
|
||||
boolean removed = grid.values().stream()
|
||||
.anyMatch(innerMap -> innerMap.values().removeIf(innerValue -> innerValue.equals(id)));
|
||||
|
||||
grid.values().removeIf(TreeMap::isEmpty);
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the island located at the specified x and z coordinates, covering both the protected area
|
||||
* and the full island space. Returns null if no island exists at the given location.
|
||||
*
|
||||
* @param x the x coordinate of the location
|
||||
* @param z the z coordinate of the location
|
||||
* @return the Island at the specified location, or null if no island is found
|
||||
*/
|
||||
* Retrieves the island located at the specified x and z coordinates, covering both the protected area
|
||||
* and the full island space. Returns null if no island exists at the given location.
|
||||
*
|
||||
* @param x the x coordinate of the location
|
||||
* @param z the z coordinate of the location
|
||||
* @return the Island at the specified location, or null if no island is found
|
||||
*/
|
||||
public Island getIslandAt(int x, int z) {
|
||||
// Attempt to find the closest x-coordinate entry that does not exceed 'x'
|
||||
Entry<Integer, TreeMap<Integer, String>> xEntry = grid.floorEntry(x);
|
||||
|
|
|
@ -19,6 +19,7 @@ import world.bentobox.bentobox.api.events.island.IslandResetEvent;
|
|||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.BlueprintsManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
|
||||
/**
|
||||
* Create and paste a new island
|
||||
|
@ -216,8 +217,9 @@ public class NewIsland {
|
|||
island.setFlagsDefaults();
|
||||
// Register metrics
|
||||
plugin.getMetrics().ifPresent(BStats::increaseIslandsCreatedCount);
|
||||
plugin.getIslands();
|
||||
// Save island
|
||||
plugin.getIslands().updateIsland(island);
|
||||
IslandsManager.updateIsland(island);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue