mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-26 01:51:30 +01:00
Npe squashing (#1857)
* Fix hanging [uuid] in info. * NPE checking * Make getProtectionCenter nonNull * More NPE fixes. * Fix test * Make getPlayer() and getOfflinePlayer() nonNull returns This requires addons to not use null checks and instead us the isPlayer or isOfflinePlayer methods. * NPE blockers * Deprecate CompositeCommand isPlayer method. * Fix test
This commit is contained in:
parent
b247b360bf
commit
53f02ae686
@ -79,8 +79,8 @@ public class AddonClassLoader extends URLClassLoader {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public static AddonDescription asDescription(YamlConfiguration data) throws InvalidAddonDescriptionException {
|
public static AddonDescription asDescription(YamlConfiguration data) throws InvalidAddonDescriptionException {
|
||||||
AddonDescription.Builder builder = new AddonDescription.Builder(data.getString("main"), data.getString("name"), data.getString("version"))
|
AddonDescription.Builder builder = new AddonDescription.Builder(Objects.requireNonNull(data.getString("main")), Objects.requireNonNull(data.getString("name")), Objects.requireNonNull(data.getString("version")))
|
||||||
.authors(data.getString("authors"))
|
.authors(Objects.requireNonNull(data.getString("authors")))
|
||||||
.metrics(data.getBoolean("metrics", true))
|
.metrics(data.getBoolean("metrics", true))
|
||||||
.repository(data.getString("repository", ""));
|
.repository(data.getString("repository", ""));
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ public class AddonClassLoader extends URLClassLoader {
|
|||||||
if (softDepend != null) {
|
if (softDepend != null) {
|
||||||
builder.softDependencies(Arrays.asList(softDepend.split("\\s*,\\s*")));
|
builder.softDependencies(Arrays.asList(softDepend.split("\\s*,\\s*")));
|
||||||
}
|
}
|
||||||
builder.icon(Material.getMaterial(data.getString("icon", "PAPER")));
|
builder.icon(Objects.requireNonNull(Material.getMaterial(data.getString("icon", "PAPER"))));
|
||||||
|
|
||||||
String apiVersion = data.getString("api-version");
|
String apiVersion = data.getString("api-version");
|
||||||
if (apiVersion != null) {
|
if (apiVersion != null) {
|
||||||
|
@ -279,6 +279,6 @@ public final class AddonDescription {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "AddonDescription [" + (name != null ? "name=" + name + ", " : "")
|
return "AddonDescription [" + (name != null ? "name=" + name + ", " : "")
|
||||||
+ (version != null ? "version=" + version : "") + "]";
|
+ "version=" + version + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,9 +476,11 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||||||
* Convenience method to check if a user is a player
|
* Convenience method to check if a user is a player
|
||||||
* @param user - the User
|
* @param user - the User
|
||||||
* @return true if sender is a player
|
* @return true if sender is a player
|
||||||
|
* @deprecated use {@link User#isPlayer()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
protected boolean isPlayer(User user) {
|
protected boolean isPlayer(User user) {
|
||||||
return user.getPlayer() != null;
|
return user.isPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +86,7 @@ public class AdminDeleteCommand extends ConfirmableCommand {
|
|||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
// Remove them from this island (it still exists and will be deleted later)
|
// Remove them from this island (it still exists and will be deleted later)
|
||||||
getIslands().removePlayer(getWorld(), targetUUID);
|
getIslands().removePlayer(getWorld(), targetUUID);
|
||||||
if (target.isOnline()) {
|
if (target.getPlayer() != null && target.isOnline()) {
|
||||||
// Execute commands when leaving
|
// Execute commands when leaving
|
||||||
Util.runCommands(user, getIWM().getOnLeaveCommands(getWorld()), "leave");
|
Util.runCommands(user, getIWM().getOnLeaveCommands(getWorld()), "leave");
|
||||||
// Remove money inventory etc.
|
// Remove money inventory etc.
|
||||||
|
@ -101,6 +101,10 @@ public class AdminSetrankCommand extends CompositeCommand {
|
|||||||
} else {
|
} else {
|
||||||
island = getIslands().getIsland(getWorld(), targetUUID);
|
island = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
}
|
}
|
||||||
|
if (island == null) {
|
||||||
|
user.sendMessage("general.errors.player-has-no-island");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
int currentRank = island.getRank(target);
|
int currentRank = island.getRank(target);
|
||||||
island.setRank(target, rankValue);
|
island.setRank(target, rankValue);
|
||||||
IslandEvent.builder()
|
IslandEvent.builder()
|
||||||
|
@ -19,6 +19,7 @@ import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
|||||||
|
|
||||||
public class AdminTeleportCommand extends CompositeCommand {
|
public class AdminTeleportCommand extends CompositeCommand {
|
||||||
|
|
||||||
|
private static final String NOT_SAFE = "general.errors.no-safe-location-found";
|
||||||
private @Nullable UUID targetUUID;
|
private @Nullable UUID targetUUID;
|
||||||
private @Nullable User userToTeleport;
|
private @Nullable User userToTeleport;
|
||||||
|
|
||||||
@ -86,9 +87,13 @@ public class AdminTeleportCommand extends CompositeCommand {
|
|||||||
} else if (getLabel().equals("tpend")) {
|
} else if (getLabel().equals("tpend")) {
|
||||||
world = getPlugin().getIWM().getEndWorld(getWorld());
|
world = getPlugin().getIWM().getEndWorld(getWorld());
|
||||||
}
|
}
|
||||||
|
if (world == null) {
|
||||||
|
user.sendMessage(NOT_SAFE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Location warpSpot = getSpot(world);
|
Location warpSpot = getSpot(world);
|
||||||
if (world == null || warpSpot == null) {
|
if (warpSpot == null) {
|
||||||
user.sendMessage("general.errors.no-safe-location-found");
|
user.sendMessage(NOT_SAFE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +104,7 @@ public class AdminTeleportCommand extends CompositeCommand {
|
|||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
if (args.size() == 2) {
|
if (args.size() == 2) {
|
||||||
player = userToTeleport.getPlayer();
|
player = userToTeleport.getPlayer();
|
||||||
failureMessage = userToTeleport.getTranslation("general.errors.no-safe-location-found");
|
failureMessage = userToTeleport.getTranslation(NOT_SAFE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Teleport
|
// Teleport
|
||||||
@ -118,7 +123,7 @@ public class AdminTeleportCommand extends CompositeCommand {
|
|||||||
return island.getSpawnPoint(world.getEnvironment());
|
return island.getSpawnPoint(world.getEnvironment());
|
||||||
}
|
}
|
||||||
// Return the default island protection center
|
// Return the default island protection center
|
||||||
return getIslands().getIslandLocation(getWorld(), targetUUID).toVector().toLocation(world);
|
return island.getProtectionCenter().toVector().toLocation(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +64,7 @@ public class AdminBlueprintCommand extends ConfirmableCommand {
|
|||||||
|
|
||||||
protected void showClipboard(User user) {
|
protected void showClipboard(User user) {
|
||||||
displayClipboards.putIfAbsent(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
|
displayClipboards.putIfAbsent(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
|
||||||
if (!user.getPlayer().isOnline()) {
|
if (!user.isPlayer() || !user.getPlayer().isOnline()) {
|
||||||
hideClipboard(user);
|
hideClipboard(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package world.bentobox.bentobox.api.commands.admin.blueprints;
|
package world.bentobox.bentobox.api.commands.admin.blueprints;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -34,7 +35,7 @@ public class AdminBlueprintOriginCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the block player is looking at
|
// Get the block player is looking at
|
||||||
Block b = user.getPlayer().getLineOfSight(null, 20).stream().filter(x -> !x.getType().equals(Material.AIR)).findFirst().orElse(null);
|
Block b = Objects.requireNonNull(user.getPlayer()).getLineOfSight(null, 20).stream().filter(x -> !x.getType().equals(Material.AIR)).findFirst().orElse(null);
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
clipboard.setOrigin(b.getLocation().toVector());
|
clipboard.setOrigin(b.getLocation().toVector());
|
||||||
user.getPlayer().sendBlockChange(b.getLocation(), Material.REDSTONE_BLOCK.createBlockData());
|
user.getPlayer().sendBlockChange(b.getLocation(), Material.REDSTONE_BLOCK.createBlockData());
|
||||||
|
@ -30,7 +30,7 @@ public class AdminBlueprintPos1Command extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
clipboard.setPos1(user.getLocation());
|
clipboard.setPos1(user.getLocation());
|
||||||
user.sendMessage("commands.admin.blueprint.set-pos1", "[vector]", Util.xyz(clipboard.getPos1().toVector()));
|
user.sendMessage("commands.admin.blueprint.set-pos1", "[vector]", Util.xyz(user.getLocation().toVector()));
|
||||||
parent.getClipboards().put(user.getUniqueId(), clipboard);
|
parent.getClipboards().put(user.getUniqueId(), clipboard);
|
||||||
parent.showClipboard(user);
|
parent.showClipboard(user);
|
||||||
return true;
|
return true;
|
||||||
|
@ -30,7 +30,7 @@ public class AdminBlueprintPos2Command extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
clipboard.setPos2(user.getLocation());
|
clipboard.setPos2(user.getLocation());
|
||||||
user.sendMessage("commands.admin.blueprint.set-pos2", "[vector]", Util.xyz((clipboard.getPos2()).toVector()));
|
user.sendMessage("commands.admin.blueprint.set-pos2", "[vector]", Util.xyz(user.getLocation().toVector()));
|
||||||
parent.getClipboards().put(user.getUniqueId(), clipboard);
|
parent.getClipboards().put(user.getUniqueId(), clipboard);
|
||||||
parent.showClipboard(user);
|
parent.showClipboard(user);
|
||||||
return true;
|
return true;
|
||||||
|
@ -55,7 +55,7 @@ public class AdminBlueprintSaveCommand extends ConfirmableCommand {
|
|||||||
private boolean hideAndSave(User user, AdminBlueprintCommand parent, BlueprintClipboard clipboard, String name) {
|
private boolean hideAndSave(User user, AdminBlueprintCommand parent, BlueprintClipboard clipboard, String name) {
|
||||||
parent.hideClipboard(user);
|
parent.hideClipboard(user);
|
||||||
boolean result = new BlueprintClipboardManager(getPlugin(), parent.getBlueprintsFolder(), clipboard).save(user, name);
|
boolean result = new BlueprintClipboardManager(getPlugin(), parent.getBlueprintsFolder(), clipboard).save(user, name);
|
||||||
if (result) {
|
if (result && clipboard.getBlueprint() != null) {
|
||||||
getPlugin().getBlueprintsManager().addBlueprint(getAddon(), clipboard.getBlueprint());
|
getPlugin().getBlueprintsManager().addBlueprint(getAddon(), clipboard.getBlueprint());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package world.bentobox.bentobox.api.commands.admin.range;
|
package world.bentobox.bentobox.api.commands.admin.range;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
@ -52,7 +53,7 @@ public class AdminRangeAddCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
||||||
int newRange = island.getProtectionRange() + Integer.parseInt(args.get(1));
|
int newRange = island.getProtectionRange() + Integer.parseInt(args.get(1));
|
||||||
|
|
||||||
if (newRange > island.getRange() * 2) {
|
if (newRange > island.getRange() * 2) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package world.bentobox.bentobox.api.commands.admin.range;
|
package world.bentobox.bentobox.api.commands.admin.range;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
@ -52,7 +53,7 @@ public class AdminRangeRemoveCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
||||||
int newRange = island.getProtectionRange() - Integer.parseInt(args.get(1));
|
int newRange = island.getProtectionRange() - Integer.parseInt(args.get(1));
|
||||||
|
|
||||||
if (newRange <= 1) {
|
if (newRange <= 1) {
|
||||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.commands.admin.range;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ public class AdminRangeResetCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get island
|
// Get island
|
||||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
||||||
|
|
||||||
// Get old range for event
|
// Get old range for event
|
||||||
int oldRange = island.getProtectionRange();
|
int oldRange = island.getProtectionRange();
|
||||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.commands.admin.range;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ public class AdminRangeSetCommand extends CompositeCommand {
|
|||||||
int range = Integer.parseInt(args.get(1));
|
int range = Integer.parseInt(args.get(1));
|
||||||
|
|
||||||
// Get island
|
// Get island
|
||||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
||||||
|
|
||||||
// Do some sanity checks to make sure the new protection range won't cause problems
|
// Do some sanity checks to make sure the new protection range won't cause problems
|
||||||
if (range < 1) {
|
if (range < 1) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package world.bentobox.bentobox.api.commands.admin.team;
|
package world.bentobox.bentobox.api.commands.admin.team;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
@ -54,11 +55,10 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the User corresponding to the current owner
|
// Get the User corresponding to the current owner
|
||||||
User previousOwner = User.getInstance(previousOwnerUUID);
|
|
||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
|
|
||||||
// Fire event so add-ons know
|
// Fire event so add-ons know
|
||||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
||||||
// Call the setowner event
|
// Call the setowner event
|
||||||
TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(island)
|
.island(island)
|
||||||
@ -82,15 +82,16 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
|
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
|
||||||
|
|
||||||
// Call the rank change event for the old island owner
|
// Call the rank change event for the old island owner
|
||||||
// We need to call it AFTER the actual change.
|
if (previousOwnerUUID != null) {
|
||||||
IslandEvent.builder()
|
// We need to call it AFTER the actual change.
|
||||||
.island(island)
|
IslandEvent.builder()
|
||||||
.involvedPlayer(previousOwnerUUID)
|
.island(island)
|
||||||
.admin(true)
|
.involvedPlayer(previousOwnerUUID)
|
||||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
.admin(true)
|
||||||
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwner))
|
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||||
.build();
|
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwnerUUID))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ public class IslandBanCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check rank to use command
|
// Check rank to use command
|
||||||
Island island = getIslands().getIsland(getWorld(), user);
|
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), user));
|
||||||
int rank = Objects.requireNonNull(island).getRank(user);
|
int rank = island.getRank(user);
|
||||||
if (rank < island.getRankCommand(getUsage())) {
|
if (rank < island.getRankCommand(getUsage())) {
|
||||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||||
return false;
|
return false;
|
||||||
@ -95,7 +95,7 @@ public class IslandBanCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean ban(@NonNull User issuer, User target) {
|
private boolean ban(@NonNull User issuer, User target) {
|
||||||
Island island = getIslands().getIsland(getWorld(), issuer.getUniqueId());
|
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), issuer.getUniqueId()));
|
||||||
|
|
||||||
// Check if player can ban any more players
|
// Check if player can ban any more players
|
||||||
int banLimit = issuer.getPermissionValue(getPermissionPrefix() + "ban.maxlimit", getIWM().getBanLimit(getWorld()));
|
int banLimit = issuer.getPermissionValue(getPermissionPrefix() + "ban.maxlimit", getIWM().getBanLimit(getWorld()));
|
||||||
|
@ -66,7 +66,7 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.island.team.demote.errors.cant-demote-yourself");
|
user.sendMessage("commands.island.team.demote.errors.cant-demote-yourself");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!inTeam(getWorld(), target) || !getOwner(getWorld(), user).equals(getOwner(getWorld(), target))) {
|
if (!inTeam(getWorld(), target) || !Objects.requireNonNull(getOwner(getWorld(), user), "Island has no owner!").equals(getOwner(getWorld(), target))) {
|
||||||
user.sendMessage("general.errors.not-in-team");
|
user.sendMessage("general.errors.not-in-team");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,8 @@ public class TextVariables {
|
|||||||
* @since 1.16.0
|
* @since 1.16.0
|
||||||
*/
|
*/
|
||||||
public static final String XYZ = "[xyz]";
|
public static final String XYZ = "[xyz]";
|
||||||
|
/**
|
||||||
|
* @since 1.17.2
|
||||||
|
*/
|
||||||
|
public static final String UUID = "[uuid]";
|
||||||
}
|
}
|
||||||
|
@ -192,10 +192,12 @@ public class User implements MetaDataAble {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Check if the User is a player before calling this method. {@link #isPlayer()}
|
||||||
* @return the player
|
* @return the player
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return Objects.requireNonNull(player, "User is not a player!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,11 +208,13 @@ public class User implements MetaDataAble {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Use {@link #isOfflinePlayer()} before calling this method
|
||||||
* @return the offline player
|
* @return the offline player
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public OfflinePlayer getOfflinePlayer() {
|
public OfflinePlayer getOfflinePlayer() {
|
||||||
return offlinePlayer;
|
return Objects.requireNonNull(offlinePlayer, "User is not an OfflinePlayer!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,6 +151,7 @@ public class BlueprintClipboard {
|
|||||||
}
|
}
|
||||||
if (index > vectorsToCopy.size()) {
|
if (index > vectorsToCopy.size()) {
|
||||||
copyTask.cancel();
|
copyTask.cancel();
|
||||||
|
assert blueprint != null;
|
||||||
blueprint.setAttached(bpAttachable);
|
blueprint.setAttached(bpAttachable);
|
||||||
blueprint.setBlocks(bpBlocks);
|
blueprint.setBlocks(bpBlocks);
|
||||||
blueprint.setEntities(bpEntities);
|
blueprint.setEntities(bpEntities);
|
||||||
|
@ -193,7 +193,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
private Boolean reserved = null;
|
private Boolean reserved = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A place to store meta data for this island.
|
* A place to store metadata for this island.
|
||||||
* @since 1.15.4
|
* @since 1.15.4
|
||||||
*/
|
*/
|
||||||
@Expose
|
@Expose
|
||||||
@ -354,7 +354,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Island Guard flag's setting. If this is a protection flag, the this will be the
|
* Gets the Island Guard flag's setting. If this is a protection flag, then this will be the
|
||||||
* rank needed to bypass this flag. If it is a Settings flag, any non-zero value means the
|
* rank needed to bypass this flag. If it is a Settings flag, any non-zero value means the
|
||||||
* setting is allowed.
|
* setting is allowed.
|
||||||
* @param flag - flag
|
* @param flag - flag
|
||||||
@ -427,41 +427,41 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the minimum protected X block coord based on the island location.
|
* Get the minimum protected X block coordinate based on the island location.
|
||||||
* It will never be less than {@link #getMinX()}
|
* It will never be less than {@link #getMinX()}
|
||||||
* @return the minProtectedX
|
* @return the minProtectedX
|
||||||
*/
|
*/
|
||||||
public int getMinProtectedX() {
|
public int getMinProtectedX() {
|
||||||
return getProtectionCenter() == null ? 0 : Math.max(getMinX(), getProtectionCenter().getBlockX() - protectionRange);
|
return Math.max(getMinX(), getProtectionCenter().getBlockX() - protectionRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the maximum protected X block coord based on the island location.
|
* Get the maximum protected X block coordinate based on the island location.
|
||||||
* It will never be more than {@link #getMaxX()}
|
* It will never be more than {@link #getMaxX()}
|
||||||
* @return the maxProtectedX
|
* @return the maxProtectedX
|
||||||
* @since 1.5.2
|
* @since 1.5.2
|
||||||
*/
|
*/
|
||||||
public int getMaxProtectedX() {
|
public int getMaxProtectedX() {
|
||||||
return getProtectionCenter() == null ? 0 : Math.min(getMaxX(), getProtectionCenter().getBlockX() + protectionRange);
|
return Math.min(getMaxX(), getProtectionCenter().getBlockX() + protectionRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the minimum protected Z block coord based on the island location.
|
* Get the minimum protected Z block coordinate based on the island location.
|
||||||
* It will never be less than {@link #getMinZ()}
|
* It will never be less than {@link #getMinZ()}
|
||||||
* @return the minProtectedZ
|
* @return the minProtectedZ
|
||||||
*/
|
*/
|
||||||
public int getMinProtectedZ() {
|
public int getMinProtectedZ() {
|
||||||
return getProtectionCenter() == null ? 0 : Math.max(getMinZ(), getProtectionCenter().getBlockZ() - protectionRange);
|
return Math.max(getMinZ(), getProtectionCenter().getBlockZ() - protectionRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the maximum protected Z block coord based on the island location.
|
* Get the maximum protected Z block coordinate based on the island location.
|
||||||
* It will never be more than {@link #getMinZ()}
|
* It will never be more than {@link #getMinZ()}
|
||||||
* @return the maxProtectedZ
|
* @return the maxProtectedZ
|
||||||
* @since 1.5.2
|
* @since 1.5.2
|
||||||
*/
|
*/
|
||||||
public int getMaxProtectedZ() {
|
public int getMaxProtectedZ() {
|
||||||
return getProtectionCenter() == null ? 0 : Math.min(getMaxZ(), getProtectionCenter().getBlockZ() + protectionRange);
|
return Math.min(getMaxZ(), getProtectionCenter().getBlockZ() + protectionRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -998,7 +998,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
* Sets whether this island is a spawn or not.
|
* Sets whether this island is a spawn or not.
|
||||||
* <br/>
|
* <br/>
|
||||||
* If {@code true}, the members and the owner will be removed from this island.
|
* If {@code true}, the members and the owner will be removed from this island.
|
||||||
* The flags will also be resetted to default values.
|
* The flags will also be reset to default values.
|
||||||
* @param isSpawn {@code true} if the island is a spawn, {@code false} otherwise.
|
* @param isSpawn {@code true} if the island is a spawn, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
public void setSpawn(boolean isSpawn){
|
public void setSpawn(boolean isSpawn){
|
||||||
@ -1380,7 +1380,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
* @return a clone of the protection center location
|
* @return a clone of the protection center location
|
||||||
* @since 1.16.0
|
* @since 1.16.0
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@NonNull
|
||||||
public Location getProtectionCenter() {
|
public Location getProtectionCenter() {
|
||||||
return location == null ? getCenter() : location.clone();
|
return location == null ? getCenter() : location.clone();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.listeners;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -35,14 +36,15 @@ public class BlockEndDragon implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void testLocation(Location location) {
|
private void testLocation(Location location) {
|
||||||
if (!plugin.getIWM().isIslandEnd(location.getWorld())
|
World w = location.getWorld();
|
||||||
|| !Flags.REMOVE_END_EXIT_ISLAND.isSetForWorld(location.getWorld())
|
if (w == null || !plugin.getIWM().isIslandEnd(w)
|
||||||
|| location.getWorld().getBlockAt(0, 255, 0).getType().equals(Material.END_PORTAL)) {
|
|| !Flags.REMOVE_END_EXIT_ISLAND.isSetForWorld(w)
|
||||||
|
|| w.getBlockAt(0, 255, 0).getType().equals(Material.END_PORTAL)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting a End Portal at the top will trick dragon legacy check.
|
// Setting a End Portal at the top will trick dragon legacy check.
|
||||||
location.getWorld().getBlockAt(0, 255, 0).setType(Material.END_PORTAL, false);
|
w.getBlockAt(0, 255, 0).setType(Material.END_PORTAL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +44,7 @@ public class BlockInteractionListener extends FlagListener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerInteract(final PlayerInteractEvent e) {
|
public void onPlayerInteract(final PlayerInteractEvent e) {
|
||||||
// We only care about the RIGHT_CLICK_BLOCK action.
|
// We only care about the RIGHT_CLICK_BLOCK action.
|
||||||
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getClickedBlock() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package world.bentobox.bentobox.managers;
|
package world.bentobox.bentobox.managers;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -97,8 +94,13 @@ public class AddonsManager {
|
|||||||
plugin.log("Registering " + parent.getDescription().getName());
|
plugin.log("Registering " + parent.getDescription().getName());
|
||||||
|
|
||||||
// Get description in the addon.yml file
|
// Get description in the addon.yml file
|
||||||
|
InputStream resource = parent.getResource("addon.yml");
|
||||||
|
if (resource == null) {
|
||||||
|
plugin.logError("Failed to register addon: no addon.yml found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Open a reader to the jar
|
// Open a reader to the jar
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(parent.getResource("addon.yml")))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource))) {
|
||||||
setAddonFile(parent, addon);
|
setAddonFile(parent, addon);
|
||||||
// Grab the description in the addon.yml file
|
// Grab the description in the addon.yml file
|
||||||
YamlConfiguration data = new YamlConfiguration();
|
YamlConfiguration data = new YamlConfiguration();
|
||||||
@ -266,7 +268,11 @@ public class AddonsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void registerPermission(ConfigurationSection perms, String perm) throws InvalidAddonDescriptionException {
|
void registerPermission(ConfigurationSection perms, String perm) throws InvalidAddonDescriptionException {
|
||||||
PermissionDefault pd = PermissionDefault.getByName(perms.getString(perm + DEFAULT));
|
String name = perms.getString(perm + DEFAULT);
|
||||||
|
if (name == null) {
|
||||||
|
throw new InvalidAddonDescriptionException("Permission default is invalid in addon.yml: " + perm + DEFAULT);
|
||||||
|
}
|
||||||
|
PermissionDefault pd = PermissionDefault.getByName(name);
|
||||||
if (pd == null) {
|
if (pd == null) {
|
||||||
throw new InvalidAddonDescriptionException("Permission default is invalid in addon.yml: " + perm + DEFAULT);
|
throw new InvalidAddonDescriptionException("Permission default is invalid in addon.yml: " + perm + DEFAULT);
|
||||||
}
|
}
|
||||||
@ -503,7 +509,7 @@ public class AddonsManager {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Class<?> getClassByName(@NonNull final String name) {
|
public Class<?> getClassByName(@NonNull final String name) {
|
||||||
try {
|
try {
|
||||||
return classes.getOrDefault(name, loaders.values().stream().map(l -> l.findClass(name, false)).filter(Objects::nonNull).findFirst().orElse(null));
|
return classes.getOrDefault(name, loaders.values().stream().filter(Objects::nonNull).map(l -> l.findClass(name, false)).filter(Objects::nonNull).findFirst().orElse(null));
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
// Ignored.
|
// Ignored.
|
||||||
}
|
}
|
||||||
|
@ -144,10 +144,12 @@ public class BlueprintClipboardManager {
|
|||||||
* @return - true if successful, false if error
|
* @return - true if successful, false if error
|
||||||
*/
|
*/
|
||||||
public boolean save(User user, String newName) {
|
public boolean save(User user, String newName) {
|
||||||
clipboard.getBlueprint().setName(newName);
|
if (clipboard.getBlueprint() != null) {
|
||||||
if (saveBlueprint(clipboard.getBlueprint())) {
|
clipboard.getBlueprint().setName(newName);
|
||||||
user.sendMessage("general.success");
|
if (saveBlueprint(clipboard.getBlueprint())) {
|
||||||
return true;
|
user.sendMessage("general.success");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
user.sendMessage("commands.admin.blueprint.could-not-save", "[message]", "Could not save temp blueprint file.");
|
user.sendMessage("commands.admin.blueprint.could-not-save", "[message]", "Could not save temp blueprint file.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -44,11 +44,11 @@ public class IslandInfo {
|
|||||||
*/
|
*/
|
||||||
public void showAdminInfo(User user) {
|
public void showAdminInfo(User user) {
|
||||||
user.sendMessage("commands.admin.info.title");
|
user.sendMessage("commands.admin.info.title");
|
||||||
user.sendMessage("commands.admin.info.island-uuid", "[uuid]", island.getUniqueId());
|
user.sendMessage("commands.admin.info.island-uuid", TextVariables.UUID, island.getUniqueId());
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
user.sendMessage("commands.admin.info.unowned");
|
user.sendMessage("commands.admin.info.unowned");
|
||||||
} else {
|
} else {
|
||||||
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner), "[uuid]", owner.toString());
|
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner), TextVariables.UUID, owner.toString());
|
||||||
|
|
||||||
// Fixes #getLastPlayed() returning 0 when it is the owner's first connection.
|
// Fixes #getLastPlayed() returning 0 when it is the owner's first connection.
|
||||||
long lastPlayed = (Bukkit.getOfflinePlayer(owner).getLastPlayed() != 0) ?
|
long lastPlayed = (Bukkit.getOfflinePlayer(owner).getLastPlayed() != 0) ?
|
||||||
@ -99,7 +99,7 @@ public class IslandInfo {
|
|||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
user.sendMessage("commands.admin.info.unowned");
|
user.sendMessage("commands.admin.info.unowned");
|
||||||
} else {
|
} else {
|
||||||
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner));
|
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner), TextVariables.UUID, owner.toString());
|
||||||
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
|
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
|
||||||
String resets = String.valueOf(plugin.getPlayers().getResets(world, owner));
|
String resets = String.valueOf(plugin.getPlayers().getResets(world, owner));
|
||||||
String total = plugin.getIWM().getResetLimit(world) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(world));
|
String total = plugin.getIWM().getResetLimit(world) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(world));
|
||||||
|
@ -164,6 +164,11 @@ public class AdminTeleportCommandTest {
|
|||||||
|
|
||||||
// Return an island for spawn checking
|
// Return an island for spawn checking
|
||||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||||
|
|
||||||
|
when(island.getCenter()).thenReturn(location);
|
||||||
|
when(location.clone()).thenReturn(location);
|
||||||
|
when(location.toVector()).thenReturn(new Vector(0,0,0));
|
||||||
|
when(island.getProtectionCenter()).thenReturn(location);
|
||||||
// Util
|
// Util
|
||||||
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
|
||||||
when(Util.getUUID(anyString())).thenCallRealMethod();
|
when(Util.getUUID(anyString())).thenCallRealMethod();
|
||||||
|
@ -196,7 +196,7 @@ public class IslandInfoCommandTest {
|
|||||||
public void testExecuteUserStringListOfStringNoArgsSuccess() {
|
public void testExecuteUserStringListOfStringNoArgsSuccess() {
|
||||||
assertTrue(iic.execute(user, "", Collections.emptyList()));
|
assertTrue(iic.execute(user, "", Collections.emptyList()));
|
||||||
verify(user).sendMessage("commands.admin.info.title");
|
verify(user).sendMessage("commands.admin.info.title");
|
||||||
verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null));
|
verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null), eq("[uuid]"), anyString());
|
||||||
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
|
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
|
||||||
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
|
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
|
||||||
verify(user).sendMessage("commands.admin.info.team-members-title");
|
verify(user).sendMessage("commands.admin.info.team-members-title");
|
||||||
@ -213,7 +213,7 @@ public class IslandInfoCommandTest {
|
|||||||
public void testExecuteUserStringListOfStringArgsSuccess() {
|
public void testExecuteUserStringListOfStringArgsSuccess() {
|
||||||
assertTrue(iic.execute(user, "", Collections.singletonList("tastybento")));
|
assertTrue(iic.execute(user, "", Collections.singletonList("tastybento")));
|
||||||
verify(user).sendMessage("commands.admin.info.title");
|
verify(user).sendMessage("commands.admin.info.title");
|
||||||
verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null));
|
verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null), eq("[uuid]"), anyString());
|
||||||
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
|
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
|
||||||
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
|
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
|
||||||
verify(user).sendMessage("commands.admin.info.team-members-title");
|
verify(user).sendMessage("commands.admin.info.team-members-title");
|
||||||
|
@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
@ -164,7 +163,6 @@ public class UserTest {
|
|||||||
// If the player has been removed from the cache, then code will ask server for player
|
// If the player has been removed from the cache, then code will ask server for player
|
||||||
// Return null and check if instance is null will show that the player is not in the cache
|
// Return null and check if instance is null will show that the player is not in the cache
|
||||||
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(null);
|
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(null);
|
||||||
assertNull(User.getInstance(uuid).getPlayer());
|
|
||||||
verify(pm).removePlayer(player);
|
verify(pm).removePlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user