mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-10 09:21:31 +01:00
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.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -102,7 +101,7 @@ public class BentoBox extends JavaPlugin {
|
||||
logWarning("BentoBox is tested only on the following Spigot versions:");
|
||||
|
||||
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("**************************************");
|
||||
@ -331,7 +330,7 @@ public class BentoBox extends JavaPlugin {
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public PlayersManager getPlayersManager() {
|
||||
return playersManager;
|
||||
return getPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -350,7 +349,7 @@ public class BentoBox extends JavaPlugin {
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public IslandsManager getIslandsManager() {
|
||||
return islandsManager;
|
||||
return getIslands();
|
||||
}
|
||||
|
||||
private static void setInstance(BentoBox plugin) {
|
||||
|
@ -158,26 +158,35 @@ public final class AddonDescription {
|
||||
* @return the permissions
|
||||
* @since 1.13.0
|
||||
*/
|
||||
public @Nullable ConfigurationSection getPermissions() {
|
||||
@Nullable
|
||||
public ConfigurationSection getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private @NonNull
|
||||
final String main;
|
||||
private @NonNull
|
||||
final String name;
|
||||
private @NonNull
|
||||
final String version;
|
||||
private @NonNull String description = "";
|
||||
private @NonNull List<String> authors = new ArrayList<>();
|
||||
private @NonNull List<String> dependencies = new ArrayList<>();
|
||||
private @NonNull List<String> softDependencies = new ArrayList<>();
|
||||
@NonNull
|
||||
private final String main;
|
||||
@NonNull
|
||||
private final String name;
|
||||
@NonNull
|
||||
private final String version;
|
||||
@NonNull
|
||||
private String description = "";
|
||||
@NonNull
|
||||
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 @NonNull String repository = "";
|
||||
private @NonNull Material icon = Material.PAPER;
|
||||
private @NonNull String apiVersion = "1";
|
||||
private @Nullable ConfigurationSection permissions;
|
||||
@NonNull
|
||||
private String repository = "";
|
||||
@NonNull
|
||||
private Material icon = Material.PAPER;
|
||||
@NonNull
|
||||
private String apiVersion = "1";
|
||||
@Nullable
|
||||
private ConfigurationSection permissions;
|
||||
|
||||
/**
|
||||
* @since 1.1
|
||||
|
@ -477,6 +477,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
* @param user - the User
|
||||
* @return true if sender is a player
|
||||
* @deprecated use {@link User#isPlayer()}
|
||||
* @forRemove 1.18.0
|
||||
*/
|
||||
@Deprecated
|
||||
protected boolean isPlayer(User user) {
|
||||
|
@ -44,15 +44,15 @@ public class AdminSwitchCommand extends ConfirmableCommand {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
// 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("general.success");
|
||||
} else {
|
||||
// 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("general.success");
|
||||
}
|
||||
|
@ -32,6 +32,14 @@ import world.bentobox.bentobox.util.ItemParser;
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@ -95,57 +103,57 @@ public class TemplateReader
|
||||
return null;
|
||||
}
|
||||
|
||||
String title = configurationSection.getString("title");
|
||||
String title = configurationSection.getString(TITLE);
|
||||
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);
|
||||
|
||||
PanelTemplateRecord.TemplateItem borderItem = null;
|
||||
|
||||
// Read Border Icon.
|
||||
if (configurationSection.isConfigurationSection("border"))
|
||||
if (configurationSection.isConfigurationSection(BORDER))
|
||||
{
|
||||
// Process border icon if it contains more options.
|
||||
ConfigurationSection borderSection = configurationSection.getConfigurationSection("border");
|
||||
ConfigurationSection borderSection = configurationSection.getConfigurationSection(BORDER);
|
||||
|
||||
if (borderSection != null)
|
||||
{
|
||||
borderItem = new PanelTemplateRecord.TemplateItem(
|
||||
ItemParser.parse((borderSection.getString("icon", Material.AIR.name()))),
|
||||
borderSection.getString("title", null),
|
||||
borderSection.getString("description", null));
|
||||
ItemParser.parse((borderSection.getString(ICON, Material.AIR.name()))),
|
||||
borderSection.getString(TITLE, null),
|
||||
borderSection.getString(DESCRIPTION, null));
|
||||
}
|
||||
}
|
||||
else if (configurationSection.isString("border"))
|
||||
else if (configurationSection.isString(BORDER))
|
||||
{
|
||||
// Process border icon if it contains only icon.
|
||||
|
||||
borderItem = new PanelTemplateRecord.TemplateItem(
|
||||
ItemParser.parse((configurationSection.getString("border", Material.AIR.name()))));
|
||||
ItemParser.parse((configurationSection.getString(BORDER, Material.AIR.name()))));
|
||||
}
|
||||
|
||||
PanelTemplateRecord.TemplateItem backgroundItem = null;
|
||||
|
||||
// Read Background block
|
||||
if (configurationSection.isConfigurationSection("background"))
|
||||
if (configurationSection.isConfigurationSection(BACKGROUND))
|
||||
{
|
||||
// Process border icon if it contains more options.
|
||||
ConfigurationSection backgroundSection = configurationSection.getConfigurationSection("background");
|
||||
ConfigurationSection backgroundSection = configurationSection.getConfigurationSection(BACKGROUND);
|
||||
|
||||
if (backgroundSection != null)
|
||||
{
|
||||
backgroundItem = new PanelTemplateRecord.TemplateItem(
|
||||
ItemParser.parse((backgroundSection.getString("icon", Material.AIR.name()))),
|
||||
backgroundSection.getString("title", null),
|
||||
backgroundSection.getString("description", null));
|
||||
ItemParser.parse((backgroundSection.getString(ICON, Material.AIR.name()))),
|
||||
backgroundSection.getString(TITLE, null),
|
||||
backgroundSection.getString(DESCRIPTION, null));
|
||||
}
|
||||
}
|
||||
else if (configurationSection.isString("background"))
|
||||
else if (configurationSection.isString(BACKGROUND))
|
||||
{
|
||||
// Process background icon if it contains only icon.
|
||||
|
||||
backgroundItem = new PanelTemplateRecord.TemplateItem(
|
||||
ItemParser.parse((configurationSection.getString("background", Material.AIR.name()))));
|
||||
ItemParser.parse((configurationSection.getString(BACKGROUND, Material.AIR.name()))));
|
||||
}
|
||||
|
||||
// Read reusable
|
||||
@ -156,7 +164,7 @@ public class TemplateReader
|
||||
{
|
||||
// Add all reusables to the local storage.
|
||||
reusable.getKeys(false).forEach(key ->
|
||||
readPanelItemTemplate(reusable.getConfigurationSection(key), key, panelItemDataMap));
|
||||
readPanelItemTemplate(reusable.getConfigurationSection(key), key, panelItemDataMap));
|
||||
}
|
||||
|
||||
// Read content
|
||||
@ -190,15 +198,15 @@ public class TemplateReader
|
||||
{
|
||||
// If it contains a section, then build a new button template from it.
|
||||
template.addButtonTemplate(rowIndex,
|
||||
columnIndex,
|
||||
readPanelItemTemplate(line.getConfigurationSection(String.valueOf(columnIndex + 1))));
|
||||
columnIndex,
|
||||
readPanelItemTemplate(line.getConfigurationSection(String.valueOf(columnIndex + 1))));
|
||||
}
|
||||
else if (line.isString(String.valueOf(columnIndex + 1)))
|
||||
{
|
||||
// If it contains just a single word, assume it is a reusable.
|
||||
template.addButtonTemplate(rowIndex,
|
||||
columnIndex,
|
||||
panelItemDataMap.get(line.getString(String.valueOf(columnIndex + 1))));
|
||||
columnIndex,
|
||||
panelItemDataMap.get(line.getString(String.valueOf(columnIndex + 1))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -221,20 +229,20 @@ public class TemplateReader
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
forceShow[number-1] = true;
|
||||
@ -267,8 +275,8 @@ public class TemplateReader
|
||||
*/
|
||||
@Nullable
|
||||
private static ItemTemplateRecord readPanelItemTemplate(@Nullable ConfigurationSection section,
|
||||
String itemKey,
|
||||
Map<String, ItemTemplateRecord> reusableItemMap)
|
||||
String itemKey,
|
||||
Map<String, ItemTemplateRecord> reusableItemMap)
|
||||
{
|
||||
if (section == null)
|
||||
{
|
||||
@ -278,13 +286,13 @@ public class TemplateReader
|
||||
|
||||
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
|
||||
{
|
||||
@ -292,10 +300,10 @@ public class TemplateReader
|
||||
}
|
||||
|
||||
// Create Item Record
|
||||
ItemTemplateRecord itemRecord = new ItemTemplateRecord(ItemParser.parse(section.getString("icon")),
|
||||
section.getString("title", null),
|
||||
section.getString("description", null),
|
||||
fallback);
|
||||
ItemTemplateRecord itemRecord = new ItemTemplateRecord(ItemParser.parse(section.getString(ICON)),
|
||||
section.getString(TITLE, null),
|
||||
section.getString(DESCRIPTION, null),
|
||||
fallback);
|
||||
|
||||
// Read data
|
||||
if (section.isConfigurationSection("data"))
|
||||
@ -325,10 +333,10 @@ public class TemplateReader
|
||||
if (actionDataSection != null)
|
||||
{
|
||||
ItemTemplateRecord.ActionRecords actionData =
|
||||
new ItemTemplateRecord.ActionRecords(clickType,
|
||||
actionDataSection.getString("type"),
|
||||
actionDataSection.getString("content"),
|
||||
actionDataSection.getString("tooltip"));
|
||||
new ItemTemplateRecord.ActionRecords(clickType,
|
||||
actionDataSection.getString("type"),
|
||||
actionDataSection.getString("content"),
|
||||
actionDataSection.getString("tooltip"));
|
||||
|
||||
itemRecord.addAction(actionData);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user