Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ jobs:
name: unit-test-reports-${{ github.run_id }}-${{ github.run_attempt }}
path: target/surefire-reports/
if-no-files-found: error

- name: Upload code coverage reports
if: ${{ !cancelled() && hashFiles('target/site/jacoco/jacoco.xml') != '' }}
uses: actions/upload-artifact@v7
with:
name: code-coverage-${{ github.run_id }}-${{ github.run_attempt }}
path: target/site/jacoco/
if-no-files-found: error
8 changes: 8 additions & 0 deletions .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ jobs:
if-no-files-found: error
retention-days: 30

- name: Upload code coverage reports
if: ${{ !cancelled() && hashFiles('target/site/jacoco/jacoco.xml') != '' }}
uses: actions/upload-artifact@v7
with:
name: code-coverage-${{ github.run_id }}-${{ github.run_attempt }}
path: target/site/jacoco/
if-no-files-found: error

publish:
needs: build
runs-on: ubuntu-24.04
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,23 @@ Copyright (c) 2026 TF-Minecraft contributors.
TF-Minecraft-authored material in this repository is licensed under the
[Artistic License 2.0](LICENSE). Third-party dependencies and bundled material
retain their own licenses.

## Tests and coverage

Use Java 21 and Maven 3.9. Install the pinned plugin dependencies with the
repository's existing `.github/scripts/prepare-release.sh` workflow, then run:

```sh
mvn -B --no-transfer-progress clean verify -DskipTests=false -Dmaven.test.skip=false
```

The JUnit 5 suite uses MockBukkit for server state and Mockito at external plugin
boundaries. JaCoCo measures every production class; no production packages,
classes, or methods are excluded. `verify` requires **100% instruction, branch,
and line coverage**, and fails when any counter falls below that threshold.
The HTML report is `target/site/jacoco/index.html`; XML/CSV are alongside it.
Build and release CI upload the coverage report as an artifact, including failed
runs when a report was generated.

Coverage proves the exercised Java behavior. It does not replace a live Paper
server integration check with the pinned ItemsAdder/MMOItems/TLibs versions.
76 changes: 73 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,32 @@
</properties>

<dependencies>
<!-- ItemsAdder loads FastNBT dynamically on a server; mocks need its API types. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>beer.devs</groupId>
<artifactId>FastNbt-jar</artifactId>
<version>1.4.22</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.20.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockbukkit.mockbukkit</groupId>
<artifactId>mockbukkit-v1.21</artifactId>
<version>4.95.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>local</groupId>
<artifactId>gson</artifactId>
Expand Down Expand Up @@ -103,6 +123,56 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.15</version>
<executions>
<execution>
<goals><goal>prepare-agent</goal></goals>
</execution>
<execution>
<id>coverage-report</id>
<phase>verify</phase>
<goals><goal>report</goal></goals>
</execution>
<execution>
<id>coverage-check</id>
<phase>verify</phase>
<goals><goal>check</goal></goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>1.0</minimum>
</limit>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>1.0</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>1.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public void createFolders() {
if(!subFolder.exists()) subFolder.mkdir();
subFolder = new File(getDataFolder(), "colour-schemes");
if(!subFolder.exists()) subFolder.mkdir();
subFolder = new File(getDataFolder(), "model-schemes");
if(!subFolder.exists()) subFolder.mkdir();
subFolder = new File(getDataFolder(), "recipes");
if(!subFolder.exists()) subFolder.mkdir();
subFolder = new File(getDataFolder(), "data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AlloyRecipe getRecipeByResult(String resultId) {
public void upsert(AlloyRecipe recipe, String resultId) {
File indexFile = recipe.resolveIndexFile(root);
File parent = indexFile.getParentFile();
if (parent != null && !parent.exists()) {
if (!parent.exists()) {
parent.mkdirs();
}
try (PrintWriter writer = new PrintWriter(indexFile, StandardCharsets.UTF_8)) {
Expand Down Expand Up @@ -122,7 +122,7 @@ public Map<String, String> loadAllComboResults() {
Map<String, String> map = new LinkedHashMap<>();
for (File indexFile : listIndexFiles()) {
IndexEntry entry = readIndexEntry(indexFile);
if (entry == null || entry.comboKey == null || entry.resultId == null) {
if (entry == null || entry.comboKey == null) {
continue;
}
map.put(entry.comboKey, entry.resultId);
Expand Down Expand Up @@ -199,10 +199,10 @@ private AlloyRecipe recipeFromIndexFile(File indexFile) {
if (fileBase.equals(baseId)) {
return new AlloyRecipe(baseId, java.util.List.of());
}
String catalystPart = fileBase.substring(baseId.length() + 2);
if (!fileBase.startsWith(baseId + "__")) {
return null;
}
String catalystPart = fileBase.substring(baseId.length() + 2);
return new AlloyRecipe(baseId, java.util.Arrays.asList(catalystPart.split("__")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;

Expand All @@ -19,6 +21,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import net.tfminecraft.advancedcrafting.AdvancedCrafting;
import net.tfminecraft.advancedcrafting.loaders.HitLoader;
import net.tfminecraft.advancedcrafting.loaders.RecipeLoader;
import net.tfminecraft.advancedcrafting.objects.crafting.CraftingRecipe;
Expand All @@ -27,15 +30,20 @@

public class Database {
private JSONObject json; // org.json.simple
private final Set<File> rejectedStationFiles = new HashSet<>();
JSONParser parser = new JSONParser();
public HashMap<Location, CraftingStation> loadStations() {
HashMap<Location, CraftingStation> map = new HashMap<>();
File folder = new File("plugins/AdvancedCrafting/data/stations");
for(final File file : folder.listFiles()) {
File folder = new File(AdvancedCrafting.plugin.getDataFolder(), "data/stations");
File[] files = folder.listFiles();
if (files == null) return map;
for(final File file : files) {
if(!file.isDirectory()) {
try {
json = (JSONObject) parser.parse(new InputStreamReader(new FileInputStream(file), "UTF-8"));
Location loc = new Location(Bukkit.getServer().getWorld((String) json.get("world")), (Double) json.get("xPos"),(Double) json.get("yPos"),(Double) json.get("zPos"));
org.bukkit.World world = Bukkit.getServer().getWorld((String) json.get("world"));
if (world == null) throw new IllegalStateException("Station world is not loaded: " + json.get("world"));
Location loc = new Location(world, (Double) json.get("xPos"),(Double) json.get("yPos"),(Double) json.get("zPos"));
CraftingRecipe r = RecipeLoader.getByString((String) json.get("recipe"));
HashMap<String, Integer> materials = new HashMap<>();
int i = 0;
Expand All @@ -58,18 +66,22 @@ public HashMap<Location, CraftingStation> loadStations() {
i++;
}
map.put(loc, new CraftingStation(loc, r, materials, hits));
rejectedStationFiles.remove(file);

} catch (Exception ex) {
rejectedStationFiles.add(file);
ex.printStackTrace();
}
}
}
return map;
}
public void clear() {
File folder = new File("plugins/AdvancedCrafting/data/stations");
for(final File file : folder.listFiles()) {
if(!file.isDirectory()) {
File folder = new File(AdvancedCrafting.plugin.getDataFolder(), "data/stations");
File[] files = folder.listFiles();
if (files == null) return;
for(final File file : files) {
if(!file.isDirectory() && !rejectedStationFiles.contains(file)) {
file.delete();
}
}
Expand All @@ -78,7 +90,12 @@ public void clear() {
public void saveStation(CraftingStation s) {
if(!s.hasRecipe()) return;
try {
File file = new File("plugins/AdvancedCrafting/data/stations",UUID.randomUUID().toString()+".json");
File folder = new File(AdvancedCrafting.plugin.getDataFolder(), "data/stations");
folder.mkdirs();
File file = new File(folder, UUID.randomUUID().toString()+".json");
while (rejectedStationFiles.contains(file)) {
file = new File(folder, UUID.randomUUID().toString()+".json");
}
if(file.exists() == true) {
file.delete();
}
Expand All @@ -90,7 +107,7 @@ public void saveStation(CraftingStation s) {
pw.close();
HashMap<String, Object> defaults = new HashMap<String, Object>();
json = (JSONObject) parser.parse(new InputStreamReader(new FileInputStream(file), "UTF-8"));
defaults.put("world", s.getLoc().getWorld().toString().replace("CraftWorld{name=", "").replace("}", ""));
defaults.put("world", s.getLoc().getWorld().getName());
defaults.put("xPos", s.getLoc().getX());
defaults.put("yPos", s.getLoc().getY());
defaults.put("zPos", s.getLoc().getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ private void parseGlobalStatOffset(String entry) {
if (entry == null || entry.isBlank() || !entry.contains("(")) {
return;
}
if (entry.lastIndexOf(')') < entry.indexOf('(')) {
return;
}
String statId = entry.substring(0, entry.indexOf('(')).trim().toLowerCase();
String amountPart = entry.substring(entry.indexOf('(') + 1, entry.lastIndexOf(')')).trim();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.scheduler.BukkitRunnable;

import dev.lone.itemsadder.api.CustomStack;
Expand Down Expand Up @@ -104,6 +105,7 @@ public void run() {
@SuppressWarnings("deprecation")
@EventHandler
public void addIngredient(PlayerInteractEvent e) {
if (e.isCancelled() || e.getHand() != EquipmentSlot.HAND) return;
if(!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return;
Block b = e.getClickedBlock();
if (!isAlloyStation(b)) {
Expand All @@ -130,6 +132,10 @@ public void addIngredient(PlayerInteractEvent e) {
return;
}
Ingredient ing = cs.getIngredient();
if (ing == null) {
p.sendMessage("§cThis ingredient is no longer configured.");
return;
}
if (!ProfessionPermissions.canUseIngredient(p, ing)) {
p.sendMessage(ProfessionPermissions.missingIngredientPermissionMessage(
ing.getIngredientData().getPermission()));
Expand Down Expand Up @@ -205,8 +211,13 @@ public void nameAlloy(Player p, String s) {
String name = StringFormatter.formatHex(new String(s).replace("_", " "));
NamableAlloy alloy = naming.get(p);
String oldId = alloy.getAlloy().getId();
String id = StringFormatter.clean(s).toLowerCase(java.util.Locale.ROOT);
Alloy existing = getAlloyById(id);
if (existing != null && existing != alloy.getAlloy()) {
p.sendMessage("§cAn alloy with that name already exists.");
return;
}
removeAlloy(oldId);
String id = StringFormatter.clean(s);
alloy.getAlloy().setId(id);
alloy.getAlloy().setName(name);
ItemStack i = alloy.getItem();
Expand All @@ -232,6 +243,7 @@ public void nameAlloy(Player p, String s) {

@EventHandler
public void breakStation(BlockBreakEvent e) {
if (e.isCancelled()) return;
Block b = e.getBlock();
if (!isValidAlloyStation(b)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ private boolean handleAcCommand(CommandSender sender, String[] args) {
p.sendMessage("§cInvalid quality percent. Usage: /ac craft <percent>");
return true;
}
if (!Double.isFinite(percent)) {
p.sendMessage("§cInvalid quality percent. Usage: /ac craft <percent>");
return true;
}
if (percent < 0) {
percent = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ private ItemStack getArmorPiece(Player player, ArmorType type) {
}

private void setArmorPiece(Player player, ArmorType type, ItemStack item) {
switch (type) {
case HELMET -> player.getInventory().setHelmet(item);
case CHESTPLATE -> player.getInventory().setChestplate(item);
case LEGGINGS -> player.getInventory().setLeggings(item);
case BOOTS -> player.getInventory().setBoots(item);
default -> {
}
}
java.util.function.Consumer<ItemStack> writer = switch (type) {
case HELMET -> player.getInventory()::setHelmet;
case CHESTPLATE -> player.getInventory()::setChestplate;
case LEGGINGS -> player.getInventory()::setLeggings;
case BOOTS -> player.getInventory()::setBoots;
};
writer.accept(item);
}

@FunctionalInterface
Expand Down
Loading