示例#1
0
  @Override
  public double getBalance(String player) {
    Account account = eco.getBank().getAccount(player);
    if (account == null) {
      eco.getBank().addAccount(player);
      account = eco.getBank().getAccount(player);
    }

    return account.getBalance();
  }
示例#2
0
  @Override
  public boolean deposit(String player, double amount) {
    if (amount > 0) {
      Account account = eco.getBank().getAccount(player);
      if (account == null) {
        eco.getBank().addAccount(player);
        account = eco.getBank().getAccount(player);
      }

      account.add(amount);
      return true;
    }
    return false;
  }
示例#3
0
  @Override
  public boolean withdraw(String player, double amount) {
    if (amount > 0) {
      Account account = eco.getBank().getAccount(player);
      if (account == null) {
        eco.getBank().addAccount(player);
        account = eco.getBank().getAccount(player);
      }

      double balance = account.getBalance();
      if ((balance - amount) >= 0) {
        account.subtract(amount);
        return true;
      }
    }

    return false;
  }
  /* (non-Javadoc)
   * @see org.bukkit.event.player.PlayerListener#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)
   */
  @Override
  public void onPlayerMove(PlayerMoveEvent event) {
    Player p = event.getPlayer();
    Location l = event.getTo();
    Block ch = l.getWorld().getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ());
    Stargate st = StargateManager.getGateFromBlock(ch);

    if (st != null && st.Active && st.Target != null) {
      String gatenetwork;
      if (st.Network != null) {
        gatenetwork = st.Network.netName;
      } else {
        gatenetwork = "Public";
      }
      wxt.prettyLog(
          Level.FINE,
          false,
          "Player in gate:"
              + st.Name
              + " gate Active: "
              + st.Active
              + " Target Gate: "
              + st.Target.Name
              + " Network: "
              + gatenetwork);

      if (ConfigManager.getWormholeUseIsTeleport()
          && ((st.IsSignPowered && !WXPermissions.checkWXPermissions(p, st, PermissionType.SIGN))
              || (!st.IsSignPowered
                  && !WXPermissions.checkWXPermissions(p, st, PermissionType.DIALER)))) {
        p.sendMessage(ConfigManager.output_strings.get(StringTypes.PERMISSION_NO));
        return;
      }
      if (st.Target.IrisActive) {
        p.sendMessage(ConfigManager.errorheader + "Remote Iris is locked!");
        p.setNoDamageTicks(2);
        event.setFrom(st.TeleportLocation);
        event.setTo(st.TeleportLocation);
        p.teleport(st.TeleportLocation);
        if (p.getFireTicks() > 0) {
          p.setFireTicks(0);
        }
        return;
      }

      Location target = st.Target.TeleportLocation;
      if (WormholeXTreme.iconomy != null) {
        double cost = ConfigManager.getIconomyWormholeUseCost();
        if (!ConfigManager.getIconomyOpsExcempt()
            && !p.isOp()
            && cost != 0.0
            && st.Owner != null
            && !st.Owner.equals(p.getName())) {
          Account player_account = iConomy.getBank().getAccount(p.getName());
          double balance = player_account.getBalance();
          String currency = iConomy.getBank().getCurrency();
          if (balance >= cost) {
            player_account.subtract(cost);
            // player_account.save();
            p.sendMessage(
                ConfigManager.normalheader
                    + "Wormhole Use \u00A7F- \u00A72"
                    + cost
                    + " \u00A77"
                    + currency);
            // p.sendMessage("You were charged " + cost + " " + iConomy.getBank().getCurrency() + "
            // to use wormhole." );
            double owner_percent = ConfigManager.getIconomyWormholeOwnerPercent();

            if (owner_percent != 0.0 && st.Owner != null) {
              if (st.Owner != null && iConomy.getBank().hasAccount(st.Owner)) {
                Account own_acc = iConomy.getBank().getAccount(st.Owner);
                own_acc.add(cost * owner_percent);
                // own_acc.save();
              }
            }
          } else {
            p.sendMessage(
                ConfigManager.errorheader
                    + "Not enough "
                    + currency
                    + "! - Requires: \u00A72"
                    + cost
                    + " \u00A77- Available: \u00A74"
                    + player_account.getBalance()
                    + " \u00A77"
                    + currency);
            // p.sendMessage("Not enough " + iConomy.getBank().getCurrency() + " to use - requires:
            // " + cost);
            target = st.TeleportLocation;
          }
        }
      }

      Block target_block =
          target.getWorld().getBlockAt(target.getBlockX(), target.getBlockY(), target.getBlockZ());
      while (target_block.getType() != Material.AIR
          && target_block.getType() != Material.WATER
          && target_block.getType() != Material.LAVA) {
        target_block = target_block.getFace(BlockFace.UP);
        target.setY(target.getY() + 1.0);
      }
      event.setFrom(target);
      event.setTo(target);
      p.setNoDamageTicks(2);
      p.teleport(target);
      event.setCancelled(true);
      if (target == st.Target.TeleportLocation)
        wxt.prettyLog(
            Level.INFO,
            false,
            p.getDisplayName() + " used wormhole: " + st.Name + " to go to: " + st.Target.Name);

      if (ConfigManager.getTimeoutShutdown() == 0) {
        st.ShutdownStargate();
      }
    } else if (st != null) {
      wxt.prettyLog(
          Level.FINE, false, "Player entered gate but wasn't active or didn't have a target.");
    }
  }
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Action action = event.getAction();
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
      Block block = event.getClickedBlock();
      Material type = block.getType();
      Player player = event.getPlayer();

      GlobalConfiguration cfg = plugin.getGlobalConfiguration();
      WorldConfiguration wcfg = cfg.getWorldConfig(event.getClickedBlock().getWorld().getName());

      if (wcfg.useRegions && player.getItemInHand().getTypeId() == wcfg.regionWand) {
        Vector pt = toVector(block);

        RegionManager mgr =
            plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
        ApplicableRegionSet app = mgr.getApplicableRegions(pt);
        List<String> regions = mgr.getApplicableRegionsIDs(pt);

        if (regions.size() > 0) {
          player.sendMessage(
              ChatColor.YELLOW
                  + "Can you build? "
                  + (app.canBuild(BukkitPlayer.wrapPlayer(plugin, player)) ? "Yes" : "No"));

          StringBuilder str = new StringBuilder();
          for (Iterator<String> it = regions.iterator(); it.hasNext(); ) {
            str.append(it.next());
            if (it.hasNext()) {
              str.append(", ");
            }
          }

          player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
        } else {
          player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
        }
      }

      if (block.getType() == Material.CHEST
          || block.getType() == Material.DISPENSER
          || block.getType() == Material.FURNACE
          || block.getType() == Material.BURNING_FURNACE
          || block.getType() == Material.NOTE_BLOCK) {
        if (wcfg.useRegions) {
          Vector pt = toVector(block);
          LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());

          if (!plugin.hasPermission(player, "region.bypass")) {
            ApplicableRegionSet set = mgr.getApplicableRegions(pt);
            if (!set.isStateFlagAllowed(Flags.CHEST_ACCESS) && !set.canBuild(localPlayer)) {
              player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
              event.setCancelled(true);
              return;
            }
          }
        }
      }

      if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON)) {
        Vector pt = toVector(block);
        RegionManager mgr =
            cfg.getWorldGuardPlugin()
                .getGlobalRegionManager()
                .getRegionManager(player.getWorld().getName());
        ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
        LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);

        if (!applicableRegions.isStateFlagAllowed(Flags.LEVER_AND_BUTTON, localPlayer)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
          event.setCancelled(true);
          return;
        }
      }

      if (wcfg.useRegions && type == Material.CAKE_BLOCK) {

        Vector pt = toVector(block);

        if (!cfg.canBuild(player, pt)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");

          byte newData = (byte) (block.getData() - 1);
          newData = newData < 0 ? 0 : newData;

          block.setData(newData);
          player.setHealth(player.getHealth() - 3);

          return;
        }
      }

      if (wcfg.useRegions
          && wcfg.useiConomy
          && cfg.getiConomy() != null
          && (type == Material.SIGN_POST || type == Material.SIGN || type == Material.WALL_SIGN)) {
        BlockState blockstate = block.getState();

        if (((Sign) blockstate).getLine(0).equalsIgnoreCase("[WorldGuard]")
            && ((Sign) blockstate).getLine(1).equalsIgnoreCase("For sale")) {
          String regionId = ((Sign) blockstate).getLine(2);
          // String regionComment = ((Sign)block).getLine(3);

          if (regionId != null && regionId != "") {
            RegionManager mgr =
                cfg.getWorldGuardPlugin()
                    .getGlobalRegionManager()
                    .getRegionManager(player.getWorld().getName());
            ProtectedRegion region = mgr.getRegion(regionId);

            if (region != null) {
              RegionFlagContainer flags = region.getFlags();

              if (flags.getBooleanFlag(Flags.BUYABLE).getValue(false)) {
                if (iConomy.getBank().hasAccount(player.getName())) {
                  Account account = iConomy.getBank().getAccount(player.getName());
                  double balance = account.getBalance();
                  double regionPrice = flags.getDoubleFlag(Flags.PRICE).getValue();

                  if (balance >= regionPrice) {
                    account.subtract(regionPrice);
                    player.sendMessage(
                        ChatColor.YELLOW
                            + "You have bought the region "
                            + regionId
                            + " for "
                            + iConomy.getBank().format(regionPrice));
                    DefaultDomain owners = region.getOwners();
                    owners.addPlayer(player.getName());
                    region.setOwners(owners);
                    flags.getBooleanFlag(Flags.BUYABLE).setValue(false);
                    account.save();
                  } else {
                    player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                  }
                } else {
                  player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                }
              } else {
                player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable");
              }
            } else {
              player.sendMessage(
                  ChatColor.DARK_RED + "The region " + regionId + " does not exist.");
            }
          } else {
            player.sendMessage(ChatColor.DARK_RED + "No region specified.");
          }
        }
      }

      if (wcfg.getBlacklist() != null) {

        if (!wcfg.getBlacklist()
            .check(
                new BlockInteractBlacklistEvent(
                    BukkitPlayer.wrapPlayer(plugin, player), toVector(block), block.getTypeId()),
                false,
                false)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }