Skip to content

Commit 9684a0c

Browse files
mattmess1221ZidaneDaniel Naylor
authored andcommitted
Add resource manager for data packs
Add packs Updates to resources I did most of this a few months ago. I don't remember all the specifics. Remove leftover empty file from rebase Fix compile errors related to PluginContainer Add some missing javadocs Convert PackVersion to a standard catalog type More edits to javadocs Fix licenses Make proper register events for ResourceReloadListener and PackDiscoverer Add a reload method to Engine to reload resources. Tweaks to API for common impl Update to use kyori text Update for API changes Implement resource events API: rename the register event method Update for registry changes ResourcePath now wraps ResourceKey Update for latest api-8. Signed-off-by: Chris Sanders <[email protected]> Fixup more naming convention - Remove the need for a Closeablelist by turning it into Stream (which auto closes) in ResourceManager. Signed-off-by: Chris Sanders <[email protected]> More refactoring - PackInfo -> PackInformation - Establish that `Pack` is engine-scoped. It is not the intention of this API to instill that client resources should be loaded server side nor should server data be loaded client side. That does not mean that a plugin couldn't take it upon themselves to do so (they are simply files after all) but it is the goal of the API to correctly establish what a developer *should* be doing ultimately. - Per the former, move retrieval of a PluginContainer's pack to ResourceManager - Migrate PackVersion/PackType to enums. There is no reason a developer should be creating additional versions or types via the API. Signed-off-by: Chris Sanders <[email protected]> Move the information manager to the resource manager. Plugins should grab their information first. If they want a pack, they can call it off the information object. Signed-off-by: Chris Sanders <[email protected]> Update for feedback/refactoring - Remove exposing listeners, not really a goal of this API unless we one day add the ability to do additional plugin provided packs - Move PackRepository up to engine, this is not tied to resource managers - Various method name fixes/javadoc fixes (needs an overall javadoc pass) Signed-off-by: Chris Sanders <[email protected]> Name isn't very helpful. Signed-off-by: Chris Sanders <[email protected]> More updates to the resource packs API based on feedback. Signed-off-by: Chris Sanders <[email protected]> More updates based on discussion - Toss PackOrder - Toss PackVersion - Add PackStatus (makes way more sense than order) - Toss PackContentsMetadata (way too tied to Vanilla) - Adjust more javadocs Signed-off-by: Chris Sanders <[email protected]> Further work after implementing the resource pack API Signed-off-by: Chris Sanders <[email protected]> Enforce that this is an id (and not a name) Signed-off-by: Chris Sanders <[email protected]> Add requireResource method to Pack * Add #close override to resource related AutoClosables to match what is expected in Vanilla to reduce unnecessary checked exceptions (and FindBugs warnings) Update based on comments in PR Co-authored-by: Chris Sanders <[email protected]> Co-authored-by: Daniel Naylor <[email protected]>
1 parent 3481b71 commit 9684a0c

File tree

14 files changed

+641
-274
lines changed

14 files changed

+641
-274
lines changed

src/main/java/org/spongepowered/api/Engine.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@
2626

2727
import org.spongepowered.api.event.CauseStackManager;
2828
import org.spongepowered.api.registry.RegistryHolder;
29+
import org.spongepowered.api.resource.Resource;
30+
import org.spongepowered.api.resource.ResourceManager;
31+
import org.spongepowered.api.resource.pack.Pack;
32+
import org.spongepowered.api.resource.pack.PackContents;
33+
import org.spongepowered.api.resource.pack.PackRepository;
2934
import org.spongepowered.api.scheduler.Scheduler;
3035

36+
import java.util.concurrent.CompletableFuture;
37+
3138
/**
3239
* Shared functionality between {@link Client} and {@link Server} engines.
3340
*/
@@ -48,6 +55,16 @@ public interface Engine extends RegistryHolder {
4855
*/
4956
CauseStackManager causeStackManager();
5057

58+
/**
59+
* @return The {@link PackRepository pack repository}
60+
*/
61+
PackRepository packRepository();
62+
63+
/**
64+
* @return The {@link ResourceManager resource manager}
65+
*/
66+
ResourceManager resourceManager();
67+
5168
/**
5269
* Gets the {@link Scheduler} used to schedule sync tasks on this {@link Engine}.
5370
*
@@ -61,4 +78,13 @@ public interface Engine extends RegistryHolder {
6178
* @return {@code true} if main thread, {@code false} if not
6279
*/
6380
boolean onMainThread();
81+
82+
/**
83+
* Rediscovers all {@link Resource resources} within all {@link Pack pack's} {@link PackContents contents}.
84+
*
85+
* <p>On the server, the future will always be completed.</p>
86+
*
87+
* @return A future that completes when reloading is complete
88+
*/
89+
CompletableFuture<Void> reloadResources();
6490
}

src/main/java/org/spongepowered/api/Game.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package org.spongepowered.api;
2626

2727
import org.checkerframework.checker.nullness.qual.NonNull;
28-
import org.spongepowered.api.asset.AssetManager;
2928
import org.spongepowered.api.config.ConfigManager;
3029
import org.spongepowered.api.data.DataManager;
3130
import org.spongepowered.api.data.persistence.DataBuilder;
@@ -160,13 +159,6 @@ default Client client() {
160159
*/
161160
EventManager eventManager();
162161

163-
/**
164-
* Gets the {@link AssetManager}.
165-
*
166-
* @return The asset manager
167-
*/
168-
AssetManager assetManager();
169-
170162
/**
171163
* Gets the {@link ConfigManager} used to load and manage configuration files
172164
* for plugins.
@@ -197,7 +189,7 @@ default Client client() {
197189
* @return The {@link SqlManager} instance.
198190
*/
199191
SqlManager sqlManager();
200-
192+
201193
/**
202194
* Gets the {@link ServiceProvider.GameScoped}, used to provide Sponge
203195
* services that plugins may provide. Services provided here are

src/main/java/org/spongepowered/api/Sponge.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.google.inject.Inject;
2828
import org.checkerframework.checker.nullness.qual.Nullable;
29-
import org.spongepowered.api.asset.AssetManager;
3029
import org.spongepowered.api.config.ConfigManager;
3130
import org.spongepowered.api.data.DataManager;
3231
import org.spongepowered.api.event.EventManager;
@@ -96,15 +95,6 @@ public static EventManager eventManager() {
9695
return Sponge.game().eventManager();
9796
}
9897

99-
/**
100-
* Gets the {@link AssetManager} instance.
101-
*
102-
* @return The asset manager instance
103-
*/
104-
public static AssetManager assetManager() {
105-
return Sponge.game().assetManager();
106-
}
107-
10898
/**
10999
* Gets the {@link ConfigManager} used to load and manage configuration files
110100
* for plugins.

src/main/java/org/spongepowered/api/asset/Asset.java

Lines changed: 0 additions & 216 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.resource;
26+
27+
import org.spongepowered.api.util.annotation.DoNotStore;
28+
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
import java.util.Optional;
32+
33+
/**
34+
* A resource can represent any kind of loaded data. It can be a file on the
35+
* filesystem, a network location, or even generated at runtime. Use
36+
* {@link #inputStream()} to retrieve the data.
37+
*/
38+
@DoNotStore
39+
public interface Resource extends AutoCloseable {
40+
41+
/**
42+
* @return The {@link ResourcePath path}
43+
*/
44+
ResourcePath path();
45+
46+
/**
47+
* Returns the {@link InputStream} of this resource. Multiple calls to this
48+
* method will not return a new object. To get a new object, get a new
49+
* resource.
50+
*
51+
* @return The input stream
52+
*/
53+
InputStream inputStream();
54+
55+
@Override
56+
void close() throws IOException;
57+
58+
}

0 commit comments

Comments
 (0)