Skip to content

Commit

Permalink
GH-71 Rewrite project - Add SpentTimeApi - improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
imDMK authored Dec 26, 2024
2 parents a536357 + 0e96a43 commit cf3cf83
Show file tree
Hide file tree
Showing 80 changed files with 1,440 additions and 1,292 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store
133 changes: 37 additions & 96 deletions build.gradle.kts
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
}
}
}
7 changes: 3 additions & 4 deletions gradle/wrapper/gradle-wrapper.properties
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
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
rootProject.name = "SpentTime"

include("spenttime-api")
include("spenttime-plugin")
22 changes: 22 additions & 0 deletions spenttime-api/build.gradle.kts
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/**",
)
}
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();

}
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.imdmk.spenttime.configuration.representer;
package com.github.imdmk.spenttime.configuration;

import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.nodes.Node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

public class DatabaseManager {
public class DatabaseService {

private final Logger logger;
private final File dataFolder;
Expand All @@ -18,7 +18,7 @@ public class DatabaseManager {
private HikariDataSource dataSource;
private ConnectionSource connectionSource;

public DatabaseManager(Logger logger, File dataFolder, DatabaseSettings databaseSettings) {
public DatabaseService(Logger logger, File dataFolder, DatabaseSettings databaseSettings) {
this.logger = logger;
this.dataFolder = dataFolder;
this.databaseSettings = databaseSettings;
Expand Down
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
}
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());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.imdmk.spenttime.notification.configuration;
package com.github.imdmk.spenttime.notification;

import com.github.imdmk.spenttime.notification.Notification;
import com.github.imdmk.spenttime.notification.NotificationType;
import eu.okaeri.configs.schema.GenericsPair;
import eu.okaeri.configs.serdes.BidirectionalTransformer;
import eu.okaeri.configs.serdes.SerdesContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package com.github.imdmk.spenttime.text;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import java.util.LinkedHashMap;
import java.util.Map;

public class Formatter {

private final Map<String, String> placeholders = new LinkedHashMap<>();

@CheckReturnValue
public Formatter placeholder(@Nonnull String from, String to) {
public Formatter placeholder(String from, String to) {
this.placeholders.put(from, to);
return this;
}

@CheckReturnValue
public Formatter placeholder(@Nonnull String from, Iterable<? extends CharSequence> sequences) {
public Formatter placeholder(String from, Iterable<? extends CharSequence> sequences) {
return this.placeholder(from, String.join(", ", sequences));
}

@CheckReturnValue
public <T> Formatter placeholder(@Nonnull String from, T to) {
public <T> Formatter placeholder(String from, T to) {
return this.placeholder(from, to.toString());
}

Expand Down
Loading

0 comments on commit cf3cf83

Please sign in to comment.