package info.u_team.u_team_core.intern.command.uteamcore;

import java.util.Collection;

import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;

import info.u_team.u_team_core.util.world.WorldUtil;
import net.minecraft.command.*;
import net.minecraft.command.arguments.*;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.dimension.DimensionType;

public class DimensionTeleportSubCommand {
	
	private static final String SUCCESS_TRANSLATION_STRING = "commands.uteamcore.dimteleport.success.";
	
	public static ArgumentBuilder<CommandSource, ?> register() {
		return Commands.literal("dimteleport") //
				.requires(source -> source.hasPermissionLevel(2)) //
				.then(Commands.argument("targets", EntityArgument.entities()) //
						.then(Commands.argument("dimension", DimensionArgument.getDimension()) //
								.executes(context -> {
									return execute(context.getSource(), EntityArgument.getEntities(context, "targets"), DimensionArgument.getDimensionArgument(context, "dimension"));
								}) //
								.then(Commands.argument("location", Vec3Argument.vec3()) //
										.executes(context -> {
											return execute(context.getSource(), EntityArgument.getEntities(context, "targets"), DimensionArgument.getDimensionArgument(context, "dimension"), Vec3Argument.getVec3(context, "location"));
										}) //
										.then(Commands.argument("yaw", FloatArgumentType.floatArg(0, 360)) //
												.then(Commands.argument("pitch", FloatArgumentType.floatArg(-90, 90)) //
														.executes(context -> {
															return execute(context.getSource(), EntityArgument.getEntities(context, "targets"), DimensionArgument.getDimensionArgument(context, "dimension"), Vec3Argument.getVec3(context, "location"), FloatArgumentType.getFloat(context, "yaw"), FloatArgumentType.getFloat(context, "pitch"));
														}))))));
	}
	
	private static int execute(CommandSource source, Collection<? extends Entity> targets, DimensionType type) {
		targets.forEach(entity -> WorldUtil.teleportEntity(entity, type, entity.getPositionVector()));
		if (targets.size() == 1) {
			source.sendFeedback(new TranslationTextComponent(SUCCESS_TRANSLATION_STRING + "single", targets.iterator().next().getDisplayName(), type.getRegistryName()), true);
		} else {
			source.sendFeedback(new TranslationTextComponent(SUCCESS_TRANSLATION_STRING + "multiple", targets.size(), type.getRegistryName()), true);
		}
		return 0;
	}
	
	private static int execute(CommandSource source, Collection<? extends Entity> targets, DimensionType type, Vec3d pos) {
		targets.forEach(entity -> WorldUtil.teleportEntity(entity, type, pos));
		sendPositionInfo(source, targets, type, pos);
		return 0;
	}
	
	private static int execute(CommandSource source, Collection<? extends Entity> targets, DimensionType type, Vec3d pos, float yaw, float pitch) {
		targets.forEach(entity -> WorldUtil.teleportEntity(entity, type, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch));
		sendPositionInfo(source, targets, type, pos);
		return 0;
	}
	
	private static void sendPositionInfo(CommandSource source, Collection<? extends Entity> targets, DimensionType type, Vec3d pos) {
		if (targets.size() == 1) {
			source.sendFeedback(new TranslationTextComponent(SUCCESS_TRANSLATION_STRING + "position.single", targets.iterator().next().getDisplayName(), type.getRegistryName(), pos.x, pos.y, pos.z), true);
		} else {
			source.sendFeedback(new TranslationTextComponent(SUCCESS_TRANSLATION_STRING + "position.multiple", targets.size(), type.getRegistryName(), pos.x, pos.y, pos.z), true);
		}
	}
}

@@ -394,16 +394,64 @@
 .Vec3d;%0A
+import net.minecraft.util.math.vector.Vector3d;%0A
 import n
@@ -550,16 +550,63 @@
 ionType;
+%0Aimport net.minecraft.world.server.ServerWorld;
 %0A%0Apublic
@@ -2191,34 +2191,33 @@
 argets, 
-DimensionType type
+ServerWorld world
 ) %7B%0A%09%09ta
@@ -2273,20 +2273,21 @@
 entity, 
-type
+world
 , entity
@@ -2301,19 +2301,16 @@
 itionVec
-tor
 ()));%0A%09%09
@@ -2471,36 +2471,53 @@
 Name(), 
-type.getRegistryName
+world.func_234923_W_().func_240901_a_
 ()), tru
@@ -2640,36 +2640,53 @@
 size(), 
-type.getRegistryName
+world.func_234923_W_().func_240901_a_
 ()), tru
@@ -2798,39 +2798,41 @@
 argets, 
-DimensionType type
+ServerWorld world
 , Vec
+tor
 3d pos) 
@@ -2890,28 +2890,29 @@
 ity(entity, 
-type
+world
 , pos));%0A%09%09s
@@ -2936,36 +2936,37 @@
 ource, targets, 
-type
+world
 , pos);%0A%09%09return
@@ -3062,39 +3062,41 @@
 argets, 
-DimensionType type
+ServerWorld world
 , Vec
+tor
 3d pos, 
@@ -3182,20 +3182,21 @@
 entity, 
-type
+world
 , pos.ge
@@ -3275,20 +3275,21 @@
 argets, 
-type
+world
 , pos);%0A
@@ -3407,31 +3407,33 @@
 ts, 
-DimensionType type
+ServerWorld world
 , Vec
+tor
 3d p
@@ -3611,36 +3611,53 @@
 Name(), 
-type.getRegistryName
+world.func_234923_W_().func_240901_a_
 (), pos.
@@ -3814,28 +3814,45 @@
 (), 
-type.getRegistryName
+world.func_234923_W_().func_240901_a_
 (), 

Update methods in dimension teleport sub command to the new format