mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
More CommandBlock API
This commit is contained in:
parent
65ec6cf342
commit
94732f8599
@ -0,0 +1,34 @@
|
||||
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.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public interface PaperCommandBlockHolder extends CommandBlockHolder {
|
||||
|
||||
BaseCommandBlock getCommandBlockHandle();
|
||||
|
||||
@Override
|
||||
default Component lastOutput() {
|
||||
return PaperAdventure.asAdventure(this.getCommandBlockHandle().getLastOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
default void lastOutput(final @Nullable Component lastOutput) {
|
||||
this.getCommandBlockHandle().setLastOutput(PaperAdventure.asVanilla(lastOutput));
|
||||
}
|
||||
|
||||
@Override
|
||||
default int getSuccessCount() {
|
||||
return this.getCommandBlockHandle().getSuccessCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
default void setSuccessCount(final int successCount) {
|
||||
this.getCommandBlockHandle().setSuccessCount(successCount);
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.CommandBlock;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
|
||||
public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity> implements CommandBlock {
|
||||
public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity> implements CommandBlock, io.papermc.paper.commands.PaperCommandBlockHolder {
|
||||
|
||||
public CraftCommandBlock(World world, CommandBlockEntity tileEntity) {
|
||||
super(world, tileEntity);
|
||||
@ -56,5 +56,10 @@ public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity>
|
||||
public void name(net.kyori.adventure.text.Component name) {
|
||||
getSnapshot().getCommandBlock().setCustomName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.world.level.BaseCommandBlock getCommandBlockHandle() {
|
||||
return getSnapshot().getCommandBlock();
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ 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) {
|
||||
@ -64,6 +64,17 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user