/** @unimplemented FIXME */
  public static Container callInventoryOpenEvent(EntityPlayer player, Container container) {
    // if (player.craftingInventory != player.inventory) { // fire INVENTORY_CLOSE if one already
    // open
    //    player.netServerHandler.handleContainerClose(new
    // Packet101CloseWindow(player.activeContainer.windowId));
    // }

    BukkitServer server = (BukkitServer) Bukkit.getServer();
    BukkitPlayer craftPlayer = (BukkitPlayer) getBukkitEntity(player);
    // player.craftingInventory.(container, craftPlayer);
    int i = 0;
    InventoryBasic inv = new InventoryBasic("", container.getInventory().size());
    for (Object j : container.inventoryItemStacks) {
      net.minecraft.src.ItemStack v = (net.minecraft.src.ItemStack) j;
      inv.setInventorySlotContents(i, v);
      i++;
    }
    InventoryOpenEvent event =
        new InventoryOpenEvent(
            new BukkitInventoryView(
                (HumanEntity) getBukkitEntity(player), new BukkitInventory(inv), container));
    server.getPluginManager().callEvent(event);

    if (event.isCancelled()) {
      container.setPlayerIsPresent(craftPlayer.getHandle(), false);
      return null;
    }

    return container;
  }
 @EventHandler
 public void onEnderChestOpen(InventoryOpenEvent e) {
   if (!(e.getPlayer() instanceof Player)) return;
   Player p = (Player) e.getPlayer();
   Inventory i = e.getInventory();
   if (i.getType() != InventoryType.ENDER_CHEST) return;
   Inventory ender = getEnderInventory(p);
   if (ender == null || ender.getContents().length < 1) return;
   i.setContents(ender.getContents());
 }
예제 #3
0
 @EventHandler(ignoreCancelled = true)
 public void onPlayerOpensInv(InventoryOpenEvent event) {
   if (dEntity.isNPC(event.getPlayer())) {
     return;
   }
   inventory = dInventory.mirrorBukkitInventory(event.getInventory());
   this.event = event;
   cancelled = event.isCancelled();
   fire();
   event.setCancelled(cancelled);
 }
예제 #4
0
 @EventHandler
 public void openInventory(InventoryOpenEvent e) {
   if (BattleArena.inArena((Player) e.getPlayer())) {
     e.setCancelled(true);
   }
   List<Player> inProgress = ma.getArenaMaster().getAllPlayers();
   for (Player p2 : inProgress) {
     if (e.getPlayer() == p2) {
       e.setCancelled(true);
     }
   }
 }
예제 #5
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onInventoryOpen(InventoryOpenEvent event) {
   String playerName = event.getPlayer().getName();
   if (ultimateGames.getPlayerManager().isPlayerInArena(playerName)) {
     Arena arena = ultimateGames.getPlayerManager().getPlayerArena(playerName);
     if (arena.getStatus() == ArenaStatus.RUNNING) {
       arena.getGame().getGamePlugin().onInventoryOpen(arena, event);
     } else {
       event.setCancelled(true);
     }
   } else if (ultimateGames.getPlayerManager().isPlayerSpectatingArena(playerName)) {
     event.setCancelled(true);
   }
 }
  @EventHandler
  public void onInventoryOpen(InventoryOpenEvent event) {
    Player player = (Player) event.getPlayer();
    Mage apiMage = controller.getRegisteredMage(player);

    if (apiMage == null || !(apiMage instanceof com.elmakers.mine.bukkit.magic.Mage)) return;
    com.elmakers.mine.bukkit.magic.Mage mage = (com.elmakers.mine.bukkit.magic.Mage) apiMage;

    Wand wand = mage.getActiveWand();
    GUIAction gui = mage.getActiveGUI();
    if (wand != null && gui == null) {
      // NOTE: The type will never actually be CRAFTING, at least for now.
      // But we can hope for server-side player inventory open notification one day, right?
      // Anyway, check for opening another inventory and close the wand.
      if (event.getView().getType() != InventoryType.CRAFTING) {
        if (wand.getMode() == WandMode.INVENTORY || !wand.isInventoryOpen()) {
          wand.deactivate();
        }
      }
    }
  }
예제 #7
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onInventoryOpenEvent(InventoryOpenEvent e) {
   Player player = (Player) e.getPlayer();
   if (e.isCancelled()) {
     return;
   }
   if (vanishNoPacket.isPlayerInvisible(player)) {
     return;
   }
   Block block;
   if (e.getInventory().getHolder() instanceof Chest) {
     Chest chest = (Chest) e.getInventory().getHolder();
     block = chest.getBlock();
   } else if (e.getInventory().getHolder() instanceof DoubleChest) {
     DoubleChest chest = (DoubleChest) e.getInventory().getHolder();
     block = chest.getLocation().getBlock();
   } else {
     return;
   }
   Set<Snitch> snitches = snitchManager.findSnitches(player.getWorld(), player.getLocation());
   for (Snitch snitch : snitches) {
     if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
       if (checkProximity(snitch, player.getName())) {
         plugin.getJaLogger().logUsed(snitch, player, block);
       }
     }
   }
 }
예제 #8
0
 @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
 public void onInventoryOpen(final InventoryOpenEvent e) {
   if (e.getView() instanceof LocaleInventory) return;
   if (e.getInventory().getType() != InventoryType.CHEST || !useLocaleInv) {
     Inventory in = e.getInventory();
     Iterator<ItemStack> it = in.iterator();
     String locale = Locale.getPlayerLocale((Player) e.getPlayer());
     try {
       while (it.hasNext()) {
         ItemStack item = it.next();
         if (ItemManager.toRPGItem(item) != null) RPGItem.updateItem(item, locale);
       }
     } catch (ArrayIndexOutOfBoundsException ex) {
       // Fix for the bug with anvils in craftbukkit
     }
   } else if (useLocaleInv) {
     LocaleInventory localeInv = new LocaleInventory((Player) e.getPlayer(), e.getView());
     e.setCancelled(true);
     e.getPlayer().openInventory(localeInv);
     localeInventories.add(localeInv);
   }
 }
예제 #9
0
  /**
   * Plant Conditions:.
   *
   * <pre>
   * 1. The player that triggered this event is in fact the bomb carrier.
   * 2. The player is NOT at his own base.
   * 3. The DetonationTimer does not exist yet.
   * - If so, start the Plant Timer: It takes about 5 to 10 seconds to plant the bomb.
   * - If not, cancel the InventoryOpenEvent.
   * </pre>
   */
  @Override
  public boolean isPlayerPlanting(InventoryOpenEvent e) {

    Player eplayer = (Player) e.getPlayer();
    int eTeamID = getTeam(eplayer).getId();
    DetonationTimer detTimer = getDetonationTimer();

    plugin.debug.log("*** PLANT CONDITIONS: ***");
    plugin.debug.log("carrier != null : " + (carrier != null));
    plugin.debug.log(
        "EventPlayer.getName().equals(carrier) : " + eplayer.getName().equalsIgnoreCase(carrier));
    boolean areTheyAwayFromHomeBase = teamBases.get(eTeamID).distance(eplayer.getLocation()) > 9;
    plugin.debug.log("Are they sufficiently away from their own base ?" + areTheyAwayFromHomeBase);
    plugin.debug.log("The detonation timer is NOT already running : " + (detTimer == null));
    if (carrier != null
        && eplayer.getName().equalsIgnoreCase(carrier)
        && teamBases.get(eTeamID).distance(eplayer.getLocation()) > 9
        && detTimer == null) {
      return true;
    }
    return false;
  }
예제 #10
0
  /**
   * Defuse Conditions:.
   *
   * <pre>
   * 1. A DetonationTimer exists = running
   * 2. The Defusers team is different than the carrier's team.
   * 3. The Defuser is at his own base.
   * - If so, start a DefuseTimer for this player.
   * - If not, check the plant conditions.
   * </pre>
   */
  @Override
  public boolean isPlayerDefusing(InventoryOpenEvent e) {

    Player eplayer = (Player) e.getPlayer();
    int eTeamID = getTeam(eplayer).getId();
    int cTeamID = getTeam(Bukkit.getPlayer(carrier)).getId();

    DetonationTimer detTimer = getDetonationTimer();
    plugin.debug.log("*** DEFUSE CONDITIONS: ***");
    plugin.debug.log("defuseTimer is running = " + (detTimer != null));
    plugin.debug.log("eTeamID != cTeamID : " + (eTeamID != cTeamID));
    // Two different ways to check the same thing:
    boolean isPlayerAtTheirOwnBase = teamBases.get(eTeamID).distance(eplayer.getLocation()) < 6;
    boolean isPlayerAtBombLocation =
        (detTimer == null) ? false : eplayer.getLocation().distance(detTimer.getBombLocation()) < 6;
    plugin.debug.log(
        "Are they at the correct base ? (where the bomb was planted) : " + isPlayerAtBombLocation);
    plugin.debug.log("Are they at their own base ?" + isPlayerAtTheirOwnBase);

    if (detTimer != null && eTeamID != cTeamID && isPlayerAtBombLocation) {
      return true;
    }
    return false;
  }
예제 #11
0
  @EventHandler
  public void openInventory(InventoryOpenEvent ioe) {
    if (!(ioe.getPlayer() instanceof Player)) {
      return;
    }

    Player player = (Player) ioe.getPlayer();
    Game game = Main.getInstance().getGameManager().getGameOfPlayer(player);

    if (game == null) {
      return;
    }

    if (game.getState() != GameState.RUNNING) {
      return;
    }

    if (ioe.getInventory().getType() == InventoryType.ENCHANTING
        || ioe.getInventory().getType() == InventoryType.BREWING
        || (ioe.getInventory().getType() == InventoryType.CRAFTING
            && !Main.getInstance().getBooleanConfig("allow-crafting", false))) {
      ioe.setCancelled(true);
      return;
    } else if (ioe.getInventory().getType() == InventoryType.CRAFTING
        && Main.getInstance().getBooleanConfig("allow-crafting", false)) {
      return;
    }

    if (game.isSpectator(player)) {
      if (ioe.getInventory().getName().equals(Main._l("ingame.spectator"))) {
        return;
      }

      ioe.setCancelled(true);
    }

    if (ioe.getInventory().getHolder() == null) {
      return;
    }

    if (game.getRegion().getInventories().contains(ioe.getInventory())) {
      return;
    }

    InventoryHolder holder = ioe.getInventory().getHolder();
    for (Class<?> interfaze : holder.getClass().getInterfaces()) {

      if (interfaze.equals(BlockState.class)) {
        game.getRegion().addInventory(ioe.getInventory());
        return;
      }

      for (Class<?> interfaze2 : interfaze.getInterfaces()) {
        if (interfaze2.equals(BlockState.class)) {
          game.getRegion().addInventory(ioe.getInventory());
          return;
        }
      }
    }
  }
예제 #12
0
 @Override
 public ScriptEntryData getScriptEntryData() {
   // TODO: Store the player / npc?
   return new BukkitScriptEntryData(
       event != null ? dEntity.getPlayerFrom(event.getPlayer()) : null, null);
 }
예제 #13
0
 @Override
 public void destroy() {
   InventoryOpenEvent.getHandlerList().unregister(this);
 }
예제 #14
0
 public void onInventoryOpen(InventoryOpenEvent event) {
   Player p = (Player) event.getPlayer();
   if (p.openInventory(qw)) {}
 }
  @EventHandler(priority = EventPriority.LOWEST)
  public void onInventoryOpenEvent(InventoryOpenEvent event) {
    if (event.isCancelled()
        || event.getInventory() == null
        || event.getInventory().getHolder() == null) return;

    final Player player = (Player) event.getPlayer();
    final InventoryHolder h = event.getInventory().getHolder();

    if (h instanceof Chest
        || h instanceof DoubleChest
        || h instanceof Furnace
        || h instanceof Dispenser) {
      if (player.getWorld() != plugin.getIslandWorld()) return;
      if (player.isOp()) return;
      if (player.hasPermission("islandworld.bypass.island")) return;

      Location loc = player.getLocation();
      if (event.getInventory().getHolder() instanceof Chest) {
        final Chest chest = (Chest) event.getInventory().getHolder();
        loc = chest.getLocation();
      } else if (event.getInventory().getHolder() instanceof Furnace) {
        final Furnace fur = (Furnace) event.getInventory().getHolder();
        loc = fur.getLocation();
      } else if (event.getInventory().getHolder() instanceof DoubleChest) {
        final DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
        loc = chest.getLocation();
      } else if (event.getInventory().getHolder() instanceof Dispenser) {
        final Dispenser disp = (Dispenser) event.getInventory().getHolder();
        loc = disp.getLocation();
      }

      if (!(plugin.canBuildOnLocation(player, loc))) event.setCancelled(true);
    }

    plugin.debug(
        "Event :"
            + event.getEventName()
            + ", class: "
            + h.getClass()
            + ", cancelled:"
            + event.isCancelled());
  }