mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-26 02:57:59 +01:00
Fixed AddonDescription to use a valid Builder pattern
AddonDescriptionBuilder has been renamed to AddonDescription.Builder ; and there is no longer public constructors in this class. This change is obviously API breaking, but it's relatively "internal", so hopefully people didn't use it.
This commit is contained in:
parent
30c20216fa
commit
c7a85c2b5a
@ -16,7 +16,6 @@ import org.bukkit.permissions.PermissionDefault;
|
||||
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.exceptions.InvalidAddonFormatException;
|
||||
import world.bentobox.bentobox.api.addons.exceptions.InvalidAddonInheritException;
|
||||
import world.bentobox.bentobox.managers.AddonsManager;
|
||||
@ -83,18 +82,19 @@ public class AddonClassLoader extends URLClassLoader {
|
||||
}
|
||||
|
||||
private AddonDescription asDescription(YamlConfiguration data) {
|
||||
AddonDescriptionBuilder adb = new AddonDescriptionBuilder(data.getString("name"))
|
||||
.withVersion(data.getString("version"))
|
||||
.withAuthor(data.getString("authors"));
|
||||
AddonDescription.Builder builder = new AddonDescription.Builder(data.getString("main"), data.getString("name"))
|
||||
.version(data.getString("version"))
|
||||
.authors(data.getString("authors"));
|
||||
|
||||
if (data.getString("depend") != null) {
|
||||
adb.withDepend(Arrays.asList(data.getString("depend").split("\\s*,\\s*")));
|
||||
builder.dependencies(Arrays.asList(data.getString("depend").split("\\s*,\\s*")));
|
||||
}
|
||||
if (data.getString("softdepend") != null) {
|
||||
adb.withSoftDepend(Arrays.asList(data.getString("softdepend").split("\\s*,\\s*")));
|
||||
}
|
||||
return adb.build();
|
||||
builder.softDependencies(Arrays.asList(data.getString("softdepend").split("\\s*,\\s*")));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.net.URLClassLoader#findClass(java.lang.String)
|
||||
|
@ -5,7 +5,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Tastybento, Poslovitch
|
||||
* @author tastybento, Poslovitch
|
||||
*/
|
||||
public final class AddonDescription {
|
||||
|
||||
@ -13,83 +13,18 @@ public final class AddonDescription {
|
||||
private String name;
|
||||
private String version;
|
||||
private String description;
|
||||
private List<String> authors = new ArrayList<>();
|
||||
private List<String> dependencies = new ArrayList<>();
|
||||
private List<String> softDependencies = new ArrayList<>();
|
||||
private List<String> authors;
|
||||
private List<String> dependencies;
|
||||
private List<String> softDependencies;
|
||||
|
||||
public AddonDescription() {}
|
||||
|
||||
public AddonDescription(String main, String name, String version, String description, List<String> authors, List<String> dependencies, List<String> softDependencies) {
|
||||
this.main = main;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.description = description;
|
||||
this.authors = authors;
|
||||
this.dependencies = dependencies;
|
||||
this.softDependencies = softDependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param main the main to set
|
||||
*/
|
||||
public void setMain(String main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param version the version to set
|
||||
*/
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authors the authors to set
|
||||
*/
|
||||
public void setAuthors(List<String> authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dependencies
|
||||
*/
|
||||
public List<String> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the softDependencies
|
||||
*/
|
||||
public List<String> getSoftDependencies() {
|
||||
return softDependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dependencies the dependencies to set
|
||||
*/
|
||||
public void setDependencies(List<String> dependencies) {
|
||||
this.dependencies = dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param softDependencies the softDependencies to set
|
||||
*/
|
||||
public void setSoftDependencies(List<String> softDependencies) {
|
||||
this.softDependencies = softDependencies;
|
||||
private AddonDescription(Builder builder) {
|
||||
this.main = builder.main;
|
||||
this.name = builder.name;
|
||||
this.version = builder.version;
|
||||
this.description = builder.description;
|
||||
this.authors = builder.authors;
|
||||
this.dependencies = builder.dependencies;
|
||||
this.softDependencies = builder.softDependencies;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -112,44 +47,61 @@ public final class AddonDescription {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public static class AddonDescriptionBuilder{
|
||||
|
||||
private AddonDescription description;
|
||||
|
||||
public AddonDescriptionBuilder(String name){
|
||||
description = new AddonDescription();
|
||||
description.setName(name);
|
||||
/**
|
||||
* @return the dependencies
|
||||
*/
|
||||
public List<String> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public AddonDescriptionBuilder withAuthor(String... authors){
|
||||
description.setAuthors(Arrays.asList(authors));
|
||||
/**
|
||||
* @return the softDependencies
|
||||
*/
|
||||
public List<String> getSoftDependencies() {
|
||||
return softDependencies;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String main;
|
||||
private String name;
|
||||
private String version;
|
||||
private String description;
|
||||
private List<String> authors = new ArrayList<>();
|
||||
private List<String> dependencies = new ArrayList<>();
|
||||
private List<String> softDependencies = new ArrayList<>();
|
||||
|
||||
public Builder(String main, String name) {
|
||||
this.main = main;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Builder version(String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddonDescriptionBuilder withDescription(String desc){
|
||||
description.setDescription(desc);
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddonDescriptionBuilder withVersion(String version){
|
||||
description.setVersion(version);
|
||||
public Builder authors(String... authors) {
|
||||
this.authors = Arrays.asList(authors);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddonDescriptionBuilder withDepend(List<String> addons) {
|
||||
description.setDependencies(addons);
|
||||
public Builder dependencies(List<String> dependencies) {
|
||||
this.dependencies = dependencies;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddonDescriptionBuilder withSoftDepend(List<String> addons) {
|
||||
description.setSoftDependencies(addons);
|
||||
public Builder softDependencies(List<String> softDependencies) {
|
||||
this.softDependencies = softDependencies;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddonDescription build() {
|
||||
return description;
|
||||
return new AddonDescription(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ public class AddonTest {
|
||||
static BentoBox plugin;
|
||||
static JavaPlugin javaPlugin;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Server server = mock(Server.class);
|
||||
@ -69,21 +68,14 @@ public class AddonTest {
|
||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||
ItemMeta itemMeta = mock(ItemMeta.class);
|
||||
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
|
||||
|
||||
}
|
||||
|
||||
class TestClass extends Addon {
|
||||
@Override
|
||||
public void onEnable() { }
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
public void onDisable() { }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -118,7 +110,7 @@ public class AddonTest {
|
||||
@Test
|
||||
public void testGetDescription() {
|
||||
TestClass test = new TestClass();
|
||||
AddonDescription d = new AddonDescription();
|
||||
AddonDescription d = new AddonDescription.Builder("main", "name").build();
|
||||
assertNull(test.getDescription());
|
||||
test.setDescription(d);
|
||||
assertEquals(d, test.getDescription());
|
||||
@ -159,14 +151,6 @@ public class AddonTest {
|
||||
test.registerListener(listener);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSaveConfig() {
|
||||
//TestClass test = new TestClass();
|
||||
// This will wipe out the config.yml of BSB so I am commenting it out
|
||||
//test.saveConfig();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDefaultConfig() {
|
||||
TestClass test = new TestClass();
|
||||
@ -210,7 +194,6 @@ public class AddonTest {
|
||||
test.saveResource("no_such_file", jarFile, false, true);
|
||||
test.saveResource("no_such_file", jarFile, true, false);
|
||||
test.saveResource("no_such_file", jarFile, true, true);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -242,7 +225,7 @@ public class AddonTest {
|
||||
@Test
|
||||
public void testSetDescription() {
|
||||
TestClass test = new TestClass();
|
||||
AddonDescription desc = new AddonDescription();
|
||||
AddonDescription desc = new AddonDescription.Builder("main", "name").build();
|
||||
test.setDescription(desc);
|
||||
assertEquals(desc, test.getDescription());
|
||||
}
|
||||
@ -279,5 +262,4 @@ public class AddonTest {
|
||||
TestClass test = new TestClass();
|
||||
assertEquals(Optional.empty(),test.getAddonByName("addon"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -299,8 +299,7 @@ public class LocalesManagerTest {
|
||||
AddonsManager am = mock(AddonsManager.class);
|
||||
List<Addon> none = new ArrayList<>();
|
||||
Addon addon = mock(Addon.class);
|
||||
AddonDescription desc = new AddonDescription();
|
||||
desc.setName("AcidIsland");
|
||||
AddonDescription desc = new AddonDescription.Builder("", "AcidIsland").build();
|
||||
when(addon.getDescription()).thenReturn(desc);
|
||||
// Create a tmp folder to jar up
|
||||
File localeDir = new File(LOCALE_FOLDER);
|
||||
|
Loading…
Reference in New Issue
Block a user