@EventHandler(priority = EventPriority.MONITOR)
  public void stackPlayer(PlayerInteractEntityEvent event) {
    // Do nothing if clicked entity is not a player.
    if (!(event.getRightClicked() instanceof Player)) return;

    // Do nothing if player does not have permission.
    Player player = event.getPlayer();
    if (!Perm.PLAYERSTACKER.has(player)) return;

    // Do nothing if clicking player is not stacking.
    User user = plugin.getUser(player.getUniqueId());
    if (user != null && !user.isStacking()) return;

    // Do nothing if clicked player is not stacking.
    Player clicked = (Player) event.getRightClicked();
    user = plugin.getUser(clicked.getUniqueId());
    if (user != null && !user.isStacking()) return;

    // Do nothing if player or clicked player are inside a vehicle.
    if (clicked.isInsideVehicle() || player.isInsideVehicle()) return;

    // Stack the player.
    Entity topPassenger = getTopPassenger(player);
    topPassenger.setPassenger(clicked);
  }
Exemple #2
0
  /**
   * Various corner cases that would cause this check to fail or require special treatment
   *
   * @param player
   * @param data
   * @param from
   * @param to
   * @return
   */
  public boolean shouldBeApplied(
      final Player player, final MovingData data, final Location from, final Location to) {

    if (player.isDead() || player.isInsideVehicle() || data.insideVehicle) return false;

    if (data.wasTeleported) {
      // Remember this location
      data.teleportedTo = from.clone();
      data.wasTeleported = false;
      data.jumpPhase = 0;
    }

    if (data.teleportedTo != null && data.teleportedTo.getWorld().equals(from.getWorld())) {
      // As long as the from-Location doesn't change, the player didn't accept the teleport
      if (data.teleportedTo.distanceSquared(from) < 0.01D) {
        // Event after Teleport ignored
        return false;
      } else {
        // The player finally accepted the teleport with the previous event
        data.teleportedTo = null;
      }
    }

    // If the target is a bed, don't check (going to bed is a kind of mini teleport...)
    if (to.getWorld().getBlockTypeIdAt(to) == Material.BED_BLOCK.getId()) {
      return false;
    }

    return true;
  }
Exemple #3
0
  @Override
  public void run() {
    Collection<? extends Player> players = Bukkit.getOnlinePlayers();
    long maxAFKTime;
    SinCityPlayer thisPlayer;
    for (Player player : players) {
      if (!player.isOnline() || player.isDead()) continue;
      thisPlayer = this.playerManager.getPlayer(player);
      maxAFKTime = this.dataManager.getMaxAFKTime(thisPlayer.getGroup());

      // WHEN AFK TIMER IS REACHED AND (PLAYER HAS NOT MOVED OR IS INSIDE
      // A VEHICLE) (PREVENT ABUSE!)
      if (maxAFKTime >= 0) {
        if (player.isInsideVehicle() || thisPlayer.hasMoved(player.getLocation())) {
          thisPlayer.setLastLocation(player.getLocation());
          return;
        }
        if (thisPlayer.isTooLongAFK(maxAFKTime)) {
          ConsoleUtils.printInfo(Core.NAME, "Kicked '" + player.getName() + "' for being AFK!");
          player.kickPlayer("Kicked being AFK!");
        }
      } else {
        thisPlayer.setLastLocation(player.getLocation());
      }
    }
  }
 public void run() {
   for (String name : lastLoc.keySet()) {
     Player player = plugin.getServer().getPlayer(name);
     if (player == null) {
       removePlayer(name);
     } else {
       // workaround for bukkit issue
       String prevWorld = lastLoc.get(name).getWorld().getName();
       String curWorld = player.getLocation().getWorld().getName();
       if (prevWorld.equals(curWorld)) {
         if (player.getLocation().distance(lastLoc.get(name)) < 1) {
           continue;
         }
       }
       // if distance between player's current location and stored
       // location is less than 1, this move is not active; if active
       // and ignore vehicle movement is set and player in vehicle,
       // then update location, but don't count this move as active
       addPlayer(player);
       if (!isIgnoreVehicleMovement || !player.isInsideVehicle()) {
         afkBooter.getPlayerActivity().recordActivity(name);
       }
     }
   }
 }
 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);
             }
           });
 }
 @EventHandler(priority = EventPriority.NORMAL)
 public void playerWalk(PlayerMoveEvent event) {
   // Player Moved
   int walkingBoots = config.getInt("walking_boots", 3);
   Player player = event.getPlayer();
   Location fromLoc = event.getFrom();
   Location toLoc = event.getTo();
   int fromX = (int) fromLoc.getX();
   int fromZ = (int) fromLoc.getZ();
   int toX = (int) toLoc.getX();
   int toZ = (int) toLoc.getZ();
   if ((fromX != toX || fromZ != toZ)
       && player.hasPermission("walkthewalk.use")
       && !player.isInsideVehicle()) {
     // Player moved to a new block, and has permission
     boolean rightBoots = false;
     if (walkingBoots != 0) {
       int invBoots = 0;
       if (player.getInventory().getBoots() != null) {
         invBoots = player.getInventory().getBoots().getTypeId();
       }
       if (invBoots == 301 && walkingBoots == 1) {
         // Leather Boots
         rightBoots = true;
       } else if (invBoots == 309 && walkingBoots == 2) {
         // Iron Boots
         rightBoots = true;
       } else if (invBoots == 317 && walkingBoots == 3) {
         // Gold Boots
         rightBoots = true;
       } else if (invBoots == 313 && walkingBoots == 4) {
         // Diamond Boots
         rightBoots = true;
       } else if (invBoots == 305 && walkingBoots == 5) {
         // Chain Boots
         rightBoots = true;
       }
     } else {
       rightBoots = true;
     }
     if (rightBoots) {
       // Player was wearing the right boots
       int xpBoost = config.getInt("xp_boost", 1);
       int boostBlocks = config.getInt("boost_blocks", 10);
       double rounding = 0.00;
       if (xpRounding.get(player.getName()) != null) {
         rounding = xpRounding.get(player.getName());
       }
       rounding += (double) xpBoost / boostBlocks;
       if (rounding >= xpBoost) {
         rounding -= xpBoost;
         player.giveExp(xpBoost);
       }
       xpRounding.put(player.getName(), rounding);
     }
   }
 }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    Player targetPlayer = sender_p;

    if (args.length == 1) {

      targetPlayer = getPlayer(args[0]);

      if (targetPlayer == null) {
        sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
        return true;
      }
    }

    if (senderIsConsole) {
      if (targetPlayer == null) {
        sender.sendMessage(
            "When used from the console, you must define a target player: /cartsit <player>");
        return true;
      }
    } else if (targetPlayer != sender_p && !TFM_AdminList.isSuperAdmin(sender)) {
      sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
      return true;
    }

    if (targetPlayer.isInsideVehicle()) {
      targetPlayer.getVehicle().eject();
    } else {
      Minecart nearest_cart = null;
      for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class)) {
        if (cart.isEmpty()) {
          if (nearest_cart == null) {
            nearest_cart = cart;
          } else {
            if (cart.getLocation().distanceSquared(targetPlayer.getLocation())
                < nearest_cart.getLocation().distanceSquared(targetPlayer.getLocation())) {
              nearest_cart = cart;
            }
          }
        }
      }

      if (nearest_cart != null) {
        nearest_cart.setPassenger(targetPlayer);
      } else {
        sender.sendMessage("There are no empty minecarts in the target world.");
      }
    }

    return true;
  }
Exemple #8
0
  @EventHandler
  public void LocationUpdater(UpdateEvent event) {
    if (event.getType() == UpdateType.TICK) {
      for (Player p : EffectManager.effect3.keySet()) {
        if (EffectManager.getEffect(p) == EffectManager.EffectType.HourGlass) {
          if (p.isValid()) {
            if (ExtraManager.isMoving(p)) {
              Location location = p.getLocation();

              Vector vector = new Vector();

              for (int i = 0; i < this.particlesPerIteration; i++) {
                this.step += 1;

                float t = 3.141593F / this.particles * this.step;
                float r =
                    MathUtils.sin(t * 2.718282F * this.particlesPerIteration / this.particles)
                        * this.size;
                float s = r * 3.141593F * t;

                vector.setX(this.xFactor * r * -MathUtils.cos(s));
                vector.setZ(this.zFactor * r * -MathUtils.sin(s));
                vector.setY(this.yFactor * r + this.yOffset + 2.0F);

                UtilVector.rotateVector(vector, this.xRotation, this.yRotation, this.zRotation);
                ParticleLib18 ench =
                    new ParticleLib18(
                        com.lightcraftmc.particles18.ParticleLib18.ParticleType.ENCHANTMENT_TABLE,
                        0.0D,
                        1,
                        0.0D);
                ench.sendToLocation(location.add(vector));

                location.subtract(vector);
              }

            } else if (!p.isInsideVehicle()) {
              ParticleLib18 ench2 =
                  new ParticleLib18(
                      com.lightcraftmc.particles18.ParticleLib18.ParticleType.ENCHANTMENT_TABLE,
                      0.1000000014901161D,
                      4,
                      0.300000011920929D);
              ench2.sendToLocation(p.getLocation().add(0.0D, 1.0D, 0.0D));
            }
          }
        }
      }
    }
  }
Exemple #9
0
 /**
  * Teleports a player to a location. Before teleporting the player is ejected if he uses any
  * vehicle, the warp-effect is played (if enabled) and chunks are loaded (if enabled and not
  * loaded before).
  *
  * @param player the player to teleport
  * @param to the location the player should be teleported to
  */
 private static void teleport(Player player, Location to) {
   Location from = player.getLocation();
   if (player.isInsideVehicle()) {
     player.getVehicle().eject();
   }
   if (WarpSettings.warpEffect) {
     from.getWorld().playEffect(from, Effect.SMOKE, 4);
     from.getWorld().playEffect(from, Effect.SMOKE, 4);
     from.getWorld().playEffect(from, Effect.SMOKE, 4);
   }
   if (WarpSettings.loadChunks && !to.getWorld().isChunkLoaded(to.getBlockX(), to.getBlockZ())) {
     to.getWorld().refreshChunk(to.getBlockX(), to.getBlockZ());
   }
   player.teleport(to);
 }
  // set targetLoc only if not current player location; set returnLocationOnly to true to have new
  // Location returned if they need to be moved to one, instead of directly handling it
  public static Location checkPlayer(
      Player player, Location targetLoc, boolean returnLocationOnly) {
    if (player == null || !player.isOnline()) return null;

    Location loc = (targetLoc == null) ? player.getLocation() : targetLoc;
    if (loc == null) return null;

    World world = loc.getWorld();
    if (world == null) return null;
    BorderData border = Config.Border(world.getName());
    if (border == null) return null;

    if (border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) return null;

    if (player.hasPermission("worldborder.ignoreborder")) return null;

    Location newLoc = newLocation(player, loc, border);

    if (Config
        .whooshEffect()) { // give some particle and sound effects where the player was beyond the
      // border
      world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
      world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.GHAST_SHOOT, 0);
    }

    if (returnLocationOnly) return newLoc;

    if (!player.isInsideVehicle()) player.teleport(newLoc);
    else {
      Vehicle ride = (Vehicle) player.getVehicle();
      if (ride != null) { // vehicles need to be offset vertically and have velocity stopped
        double vertOffset = ride.getLocation().getY() - loc.getY();
        newLoc.setY(newLoc.getY() + vertOffset);
        ride.setVelocity(new Vector(0, 0, 0));
        ride.teleport(newLoc);
      } else { // if player.getVehicle() returns null (when riding a pig on older Bukkit releases,
        // for instance), player has to be ejected
        player.leaveVehicle();
        player.teleport(newLoc);
      }
    }

    return null;
  }
  @EventHandler
  public void denyMapExploit(PlayerMoveEvent event) {
    // Do nothing if this module is disabled.
    if (!settings.isFactionMap()) return;

    // Do nothing if player is not in a vehicle.
    Player player = event.getPlayer();
    if (!player.isInsideVehicle()) return;

    // Do nothing if player has permission.
    if (player.hasPermission(Perm.AntiGlitch.FACTION_MAP)) return;

    // Do nothing if distance is less than 8.
    if (event.getTo().distance(event.getFrom()) < 8D) return;

    // Deny movement.
    event.setTo(event.getFrom().setDirection(event.getTo().getDirection()));
  }
Exemple #12
0
  /**
   * Teleport a player to a location.
   *
   * @param player The player.
   * @param to The location to teleport to.
   * @param keepVehicle Whether or not to keep the vehicle.
   */
  public static void teleport(Player player, Location to, boolean keepVehicle) {
    if (to == null || player == null) return;

    if (player.isInsideVehicle()) {
      // Eject the vehicle...
      Entity vehicle = player.getVehicle();
      vehicle.eject();
      // Teleport the player...
      player.teleport(to);
      // Remove the vehicle if it's not persisting.
      if (!keepVehicle) vehicle.remove();
      else {
        // Otherwise teleport the vehicle and remount.
        vehicle.teleport(to);
        vehicle.setPassenger(player);
      }
      return;
    }

    player.teleport(to);
  }
Exemple #13
0
  private void makeItSo(Player player) {
    // start with the block shifted vertically from the player
    // to the destination sign's height (plus one).
    // check if this looks at all like something we're interested in first

    double toX = 0;
    double toY = 0;
    double toZ = 0;

    if (trigger.getState() instanceof Sign) {
      Sign s = (Sign) trigger.getState();
      String[] pos = s.getLine(2).split(":");
      if (pos.length > 2) {
        try {
          toX = Double.parseDouble(pos[0]);
          toY = Double.parseDouble(pos[1]);
          toZ = Double.parseDouble(pos[2]);
        } catch (Exception e) {
          return;
        }
      } else return;
    }

    Block floor =
        trigger
            .getWorld()
            .getBlockAt((int) Math.floor(toX), (int) (Math.floor(toY) + 1), (int) Math.floor(toZ));
    // well, unless that's already a ceiling.
    if (!occupiable(floor)) floor = floor.getRelative(BlockFace.DOWN);

    // now iterate down until we find enough open space to stand in
    // or until we're 5 blocks away, which we consider too far.
    int foundFree = 0;
    for (int i = 0; i < 5; i++) {
      if (occupiable(floor)) {
        foundFree++;
      } else {
        break;
      }
      if (floor.getY() == 0x0) // hit the bottom of the world
      break;
      floor = floor.getRelative(BlockFace.DOWN);
    }
    if (foundFree < 2) {
      player.sendMessage("mech.lift.obstruct");
      return;
    }

    // Teleport!
    Location subspaceRift = player.getLocation().clone();
    subspaceRift.setY(floor.getY() + 1);
    subspaceRift.setX(floor.getX());
    subspaceRift.setZ(floor.getZ());
    if (player.isInsideVehicle()) {
      subspaceRift = player.getVehicle().getLocation().clone();
      subspaceRift.setY(floor.getY() + 2);
      subspaceRift.setX(floor.getX());
      subspaceRift.setZ(floor.getZ());
      player.getVehicle().teleport(subspaceRift);
    }
    player.teleport(subspaceRift);

    player.sendMessage("mech.teleport.alert");
  }
 @Override
 public boolean onCommand(CommandSender sender, Command cmd, String arg, String[] args) {
   if (cmd.getName().equalsIgnoreCase("achievementride")) {
     if (!(sender instanceof Player)) {
       switch (args[0]) {
         default:
           break;
         case "fe":
           for (Player p : Bukkit.getOnlinePlayers()) {
             Location pLoc = p.getLocation();
             if (pLoc.getX() <= -43 && pLoc.getX() >= -53) {
               if (pLoc.getY() <= 70 && pLoc.getY() >= 65) {
                 if (pLoc.getZ() <= -597 && pLoc.getZ() >= -599) {
                   if (p.isInsideVehicle()) {
                     CorePlayer cp = PlayerUtils.getProfile(p);
                     cp.awardAchievement(p, AchievementsEnum.FE_RIDE);
                     cp.addExp(p, MiscUtils.randomInt(10, 50), "Farm Expediton ritje", true, true);
                   }
                 }
               }
             }
           }
           break;
         case "dc":
           for (Player p : Bukkit.getOnlinePlayers()) {
             Location pLoc = p.getLocation();
             if (pLoc.getX() <= -166 && pLoc.getX() >= -176) {
               if (pLoc.getY() <= 74 && pLoc.getY() >= 69) {
                 if (pLoc.getZ() <= -616 && pLoc.getZ() >= -618) {
                   if (p.isInsideVehicle()) {
                     CorePlayer cp = PlayerUtils.getProfile(p);
                     cp.awardAchievement(p, AchievementsEnum.DC_RIDE);
                     cp.addExp(p, MiscUtils.randomInt(10, 50), "Dive Coaster ritje", true, true);
                   }
                 }
               }
             }
           }
           break;
         case "ts": // -514,68,-552 en -500,72,-550
           for (Player p : Bukkit.getOnlinePlayers()) {
             Location pLoc = p.getLocation();
             if (pLoc.getX() <= -500 && pLoc.getX() >= -514) {
               if (pLoc.getY() <= 72 && pLoc.getY() >= 68) {
                 if (pLoc.getZ() <= -550 && pLoc.getZ() >= -552) {
                   if (p.isInsideVehicle()) {
                     CorePlayer cp = PlayerUtils.getProfile(p);
                     cp.awardAchievement(p, AchievementsEnum.TS_RIDE);
                     cp.addExp(p, MiscUtils.randomInt(10, 50), "The Swinger ritje", true, true);
                   }
                 }
               }
             }
           }
           break;
         case "cr": // 257 64 -474 | 255 69 -466
           for (Player p : Bukkit.getOnlinePlayers()) {
             Location pLoc = p.getLocation();
             if (pLoc.getX() <= 257 && pLoc.getX() >= 255) {
               if (pLoc.getY() <= 69 && pLoc.getY() >= 64) {
                 if (pLoc.getZ() <= -466 && pLoc.getZ() >= -474) {
                   if (p.isInsideVehicle()) {
                     CorePlayer cp = PlayerUtils.getProfile(p);
                     cp.awardAchievement(p, AchievementsEnum.CR_RIDE);
                     cp.addExp(p, MiscUtils.randomInt(10, 50), "The Crush ritje", true, true);
                   }
                 }
               }
             }
           }
           break;
       }
     } else {
       ChatUtils.sendNoPremTag((Player) sender, "SetRide");
     }
   }
   return true;
 }
Exemple #15
0
  public static Object handle(Object obj) {
    if (obj instanceof World.Environment) {
      World.Environment e = (World.Environment) obj;
      if (e == World.Environment.NETHER) {
        return "nether";
      } else {
        return "normal";
      }
    } else if (obj instanceof File) {
      return ((File) obj).toString();
    } else if (obj instanceof Player) {
      Player p = (Player) obj;
      JSONObject o = new JSONObject();

      o.put("name", p.getName());
      o.put("op", p.isOp());
      o.put("health", p.getHealth());
      o.put("ip", p.getAddress().toString());
      o.put("itemInHand", p.getItemInHand());
      o.put("location", p.getLocation());
      o.put("inventory", p.getInventory());
      o.put("sneaking", p.isSneaking());
      o.put("inVehicle", p.isInsideVehicle());
      o.put("sleeping", p.isSleeping());
      o.put("world", p.getServer().getWorlds().indexOf(p.getWorld()));

      return o;
    } else if (obj instanceof Server) {
      Server s = (Server) obj;

      JSONObject o = new JSONObject();

      o.put("maxPlayers", s.getMaxPlayers());
      o.put("players", Arrays.asList(s.getOnlinePlayers()));
      o.put("port", s.getPort());
      o.put("name", s.getName());
      o.put("serverName", s.getServerName());
      o.put("version", s.getVersion());
      o.put("worlds", s.getWorlds());

      return o;
    } else if (obj instanceof World) {
      World w = (World) obj;

      JSONObject o = new JSONObject();

      o.put("environment", w.getEnvironment());
      o.put("fullTime", w.getFullTime());
      o.put("time", w.getTime());
      o.put("name", w.getName());
      o.put("isThundering", w.isThundering());
      o.put("hasStorm", w.hasStorm());

      return o;
    } else if (obj instanceof Plugin) {
      Plugin p = (Plugin) obj;
      PluginDescriptionFile d = p.getDescription();

      JSONObject o = new JSONObject();

      o.put("name", d.getName());
      o.put("description", d.getDescription());
      o.put("authors", d.getAuthors());
      o.put("version", d.getVersion());
      o.put("website", d.getWebsite());
      o.put("enabled", JSONAPI.instance.getServer().getPluginManager().isPluginEnabled(p));

      return o;
    } else if (obj instanceof ItemStack) {
      ItemStack i = (ItemStack) obj;

      JSONObject o = new JSONObject();

      o.put("type", i.getTypeId());
      o.put("durability", i.getDurability());
      o.put("amount", i.getAmount());

      return o;
    } else if (obj instanceof PlayerInventory) {
      PlayerInventory p = (PlayerInventory) obj;

      JSONObject o = new JSONObject();

      JSONObject armor = new JSONObject();
      armor.put("boots", p.getBoots());
      armor.put("chestplate", p.getChestplate());
      armor.put("helmet", p.getHelmet());
      armor.put("leggings", p.getLeggings());

      o.put("armor", armor);
      o.put("hand", p.getItemInHand());
      o.put("inventory", Arrays.asList(p.getContents()));

      return o;
    } else if (obj instanceof Location) {
      Location l = (Location) obj;

      JSONObject o = new JSONObject();

      o.put("x", l.getX());
      o.put("y", l.getY());
      o.put("z", l.getZ());
      o.put("pitch", l.getPitch());
      o.put("yaw", l.getYaw());

      return o;
    } else if (obj instanceof Plugin[]) {
      List<Plugin> l = Arrays.asList((Plugin[]) obj);

      Collections.sort(l, new PluginSorter());

      return l;
    } else if (obj instanceof Object[]) {
      int l = ((Object[]) obj).length;
      JSONArray a = new JSONArray();
      for (int i = 0; i < l; i++) {
        a.add(((Object[]) obj)[i]);
      }

      return a;
    }
    Logger.getLogger("JSONAPI").warning("Uncaugh object! Value:");
    Logger.getLogger("JSONAPI").warning(obj.toString());
    Logger.getLogger("JSONAPI").warning("Type:");
    Logger.getLogger("JSONAPI").warning(obj.getClass().getName());

    return new Object();
  }
Exemple #16
0
 @Override
 public boolean isInsideVehicle() {
   return caller.isInsideVehicle();
 }
Exemple #17
0
  @Override
  public void execute(TeamAdvantage plugin, CommandSender sender, Player player, String[] args) {
    if (sender.hasPermission("teamadvantage.use")) {
      if (null != player) {
        TATeam teamOfPlayer = plugin.getTeamOfPlayer(player.getName());

        if (null != teamOfPlayer) {
          if (null != teamOfPlayer.getHome()) {
            if (checkIfTeleportDestinationIsSave(teamOfPlayer.getHome())) {
              // handle teleport with mount
              if (player.isInsideVehicle()) {
                if (player.getVehicle() instanceof Horse) {
                  Horse mount = (Horse) player.getVehicle();

                  if (mount.isTamed()
                      && (null
                          != mount
                              .getInventory()
                              .getSaddle())) // player may only warp with a tamed mount with a
                                             // saddle
                  {
                    // unmount player
                    boolean resUnmount = player.leaveVehicle();
                    // teleport horse and re-mount player (teleporting him in the proccess)
                    boolean resTele = mount.teleport(teamOfPlayer.getHome());
                    boolean resSetPassenger =
                        mount.setPassenger(player); // will teleport the player to the horses back

                    if (resUnmount && resTele && resSetPassenger) {
                      player.sendMessage(
                          "§a"
                              + "Willkommen beim Team-Home von "
                              + "§f"
                              + teamOfPlayer.getName()
                              + "§a"
                              + "!");
                    } else {
                      player.sendMessage("§4" + "Teleport fehlgeschlagen!");
                    }
                  } else {
                    player.sendMessage(
                        "§6"
                            + "Du kannst nur auf einem gezaehmten und besatteltem Reittier warpen!");
                  }
                } else {
                  player.sendMessage(
                      "§6" + "Du kannst nur auf einem gezaehmten und besatteltem Reittier warpen!");
                }
              } else {
                if (player.teleport(teamOfPlayer.getHome())) {
                  player.sendMessage(
                      "§a"
                          + "Willkommen beim Team-Home von "
                          + "§f"
                          + teamOfPlayer.getName()
                          + "§a"
                          + "!");
                } else {
                  player.sendMessage("§4" + "Warpen fehlgeschlagen!");
                }
              }
            } else {
              player.sendMessage(
                  "§6"
                      + "Der Home-Punkt ist moeglicherweise nicht sicher!\n"
                      + "Verwende 'home-force-to' um dennoch dorthin zu teleportieren.");
            }
          } else {
            player.sendMessage("§6" + "Es ist kein Home-Punkt fuer dein Team gesetzt!");
          }
        } else {
          player.sendMessage("§6" + "Du bist kein Mitglied eines Teams!");
        }
      } else {
        sender.sendMessage(TeamAdvantage.logPrefix + "Only players can use this command!");
      }
    }
  }
Exemple #18
0
  @Override
  public final void check(IProfile player) {
    final Player p = player.getBukkitPlayer();
    if (p.isInsideVehicle())
      return; // Riding a horse or minecart makes it possible to move much faster
    if (p.getAllowFlight()) return;
    // If they have both speed AND slowness, we're just going to ignore them...

    if (p.hasPotionEffect(PotionEffectType.SPEED) && !p.hasPotionEffect(PotionEffectType.SLOW)) {
      PotionEffect potionEffect = null;

      for (PotionEffect effect : p.getActivePotionEffects()) {
        if (effect.getType().equals(PotionEffectType.SPEED)) {
          potionEffect = effect;
          break;
        }
      }

      double maxBps = this.maxBlocksPerSecond;

      if (potionEffect != null) {
        // They have speed
        int amp = potionEffect.getAmplifier();
        maxBps =
            maxBlocksPerSecond
                + (maxBlocksPerSecond * ((amp + 1) * 0.20)); // Speed increases by 20%
      }

      double bps = player.getProfileData().getBlocksPerSecond();

      if (bps > maxBps) {
        fail(player);
      }

    } else if (p.hasPotionEffect(PotionEffectType.SLOW)
        && !p.hasPotionEffect(PotionEffectType.SPEED)) {
      // Slowness decreases by 15% * potion level
      PotionEffect potionEffect = null;
      for (PotionEffect effect : p.getActivePotionEffects()) {
        if (effect.getType().equals(PotionEffectType.SLOW)) {
          potionEffect = effect;
          break;
        }
      }

      double maxBps = this.maxBlocksPerSecond;

      if (potionEffect != null) {
        // They have slow
        int amp = potionEffect.getAmplifier();
        maxBps = maxBlocksPerSecond * (amp - (amp * 0.15)); // Slow decreases by 15%
      }

      double bps = player.getProfileData().getBlocksPerSecond();

      if (bps > maxBps) {
        fail(player);
      }
    } else if (!p.hasPotionEffect(PotionEffectType.SPEED)
        && !p.hasPotionEffect(PotionEffectType.SLOW)) {

      double bps = player.getProfileData().getBlocksPerSecond();

      if (bps > this.maxBlocksPerSecond) {
        fail(player);
      }
    }

    // Reset their blocks per second
    player.getProfileData().setBlocksPerSecond(0);
  }
Exemple #19
0
  @SuppressWarnings("deprecation")
  public boolean addPlayer(final Player p) {
    if (SettingsManager.getInstance().getLobbySpawn() == null) {
      msgmgr.sendFMessage(PrefixType.WARNING, "error.nolobbyspawn", p);
      return false;
    }
    if (!p.hasPermission("sg.arena.join." + gameID)) {
      debug("permission needed to join arena: " + "sg.arena.join." + gameID);
      msgmgr.sendFMessage(PrefixType.WARNING, "game.nopermission", p, "arena-" + gameID);
      return false;
    }
    HookManager.getInstance()
        .runHook(
            "GAME_PRE_ADDPLAYER",
            "arena-" + gameID,
            "player-" + p.getName(),
            "maxplayers-" + spawns.size(),
            "players-" + activePlayers.size());

    GameManager.getInstance().removeFromOtherQueues(p, gameID);

    if (GameManager.getInstance().getPlayerGameId(p) != -1) {
      if (GameManager.getInstance().isPlayerActive(p)) {
        msgmgr.sendMessage(PrefixType.ERROR, "Cannot join multiple games!", p);
        return false;
      }
    }
    if (p.isInsideVehicle()) {
      p.leaveVehicle();
    }
    if (spectators.contains(p)) removeSpectator(p);
    if (mode == GameMode.WAITING || mode == GameMode.STARTING) {
      if (activePlayers.size() < SettingsManager.getInstance().getSpawnCount(gameID)) {
        msgmgr.sendMessage(PrefixType.INFO, "Joining Arena '" + name + "'", p);
        PlayerJoinArenaEvent joinarena =
            new PlayerJoinArenaEvent(p, GameManager.getInstance().getGame(gameID));
        Bukkit.getServer().getPluginManager().callEvent(joinarena);
        if (joinarena.isCancelled()) return false;
        boolean placed = false;
        int spawnCount = SettingsManager.getInstance().getSpawnCount(gameID);

        for (int a = 1; a <= spawnCount; a++) {
          if (spawns.get(a) == null) {
            placed = true;
            spawns.put(a, p);
            p.setGameMode(org.bukkit.GameMode.SURVIVAL);

            // p.teleport(SettingsManager.getInstance().getLobbySpawn());
            p.teleport(SettingsManager.getInstance().getSpawnPoint(gameID, a));

            p.setHealth(p.getMaxHealth());
            p.setFoodLevel(20);
            p.getInventory().clear();
            p.getEquipment().setArmorContents(null);
            p.updateInventory();

            p.setFlying(false);
            p.setAllowFlight(false);
            p.setWalkSpeed(0.2F);
            p.setFireTicks(0);

            activePlayers.add(p);
            sm.addPlayer(p, gameID);

            scoreBoard.addPlayer(p);

            hookvars.put("activeplayers", activePlayers.size() + "");
            LobbyManager.getInstance().updateWall(gameID);
            HookManager.getInstance()
                .runHook("GAME_POST_ADDPLAYER", "activePlayers-" + activePlayers.size());

            if (spawnCount == activePlayers.size()) {
              countdown(5);
            }

            Bukkit.getServer()
                .getScheduler()
                .scheduleSyncDelayedTask(
                    GameManager.getInstance().getPlugin(),
                    new Runnable() {
                      public void run() {
                        p.setFlying(false);
                        p.setAllowFlight(false);
                        p.setWalkSpeed(0.2F);
                        p.setFireTicks(0);

                        p.getInventory().clear();
                        p.getEquipment().setArmorContents(null);
                        p.updateInventory();
                        showMenu(p);

                        for (PotionEffect effect : p.getActivePotionEffects()) {
                          p.removePotionEffect(effect.getType());
                        }
                      }
                    },
                    1L);

            break;
          }
        }
        if (!placed) {
          msgmgr.sendFMessage(PrefixType.ERROR, "error.gamefull", p, "arena-" + gameID);
          return false;
        }

      } else if (SettingsManager.getInstance().getSpawnCount(gameID) == 0) {
        msgmgr.sendMessage(PrefixType.WARNING, "No spawns set for Arena " + gameID + "!", p);
        return false;
      } else {
        msgmgr.sendFMessage(PrefixType.WARNING, "error.gamefull", p, "arena-" + gameID);
        return false;
      }
      msgFall(
          PrefixType.INFO,
          "game.playerjoingame",
          "player-" + p.getName(),
          "activeplayers-" + getActivePlayers(),
          "maxplayers-" + SettingsManager.getInstance().getSpawnCount(gameID));
      if (activePlayers.size() >= config.getInt("auto-start-players") && !countdownRunning)
        countdown(config.getInt("auto-start-time"));
      return true;
    } else {
      if (config.getBoolean("enable-player-queue")) {
        if (!queue.contains(p)) {
          queue.add(p);
          msgmgr.sendFMessage(
              PrefixType.INFO, "game.playerjoinqueue", p, "queuesize-" + queue.size());
        }
        int a = 1;
        for (Player qp : queue) {
          if (qp == p) {
            msgmgr.sendFMessage(PrefixType.INFO, "game.playercheckqueue", p, "queuepos-" + a);
            break;
          }
          a++;
        }
      }
    }
    if (mode == GameMode.INGAME) msgmgr.sendFMessage(PrefixType.WARNING, "error.alreadyingame", p);
    else if (mode == GameMode.DISABLED)
      msgmgr.sendFMessage(PrefixType.WARNING, "error.gamedisabled", p, "arena-" + gameID);
    else if (mode == GameMode.RESETING)
      msgmgr.sendFMessage(PrefixType.WARNING, "error.gamereseting", p);
    else msgmgr.sendMessage(PrefixType.INFO, "Cannot join game!", p);
    LobbyManager.getInstance().updateWall(gameID);
    return false;
  }