Skip to content

Commit

Permalink
Make bukkit module support java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
iiAhmedYT committed Oct 11, 2024
1 parent b175f67 commit 30e2139
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 6 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ allprojects {

subprojects {
plugins.apply("java-library")

if (project.name == "paper") {
return
}

plugins.apply("com.vanniktech.maven.publish")

mavenPublishing {
Expand Down
7 changes: 3 additions & 4 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ dependencies {
api project(":brigadier")

compileOnly project(":core")
compileOnlyApi project(":paper")

compileOnly("com.mojang:brigadier:1.0.18")
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly 'org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT'

compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
//compileOnly("io.papermc.paper:paper-mojangapi:1.19.1-R0.1-SNAPSHOT")

compileOnly "${kyori(KyoriModule.API)}"
compileOnly "${kyoriPlatform(KyoriModule.BUKKIT)}"
}
Expand All @@ -42,5 +41,5 @@ processTestResources {
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
import com.mojang.brigadier.tree.LiteralCommandNode;
import dev.velix.imperat.WrappedBukkitCommand;
import dev.velix.imperat.command.Command;
import dev.velix.imperat.util.reflection.Reflections;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.registrar.RegistrarEvent;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.function.Predicate;

Expand All @@ -22,6 +27,17 @@ final class ModernPaperCommodore extends AbstractCommodore<WrappedBukkitCommand>

private final Plugin plugin;
private final LifecycleEventManager<Plugin> manager;
private final LifecycleEventType.Prioritizable commandsField = Reflections.getField(LifecycleEvents.class, LifecycleEventType.Prioritizable.class).get(null);
private final Method registrarEventRegistar;

{
try {
registrarEventRegistar = RegistrarEvent.class.getDeclaredMethod("registrar");
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

ModernPaperCommodore(Plugin plugin) throws ClassNotFoundException {
Class.forName("io.papermc.paper.command.brigadier.Commands");
this.plugin = plugin;
Expand Down Expand Up @@ -49,8 +65,13 @@ public void register(WrappedBukkitCommand command, LiteralCommandNode<?> node, P
Objects.requireNonNull(node, "node");
Objects.requireNonNull(permissionTest, "permissionTest");

manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
Commands registrar = event.registrar();
manager.registerEventHandler(commandsField, event -> {
Commands registrar = null;
try {
registrar = (Commands) registrarEventRegistar.invoke(event);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}

String desc = command == null ? null : command.description().toString();

Expand Down
24 changes: 24 additions & 0 deletions paper/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repositories {
mavenCentral()
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url = 'https://oss.sonatype.org/content/repositories/central' }
maven {
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
url = "https://libraries.minecraft.net"
}
}

dependencies {
compileOnly("com.mojang:brigadier:1.0.18")
compileOnlyApi("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
}

processTestResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.destroystokyo.paper.event.brigadier;

import com.mojang.brigadier.tree.RootCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

public class AsyncPlayerSendCommandsEvent<S extends CommandSourceStack> extends PlayerEvent {

private static final HandlerList HANDLER_LIST = new HandlerList();
private final RootCommandNode<S> node;
private final boolean hasFiredAsync;

@ApiStatus.Internal
public AsyncPlayerSendCommandsEvent(Player player, RootCommandNode<S> node, boolean hasFiredAsync) {
super(player, !Bukkit.isPrimaryThread());
this.node = node;
this.hasFiredAsync = hasFiredAsync;
}

public RootCommandNode<S> getCommandNode() {
return this.node;
}

public boolean hasFiredAsync() {
return this.hasFiredAsync;
}

public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}

public static HandlerList getHandlerList() {
return HANDLER_LIST;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.papermc.paper.command.brigadier;

import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.Nullable;

public interface CommandSourceStack {
Location getLocation();

CommandSender getSender();

@Nullable
Entity getExecutor();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.papermc.paper.command.brigadier;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.plugin.configuration.PluginMeta;
import io.papermc.paper.plugin.lifecycle.event.registrar.Registrar;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

import java.util.Collection;
import java.util.Set;

public interface Commands extends Registrar {

static LiteralArgumentBuilder<CommandSourceStack> literal(String literal) {
return LiteralArgumentBuilder.literal(literal);
}

static <T> RequiredArgumentBuilder<CommandSourceStack, T> argument(String name, ArgumentType<T> argumentType) {
return RequiredArgumentBuilder.argument(name, argumentType);
}

CommandDispatcher<CommandSourceStack> getDispatcher();

default @Unmodifiable Set<String> register(LiteralCommandNode<CommandSourceStack> node) {
return null;
}

default @Unmodifiable Set<String> register(LiteralCommandNode<CommandSourceStack> node, @Nullable String description) {
return null;
}

default @Unmodifiable Set<String> register(LiteralCommandNode<CommandSourceStack> node, Collection<String> aliases) {
return null;
}

@Unmodifiable
Set<String> register(LiteralCommandNode<CommandSourceStack> var1, @Nullable String var2, Collection<String> var3);

@Unmodifiable Set<String> register(PluginMeta var1, LiteralCommandNode<CommandSourceStack> var2, @Nullable String var3, Collection<String> var4);

}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ rootProject.name = 'Imperat'

include 'core'
include 'bukkit'
include 'paper'
include 'bungee'
include 'velocity'
include 'brigadier'
Expand Down

0 comments on commit 30e2139

Please sign in to comment.