Skip to content

Commit

Permalink
Project wide syntax/annotation cleanup (#4238)
Browse files Browse the repository at this point in the history
Co-authored-by: Konicai <[email protected]>
  • Loading branch information
onebeastchris and Konicai authored Dec 5, 2023
1 parent 998caee commit 95d6535
Show file tree
Hide file tree
Showing 270 changed files with 891 additions and 977 deletions.
18 changes: 7 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,28 @@ public class LongClassName {
public int nameWithMultipleWords = 0;

/**
* Javadoc comment to explain what a function does.
*/
* Javadoc comment to explain what a function does.
*/
@RandomAnnotation(stuff = true, moreStuff = "might exist")
public void applyStuff() {
Variable variable = new Variable();
Variable otherVariable = new Variable();

if (condition) {
// Do stuff.
// Do stuff.
} else if (anotherCondition) {
// Do something else.
// Do something else.
}

switch (value) {
case 0:
stuff();
break;
case 1:
differentStuff();
break;
case 0 -> stuff();
case 1 -> differentStuff();
}
}
}
```

Make sure to comment your code where possible.
Make sure to comment your code where possible. To mark nullable methods, use `@Nullable` (and subsequently, `@NonNull`) from the `org.checkerframework.checker.nullness.qual` package.

The nature of our software requires a lot of arrays and maps to be stored - where possible, use Fastutil's specialized maps. For example, if you're storing block state translations, use an `Int2IntMap`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.geysermc.geyser.processor;

import org.checkerframework.checker.nullness.qual.Nullable;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
Expand Down Expand Up @@ -159,7 +161,7 @@ public void complete() {
this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Completed processing for " + this.annotationClassName);
}

private BufferedReader createReader() throws IOException {
private @Nullable BufferedReader createReader() throws IOException {
if (this.outputPath != null) {
this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Reading existing " + this.annotationClassName + " list from " + this.outputPath);
return Files.newBufferedReader(this.outputPath);
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/org/geysermc/geyser/api/GeyserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public interface GeyserApi extends GeyserApiBase {
* @param apiClass the builder class
* @param <R> the implementation type
* @param <T> the API type
* @throws IllegalArgumentException if there is no provider for the specified API class
* @return the builder instance
*/
@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@

public enum CameraShake {
POSITIONAL,
ROTATIONAL;
ROTATIONAL
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

package org.geysermc.geyser.api.block.custom.component;

import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.LinkedHashMap;
import java.util.Set;

import org.checkerframework.checker.nullness.qual.NonNull;

/**
* This class is used to store conditions for a placement filter for a custom block.
*
Expand All @@ -43,7 +43,7 @@ public enum Face {
NORTH,
SOUTH,
WEST,
EAST;
EAST
}

public enum BlockFilterType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface JavaBlockState {
*
* @return whether the block state is waterlogged
*/
@NonNull boolean waterlogged();
boolean waterlogged();

/**
* Gets the collision of the block state
Expand All @@ -53,7 +53,7 @@ public interface JavaBlockState {
*
* @return whether the block state can be broken with hand
*/
@NonNull boolean canBreakWithHand();
boolean canBreakWithHand();

/**
* Gets the pick item of the block state
Expand All @@ -74,7 +74,7 @@ public interface JavaBlockState {
*
* @return whether the block state has block entity
*/
@Nullable boolean hasBlockEntity();
boolean hasBlockEntity();

/**
* Creates a new {@link JavaBlockState.Builder} instance
Expand All @@ -94,17 +94,17 @@ interface Builder {

Builder blockHardness(@NonNegative float blockHardness);

Builder waterlogged(@NonNull boolean waterlogged);
Builder waterlogged(boolean waterlogged);

Builder collision(@NonNull JavaBoundingBox[] collision);

Builder canBreakWithHand(@NonNull boolean canBreakWithHand);
Builder canBreakWithHand(boolean canBreakWithHand);

Builder pickItem(@Nullable String pickItem);

Builder pistonBehavior(@Nullable String pistonBehavior);

Builder hasBlockEntity(@Nullable boolean hasBlockEntity);
Builder hasBlockEntity(boolean hasBlockEntity);

JavaBlockState build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package org.geysermc.geyser.api.block.custom.nonvanilla;

import org.checkerframework.checker.nullness.qual.NonNull;

public record JavaBoundingBox(@NonNull double middleX, @NonNull double middleY, @NonNull double middleZ, @NonNull double sizeX, @NonNull double sizeY, @NonNull double sizeZ) {
public record JavaBoundingBox(double middleX, double middleY, double middleZ, double sizeX, double sizeY, double sizeZ) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.event.bus.OwnedEventBus;
import org.geysermc.geyser.api.extension.Extension;

import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import org.geysermc.event.Event;
import org.geysermc.event.subscribe.OwnedSubscriber;
import org.geysermc.geyser.api.extension.Extension;

/**
* Represents a subscribed listener to a {@link Event}. Wraps around
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/**
* Called whenever Geyser gets pinged
*
* <p>
* This event allows you to modify/obtain the MOTD, maximum player count, and current number of players online,
* Geyser will reply to the client with what was given.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/**
* Called when commands are defined within Geyser.
*
* <p>
* This event allows you to register new commands using the {@link #register(Command)}
* method and retrieve the default commands defined.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.block.custom.CustomBlockData;
import org.geysermc.geyser.api.block.custom.CustomBlockState;
import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockItem;
import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState;
import org.geysermc.event.Event;

/**
* Called on Geyser's startup when looking for custom blocks. Custom blocks must be registered through this event.
*
* <p>
* This event will not be called if the "add-non-bedrock-items" setting is disabled in the Geyser config.
*/
public abstract class GeyserDefineCustomBlocksEvent implements Event {
Expand All @@ -48,8 +47,8 @@ public abstract class GeyserDefineCustomBlocksEvent implements Event {
/**
* Registers the given {@link CustomBlockState} as an override for the
* given java state identifier
* Java state identifiers are listed in
* https://raw.githubusercontent.com/GeyserMC/mappings/master/blocks.json
* Java state identifiers are listed
* <a href="https://raw.githubusercontent.com/GeyserMC/mappings/master/blocks.json">here</a>
*
* @param javaIdentifier the java state identifier to override
* @param customBlockState the custom block state with which to override java state identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/**
* Called on Geyser's startup when looking for custom items. Custom items must be registered through this event.
*
* <p>
* This event will not be called if the "add non-Bedrock items" setting is disabled in the Geyser config.
*/
public interface GeyserDefineCustomItemsEvent extends Event {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/**
* Called on Geyser's startup when looking for custom skulls. Custom skulls must be registered through this event.
*
* <p>
* This event will not be called if the "add-non-bedrock-items" setting is disabled in the Geyser config.
*/
public abstract class GeyserDefineCustomSkullsEvent implements Event {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@

package org.geysermc.geyser.api.extension.exception;

import java.io.Serial;

/**
* Thrown when an extension's description is invalid.
*/
public class InvalidDescriptionException extends Exception {

@Serial
private static final long serialVersionUID = 1L;

public InvalidDescriptionException(Throwable cause) {
super(cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@

package org.geysermc.geyser.api.extension.exception;

import java.io.Serial;

/**
* Thrown when an extension is invalid.
*/
public class InvalidExtensionException extends Exception {

@Serial
private static final long serialVersionUID = 1L;

public InvalidExtensionException(Throwable cause) {
super(cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public enum CreativeCategory {
*
* @return the name of the category
*/
@NonNull public String internalName() {
public @NonNull String internalName() {
return internalName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/**
* This is a way to represent a boolean, but with a non set value added.
* This class was inspired by adventure's version https://github.com/KyoriPowered/adventure/blob/main/4/api/src/main/java/net/kyori/adventure/util/TriState.java
* This class was inspired by adventure's <a href="https://github.com/KyoriPowered/adventure/blob/main/4/api/src/main/java/net/kyori/adventure/util/TriState.java">TriState</a>
*/
public enum TriState {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.md_5.bungee.api.plugin.Plugin;
import org.geysermc.geyser.dump.BootstrapDumpInfo;

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -51,7 +52,8 @@ public class GeyserBungeeDumpInfo extends BootstrapDumpInfo {
this.plugins = new ArrayList<>();

for (net.md_5.bungee.api.config.ListenerInfo listener : proxy.getConfig().getListeners()) {
this.listeners.add(new ListenerInfo(listener.getHost().getHostString(), listener.getHost().getPort()));
InetSocketAddress address = (InetSocketAddress) listener.getSocketAddress();
this.listeners.add(new ListenerInfo(address.getHostString(), address.getPort()));
}

for (Plugin plugin : proxy.getPluginManager().getPlugins()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.netty.PipelineUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.network.netty.GeyserInjector;
Expand Down Expand Up @@ -125,7 +126,7 @@ protected void initializeLocalChannel0(GeyserBootstrap bootstrap) throws Excepti
.channel(LocalServerChannelWrapper.class)
.childHandler(new ChannelInitializer<>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(@NonNull Channel ch) throws Exception {
if (proxy.getConfig().getServers() == null) {
// Proxy hasn't finished loading all plugins - it loads the config after all plugins
// Probably doesn't need to be translatable?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.protocol.ProtocolConstants;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.ping.GeyserPingInfo;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;

Expand Down Expand Up @@ -104,7 +105,7 @@ public int getVersion() {
}

@Override
public InetSocketAddress getVirtualHost() {
public @Nullable InetSocketAddress getVirtualHost() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.protocol.ProtocolConstants;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserBootstrap;
Expand All @@ -44,7 +45,6 @@
import org.geysermc.geyser.platform.bungeecord.command.GeyserBungeeCommandExecutor;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.FileUtils;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -72,6 +72,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {

private static boolean INITIALIZED = false;

@SuppressWarnings({"JavaReflectionMemberAccess", "ResultOfMethodCallIgnored"})
@Override
public void onLoad() {
GeyserLocale.init(this);
Expand Down Expand Up @@ -251,7 +252,7 @@ public SocketAddress getSocketAddress() {
return this.geyserInjector.getServerSocketAddress();
}

@NotNull
@NonNull
@Override
public String getServerBindAddress() {
return findCompatibleListener().map(InetSocketAddress::getHostString).orElse("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.text.GeyserLocale;

Expand All @@ -50,7 +51,7 @@ public String name() {
}

@Override
public void sendMessage(String message) {
public void sendMessage(@NonNull String message) {
handle.sendMessage(TextComponent.fromLegacyText(message));
}

Expand Down
Loading

0 comments on commit 95d6535

Please sign in to comment.