<commit_before>package com.ForgeEssentials.commands;

import java.util.Arrays;
import java.util.List;

import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.EnumGameType;
import net.minecraft.world.WorldSettings;

import com.ForgeEssentials.core.commands.ForgeEssentialsCommandBase;
import com.ForgeEssentials.permission.PermissionsAPI;
import com.ForgeEssentials.permission.query.PermQueryPlayer;
import com.ForgeEssentials.util.FunctionHelper;
import com.ForgeEssentials.util.Localization;

import cpw.mods.fml.common.FMLCommonHandler;

public class CommandGameMode extends ForgeEssentialsCommandBase
{
	@Override
	public String getCommandName()
	{
		return "gamemode";
	}

	@Override
	public List getCommandAliases()
	{
		return Arrays.asList(new String[] { "gm" });
	}

	@Override
	public void processCommandPlayer(EntityPlayer sender, String[] args)
	{
		if (args.length < 2)
		{
			if (args.length == 1)
			{
				sender.setGameType(getGameTypeFromString(sender, args[0]));
			}
			else
			{
				EnumGameType gm;
				if (((EntityPlayerMP) sender).theItemInWorldManager.getGameType().isCreative())
				{
					gm = EnumGameType.SURVIVAL;
				}
				else
				{
					gm = EnumGameType.CREATIVE;
				}

				sender.setGameType(gm);
			}
		}
		else if (args.length == 2 && PermissionsAPI.checkPermAllowed(new PermQueryPlayer(sender, getCommandPerm() + ".others")))
		{
			EntityPlayer victim = FunctionHelper.getPlayerFromUsername(args[0]);
			if (args.length == 2)
			{
				victim.setGameType(getGameTypeFromString(sender, args[1]));
			}
			else
			{
				EnumGameType gm;
				if (((EntityPlayerMP) victim).theItemInWorldManager.getGameType().isSurvivalOrAdventure())
				{
					gm = EnumGameType.CREATIVE;
				}
				else
				{
					gm = EnumGameType.SURVIVAL;
				}

				victim.setGameType(gm);
			}
			sender.sendChatToPlayer("Gamemode changed of " + victim.username);
		}
		else
		{
			sender.sendChatToPlayer(Localization.get(Localization.ERROR_BADSYNTAX) + getSyntaxPlayer(sender));
		}
	}

	@Override
	public void processCommandConsole(ICommandSender sender, String[] args)
	{
		if (args.length <= 2)
		{
			EntityPlayer victim = FunctionHelper.getPlayerFromUsername(args[0]);
			if (args.length == 2)
			{
				victim.setGameType(getGameTypeFromString(sender, args[1]));
			}
			else
			{
				EnumGameType gm;
				if (((EntityPlayerMP) victim).theItemInWorldManager.getGameType().isSurvivalOrAdventure())
				{
					gm = EnumGameType.CREATIVE;
				}
				else
				{
					gm = EnumGameType.SURVIVAL;
				}

				victim.setGameType(gm);
			}
			sender.sendChatToPlayer("Gamemode changed of " + victim.username);
		}
		else
		{
			sender.sendChatToPlayer(Localization.get(Localization.ERROR_BADSYNTAX) + getSyntaxConsole());
		}
	}

	public EnumGameType getGameTypeFromString(ICommandSender sender, String string)
	{
		return !string.equalsIgnoreCase(EnumGameType.SURVIVAL.getName()) && !string.equalsIgnoreCase("s") ? (!string.equalsIgnoreCase(EnumGameType.CREATIVE<commit_msg>Fixed NPE in console parsing.<commit_after>package com.ForgeEssentials.commands;

import java.util.Arrays;
import java.util.List;

import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.EnumGameType;
import net.minecraft.world.WorldSettings;

import com.ForgeEssentials.core.commands.ForgeEssentialsCommandBase;
import com.ForgeEssentials.permission.PermissionsAPI;
import com.ForgeEssentials.permission.query.PermQueryPlayer;
import com.ForgeEssentials.util.FunctionHelper;
import com.ForgeEssentials.util.Localization;

import cpw.mods.fml.common.FMLCommonHandler;

public class CommandGameMode extends ForgeEssentialsCommandBase
{
	@Override
	public String getCommandName()
	{
		return "gamemode";
	}

	@Override
	public List getCommandAliases()
	{
		return Arrays.asList(new String[] { "gm" });
	}

	@Override
	public void processCommandPlayer(EntityPlayer sender, String[] args)
	{
		if (args.length < 2)
		{
			if (args.length == 1)
			{
				sender.setGameType(getGameTypeFromString(sender, args[0]));
			}
			else
			{
				EnumGameType gm;
				if (((EntityPlayerMP) sender).theItemInWorldManager.getGameType().isCreative())
				{
					gm = EnumGameType.SURVIVAL;
				}
				else
				{
					gm = EnumGameType.CREATIVE;
				}

				sender.setGameType(gm);
			}
		}
		else if (args.length == 2 && PermissionsAPI.checkPermAllowed(new PermQueryPlayer(sender, getCommandPerm() + ".others")))
		{
			EntityPlayer victim = FunctionHelper.getPlayerFromUsername(args[0]);
			if (args.length == 2)
			{
				victim.setGameType(getGameTypeFromString(sender, args[1]));
			}
			else
			{
				EnumGameType gm;
				if (((EntityPlayerMP) victim).theItemInWorldManager.getGameType().isSurvivalOrAdventure())
				{
					gm = EnumGameType.CREATIVE;
				}
				else
				{
					gm = EnumGameType.SURVIVAL;
				}

				victim.setGameType(gm);
			}
			sender.sendChatToPlayer("Gamemode changed of " + victim.username);
		}
		else
		{
			sender.sendChatToPlayer(Localization.get(Localization.ERROR_BADSYNTAX) + getSyntaxPlayer(sender));
		}
	}

	@Override
	public void processCommandConsole(ICommandSender sender, String[] args)
	{
		if (args.length <= 2)
		{
			EntityPlayer victim = FunctionHelper.getPlayerFromUsername(args[0]);
			if (args.length == 2)
			{
				victim.setGameType(getGameTypeFromString(sender, args[1]));
			}
			else
			{
				EnumGameType gm;
				if (((EntityPlayerMP) victim).theItemInWorldManager.getGameType() == EnumGameType.SURVIVAL ||
						((EntityPlayerMP) victim).theItemInWorldManager.getGameType() == EnumGameType.ADVENTURE)
				{
					gm = EnumGameType.CREATIVE;
				}
				else
				{
					gm = EnumGameType.SURVIVAL;
				}

				victim.setGameType(gm);
			}
			sender.sendChatToPlayer("Gamemode changed of " + victim.username);
		}
		else
		{
			sender.sendChatToPlayer(Localization.get(Localization.ERROR_BADSYNTAX) + getSyntaxConsole());
		}
	}

	public EnumGameType getGameTypeFromString(ICommandSender sender, String string)
	{
		return !string.equalsIgnoreCase(EnumGameType.SURVIVAL.getName()) && !string.equalsIgnoreCase("s") ? (!string.equalsIgnoreCase(EnumGameType.CREATIVE
{'fraction_non_alphanumeric': 0.1148477157360406, 'fraction_numerical': 0.0034898477157360407, 'mean_word_length': 4.219370860927152, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1890757', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2098, 'n_words': 319}