Merge remote-tracking branch 'origin/master'

This commit is contained in:
themode 2020-10-01 17:54:44 +02:00
commit 51530b8c61
12 changed files with 42 additions and 62 deletions

View File

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

View File

@ -1,5 +1,7 @@
package net.minestom.server.attribute;
import org.jetbrains.annotations.Nullable;
public enum AttributeOperation {
ADDITION(0),
MULTIPLY_BASE(1),
@ -12,15 +14,15 @@ public enum AttributeOperation {
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() {
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 {
ROOT(0), LITERAL(0b1), ARGUMENT(0b10), NONE(0x11);
private int mask;
private final int mask;
NodeType(int mask) {
this.mask = mask;

View File

@ -59,7 +59,7 @@ public enum Effects {
ENDERDRAGON_GROWL(3001),
;
private int id;
private final int id;
Effects(int 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.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
@ -49,12 +50,13 @@ public class EntityMooshroom extends EntityCreature implements Animal {
RED("red"),
BROWN("brown");
private String identifier;
private final String identifier;
MooshroomType(String identifier) {
this.identifier = identifier;
}
@NotNull
private String getIdentifier() {
return identifier;
}

View File

@ -76,7 +76,7 @@ public class EntityCreeper extends EntityCreature implements Monster {
IDLE(-1),
FUSE(1);
private int state;
private final int state;
CreeperState(int 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.ServerPacketIdentifier;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.UUID;
@ -44,12 +45,13 @@ public class PlayerInfoPacket implements ServerPacket {
UPDATE_DISPLAY_NAME(UpdateDisplayName.class),
REMOVE_PLAYER(RemovePlayer.class);
private Class<? extends PlayerInfo> clazz;
private final Class<? extends PlayerInfo> clazz;
Action(Class<? extends PlayerInfo> clazz) {
this.clazz = clazz;
}
@NotNull
public Class<? extends PlayerInfo> getClazz() {
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.ServerPacketIdentifier;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
/**
* The packet creates or updates teams
@ -159,6 +160,7 @@ public class TeamsPacket implements ServerPacket {
*
* @return the identifier
*/
@NotNull
public String getIdentifier() {
return identifier;
}
@ -204,6 +206,7 @@ public class TeamsPacket implements ServerPacket {
*
* @return the identifier
*/
@NotNull
public String getIdentifier() {
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
if (attribute == null)
break;
final AttributeOperation attributeOperation = AttributeOperation.byId(operation);
final AttributeOperation attributeOperation = AttributeOperation.fromId(operation);
// Wrong attribute operation, stop here
if (attributeOperation == null)
if (attributeOperation == null) {
break;
}
final AttributeSlot attributeSlot = AttributeSlot.valueOf(slot.toUpperCase());
// Wrong attribute slot, stop here
if (attributeSlot == null)
if (attributeSlot == null) {
break;
}
// Add attribute
final ItemAttribute itemAttribute =

View File

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

View File

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