filter);
/**
* Returns true if the given {@link ResourcePath} exists in the active
diff --git a/src/main/java/org/spongepowered/api/resource/ResourcePath.java b/src/main/java/org/spongepowered/api/resource/ResourcePath.java
index 0c9a113f181..2b99759f262 100644
--- a/src/main/java/org/spongepowered/api/resource/ResourcePath.java
+++ b/src/main/java/org/spongepowered/api/resource/ResourcePath.java
@@ -25,6 +25,8 @@
package org.spongepowered.api.resource;
import org.spongepowered.api.Sponge;
+import org.spongepowered.api.data.DataContainer;
+import org.spongepowered.api.data.DataSerializable;
import org.spongepowered.api.util.ResettableBuilder;
import java.util.Iterator;
@@ -33,17 +35,19 @@
import java.util.Optional;
/**
- * A resource path should contain a namespace. If one is not provided,
- * {@code minecraft} will be used instead. The namespace and path must not
- * contain any special characters or uppercase letters.
+ *
A resource path should contain a namespace. The namespace and path must
+ * not contain any special characters or uppercase letters.
*
- *
In the pack, the path will point to a resource. The resource should
- * be located roughly at {@code data/namespace/path}
+ * A namespace can only contain the following characters:
+ * "{@code a-z0-9_-}"
+ * A path can only contain the following characters:
+ * "{@code a-z0-9_/.-}". Additionally, a path cannot use {@code ..} to go to
+ * the parent directory.
*
- *
A resource path should be usable in a {@link Map}, so implementations
+ * @implNote A resource path should be usable in a {@link Map}, so implementations
* should override {@link #hashCode()} and {@link #equals(Object)}.
*/
-public interface ResourcePath extends Comparable, Iterable {
+public interface ResourcePath extends Comparable {
/**
* Creates a new {@link Builder} to build a {@link ResourcePath}.
@@ -58,7 +62,7 @@ static Builder builder() {
* Creates a new {@link ResourcePath} using the given namespace and path.
*
* @param namespace The namespace to use
- * @param path The path to use
+ * @param path The path to use
* @return A new ResourcePath
*/
static ResourcePath of(String namespace, String path) throws IllegalArgumentException {
@@ -95,38 +99,21 @@ static ResourcePath parse(String path) throws IllegalArgumentException {
*/
String getPath();
- /**
- * Gets the root path from this path.
- *
- * @return The root path
- */
- ResourcePath getRoot();
-
/**
* Gets the immediate parent for this {@link ResourcePath}. If this path is
* the root path, itself is returned.
*
* @return The parent path
- * @see #getRoot()
*/
ResourcePath getParent();
- /**
- * Gets a list of names which make up this {@link ResourcePath}. Order of
- * names will be root first, with the last name being this path's
- * filename.
- *
- * @return The list of paths
- */
- List getNames();
-
/**
* Tests if this {@link ResourcePath} is a direct child of the given other path.
*
* @param parent The other resource path to check against
* @return True if this is a child to other
*/
- boolean isParent(ResourcePath parent);
+ boolean startsWith(ResourcePath parent);
/**
* Gets the file name portion of this {@link ResourcePath}.
@@ -158,7 +145,7 @@ static ResourcePath parse(String path) throws IllegalArgumentException {
Optional getExtension();
/**
- * Tests if this path has one of the given extensions. Case is insensitive.
+ * Tests if this path has one of the given extensions.
*
* @param ext The extensions to test
* @return True if the extension matches one of the ones provided
@@ -184,13 +171,28 @@ static ResourcePath parse(String path) throws IllegalArgumentException {
ResourcePath resolveSibling(String name);
/**
- * Returns an iterator of the paths leading up to this path, starting with
- * the root.
+ * Provides a String representation of this object consisting of
+ * {@code namespace:path}. This is easily reversible via
+ * {@link #parse(String)}.
*
- * @return The iterator
+ * @return A string reprsentation
*/
@Override
- Iterator iterator();
+ String toString();
+
+ /**
+ * {@inheritDoc}
+ *
+ * @implNote Implementation should override this for Map usage.
+ */
+ boolean equals(Object other);
+
+ /**
+ * {@inheritDoc}
+ *
+ * @implNote Implementation should override this for Map usage.
+ */
+ int hashCode();
/**
* Represents a builder to create {@link ResourcePath} instances.
diff --git a/src/main/java/org/spongepowered/api/resource/Pack.java b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
similarity index 85%
rename from src/main/java/org/spongepowered/api/resource/Pack.java
rename to src/main/java/org/spongepowered/api/resource/pack/Pack.java
index a237fbac9c3..52a692de71c 100644
--- a/src/main/java/org/spongepowered/api/resource/Pack.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
@@ -22,9 +22,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.api.resource;
+package org.spongepowered.api.resource.pack;
import org.spongepowered.api.data.DataView;
+import org.spongepowered.api.resource.Resource;
+import org.spongepowered.api.resource.ResourceManager;
+import org.spongepowered.api.resource.ResourcePath;
import java.io.IOException;
import java.io.InputStream;
@@ -46,7 +49,7 @@ public interface Pack {
* @return The input stream
* @throws IOException If the resource does not exist or another IOException occurs.
*/
- InputStream openStream(ResourceType type, ResourcePath path) throws IOException;
+ InputStream openStream(PackType type, ResourcePath path) throws IOException;
/**
* Recursively gets all the resources loaded from this pack. All namespaces
@@ -56,9 +59,9 @@ public interface Pack {
* @param path The resource path
* @param filter The file name filter
* @return Collection of resources
- * @see ResourceManager#getResources(String, Predicate)
+ * @see ResourceManager#getPaths(String, Predicate)
*/
- Collection getResources(ResourceType type, String path, Predicate filter);
+ Collection getPaths(PackType type, String path, Predicate filter);
/**
* Checks if a resource exists in this pack.
@@ -67,7 +70,7 @@ public interface Pack {
* @param path THe path of the resource
* @return True if the resource exists, false otherwise
*/
- boolean exists(ResourceType type, ResourcePath path);
+ boolean exists(PackType type, ResourcePath path);
/**
* Gets the metadata of this pack. The {@link DataView} represented is of
diff --git a/src/main/java/org/spongepowered/api/resource/PackInfo.java b/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
similarity index 85%
rename from src/main/java/org/spongepowered/api/resource/PackInfo.java
rename to src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
index 24630b14c04..3a2c2fb83a2 100644
--- a/src/main/java/org/spongepowered/api/resource/PackInfo.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
@@ -22,14 +22,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.api.resource;
+package org.spongepowered.api.resource.pack;
+import org.spongepowered.api.data.DataSerializable;
import org.spongepowered.api.text.Text;
+import org.spongepowered.api.text.TextRepresentable;
/**
* Basic info about a {@link Pack}
*/
-public interface PackInfo {
+public interface PackInfo extends DataSerializable, TextRepresentable {
/**
* Gets the name of the {@link Pack} used to identify it in the
@@ -54,14 +56,6 @@ public interface PackInfo {
*/
Text getDescription();
- /**
- * Formats the text of the pack info to display to the user.
- *
- * @param active Whether this pack is active or not
- * @return The formatted text
- */
- Text formatName(boolean active);
-
/**
* Gets the {@link Pack} associated with this pack info.
*
@@ -86,4 +80,22 @@ public interface PackInfo {
*/
boolean isRemote();
+ boolean isLocked();
+
+ Priority getPriority();
+
+ Compatibility getCompatability();
+
+ enum Priority {
+ FIRST,
+ LAST
+ }
+
+ enum Compatibility {
+ OLD,
+ NEW,
+ OK
+ }
+
+
}
diff --git a/src/main/java/org/spongepowered/api/resource/PackRepository.java b/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
similarity index 94%
rename from src/main/java/org/spongepowered/api/resource/PackRepository.java
rename to src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
index 5ec057df787..a4f0e381e93 100644
--- a/src/main/java/org/spongepowered/api/resource/PackRepository.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
@@ -22,9 +22,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.api.resource;
+package org.spongepowered.api.resource.pack;
import org.spongepowered.api.plugin.PluginContainer;
+import org.spongepowered.api.resource.ReloadableResourceManager;
+import org.spongepowered.api.resource.ResourceManager;
import java.util.Collection;
import java.util.Optional;
diff --git a/src/main/java/org/spongepowered/api/resource/ResourceType.java b/src/main/java/org/spongepowered/api/resource/pack/PackType.java
similarity index 92%
rename from src/main/java/org/spongepowered/api/resource/ResourceType.java
rename to src/main/java/org/spongepowered/api/resource/pack/PackType.java
index a3a1e2528dd..29507d5c2c5 100644
--- a/src/main/java/org/spongepowered/api/resource/ResourceType.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackType.java
@@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.api.resource;
+package org.spongepowered.api.resource.pack;
import org.spongepowered.api.CatalogType;
import org.spongepowered.api.util.annotation.CatalogedBy;
@@ -31,8 +31,8 @@
* Represents the root directory for different resource types. Current
* values in vanilla is assets and data.
*/
-@CatalogedBy(ResourceTypes.class)
-public interface ResourceType extends CatalogType {
+@CatalogedBy(PackTypes.class)
+public interface PackType extends CatalogType {
/**
* Gets the name of the root directory path for this resource type.
diff --git a/src/main/java/org/spongepowered/api/resource/ResourceTypes.java b/src/main/java/org/spongepowered/api/resource/pack/PackTypes.java
similarity index 83%
rename from src/main/java/org/spongepowered/api/resource/ResourceTypes.java
rename to src/main/java/org/spongepowered/api/resource/pack/PackTypes.java
index a99a7b30963..37f3e4b7316 100644
--- a/src/main/java/org/spongepowered/api/resource/ResourceTypes.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackTypes.java
@@ -22,17 +22,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.api.resource;
+package org.spongepowered.api.resource.pack;
import org.spongepowered.api.util.generator.dummy.DummyObjectProvider;
-public class ResourceTypes {
+public class PackTypes {
// SORTFIELDS:ON
- public static final ResourceType ASSETS = DummyObjectProvider.createFor(ResourceType.class, "ASSETS");
+ public static final PackType ASSETS = DummyObjectProvider.createFor(PackType.class, "ASSETS");
- public static final ResourceType DATA = DummyObjectProvider.createFor(ResourceType.class, "DATA");
+ public static final PackType DATA = DummyObjectProvider.createFor(PackType.class, "DATA");
// SORTFIELDS:OFF
}
diff --git a/src/main/java/org/spongepowered/api/event/resource/package-info.java b/src/main/java/org/spongepowered/api/resource/pack/package-info.java
similarity index 97%
rename from src/main/java/org/spongepowered/api/event/resource/package-info.java
rename to src/main/java/org/spongepowered/api/resource/pack/package-info.java
index 88e5eabc8a6..9d7e7ee417a 100644
--- a/src/main/java/org/spongepowered/api/event/resource/package-info.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/package-info.java
@@ -22,4 +22,4 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-@org.spongepowered.api.util.annotation.NonnullByDefault package org.spongepowered.api.event.resource;
+@org.spongepowered.api.util.annotation.NonnullByDefault package org.spongepowered.api.resource.pack;
From 30fe7de548f411a3d47a4825f3994fbc9957712a Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Thu, 2 May 2019 23:52:51 -0400
Subject: [PATCH 13/22] Fix the build
---
build.gradle | 2 +-
.../org/spongepowered/api/resource/Resource.java | 2 +-
.../api/resource/SimpleReloadListener.java | 13 +++++++++++++
3 files changed, 15 insertions(+), 2 deletions(-)
create mode 100644 src/main/java/org/spongepowered/api/resource/SimpleReloadListener.java
diff --git a/build.gradle b/build.gradle
index aee52d8d07d..eb31c4cc0cd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -175,7 +175,7 @@ sortClassFields {
add 'main', 'org.spongepowered.api.item.inventory.equipment.EquipmentTypes'
add 'main', 'org.spongepowered.api.item.inventory.query.QueryOperationTypes'
add 'main', 'org.spongepowered.api.item.potion.PotionTypes'
- add 'main', 'org.spongepowered.api.resource.ResourceTypes'
+ add 'main', 'org.spongepowered.api.resource.pack.PackTypes'
add 'main', 'org.spongepowered.api.scoreboard.CollisionRules'
add 'main', 'org.spongepowered.api.scoreboard.Visibilities'
add 'main', 'org.spongepowered.api.scoreboard.criteria.Criteria'
diff --git a/src/main/java/org/spongepowered/api/resource/Resource.java b/src/main/java/org/spongepowered/api/resource/Resource.java
index 86d5c291644..dd3707e5969 100644
--- a/src/main/java/org/spongepowered/api/resource/Resource.java
+++ b/src/main/java/org/spongepowered/api/resource/Resource.java
@@ -55,7 +55,7 @@
* try (Resource res = resourceManager.getResource(path)) {
* logger.info(res.readString(DefaultCharsets.UTF_8));
* } catch (IOException e) {
- * e.printStackTrace();
+ * logger.warn("Failed to load resource: {}", path, e);
* }
*
*/
diff --git a/src/main/java/org/spongepowered/api/resource/SimpleReloadListener.java b/src/main/java/org/spongepowered/api/resource/SimpleReloadListener.java
new file mode 100644
index 00000000000..ba18c4ee61c
--- /dev/null
+++ b/src/main/java/org/spongepowered/api/resource/SimpleReloadListener.java
@@ -0,0 +1,13 @@
+package org.spongepowered.api.resource;
+
+
+import java.util.concurrent.CompletableFuture;
+
+public interface SimpleReloadListener extends AsyncReloadListener {
+ @Override
+ default CompletableFuture listen(Staging stg, AsyncReloader reloader) {
+ return stg.setup(null).thenRunAsync(() -> onReload(reloader.getResourceManager()), reloader.getEngine());
+ }
+
+ void onReload(ResourceManager manager);
+}
From 1052aabcd5f7e710fdef1bca1de03e229a0aaad1 Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Sun, 5 May 2019 17:42:45 -0400
Subject: [PATCH 14/22] Fix some rebase artifacts
---
src/main/java/org/spongepowered/api/Server.java | 2 --
.../api/plugin/PluginContainer.java | 16 +++++++++++++++-
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/spongepowered/api/Server.java b/src/main/java/org/spongepowered/api/Server.java
index f0e6ffaaf2d..ca3dd73d384 100644
--- a/src/main/java/org/spongepowered/api/Server.java
+++ b/src/main/java/org/spongepowered/api/Server.java
@@ -27,8 +27,6 @@
import org.spongepowered.api.command.source.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.profile.GameProfileManager;
-import org.spongepowered.api.resource.pack.PackRepository;
-import org.spongepowered.api.resource.ReloadableResourceManager;
import org.spongepowered.api.resourcepack.ResourcePack;
import org.spongepowered.api.scoreboard.Scoreboard;
import org.spongepowered.api.text.Text;
diff --git a/src/main/java/org/spongepowered/api/plugin/PluginContainer.java b/src/main/java/org/spongepowered/api/plugin/PluginContainer.java
index 4774cc019df..775d211f964 100644
--- a/src/main/java/org/spongepowered/api/plugin/PluginContainer.java
+++ b/src/main/java/org/spongepowered/api/plugin/PluginContainer.java
@@ -29,6 +29,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.api.CatalogKey;
+import org.spongepowered.api.Sponge;
+import org.spongepowered.api.asset.Asset;
+import org.spongepowered.api.asset.AssetManager;
import org.spongepowered.plugin.meta.PluginDependency;
import java.nio.file.Path;
@@ -122,11 +125,22 @@ default Optional getDependency(String id) {
return Optional.empty();
}
+ /**
+ * Retrieves the {@link Asset} of the specified name from the
+ * {@link AssetManager} for this {@link Plugin}.
+ *
+ * @param name Name of asset
+ * @return Asset if present, empty otherwise
+ */
+ default Optional getAsset(String name) {
+ return Sponge.getAssetManager().getAsset(this, name);
+ }
+
/**
* Returns the source the plugin was loaded from.
*
* @return The source the plugin was loaded from or {@link Optional#empty()}
- * if unknown
+ * if unknown
*/
default Optional getSource() {
return Optional.empty();
From 84cf0d9aec19651b8fd2e50b48bf681dd15b75e1 Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Sat, 11 May 2019 21:11:12 -0400
Subject: [PATCH 15/22] AsyncReloader had too much impl.
---
.../java/org/spongepowered/api/Engine.java | 14 ++++++--
.../resource/ResourceEvent.java} | 32 +++++++++++++----
.../api/resource/AsyncReloadListener.java | 14 --------
.../api/resource/AsyncReloader.java | 34 -------------------
.../api/resource/ResourceManager.java | 2 +-
.../api/resource/ResourcePath.java | 9 +++--
.../api/resource/SimpleReloadListener.java | 13 -------
.../spongepowered/api/resource/pack/Pack.java | 19 +++++++----
.../api/resource/pack/PackInfo.java | 34 +++++--------------
.../api/resource/pack/PackRepository.java | 30 ++++++++--------
10 files changed, 77 insertions(+), 124 deletions(-)
rename src/main/java/org/spongepowered/api/{resource/ReloadableResourceManager.java => event/resource/ResourceEvent.java} (63%)
delete mode 100644 src/main/java/org/spongepowered/api/resource/AsyncReloadListener.java
delete mode 100644 src/main/java/org/spongepowered/api/resource/AsyncReloader.java
delete mode 100644 src/main/java/org/spongepowered/api/resource/SimpleReloadListener.java
diff --git a/src/main/java/org/spongepowered/api/Engine.java b/src/main/java/org/spongepowered/api/Engine.java
index b6f808732d5..8bb77138369 100644
--- a/src/main/java/org/spongepowered/api/Engine.java
+++ b/src/main/java/org/spongepowered/api/Engine.java
@@ -29,12 +29,12 @@
import org.spongepowered.api.resource.pack.PackRepository;
import org.spongepowered.api.scheduler.Scheduler;
-import java.util.concurrent.Executor;
+import java.util.concurrent.CompletableFuture;
/**
* Shared functionality between {@link Client} and {@link Server} engines.
*/
-public interface Engine extends Executor {
+public interface Engine {
/**
* Gets the {@link Scheduler} used to schedule sync tasks on this {@link Engine}.
@@ -46,7 +46,7 @@ public interface Engine extends Executor {
/**
* Gets the {@link ResourceManager} for the server instance. As of
* Minecraft 1.13 there is only one instance of the resource manager per
- * server instance. It is not per-world.
+ * server/client instance. It is not per-world.
*
* @return The resource manager
*/
@@ -58,6 +58,14 @@ public interface Engine extends Executor {
*/
PackRepository getPackRepository();
+ /**
+ * Reloads resources from the {@link ResourceManager} using active packs
+ * from the {@link PackRepository}.
+ *
+ * @return The future when it will finish.
+ */
+ CompletableFuture reloadResources();
+
/**
* Checks if the {@link Thread#currentThread() current thread} is the main thread of the engine.
*
diff --git a/src/main/java/org/spongepowered/api/resource/ReloadableResourceManager.java b/src/main/java/org/spongepowered/api/event/resource/ResourceEvent.java
similarity index 63%
rename from src/main/java/org/spongepowered/api/resource/ReloadableResourceManager.java
rename to src/main/java/org/spongepowered/api/event/resource/ResourceEvent.java
index d2f811ea1e7..21152c2b84d 100644
--- a/src/main/java/org/spongepowered/api/resource/ReloadableResourceManager.java
+++ b/src/main/java/org/spongepowered/api/event/resource/ResourceEvent.java
@@ -22,14 +22,34 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.api.resource;
+package org.spongepowered.api.event.resource;
-public interface ReloadableResourceManager extends ResourceManager {
+import org.spongepowered.api.Engine;
+import org.spongepowered.api.event.Event;
+import org.spongepowered.api.resource.ResourceManager;
- default AsyncReloader.Builder reload() {
- return AsyncReloader.builder().manager(this);
- }
+/**
+ * Base class for events related to resources.
+ */
+public interface ResourceEvent extends Event {
+
+ /**
+ * Gets the engine of the resources
+ * @return The engine
+ */
+ Engine getEngine();
- void addListener(AsyncReloadListener listener);
+ /**
+ * Gets the {@link ResourceManager}.
+ * @return The resource manager
+ */
+ ResourceManager getResourceManager();
+ /**
+ * Fired after a {@link ResourceManager} has been reloaded. This can be
+ * used to reload some systems that are resource based.
+ */
+ interface Reload extends ResourceEvent {
+
+ }
}
diff --git a/src/main/java/org/spongepowered/api/resource/AsyncReloadListener.java b/src/main/java/org/spongepowered/api/resource/AsyncReloadListener.java
deleted file mode 100644
index 3a8173f4a58..00000000000
--- a/src/main/java/org/spongepowered/api/resource/AsyncReloadListener.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.spongepowered.api.resource;
-
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-import java.util.concurrent.CompletableFuture;
-
-public interface AsyncReloadListener {
-
- CompletableFuture listen(Staging stg, AsyncReloader reloader);
-
- interface Staging {
- <@Nullable T> CompletableFuture setup(T instance);
- }
-}
diff --git a/src/main/java/org/spongepowered/api/resource/AsyncReloader.java b/src/main/java/org/spongepowered/api/resource/AsyncReloader.java
deleted file mode 100644
index 46b8199cb1d..00000000000
--- a/src/main/java/org/spongepowered/api/resource/AsyncReloader.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.spongepowered.api.resource;
-
-import org.spongepowered.api.Sponge;
-import org.spongepowered.api.resource.pack.Pack;
-import org.spongepowered.api.util.ResettableBuilder;
-
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executor;
-
-public interface AsyncReloader {
-
- static Builder builder() {
- return Sponge.getRegistry().createBuilder(Builder.class);
- }
-
- ResourceManager getResourceManager();
-
- Executor getWorker();
-
- Executor getEngine();
-
- interface Builder extends ResettableBuilder {
-
- Builder manager(ReloadableResourceManager manager);
-
- Builder engine(Executor engine);
-
- Builder packs(Pack... packs);
-
- Builder action(CompletableFuture action);
-
- AsyncReloader build();
- }
-}
diff --git a/src/main/java/org/spongepowered/api/resource/ResourceManager.java b/src/main/java/org/spongepowered/api/resource/ResourceManager.java
index c3d25efd65c..2a1ab6fef22 100644
--- a/src/main/java/org/spongepowered/api/resource/ResourceManager.java
+++ b/src/main/java/org/spongepowered/api/resource/ResourceManager.java
@@ -89,7 +89,7 @@ public interface ResourceManager {
* @param filter The file name filter
* @return A collection of resource paths
*/
- Collection getPaths(String path, Predicate filter);
+ Collection getPaths(String path, Predicate filter);
/**
* Returns true if the given {@link ResourcePath} exists in the active
diff --git a/src/main/java/org/spongepowered/api/resource/ResourcePath.java b/src/main/java/org/spongepowered/api/resource/ResourcePath.java
index 2b99759f262..d3b01fd6570 100644
--- a/src/main/java/org/spongepowered/api/resource/ResourcePath.java
+++ b/src/main/java/org/spongepowered/api/resource/ResourcePath.java
@@ -25,12 +25,9 @@
package org.spongepowered.api.resource;
import org.spongepowered.api.Sponge;
-import org.spongepowered.api.data.DataContainer;
-import org.spongepowered.api.data.DataSerializable;
+import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.util.ResettableBuilder;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -185,6 +182,7 @@ static ResourcePath parse(String path) throws IllegalArgumentException {
*
* @implNote Implementation should override this for Map usage.
*/
+ @Override
boolean equals(Object other);
/**
@@ -192,6 +190,7 @@ static ResourcePath parse(String path) throws IllegalArgumentException {
*
* @implNote Implementation should override this for Map usage.
*/
+ @Override
int hashCode();
/**
@@ -215,7 +214,7 @@ interface Builder extends ResettableBuilder {
* @param plugin The owning plugin
* @return This builder
*/
- Builder plugin(Object plugin);
+ Builder namespace(PluginContainer plugin);
/**
* Sets the path of the {@link ResourcePath}.
diff --git a/src/main/java/org/spongepowered/api/resource/SimpleReloadListener.java b/src/main/java/org/spongepowered/api/resource/SimpleReloadListener.java
deleted file mode 100644
index ba18c4ee61c..00000000000
--- a/src/main/java/org/spongepowered/api/resource/SimpleReloadListener.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.spongepowered.api.resource;
-
-
-import java.util.concurrent.CompletableFuture;
-
-public interface SimpleReloadListener extends AsyncReloadListener {
- @Override
- default CompletableFuture listen(Staging stg, AsyncReloader reloader) {
- return stg.setup(null).thenRunAsync(() -> onReload(reloader.getResourceManager()), reloader.getEngine());
- }
-
- void onReload(ResourceManager manager);
-}
diff --git a/src/main/java/org/spongepowered/api/resource/pack/Pack.java b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
index 52a692de71c..f319614e20f 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/Pack.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
@@ -32,7 +32,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
-import java.util.Optional;
+import java.util.Set;
import java.util.function.Predicate;
/**
@@ -55,13 +55,13 @@ public interface Pack {
* Recursively gets all the resources loaded from this pack. All namespaces
* are considered.
*
- * @param type The resource type
- * @param path The resource path
+ * @param type The resource type
+ * @param path The resource path
* @param filter The file name filter
* @return Collection of resources
* @see ResourceManager#getPaths(String, Predicate)
*/
- Collection getPaths(PackType type, String path, Predicate filter);
+ Collection getPaths(PackType type, String path, int depth, Predicate filter);
/**
* Checks if a resource exists in this pack.
@@ -72,14 +72,21 @@ public interface Pack {
*/
boolean exists(PackType type, ResourcePath path);
+ /**
+ * Gets all the namespaces which exist in this pack.
+ *
+ * @return The set of namespaces
+ */
+ Set getNamespaces();
+
/**
* Gets the metadata of this pack. The {@link DataView} represented is of
* the pack.json file in the pack root. If the pack does not contain a
- * pack.json, {@link Optional#empty()} is returned.
+ * pack.json, it is an error.
*
* @return The metadata if it exists
*/
- Optional getMetadata();
+ DataView getMetadata();
/**
* Gets the name of this pack which is displayed to the user.
diff --git a/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java b/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
index 3a2c2fb83a2..49e209e6e25 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
@@ -42,7 +42,8 @@ public interface PackInfo extends DataSerializable, TextRepresentable {
String getName();
/**
- * Gets the display name of the {@link Pack} which is displayed to the user.
+ * Gets the display name of the {@link Pack} which is displayed to the
+ * user. This is loaded from the pack.mcmeta
*
* @return The display name
*/
@@ -50,18 +51,18 @@ public interface PackInfo extends DataSerializable, TextRepresentable {
/**
* Gets the description of the {@link Pack} which is displayed as the hover
- * text to the user.
+ * text to the user. This is loaded from the pack.mcmeta
*
* @return The description
*/
Text getDescription();
/**
- * Gets the {@link Pack} associated with this pack info.
+ * Creates a new instance of {@link Pack} associated with this pack info.
*
- * @return
+ * @return The new Pack
*/
- Pack getPack();
+ Pack createPack();
/**
* Gets whether or not this pack is required to be active. If it is
@@ -72,30 +73,11 @@ public interface PackInfo extends DataSerializable, TextRepresentable {
*/
boolean isRequired();
- /**
- * Gets whether or not this pack was loaded from a remote location. For
- * example, if this is a server-defined client resource pack.
- *
- * @return Whether this pack is remote
- */
- boolean isRemote();
-
- boolean isLocked();
-
- Priority getPriority();
+ InsertionPosition getPosition();
- Compatibility getCompatability();
-
- enum Priority {
+ enum InsertionPosition {
FIRST,
LAST
}
- enum Compatibility {
- OLD,
- NEW,
- OK
- }
-
-
}
diff --git a/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java b/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
index a4f0e381e93..7ef66d3338e 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
@@ -24,23 +24,28 @@
*/
package org.spongepowered.api.resource.pack;
+import org.spongepowered.api.Engine;
import org.spongepowered.api.plugin.PluginContainer;
-import org.spongepowered.api.resource.ReloadableResourceManager;
-import org.spongepowered.api.resource.ResourceManager;
import java.util.Collection;
import java.util.Optional;
public interface PackRepository {
+ /**
+ * Refreshes all the providers in the repository.
+ */
+ void refresh();
+
/**
* Sets the active packs to be used when reloading resources. Calls to this
- * should be followed by {@link ReloadableResourceManager#reload()}.
+ * should be followed by {@link Engine#reloadResources()} in order to take
+ * effect.
*
* @param packs The active packs
- * @see ReloadableResourceManager#reload()
+ * @see Engine#reloadResources()
*/
- void setActivePacks(Collection packs);
+ void setEnabledPacks(Collection packs);
/**
* Returns a collection of all available packs. An available pack could be
@@ -50,14 +55,7 @@ public interface PackRepository {
*/
Collection getAllPacks();
- /**
- * Returns a collection of the disabled packs. Disabled packs are present,
- * but not used in the {@link ResourceManager}. Resources can still be
- * accessed using {@link PackInfo#getPack()}.
- *
- * @return The disabled packs
- */
- Collection getDisabledPacks();
+ Collection getAvailablePacks();
/**
* Returns a collection of enabled packs.
@@ -67,14 +65,14 @@ public interface PackRepository {
Collection getEnabledPacks();
/**
- * Gets the {@link Pack} defined from {@link PluginContainer#getSource()}.
- * The name of the pack will contain the plugin id.
+ * Gets the {@link Pack} defined from the plugin contains. The name of the
+ * pack will contain the plugin id.
*
* @param plugin The plugin instance or container.
* @return The pack
* @throws IllegalArgumentException if the object is not a plugin
*/
- PackInfo getPack(Object plugin);
+ PackInfo getPack(PluginContainer plugin);
/**
* Gets the pack by its name.
From 309d66ec73603cff4d8e166941937399eb3ad575 Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Sat, 11 May 2019 21:25:09 -0400
Subject: [PATCH 16/22] Pack should be closeable.
---
src/main/java/org/spongepowered/api/resource/pack/Pack.java | 3 ++-
.../org/spongepowered/api/resource/pack/PackRepository.java | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/spongepowered/api/resource/pack/Pack.java b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
index f319614e20f..63ac13bc487 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/Pack.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
@@ -29,6 +29,7 @@
import org.spongepowered.api.resource.ResourceManager;
import org.spongepowered.api.resource.ResourcePath;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
@@ -39,7 +40,7 @@
* A pack can contain several {@link Resource Resources}. Each pack is
* independently loaded with a configured priority.
*/
-public interface Pack {
+public interface Pack extends Closeable {
/**
* Opens a new {@link InputStream} to the specified resource.
diff --git a/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java b/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
index 7ef66d3338e..a16d7a31bfd 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
@@ -65,7 +65,7 @@ public interface PackRepository {
Collection getEnabledPacks();
/**
- * Gets the {@link Pack} defined from the plugin contains. The name of the
+ * Gets the {@link Pack} defined from the plugin container. The name of the
* pack will contain the plugin id.
*
* @param plugin The plugin instance or container.
From d6dc2a03231afec423293b44906c4c47c32f4ba6 Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Sat, 11 May 2019 21:59:46 -0400
Subject: [PATCH 17/22] Fixes to javadocs and nitpicks
---
.../spongepowered/api/resource/pack/Pack.java | 6 +++---
.../api/resource/pack/PackInfo.java | 10 +++++++---
.../api/resource/pack/PackRepository.java | 18 ++++++++++++++----
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/spongepowered/api/resource/pack/Pack.java b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
index 63ac13bc487..f94e31b8954 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/Pack.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
@@ -62,7 +62,7 @@ public interface Pack extends Closeable {
* @return Collection of resources
* @see ResourceManager#getPaths(String, Predicate)
*/
- Collection getPaths(PackType type, String path, int depth, Predicate filter);
+ Collection getPaths(PackType type, String path, int depth, Predicate filter);
/**
* Checks if a resource exists in this pack.
@@ -82,8 +82,8 @@ public interface Pack extends Closeable {
/**
* Gets the metadata of this pack. The {@link DataView} represented is of
- * the pack.json file in the pack root. If the pack does not contain a
- * pack.json, it is an error.
+ * the pack.mcmeta file in the pack root. If the pack does not contain a
+ * pack.mcmeta, it is an error.
*
* @return The metadata if it exists
*/
diff --git a/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java b/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
index 49e209e6e25..07be2b0f896 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
@@ -24,14 +24,13 @@
*/
package org.spongepowered.api.resource.pack;
-import org.spongepowered.api.data.DataSerializable;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.TextRepresentable;
/**
- * Basic info about a {@link Pack}
+ * Basic info about a {@link Pack}. Is also used to create new instances.
*/
-public interface PackInfo extends DataSerializable, TextRepresentable {
+public interface PackInfo extends TextRepresentable {
/**
* Gets the name of the {@link Pack} used to identify it in the
@@ -73,6 +72,11 @@ public interface PackInfo extends DataSerializable, TextRepresentable {
*/
boolean isRequired();
+ /**
+ * Gets the insertion position of this pack. Should it be added before or
+ * after existing packs?
+ * @return
+ */
InsertionPosition getPosition();
enum InsertionPosition {
diff --git a/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java b/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
index a16d7a31bfd..0bec390387b 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackRepository.java
@@ -28,8 +28,14 @@
import org.spongepowered.api.plugin.PluginContainer;
import java.util.Collection;
+import java.util.List;
import java.util.Optional;
+/**
+ * Manages the {@link PackInfo packs} which are known to the game. Use this
+ * class to get specific packs, as well as enable and disable packs from
+ * loading on the next call to {@link Engine#reloadResources()}.
+ */
public interface PackRepository {
/**
@@ -45,7 +51,7 @@ public interface PackRepository {
* @param packs The active packs
* @see Engine#reloadResources()
*/
- void setEnabledPacks(Collection packs);
+ void setEnabledPacks(List packs);
/**
* Returns a collection of all available packs. An available pack could be
@@ -55,6 +61,11 @@ public interface PackRepository {
*/
Collection getAllPacks();
+ /**
+ * Gets the list of packs which are not enabled.
+ *
+ * @return The disabled packs
+ */
Collection getAvailablePacks();
/**
@@ -62,15 +73,14 @@ public interface PackRepository {
*
* @return The enabled packs
*/
- Collection getEnabledPacks();
+ List getEnabledPacks();
/**
* Gets the {@link Pack} defined from the plugin container. The name of the
* pack will contain the plugin id.
*
- * @param plugin The plugin instance or container.
+ * @param plugin The plugin container.
* @return The pack
- * @throws IllegalArgumentException if the object is not a plugin
*/
PackInfo getPack(PluginContainer plugin);
From a47186a37dd7c912b5aeabc44c47931d5cf3c044 Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Sat, 11 May 2019 23:15:01 -0400
Subject: [PATCH 18/22] Change PackTypes.ASSETS to RESOURCES
---
.../org/spongepowered/api/resource/pack/PackTypes.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/spongepowered/api/resource/pack/PackTypes.java b/src/main/java/org/spongepowered/api/resource/pack/PackTypes.java
index 37f3e4b7316..78fe2d0227f 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/PackTypes.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackTypes.java
@@ -30,9 +30,15 @@ public class PackTypes {
// SORTFIELDS:ON
- public static final PackType ASSETS = DummyObjectProvider.createFor(PackType.class, "ASSETS");
-
+ /**
+ * Resources from the server. The root directory is {@code /data}.
+ */
public static final PackType DATA = DummyObjectProvider.createFor(PackType.class, "DATA");
+ /**
+ * Resources from the client. The root directory is {@code /assets}.
+ */
+ public static final PackType RESOURCES = DummyObjectProvider.createFor(PackType.class, "RESOURCES");
+
// SORTFIELDS:OFF
}
From b124bb87a12482339be6fdf24c528ff07e52be62 Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Tue, 14 May 2019 22:17:35 -0400
Subject: [PATCH 19/22] Remove the assets package.
---
src/main/java/org/spongepowered/api/Game.java | 11 -
.../java/org/spongepowered/api/Sponge.java | 12 -
.../org/spongepowered/api/asset/Asset.java | 218 ------------------
.../org/spongepowered/api/asset/AssetId.java | 51 ----
.../spongepowered/api/asset/AssetManager.java | 69 ------
.../spongepowered/api/asset/package-info.java | 26 ---
.../api/plugin/PluginContainer.java | 14 --
7 files changed, 401 deletions(-)
delete mode 100644 src/main/java/org/spongepowered/api/asset/Asset.java
delete mode 100644 src/main/java/org/spongepowered/api/asset/AssetId.java
delete mode 100644 src/main/java/org/spongepowered/api/asset/AssetManager.java
delete mode 100644 src/main/java/org/spongepowered/api/asset/package-info.java
diff --git a/src/main/java/org/spongepowered/api/Game.java b/src/main/java/org/spongepowered/api/Game.java
index 4579b744e67..fa1f92dd4d0 100644
--- a/src/main/java/org/spongepowered/api/Game.java
+++ b/src/main/java/org/spongepowered/api/Game.java
@@ -24,7 +24,6 @@
*/
package org.spongepowered.api;
-import org.spongepowered.api.asset.AssetManager;
import org.spongepowered.api.client.Client;
import org.spongepowered.api.config.ConfigManager;
import org.spongepowered.api.data.DataManager;
@@ -163,16 +162,6 @@ default EventManager getEventManager() {
return Sponge.getEventManager();
}
- /**
- * Gets the {@link AssetManager}.
- *
- * @return The asset manager
- */
- @Deprecated
- default AssetManager getAssetManager() {
- return Sponge.getAssetManager();
- }
-
/**
* Gets the {@link ConfigManager} used to load and manage configuration files
* for plugins.
diff --git a/src/main/java/org/spongepowered/api/Sponge.java b/src/main/java/org/spongepowered/api/Sponge.java
index 2a7562363a9..0a1ed94a972 100644
--- a/src/main/java/org/spongepowered/api/Sponge.java
+++ b/src/main/java/org/spongepowered/api/Sponge.java
@@ -28,7 +28,6 @@
import com.google.inject.Inject;
import org.checkerframework.checker.nullness.qual.Nullable;
-import org.spongepowered.api.asset.AssetManager;
import org.spongepowered.api.command.manager.CommandManager;
import org.spongepowered.api.config.ConfigManager;
import org.spongepowered.api.data.DataManager;
@@ -58,7 +57,6 @@ public final class Sponge {
@Inject private static PropertyRegistry propertyRegistry;
@Inject private static PluginManager pluginManager;
@Inject private static EventManager eventManager;
- @Inject private static AssetManager assetManager;
@Inject private static ConfigManager configManager;
@Inject private static ServiceManager serviceManager;
@Inject private static ChannelRegistrar channelRegistrar;
@@ -140,16 +138,6 @@ public static EventManager getEventManager() {
return check(eventManager);
}
- /**
- * Gets the {@link AssetManager} instance.
- *
- * @return The asset manager instance
- */
- @Deprecated
- public static AssetManager getAssetManager() {
- return check(assetManager);
- }
-
/**
* Gets the {@link ConfigManager} used to load and manage configuration files
* for plugins.
diff --git a/src/main/java/org/spongepowered/api/asset/Asset.java b/src/main/java/org/spongepowered/api/asset/Asset.java
deleted file mode 100644
index 0c6f52b3a7a..00000000000
--- a/src/main/java/org/spongepowered/api/asset/Asset.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * This file is part of SpongeAPI, licensed under the MIT License (MIT).
- *
- * Copyright (c) SpongePowered
- * Copyright (c) contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package org.spongepowered.api.asset;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.io.Resources;
-import org.spongepowered.api.plugin.Plugin;
-import org.spongepowered.api.plugin.PluginContainer;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.List;
-
-/**
- * Represents an {@link Asset} within Sponge that belongs to a {@link Plugin}.
- */
-@Deprecated
-public interface Asset {
-
- /**
- * The default {@link Charset} that is used for reading {@link Asset}s.
- */
- Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
-
- /**
- * Returns the original {@link Plugin} owner of this Asset.
- *
- * @return Original owner of asset
- */
- PluginContainer getOwner();
-
- /**
- * Returns the {@link URL} to this Asset.
- *
- * @return URL to asset
- */
- URL getUrl();
-
- /**
- * Copies this Asset to the specified 'output' {@link Path}.
- *
- * @param output Path to copy to
- * @throws IOException If any file exception is thrown
- */
- default void copyToFile(Path output) throws IOException {
- this.copyToFile(output, false);
- }
-
- /**
- * Copies this Asset to the specified 'output' {@link Path}.
- *
- * @param output Path to copy to
- * @param overwrite If the file should be overwritten if it exists
- * @throws IOException File exception
- */
- default void copyToFile(Path output, boolean overwrite) throws IOException {
- this.copyToFile(output, overwrite, true);
- }
-
- /**
- * Copies this Asset to the specified 'output' {@link Path}.
- *
- * @param output Path to copy to
- * @param overwrite If the file should be overwritten if it exists
- * @param onlyIfAbsent If the file should only be copied if absent
- * @throws IOException File exception
- */
- default void copyToFile(Path output, boolean overwrite, boolean onlyIfAbsent) throws IOException {
- checkNotNull(output, "output");
- if (Files.exists(output)) {
- if (overwrite) {
- Files.delete(output);
- } else if (onlyIfAbsent) {
- return;
- }
- }
- try (InputStream in = this.getUrl().openStream()) {
- Files.copy(in, output);
- }
- }
-
- /**
- * Copies this Asset to the specified 'outputDirectory' {@link Path}.
- *
- * @param outputDirectory The directory to copy to
- * @throws IOException If any file exception is thrown
- */
- default void copyToDirectory(Path outputDirectory) throws IOException {
- this.copyToDirectory(outputDirectory, false);
- }
-
- /**
- * Copies this Asset to the specified 'outputDirectory' {@link Path}.
- *
- * @param outputDirectory The directory to copy to
- * @param overwrite If the file should be overwritten if it exists
- * @throws IOException File exception
- */
- default void copyToDirectory(Path outputDirectory, boolean overwrite) throws IOException {
- this.copyToDirectory(outputDirectory, overwrite, true);
- }
-
- /**
- * Copies this Asset to the specified 'outputDirectory' {@link Path}.
- *
- * @param outputDirectory The directory to copy to
- * @param overwrite If the file should be overwritten if it exists
- * @param onlyIfAbsent If the file should only be copied if absent
- * @throws IOException File exception
- */
- default void copyToDirectory(Path outputDirectory, boolean overwrite, boolean onlyIfAbsent) throws IOException {
- checkNotNull(outputDirectory, "outputDirectory");
- Files.createDirectories(outputDirectory);
- this.copyToFile(outputDirectory.resolve(this.getFileName()), overwrite, onlyIfAbsent);
- }
-
- /**
- * Returns the the last portion of the Asset URL, e.g. the file name.
- *
- * @return The file name
- */
- default String getFileName() {
- String path = getUrl().getPath();
- //We don't need to worry about file system specific file separators as we are dealing with a substring of URL
- int end = path.lastIndexOf('/');
- if (end < 0) {
- return path;
- }
-
- return path.substring(end + 1);
- }
-
- /**
- * Reads this Asset in it's entirety as a {@link String} and returns the
- * result.
- *
- * @return String representation of Asset
- * @throws IOException If any file exception is thrown
- */
- default String readString() throws IOException {
- return readString(DEFAULT_CHARSET);
- }
-
- /**
- * Reads this Asset in it's entirety as a {@link String} and returns the
- * result.
- *
- * @param charset The charset to read the asset with
- * @return String representation of Asset
- * @throws IOException If any file exception is thrown
- */
- default String readString(Charset charset) throws IOException {
- checkNotNull(charset, "charset");
- return Resources.toString(getUrl(), charset);
- }
-
- /**
- * Reads all lines from the asset and returns the result.
- *
- * @return The lines read from the asset
- * @throws IOException If any file exception is thrown
- */
- default List readLines() throws IOException {
- return readLines(DEFAULT_CHARSET);
- }
-
- /**
- * Reads all lines from the asset and returns the result.
- *
- * @param charset The charset to read the asset with
- * @return An immutable list of the lines read from the asset
- * @throws IOException If any file exception is thrown
- */
- default List readLines(Charset charset) throws IOException {
- checkNotNull(charset, "charset");
- return Resources.asCharSource(getUrl(), charset).readLines();
- }
-
- /**
- * Reads this Asset in it's entirety as a byte array and returns the
- * result.
- *
- * @return Byte array representation of Asset
- * @throws IOException If any file exception is thrown
- */
- default byte[] readBytes() throws IOException {
- return Resources.toByteArray(getUrl());
- }
-
-}
diff --git a/src/main/java/org/spongepowered/api/asset/AssetId.java b/src/main/java/org/spongepowered/api/asset/AssetId.java
deleted file mode 100644
index 919c936feaf..00000000000
--- a/src/main/java/org/spongepowered/api/asset/AssetId.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * This file is part of SpongeAPI, licensed under the MIT License (MIT).
- *
- * Copyright (c) SpongePowered
- * Copyright (c) contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package org.spongepowered.api.asset;
-
-import com.google.inject.BindingAnnotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Provides an injection for {@link Asset}s in plugins.
- */
-@Deprecated
-@BindingAnnotation
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.PARAMETER})
-public @interface AssetId {
-
- /**
- * The path to the {@link Asset} in the asset folder of the plugin.
- *
- * @return The path to the asset
- * @see AssetManager#getAsset(String)
- */
- String value();
-
-}
diff --git a/src/main/java/org/spongepowered/api/asset/AssetManager.java b/src/main/java/org/spongepowered/api/asset/AssetManager.java
deleted file mode 100644
index d0dfb8dc0f3..00000000000
--- a/src/main/java/org/spongepowered/api/asset/AssetManager.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * This file is part of SpongeAPI, licensed under the MIT License (MIT).
- *
- * Copyright (c) SpongePowered
- * Copyright (c) contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package org.spongepowered.api.asset;
-
-import org.spongepowered.api.plugin.Plugin;
-import org.spongepowered.api.plugin.PluginContainer;
-import org.spongepowered.api.resource.ResourceManager;
-
-import java.util.Optional;
-
-/**
- * The AssetManager offers a convenient way to easily retrieve resources from
- * Sponge {@link Plugin}s. The asset manager will attempt to find the
- * asset of the specified name at: assets/<plugin_id>
- *
- * @deprecated The asset manager was unable to provide assets which are not on
- * the classpath. Additionally, it was limited to providing the URL to an
- * asset, which might not have been useful in some situations.
- *
- * Use the more powerful {@link ResourceManager} instead. It allows you to
- * add resources from local files as well as on-the-fly generation.
- */
-@Deprecated
-public interface AssetManager {
-
- /**
- * Returns the {@link Asset} of the specified name for the specified
- * {@link Plugin} instance.
- *
- * @param plugin Plugin instance
- * @param name Name of resource to retrieve
- * @return Asset if present, empty otherwise
- */
- Optional getAsset(PluginContainer plugin, String name);
-
- /**
- * Returns the {@link Asset} of the specified name within the domain of the
- * implementation. This method will typically call
- * {@link #getAsset(PluginContainer, String)} using a dummy
- * {@link PluginContainer} for the SpongeAPI implementation.
- *
- * @param name Name of resource to retrieve
- * @return Asset if present, empty otherwise
- */
- Optional getAsset(String name);
-
-}
diff --git a/src/main/java/org/spongepowered/api/asset/package-info.java b/src/main/java/org/spongepowered/api/asset/package-info.java
deleted file mode 100644
index bbc2a752e3c..00000000000
--- a/src/main/java/org/spongepowered/api/asset/package-info.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * This file is part of SpongeAPI, licensed under the MIT License (MIT).
- *
- * Copyright (c) SpongePowered
- * Copyright (c) contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-@org.checkerframework.framework.qual.DefaultQualifier(org.checkerframework.checker.nullness.qual.NonNull.class)
-package org.spongepowered.api.asset;
diff --git a/src/main/java/org/spongepowered/api/plugin/PluginContainer.java b/src/main/java/org/spongepowered/api/plugin/PluginContainer.java
index 775d211f964..58d87487be3 100644
--- a/src/main/java/org/spongepowered/api/plugin/PluginContainer.java
+++ b/src/main/java/org/spongepowered/api/plugin/PluginContainer.java
@@ -29,9 +29,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.api.CatalogKey;
-import org.spongepowered.api.Sponge;
-import org.spongepowered.api.asset.Asset;
-import org.spongepowered.api.asset.AssetManager;
import org.spongepowered.plugin.meta.PluginDependency;
import java.nio.file.Path;
@@ -125,17 +122,6 @@ default Optional getDependency(String id) {
return Optional.empty();
}
- /**
- * Retrieves the {@link Asset} of the specified name from the
- * {@link AssetManager} for this {@link Plugin}.
- *
- * @param name Name of asset
- * @return Asset if present, empty otherwise
- */
- default Optional getAsset(String name) {
- return Sponge.getAssetManager().getAsset(this, name);
- }
-
/**
* Returns the source the plugin was loaded from.
*
From f540f2be84b2f6e11f97faf3930470d7d7a60f7f Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Tue, 14 May 2019 22:18:04 -0400
Subject: [PATCH 20/22] Fix some nitpicks
---
.../java/org/spongepowered/api/resource/pack/Pack.java | 4 ++--
.../org/spongepowered/api/resource/pack/PackInfo.java | 10 +++++-----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/spongepowered/api/resource/pack/Pack.java b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
index f94e31b8954..467eaa1819a 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/Pack.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/Pack.java
@@ -83,9 +83,9 @@ public interface Pack extends Closeable {
/**
* Gets the metadata of this pack. The {@link DataView} represented is of
* the pack.mcmeta file in the pack root. If the pack does not contain a
- * pack.mcmeta, it is an error.
+ * pack.mcmeta, an auto-generated view is returned.
*
- * @return The metadata if it exists
+ * @return The metadata
*/
DataView getMetadata();
diff --git a/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java b/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
index 07be2b0f896..8ee80fe336f 100644
--- a/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
+++ b/src/main/java/org/spongepowered/api/resource/pack/PackInfo.java
@@ -33,20 +33,20 @@
public interface PackInfo extends TextRepresentable {
/**
- * Gets the name of the {@link Pack} used to identify it in the
+ * Gets the id of the {@link Pack} used to identify it in the
* {@link PackRepository}.
*
* @return The pack name
*/
- String getName();
+ String getId();
/**
- * Gets the display name of the {@link Pack} which is displayed to the
- * user. This is loaded from the pack.mcmeta
+ * Gets the name of the {@link Pack} which is displayed to the
+ * user.
*
* @return The display name
*/
- Text getDisplayName();
+ Text getName();
/**
* Gets the description of the {@link Pack} which is displayed as the hover
From fcfb76c7931dafee07f64f3e9294c4a7a952e014 Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Tue, 18 Jun 2019 01:29:14 -0400
Subject: [PATCH 21/22] Remove WillNotClose from Resource copy.
---
src/main/java/org/spongepowered/api/resource/Resource.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/org/spongepowered/api/resource/Resource.java b/src/main/java/org/spongepowered/api/resource/Resource.java
index dd3707e5969..e92f24f4856 100644
--- a/src/main/java/org/spongepowered/api/resource/Resource.java
+++ b/src/main/java/org/spongepowered/api/resource/Resource.java
@@ -42,7 +42,6 @@
import java.nio.file.Path;
import java.util.Optional;
import java.util.stream.Stream;
-import javax.annotation.WillNotClose;
/**
* A resource can represent any kind of loaded data. It can be a file on the
@@ -171,7 +170,7 @@ default void copyTo(Path path, OpenOption... options) throws IOException {
* @param out The output stream to write
* @throws IOException if an error occurs
*/
- default void copyTo(@WillNotClose OutputStream out) throws IOException {
+ default void copyTo(OutputStream out) throws IOException {
ByteStreams.copy(getInputStream(), out);
}
From b195b1d128281d8f751ebea503036cdac89e23ab Mon Sep 17 00:00:00 2001
From: Matthew Messinger
Date: Tue, 18 Jun 2019 01:35:25 -0400
Subject: [PATCH 22/22] Change getInputStream javadoc to represent current
code.
---
src/main/java/org/spongepowered/api/resource/Resource.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/org/spongepowered/api/resource/Resource.java b/src/main/java/org/spongepowered/api/resource/Resource.java
index e92f24f4856..2cbb2483496 100644
--- a/src/main/java/org/spongepowered/api/resource/Resource.java
+++ b/src/main/java/org/spongepowered/api/resource/Resource.java
@@ -61,8 +61,7 @@
public interface Resource extends Closeable {
/**
- * Returns a new {@link InputStream} of this resource. A new input stream
- * should be created each time this method is called.
+ * Returns the {@link InputStream} of this resource.
*
* @return A new input stream
*/