Code smell improvements and null protections

This commit is contained in:
tastybento 2019-08-10 11:44:29 -07:00
parent 1d6dba8d59
commit b5202c3944
7 changed files with 11 additions and 9 deletions

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.panels.builders; package world.bentobox.bentobox.api.panels.builders;
import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -16,7 +17,7 @@ import world.bentobox.bentobox.api.user.User;
*/ */
public class PanelBuilder { public class PanelBuilder {
private String name; private String name;
private final TreeMap<Integer, PanelItem> items = new TreeMap<>(); private final SortedMap<Integer, PanelItem> items = new TreeMap<>();
private int size; private int size;
private User user; private User user;
private PanelListener listener; private PanelListener listener;
@ -120,7 +121,7 @@ public class PanelBuilder {
/** /**
* @return the items * @return the items
*/ */
public TreeMap<Integer, PanelItem> getItems() { public SortedMap<Integer, PanelItem> getItems() {
return items; return items;
} }

View File

@ -254,7 +254,6 @@ public class BlueprintPaster {
// Center, and just a bit high // Center, and just a bit high
Location center = location.add(new Vector(0.5, 0.5, 0.5)); Location center = location.add(new Vector(0.5, 0.5, 0.5));
LivingEntity e = (LivingEntity)location.getWorld().spawnEntity(center, k.getType()); LivingEntity e = (LivingEntity)location.getWorld().spawnEntity(center, k.getType());
if (e == null) return;
if (k.getCustomName() != null) { if (k.getCustomName() != null) {
e.setCustomName(k.getCustomName()); e.setCustomName(k.getCustomName());
} }

View File

@ -214,6 +214,7 @@ public class Island implements DataObject {
this.world = island.world; this.world = island.world;
this.cooldowns = island.cooldowns; this.cooldowns = island.cooldowns;
this.commandRanks = island.commandRanks; this.commandRanks = island.commandRanks;
this.reserved = island.reserved;
} }
/* /*

View File

@ -153,6 +153,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
continue; continue;
} }
// Get the getter and setters for this field using the JavaBeans system // Get the getter and setters for this field using the JavaBeans system
//noinspection RedundantCast
PropertyDescriptor propertyDescriptor = new PropertyDescriptor((String)field.getName(), dataObject); PropertyDescriptor propertyDescriptor = new PropertyDescriptor((String)field.getName(), dataObject);
// Get the write method // Get the write method
Method method = propertyDescriptor.getWriteMethod(); Method method = propertyDescriptor.getWriteMethod();
@ -344,6 +345,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
continue; continue;
} }
// Get the property descriptor for this field // Get the property descriptor for this field
//noinspection RedundantCast
PropertyDescriptor propertyDescriptor = new PropertyDescriptor((String)field.getName(), dataObject); PropertyDescriptor propertyDescriptor = new PropertyDescriptor((String)field.getName(), dataObject);
// Get the read method // Get the read method
Method method = propertyDescriptor.getReadMethod(); Method method = propertyDescriptor.getReadMethod();

View File

@ -50,6 +50,7 @@ public class CommandsManager {
try { try {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Command> knownCommands = (Map<String, Command>) commandMap.getClass().getMethod("getKnownCommands").invoke(commandMap); Map<String, Command> knownCommands = (Map<String, Command>) commandMap.getClass().getMethod("getKnownCommands").invoke(commandMap);
//noinspection SuspiciousMethodCalls
knownCommands.values().removeIf(commands.values()::contains); knownCommands.values().removeIf(commands.values()::contains);
// Not sure if this is needed, but it clears out all references // Not sure if this is needed, but it clears out all references
commands.values().forEach(c -> c.unregister(commandMap)); commands.values().forEach(c -> c.unregister(commandMap));

View File

@ -64,9 +64,7 @@ public class Converter {
.map(this::convertLegacyEntity) .map(this::convertLegacyEntity)
// Collect into a map // Collect into a map
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (le != null) { bp.setEntities(le);
bp.setEntities(le);
}
} }
// Attached blocks // Attached blocks
if (bc.isConfigurationSection(ATTACHED_YAML_PREFIX)) { if (bc.isConfigurationSection(ATTACHED_YAML_PREFIX)) {

View File

@ -67,9 +67,9 @@ import world.bentobox.bentobox.util.Util;
@PrepareForTest( {BentoBox.class, Flags.class, Util.class, Bukkit.class} ) @PrepareForTest( {BentoBox.class, Flags.class, Util.class, Bukkit.class} )
public class TNTListenerTest { public class TNTListenerTest {
private static Location location; private Location location;
private static BentoBox plugin; private BentoBox plugin;
private static Notifier notifier; private Notifier notifier;
@Before @Before
public void setUp() { public void setUp() {