有更好的方法吗?
尝试为插口创建附魔插件, 我喜欢有三类各种各样的附魔 每个类中包含的附魔类型。 第一次使用枚举,谢谢。
public class EnchantmentType {
public enum Enchantments {
INK(Types.INK, Category.Adrian),
PUFFERFISH(Types.PUFFERFISH, Category.Adrian),
HOLYWATER(Types.HOLYWATER, Category.Adrian),
URCHIN(Types.URCHIN, Category.Adrian),
SEALORD(Types.SEALORD, Category.Adrian),
DYSPEPSIA(Types.DYSPEPSIA, Category.Adrian),
TOXIN(Types.TOXIN, Category.Adrian),
YPHOON(Types.YPHOON, Category.Adrian),
TSUNAMI(Types.TSUNAMI, Category.Adrian),
SPONGE(Types.SPONGE, Category.Adrian),
PRISTINE(Types.PRISTINE, Category.Adrian),
CLEANSE(Types.CLEANSE, Category.Adrian),
STARLIGHT(Types.STARLIGHT,Category.Zephira),
GUST(Types.GUST,Category.Zephira),
GRAVITY(Types.GRAVITY,Category.Zephira),
DETERMINATION(Types.DETERMINATION,Category.Zephira),
COURAGE(Types.COURAGE,Category.Zephira),
FOREGIVENESS(Types.FOREGIVENESS,Category.Zephira),
TORNADO(Types.TORNADO,Category.Zephira),
REDEMPTION(Types.REDEMPTION,Category.Zephira),
PEACEFUL(Types.PEACEFUL,Category.Zephira),
FLEE(Types.FLEE,Category.Zephira),
VIRTUE(Types.VIRTUE,Category.Zephira),
AMBIGUITY(Types.AMBIGUITY,Category.Zephira),
VALERE(Types.VALERE,Category.Zephira),
SANDSTORM(Types.SANDSTORM,Category.Zephira),
REKINDLE(Types.REKINDLE,Category.Zephira),
THERMALS(Types.THERMALS,Category.Zephira),
APPERTITE(Types.APPERTITE, Category.Partial);
Types eType;
Category eCat;
Enchantments(Types eType, EnchantmentType.Category eCat) {
this.eCat = eCat;
this.eType = eType;
}
Category getCategory() {
return this.eCat;
}
Types getType() {
return this.eType;
}
public enum Types {
INK, PUFFERFISH, HOLYWATER, URCHIN, SEALORD, DYSPEPSIA, TOXIN, YPHOON, TSUNAMI, SPONGE, PRISTINE, CLEANSE, STARLIGHT, GUST, GRAVITY, DETERMINATION, COURAGE, FOREGIVENESS, TORNADO, REDEMPTION, PEACEFUL, FLEE, VIRTUE, AMBIGUITY, VALERE, SANDSTORM, REKINDLE, THERMALS, APPERTITE;
}
}
Enchantments eType;
Category eCat;
public EnchantmentType(Enchantment eType) {
this.eType = eType.getType();
this.eCat = eType.getCategory();
}
public enum Category {
Adrian, Zephira, Partial;
}
}
答案 0 :(得分:0)
您可以删除Type枚举。您可以使用YourEnum.TYPE.name()
方法获取枚举的String表示。
如果您打算扩展当前的附魔列表,也可以使用数据驱动设计。这基本上意味着,不是将值硬编码到程序中,而是从文件中加载它们。该文件将定义关于附魔的所有内容,例如名称,类别等。这有额外的好处,当你想增加附魔的数量时,你不必重新编译插件。