Update Upstream

acd63daddf7b45ce2b7699bc85ae88e0aa4433e9: Slightly improve usability of LocalSession#getSelection.
Co-Authored-By: wizjany <568161+wizjany@users.noreply.github.com>
This commit is contained in:
NotMyFault 2021-03-26 10:11:26 +01:00
parent 4af7316118
commit c689b4e5d2
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C

View File

@ -712,19 +712,36 @@ public class LocalSession implements TextureHolder {
return selector.isDefined(); return selector.isDefined();
} }
/**
* Get the selection region. If you change the region, you should
* call learnRegionChanges(). If the selection is not fully defined,
* the {@code IncompleteRegionException} exception will be thrown.
*
* <p>Note that this method will return a region in the current selection world,
* which is not guaranteed to be the player's world or even the current world
* override. If you require a specific world, use the
* {@link LocalSession#getSelection(World)} overload instead.
*
* @return the selected region
* @throws IncompleteRegionException if the region is not fully defined
*/
public Region getSelection() throws IncompleteRegionException {
return getSelection(getSelectionWorld());
}
/** /**
* Get the selection region. If you change the region, you should * Get the selection region. If you change the region, you should
* call learnRegionChanges(). If the selection is defined in * call learnRegionChanges(). If the selection is defined in
* a different world, the {@code IncompleteRegionException} * a different world, or the selection isn't fully defined,
* exception will be thrown. * the {@code IncompleteRegionException} exception will be thrown.
* *
* @param world the world * @param world the world
* @return a region * @return a region
* @throws IncompleteRegionException if no region is selected * @throws IncompleteRegionException if no region is selected, or the provided world is null
*/ */
public Region getSelection(World world) throws IncompleteRegionException { public Region getSelection(@Nullable World world) throws IncompleteRegionException {
checkNotNull(world); if (world == null || selector.getIncompleteRegion().getWorld() == null
if (selector.getIncompleteRegion().getWorld() == null || !selector.getIncompleteRegion().getWorld().equals(world)) { || !selector.getIncompleteRegion().getWorld().equals(world)) {
throw new IncompleteRegionException() { throw new IncompleteRegionException() {
@Override @Override
public synchronized Throwable fillInStackTrace() { public synchronized Throwable fillInStackTrace() {
@ -769,6 +786,7 @@ public class LocalSession implements TextureHolder {
* *
* @return the the world of the selection * @return the the world of the selection
*/ */
@Nullable
public World getSelectionWorld() { public World getSelectionWorld() {
World world = selector.getIncompleteRegion().getWorld(); World world = selector.getIncompleteRegion().getWorld();
if (world instanceof WorldWrapper) { if (world instanceof WorldWrapper) {