Skip to content

Commit b67bb30

Browse files
committed
99% of the way there
1 parent ef3822e commit b67bb30

22 files changed

Lines changed: 571 additions & 69 deletions

build.gradle

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
plugins {
2+
id 'idea'
23
id 'java'
34
id 'maven-publish'
45
id 'com.diffplug.spotless' version '8.1.0'
56
id 'com.gradleup.shadow' version '9.3.0'
7+
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.3'
8+
}
9+
10+
ext {
11+
def home = System.getProperty("user.home")
12+
def os = System.getProperty("os.name").toLowerCase()
13+
14+
if (os.contains("win")) {
15+
hytaleHome = "${home}/AppData/Roaming/Hytale"
16+
} else {
17+
hytaleHome = "${System.getProperty("user.home")}/.var/app/com.hypixel.HytaleLauncher/data/Hytale"
18+
}
19+
}
20+
21+
javadoc {
22+
options.addStringOption('Xdoclint:-missing', '-quiet')
623
}
724

825
group = project.group
@@ -13,11 +30,16 @@ java {
1330

1431
repositories {
1532
mavenCentral()
33+
maven {
34+
name = "hMReleases"
35+
url = uri("https://maven.hytale-modding.info/releases")
36+
}
1637
}
1738

1839
dependencies {
1940
// Hytale server
20-
// compileOnly fileTree(dir: "$rootDir/libs", include: ["*.jar"])
41+
implementation(files("$hytaleHome/install/$patchline/package/game/latest/Server/HytaleServer.jar"))
42+
// implementation("com.buuz135:MultipleHUD:1.0.1")
2143
// Needed libs
2244
implementation 'com.h2database:h2:2.4.240'
2345
implementation 'com.zaxxer:HikariCP:7.0.2'
@@ -34,6 +56,43 @@ dependencies {
3456
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
3557
}
3658

59+
def serverRunDir = file("$projectDir/run")
60+
if (!serverRunDir.exists()) {
61+
serverRunDir.mkdirs()
62+
}
63+
64+
tasks.register('updatePluginManifest') {
65+
def manifestFile = file('src/main/resources/manifest.json')
66+
doLast {
67+
if (!manifestFile.exists()) {
68+
throw new GradleException("Could not find manifest.json at ${manifestFile.path}!")
69+
}
70+
def manifestJson = new groovy.json.JsonSlurper().parseText(manifestFile.text)
71+
manifestJson.Version = version
72+
manifestJson.IncludesAssetPack = includes_pack.toBoolean()
73+
manifestFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(manifestJson))
74+
}
75+
}
76+
77+
tasks.named('processResources') {
78+
dependsOn 'updatePluginManifest'
79+
}
80+
81+
idea.project.settings.runConfigurations {
82+
'HytaleServer'(org.jetbrains.gradle.ext.Application) {
83+
mainClass = 'com.hypixel.hytale.Main'
84+
moduleName = project.idea.module.name + '.main'
85+
programParameters = "--allow-op --assets=$hytaleHome/install/$patchline/package/game/latest/Assets.zip"
86+
if (includes_pack.toBoolean()) {
87+
programParameters += " --mods=${sourceSets.main.java.srcDirs.first().parentFile.absolutePath}"
88+
}
89+
if (load_user_mods.toBoolean()) {
90+
programParameters += " --mods=$hytaleHome/UserData/Mods"
91+
}
92+
workingDirectory = serverRunDir.absolutePath
93+
}
94+
}
95+
3796
test {
3897
useJUnitPlatform()
3998
}
@@ -107,7 +166,38 @@ if (keyPropsFile.exists()) {
107166

108167
commandLine(
109168
curlExe, '-X', 'POST',
110-
"https://api.modtale.net/api/projects/${projectId}/versions",
169+
"https://api.modtale.net/api/v1/projects/$projectId/versions",
170+
'-H', "X-MODTALE-KEY: ${apiKey}",
171+
'-F', "file=@${jarFile.absolutePath}",
172+
'-F', "versionNumber=${project.version}",
173+
'-F', "channel=${project.release_type}",
174+
'-F', "gameVersions=${project.hytale_version}",
175+
'-F', "changelog=${changelogText}"
176+
)
177+
}
178+
}
179+
tasks.register("publishToCurseForge", Exec) {
180+
group = "publishing"
181+
description = "Publishes the built jar and changelog to Modtale.net."
182+
dependsOn tasks.named("build")
183+
def curlExe = org.gradle.internal.os.OperatingSystem.current().isWindows()
184+
? "C:/Windows/System32/curl.exe"
185+
: "curl"
186+
187+
doFirst {
188+
def releaseProp = new Properties()
189+
releaseProp.load(new FileInputStream(keyPropsFile))
190+
def apiKey = releaseProp.getProperty("curseKey")
191+
def projectId = releaseProp.getProperty("curseProjectId")
192+
def jarFile = layout.buildDirectory
193+
.file("libs/${project.name}-${project.version}.jar")
194+
.get().asFile
195+
def changelogFile = rootProject.file("changelog.md")
196+
def changelogText = changelogFile.text
197+
198+
commandLine(
199+
curlExe, '-X', 'POST',
200+
"https://api.modtale.net/api/v1/projects/$projectId/versions",
111201
'-H', "X-MODTALE-KEY: ${apiKey}",
112202
'-F', "file=@${jarFile.absolutePath}",
113203
'-F', "versionNumber=${project.version}",

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ mod_url = https://modtale.net/mod/levelingcore-a4c0
2323
mod_issues = https://github.com/AzureDoom/LevelingCore/issues
2424
mod_sources = https://github.com/AzureDoom/LevelingCore
2525
version = 0.1.0
26+
includes_pack = false
27+
patchline = release
28+
load_user_mods = false

gradle/wrapper/gradle-wrapper.jar

176 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,88 @@
11
package com.azuredoom.levelingcore;
22

3+
import com.azuredoom.levelingcore.events.GainXPEventSystem;
4+
import com.hypixel.hytale.logger.HytaleLogger;
5+
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
6+
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
7+
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
8+
import com.hypixel.hytale.server.core.util.Config;
9+
310
import java.nio.file.Path;
411
import java.nio.file.Paths;
5-
import java.util.UUID;
612
import java.util.logging.*;
13+
import javax.annotation.Nonnull;
714

8-
import com.azuredoom.levelingcore.api.LevelingCoreApi;
9-
import com.azuredoom.levelingcore.config.ConfigBootstrap;
15+
import com.azuredoom.levelingcore.commands.*;
16+
import com.azuredoom.levelingcore.config.GUIConfig;
17+
import com.azuredoom.levelingcore.config.internal.ConfigBootstrap;
1018
import com.azuredoom.levelingcore.exceptions.LevelingCoreException;
1119
import com.azuredoom.levelingcore.level.LevelServiceImpl;
12-
import com.azuredoom.levelingcore.logging.LogConfig;
1320

14-
public class LevelingCore {
21+
public class LevelingCore extends JavaPlugin {
1522

16-
public static final Logger LOGGER = LogConfig.setup(LevelingCore.class);
23+
public static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
1724

18-
public static final Path configPath = Paths.get("./data/plugins/levelingcore/");
25+
public static final Path configPath = Paths.get("./mods/levelingcore_LevelingCore/data/config/");
1926

2027
private static final ConfigBootstrap.Bootstrap bootstrap = ConfigBootstrap.bootstrap(configPath);
2128

2229
private static LevelServiceImpl levelingService;
2330

24-
public LevelingCore() {}
31+
private static LevelingCore INSTANCE;
32+
33+
private final Config<GUIConfig> config;
34+
35+
/**
36+
* Constructs a new {@code LevelingCore} instance and initializes the core components of the leveling system. This
37+
* constructor takes a non-null {@link JavaPluginInit} object to set up the necessary dependencies and
38+
* configurations required for the leveling system to function.
39+
*
40+
* @param init a {@link JavaPluginInit} instance used to initialize the plugin environment and dependencies. Must
41+
* not be {@code null}.
42+
*/
43+
public LevelingCore(@Nonnull JavaPluginInit init) {
44+
super(init);
45+
INSTANCE = this;
46+
config = this.withConfig("levelingcore", GUIConfig.CODEC);
47+
}
2548

26-
// TODO: Call this from the server startup hook
27-
public static void init() {
28-
LOGGER.log(Level.INFO, "Leveling Core initialized");
49+
@Override
50+
protected void setup() {
51+
super.setup();
52+
this.config.save();
53+
LOGGER.at(Level.INFO).log("Leveling Core initializing");
2954
levelingService = bootstrap.service();
55+
getCommandRegistry().registerCommand(new AddLevelCommand());
56+
getCommandRegistry().registerCommand(new CheckLevelCommand());
57+
getCommandRegistry().registerCommand(new AddXpCommand());
58+
getCommandRegistry().registerCommand(new SetLevelCommand());
59+
getCommandRegistry().registerCommand(new RemoveLevelCommand());
60+
getCommandRegistry().registerCommand(new RemoveXpCommand());
61+
getEntityStoreRegistry().registerSystem(new GainXPEventSystem());
3062
}
3163

32-
// TODO: Call this from the server shutdown hook
33-
public static void shutdown() {
34-
LOGGER.log(Level.INFO, "Leveling Core shutting down");
64+
@Override
65+
protected void shutdown() {
66+
super.shutdown();
67+
LOGGER.at(Level.INFO).log("Leveling Core shutting down");
3568
try {
3669
LevelingCore.bootstrap.closeable().close();
3770
} catch (Exception e) {
3871
throw new LevelingCoreException("Failed to close resources", e);
3972
}
4073
}
4174

42-
static void main() {
43-
LevelingCore.init();
44-
// TODO: Remove once hooks into the player/mob kill events are found and integrable.
45-
var testId = UUID.fromString("d3804858-4bb8-4026-ae21-386255ed467d");
46-
if (LevelingCoreApi.getLevelServiceIfPresent().isPresent()) {
47-
var levelingService = LevelingCoreApi.getLevelServiceIfPresent().get();
48-
levelingService.addXp(testId, 500);
49-
// TODO: Move to chat based logging instead of System loggers
50-
LevelingCore.LOGGER.log(Level.INFO, String.format("XP: %d", levelingService.getXp(testId)));
51-
LevelingCore.LOGGER.log(
52-
Level.INFO,
53-
String.format("Level: %d", levelingService.getLevel(testId))
54-
);
55-
}
56-
LevelingCore.shutdown();
57-
}
75+
// static void main() {
76+
// TODO: Remove once hooks into the player/mob kill events are found and integrable.
77+
// var testId = UUID.fromString("d3804858-4bb8-4026-ae21-386255ed467d");
78+
// if (LevelingCoreApi.getLevelServiceIfPresent().isPresent()) {
79+
// var levelingService = LevelingCoreApi.getLevelServiceIfPresent().get();
80+
// levelingService.addXp(testId, 500);
81+
// TODO: Move to chat or display based logging instead of loggers for gaining or lossing Levels/XP.
82+
// LOGGER.at(Level.INFO).log("Added 500 XP to player");
83+
// LOGGER.at(Level.INFO).log("Player level: " + levelingService.getLevel(testId));
84+
// }
85+
// }
5886

5987
/**
6088
* Retrieves the {@link LevelServiceImpl} instance managed by the {@code LevelingCore} class. The
@@ -65,4 +93,15 @@ static void main() {
6593
public static LevelServiceImpl getLevelService() {
6694
return levelingService;
6795
}
96+
97+
/**
98+
* Provides access to the singleton instance of the {@code LevelingCore} class. This instance serves as the primary
99+
* entry point for managing the core functionality of the leveling system, including initialization, configuration,
100+
* and lifecycle management.
101+
*
102+
* @return the singleton instance of {@code LevelingCore}.
103+
*/
104+
public static LevelingCore getInstance() {
105+
return INSTANCE;
106+
}
68107
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.azuredoom.levelingcore.commands;
2+
3+
import com.hypixel.hytale.server.core.Message;
4+
import com.hypixel.hytale.server.core.command.system.CommandContext;
5+
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
6+
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
7+
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;
8+
import com.hypixel.hytale.server.core.universe.PlayerRef;
9+
10+
import javax.annotation.Nonnull;
11+
12+
import com.azuredoom.levelingcore.api.LevelingCoreApi;
13+
14+
public class AddLevelCommand extends CommandBase {
15+
16+
@Nonnull
17+
private final RequiredArg<PlayerRef> playerArg;
18+
19+
@Nonnull
20+
private final RequiredArg<Integer> levelArg;
21+
22+
public AddLevelCommand() {
23+
super("addlevel", "Add level to player");
24+
this.playerArg = this.withRequiredArg(
25+
"player",
26+
"server.commands.levelingcore.addlevel.desc",
27+
ArgTypes.PLAYER_REF
28+
);
29+
this.levelArg = this.withRequiredArg("level", "server.commands.levelingcore.addlevel.desc", ArgTypes.INTEGER);
30+
}
31+
32+
@Override
33+
protected void executeSync(@Nonnull CommandContext commandContext) {
34+
if (LevelingCoreApi.getLevelServiceIfPresent().isEmpty()) {
35+
commandContext.sendMessage(Message.raw("Leveling Core is not initialized"));
36+
return;
37+
}
38+
var playerRef = this.playerArg.get(commandContext);
39+
var levelRef = this.levelArg.get(commandContext);
40+
var playerUUID = playerRef.getUuid();
41+
LevelingCoreApi.getLevelServiceIfPresent().get().addLevel(playerUUID, levelRef);
42+
commandContext.sendMessage(Message.raw("Added " + levelRef + " levels to " + playerRef.getUsername()));
43+
commandContext.sendMessage(Message.raw("Player " + playerRef.getUsername() + " now has " + LevelingCoreApi.getLevelServiceIfPresent().get().getLevel(playerUUID) + " levels"));
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.azuredoom.levelingcore.commands;
2+
3+
import com.hypixel.hytale.server.core.Message;
4+
import com.hypixel.hytale.server.core.command.system.CommandContext;
5+
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
6+
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
7+
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;
8+
import com.hypixel.hytale.server.core.universe.PlayerRef;
9+
10+
import javax.annotation.Nonnull;
11+
12+
import com.azuredoom.levelingcore.api.LevelingCoreApi;
13+
14+
public class AddXpCommand extends CommandBase {
15+
16+
@Nonnull
17+
private final RequiredArg<PlayerRef> playerArg;
18+
19+
@Nonnull
20+
private final RequiredArg<Integer> xpArg;
21+
22+
public AddXpCommand() {
23+
super("addxp", "Add XP to player");
24+
this.playerArg = this.withRequiredArg(
25+
"player",
26+
"server.commands.levelingcore.addlevel.desc",
27+
ArgTypes.PLAYER_REF
28+
);
29+
this.xpArg = this.withRequiredArg("xpvalue", "server.commands.levelingcore.addlevel.desc", ArgTypes.INTEGER);
30+
}
31+
32+
@Override
33+
protected void executeSync(@Nonnull CommandContext commandContext) {
34+
if (LevelingCoreApi.getLevelServiceIfPresent().isEmpty()) {
35+
commandContext.sendMessage(Message.raw("Leveling Core is not initialized"));
36+
return;
37+
}
38+
var playerRef = this.playerArg.get(commandContext);
39+
var xpRef = this.xpArg.get(commandContext);
40+
var playerUUID = playerRef.getUuid();
41+
LevelingCoreApi.getLevelServiceIfPresent().get().addXp(playerUUID, xpRef);
42+
commandContext.sendMessage(Message.raw("Added " + xpRef + " xp to " + playerRef.getUsername()));
43+
commandContext.sendMessage(Message.raw("Player " + playerRef.getUsername() + " now has " + LevelingCoreApi.getLevelServiceIfPresent().get().getXp(playerUUID) + " xp"));
44+
}
45+
}

0 commit comments

Comments
 (0)