mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Enum refactoring
This commit is contained in:
parent
78d3705a55
commit
41828dbf9c
9 changed files with 37 additions and 21 deletions
|
@ -1,6 +1,6 @@
|
|||
package brainwine.gameserver.entity;
|
||||
|
||||
import brainwine.gameserver.msgpack.EnumIdentifier;
|
||||
import brainwine.gameserver.msgpack.EnumValue;
|
||||
import brainwine.gameserver.msgpack.RegisterEnum;
|
||||
|
||||
@RegisterEnum
|
||||
|
@ -11,10 +11,14 @@ public enum EntityType {
|
|||
TERRAPUS_JUVENLIE(3),
|
||||
TERRAPUS_ADULT(4);
|
||||
|
||||
@EnumIdentifier
|
||||
public final int id;
|
||||
private final int id;
|
||||
|
||||
private EntityType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@EnumValue
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package brainwine.gameserver.entity;
|
||||
|
||||
import brainwine.gameserver.msgpack.EnumIdentifier;
|
||||
import brainwine.gameserver.msgpack.EnumValue;
|
||||
import brainwine.gameserver.msgpack.RegisterEnum;
|
||||
|
||||
@RegisterEnum
|
||||
|
@ -9,10 +9,14 @@ public enum FacingDirection {
|
|||
WEST(-1),
|
||||
EAST(1);
|
||||
|
||||
@EnumIdentifier
|
||||
public final int id;
|
||||
private final int id;
|
||||
|
||||
private FacingDirection(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@EnumValue
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package brainwine.gameserver.entity.player;
|
||||
|
||||
import brainwine.gameserver.msgpack.EnumIdentifier;
|
||||
import brainwine.gameserver.msgpack.EnumValue;
|
||||
import brainwine.gameserver.msgpack.RegisterEnum;
|
||||
|
||||
@RegisterEnum
|
||||
|
@ -11,10 +11,14 @@ public enum ChatType {
|
|||
SPEECH("s"),
|
||||
THOUGHT("t");
|
||||
|
||||
@EnumIdentifier
|
||||
public String id;
|
||||
private final String id;
|
||||
|
||||
private ChatType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@EnumValue
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package brainwine.gameserver.entity.player;
|
||||
|
||||
import brainwine.gameserver.msgpack.EnumIdentifier;
|
||||
import brainwine.gameserver.msgpack.EnumValue;
|
||||
import brainwine.gameserver.msgpack.RegisterEnum;
|
||||
|
||||
@RegisterEnum
|
||||
|
@ -9,10 +9,14 @@ public enum ContainerType {
|
|||
HOTBAR("h"),
|
||||
ACCESSORIES("a");
|
||||
|
||||
@EnumIdentifier
|
||||
public final String id;
|
||||
private final String id;
|
||||
|
||||
private ContainerType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@EnumValue
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class Inventory {
|
|||
int slot = -1;
|
||||
|
||||
if((slot = hotbar.getSlot(item)) != -1) {
|
||||
itemData.add(ContainerType.HOTBAR.id);
|
||||
itemData.add(ContainerType.HOTBAR.getId());
|
||||
itemData.add(slot);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package brainwine.gameserver.entity.player;
|
||||
|
||||
import brainwine.gameserver.msgpack.EnumIdentifier;
|
||||
import brainwine.gameserver.msgpack.EnumValue;
|
||||
import brainwine.gameserver.msgpack.RegisterEnum;
|
||||
|
||||
@RegisterEnum
|
||||
|
@ -19,8 +19,8 @@ public enum Skill {
|
|||
STAMINA,
|
||||
SURVIVAL;
|
||||
|
||||
@EnumIdentifier
|
||||
public String code() {
|
||||
@EnumValue
|
||||
public String getId() {
|
||||
return toString().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public enum ItemUseType {
|
|||
UNKNOWN;
|
||||
|
||||
@JsonCreator
|
||||
public static ItemUseType create(String id) {
|
||||
public static ItemUseType fromId(String id) {
|
||||
String formatted = id.toUpperCase().replace(" ", "_");
|
||||
|
||||
for(ItemUseType value : values()) {
|
||||
|
|
|
@ -11,4 +11,4 @@ import java.lang.annotation.Target;
|
|||
*/
|
||||
@Target({ElementType.FIELD, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface EnumIdentifier {}
|
||||
public @interface EnumValue {}
|
|
@ -13,7 +13,7 @@ import org.msgpack.template.AbstractTemplate;
|
|||
import org.msgpack.type.ValueType;
|
||||
import org.msgpack.unpacker.Unpacker;
|
||||
|
||||
import brainwine.gameserver.msgpack.EnumIdentifier;
|
||||
import brainwine.gameserver.msgpack.EnumValue;
|
||||
|
||||
public class EnumTemplate<T> extends AbstractTemplate<T> {
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class EnumTemplate<T> extends AbstractTemplate<T> {
|
|||
T[] entries = type.getEnumConstants();
|
||||
|
||||
for(Field field : type.getFields()) {
|
||||
if(field.isAnnotationPresent(EnumIdentifier.class)) {
|
||||
if(field.isAnnotationPresent(EnumValue.class)) {
|
||||
try {
|
||||
for(T entry : entries) {
|
||||
Object id = field.get(entry);
|
||||
|
@ -40,7 +40,7 @@ public class EnumTemplate<T> extends AbstractTemplate<T> {
|
|||
}
|
||||
|
||||
for(Method method : type.getMethods()) {
|
||||
if(method.isAnnotationPresent(EnumIdentifier.class)) {
|
||||
if(method.isAnnotationPresent(EnumValue.class)) {
|
||||
try {
|
||||
for(T entry : entries) {
|
||||
Object id = method.invoke(entry);
|
||||
|
|
Loading…
Add table
Reference in a new issue