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

View File

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

View File

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

View File

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

View File

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

View File

@ -64,9 +64,7 @@ public class Converter {
.map(this::convertLegacyEntity)
// Collect into a map
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (le != null) {
bp.setEntities(le);
}
bp.setEntities(le);
}
// Attached blocks
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} )
public class TNTListenerTest {
private static Location location;
private static BentoBox plugin;
private static Notifier notifier;
private Location location;
private BentoBox plugin;
private Notifier notifier;
@Before
public void setUp() {