-
Notifications
You must be signed in to change notification settings - Fork 7
Redirect annotation
Aki edited this page Aug 22, 2018
·
1 revision
While @LMethod
methods may simply acts as a proxy to Glowstone methods, implementing fields is a harder problem.
How can we keep fields up to date, especially for primitive values?
Our solution was to replace accesses and assignments of fields with a @LField
and @LRedirect
annotation against invokes of a getter and setter method.
These are the rules you have to follow:
- Getter and setters must be declared immediately after their field
- Every annotated field must have getters and setters. (Final fields should only have getters)
- There must be a getter and setter for every version that's in the
@LField
annotation - The name of getters and setters don't matter. They are detected by their
@LGetter
or@LSetter
annotation respectively.
Here's an example:
@LRedirect
@LField(version = { V1_11_R1, V1_12_R1 })
public int age;
@LGetter(version = { V1_11_R1, V1_12_R1 })
public int ageGetter() {
return glowEntity.getAge();
}
// This setter applies for version 1.11
@LSetter(version = V1_11_R1)
public void ageSetter(int age) {
glowEntity.setAge(age);
}
// This one is for version 1.12
@LSetter(version = V1_12_R1)
public void ageSetter2(int age) {
glowEntity.setAge(Math.abs(age));
}