Skip to content

Commit

Permalink
Update to Paper plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Aug 1, 2023
1 parent 4d3c842 commit 96ac236
Show file tree
Hide file tree
Showing 28 changed files with 138 additions and 159 deletions.
6 changes: 3 additions & 3 deletions debuggery-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ tasks {
}

runServer {
minecraftVersion("1.19.4")
minecraftVersion("1.20.1")
}
}

dependencies {
implementation(project(":debuggery-common"))
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
testImplementation(project(path = ":debuggery-common", configuration = "testArchive"))
testImplementation("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
testImplementation("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.zachbr.debuggery.reflection.types.handlers.bukkit.BukkitBootstrap;
import io.zachbr.debuggery.util.EventDebugger;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -68,12 +67,7 @@ private void registerCommands() {
this.registerCommand(new EventRemoveCommand(this));

for (BukkitCommandBase c : commands.values()) {
PluginCommand bukkitCmd = this.getJavaPlugin().getCommand(c.getName());
if (bukkitCmd == null) {
throw new IllegalStateException("Unable to register " + c.getName() + ". Command not registered in plugin.yml?");
}

bukkitCmd.setExecutor(c);
this.getJavaPlugin().getServer().getCommandMap().register(c.getName(), c);
}
}

Expand Down Expand Up @@ -104,7 +98,7 @@ public EventDebugger getEventDebugger() {

@Override
String getPluginVersion() {
return javaPlugin.getDescription().getVersion();
return javaPlugin.getPluginMeta().getVersion();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BlockCommand(DebuggeryBukkit debuggery) {
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
Player player = (Player) sender;
Block block = player.getTargetBlock(null, 50);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ChunkCommand(DebuggeryBukkit debuggery) {
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
Player player = (Player) sender;

return getCommandReflection().doReflectionLookups(sender, args, player.getLocation().getChunk());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public class DebugCommand extends BukkitCommandBase {
private final Set<Audience> debugListeners;

public DebugCommand(DebuggeryBukkit debuggery) {
super("ddebug", "debuggery.debug", false, false);
super("ddebug", "debuggery.debug", false, false, debuggery.getJavaPlugin());

this.plugin = debuggery;
this.debugListeners = ((BukkitLogger) debuggery.getLogger()).getDebugListeners();
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
// no debug mode, no debug command
if (!DebuggeryBukkit.isDebugMode()) {
sender.sendMessage(text("Debuggery Debug Mode is not enabled!", NamedTextColor.RED));
Expand Down Expand Up @@ -130,13 +130,13 @@ private void sendSystemInfo(Audience sender) {
}

@Override
protected boolean helpLogic(Audience sender, String[] args) {
public boolean helpLogic(Audience sender, String[] args) {
sender.sendMessage(text("Exposes the internal systems state of the Debuggery plugin"));
return true;
}

@Override
protected List<String> tabCompleteLogic(Audience sender, String[] args) {
public List<String> tabCompleteLogic(Audience sender, String[] args) {
return switch (args.length) {
case 1 -> List.of("subscribe", "unsubscribe", "info");
case 2 -> switch (args[0].toLowerCase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public class DebuggeryCommand extends BukkitCommandBase {
private final DebuggeryBukkit debuggery;

public DebuggeryCommand(DebuggeryBukkit debuggery) {
super("debuggery", "debuggery.debuggery", false, false);
super("debuggery", "debuggery.debuggery", false, false, debuggery.getJavaPlugin());
this.debuggery = debuggery;
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
if (args.length == 0) {
sender.sendMessage(text("=== Debuggery v" + debuggery.getJavaPlugin().getDescription().getVersion() + " ===", NamedTextColor.GOLD));
sender.sendMessage(text("=== Debuggery v" + debuggery.getJavaPlugin().getPluginMeta().getVersion() + " ===", NamedTextColor.GOLD));
sender.sendMessage(text("Debuggery is designed to expose API values at runtime."));
sender.sendMessage(text("To see what commands are available and any help associated with them, use tab completion on this command."));
sender.sendMessage(text("Source code can be found here: ").append(text(debuggery.getJavaPlugin().getDescription().getWebsite(), NamedTextColor.BLUE)));
sender.sendMessage(text("Source code can be found here: ").append(text(debuggery.getJavaPlugin().getPluginMeta().getWebsite(), NamedTextColor.BLUE)));
return true;
}

Expand All @@ -64,15 +64,15 @@ protected boolean commandLogic(Audience sender, String[] args) {
}

@Override
protected boolean helpLogic(Audience sender, String[] args) {
public boolean helpLogic(Audience sender, String[] args) {
sender.sendMessage(text("Displays general information about the plugin."));
sender.sendMessage(text("Also shows more specific help for each command when entered"));
sender.sendMessage(text("Try using tab completion to see all available subtopics."));
return true;
}

@Override
protected List<String> tabCompleteLogic(Audience sender, String[] args) {
public List<String> tabCompleteLogic(Audience sender, String[] args) {
if (args.length > 1) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public EntityCommand(DebuggeryBukkit debuggery) {
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
Player player = (Player) sender;
Entity target = this.getTarget(player);
if (target == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public EventCommand(DebuggeryBukkit debuggery) {
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
if (args.length == 0) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public class EventRemoveCommand extends BukkitCommandBase {
private final DebuggeryBukkit debuggery;

public EventRemoveCommand(DebuggeryBukkit debuggery) {
super("deventremove", "debuggery.devent.remove", true, true);
super("deventremove", "debuggery.devent.remove", true, true, debuggery.getJavaPlugin());
this.debuggery = debuggery;
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
if (args.length > 0 && args[0].equals("*")) {
this.debuggery.getEventDebugger().clearAll();
sender.sendMessage(Component.text("Cleared all event debuggers!", NamedTextColor.GREEN));
Expand All @@ -58,13 +58,13 @@ protected boolean commandLogic(Audience sender, String[] args) {
}

@Override
protected boolean helpLogic(Audience sender, String[] args) {
public boolean helpLogic(Audience sender, String[] args) {
sender.sendMessage(Component.text("Clears the event debugger for the provided event."));
return true;
}

@Override
protected List<String> tabCompleteLogic(Audience sender, String[] args) {
public List<String> tabCompleteLogic(Audience sender, String[] args) {
List<String> names = new ArrayList<>();
this.debuggery.getEventDebugger().getAll().forEach((clazz) -> names.add(clazz.getName()));
names.add("*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ItemCommand(DebuggeryBukkit debuggery) {
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
Player player = (Player) sender;
ItemStack itemStack = player.getInventory().getItemInMainHand();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public PlayerCommand(DebuggeryBukkit debuggery) {
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
Player player = (Player) sender;

return getCommandReflection().doReflectionLookups(sender, args, player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public class SelectEntityCommand extends BukkitCommandBase {
private final DebuggeryBukkit debuggery;

public SelectEntityCommand(DebuggeryBukkit debuggery) {
super("dentityselect", "debuggery.entity.select", true, true);
super("dentityselect", "debuggery.entity.select", true, true, debuggery.getJavaPlugin());
this.debuggery = debuggery;
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
if (args.length > 0 && args[0].equals("unselect")) {
this.debuggery.setTargetedEntity(null);
sender.sendMessage(Component.text("Unselected entity!", NamedTextColor.GREEN));
Expand Down Expand Up @@ -68,13 +68,13 @@ public void run() {
}

@Override
protected boolean helpLogic(Audience sender, String[] args) {
public boolean helpLogic(Audience sender, String[] args) {
sender.sendMessage(Component.text("Look at an entity to select that entity for further /dentity actions."));
return true;
}

@Override
protected List<String> tabCompleteLogic(Audience sender, String[] args) {
public List<String> tabCompleteLogic(Audience sender, String[] args) {
return List.of("unselect");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ServerCommand(DebuggeryBukkit debuggery) {
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
public boolean commandLogic(Audience sender, String[] args) {
return getCommandReflection().doReflectionLookups(sender, args, Bukkit.getServer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public WorldCommand(DebuggeryBukkit debuggery) {
}

@Override
protected boolean commandLogic(Audience sender, String[] args) {
Player player = (Player) sender;
public boolean commandLogic(Audience sender, String[] args) {
final Player player = (Player) sender;

return getCommandReflection().doReflectionLookups(sender, args, player.getWorld());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,43 @@

import io.zachbr.debuggery.commands.CommandBase;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.permission.PermissionChecker;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Location;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;

/**
* Class to handle all the stupid minutia involved with commands
*/
public abstract class BukkitCommandBase extends CommandBase implements CommandExecutor, TabCompleter {
private static final Component NO_PERMS_MSG = Component.text("You do not have permission to do that!", NamedTextColor.RED) ;
public abstract class BukkitCommandBase extends Command implements CommandBase, PluginIdentifiableCommand {
private static final Component PLAYER_USE_ONLY_MSG = Component.text("This command can only be used by players!", NamedTextColor.RED);

protected BukkitCommandBase(String name, String permission, boolean requiresPlayer, boolean shouldShowInHelp) {
super(name, permission, requiresPlayer, shouldShowInHelp);
private final boolean requiresPlayer;
private final boolean shouldShowInHelp;
private final JavaPlugin plugin;

protected BukkitCommandBase(String name, String permission, boolean requiresPlayer, boolean shouldShowInHelp, JavaPlugin plugin) {
super(name);
this.setPermission(permission);
this.requiresPlayer = requiresPlayer;
this.shouldShowInHelp = shouldShowInHelp;
this.plugin = plugin;
}

/**
* This is the normal Bukkit command function, intercepted here so that we don't have to deal the same
* repetitive garbage over and over.
*/
@Override
public final boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!sender.hasPermission(this.getPermission())) {
sender.sendMessage(NO_PERMS_MSG);
return true;
}

public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (this.isRequiresPlayer() && !(sender instanceof Player)) {
sender.sendMessage(PLAYER_USE_ONLY_MSG);
return true;
Expand All @@ -66,12 +71,7 @@ public final boolean onCommand(@NotNull CommandSender sender, @NotNull Command c
* @param args arguments for the given command
* @return whether the command was successfully handled
*/
public final boolean showHelpText(Audience sender, String[] args) {
if (!sender.get(PermissionChecker.POINTER).map(checker -> checker.test(this.getPermission())).orElse(false)) {
sender.sendMessage(NO_PERMS_MSG);
return true;
}

public final boolean showHelpText(final Audience sender, final String[] args) {
sender.sendMessage(
Component.text("==== ")
.append(Component.text(this.getName(), NamedTextColor.GOLD))
Expand All @@ -80,18 +80,30 @@ public final boolean showHelpText(Audience sender, String[] args) {
return this.helpLogic(sender, args);
}

@Override
public final List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
if (!sender.hasPermission(this.getPermission())) {
sender.sendMessage(NO_PERMS_MSG);
return Collections.emptyList();
}


@Override
public final @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args, @Nullable Location location) {
if (this.isRequiresPlayer() && !(sender instanceof Player)) {
sender.sendMessage(PLAYER_USE_ONLY_MSG);
return Collections.emptyList();
}

return this.tabCompleteLogic(sender, args);
}

@Override
public boolean isRequiresPlayer() {
return this.requiresPlayer;
}

@Override
public boolean shouldShowInHelp() {
return this.shouldShowInHelp;
}

@Override
public @NotNull Plugin getPlugin() {
return this.plugin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public abstract class BukkitCommandReflection extends BukkitCommandBase {
private final CommandReflection commandReflection;

protected BukkitCommandReflection(String name, String permission, boolean requiresPlayer, boolean shouldShowInHelp, Class<?> clazz, DebuggeryBukkit plugin) {
super(name, permission, requiresPlayer, shouldShowInHelp);
super(name, permission, requiresPlayer, shouldShowInHelp, plugin.getJavaPlugin());
this.commandReflection = new CommandReflection(clazz, plugin);
}

@Override
protected boolean helpLogic(Audience sender, String[] args) {
public boolean helpLogic(Audience sender, String[] args) {
sender.sendMessage(Component.text("Uses reflection to call API methods built into Bukkit."));
sender.sendMessage(Component.text("Try using the tab completion to see all available subcommands."));
return true;
Expand Down
7 changes: 7 additions & 0 deletions debuggery-bukkit/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Debuggery
main: io.zachbr.debuggery.DebuggeryJavaPlugin
version: ${version}
api-version: '1.19'
authors: [Z750, kennytv, Owen1212055]
website: https://github.com/PaperMC/Debuggery
description: A small plugin designed to expose API values at runtime.
Loading

0 comments on commit 96ac236

Please sign in to comment.