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
142 changes: 142 additions & 0 deletions .github/workflows/xraymonitor-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: XRayMonitor CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
MAVEN_OPTS: "-Dmaven.repo.local=$HOME/.m2/repository -Xmx1024m"

jobs:
test:
name: Test on Java ${{ matrix.java-version }}
runs-on: ubuntu-latest

strategy:
matrix:
java-version: [21]
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'

- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Verify Maven setup
run: mvn --version

- name: Compile project
run: mvn clean compile -B

- name: Run unit tests
run: mvn test -B

- name: Generate test report
if: success() || failure()
uses: dorny/test-reporter@v1.9.1
with:
name: Test Results (Java ${{ matrix.java-version }})
path: target/surefire-reports/*.xml
reporter: java-junit
fail-on-error: false

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-java-${{ matrix.java-version }}
path: |
target/surefire-reports/
target/classes/
retention-days: 7

build-plugin:
name: Build Minecraft Plugin
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Build plugin JAR
run: mvn clean package -B -DskipTests

- name: Verify JAR created
run: |
ls -la target/
echo "Plugin JAR details:"
ls -la target/*.jar || echo "No JAR files found"

- name: Upload plugin artifact
uses: actions/upload-artifact@v4
with:
name: xraymonitor-plugin
path: target/XRayMonitor-*.jar
retention-days: 30

validate-code:
name: Code Quality Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Validate code compilation
run: mvn clean compile -B

- name: Check for common issues
run: |
echo "Checking for common code issues..."
# Check for TODO/FIXME comments
echo "TODO/FIXME comments found:"
grep -r "TODO\|FIXME" src/ || echo "None found"

# Check line endings (should all be LF after our conversion)
echo "Checking line endings..."
if find src/ -name "*.java" -exec file {} \; | grep -q "CRLF"; then
echo "❌ Found files with CRLF line endings"
exit 1
else
echo "✅ All Java files have LF line endings"
fi

# Check for proper imports
echo "Checking for unused imports..."
grep -r "^import.*\*" src/ && echo "⚠️ Found wildcard imports" || echo "✅ No wildcard imports found"
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# xRayMonitor
# XRayMonitor

[![CI](https://github.com/DmitryRendov/XRayMonitor/actions/workflows/xraymonitor-ci.yml/badge.svg)](https://github.com/DmitryRendov/XRayMonitor/actions/workflows/xraymonitor-ci.yml)
[![Java](https://img.shields.io/badge/Java-17%2B-orange.svg)](https://java.com)
[![License](https://img.shields.io/github/license/DmitryRendov/XRayMonitor)](LICENSE)

Let's fight X-Ray cheat with simple Math!
76 changes: 76 additions & 0 deletions REFACTORING_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Checkers.java Summary

## Overview
The `Checkers.java` file provides a maintainable, extensible architecture for handling different ore types in the X-Ray monitoring system.

## Key Principles

### 1. **Data-Driven Configuration**
```java
private static final Map<String, OreConfig> ORE_CONFIGS = new HashMap<String, OreConfig>() {{
put("diamond", new OreConfig("diamond", Messages.Diamond, 10.0f,
Arrays.asList("diamond_ore", "deepslate_diamond_ore")));
put("emerald", new OreConfig("emerald", Messages.Emerald, 10.0f,
Arrays.asList("emerald_ore", "deepslate_emerald_ore")));
// ... more ore configurations
}};
```

### 2. **Modular Architecture**
- **OreConfig Class**: Encapsulates ore-specific configuration
- `configKey`: Configuration key for the ore type
- `message`: Display message enum
- `levelMultiplier`: Impact on X-ray suspicion level
- `oreVariants`: List of block types (supports regular + deepslate variants)
- `useNetherStones`: Whether to use nether stones for percentage calculation

- **OreLookupResult Class**: Data container for lookup results
- `count`: Number of ores found
- `stoneCount`: Base stone count for percentage calculation

### 3. **Helper Methods for Better Code Organization**
- `getOreCounts()`: Batch retrieval of ore counts
- `processOreType()`: Single ore type processing
- `calculateAndDisplayOre()`: Ore percentage calculation and display
- `determineOreColor()`: Color determination based on rates
- `formatPercentage()`: Consistent percentage formatting

## Adding New Materials

### Easy Extension Process:
1. **Add Message Entry** (in Messages.java):
```java
Quartz("quartz", "§6Quartz: §a%s"),
```

2. **Add Configuration Entry** (in Checkers.java):
```java
put("quartz", new OreConfig("quartz", Messages.Quartz, 2.0f,
Arrays.asList("nether_quartz_ore"), true));
```

### Example Future Materials:
```java
// Future Minecraft materials
put("ruby", new OreConfig("ruby", Messages.Ruby, 12.0f,
Arrays.asList("ruby_ore", "deepslate_ruby_ore")));
put("amethyst", new OreConfig("amethyst", Messages.Amethyst, 5.0f,
Arrays.asList("amethyst_cluster", "budding_amethyst")));
```

## Testing Results

### Test Coverage:
- **21 Total Tests**: All passing ✅
- **ConfigTest**: 6 tests passing
- **CustomizableMessageTest**: 5 tests passing
- **MessagesTest**: 5 tests passing
- **CheckersTest**: 5 tests passing

## Future Development

### Recommended Next Steps:
1. **Configuration File Integration**: Move ore configurations to external files
2. **Dynamic Loading**: Support runtime addition of new ore types
3. **Plugin Integration**: Add hooks for other plugins to register custom ores
4. **Performance Monitoring**: Add metrics for ore processing performance
10 changes: 6 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>me.drendov.xRayMonitor</groupId>
<artifactId>XRayMonitor</artifactId>
<version>0.4.5</version>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>XRayMonitor</name>
<description>Let's fight X-Ray cheat with simple Math!</description>
Expand All @@ -27,8 +27,6 @@
<groupId>de.diddiz</groupId>
<artifactId>logblock</artifactId>
<version>1.20.0.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/LogBlock.jar</systemPath>
</dependency>
<!-- bStats -->
<dependency>
Expand Down Expand Up @@ -81,6 +79,10 @@
<id>spigot-repo-new</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>logblock-repo</id>
<url>https://www.iani.de/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>


Expand Down Expand Up @@ -115,7 +117,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.5.1</version>
<configuration>
<relocations>
<relocation>
Expand Down
Loading