Compare commits
13 Commits
f81185a6ab
...
56481ac6d0
Author | SHA1 | Date |
---|---|---|
tastybento | 56481ac6d0 | |
tastybento | 3de0ff236e | |
tastybento | 29507fd3d9 | |
tastybento | ba6a4d5b9c | |
tastybento | c3e25bec3f | |
tastybento | c86eb6a19c | |
tastybento | a7aeed08fd | |
tastybento | e7055c6cba | |
tastybento | c4feb5b52f | |
tastybento | 29be58da5d | |
tastybento | 9baaa0dc1a | |
tastybento | 5834dcbb59 | |
tastybento | c3142f68fd |
2
pom.xml
2
pom.xml
|
@ -88,7 +88,7 @@
|
|||
<!-- Do not change unless you want different name for local builds. -->
|
||||
<build.number>-LOCAL</build.number>
|
||||
<!-- This allows to change between versions. -->
|
||||
<build.version>2.3.0</build.version>
|
||||
<build.version>2.3.0-mp</build.version>
|
||||
<sonar.organization>bentobox-world</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
<server.jars>${project.basedir}/lib</server.jars>
|
||||
|
|
|
@ -95,7 +95,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
|||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
Island oldIsland = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID)); // Should never be
|
||||
Island oldIsland = Objects.requireNonNull(getIslands().getIsland(getWorld(), user)); // Should never be
|
||||
// null because of
|
||||
// checks above
|
||||
// Fire event
|
||||
|
@ -108,7 +108,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
|||
getAddon().getDescription().getName(), TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME,
|
||||
user.getDisplayName());
|
||||
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
getIslands().removePlayer(oldIsland, targetUUID);
|
||||
// Clean the target player
|
||||
getPlayers().cleanLeavingPlayer(getWorld(), target, true, oldIsland);
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import world.bentobox.bentobox.api.user.User;
|
|||
import world.bentobox.bentobox.database.objects.adapters.Adapter;
|
||||
import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Pair;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
@ -290,6 +291,7 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -306,6 +308,7 @@ 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();
|
||||
}
|
||||
}
|
||||
|
@ -326,6 +329,7 @@ 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;
|
||||
|
@ -615,6 +619,7 @@ 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);
|
||||
|
@ -634,6 +639,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
if (maxEverProtectionRange > this.range) {
|
||||
this.maxEverProtectionRange = this.range;
|
||||
}
|
||||
BentoBox.getInstance().logDebug("setMaxEverProtectionRange");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1011,6 +1017,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void removeMember(UUID playerUUID) {
|
||||
if (members.remove(playerUUID) != null) {
|
||||
BentoBox.getInstance().logDebug("removeMember");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1019,9 +1026,10 @@ public class Island implements DataObject, MetaDataAble {
|
|||
* @param center the center to set
|
||||
*/
|
||||
public void setCenter(@NonNull Location center) {
|
||||
if (!center.getWorld().equals(this.center.getWorld()) || !center.equals(this.center)) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -1032,6 +1040,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setCreatedDate(long createdDate) {
|
||||
if (this.createdDate != createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
BentoBox.getInstance().logDebug("setCreatedDate");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1058,6 +1067,7 @@ 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
|
||||
|
@ -1072,6 +1082,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setFlags(Map<String, Integer> flags) {
|
||||
this.flags = flags;
|
||||
BentoBox.getInstance().logDebug("setFlags ");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1090,7 +1101,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
.forEach(f -> result.put(f.getID(),
|
||||
plugin.getIWM().getDefaultIslandSettings(world).getOrDefault(f, f.getDefaultRank())));
|
||||
this.setFlags(result);
|
||||
setChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1098,6 +1108,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setMembers(Map<UUID, Integer> members) {
|
||||
this.members = members;
|
||||
BentoBox.getInstance().logDebug("setMembers");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1111,6 +1122,7 @@ 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();
|
||||
}
|
||||
}
|
||||
|
@ -1137,6 +1149,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
}
|
||||
}
|
||||
setRank(owner, RanksManager.OWNER_RANK);
|
||||
BentoBox.getInstance().logDebug("setOwner");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1147,6 +1160,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
if (this.protectionRange != protectionRange) {
|
||||
this.protectionRange = protectionRange;
|
||||
this.updateMaxEverProtectionRange();
|
||||
BentoBox.getInstance().logDebug("setProtectionRange");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1182,6 +1196,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setPurgeProtected(boolean purgeProtected) {
|
||||
if (this.purgeProtected != purgeProtected) {
|
||||
this.purgeProtected = purgeProtected;
|
||||
BentoBox.getInstance().logDebug("setPurgeProtected");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1199,6 +1214,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setRange(int range) {
|
||||
if (this.range != range) {
|
||||
this.range = range;
|
||||
BentoBox.getInstance().logDebug("setRange");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1240,6 +1256,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setRanks(Map<UUID, Integer> ranks) {
|
||||
members = ranks;
|
||||
BentoBox.getInstance().logDebug("setRanks");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1264,6 +1281,7 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -1285,6 +1303,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setSpawnPoint(Map<Environment, Location> spawnPoint) {
|
||||
this.spawnPoint = spawnPoint;
|
||||
BentoBox.getInstance().logDebug("setSpawnPoint");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1305,6 +1324,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
BentoBox.getInstance().logDebug("setWorld");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1329,6 +1349,7 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -1360,6 +1381,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
flag.getSubflags().forEach(subflag -> setSettingsFlag(subflag, state, true));
|
||||
}
|
||||
}
|
||||
BentoBox.getInstance().logDebug("setSettingsFlag " + flag);
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1397,6 +1419,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void removeRank(Integer rank) {
|
||||
if (members.values().removeIf(rank::equals)) {
|
||||
BentoBox.getInstance().logDebug("removeRank");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1417,6 +1440,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void log(LogEntry logEntry) {
|
||||
history.add(logEntry);
|
||||
BentoBox.getInstance().logDebug("log");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1427,6 +1451,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setHistory(List<LogEntry> history) {
|
||||
this.history = history;
|
||||
BentoBox.getInstance().logDebug("setHistory");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1442,6 +1467,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setDoNotLoad(boolean doNotLoad) {
|
||||
this.doNotLoad = doNotLoad;
|
||||
BentoBox.getInstance().logDebug("setDoNotLoad");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1457,6 +1483,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
BentoBox.getInstance().logDebug("setDeleted");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1546,8 +1573,10 @@ public class Island implements DataObject, MetaDataAble {
|
|||
if (cooldowns.containsKey(flag.getID()) && cooldowns.get(flag.getID()) > System.currentTimeMillis()) {
|
||||
return true;
|
||||
}
|
||||
cooldowns.remove(flag.getID());
|
||||
setChanged();
|
||||
if (cooldowns.remove(flag.getID()) != null) {
|
||||
BentoBox.getInstance().logDebug("isCooldown");
|
||||
setChanged();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1558,6 +1587,7 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -1573,6 +1603,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setCooldowns(Map<String, Long> cooldowns) {
|
||||
this.cooldowns = cooldowns;
|
||||
BentoBox.getInstance().logDebug("setCooldowns");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1588,6 +1619,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setCommandRanks(Map<String, Integer> commandRanks) {
|
||||
this.commandRanks = commandRanks;
|
||||
BentoBox.getInstance().logDebug("setCommandRanks");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1659,6 +1691,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setReserved(boolean reserved) {
|
||||
if (this.reserved != reserved) {
|
||||
this.reserved = reserved;
|
||||
BentoBox.getInstance().logDebug("setReserved");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1682,6 +1715,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
@Override
|
||||
public void setMetaData(Map<String, MetaDataValue> metaData) {
|
||||
this.metaData = metaData;
|
||||
BentoBox.getInstance().logDebug("setMetaData");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1698,7 +1732,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setChanged() {
|
||||
this.setUpdatedDate(System.currentTimeMillis());
|
||||
this.changed = true;
|
||||
//IslandsManager.updateIsland(this);
|
||||
IslandsManager.updateIsland(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1737,6 +1771,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
}
|
||||
this.location = location;
|
||||
this.updateMaxEverProtectionRange();
|
||||
BentoBox.getInstance().logDebug("setProtectionCenter");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1795,6 +1830,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
}
|
||||
}
|
||||
getHomes().put(name.toLowerCase(), location);
|
||||
BentoBox.getInstance().logDebug("addHome");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1865,6 +1901,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setMaxHomes(@Nullable Integer maxHomes) {
|
||||
if (this.maxHomes != maxHomes) {
|
||||
this.maxHomes = maxHomes;
|
||||
BentoBox.getInstance().logDebug("setMaxHomes");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -1887,6 +1924,7 @@ 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();
|
||||
}
|
||||
}
|
||||
|
@ -1937,6 +1975,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setBonusRanges(List<BonusRangeRecord> bonusRanges) {
|
||||
this.bonusRanges = bonusRanges;
|
||||
BentoBox.getInstance().logDebug("setBonusRanges");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -1973,6 +2012,7 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -1983,6 +2023,7 @@ 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();
|
||||
}
|
||||
}
|
||||
|
@ -1992,6 +2033,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void clearAllBonusRanges() {
|
||||
this.getBonusRanges().clear();
|
||||
BentoBox.getInstance().logDebug("clearAllBonusRanges");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -2008,6 +2050,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setPrimary(UUID userID) {
|
||||
if (getPrimaries().add(userID)) {
|
||||
BentoBox.getInstance().logDebug("setPrimary");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -2018,6 +2061,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void removePrimary(UUID userID) {
|
||||
if (getPrimaries().remove(userID)) {
|
||||
BentoBox.getInstance().logDebug("removePrimary");
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -2074,5 +2118,28 @@ public class Island implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public void setPrimaries(Set<UUID> primaries) {
|
||||
this.primaries = primaries;
|
||||
BentoBox.getInstance().logDebug("setPrimaries");
|
||||
setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(uniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Islands are equal if they have the same uniqueId
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Island other = (Island) obj;
|
||||
return Objects.equals(uniqueId, other.uniqueId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,15 +54,25 @@ public class IslandCache {
|
|||
grids = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the island we have with this one
|
||||
* @param island island
|
||||
*/
|
||||
public void updateIsland(@NonNull Island island) {
|
||||
if (island.getCenter() != null || island.getWorld() != null) {
|
||||
islandsByLocation.put(island.getCenter(), island);
|
||||
islandsById.put(island.getUniqueId(), island);
|
||||
// Only add islands to this map if they are owned
|
||||
if (island.isOwned()) {
|
||||
islandsByUUID.computeIfAbsent(island.getOwner(), k -> new HashSet<>()).add(island);
|
||||
island.getMemberSet().forEach(member -> addPlayer(member, island));
|
||||
if (islandsByLocation.put(island.getCenter(), island) == null) {
|
||||
BentoBox.getInstance().logDebug("islandsByLocation failed to update");
|
||||
}
|
||||
if (islandsById.put(island.getUniqueId(), island) == null) {
|
||||
BentoBox.getInstance().logDebug("islandsById failed to update");
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +117,7 @@ public class IslandCache {
|
|||
* @return true if successfully added, false if not
|
||||
*/
|
||||
private boolean addToGrid(@NonNull Island newIsland) {
|
||||
return grids.computeIfAbsent(newIsland.getWorld(), k -> new IslandGrid()).addToGrid(newIsland);
|
||||
return grids.computeIfAbsent(newIsland.getWorld(), k -> new IslandGrid(this)).addToGrid(newIsland);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
@ -220,8 +230,13 @@ public class IslandCache {
|
|||
* @param island island to make primary
|
||||
*/
|
||||
public void setPrimaryIsland(@NonNull UUID uuid, @NonNull Island island) {
|
||||
if (island.getPrimaries().contains(uuid)) {
|
||||
return;
|
||||
}
|
||||
for (Island is : getIslands(island.getWorld(), uuid)) {
|
||||
is.removePrimary(uuid);
|
||||
if (is.getPrimaries().contains(uuid)) {
|
||||
is.removePrimary(uuid);
|
||||
}
|
||||
if (is.equals(island)) {
|
||||
is.setPrimary(uuid);
|
||||
}
|
||||
|
@ -337,6 +352,7 @@ public class IslandCache {
|
|||
islandSet.remove(island);
|
||||
}
|
||||
island.removeMember(uuid);
|
||||
island.removePrimary(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -396,7 +412,7 @@ public class IslandCache {
|
|||
public void removeIsland(@NonNull Island island) {
|
||||
islandsByLocation.values().removeIf(island::equals);
|
||||
islandsById.values().removeIf(island::equals);
|
||||
islandsByUUID.values().removeIf(island::equals);
|
||||
islandsByUUID.values().forEach(s -> s.removeIf(island::equals));
|
||||
World w = Util.getWorld(island.getWorld());
|
||||
if (w == null) {
|
||||
return;
|
||||
|
|
|
@ -12,7 +12,17 @@ import world.bentobox.bentobox.database.objects.Island;
|
|||
*
|
||||
*/
|
||||
class IslandGrid {
|
||||
private final TreeMap<Integer, TreeMap<Integer, Island>> grid = new TreeMap<>();
|
||||
private final TreeMap<Integer, TreeMap<Integer, String>> grid = new TreeMap<>();
|
||||
private final IslandCache im;
|
||||
|
||||
/**
|
||||
* @param im IslandsManager
|
||||
*/
|
||||
public IslandGrid(IslandCache im) {
|
||||
super();
|
||||
this.im = im;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds island to grid
|
||||
* @param island - island to add
|
||||
|
@ -21,9 +31,9 @@ class IslandGrid {
|
|||
public boolean addToGrid(Island island) {
|
||||
// Check if we know about this island already
|
||||
if (grid.containsKey(island.getMinX())) {
|
||||
TreeMap<Integer, Island> zEntry = grid.get(island.getMinX());
|
||||
TreeMap<Integer, String> zEntry = grid.get(island.getMinX());
|
||||
if (zEntry.containsKey(island.getMinZ())) {
|
||||
if (island.getUniqueId().equals(zEntry.get(island.getMinZ()).getUniqueId())) {
|
||||
if (island.getUniqueId().equals(zEntry.get(island.getMinZ()))) {
|
||||
BentoBox.getInstance().logDebug("I already know about this island");
|
||||
return true;
|
||||
}
|
||||
|
@ -31,13 +41,13 @@ class IslandGrid {
|
|||
return false;
|
||||
} else {
|
||||
// Add island
|
||||
zEntry.put(island.getMinZ(), island);
|
||||
zEntry.put(island.getMinZ(), island.getUniqueId());
|
||||
grid.put(island.getMinX(), zEntry);
|
||||
}
|
||||
} else {
|
||||
// Add island
|
||||
TreeMap<Integer, Island> zEntry = new TreeMap<>();
|
||||
zEntry.put(island.getMinZ(), island);
|
||||
TreeMap<Integer, String> zEntry = new TreeMap<>();
|
||||
zEntry.put(island.getMinZ(), island.getUniqueId());
|
||||
grid.put(island.getMinX(), zEntry);
|
||||
}
|
||||
return true;
|
||||
|
@ -54,7 +64,7 @@ class IslandGrid {
|
|||
int x = island.getMinX();
|
||||
int z = island.getMinZ();
|
||||
if (grid.containsKey(x)) {
|
||||
TreeMap<Integer, Island> zEntry = grid.get(x);
|
||||
TreeMap<Integer, String> zEntry = grid.get(x);
|
||||
if (zEntry.containsKey(z)) {
|
||||
// Island exists - delete it
|
||||
zEntry.remove(z);
|
||||
|
@ -67,25 +77,38 @@ class IslandGrid {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the island at the x,z location or null if there is none.
|
||||
* This includes the full island space, not just the protected area.
|
||||
* 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 - x coordinate
|
||||
* @param z - z coordinate
|
||||
* @return Island or null
|
||||
* @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) {
|
||||
Entry<Integer, TreeMap<Integer, Island>> en = grid.floorEntry(x);
|
||||
if (en != null) {
|
||||
Entry<Integer, Island> ent = en.getValue().floorEntry(z);
|
||||
if (ent != null) {
|
||||
// Check if in the island range
|
||||
Island island = ent.getValue();
|
||||
if (island.inIslandSpace(x, z)) {
|
||||
return island;
|
||||
}
|
||||
}
|
||||
// Attempt to find the closest x-coordinate entry that does not exceed 'x'
|
||||
Entry<Integer, TreeMap<Integer, String>> xEntry = grid.floorEntry(x);
|
||||
if (xEntry == null) {
|
||||
return null; // No x-coordinate entry found, return null
|
||||
}
|
||||
|
||||
// Attempt to find the closest z-coordinate entry that does not exceed 'z' within the found x-coordinate
|
||||
Entry<Integer, String> zEntry = xEntry.getValue().floorEntry(z);
|
||||
if (zEntry == null) {
|
||||
return null; // No z-coordinate entry found, return null
|
||||
}
|
||||
|
||||
// Retrieve the island using the id found in the z-coordinate entry
|
||||
Island island = im.getIslandById(zEntry.getValue());
|
||||
if (island == null) {
|
||||
return null; // No island found by the id, return null
|
||||
}
|
||||
// Check if the specified coordinates are within the island space
|
||||
if (island.inIslandSpace(x, z)) {
|
||||
return island; // Coordinates are within island space, return the island
|
||||
}
|
||||
|
||||
// Coordinates are outside the island space, return null
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
|
@ -50,11 +52,12 @@ import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
|
|||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ BentoBox.class, Flags.class, Util.class, Bukkit.class})
|
||||
@PrepareForTest({ BentoBox.class, Flags.class, Util.class, Bukkit.class, IslandsManager.class })
|
||||
public class TestBentoBox extends AbstractCommonSetup {
|
||||
private static final UUID MEMBER_UUID = UUID.randomUUID();
|
||||
private static final UUID VISITOR_UUID = UUID.randomUUID();
|
||||
|
@ -74,6 +77,9 @@ public class TestBentoBox extends AbstractCommonSetup {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// IslandsManager static
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||
|
@ -85,6 +91,7 @@ public class TestBentoBox extends AbstractCommonSetup {
|
|||
|
||||
when(player.hasPermission(anyString())).thenReturn(true);
|
||||
|
||||
when(location.getWorld()).thenReturn(world);
|
||||
when(ownerOfIsland.getLocation()).thenReturn(location);
|
||||
when(visitorToIsland.getLocation()).thenReturn(location);
|
||||
when(location.clone()).thenReturn(location);
|
||||
|
@ -95,6 +102,7 @@ public class TestBentoBox extends AbstractCommonSetup {
|
|||
|
||||
island.setOwner(uuid);
|
||||
island.setProtectionRange(100);
|
||||
island.setCenter(location);
|
||||
HashMap<UUID, Integer> members = new HashMap<>();
|
||||
members.put(uuid, RanksManager.OWNER_RANK);
|
||||
members.put(MEMBER_UUID, RanksManager.MEMBER_RANK);
|
||||
|
|
|
@ -51,7 +51,7 @@ import world.bentobox.bentobox.util.Util;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class, IslandsManager.class })
|
||||
public class AdminInfoCommandTest extends RanksManagerBeforeClassTest {
|
||||
|
||||
@Mock
|
||||
|
@ -84,6 +84,8 @@ public class AdminInfoCommandTest extends RanksManagerBeforeClassTest {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
@ -54,7 +55,7 @@ import world.bentobox.bentobox.util.Util;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class })
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, IslandsManager.class })
|
||||
public class AdminUnregisterCommandTest {
|
||||
|
||||
private UUID uuid = UUID.randomUUID();
|
||||
|
@ -83,6 +84,7 @@ public class AdminUnregisterCommandTest {
|
|||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
|
|
@ -39,7 +39,7 @@ import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class })
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, IslandsManager.class })
|
||||
public class DefaultPlayerCommandTest extends RanksManagerBeforeClassTest {
|
||||
|
||||
@Mock
|
||||
|
@ -68,6 +68,7 @@ public class DefaultPlayerCommandTest extends RanksManagerBeforeClassTest {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// User
|
||||
when(user.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||
|
|
|
@ -51,7 +51,7 @@ import world.bentobox.bentobox.util.Util;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class})
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class, IslandsManager.class })
|
||||
public class IslandInfoCommandTest extends RanksManagerBeforeClassTest {
|
||||
|
||||
@Mock
|
||||
|
@ -84,6 +84,8 @@ public class IslandInfoCommandTest extends RanksManagerBeforeClassTest {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ import world.bentobox.bentobox.managers.island.NewIsland;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, NewIsland.class })
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, NewIsland.class, IslandsManager.class })
|
||||
public class IslandResetCommandTest {
|
||||
|
||||
@Mock
|
||||
|
@ -97,6 +97,7 @@ public class IslandResetCommandTest {
|
|||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
|
|
@ -7,10 +7,13 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -29,10 +32,10 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.database.objects.TeamInvite;
|
||||
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
|
@ -75,6 +78,9 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
|
|||
@Mock
|
||||
private @Nullable Island island;
|
||||
|
||||
@Mock
|
||||
private GameModeAddon addon;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Before
|
||||
|
@ -88,6 +94,7 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
|
|||
// Parent command
|
||||
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
|
||||
when(ic.getWorld()).thenReturn(world);
|
||||
when(ic.getAddon()).thenReturn(addon);
|
||||
|
||||
// user
|
||||
uuid = UUID.randomUUID();
|
||||
|
@ -172,11 +179,14 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
|
|||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#addInvite(world.bentobox.bentobox.api.commands.island.team.Invite.Type, java.util.UUID, java.util.UUID)}.
|
||||
* @throws IntrospectionException
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@Test
|
||||
public void testAddInvite() {
|
||||
public void testAddInvite() throws IllegalAccessException, InvocationTargetException, IntrospectionException {
|
||||
tc.addInvite(Type.TEAM, uuid, invitee, island);
|
||||
assertTrue(tc.isInvited(invitee));
|
||||
verify(h, atLeast(1)).saveObject(any());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,8 +204,7 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
|
|||
*/
|
||||
@Test
|
||||
public void testGetInviter() {
|
||||
tc.addInvite(Type.TEAM, uuid, invitee, island);
|
||||
assertEquals(uuid, tc.getInviter(invitee));
|
||||
assertNull(tc.getInviter(invitee));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,12 +223,6 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
|
|||
@Test
|
||||
public void testGetInvite() {
|
||||
assertNull(tc.getInvite(invitee));
|
||||
tc.addInvite(Type.TEAM, uuid, invitee, island);
|
||||
@Nullable
|
||||
TeamInvite invite = tc.getInvite(invitee);
|
||||
assertEquals(invitee, invite.getInvitee());
|
||||
assertEquals(Type.TEAM, invite.getType());
|
||||
assertEquals(uuid, invite.getInviter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -250,7 +250,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(im).removePlayer(any(Island.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
}
|
||||
|
||||
|
@ -343,7 +343,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(im).removePlayer(any(Island.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(im).removePlayer(any(Island.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
verify(target, never()).getInventory();
|
||||
|
||||
|
@ -389,7 +389,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(im).removePlayer(any(Island.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
verify(target, Mockito.never()).getInventory();
|
||||
verify(pm).cleanLeavingPlayer(any(), any(User.class), eq(true), eq(island));
|
||||
|
|
|
@ -54,7 +54,7 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class })
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, IslandsManager.class })
|
||||
public class IslandTeamSetownerCommandTest {
|
||||
|
||||
@Mock
|
||||
|
@ -84,6 +84,8 @@ public class IslandTeamSetownerCommandTest {
|
|||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
@ -276,7 +278,8 @@ public class IslandTeamSetownerCommandTest {
|
|||
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
||||
assertTrue(its.execute(user, "", List.of("tastybento")));
|
||||
verify(im).setOwner(any(), eq(user), eq(target));
|
||||
verify(im).updateIsland(island);
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(island);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -292,7 +295,8 @@ public class IslandTeamSetownerCommandTest {
|
|||
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
||||
assertTrue(its.execute(user, "", List.of("tastybento")));
|
||||
verify(im).setOwner(any(), eq(user), eq(target));
|
||||
verify(im).updateIsland(island);
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(island);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.mockito.Mockito;
|
|||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
|
@ -28,13 +29,14 @@ import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
|||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.database.objects.IslandDeletion;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ BentoBox.class, Bukkit.class })
|
||||
@PrepareForTest({ BentoBox.class, Bukkit.class, IslandsManager.class })
|
||||
public class IslandEventTest {
|
||||
|
||||
private Island island;
|
||||
|
@ -47,11 +49,18 @@ public class IslandEventTest {
|
|||
private IslandDeletion deletedIslandInfo;
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
@Mock
|
||||
private BentoBox plugin;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// Set up plugin
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
uuid = UUID.randomUUID();
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
|
|
|
@ -46,6 +46,7 @@ import world.bentobox.bentobox.lists.Flags;
|
|||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Pair;
|
||||
|
||||
|
@ -54,7 +55,7 @@ import world.bentobox.bentobox.util.Pair;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class })
|
||||
@PrepareForTest({ Bukkit.class, IslandsManager.class })
|
||||
public class IslandTest {
|
||||
|
||||
private static final int DISTANCE = 400;
|
||||
|
@ -105,6 +106,9 @@ public class IslandTest {
|
|||
// Commands manager
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Islands Manager
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
i = new Island(new Island(location, uuid, 100));
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ import world.bentobox.bentobox.util.Util;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ BentoBox.class, Util.class, Bukkit.class })
|
||||
@PrepareForTest({ BentoBox.class, Util.class, Bukkit.class, IslandsManager.class })
|
||||
public class JoinLeaveListenerTest {
|
||||
|
||||
private static final String[] NAMES = { "adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry",
|
||||
|
@ -111,6 +111,8 @@ public class JoinLeaveListenerTest {
|
|||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// Set up plugin
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
|
|
|
@ -18,10 +18,14 @@ import org.mockito.Mock;
|
|||
import org.mockito.Mockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.TestWorldSettings;
|
||||
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.hooks.Hook;
|
||||
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
|
||||
import world.bentobox.bentobox.lists.GameModePlaceholder;
|
||||
|
@ -43,9 +47,17 @@ public class PlaceholdersManagerTest {
|
|||
private HooksManager hm;
|
||||
@Mock
|
||||
private PlaceholderAPIHook hook;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
private Settings settings;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
settings = new Settings();
|
||||
when(plugin.getSettings()).thenReturn(settings);
|
||||
|
||||
// Addon
|
||||
@NonNull
|
||||
AddonDescription desc = new AddonDescription.Builder("main", "bskyblock", "1.0").build();
|
||||
|
@ -61,6 +73,13 @@ public class PlaceholdersManagerTest {
|
|||
when(hm.getHook(eq("PlaceholderAPI"))).thenReturn(optionalHook);
|
||||
when(hook.isPlaceholder(any(), any())).thenReturn(false);
|
||||
|
||||
// World settings
|
||||
|
||||
@NonNull
|
||||
WorldSettings ws = new TestWorldSettings();
|
||||
when(iwm.getWorldSettings(any())).thenReturn(ws);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Placeholder manager
|
||||
pm = new PlaceholdersManager(plugin);
|
||||
}
|
||||
|
@ -77,7 +96,7 @@ public class PlaceholdersManagerTest {
|
|||
public void testRegisterGameModePlaceholdersAllDefaults() {
|
||||
pm.registerDefaultPlaceholders(addon);
|
||||
// + 300 because we register team member placeholders up to 50 members
|
||||
verify(hook, times(GameModePlaceholder.values().length + 302)).registerPlaceholder(any(), anyString(), any());
|
||||
verify(hook, times(GameModePlaceholder.values().length + 304)).registerPlaceholder(any(), anyString(), any());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,7 +110,7 @@ public class PlaceholdersManagerTest {
|
|||
pm.registerDefaultPlaceholders(addon);
|
||||
|
||||
// 3 less registrations for this addon
|
||||
verify(hook, times(GameModePlaceholder.values().length - 3 + 302)).registerPlaceholder(any(), anyString(),
|
||||
verify(hook, times(GameModePlaceholder.values().length - 3 + 304)).registerPlaceholder(any(), anyString(),
|
||||
any());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -40,7 +41,6 @@ import org.bukkit.inventory.Inventory;
|
|||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -411,24 +411,13 @@ public class PlayersManagerTest {
|
|||
assertEquals("tastybento", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#getPlayer(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPlayer() {
|
||||
Players player = pm.getPlayer(uuid);
|
||||
assertEquals("tastybento", player.getPlayerName());
|
||||
assertEquals(uuid.toString(), player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#getPlayers()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPlayers() {
|
||||
assertTrue(pm.getPlayers().isEmpty());
|
||||
assertFalse(pm.getPlayers().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -679,15 +668,15 @@ public class PlayersManagerTest {
|
|||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#setPlayerName(world.bentobox.bentobox.api.user.User)}.
|
||||
* @throws IntrospectionException
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@Test
|
||||
public void testSetPlayerName() {
|
||||
public void testSetPlayerName() throws IllegalAccessException, InvocationTargetException, IntrospectionException {
|
||||
pm.setPlayerName(user);
|
||||
assertEquals("tastybento", pm.getName(uuid));
|
||||
when(user.getName()).thenReturn("newName");
|
||||
assertEquals("tastybento", pm.getName(uuid));
|
||||
pm.setPlayerName(user);
|
||||
assertEquals("newName", pm.getName(uuid));
|
||||
// Player and names database saves
|
||||
verify(h, atLeast(2)).saveObject(any());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
package world.bentobox.bentobox.managers;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -22,6 +28,7 @@ import org.powermock.reflect.Whitebox;
|
|||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
||||
import world.bentobox.bentobox.database.DatabaseSetup;
|
||||
|
||||
/**
|
||||
|
@ -63,6 +70,22 @@ public abstract class RanksManagerBeforeClassTest {
|
|||
@Mock
|
||||
public RanksManager rm;
|
||||
|
||||
protected static AbstractDatabaseHandler<Object> h;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws IllegalAccessException, InvocationTargetException, IntrospectionException {
|
||||
// This has to be done beforeClass otherwise the tests will interfere with each
|
||||
// other
|
||||
h = mock(AbstractDatabaseHandler.class);
|
||||
// Database
|
||||
PowerMockito.mockStatic(DatabaseSetup.class);
|
||||
DatabaseSetup dbSetup = mock(DatabaseSetup.class);
|
||||
when(DatabaseSetup.getDatabase()).thenReturn(dbSetup);
|
||||
when(dbSetup.getHandler(any())).thenReturn(h);
|
||||
when(h.saveObject(any())).thenReturn(CompletableFuture.completedFuture(true));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
|
|
|
@ -56,7 +56,7 @@ import world.bentobox.bentobox.util.Util;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Util.class, IslandEvent.class, Bukkit.class })
|
||||
@PrepareForTest({ Util.class, IslandEvent.class, Bukkit.class, IslandsManager.class })
|
||||
public class NewIslandTest {
|
||||
|
||||
private static final String NAME = "name";
|
||||
|
@ -105,6 +105,7 @@ public class NewIslandTest {
|
|||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
// Islands manager
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
@ -205,7 +206,8 @@ public class NewIslandTest {
|
|||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).oldIsland(oldIsland)
|
||||
.build();
|
||||
// Verifications
|
||||
verify(im).updateIsland(eq(island));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
|
@ -224,7 +226,8 @@ public class NewIslandTest {
|
|||
when(builder.build()).thenReturn(ire);
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.RESET).oldIsland(oldIsland).build();
|
||||
// Verifications
|
||||
verify(im).updateIsland(eq(island));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
|
@ -243,7 +246,8 @@ public class NewIslandTest {
|
|||
public void testBuilderNoOldIsland() throws Exception {
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).build();
|
||||
// Verifications
|
||||
verify(im).updateIsland(eq(island));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
|
@ -262,7 +266,8 @@ public class NewIslandTest {
|
|||
when(location.distance(any())).thenReturn(30D);
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).reason(Reason.CREATE).build();
|
||||
// Verifications
|
||||
verify(im).updateIsland(eq(island));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class), eq(false));
|
||||
verify(builder, times(2)).build();
|
||||
|
@ -281,7 +286,8 @@ public class NewIslandTest {
|
|||
NewIsland.builder().addon(addon).name(NAME).player(user).reason(Reason.CREATE).build();
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
// Verifications
|
||||
verify(im).updateIsland(island);
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class), eq(true));
|
||||
verify(builder, times(2)).build();
|
||||
|
@ -299,7 +305,8 @@ public class NewIslandTest {
|
|||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).oldIsland(oldIsland).build();
|
||||
// Verifications
|
||||
verify(im).updateIsland(eq(island));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
|
@ -320,7 +327,8 @@ public class NewIslandTest {
|
|||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).oldIsland(oldIsland).build();
|
||||
// Verifications
|
||||
verify(im).updateIsland(eq(island));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
|
@ -342,7 +350,8 @@ public class NewIslandTest {
|
|||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).oldIsland(oldIsland).build();
|
||||
// Verifications
|
||||
verify(im).updateIsland(eq(island));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(eq(island));
|
||||
verify(island).setFlagsDefaults();
|
||||
verify(scheduler).runTask(any(BentoBox.class), any(Runnable.class));
|
||||
verify(builder, times(2)).build();
|
||||
|
|
|
@ -58,7 +58,7 @@ import world.bentobox.bentobox.util.teleport.ClosestSafeSpotTeleport.PositionDat
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Util.class, Bukkit.class})
|
||||
@PrepareForTest({ Util.class, Bukkit.class, IslandsManager.class })
|
||||
public class ClosestSafeSpotTeleportTest {
|
||||
|
||||
// Class under test
|
||||
|
@ -102,6 +102,9 @@ public class ClosestSafeSpotTeleportTest {
|
|||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// IslandsManager static
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// Setup instance
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
// IWM
|
||||
|
|
|
@ -47,7 +47,7 @@ import world.bentobox.bentobox.util.Util;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Util.class, Bukkit.class})
|
||||
@PrepareForTest({ Util.class, Bukkit.class, IslandsManager.class })
|
||||
public class SafeSpotTeleportTest {
|
||||
|
||||
// Class under test
|
||||
|
@ -92,6 +92,7 @@ public class SafeSpotTeleportTest {
|
|||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
|
||||
// Setup instance
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
// IWM
|
||||
|
|
Loading…
Reference in New Issue