Move some default methods to EntityType

This commit is contained in:
KennyTV 2019-05-15 12:04:56 +02:00
parent cbb0f87676
commit f8f20097a9
5 changed files with 27 additions and 97 deletions

View File

@ -10,6 +10,7 @@ import java.util.Map;
// 1.11 Entity / Object ids TODO maybe in the future instead of copying it, some api.
public class Entity1_11Types {
public static EntityType getTypeFromId(int typeID, boolean isObject) {
Optional<EntityType> type;
@ -164,30 +165,6 @@ public class Entity1_11Types {
return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
}
public boolean is(EntityType... types) {
for (EntityType type : types)
if (is(type))
return true;
return false;
}
public boolean is(EntityType type) {
return this == type;
}
public boolean isOrHasParent(EntityType type) {
EntityType parent = this;
do {
if (parent.equals(type))
return true;
parent = parent.getParent();
} while (parent != null);
return false;
}
}
@AllArgsConstructor

View File

@ -20,6 +20,7 @@ import java.util.Map;
// 1.12 Entity / Object taken from https://github.com/Matsv/ViaBackwards/blob/master/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_12.java
public class Entity1_12Types {
public static EntityType getTypeFromId(int typeID, boolean isObject) {
Optional<EntityType> type;
@ -177,30 +178,6 @@ public class Entity1_12Types {
return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
}
public boolean is(EntityType... types) {
for (EntityType type : types)
if (is(type))
return true;
return false;
}
public boolean is(EntityType type) {
return this == type;
}
public boolean isOrHasParent(EntityType type) {
EntityType parent = this;
do {
if (parent.equals(type))
return true;
parent = parent.getParent();
} while (parent != null);
return false;
}
}
@AllArgsConstructor

View File

@ -8,9 +8,9 @@ import us.myles.ViaVersion.api.Via;
import java.util.HashMap;
import java.util.Map;
// TODO auto generate 18w11a with PAaaS
public class Entity1_13Types {
public static EntityType getTypeFromId(int typeID, boolean isObject) {
Optional<EntityType> type;
@ -220,30 +220,6 @@ public class Entity1_13Types {
return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
}
public boolean is(EntityType... types) {
for (EntityType type : types)
if (is(type))
return true;
return false;
}
public boolean is(EntityType type) {
return this == type;
}
public boolean isOrHasParent(EntityType type) {
EntityType parent = this;
do {
if (parent.equals(type))
return true;
parent = parent.getParent();
} while (parent != null);
return false;
}
}
@AllArgsConstructor

View File

@ -10,6 +10,7 @@ import java.util.Map;
public class Entity1_14Types {
public static EntityType getTypeFromId(int typeID) {
Optional<EntityType> type = Entity1_14Types.EntityType.findById(typeID);
@ -220,29 +221,5 @@ public class Entity1_14Types {
return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
}
public boolean is(EntityType... types) {
for (EntityType type : types)
if (is(type))
return true;
return false;
}
public boolean is(EntityType type) {
return this == type;
}
public boolean isOrHasParent(EntityType type) {
EntityType parent = this;
do {
if (parent == type)
return true;
parent = parent.getParent();
} while (parent != null);
return false;
}
}
}

View File

@ -6,4 +6,27 @@ public interface EntityType {
EntityType getParent();
default boolean is(EntityType... types) {
for (EntityType type : types)
if (is(type))
return true;
return false;
}
default boolean is(EntityType type) {
return this == type;
}
default boolean isOrHasParent(EntityType type) {
EntityType parent = this;
do {
if (parent.equals(type))
return true;
parent = parent.getParent();
} while (parent != null);
return false;
}
}