Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.configuration.Configuration;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.gmail.nossr50.datatypes.skills.SkillType;
- import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
- public class TestPlugin extends JavaPlugin implements Listener {
- boolean configProblems = false;
- @Override
- public void onEnable() {
- saveDefaultConfig();
- getServer().getPluginManager().registerEvents(this, this);
- getCommand("mcxpperks").setExecutor(this);
- if (validateConfig(getConfig())) {
- getLogger().warning("### Some mistakes were found in the configuration file. ###");
- getLogger().warning("### Those players' perks may not function correctly. ###");
- configProblems = true;
- }
- }
- private boolean validateConfig(ConfigurationSection config) {
- configProblems = false;
- ConfigurationSection playersSection = config.getConfigurationSection("players");
- for (String plName : playersSection.getKeys(false)) {
- OfflinePlayer op = getServer().getOfflinePlayer(plName);
- if (!op.hasPlayedBefore()) {
- getLogger().warning(plName + " has not played on this server, but they are in the config file!");
- configProblems = true;
- }
- ConfigurationSection subSection = playersSection.getConfigurationSection(plName);
- for (String skName : subSection.getKeys(false)) {
- SkillType skilltype = SkillType.valueOf(skName);
- if (skilltype == null) {
- getLogger().warning(skName + " is not a valid skill name (found in " + plName + "'s section)");
- configProblems = true;
- } else if (!skilltype.name().toLowerCase().equals(skName)) {
- getLogger().warning("Please use '" + skilltype.name().toLowerCase() + "' instead of '" + skName + "'.");
- configProblems = true;
- }
- }
- }
- return configProblems;
- }
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- this.reloadConfig();
- if (validateConfig(getConfig())) {
- String message = ChatColor.AQUA + "Reloaded mcMMO XP Perks config, " + ChatColor.RED + "but some problems were found.";
- if (!(sender instanceof ConsoleCommandSender)) {
- sender.sendMessage(message);
- sender.sendMessage(ChatColor.RED + "Please review the issues printed in the server console.");
- Bukkit.getConsoleSender().sendMessage(message);
- } else {
- sender.sendMessage(message);
- sender.sendMessage(ChatColor.RED + "Please review the issues printed above.");
- }
- } else {
- String message = ChatColor.AQUA + "Reloaded mcMMO XP Perks config. " + ChatColor.GREEN + "No issues found.";
- if (!(sender instanceof ConsoleCommandSender)) {
- sender.sendMessage(message);
- }
- Bukkit.getConsoleSender().sendMessage(message);
- }
- return true;
- }
- @EventHandler
- public void onJoin(PlayerJoinEvent event) {
- if (configProblems && event.getPlayer().isOp()) {
- event.getPlayer().sendMessage(ChatColor.RED + "Some problems were found in the " + ChatColor.DARK_AQUA + "CustomMcmmoXpPerks" + ChatColor.RED + " configuration file.");
- event.getPlayer().sendMessage(ChatColor.RED + "Please resolve the issues and run /mcxpperks reload to reload the configuration.");
- }
- }
- @EventHandler
- public void onXp(McMMOPlayerXpGainEvent event) {
- event.setRawXpGained((float) (event.getRawXpGained() * getMultiplier(event.getPlayer(), event.getSkill())));
- }
- private double getMultiplier(Player player, SkillType skill) {
- return getConfig().getDouble("players." + player.getName() + "." + skill.name().toLowerCase(), 1D);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement