Misc intellij suggestions

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-10-27 15:25:51 +02:00
parent 3e2ac14048
commit c95ced9493
15 changed files with 60 additions and 74 deletions

View File

@ -1,7 +1,6 @@
package net.minestom.server.command.builder.arguments; package net.minestom.server.command.builder.arguments;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException; import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
import net.minestom.server.utils.StringUtils; import net.minestom.server.utils.StringUtils;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;

View File

@ -245,9 +245,9 @@ non-sealed class EventNodeImpl<T extends Event> implements EventNode<T> {
for (Iterator<? extends @NotNull Graph> iterator = nextNodes.iterator(); iterator.hasNext(); ) { for (Iterator<? extends @NotNull Graph> iterator = nextNodes.iterator(); iterator.hasNext(); ) {
Graph next = iterator.next(); Graph next = iterator.next();
if (iterator.hasNext()) { if (iterator.hasNext()) {
genToStringTree(buffer, childrenPrefix + '\u251C' + '\u2500' + " ", childrenPrefix + '\u2502' + " ", next); genToStringTree(buffer, childrenPrefix + '├' + '─' + " ", childrenPrefix + '' + " ", next);
} else { } else {
genToStringTree(buffer, childrenPrefix + '\u2514' + '\u2500' + " ", childrenPrefix + " ", next); genToStringTree(buffer, childrenPrefix + '└' + '─' + " ", childrenPrefix + " ", next);
} }
} }
} }

View File

@ -41,7 +41,8 @@ public class AnvilLoader implements IChunkLoader {
private final Path levelPath; private final Path levelPath;
private final Path regionPath; private final Path regionPath;
private static class RegionCache extends ConcurrentHashMap<IntIntImmutablePair, Set<IntIntImmutablePair>> {} private static class RegionCache extends ConcurrentHashMap<IntIntImmutablePair, Set<IntIntImmutablePair>> {
}
/** /**
* Represents the chunks currently loaded per region. Used to determine when a region file can be unloaded. * Represents the chunks currently loaded per region. Used to determine when a region file can be unloaded.
@ -49,12 +50,7 @@ public class AnvilLoader implements IChunkLoader {
private final RegionCache perRegionLoadedChunks = new RegionCache(); private final RegionCache perRegionLoadedChunks = new RegionCache();
// thread local to avoid contention issues with locks // thread local to avoid contention issues with locks
private final ThreadLocal<Int2ObjectMap<BlockState>> blockStateId2ObjectCacheTLS = new ThreadLocal<>() { private final ThreadLocal<Int2ObjectMap<BlockState>> blockStateId2ObjectCacheTLS = ThreadLocal.withInitial(() -> new Int2ObjectArrayMap<>());
@Override
protected Int2ObjectMap<BlockState> initialValue() {
return new Int2ObjectArrayMap<>();
}
};
public AnvilLoader(@NotNull Path path) { public AnvilLoader(@NotNull Path path) {
this.path = path; this.path = path;
@ -108,7 +104,7 @@ public class AnvilLoader implements IChunkLoader {
Chunk chunk = new DynamicChunk(instance, chunkX, chunkZ); Chunk chunk = new DynamicChunk(instance, chunkX, chunkZ);
synchronized (chunk) { synchronized (chunk) {
var yRange = chunkReader.getYRange(); var yRange = chunkReader.getYRange();
if(yRange.getStart() < instance.getDimensionType().getMinY()) { if (yRange.getStart() < instance.getDimensionType().getMinY()) {
throw new AnvilException( throw new AnvilException(
String.format("Trying to load chunk with minY = %d, but instance dimension type (%s) has a minY of %d", String.format("Trying to load chunk with minY = %d, but instance dimension type (%s) has a minY of %d",
yRange.getStart(), yRange.getStart(),
@ -116,7 +112,7 @@ public class AnvilLoader implements IChunkLoader {
instance.getDimensionType().getMinY() instance.getDimensionType().getMinY()
)); ));
} }
if(yRange.getEndInclusive() > instance.getDimensionType().getMaxY()) { if (yRange.getEndInclusive() > instance.getDimensionType().getMaxY()) {
throw new AnvilException( throw new AnvilException(
String.format("Trying to load chunk with maxY = %d, but instance dimension type (%s) has a maxY of %d", String.format("Trying to load chunk with maxY = %d, but instance dimension type (%s) has a maxY of %d",
yRange.getEndInclusive(), yRange.getEndInclusive(),
@ -137,7 +133,7 @@ public class AnvilLoader implements IChunkLoader {
int regionZ = CoordinatesKt.chunkToRegion(chunkZ); int regionZ = CoordinatesKt.chunkToRegion(chunkZ);
var chunks = perRegionLoadedChunks.computeIfAbsent(new IntIntImmutablePair(regionX, regionZ), r -> new HashSet<>()); // region cache may have been removed on another thread due to unloadChunk var chunks = perRegionLoadedChunks.computeIfAbsent(new IntIntImmutablePair(regionX, regionZ), r -> new HashSet<>()); // region cache may have been removed on another thread due to unloadChunk
chunks.add(new IntIntImmutablePair(chunkX, chunkZ)); chunks.add(new IntIntImmutablePair(chunkX, chunkZ));
}; }
return CompletableFuture.completedFuture(chunk); return CompletableFuture.completedFuture(chunk);
} }
@ -153,8 +149,8 @@ public class AnvilLoader implements IChunkLoader {
synchronized (perRegionLoadedChunks) { synchronized (perRegionLoadedChunks) {
Set<IntIntImmutablePair> previousVersion = perRegionLoadedChunks.put(new IntIntImmutablePair(regionX, regionZ), new HashSet<>()); Set<IntIntImmutablePair> previousVersion = perRegionLoadedChunks.put(new IntIntImmutablePair(regionX, regionZ), new HashSet<>());
assert previousVersion == null : "The AnvilLoader cache should not already have data for this region."; assert previousVersion == null : "The AnvilLoader cache should not already have data for this region.";
}; }
return new RegionFile(new RandomAccessFile(regionPath.toFile(), "rw"), regionX, regionZ, instance.getDimensionType().getMinY(), instance.getDimensionType().getMaxY()-1); return new RegionFile(new RandomAccessFile(regionPath.toFile(), "rw"), regionX, regionZ, instance.getDimensionType().getMinY(), instance.getDimensionType().getMaxY() - 1);
} catch (IOException | AnvilException e) { } catch (IOException | AnvilException e) {
MinecraftServer.getExceptionManager().handleException(e); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
@ -173,19 +169,19 @@ public class AnvilLoader implements IChunkLoader {
Section section = chunk.getSection(sectionY); Section section = chunk.getSection(sectionY);
if(sectionReader.getSkyLight() != null) { if (sectionReader.getSkyLight() != null) {
section.setSkyLight(sectionReader.getSkyLight().copyArray()); section.setSkyLight(sectionReader.getSkyLight().copyArray());
} }
if(sectionReader.getBlockLight() != null) { if (sectionReader.getBlockLight() != null) {
section.setBlockLight(sectionReader.getBlockLight().copyArray()); section.setBlockLight(sectionReader.getBlockLight().copyArray());
} }
// Biomes // Biomes
if(chunkReader.getGenerationStatus().compareTo(ChunkColumn.GenerationStatus.Biomes) > 0) { if (chunkReader.getGenerationStatus().compareTo(ChunkColumn.GenerationStatus.Biomes) > 0) {
SectionBiomeInformation sectionBiomeInformation = chunkReader.readSectionBiomes(sectionReader); SectionBiomeInformation sectionBiomeInformation = chunkReader.readSectionBiomes(sectionReader);
if(sectionBiomeInformation != null && sectionBiomeInformation.hasBiomeInformation()) { if (sectionBiomeInformation != null && sectionBiomeInformation.hasBiomeInformation()) {
if(sectionBiomeInformation.isFilledWithSingleBiome()) { if (sectionBiomeInformation.isFilledWithSingleBiome()) {
for (int y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) { for (int y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) {
for (int z = 0; z < Chunk.CHUNK_SIZE_Z; z++) { for (int z = 0; z < Chunk.CHUNK_SIZE_Z; z++) {
for (int x = 0; x < Chunk.CHUNK_SIZE_X; x++) { for (int x = 0; x < Chunk.CHUNK_SIZE_X; x++) {
@ -207,7 +203,7 @@ public class AnvilLoader implements IChunkLoader {
int finalZ = chunk.chunkZ * Chunk.CHUNK_SIZE_Z + z; int finalZ = chunk.chunkZ * Chunk.CHUNK_SIZE_Z + z;
int finalY = sectionY * Chunk.CHUNK_SECTION_SIZE + y; int finalY = sectionY * Chunk.CHUNK_SECTION_SIZE + y;
int index = x/4 + (z/4) * 4 + (y/4) * 16; int index = x / 4 + (z / 4) * 4 + (y / 4) * 16;
String biomeName = sectionBiomeInformation.getBiomes()[index]; String biomeName = sectionBiomeInformation.getBiomes()[index];
Biome biome = biomeCache.computeIfAbsent(biomeName, n -> Biome biome = biomeCache.computeIfAbsent(biomeName, n ->
Objects.requireNonNullElse(MinecraftServer.getBiomeManager().getByName(NamespaceID.from(n)), BIOME)); Objects.requireNonNullElse(MinecraftServer.getBiomeManager().getByName(NamespaceID.from(n)), BIOME));
@ -221,7 +217,7 @@ public class AnvilLoader implements IChunkLoader {
// Blocks // Blocks
final NBTList<NBTCompound> blockPalette = sectionReader.getBlockPalette(); final NBTList<NBTCompound> blockPalette = sectionReader.getBlockPalette();
if(blockPalette != null) { if (blockPalette != null) {
int[] blockStateIndices = sectionReader.getUncompressedBlockStateIDs(); int[] blockStateIndices = sectionReader.getUncompressedBlockStateIDs();
Block[] convertedPalette = new Block[blockPalette.getSize()]; Block[] convertedPalette = new Block[blockPalette.getSize()];
for (int i = 0; i < convertedPalette.length; i++) { for (int i = 0; i < convertedPalette.length; i++) {
@ -366,8 +362,8 @@ public class AnvilLoader implements IChunkLoader {
} }
private void save(Chunk chunk, ChunkWriter chunkWriter) { private void save(Chunk chunk, ChunkWriter chunkWriter) {
final int minY = chunk.getMinSection()*Chunk.CHUNK_SECTION_SIZE; final int minY = chunk.getMinSection() * Chunk.CHUNK_SECTION_SIZE;
final int maxY = chunk.getMaxSection()*Chunk.CHUNK_SECTION_SIZE -1; final int maxY = chunk.getMaxSection() * Chunk.CHUNK_SECTION_SIZE - 1;
chunkWriter.setYPos(minY); chunkWriter.setYPos(minY);
List<NBTCompound> blockEntities = new ArrayList<>(); List<NBTCompound> blockEntities = new ArrayList<>();
chunkWriter.setStatus(ChunkColumn.GenerationStatus.Full); chunkWriter.setStatus(ChunkColumn.GenerationStatus.Full);
@ -376,7 +372,7 @@ public class AnvilLoader implements IChunkLoader {
int[] palettedBiomes = new int[ChunkSection.Companion.getBiomeArraySize()]; int[] palettedBiomes = new int[ChunkSection.Companion.getBiomeArraySize()];
int[] palettedBlockStates = new int[Chunk.CHUNK_SIZE_X * Chunk.CHUNK_SECTION_SIZE * Chunk.CHUNK_SIZE_Z]; int[] palettedBlockStates = new int[Chunk.CHUNK_SIZE_X * Chunk.CHUNK_SECTION_SIZE * Chunk.CHUNK_SIZE_Z];
for (int sectionY = chunk.getMinSection(); sectionY < chunk.getMaxSection(); sectionY++) { for (int sectionY = chunk.getMinSection(); sectionY < chunk.getMaxSection(); sectionY++) {
ChunkSectionWriter sectionWriter = new ChunkSectionWriter(SupportedVersion.Companion.getLatest(), (byte)sectionY); ChunkSectionWriter sectionWriter = new ChunkSectionWriter(SupportedVersion.Companion.getLatest(), (byte) sectionY);
Section section = chunk.getSection(sectionY); Section section = chunk.getSection(sectionY);
sectionWriter.setSkyLights(section.getSkyLight()); sectionWriter.setSkyLights(section.getSkyLight());
@ -399,8 +395,8 @@ public class AnvilLoader implements IChunkLoader {
palettedBlockStates[blockIndex] = blockPalette.getPaletteIndex(hephaistosBlockState); palettedBlockStates[blockIndex] = blockPalette.getPaletteIndex(hephaistosBlockState);
// biome are stored for 4x4x4 volumes, avoid unnecessary work // biome are stored for 4x4x4 volumes, avoid unnecessary work
if(x % 4 == 0 && sectionLocalY % 4 == 0 && z % 4 == 0) { if (x % 4 == 0 && sectionLocalY % 4 == 0 && z % 4 == 0) {
int biomeIndex = (x/4) + (sectionLocalY/4) * 4 * 4 + (z/4) * 4; int biomeIndex = (x / 4) + (sectionLocalY / 4) * 4 * 4 + (z / 4) * 4;
final Biome biome = chunk.getBiome(x, y, z); final Biome biome = chunk.getBiome(x, y, z);
final String biomeName = biome.name().asString(); final String biomeName = biome.name().asString();
@ -440,6 +436,7 @@ public class AnvilLoader implements IChunkLoader {
/** /**
* Unload a given chunk. Also unloads a region when no chunk from that region is loaded. * Unload a given chunk. Also unloads a region when no chunk from that region is loaded.
*
* @param chunk the chunk to unload * @param chunk the chunk to unload
*/ */
@Override @Override
@ -450,14 +447,14 @@ public class AnvilLoader implements IChunkLoader {
final IntIntImmutablePair regionKey = new IntIntImmutablePair(regionX, regionZ); final IntIntImmutablePair regionKey = new IntIntImmutablePair(regionX, regionZ);
synchronized (perRegionLoadedChunks) { synchronized (perRegionLoadedChunks) {
Set<IntIntImmutablePair> chunks = perRegionLoadedChunks.get(regionKey); Set<IntIntImmutablePair> chunks = perRegionLoadedChunks.get(regionKey);
if(chunks != null) { // if null, trying to unload a chunk from a region that was not created by the AnvilLoader if (chunks != null) { // if null, trying to unload a chunk from a region that was not created by the AnvilLoader
// don't check return value, trying to unload a chunk not created by the AnvilLoader is valid // don't check return value, trying to unload a chunk not created by the AnvilLoader is valid
chunks.remove(new IntIntImmutablePair(chunk.chunkX, chunk.chunkZ)); chunks.remove(new IntIntImmutablePair(chunk.chunkX, chunk.chunkZ));
if(chunks.isEmpty()) { if (chunks.isEmpty()) {
perRegionLoadedChunks.remove(regionKey); perRegionLoadedChunks.remove(regionKey);
RegionFile regionFile = alreadyLoaded.remove(RegionFile.Companion.createFileName(regionX, regionZ)); RegionFile regionFile = alreadyLoaded.remove(RegionFile.Companion.createFileName(regionX, regionZ));
if(regionFile != null) { if (regionFile != null) {
try { try {
regionFile.close(); regionFile.close();
} catch (IOException e) { } catch (IOException e) {
@ -466,7 +463,7 @@ public class AnvilLoader implements IChunkLoader {
} }
} }
} }
}; }
} }
@Override @Override

View File

@ -3,7 +3,6 @@ package net.minestom.server.instance.generator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collection; import java.util.Collection;
import java.util.List;
@FunctionalInterface @FunctionalInterface
public interface Generator { public interface Generator {

View File

@ -1,9 +1,7 @@
package net.minestom.server.item; package net.minestom.server.item;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.attribute.ItemAttribute; import net.minestom.server.item.attribute.ItemAttribute;
import net.minestom.server.registry.ProtocolObject;
import net.minestom.server.tag.Tag; import net.minestom.server.tag.Tag;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -32,31 +32,31 @@ public final class Messenger {
static { static {
try { try {
CHAT_REGISTRY = (NBTCompound) new SNBTParser(new StringReader( CHAT_REGISTRY = (NBTCompound) new SNBTParser(new StringReader(
"{\n" + """
" \"type\": \"minecraft:chat_type\",\n" + {
" \"value\": [\n" + "type": "minecraft:chat_type",
" {\n" + "value": [
" \"name\":\"minecraft:chat\",\n" + {
" \"id\":1,\n" + "name":"minecraft:chat",
" \"element\":{\n" + "id":1,
" \"chat\":{\n" + "element":{
" \"translation_key\":\"chat.type.text\",\n" + "chat":{
" \"parameters\":[\n" + "translation_key":"chat.type.text",
" \"sender\",\n" + "parameters":[
" \"content\"\n" + "sender",
" ]\n" + "content"
" },\n" + ]
" \"narration\":{\n" + },
" \"translation_key\":\"chat.type.text.narrate\",\n" + "narration":{
" \"parameters\":[\n" + "translation_key":"chat.type.text.narrate",
" \"sender\",\n" + "parameters":[
" \"content\"\n" + "sender",
" ]\n" + "content"
" }\n" + ]
" }\n" + }
" }" + }
" ]\n" + } ]
"}" }"""
)).parse(); )).parse();
} catch (NBTException e) { } catch (NBTException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -15,7 +15,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping> advancementMappings, public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping> advancementMappings,
@NotNull List<String> identifiersToRemove, @NotNull List<String> identifiersToRemove,

View File

@ -10,7 +10,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;

View File

@ -12,7 +12,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
public record SetSlotPacket(byte windowId, int stateId, short slot, public record SetSlotPacket(byte windowId, int stateId, short slot,

View File

@ -12,9 +12,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
public record WindowItemsPacket(byte windowId, int stateId, @NotNull List<ItemStack> items, public record WindowItemsPacket(byte windowId, int stateId, @NotNull List<ItemStack> items,
@NotNull ItemStack carriedItem) implements ComponentHoldingServerPacket { @NotNull ItemStack carriedItem) implements ComponentHoldingServerPacket {

View File

@ -89,10 +89,10 @@ public enum ServerListPingType {
final String motd = SECTION.serialize(data.getDescription()); final String motd = SECTION.serialize(data.getDescription());
if (supportsVersions) { if (supportsVersions) {
return String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", return String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d",
data.getProtocol(), data.getVersion(), motd, data.getOnline(), data.getMaxPlayer()); data.getProtocol(), data.getVersion(), motd, data.getOnline(), data.getMaxPlayer());
} else { } else {
return String.format("%s\u00a7%d\u00a7%d", motd, data.getOnline(), data.getMaxPlayer()); return String.format("%s§%d§%d", motd, data.getOnline(), data.getMaxPlayer());
} }
} }

View File

@ -317,7 +317,7 @@ public class Sidebar implements Scoreboard {
* Creates a new {@link SidebarTeam} * Creates a new {@link SidebarTeam}
*/ */
private void createTeam() { private void createTeam() {
this.entityName = '\u00A7' + Integer.toHexString(colorName); this.entityName = '§' + Integer.toHexString(colorName);
this.sidebarTeam = new SidebarTeam(teamName, content, Component.empty(), entityName); this.sidebarTeam = new SidebarTeam(teamName, content, Component.empty(), entityName);
} }

View File

@ -30,7 +30,7 @@ public final class MinestomConsoleWriter extends AbstractFormatPatternWriter {
} }
@Override @Override
public void close() throws Exception { public void close() {
// EMPTY // EMPTY
} }
} }

View File

@ -3,6 +3,7 @@ package net.minestom.server.utils;
import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import org.intellij.lang.annotations.Pattern;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Objects; import java.util.Objects;
@ -95,6 +96,7 @@ public final class NamespaceID implements CharSequence, Key {
} }
@Override @Override
@Pattern("[a-z0-9_\\-.]+")
public @NotNull String namespace() { public @NotNull String namespace() {
return this.domain; return this.domain;
} }

View File

@ -30,9 +30,7 @@ public record BiomeParticle(float probability, Option option) {
nbtCompound.setString("Name", block.name()); nbtCompound.setString("Name", block.name());
Map<String, String> propertiesMap = block.properties(); Map<String, String> propertiesMap = block.properties();
if (propertiesMap.size() != 0) { if (propertiesMap.size() != 0) {
nbtCompound.set("Properties", NBT.Compound(p -> { nbtCompound.set("Properties", NBT.Compound(p -> propertiesMap.forEach(p::setString)));
propertiesMap.forEach(p::setString);
}));
} }
}); });
} }
@ -59,9 +57,7 @@ public record BiomeParticle(float probability, Option option) {
public NBTCompound toNbt() { public NBTCompound toNbt() {
//todo test count might be wrong type //todo test count might be wrong type
NBTCompound nbtCompound = item.meta().toNBT(); NBTCompound nbtCompound = item.meta().toNBT();
return nbtCompound.modify(n -> { return nbtCompound.modify(n -> n.setString("type", type));
n.setString("type", type);
});
} }
} }