nus-yam/ex-repair huggingface dataset:
Program: 178064
Project: 178064
Buggy source:
public static void load(){
  try {
    accounts=DaoCreator.getDaoAndCreateTable(Account.class);
    adminAccount=new Account(Properties.ADMIN_SHOP_NAME,Bukkit.getOfflinePlayer(Properties.ADMIN_SHOP_NAME).getUniqueId());
    accounts.createOrUpdate(adminAccount);
    if (!Properties.SERVER_ECONOMY_ACCOUNT.isEmpty()) {
      serverEconomyAccount=getAccount(Properties.SERVER_ECONOMY_ACCOUNT);
      if (serverEconomyAccount == null || serverEconomyAccount.getUuid() == null) {
        ChestShop.getBukkitLogger().log(Level.WARNING,"String_Node_Str" + Properties.SERVER_ECONOMY_ACCOUNT + "String_Node_Str");
      }
    }
  }
 catch (  SQLException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
public static void load(){
  try {
    accounts=DaoCreator.getDaoAndCreateTable(Account.class);
    adminAccount=new Account(Properties.ADMIN_SHOP_NAME,Bukkit.getOfflinePlayer(Properties.ADMIN_SHOP_NAME).getUniqueId());
    accounts.createOrUpdate(adminAccount);
    if (!Properties.SERVER_ECONOMY_ACCOUNT.isEmpty()) {
      serverEconomyAccount=getAccount(Properties.SERVER_ECONOMY_ACCOUNT);
      if (serverEconomyAccount == null || serverEconomyAccount.getUuid() == null) {
        serverEconomyAccount=null;
        ChestShop.getBukkitLogger().log(Level.WARNING,"String_Node_Str" + Properties.SERVER_ECONOMY_ACCOUNT + "String_Node_Str");
      }
    }
  }
 catch (  SQLException e) {
    e.printStackTrace();
  }
}
Program: 178065
Project: 178065
Buggy source:
/** 
 * Checks if the itemStacks are equal, ignoring their amount
 * @param one first itemStack
 * @param two second itemStack
 * @return Are they equal?
 */
public static boolean equals(ItemStack one,ItemStack two){
  if (one == null || two == null) {
    return one != two;
  }
  if (one.isSimilar(two)) {
    return true;
  }
  return one.getType() == two.getType() && one.getDurability() == two.getDurability() && one.getData().equals(two.getData()) && one.hasItemMeta() && two.hasItemMeta() && one.getItemMeta() instanceof BookMeta && two.getItemMeta() instanceof BookMeta && one.getItemMeta().serialize().equals(two.getItemMeta().serialize());
}

Fixed version (ground truth):
/** 
 * Checks if the itemStacks are equal, ignoring their amount
 * @param one first itemStack
 * @param two second itemStack
 * @return Are they equal?
 */
public static boolean equals(ItemStack one,ItemStack two){
  if (one == null || two == null) {
    return one == two;
  }
  if (one.isSimilar(two)) {
    return true;
  }
  return one.getType() == two.getType() && one.getDurability() == two.getDurability() && one.getData().equals(two.getData()) && one.hasItemMeta() && two.hasItemMeta() && one.getItemMeta() instanceof BookMeta && two.getItemMeta() instanceof BookMeta && one.getItemMeta().serialize().equals(two.getItemMeta().serialize());
}
Program: 178066
Project: 178066
Buggy source:
/** 
 * Make an array of items fit into an inventory.
 * @param stock     The items to fit in the inventory
 * @param inventory The inventory to fit it in
 * @return Whether or not the items fit into the inventory
 */
private static ItemStack[] getItemsThatFit(ItemStack[] stock,Inventory inventory){
  List<ItemStack> resultStock=new ArrayList<>();
  int emptySlots=InventoryUtil.countEmpty(inventory);
  ItemStack[] itemsInInventory=getItems(stock,inventory);
  for (  ItemStack item : stock) {
    int maxStackSize=InventoryUtil.getMaxStackSize(item);
    int free=0;
    for (    ItemStack itemInInventory : itemsInInventory) {
      if (MaterialUtil.equals(item,itemInInventory)) {
        free=(maxStackSize - itemInInventory.getAmount()) % maxStackSize;
        break;
      }
    }
    if (free == 0 && emptySlots == 0) {
      continue;
    }
    ItemStack clone=item.clone();
    if (item.getAmount() > free) {
      if (emptySlots > 0) {
        int requiredSlots=(int)Math.ceil((item.getAmount() - free) / maxStackSize);
        if (requiredSlots <= emptySlots) {
          emptySlots=emptySlots - requiredSlots;
        }
 else {
          emptySlots=0;
          clone.setAmount(free + maxStackSize * emptySlots);
        }
      }
 else {
        clone.setAmount(free);
      }
    }
    resultStock.add(clone);
  }
  return resultStock.toArray(new ItemStack[resultStock.size()]);
}

Fixed version (ground truth):
/** 
 * Make an array of items fit into an inventory.
 * @param stock     The items to fit in the inventory
 * @param inventory The inventory to fit it in
 * @return Whether or not the items fit into the inventory
 */
private static ItemStack[] getItemsThatFit(ItemStack[] stock,Inventory inventory){
  List<ItemStack> resultStock=new ArrayList<>();
  int emptySlots=InventoryUtil.countEmpty(inventory);
  for (  ItemStack item : InventoryUtil.mergeSimilarStacks(stock)) {
    int maxStackSize=InventoryUtil.getMaxStackSize(item);
    int free=0;
    for (    ItemStack itemInInventory : inventory.getContents()) {
      if (MaterialUtil.equals(item,itemInInventory)) {
        free+=(maxStackSize - itemInInventory.getAmount()) % maxStackSize;
      }
    }
    if (free == 0 && emptySlots == 0) {
      continue;
    }
    if (item.getAmount() > free) {
      if (emptySlots > 0) {
        int requiredSlots=(int)Math.ceil(((double)item.getAmount() - free) / maxStackSize);
        if (requiredSlots <= emptySlots) {
          emptySlots=emptySlots - requiredSlots;
        }
 else {
          item.setAmount(free + maxStackSize * emptySlots);
          emptySlots=0;
        }
      }
 else {
        item.setAmount(free);
      }
    }
    resultStock.add(item);
  }
  return resultStock.toArray(new ItemStack[resultStock.size()]);
}
Program: 178068
Project: 178068
Buggy source:
/** 
 * Adds an item to the inventor
 * @param item      Item to add
 * @param inventory Inventory
 * @return Number of leftover items
 */
public static int add(ItemStack item,Inventory inventory){
  Map<Integer,ItemStack> leftovers=inventory.addItem(item.clone());
  return countItems(leftovers);
}

Fixed version (ground truth):
/** 
 * Adds an item to the inventor
 * @param item      Item to add
 * @param inventory Inventory
 * @return Number of leftover items
 */
public static int add(ItemStack item,Inventory inventory){
  Map<Integer,ItemStack> leftovers=inventory.addItem(item.clone());
  if (!leftovers.isEmpty()) {
    for (Iterator<ItemStack> iterator=leftovers.values().iterator(); iterator.hasNext(); ) {
      ItemStack left=iterator.next();
      int amountLeft=addManually(left,inventory,left.getMaxStackSize());
      if (amountLeft == 0) {
        iterator.remove();
      }
 else {
        left.setAmount(amountLeft);
      }
    }
  }
  return countItems(leftovers);
}
Program: 178069
Project: 178069
Buggy source:
/** 
 * Counts leftovers from a map
 * @param items Leftovers
 * @return Number of leftovers
 */
public static int countItems(Map<Integer,?> items){
  int totalLeft=0;
  for (  int left : items.keySet()) {
    totalLeft+=left;
  }
  return totalLeft;
}

Fixed version (ground truth):
/** 
 * Counts leftovers from a map
 * @param items Leftovers
 * @return Number of leftovers
 */
public static int countItems(Map<Integer,ItemStack> items){
  int totalLeft=0;
  for (  ItemStack left : items.values()) {
    totalLeft+=left.getAmount();
  }
  return totalLeft;
}
Program: 178070
Project: 178070
Buggy source:
/** 
 * Checks if the inventory has stock of this type
 * @param items     items
 * @param inventory inventory
 * @return Does the inventory contain stock of this type?
 */
public static boolean hasItems(ItemStack[] items,Inventory inventory){
  for (  ItemStack item : items) {
    if (!inventory.containsAtLeast(item,item.getAmount())) {
      return false;
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Checks if the inventory has stock of this type
 * @param items     items
 * @param inventory inventory
 * @return Does the inventory contain stock of this type?
 */
public static boolean hasItems(ItemStack[] items,Inventory inventory){
  for (  ItemStack item : items) {
    if (getAmount(item,inventory) < item.getAmount()) {
      return false;
    }
  }
  return true;
}
Program: 178071
Project: 178071
Buggy source:
/** 
 * Removes an item from the inventory
 * @param item      Item to remove
 * @param inventory Inventory
 * @return Number of items that couldn't be removed
 */
public static int remove(ItemStack item,Inventory inventory){
  Map<Integer,ItemStack> leftovers=inventory.removeItem(item);
  return countItems(leftovers);
}

Fixed version (ground truth):
/** 
 * Removes an item from the inventory
 * @param item      Item to remove
 * @param inventory Inventory
 * @return Number of items that couldn't be removed
 */
public static int remove(ItemStack item,Inventory inventory){
  Map<Integer,ItemStack> leftovers=inventory.removeItem(item);
  if (!leftovers.isEmpty()) {
    for (Iterator<ItemStack> iterator=leftovers.values().iterator(); iterator.hasNext(); ) {
      ItemStack left=iterator.next();
      if (removeManually(left,inventory) == 0) {
        iterator.remove();
      }
    }
  }
  return countItems(leftovers);
}
Program: 178072
Project: 178072
Buggy source:
/** 
 * Checks if the itemStacks are equal, ignoring their amount
 * @param one first itemStack
 * @param two second itemStack
 * @return Are they equal?
 */
public static boolean equals(ItemStack one,ItemStack two){
  return one.isSimilar(two);
}

Fixed version (ground truth):
/** 
 * Checks if the itemStacks are equal, ignoring their amount
 * @param one first itemStack
 * @param two second itemStack
 * @return Are they equal?
 */
public static boolean equals(ItemStack one,ItemStack two){
  if (one == null || two == null) {
    return one != two;
  }
  if (one.isSimilar(two)) {
    return true;
  }
  return one.getType() == two.getType() && one.getDurability() == two.getDurability() && one.getData().equals(two.getData()) && one.hasItemMeta() && two.hasItemMeta() && one.getItemMeta() instanceof BookMeta && two.getItemMeta() instanceof BookMeta && one.getItemMeta().serialize().equals(two.getItemMeta().serialize());
}
Program: 178073
Project: 178073
Buggy source:
public static boolean canAccess(Player player,Sign sign){
  if (player == null)   return false;
  if (sign == null)   return true;
  return NameManager.canUseName(player,sign.getLine(NAME_LINE));
}

Fixed version (ground truth):
public static boolean canAccess(Player player,Sign sign){
  if (player == null)   return false;
  if (sign == null)   return true;
  String name=sign.getLine(NAME_LINE);
  if (name == null || name.isEmpty())   return true;
  return NameManager.canUseName(player,name);
}
Program: 178074
Project: 178074
Buggy source:
@Override public void run(){
  String playerName=NameUtil.stripUsername(playerDTO.getName());
  UUID uuid=NameManager.getUUID(playerName);
  NameManager.storeUsername(playerDTO);
}

Fixed version (ground truth):
@Override public void run(){
  NameManager.storeUsername(playerDTO);
}
Program: 178075
Project: 178075
Buggy source:
@EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) public static void onPlayerConnect(final PlayerJoinEvent event){
  final PlayerDTO playerDTO=new PlayerDTO(event.getPlayer());
  Bukkit.getScheduler().runTaskAsynchronously(ChestShop.getPlugin(),new Runnable(){
    @Override public void run(){
      String playerName=NameUtil.stripUsername(playerDTO.getName());
      UUID uuid=NameManager.getUUID(playerName);
      NameManager.storeUsername(playerDTO);
    }
  }
);
}

Fixed version (ground truth):
@EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) public static void onPlayerConnect(final PlayerJoinEvent event){
  final PlayerDTO playerDTO=new PlayerDTO(event.getPlayer());
  Bukkit.getScheduler().runTaskAsynchronously(ChestShop.getPlugin(),new Runnable(){
    @Override public void run(){
      NameManager.storeUsername(playerDTO);
    }
  }
);
}
Program: 178077
Project: 178077
Buggy source:
@EventHandler(priority=EventPriority.MONITOR) public static void onShopDestroy(ShopDestroyedEvent event){
  double refundPrice=Properties.SHOP_REFUND_PRICE;
  if (event.getDestroyer() == null || Permission.has(event.getDestroyer(),NOFEE) || refundPrice == 0) {
    return;
  }
  String ownerName=NameManager.getFullUsername(event.getSign().getLine(NAME_LINE));
  UUID owner=NameManager.getUUID(ownerName);
  CurrencyAddEvent currencyEvent=new CurrencyAddEvent(BigDecimal.valueOf(refundPrice),owner,event.getSign().getWorld());
  ChestShop.callEvent(currencyEvent);
  if (!Economy.getServerAccountName().isEmpty()) {
    CurrencySubtractEvent currencySubtractEvent=new CurrencySubtractEvent(BigDecimal.valueOf(refundPrice),NameManager.getUUID(Economy.getServerAccountName()),event.getSign().getWorld());
    ChestShop.callEvent(currencySubtractEvent);
  }
  String message=Messages.SHOP_REFUNDED.replace("String_Node_Str",Economy.formatBalance(refundPrice));
  event.getDestroyer().sendMessage(Messages.prefix(message));
}

Fixed version (ground truth):
@EventHandler(priority=EventPriority.MONITOR) public static void onShopDestroy(ShopDestroyedEvent event){
  double refundPrice=Properties.SHOP_REFUND_PRICE;
  if (event.getDestroyer() == null || Permission.has(event.getDestroyer(),NOFEE) || refundPrice == 0) {
    return;
  }
  String ownerName=NameManager.getFullUsername(event.getSign().getLine(NAME_LINE));
  if (ownerName.isEmpty()) {
    return;
  }
  UUID owner=NameManager.getUUID(ownerName);
  CurrencyAddEvent currencyEvent=new CurrencyAddEvent(BigDecimal.valueOf(refundPrice),owner,event.getSign().getWorld());
  ChestShop.callEvent(currencyEvent);
  if (!Economy.getServerAccountName().isEmpty()) {
    CurrencySubtractEvent currencySubtractEvent=new CurrencySubtractEvent(BigDecimal.valueOf(refundPrice),NameManager.getUUID(Economy.getServerAccountName()),event.getSign().getWorld());
    ChestShop.callEvent(currencySubtractEvent);
  }
  String message=Messages.SHOP_REFUNDED.replace("String_Node_Str",Economy.formatBalance(refundPrice));
  event.getDestroyer().sendMessage(Messages.prefix(message));
}
Program: 178078
Project: 178078
Buggy source:
public static UUID getUUID(String username){
  if (usernameToUUID.containsKey(username)) {
    return usernameToUUID.get(username);
  }
  String shortenedName=NameUtil.stripUsername(username);
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",shortenedName).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
  if (account == null) {
    return Bukkit.getOfflinePlayer(username).getUniqueId();
  }
  UUID uuid=account.getUuid();
  if (uuid != null && !usernameToUUID.containsValue(uuid)) {
    usernameToUUID.put(account.getName(),uuid);
  }
  return uuid;
}

Fixed version (ground truth):
public static UUID getUUID(String username){
  Validate.notEmpty(username,"String_Node_Str");
  if (usernameToUUID.containsKey(username)) {
    return usernameToUUID.get(username);
  }
  String shortenedName=NameUtil.stripUsername(username);
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",shortenedName).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
  if (account == null) {
    return Bukkit.getOfflinePlayer(username).getUniqueId();
  }
  UUID uuid=account.getUuid();
  if (uuid != null && !usernameToUUID.containsValue(uuid)) {
    usernameToUUID.put(account.getName(),uuid);
  }
  return uuid;
}
Program: 178079
Project: 178079
Buggy source:
public static boolean canUseName(Player player,String name){
  String shortenedName=NameUtil.stripUsername(getUsername(player.getUniqueId()));
  if (ChestShopSign.isAdminShop(name)) {
    return false;
  }
  return shortenedName.equals(name) || Permission.otherName(player,name) || player.getUniqueId().equals(getUUID(name));
}

Fixed version (ground truth):
public static boolean canUseName(Player player,String name){
  String shortenedName=NameUtil.stripUsername(getUsername(player.getUniqueId()));
  if (ChestShopSign.isAdminShop(name)) {
    return false;
  }
  return shortenedName.equals(name) || Permission.otherName(player,name) || (!name.isEmpty() && player.getUniqueId().equals(getUUID(name)));
}
Program: 178080
Project: 178080
Buggy source:
@EventHandler public static void onSignChange(SignChangeEvent event){
  Block signBlock=event.getBlock();
  String[] line=event.getLines();
  if (!BlockUtil.isSign(signBlock)) {
    return;
  }
  if (!ChestShopSign.isValidPreparedSign(line)) {
    return;
  }
  PreShopCreationEvent preEvent=new PreShopCreationEvent(event.getPlayer(),(Sign)signBlock.getState(),line);
  ChestShop.callEvent(preEvent);
  if (preEvent.isCancelled()) {
    return;
  }
  for (byte i=0; i < event.getLines().length; ++i) {
    event.setLine(i,preEvent.getSignLine(i));
  }
  ShopCreatedEvent postEvent=new ShopCreatedEvent(preEvent.getPlayer(),preEvent.getSign(),uBlock.findConnectedChest(preEvent.getSign()),preEvent.getSignLines());
  ChestShop.callEvent(postEvent);
}

Fixed version (ground truth):
@EventHandler public static void onSignChange(SignChangeEvent event){
  Block signBlock=event.getBlock();
  String[] line=StringUtil.stripColourCodes(event.getLines());
  if (!BlockUtil.isSign(signBlock)) {
    return;
  }
  if (!ChestShopSign.isValidPreparedSign(line)) {
    return;
  }
  PreShopCreationEvent preEvent=new PreShopCreationEvent(event.getPlayer(),(Sign)signBlock.getState(),line);
  ChestShop.callEvent(preEvent);
  if (preEvent.isCancelled()) {
    return;
  }
  for (byte i=0; i < event.getLines().length; ++i) {
    event.setLine(i,preEvent.getSignLine(i));
  }
  ShopCreatedEvent postEvent=new ShopCreatedEvent(preEvent.getPlayer(),preEvent.getSign(),uBlock.findConnectedChest(preEvent.getSign()),preEvent.getSignLines());
  ChestShop.callEvent(postEvent);
}
Program: 178081
Project: 178081
Buggy source:
public static void load(){
  File databaseFile=ChestShop.loadFile("String_Node_Str");
  String uri=ConnectionManager.getURI(databaseFile);
  ConnectionSource connection;
  try {
    connection=new JdbcConnectionSource(uri);
    accounts=DaoManager.createDao(connection,Account.class);
    TableUtils.createTableIfNotExists(connection,Account.class);
    Account adminAccount=new Account(Properties.ADMIN_SHOP_NAME,Bukkit.getOfflinePlayer(Properties.ADMIN_SHOP_NAME).getUniqueId());
    accounts.createIfNotExists(adminAccount);
  }
 catch (  SQLException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
public static void load(){
  File databaseFile=ChestShop.loadFile("String_Node_Str");
  String uri=ConnectionManager.getURI(databaseFile);
  ConnectionSource connection;
  try {
    connection=new JdbcConnectionSource(uri);
    accounts=DaoManager.createDao(connection,Account.class);
    TableUtils.createTableIfNotExists(connection,Account.class);
    Account adminAccount=new Account(Properties.ADMIN_SHOP_NAME,Bukkit.getOfflinePlayer(Properties.ADMIN_SHOP_NAME).getUniqueId());
    accounts.createOrUpdate(adminAccount);
  }
 catch (  SQLException e) {
    e.printStackTrace();
  }
}
Program: 178082
Project: 178082
Buggy source:
@Override public void run(){
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",uuid).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return;
  }
  if (account != null) {
    return;
  }
  account=new Account(player.getName(),player.getUniqueId());
  try {
    accounts.create(account);
  }
 catch (  SQLException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
@Override public void run(){
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",uuid).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return;
  }
  if (account != null) {
    return;
  }
  account=new Account(player.getName(),player.getUniqueId());
  try {
    accounts.createOrUpdate(account);
  }
 catch (  SQLException e) {
    e.printStackTrace();
  }
}
Program: 178083
Project: 178083
Buggy source:
public static void storeUsername(final Player player){
  final UUID uuid=player.getUniqueId();
  if (!usernameToUUID.inverse().containsKey(uuid)) {
    usernameToUUID.inverse().put(uuid,player.getName());
  }
  Bukkit.getScheduler().runTaskAsynchronously(ChestShop.getPlugin(),new Runnable(){
    @Override public void run(){
      Account account=null;
      try {
        account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",uuid).queryForFirst();
      }
 catch (      SQLException e) {
        e.printStackTrace();
        return;
      }
      if (account != null) {
        return;
      }
      account=new Account(player.getName(),player.getUniqueId());
      try {
        accounts.create(account);
      }
 catch (      SQLException e) {
        e.printStackTrace();
      }
    }
  }
);
}

Fixed version (ground truth):
public static void storeUsername(final Player player){
  final UUID uuid=player.getUniqueId();
  if (!usernameToUUID.inverse().containsKey(uuid)) {
    usernameToUUID.inverse().put(uuid,player.getName());
  }
  Bukkit.getScheduler().runTaskAsynchronously(ChestShop.getPlugin(),new Runnable(){
    @Override public void run(){
      Account account=null;
      try {
        account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",uuid).queryForFirst();
      }
 catch (      SQLException e) {
        e.printStackTrace();
        return;
      }
      if (account != null) {
        return;
      }
      account=new Account(player.getName(),player.getUniqueId());
      try {
        accounts.createOrUpdate(account);
      }
 catch (      SQLException e) {
        e.printStackTrace();
      }
    }
  }
);
}
Program: 178084
Project: 178084
Buggy source:
/** 
 * Returns item's name, just like on the sign
 * @param itemStack ItemStack to name
 * @return ItemStack's name
 */
public static String getSignName(ItemStack itemStack){
  StringBuilder name=new StringBuilder(15);
  name.append(itemStack.getType().name());
  if (itemStack.getDurability() != 0) {
    name.append(':').append(itemStack.getDurability());
  }
  if (itemStack.hasItemMeta()) {
    name.append('#').append(Metadata.getItemCode(itemStack));
  }
  return StringUtil.capitalizeFirstLetter(name.toString(),'_');
}

Fixed version (ground truth):
/** 
 * Returns item's name, just like on the sign
 * @param itemStack ItemStack to name
 * @return ItemStack's name
 */
public static String getSignName(ItemStack itemStack){
  StringBuilder name=new StringBuilder(15);
  String itemName=itemStack.getType().name();
  itemName=StringUtil.capitalizeFirstLetter(itemName,'_');
  name.append(itemName);
  if (itemStack.getDurability() != 0) {
    name.append(':').append(itemStack.getDurability());
  }
  if (itemStack.hasItemMeta()) {
    name.append('#').append(Metadata.getItemCode(itemStack));
  }
  return name.toString();
}
Program: 178085
Project: 178085
Buggy source:
public static boolean canUseName(Player player,String name){
  String shortenedName=NameUtil.stripUsername(getUsername(player.getUniqueId()));
  return shortenedName.equals(name) || Permission.otherName(player,name) || player.getUniqueId().equals(getUUID(name));
}

Fixed version (ground truth):
public static boolean canUseName(Player player,String name){
  String shortenedName=NameUtil.stripUsername(getUsername(player.getUniqueId()));
  if (ChestShopSign.isAdminShop(name)) {
    return false;
  }
  return shortenedName.equals(name) || Permission.otherName(player,name) || player.getUniqueId().equals(getUUID(name));
}
Program: 178086
Project: 178086
Buggy source:
public static String getLastSeenName(UUID uuid){
  if (lastSeenName.containsKey(uuid)) {
    return lastSeenName.get(uuid);
  }
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str","String_Node_Str").where().eq("String_Node_Str",uuid).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
  if (account == null) {
    return "String_Node_Str";
  }
  if (account.getLastSeenName() != null) {
    lastSeenName.put(uuid,account.getLastSeenName());
  }
 else   if (account.getName() != null) {
    lastSeenName.put(uuid,account.getName());
  }
  return account.getLastSeenName();
}

Fixed version (ground truth):
public static String getLastSeenName(UUID uuid){
  if (lastSeenName.containsKey(uuid)) {
    return lastSeenName.get(uuid);
  }
  if (Bukkit.getOfflinePlayer(uuid).getName() != null) {
    String lastSeen=Bukkit.getOfflinePlayer(uuid).getName();
    lastSeenName.put(uuid,lastSeen);
    return lastSeen;
  }
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str","String_Node_Str").where().eq("String_Node_Str",uuid).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
  if (account == null) {
    return "String_Node_Str";
  }
  if (account.getLastSeenName() != null) {
    lastSeenName.put(uuid,account.getLastSeenName());
  }
 else   if (account.getName() != null) {
    lastSeenName.put(uuid,account.getName());
  }
  return account.getLastSeenName();
}
Program: 178087
Project: 178087
Buggy source:
public static UUID getUUID(String username){
  if (usernameToUUID.containsKey(username)) {
    return usernameToUUID.get(username);
  }
  String shortenedName=NameUtil.stripUsername(username);
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",shortenedName).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
  if (account == null) {
    UUID uuid=Bukkit.getOfflinePlayer(username).getUniqueId();
    usernameToUUID.put(username,uuid);
    return uuid;
  }
  UUID uuid=account.getUuid();
  if (uuid != null) {
    usernameToUUID.put(account.getName(),uuid);
  }
  return uuid;
}

Fixed version (ground truth):
public static UUID getUUID(String username){
  if (usernameToUUID.containsKey(username)) {
    return usernameToUUID.get(username);
  }
  String shortenedName=NameUtil.stripUsername(username);
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",shortenedName).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
  if (account == null) {
    UUID uuid=Bukkit.getOfflinePlayer(username).getUniqueId();
    usernameToUUID.put(username,uuid);
    return uuid;
  }
  UUID uuid=account.getUuid();
  if (uuid != null && !usernameToUUID.containsValue(uuid)) {
    usernameToUUID.put(account.getName(),uuid);
  }
  return uuid;
}
Program: 178088
Project: 178088
Buggy source:
public static boolean canUseName(Player player,String name){
  String shortenedName=NameUtil.stripUsername(getUsername(player.getUniqueId()));
  return shortenedName.equals(name) || Permission.otherName(player,name);
}

Fixed version (ground truth):
public static boolean canUseName(Player player,String name){
  String shortenedName=NameUtil.stripUsername(getUsername(player.getUniqueId()));
  return shortenedName.equals(name) || Permission.otherName(player,name) || player.getUniqueId().equals(getUUID(name));
}
Program: 178089
Project: 178089
Buggy source:
@EventHandler public void onAmountCheck(CurrencyAmountEvent event){
  if (!event.getAmount().equals(BigDecimal.ZERO)) {
    return;
  }
  double balance=provider.getBalance(Bukkit.getOfflinePlayer(event.getAccount()),event.getWorld().getName());
  if (balance > Double.MAX_VALUE) {
    balance=Double.MAX_VALUE;
  }
  event.setAmount(balance);
}

Fixed version (ground truth):
@EventHandler public void onAmountCheck(CurrencyAmountEvent event){
  if (!event.getAmount().equals(BigDecimal.ZERO)) {
    return;
  }
  double balance=provider.getBalance(NameManager.getUsername(event.getAccount()),event.getWorld().getName());
  if (balance > Double.MAX_VALUE) {
    balance=Double.MAX_VALUE;
  }
  event.setAmount(balance);
}
Program: 178090
Project: 178090
Buggy source:
@EventHandler public void onCurrencyCheck(CurrencyCheckEvent event){
  if (event.hasEnough()) {
    return;
  }
  World world=event.getWorld();
  if (provider.has(Bukkit.getOfflinePlayer(event.getAccount()),world.getName(),event.getDoubleAmount())) {
    event.hasEnough(true);
  }
}

Fixed version (ground truth):
@EventHandler public void onCurrencyCheck(CurrencyCheckEvent event){
  if (event.hasEnough()) {
    return;
  }
  World world=event.getWorld();
  if (provider.has(NameManager.getUsername(event.getAccount()),world.getName(),event.getDoubleAmount())) {
    event.hasEnough(true);
  }
}
Program: 178091
Project: 178091
Buggy source:
@EventHandler public void onCurrencyAdd(CurrencyAddEvent event){
  if (event.isAdded()) {
    return;
  }
  World world=event.getWorld();
  provider.depositPlayer(Bukkit.getOfflinePlayer(event.getTarget()),world.getName(),event.getDoubleAmount());
}

Fixed version (ground truth):
@EventHandler public void onCurrencyAdd(CurrencyAddEvent event){
  if (event.isAdded()) {
    return;
  }
  World world=event.getWorld();
  provider.depositPlayer(NameManager.getUsername(event.getTarget()),world.getName(),event.getDoubleAmount());
}
Program: 178092
Project: 178092
Buggy source:
@EventHandler public void onCurrencySubtraction(CurrencySubtractEvent event){
  if (event.isSubtracted()) {
    return;
  }
  World world=event.getWorld();
  provider.withdrawPlayer(Bukkit.getOfflinePlayer(event.getTarget()),world.getName(),event.getDoubleAmount());
}

Fixed version (ground truth):
@EventHandler public void onCurrencySubtraction(CurrencySubtractEvent event){
  if (event.isSubtracted()) {
    return;
  }
  World world=event.getWorld();
  provider.withdrawPlayer(NameManager.getUsername(event.getTarget()),world.getName(),event.getDoubleAmount());
}
Program: 178093
Project: 178093
Buggy source:
@EventHandler public void onCurrencyHoldCheck(CurrencyHoldEvent event){
  if (event.getAccount() == null || !transactionCanFail()) {
    return;
  }
  if (!provider.hasAccount(Bukkit.getOfflinePlayer(event.getAccount()),event.getWorld().getName())) {
    event.canHold(false);
    return;
  }
  EconomyResponse response=provider.depositPlayer(Bukkit.getOfflinePlayer(event.getAccount()),event.getWorld().getName(),event.getDoubleAmount());
  if (!response.transactionSuccess()) {
    event.canHold(false);
    return;
  }
  provider.withdrawPlayer(Bukkit.getOfflinePlayer(event.getAccount()),event.getWorld().getName(),event.getDoubleAmount());
}

Fixed version (ground truth):
@EventHandler public void onCurrencyHoldCheck(CurrencyHoldEvent event){
  if (event.getAccount() == null || !transactionCanFail()) {
    return;
  }
  if (!provider.hasAccount(NameManager.getUsername(event.getAccount()),event.getWorld().getName())) {
    event.canHold(false);
    return;
  }
  EconomyResponse response=provider.depositPlayer(NameManager.getUsername(event.getAccount()),event.getWorld().getName(),event.getDoubleAmount());
  if (!response.transactionSuccess()) {
    event.canHold(false);
    return;
  }
  provider.withdrawPlayer(NameManager.getUsername(event.getAccount()),event.getWorld().getName(),event.getDoubleAmount());
}
Program: 178094
Project: 178094
Buggy source:
@EventHandler public void onAccountCheck(AccountCheckEvent event){
  if (event.hasAccount()) {
    return;
  }
  World world=event.getWorld();
  if (!provider.hasAccount(Bukkit.getOfflinePlayer(event.getAccount()),world.getName())) {
    event.hasAccount(false);
  }
}

Fixed version (ground truth):
@EventHandler public void onAccountCheck(AccountCheckEvent event){
  if (event.hasAccount()) {
    return;
  }
  World world=event.getWorld();
  if (!provider.hasAccount(NameManager.getUsername(event.getAccount()),world.getName())) {
    event.hasAccount(false);
  }
}
Program: 178095
Project: 178095
Buggy source:
@EventHandler(priority=EventPriority.LOW) public static void onCurrencyAdd(CurrencyAddEvent event){
  if (event.isAdded()) {
    return;
  }
  UUID target=event.getTarget();
  if (Bukkit.getOfflinePlayer(target).getName().equals(Economy.getServerAccountName())) {
    return;
  }
  float taxAmount=isServerAccount(target) ? Properties.SERVER_TAX_AMOUNT : Properties.TAX_AMOUNT;
  if (taxAmount == 0) {
    return;
  }
  BigDecimal tax=getTax(event.getAmount(),taxAmount);
  if (!Economy.getServerAccountName().isEmpty()) {
    CurrencyAddEvent currencyAddEvent=new CurrencyAddEvent(tax,NameManager.getUUID(Economy.getServerAccountName()),event.getWorld());
    ChestShop.callEvent(currencyAddEvent);
  }
  event.setAmount(event.getAmount().subtract(tax));
}

Fixed version (ground truth):
@EventHandler(priority=EventPriority.LOW) public static void onCurrencyAdd(CurrencyAddEvent event){
  if (event.isAdded()) {
    return;
  }
  UUID target=event.getTarget();
  if (NameManager.getUsername(target).equals(Economy.getServerAccountName())) {
    return;
  }
  float taxAmount=isServerAccount(target) ? Properties.SERVER_TAX_AMOUNT : Properties.TAX_AMOUNT;
  if (taxAmount == 0) {
    return;
  }
  BigDecimal tax=getTax(event.getAmount(),taxAmount);
  if (!Economy.getServerAccountName().isEmpty()) {
    CurrencyAddEvent currencyAddEvent=new CurrencyAddEvent(tax,NameManager.getUUID(Economy.getServerAccountName()),event.getWorld());
    ChestShop.callEvent(currencyAddEvent);
  }
  event.setAmount(event.getAmount().subtract(tax));
}
Program: 178096
Project: 178096
Buggy source:
@EventHandler(priority=EventPriority.MONITOR) public static void onShopDestroy(ShopDestroyedEvent event){
  double refundPrice=Properties.SHOP_REFUND_PRICE;
  if (event.getDestroyer() == null || Permission.has(event.getDestroyer(),NOFEE) || refundPrice == 0) {
    return;
  }
  UUID owner=NameManager.getUUID(event.getSign().getLine(NAME_LINE));
  CurrencyAddEvent currencyEvent=new CurrencyAddEvent(BigDecimal.valueOf(refundPrice),owner,event.getSign().getWorld());
  ChestShop.callEvent(currencyEvent);
  String message=Messages.SHOP_REFUNDED.replace("String_Node_Str",Economy.formatBalance(refundPrice));
  event.getDestroyer().sendMessage(Messages.prefix(message));
}

Fixed version (ground truth):
@EventHandler(priority=EventPriority.MONITOR) public static void onShopDestroy(ShopDestroyedEvent event){
  double refundPrice=Properties.SHOP_REFUND_PRICE;
  if (event.getDestroyer() == null || Permission.has(event.getDestroyer(),NOFEE) || refundPrice == 0) {
    return;
  }
  String ownerName=NameManager.getFullUsername(event.getSign().getLine(NAME_LINE));
  UUID owner=NameManager.getUUID(ownerName);
  CurrencyAddEvent currencyEvent=new CurrencyAddEvent(BigDecimal.valueOf(refundPrice),owner,event.getSign().getWorld());
  ChestShop.callEvent(currencyEvent);
  String message=Messages.SHOP_REFUNDED.replace("String_Node_Str",Economy.formatBalance(refundPrice));
  event.getDestroyer().sendMessage(Messages.prefix(message));
}
Program: 178097
Project: 178097
Buggy source:
public static UUID getUUID(String username){
  if (usernameToUUID.containsKey(username)) {
    return usernameToUUID.get(username);
  }
  String shortenedName=NameUtil.stripUsername(username);
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",shortenedName).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
  if (account == null) {
    UUID uuid=Bukkit.getOfflinePlayer(username).getUniqueId();
    usernameToUUID.put(username,uuid);
    return uuid;
  }
  UUID uuid=account.getUuid();
  if (uuid != null) {
    usernameToUUID.put(username,uuid);
  }
  return uuid;
}

Fixed version (ground truth):
public static UUID getUUID(String username){
  if (usernameToUUID.containsKey(username)) {
    return usernameToUUID.get(username);
  }
  String shortenedName=NameUtil.stripUsername(username);
  Account account=null;
  try {
    account=accounts.queryBuilder().selectColumns("String_Node_Str").where().eq("String_Node_Str",shortenedName).queryForFirst();
  }
 catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
  if (account == null) {
    UUID uuid=Bukkit.getOfflinePlayer(username).getUniqueId();
    usernameToUUID.put(username,uuid);
    return uuid;
  }
  UUID uuid=account.getUuid();
  if (uuid != null) {
    usernameToUUID.put(account.getName(),uuid);
  }
  return uuid;
}
Program: 178098
Project: 178098
Buggy source:
/** 
 * Gets the price from the text
 * @param text      Text to check
 * @param indicator Price indicator (for example, B for buy)
 * @return price
 */
public static double get(String text,char indicator){
  String[] split=text.replace("String_Node_Str","String_Node_Str").toLowerCase().split("String_Node_Str");
  String character=String.valueOf(indicator).toLowerCase();
  for (  String part : split) {
    if (!part.contains(character)) {
      continue;
    }
    part=part.replace(character,"String_Node_Str");
    if (part.equals(FREE_TEXT)) {
      return FREE;
    }
    if (NumberUtil.isDouble(part)) {
      double price=Double.valueOf(part);
      if (price <= 0) {
        return NO_PRICE;
      }
 else {
        return price;
      }
    }
  }
  return NO_PRICE;
}

Fixed version (ground truth):
/** 
 * Gets the price from the text
 * @param text      Text to check
 * @param indicator Price indicator (for example, B for buy)
 * @return price
 */
public static double get(String text,char indicator){
  String[] split=text.replace("String_Node_Str","String_Node_Str").toLowerCase().split("String_Node_Str");
  String character=String.valueOf(indicator).toLowerCase();
  for (  String part : split) {
    if (!part.contains(character)) {
      continue;
    }
    part=part.replace(character,"String_Node_Str");
    if (part.equals(FREE_TEXT)) {
      return FREE;
    }
    if (NumberUtil.isDouble(part)) {
      double price=Double.valueOf(part);
      if (Double.isInfinite(price) || price <= 0) {
        return NO_PRICE;
      }
 else {
        return price;
      }
    }
  }
  return NO_PRICE;
}
Program: 178099
Project: 178099
Buggy source:
/** 
 * Checks if the string is a valid price
 * @param text Text to check
 * @return Is the string a valid price
 */
public static boolean isPrice(String text){
  if (NumberUtil.isFloat(text)) {
    return true;
  }
  return text.trim().equalsIgnoreCase(FREE_TEXT);
}

Fixed version (ground truth):
/** 
 * Checks if the string is a valid price
 * @param text Text to check
 * @return Is the string a valid price
 */
public static boolean isPrice(String text){
  if (NumberUtil.isDouble(text)) {
    return true;
  }
  return text.trim().equalsIgnoreCase(FREE_TEXT);
}
Program: 178100
Project: 178100
Buggy source:
/** 
 * Gets the item code for this item
 * @param item Item
 * @return Item code for this item
 */
public String getItemCode(ItemStack item){
  try {
    ItemStack clone=item.clone();
    clone.setAmount(1);
    String code=Base64.encodeObject(yaml.dump(clone));
    table.insertRow("String_Node_Str" + code + '\'');
    int id=Integer.parseInt(table.getRow("String_Node_Str" + code + '\'').get("String_Node_Str"));
    return Base62.encode(id);
  }
 catch (  IOException e) {
    e.printStackTrace();
    return null;
  }
catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
}

Fixed version (ground truth):
/** 
 * Gets the item code for this item
 * @param item Item
 * @return Item code for this item
 */
public String getItemCode(ItemStack item){
  try {
    ItemStack clone=new ItemStack(item);
    clone.setAmount(1);
    String code=Base64.encodeObject(yaml.dump(clone));
    table.insertRow("String_Node_Str" + code + '\'');
    int id=Integer.parseInt(table.getRow("String_Node_Str" + code + '\'').get("String_Node_Str"));
    return Base62.encode(id);
  }
 catch (  IOException e) {
    e.printStackTrace();
    return null;
  }
catch (  SQLException e) {
    e.printStackTrace();
    return null;
  }
catch (  IllegalArgumentException e) {
    return null;
  }
}
Program: 178101
Project: 178101
Buggy source:
@EventHandler public void onCurrencyHoldCheck(CurrencyHoldEvent event){
  EconomyResponse response=provider.depositPlayer(event.getAccount(),event.getWorld().getName(),event.getDoubleAmount());
  if (!response.transactionSuccess()) {
    event.canHold(false);
  }
  provider.withdrawPlayer(event.getAccount(),event.getWorld().getName(),event.getDoubleAmount());
}

Fixed version (ground truth):
@EventHandler public void onCurrencyHoldCheck(CurrencyHoldEvent event){
  if (event.getAccount().isEmpty() || !transactionCanFail()) {
    return;
  }
  if (!provider.hasAccount(event.getAccount(),event.getWorld().getName())) {
    event.canHold(false);
    return;
  }
  EconomyResponse response=provider.depositPlayer(event.getAccount(),event.getWorld().getName(),event.getDoubleAmount());
  if (!response.transactionSuccess()) {
    event.canHold(false);
    return;
  }
  provider.withdrawPlayer(event.getAccount(),event.getWorld().getName(),event.getDoubleAmount());
}
Program: 178102
Project: 178102
Buggy source:
@EventHandler public static void onPlayerTeleport(PlayerTeleportEvent event){
  event.getPlayer().closeInventory();
}

Fixed version (ground truth):
@EventHandler public static void onPlayerTeleport(PlayerTeleportEvent event){
  if (!event.getPlayer().isConversing()) {
    event.getPlayer().closeInventory();
  }
}
Program: 178103
Project: 178103
Buggy source:
@EventHandler public static void onPlayerTeleport(PlayerTeleportEvent event){
  if (!event.getPlayer().isConversing()) {
    event.getPlayer().closeInventory();
  }
}

Fixed version (ground truth):
@EventHandler public static void onPlayerTeleport(PlayerTeleportEvent event){
  if (event.getPlayer().getOpenInventory().getType() != InventoryType.CRAFTING) {
    event.getPlayer().closeInventory();
  }
}
Program: 178104
Project: 178104
Buggy source:
private void setupDB(){
  Database DB;
  DB=new Database(this){
    protected java.util.List<Class<?>> getDatabaseClasses(){
      List<Class<?>> list=new ArrayList<Class<?>>();
      list.add(Transaction.class);
      return list;
    }
  }
;
  FileConfiguration config=YamlConfiguration.loadConfiguration(new File("String_Node_Str"));
  DB.initializeDatabase(config.getString("String_Node_Str"),config.getString("String_Node_Str"),config.getString("String_Node_Str"),config.getString("String_Node_Str"),config.getString("String_Node_Str"));
  database=DB.getDatabase();
  scheduleTask(new Queue(),200L,200L);
}

Fixed version (ground truth):
private void setupDB(){
  loadFile(new File("String_Node_Str"));
  Database DB;
  DB=new Database(this){
    protected java.util.List<Class<?>> getDatabaseClasses(){
      List<Class<?>> list=new ArrayList<Class<?>>();
      list.add(Transaction.class);
      return list;
    }
  }
;
  FileConfiguration config=YamlConfiguration.loadConfiguration(new File("String_Node_Str"));
  DB.initializeDatabase(config.getString("String_Node_Str"),config.getString("String_Node_Str"),config.getString("String_Node_Str"),config.getString("String_Node_Str"),config.getString("String_Node_Str"));
  database=DB.getDatabase();
  scheduleTask(new Queue(),200L,200L);
}
Program: 178105
Project: 178105
Buggy source:
@EventHandler(priority=EventPriority.LOW) public static void onPreBuyTransaction(PreTransactionEvent event){
  if (event.isCancelled() || event.getTransactionType() != BUY) {
    return;
  }
  Player client=event.getClient();
  String clientName=client.getName();
  ItemStack[] stock=event.getStock();
  double price=event.getPrice();
  double pricePerItem=event.getPrice() / InventoryUtil.countItems(stock);
  double walletMoney=Economy.getBalance(clientName);
  if (!Economy.hasEnough(clientName,price)) {
    int amountAffordable=getAmountOfAffordableItems(walletMoney,pricePerItem);
    if (amountAffordable < 1) {
      event.setCancelled(CLIENT_DOES_NOT_HAVE_ENOUGH_MONEY);
      return;
    }
    event.setPrice(amountAffordable * pricePerItem);
    event.setStock(getCountedItemStack(stock,amountAffordable));
  }
  String seller=event.getOwner().getName();
  if (Economy.transactionCanFail()) {
    if (Economy.add(seller,price)) {
      Economy.subtract(seller,price);
    }
 else {
      event.setCancelled(SHOP_DEPOSIT_FAILED);
      return;
    }
  }
  stock=event.getStock();
  if (!InventoryUtil.hasItems(stock,event.getOwnerInventory())) {
    ItemStack[] itemsHad=getItems(stock,event.getOwnerInventory());
    int posessedItemCount=InventoryUtil.countItems(itemsHad);
    if (posessedItemCount <= 0) {
      event.setCancelled(NOT_ENOUGH_STOCK_IN_CHEST);
      return;
    }
    event.setPrice(pricePerItem * posessedItemCount);
    event.setStock(itemsHad);
  }
}

Fixed version (ground truth):
@EventHandler(priority=EventPriority.LOW) public static void onPreBuyTransaction(PreTransactionEvent event){
  if (event.isCancelled() || event.getTransactionType() != BUY) {
    return;
  }
  Player client=event.getClient();
  String clientName=client.getName();
  ItemStack[] stock=event.getStock();
  double price=event.getPrice();
  double pricePerItem=event.getPrice() / InventoryUtil.countItems(stock);
  double walletMoney=Economy.getBalance(clientName);
  if (!Economy.hasEnough(clientName,price)) {
    int amountAffordable=getAmountOfAffordableItems(walletMoney,pricePerItem);
    if (amountAffordable < 1) {
      event.setCancelled(CLIENT_DOES_NOT_HAVE_ENOUGH_MONEY);
      return;
    }
    event.setPrice(amountAffordable * pricePerItem);
    event.setStock(getCountedItemStack(stock,amountAffordable));
  }
  String seller=event.getOwner().getName();
  if (!Economy.canHold(seller,price)) {
    event.setCancelled(SHOP_DEPOSIT_FAILED);
    return;
  }
  stock=event.getStock();
  if (!InventoryUtil.hasItems(stock,event.getOwnerInventory())) {
    ItemStack[] itemsHad=getItems(stock,event.getOwnerInventory());
    int posessedItemCount=InventoryUtil.countItems(itemsHad);
    if (posessedItemCount <= 0) {
      event.setCancelled(NOT_ENOUGH_STOCK_IN_CHEST);
      return;
    }
    event.setPrice(pricePerItem * posessedItemCount);
    event.setStock(itemsHad);
  }
}