Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some IDE warnings #273

Merged
merged 13 commits into from
Dec 12, 2024
18 changes: 6 additions & 12 deletions src/main/java/com/cleanroommc/groovyscript/GroovyScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,33 +204,27 @@ public static void onInput(InputEvent.KeyInputEvent event) {
}
}

@NotNull
public static String getScriptPath() {
public static @NotNull String getScriptPath() {
return getScriptFile().getPath();
}

@NotNull
public static File getMinecraftHome() {
public static @NotNull File getMinecraftHome() {
return SandboxData.getMinecraftHome();
}

@NotNull
public static File getScriptFile() {
public static @NotNull File getScriptFile() {
return SandboxData.getScriptFile();
}

@NotNull
public static File getResourcesFile() {
public static @NotNull File getResourcesFile() {
return SandboxData.getResourcesFile();
}

@NotNull
public static File getRunConfigFile() {
public static @NotNull File getRunConfigFile() {
return SandboxData.getRunConfigFile();
}

@NotNull
public static GroovyScriptSandbox getSandbox() {
public static @NotNull GroovyScriptSandbox getSandbox() {
if (sandbox == null) {
throw new IllegalStateException("GroovyScript is not yet loaded or failed to load!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public interface GroovyLog {
/**
* @return an instance of {@link GroovyLog}
*/
@NotNull
static GroovyLog get() {
static @NotNull GroovyLog get() {
return GroovyLogImpl.LOG;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public interface IGroovyContainer {
*
* @return aliases
*/
@NotNull
default Collection<String> getAliases() {
default @NotNull Collection<String> getAliases() {
return Collections.singletonList(getModId());
}

Expand All @@ -67,8 +66,7 @@ default Collection<String> getAliases() {
* @return the override priority
* @see Priority
*/
@NotNull
default Priority getOverridePriority() {
default @NotNull Priority getOverridePriority() {
return Priority.NONE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ public boolean test(ItemStack stack) {
return stack.isEmpty();
}

@Nullable
@Override
public String getMark() {
public @Nullable String getMark() {
return null;
}

Expand Down Expand Up @@ -152,9 +151,8 @@ public boolean test(ItemStack stack) {
return true;
}

@Nullable
@Override
public String getMark() {
public @Nullable String getMark() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ default boolean hasNbt() {
@Nullable
NBTTagCompound getNbt();

@NotNull
default NBTTagCompound getOrCreateNbt() {
default @NotNull NBTTagCompound getOrCreateNbt() {
NBTTagCompound nbt = getNbt();
if (nbt == null) {
nbt = new NBTTagCompound();
Expand All @@ -30,8 +29,7 @@ default NBTTagCompound getOrCreateNbt() {
return nbt;
}

@Nullable
default NBTBase getSubTag(String key) {
default @Nullable NBTBase getSubTag(String key) {
NBTTagCompound nbt = getNbt();
return nbt == null ? null : nbt.getTag(key);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cleanroommc/groovyscript/api/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static <T> Result<T> some(@NotNull T value) {
@NotNull
T getValue();

@SuppressWarnings("ClassCanBeRecord")
class Some<T> implements Result<T> {

private final T value;
Expand All @@ -60,6 +61,7 @@ public boolean hasError() {
}
}

@SuppressWarnings("ClassCanBeRecord")
class Error<T> implements Result<T> {

private final String error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,48 @@ public class InfoParserPackage {
/**
* Server where the command is executed
*/
@NotNull
private final MinecraftServer server;
private final @NotNull MinecraftServer server;
/**
* Player who executes the command
*/
@NotNull
private final EntityPlayer player;
private final @NotNull EntityPlayer player;
/**
* Arguments of the command
*/
@NotNull
private final List<String> args;
private final @NotNull List<String> args;
/**
* A list of messages that will be sent to the player after this event.
* Add or remove your messages here.
*/
@NotNull
private final List<ITextComponent> messages;
private final @NotNull List<ITextComponent> messages;
/**
* If pretty nbt is enabled
*/
private final boolean prettyNbt;
/**
* The held item or the item form of the block being looked at.
*/
@NotNull
private ItemStack stack;
private @NotNull ItemStack stack;
/**
* The entity the player is looking at
*/
@Nullable
private Entity entity;
private @Nullable Entity entity;
/**
* The block position the player is looking at
*/
@Nullable
private BlockPos pos;
private @Nullable BlockPos pos;
/**
* The block state of the held item or the block state the player is looking at
*/
@Nullable
private IBlockState blockState;
private @Nullable IBlockState blockState;
/**
* The block of the held item or the block the player is looking at
*/
@Nullable
private Block block;
private @Nullable Block block;
/**
* The tile entity the player is looking at
*/
@Nullable
private TileEntity tileEntity;
private @Nullable TileEntity tileEntity;

public InfoParserPackage(
@NotNull MinecraftServer server,
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ public GSCommand() {
addSubcommand(new SimpleCommand("log", (server, sender, args) -> postLogFiles(sender)));

addSubcommand(new SimpleCommand("reload", (server, sender, args) -> {
if (sender instanceof EntityPlayerMP) {
if (sender instanceof EntityPlayerMP player) {
if (hasArgument(args, "--clean")) {
GroovyLogImpl.LOG.cleanLog();
}
runReload((EntityPlayerMP) sender, server);
runReload(player, server);
}
}));

addSubcommand(new SimpleCommand("check", (server, sender, args) -> {
if (sender instanceof EntityPlayerMP) {
if (sender instanceof EntityPlayerMP player) {
sender.sendMessage(new TextComponentString("Checking groovy syntax..."));
long time = System.currentTimeMillis();
GroovyScript.getSandbox().checkSyntax();
time = System.currentTimeMillis() - time;
sender.sendMessage(new TextComponentString("Checking syntax took " + time + "ms"));
GroovyScript.postScriptRunResult((EntityPlayerMP) sender, false, false, false, time);
GroovyScript.postScriptRunResult(player, false, false, false, time);
}
}));

Expand Down Expand Up @@ -161,20 +161,17 @@ public static boolean hasArgument(String[] args, String arg) {
}

@Override
@NotNull
public String getName() {
public @NotNull String getName() {
return "groovyscript";
}

@Override
@NotNull
public List<String> getAliases() {
public @NotNull List<String> getAliases() {
return Arrays.asList("grs", "gs");
}

@Override
@NotNull
public String getUsage(@NotNull ICommandSender sender) {
public @NotNull String getUsage(@NotNull ICommandSender sender) {
return "/grs []";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,11 @@ private boolean tryRecipe(World world, BlockPos pos, List<ItemContainer> itemsIn
*/
public abstract void handleRecipeResult(World world, BlockPos pos);

@Nullable
public static Fluid getFluid(IBlockState state) {
public static @Nullable Fluid getFluid(IBlockState state) {
Block block = state.getBlock();

if (block instanceof IFluidBlock) {
return ((IFluidBlock) block).getFluid();
if (block instanceof IFluidBlock iFluidBlock) {
return iFluidBlock.getFluid();
}
if (block instanceof BlockLiquid) {
if (state.getMaterial() == Material.WATER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void handleRecipeResult(World world, BlockPos pos) {

public static class RecipeBuilder extends FluidRecipe.RecipeBuilder<FluidToItem.Recipe> {

private float fluidConsumptionChance = 1f;
private float fluidConsumptionChance = 1.0f;

public RecipeBuilder fluidInput(FluidStack fluidStack, float fluidConsumptionChance) {
fluidInput(fluidStack);
Expand All @@ -144,7 +144,7 @@ public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, Recipe.MAX_ITEM_INPUT, 1, 1);
validateFluids(msg, 1, 1, 0, 0);
validateChances(msg);
this.fluidConsumptionChance = MathHelper.clamp(this.fluidConsumptionChance, 0f, 1f);
this.fluidConsumptionChance = MathHelper.clamp(this.fluidConsumptionChance, 0.0f, 1.0f);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ public void drawExtras(@NotNull Minecraft minecraft) {
GlStateManager.popMatrix();
}

@Nullable
@Override
public IDrawable getIcon() {
public @Nullable IDrawable getIcon() {
return icon;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public void drawExtras(@NotNull Minecraft minecraft) {
GlStateManager.popMatrix();
}

@Nullable
@Override
public IDrawable getIcon() {
public @Nullable IDrawable getIcon() {
return icon;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public void setRecipe(@NotNull IRecipeLayout recipeLayout, @NotNull RecipeWrappe
recipeLayout.getItemStacks().addTooltipCallback((slotIndex, input, ingredient, tooltip) -> {
if (slotIndex < 9) {
float chance = recipeWrapper.recipe.getItemConsumeChance()[slotIndex];
if (chance < 1f) {
if (chance < 1.0f) {
tooltip.add(1, I18n.format("groovyscript.recipe.chance_consume", numberFormat.format(chance)));
}
}
});
recipeLayout.getFluidStacks().addTooltipCallback((slotIndex, input, ingredient, tooltip) -> {
if (slotIndex == 10 && recipeWrapper.recipe instanceof FluidToItem.Recipe fluidToItemRecipe) {
float chance = fluidToItemRecipe.getFluidConsumptionChance();
if (chance < 1f) {
if (chance < 1.0f) {
tooltip.add(1, I18n.format("groovyscript.recipe.chance_consume", numberFormat.format(chance)));
}
}
Expand Down Expand Up @@ -104,9 +104,8 @@ public void drawExtras(@NotNull Minecraft minecraft) {
rightArrow.draw(minecraft, 76, outputY + 1);
}

@Nullable
@Override
public IDrawable getIcon() {
public @Nullable IDrawable getIcon() {
return this.icon;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ public void drawExtras(@NotNull Minecraft minecraft) {
GlStateManager.popMatrix();
}

@Nullable
@Override
public IDrawable getIcon() {
public @Nullable IDrawable getIcon() {
return icon;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Arrays;
import java.util.Random;

@SuppressWarnings("ClassCanBeRecord")
public class GroovyLootCondition implements LootCondition {

private static final Class<?>[] CLOSURE_CLASSES = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public boolean isLoaded() {
return true;
}

@NotNull
@Override
public Collection<String> getAliases() {
public @NotNull Collection<String> getAliases() {
return aliases;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ protected void addProperty(INamed property) {
}
}

@UnmodifiableView
public Collection<INamed> getRegistries() {
public @UnmodifiableView Collection<INamed> getRegistries() {
return this.view.values();
}

@UnmodifiableView
public Map<String, INamed> getProperties() {
public @UnmodifiableView Map<String, INamed> getProperties() {
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public boolean isLoaded() {
return loaded;
}

@NotNull
@Override
public Collection<String> getAliases() {
public @NotNull Collection<String> getAliases() {
return aliases;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ public static void init() {
}
}

@NotNull
public GroovyContainer<?> getContainer(String mod) {
public @NotNull GroovyContainer<?> getContainer(String mod) {
if (!containers.containsKey(mod)) {
throw new IllegalStateException("There is no compat registered for '" + mod + "'!");
}
Expand Down
Loading