<commit_before>package com.forgeessentials.multiworld.command;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.permissions.PermissionsManager.RegisteredPermValue;

import com.forgeessentials.core.commands.ForgeEssentialsCommandBase;
import com.forgeessentials.multiworld.ModuleMultiworld;
import com.forgeessentials.multiworld.Multiworld;
import com.forgeessentials.util.OutputHandler;
import com.forgeessentials.util.UserIdent;

/**
 * @author Olee
 */
public class CommandMultiworldTeleport extends ForgeEssentialsCommandBase {

    @Override
    public String getCommandName()
    {
        return "mwtp";
    }

    @Override
    public String getCommandUsage(ICommandSender commandSender)
    {
        return "/mwtp <world> [player] [x y z]";
    }

    @Override
    public List addTabCompletionOptions(ICommandSender sender, String[] argsArray)
    {
        switch (argsArray.length)
        {
        case 1:
            return ForgeEssentialsCommandBase.getListOfStringsMatchingLastWord(argsArray[0], ModuleMultiworld.getMultiworldManager().getWorldMap().keySet());
        case 2:
            return ForgeEssentialsCommandBase.completePlayername(argsArray[1]);
        case 0:
        default:
            return null;
        }
    }

    @Override
    public void processCommand(ICommandSender sender, String[] argsArray)
    {
        EntityPlayerMP player = (sender instanceof EntityPlayerMP) ? (EntityPlayerMP) sender : null;
        Queue<String> args = new LinkedList<>(Arrays.asList(argsArray));

        if (args.isEmpty())
            throw new CommandException("Missing world argument.");

        String worldName = args.remove();
        Multiworld multiworld = null;
        if (!worldName.equals("0"))
        {
            multiworld = ModuleMultiworld.getMultiworldManager().getMultiworld(worldName);
            if (multiworld == null)
                throw new CommandException("Multiworld " + worldName + " does not exist.");
        }

        if (args.isEmpty())
        {
            if (player == null)
                throw new CommandException("Missing player-name argument.");
        }
        else
        {
            String playerName = args.remove();
            player = UserIdent.getPlayerByMatchOrUsername(sender, playerName);
            if (player == null)
                throw new CommandException("Could not find player " + playerName);
        }

        double x = Math.floor(player.posX) + 0.5;
        double y = Math.floor(player.posY);
        double z = Math.floor(player.posZ) + 0.5;
        if (!args.isEmpty())
        {
            if (args.size() < 3)
                throw new CommandException("Too few arguments for location.");
            x = parseDouble(sender, args.remove());
            y = parseDouble(sender, args.remove());
            z = parseDouble(sender, args.remove());
        }

        int dimId = multiworld == null ? 0 : multiworld.getDimensionId();
        if (!DimensionManager.isDimensionRegistered(dimId))
            throw new CommandException("Dimension #" + dimId + " does not exist.");

        if (dimId < 0 || dimId == 1)
            throw new CommandException("You are not allowed to teleport to that dimension");

        WorldServer world = player.mcServer.worldServerForDimension(dimId);
<commit_msg>Allowed /mwtp to teleport to all dimensions.<commit_after>package com.forgeessentials.multiworld.command;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.permissions.PermissionsManager.RegisteredPermValue;

import com.forgeessentials.core.commands.ForgeEssentialsCommandBase;
import com.forgeessentials.multiworld.ModuleMultiworld;
import com.forgeessentials.multiworld.Multiworld;
import com.forgeessentials.util.OutputHandler;
import com.forgeessentials.util.UserIdent;

/**
 * @author Olee
 */
public class CommandMultiworldTeleport extends ForgeEssentialsCommandBase {

    @Override
    public String getCommandName()
    {
        return "mwtp";
    }

    @Override
    public String getCommandUsage(ICommandSender commandSender)
    {
        return "/mwtp <world> [player] [x y z]";
    }

    @Override
    public List addTabCompletionOptions(ICommandSender sender, String[] argsArray)
    {
        switch (argsArray.length)
        {
        case 1:
            return ForgeEssentialsCommandBase.getListOfStringsMatchingLastWord(argsArray[0], ModuleMultiworld.getMultiworldManager().getWorldMap().keySet());
        case 2:
            return ForgeEssentialsCommandBase.completePlayername(argsArray[1]);
        case 0:
        default:
            return null;
        }
    }

    @Override
    public void processCommand(ICommandSender sender, String[] argsArray)
    {
        EntityPlayerMP player = (sender instanceof EntityPlayerMP) ? (EntityPlayerMP) sender : null;
        Queue<String> args = new LinkedList<>(Arrays.asList(argsArray));

        if (args.isEmpty())
            throw new CommandException("Missing world argument.");

        String worldName = args.remove();
        Multiworld multiworld = null;
        if (!worldName.equals("0"))
        {
            multiworld = ModuleMultiworld.getMultiworldManager().getMultiworld(worldName);
            if (multiworld == null)
                throw new CommandException("Multiworld " + worldName + " does not exist.");
        }

        if (args.isEmpty())
        {
            if (player == null)
                throw new CommandException("Missing player-name argument.");
        }
        else
        {
            String playerName = args.remove();
            player = UserIdent.getPlayerByMatchOrUsername(sender, playerName);
            if (player == null)
                throw new CommandException("Could not find player " + playerName);
        }

        double x = Math.floor(player.posX) + 0.5;
        double y = Math.floor(player.posY);
        double z = Math.floor(player.posZ) + 0.5;
        if (!args.isEmpty())
        {
            if (args.size() < 3)
                throw new CommandException("Too few arguments for location.");
            x = parseDouble(sender, args.remove());
            y = parseDouble(sender, args.remove());
            z = parseDouble(sender, args.remove());
        }

        int dimId = multiworld == null ? 0 : multiworld.getDimensionId();
        if (!DimensionManager.isDimensionRegistered(dimId))
            throw new CommandException("Dimension #" + dimId + " does not exist.");

        //if (dimId < 0 || dimId == 1)
        //    throw new CommandException("You are not allowed to teleport to that dimension");

        WorldServer world = player.mcServer.worldServerForDimension(dimId);

{'fraction_non_alphanumeric': 0.10100454107609742, 'fraction_numerical': 0.0038530342644832807, 'mean_word_length': 2.7444616177228234, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4673787', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1922, 'n_words': 444}