PersistentRef class
Пакет: com.hypixel.hytale.server.core.entity.reference
Файл: com/hypixel/hytale/server/core/entity/reference/PersistentRef.java
Поля (1)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
BuilderCodec<PersistentRef> |
CODEC |
Методы (6)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
public |
void |
clearvoid clear() |
public |
boolean |
isValidboolean isValid() |
public |
void |
setEntityvoid setEntity(Ref<EntityStore> var1, UUID var2) |
public |
void |
setEntityvoid setEntity(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) |
public |
void |
setUuidvoid setUuid(UUID var1) |
protected |
boolean |
validateEntityReferenceboolean validateEntityReference(Ref<EntityStore> var1, ComponentAccessor<EntityStore> var2) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.entity.reference;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.UUID;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class PersistentRef {
class="kw">public class="kw">static class="kw">final BuilderCodec<PersistentRef> CODEC = BuilderCodec.builder(PersistentRef.class, PersistentRef::new)
.append(new KeyedCodec<>("UUID", Codec.UUID_BINARY), (var0, var1) -> var0.uuid = var1, var0 -> var0.uuid)
.add()
.build();
@Nullable
class="kw">protected UUID uuid;
@Nullable
class="kw">protected Ref<EntityStore> reference;
class="kw">public PersistentRef() {
}
class="kw">public PersistentRef(@Nullable UUID var1) {
this.uuid = var1;
}
@Nullable
class="kw">public UUID getUuid() {
class="kw">return this.uuid;
}
class="kw">public void setUuid(UUID var1) {
this.uuid = var1;
this.reference = null;
}
class="kw">public void setEntity(Ref<EntityStore> var1, UUID var2) {
this.uuid = var2;
this.reference = var1;
}
class="kw">public void setEntity(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
this.uuid = var2.getComponent(var1, UUIDComponent.getComponentType()).getUuid();
this.reference = var1;
}
class="kw">public void clear() {
this.uuid = null;
this.reference = null;
}
class="kw">public boolean isValid() {
class="kw">return this.uuid != null;
}
@Nullable
class="kw">public Ref<EntityStore> getEntity(@Nonnull ComponentAccessor<EntityStore> var1) {
if (!this.isValid()) {
class="kw">return null;
}
if (this.reference != null && this.reference.isValid()) {
class="kw">return this.reference;
}
this.reference = var1.getExternalData().getRefFromUUID(this.uuid);
if (this.reference != null && !this.validateEntityReference(this.reference, var1)) {
this.clear();
}
class="kw">return this.reference;
}
class="kw">protected boolean validateEntityReference(Ref<EntityStore> var1, ComponentAccessor<EntityStore> var2) {
class="kw">return true;
}
}