Preveent NPEs and other items.

This commit is contained in:
tastybento 2021-11-12 15:39:52 -08:00
parent 7616f6aa2a
commit 7277432c41
3 changed files with 57 additions and 24 deletions

View File

@ -7,6 +7,9 @@
package world.bentobox.bentobox.api.panels.reader;
import java.util.Arrays;
import java.util.Objects;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
@ -76,4 +79,32 @@ public record PanelTemplateRecord(Panel.Type type,
this(icon, null, null);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.deepHashCode(content);
result = prime * result + Arrays.hashCode(forcedRows);
result = prime * result + Objects.hash(background, border, title, type);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof PanelTemplateRecord)) {
return false;
}
PanelTemplateRecord other = (PanelTemplateRecord) obj;
return Objects.equals(background, other.background) && Objects.equals(border, other.border)
&& Arrays.deepEquals(content, other.content) && Arrays.equals(forcedRows, other.forcedRows)
&& Objects.equals(title, other.title) && type == other.type;
}
}

View File

@ -60,10 +60,12 @@ public class IslandRespawnListener extends FlagListener {
if (world == null) {
return; // world no longer available
}
final Location respawnLocation = getIslands().getSafeHomeLocation(Util.getWorld(world), User.getInstance(e.getPlayer().getUniqueId()), "");
if (respawnLocation != null) {
e.setRespawnLocation(respawnLocation);
World w = Util.getWorld(world);
if (w != null) {
final Location respawnLocation = getIslands().getSafeHomeLocation(w, User.getInstance(e.getPlayer().getUniqueId()), "");
if (respawnLocation != null) {
e.setRespawnLocation(respawnLocation);
}
}
// Run respawn commands, if any
Util.runCommands(User.getInstance(e.getPlayer()), getIWM().getOnRespawnCommands(world), "respawn");

View File

@ -183,7 +183,7 @@ public class BlueprintManagementPanel {
// Toggle permission - default is always allowed
pb.item(39, getNoPermissionIcon());
} else {
// Panel has a Trash icon. If right clicked it is discarded
// Panel has a Trash icon. If right clicked it is discarded
pb.item(36, getTrashIcon(addon, bb));
// Toggle permission - default is always allowed
pb.item(39, getPermissionIcon(addon, bb));
@ -256,22 +256,22 @@ public class BlueprintManagementPanel {
Material icon;
String worldName;
switch (env) {
case NORMAL -> {
icon = Material.GRASS_BLOCK;
worldName = normalBlueprint.getName();
}
case NETHER -> {
icon = Material.NETHERRACK;
worldName = netherBlueprint.getName();
}
case THE_END -> {
icon = Material.END_STONE;
worldName = endBlueprint.getName();
}
default -> {
icon = Material.STONE;
worldName = Util.prettifyText(env.name());
}
case NORMAL -> {
icon = Material.GRASS_BLOCK;
worldName = normalBlueprint.getName();
}
case NETHER -> {
icon = Material.NETHERRACK;
worldName = netherBlueprint.getName();
}
case THE_END -> {
icon = Material.END_STONE;
worldName = endBlueprint.getName();
}
default -> {
icon = Material.STONE;
worldName = Util.prettifyText(env.name());
}
}
return new PanelItemBuilder()
@ -297,7 +297,7 @@ public class BlueprintManagementPanel {
})
.build();
}
private PanelItem getNoTrashIcon() {
return new PanelItemBuilder()
.name(t("no-trash"))
@ -321,7 +321,7 @@ public class BlueprintManagementPanel {
return true;
}).build();
}
private PanelItem getNoPermissionIcon() {
return new PanelItemBuilder().icon(Material.PAINTING).name(t("no-permission"))
.description(t("no-perm-required"))
@ -350,7 +350,7 @@ public class BlueprintManagementPanel {
return new PanelItemBuilder()
.name(blueprint.getDisplayName() == null ? blueprint.getName() : blueprint.getDisplayName())
.description(desc)
.icon(blueprint.getIcon() == null ? Material.PAPER : blueprint.getIcon())
.icon(blueprint.getIcon())
.glow(selected != null && pos == selected.getKey())
.clickHandler((panel, u, clickType, slot) -> {
// Handle the world squares