mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-15 21:31:05 +00:00
implement ServerCommandSourceMixin
This commit is contained in:
@@ -362,7 +362,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, CommandManager manager) {
|
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, CommandManager manager) {
|
||||||
return in.suggests((context, builder) -> {
|
return in.suggests((context, builder) -> {
|
||||||
List<String> args = parseCommand(context.getInput());
|
List<String> args = parseCommand(context.getInput());
|
||||||
CommandSender sender = FabricAdapter.adapt(context.getSource());
|
CommandSender sender = (CommandSender) context.getSource();
|
||||||
try {
|
try {
|
||||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||||
} catch(CommandException e) {
|
} catch(CommandException e) {
|
||||||
@@ -372,7 +372,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
}).executes(context -> {
|
}).executes(context -> {
|
||||||
List<String> args = parseCommand(context.getInput());
|
List<String> args = parseCommand(context.getInput());
|
||||||
try {
|
try {
|
||||||
manager.execute(args.remove(0), FabricAdapter.adapt(context.getSource()), args);
|
manager.execute(args.remove(0), (CommandSender) context.getSource(), args);
|
||||||
} catch(CommandException e) {
|
} catch(CommandException e) {
|
||||||
context.getSource().sendError(new LiteralText(e.getMessage()));
|
context.getSource().sendError(new LiteralText(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package com.dfsek.terra.fabric.mixin.entity;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.platform.CommandSender;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import org.spongepowered.asm.mixin.Implements;
|
||||||
|
import org.spongepowered.asm.mixin.Interface;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
||||||
|
@Mixin(ServerCommandSource.class)
|
||||||
|
@Implements(@Interface(iface = CommandSender.class, prefix = "vw$"))
|
||||||
|
public abstract class ServerCommandSourceMixin {
|
||||||
|
@Shadow
|
||||||
|
public abstract void sendFeedback(Text message, boolean broadcastToOps);
|
||||||
|
|
||||||
|
public void vw$sendMessage(String message) {
|
||||||
|
sendFeedback(new LiteralText(message), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object vw$getHandle() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.dfsek.terra.fabric.world;
|
package com.dfsek.terra.fabric.world;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.vector.Vector3;
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
import com.dfsek.terra.api.platform.CommandSender;
|
|
||||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||||
import com.dfsek.terra.api.platform.block.BlockType;
|
import com.dfsek.terra.api.platform.block.BlockType;
|
||||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||||
@@ -18,17 +17,13 @@ import com.dfsek.terra.fabric.world.block.data.FabricRotatable;
|
|||||||
import com.dfsek.terra.fabric.world.block.data.FabricSlab;
|
import com.dfsek.terra.fabric.world.block.data.FabricSlab;
|
||||||
import com.dfsek.terra.fabric.world.block.data.FabricStairs;
|
import com.dfsek.terra.fabric.world.block.data.FabricStairs;
|
||||||
import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged;
|
import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged;
|
||||||
import com.dfsek.terra.fabric.world.entity.FabricCommandSender;
|
|
||||||
import com.dfsek.terra.fabric.world.entity.FabricEntityType;
|
import com.dfsek.terra.fabric.world.entity.FabricEntityType;
|
||||||
import com.dfsek.terra.fabric.world.entity.FabricPlayer;
|
|
||||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
|
||||||
import net.minecraft.state.property.Properties;
|
import net.minecraft.state.property.Properties;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
@@ -65,11 +60,6 @@ public final class FabricAdapter {
|
|||||||
return new FabricBlockData(state);
|
return new FabricBlockData(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommandSender adapt(ServerCommandSource serverCommandSource) {
|
|
||||||
if(serverCommandSource.getEntity() instanceof PlayerEntity) return new FabricPlayer((PlayerEntity) serverCommandSource.getEntity());
|
|
||||||
return new FabricCommandSender(serverCommandSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Direction adapt(BlockFace face) {
|
public static Direction adapt(BlockFace face) {
|
||||||
switch(face) {
|
switch(face) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
|
|||||||
-23
@@ -1,23 +0,0 @@
|
|||||||
package com.dfsek.terra.fabric.world.entity;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.platform.CommandSender;
|
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
|
||||||
import net.minecraft.text.LiteralText;
|
|
||||||
|
|
||||||
public class FabricCommandSender implements CommandSender {
|
|
||||||
private final ServerCommandSource delegate;
|
|
||||||
|
|
||||||
public FabricCommandSender(ServerCommandSource delegate) {
|
|
||||||
this.delegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(String message) {
|
|
||||||
delegate.sendFeedback(new LiteralText(message), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getHandle() {
|
|
||||||
return delegate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinGeneratorOptions",
|
"MixinGeneratorOptions",
|
||||||
|
"entity.ServerCommandSourceMixin",
|
||||||
"world.ChunkRegionMixin",
|
"world.ChunkRegionMixin",
|
||||||
"world.ProtoChunkMixin",
|
"world.ProtoChunkMixin",
|
||||||
"world.WorldChunkMixin"
|
"world.WorldChunkMixin"
|
||||||
|
|||||||
Reference in New Issue
Block a user