Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow removing metadata by key #6089

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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