Fix some code smells.
This commit is contained in:
parent
f6f5b63110
commit
29fa03976c
|
@ -2,7 +2,6 @@ package world.bentobox.bentobox;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -102,7 +101,7 @@ public class BentoBox extends JavaPlugin {
|
||||||
logWarning("BentoBox is tested only on the following Spigot versions:");
|
logWarning("BentoBox is tested only on the following Spigot versions:");
|
||||||
|
|
||||||
List<String> versions = ServerCompatibility.ServerVersion.getVersions(ServerCompatibility.Compatibility.COMPATIBLE, ServerCompatibility.Compatibility.SUPPORTED)
|
List<String> versions = ServerCompatibility.ServerVersion.getVersions(ServerCompatibility.Compatibility.COMPATIBLE, ServerCompatibility.Compatibility.SUPPORTED)
|
||||||
.stream().map(ServerCompatibility.ServerVersion::toString).collect(Collectors.toList());
|
.stream().map(ServerCompatibility.ServerVersion::toString).toList();
|
||||||
|
|
||||||
logWarning(String.join(", ", versions));
|
logWarning(String.join(", ", versions));
|
||||||
logWarning("**************************************");
|
logWarning("**************************************");
|
||||||
|
@ -331,7 +330,7 @@ public class BentoBox extends JavaPlugin {
|
||||||
* @since 1.16.0
|
* @since 1.16.0
|
||||||
*/
|
*/
|
||||||
public PlayersManager getPlayersManager() {
|
public PlayersManager getPlayersManager() {
|
||||||
return playersManager;
|
return getPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -350,7 +349,7 @@ public class BentoBox extends JavaPlugin {
|
||||||
* @since 1.16.0
|
* @since 1.16.0
|
||||||
*/
|
*/
|
||||||
public IslandsManager getIslandsManager() {
|
public IslandsManager getIslandsManager() {
|
||||||
return islandsManager;
|
return getIslands();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setInstance(BentoBox plugin) {
|
private static void setInstance(BentoBox plugin) {
|
||||||
|
|
|
@ -158,26 +158,35 @@ public final class AddonDescription {
|
||||||
* @return the permissions
|
* @return the permissions
|
||||||
* @since 1.13.0
|
* @since 1.13.0
|
||||||
*/
|
*/
|
||||||
public @Nullable ConfigurationSection getPermissions() {
|
@Nullable
|
||||||
|
public ConfigurationSection getPermissions() {
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private @NonNull
|
@NonNull
|
||||||
final String main;
|
private final String main;
|
||||||
private @NonNull
|
@NonNull
|
||||||
final String name;
|
private final String name;
|
||||||
private @NonNull
|
@NonNull
|
||||||
final String version;
|
private final String version;
|
||||||
private @NonNull String description = "";
|
@NonNull
|
||||||
private @NonNull List<String> authors = new ArrayList<>();
|
private String description = "";
|
||||||
private @NonNull List<String> dependencies = new ArrayList<>();
|
@NonNull
|
||||||
private @NonNull List<String> softDependencies = new ArrayList<>();
|
private List<String> authors = new ArrayList<>();
|
||||||
|
@NonNull
|
||||||
|
private List<String> dependencies = new ArrayList<>();
|
||||||
|
@NonNull
|
||||||
|
private List<String> softDependencies = new ArrayList<>();
|
||||||
private boolean metrics = true;
|
private boolean metrics = true;
|
||||||
private @NonNull String repository = "";
|
@NonNull
|
||||||
private @NonNull Material icon = Material.PAPER;
|
private String repository = "";
|
||||||
private @NonNull String apiVersion = "1";
|
@NonNull
|
||||||
private @Nullable ConfigurationSection permissions;
|
private Material icon = Material.PAPER;
|
||||||
|
@NonNull
|
||||||
|
private String apiVersion = "1";
|
||||||
|
@Nullable
|
||||||
|
private ConfigurationSection permissions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
|
|
|
@ -477,6 +477,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||||
* @param user - the User
|
* @param user - the User
|
||||||
* @return true if sender is a player
|
* @return true if sender is a player
|
||||||
* @deprecated use {@link User#isPlayer()}
|
* @deprecated use {@link User#isPlayer()}
|
||||||
|
* @forRemove 1.18.0
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected boolean isPlayer(User user) {
|
protected boolean isPlayer(User user) {
|
||||||
|
|
|
@ -44,15 +44,15 @@ public class AdminSwitchCommand extends ConfirmableCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
boolean switchState = user.getMetaData("AdminCommandSwitch").map(MetaDataValue::asBoolean).orElse(false);
|
boolean switchState = user.getMetaData(META_TAG).map(MetaDataValue::asBoolean).orElse(false);
|
||||||
if (switchState) {
|
if (switchState) {
|
||||||
// Turn off
|
// Turn off
|
||||||
user.putMetaData("AdminCommandSwitch", new MetaDataValue(false));
|
user.putMetaData(META_TAG, new MetaDataValue(false));
|
||||||
user.sendMessage("commands.admin.switch.adding"); // Adding protection bypass
|
user.sendMessage("commands.admin.switch.adding"); // Adding protection bypass
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
} else {
|
} else {
|
||||||
// Turn on
|
// Turn on
|
||||||
user.putMetaData("AdminCommandSwitch", new MetaDataValue(true));
|
user.putMetaData(META_TAG, new MetaDataValue(true));
|
||||||
user.sendMessage("commands.admin.switch.removing"); // Removing protection bypass
|
user.sendMessage("commands.admin.switch.removing"); // Removing protection bypass
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,14 @@ import world.bentobox.bentobox.util.ItemParser;
|
||||||
*/
|
*/
|
||||||
public class TemplateReader
|
public class TemplateReader
|
||||||
{
|
{
|
||||||
|
private static final String TITLE = "title";
|
||||||
|
private static final String ICON = "icon";
|
||||||
|
private static final String DESCRIPTION = "description";
|
||||||
|
private static final String BACKGROUND = "background";
|
||||||
|
private static final String BORDER = "border";
|
||||||
|
private static final String FORCE_SHOWN = "force-shown";
|
||||||
|
private static final String FALLBACK = "fallback";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read template panel panel template record.
|
* Read template panel panel template record.
|
||||||
*
|
*
|
||||||
|
@ -95,57 +103,57 @@ public class TemplateReader
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String title = configurationSection.getString("title");
|
String title = configurationSection.getString(TITLE);
|
||||||
Panel.Type type =
|
Panel.Type type =
|
||||||
Enums.getIfPresent(Panel.Type.class, configurationSection.getString("type", "INVENTORY")).
|
Enums.getIfPresent(Panel.Type.class, configurationSection.getString("type", "INVENTORY")).
|
||||||
or(Panel.Type.INVENTORY);
|
or(Panel.Type.INVENTORY);
|
||||||
|
|
||||||
PanelTemplateRecord.TemplateItem borderItem = null;
|
PanelTemplateRecord.TemplateItem borderItem = null;
|
||||||
|
|
||||||
// Read Border Icon.
|
// Read Border Icon.
|
||||||
if (configurationSection.isConfigurationSection("border"))
|
if (configurationSection.isConfigurationSection(BORDER))
|
||||||
{
|
{
|
||||||
// Process border icon if it contains more options.
|
// Process border icon if it contains more options.
|
||||||
ConfigurationSection borderSection = configurationSection.getConfigurationSection("border");
|
ConfigurationSection borderSection = configurationSection.getConfigurationSection(BORDER);
|
||||||
|
|
||||||
if (borderSection != null)
|
if (borderSection != null)
|
||||||
{
|
{
|
||||||
borderItem = new PanelTemplateRecord.TemplateItem(
|
borderItem = new PanelTemplateRecord.TemplateItem(
|
||||||
ItemParser.parse((borderSection.getString("icon", Material.AIR.name()))),
|
ItemParser.parse((borderSection.getString(ICON, Material.AIR.name()))),
|
||||||
borderSection.getString("title", null),
|
borderSection.getString(TITLE, null),
|
||||||
borderSection.getString("description", null));
|
borderSection.getString(DESCRIPTION, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (configurationSection.isString("border"))
|
else if (configurationSection.isString(BORDER))
|
||||||
{
|
{
|
||||||
// Process border icon if it contains only icon.
|
// Process border icon if it contains only icon.
|
||||||
|
|
||||||
borderItem = new PanelTemplateRecord.TemplateItem(
|
borderItem = new PanelTemplateRecord.TemplateItem(
|
||||||
ItemParser.parse((configurationSection.getString("border", Material.AIR.name()))));
|
ItemParser.parse((configurationSection.getString(BORDER, Material.AIR.name()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
PanelTemplateRecord.TemplateItem backgroundItem = null;
|
PanelTemplateRecord.TemplateItem backgroundItem = null;
|
||||||
|
|
||||||
// Read Background block
|
// Read Background block
|
||||||
if (configurationSection.isConfigurationSection("background"))
|
if (configurationSection.isConfigurationSection(BACKGROUND))
|
||||||
{
|
{
|
||||||
// Process border icon if it contains more options.
|
// Process border icon if it contains more options.
|
||||||
ConfigurationSection backgroundSection = configurationSection.getConfigurationSection("background");
|
ConfigurationSection backgroundSection = configurationSection.getConfigurationSection(BACKGROUND);
|
||||||
|
|
||||||
if (backgroundSection != null)
|
if (backgroundSection != null)
|
||||||
{
|
{
|
||||||
backgroundItem = new PanelTemplateRecord.TemplateItem(
|
backgroundItem = new PanelTemplateRecord.TemplateItem(
|
||||||
ItemParser.parse((backgroundSection.getString("icon", Material.AIR.name()))),
|
ItemParser.parse((backgroundSection.getString(ICON, Material.AIR.name()))),
|
||||||
backgroundSection.getString("title", null),
|
backgroundSection.getString(TITLE, null),
|
||||||
backgroundSection.getString("description", null));
|
backgroundSection.getString(DESCRIPTION, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (configurationSection.isString("background"))
|
else if (configurationSection.isString(BACKGROUND))
|
||||||
{
|
{
|
||||||
// Process background icon if it contains only icon.
|
// Process background icon if it contains only icon.
|
||||||
|
|
||||||
backgroundItem = new PanelTemplateRecord.TemplateItem(
|
backgroundItem = new PanelTemplateRecord.TemplateItem(
|
||||||
ItemParser.parse((configurationSection.getString("background", Material.AIR.name()))));
|
ItemParser.parse((configurationSection.getString(BACKGROUND, Material.AIR.name()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read reusable
|
// Read reusable
|
||||||
|
@ -156,7 +164,7 @@ public class TemplateReader
|
||||||
{
|
{
|
||||||
// Add all reusables to the local storage.
|
// Add all reusables to the local storage.
|
||||||
reusable.getKeys(false).forEach(key ->
|
reusable.getKeys(false).forEach(key ->
|
||||||
readPanelItemTemplate(reusable.getConfigurationSection(key), key, panelItemDataMap));
|
readPanelItemTemplate(reusable.getConfigurationSection(key), key, panelItemDataMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read content
|
// Read content
|
||||||
|
@ -190,15 +198,15 @@ public class TemplateReader
|
||||||
{
|
{
|
||||||
// If it contains a section, then build a new button template from it.
|
// If it contains a section, then build a new button template from it.
|
||||||
template.addButtonTemplate(rowIndex,
|
template.addButtonTemplate(rowIndex,
|
||||||
columnIndex,
|
columnIndex,
|
||||||
readPanelItemTemplate(line.getConfigurationSection(String.valueOf(columnIndex + 1))));
|
readPanelItemTemplate(line.getConfigurationSection(String.valueOf(columnIndex + 1))));
|
||||||
}
|
}
|
||||||
else if (line.isString(String.valueOf(columnIndex + 1)))
|
else if (line.isString(String.valueOf(columnIndex + 1)))
|
||||||
{
|
{
|
||||||
// If it contains just a single word, assume it is a reusable.
|
// If it contains just a single word, assume it is a reusable.
|
||||||
template.addButtonTemplate(rowIndex,
|
template.addButtonTemplate(rowIndex,
|
||||||
columnIndex,
|
columnIndex,
|
||||||
panelItemDataMap.get(line.getString(String.valueOf(columnIndex + 1))));
|
panelItemDataMap.get(line.getString(String.valueOf(columnIndex + 1))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,20 +229,20 @@ public class TemplateReader
|
||||||
{
|
{
|
||||||
boolean[] forceShow = new boolean[6];
|
boolean[] forceShow = new boolean[6];
|
||||||
|
|
||||||
if (section != null && section.contains("force-shown"))
|
if (section != null && section.contains(FORCE_SHOWN))
|
||||||
{
|
{
|
||||||
if (section.isInt("force-shown"))
|
if (section.isInt(FORCE_SHOWN))
|
||||||
{
|
{
|
||||||
int value = section.getInt("force-shown");
|
int value = section.getInt(FORCE_SHOWN);
|
||||||
|
|
||||||
if (value > 0 && value < 7)
|
if (value > 0 && value < 7)
|
||||||
{
|
{
|
||||||
forceShow[value-1] = true;
|
forceShow[value-1] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (section.isList("force-shown"))
|
else if (section.isList(FORCE_SHOWN))
|
||||||
{
|
{
|
||||||
section.getIntegerList("force-shown").forEach(number -> {
|
section.getIntegerList(FORCE_SHOWN).forEach(number -> {
|
||||||
if (number > 0 && number < 7)
|
if (number > 0 && number < 7)
|
||||||
{
|
{
|
||||||
forceShow[number-1] = true;
|
forceShow[number-1] = true;
|
||||||
|
@ -267,8 +275,8 @@ public class TemplateReader
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private static ItemTemplateRecord readPanelItemTemplate(@Nullable ConfigurationSection section,
|
private static ItemTemplateRecord readPanelItemTemplate(@Nullable ConfigurationSection section,
|
||||||
String itemKey,
|
String itemKey,
|
||||||
Map<String, ItemTemplateRecord> reusableItemMap)
|
Map<String, ItemTemplateRecord> reusableItemMap)
|
||||||
{
|
{
|
||||||
if (section == null)
|
if (section == null)
|
||||||
{
|
{
|
||||||
|
@ -278,13 +286,13 @@ public class TemplateReader
|
||||||
|
|
||||||
ItemTemplateRecord fallback;
|
ItemTemplateRecord fallback;
|
||||||
|
|
||||||
if (section.isConfigurationSection("fallback"))
|
if (section.isConfigurationSection(FALLBACK))
|
||||||
{
|
{
|
||||||
fallback = readPanelItemTemplate(section.getConfigurationSection("fallback"));
|
fallback = readPanelItemTemplate(section.getConfigurationSection(FALLBACK));
|
||||||
}
|
}
|
||||||
else if (section.isString("fallback") && reusableItemMap != null)
|
else if (section.isString(FALLBACK) && reusableItemMap != null)
|
||||||
{
|
{
|
||||||
fallback = reusableItemMap.get(section.getString("fallback"));
|
fallback = reusableItemMap.get(section.getString(FALLBACK));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -292,10 +300,10 @@ public class TemplateReader
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Item Record
|
// Create Item Record
|
||||||
ItemTemplateRecord itemRecord = new ItemTemplateRecord(ItemParser.parse(section.getString("icon")),
|
ItemTemplateRecord itemRecord = new ItemTemplateRecord(ItemParser.parse(section.getString(ICON)),
|
||||||
section.getString("title", null),
|
section.getString(TITLE, null),
|
||||||
section.getString("description", null),
|
section.getString(DESCRIPTION, null),
|
||||||
fallback);
|
fallback);
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
if (section.isConfigurationSection("data"))
|
if (section.isConfigurationSection("data"))
|
||||||
|
@ -325,10 +333,10 @@ public class TemplateReader
|
||||||
if (actionDataSection != null)
|
if (actionDataSection != null)
|
||||||
{
|
{
|
||||||
ItemTemplateRecord.ActionRecords actionData =
|
ItemTemplateRecord.ActionRecords actionData =
|
||||||
new ItemTemplateRecord.ActionRecords(clickType,
|
new ItemTemplateRecord.ActionRecords(clickType,
|
||||||
actionDataSection.getString("type"),
|
actionDataSection.getString("type"),
|
||||||
actionDataSection.getString("content"),
|
actionDataSection.getString("content"),
|
||||||
actionDataSection.getString("tooltip"));
|
actionDataSection.getString("tooltip"));
|
||||||
|
|
||||||
itemRecord.addAction(actionData);
|
itemRecord.addAction(actionData);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue