Remove Named and Identified interfaces

This commit is contained in:
Kieran Wallbanks 2021-04-20 14:55:48 +01:00
parent a15e3aef44
commit 462397d102
6 changed files with 24 additions and 55 deletions

View File

@ -39,7 +39,6 @@ import net.minestom.server.utils.callback.OptionalCallback;
import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.utils.entity.EntityUtils; import net.minestom.server.utils.entity.EntityUtils;
import net.minestom.server.utils.identity.Identified;
import net.minestom.server.utils.player.PlayerUtils; import net.minestom.server.utils.player.PlayerUtils;
import net.minestom.server.utils.time.Cooldown; import net.minestom.server.utils.time.Cooldown;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
@ -62,7 +61,7 @@ import java.util.function.UnaryOperator;
* <p> * <p>
* To create your own entity you probably want to extends {@link LivingEntity} or {@link EntityCreature} instead. * To create your own entity you probably want to extends {@link LivingEntity} or {@link EntityCreature} instead.
*/ */
public class Entity implements Viewable, Tickable, EventHandler, DataContainer, PermissionHandler, HoverEventSource<ShowEntity>, Identified { public class Entity implements Viewable, Tickable, EventHandler, DataContainer, PermissionHandler, HoverEventSource<ShowEntity> {
private static final Map<Integer, Entity> ENTITY_BY_ID = new ConcurrentHashMap<>(); private static final Map<Integer, Entity> ENTITY_BY_ID = new ConcurrentHashMap<>();
private static final Map<UUID, Entity> ENTITY_BY_UUID = new ConcurrentHashMap<>(); private static final Map<UUID, Entity> ENTITY_BY_UUID = new ConcurrentHashMap<>();

View File

@ -1,19 +0,0 @@
package net.minestom.server.utils.identity;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
/**
* An object with a unique identifier.
*/
@FunctionalInterface
public interface Identified {
/**
* Gets the unique identifier for this object.
*
* @return the uuid
*/
@NotNull UUID getUuid();
}

View File

@ -1,19 +0,0 @@
package net.minestom.server.utils.identity;
import org.jetbrains.annotations.NotNull;
/**
* An object with a name.
*
* @param <T> the type of the name
*/
@FunctionalInterface
public interface Named<T> {
/**
* Gets the name of this object.
*
* @return the name
*/
@NotNull T getName();
}

View File

@ -1,17 +1,14 @@
package net.minestom.server.utils.identity; package net.minestom.server.utils.identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.UUID; import java.util.UUID;
import static net.minestom.server.utils.identity.NamedAndIdentifiedImpl.EMPTY;
/** /**
* An object with a {@link Component} name and a {@link UUID} identity. * An object with a {@link Component} name and a {@link UUID} identity.
*/ */
public interface NamedAndIdentified extends Named<Component>, Identified { public interface NamedAndIdentified {
/** /**
* Creates a {@link NamedAndIdentified} instance with an empty name and a random UUID. * Creates a {@link NamedAndIdentified} instance with an empty name and a random UUID.
@ -19,7 +16,7 @@ public interface NamedAndIdentified extends Named<Component>, Identified {
* @return the named and identified instance * @return the named and identified instance
*/ */
static @NotNull NamedAndIdentified empty() { static @NotNull NamedAndIdentified empty() {
return of(EMPTY, UUID.randomUUID()); return of(Component.empty(), UUID.randomUUID());
} }
/** /**
@ -49,7 +46,7 @@ public interface NamedAndIdentified extends Named<Component>, Identified {
* @return the named and identified instance * @return the named and identified instance
*/ */
static @NotNull NamedAndIdentified identified(@NotNull UUID uuid) { static @NotNull NamedAndIdentified identified(@NotNull UUID uuid) {
return of(EMPTY, uuid); return of(Component.empty(), uuid);
} }
/** /**
@ -73,4 +70,18 @@ public interface NamedAndIdentified extends Named<Component>, Identified {
static @NotNull NamedAndIdentified of(@NotNull Component name, @NotNull UUID uuid) { static @NotNull NamedAndIdentified of(@NotNull Component name, @NotNull UUID uuid) {
return new NamedAndIdentifiedImpl(name, uuid); return new NamedAndIdentifiedImpl(name, uuid);
} }
/**
* Gets the name of this object.
*
* @return the name
*/
@NotNull Component getName();
/**
* Gets the UUID of this object.
*
* @return the uuid
*/
@NotNull UUID getUuid();
} }

View File

@ -8,10 +8,10 @@ import java.util.UUID;
/** /**
* Simple implementation of {@link NamedAndIdentified}. * Simple implementation of {@link NamedAndIdentified}.
* @see #of(String, UUID)
* @see #of(Component, UUID)
*/ */
class NamedAndIdentifiedImpl implements NamedAndIdentified { class NamedAndIdentifiedImpl implements NamedAndIdentified {
static final Component EMPTY = Component.empty();
private final Component name; private final Component name;
private final UUID uuid; private final UUID uuid;
@ -51,9 +51,9 @@ class NamedAndIdentifiedImpl implements NamedAndIdentified {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (!(o instanceof NamedAndIdentified)) return false;
NamedAndIdentifiedImpl that = (NamedAndIdentifiedImpl) o; NamedAndIdentified that = (NamedAndIdentified) o;
return this.uuid.equals(that.uuid); return this.uuid.equals(that.getUuid());
} }
@Override @Override
@ -65,4 +65,4 @@ class NamedAndIdentifiedImpl implements NamedAndIdentified {
public String toString() { public String toString() {
return String.format("NamedAndIdentifiedImpl{name='%s', uuid=%s}", this.name, this.uuid); return String.format("NamedAndIdentifiedImpl{name='%s', uuid=%s}", this.name, this.uuid);
} }
} }

View File

@ -5,7 +5,6 @@ import demo.blocks.CustomBlockSample;
import demo.blocks.UpdatableBlockDemo; import demo.blocks.UpdatableBlockDemo;
import demo.commands.*; import demo.commands.*;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
@ -22,8 +21,6 @@ import net.minestom.server.utils.identity.NamedAndIdentified;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption; import net.minestom.server.utils.time.UpdateOption;
import java.util.UUID;
public class Main { public class Main {