mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Fixed code smells.
This commit is contained in:
parent
471cb30a87
commit
b80928184e
@ -39,9 +39,6 @@ public class BentoBox extends JavaPlugin {
|
||||
private PlayersManager playersManager;
|
||||
private IslandsManager islandsManager;
|
||||
|
||||
// bStats
|
||||
private BStats bStats;
|
||||
|
||||
// Managers
|
||||
private CommandsManager commandsManager;
|
||||
private LocalesManager localesManager;
|
||||
@ -89,7 +86,7 @@ public class BentoBox extends JavaPlugin {
|
||||
headGetter = new HeadGetter(this);
|
||||
|
||||
// Load metrics
|
||||
bStats = new BStats(this);
|
||||
BStats bStats = new BStats(this);
|
||||
|
||||
// Load Notifier
|
||||
notifier = new Notifier();
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.plugin.InvalidDescriptionException;
|
||||
import org.bukkit.util.permissions.DefaultPermissions;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.AddonDescription.AddonDescriptionBuilder;
|
||||
import world.bentobox.bentobox.api.addons.exception.InvalidAddonFormatException;
|
||||
import world.bentobox.bentobox.api.addons.exception.InvalidAddonInheritException;
|
||||
import world.bentobox.bentobox.managers.AddonsManager;
|
||||
|
||||
@ -43,7 +44,7 @@ public class AddonClassLoader extends URLClassLoader {
|
||||
String mainClass = data.getString("main");
|
||||
javaClass = Class.forName(mainClass, true, this);
|
||||
if(mainClass.startsWith("world.bentobox.bentobox")){
|
||||
throw new Exception("Packages declaration cannot start with 'world.bentobox.bentobox'");
|
||||
throw new InvalidAddonFormatException("Packages declaration cannot start with 'world.bentobox.bentobox'");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new InvalidDescriptionException("Could not load '" + path.getName() + "' in folder '" + path.getParent() + "' - " + e.getMessage());
|
||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -37,6 +38,8 @@ import world.bentobox.bentobox.util.Util;
|
||||
*/
|
||||
public abstract class CompositeCommand extends Command implements PluginIdentifiableCommand, BentoBoxCommand {
|
||||
|
||||
private static final String COMMANDS = "commands.";
|
||||
|
||||
private final BentoBox plugin;
|
||||
|
||||
/**
|
||||
@ -127,8 +130,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
plugin.getCommandsManager().registerCommand(this);
|
||||
}
|
||||
// Default references to description and parameters
|
||||
setDescription("commands." + label + ".description");
|
||||
setParametersHelp("commands." + label + ".parameters");
|
||||
setDescription(COMMANDS + label + ".description");
|
||||
setParametersHelp(COMMANDS + label + ".parameters");
|
||||
setup();
|
||||
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
|
||||
new DefaultHelpCommand(this);
|
||||
@ -192,8 +195,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
p = p.getParent();
|
||||
index++;
|
||||
}
|
||||
setDescription("commands." + reference.toString() + ".description");
|
||||
setParametersHelp("commands." + reference.toString() + ".parameters");
|
||||
setDescription(COMMANDS + reference.toString() + ".description");
|
||||
setParametersHelp(COMMANDS + reference.toString() + ".parameters");
|
||||
setup();
|
||||
// If this command does not define its own help class, then use the default help command
|
||||
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
|
||||
@ -569,30 +572,19 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
}
|
||||
// Add any tab completion from the subcommand
|
||||
options.addAll(cmd.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElse(new ArrayList<>()));
|
||||
// Add any sub-commands automatically
|
||||
if (cmd.hasSubCommands()) {
|
||||
// Check if subcommands are visible to this sender
|
||||
for (CompositeCommand subCommand: cmd.getSubCommands().values()) {
|
||||
if (sender instanceof Player) {
|
||||
// Player
|
||||
if (subCommand.getPermission().isEmpty() || sender.hasPermission(subCommand.getPermission()) || sender.isOp()) {
|
||||
// Permission is okay
|
||||
options.add(subCommand.getLabel());
|
||||
}
|
||||
} else {
|
||||
// Console
|
||||
if (!subCommand.onlyPlayer) {
|
||||
// Not a player command
|
||||
options.add(subCommand.getLabel());
|
||||
}
|
||||
}
|
||||
}
|
||||
options.addAll(getSubCommandLabels(sender, cmd));
|
||||
}
|
||||
|
||||
String lastArg = args.length != 0 ? args[args.length - 1] : "";
|
||||
return Util.tabLimit(options, lastArg).stream().sorted().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<String> getSubCommandLabels(CommandSender sender, CompositeCommand cmd) {
|
||||
return cmd.getSubCommands().values().stream().filter(c -> !c.isOnlyPlayer() || sender.isOp()
|
||||
|| (sender instanceof Player && (c.getPermission().isEmpty() || sender.hasPermission(c.getPermission()))) )
|
||||
.map(CompositeCommand::getLabel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help
|
||||
* @param command - command that this help is for
|
||||
|
@ -18,10 +18,11 @@ import world.bentobox.bentobox.api.user.User;
|
||||
*/
|
||||
public class AdminRangeDisplayCommand extends CompositeCommand {
|
||||
|
||||
private static final String DISPLAY = "display";
|
||||
private Map<User, Integer> display = new HashMap<>();
|
||||
|
||||
public AdminRangeDisplayCommand(CompositeCommand parent) {
|
||||
super(parent, "display", "show", "hide");
|
||||
super(parent, DISPLAY, "show", "hide");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -40,7 +41,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
|
||||
|
||||
if (!display.containsKey(user)) {
|
||||
switch (label) {
|
||||
case "display":
|
||||
case DISPLAY:
|
||||
case "show":
|
||||
showZones(user);
|
||||
break;
|
||||
@ -53,7 +54,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
|
||||
}
|
||||
} else {
|
||||
switch (label) {
|
||||
case "display":
|
||||
case DISPLAY:
|
||||
case "hide":
|
||||
hideZones(user);
|
||||
break;
|
||||
|
@ -136,7 +136,6 @@ public class FlatFileDatabaseConnector implements DatabaseConnector {
|
||||
Files.delete(commentedFile.toPath());
|
||||
} catch (IOException e1) {
|
||||
plugin.logError("Could not comment config file " + file.getName() + " " + e1.getMessage());
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user