Ejemplo n.º 1
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;
            }
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  // Command
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    // Check for player
    if (sender instanceof Player) {
      // Store player and command
      Player player = (Player) sender;
      String command = cmd.getName().toUpperCase();

      // Check command
      if (command.equals("IPARKOUR")) {
        // Check for perms
        if (player.hasPermission("iParkour.iparkour")) {
          // Check args
          if (args.length == 0) {
            // Display a list of commands
            for (String str : helpMsgs) {
              player.sendMessage(str);
            }
            return true;

          } else if (args.length == 1) {
            // See which sub command
            String subCMD = args[0].toUpperCase();

            // EDIT
            if (subCMD.equals("EDIT")) {
              // Check for perms
              if (player.hasPermission("iParkour.iparkour.edit")) {
                // Check player's gamemode
                if (player.getGameMode().equals(GameMode.CREATIVE)) {
                  try {
                    new WorldInventory(plugin);
                    MenuManager mm = new MenuManager();
                    player.openInventory(mm.getMenu("World List"));
                  } catch (NullPointerException npe) {
                    player.sendMessage(
                        ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + "[iParkour] "
                            + ChatColor.RED
                            + "There are not any points registered on this server.");
                  }
                  return true;
                } else {
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour] "
                          + ChatColor.RED
                          + "You must be in CREATIVE mode to use this command.");
                }

              } else { // No perms
                player.sendMessage(
                    ChatColor.GREEN
                        + ""
                        + ChatColor.BOLD
                        + "[iParkour] "
                        + ChatColor.RED
                        + "You do not have permission to use this command.");
                return true;
              }
              // CHECKPOINT
            } else if (subCMD.equals("CHECKPOINT")) {
              // Check for perms
              if (player.hasPermission("iParkour.iparkour.checkpoint")) {
                // Check if the player has started
                PlayerInfo pInfo = new PlayerInfo(player, plugin);
                if (pInfo.getHasStarted()) {
                  String lastCP = pInfo.getLastCP();
                  if (lastCP.equals("null")) {
                    player.sendMessage(
                        ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + "[iParkour] "
                            + ChatColor.GOLD
                            + "You have not reached a Checkpoint yet!");
                    return true;
                  } else {
                    Point pointInfo = new Point(plugin, player.getWorld(), pInfo.getLastCP());
                    Location cpLoc = pointInfo.getLocation();
                    cpLoc.setX(cpLoc.getX() + .5);
                    cpLoc.setY(cpLoc.getY() + .5);
                    cpLoc.setZ(cpLoc.getZ() + .5);
                    cpLoc.setYaw(player.getLocation().getYaw());
                    player.teleport(cpLoc);
                    player.sendMessage(
                        ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + "[iParkour] "
                            + ChatColor.GOLD
                            + "You were teleported to "
                            + ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + lastCP
                            + ChatColor.GOLD
                            + "!");
                    return true;
                  }
                } else {
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour] "
                          + ChatColor.GOLD
                          + "You have to start before you can use a Checkpoint!");
                  return true;
                }
              } else { // No perms
                player.sendMessage(
                    ChatColor.GREEN
                        + ""
                        + ChatColor.BOLD
                        + "[iParkour] "
                        + ChatColor.RED
                        + "You do not have permission to use this command.");
                return true;
              }
            }
            return true;
          }
        } else { // No perms
          player.sendMessage(
              ChatColor.GREEN
                  + ""
                  + ChatColor.BOLD
                  + "[iParkour] "
                  + ChatColor.RED
                  + "You do not have permission to use this command.");
          return true;
        }
      } // Else do nothing

      // Else give sender error
    } else {
      sender.sendMessage("[iParkour] This command is only for players!");
    }
    return true;
  }