Beispiel #1
0
  /**
   * Broadcasts level up about a player
   *
   * @param jPlayer
   * @param job
   */
  public void performLevelUp(JobsPlayer jPlayer, Job job) {
    Player player = plugin.getServer().getPlayer(jPlayer.getName());
    JobProgression prog = jPlayer.getJobProgression(job);
    if (prog == null) return;

    String message;
    if (plugin.getJobsConfiguration().isBroadcastingLevelups()) {
      message = plugin.getMessageConfig().getMessage("level-up-broadcast");
    } else {
      message = plugin.getMessageConfig().getMessage("level-up-no-broadcast");
    }
    message = message.replace("%jobname%", job.getName());
    message = message.replace("%jobcolour%", job.getChatColour().toString());
    if (prog.getTitle() != null) {
      message = message.replace("%titlename%", prog.getTitle().getName());
      message = message.replace("%titlecolour%", prog.getTitle().getChatColor().toString());
    }
    message = message.replace("%playername%", jPlayer.getName());
    if (player == null) {
      message = message.replace("%playerdisplayname%", jPlayer.getName());
    } else {
      message = message.replace("%playerdisplayname%", player.getDisplayName());
    }
    message = message.replace("%joblevel%", "" + prog.getLevel());
    for (String line : message.split("\n")) {
      if (plugin.getJobsConfiguration().isBroadcastingLevelups()) {
        plugin.getServer().broadcastMessage(line);
      } else if (player != null) {
        player.sendMessage(line);
      }
    }

    Title levelTitle = plugin.getJobsConfiguration().getTitleForLevel(prog.getLevel());
    if (levelTitle != null && !levelTitle.equals(prog.getTitle())) {
      // user would skill up
      if (plugin.getJobsConfiguration().isBroadcastingSkillups()) {
        message = plugin.getMessageConfig().getMessage("skill-up-broadcast");
      } else {
        message = plugin.getMessageConfig().getMessage("skill-up-no-broadcast");
      }
      message = message.replace("%playername%", jPlayer.getName());
      message = message.replace("%titlecolour%", levelTitle.getChatColor().toString());
      message = message.replace("%titlename%", levelTitle.getName());
      message = message.replace("%jobcolour%", job.getChatColour().toString());
      message = message.replace("%jobname%", job.getName());
      for (String line : message.split("\n")) {
        if (plugin.getJobsConfiguration().isBroadcastingLevelups()) {
          plugin.getServer().broadcastMessage(line);
        } else if (player != null) {
          player.sendMessage(line);
        }
      }
    }
    prog.setTitle(levelTitle);
    jPlayer.reloadHonorific();
    jPlayer.recalculatePermissions();
  }
Beispiel #2
0
  /**
   * Removes experience to the player
   *
   * @param jPlayer
   * @param job - the job
   * @param experience - experience gained
   */
  public void removeExperience(JobsPlayer jPlayer, Job job, double experience) {
    synchronized (jPlayer.saveLock) {
      JobProgression prog = jPlayer.getJobProgression(job);
      if (prog == null) return;
      prog.addExperience(-experience);

      jPlayer.save(plugin.getJobsCore().getJobsDAO());
    }

    Player player = plugin.getServer().getPlayer(jPlayer.getName());
    if (player != null) {
      String message = plugin.getMessageConfig().getMessage("removexp-target");
      message = message.replace("%jobcolour%", job.getChatColour().toString());
      message = message.replace("%jobname%", job.getName());
      message = message.replace("%expgained%", Double.valueOf(experience).toString());
      for (String line : message.split("\n")) {
        player.sendMessage(line);
      }
    }
  }