Skip to content

Commit bc32d68

Browse files
authored
Merge pull request #106 from UnknownCityMC/version/0.8.0
Version/0.8.0
2 parents fb7fd54 + 635ae9e commit bc32d68

84 files changed

Lines changed: 2012 additions & 704 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ run/
116116

117117
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
118118
!gradle-wrapper.jar
119+
.gradle-home/

‎README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# AstraLib
2+
3+
AstraLib is a library for the faster development of Minecraft Paper and Velocity plugins.
4+
The name originates from a combination of the name Astralia (a Minecraft RPG server that never came to life) and the word library.
5+
Now it is used for serveral plugins for the german Minecraft CityBuild and Skyblocm server UnknownCity.de (whose development is currently paused)
6+
and some personal projects of TheZexquex.
7+
8+
## Usage
9+
![Dynamic XML Badge](https://img.shields.io/badge/dynamic/xml?url=https%3A%2F%2Frepo.unknowncity.de%2Fsnapshots%2Fde%2Funknowncity%2Fastralib%2Fastralib-common%2Fmaven-metadata.xml&query=%2Fmetadata%2Fversioning%2Flatest&label=latest)
10+
11+
Repository:
12+
```kts
13+
maven {
14+
name = "unknowncitySnapshots"
15+
url = uri("https://repo.unknowncity.de/snapshots")
16+
}
17+
```
18+
Dependency:
19+
AstraLib is available for the platforms `paper` and `velocity`
20+
```kts
21+
implementation("de.unknowncity.astralib:astralib-{{PLATFORM}}:{{VERSION}}")
22+
```

‎astralib-common/build.gradle.kts‎

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
2-
`maven-publish`
32
id("java")
3+
id("astralib-publishing")
44
}
55

66
val shadeBasePath = "${group}.${rootProject.name.lowercase()}."
@@ -27,8 +27,9 @@ dependencies {
2727
compileOnly(libs.adventure.text.minimessage)
2828
compileOnly(libs.adventure.api)
2929

30-
testImplementation(platform("org.junit:junit-bom:6.0.1"))
30+
testImplementation(platform("org.junit:junit-bom:6.1.0"))
3131
testImplementation("org.junit.jupiter:junit-jupiter")
32+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
3233

3334
testCompileOnly(libs.jackson.yaml)
3435
}
@@ -49,30 +50,3 @@ tasks {
4950
useJUnitPlatform()
5051
}
5152
}
52-
53-
publishing {
54-
repositories {
55-
maven {
56-
name = "UnknownCity"
57-
url = if(rootProject.version.toString().endsWith("-SNAPSHOT")) {
58-
uri("https://repo.unknowncity.de/snapshots")
59-
} else {
60-
uri("https://repo.unknowncity.de/releases")
61-
}
62-
63-
credentials {
64-
username = System.getenv("MVN_REPO_USERNAME")
65-
password = System.getenv("MVN_REPO_PASSWORD")
66-
}
67-
}
68-
}
69-
70-
publications {
71-
register<MavenPublication>("maven") {
72-
from(components["java"])
73-
group = rootProject.group
74-
artifactId = project.name
75-
version = rootProject.version.toString()
76-
}
77-
}
78-
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package de.unknowncity.astralib.common.command;
2+
3+
import de.unknowncity.astralib.common.message.AbstractMessenger;
4+
import de.unknowncity.astralib.common.platform.AstraLib;
5+
import de.unknowncity.astralib.common.plugin.ReloadManager;
6+
import net.kyori.adventure.audience.Audience;
7+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
8+
import org.incendo.cloud.CommandManager;
9+
import org.incendo.cloud.parser.standard.StringParser;
10+
import org.incendo.cloud.suggestion.SuggestionProvider;
11+
import org.spongepowered.configurate.NodePath;
12+
13+
import java.util.logging.Level;
14+
15+
/**
16+
* The /astralib reload [plugin] command. Reloads any plugin registered
17+
* in the {@link ReloadManager}. Platform independent, registered by the
18+
* AstraLib platform plugins on their own command manager.
19+
*/
20+
public final class ReloadCommand {
21+
22+
private ReloadCommand() {
23+
24+
}
25+
26+
public static <C extends Audience> void register(CommandManager<C> commandManager, AbstractMessenger<?> messenger) {
27+
commandManager.command(commandManager.commandBuilder("astralib")
28+
.literal("reload")
29+
.permission("astralib.command.reload")
30+
.required("plugin", StringParser.stringParser(),
31+
SuggestionProvider.blockingStrings((context, input) -> ReloadManager.registeredPluginNames()))
32+
.handler(context -> {
33+
String pluginName = context.get("plugin");
34+
var sender = context.sender();
35+
var pluginPlaceholder = Placeholder.parsed("plugin", pluginName);
36+
37+
if (!ReloadManager.isRegistered(pluginName)) {
38+
messenger.sendMessage(sender, NodePath.path("command", "reload", "unknown-plugin"), pluginPlaceholder);
39+
return;
40+
}
41+
42+
try {
43+
ReloadManager.reload(pluginName);
44+
messenger.sendMessage(sender, NodePath.path("command", "reload", "success"), pluginPlaceholder);
45+
} catch (Exception e) {
46+
AstraLib.getPlatform().getLogger().log(Level.SEVERE, "Failed to reload plugin " + pluginName, e);
47+
messenger.sendMessage(sender, NodePath.path("command", "reload", "error"), pluginPlaceholder);
48+
}
49+
})
50+
);
51+
}
52+
}
Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
11
package de.unknowncity.astralib.common.command;
22

3-
import de.unknowncity.astralib.common.message.Messenger;
3+
import de.unknowncity.astralib.common.message.AbstractMessenger;
4+
import net.kyori.adventure.audience.Audience;
45
import org.incendo.cloud.CommandManager;
6+
import org.incendo.cloud.caption.Caption;
7+
import org.incendo.cloud.caption.CaptionProvider;
8+
import org.incendo.cloud.caption.StandardCaptionKeys;
9+
import org.spongepowered.configurate.NodePath;
510

6-
public class SimpleCloudCaptionRegistry{
11+
import java.util.Map;
12+
import java.util.function.Function;
713

8-
public static <C, P> void registerDefaultCaptions(CommandManager<C> commandManager, Messenger<P> messenger) {
14+
public final class SimpleCloudCaptionRegistry {
15+
private static final Map<Caption, String> ARGUMENT_PARSE_CAPTIONS = Map.of(
16+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_BOOLEAN, "boolean",
17+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_CHAR, "char",
18+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_COLOR, "color",
19+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_DURATION, "duration",
20+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_ENUM, "enum",
21+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_NUMBER, "number",
22+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_REGEX, "regex",
23+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_STRING, "string",
24+
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_UUID, "uuid"
25+
);
926

27+
private SimpleCloudCaptionRegistry() {
28+
}
29+
30+
/**
31+
* Registers messenger backed caption providers for clouds standard
32+
* argument-parse failure captions. Lang path: exception.argument-parse.[type]
33+
* @param commandManager the command manager whose caption registry gets populated
34+
* @param messenger the messenger resolving the lang strings
35+
* @param playerMapper maps a command sender to a platform player, returning null for non-players
36+
*/
37+
public static <C, P extends Audience> void registerDefaultCaptions(
38+
CommandManager<C> commandManager,
39+
AbstractMessenger<P> messenger,
40+
Function<C, P> playerMapper
41+
) {
42+
ARGUMENT_PARSE_CAPTIONS.forEach((caption, type) -> commandManager.captionRegistry().registerProvider(
43+
CaptionProvider.forCaption(caption, sender -> messenger.getNullableString(
44+
playerMapper.apply(sender), NodePath.path("exception", "argument-parse", type)))
45+
));
1046
}
1147
}

‎astralib-common/src/main/java/de/unknowncity/astralib/common/configuration/YamlAstraConfiguration.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.IOException;
1515
import java.nio.file.Files;
1616
import java.nio.file.Path;
17+
import java.nio.file.StandardCopyOption;
1718
import java.util.Optional;
1819
import java.util.logging.Level;
1920
import java.util.logging.Logger;
@@ -46,6 +47,7 @@ public static <T extends YamlAstraConfiguration> Optional<T> loadFromFile(Class<
4647
return Optional.of(config);
4748
} catch (IOException e) {
4849
Logger.getLogger("Configuration").log(Level.SEVERE, "Error while reading configuration file", e);
50+
backupBrokenConfig(configPath);
4951
return Optional.empty();
5052
}
5153
}
@@ -69,10 +71,26 @@ public static <T extends YamlAstraConfiguration> Optional<T> loadFromFile(Class<
6971
return Optional.of(objectMapper.readValue(configPath.toFile(), configurationClass));
7072
} catch (IOException e) {
7173
Logger.getLogger("Configuration").log(Level.SEVERE, "Error while reading configuration file", e);
74+
backupBrokenConfig(configPath);
7275
return Optional.empty();
7376
}
7477
}
7578

79+
/**
80+
* Copies an unreadable configuration file to a ".broken" sibling so that user edits
81+
* are not lost when the configuration is rewritten with defaults afterwards
82+
* @param configPath the path of the unreadable configuration file
83+
*/
84+
private static void backupBrokenConfig(Path configPath) {
85+
var backupPath = configPath.resolveSibling(configPath.getFileName() + ".broken");
86+
try {
87+
Files.copy(configPath, backupPath, StandardCopyOption.REPLACE_EXISTING);
88+
Logger.getLogger("Configuration").log(Level.WARNING, "Backed up broken configuration to " + backupPath);
89+
} catch (IOException e) {
90+
Logger.getLogger("Configuration").log(Level.SEVERE, "Failed to back up broken configuration file", e);
91+
}
92+
}
93+
7694

7795
public void save() {
7896
var configPath = pluginDataPath == null ? targetFile() : pluginDataPath.resolve(targetFile());

‎astralib-common/src/main/java/de/unknowncity/astralib/common/configuration/setting/defaults/ModernRedisSetting.java‎

Lines changed: 0 additions & 40 deletions
This file was deleted.

‎astralib-common/src/main/java/de/unknowncity/astralib/common/configuration/setting/defaults/RedisSetting.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public final class RedisSetting {
1212
@JsonProperty
1313
private final String password = null;
1414
@JsonProperty
15-
private final boolean ssl = true;
15+
private final boolean ssl = false;
1616

1717
public RedisSetting() {
1818

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package de.unknowncity.astralib.common.database.dao;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.Executors;
5+
import java.util.concurrent.atomic.AtomicInteger;
6+
7+
/**
8+
* Shared pool for blocking JDBC calls so daos don't occupy the common fork-join pool
9+
*/
10+
public final class DaoExecutor {
11+
private static final AtomicInteger THREAD_COUNTER = new AtomicInteger(1);
12+
public static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(2, runnable -> {
13+
var thread = new Thread(runnable, "astralib-dao-" + THREAD_COUNTER.getAndIncrement());
14+
thread.setDaemon(true);
15+
return thread;
16+
});
17+
18+
private DaoExecutor() {
19+
20+
}
21+
}

astralib-paper-plugin/src/main/java/de/unknowncity/astralib/paper/plugin/database/dao/language/LanguageDao.java renamed to astralib-common/src/main/java/de/unknowncity/astralib/common/database/dao/language/LanguageDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package de.unknowncity.astralib.paper.plugin.database.dao.language;
1+
package de.unknowncity.astralib.common.database.dao.language;
22

33
import de.unknowncity.astralib.common.message.lang.Language;
44

0 commit comments

Comments
 (0)