Skip to content

Commit 32d35cc

Browse files
Merge pull request #11 from OneLiteFeatherNET/lang-rewrite/java
Project Rewrite and bug fixing
2 parents 384246b + 05bc15d commit 32d35cc

82 files changed

Lines changed: 3393 additions & 2977 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.

build.gradle.kts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
kotlin("jvm") version "2.1.0"
2+
id("java")
33
alias(libs.plugins.pluginYaml)
44
alias(libs.plugins.shadow)
55
alias(libs.plugins.runServer)
@@ -20,7 +20,6 @@ dependencies {
2020

2121
compileOnly(libs.paper)
2222
implementation(libs.bundles.cloud)
23-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC.2")
2423
compileOnly(libs.luckperms)
2524
compileOnly(libs.protocolLib)
2625

@@ -34,16 +33,25 @@ dependencies {
3433
testRuntimeOnly(libs.junitEngine)
3534
}
3635

37-
kotlin {
38-
jvmToolchain {
36+
java {
37+
toolchain {
3938
languageVersion.set(JavaLanguageVersion.of(21))
4039
}
4140
}
4241

4342
tasks {
4443

44+
build {
45+
dependsOn(shadowJar)
46+
}
47+
48+
compileJava {
49+
options.encoding = "UTF-8"
50+
options.release.set(21)
51+
}
52+
4553
runServer {
46-
minecraftVersion("1.21.1")
54+
minecraftVersion("1.21.4")
4755
jvmArgs("-Dcom.mojang.eula.agree=true")
4856
}
4957

@@ -53,7 +61,7 @@ tasks {
5361
}
5462

5563
shadowJar {
56-
archiveFileName.set("${rootProject.name}.${archiveExtension.getOrElse("jar")}")
64+
archiveFileName.set("${rootProject.name}-${rootProject.version}.${archiveExtension.getOrElse("jar")}")
5765
}
5866
}
5967

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencyResolutionManagement {
1313
create("libs") {
1414

1515
version("hibernate", "6.6.4.Final")
16-
version("paper", "1.21.1-R0.1-SNAPSHOT")
16+
version("paper", "1.21.4-R0.1-SNAPSHOT")
1717
version("luckperms", "5.4")
1818
version("protocolLib", "5.0.0")
1919
version("jaxbRuntime", "4.0.5")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package net.onelitefeather.stardust;
2+
3+
import net.onelitefeather.stardust.util.ThreadHelper;
4+
import org.hibernate.SessionFactory;
5+
import org.hibernate.cfg.Configuration;
6+
7+
import java.util.Optional;
8+
9+
public class DatabaseConnectionService implements ThreadHelper {
10+
11+
private SessionFactory factory;
12+
13+
public DatabaseConnectionService(StardustPlugin plugin) {
14+
syncThreadForServiceLoader(() -> {
15+
factory = new Configuration()
16+
.configure()
17+
.configure(plugin.getDataFolder().toPath().resolve("hibernate.cfg.xml").toFile())
18+
.buildSessionFactory();
19+
});
20+
}
21+
22+
public Optional<SessionFactory> getSessionFactory() {
23+
return Optional.ofNullable(this.factory);
24+
}
25+
26+
public void close() {
27+
if (factory == null) return;
28+
factory.close();
29+
}
30+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package net.onelitefeather.stardust;
2+
3+
import net.kyori.adventure.key.Key;
4+
import net.kyori.adventure.text.Component;
5+
import net.kyori.adventure.translation.GlobalTranslator;
6+
import net.kyori.adventure.translation.TranslationRegistry;
7+
import net.kyori.adventure.util.UTF8ResourceBundleControl;
8+
import net.onelitefeather.stardust.api.CommandCooldownService;
9+
import net.onelitefeather.stardust.api.ItemSignService;
10+
import net.onelitefeather.stardust.configuration.PluginConfiguration;
11+
import net.onelitefeather.stardust.listener.*;
12+
import net.onelitefeather.stardust.service.*;
13+
import net.onelitefeather.stardust.translation.PluginTranslationRegistry;
14+
import org.bukkit.entity.Player;
15+
import org.bukkit.inventory.ItemStack;
16+
import org.bukkit.plugin.java.JavaPlugin;
17+
18+
import java.util.List;
19+
import java.util.Locale;
20+
import java.util.ResourceBundle;
21+
22+
public class StardustPlugin extends JavaPlugin {
23+
24+
private final List<Locale> supportedLocals = List.of(Locale.US, Locale.GERMANY);
25+
26+
private SyncFrogService syncFrogService;
27+
private DatabaseConnectionService databaseService;
28+
private UserService userService;
29+
private CommandCooldownService cooldownService;
30+
private LuckPermsService luckPermsService;
31+
private PaperCommandService commandService;
32+
33+
private ItemSignService<ItemStack, Player> itemSignService;
34+
private PacketListener packetListener;
35+
private PluginConfiguration pluginConfiguration;
36+
37+
@Override
38+
public void onEnable() {
39+
40+
saveDefaultConfig();
41+
getConfig().options().copyDefaults(true);
42+
saveConfig();
43+
44+
this.pluginConfiguration = new PluginConfiguration(getConfig());
45+
46+
var registry = TranslationRegistry.create(Key.key("stardust", "localization"));
47+
supportedLocals.forEach(locale -> {
48+
var bundle = ResourceBundle.getBundle("stardust", locale, UTF8ResourceBundleControl.get());
49+
registry.registerAll(locale, bundle, false);
50+
});
51+
52+
registry.defaultLocale(supportedLocals.getFirst());
53+
GlobalTranslator.translator().addSource(new PluginTranslationRegistry(registry));
54+
55+
this.syncFrogService = new SyncFrogService(this);
56+
57+
this.commandService = new PaperCommandService(this);
58+
this.commandService.registerCommands();
59+
60+
this.luckPermsService = new LuckPermsService(this);
61+
this.luckPermsService.init();
62+
63+
this.databaseService = new DatabaseConnectionService(this);
64+
this.cooldownService = new BukkitCommandCooldownService(this, this.databaseService);
65+
66+
this.itemSignService = new BukkitItemSignService(this);
67+
this.userService = new UserService(this);
68+
69+
if (getServer().getPluginManager().isPluginEnabled("ProtocolLib")) {
70+
packetListener = new PacketListener(this);
71+
packetListener.register();
72+
}
73+
74+
registerListeners();
75+
}
76+
77+
@Override
78+
public void onDisable() {
79+
if (this.packetListener != null) this.packetListener.unregister();
80+
this.userService.stopUserTask();
81+
this.luckPermsService.unsubscribeEvents();
82+
this.databaseService.close();
83+
}
84+
85+
public PluginConfiguration getPluginConfiguration() {
86+
return pluginConfiguration;
87+
}
88+
89+
public SyncFrogService getSyncFrogService() {
90+
return syncFrogService;
91+
}
92+
93+
public PaperCommandService getCommandService() {
94+
return commandService;
95+
}
96+
97+
public LuckPermsService getLuckPermsService() {
98+
return luckPermsService;
99+
}
100+
101+
public CommandCooldownService getCooldownService() {
102+
return cooldownService;
103+
}
104+
105+
public UserService getUserService() {
106+
return userService;
107+
}
108+
109+
public DatabaseConnectionService getDatabaseService() {
110+
return databaseService;
111+
}
112+
113+
public ItemSignService<ItemStack, Player> getItemSignService() {
114+
return itemSignService;
115+
}
116+
117+
public Component getPrefix() {
118+
return Component.translatable("plugin.prefix");
119+
}
120+
121+
private void registerListeners() {
122+
getServer().getPluginManager().registerEvents(new VanishSilentContainerFeature(this), this);
123+
getServer().getPluginManager().registerEvents(new CommandCooldownListener(this), this);
124+
getServer().getPluginManager().registerEvents(new PlayerChatListener(this), this);
125+
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(this), this);
126+
getServer().getPluginManager().registerEvents(new PlayerVanishListener(this), this);
127+
getServer().getPluginManager().registerEvents(new PlayerAdvancementListener(this), this);
128+
}
129+
130+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package net.onelitefeather.stardust.api;
2+
3+
import net.onelitefeather.stardust.command.CommandCooldown;
4+
import net.onelitefeather.stardust.command.CooldownData;
5+
6+
import java.util.List;
7+
import java.util.Optional;
8+
import java.util.UUID;
9+
import java.util.concurrent.TimeUnit;
10+
11+
public interface CommandCooldownService {
12+
13+
/**
14+
* Gives back a cooldown object
15+
*
16+
* @param commandSender be sent the command
17+
* @param command be sent
18+
* @return a cooldown object if the uuid and command inside the cache.
19+
*/
20+
CommandCooldown getCommandCooldown(UUID commandSender, String command);
21+
22+
/**
23+
* Add a command based on a sender and a time into the cache
24+
*
25+
* @param commandSender be sent the command
26+
* @param command be sent
27+
* @param time after the command can used again
28+
* @param timeUnit is the unit to specify time for day, minutes and more
29+
*/
30+
void addCommandCooldown(UUID commandSender, String command, long time, TimeUnit timeUnit);
31+
32+
/**
33+
* Removes a command from the cache
34+
*
35+
* @param command be removed
36+
* @param commandSender be used to identify
37+
*/
38+
void removeCommandCooldown(UUID commandSender, String command);
39+
40+
/**
41+
* Check if the command in the cache
42+
*
43+
* @param command to be checked
44+
* @param commandSender to be used to identify
45+
*/
46+
default boolean exists(UUID commandSender, String command) {
47+
return getCommandCooldown(commandSender, command) != null;
48+
}
49+
50+
/**
51+
* Check if the cooldown over for a command
52+
*
53+
* @param command to be checked
54+
* @param commandSender to be used to identify
55+
*/
56+
default boolean isCooldownOver(UUID commandSender, String command) {
57+
return Optional.ofNullable(getCommandCooldown(commandSender, command))
58+
.map(CommandCooldown::isOver)
59+
.orElse(true);
60+
}
61+
62+
/**
63+
* Check of the command is still in cache
64+
*
65+
* @param commandOrLabel checks if inside the cache
66+
*/
67+
default boolean hasCommandCooldown(String commandOrLabel) {
68+
return getCooldownData(commandOrLabel) != null;
69+
}
70+
71+
/**
72+
* Gets a list of all cooldown elements
73+
*
74+
* @return a list of objects
75+
*/
76+
List<CooldownData> getCooldownDataList();
77+
78+
/**
79+
* Get a cooldown data based on the command
80+
*
81+
* @return a cooldown object or null if the command not in the cache
82+
*/
83+
default CooldownData getCooldownData(String command) {
84+
return getCooldownDataList().stream()
85+
.filter(cooldownData -> cooldownData.getCommandName().equalsIgnoreCase(command))
86+
.findFirst()
87+
.orElse(null);
88+
}
89+
90+
/**
91+
* Get the milli time in the future based on a unit and a time indicator
92+
*/
93+
default long getCooldownTime(TimeUnit timeUnit, long time) {
94+
return System.currentTimeMillis() + switch (timeUnit) {
95+
case TimeUnit.DAYS -> 1000 * 60 * 60 * 24 * time;
96+
case TimeUnit.HOURS -> 1000 * 60 * 60 * time;
97+
case TimeUnit.MINUTES -> 1000 * 60 * time;
98+
case TimeUnit.SECONDS -> 1000 * time;
99+
default -> throw new IllegalArgumentException(
100+
"The TimeUnit " + timeUnit.toString().toLowerCase() + " is not allowed here"
101+
);
102+
};
103+
}
104+
}

src/main/kotlin/net/onelitefeather/stardust/api/ItemSignService.kt renamed to src/main/java/net/onelitefeather/stardust/api/ItemSignService.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
1-
package net.onelitefeather.stardust.api
1+
package net.onelitefeather.stardust.api;
22

3-
import net.kyori.adventure.text.Component
4-
import org.bukkit.entity.Player
5-
import org.bukkit.inventory.ItemStack
3+
import net.kyori.adventure.text.Component;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.inventory.ItemStack;
66

7-
/**
8-
* API Class to handle item Signing
9-
* @author TheMeinerLP
10-
*/
11-
interface ItemSignService<I : ItemStack, P : Player> {
7+
import java.util.List;
8+
9+
public interface ItemSignService<I extends ItemStack, P extends Player> {
1210

1311
/**
1412
* Sign an item with specific lore lines and more
1513
* @param baseItemStack to sign
1614
* @param lore to bet set to the item
1715
* @param player be used for replacement on the lore
1816
*/
19-
fun sign(baseItemStack: I, lore: List<Component>, player: P): I
17+
I sign(I baseItemStack, List<Component> lore, P player);
2018

2119
/**
2220
* Remove a signature from an item
2321
* @param baseItemStack to be modified
2422
* @param player be used for replacement on the lore
2523
*/
26-
fun removeSignature(baseItemStack: I, player: P): I
24+
I removeSignature(I baseItemStack, P player);
2725

2826
/**
2927
* Checks if the item be signed
3028
* @param itemStack to be checked
3129
* @param player be used
3230
*/
33-
fun hasSigned(itemStack: I, player: P): Boolean
34-
35-
}
31+
boolean hasSigned(I itemStack, P player);
32+
}

0 commit comments

Comments
 (0)