Fixed code smells (#1444)

* Code smell changes

* Fixes issues raised in reviews.
This commit is contained in:
tastybento 2020-07-09 00:03:01 -07:00 committed by GitHub
parent 44903e98cb
commit bdbfd33a34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 66 additions and 71 deletions

View File

@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Set;
import org.bukkit.Material;
import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.api.configuration.ConfigEntry;
import world.bentobox.bentobox.api.configuration.ConfigObject;

View File

@ -24,7 +24,6 @@ public class AdminGetrankCommand extends CompositeCommand {
private Island island;
private @Nullable UUID targetUUID;
private @Nullable UUID ownerUUID;
public AdminGetrankCommand(CompositeCommand adminCommand) {
super(adminCommand, "getrank");
@ -64,7 +63,7 @@ public class AdminGetrankCommand extends CompositeCommand {
} else {
// We want to get the rank of the player on the island of the owner we specify.
// So we have to make sure that the island owner actually owns an island
ownerUUID = getPlayers().getUUID(args.get(1));
@Nullable UUID ownerUUID = getPlayers().getUUID(args.get(1));
if (ownerUUID == null) {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(1));
return false;

View File

@ -1,11 +1,12 @@
package world.bentobox.bentobox.api.commands.admin;
import org.bukkit.World;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.bukkit.World;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User;

View File

@ -31,8 +31,8 @@ public abstract class DefaultAdminCommand extends CompositeCommand {
public DefaultAdminCommand(GameModeAddon addon) {
// Register command with alias from config.
super(addon,
addon.getWorldSettings().getAdminCommandAliases().split(" ")[0],
addon.getWorldSettings().getAdminCommandAliases().split(" "));
addon.getWorldSettings().getAdminCommandAliases().split(" ")[0],
addon.getWorldSettings().getAdminCommandAliases().split(" "));
}
/**
@ -92,7 +92,7 @@ public abstract class DefaultAdminCommand extends CompositeCommand {
/**
* Defines what will be executed when this command is run.
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(User, String, List<String>)
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(User, String, List&lt;String&gt;)
*/
@Override
public boolean execute(User user, String label, List<String> args) {

View File

@ -10,7 +10,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Particle;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User;
@ -55,7 +54,7 @@ public class AdminBlueprintCommand extends ConfirmableCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
new BlueprintManagementPanel(getPlugin(), user, (GameModeAddon)getAddon()).openPanel();
new BlueprintManagementPanel(getPlugin(), user, getAddon()).openPanel();
return true;
}

View File

@ -1,15 +1,15 @@
package world.bentobox.bentobox.api.commands.admin.blueprints;
import java.io.File;
import java.util.List;
import java.util.Locale;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.blueprints.Blueprint;
import world.bentobox.bentobox.managers.BlueprintsManager;
import java.io.File;
import java.util.List;
import java.util.Locale;
/**
* Renames an existing blueprint.
* @author Poslovitch

View File

@ -84,7 +84,7 @@ public abstract class DefaultPlayerCommand extends CompositeCommand
/**
* Defines what will be executed when this command is run.
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(User, String, List<String>)
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(User, String, List&lt;String&gt;)
*/
@Override
public boolean execute(User user, String label, List<String> args)

View File

@ -62,13 +62,11 @@ public class IslandBanlistCommand extends CompositeCommand {
StringBuilder line = new StringBuilder();
// Put the names into lines of no more than 40 characters long, separated by commas
names.forEach(n -> {
if (line.length() + n.length() < 41) {
line.append(n);
} else {
if (line.length() + n.length() >= 41) {
lines.add(line.toString().trim());
line.setLength(0);
line.append(n);
}
line.append(n);
line.append(", ");
});
// Remove trailing comma

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -80,7 +79,7 @@ public class IslandResetCommand extends ConfirmableCommand {
public boolean execute(User user, String label, List<String> args) {
// Permission check if the name is not the default one
if (!args.isEmpty()) {
String name = getPlugin().getBlueprintsManager().validate((GameModeAddon)getAddon(), args.get(0).toLowerCase(java.util.Locale.ENGLISH));
String name = getPlugin().getBlueprintsManager().validate(getAddon(), args.get(0).toLowerCase(java.util.Locale.ENGLISH));
if (name == null || name.isEmpty()) {
// The blueprint name is not valid.
user.sendMessage("commands.island.create.unknown-blueprint");
@ -107,7 +106,7 @@ public class IslandResetCommand extends ConfirmableCommand {
*/
private void selectBundle(@NonNull User user, @NonNull String label) {
// Show panel only if there are multiple bundles available
if (getPlugin().getBlueprintsManager().getBlueprintBundles((GameModeAddon)getAddon()).size() > 1) {
if (getPlugin().getBlueprintsManager().getBlueprintBundles(getAddon()).size() > 1) {
// Show panel - once the player selected a bundle, this will re-run this command
IslandCreationPanel.openPanel(this, user, label);
} else {

View File

@ -51,7 +51,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
return false;
}
UUID playerUUID = user.getUniqueId();
if (args.isEmpty() || args.size() > 1) {
if (args.size() != 1) {
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far and why
if (itc.isInvited(playerUUID)) {
Invite invite = itc.getInvite(playerUUID);

View File

@ -602,16 +602,15 @@ public class Flag implements Comparable<Flag> {
public Flag build() {
// If no clickHandler has been set, then apply default ones
if (clickHandler == null) {
switch (type){
case PROTECTION:
clickHandler = new CycleClick(id);
break;
switch (type) {
case SETTING:
clickHandler = new IslandToggleClick(id);
break;
case WORLD_SETTING:
clickHandler = new WorldToggleClick(id);
break;
case PROTECTION:
// Default option
default:
clickHandler = new CycleClick(id);
break;

View File

@ -97,12 +97,11 @@ public class PanelItem {
if (invisible) {
meta.addEnchant(Enchantment.VANISHING_CURSE, 1, true);
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
icon.setItemMeta(meta);
} else {
meta.removeEnchant(Enchantment.VANISHING_CURSE);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
icon.setItemMeta(meta);
}
icon.setItemMeta(meta);
}
}

View File

@ -589,7 +589,7 @@ public class User {
* @param z Z coordinate of the particle to display.
*/
public void spawnParticle(Particle particle, Particle.DustOptions dustOptions, int x, int y, int z) {
spawnParticle(particle, dustOptions, (double) x, (double) y, (double) z);
spawnParticle(particle, dustOptions, x, y, z);
}
/* (non-Javadoc)

View File

@ -25,11 +25,11 @@ public class Blueprint {
* Unique name for this blueprint. The filename will be this plus the blueprint suffix
*/
@Expose
private @NonNull String name;
private @NonNull String name = "";
@Expose
private String displayName;
@Expose
private @NonNull Material icon;
private @NonNull Material icon = Material.PAPER;
@Expose
private List<String> description;
@Expose

View File

@ -105,7 +105,6 @@ public class BlueprintPaster {
* @param plugin - BentoBox
* @param clipboard - clipboard to paste
* @param location - location to paste to
* @param task - task to run after pasting, null if none
*/
public BlueprintPaster(@NonNull BentoBox plugin, @NonNull BlueprintClipboard clipboard, @NonNull Location location) {
this.plugin = plugin;
@ -125,7 +124,6 @@ public class BlueprintPaster {
* @param bp - blueprint to paste
* @param world - world to paste to
* @param island - island related to this paste
* @param task - task to run after pasting
*/
public BlueprintPaster(@NonNull BentoBox plugin, @NonNull Blueprint bp, World world, @NonNull Island island) {
this.plugin = plugin;

View File

@ -47,7 +47,7 @@ public class BentoBoxVersionCommand extends CompositeCommand {
user.sendMessage("commands.bentobox.version.database", "[database]", getSettings().getDatabaseType().toString());
user.sendMessage("commands.bentobox.version.loaded-game-worlds");
getIWM().getOverWorldNames().entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey))
getIWM().getOverWorldNames().entrySet().stream().sorted(Map.Entry.comparingByKey())
.forEach(e -> {
String worlds = user.getTranslation("general.worlds.overworld");

View File

@ -1,12 +1,12 @@
package world.bentobox.bentobox.commands.reload;
import java.util.List;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.commands.BentoBoxReloadCommand;
import world.bentobox.bentobox.listeners.PanelListenerManager;
import java.util.List;
/**
* Reloads locales files.
*

View File

@ -3,10 +3,14 @@ package world.bentobox.bentobox.database.mongodb;
import java.util.HashSet;
import java.util.Set;
import com.mongodb.*;
import org.bukkit.Bukkit;
import org.eclipse.jdt.annotation.NonNull;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;

View File

@ -6,13 +6,13 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target(TYPE)
/**
* Annotation to explicitly name tables
* @author tastybento
* @since 1.14.0
*/
@Retention(RUNTIME)
@Target(TYPE)
public @interface Table {
/**
* @return name of the table to be used in the database

View File

@ -39,10 +39,11 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
.renameTable("ALTER TABLE `[oldTableName]` RENAME TO `[tableName]`"));
}
@Override
/**
* Creates the table in the database if it doesn't exist already
*/
@Override
protected void createSchema() {
if (getSqlConfig().renameRequired()) {
// SQLite does not have a rename if exists command so we have to manually check if the old table exists

View File

@ -34,9 +34,6 @@ public class ConfigHandler<T> extends YamlDatabaseHandler<T> {
}
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, NoSuchMethodException {
if (dbConfig == null) {
return loadObject(uniqueId);
}
// TODO: compare the loaded with the database copy

View File

@ -330,7 +330,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
* Inserts T into the corresponding database-table
*
* @param instance that should be inserted into the database
* @return
* @return CompletableFuture that will be true if object is saved successfully
*/
@SuppressWarnings("unchecked")
@Override

View File

@ -5,6 +5,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;

View File

@ -1,8 +1,10 @@
package world.bentobox.bentobox.listeners.flags.protection;
import com.destroystokyo.paper.event.player.PlayerPickupExperienceEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import com.destroystokyo.paper.event.player.PlayerPickupExperienceEvent;
import world.bentobox.bentobox.lists.Flags;
/**

View File

@ -258,7 +258,7 @@ public class AddonsManager {
/**
* Handles an addon which failed to load due to an incompatibility (missing class, missing method).
* @param addon instance of the Addon.
* @param e
* @param e - linkage exception
* @since 1.1
*/
private void handleAddonIncompatibility(@NonNull Addon addon, LinkageError e) {
@ -439,7 +439,7 @@ public class AddonsManager {
public Class<?> getClassByName(@NonNull final String name) {
try {
return classes.getOrDefault(name, loaders.values().stream().map(l -> l.findClass(name, false)).filter(Objects::nonNull).findFirst().orElse(null));
} catch (Exception e) {}
} catch (Exception ignored) {}
return null;
}

View File

@ -125,7 +125,7 @@ public class FlagsManager {
/**
* Unregister a specific flag
* @param Flag - flag
* @param flag - flag
* @since 1.14.0
*/
public void unregister(@NonNull Flag flag) {

View File

@ -20,9 +20,9 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.localization.BentoBoxLocale;

View File

@ -239,7 +239,7 @@ public class WebManager {
/**
*
* @param repository
* @param repository - name of the repo
* @return list of contributors
* @since 1.9.0
*/

View File

@ -142,7 +142,7 @@ public class NewIsland {
/**
* @return Island
* @throws Exception
* @throws IOException - if there are insufficient parameters, i.e., no user
*/
public Island build() throws IOException {
if (user2 != null) {

View File

@ -65,9 +65,6 @@ public class ItemParser {
// Rearrange
String[] twoer = {part[0], part[2]};
ItemStack result = two(twoer);
if (result == null) {
return null;
}
return result;
}

View File

@ -3,7 +3,6 @@ package world.bentobox.bentobox.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
@ -531,8 +530,7 @@ public class Util {
*/
private static boolean isJUnitTest() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
List<StackTraceElement> list = Arrays.asList(stackTrace);
for (StackTraceElement element : list) {
for (StackTraceElement element : stackTrace) {
if (element.getClassName().startsWith("org.junit.")) {
return true;
}

View File

@ -10,8 +10,8 @@ public class HeadCache {
private final ItemStack head;
private final long timestamp;
/**
* @param head
* @param timestamp
* @param head - head ItemStack
* @param timestamp - timestamp when made
*/
public HeadCache(ItemStack head, long timestamp) {
super();

View File

@ -1,5 +1,14 @@
package world.bentobox.bentobox.api.commands.admin.purge;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.junit.After;
@ -12,6 +21,7 @@ import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
@ -21,15 +31,6 @@ import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import java.util.Collections;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* @author Poslovitch
*

View File

@ -7,9 +7,9 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.never;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -16,7 +16,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.UUID;
import com.google.common.collect.ImmutableSet;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
@ -31,6 +30,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import com.google.common.collect.ImmutableSet;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.localization.TextVariables;

View File

@ -6,10 +6,10 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.never;
import java.util.Collections;
import java.util.HashMap;

View File

@ -6,10 +6,10 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.never;
import java.util.Arrays;
import java.util.HashMap;