-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-71 Rewrite project - Add SpentTimeApi - improve performance
- Loading branch information
Showing
80 changed files
with
1,440 additions
and
1,292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,4 @@ bin/ | |
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,54 @@ | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
|
||
plugins { | ||
id("java-library") | ||
|
||
id("com.github.johnrengelman.shadow") version "8.1.1" | ||
id("net.minecrell.plugin-yml.bukkit") version "0.6.0" | ||
id("com.github.johnrengelman.shadow") version "7.1.0" | ||
id("checkstyle") | ||
} | ||
|
||
group = "com.github.imdmk" | ||
version = "1.0.7" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
||
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") } | ||
maven { url = uri("https://storehouse.okaeri.eu/repository/maven-public/") } | ||
maven { url = uri("https://repo.panda-lang.org/releases") } | ||
maven { url = uri("https://repo.eternalcode.pl/releases") } | ||
maven { url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/") } | ||
} | ||
|
||
dependencies { | ||
compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") | ||
compileOnly("me.clip:placeholderapi:2.11.5") | ||
|
||
implementation("dev.triumphteam:triumph-gui:3.1.10") | ||
|
||
implementation("eu.okaeri:okaeri-configs-yaml-snakeyaml:5.0.2") | ||
implementation("eu.okaeri:okaeri-configs-serdes-commons:5.0.2") | ||
implementation("eu.okaeri:okaeri-configs-serdes-bukkit:5.0.2") | ||
|
||
implementation("net.kyori:adventure-platform-bukkit:4.3.3") | ||
implementation("net.kyori:adventure-text-minimessage:4.17.0") | ||
|
||
implementation("dev.rollczi:litecommands-bukkit:3.4.2") | ||
implementation("dev.rollczi:litecommands-annotations:3.4.0") | ||
|
||
implementation("com.zaxxer:HikariCP:5.1.0") | ||
implementation("com.j256.ormlite:ormlite-jdbc:6.1") | ||
|
||
implementation("com.eternalcode:gitcheck:1.0.0") | ||
implementation("org.bstats:bstats-bukkit:3.0.2") | ||
|
||
testImplementation(platform("org.junit:junit-bom:5.10.2")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
allprojects { | ||
apply(plugin = "java-library") | ||
apply(plugin = "com.github.johnrengelman.shadow") | ||
apply(plugin = "checkstyle") | ||
|
||
testImplementation("com.google.guava:guava-testlib:33.1.0-jre") | ||
} | ||
|
||
java { | ||
toolchain.languageVersion.set(JavaLanguageVersion.of(21)) | ||
} | ||
repositories { | ||
mavenCentral() | ||
|
||
bukkit { | ||
name = "SpentTime" | ||
version = "${project.version}" | ||
apiVersion = "1.17" | ||
main = "com.github.imdmk.spenttime.SpentTimePlugin" | ||
author = "DMK" | ||
description = "An efficient plugin for your time spent in the game with many features and configuration possibilities." | ||
website = "https://github.com/imDMK/SpentTime" | ||
} | ||
maven { url = uri("https://storehouse.okaeri.eu/repository/maven-public/") } | ||
maven { url = uri("https://repo.panda-lang.org/releases") } | ||
maven { url = uri("https://nexus.velocitypowered.com/repository/maven-public/")} | ||
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots")} | ||
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")} | ||
} | ||
|
||
checkstyle { | ||
toolVersion = "10.12.1" | ||
dependencies { | ||
implementation("com.zaxxer:HikariCP:6.2.1") | ||
implementation("com.j256.ormlite:ormlite-jdbc:6.1") | ||
|
||
configFile = file("${rootDir}/checkstyle.xml") | ||
} | ||
implementation("eu.okaeri:okaeri-configs-yaml-snakeyaml:5.0.5") | ||
implementation("eu.okaeri:okaeri-configs-serdes-commons:5.0.5") | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
testImplementation(platform("org.junit:junit-bom:5.10.2")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
|
||
tasks.withType<JavaCompile> { | ||
options.compilerArgs = listOf("-Xlint:deprecation", "-parameters") | ||
options.encoding = "UTF-8" | ||
options.release = 17 | ||
} | ||
testImplementation("com.google.guava:guava-testlib:33.1.0-jre") | ||
} | ||
|
||
tasks.withType<ShadowJar> { | ||
archiveFileName.set("${project.name} v${project.version}.jar") | ||
java { | ||
toolchain.languageVersion.set(JavaLanguageVersion.of(17)) | ||
} | ||
|
||
dependsOn("checkstyleMain") | ||
dependsOn("checkstyleTest") | ||
dependsOn("test") | ||
checkstyle { | ||
toolVersion = "10.21.0" | ||
|
||
exclude( | ||
"org/intellij/lang/annotations/**", | ||
"org/jetbrains/annotations/**", | ||
"META-INF/**", | ||
) | ||
configFile = file("${rootDir}/checkstyle.xml") | ||
} | ||
|
||
val libPrefix = "com.github.imdmk.spenttime.lib" | ||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
|
||
listOf( | ||
"dev.triumphteam", | ||
"dev.rollczi", | ||
"com.eternalcode", | ||
"com.j256", | ||
"com.zaxxer", | ||
"eu.okaeri", | ||
"net.kyori", | ||
"org.json", | ||
"org.yaml", | ||
"org.bstats", | ||
"panda", | ||
"javassist" | ||
).forEach { lib -> | ||
relocate(lib, "$libPrefix.$lib") | ||
tasks.withType<JavaCompile> { | ||
options.compilerArgs = listOf("-Xlint:deprecation", "-parameters") | ||
options.encoding = "UTF-8" | ||
options.release = 17 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#Mon Dec 23 12:09:35 CET 2024 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
rootProject.name = "SpentTime" | ||
|
||
include("spenttime-api") | ||
include("spenttime-plugin") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
|
||
group = "com.github.imdmk.spenttime.api" | ||
version = "2.0.0" | ||
|
||
dependencies { | ||
implementation("com.github.ben-manes.caffeine:caffeine:3.1.8") | ||
} | ||
|
||
tasks.withType<ShadowJar> { | ||
archiveFileName.set("${project.name} v${project.version}.jar") | ||
|
||
dependsOn("checkstyleMain") | ||
dependsOn("checkstyleTest") | ||
dependsOn("test") | ||
|
||
exclude( | ||
"org/intellij/lang/annotations/**", | ||
"org/jetbrains/annotations/**", | ||
"META-INF/**", | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
spenttime-api/src/main/java/com/github/imdmk/spenttime/SpentTimeApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.imdmk.spenttime; | ||
|
||
import com.github.imdmk.spenttime.user.UserCache; | ||
import com.github.imdmk.spenttime.user.UserService; | ||
import com.github.imdmk.spenttime.user.repository.UserRepository; | ||
|
||
public interface SpentTimeApi { | ||
|
||
UserCache getUserCache(); | ||
|
||
UserService getUserService(); | ||
|
||
UserRepository getUserRepository(); | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
spenttime-api/src/main/java/com/github/imdmk/spenttime/SpentTimeApiProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.imdmk.spenttime; | ||
|
||
public class SpentTimeApiProvider { | ||
|
||
private static SpentTimeApi SPENT_TIME_API; | ||
|
||
private SpentTimeApiProvider() { | ||
throw new UnsupportedOperationException("This class cannot be instantiated."); | ||
} | ||
|
||
public static SpentTimeApi get() { | ||
if (SPENT_TIME_API == null) { | ||
throw new IllegalStateException("The DiscordIntegrationAPI isn't registered."); | ||
} | ||
|
||
return SPENT_TIME_API; | ||
} | ||
|
||
static void register(SpentTimeApi spentTimeApi) { | ||
if (SPENT_TIME_API != null) { | ||
throw new IllegalStateException("The DiscordIntegrationAPI is already registered."); | ||
} | ||
|
||
SPENT_TIME_API = spentTimeApi; | ||
} | ||
|
||
static void unregister() { | ||
if (SPENT_TIME_API == null) { | ||
throw new IllegalStateException("The DiscordIntegrationAPI isn't registered."); | ||
} | ||
|
||
SPENT_TIME_API = null; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ration/representer/CustomRepresenter.java → ...time/configuration/CustomRepresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...m/github/imdmk/spenttime/gui/GuiType.java → ...m/github/imdmk/spenttime/gui/GuiType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.github.imdmk.spenttime.gui; | ||
|
||
public enum GuiType { | ||
STANDARD, PAGINATED, SCROLLING, DISABLED | ||
STANDARD, PAGINATED, SCROLLING, DISABLED | ||
} |
File renamed without changes.
58 changes: 58 additions & 0 deletions
58
...time-api/src/main/java/com/github/imdmk/spenttime/notification/NotificationFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.imdmk.spenttime.notification; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class NotificationFormatter { | ||
|
||
private NotificationType type; | ||
private String message; | ||
|
||
private final Map<String, String> placeholders = new LinkedHashMap<>(); | ||
|
||
public NotificationFormatter notification(Notification notification) { | ||
this.type = notification.type(); | ||
this.message = notification.message(); | ||
return this; | ||
} | ||
|
||
public NotificationFormatter type(NotificationType type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public NotificationFormatter placeholder(String from, String to) { | ||
this.placeholders.put(from, to); | ||
return this; | ||
} | ||
|
||
public NotificationFormatter placeholder(String from, Iterable<? extends CharSequence> sequences) { | ||
return this.placeholder(from, String.join(", ", sequences)); | ||
} | ||
|
||
public <T> NotificationFormatter placeholder(String from, T to) { | ||
return this.placeholder(from, to.toString()); | ||
} | ||
|
||
public Notification build() { | ||
StringBuilder replacedMessage = new StringBuilder(this.message); | ||
|
||
for (Map.Entry<String, String> placeholder : this.placeholders.entrySet()) { | ||
String key = placeholder.getKey(); | ||
String replacement = placeholder.getValue(); | ||
|
||
this.replaceAllOccurrences(replacedMessage, key, replacement); | ||
} | ||
|
||
return new Notification(this.type, replacedMessage.toString()); | ||
} | ||
|
||
private void replaceAllOccurrences(StringBuilder builder, String message, String replacement) { | ||
int index = builder.indexOf(message); | ||
|
||
while (index != -1) { | ||
builder.replace(index, index + message.length(), replacement); | ||
index = builder.indexOf(message, index + replacement.length()); | ||
} | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
...onfiguration/NotificationTransformer.java → ...notification/NotificationTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
11 changes: 3 additions & 8 deletions
11
...ithub/imdmk/spenttime/text/Formatter.java → ...ithub/imdmk/spenttime/text/Formatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.