Fixed some code smells

This commit is contained in:
Florian CUNY 2018-08-15 09:43:28 +02:00
parent fc066a04a3
commit 539d2a0516
8 changed files with 15 additions and 32 deletions

View File

@ -125,8 +125,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
// Register command if it is not already registered
if (plugin.getCommand(label) == null) {
plugin.getCommandsManager().registerCommand(this);
// register your completions.
//registerCompletions(plugin.getCommodore(), this);
}
// Default references to description and parameters
setDescription("commands." + label + ".description");

View File

@ -47,7 +47,7 @@ public class AdminDeleteCommand extends ConfirmableCommand {
}
// Confirm
askConfirmation(user, () -> deletePlayer(user, targetUUID));
return false;
return true;
}
private void deletePlayer(User user, UUID targetUUID) {

View File

@ -1,10 +1,7 @@
package world.bentobox.bentobox.api.commands.island;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;

View File

@ -154,20 +154,10 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
*/
// Check if there is a ConfigEntry annotation on the field
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
boolean overrideOnChange = false;
boolean experimental = false;
boolean needsReset = false;
// If there is a config annotation then do something
if (configEntry != null && !configEntry.path().isEmpty()) {
storageLocation = configEntry.path();
// TODO: Not sure what to do with this one
overrideOnChange = configEntry.overrideOnChange();
// TODO: Not sure what to do with this one
experimental = configEntry.experimental();
// If this value has changed, then the addon will need a full reset
// TODO: Inform addon if this value is different to a value stored in the database?
needsReset = configEntry.needsReset();
}
// Some fields need custom handling to serialize or deserialize and the programmer will need to
// define them herself. She can add an annotation to do that.

View File

@ -54,10 +54,6 @@ public class Flags {
// Disabled setting 'rank'
private static final int DISABLED = -1;
// TODO: add ELYTRA
// TODO: add FISHING
// TODO: add KEEP_INVENTORY - is it needed?
public static final Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build();
public static final Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.GRASS).listener(new PlaceBlocksListener()).build();

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.managers;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.bukkit.Bukkit;
@ -11,7 +12,7 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
public class CommandsManager {
private HashMap<String, CompositeCommand> commands = new HashMap<>();
private Map<String, CompositeCommand> commands = new HashMap<>();
public void registerCommand(CompositeCommand command) {
commands.put(command.getLabel(), command);
@ -36,6 +37,13 @@ public class CommandsManager {
return commands.get(command);
}
/**
* @return the commands
*/
public Map<String, CompositeCommand> getCommands() {
return commands;
}
/**
* List all commands registered so far
* @return set of commands
@ -44,11 +52,4 @@ public class CommandsManager {
return commands.keySet();
}
/**
* @return the commands
*/
public HashMap<String, CompositeCommand> getCommands() {
return commands;
}
}

View File

@ -30,8 +30,8 @@ public class LocalesManager {
public LocalesManager(BentoBox plugin) {
this.plugin = plugin;
copyLocalesFromJar("BentoBox");
loadLocalesFromFile("BentoBox"); // Default
copyLocalesFromJar(plugin.getName());
loadLocalesFromFile(plugin.getName()); // Default
}
/**
@ -157,7 +157,7 @@ public class LocalesManager {
*/
public void reloadLanguages() {
languages.clear();
loadLocalesFromFile("BentoBox");
loadLocalesFromFile(plugin.getName());
plugin.getAddonsManager().getAddons().forEach(addon -> loadLocalesFromFile(addon.getDescription().getName()));
}
}

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.commands.admin;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -188,7 +189,7 @@ public class AdminDeleteCommandTest {
AdminDeleteCommand itl = new AdminDeleteCommand(ac);
// First requires confirmation
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
Mockito.verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "0");
// Confirm
itl.execute(user, itl.getLabel(), Arrays.asList(name));