Final for enums and some annotations.

This commit is contained in:
Articdive 2020-09-29 21:45:16 +02:00
parent af9851c334
commit 29c6d92bdc
No known key found for this signature in database
GPG Key ID: B069585F0F7D90DE
12 changed files with 42 additions and 62 deletions

View File

@ -1,5 +1,8 @@
package net.minestom.server.attribute; package net.minestom.server.attribute;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public enum Attribute { public enum Attribute {
MAX_HEALTH("generic.max_health", 20, 1024), MAX_HEALTH("generic.max_health", 20, 1024),
@ -16,9 +19,9 @@ public enum Attribute {
HORSE_JUMP_STRENGTH("horse.jump_strength", 0.7f, 2), HORSE_JUMP_STRENGTH("horse.jump_strength", 0.7f, 2),
ZOMBIE_SPAWN_REINFORCEMENTS("zombie.spawn_reinforcements", 0, 1); ZOMBIE_SPAWN_REINFORCEMENTS("zombie.spawn_reinforcements", 0, 1);
private String key; private final String key;
private float defaultValue; private final float defaultValue;
private float maxVanillaValue; private final float maxVanillaValue;
Attribute(String key, float defaultValue, float maxVanillaValue) { Attribute(String key, float defaultValue, float maxVanillaValue) {
this.key = key; this.key = key;
@ -26,6 +29,7 @@ public enum Attribute {
this.maxVanillaValue = maxVanillaValue; this.maxVanillaValue = maxVanillaValue;
} }
@NotNull
public String getKey() { public String getKey() {
return key; return key;
} }
@ -38,7 +42,8 @@ public enum Attribute {
return maxVanillaValue; return maxVanillaValue;
} }
public static Attribute fromKey(String key) { @Nullable
public static Attribute fromKey(@NotNull String key) {
for (Attribute attribute : values()) { for (Attribute attribute : values()) {
if (attribute.getKey().equals(key)) if (attribute.getKey().equals(key))
return attribute; return attribute;

View File

@ -1,5 +1,7 @@
package net.minestom.server.attribute; package net.minestom.server.attribute;
import org.jetbrains.annotations.Nullable;
public enum AttributeOperation { public enum AttributeOperation {
ADDITION(0), ADDITION(0),
MULTIPLY_BASE(1), MULTIPLY_BASE(1),
@ -12,15 +14,15 @@ public enum AttributeOperation {
this.id = id; this.id = id;
} }
public static AttributeOperation byId(int id) {
if (id >= 0 && id < VALUES.length) {
return VALUES[id];
} else {
throw new IllegalArgumentException("No operation with value " + id);
}
}
public int getId() { public int getId() {
return this.id; return this.id;
} }
@Nullable
public static AttributeOperation fromId(int id) {
if (id >= 0 && id < VALUES.length) {
return VALUES[id];
}
return null;
}
} }

View File

@ -558,7 +558,7 @@ public class CommandManager {
private enum NodeType { private enum NodeType {
ROOT(0), LITERAL(0b1), ARGUMENT(0b10), NONE(0x11); ROOT(0), LITERAL(0b1), ARGUMENT(0b10), NONE(0x11);
private int mask; private final int mask;
NodeType(int mask) { NodeType(int mask) {
this.mask = mask; this.mask = mask;

View File

@ -59,7 +59,7 @@ public enum Effects {
ENDERDRAGON_GROWL(3001), ENDERDRAGON_GROWL(3001),
; ;
private int id; private final int id;
Effects(int id) { Effects(int id) {
this.id = id; this.id = id;

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Animal; import net.minestom.server.entity.type.Animal;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -49,12 +50,13 @@ public class EntityMooshroom extends EntityCreature implements Animal {
RED("red"), RED("red"),
BROWN("brown"); BROWN("brown");
private String identifier; private final String identifier;
MooshroomType(String identifier) { MooshroomType(String identifier) {
this.identifier = identifier; this.identifier = identifier;
} }
@NotNull
private String getIdentifier() { private String getIdentifier() {
return identifier; return identifier;
} }

View File

@ -76,7 +76,7 @@ public class EntityCreeper extends EntityCreature implements Monster {
IDLE(-1), IDLE(-1),
FUSE(1); FUSE(1);
private int state; private final int state;
CreeperState(int state) { CreeperState(int state) {
this.state = state; this.state = state;

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.GameMode;
import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
@ -44,12 +45,13 @@ public class PlayerInfoPacket implements ServerPacket {
UPDATE_DISPLAY_NAME(UpdateDisplayName.class), UPDATE_DISPLAY_NAME(UpdateDisplayName.class),
REMOVE_PLAYER(RemovePlayer.class); REMOVE_PLAYER(RemovePlayer.class);
private Class<? extends PlayerInfo> clazz; private final Class<? extends PlayerInfo> clazz;
Action(Class<? extends PlayerInfo> clazz) { Action(Class<? extends PlayerInfo> clazz) {
this.clazz = clazz; this.clazz = clazz;
} }
@NotNull
public Class<? extends PlayerInfo> getClazz() { public Class<? extends PlayerInfo> getClazz() {
return clazz; return clazz;
} }

View File

@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
/** /**
* The packet creates or updates teams * The packet creates or updates teams
@ -159,6 +160,7 @@ public class TeamsPacket implements ServerPacket {
* *
* @return the identifier * @return the identifier
*/ */
@NotNull
public String getIdentifier() { public String getIdentifier() {
return identifier; return identifier;
} }
@ -204,6 +206,7 @@ public class TeamsPacket implements ServerPacket {
* *
* @return the identifier * @return the identifier
*/ */
@NotNull
public String getIdentifier() { public String getIdentifier() {
return identifier; return identifier;
} }

View File

@ -1,39 +0,0 @@
package net.minestom.server.registry;
import java.util.Map;
/**
* Class used to represent the contents of a versions/{version}/{version}.json file
* Structured in a way that makes loading with Gson easy.
* Only concerned with helping extracting data from the server jar, lots of features may be missing.
*/
class VersionInfo {
private Map<String, DownloadObject> downloads;
private VersionInfo() {
}
public Map<String, DownloadObject> getDownloadableFiles() {
return downloads;
}
static class DownloadObject {
private String url;
private String sha1;
private long size;
public String getUrl() {
return url;
}
public long getSize() {
return size;
}
public String getSha1() {
return sha1;
}
}
}

View File

@ -153,14 +153,16 @@ public final class NBTUtils {
// Wrong attribute name, stop here // Wrong attribute name, stop here
if (attribute == null) if (attribute == null)
break; break;
final AttributeOperation attributeOperation = AttributeOperation.byId(operation); final AttributeOperation attributeOperation = AttributeOperation.fromId(operation);
// Wrong attribute operation, stop here // Wrong attribute operation, stop here
if (attributeOperation == null) if (attributeOperation == null) {
break; break;
}
final AttributeSlot attributeSlot = AttributeSlot.valueOf(slot.toUpperCase()); final AttributeSlot attributeSlot = AttributeSlot.valueOf(slot.toUpperCase());
// Wrong attribute slot, stop here // Wrong attribute slot, stop here
if (attributeSlot == null) if (attributeSlot == null) {
break; break;
}
// Add attribute // Add attribute
final ItemAttribute itemAttribute = final ItemAttribute itemAttribute =

View File

@ -4,7 +4,7 @@ public enum Difficulty {
PEACEFUL((byte) 0), EASY((byte) 1), NORMAL((byte) 2), HARD((byte) 3); PEACEFUL((byte) 0), EASY((byte) 1), NORMAL((byte) 2), HARD((byte) 3);
private byte id; private final byte id;
Difficulty(byte id) { Difficulty(byte id) {
this.id = id; this.id = id;

View File

@ -1,5 +1,7 @@
package net.minestom.server.world; package net.minestom.server.world;
import org.jetbrains.annotations.Nullable;
public enum LevelType { public enum LevelType {
DEFAULT("default"), DEFAULT("default"),
@ -8,12 +10,13 @@ public enum LevelType {
AMPLIFIED("amplified"), AMPLIFIED("amplified"),
DEFAULT_1_1("default_1_1"); DEFAULT_1_1("default_1_1");
private String type; private final String type;
LevelType(String type) { LevelType(@Nullable String type) {
this.type = type; this.type = type;
} }
@Nullable
public String getType() { public String getType() {
return type; return type;
} }