Skip to content

Commit 1fecd28

Browse files
committed
Improve matching for dynamic Enums
1 parent f93d275 commit 1fecd28

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

src/main/java/com/laytonsmith/abstraction/enums/bukkit/BukkitMCBiomeType.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ public static void build() {
5555
ArrayList<Biome> counted = new ArrayList<>();
5656
for(MCVanillaBiomeType v : MCVanillaBiomeType.values()) {
5757
if(v.existsInCurrent()) {
58-
Biome type = getBukkitType(v);
59-
if(type == null) {
60-
CHLog.GetLogger().e(CHLog.Tags.RUNTIME, "Could not find a matching biome type for " + v.name()
61-
+ ". This is an error, please report this to the bug tracker.", Target.UNKNOWN);
58+
Biome type;
59+
try {
60+
type = getBukkitType(v);
61+
} catch (IllegalArgumentException | NoSuchFieldError ex) {
62+
CHLog.GetLogger().w(CHLog.Tags.RUNTIME, "Could not find a Bukkit BiomeType for " + v.name(), Target.UNKNOWN);
6263
continue;
6364
}
6465
BukkitMCBiomeType wrapper = new BukkitMCBiomeType(v, type);
@@ -146,10 +147,6 @@ private static Biome getBukkitType(MCVanillaBiomeType v) {
146147
return Biome.MUTATED_MESA_ROCK;
147148
}
148149
}
149-
try {
150-
return Biome.valueOf(v.name());
151-
} catch (IllegalArgumentException iae) {
152-
return null;
153-
}
150+
return Biome.valueOf(v.name());
154151
}
155152
}

src/main/java/com/laytonsmith/abstraction/enums/bukkit/BukkitMCEntityType.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ public static void build() {
3232
ArrayList<EntityType> counted = new ArrayList<>();
3333
for(MCVanillaEntityType v : MCVanillaEntityType.values()) {
3434
if(v.existsInCurrent()) {
35-
EntityType type = getBukkitType(v);
36-
if(type == null) {
37-
CHLog.GetLogger().e(CHLog.Tags.RUNTIME, "Could not find a matching entity type for " + v.name()
38-
+ ". This is an error, please report this to the bug tracker.", Target.UNKNOWN);
35+
EntityType type;
36+
try {
37+
type = getBukkitType(v);
38+
} catch (IllegalArgumentException | NoSuchFieldError ex) {
39+
CHLog.GetLogger().w(CHLog.Tags.RUNTIME, "Could not find a Bukkit EntityType for " + v.name(), Target.UNKNOWN);
3940
continue;
4041
}
4142
BukkitMCEntityType wrapper = new BukkitMCEntityType(type, v);
@@ -89,16 +90,12 @@ public static BukkitMCEntityType valueOfConcrete(String test) {
8990
}
9091

9192
// Add exceptions here
92-
public static EntityType getBukkitType(MCVanillaEntityType v) {
93+
private static EntityType getBukkitType(MCVanillaEntityType v) {
9394
switch(v) {
9495
case ENDER_EYE:
9596
return EntityType.ENDER_SIGNAL;
9697
}
97-
try {
98-
return EntityType.valueOf(v.name());
99-
} catch (IllegalArgumentException iae) {
100-
return null;
101-
}
98+
return EntityType.valueOf(v.name());
10299
}
103100

104101
// This is here because it shouldn't be getting changed from API

src/main/java/com/laytonsmith/abstraction/enums/bukkit/BukkitMCSound.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ public static void build() {
5454
ArrayList<Sound> counted = new ArrayList<>();
5555
for(MCVanillaSound v : MCVanillaSound.values()) {
5656
if(v.existsInCurrent()) {
57-
Sound sound = getBukkitType(v);
58-
if(sound == null) {
59-
CHLog.GetLogger().e(CHLog.Tags.RUNTIME, "Could not find a matching sound for " + v.name()
60-
+ ". This is an error, please report this to the bug tracker.", Target.UNKNOWN);
57+
Sound sound;
58+
try {
59+
sound = getBukkitType(v);
60+
} catch (IllegalArgumentException | NoSuchFieldError ex) {
61+
CHLog.GetLogger().w(CHLog.Tags.RUNTIME, "Could not find a Bukkit Sound for " + v.name(), Target.UNKNOWN);
6162
continue;
6263
}
6364
BukkitMCSound wrapper = new BukkitMCSound(v, sound);
@@ -475,10 +476,6 @@ private static Sound getBukkitType(MCVanillaSound v) {
475476
return Sound.ENTITY_VILLAGER_YES;
476477
}
477478
}
478-
try {
479-
return Sound.valueOf(v.name());
480-
} catch (IllegalArgumentException iae) {
481-
return null;
482-
}
479+
return Sound.valueOf(v.name());
483480
}
484481
}

0 commit comments

Comments
 (0)