-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tankson.Compatibility to address cross version compatability
- Loading branch information
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package tanks.tankson; | ||
|
||
import tanks.tank.Explosion; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.HashMap; | ||
import java.util.function.Function; | ||
|
||
public class Compatibility { | ||
public static final HashMap<String, Function<Object, Object>> compatibility_table = new HashMap<>(); | ||
public static final HashMap<String, String> field_table = new HashMap<>(); | ||
|
||
public static void init() { | ||
compatibility_table.put("explode_on_destroy", Compatibility::updateExplosion); | ||
} | ||
|
||
public static Object convert(Field f, Object v) { | ||
return compatibility_table.get(Serializer.getid(f)).apply(v); | ||
} | ||
|
||
public static String convert(String f) { | ||
return field_table.get(f); | ||
} | ||
|
||
// Explosions 1.6.b -> 1.6.c | ||
public static Object updateExplosion(Object o) { | ||
if (o instanceof Boolean) { | ||
if ((Boolean) o) { | ||
return new Explosion(); | ||
} else { | ||
return null; | ||
} | ||
} else { | ||
throw new RuntimeException("Update Explosions from 1.6.b --> 1.6.c"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters