From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 23 Sep 2021 10:40:09 -0700 Subject: [PATCH] More CommmandBlock API diff --git a/src/main/java/io/papermc/paper/commands/PaperCommandBlockHolder.java b/src/main/java/io/papermc/paper/commands/PaperCommandBlockHolder.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 --- /dev/null +++ b/src/main/java/io/papermc/paper/commands/PaperCommandBlockHolder.java @@ -0,0 +0,0 @@ +package io.papermc.paper.commands; + +import io.papermc.paper.adventure.PaperAdventure; +import io.papermc.paper.command.CommandBlockHolder; +import net.kyori.adventure.text.Component; +import net.minecraft.world.level.BaseCommandBlock; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface PaperCommandBlockHolder extends CommandBlockHolder { + + BaseCommandBlock getCommandBlockHandle(); + + @Override + default @NotNull Component lastOutput() { + return PaperAdventure.asAdventure(getCommandBlockHandle().getLastOutput()); + } + + @Override + default void lastOutput(@Nullable Component lastOutput) { + getCommandBlockHandle().setLastOutput(PaperAdventure.asVanilla(lastOutput)); + } + + @Override + default int getSuccessCount() { + return getCommandBlockHandle().getSuccessCount(); + } + + @Override + default void setSuccessCount(int successCount) { + getCommandBlockHandle().setSuccessCount(successCount); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java @@ -0,0 +0,0 @@ import org.bukkit.World; import org.bukkit.block.CommandBlock; import org.bukkit.craftbukkit.util.CraftChatMessage; -public class CraftCommandBlock extends CraftBlockEntityState implements CommandBlock { +public class CraftCommandBlock extends CraftBlockEntityState implements CommandBlock, io.papermc.paper.commands.PaperCommandBlockHolder { public CraftCommandBlock(World world, CommandBlockEntity tileEntity) { super(world, tileEntity); @@ -0,0 +0,0 @@ public class CraftCommandBlock extends CraftBlockEntityState public void name(net.kyori.adventure.text.Component name) { getSnapshot().getCommandBlock().setName(name == null ? new net.minecraft.network.chat.TextComponent("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name)); } + + @Override + public net.minecraft.world.level.BaseCommandBlock getCommandBlockHandle() { + return getSnapshot().getCommandBlock(); + } // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java @@ -0,0 +0,0 @@ import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; -public class CraftMinecartCommand extends CraftMinecart implements CommandMinecart { +public class CraftMinecartCommand extends CraftMinecart implements CommandMinecart, io.papermc.paper.commands.PaperCommandBlockHolder { private final PermissibleBase perm = new PermissibleBase(this); public CraftMinecartCommand(CraftServer server, MinecartCommandBlock entity) { @@ -0,0 +0,0 @@ public class CraftMinecartCommand extends CraftMinecart implements CommandMineca public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() { return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getCommandBlock().getName()); } + + @Override + public net.minecraft.world.level.BaseCommandBlock getCommandBlockHandle() { + return getHandle().getCommandBlock(); + } + + @Override + public void lastOutput(net.kyori.adventure.text.Component lastOutput) { + io.papermc.paper.commands.PaperCommandBlockHolder.super.lastOutput(lastOutput); + getCommandBlockHandle().onUpdated(); + } // Paper end @Override