/* * Set up an auction house for the player */ public AuctionHouse(Player player) { try { this.page = 0; this.player = player; this.database = new Database(); this.database.getConnection(); ids = new ArrayList<Integer>(); setupStaticItems(); // Add listener for next page RPGMaker plugin = RPGMaker.getPlugin(RPGMaker.class); plugin.getServer().getPluginManager().registerEvents(new AuctionHouseListener(), plugin); } catch (SQLException e) { e.printStackTrace(); } }
@EventHandler public void NextPageEvent(InventoryClickEvent event) { // Get next items when next page item is clicked if (event.getInventory().getTitle().equals("Auction House")) { if (event.getClick().equals(ClickType.SHIFT_LEFT)) { Plugin plugin = RPGMaker.getPlugin(RPGMaker.class); boolean flag = true; Inventory inv = null; if (event.getCurrentItem().equals(nextpage)) { // Get next page player.sendMessage("Getting next page"); page++; ids.clear(); inv = getInventory(); } else if (event.getCurrentItem().equals(sortname)) { sortingType = 2; ids.clear(); sortByName(); } else if (event.getCurrentItem().equals(sortnew)) { sortingType = 0; ids.clear(); inv = sortByNew(); } else if (event.getCurrentItem().equals(sortold)) { sortingType = 1; ids.clear(); inv = sortByOld(); } else { flag = false; player.sendMessage("You are trying to buy something"); // Real time updates? -> need to update every viewer of AH ItemStack item = event.getCurrentItem(); if (!(item.getType().equals(Material.AIR))) { if (getCost(item) == 0) { event.setCancelled(true); return; } item = removeAuctionLore(item); int id = ids.get(event.getRawSlot()); try { String Query = "delete from `auctionhouse` where `ID` = " + id + ";"; database.Query = database.connection.prepareStatement(Query); database.Query.execute(); player.getInventory().addItem(item); player.closeInventory(); // for now until I handle realtime updates // and economy } catch (SQLException e) { e.printStackTrace(); } } } final Inventory savedInv = inv; final Inventory oldInv = event.getInventory(); if (flag) { Bukkit.getServer() .getScheduler() .scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { // player.closeInventory(); oldInv.setContents(savedInv.getContents()); } }, 1); } } event.setCancelled(true); } }