Skip to content

Commit

Permalink
Merge branch 'master' into move-packages-and-move-config-sections
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy committed Feb 7, 2025
2 parents f9c5fe6 + f1b18b2 commit 438c287
Show file tree
Hide file tree
Showing 33 changed files with 462 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Checkout
uses: actions/[email protected]
- name: 'Set up JDK ${{ matrix.java }}'
uses: actions/setup-java@v4.6.0
uses: actions/setup-java@v4.7.0
with:
distribution: adopt
java-version: '${{ matrix.java }}'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Get the latest development builds from our [GitHub Actions](https://github.com/E
- :house: Home, Warp, and Spawn System
- :page_facing_up: PlaceholderAPI Support
- :memo: Customizable and Translatable Messages (Player language selection available)
- <details><summary>Server links feature (Click to see how it works)</summary><img src="assets/server-links-showcase.gif" alt="Server Links Showcase"></details>
- :gear: Advanced Configuration System for customization
- :card_index: Database Integration (PostgreSQL, SQLite, MySQL, MariaDB, H2)
- :rainbow: Adventure and [MiniMessage](https://docs.advntr.dev/minimessage/format.html) integration with legacy color processing (e.g., &7, &e)
Expand Down
Binary file added assets/server-links-showcase.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
dependencies {
implementation("net.kyori:blossom:1.3.1")
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.5")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.0")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.10")
implementation("net.minecrell:plugin-yml:0.6.0")
}

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Versions {
const val ETERNALCODE_COMMONS = "1.1.5"
const val MULTIFICATION = "1.2.1"

const val JETBRAINS_ANNOTATIONS = "26.0.1"
const val JETBRAINS_ANNOTATIONS = "26.0.2"
const val PLACEHOLDER_API = "2.11.6"
const val LOMBOK = "1.18.36"
const val GIT_CHECK = "1.0.0"
Expand All @@ -27,7 +27,7 @@ object Versions {
const val LITE_SKULL_API = "1.3.0"

const val GUAVA = "33.4.0-jre"
const val GSON = "2.11.0"
const val GSON = "2.12.0"

const val EXPRESSIBLE = "1.3.6"
const val PANDA_UTILITIES = "0.5.3-alpha"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/eternalcode-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ group = "com.eternalcode"
version = "1.5.2"

checkstyle {
toolVersion = "10.21.1"
toolVersion = "10.21.2"

configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
configProperties["checkstyle.suppressions.file"] = "${rootDir}/config/checkstyle/suppressions.xml"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.eternalcode.core.feature.warp;

import org.bukkit.Location;
import org.jetbrains.annotations.ApiStatus.Experimental;

import java.util.Collection;
import java.util.Optional;
import org.jetbrains.annotations.ApiStatus.Experimental;

public interface WarpService {

Warp createWarp(String name, Location location);
Warp createWarp(String warp, Location location);

void removeWarp(String warp);

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

boolean isExist(String name);
boolean exists(String warp);

Optional<Warp> findWarp(String name);
Optional<Warp> findWarp(String warp);

Collection<Warp> getWarps();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.eternalcode.core;

import com.eternalcode.core.compatibility.CompatibilityService;
import com.eternalcode.core.configuration.ReloadableConfig;
import com.eternalcode.core.configuration.compatibility.ConfigurationCompatibilityV21_2;
import com.eternalcode.core.injector.DependencyInjector;
import com.eternalcode.core.injector.annotations.component.Component;
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
Expand Down Expand Up @@ -78,6 +80,8 @@ public EternalCore(Plugin plugin) {
beanFactory.addCandidate(beanCandidate);
}

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

this.publisher = beanFactory.getDependency(Publisher.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import com.eternalcode.core.injector.annotations.component.Controller;
import com.eternalcode.core.publish.Subscribe;

// TODO: Make this package private
@Controller
@Compatibility(from = @Version(minor = 21, patch = 2))
class ConfigurationCompatibilityV21_2 {
public class ConfigurationCompatibilityV21_2 {

@Subscribe
void onConfigSettingsSetup(ConfigurationSettingsSetupEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import com.eternalcode.core.feature.helpop.HelpOpSettings;
import com.eternalcode.core.feature.jail.JailSettings;
import com.eternalcode.core.feature.randomteleport.RandomTeleportSettingsImpl;
import com.eternalcode.core.feature.serverlinks.ServerLinksConfig;
import com.eternalcode.core.feature.spawn.SpawnSettings;
import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings;
import com.eternalcode.core.injector.annotations.Bean;
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings;
import net.dzikoysk.cdn.entity.Contextual;
import net.dzikoysk.cdn.entity.Description;
import net.dzikoysk.cdn.entity.Exclude;
Expand Down Expand Up @@ -345,7 +346,7 @@ public static class Warp {

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

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

Expand Down Expand Up @@ -440,6 +441,10 @@ public float getCatboyWalkSpeed() {
}
}

@Bean
@Description({ " ", "# ServerLinks Section" })
ServerLinksConfig serverLinks = new ServerLinksConfig();

@Override
public Resource resource(File folder) {
return Source.of(folder, "config.yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.bukkit.entity.Player;

@Command(name = "gamemode", aliases = "gm")
@Permission("eternalcore.gamemode")
class GameModeCommand {

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

@Execute
@Permission("eternalcore.gamemode")
@DescriptionDocs(description = "Sets your gamemode", arguments = "<gamemode>")
void execute(@Context Player sender, @Arg GameMode gameMode) {
sender.setGameMode(gameMode);
Expand All @@ -54,6 +54,7 @@ void execute(@Context Player sender, @Arg GameMode gameMode) {
}

@Execute
@Permission("eternalcore.gamemode.other")
@DescriptionDocs(description = "Sets gamemode of another player", arguments = "<gamemode> <player>")
void execute(@Context Viewer sender, @Arg GameMode gameMode, @Arg Player player) {
player.setGameMode(gameMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RandomTeleportSettingsImpl implements RandomTeleportSettings, Migra
"# If you want to use a static radius, set the type to STATIC_RADIUS and set the radius here.",
"# If you using WORLD_BORDER_RADIUS, this value will be ignored."
})
public RandomTeleportRadiusConfig radius = new RandomTeleportRadiusConfig(5000, 5000, 5000, 5000);
public RandomTeleportRadiusConfig radius = new RandomTeleportRadiusConfig(-5000, 5000, -5000, 5000);
@Deprecated public Integer randomTeleportRadius = null;

@Description("# Teleport to a specific world, if left empty it will teleport to the player's current world")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ class RandomTeleportTaskService {

CompletableFuture<RandomTeleportResult> createTeleport(Player player) {
World world = resolveWorld(player, randomTeleportSettings);
RandomTeleportRadius radius = this.randomTeleportSettings.radius();
return this.randomTeleportSafeLocationService.getSafeRandomLocation(
world,
radius,
this.randomTeleportSettings.radius(),
this.randomTeleportSettings.teleportAttempts()
).thenCompose(location -> this.createTeleport(player, location));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.eternalcode.core.feature.serverlinks;

import java.util.List;
import net.dzikoysk.cdn.entity.Contextual;
import net.dzikoysk.cdn.entity.Description;

@Contextual
public class ServerLinksConfig {

@Description({
"# Configuration of server links displayed in the ESC/pause menu",
"# Links will be visible in the game's pause menu under server information",
"# Note: This feature requires Minecraft version 1.21 or newer to work properly"
})
public boolean sendLinksOnJoin = true;

public List<ServerLinksEntry> serverLinks = List.of(
ServerLinksEntry.of("<rainbow>Discord", "https://discord.gg/v2rkPb4Q2r"),
ServerLinksEntry.of("Website", "https://www.eternalcode.pl")
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.eternalcode.core.feature.serverlinks;

import com.eternalcode.core.compatibility.Compatibility;
import com.eternalcode.core.compatibility.Version;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Controller;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

@Controller
@Compatibility(from = @Version(minor = 21, patch = 0))
public class ServerLinksController implements Listener {

private final ServerLinksService serverLinksService;
private final ServerLinksConfig serverLinksConfig;

@Inject
public ServerLinksController(ServerLinksService serverLinksService, ServerLinksConfig serverLinksConfig) {
this.serverLinksService = serverLinksService;
this.serverLinksConfig = serverLinksConfig;
}

@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (this.serverLinksConfig.sendLinksOnJoin) {
this.serverLinksService.sendServerLinks(event.getPlayer());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.eternalcode.core.feature.serverlinks;

import net.dzikoysk.cdn.entity.Contextual;

@Contextual
public class ServerLinksEntry {

public final String name;
public final String address;

public ServerLinksEntry(String name, String address) {
this.name = name;
this.address = address;
}

public static ServerLinksEntry of(String name, String address) {
return new ServerLinksEntry(name, address);
}

public String name() {
return name;
}

public String address() {
return this.address;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.eternalcode.core.feature.serverlinks;

import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;

import com.eternalcode.annotations.scan.feature.FeatureDocs;
import com.eternalcode.core.compatibility.Compatibility;
import com.eternalcode.core.compatibility.Version;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Service;
import java.net.URI;
import java.net.URISyntaxException;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.ServerLinks;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

@Service
@Compatibility(from = @Version(minor = 21, patch = 0))
@FeatureDocs(name = "ServerLinks", description = "Server links to players allow to display link's dedicated to server social media. Displayed under the pause menu (ESC).")
public class ServerLinksService {

private final Plugin plugin;
private final MiniMessage miniMessage;
private final ServerLinksConfig config;

@Inject
public ServerLinksService(Plugin plugin, MiniMessage miniMessage, ServerLinksConfig config) {
this.plugin = plugin;
this.miniMessage = miniMessage;
this.config = config;
}

public void sendServerLinks(Player player) {
ServerLinks serverLinks = this.plugin.getServer().getServerLinks().copy();

for (ServerLinksEntry serverLink : this.config.serverLinks) {
this.parseLinks(serverLinks, serverLink);
}

player.sendLinks(serverLinks);
}

private URI parseUrl(String url) {
try {
if (!url.startsWith("https://") && !url.startsWith("http://")) {
return null;
}
return new URI(url);
}
catch (URISyntaxException exception) {
return null;
}
}

private org.bukkit.ServerLinks.ServerLink parseLinks(org.bukkit.ServerLinks serverLinks, ServerLinksEntry links) {
URI url = parseUrl(links.address());

if (url == null) {
return null;
}

// TODO: Use ServerLinks#addLinks(Component, URI) instead of ServerLinks#addLink(String, URI) when we use
// PaperAPI in nearly future.
Component deserialize = this.miniMessage.deserialize(links.name());
return serverLinks.addLink(legacySection().serialize(deserialize), url);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.eternalcode.core.feature.setslot;

import com.eternalcode.annotations.scan.command.DescriptionDocs;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.viewer.Viewer;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.async.Async;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;

@Command(name = "setslot")
@Permission("eternalcore.setslot")
public class SetSlotCommand {

private final SetSlotService setSlotService;
private final NoticeService noticeService;

@Inject
public SetSlotCommand(
SetSlotService setSlotService,
NoticeService noticeService
) {
this.setSlotService = setSlotService;
this.noticeService = noticeService;
}

@Execute
@Async
@DescriptionDocs(description = "Set the max players on the server")
public void execute(@Context Viewer viewer, @Arg int slots) {
if (slots <= 0) {
this.noticeService.create()
.notice(notice -> notice.argument().numberBiggerThanOrEqualZero())
.viewer(viewer)
.send();
return;
}

this.setSlotService.setCapacity(slots);
this.noticeService.create()
.notice(notice -> notice.setSlot().slotSaved())
.placeholder("{SLOTS}", String.valueOf(slots))
.viewer(viewer)
.send();
}
}
Loading

0 comments on commit 438c287

Please sign in to comment.