forked from PseudoKnight/Stargate-Bukkit
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fe4d3a
commit 0d844c5
Showing
17 changed files
with
173 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/org/sgrewritten/stargate/api/MetadataHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.sgrewritten.stargate.api; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface MetadataHolder { | ||
|
||
/** | ||
* Set metadata for this portal. This sets all metadata for this entity, it's advised to use {@link MetadataHolder#setMetadata(JsonElement, String)} | ||
* | ||
* @param data <p> The meta data to set </p> | ||
*/ | ||
@ApiStatus.Internal | ||
void setMetadata(@Nullable String data); | ||
|
||
/** | ||
* Get metadata for this portal. This gets all metadata for this entity, it's advised to use the {@link MetadataHolder#getMetadata(String)} method | ||
* | ||
* @return <p> The meta data of this portal </p> | ||
*/ | ||
@ApiStatus.Internal | ||
@Nullable | ||
String getMetadata(); | ||
|
||
/** | ||
* Set the metadata of this instance | ||
* @param data <p>The data to set</p> | ||
* @param plugin <p>The name of the plugin this relates to</p> | ||
*/ | ||
default void setMetadata(@Nullable JsonElement data, String plugin){ | ||
JsonObject metadata = loadMetadata(); | ||
if (data == null) { | ||
metadata.remove(plugin); | ||
} else { | ||
metadata.add(plugin, data); | ||
} | ||
this.setMetadata(metadata.toString()); | ||
} | ||
|
||
/** | ||
* Get the metadata of this instance | ||
* @param pluginName <p>The name of the plugin this relates to</p> | ||
* @return <p>The metadata of this instance</p> | ||
*/ | ||
@Nullable | ||
default JsonElement getMetadata(String pluginName){ | ||
JsonObject metaData = loadMetadata(); | ||
return metaData.get(pluginName); | ||
} | ||
|
||
private @NotNull JsonObject loadMetadata(){ | ||
String metadataString = getMetadata(); | ||
JsonObject metadata; | ||
if (metadataString == null) { | ||
metadata = new JsonObject(); | ||
} else { | ||
metadata = JsonParser.parseString(metadataString).getAsJsonObject(); | ||
} | ||
return metadata; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
src/main/java/org/sgrewritten/stargate/api/network/portal/MetaData.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
src/main/java/org/sgrewritten/stargate/api/network/portal/Metadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.sgrewritten.stargate.api.network.portal; | ||
|
||
import com.google.gson.JsonElement; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.sgrewritten.stargate.api.MetadataHolder; | ||
|
||
/** | ||
* Convenience class to hold one string value that can be changed without losing the reference. | ||
*/ | ||
public class Metadata implements MetadataHolder { | ||
private String metaDataString; | ||
|
||
public Metadata(String metaDataString) { | ||
this.metaDataString = metaDataString; | ||
} | ||
|
||
@Override | ||
public void setMetadata(@Nullable String data) { | ||
this.metaDataString = data; | ||
} | ||
|
||
@Override | ||
public @Nullable String getMetadata() { | ||
return this.metaDataString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.