Do not access nms for older versions on newer ones

This commit is contained in:
NotMyFault 2021-03-31 12:42:32 +02:00
parent d9b5dc5dd7
commit 932873ba02
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C

View File

@ -49,13 +49,19 @@ public class SingleWorldListener implements Listener {
private Method methodGetHandleChunk;
private Field mustSave;
private boolean isTrueForNotSave = true;
public SingleWorldListener(Plugin plugin) throws Exception {
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod();
try {
this.mustSave = classChunk.getField("mustSave").getRealField();
if (PlotSquared.get().IMP.getServerVersion()[1] == 13) {
this.mustSave = classChunk.getField("mustSave").getRealField();
this.isTrueForNotSave = false;
} else {
this.mustSave = classChunk.getField("mustNotSave").getRealField();
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
}