Remove Ownership code

This commit is contained in:
TheMode 2021-04-10 17:47:45 +02:00
parent bd3c678bde
commit e81c31f61b
2 changed files with 0 additions and 68 deletions

View File

@ -588,15 +588,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
}
}
// ItemStack ownership cache
{
ItemStack[] itemStacks = inventory.getItemStacks();
for (ItemStack itemStack : itemStacks) {
// FIXME: item data
//ItemStack.DATA_OWNERSHIP.clearCache(itemStack.getIdentifier());
}
}
// Clear all viewable entities
this.viewableEntities.forEach(entity -> entity.removeViewer(this));
// Clear all viewable chunks

View File

@ -1,59 +0,0 @@
package net.minestom.server.utils.ownership;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
* Convenient class to keep trace of objects linked to an {@link UUID}.
*
* @param <T> the owned object type
*/
public class OwnershipHandler<T> {
// identifier = the object having an ownership
private ConcurrentHashMap<UUID, T> ownershipDataMap = new ConcurrentHashMap<>();
/**
* Generates a new unique identifier.
* <p>
* Does call {@link UUID#randomUUID()} internally.
*
* @return a new generated identifier
*/
public UUID generateIdentifier() {
return UUID.randomUUID();
}
/**
* Retrieves the owned object based on its identifier.
*
* @param identifier the object identifier
* @return the own object, null if not found
*/
@Nullable
public T getOwnObject(@NotNull UUID identifier) {
return ownershipDataMap.get(identifier);
}
/**
* Saves, replace or remove the own object of an identifier.
*
* @param identifier the identifier of the object
* @param value the value of the object, can override the previous value, null means removing the identifier
*/
public void saveOwnObject(@NotNull UUID identifier, @Nullable T value) {
if (value != null) {
this.ownershipDataMap.put(identifier, value);
} else {
clearCache(identifier);
}
}
public void clearCache(@NotNull UUID identifier) {
this.ownershipDataMap.remove(identifier);
}
}