<commit_before>package com.comandante.creeper.merchant;

import com.comandante.creeper.Items.Item;
import com.comandante.creeper.Items.ItemType;
import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.player.Player;
import com.comandante.creeper.player.PlayerMetadata;
import com.comandante.creeper.server.Color;
import com.comandante.creeper.server.CreeperSession;
import com.google.common.collect.Maps;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.nocrala.tools.texttablefmt.BorderStyle;
import org.nocrala.tools.texttablefmt.ShownBorders;
import org.nocrala.tools.texttablefmt.Table;

import java.util.Iterator;
import java.util.Map;
import java.util.UUID;

public class MerchantCommandHandler extends SimpleChannelUpstreamHandler {

    private final GameManager gameManager;
    private final Merchant merchant;
    private final MerchantManager merchantManager;

    public MerchantCommandHandler(GameManager gameManager, Merchant merchant) {
        this.gameManager = gameManager;
        this.merchant = merchant;
        this.merchantManager = new MerchantManager(gameManager);
    }

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        CreeperSession creeperSession = (CreeperSession) e.getChannel().getAttachment();
        Player playerByUsername = gameManager.getPlayerManager().getPlayerByUsername(creeperSession.getUsername().get());
        Map<Integer, InventoryItemForSale> inventoryMenu = getInventoryMenu(playerByUsername);
        try {
            String message = (String) e.getMessage();
            String cmd = message;
            String[] split = null;
            if (message.contains(" ")) {
                split = message.split(" ");
                cmd = split[0];
            }
            if (cmd.equalsIgnoreCase("buy")) {
                if (split != null && isInteger(split[1])) {
                    Integer desiredItem = Integer.parseInt(split[1]);
                    merchantManager.purchaseItem(merchant, desiredItem, playerByUsername);
                } else {
                    gameManager.getChannelUtils().write(playerByUsername.getPlayerId(), merchant.getMenu() + "\r\n");
                }
            } else if (cmd.equalsIgnoreCase("sell")) {<commit_msg>bug when sell with a whitespace character was entered<commit_after>package com.comandante.creeper.merchant;

import com.comandante.creeper.Items.Item;
import com.comandante.creeper.Items.ItemType;
import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.player.Player;
import com.comandante.creeper.player.PlayerMetadata;
import com.comandante.creeper.server.Color;
import com.comandante.creeper.server.CreeperSession;
import com.google.common.collect.Maps;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.nocrala.tools.texttablefmt.BorderStyle;
import org.nocrala.tools.texttablefmt.ShownBorders;
import org.nocrala.tools.texttablefmt.Table;

import java.util.Iterator;
import java.util.Map;
import java.util.UUID;

public class MerchantCommandHandler extends SimpleChannelUpstreamHandler {

    private final GameManager gameManager;
    private final Merchant merchant;
    private final MerchantManager merchantManager;

    public MerchantCommandHandler(GameManager gameManager, Merchant merchant) {
        this.gameManager = gameManager;
        this.merchant = merchant;
        this.merchantManager = new MerchantManager(gameManager);
    }

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        CreeperSession creeperSession = (CreeperSession) e.getChannel().getAttachment();
        Player playerByUsername = gameManager.getPlayerManager().getPlayerByUsername(creeperSession.getUsername().get());
        Map<Integer, InventoryItemForSale> inventoryMenu = getInventoryMenu(playerByUsername);
        try {
            String message = (String) e.getMessage();
            String cmd = message.replaceFirst("\\s+$", "");
            String[] split = null;
            if (cmd.contains(" ")) {
                split = message.split(" ");
                cmd = split[0];
            }
            if (cmd.equalsIgnoreCase("buy")) {
                if (split != null && isInteger(split[1])) {
                    Integer desiredItem = Integer.parseInt(split[1]);
                    merchantManager.purchaseItem(merchant, desiredItem, playerByUsername);
                } else {
                    gameManager.getChannelUtils().write(playerByUsername.getPlayerId(), merchant.getMenu() + "\r\n");
                }
            } else if (cmd.equalsIgnoreCase("sell")) {
{'fraction_non_alphanumeric': 0.09979633401221996, 'fraction_numerical': 0.0012219959266802445, 'mean_word_length': 3.396598030438675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '681098', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1348, 'n_words': 250}