-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into move-packages-and-move-config-sections
- Loading branch information
Showing
33 changed files
with
462 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }}' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...alcore-core/src/main/java/com/eternalcode/core/feature/serverlinks/ServerLinksConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
...re-core/src/main/java/com/eternalcode/core/feature/serverlinks/ServerLinksController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...nalcore-core/src/main/java/com/eternalcode/core/feature/serverlinks/ServerLinksEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...lcore-core/src/main/java/com/eternalcode/core/feature/serverlinks/ServerLinksService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
eternalcore-core/src/main/java/com/eternalcode/core/feature/setslot/SetSlotCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.