mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 20:56:45 +01:00
perf: Avoid expensive Plot#getOwner calls in Plot#getOwners (#4418)
* Avoid expensive Plot#getOwner calls in Plot#getOwners * Don't check for the owner beforehand, because it's done in the loop regardless
This commit is contained in:
parent
a7447c9d75
commit
83fe761fe4
@ -643,35 +643,22 @@ public class Plot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a immutable set of owner UUIDs for a plot (supports multi-owner mega-plots).
|
* Gets an immutable set of owner UUIDs for a plot (supports multi-owner mega-plots).
|
||||||
* <p>
|
* <p>
|
||||||
* This method cannot be used to add or remove owners from a plot.
|
* This method cannot be used to add or remove owners from a plot.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return Immutable view of plot owners
|
* @return Immutable set of plot owners
|
||||||
*/
|
*/
|
||||||
public @NonNull Set<UUID> getOwners() {
|
public @NonNull Set<UUID> getOwners() {
|
||||||
if (this.getOwner() == null) {
|
ImmutableSet.Builder<UUID> owners = ImmutableSet.builder();
|
||||||
return ImmutableSet.of();
|
for (Plot plot : getConnectedPlots()) {
|
||||||
}
|
UUID owner = plot.getOwner();
|
||||||
if (isMerged()) {
|
if (owner != null) {
|
||||||
Set<Plot> plots = getConnectedPlots();
|
owners.add(owner);
|
||||||
Plot[] array = plots.toArray(new Plot[0]);
|
|
||||||
ImmutableSet.Builder<UUID> owners = ImmutableSet.builder();
|
|
||||||
UUID last = this.getOwner();
|
|
||||||
owners.add(this.getOwner());
|
|
||||||
for (final Plot current : array) {
|
|
||||||
if (current.getOwner() == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (last == null || current.getOwner().getMostSignificantBits() != last.getMostSignificantBits()) {
|
|
||||||
owners.add(current.getOwner());
|
|
||||||
last = current.getOwner();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return owners.build();
|
|
||||||
}
|
}
|
||||||
return ImmutableSet.of(this.getOwner());
|
return owners.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user