mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-30 20:11:26 +01:00
Cleanup 2
This commit is contained in:
parent
68bb479f4a
commit
3ddca82aaa
@ -7,6 +7,7 @@ import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
@ -24,6 +25,8 @@ import static net.minestom.server.MinecraftServer.*;
|
||||
* <p>
|
||||
* Needs to be enabled with {@link #enable(UpdateOption)}. Memory can then be accessed with {@link #getUsedMemory()}
|
||||
* and the CPUs usage with {@link #getResultMap()} or {@link #getCpuMonitoringMessage()}.
|
||||
* <p>
|
||||
* Be aware that this is not the most accurate method, you should use a proper java profiler depending on your needs.
|
||||
*/
|
||||
public final class BenchmarkManager {
|
||||
|
||||
@ -53,7 +56,7 @@ public final class BenchmarkManager {
|
||||
|
||||
private long time;
|
||||
|
||||
public void enable(UpdateOption updateOption) {
|
||||
public void enable(@NotNull UpdateOption updateOption) {
|
||||
Check.stateCondition(enabled, "A benchmark is already running, please disable it first.");
|
||||
|
||||
time = updateOption.getTimeUnit().toMilliseconds(updateOption.getValue());
|
||||
@ -84,7 +87,7 @@ public final class BenchmarkManager {
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
public void addThreadMonitor(String threadName) {
|
||||
public void addThreadMonitor(@NotNull String threadName) {
|
||||
THREADS.add(threadName);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.minestom.server.bossbar;
|
||||
|
||||
/**
|
||||
* Represents the displayed color of a {@link BossBar}
|
||||
* Represents the displayed color of a {@link BossBar}.
|
||||
*/
|
||||
public enum BarColor {
|
||||
PINK,
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.minestom.server.bossbar;
|
||||
|
||||
/**
|
||||
* Used to define the number of segments on a {@link BossBar}
|
||||
* Used to define the number of segments on a {@link BossBar}.
|
||||
*/
|
||||
public enum BarDivision {
|
||||
SOLID,
|
||||
|
@ -13,8 +13,8 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
public class ChatHoverEvent {
|
||||
|
||||
private final String action;
|
||||
private String value;
|
||||
private JsonObject valueObject;
|
||||
private final String value;
|
||||
private final JsonObject valueObject;
|
||||
private final boolean isJson;
|
||||
|
||||
private ChatHoverEvent(@NotNull String action, @NotNull String value) {
|
||||
|
@ -58,7 +58,7 @@ public abstract class JsonMessage {
|
||||
|
||||
public static class RawJsonMessage extends JsonMessage {
|
||||
|
||||
private JsonObject jsonObject;
|
||||
private final JsonObject jsonObject;
|
||||
|
||||
public RawJsonMessage(@NotNull JsonObject jsonObject) {
|
||||
this.jsonObject = jsonObject;
|
||||
|
@ -61,28 +61,25 @@ public class BoundingBox {
|
||||
|
||||
final float offsetX = 1;
|
||||
final float x = blockPosition.getX();
|
||||
final float minX = x;
|
||||
final float maxX = x + offsetX;
|
||||
|
||||
final boolean checkX = getMinX() < maxX && getMaxX() > minX;
|
||||
final boolean checkX = getMinX() < maxX && getMaxX() > x;
|
||||
if (!checkX)
|
||||
return false;
|
||||
|
||||
final float y = blockPosition.getY();
|
||||
final float minY = y;
|
||||
final float maxY = y + 0.99999f;
|
||||
|
||||
final boolean checkY = getMinY() < maxY && getMaxY() > minY;
|
||||
final boolean checkY = getMinY() < maxY && getMaxY() > y;
|
||||
if (!checkY)
|
||||
return false;
|
||||
|
||||
final float offsetZ = 1;
|
||||
final float z = blockPosition.getZ();
|
||||
final float minZ = z;
|
||||
final float maxZ = z + offsetZ;
|
||||
|
||||
final boolean checkZ = getMinZ() < maxZ && getMaxZ() > minZ;
|
||||
return checkZ;
|
||||
// Z check
|
||||
return getMinZ() < maxZ && getMaxZ() > z;
|
||||
}
|
||||
|
||||
public boolean intersect(float x, float y, float z) {
|
||||
|
@ -105,7 +105,7 @@ public class CollisionUtils {
|
||||
if (!collisionFound) {
|
||||
Vector direction = new Vector();
|
||||
direction.copy(axis);
|
||||
collisionFound |= !stepOnce(instance, direction, remainingLength, cornersCopy, cornerPositions);
|
||||
collisionFound = !stepOnce(instance, direction, remainingLength, cornersCopy, cornerPositions);
|
||||
}
|
||||
|
||||
// find the corner which moved the least
|
||||
|
@ -163,9 +163,10 @@ public class Command {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default {@link CommandExecutor} (which is called when there is no argument).
|
||||
* Sets the default {@link CommandExecutor}.
|
||||
*
|
||||
* @param executor the new default executor, null to remove it
|
||||
* @see #getDefaultExecutor()
|
||||
*/
|
||||
public void setDefaultExecutor(@Nullable CommandExecutor executor) {
|
||||
this.defaultExecutor = executor;
|
||||
|
@ -35,8 +35,7 @@ public class ArgumentDynamicStringArray extends Argument<String[]> {
|
||||
public int getConditionResult(@NotNull String[] value) {
|
||||
|
||||
// true if 'value' is valid based on the dynamic restriction
|
||||
final boolean restrictionCheck = dynamicRestriction != null ?
|
||||
dynamicRestriction.isValid(value) : true;
|
||||
final boolean restrictionCheck = dynamicRestriction == null || dynamicRestriction.isValid(value);
|
||||
|
||||
if (!restrictionCheck) {
|
||||
return RESTRICTION_ERROR;
|
||||
|
@ -37,8 +37,7 @@ public class ArgumentDynamicWord extends Argument<String> {
|
||||
public int getConditionResult(@NotNull String value) {
|
||||
|
||||
// true if 'value' is valid based on the dynamic restriction
|
||||
final boolean restrictionCheck = dynamicRestriction != null ?
|
||||
dynamicRestriction.isValid(value) : true;
|
||||
final boolean restrictionCheck = dynamicRestriction == null || dynamicRestriction.isValid(value);
|
||||
|
||||
if (!restrictionCheck) {
|
||||
return RESTRICTION_ERROR;
|
||||
|
@ -10,7 +10,7 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* Support for <a href="https://velocitypowered.com/">Velocity proxy</a>.
|
||||
* Support for <a href="https://velocitypowered.com/">Velocity</a> modern forwarding.
|
||||
* <p>
|
||||
* Can be enabled by simply calling {@link #enable(String)}.
|
||||
*/
|
||||
|
@ -661,8 +661,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
* Sends a {@link BlockActionPacket} for all the viewers of the specific position.
|
||||
*
|
||||
* @param blockPosition the block position
|
||||
* @param actionId
|
||||
* @param actionParam
|
||||
* @param actionId the action id, depends on the block
|
||||
* @param actionParam the action parameter, depends on the block
|
||||
* @see <a href="https://wiki.vg/Protocol#Block_Action">BlockActionPacket</a> for the action id & param
|
||||
*/
|
||||
public void sendBlockAction(@NotNull BlockPosition blockPosition, byte actionId, byte actionParam) {
|
||||
|
@ -27,7 +27,7 @@ public class FurnaceInventory extends Inventory {
|
||||
/**
|
||||
* Represents the amount of tick until the fire icon come empty.
|
||||
*
|
||||
* @param remainingFuelTick
|
||||
* @param remainingFuelTick the amount of tick until the fire icon is empty
|
||||
*/
|
||||
public void setRemainingFuelTick(short remainingFuelTick) {
|
||||
this.remainingFuelTick = remainingFuelTick;
|
||||
|
@ -45,7 +45,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
|
||||
// Used for the login plugin request packet, to retrieve the channel from a message id,
|
||||
// cleared once the player enters the play state
|
||||
private Map<Integer, String> pluginRequestMap = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, String> pluginRequestMap = new ConcurrentHashMap<>();
|
||||
|
||||
public NettyPlayerConnection(@NotNull SocketChannel channel) {
|
||||
super();
|
||||
|
@ -22,10 +22,11 @@ public class NamespaceID implements CharSequence {
|
||||
* Extracts the domain from the namespace ID. "minecraft:stone" would return "minecraft".
|
||||
* If no ':' character is found, "minecraft" is returned.
|
||||
*
|
||||
* @param namespaceID
|
||||
* @param namespaceID the namespace id to get the domain from
|
||||
* @return the domain of the namespace ID
|
||||
*/
|
||||
public static String getDomain(String namespaceID) {
|
||||
@NotNull
|
||||
public static String getDomain(@NotNull String namespaceID) {
|
||||
final int index = namespaceID.indexOf(':');
|
||||
if (index < 0)
|
||||
return "minecraft";
|
||||
@ -37,10 +38,10 @@ public class NamespaceID implements CharSequence {
|
||||
* Extracts the path from the namespace ID. "minecraft:blocks/stone" would return "blocks/stone".
|
||||
* If no ':' character is found, the <pre>namespaceID</pre> is returned.
|
||||
*
|
||||
* @param namespaceID
|
||||
* @param namespaceID the namespace id to get the path from
|
||||
* @return the path of the namespace ID
|
||||
*/
|
||||
public static String getPath(String namespaceID) {
|
||||
public static String getPath(@NotNull String namespaceID) {
|
||||
final int index = namespaceID.indexOf(':');
|
||||
if (index < 0)
|
||||
return namespaceID;
|
||||
@ -61,7 +62,7 @@ public class NamespaceID implements CharSequence {
|
||||
return from(getDomain(id), getPath(id));
|
||||
}
|
||||
|
||||
private NamespaceID(String path) {
|
||||
private NamespaceID(@NotNull String path) {
|
||||
final int index = path.indexOf(':');
|
||||
if (index < 0) {
|
||||
this.domain = "minecraft";
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.world;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTList;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTTypes;
|
||||
@ -9,45 +10,47 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows servers to register custom dimensions. Also used during player joining to send the list of all existing dimensions.
|
||||
*
|
||||
* Allows servers to register custom dimensions. Also used during player login to send the list of all existing dimensions.
|
||||
* <p>
|
||||
* Contains {@link DimensionType#OVERWORLD} by default but can be removed.
|
||||
*/
|
||||
public class DimensionTypeManager {
|
||||
public final class DimensionTypeManager {
|
||||
|
||||
private List<DimensionType> dimensionTypes = new LinkedList<>();
|
||||
private final List<DimensionType> dimensionTypes = new LinkedList<>();
|
||||
|
||||
public DimensionTypeManager() {
|
||||
addDimension(DimensionType.OVERWORLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new dimension type. This does NOT send the new list to players.
|
||||
* @param dimensionType
|
||||
* Adds a new dimension type. This does NOT send the new list to players.
|
||||
*
|
||||
* @param dimensionType the dimension to add
|
||||
*/
|
||||
public void addDimension(DimensionType dimensionType) {
|
||||
public void addDimension(@NotNull DimensionType dimensionType) {
|
||||
dimensionTypes.add(dimensionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a dimension type. This does NOT send the new list to players.
|
||||
* @param dimensionType
|
||||
*
|
||||
* @param dimensionType the dimension to remove
|
||||
* @return if the dimension type was removed, false if it was not present before
|
||||
*/
|
||||
public boolean removeDimension(DimensionType dimensionType) {
|
||||
public boolean removeDimension(@NotNull DimensionType dimensionType) {
|
||||
return dimensionTypes.remove(dimensionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an immutable copy of the dimension types already registered
|
||||
* @return
|
||||
* Returns an immutable copy of the dimension types already registered.
|
||||
*
|
||||
* @return an unmodifiable {@link List} containing all the added dimensions
|
||||
*/
|
||||
@NotNull
|
||||
public List<DimensionType> unmodifiableList() {
|
||||
return Collections.unmodifiableList(dimensionTypes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public NBTCompound toNBT() {
|
||||
NBTCompound dimensions = new NBTCompound();
|
||||
dimensions.setString("type", "minecraft:dimension_type");
|
||||
|
Loading…
Reference in New Issue
Block a user