mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 05:05:18 +01:00
Added Island#isOwned(), Island#isUnowned() and improved javadoc on Island#getOwner()
This commit is contained in:
parent
3d853d58f8
commit
23c621544d
@ -62,7 +62,7 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
||||
}
|
||||
// Check if island is owned
|
||||
Optional<Island> island = getIslands().getIslandAt(user.getLocation());
|
||||
if (island.map(i -> i.getOwner() != null).orElse(false)) {
|
||||
if (island.map(Island::isOwned).orElse(false)) {
|
||||
user.sendMessage("commands.admin.register.already-owned");
|
||||
return false;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class AdminSetspawnCommand extends ConfirmableCommand {
|
||||
|
||||
private void setSpawn(User user, Island i) {
|
||||
if (!i.getMembers().isEmpty()) {
|
||||
if (i.getOwner() != null) {
|
||||
if (i.isOwned()) {
|
||||
// Fire event
|
||||
IslandBaseEvent event = IslandEvent.builder()
|
||||
.island(i)
|
||||
|
@ -120,7 +120,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
|
||||
return getPlugin().getIslands().getIslands().stream()
|
||||
.filter(i -> !i.getPurgeProtected())
|
||||
.filter(i -> i.getWorld().equals(this.getWorld()))
|
||||
.filter(i -> i.getOwner() != null)
|
||||
.filter(Island::isOwned)
|
||||
.filter(i -> i.getMembers().size() == 1)
|
||||
.filter(i -> (System.currentTimeMillis() - Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed()) > days * 1000 * 24 * 3600)
|
||||
.map(Island::getUniqueId)
|
||||
|
@ -51,7 +51,7 @@ public class AdminPurgeUnownedCommand extends ConfirmableCommand {
|
||||
return getPlugin().getIslands().getIslands().stream()
|
||||
.filter(i -> !i.getPurgeProtected())
|
||||
.filter(i -> i.getWorld().equals(this.getWorld()))
|
||||
.filter(i -> i.getOwner() == null)
|
||||
.filter(Island::isUnowned)
|
||||
.map(Island::getUniqueId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class IslandNearCommand extends CompositeCommand {
|
||||
if (island.getName() != null && !island.getName().isEmpty()) {
|
||||
return island.getName();
|
||||
}
|
||||
if (island.getOwner() == null) {
|
||||
if (island.isUnowned()) {
|
||||
return user.getTranslation("commands.admin.info.unowned");
|
||||
}
|
||||
return getPlayers().getName(island.getOwner());
|
||||
|
@ -441,13 +441,38 @@ public class Island implements DataObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the owner
|
||||
* Returns the owner of this island.
|
||||
* @return the owner, may be null.
|
||||
* @see #isOwned()
|
||||
* @see #isUnowned()
|
||||
*/
|
||||
@Nullable
|
||||
public UUID getOwner(){
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this island is owned or not.
|
||||
* @return {@code true} if this island has an owner, {@code false} otherwise.
|
||||
* @since 1.9.1
|
||||
* @see #getOwner()
|
||||
* @see #isUnowned()
|
||||
*/
|
||||
public boolean isOwned() {
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this island does not have an owner.
|
||||
* @return {@code true} if this island does not have an owner, {@code false} otherwise.
|
||||
* @since 1.9.1
|
||||
* @see #getOwner()
|
||||
* @see #isOwned()
|
||||
*/
|
||||
public boolean isUnowned() {
|
||||
return owner == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the protectionRange
|
||||
*/
|
||||
|
@ -97,7 +97,7 @@ public class EnterExitListener extends FlagListener {
|
||||
}
|
||||
|
||||
// Send message if island is owned by someone
|
||||
if (island.getOwner() != null) {
|
||||
if (island.isOwned()) {
|
||||
// Leave messages are always specific to this world
|
||||
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (island.getName() != null) ? island.getName() :
|
||||
user.getTranslation(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner())));
|
||||
@ -121,7 +121,7 @@ public class EnterExitListener extends FlagListener {
|
||||
}
|
||||
|
||||
// Send message if island is owned by someone
|
||||
if (island.getOwner() != null) {
|
||||
if (island.isOwned()) {
|
||||
// Leave messages are always specific to this world
|
||||
user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (island.getName() != null) ? island.getName() :
|
||||
user.getTranslation(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner())));
|
||||
|
@ -842,7 +842,7 @@ public class IslandsManager {
|
||||
// Add to quarantine cache
|
||||
island.setDoNotLoad(true);
|
||||
quarantineCache.computeIfAbsent(island.getOwner(), k -> new ArrayList<>()).add(island);
|
||||
if (island.getOwner() == null) {
|
||||
if (island.isUnowned()) {
|
||||
unowned++;
|
||||
} else {
|
||||
owned++;
|
||||
|
@ -67,7 +67,7 @@ public class IslandCache {
|
||||
// Make world
|
||||
islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>());
|
||||
// Only add islands to this map if they are owned
|
||||
if (island.getOwner() != null) {
|
||||
if (island.isOwned()) {
|
||||
islandsByUUID.get(island.getWorld()).put(island.getOwner(), island);
|
||||
island.getMemberSet().forEach(member -> islandsByUUID.get(island.getWorld()).put(member, island));
|
||||
}
|
||||
@ -235,7 +235,7 @@ public class IslandCache {
|
||||
islandsByUUID.putIfAbsent(world, new HashMap<>());
|
||||
Island island = islandsByUUID.get(world).get(uuid);
|
||||
if (island != null) {
|
||||
if (island.getOwner() != null && island.getOwner().equals(uuid)) {
|
||||
if (uuid.equals(island.getOwner())) {
|
||||
// Clear ownership and members
|
||||
island.getMembers().clear();
|
||||
island.setOwner(null);
|
||||
|
Loading…
Reference in New Issue
Block a user