Skip to content

Commit

Permalink
Merge pull request #6089 from TownyAdvanced/feature/metadata-by-key
Browse files Browse the repository at this point in the history
Allow removing metadata by key
  • Loading branch information
LlmDl authored Aug 8, 2022
2 parents ac9eb1a + 475b040 commit 71f462d
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/com/palmergames/bukkit/towny/object/TownyObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public void addMetaData(@NotNull CustomDataField<?> md, boolean save) {
* The metadata does not need to be the same instance of the one added,
* but must have the same key.
* Most implementations will save the TownyObject after removing the metadata.
*
*
* @param md CustomDataField to remove.
*/
Expand All @@ -114,10 +113,35 @@ public void removeMetaData(@NotNull CustomDataField<?> md) {
// DO NOT OVERRIDE THIS METHOD ANYWHERE
public boolean removeMetaData(@NotNull CustomDataField<?> md, boolean save) {
Preconditions.checkNotNull(md);
return removeMetaData(md.getKey(), save);
}

/**
* Remove a specific metadata from the TownyObject.
* Most implementations will save the TownyObject after removing the metadata.
*
* @param key Key of the data field to remove.
* @return whether the metadata was successfully removed.
*/
public boolean removeMetaData(@NotNull String key) {
return removeMetaData(key, false);
}

/**
* Remove a specific metadata from the TownyObject.
*
* @param key Key of the data field to remove.
* @param save whether to save the object or not after the metadata is removed.
*
* @return whether the metadata was successfully removed.
*/
public boolean removeMetaData(@NotNull String key, boolean save) {
Preconditions.checkNotNull(key);

if (!hasMeta())
return false;

final boolean removed = metadata.remove(md.getKey()) != null;
final boolean removed = metadata.remove(key) != null;

if (metadata.isEmpty())
this.metadata = null;
Expand Down

0 comments on commit 71f462d

Please sign in to comment.