@Override
  public void onBlockPlace(BlockPlaceEvent event) {
    if (event.isCancelled()) return;

    final Player player = event.getPlayer();
    final Block block = event.getBlock();

    // Check if block in an ExpensiveType
    if (!fieldManager.isExpensiveType(block.getTypeId())) return;
    // Check if block is known to PreciousStone (did stone get registered there)
    if (!stones.getForceFieldManager().isField(block)) return;
    System.out.println("Expst: stone is a Field block.");
    // Do nothing when player has bypass permissions
    if (permissionManager.bypassResult(player)) {
      player.sendMessage(
          ChatColor.YELLOW + "ExpensiveStones: Bypassed! Field handled by PreciousStones.");
      return;
    }

    // Add Field, will auto-dormant in creation of ExpensiveField
    ExpensiveField expField = new ExpensiveField(stones.getForceFieldManager().getField(block));
    fieldManager.addField(expField, true);
    player.sendMessage(ChatColor.YELLOW + "ExpensiveStones: stone detected! Stone is disabled.");
    player.sendMessage(ChatColor.YELLOW + "Place chest and sign to activate the field.");
  }
  /** @param event */
  @EventHandler(priority = EventPriority.HIGH)
  public void onVehicleDestroy(VehicleDestroyEvent event) {
    Vehicle vehicle = event.getVehicle();

    Field field =
        plugin
            .getForceFieldManager()
            .getEnabledSourceField(vehicle.getLocation(), FieldFlag.PREVENT_VEHICLE_DESTROY);

    if (field != null) {
      if (event.getAttacker() instanceof Player) {
        Player player = (Player) event.getAttacker();

        if (FieldFlag.PREVENT_VEHICLE_DESTROY.applies(field, player)) {
          if (plugin.getPermissionsManager().has(player, "preciousstones.bypass.destroy")) {
            plugin.getCommunicationManager().notifyBypassDestroyVehicle(player, vehicle, field);
          } else {
            event.setCancelled(true);
            plugin.getCommunicationManager().warnDestroyVehicle(player, vehicle, field);
            return;
          }
        }
      }
    }
  }
Example #3
0
  /**
   * Execute an insert statement
   *
   * @param query
   */
  public long insert(String query) {
    if (PreciousStones.getInstance().getSettingsManager().isDebugsql()) {
      PreciousStones.getLog().info(query);
    }

    try {
      Statement statement = getConnection().createStatement();
      ResultSet keys = null;

      try {
        statement.executeUpdate(query);
        keys = statement.executeQuery("SELECT last_insert_rowid()");
      } finally {
        if (keys != null) {
          if (keys.next()) {
            return keys.getLong(1);
          }
        }
        statement.close();
        return 0;
      }
    } catch (SQLException ex) {
      if (!ex.toString().contains("not return ResultSet")) {
        log.severe("Error at SQL INSERT Query: " + ex);
        log.severe("Query: " + query);
      }
    }

    return 0;
  }
  /**
   * @param player
   * @param field
   */
  public void addFieldMark(Player player, Field field) {
    Visualization vis = visualizations.get(player.getName());

    if (vis == null) {
      vis = new Visualization();
    }

    vis.addField(field);

    World world = plugin.getServer().getWorld(field.getWorld());

    if (world != null) {
      for (int y = 0; y < 256; y++) {
        int typeId = world.getBlockTypeIdAt(field.getX(), y, field.getZ());

        if (plugin.getSettingsManager().isThroughType(typeId)) {
          vis.addBlock(
              new Location(world, field.getX(), y, field.getZ()),
              plugin.getSettingsManager().getVisualizeMarkBlock(),
              (byte) 0);
        }
      }
    }

    visualizations.put(player.getName(), vis);
  }
  /**
   * @param player
   * @param field
   */
  public void enterLightning(final Player player, final Field field) {
    if (plugin.getPermissionsManager().hasPermission(player, "preciousstones.bypass.lightning")) {
      return;
    }

    if (!plugin.getForceFieldManager().isAllowed(field, player.getName())) {
      FieldSettings fs = field.getSettings();

      final int delay = fs.getLightningDelaySeconds();
      final int leftbehind = fs.getLightningReplaceBlock();

      if (fs.hasFlag(FieldFlag.LIGHTNING)) {
        plugin.getCommunicationManager().showLightning(player);

        plugin
            .getServer()
            .getScheduler()
            .scheduleSyncDelayedTask(
                plugin,
                new Runnable() {
                  public void run() {
                    Block block = plugin.getForceFieldManager().getBlock(field);

                    player.getWorld().strikeLightning(player.getLocation());

                    if (leftbehind >= 0) {
                      plugin.getForceFieldManager().silentRelease(field);
                      block.setType(Material.getMaterial(leftbehind));
                    }
                  }
                },
                delay * 20L);
      }
    }
  }
  public boolean teleport(Entity entity, Field sourceField, String announce) {
    Field destinationField =
        plugin.getForceFieldManager().getDestinationField(sourceField.getOwner(), sourceField);

    if (destinationField != null) {
      if (sourceField.getSettings().getTeleportMaxDistance() > 0) {
        if (sourceField.getLocation().distance(destinationField.getLocation())
            > sourceField.getSettings().getTeleportMaxDistance()) {
          Player player = Bukkit.getServer().getPlayerExact(sourceField.getOwner());

          if (player != null) {
            ChatBlock.send(
                player, "teleportMaxDistance", sourceField.getSettings().getTeleportMaxDistance());
          }
          return false;
        }
      }

      if (sourceField.getSettings().getTeleportCost() > 0) {
        if (plugin.getPermissionsManager().hasEconomy()) {
          if (PermissionsManager.hasMoney(
              sourceField.getOwner(), sourceField.getSettings().getTeleportCost())) {
            plugin
                .getPermissionsManager()
                .playerCharge(sourceField.getOwner(), sourceField.getSettings().getTeleportCost());
          } else {
            Player player = Bukkit.getServer().getPlayerExact(sourceField.getOwner());

            if (player != null) {
              ChatBlock.send(player, "economyNotEnoughMoney");
            }
            return false;
          }
        }
      }

      if (sourceField.hasFlag(FieldFlag.TELEPORT_RELATIVELY)) {
        return plugin
            .getTeleportationManager()
            .teleport(
                new TeleportEntry(
                    entity,
                    new RelativeBlock(sourceField.toVec(), new Vec(entity.getLocation())),
                    sourceField,
                    destinationField,
                    announce));
      } else {
        return plugin
            .getTeleportationManager()
            .teleport(new TeleportEntry(entity, sourceField, destinationField, announce));
      }
    }

    return false;
  }
  private boolean isEmptySpace(World world, int x, int y, int z) {
    int type1 = world.getBlockTypeIdAt(x, y, z);
    int type2 = world.getBlockTypeIdAt(x, y, z);

    if (plugin.getSettingsManager().isThroughType(type1)
        && plugin.getSettingsManager().isThroughType(type2)) {
      return true;
    }

    return false;
  }
  /**
   * Get a player's data file
   *
   * @param playerName
   * @return
   */
  public PlayerEntry getPlayerEntry(String playerName) {
    // look for player in memory
    PlayerEntry data = players.get(playerName.toLowerCase());

    // otherwise look in database
    if (data == null) {
      data = plugin.getStorageManager().extractPlayer(playerName);
      if (data == null) {
        data = plugin.getStorageManager().createPlayer(playerName, null);
      }
      players.put(playerName.toLowerCase(), data);
    }

    return data;
  }
  private void detectLWC() {
    Plugin lwcPlugin = plugin.getServer().getPluginManager().getPlugin("LWC");

    if (lwcPlugin != null) {
      lwc = ((LWCPlugin) lwcPlugin).getLWC();
    }
  }
 public ESBlockListener() {
   stones = PreciousStones.getInstance();
   plugin = ExpensiveStones.getInstance();
   fieldManager = plugin.getESFieldManager();
   powerManager = plugin.getESPowerManager();
   permissionManager = plugin.getESPermissionManager();
 }
Example #11
0
  public Field getField() {
    if (field != null) {
      return field;
    }

    return PreciousStones.getInstance().getForceFieldManager().getField(getAttachedBlock());
  }
  public void offerOnlinePlayerEntries() {
    Collection<Player> onlinePlayers = Helper.getOnlinePlayers();

    for (Player player : onlinePlayers) {
      plugin.getStorageManager().offerPlayer(player.getName());
    }
  }
Example #13
0
  /**
   * Gets the maximum amount of fields a player can place
   *
   * @param player
   * @param fs the field settings of the field you need to get the limit of
   * @return the limit, -1 if no limit
   */
  public int getLimit(Player player, FieldSettings fs) {
    List<Integer> limits = fs.getLimits();

    if (limits.isEmpty()) {
      return -1;
    }

    List<Integer> playersLimits = new ArrayList<Integer>();

    // get all the counts for all limits the player has

    for (int i = limits.size() - 1; i >= 0; i--) {
      if (plugin.getPermissionsManager().has(player, "preciousstones.limit" + (i + 1))) {
        playersLimits.add(limits.get(i));
      }
    }

    // return the highest one

    if (!playersLimits.isEmpty()) {
      return Collections.max(playersLimits);
    }

    return -1;
  }
  /**
   * Whether SimpleClans was loaded
   *
   * @return
   */
  public boolean hasSimpleClans() {
    if (plugin.getSettingsManager().isDisableSimpleClanHook()) {
      return false;
    }

    return simpleClans != null;
  }
  /** @param event */
  @EventHandler(priority = EventPriority.HIGH)
  public void onVehicleMove(VehicleMoveEvent event) {
    Vehicle v = event.getVehicle();
    Entity entity = v.getPassenger();

    if (plugin.getSettingsManager().isBlacklistedWorld(v.getLocation().getWorld())) {
      return;
    }

    if (!(entity instanceof Player)) {
      return;
    }

    plugin
        .getPlayerListener()
        .onPlayerMove(new PlayerMoveEvent((Player) entity, event.getFrom(), event.getTo()));
  }
  private void getWorldGuard() {
    if (wg == null) {
      Plugin test = plugin.getServer().getPluginManager().getPlugin("WorldGuard");

      if (test != null) {
        this.wg = (WorldGuardPlugin) test;
      }
    }
  }
  private void detectPermissions() {
    if (handler == null) {
      Plugin test = plugin.getServer().getPluginManager().getPlugin("Permissions");

      if (test != null) {
        handler = ((Permissions) test).getHandler();
      }
    }
  }
  private void getSimpleClans() {
    if (simpleClans == null) {
      Plugin test = plugin.getServer().getPluginManager().getPlugin("SimpleClans");

      if (test != null) {
        this.simpleClans = (SimpleClans) test;
      }
    }
  }
  private void detectPermissionsEx() {
    if (pex == null) {
      Plugin test = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");

      if (test != null) {
        pex = (PermissionsEx) test;
      }
    }
  }
  private void detectPermissionsBukkit() {
    if (pbukkit == null) {
      Plugin test = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");

      if (test != null) {
        pbukkit = ((PermissionsPlugin) test);
      }
    }
  }
Example #21
0
  /**
   * Execute a delete statement
   *
   * @param query
   */
  public void delete(String query) {
    if (PreciousStones.getInstance().getSettingsManager().isDebugsql()) {
      PreciousStones.getLog().info(query);
    }

    try {
      Statement statement = getConnection().createStatement();

      try {
        statement.executeQuery(query);
      } finally {
        statement.close();
      }
    } catch (SQLException ex) {
      if (!ex.toString().contains("not return ResultSet")) {
        log.severe("Error at SQL DELETE Query: " + ex);
        log.severe("Query: " + query);
      }
    }
  }
Example #22
0
  /**
   * Execute a statement
   *
   * @param query
   * @return
   */
  public Boolean execute(String query) {
    if (PreciousStones.getInstance().getSettingsManager().isDebugsql()) {
      PreciousStones.getLog().info(query);
    }

    try {
      Statement statement = getConnection().createStatement();
      Boolean result = false;
      try {
        result = statement.execute(query);
      } finally {
        statement.close();
        return result;
      }
    } catch (SQLException ex) {
      log.severe(ex.getMessage());
      log.severe("Query: " + query);
      return false;
    }
  }
 private Boolean setupPermissions() {
   RegisteredServiceProvider<Permission> permissionProvider =
       plugin
           .getServer()
           .getServicesManager()
           .getRegistration(net.milkbowl.vault.permission.Permission.class);
   if (permissionProvider != null) {
     permission = permissionProvider.getProvider();
   }
   return (permission != null);
 }
Example #24
0
  /**
   * Whether the player has reached the placing limit for a field
   *
   * @param player
   * @param fs the field settings of the field you need to get the limit of
   * @return
   */
  public boolean reachedLimit(Player player, FieldSettings fs) {
    List<Integer> limits = fs.getLimits();

    if (limits.isEmpty()) {
      return false;
    }

    if (plugin.getPermissionsManager().has(player, "preciousstones.bypass.limits")) {
      return false;
    }

    int limit = getLimit(player, fs);
    int count =
        plugin.getForceFieldManager().getFieldCount(player.getName(), fs.getTypeEntry())
            + plugin
                .getForceFieldManager()
                .getRentedFieldCount(player.getName(), fs.getTypeEntry());

    if (limit == -1) {
      return false;
    }

    if (limit == 0) {
      ChatHelper.send(player, "limitsCannotPlace", fs.getTitle());
      return true;
    }

    if (count >= limit) {
      ChatHelper.send(player, "limitsReached", fs.getTitle(), limit);
      return true;
    }

    int totalCount = plugin.getForceFieldManager().getTotalFieldCount(player.getName());

    if (totalCount >= plugin.getSettingsManager().getGlobalFieldLimit()) {
      ChatHelper.send(player, "limitsReachedGlobal", limit);
      return true;
    }

    return false;
  }
  private Boolean setupEconomy() {
    RegisteredServiceProvider<Economy> economyProvider =
        plugin
            .getServer()
            .getServicesManager()
            .getRegistration(net.milkbowl.vault.economy.Economy.class);

    if (economyProvider != null) {
      economy = economyProvider.getProvider();
    }

    return (economy != null);
  }
  @Override
  public void onSignChange(SignChangeEvent event) {
    if (event.isCancelled()) return;

    if (!event.getLine(0).equalsIgnoreCase("[ExpStone]")) return;

    // Get basics
    final Block block = event.getBlock();
    final Player player = event.getPlayer();
    // Get a certein block.
    final Block fieldBlock = BlockUtil.getFieldStone(block, true);
    // Chech if any surrounding blocks is a known fieldblock.
    if (fieldBlock == null) {
      player.sendMessage(ChatColor.YELLOW + "ExpensiveStones: No Expensive StoneType Found.");
      return;
    }
    // _____________________Test Adming_____________________________
    if (event.getLine(2).equalsIgnoreCase("admin")) {
      // Check rights
      if (!player.hasPermission(ESPermissionManager.PERM_ADMIN)) {
        player.sendMessage(
            ChatColor.YELLOW
                + "ExpensiveStones: You don't have the permissions to make an adminField.");
      } else {
        fieldManager.setAdminField(fieldManager.getExpensiveField(block));
        player.sendMessage(
            ChatColor.YELLOW
                + "ExpensiveStones: Admin-Field created, field is now handled by PreciousStones.");
        player.sendMessage(ChatColor.YELLOW + "You can now destroy this sign.");
      }
      return;
    }

    // _____________________Normal Player___________________________
    final Block chestBlock = BlockUtil.getChest(block);
    // Chech chest
    if (chestBlock == null) {
      player.sendMessage(ChatColor.YELLOW + "ExpensiveStones: No chest found for register");
      return;
    }
    final ExpensiveField expField =
        new ExpensiveField(block, chestBlock, stones.getForceFieldManager().getField(fieldBlock));
    fieldManager.disableField(expField);
    event.setLine(1, expField.getField().getOwner());
    event.setLine(2, expField.getSettings().getMaterial().toString());
    event.setLine(3, "<DISABLED>");
    player.sendMessage(
        ChatColor.YELLOW + "ExpensiveStones: Field Registered, click to enable field");
  }
  /**
   * Get a player's data file, will look up by UUID first, then name.
   *
   * @param player
   * @return
   */
  public PlayerEntry getPlayerEntry(Player player) {
    // look for player in memory
    String playerName = player.getName();
    PlayerEntry data = players.get(playerName.toLowerCase());

    // otherwise look in database
    if (data == null) {
      UUID uuid = player.getUniqueId();

      data = plugin.getStorageManager().extractPlayer(uuid);
      if (data == null) {
        data = plugin.getStorageManager().extractPlayer(player.getName());
      } else if (!playerName.equalsIgnoreCase(data.getName())) {
        plugin.getStorageManager().migrate(data.getName(), playerName);
        data.setName(playerName);
      }
      if (data == null) {
        data = plugin.getStorageManager().createPlayer(playerName, uuid);
      }
      players.put(playerName.toLowerCase(), data);
    }

    return data;
  }
  public PermissionsManager() {
    plugin = PreciousStones.getInstance();
    detectPermissionsBukkit();
    detectPermissionsEx();
    detectPermissions();
    detectLWC();

    try {
      Class.forName("net.milkbowl.vault.permission.Permission");

      setupEconomy();
      setupPermissions();
    } catch (ClassNotFoundException e) {
      // SimpleClans.log("[PreciousStones] Vault.jar not found. No economy support.");
      // no need to spam everyone who doesnt use vault
    }
  }
  /**
   * @param owner
   * @param playerName
   * @return
   */
  public boolean isAllyOwner(String owner, String playerName) {
    if (!hasSimpleClans()) {
      return false;
    }

    Player player = plugin.getServer().getPlayerExact(playerName);

    if (player != null) {
      ClanPlayer cpOwner = simpleClans.getClanManager().getClanPlayer(owner);

      if (cpOwner != null) {
        return cpOwner.isAlly(player);
      }
    }

    return false;
  }
  public boolean canBuild(Player player, Location loc) {
    try {
      if (wg == null) {
        return true;
      }

      // if null passed then pick up some random player

      if (player == null) {
        player = plugin.getServer().getWorlds().get(0).getPlayers().get(0);
      }

      return wg.canBuild(player, loc);
    } catch (Exception ex) {
      return true;
    }
  }