mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 11:15:24 +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
|
// Check if island is owned
|
||||||
Optional<Island> island = getIslands().getIslandAt(user.getLocation());
|
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");
|
user.sendMessage("commands.admin.register.already-owned");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class AdminSetspawnCommand extends ConfirmableCommand {
|
|||||||
|
|
||||||
private void setSpawn(User user, Island i) {
|
private void setSpawn(User user, Island i) {
|
||||||
if (!i.getMembers().isEmpty()) {
|
if (!i.getMembers().isEmpty()) {
|
||||||
if (i.getOwner() != null) {
|
if (i.isOwned()) {
|
||||||
// Fire event
|
// Fire event
|
||||||
IslandBaseEvent event = IslandEvent.builder()
|
IslandBaseEvent event = IslandEvent.builder()
|
||||||
.island(i)
|
.island(i)
|
||||||
|
@ -120,7 +120,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
|
|||||||
return getPlugin().getIslands().getIslands().stream()
|
return getPlugin().getIslands().getIslands().stream()
|
||||||
.filter(i -> !i.getPurgeProtected())
|
.filter(i -> !i.getPurgeProtected())
|
||||||
.filter(i -> i.getWorld().equals(this.getWorld()))
|
.filter(i -> i.getWorld().equals(this.getWorld()))
|
||||||
.filter(i -> i.getOwner() != null)
|
.filter(Island::isOwned)
|
||||||
.filter(i -> i.getMembers().size() == 1)
|
.filter(i -> i.getMembers().size() == 1)
|
||||||
.filter(i -> (System.currentTimeMillis() - Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed()) > days * 1000 * 24 * 3600)
|
.filter(i -> (System.currentTimeMillis() - Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed()) > days * 1000 * 24 * 3600)
|
||||||
.map(Island::getUniqueId)
|
.map(Island::getUniqueId)
|
||||||
|
@ -51,7 +51,7 @@ public class AdminPurgeUnownedCommand extends ConfirmableCommand {
|
|||||||
return getPlugin().getIslands().getIslands().stream()
|
return getPlugin().getIslands().getIslands().stream()
|
||||||
.filter(i -> !i.getPurgeProtected())
|
.filter(i -> !i.getPurgeProtected())
|
||||||
.filter(i -> i.getWorld().equals(this.getWorld()))
|
.filter(i -> i.getWorld().equals(this.getWorld()))
|
||||||
.filter(i -> i.getOwner() == null)
|
.filter(Island::isUnowned)
|
||||||
.map(Island::getUniqueId)
|
.map(Island::getUniqueId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class IslandNearCommand extends CompositeCommand {
|
|||||||
if (island.getName() != null && !island.getName().isEmpty()) {
|
if (island.getName() != null && !island.getName().isEmpty()) {
|
||||||
return island.getName();
|
return island.getName();
|
||||||
}
|
}
|
||||||
if (island.getOwner() == null) {
|
if (island.isUnowned()) {
|
||||||
return user.getTranslation("commands.admin.info.unowned");
|
return user.getTranslation("commands.admin.info.unowned");
|
||||||
}
|
}
|
||||||
return getPlayers().getName(island.getOwner());
|
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
|
@Nullable
|
||||||
public UUID getOwner(){
|
public UUID getOwner(){
|
||||||
return owner;
|
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
|
* @return the protectionRange
|
||||||
*/
|
*/
|
||||||
|
@ -97,7 +97,7 @@ public class EnterExitListener extends FlagListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send message if island is owned by someone
|
// Send message if island is owned by someone
|
||||||
if (island.getOwner() != null) {
|
if (island.isOwned()) {
|
||||||
// Leave messages are always specific to this world
|
// 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.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())));
|
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
|
// Send message if island is owned by someone
|
||||||
if (island.getOwner() != null) {
|
if (island.isOwned()) {
|
||||||
// Leave messages are always specific to this world
|
// 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.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())));
|
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
|
// Add to quarantine cache
|
||||||
island.setDoNotLoad(true);
|
island.setDoNotLoad(true);
|
||||||
quarantineCache.computeIfAbsent(island.getOwner(), k -> new ArrayList<>()).add(island);
|
quarantineCache.computeIfAbsent(island.getOwner(), k -> new ArrayList<>()).add(island);
|
||||||
if (island.getOwner() == null) {
|
if (island.isUnowned()) {
|
||||||
unowned++;
|
unowned++;
|
||||||
} else {
|
} else {
|
||||||
owned++;
|
owned++;
|
||||||
|
@ -67,7 +67,7 @@ public class IslandCache {
|
|||||||
// Make world
|
// Make world
|
||||||
islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>());
|
islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>());
|
||||||
// Only add islands to this map if they are owned
|
// 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);
|
islandsByUUID.get(island.getWorld()).put(island.getOwner(), island);
|
||||||
island.getMemberSet().forEach(member -> islandsByUUID.get(island.getWorld()).put(member, island));
|
island.getMemberSet().forEach(member -> islandsByUUID.get(island.getWorld()).put(member, island));
|
||||||
}
|
}
|
||||||
@ -235,7 +235,7 @@ public class IslandCache {
|
|||||||
islandsByUUID.putIfAbsent(world, new HashMap<>());
|
islandsByUUID.putIfAbsent(world, new HashMap<>());
|
||||||
Island island = islandsByUUID.get(world).get(uuid);
|
Island island = islandsByUUID.get(world).get(uuid);
|
||||||
if (island != null) {
|
if (island != null) {
|
||||||
if (island.getOwner() != null && island.getOwner().equals(uuid)) {
|
if (uuid.equals(island.getOwner())) {
|
||||||
// Clear ownership and members
|
// Clear ownership and members
|
||||||
island.getMembers().clear();
|
island.getMembers().clear();
|
||||||
island.setOwner(null);
|
island.setOwner(null);
|
||||||
|
Loading…
Reference in New Issue
Block a user