コード例 #1
0
  public InventoryEvents(Main plugin) {
    trademanager = TradeManager.getInstance();

    main = plugin;

    Bukkit.getScheduler()
        .scheduleSyncRepeatingTask(
            main,
            new Runnable() {
              @Override
              public void run() {
                for (UUID pUUID : tradeCountdown.keySet()) {
                  Player p = Bukkit.getPlayer(pUUID);
                  Integer amount = tradeCountdown.get(p);
                  Inventory inv = p.getInventory();

                  ItemStack divider = new ItemStack(Material.FENCE, 1);
                  ItemMeta im = divider.getItemMeta();
                  im.setDisplayName(ChatColor.GRAY + "" + ChatColor.BOLD + "<--");
                  ArrayList<String> newLore = new ArrayList<String>();
                  newLore.add("Place your items on the left");
                  im.setLore(newLore);
                  divider.setItemMeta(im);

                  inv.setItem((amount * 9), divider);
                }
              }
            },
            20,
            20);
  }
コード例 #2
0
  @EventHandler
  public void ItemMoveEvent(InventoryClickEvent event) {
    Inventory inv = event.getClickedInventory();

    if (event.getClickedInventory() == null) {
      return;
    }
    if (!event
        .getClickedInventory()
        .getName()
        .equals(ChatColor.GREEN + "" + ChatColor.BOLD + "PLACE ITEMS BELOW")) {
      return;
    }

    trademanager.updateTradeInv((Player) event.getWhoClicked());
    // trademanager.loadNewInv(inv.getViewers());
  }
コード例 #3
0
  @EventHandler
  public void InvCloseEvent(InventoryCloseEvent event) {
    Inventory closedInv = event.getInventory();
    Player p = (Player) event.getPlayer();
    if (closedInv.getName().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "PLACE ITEMS BELOW")) {
      TradeStats tradestat = null;
      if (trademanager.getTradeStatFromTradingWith(p) != null) {
        tradestat = trademanager.getTradeStatFromTradingWith(p);
      } else {
        tradestat = trademanager.getTradeStatFromWhoSent(p);
      }

      if (tradestat == null) {
        Bukkit.getLogger().warning("TradeStat is null for InvCloseEvent.");
        return;
      }

      if (closingTrade.keySet().contains(p) || closingTrade.values().contains(p)) {
        System.out.println("yes");
        return;
      }

      Player whoSentTrade = tradestat.getWhoSentTrade();
      Player whoTradingWith = tradestat.getWhoTradingWith();

      for (ItemStack item : tradestat.getSentTradeItems()) {
        whoSentTrade.getInventory().addItem(item);
      }
      for (ItemStack item : tradestat.getTradingWithItems()) {
        whoTradingWith.getInventory().addItem(item);
      }

      //            closingTrade.add(p, );
      Messages.Error(p, "You have cancelled the trade.");
      //            if (whoSentTrade.equals(p)) {
      //                Messages.Error(whoTradingWith, p.getDisplayName() + " has cancelled the
      // trade.");
      //                whoTradingWith.closeInventory();
      //                closingTrade.put(p, whoTradingWith);
      //            } else {
      //                Messages.Error(whoSentTrade, p.getDisplayName() + " has cancelled the
      // trade.");
      //                whoSentTrade.closeInventory();
      //                closingTrade.put(p, whoSentTrade);
      //            }
      trademanager.clearTradeFromTradeStat(tradestat);
      final TradeStats tradestatfinal = tradestat;
      Bukkit.getScheduler()
          .scheduleSyncDelayedTask(
              main,
              new Runnable() {
                @Override
                public void run() {
                  //                    for (Player playa : closingTrade.keySet()) {
                  //                        if (playa == p) {
                  //                            closingTrade.remove(p);
                  //                            break;
                  //                        } else if (closingTrade.get(playa).equals(p)) {
                  //                            closingTrade.remove(playa);
                  //                            break;
                  //                        }
                  //                    }
                  if (whoSentTrade.equals(p)) {
                    Messages.Error(
                        whoTradingWith, p.getDisplayName() + " has cancelled the trade.");
                    whoTradingWith.closeInventory();
                    System.out.println("closed2");
                    // closingTrade.put(p, whoTradingWith);
                  } else {
                    Messages.Error(whoSentTrade, p.getDisplayName() + " has cancelled the trade.");
                    whoSentTrade.closeInventory();
                    System.out.println("closed1");
                    // closingTrade.put(p, whoSentTrade);
                  }
                }
              },
              20L);
    }
  }