Skip to content

Commit

Permalink
refactor: change things a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Mar 22, 2024
1 parent ff9e2af commit 24350a5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
distribution: temurin

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1.1.0
uses: gradle/wrapper-validation-action@v2

- name: Build with Gradle
uses: gradle/gradle-build-action@v2.11.1
uses: gradle/gradle-build-action@v3
with:
arguments: build

Expand Down
47 changes: 25 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@ plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'org.sonarqube' version '4.4.1.3373'
id 'io.freefair.lombok' version '8.6'
id 'net.minecrell.plugin-yml.bukkit' version '0.6.0'
}

group = 'io.github.slimefunguguproject'
version = 'UNOFFICIAL'
description = 'Bump'
java.sourceCompatibility = JavaVersion.VERSION_16

java {
sourceCompatibility = JavaVersion.VERSION_16
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

repositories {
mavenLocal()
mavenCentral()

maven {
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
}
Expand All @@ -24,33 +36,28 @@ repositories {
}

dependencies {
implementation 'net.guizhanss:GuizhanLib-api:1.7.0'
implementation 'net.guizhanss:GuizhanLib-api:1.7.6'
implementation 'dev.sefiraat:SefiLib:0.2.6'
implementation 'org.bstats:bstats-bukkit:3.0.2'

compileOnly 'org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT'
compileOnly 'io.github.Slimefun:Slimefun4:RC-32'
compileOnly 'org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT'
compileOnly 'io.github.Slimefun:Slimefun4:RC-37'
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
compileOnly 'org.projectlombok:lombok:1.18.30'

annotationProcessor 'org.projectlombok:lombok:1.18.30'
}

shadowJar {
// relocate 'net.guizhanss.guizhanlib', 'io.github.slimefunguguproject.bump.guizhanlib'
relocate 'dev.sefiraat.sefilib', 'io.github.slimefunguguproject.bump.sefilib'
relocate 'org.bstats', 'io.github.slimefunguguproject.bump.bstats'
relocate 'net.guizhanss.guizhanlib', 'io.github.slimefunguguproject.bump.libs.guizhanlib'
relocate 'dev.sefiraat.sefilib', 'io.github.slimefunguguproject.bump.libs.sefilib'
relocate 'org.bstats', 'io.github.slimefunguguproject.bump.libs.bstats'
minimize()
}

processResources {
expand project.properties
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
bukkit {
main = 'io.github.slimefunguguproject.bump.implementation.Bump'
apiVersion = '1.16'
authors = ['bxx2004', 'LobbyTech-MC', 'zimzaza4', 'haiman233', 'ybw0014']
depend = ['Slimefun']
softDepend = ['GuizhanLibPlugin']
}

sonar {
Expand All @@ -60,7 +67,3 @@ sonar {
property "sonar.host.url", "https://sonarcloud.io"
}
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public int hashCode() {
}

/**
* Get the percentile of result value within range.
* Get the percentage of result value within range.
* <p>
* Return range from 0 to 100.
*
* @param value The result value.
*
* @return The percentile of the result value.
* @return The percentage of the result value.
*/
public double getPercentile(double value) {
public double getPercentage(double value) {
if (value <= min) {
return 0;
} else if (value >= max) {
Expand All @@ -104,13 +104,13 @@ public double getPercentile(double value) {
}

/**
* Get the weighted percentile of result value.
* Get the weighted percentage of result value.
*
* @param value The result value.
*
* @return The weighted percentile of the result value.
* @return The weighted percentage of the result value.
*/
public double getWeightedPercentile(double value) {
return getPercentile(value) * weight / 100.D;
public double getWeightedPercentage(double value) {
return getPercentage(value) * weight / 100.D;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import lombok.Getter;

/**
* An {@link AppraiseResult} contains results of attributes and
* An {@link AppraiseResult} contains results of attributes and the weights.
*
* @author ybw0014
*/
Expand All @@ -40,20 +40,17 @@ public final class AppraiseResult {
/**
* This is a reference to the {@link AppraiseType} that generates this {@link AppraiseResult}.
*/
@Getter
private final AppraiseType appraiseType;

/**
* This unmodifiable map stores the {@link AppraiseAttribute} and result.
*/
@Getter
private final Map<AppraiseAttribute, Double> result;

/**
* This represents the calculated overall percentile.
* This represents the calculated overall percentage.
*/
@Getter
private final double totalPercentile;
private final double totalPercentage;

/**
* Construct this {@link AppraiseResult} from {@link Builder}
Expand All @@ -63,7 +60,7 @@ public final class AppraiseResult {
private AppraiseResult(@Nonnull Builder builder) {
this.appraiseType = builder.appraiseType;
this.result = Map.copyOf(builder.result);
this.totalPercentile = builder.totalPercentile;
this.totalPercentage = builder.totalPercentage;
}

/**
Expand All @@ -74,7 +71,7 @@ private AppraiseResult(@Nonnull Builder builder) {
*/
public byte getStars() {
for (Map.Entry<Byte, Byte> entry : Bump.getRegistry().getStarThresholds().entrySet()) {
if (totalPercentile >= entry.getKey()) {
if (totalPercentage >= entry.getKey()) {
return entry.getValue();
}
}
Expand Down Expand Up @@ -140,7 +137,7 @@ public void apply(@Nullable ItemStack itemStack) {
static class Builder {
private final AppraiseType appraiseType;
private final Map<AppraiseAttribute, Double> result = new HashMap<>();
private double totalPercentile = 0;
private double totalPercentage = 0;

Builder(@Nonnull AppraiseType type) {
appraiseType = type;
Expand All @@ -156,7 +153,7 @@ static class Builder {
*/
Builder add(AppraiseAttribute attribute, double result) {
this.result.put(attribute, result);
totalPercentile += attribute.getWeightedPercentile(result);
totalPercentage += attribute.getWeightedPercentage(result);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ public class AppraiseType {
private final NamespacedKey key;

/**
* This is the display name of {@link AppraiseType}.
* The display name of {@link AppraiseType}.
*/
@Getter
private String name;

/**
* This is the description of {@link AppraiseType}.
* The description of {@link AppraiseType}.
*/
@Getter
private List<String> description = new ArrayList<>();

/**
* The permission required to use this {@link AppraiseType}.
*/
@Getter
private String permission;

Expand All @@ -77,9 +80,9 @@ public class AppraiseType {
private Set<AppraiseAttribute> attributes = new LinkedHashSet<>();

/**
* This indicates the used percentile of added {@link AppraiseAttribute}.
* This indicates the used percentage of added {@link AppraiseAttribute}.
*/
private double usedPercentile;
private double usedPercentage;

/**
* This indicates whether check equipment material when appraising.
Expand Down Expand Up @@ -267,14 +270,14 @@ public final AppraiseType addAttribute(Attribute attribute, double min, double m

Preconditions.checkArgument(weight == -1 || (weight >= 0 && weight <= 100), "The weight should be -1 or between 0 and 100");
if (weight != -1) {
Preconditions.checkArgument(usedPercentile + weight <= 100, "The overall weight exceeds 100");
Preconditions.checkArgument(usedPercentage + weight <= 100, "The overall weight exceeds 100");
}

AppraiseAttribute attr = new AppraiseAttribute(attribute, min, max, weight);
attributes.add(attr);

if (weight != -1) {
usedPercentile += weight;
usedPercentage += weight;
}

return this;
Expand Down Expand Up @@ -405,17 +408,17 @@ public final AppraiseType register(@Nonnull SlimefunAddon addon) {
.filter(appraiseAttribute -> appraiseAttribute.getWeight() == -1)
.collect(Collectors.toSet());

// check percentile
if (usedPercentile < 100 && noWeightAttributes.isEmpty()) {
throw new IllegalArgumentException("Used percentile is less than 100");
// check percentage
if (usedPercentage < 100 && noWeightAttributes.isEmpty()) {
throw new IllegalArgumentException("Used percentage is less than 100");
}

// split remaining weight
int num = noWeightAttributes.size();
double percentile = (100 - usedPercentile) / num;
double percentage = (100 - usedPercentage) / num;
for (AppraiseAttribute attr : noWeightAttributes) {
attr.setWeight(percentile);
usedPercentile += percentile;
attr.setWeight(percentage);
usedPercentage += percentage;
}

// registry
Expand Down
15 changes: 0 additions & 15 deletions src/main/resources/plugin.yml

This file was deleted.

0 comments on commit 24350a5

Please sign in to comment.