Skip to content

Commit 438c287

Browse files
committed
Merge branch 'master' into move-packages-and-move-config-sections
2 parents f9c5fe6 + f1b18b2 commit 438c287

33 files changed

+462
-59
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Checkout
1919
uses: actions/[email protected]
2020
- name: 'Set up JDK ${{ matrix.java }}'
21-
uses: actions/setup-java@v4.6.0
21+
uses: actions/setup-java@v4.7.0
2222
with:
2323
distribution: adopt
2424
java-version: '${{ matrix.java }}'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Get the latest development builds from our [GitHub Actions](https://github.com/E
5151
- :house: Home, Warp, and Spawn System
5252
- :page_facing_up: PlaceholderAPI Support
5353
- :memo: Customizable and Translatable Messages (Player language selection available)
54+
- <details><summary>Server links feature (Click to see how it works)</summary><img src="assets/server-links-showcase.gif" alt="Server Links Showcase"></details>
5455
- :gear: Advanced Configuration System for customization
5556
- :card_index: Database Integration (PostgreSQL, SQLite, MySQL, MariaDB, H2)
5657
- :rainbow: Adventure and [MiniMessage](https://docs.advntr.dev/minimessage/format.html) integration with legacy color processing (e.g., &7, &e)

assets/server-links-showcase.gif

5.2 MB
Loading

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repositories {
99
dependencies {
1010
implementation("net.kyori:blossom:1.3.1")
1111
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.5")
12-
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.0")
12+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.10")
1313
implementation("net.minecrell:plugin-yml:0.6.0")
1414
}
1515

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Versions {
66
const val ETERNALCODE_COMMONS = "1.1.5"
77
const val MULTIFICATION = "1.2.1"
88

9-
const val JETBRAINS_ANNOTATIONS = "26.0.1"
9+
const val JETBRAINS_ANNOTATIONS = "26.0.2"
1010
const val PLACEHOLDER_API = "2.11.6"
1111
const val LOMBOK = "1.18.36"
1212
const val GIT_CHECK = "1.0.0"
@@ -27,7 +27,7 @@ object Versions {
2727
const val LITE_SKULL_API = "1.3.0"
2828

2929
const val GUAVA = "33.4.0-jre"
30-
const val GSON = "2.11.0"
30+
const val GSON = "2.12.0"
3131

3232
const val EXPRESSIBLE = "1.3.6"
3333
const val PANDA_UTILITIES = "0.5.3-alpha"

buildSrc/src/main/kotlin/eternalcode-java.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ group = "com.eternalcode"
77
version = "1.5.2"
88

99
checkstyle {
10-
toolVersion = "10.21.1"
10+
toolVersion = "10.21.2"
1111

1212
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
1313
configProperties["checkstyle.suppressions.file"] = "${rootDir}/config/checkstyle/suppressions.xml"
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.eternalcode.core.feature.warp;
22

33
import org.bukkit.Location;
4+
import org.jetbrains.annotations.ApiStatus.Experimental;
45

56
import java.util.Collection;
67
import java.util.Optional;
7-
import org.jetbrains.annotations.ApiStatus.Experimental;
88

99
public interface WarpService {
1010

11-
Warp createWarp(String name, Location location);
11+
Warp createWarp(String warp, Location location);
1212

1313
void removeWarp(String warp);
1414

@@ -18,9 +18,9 @@ public interface WarpService {
1818
@Experimental
1919
Warp removePermissions(String warp, String... permissions);
2020

21-
boolean isExist(String name);
21+
boolean exists(String warp);
2222

23-
Optional<Warp> findWarp(String name);
23+
Optional<Warp> findWarp(String warp);
2424

2525
Collection<Warp> getWarps();
2626
}

eternalcore-core/src/main/java/com/eternalcode/core/EternalCore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.eternalcode.core;
22

33
import com.eternalcode.core.compatibility.CompatibilityService;
4+
import com.eternalcode.core.configuration.ReloadableConfig;
5+
import com.eternalcode.core.configuration.compatibility.ConfigurationCompatibilityV21_2;
46
import com.eternalcode.core.injector.DependencyInjector;
57
import com.eternalcode.core.injector.annotations.component.Component;
68
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
@@ -78,6 +80,8 @@ public EternalCore(Plugin plugin) {
7880
beanFactory.addCandidate(beanCandidate);
7981
}
8082

83+
beanFactory.initializeCandidates(ConfigurationCompatibilityV21_2.class); // TODO: Remove this when the cdn will be fixed
84+
beanFactory.initializeCandidates(ReloadableConfig.class); // TODO: Remove this when the cdn will be fixed
8185
beanFactory.initializeCandidates();
8286

8387
this.publisher = beanFactory.getDependency(Publisher.class);

eternalcore-core/src/main/java/com/eternalcode/core/configuration/compatibility/ConfigurationCompatibilityV21_2.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import com.eternalcode.core.injector.annotations.component.Controller;
88
import com.eternalcode.core.publish.Subscribe;
99

10+
// TODO: Make this package private
1011
@Controller
1112
@Compatibility(from = @Version(minor = 21, patch = 2))
12-
class ConfigurationCompatibilityV21_2 {
13+
public class ConfigurationCompatibilityV21_2 {
1314

1415
@Subscribe
1516
void onConfigSettingsSetup(ConfigurationSettingsSetupEvent event) {

eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import com.eternalcode.core.feature.helpop.HelpOpSettings;
1010
import com.eternalcode.core.feature.jail.JailSettings;
1111
import com.eternalcode.core.feature.randomteleport.RandomTeleportSettingsImpl;
12+
import com.eternalcode.core.feature.serverlinks.ServerLinksConfig;
1213
import com.eternalcode.core.feature.spawn.SpawnSettings;
14+
import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings;
1315
import com.eternalcode.core.injector.annotations.Bean;
1416
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
15-
import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings;
1617
import net.dzikoysk.cdn.entity.Contextual;
1718
import net.dzikoysk.cdn.entity.Description;
1819
import net.dzikoysk.cdn.entity.Exclude;
@@ -345,7 +346,7 @@ public static class Warp {
345346

346347
@Description({"# Options below allow you to customize item representing warp added to GUI, ",
347348
"# you can change almost everything inside langueage files, after the warp has been added to the inventory."})
348-
public String itemNamePrefix = "&8» &6Warp: &f";
349+
public String itemNamePrefix = "&8» &6Warp: &f";
349350

350351
public String itemLore = "&7Click to teleport!";
351352

@@ -440,6 +441,10 @@ public float getCatboyWalkSpeed() {
440441
}
441442
}
442443

444+
@Bean
445+
@Description({ " ", "# ServerLinks Section" })
446+
ServerLinksConfig serverLinks = new ServerLinksConfig();
447+
443448
@Override
444449
public Resource resource(File folder) {
445450
return Source.of(folder, "config.yml");

eternalcore-core/src/main/java/com/eternalcode/core/feature/gamemode/GameModeCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.bukkit.entity.Player;
1919

2020
@Command(name = "gamemode", aliases = "gm")
21-
@Permission("eternalcore.gamemode")
2221
class GameModeCommand {
2322

2423
private final CommandConfiguration commandConfiguration;
@@ -42,6 +41,7 @@ void executeAlias(@Context Invocation<CommandSender> invocation, @Context Player
4241
}
4342

4443
@Execute
44+
@Permission("eternalcore.gamemode")
4545
@DescriptionDocs(description = "Sets your gamemode", arguments = "<gamemode>")
4646
void execute(@Context Player sender, @Arg GameMode gameMode) {
4747
sender.setGameMode(gameMode);
@@ -54,6 +54,7 @@ void execute(@Context Player sender, @Arg GameMode gameMode) {
5454
}
5555

5656
@Execute
57+
@Permission("eternalcore.gamemode.other")
5758
@DescriptionDocs(description = "Sets gamemode of another player", arguments = "<gamemode> <player>")
5859
void execute(@Context Viewer sender, @Arg GameMode gameMode, @Arg Player player) {
5960
player.setGameMode(gameMode);

eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class RandomTeleportSettingsImpl implements RandomTeleportSettings, Migra
3131
"# If you want to use a static radius, set the type to STATIC_RADIUS and set the radius here.",
3232
"# If you using WORLD_BORDER_RADIUS, this value will be ignored."
3333
})
34-
public RandomTeleportRadiusConfig radius = new RandomTeleportRadiusConfig(5000, 5000, 5000, 5000);
34+
public RandomTeleportRadiusConfig radius = new RandomTeleportRadiusConfig(-5000, 5000, -5000, 5000);
3535
@Deprecated public Integer randomTeleportRadius = null;
3636

3737
@Description("# Teleport to a specific world, if left empty it will teleport to the player's current world")

eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportTaskService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ class RandomTeleportTaskService {
4242

4343
CompletableFuture<RandomTeleportResult> createTeleport(Player player) {
4444
World world = resolveWorld(player, randomTeleportSettings);
45-
RandomTeleportRadius radius = this.randomTeleportSettings.radius();
4645
return this.randomTeleportSafeLocationService.getSafeRandomLocation(
4746
world,
48-
radius,
47+
this.randomTeleportSettings.radius(),
4948
this.randomTeleportSettings.teleportAttempts()
5049
).thenCompose(location -> this.createTeleport(player, location));
5150
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.eternalcode.core.feature.serverlinks;
2+
3+
import java.util.List;
4+
import net.dzikoysk.cdn.entity.Contextual;
5+
import net.dzikoysk.cdn.entity.Description;
6+
7+
@Contextual
8+
public class ServerLinksConfig {
9+
10+
@Description({
11+
"# Configuration of server links displayed in the ESC/pause menu",
12+
"# Links will be visible in the game's pause menu under server information",
13+
"# Note: This feature requires Minecraft version 1.21 or newer to work properly"
14+
})
15+
public boolean sendLinksOnJoin = true;
16+
17+
public List<ServerLinksEntry> serverLinks = List.of(
18+
ServerLinksEntry.of("<rainbow>Discord", "https://discord.gg/v2rkPb4Q2r"),
19+
ServerLinksEntry.of("Website", "https://www.eternalcode.pl")
20+
);
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.eternalcode.core.feature.serverlinks;
2+
3+
import com.eternalcode.core.compatibility.Compatibility;
4+
import com.eternalcode.core.compatibility.Version;
5+
import com.eternalcode.core.injector.annotations.Inject;
6+
import com.eternalcode.core.injector.annotations.component.Controller;
7+
import org.bukkit.event.EventHandler;
8+
import org.bukkit.event.Listener;
9+
import org.bukkit.event.player.PlayerJoinEvent;
10+
11+
@Controller
12+
@Compatibility(from = @Version(minor = 21, patch = 0))
13+
public class ServerLinksController implements Listener {
14+
15+
private final ServerLinksService serverLinksService;
16+
private final ServerLinksConfig serverLinksConfig;
17+
18+
@Inject
19+
public ServerLinksController(ServerLinksService serverLinksService, ServerLinksConfig serverLinksConfig) {
20+
this.serverLinksService = serverLinksService;
21+
this.serverLinksConfig = serverLinksConfig;
22+
}
23+
24+
@EventHandler
25+
public void onJoin(PlayerJoinEvent event) {
26+
if (this.serverLinksConfig.sendLinksOnJoin) {
27+
this.serverLinksService.sendServerLinks(event.getPlayer());
28+
}
29+
}
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.eternalcode.core.feature.serverlinks;
2+
3+
import net.dzikoysk.cdn.entity.Contextual;
4+
5+
@Contextual
6+
public class ServerLinksEntry {
7+
8+
public final String name;
9+
public final String address;
10+
11+
public ServerLinksEntry(String name, String address) {
12+
this.name = name;
13+
this.address = address;
14+
}
15+
16+
public static ServerLinksEntry of(String name, String address) {
17+
return new ServerLinksEntry(name, address);
18+
}
19+
20+
public String name() {
21+
return name;
22+
}
23+
24+
public String address() {
25+
return this.address;
26+
}
27+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.eternalcode.core.feature.serverlinks;
2+
3+
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
4+
5+
import com.eternalcode.annotations.scan.feature.FeatureDocs;
6+
import com.eternalcode.core.compatibility.Compatibility;
7+
import com.eternalcode.core.compatibility.Version;
8+
import com.eternalcode.core.injector.annotations.Inject;
9+
import com.eternalcode.core.injector.annotations.component.Service;
10+
import java.net.URI;
11+
import java.net.URISyntaxException;
12+
import net.kyori.adventure.text.Component;
13+
import net.kyori.adventure.text.minimessage.MiniMessage;
14+
import org.bukkit.ServerLinks;
15+
import org.bukkit.entity.Player;
16+
import org.bukkit.plugin.Plugin;
17+
18+
@Service
19+
@Compatibility(from = @Version(minor = 21, patch = 0))
20+
@FeatureDocs(name = "ServerLinks", description = "Server links to players allow to display link's dedicated to server social media. Displayed under the pause menu (ESC).")
21+
public class ServerLinksService {
22+
23+
private final Plugin plugin;
24+
private final MiniMessage miniMessage;
25+
private final ServerLinksConfig config;
26+
27+
@Inject
28+
public ServerLinksService(Plugin plugin, MiniMessage miniMessage, ServerLinksConfig config) {
29+
this.plugin = plugin;
30+
this.miniMessage = miniMessage;
31+
this.config = config;
32+
}
33+
34+
public void sendServerLinks(Player player) {
35+
ServerLinks serverLinks = this.plugin.getServer().getServerLinks().copy();
36+
37+
for (ServerLinksEntry serverLink : this.config.serverLinks) {
38+
this.parseLinks(serverLinks, serverLink);
39+
}
40+
41+
player.sendLinks(serverLinks);
42+
}
43+
44+
private URI parseUrl(String url) {
45+
try {
46+
if (!url.startsWith("https://") && !url.startsWith("http://")) {
47+
return null;
48+
}
49+
return new URI(url);
50+
}
51+
catch (URISyntaxException exception) {
52+
return null;
53+
}
54+
}
55+
56+
private org.bukkit.ServerLinks.ServerLink parseLinks(org.bukkit.ServerLinks serverLinks, ServerLinksEntry links) {
57+
URI url = parseUrl(links.address());
58+
59+
if (url == null) {
60+
return null;
61+
}
62+
63+
// TODO: Use ServerLinks#addLinks(Component, URI) instead of ServerLinks#addLink(String, URI) when we use
64+
// PaperAPI in nearly future.
65+
Component deserialize = this.miniMessage.deserialize(links.name());
66+
return serverLinks.addLink(legacySection().serialize(deserialize), url);
67+
}
68+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.eternalcode.core.feature.setslot;
2+
3+
import com.eternalcode.annotations.scan.command.DescriptionDocs;
4+
import com.eternalcode.core.injector.annotations.Inject;
5+
import com.eternalcode.core.notice.NoticeService;
6+
import com.eternalcode.core.viewer.Viewer;
7+
import dev.rollczi.litecommands.annotations.argument.Arg;
8+
import dev.rollczi.litecommands.annotations.async.Async;
9+
import dev.rollczi.litecommands.annotations.command.Command;
10+
import dev.rollczi.litecommands.annotations.context.Context;
11+
import dev.rollczi.litecommands.annotations.execute.Execute;
12+
import dev.rollczi.litecommands.annotations.permission.Permission;
13+
14+
@Command(name = "setslot")
15+
@Permission("eternalcore.setslot")
16+
public class SetSlotCommand {
17+
18+
private final SetSlotService setSlotService;
19+
private final NoticeService noticeService;
20+
21+
@Inject
22+
public SetSlotCommand(
23+
SetSlotService setSlotService,
24+
NoticeService noticeService
25+
) {
26+
this.setSlotService = setSlotService;
27+
this.noticeService = noticeService;
28+
}
29+
30+
@Execute
31+
@Async
32+
@DescriptionDocs(description = "Set the max players on the server")
33+
public void execute(@Context Viewer viewer, @Arg int slots) {
34+
if (slots <= 0) {
35+
this.noticeService.create()
36+
.notice(notice -> notice.argument().numberBiggerThanOrEqualZero())
37+
.viewer(viewer)
38+
.send();
39+
return;
40+
}
41+
42+
this.setSlotService.setCapacity(slots);
43+
this.noticeService.create()
44+
.notice(notice -> notice.setSlot().slotSaved())
45+
.placeholder("{SLOTS}", String.valueOf(slots))
46+
.viewer(viewer)
47+
.send();
48+
}
49+
}

0 commit comments

Comments
 (0)