Merge pull request #313 from Minestom/fix-potion-ids

Fix potion effect IDs.
This commit is contained in:
TheMode 2021-06-07 19:37:06 +02:00 committed by GitHub
commit 73abe7a4d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -81,7 +81,7 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator {
potionEffectClass.addMethod(
MethodSpec.methodBuilder("getId")
.returns(TypeName.SHORT)
.addStatement("return (short) ordinal()")
.addStatement("return (short) (ordinal() + 1)")
.addModifiers(Modifier.PUBLIC)
.build()
);
@ -100,8 +100,8 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator {
.returns(potionEffectClassName)
.addAnnotation(Nullable.class)
.addParameter(TypeName.SHORT, "id")
.beginControlFlow("if(id >= 0 && id < VALUES.length)")
.addStatement("return VALUES[id]")
.beginControlFlow("if(id >= 1 && id < VALUES.length + 1)")
.addStatement("return VALUES[id - 1]")
.endControlFlow()
.addStatement("return null")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)

View File

@ -92,7 +92,7 @@ public enum PotionEffect implements Keyed {
}
public short getId() {
return (short) ordinal();
return (short) (ordinal() + 1);
}
@NotNull
@ -102,8 +102,8 @@ public enum PotionEffect implements Keyed {
@Nullable
public static PotionEffect fromId(short id) {
if(id >= 0 && id < VALUES.length) {
return VALUES[id];
if(id >= 1 && id < VALUES.length + 1) {
return VALUES[id - 1];
}
return null;
}