Пример #1
0
 /**
  * Construct our PlayerListener.
  *
  * @param instance
  * @param configMV
  */
 public MVPlayerListener(MultiVerse instance, Configuration configMV) {
   /** Setup our Plugin, Server and Configuration variables which we initialised. */
   this.plugin = instance;
   this.server = instance.getServer();
   this.configuration = configMV;
   /** Create new instances of MVUtils and MVTeleport and assign them to our variables. */
   this.utils = new MVUtils(instance);
   this.playerTeleporter = new MVTeleport(this.plugin);
 }
Пример #2
0
  /** On player move, detect they are inside a portal then teleport them appropriately. */
  @Override
  public void onPlayerMove(PlayerMoveEvent event) {
    if (event.isCancelled()) {
      return;
    }
    /** Grab the Player and our Players Session */
    final Player pl = event.getPlayer();
    final Location loc = pl.getLocation();

    MVPlayerSession ps = this.plugin.getPlayerSession(pl);
    if (ps == null
        || ps.getLocation().getBlockX() == loc.getBlockX()
            && ps.getLocation().getBlockY() == loc.getBlockY()
            && ps.getLocation().getBlockZ() == loc.getBlockZ()) {
      return;
    } else {
      ps.setLocation(loc); // Update the Players Session to the new Location.
    }

    /** Start the Price off at 0, this will change according to the Portal/World Settings. */
    Integer price = 0;
    /** Start of our Location as NULL, this allows us to check it later on. */
    Location d = null;
    /**
     * First we do a check against all the Portals we have created, if the area the user is within
     * is a Portal then we will act upon it; if not then we move onto our next check.
     */
    String ptest = utils.isPortal(pl.getLocation());
    if (ptest != null) {
      MVPortal p = this.plugin.MVPortals.get(ptest);
      price = (int) Math.round(p.getPrice());
      d = playerTeleporter.portalDestination(pl, ptest, p);
    }
    /** End of First Portal Check. */

    /**
     * If the first Portal Check failed then we will check for Any Signs around the player. This
     * check is only performed if the user is standing inside a Portal Block.
     */
    if (this.plugin.configMV.getBoolean("checksigns", true) && d == null) {
      d = playerTeleporter.portalSignMethod(pl);
    }
    /** End of Sign Based Portal Check. */

    /**
     * Standard Nether Portal Check, this will be for a Single Player like feel, customizeable...
     * Can be on or off.
     */
    if (this.plugin.configMV.getBoolean("splike", false) && d == null) {
      d = playerTeleporter.portalSPNether(pl);
    }
    /** End of Single Player Nether Check. */

    // TODO: Permissions to add here...
    /** If we have a Location set and it is NOT NULL then we can perform a teleport. */
    if (d != null) {
      if (!ps.getTeleportable()) {
        return;
      }
      if (!playerTeleporter.canTravelFromWorld(pl, d.getWorld())) {
        ps.sendMessage(
            "Sorry but you cannot travel to '" + d.getWorld().getName() + "' from this World!");
        return;
      }
      if (!playerTeleporter.canEnterWorld(pl, d.getWorld())) {
        ps.sendMessage("Sorry but you cannot enter the '" + d.getWorld().getName() + "' world.");
        return;
      }
      if (MultiVerse.useiConomy
          && !MultiVerse.Permissions.has(pl, "multiverse.portal.exempt")
          && price > 0) {
        Holdings balance = iConomy.getAccount(pl.getName()).getHoldings();
        if (balance.hasEnough(price)) {
          balance.subtract(price);
          pl.sendMessage(
              ChatColor.RED
                  + this.plugin.logPrefix
                  + " You have been charged "
                  + iConomy.format(price));
        } else {
          if (ps.getAlertable()) {
            pl.sendMessage("Sorry but you do not have the required funds for this portal");
            ps.setAlertCooldown();
          }
          return;
        }
      }
      final Location destination = d;
      plugin
          .getServer()
          .getScheduler()
          .scheduleSyncDelayedTask(
              plugin,
              new Runnable() {
                @Override
                public void run() {
                  pl.teleport(destination);
                }
              });
      ps.setTPCooldown();
      return;
    }
    return;
  }