Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ jobs:
- name: Build all Fabric versions
run: ./gradlew :fabric:1.20.1:remapJar :fabric:1.21.1:remapJar :fabric:1.21.4:remapJar --build-cache

# Build both Sponge modules (legacy API 7 and modern API 11+)
- name: Build Sponge modules
run: ./gradlew :BanManagerSponge:shadowJar :BanManagerSponge7:shadowJar --build-cache
- name: Build Sponge module
run: ./gradlew :BanManagerSponge:shadowJar --build-cache
8 changes: 0 additions & 8 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ jobs:
:BanManagerBungee:shadowJar
:BanManagerVelocity:shadowJar
:BanManagerSponge:shadowJar
:BanManagerSponge7:shadowJar
:fabric:1.20.1:remapJar
:fabric:1.21.1:remapJar
:fabric:1.21.4:remapJar
Expand All @@ -71,7 +70,6 @@ jobs:
bungee/build/libs/BanManagerBungeeCord.jar
velocity/build/libs/BanManagerVelocity.jar
sponge/build/libs/BanManagerSponge.jar
sponge-api7/build/libs/BanManagerSponge7.jar
fabric/versions/1.20.1/build/libs/BanManagerFabric-mc1.20.1.jar
fabric/versions/1.21.1/build/libs/BanManagerFabric-mc1.21.1.jar
fabric/versions/1.21.4/build/libs/BanManagerFabric-mc1.21.4.jar
Expand Down Expand Up @@ -139,12 +137,6 @@ jobs:
mc_version: "1.21.3"
java_image: "java21"
spongeversion: "1.21.3-13.0.0"
# Sponge API 7 (Legacy - MC 1.12.2, Java 8)
- platform: Sponge7-1.12.2
task: testSponge7
compose_dir: platforms/sponge7
mc_version: "1.12.2"
java_image: "java8"
# Velocity Proxy
- platform: Velocity
task: testVelocity
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ jobs:
- name: Build all Fabric versions
run: ./gradlew :fabric:1.20.1:remapJar :fabric:1.21.1:remapJar :fabric:1.21.4:remapJar :fabric:1.21.11:remapJar --build-cache

# Build both Sponge modules (legacy API 7 and modern API 11+)
- name: Build Sponge modules
run: ./gradlew :BanManagerSponge:shadowJar :BanManagerSponge7:shadowJar --build-cache
- name: Build Sponge module
run: ./gradlew :BanManagerSponge:shadowJar --build-cache

- name: Get version from tag
id: version
Expand All @@ -73,7 +72,6 @@ jobs:
[Download BungeeCord](https://github.com/BanManagement/BanManager/releases/download/v${{ steps.version.outputs.VERSION }}/BanManagerBungeeCord.jar)
[Download Velocity](https://github.com/BanManagement/BanManager/releases/download/v${{ steps.version.outputs.VERSION }}/BanManagerVelocity.jar)
[Download Sponge](https://github.com/BanManagement/BanManager/releases/download/v${{ steps.version.outputs.VERSION }}/BanManagerSponge.jar)
[Download Sponge 7](https://github.com/BanManagement/BanManager/releases/download/v${{ steps.version.outputs.VERSION }}/BanManagerSponge7.jar)
[Download Fabric 1.20.1](https://github.com/BanManagement/BanManager/releases/download/v${{ steps.version.outputs.VERSION }}/BanManagerFabric-mc1.20.1.jar)
[Download Fabric 1.21.1](https://github.com/BanManagement/BanManager/releases/download/v${{ steps.version.outputs.VERSION }}/BanManagerFabric-mc1.21.1.jar)
[Download Fabric 1.21.4](https://github.com/BanManagement/BanManager/releases/download/v${{ steps.version.outputs.VERSION }}/BanManagerFabric-mc1.21.4.jar)
Expand All @@ -83,7 +81,6 @@ jobs:
bungee/build/libs/BanManagerBungeeCord.jar
velocity/build/libs/BanManagerVelocity.jar
sponge/build/libs/BanManagerSponge.jar
sponge-api7/build/libs/BanManagerSponge7.jar
fabric/versions/1.20.1/build/libs/BanManagerFabric-mc1.20.1.jar
fabric/versions/1.21.1/build/libs/BanManagerFabric-mc1.21.1.jar
fabric/versions/1.21.4/build/libs/BanManagerFabric-mc1.21.4.jar
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/CommonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ fun Project.applyCommonConfiguration() {
}
}

// Only set Java 1.8 for non-Fabric modules
// Set Java 17 for non-Fabric modules
// Fabric uses toolchain configuration in its build.gradle.kts
plugins.withId("java") {
if (!plugins.hasPlugin("fabric-loom")) {
the<JavaPluginExtension>().setSourceCompatibility("1.8")
the<JavaPluginExtension>().setTargetCompatibility("1.8")
the<JavaPluginExtension>().setSourceCompatibility("17")
the<JavaPluginExtension>().setTargetCompatibility("17")
}
}
}
8 changes: 4 additions & 4 deletions buildSrc/src/main/kotlin/LibsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ fun Project.applyLibrariesConfiguration() {
}

plugins.withId("java") {
the<JavaPluginExtension>().setSourceCompatibility("1.8")
the<JavaPluginExtension>().setTargetCompatibility("1.8")
the<JavaPluginExtension>().setSourceCompatibility("17")
the<JavaPluginExtension>().setTargetCompatibility("17")
}

group = "${rootProject.group}.BanManagerLibs"
Expand Down Expand Up @@ -100,7 +100,7 @@ fun Project.applyLibrariesConfiguration() {
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR))
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
}
outgoing.artifact(tasks.named("jar"))
}
Expand All @@ -115,7 +115,7 @@ fun Project.applyLibrariesConfiguration() {
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR))
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
}
outgoing.artifact(tasks.named("jar"))
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object Versions {
const val JUNIT = "4.13"
const val MOCKITO = "3.7.7"
const val ADVENTURE = "4.9.3"
const val ADVENTURE = "4.21.0"
}
3 changes: 3 additions & 0 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ dependencies {
"compileOnly"("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT") {
exclude("junit", "junit")
}
"compileOnly"("net.kyori:adventure-api:${Versions.ADVENTURE}")
"compileOnly"("net.kyori:adventure-text-serializer-gson:${Versions.ADVENTURE}")
"compileOnly"("net.kyori:adventure-text-serializer-json:${Versions.ADVENTURE}")
"compileOnly"("me.clip:placeholderapi:2.10.9")
"shadeOnly"("org.bstats:bstats-bukkit:2.2.1")
"shadeOnly"("org.slf4j:slf4j-api:1.7.36")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class BMBukkitPlugin extends JavaPlugin {
"webhooks.yml",
"exemptions.yml",
"geoip.yml",
"messages.yml",
"notifications.yml",
"reasons.yml",
"schedules.yml"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,37 @@
import me.confuser.banmanager.common.CommonPlayer;
import me.confuser.banmanager.common.CommonWorld;
import me.confuser.banmanager.common.data.PlayerData;
import me.confuser.banmanager.common.kyori.text.Component;
import me.confuser.banmanager.common.kyori.text.TextComponent;
import me.confuser.banmanager.common.kyori.text.serializer.gson.GsonComponentSerializer;
import me.confuser.banmanager.common.util.Message;
import me.confuser.banmanager.common.util.MessageRenderer;
import me.confuser.banmanager.common.util.MessageRegistry;
import me.confuser.banmanager.common.util.UUIDUtils;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;

import java.net.InetAddress;
import java.sql.SQLException;
import java.util.UUID;

public class BukkitPlayer implements CommonPlayer {
private static final boolean PAPER_ADVENTURE;

static {
boolean paper = false;
try {
Class.forName("io.papermc.paper.adventure.PaperAdventure");
paper = true;
} catch (ClassNotFoundException ignored) {
}
PAPER_ADVENTURE = paper;
}

private Player player;
private final UUID uuid;
private InetAddress address;
Expand All @@ -44,6 +61,15 @@ public void kick(String message) {
getPlayer().kickPlayer(BukkitServer.formatMessage(message));
}

@Override
public void kick(Component component) {
if (PAPER_ADVENTURE) {
PaperAdventureHelper.kick(getPlayer(), component);
} else {
kick(MessageRenderer.getInstance().toLegacy(component));
}
}

public void sendMessage(String message) {
if(message.isEmpty()) return;

Expand All @@ -54,8 +80,47 @@ public void sendMessage(String message) {
}
}

public void sendMessage(Message message) {
sendMessage(message.toString());
@Override
public void sendMessage(Component component) {
if (PAPER_ADVENTURE) {
PaperAdventureHelper.sendMessage(getPlayer(), component);
} else {
String json = MessageRenderer.getInstance().toJson(component);
getPlayer().spigot().sendMessage(ComponentSerializer.parse(json));
}
}

@Override
public void sendActionBar(Component component) {
if (PAPER_ADVENTURE) {
PaperAdventureHelper.sendActionBar(getPlayer(), component);
} else {
String json = MessageRenderer.getInstance().toJson(component);
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, ComponentSerializer.parse(json));
}
}

@Override
public void showTitle(Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
if (PAPER_ADVENTURE) {
PaperAdventureHelper.showTitle(getPlayer(), title, subtitle, fadeIn, stay, fadeOut);
} else {
MessageRenderer renderer = MessageRenderer.getInstance();
String legacyTitle = title != null ? renderer.toLegacy(title) : "";
String legacySubtitle = subtitle != null ? renderer.toLegacy(subtitle) : "";
getPlayer().sendTitle(legacyTitle, legacySubtitle, fadeIn, stay, fadeOut);
}
}

@Override
public void playSound(String sound, float volume, float pitch) {
Player p = getPlayer();
if (p == null) return;
try {
p.playSound(p.getLocation(), sound, volume, pitch);
} catch (IllegalArgumentException ignored) {
// Invalid sound key -- silently ignore
}
}

@Override
Expand Down Expand Up @@ -125,6 +190,13 @@ public boolean isOnline() {
return getPlayer() != null;
}

@Override
public String getLocale() {
Player p = getPlayer();
if (p == null) return "en";
return MessageRegistry.normaliseLocale(p.getLocale());
}

private Player getPlayer() {
if (player != null) return player;
if (isOnlineMode()) return Bukkit.getServer().getPlayer(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public void sendMessage(String message) {
sender.sendMessage(BukkitServer.formatMessage(message));
}

@Override
public void sendMessage(Message message) {
sendMessage(message.toString());
}

@Override
public boolean isConsole() {
return !(sender instanceof Player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import me.confuser.banmanager.common.api.events.CommonEvent;
import me.confuser.banmanager.common.commands.CommonSender;
import me.confuser.banmanager.common.data.*;
import me.confuser.banmanager.common.kyori.text.TextComponent;
import me.confuser.banmanager.common.util.ColorUtils;
import me.confuser.banmanager.common.util.Message;
import org.bukkit.Bukkit;
Expand All @@ -17,7 +16,6 @@
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;

import java.util.Arrays;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -82,13 +80,6 @@ public void broadcast(String message, String permission) {
}
}

@Override
public void broadcastJSON(TextComponent message, String permission) {
Arrays.stream(getOnlinePlayers()).forEach(player -> {
if (player.hasPermission(permission)) player.sendJSONMessage(message);
});
}

@Override
public void broadcast(String message, String permission, CommonSender sender) {
broadcast(message, permission);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package me.confuser.banmanager.bukkit;

import me.confuser.banmanager.common.kyori.text.Component;
import me.confuser.banmanager.common.util.MessageRenderer;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.title.Title;
import org.bukkit.entity.Player;

import java.time.Duration;

/**
* Paper-only helper that uses native Adventure API for zero-overhead Component delivery.
* Paper's Player implements Audience, so we cast to Audience for Adventure methods.
* This class must only be loaded when Paper's Adventure API is on the classpath.
*/
class PaperAdventureHelper {

private static final java.lang.reflect.Method KICK_METHOD;

static {
java.lang.reflect.Method m = null;
try {
m = Player.class.getMethod("kick", net.kyori.adventure.text.Component.class);
} catch (NoSuchMethodException e) {
// Expected on older Paper/Spigot versions without Component-based kick
}
KICK_METHOD = m;
}

private PaperAdventureHelper() {}

static void sendMessage(Player player, Component component) {
((Audience) player).sendMessage(convertToNative(component));
}

static void sendActionBar(Player player, Component component) {
((Audience) player).sendActionBar(convertToNative(component));
}

static void showTitle(Player player, Component title, Component subtitle,
int fadeIn, int stay, int fadeOut) {
net.kyori.adventure.text.Component nativeTitle = title != null
? convertToNative(title) : net.kyori.adventure.text.Component.empty();
net.kyori.adventure.text.Component nativeSubtitle = subtitle != null
? convertToNative(subtitle) : net.kyori.adventure.text.Component.empty();

Title.Times times = Title.Times.times(
Duration.ofMillis(fadeIn * 50L),
Duration.ofMillis(stay * 50L),
Duration.ofMillis(fadeOut * 50L)
);
((Audience) player).showTitle(Title.title(nativeTitle, nativeSubtitle, times));
}

static void kick(Player player, Component component) {
if (KICK_METHOD != null) {
try {
KICK_METHOD.invoke(player, convertToNative(component));
return;
} catch (IllegalAccessException e) {
java.util.logging.Logger.getLogger("BanManager").warning("Failed to invoke Paper kick method, falling back to legacy: " + e.getMessage());
} catch (java.lang.reflect.InvocationTargetException e) {
throw new IllegalStateException("Failed to kick player", e.getCause());
}
}
player.kickPlayer(MessageRenderer.getInstance().toLegacy(component));
}

private static net.kyori.adventure.text.Component convertToNative(Component component) {
String json = MessageRenderer.getInstance().toJson(component);
return GsonComponentSerializer.gson().deserialize(json);
}
}
Loading
Loading