mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-11 20:06:42 +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())) {
|
if (clipboards.containsKey(user.getUniqueId())) {
|
||||||
BlueprintClipboard clipboard = clipboards.get(user.getUniqueId());
|
BlueprintClipboard clipboard = clipboards.get(user.getUniqueId());
|
||||||
if (clipboard.getPos1() != null && clipboard.getPos2() != null) {
|
|
||||||
paintAxis(user, clipboard);
|
paintAxis(user, clipboard);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}, 20, 20));
|
}, 20, 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintAxis(User user, BlueprintClipboard clipboard) {
|
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 minX = Math.min(clipboard.getPos1().getBlockX(), clipboard.getPos2().getBlockX());
|
||||||
int minY = Math.min(clipboard.getPos1().getBlockY(), clipboard.getPos2().getBlockY());
|
int minY = Math.min(clipboard.getPos1().getBlockY(), clipboard.getPos2().getBlockY());
|
||||||
int minZ = Math.min(clipboard.getPos1().getBlockZ(), clipboard.getPos2().getBlockZ());
|
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.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -175,16 +176,17 @@ public class User implements MetaDataAble {
|
|||||||
return sender.getEffectivePermissions();
|
return sender.getEffectivePermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
public PlayerInventory getInventory() {
|
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() {
|
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() {
|
public String getName() {
|
||||||
return player != null ? player.getName() : plugin.getPlayers().getName(playerUUID);
|
return player != null ? player.getName() : plugin.getPlayers().getName(playerUUID);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user