Skip to content

Commit

Permalink
Allow chunk list command header customization and fix update checker …
Browse files Browse the repository at this point in the history
…again
  • Loading branch information
cjburkey01 committed Jun 5, 2024
1 parent 06452bc commit 0b4462f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 14 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![ClaimChunk Logo](imgs/icon64.png)
![ClaimChunk Title](imgs/logo_carrier.png)

[![Plugin Version](https://img.shields.io/static/v1?label=Version&message=0.0.25-FIX2&color=blueviolet&style=for-the-badge)](https://github.com/cjburkey01/ClaimChunk/releases)
[![Plugin Version](https://img.shields.io/static/v1?label=Version&message=0.0.25-FIX3&color=blueviolet&style=for-the-badge)](https://github.com/cjburkey01/ClaimChunk/releases)
[![Maven Central Version](https://img.shields.io/maven-central/v/com.cjburkey.claimchunk/claimchunk?label=Maven%20Central&color=blueviolet&style=for-the-badge)](https://central.sonatype.com/artifact/com.cjburkey.claimchunk/claimchunk)
[![Minecraft Version](https://img.shields.io/static/v1?label=Spigot&message=1.20.6&color=blueviolet&style=for-the-badge)](https://www.spigotmc.org/resources/claimchunk.44458/)
![Java Version](https://img.shields.io/static/v1?label=Java&message=17&color=blueviolet&style=for-the-badge)
Expand Down Expand Up @@ -85,26 +85,26 @@ Maven:
<dependency>
<groupId>com.cjburkey.claimchunk</groupId>
<artifactId>claimchunk</artifactId>
<version>0.0.25-FIX2</version>
<version>0.0.25-FIX3</version>
</dependency>
```

Gradle (Groovy):

```groovy
implementation 'com.cjburkey.claimchunk:claimchunk:0.0.25-FIX2'
implementation 'com.cjburkey.claimchunk:claimchunk:0.0.25-FIX3'
```

Gradle (Kotlin):

```kotlin
implementation("com.cjburkey.claimchunk:claimchunk:0.0.25-FIX2")
implementation("com.cjburkey.claimchunk:claimchunk:0.0.25-FIX3")
```

Building
--------
[![Automatic Build](https://img.shields.io/github/actions/workflow/status/cjburkey01/ClaimChunk/gradle.yml?branch=main&style=for-the-badge)](https://claimchunk.cjburkey.com/server/Downloads.html#snapshot-downloads)
[![Version Info](https://img.shields.io/static/v1?label=Repository%20Version&message=0.0.25-FIX2&color=ff5555&style=for-the-badge)](https://github.com/cjburkey01/ClaimChunk/archive/main.zip)
[![Version Info](https://img.shields.io/static/v1?label=Repository%20Version&message=0.0.25-FIX3&color=ff5555&style=for-the-badge)](https://github.com/cjburkey01/ClaimChunk/archive/main.zip)

If you want to obtain a version of the plugin that isn't available yet (like a snapshot), you can do so by asking on the
Discord or building it yourself. Here's how to build it yourself:
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ plugins {
object DepData {
const val JAVA_VERSION = 17

const val LIVE_VERSION = "0.0.25-FIX2"
const val THIS_VERSION = "0.0.25-FIX2"
const val LIVE_VERSION = "0.0.25-FIX3"
const val THIS_VERSION = "0.0.25-FIX3"
const val PLUGIN_NAME = "ClaimChunk"
const val ARCHIVES_BASE_NAME = "claimchunk"
const val MAIN_CLASS = "com.cjburkey.claimchunk.ClaimChunk"
Expand Down
5 changes: 5 additions & 0 deletions changelogs/0.0.25-FIX3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ClaimChunk 0.0.25-FIX1

Fixes:
* My stupid update checker
* Allow header customization for chunk list command in messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public final class V2JsonMessages {
public String infoName = "Chunk name: &l%%NAME%%";

// List localization
public String claimsHeader = "%s&l--- [ %s ] ---";
public String claimsTitle = "Claims for %%NAME%% in %%WORLD%%";
public String claimsChunk = "%%X%%, %%Z%%";
public String claimsPagination = "Page %%PAGE%% of %%MAXPAGE%%";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean onCall(@NotNull String cmdUsed, @NotNull CommandSender executor,
messageChat(
player,
String.format(
"%s&l--- [ %s ] ---",
claimChunk.getMessages().claimsHeader,
claimChunk.getConfigHandler().getInfoColor(),
claimChunk
.getMessages()
Expand Down
41 changes: 37 additions & 4 deletions src/main/java/com/cjburkey/claimchunk/update/SemVer.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,60 @@ private static IllegalArgumentException INVALID_SEMVER(String input, Throwable c

@Override
public int compareTo(SemVer o) {
// If the other major is larger than this one, this one is older
if (o.major > major) return -1;
// If this major is larger, this one is newer
if (o.major < major) return 1;

// Same as major handling
if (o.minor > minor) return -1;
if (o.minor < minor) return 1;

// Same as major/minor handling
if (o.patch > patch) return -1;
if (o.patch < patch) return 1;

if (marker != null && o.marker != null) {
return marker.compareTo(o.marker);
}
boolean thisIsFixMarker = marker != null && marker.toUpperCase().startsWith("FIX");
boolean otherIsFixMarker = o.marker != null && o.marker.toUpperCase().startsWith("FIX");

if (marker == null && o.marker != null) {
// If the other version has a "FIX" marker but this version has no marker, the fix is newer.
if (marker == null && o.marker != null && otherIsFixMarker) {
return -1;
}
// If the other version doesn't have a marker but this one has a fix marker, this one is
// newer.
if (o.marker == null && marker != null && thisIsFixMarker) {
return 1;
}

if (marker != null) {
// If both versions have a marker, do string comparison (they should end with numbers to
// differentiate them, such as RC1, RC2, etc.)
if (o.marker != null) {
// If this version has a fix marker but the other one doesn't, this one is newer
if (thisIsFixMarker && !otherIsFixMarker) {
return 1;
}
// If this version doesn't have a fix marker but the other one does, the other
// version is newer.
if (otherIsFixMarker && !thisIsFixMarker) {
return -1;
}

return marker.compareTo(o.marker);
}

// If there is a marker on this one but not a marker on the other one, this one is OLDER
return -1;
}

// If the other version has a marker but this one does not (and it's not a FIX marker), this
// version is newer.
if (o.marker != null) {
return 1;
}

// Versions are equal
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.Arrays;
import java.util.Comparator;

// A not-too-flexible GitHub update checker designed by yours truly!
Expand Down Expand Up @@ -62,7 +61,6 @@ public static SemVer getLatestRelease(String repoOwner, String repoName)
throws URISyntaxException, InterruptedException, IOException {
GithubRelease[] tags = getRepoReleases(repoOwner, repoName);
if (tags.length == 0) return null;
if (tags.length > 1) Arrays.sort(tags, new GithubTagComparator());
return tags[tags.length - 1].semVer;
}

Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/cjburkey/claimchunk/TestSemVerMee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.cjburkey.claimchunk;

import com.cjburkey.claimchunk.update.SemVer;

import org.junit.jupiter.api.Test;

class TestSemVerMee {

@Test
void testVersions() {
SemVer v0022 = new SemVer(0, 0, 22, null);
SemVer v0024 = new SemVer(0, 0, 24, null);
SemVer v0024FIX1 = new SemVer(0, 0, 24, "FIX1");
SemVer v0024FIX2 = new SemVer(0, 0, 24, "FIX2");
SemVer v0024RC1 = new SemVer(0, 0, 24, "RC1");
SemVer v0024RC2 = new SemVer(0, 0, 24, "RC2");

assert v0024.isNewerThan(v0022);
assert v0024FIX1.isNewerThan(v0024);
assert v0024FIX1.isNewerThan(v0024RC1);
assert v0024FIX2.isNewerThan(v0024FIX1);
assert v0024RC2.isNewerThan(v0024RC1);
assert !v0024RC1.isNewerThan(v0024RC2);
}
}

0 comments on commit 0b4462f

Please sign in to comment.