Beispiel #1
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (CommandUtils.noConsoleUsage(sender)) {
      return true;
    }

    switch (args.length) {
      case 0:
        McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
        Player player = mcMMOPlayer.getPlayer();

        if (Config.getInstance().getMcstatsScoreboardsEnabled()) {
          ScoreboardManager.setupPlayerScoreboard(player.getName());
          ScoreboardManager.enablePlayerStatsScoreboard(mcMMOPlayer);
        } else {
          player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
          player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));

          CommandUtils.printGatheringSkills(player);
          CommandUtils.printCombatSkills(player);
          CommandUtils.printMiscSkills(player);

          int powerLevelCap = Config.getInstance().getPowerLevelCap();

          if (powerLevelCap != Integer.MAX_VALUE) {
            player.sendMessage(
                LocaleLoader.getString(
                    "Commands.PowerLevel.Capped",
                    UserManager.getPlayer(player).getPowerLevel(),
                    powerLevelCap));
          } else {
            player.sendMessage(
                LocaleLoader.getString(
                    "Commands.PowerLevel", UserManager.getPlayer(player).getPowerLevel()));
          }
        }

        return true;

      default:
        return false;
    }
  }
Beispiel #2
0
  /** Things to be run when the plugin is disabled. */
  @Override
  public void onDisable() {
    try {
      Alchemy
          .finishAllBrews(); // Finish all partially complete AlchemyBrewTasks to prevent vanilla
                             // brewing continuation on restart
      UserManager.saveAll(); // Make sure to save player information if the server shuts down
      PartyManager.saveParties(); // Save our parties
      ScoreboardManager.teardownAll();
      formulaManager.saveFormula();
      placeStore.saveAll(); // Save our metadata
      placeStore.cleanUp(); // Cleanup empty metadata stores
    } catch (NullPointerException e) {
    }

    getServer().getScheduler().cancelTasks(this); // This removes our tasks
    HandlerList.unregisterAll(this); // Cancel event registrations

    if (Config.getInstance().getBackupsEnabled()) {
      // Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
      try {
        ZipLibrary.mcMMOBackup();
      } catch (IOException e) {
        getLogger().severe(e.toString());
      } catch (Throwable e) {
        if (e instanceof NoClassDefFoundError) {
          getLogger().severe("Backup class not found!");
          getLogger().info("Please do not replace the mcMMO jar while the server is running.");
        } else {
          getLogger().severe(e.toString());
        }
      }
    }

    debug("Was disabled."); // How informative!
  }
Beispiel #3
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    switch (args.length) {
      case 1:
        if (sender instanceof Player && Config.getInstance().getInspectScoreboardEnabled()) {
          ScoreboardManager.setupPlayerScoreboard(sender.getName());
        }

        String playerName = Misc.getMatchedPlayerName(args[0]);
        McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);

        // If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in
        // the database. If it's not, abort the process.
        if (mcMMOPlayer == null) {
          PlayerProfile profile =
              mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false); // Temporary Profile

          if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
            return true;
          }

          if (sender instanceof Player && Config.getInstance().getInspectScoreboardEnabled()) {
            ScoreboardManager.enablePlayerInspectScoreboardOffline((Player) sender, profile);
            return true;
          }

          sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", playerName));

          sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
          for (SkillType skill : SkillType.GATHERING_SKILLS) {
            sender.sendMessage(CommandUtils.displaySkill(profile, skill));
          }

          sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat"));
          for (SkillType skill : SkillType.COMBAT_SKILLS) {
            sender.sendMessage(CommandUtils.displaySkill(profile, skill));
          }

          sender.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
          for (SkillType skill : SkillType.MISC_SKILLS) {
            sender.sendMessage(CommandUtils.displaySkill(profile, skill));
          }

        } else {
          Player target = mcMMOPlayer.getPlayer();

          if (CommandUtils.hidden(sender, target, Permissions.inspectHidden(sender))) {
            if (!Permissions.inspectOffline(sender)) {
              sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
              return true;
            }
          } else if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
            return true;
          }

          if (sender instanceof Player && Config.getInstance().getInspectScoreboardEnabled()) {
            ScoreboardManager.enablePlayerInspectScoreboardOnline((Player) sender, mcMMOPlayer);
            return true;
          }

          sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName()));
          CommandUtils.printGatheringSkills(target, sender);
          CommandUtils.printCombatSkills(target, sender);
          CommandUtils.printMiscSkills(target, sender);
          sender.sendMessage(
              LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel()));
        }

        return true;

      default:
        return false;
    }
  }
Beispiel #4
0
  /** Things to be run when the plugin is enabled. */
  @Override
  public void onEnable() {
    try {
      p = this;
      getLogger().setFilter(new LogFilter(this));
      metadataValue = new FixedMetadataValue(this, true);

      mcpcEnabled = getServer().getName().equals("MCPC+");
      combatTagEnabled = getServer().getPluginManager().getPlugin("CombatTag") != null;
      healthBarPluginEnabled = getServer().getPluginManager().getPlugin("HealthBar") != null;
      noCheatPlusPluginEnabled = getServer().getPluginManager().getPlugin("NoCheatPlus") != null;
      compatNoCheatPlusPluginEnabled =
          getServer().getPluginManager().getPlugin("CompatNoCheatPlus") != null;

      setupFilePaths();

      loadConfigFiles();

      if (!noErrorsInConfigFiles) {
        return;
      }

      if (mcpcEnabled) {
        checkModConfigs();
      }

      if (healthBarPluginEnabled) {
        getLogger().info("HealthBar plugin found, mcMMO's healthbars are automatically disabled.");
      }

      if (noCheatPlusPluginEnabled && !compatNoCheatPlusPluginEnabled) {
        getLogger().warning("NoCheatPlus plugin found, but CompatNoCheatPlus was not found!");
        getLogger()
            .warning(
                "mcMMO will not work properly alongside NoCheatPlus without CompatNoCheatPlus");
      }

      databaseManager = DatabaseManagerFactory.getDatabaseManager();

      registerEvents();
      registerCustomRecipes();

      PartyManager.loadParties();

      formulaManager = new FormulaManager();

      for (Player player : getServer().getOnlinePlayers()) {
        UserManager.addUser(player); // In case of reload add all users back into UserManager
        ScoreboardManager.setupPlayer(player);
      }

      debug("Version " + getDescription().getVersion() + " is enabled!");

      scheduleTasks();
      CommandRegistrationManager.registerCommands();

      MetricsManager.setup();

      placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager

      checkForUpdates();

      if (Config.getInstance().getPTPCommandWorldPermissions()) {
        Permissions.generateWorldTeleportPermissions();
      }
    } catch (Throwable t) {
      getLogger().severe("There was an error while enabling mcMMO!");

      if (!(t instanceof ExceptionInInitializerError)) {
        t.printStackTrace();
      } else {
        getLogger().info("Please do not replace the mcMMO jar while the server is running.");
      }

      getServer().getPluginManager().disablePlugin(this);
    }
  }
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (CommandUtils.noConsoleUsage(sender)) {
      return true;
    }

    switch (args.length) {
      case 0:
        Player player = (Player) sender;
        McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);

        boolean isLucky = Permissions.lucky(player, skill);
        boolean hasEndurance = (PerksUtils.handleActivationPerks(player, 0, 0) != 0);
        float skillValue = mcMMOPlayer.getSkillLevel(skill);

        permissionsCheck(player);
        dataCalculations(player, skillValue, isLucky);

        if (Config.getInstance().getSkillUseBoard()) {
          ScoreboardManager.enablePlayerSkillScoreboard(player, skill);
        }

        if (!skill.isChildSkill()) {
          player.sendMessage(LocaleLoader.getString("Skills.Header", skillName));
          player.sendMessage(
              LocaleLoader.getString(
                  "Commands.XPGain",
                  LocaleLoader.getString(
                      "Commands.XPGain." + StringUtils.getCapitalized(skill.toString()))));
          player.sendMessage(
              LocaleLoader.getString(
                  "Effects.Level",
                  (int) skillValue,
                  mcMMOPlayer.getSkillXpLevel(skill),
                  mcMMOPlayer.getXpToLevel(skill)));
        } else {
          player.sendMessage(
              LocaleLoader.getString(
                  "Skills.Header", skillName + " " + LocaleLoader.getString("Skills.Child")));
          player.sendMessage(
              LocaleLoader.getString(
                  "Commands.XPGain", LocaleLoader.getString("Commands.XPGain.Child")));
          player.sendMessage(LocaleLoader.getString("Effects.Child", (int) skillValue));

          player.sendMessage(
              LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Skills.Parents")));
          Set<SkillType> parents = FamilyTree.getParents(skill);

          for (SkillType parent : parents) {
            player.sendMessage(
                parent.getName()
                    + " - "
                    + LocaleLoader.getString(
                        "Effects.Level",
                        mcMMOPlayer.getSkillLevel(parent),
                        mcMMOPlayer.getSkillXpLevel(parent),
                        mcMMOPlayer.getXpToLevel(parent)));
          }
        }

        List<String> effectMessages = effectsDisplay();

        if (!effectMessages.isEmpty()) {
          player.sendMessage(
              LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));

          if (isLucky) {
            String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
            player.sendMessage(
                perkPrefix
                    + LocaleLoader.getString(
                        "Effects.Template",
                        LocaleLoader.getString("Perks.Lucky.Name"),
                        LocaleLoader.getString("Perks.Lucky.Desc", skillName)));
          }

          for (String message : effectMessages) {
            player.sendMessage(message);
          }
        }

        List<String> statsMessages = statsDisplay(player, skillValue, hasEndurance, isLucky);

        if (!statsMessages.isEmpty()) {
          player.sendMessage(
              LocaleLoader.getString(
                  "Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));

          for (String message : statsMessages) {
            player.sendMessage(message);
          }
        }

        player.sendMessage(
            LocaleLoader.getString("Guides.Available", skillName, skillName.toLowerCase()));
        return true;

      default:
        return skillGuideCommand.onCommand(sender, command, label, args);
    }
  }