mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 00:17:58 +01:00
Remove Ownership code
This commit is contained in:
parent
bd3c678bde
commit
e81c31f61b
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user