@EventHandler(priority = EventPriority.LOWEST)
 public void onPlayerInteract(PlayerInteractEvent event) {
   if (PConfManager.getPValBoolean(event.getPlayer(), "jailed")) event.setCancelled(true);
   Action act = event.getAction();
   if (act.equals(Action.PHYSICAL)) return;
   ItemStack id = event.getItem();
   if (id == null) return;
   int idn = id.getTypeId();
   if (idn == 0) return;
   List<String> cmds = PConfManager.getPValStringList(event.getPlayer(), "assign." + idn);
   if (cmds == null) return;
   for (String s : cmds) {
     if (s.toLowerCase().trim().startsWith("c:")) event.getPlayer().chat(s.trim().substring(2));
     else event.getPlayer().performCommand(s.trim());
   }
 }
  @Override
  public boolean playerInteract(PlayerInteractEvent event) {

    Action action = event.getAction();
    Player player = event.getPlayer();
    SuperNPlayer snplayer = SuperNManager.get(player);
    Material itemMaterial = event.getMaterial();

    if (action.equals(Action.LEFT_CLICK_AIR) || action.equals(Action.LEFT_CLICK_BLOCK)) {
      if (itemMaterial.equals(Material.BOWL)) {
        remoteDonations(player);
        return true;
      }
    }

    return false;
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void kitSelector(PlayerInteractEvent evt) {
    Action a = evt.getAction();
    if (a.equals(Action.LEFT_CLICK_AIR) || a.equals(Action.LEFT_CLICK_BLOCK)) {
      return;
    }

    ItemStack i = evt.getPlayer().getItemInHand();
    if (i.getType() == Material.AIR) {
      return;
    }

    if (!i.hasItemMeta()) {
      return;
    }

    String im = i.getItemMeta().getDisplayName();
    String sel = InvUtil.getMasteryItem().getItemMeta().getDisplayName();

    if (im == null || sel == null) {
      return;
    }

    if (!im.equals(sel)) { // Make sure the item they're holding is the kit item.
      return;
    }

    Player p = evt.getPlayer();
    if (Room.PLAYERS.containsKey(p)) { // If the player is in a game and has the perk selector.
      if (Room.ROOMS.get(Room.PLAYERS.get(p)).isGameInProgress()) {
        p.getInventory().removeItem(i); // Remove it
      } else {
        p.sendMessage(ChatUtil.basicErrorMsg("You cannot change masteries while in queue."));
      }

      return;
    }

    MasteryMenu.menu.open(p);
    p.playSound(p.getLocation(), Sound.ITEM_BREAK, 1.0F, 0.3F);
  }
 private Object cycle(Object[] types, int ordinal, Action direction) {
   if (direction.equals(Action.LEFT_CLICK_BLOCK)) {
     ordinal++;
     if (ordinal == types.length) {
       ordinal = 0;
     }
   } else {
     ordinal--;
     if (ordinal < 0) {
       ordinal = types.length - 1;
     }
   }
   return types[ordinal];
 }
Beispiel #5
0
  // Event
  @EventHandler
  public void pInteract(PlayerInteractEvent event) {
    // Store player, action, block, world, location
    Player player = event.getPlayer();
    Action action = event.getAction();
    Block block = event.getClickedBlock();
    World world;
    try {
      world = block.getWorld();
    } catch (NullPointerException npe) {
      return;
    }
    Location loc = block.getLocation();

    // Keep players from clicking the points
    if (action.equals(Action.RIGHT_CLICK_BLOCK) || action.equals(Action.LEFT_CLICK_BLOCK)) {
      // Check if its a gold or iron plate
      if (block.getType().equals(Material.GOLD_PLATE)
          || block.getType().equals(Material.IRON_PLATE)) {
        // Check if this blocks coords match coords in the file
        File file = new File(plugin.getDataFolder() + "/worldData/" + world.getName() + ".yml");
        FileConfiguration config = YamlConfiguration.loadConfiguration(file);
        for (String key : config.getConfigurationSection("").getKeys(false)) {
          Point pointInfo = new Point(plugin, world, key);
          Location keyLoc = pointInfo.getLocation();
          if (keyLoc.equals(loc)) {
            // Make sure it exists
            if (pointInfo.getExists()) {
              event.setCancelled(true);
              return;
            }
          }
        }
      }
      // Else player stepped on it
    } else if (action.equals(Action.PHYSICAL)) {
      PlayerInfo pInfo = new PlayerInfo(player, plugin);
      // Check if iron or gold
      // Gold
      if (block.getType().equals(Material.GOLD_PLATE)) {
        // See if the coords match the Start or Finish for this world
        // ***** Start *****
        Point pointInfo = new Point(plugin, world, "Start");
        if (pointInfo.getLocation().equals(loc)) {
          if (pointInfo.getExists()) {
            // Check if the player has a cooldown
            if (!pInfo.getHasStartCD()) {
              // Check for finish point
              Point point = new Point(plugin, world, "Finish");
              if (point.getExists()) {
                pInfo.setStartTime(System.currentTimeMillis());
                pInfo.setLastCP("null");
                pInfo.setHasStartCD(true);
                pInfo.setHasFinishCD(false);
                // Check if started
                if (pInfo.getHasStarted()) {
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour]"
                          + ChatColor.GOLD
                          + " Your time has been reset! Good luck!");
                } else {
                  pInfo.setHasStarted(true);
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour]"
                          + ChatColor.GOLD
                          + " The timer has started! Good luck!");
                }
                // Finish doesn't exist
              } else {
                player.sendMessage(
                    ChatColor.GREEN
                        + ""
                        + ChatColor.BOLD
                        + "[iParkour]"
                        + ChatColor.RED
                        + " There has to be a Finish point before you can start!");
                pInfo.setHasStartCD(true);
              }
            }
          } // Else do nothing

          // ***** Finish *****
        } else {
          pointInfo = new Point(plugin, world, "Finish");
          if (pointInfo.getLocation().equals(loc)) {
            // Check if exists
            if (pointInfo.getExists()) {
              // Check for Start
              Point point = new Point(plugin, world, "Start");
              if (point.getExists()) {
                // Check if the player has started
                if (pInfo.getHasStarted()) {
                  // Check for finish cooldown
                  if (!pInfo.getHasFinishCD()) {
                    Long endTime = System.currentTimeMillis();
                    pInfo.checkForRecord(endTime);
                    pInfo.setHasStarted(false);
                    pInfo.setHasStartCD(false);
                    pInfo.setHasFinishCD(true);
                    pInfo.setLastCP("null");
                  }
                } else {
                  if (!pInfo.getHasFinishCD()) {
                    pInfo.setHasFinishCD(true);
                    player.sendMessage(
                        ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + "[iParkour] "
                            + ChatColor.GOLD
                            + "You have to start at the beginning!");
                  }
                }

                // Start doesn't exist
              } else {
                player.sendMessage(
                    ChatColor.GREEN
                        + ""
                        + ChatColor.BOLD
                        + "[iParkour]"
                        + ChatColor.RED
                        + " There has to be a Start point before you can finish!");
                pInfo.setHasStartCD(true);
              }
            } // Else do nothing
          }
        }

        // Iron
      } else if (block.getType().equals(Material.IRON_PLATE)) {
        File file = new File(plugin.getDataFolder() + "/worldData/" + world.getName() + ".yml");
        FileConfiguration config = YamlConfiguration.loadConfiguration(file);
        for (String key : config.getConfigurationSection("").getKeys(false)) {
          // If start or finish ignore it
          if (!key.equals("Start") && !key.equals("Finish")) {
            Point pointInfo = new Point(plugin, world, key);
            if (loc.equals(pointInfo.getLocation()) && pointInfo.getExists()) {
              // Check if player has started
              if (pInfo.getHasStarted()) {
                // Check for new checkpoint
                String lastCP = pInfo.getLastCP();
                if (lastCP.equals("null") || !lastCP.equals(key)) {
                  pInfo.setLastCP(key);
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour] "
                          + ChatColor.GOLD
                          + "You have reached a Checkpoint! Use the command "
                          + ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "/iparkour checkpoint"
                          + ChatColor.GOLD
                          + " to return here!");
                  return;
                }
              }
              return;
            }
          }
        }
      }
    }
  }