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

Enable spotless and editorconfig #95

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
59 changes: 25 additions & 34 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
//version: 1707682661

/*
* DO NOT UPDATE THIS BUILDSCRIPT!!!!!!!!!!!!!!!!!!!!!!
* spotless is replaced by CleanroomGradle's
*/

/*
* DO NOT CHANGE THIS FILE!
* Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -27,7 +33,7 @@ plugins {
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.33'
id 'net.darkhax.curseforgegradle' version '1.1.18' apply false
id 'com.modrinth.minotaur' version '2.8.7' apply false
id 'com.diffplug.spotless' version '6.13.0' apply false
id 'com.diffplug.spotless' version '6.23.3' apply false
id 'com.palantir.git-version' version '3.0.0' apply false
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id 'org.jetbrains.kotlin.jvm' version '1.8.0' apply false
Expand Down Expand Up @@ -200,51 +206,36 @@ project.extensions.add(com.diffplug.blowdryer.Blowdryer, 'Blowdryer', com.diffpl
if (enableSpotless.toBoolean()) {
apply plugin: 'com.diffplug.spotless'

// Spotless auto-formatter
// See https://github.com/diffplug/spotless/tree/main/plugin-gradle
// Can be locally toggled via spotless:off/spotless:on comments
// THIS IS FROM CLEANROOM_GRADLE
spotless {
encoding 'UTF-8'

format 'misc', {
target '.gitignore'

format ('misc') {
target '*.gradle', '.gitattributes', '.gitignore', '*.properties'
indentWithSpaces()
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
}
java {
target 'src/main/java/**/*.java', 'src/test/java/**/*.java' // exclude api as they are not our files

def orderFile = project.file('spotless.importorder')
if (!orderFile.exists()) {
orderFile = Blowdryer.file('spotless.importorder')
}
def formatFile = project.file('spotless.eclipseformat.xml')
if (!formatFile.exists()) {
formatFile = Blowdryer.file('spotless.eclipseformat.xml')
}

toggleOffOn()
importOrderFile(orderFile)
importOrder 'java', 'javax', 'org', 'com', '', '\\#'
removeUnusedImports()
endWithNewline()
//noinspection GroovyAssignabilityCheck
eclipse('4.19.0').configFile(formatFile)
}
kotlin {
target 'src/*/kotlin/**/*.kt'

toggleOffOn()
ktfmt('0.39')

indentWithSpaces()
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
formatAnnotations()
eclipse('4.26').configFile('cleanroom_format.xml')
custom 'noWildcardImports', com.diffplug.spotless.FormatterFunc.needsFile((text, file) -> {
text.eachLine {
if (it.trim() ==~ /^import\s(static\s)?\S+\*;/) {
throw new Error("${file.getName()}\n\t $it\n\t\tNo wildcard imports allowed, import individually.")
}
}
})
}
scala {
target 'src/*/scala/**/*.scala'
scalafmt('3.7.1')
json {
target 'src/**/*.json'
simple().indentWithSpaces(4)
}
}
}
Expand Down
380 changes: 380 additions & 0 deletions cleanroom_format.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mavenArtifactGroup =
# By default this will use the files found here: https://github.com/GregTechCEu/Buildscripts/tree/master/spotless
# to format your code. However, you can create your own version of these files and place them in your project's
# root directory to apply your own formatting options instead.
enableSpotless = false
enableSpotless = true

# Enable JUnit testing platform used for testing your code.
# Uses JUnit 5. See guide and documentation here: https://junit.org/junit5/docs/current/user-guide/
Expand Down
49 changes: 16 additions & 33 deletions src/main/java/betterquesting/AdminExecute.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package betterquesting;

import javax.annotation.Nonnull;

import net.minecraft.command.CommandResultStats.Type;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
Expand All @@ -10,29 +12,22 @@
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;

import javax.annotation.Nonnull;

/**
* Elevates the player's privileges to OP level for use in command rewards
*/
public class AdminExecute implements ICommandSender {

private final EntityPlayer player;

public AdminExecute(EntityPlayer player) {
this.player = player;
}

@Nonnull
@Override
public String getName() {
return player.getName();
}
@Nonnull @Override
public String getName() { return player.getName(); }

@Nonnull
@Override
public ITextComponent getDisplayName() {
return player.getDisplayName();
}
@Nonnull @Override
public ITextComponent getDisplayName() { return player.getDisplayName(); }

@Override
public void sendMessage(ITextComponent p_145747_1_) {
Expand All @@ -44,28 +39,17 @@ public boolean canUseCommand(int p_70003_1_, @Nonnull String p_70003_2_) {
return true;
}

@Nonnull
@Override
public BlockPos getPosition() {
return player.getPosition();
}
@Nonnull @Override
public BlockPos getPosition() { return player.getPosition(); }

@Nonnull
@Override
public World getEntityWorld() {
return player.getEntityWorld();
}
@Nonnull @Override
public World getEntityWorld() { return player.getEntityWorld(); }

@Nonnull
@Override
public Vec3d getPositionVector() {
return player.getPositionVector();
}
@Nonnull @Override
public Vec3d getPositionVector() { return player.getPositionVector(); }

@Override
public Entity getCommandSenderEntity() {
return player.getCommandSenderEntity();
}
public Entity getCommandSenderEntity() { return player.getCommandSenderEntity(); }

@Override
public boolean sendCommandFeedback() {
Expand All @@ -78,7 +62,6 @@ public void setCommandStat(Type type, int amount) {
}

@Override
public MinecraftServer getServer() {
return player.getServer();
}
public MinecraftServer getServer() { return player.getServer(); }

}
2 changes: 2 additions & 0 deletions src/main/java/betterquesting/NBTReplaceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.nbt.NBTTagString;

public class NBTReplaceUtil {

@SuppressWarnings("unchecked")
public static <T extends NBTBase> T replaceStrings(T baseTag, String key, String replace) {
if (baseTag == null) {
Expand All @@ -31,4 +32,5 @@ public static <T extends NBTBase> T replaceStrings(T baseTag, String key, String

return baseTag; // Either isn't a string or doesn't contain one
}

}
2 changes: 2 additions & 0 deletions src/main/java/betterquesting/NbtBlockType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public class NbtBlockType // TODO: Make a version of this for the base mod and give it a dedicated editor
{

public Block b = Blocks.LOG;
public int m = -1;
public int n = 1;
Expand Down Expand Up @@ -62,4 +63,5 @@ public BigItemStack getItemStack() {
stack.setOreDict(oreDict);
return stack;
}

}
21 changes: 13 additions & 8 deletions src/main/java/betterquesting/ScoreBQ.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package betterquesting;

import betterquesting.api2.storage.INBTPartial;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.UUID;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import betterquesting.api2.storage.INBTPartial;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

public class ScoreBQ implements INBTPartial<NBTTagList, UUID> {

private final TreeMap<UUID, Integer> playerScores = new TreeMap<>();

public synchronized int getScore(@Nonnull UUID uuid) {
Expand All @@ -30,7 +32,8 @@ public synchronized boolean hasEntry(@Nonnull UUID uuid) {
@Override
public synchronized NBTTagList writeToNBT(NBTTagList nbt, @Nullable List<UUID> subset) {
for (Entry<UUID, Integer> entry : playerScores.entrySet()) {
if (subset != null && !subset.contains(entry.getKey())) continue;
if (subset != null && !subset.contains(entry.getKey()))
continue;
NBTTagCompound jObj = new NBTTagCompound();
jObj.setString("uuid", entry.getKey().toString());
jObj.setInteger("value", entry.getValue());
Expand All @@ -42,7 +45,8 @@ public synchronized NBTTagList writeToNBT(NBTTagList nbt, @Nullable List<UUID> s

@Override
public synchronized void readFromNBT(NBTTagList nbt, boolean merge) {
if (!merge) playerScores.clear();
if (!merge)
playerScores.clear();

for (int i = 0; i < nbt.tagCount(); i++) {
try {
Expand All @@ -53,4 +57,5 @@ public synchronized void readFromNBT(NBTTagList nbt, boolean merge) {
}
}
}

}
18 changes: 11 additions & 7 deletions src/main/java/betterquesting/ScoreboardBQ.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package betterquesting;

import betterquesting.api2.storage.INBTPartial;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.UUID;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import betterquesting.api2.storage.INBTPartial;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

public class ScoreboardBQ implements INBTPartial<NBTTagList, UUID> {

public static final ScoreboardBQ INSTANCE = new ScoreboardBQ();

private final TreeMap<String, ScoreBQ> objectives = new TreeMap<>();
Expand All @@ -28,7 +30,8 @@ public synchronized void setScore(@Nonnull UUID uuid, @Nonnull String scoreName,

@Override
public synchronized void readFromNBT(NBTTagList nbt, boolean merge) {
if (!merge) objectives.clear();
if (!merge)
objectives.clear();
for (int i = 0; i < nbt.tagCount(); i++) {
NBTTagCompound jObj = nbt.getCompoundTagAt(i);
ScoreBQ score = objectives.computeIfAbsent(jObj.getString("name"), (key) -> new ScoreBQ());
Expand All @@ -47,4 +50,5 @@ public synchronized NBTTagList writeToNBT(NBTTagList nbt, @Nullable List<UUID> u

return nbt;
}

}
20 changes: 14 additions & 6 deletions src/main/java/betterquesting/XPHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.network.play.server.SPacketSetExperience;

public class XPHelper {

// Pre-calculated XP levels at 1M intervals for speed searching
private static long[] QUICK_XP = new long[2147];

Expand All @@ -26,7 +27,8 @@ public static void addXP(EntityPlayer player, long xp, boolean sync) {
player.experience = (float) ((double) (experience - expForLevel) / (double) xpBarCap(player));
player.experience = Math.max(0F, player.experience); // Sanity check

if (sync && player instanceof EntityPlayerMP) syncXP((EntityPlayerMP) player);
if (sync && player instanceof EntityPlayerMP)
syncXP((EntityPlayerMP) player);
}

public static void syncXP(EntityPlayerMP player) {
Expand All @@ -50,21 +52,26 @@ public static long xpBarCap(EntityPlayer player) {
}

public static int getXPLevel(long xp) {
if (xp <= 0) return 0;
if (xp <= 0)
return 0;

int i = 0;

while (i < QUICK_XP.length && QUICK_XP[i] <= xp) i++;
while (i < QUICK_XP.length && QUICK_XP[i] <= xp)
i++;

if (i > 0) i = (i - 1) * 1000000;
if (i > 0)
i = (i - 1) * 1000000;

while (i < Integer.MAX_VALUE && getLevelXP(i) <= xp) i++;
while (i < Integer.MAX_VALUE && getLevelXP(i) <= xp)
i++;

return i - 1;
}

public static long getLevelXP(int level) {
if (level <= 0) return 0;
if (level <= 0)
return 0;

if (level < 17) {
return (long) (Math.pow(level, 2D) + (level * 6D));
Expand All @@ -74,4 +81,5 @@ public static long getLevelXP(int level) {
return (long) (4.5D * Math.pow(level, 2D) - (level * 162.5D) + 2220L);
}
}

}
Loading