Esempio n. 1
0
 public void sendToSpawn(Gamer gamer) {
   final Player p = gamer.getPlayer();
   Location originalSpawn = p.getWorld().getSpawnLocation();
   MainConfig main = HungergamesApi.getConfigManager().getMainConfig();
   int spawnRadius = main.getSpawnRadius();
   int spawnHeight = main.getSpawnHeight();
   if (spawns.size() > 0) {
     if (spawnItel == null || !spawnItel.hasNext()) spawnItel = spawns.keySet().iterator();
     originalSpawn = spawnItel.next();
     spawnRadius = Math.max(1, spawns.get(originalSpawn)[0]);
     spawnHeight = Math.max(1, spawns.get(originalSpawn)[1]);
   }
   Location spawn = originalSpawn.clone();
   int chances = 0;
   if (p.isInsideVehicle()) p.leaveVehicle();
   p.eject();
   while (chances < main.getTimesToCheckForValidSpawnPerPlayer()) {
     chances++;
     Location newLoc =
         new Location(
             p.getWorld(),
             spawn.getX() + returnChance(-spawnRadius, spawnRadius),
             spawn.getY() + new Random().nextInt(spawnHeight),
             spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
     if (nonSolid.contains(newLoc.getBlock().getTypeId())
         && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.UP).getTypeId())) {
       while (newLoc.getBlockY() >= 1
           && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.DOWN).getTypeId())) {
         newLoc = newLoc.add(0, -1, 0);
       }
       if (newLoc.getBlockY() <= 1) continue;
       spawn = newLoc;
       break;
     }
   }
   if (spawn.equals(originalSpawn)) {
     spawn =
         new Location(
             p.getWorld(),
             spawn.getX() + returnChance(-spawnRadius, spawnRadius),
             0,
             spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
     spawn.setY(spawn.getWorld().getHighestBlockYAt(spawn));
     if (gamer.isAlive() && spawn.getY() <= 1) {
       spawn.getBlock().setType(Material.GLASS);
       spawn.setY(spawn.getY() + 1);
     }
   }
   final Location destination = spawn.add(0.5, 0.1, 0.5);
   p.teleport(destination);
   Bukkit.getScheduler()
       .scheduleSyncDelayedTask(
           hg,
           new Runnable() {
             public void run() {
               p.teleport(destination);
             }
           });
 }
Esempio n. 2
0
 /**
  * @param location
  * @return Name of warp owner
  */
 public String getWarpOwner(Location location) {
   for (UUID playerUUID : warpList.keySet()) {
     if (location.equals(warpList.get(playerUUID))) {
       return plugin.getPlayers().getName(playerUUID);
     }
   }
   return "";
 }
Esempio n. 3
0
  public Boolean outOfRange(Location l) {
    if (!location.getWorld().equals(l.getWorld())) return true;

    if (location.equals(l)) return false;
    if (location.distanceSquared(l) > range_squared) return true;

    return false;
  }
Esempio n. 4
0
  public List<Player> matchLoc(Location currentLoc) {
    List<Player> matched = new ArrayList<Player>();
    for (Player player : plugin.store.stored) {
      Location storedLoc = plugin.store.placed.get(player);
      if (currentLoc.equals(storedLoc)) {
        matched.add(player);
      }
    }

    return matched;
  }
Esempio n. 5
0
  public Area getArea(Location loc) {
    FileConfiguration locationsFile =
        YamlConfiguration.loadConfiguration(Main.getInstance().locations);
    List<Area> areas = Area.getBlockSpawns();
    int i = 0;
    for (int t = 1; t < 9; t++) {
      String[] data = locationsFile.getString("arena.blockspawnareas." + t).split(" ");

      Location minimum = locationUtil.deserializeLoc(data[0]);
      Location maximum = locationUtil.deserializeLoc(data[1]);
      for (double x = minimum.getX(); x <= maximum.getX(); x++) {
        for (double y = minimum.getY(); y <= maximum.getY(); y++) {
          for (double z = minimum.getZ(); z <= maximum.getZ(); z++) {
            Location location = new Location(minimum.getWorld(), x, y, z);
            if (location.equals(loc)) {
              return areas.get(i);
            }
          }
        }
      }
      i++;
    }
    return null;
  }
Esempio n. 6
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;
            }
          }
        }
      }
    }
  }
Esempio n. 7
0
 private void doBorder(Gamer gamer) {
   Player p = gamer.getPlayer();
   Location pLoc = p.getLocation().clone();
   Location sLoc = world.getSpawnLocation().clone();
   double border = mainConfig.getBorderSize();
   if (mainConfig.isRoundedBorder()) {
     sLoc.setY(pLoc.getY());
     double fromSpawn = pLoc.distance(sLoc);
     if (fromSpawn >= border - 20) {
       // Warn
       p.sendMessage(translationsConfig.getMessagePlayerApproachingBorder());
       if (fromSpawn >= border) {
         // Punish
         if (gamer.isAlive()) {
           // Damage and potentially kill.
           double dmg = HungergamesApi.getConfigManager().getMainConfig().getDamageBorderDeals();
           if (p.getHealth() - dmg > 0) {
             p.damage(0);
             p.setHealth(p.getHealth() - dmg);
           } else {
             pm.killPlayer(
                 gamer,
                 null,
                 pLoc,
                 gamer.getInventory(),
                 String.format(
                     translationsConfig.getKillMessageKilledByBorder(), gamer.getName()));
           }
         } else if (border > 10) {
           // Hmm. Preferably I tp them back inside.
           // May as well just tp to spawn. No harm done.
           pm.sendToSpawn(gamer);
         }
       }
     }
   } else {
     Location tpTo = pLoc.clone();
     int xDist = pLoc.getBlockX() - sLoc.getBlockX();
     if (Math.abs(xDist) > border - 20) {
       if (xDist > 0) {
         tpTo.setX(border - 2 + sLoc.getBlockX());
       } else {
         tpTo.setX(border + 2 + sLoc.getBlockX());
       }
     }
     int zDist = pLoc.getBlockZ() - sLoc.getBlockZ();
     if (Math.abs(zDist) > border - 20) {
       if (zDist > 0) {
         tpTo.setZ(border - 2 + sLoc.getBlockZ());
       } else {
         tpTo.setZ(border + 2 + sLoc.getBlockZ());
       }
     }
     if (!pLoc.equals(tpTo)) p.sendMessage(translationsConfig.getMessagePlayerApproachingBorder());
     if (tpTo.getBlockX() != pLoc.getBlockX() || tpTo.getBlockZ() != pLoc.getBlockZ()) {
       if (gamer.isAlive()) {
         // Damage and potentially kill.
         double dmg = HungergamesApi.getConfigManager().getMainConfig().getDamageBorderDeals();
         if (p.getHealth() - dmg > 0) {
           p.damage(0);
           p.setHealth(p.getHealth() - dmg);
         } else {
           pm.killPlayer(
               gamer,
               null,
               pLoc,
               gamer.getInventory(),
               String.format(translationsConfig.getKillMessageKilledByBorder(), gamer.getName()));
         }
       } else if (border > 10) {
         gamer.getPlayer().teleport(tpTo);
       }
     }
   }
 }
Esempio n. 8
0
 private void doBorder(Gamer gamer) {
   Player p = gamer.getPlayer();
   Location loc = p.getLocation().clone();
   Location sLoc = world.getSpawnLocation().clone();
   double border = mainConfig.getBorderSize();
   if (mainConfig.isRoundedBorder()) {
     sLoc.setY(loc.getY());
     double fromBorder = loc.distance(sLoc) - border;
     if (fromBorder - 20 > 0) {
       // Warn
       p.sendMessage(translationsConfig.getMessagePlayerApproachingBorder());
       if (fromBorder > 0) {
         // Punish
         if (gamer.isAlive()) {
           // Damage and potentially kill.
           if (p.getHealth() - 2 > 0) {
             p.damage(0);
             p.setHealth(p.getHealth() - 2);
           } else {
             pm.killPlayer(
                 gamer,
                 null,
                 loc,
                 gamer.getInventory(),
                 String.format(
                     translationsConfig.getKillMessageKilledByBorder(), gamer.getName()));
           }
         } else if (border > 10) {
           // Hmm. Preferably I tp them back inside.
           // May as well just tp to spawn. No harm done.
           pm.sendToSpawn(gamer);
         }
       }
     }
   } else {
     Location tpTo = loc.clone();
     int fromSpawn = loc.getBlockX() - sLoc.getBlockX();
     if (fromSpawn > border - 20) {
       tpTo.setX(((border - 2) + sLoc.getBlockX()));
     }
     if (fromSpawn < -(border - 20)) {
       tpTo.setX((-(border - 2) + sLoc.getBlockX()));
     }
     boolean hurt = Math.abs(fromSpawn) >= border;
     fromSpawn = loc.getBlockZ() - sLoc.getBlockZ();
     if (fromSpawn > (border - 20)) {
       tpTo.setZ(((border - 2) + sLoc.getBlockZ()));
     }
     if (fromSpawn < -(border - 20)) {
       tpTo.setZ((-(border - 2) + sLoc.getBlockZ()));
     }
     if (!hurt) hurt = Math.abs(fromSpawn) >= border;
     if (!loc.equals(tpTo)) p.sendMessage(translationsConfig.getMessagePlayerApproachingBorder());
     if (hurt) {
       if (gamer.isAlive()) {
         // Damage and potentially kill.
         if (p.getHealth() - 2 > 0) {
           p.damage(0);
           p.setHealth(p.getHealth() - 2);
         } else {
           pm.killPlayer(
               gamer,
               null,
               loc,
               gamer.getInventory(),
               String.format(translationsConfig.getKillMessageKilledByBorder(), gamer.getName()));
         }
       } else if (border > 10) {
         gamer.getPlayer().teleport(tpTo);
       }
     }
   }
 }
Esempio n. 9
0
  private void doPathgroups() {
    // TODO Auto-generated method stub

    Debug(1, "doPathgroups:Begun:Countdown: " + this.parent.movecountdown);
    if (this.parent.movecountdown == 0) {
      // It's time to execute

      // Are they on a pathspot?
      if (this.parent.currentpathspot < 1) {
        // In a pathgroup but not in a pathspot! Fix it
        this.parent.currentpathspot = 1;
      }
      Debug(1, "doPathgroups:Checking entries");

      // Lets look at all the pathgroup entries and get the one we're on
      for (myPathgroup_entry entry : this.parent.pathgroup.pathgroupentries) {
        Debug(1, "doPathgroups:Cycling entries");

        // This is the entry the npc is on
        if (entry.spot == this.parent.currentpathspot) {
          Debug(
              1,
              "Does "
                  + entry.location
                  + " match "
                  + this.getBukkitEntity().getLocation()
                  + " : "
                  + this.parent.currentpathspot);
          // Ignore yaw and pitch
          Location loca =
              new Location(
                  entry.location.getWorld(),
                  entry.location.getX(),
                  entry.location.getY(),
                  entry.location.getZ(),
                  0,
                  0);
          Location locb =
              new Location(
                  this.getBukkitEntity().getWorld(),
                  this.getBukkitEntity().getLocation().getX(),
                  this.getBukkitEntity().getLocation().getY(),
                  this.getBukkitEntity().getLocation().getZ(),
                  0,
                  0);

          if (loca.equals(locb)) {
            Panic(
                1,
                "Already reached: "
                    + this.getBukkitEntity().getLocation()
                    + " spot: "
                    + this.parent.currentpathspot);

            // Move to net location
            this.parent.movecountdown = 10;
            iteratePathspot();

          } else {
            // Lets convert it into a Location
            Location loc =
                new Location(
                    this.getBukkitEntity().getWorld(),
                    entry.location.getX(),
                    entry.location.getY(),
                    entry.location.getZ(),
                    entry.location.getYaw(),
                    entry.location.getPitch());
            // We should try to move closer to it
            this.moveCloserToLocation(loc);
          }
        }
      }

    } else {
      if (this.parent.movecountdown < 0) {
        // why is the countdown less than 0, reset it (executes)
        this.parent.movecountdown = 0;
      } else {
        // move the countdown closer to execution
        this.parent.movecountdown--;
      }
    }
  }