Exemple #1
0
  // Info:
  @Command(
      aliases = {"phelp"},
      usage = "[page]",
      flags = "",
      desc = "Display player help.",
      min = 0,
      max = 1)
  @CommandPermissions({"saga.user.help.player"})
  public static void help(CommandContext args, Saga plugin, SagaPlayer sagaPlayer) {

    Integer page = null;

    // Arguments:
    if (args.argsLength() == 1) {
      try {
        page = Integer.parseInt(args.getString(0));
      } catch (NumberFormatException e) {
        sagaPlayer.message(GeneralMessages.notNumber(args.getString(0)));
        return;
      }
    } else {
      page = 0;
    }

    // Inform:
    sagaPlayer.message(HelpMessages.phelp(page - 1));
  }
Exemple #2
0
  // Info:
  @Command(
      aliases = {"stats"},
      usage = "[page]",
      flags = "",
      desc = "Shows player stats.",
      min = 0,
      max = 1)
  @CommandPermissions({"saga.user.player.stats"})
  public static void stats(CommandContext args, Saga plugin, SagaPlayer sagaPlayer) {

    Integer page = null;

    // Arguments:
    if (args.argsLength() == 1) {

      String argsPage = args.getString(0);

      try {
        page = Integer.parseInt(argsPage);
      } catch (NumberFormatException e) {
        sagaPlayer.message(GeneralMessages.notNumber(argsPage));
        return;
      }

    } else {
      page = 1;
    }

    // Inform:
    sagaPlayer.message(StatsMessages.stats(sagaPlayer, page - 1));
  }
Exemple #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.saga.buildings.signs.BuildingSign#onRightClick(org.saga.player.SagaPlayer)
   */
  @Override
  protected void onRightClick(SagaPlayer sagaPlayer) {

    // Create item:
    ItemStack item = this.item.createItem();

    // Available goods:
    if (stored < 1.0) {
      sagaPlayer.message(EconomyMessages.insufItems(item.getType()));
      return;
    }

    // Trim amount based on goods:
    if (item.getAmount() > stored) item.setAmount(stored.intValue());

    // Trim amount based on coins:
    double coins = EconomyDependency.getCoins(sagaPlayer);
    if (item.getAmount() * price > coins) item.setAmount((int) (coins / price));

    // Available coins:
    if (item.getAmount() < 1) {
      sagaPlayer.message(EconomyMessages.insufCoins());
      return;
    }

    // Take item:
    if (item.getAmount() < 1) {
      sagaPlayer.message(EconomyMessages.insufItems(item.getType()));
      return;
    }
    stored -= item.getAmount();

    // Finish transaction:
    Double cost = price * item.getAmount();
    EconomyDependency.removeCoins(sagaPlayer, cost);
    getBuilding().getSettlement().payCoins(cost);
    sagaPlayer.addItem(item);

    // Inform:
    sagaPlayer.message(EconomyMessages.bought(item.getType(), item.getAmount(), price));

    // Statistics:
    StatisticsManager.manager()
        .addBuy(sagaPlayer, item.getType(), item.getAmount(), price * item.getAmount());

    // Update sign:
    refresh();
  }
Exemple #4
0
  private static void chatMessage(String message) {

    // Send the message to all players who have the correct permission:
    Collection<SagaPlayer> allPlayers = Saga.plugin().getLoadedPlayers();

    for (SagaPlayer loadedPlayer : allPlayers) {

      if (PermissionsDependency.hasPermission(
          loadedPlayer, PermissionsDependency.SPECIAL_CHAT_PERMISSION)) {
        loadedPlayer.message(message);
      }
    }

    // Log:
    SagaLogger.message(message);
  }
Exemple #5
0
  @Command(
      aliases = {"grenable"},
      usage = "",
      flags = "",
      desc = "Enable guardian rune.",
      min = 0,
      max = 0)
  @CommandPermissions({"saga.user.player.guardrune.enable"})
  public static void enableGuardianStone(CommandContext args, Saga plugin, SagaPlayer sagaPlayer) {

    GuardianRune rune = sagaPlayer.getGuardRune();

    // Already enabled:
    if (rune.isEnabled()) {
      sagaPlayer.message(PlayerMessages.alreadyEnabled(rune));
      return;
    }

    // Disable:
    rune.setEnabled(true);

    // Inform:
    sagaPlayer.message(PlayerMessages.enabled(rune));
  }
Exemple #6
0
  @Command(
      aliases = {"ability", "pabilityinfo, abilityinfo"},
      usage = "<ability_name>",
      flags = "",
      desc = "Display ability information.",
      min = 1)
  @CommandPermissions({"saga.user.help.player.abilityinfo"})
  public static void abilityInfo(CommandContext args, Saga plugin, SagaPlayer sagaPlayer) {

    AbilityDefinition definition = null;

    String abilityName = null;

    // Arguments:
    abilityName = GeneralMessages.nameFromArg(args.getJoinedStrings(0));
    definition = AbilityConfiguration.config().getDefinition(abilityName);
    if (definition == null) {
      sagaPlayer.message(AbilityMessages.invalidAbility(abilityName));
      return;
    }

    // Inform:
    sagaPlayer.message(HelpMessages.ability(definition));
  }
Exemple #7
0
  // Special chat:
  @Command(
      aliases = {"sc"},
      usage = "<message>",
      flags = "",
      desc = "Sends a message in the special chat.",
      min = 1)
  @CommandPermissions({"saga.special.player.chat"})
  public static void specialChat(CommandContext args, Saga plugin, SagaPlayer sagaPlayer) {

    // Send special message:
    String message =
        PlayerMessages.specialChatMessage(sagaPlayer.getName(), args.getJoinedStrings(0));

    chatMessage(message);
  }
Exemple #8
0
  /**
   * Gets armour multiplier.
   *
   * @param sagaPlayer saga player
   * @return armour multiplier
   */
  private double getArmourMultiplier(SagaPlayer sagaPlayer) {

    double armour = 0;
    PlayerInventory inventory = sagaPlayer.getPlayer().getInventory();

    ItemStack helmet = inventory.getHelmet();
    ItemStack chestplate = inventory.getChestplate();
    ItemStack leggings = inventory.getLeggings();
    ItemStack boots = inventory.getBoots();

    if (helmet != null
        && (helmet.getType().equals(Material.DIAMOND_HELMET)
            || helmet.getType().equals(Material.IRON_HELMET))) {
      armour += 0.15;
    }

    if (chestplate != null
        && (chestplate.getType().equals(Material.DIAMOND_CHESTPLATE)
            || chestplate.getType().equals(Material.IRON_CHESTPLATE))) {
      armour += 0.4;
    }

    if (leggings != null
        && (leggings.getType().equals(Material.DIAMOND_LEGGINGS)
            || leggings.getType().equals(Material.IRON_LEGGINGS))) {
      armour += 0.3;
    }

    if (boots != null
        && (boots.getType().equals(Material.DIAMOND_BOOTS)
            || boots.getType().equals(Material.IRON_BOOTS))) {
      armour += 0.15;
    }

    return armour;
  }
Exemple #9
0
  /** Creates a chunk map. */
  public static ArrayList<String> getMap(SagaPlayer sagaPlayer, Location location) {

    ArrayList<String> map = new ArrayList<String>();

    int halfHeight = 14 / 2;
    int halfWidth = 24 / 2;

    double inDegrees = location.getYaw();

    Chunk locationChunk = location.getWorld().getChunkAt(location);
    SagaChunk locationSagaChunk = sagaPlayer.getSagaChunk();

    int topLeftX = locationChunk.getX() - halfWidth;
    int topLeftZ = locationChunk.getZ() + halfHeight;

    int width = halfHeight * 2 + 1;
    int height = halfWidth * 2 + 1;

    ChatColor prevColor = null;
    ChatColor color = ChatColor.GRAY;

    // Row:
    for (int dz = -width + 1; dz <= 0; dz++) {
      prevColor = null;
      color = null;

      // Column:
      StringBuffer row = new StringBuffer();
      for (int dx = 0; dx < height; dx++) {

        SagaChunk sagaChunk =
            BundleManager.manager()
                .getSagaChunk(location.getWorld().getName(), topLeftX + dx, topLeftZ + dz);

        String symbol = "?";

        // Claimed:
        if (sagaChunk != null) {

          // Building:
          if (sagaChunk.getBuilding() != null) {
            symbol = BUILDING.replace("B", sagaChunk.getBuilding().getMapChar());
            color = ChatColor.DARK_PURPLE;
          }

          // Border:
          else if (sagaChunk.isBorder()) {
            symbol = BORDER;
            color = ChatColor.GOLD;
          }

          // Claimed:
          else {
            symbol = CLAIMED;
            color = ChatColor.YELLOW;
          }

        }

        // Not claimed:
        else {

          symbol = WILDERNESS;

          Biome biome =
              location.getWorld().getBiome((topLeftX + dx) * 16 + 8, (topLeftZ + dz) * 16 + 8);
          color = BIOME_COLOURS.get(biome);
          if (color == null) color = ChatColor.GRAY;
        }

        // Player location:
        if (dx == halfWidth && dz == -halfHeight) {
          color = ChatColor.DARK_RED;
          symbol = YOUAREHERE;
        }

        // Append new colour:
        if (prevColor != color) {
          row.append(color);
          prevColor = color;
        }

        // Append symbol:
        row.append(symbol);
      }

      map.add(row.toString());
    }

    // Get the compass:
    ArrayList<String> asciiCompass =
        AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, ChatColor.GOLD);

    // Add the compass:
    map.set(0, map.get(0) + " " + asciiCompass.get(0));
    map.set(1, map.get(1) + " " + asciiCompass.get(1));
    map.set(2, map.get(2) + " " + asciiCompass.get(2));

    // Add name:
    char[] locationName = null;

    if (locationSagaChunk != null) {
      locationName = locationSagaChunk.getChunkBundle().getName().toUpperCase().toCharArray();
    } else {
      locationName = "WILDERNESS".toCharArray();
    }

    for (int i = 0; i + 4 < map.size() && i < locationName.length; i++) {
      map.set(i + 4, map.get(i + 4) + "   " + ChatColor.GOLD + locationName[i]);
    }

    return map;
  }