mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 11:15:24 +01:00
Non null user methods (#1856)
* This makes some User methods non-null. Instead of returning null, some methods will throw an error if they are called on non-Players. This means code does not have to do null checks. * Perform null check in method.
This commit is contained in:
parent
cad7dc1666
commit
25fe86d812
@ -70,15 +70,16 @@ public class AdminBlueprintCommand extends ConfirmableCommand {
|
||||
|
||||
if (clipboards.containsKey(user.getUniqueId())) {
|
||||
BlueprintClipboard clipboard = clipboards.get(user.getUniqueId());
|
||||
if (clipboard.getPos1() != null && clipboard.getPos2() != null) {
|
||||
paintAxis(user, clipboard);
|
||||
}
|
||||
paintAxis(user, clipboard);
|
||||
}
|
||||
|
||||
}, 20, 20));
|
||||
}
|
||||
|
||||
private void paintAxis(User user, BlueprintClipboard clipboard) {
|
||||
if (clipboard.getPos1() == null || clipboard.getPos2() == null) {
|
||||
return;
|
||||
}
|
||||
int minX = Math.min(clipboard.getPos1().getBlockX(), clipboard.getPos2().getBlockX());
|
||||
int minY = Math.min(clipboard.getPos1().getBlockY(), clipboard.getPos2().getBlockY());
|
||||
int minZ = Math.min(clipboard.getPos1().getBlockZ(), clipboard.getPos2().getBlockZ());
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -175,16 +176,17 @@ public class User implements MetaDataAble {
|
||||
return sender.getEffectivePermissions();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public PlayerInventory getInventory() {
|
||||
return player != null ? player.getInventory() : null;
|
||||
return Objects.requireNonNull(player, "getInventory can only be called for online players!").getInventory();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public Location getLocation() {
|
||||
return player != null ? player.getLocation() : null;
|
||||
return Objects.requireNonNull(player, "getLocation can only be called for online players!").getLocation();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getName() {
|
||||
return player != null ? player.getName() : plugin.getPlayers().getName(playerUUID);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user