Skip to content

Commit

Permalink
refactor: code style clean up & add qodana_code_quality.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Aug 5, 2023
1 parent 521fe0b commit 2b1e104
Show file tree
Hide file tree
Showing 34 changed files with 136 additions and 87 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/qodana_code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Qodana
on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
qodana:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: 'Qodana Scan'
uses: JetBrains/[email protected]
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.allay.api.client;

import cn.allay.api.client.data.AdventureSettings;
import cn.allay.api.client.data.LoginData;
import cn.allay.api.client.skin.Skin;
import cn.allay.api.entity.impl.EntityPlayer;
Expand Down
1 change: 1 addition & 0 deletions Allay-API/src/main/java/cn/allay/api/client/Client.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.allay.api.client;

import cn.allay.api.client.data.AdventureSettings;
import cn.allay.api.client.data.LoginData;
import cn.allay.api.client.info.DeviceInfo;
import cn.allay.api.client.skin.Skin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
*
* @author daoge_cmd
*/
@Getter
public class FakeClient extends BaseClient {

protected static final ContainerActionProcessorHolder EMPTY_CONTAINER_ACTION_PROCESSOR_HOLDER = new SimpleContainerActionProcessorHolder();

@Getter
@Setter
protected boolean loaderActive;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.allay.api.client;
package cn.allay.api.client.data;

import cn.allay.api.client.Client;
import lombok.Getter;
import org.cloudburstmc.protocol.bedrock.data.Ability;
import org.cloudburstmc.protocol.bedrock.data.AbilityLayer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cn.allay.api.client.movement;

/**
* Allay Project 2023/8/5
*
* @author daoge_cmd
*/
public interface ClientMovementValidator {
boolean validate()
}
4 changes: 3 additions & 1 deletion Allay-API/src/main/java/cn/allay/api/client/skin/Skin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.cloudburstmc.protocol.bedrock.data.skin.*;
import org.jose4j.json.internal.json_simple.JSONObject;
import org.jose4j.json.internal.json_simple.JSONValue;
Expand All @@ -28,6 +29,7 @@
@ToString
@Getter
@Setter
@Slf4j
public class Skin {

public static final int SINGLE_SKIN_SIZE = 8192;
Expand Down Expand Up @@ -102,7 +104,7 @@ public static Skin fromInputStream(InputStream inputStream) {
try {
skinData = ImageIO.read(inputStream);
} catch (IOException e) {
e.printStackTrace();
log.error("Error while reading skin from input stream", e);
}
if (skinData != null) {
skin.setSkinData(skinData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private void detectCollisionPairsWithNode(AABBTreeNode<T> nodeToTest, CollisionF
AABBf overlapWith = nodeToTest.getAABB();

while (!stack.isEmpty()) {
Integer nodeIndex = stack.pop();
int nodeIndex = stack.pop();
if (nodeIndex == AABBTreeNode.INVALID_NODE_INDEX) {
continue;
}
Expand Down Expand Up @@ -377,8 +377,7 @@ public void detectCollisionPairs(CollisionFilter<T> filter, List<CollisionPair<T

Set<CollisionPair<T>> alreadyTested = new HashSet<>();

for (int i = 0; i < nodes.size(); i++) {
AABBTreeNode<T> testedNode = nodes.get(i);
for (AABBTreeNode<T> testedNode : nodes) {
if (!testedNode.isLeaf()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@
import java.util.Objects;

@Getter
public final class CollisionPair<T extends Boundable & Identifiable> {
private final T objectA;
private final T objectB;
public record CollisionPair<T extends Boundable & Identifiable>(T objectA, T objectB) {

public CollisionPair(T objectA, T objectB) {
this.objectA = objectA;
this.objectB = objectB;
}

@Override
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import it.unimi.dsi.fastutil.ints.AbstractIntSet;
import it.unimi.dsi.fastutil.ints.IntIterator;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.io.Serial;
Expand Down Expand Up @@ -431,7 +432,7 @@ public TypeV remove(Object key) {
/**
* Auto-boxing version of {@link #remove(int, Object)}.
*/
public boolean remove(Object key, Object Val) {
public boolean remove(@NotNull Object key, Object Val) {
return (key instanceof Integer) && remove(((Integer) key).intValue(), Val);
}

Expand Down Expand Up @@ -803,7 +804,7 @@ private static final class CHM implements Serializable {
static private final AtomicLongFieldUpdater<CHM> _copyDoneUpdater =
AtomicLongFieldUpdater.newUpdater(CHM.class, "_copyDone");
// Back-pointer to top-level structure
final Int2ObjectNonBlockingMap _nbhml;
final Int2ObjectNonBlockingMap<?> _nbhml;
final int[] _keys;
final Object[] _vals;
// ---
Expand Down Expand Up @@ -844,7 +845,7 @@ private static final class CHM implements Serializable {
private ConcurrentAutoIntTable _slots;

// Simple constructor
CHM(final Int2ObjectNonBlockingMap nbhml, ConcurrentAutoIntTable size, final int logsize) {
CHM(final Int2ObjectNonBlockingMap<?> nbhml, ConcurrentAutoIntTable size, final int logsize) {
_nbhml = nbhml;
_size = size;
_slots = new ConcurrentAutoIntTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import it.unimi.dsi.fastutil.longs.AbstractLongSet;
import it.unimi.dsi.fastutil.longs.LongIterator;
import it.unimi.dsi.fastutil.longs.LongSet;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.io.Serial;
Expand Down Expand Up @@ -433,7 +434,7 @@ public TypeV remove(Object key) {
/**
* Auto-boxing version of {@link #remove(long, Object)}.
*/
public boolean remove(Object key, Object Val) {
public boolean remove(@NotNull Object key, Object Val) {
return (key instanceof Long) && remove(((Long) key).longValue(), Val);
}

Expand Down Expand Up @@ -808,7 +809,7 @@ private static final class CHM implements Serializable {
static private final AtomicLongFieldUpdater<CHM> _copyDoneUpdater =
AtomicLongFieldUpdater.newUpdater(CHM.class, "_copyDone");
// Back-pointer to top-level structure
final Long2ObjectNonBlockingMap _nbhml;
final Long2ObjectNonBlockingMap<?> _nbhml;
final long[] _keys;
final Object[] _vals;
// ---
Expand Down Expand Up @@ -849,7 +850,7 @@ private static final class CHM implements Serializable {
private ConcurrentAutoLongTable _slots;

// Simple constructor
CHM(final Long2ObjectNonBlockingMap nbhml, ConcurrentAutoLongTable size, final int logsize) {
CHM(final Long2ObjectNonBlockingMap<?> nbhml, ConcurrentAutoLongTable size, final int logsize) {
_nbhml = nbhml;
_size = size;
_slots = new ConcurrentAutoLongTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ public interface EntityBaseComponent {

@Inject
void sendPacketToViewersImmediately(BedrockPacket packet);

@Inject
default double getBaseOffset() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public BedrockPacket createSpawnPacket() {
addEntityPacket.setRuntimeEntityId(uniqueId);
addEntityPacket.setUniqueEntityId(uniqueId);
addEntityPacket.setIdentifier(entityType.getIdentifier().toString());
addEntityPacket.setPosition(Vector3f.from(location.x(), location.y(), location.z()));
addEntityPacket.setPosition(Vector3f.from(location.x(), location.y() + getBaseOffset(), location.z()));
addEntityPacket.setMotion(Vector3f.from(motion.x(), motion.y(), motion.z()));
addEntityPacket.setRotation(Vector2f.from(location.pitch(), location.yaw()));
addEntityPacket.getMetadata().putAll(metadata.getEntityDataMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void onSlotChange(Container container, int slot, ItemStack current) {
@Nullable
@Impl
public <T extends Container> T getOpenedContainer(FullContainerType<T> type) {
return (T) id2ContainerBiMap.get(type);
return (T) type2ContainerBiMap.get(type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class EntityPlayerBaseComponentImpl extends EntityBaseComponentImpl<EntityPlayer
protected boolean sneaking;
protected boolean swimming;
protected boolean gliding;
protected boolean crawling;

public EntityPlayerBaseComponentImpl(EntityInitInfo<EntityPlayer> info, Function<EntityPlayer, AABBdc> aabbGetter) {
super(info, aabbGetter);
Expand Down Expand Up @@ -127,7 +128,7 @@ public BedrockPacket createSpawnPacket() {
addPlayerPacket.setUuid(client.getLoginData().getUuid());
addPlayerPacket.setUsername(client.getName());
addPlayerPacket.setPlatformChatId(client.getLoginData().getDeviceInfo().getDeviceId());
addPlayerPacket.setPosition(Vector3f.from(location.x(), location.y(), location.z()));
addPlayerPacket.setPosition(Vector3f.from(location.x(), location.y() + getBaseOffset(), location.z()));
addPlayerPacket.setMotion(Vector3f.from(motion.x(), motion.y(), motion.z()));
addPlayerPacket.setRotation(Vector3f.from(location.pitch(), location.yaw(), location.headYaw()));
addPlayerPacket.setGameType(client.getGameType());
Expand Down Expand Up @@ -190,6 +191,22 @@ public void setGliding(boolean gliding) {
public boolean isGliding() {
return gliding;
}

@Override
public void setCrawling(boolean crawling) {
this.crawling = crawling;
}

@Override
public boolean isCrawling() {
return crawling;
}

@Override
@Impl
public double getBaseOffset() {
return 1.62;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface ItemBaseComponent {
NbtMap getNbt();

@Inject
void setNbt(@Nullable NbtMap nbt);
void setNbt(@Nullable NbtMap nbt);

@Nullable
@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public NbtMap getNbt() {

@Override
@Impl
public void setNbt(NbtMap nbt) {
public void setNbt(@Nullable NbtMap nbt) {
this.nbt = nbt;
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public void setStackNetworkId(int newStackNetworkId) {
@Override
@Impl
public ItemStack copy(boolean newStackNetworkId) {
return itemType.createItemStack(new ItemStackInitInfo.Simple(count, damage, nbt, blockState, stackNetworkId, newStackNetworkId));
return itemType.createItemStack(new ItemStackInitInfo.Simple<>(count, damage, nbt, blockState, stackNetworkId, newStackNetworkId));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class Simple<T extends ItemStack> implements ItemStackInitInfo<T> {
@Setter
private ItemType<T> itemType;

public Simple(int count, int damage, NbtMap nbt, BlockState blockState, Integer stackNetworkId, boolean autoAssignStackNetworkId) {
public Simple(int count, int damage, @Nullable NbtMap nbt, @Nullable BlockState blockState, @Nullable Integer stackNetworkId, boolean autoAssignStackNetworkId) {
this.count = count;
this.damage = damage;
this.nbt = nbt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cn.allay.api.world.entity;

import cn.allay.api.entity.Entity;
import cn.allay.api.math.Location3dc;
import org.joml.Vector3dc;
import org.joml.primitives.AABBdc;

import java.util.Collections;
Expand All @@ -23,13 +25,13 @@ public interface EntityPhysicsService {

void containEntity(Entity entity);

void offerNewLocation(Entity entity, Location3dc location);

default List<Entity> getCollidingEntities(Entity entity) {
if (entity.hasCollision())
return getCollidingEntities(entity.getAABB());
else return Collections.emptyList();
}

List<Entity> getCollidingEntities(AABBdc aabb);


}
23 changes: 12 additions & 11 deletions Allay-API/src/main/java/cn/allay/api/world/palette/Palette.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public void readFromNetwork(ByteBuf byteBuf, RuntimeDataDeserializer<V> deserial
}

public void writeToStoragePersistent(ByteBuf byteBuf, PersistentDataSerializer<V> serializer) {
byteBuf.writeByte(Palette.getPaletteHeader(this.bitArray.getVersion(), false));
byteBuf.writeByte(Palette.getPaletteHeader(this.bitArray.version(), false));

for (int word : this.bitArray.getWords()) byteBuf.writeIntLE(word);
for (int word : this.bitArray.words()) byteBuf.writeIntLE(word);

byteBuf.writeIntLE(this.palette.size());

Expand All @@ -103,8 +103,8 @@ public void writeToStorageRuntime(ByteBuf byteBuf, RuntimeDataSerializer<V> seri
if (writeLast(byteBuf, last)) return;
if (writeEmpty(byteBuf, serializer)) return;

byteBuf.writeByte(Palette.getPaletteHeader(this.bitArray.getVersion(), true));
for (int word : this.bitArray.getWords()) byteBuf.writeIntLE(word);
byteBuf.writeByte(Palette.getPaletteHeader(this.bitArray.version(), true));
for (int word : this.bitArray.words()) byteBuf.writeIntLE(word);
byteBuf.writeIntLE(this.palette.size());
for (V value : this.palette) byteBuf.writeIntLE(serializer.serialize(value));
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public int paletteIndexFor(V value) {
index = this.palette.size();
this.palette.add(value);

final BitArrayVersion version = this.bitArray.getVersion();
final BitArrayVersion version = this.bitArray.version();
if (index > version.maxEntryValue) {
final BitArrayVersion next = version.next;
if (next != null) this.onResize(next);
Expand All @@ -185,11 +185,12 @@ public int paletteIndexFor(V value) {
}

public boolean isEmpty() {
boolean result = true;
if (this.palette.size() > 1) result = false;
for (int word : this.bitArray.getWords())
if (Integer.toUnsignedLong(word) != 0L)
boolean result = this.palette.size() <= 1;
for (int word : this.bitArray.words())
if (Integer.toUnsignedLong(word) != 0L) {
result = false;
break;
}
return result;
}

Expand Down Expand Up @@ -217,9 +218,9 @@ private boolean writeLast(ByteBuf byteBuf, Palette<V> last) {
}

private void writeWords(ByteBuf byteBuf, RuntimeDataSerializer<V> serializer) {
byteBuf.writeByte(getPaletteHeader(this.bitArray.getVersion(), true));
byteBuf.writeByte(getPaletteHeader(this.bitArray.version(), true));

for (int word : this.bitArray.getWords()) byteBuf.writeIntLE(word);
for (int word : this.bitArray.words()) byteBuf.writeIntLE(word);

this.bitArray.writeSizeToNetwork(byteBuf, this.palette.size());
for (V value : this.palette) VarInts.writeInt(byteBuf, serializer.serialize(value));
Expand Down
Loading

0 comments on commit 2b1e104

Please sign in to comment.