Because i don't know how to do git repo, i send the Command class
SwitchDimCommand:
package io.github.Natank25.customdim.commom.command.impl;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import io.github.Natank25.customdim.commom.command.BaseCommand;
import io.github.Natank25.customdim.core.init.DimensionInit;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.EntityArgument;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.world.World;
public class SwitchDimCommand extends BaseCommand {
public SwitchDimCommand(String name, int permissionLevel, boolean enabled) {
super(name, permissionLevel, enabled);
}
@Override
public LiteralArgumentBuilder<CommandSource> setExecution() {
return builder.then(Commands.argument("null", null)
.executes(source -> execute(source.getSource(), EntityArgument.getPlayer(source, "player"))));
}
private int execute(CommandSource source, ServerPlayerEntity player) {
if (source.getLevel() == source.getServer().getLevel(World.OVERWORLD)) {
player.teleportTo(source.getServer().getLevel(DimensionInit.EMPTY_DIM),0,4,0,0,0);
} else if (source.getLevel() == source.getServer().getLevel(DimensionInit.EMPTY_DIM)) {
player.teleportTo(source.getServer().getLevel(World.OVERWORLD),-268,76,276,0,0);
}
return Command.SINGLE_SUCCESS;
}
}
BaseCommand:
package io.github.Natank25.customdim.commom.command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
public class BaseCommand {
protected LiteralArgumentBuilder<CommandSource> builder;
boolean enabled;
public BaseCommand(String name, int permissionLevel, boolean enabled) {
this.builder = Commands.literal(name).requires(source -> source.hasPermission(permissionLevel));
this.enabled = enabled;
}
public LiteralArgumentBuilder<CommandSource> getBuilder() {
return builder;
}
public boolean isEnabled() {
return enabled;
}
public LiteralArgumentBuilder<CommandSource> setExecution() {
return null;
}
}