Cleanup...

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-05 03:40:30 +02:00
parent 026550ac07
commit 8cbd6460f4
10 changed files with 36 additions and 66 deletions

View File

@ -7,7 +7,6 @@ import net.minestom.server.entity.Entity;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -105,20 +104,15 @@ public class BoundingBox {
public boolean intersectWithBlock(int blockX, int blockY, int blockZ) { public boolean intersectWithBlock(int blockX, int blockY, int blockZ) {
final double offsetX = 1; final double offsetX = 1;
final double maxX = (double) blockX + offsetX; final double maxX = (double) blockX + offsetX;
final boolean checkX = getMinX() < maxX && getMaxX() > (double) blockX; final boolean checkX = getMinX() < maxX && getMaxX() > (double) blockX;
if (!checkX) if (!checkX) return false;
return false;
final double maxY = (double) blockY + 0.99999; final double maxY = (double) blockY + 0.99999;
final boolean checkY = getMinY() < maxY && getMaxY() > (double) blockY; final boolean checkY = getMinY() < maxY && getMaxY() > (double) blockY;
if (!checkY) if (!checkY) return false;
return false;
final double offsetZ = 1; final double offsetZ = 1;
final double maxZ = (double) blockZ + offsetZ; final double maxZ = (double) blockZ + offsetZ;
// Z check // Z check
return getMinZ() < maxZ && getMaxZ() > (double) blockZ; return getMinZ() < maxZ && getMaxZ() > (double) blockZ;
} }
@ -170,7 +164,6 @@ public class BoundingBox {
*/ */
public boolean intersect(double x1, double y1, double z1, double x2, double y2, double z2) { public boolean intersect(double x1, double y1, double z1, double x2, double y2, double z2) {
// originally from http://www.3dkingdoms.com/weekly/weekly.php?a=3 // originally from http://www.3dkingdoms.com/weekly/weekly.php?a=3
double x3 = getMinX(); double x3 = getMinX();
double x4 = getMaxX(); double x4 = getMaxX();
double y3 = getMinY(); double y3 = getMinY();
@ -181,8 +174,8 @@ public class BoundingBox {
return true; return true;
} }
if (x1 < x3 && x2 < x3 || x1 > x4 && x2 > x4 || if (x1 < x3 && x2 < x3 || x1 > x4 && x2 > x4 ||
y1 < y3 && y2 < y3 || y1 > y4 && y2 > y4 || y1 < y3 && y2 < y3 || y1 > y4 && y2 > y4 ||
z1 < z3 && z2 < z3 || z1 > z4 && z2 > z4) { z1 < z3 && z2 < z3 || z1 > z4 && z2 > z4) {
return false; return false;
} }
return isInsideBoxWithAxis(Axis.X, getSegmentIntersection(x1 - x3, x2 - x3, x1, y1, z1, x2, y2, z2)) || return isInsideBoxWithAxis(Axis.X, getSegmentIntersection(x1 - x3, x2 - x3, x1, y1, z1, x2, y2, z2)) ||
@ -197,7 +190,7 @@ public class BoundingBox {
* Used to know if the bounding box intersects a line segment. * Used to know if the bounding box intersects a line segment.
* *
* @param start first line segment point * @param start first line segment point
* @param end second line segment point * @param end second line segment point
* @return true if the bounding box intersects with the line segment, false otherwise. * @return true if the bounding box intersects with the line segment, false otherwise.
*/ */
public boolean intersect(@NotNull Point start, @NotNull Point end) { public boolean intersect(@NotNull Point start, @NotNull Point end) {
@ -212,10 +205,8 @@ public class BoundingBox {
} }
private @Nullable Vec getSegmentIntersection(double dst1, double dst2, double x1, double y1, double z1, double x2, double y2, double z2) { private @Nullable Vec getSegmentIntersection(double dst1, double dst2, double x1, double y1, double z1, double x2, double y2, double z2) {
if (dst1 == dst2 || dst1 * dst2 >= 0D) { if (dst1 == dst2 || dst1 * dst2 >= 0D) return null;
return null; final double delta = dst1 / (dst1 - dst2);
}
double delta = dst1 / (dst1 - dst2);
return new Vec( return new Vec(
x1 + (x2 - x1) * delta, x1 + (x2 - x1) * delta,
y1 + (y2 - y1) * delta, y1 + (y2 - y1) * delta,
@ -224,9 +215,7 @@ public class BoundingBox {
} }
private boolean isInsideBoxWithAxis(Axis axis, @Nullable Vec intersection) { private boolean isInsideBoxWithAxis(Axis axis, @Nullable Vec intersection) {
if (intersection == null) { if (intersection == null) return false;
return false;
}
double x1 = getMinX(); double x1 = getMinX();
double x2 = getMaxX(); double x2 = getMaxX();
double y1 = getMinY(); double y1 = getMinY();
@ -246,8 +235,7 @@ public class BoundingBox {
* @param z the Z offset * @param z the Z offset
* @return a new {@link BoundingBox} expanded * @return a new {@link BoundingBox} expanded
*/ */
@NotNull public @NotNull BoundingBox expand(double x, double y, double z) {
public BoundingBox expand(double x, double y, double z) {
return new BoundingBox(entity, this.x + x, this.y + y, this.z + z); return new BoundingBox(entity, this.x + x, this.y + y, this.z + z);
} }
@ -259,8 +247,7 @@ public class BoundingBox {
* @param z the Z offset * @param z the Z offset
* @return a new bounding box contracted * @return a new bounding box contracted
*/ */
@NotNull public @NotNull BoundingBox contract(double x, double y, double z) {
public BoundingBox contract(double x, double y, double z) {
return new BoundingBox(entity, this.x - x, this.y - y, this.z - z); return new BoundingBox(entity, this.x - x, this.y - y, this.z - z);
} }
@ -415,8 +402,7 @@ public class BoundingBox {
X, Y, Z X, Y, Z
} }
private class CachedFace { private final class CachedFace {
private final AtomicReference<@Nullable PositionedPoints> reference = new AtomicReference<>(null); private final AtomicReference<@Nullable PositionedPoints> reference = new AtomicReference<>(null);
private final Supplier<@NotNull List<Vec>> faceProducer; private final Supplier<@NotNull List<Vec>> faceProducer;
@ -434,11 +420,9 @@ public class BoundingBox {
return value; return value;
}).points; }).points;
} }
} }
private static class PositionedPoints { private static final class PositionedPoints {
private final @NotNull Pos lastPosition; private final @NotNull Pos lastPosition;
private final @NotNull List<Vec> points; private final @NotNull List<Vec> points;
@ -446,7 +430,5 @@ public class BoundingBox {
this.lastPosition = lastPosition; this.lastPosition = lastPosition;
this.points = points; this.points = points;
} }
} }
} }

View File

@ -16,7 +16,6 @@ import net.minestom.server.event.entity.EntityFireEvent;
import net.minestom.server.event.item.EntityEquipEvent; import net.minestom.server.event.item.EntityEquipEvent;
import net.minestom.server.event.item.PickupItemEvent; import net.minestom.server.event.item.PickupItemEvent;
import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.block.Block;
import net.minestom.server.inventory.EquipmentHandler; import net.minestom.server.inventory.EquipmentHandler;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
import net.minestom.server.network.ConnectionState; import net.minestom.server.network.ConnectionState;
@ -37,7 +36,6 @@ import java.time.Duration;
import java.time.temporal.TemporalUnit; import java.time.temporal.TemporalUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
public class LivingEntity extends Entity implements EquipmentHandler { public class LivingEntity extends Entity implements EquipmentHandler {

View File

@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
*/ */
public class EntityItemMergeEvent implements EntityEvent, CancellableEvent { public class EntityItemMergeEvent implements EntityEvent, CancellableEvent {
private Entity entity; private final Entity entity;
private final ItemEntity merged; private final ItemEntity merged;
private ItemStack result; private ItemStack result;
@ -31,9 +31,8 @@ public class EntityItemMergeEvent implements EntityEvent, CancellableEvent {
* *
* @return the source ItemEntity * @return the source ItemEntity
*/ */
@NotNull
@Override @Override
public ItemEntity getEntity() { public @NotNull ItemEntity getEntity() {
return (ItemEntity) entity; return (ItemEntity) entity;
} }
@ -44,8 +43,7 @@ public class EntityItemMergeEvent implements EntityEvent, CancellableEvent {
* *
* @return the merged ItemEntity * @return the merged ItemEntity
*/ */
@NotNull public @NotNull ItemEntity getMerged() {
public ItemEntity getMerged() {
return merged; return merged;
} }
@ -54,8 +52,7 @@ public class EntityItemMergeEvent implements EntityEvent, CancellableEvent {
* *
* @return the item stack * @return the item stack
*/ */
@NotNull public @NotNull ItemStack getResult() {
public ItemStack getResult() {
return result; return result;
} }

View File

@ -321,8 +321,7 @@ public class ExtensionManager {
* *
* @return A list of discovered extensions from this folder. * @return A list of discovered extensions from this folder.
*/ */
@NotNull private @NotNull List<DiscoveredExtension> discoverExtensions() {
private List<DiscoveredExtension> discoverExtensions() {
List<DiscoveredExtension> extensions = new LinkedList<>(); List<DiscoveredExtension> extensions = new LinkedList<>();
File[] fileList = extensionFolder.listFiles(); File[] fileList = extensionFolder.listFiles();
@ -378,9 +377,8 @@ public class ExtensionManager {
* @param file The jar to grab it from (a .jar is a formatted .zip file) * @param file The jar to grab it from (a .jar is a formatted .zip file)
* @return The created DiscoveredExtension. * @return The created DiscoveredExtension.
*/ */
@Nullable private @Nullable DiscoveredExtension discoverFromJar(@NotNull File file) {
private DiscoveredExtension discoverFromJar(@NotNull File file) { try (ZipFile f = new ZipFile(file)) {
try (ZipFile f = new ZipFile(file);) {
ZipEntry entry = f.getEntry("extension.json"); ZipEntry entry = f.getEntry("extension.json");

View File

@ -13,7 +13,6 @@ import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -86,17 +85,17 @@ public class ItemMeta implements TagReadable, Writeable {
@Contract(pure = true) @Contract(pure = true)
public @NotNull List<@NotNull Component> getLore() { public @NotNull List<@NotNull Component> getLore() {
return Collections.unmodifiableList(lore); return lore;
} }
@Contract(pure = true) @Contract(pure = true)
public @NotNull Map<Enchantment, Short> getEnchantmentMap() { public @NotNull Map<Enchantment, Short> getEnchantmentMap() {
return Collections.unmodifiableMap(enchantmentMap); return enchantmentMap;
} }
@Contract(pure = true) @Contract(pure = true)
public @NotNull List<@NotNull ItemAttribute> getAttributes() { public @NotNull List<@NotNull ItemAttribute> getAttributes() {
return Collections.unmodifiableList(attributes); return attributes;
} }
@Contract(pure = true) @Contract(pure = true)
@ -106,12 +105,12 @@ public class ItemMeta implements TagReadable, Writeable {
@Contract(pure = true) @Contract(pure = true)
public @NotNull Set<@NotNull Block> getCanDestroy() { public @NotNull Set<@NotNull Block> getCanDestroy() {
return Collections.unmodifiableSet(canDestroy); return canDestroy;
} }
@Contract(pure = true) @Contract(pure = true)
public @NotNull Set<@NotNull Block> getCanPlaceOn() { public @NotNull Set<@NotNull Block> getCanPlaceOn() {
return Collections.unmodifiableSet(canPlaceOn); return canPlaceOn;
} }
@Override @Override

View File

@ -47,16 +47,16 @@ public class FireworkEffect {
List<Color> secondaryColor = new ArrayList<>(); List<Color> secondaryColor = new ArrayList<>();
if (compound.containsKey("Colors")) { if (compound.containsKey("Colors")) {
int[] color = compound.getIntArray("Colors"); final int[] color = compound.getIntArray("Colors");
for (int i = 0; i < color.length; i++) { for (int j : color) {
primaryColor.add(new Color(color[i])); primaryColor.add(new Color(j));
} }
} }
if (compound.containsKey("FadeColors")) { if (compound.containsKey("FadeColors")) {
int[] fadeColor = compound.getIntArray("FadeColors"); final int[] fadeColor = compound.getIntArray("FadeColors");
for (int i = 0; i < fadeColor.length; i++) { for (int j : fadeColor) {
secondaryColor.add(new Color(fadeColor[i])); secondaryColor.add(new Color(j));
} }
} }

View File

@ -53,9 +53,8 @@ public class FireworkMeta extends ItemMeta implements ItemMetaBuilder.Provider<F
public Builder flightDuration(byte flightDuration) { public Builder flightDuration(byte flightDuration) {
this.flightDuration = flightDuration; this.flightDuration = flightDuration;
handleCompound("Fireworks", nbtCompound -> { handleCompound("Fireworks", nbtCompound ->
nbtCompound.setByte("Flight", this.flightDuration); nbtCompound.setByte("Flight", this.flightDuration));
});
return this; return this;
} }

View File

@ -40,9 +40,8 @@ public class PlayerHeadMeta extends ItemMeta implements ItemMetaBuilder.Provider
public Builder skullOwner(@Nullable UUID skullOwner) { public Builder skullOwner(@Nullable UUID skullOwner) {
this.skullOwner = skullOwner; this.skullOwner = skullOwner;
handleCompound("SkullOwner", nbtCompound -> { handleCompound("SkullOwner", nbtCompound ->
nbtCompound.setIntArray("Id", Utils.uuidToIntArray(this.skullOwner)); nbtCompound.setIntArray("Id", Utils.uuidToIntArray(this.skullOwner)));
});
return this; return this;
} }

View File

@ -1,6 +1,5 @@
package net.minestom.server.timer; package net.minestom.server.timer;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minestom.server.extras.selfmodification.MinestomRootClassLoader; import net.minestom.server.extras.selfmodification.MinestomRootClassLoader;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,11 +1,10 @@
package net.minestom.server.utils.block; package net.minestom.server.utils.block;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.LivingEntity;
import net.minestom.server.instance.block.BlockFace;
import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos; import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec; import net.minestom.server.coordinate.Vec;
import net.minestom.server.entity.Entity;
import net.minestom.server.instance.block.BlockFace;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Iterator; import java.util.Iterator;