3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Move some default methods to EntityType

Dieser Commit ist enthalten in:
KennyTV 2019-05-15 12:04:56 +02:00
Ursprung cbb0f87676
Commit f8f20097a9
5 geänderte Dateien mit 27 neuen und 97 gelöschten Zeilen

Datei anzeigen

@ -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

Datei anzeigen

@ -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

Datei anzeigen

@ -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

Datei anzeigen

@ -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;
}
}
}

Datei anzeigen

@ -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;
}
}