This method lets you replace a final field:
Code:public static final void replaceField(Class<?> c, String fieldName, Object replacement) { try { Field f = c.getDeclaredField(fieldName); Field m = Field.class.getDeclaredField("modifiers"); m.setAccessible(true); m.setInt(f, f.getModifiers() & ~Modifier.FINAL); f.setAccessible(true); f.set(f, replacement); } catch (ReflectiveOperationException e) { e.printStackTrace(); } }
This gives you the current time:
Code:SimpleDateFormat t = new SimpleDateFormat("HH:mm:ss"); String time = t.format(Calendar.getInstance().getTime());
H is hour, m is minutes, s is second, y is year, d is date and M is month.
Another example and a possible use for it (not really useful for modding though):
Code:SimpleDateFormat year = new SimpleDateFormat("yyyy"); String copyright = "CoolSquid " + year.format(Calendar.getInstance().getTime()) + ".";
it's faster to cache the Field object between calls and it may cause glitches when the field is statically initialized due to inlining
that time is the system time not the ingame time
copyright text should be static as it shows when the version was released