diff --git a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java index 5f1a630e9..552121bdf 100644 --- a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java +++ b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java @@ -5,7 +5,8 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.skills.AbilityType; import com.gmail.nossr50.util.Users; -public class AbilityAPI { +public final class AbilityAPI { + private AbilityAPI() {} public static boolean berserkEnabled(Player player) { return Users.getProfile(player).getAbilityMode(AbilityType.BERSERK); diff --git a/src/main/java/com/gmail/nossr50/api/ChatAPI.java b/src/main/java/com/gmail/nossr50/api/ChatAPI.java index f422f36f1..1bc85ae58 100644 --- a/src/main/java/com/gmail/nossr50/api/ChatAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ChatAPI.java @@ -1,11 +1,9 @@ package com.gmail.nossr50.api; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.util.ChatManager; public final class ChatAPI { - private ChatAPI() {} /** @@ -18,8 +16,7 @@ public final class ChatAPI { * @param message The message to send */ public static void sendPartyChat(String sender, String party, String message) { - ChatManager chatManager = new ChatManager(mcMMO.p, sender, message); - chatManager.handlePartyChat(PartyManager.getInstance().getParty(party)); + ChatManager.handlePartyChat(PartyManager.getParty(party), sender, message); } /** @@ -31,7 +28,6 @@ public final class ChatAPI { * @param message The message to send */ public static void sendAdminChat(String sender, String message) { - ChatManager chatManager = new ChatManager(mcMMO.p, sender, message); - chatManager.handleAdminChat(); + ChatManager.handleAdminChat(sender, message); } } diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index fdac4bc28..807c0b105 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -3,11 +3,10 @@ package com.gmail.nossr50.api; import org.bukkit.entity.Player; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Users; public final class ExperienceAPI { - private ExperienceAPI() {} /** @@ -18,10 +17,10 @@ public final class ExperienceAPI { */ private static void checkXP(Player player, SkillType skillType) { if (skillType.equals(SkillType.ALL)) { - Skills.xpCheckAll(player, Users.getProfile(player)); + SkillTools.xpCheckAll(player, Users.getProfile(player)); } else { - Skills.xpCheckSkill(skillType, player, Users.getProfile(player)); + SkillTools.xpCheckSkill(skillType, player, Users.getProfile(player)); } } diff --git a/src/main/java/com/gmail/nossr50/api/PartyAPI.java b/src/main/java/com/gmail/nossr50/api/PartyAPI.java index 491976d82..1857d6c67 100644 --- a/src/main/java/com/gmail/nossr50/api/PartyAPI.java +++ b/src/main/java/com/gmail/nossr50/api/PartyAPI.java @@ -9,7 +9,6 @@ import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.util.Users; public final class PartyAPI { - private PartyAPI() {} /** @@ -46,7 +45,7 @@ public final class PartyAPI { * @return true if the two players are in the same party, false otherwise */ public static boolean inSameParty(Player playera, Player playerb) { - return PartyManager.getInstance().inSameParty(playera, playerb); + return PartyManager.inSameParty(playera, playerb); } /** @@ -57,7 +56,7 @@ public final class PartyAPI { * @return the list of parties. */ public static List getParties() { - return PartyManager.getInstance().getParties(); + return PartyManager.getParties(); } /** @@ -69,7 +68,7 @@ public final class PartyAPI { * @param partyName The party to add the player to */ public static void addToParty(Player player, String partyName) { - Party party = PartyManager.getInstance().getParty(partyName); + Party party = PartyManager.getParty(partyName); String playerName = player.getName(); if (party == null) { @@ -78,7 +77,7 @@ public final class PartyAPI { party.setLeader(playerName); } - PartyManager.getInstance().addToParty(playerName, Users.getProfile(player), party); + PartyManager.addToParty(playerName, Users.getProfile(player), party); } /** @@ -89,7 +88,7 @@ public final class PartyAPI { * @param player The player to remove */ public static void removeFromParty(Player player) { - PartyManager.getInstance().removeFromParty(player.getName(), Users.getProfile(player).getParty()); + PartyManager.removeFromParty(player.getName(), Users.getProfile(player).getParty()); } /** @@ -101,7 +100,7 @@ public final class PartyAPI { * @return the leader of the party */ public static String getPartyLeader(String partyName) { - return PartyManager.getInstance().getPartyLeader(partyName); + return PartyManager.getPartyLeader(partyName); } /** @@ -113,7 +112,7 @@ public final class PartyAPI { * @param player The player to set as leader */ public static void setPartyLeader(String partyName, String player) { - PartyManager.getInstance().setPartyLeader(player, PartyManager.getInstance().getParty(partyName)); + PartyManager.setPartyLeader(player, PartyManager.getParty(partyName)); } /** @@ -125,7 +124,7 @@ public final class PartyAPI { * @return all the players in the player's party */ public static List getAllMembers(Player player) { - return PartyManager.getInstance().getAllMembers(player); + return PartyManager.getAllMembers(player); } /** @@ -137,7 +136,7 @@ public final class PartyAPI { * @return all online players in this party */ public static List getOnlineMembers(String partyName) { - return PartyManager.getInstance().getOnlineMembers(partyName); + return PartyManager.getOnlineMembers(partyName); } /** @@ -149,6 +148,6 @@ public final class PartyAPI { * @return all online players in the player's party */ public static List getOnlineMembers(Player player) { - return PartyManager.getInstance().getOnlineMembers(player); + return PartyManager.getOnlineMembers(player); } } diff --git a/src/main/java/com/gmail/nossr50/api/SpoutToolsAPI.java b/src/main/java/com/gmail/nossr50/api/SpoutToolsAPI.java index bbc397d43..2bc505d97 100644 --- a/src/main/java/com/gmail/nossr50/api/SpoutToolsAPI.java +++ b/src/main/java/com/gmail/nossr50/api/SpoutToolsAPI.java @@ -8,15 +8,14 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.skills.ToolType; public final class SpoutToolsAPI { - - private SpoutToolsAPI() {} - public static final List spoutSwords = new ArrayList(); public static final List spoutAxes = new ArrayList(); public static final List spoutPickaxes = new ArrayList(); public static final List spoutHoes = new ArrayList(); public static final List spoutShovels = new ArrayList(); + private SpoutToolsAPI() {} + /** * Add a custom Spout tool to mcMMO for XP gain & ability use. *
diff --git a/src/main/java/com/gmail/nossr50/commands/CommandHelper.java b/src/main/java/com/gmail/nossr50/commands/CommandHelper.java index 852b3f230..38b2df24c 100644 --- a/src/main/java/com/gmail/nossr50/commands/CommandHelper.java +++ b/src/main/java/com/gmail/nossr50/commands/CommandHelper.java @@ -6,11 +6,12 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; -public class CommandHelper { +public final class CommandHelper { + private CommandHelper() {} /** * Checks for command permissions. @@ -48,7 +49,7 @@ public class CommandHelper { * @param display The sender to display stats to */ public static void printGatheringSkills(Player inspect, CommandSender display) { - if (Skills.hasGatheringSkills(inspect)) { + if (SkillTools.hasGatheringSkills(inspect)) { PlayerProfile profile = Users.getProfile(inspect); if (profile == null) { @@ -91,7 +92,7 @@ public class CommandHelper { * @param display The sender to display stats to */ public static void printCombatSkills(Player inspect, CommandSender display) { - if (Skills.hasCombatSkills(inspect)) { + if (SkillTools.hasCombatSkills(inspect)) { PlayerProfile profile = Users.getProfile(inspect); if (profile == null) { @@ -134,7 +135,7 @@ public class CommandHelper { * @param display The sender to display stats to */ public static void printMiscSkills(Player inspect, CommandSender display) { - if (Skills.hasMiscSkills(inspect)) { + if (SkillTools.hasMiscSkills(inspect)) { PlayerProfile profile = Users.getProfile(inspect); if (profile == null) { diff --git a/src/main/java/com/gmail/nossr50/commands/general/AddlevelsCommand.java b/src/main/java/com/gmail/nossr50/commands/general/AddlevelsCommand.java index ed8234b40..4233ba953 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/AddlevelsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/AddlevelsCommand.java @@ -11,17 +11,11 @@ import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Users; public class AddlevelsCommand implements CommandExecutor{ - private final mcMMO plugin; - - public AddlevelsCommand (mcMMO plugin) { - this.plugin = plugin; - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { OfflinePlayer modifiedPlayer; @@ -37,7 +31,7 @@ public class AddlevelsCommand implements CommandExecutor{ switch (args.length) { case 2: if (sender instanceof Player) { - if (!Skills.isSkill(args[0])) { + if (!SkillTools.isSkill(args[0])) { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); return true; } @@ -45,7 +39,7 @@ public class AddlevelsCommand implements CommandExecutor{ if (Misc.isInt(args[1])) { modifiedPlayer = (Player) sender; levels = Integer.valueOf(args[1]); - skill = Skills.getSkillType(args[0]); + skill = SkillTools.getSkillType(args[0]); profile = Users.getProfile(modifiedPlayer); if (skill.equals(SkillType.ALL)) { @@ -65,7 +59,7 @@ public class AddlevelsCommand implements CommandExecutor{ return true; case 3: - modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]); + modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]); String playerName = modifiedPlayer.getName(); profile = Users.getProfile(modifiedPlayer); @@ -79,14 +73,14 @@ public class AddlevelsCommand implements CommandExecutor{ return true; } - if (!Skills.isSkill(args[1])) { + if (!SkillTools.isSkill(args[1])) { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); return true; } if (Misc.isInt(args[2])) { levels = Integer.valueOf(args[2]); - skill = Skills.getSkillType(args[1]); + skill = SkillTools.getSkillType(args[1]); Users.getProfile(modifiedPlayer).addLevels(skill, levels); diff --git a/src/main/java/com/gmail/nossr50/commands/general/AddxpCommand.java b/src/main/java/com/gmail/nossr50/commands/general/AddxpCommand.java index f82426584..9507dca5b 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/AddxpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/AddxpCommand.java @@ -11,18 +11,12 @@ import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Users; //TODO: Any way we can make this work for offline use? public class AddxpCommand implements CommandExecutor { - private final mcMMO plugin; - - public AddxpCommand (mcMMO plugin) { - this.plugin = plugin; - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { Player modifiedPlayer; @@ -37,7 +31,7 @@ public class AddxpCommand implements CommandExecutor { switch (args.length) { case 2: if (sender instanceof Player) { - if (!Skills.isSkill(args[1])) { + if (!SkillTools.isSkill(args[1])) { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); return true; } @@ -45,7 +39,7 @@ public class AddxpCommand implements CommandExecutor { if (Misc.isInt(args[1])) { modifiedPlayer = (Player) sender; xp = Integer.valueOf(args[1]); - skill = Skills.getSkillType(args[0]); + skill = SkillTools.getSkillType(args[0]); PlayerProfile profile = Users.getProfile(modifiedPlayer); McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer); @@ -59,10 +53,10 @@ public class AddxpCommand implements CommandExecutor { } if (skill.equals(SkillType.ALL)) { - Skills.xpCheckAll(modifiedPlayer, profile); + SkillTools.xpCheckAll(modifiedPlayer, profile); } else { - Skills.xpCheckSkill(skill, modifiedPlayer, profile); + SkillTools.xpCheckSkill(skill, modifiedPlayer, profile); } } else { @@ -76,7 +70,7 @@ public class AddxpCommand implements CommandExecutor { return true; case 3: - modifiedPlayer = plugin.getServer().getPlayer(args[0]); + modifiedPlayer = mcMMO.p.getServer().getPlayer(args[0]); String playerName = modifiedPlayer.getName(); McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer); PlayerProfile profile = Users.getProfile(modifiedPlayer); @@ -91,14 +85,14 @@ public class AddxpCommand implements CommandExecutor { return true; } - if (!Skills.isSkill(args[1])) { + if (!SkillTools.isSkill(args[1])) { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); return true; } if (Misc.isInt(args[2])) { xp = Integer.valueOf(args[2]); - skill = Skills.getSkillType(args[1]); + skill = SkillTools.getSkillType(args[1]); mcMMOPlayer.addXPOverride(skill, xp); @@ -111,11 +105,11 @@ public class AddxpCommand implements CommandExecutor { if (skill.equals(SkillType.ALL)) { modifiedPlayer.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", new Object[] {xp})); - Skills.xpCheckAll(modifiedPlayer, profile); + SkillTools.xpCheckAll(modifiedPlayer, profile); } else { modifiedPlayer.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", new Object[] {xp, Misc.getCapitalized(skill.toString())})); - Skills.xpCheckSkill(skill, modifiedPlayer, profile); + SkillTools.xpCheckSkill(skill, modifiedPlayer, profile); } } else { diff --git a/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java b/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java index 2fa888bc3..236dd291b 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java @@ -11,7 +11,6 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Users; public class McstatsCommand implements CommandExecutor { - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandHelper.noConsoleUsage(sender)) { diff --git a/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java b/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java index 028cd9398..9d6f3621d 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java @@ -10,7 +10,7 @@ import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Users; @@ -30,7 +30,7 @@ public class MmoeditCommand implements CommandExecutor { switch (args.length) { case 2: if (sender instanceof Player) { - if (!Skills.isSkill(args[0])) { + if (!SkillTools.isSkill(args[0])) { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); return true; } @@ -38,7 +38,7 @@ public class MmoeditCommand implements CommandExecutor { if (Misc.isInt(args[1])) { Player player = (Player) sender; newValue = Integer.valueOf(args[1]); - skill = Skills.getSkillType(args[0]); + skill = SkillTools.getSkillType(args[0]); profile = Users.getProfile(player); if (skill.equals(SkillType.ALL)) { @@ -67,7 +67,7 @@ public class MmoeditCommand implements CommandExecutor { return true; } - skill = Skills.getSkillType(args[1]); + skill = SkillTools.getSkillType(args[1]); if (skill == null) { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); diff --git a/src/main/java/com/gmail/nossr50/commands/general/SkillResetCommand.java b/src/main/java/com/gmail/nossr50/commands/general/SkillResetCommand.java index 7074141db..bc191fec3 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/SkillResetCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/SkillResetCommand.java @@ -12,7 +12,6 @@ import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.util.Users; public class SkillResetCommand implements CommandExecutor { - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandHelper.noConsoleUsage(sender)) { diff --git a/src/main/java/com/gmail/nossr50/commands/general/XprateCommand.java b/src/main/java/com/gmail/nossr50/commands/general/XprateCommand.java index 0bbdc3d89..167a7ac77 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/XprateCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/XprateCommand.java @@ -12,14 +12,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Misc; public class XprateCommand implements CommandExecutor { - private final mcMMO plugin; - private static double oldRate = Config.getInstance().xpGainMultiplier; - private boolean xpEvent; - - public XprateCommand (mcMMO plugin) { - this.plugin = plugin; - this.xpEvent = plugin.isXPEventEnabled(); - } + private static double originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -31,20 +24,21 @@ public class XprateCommand implements CommandExecutor { return true; } + boolean xpEventEnabled = mcMMO.p.isXPEventEnabled(); + switch (args.length) { case 1: if (args[0].equalsIgnoreCase("reset")) { - if (xpEvent) { - for (Player x : plugin.getServer().getOnlinePlayers()) { + if (xpEventEnabled) { + for (Player x : mcMMO.p.getServer().getOnlinePlayers()) { x.sendMessage(LocaleLoader.getString("Commands.xprate.over")); } - xpEvent = !xpEvent; - plugin.setXPEventEnabled(xpEvent); - Config.getInstance().xpGainMultiplier = oldRate; + mcMMO.p.setXPEventEnabled(!xpEventEnabled); + Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate); } else { - Config.getInstance().xpGainMultiplier = oldRate; + Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate); } } else if (Misc.isInt(args[0])) { @@ -58,26 +52,24 @@ public class XprateCommand implements CommandExecutor { case 2: if (Misc.isInt(args[0])) { - oldRate = Config.getInstance().xpGainMultiplier; - if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) { - xpEvent = Boolean.valueOf(args[1]); - plugin.setXPEventEnabled(xpEvent); + mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1])); } else { sender.sendMessage(usage3); } - Config.getInstance().xpGainMultiplier = Misc.getInt(args[0]); + int newRate = Misc.getInt(args[0]); + Config.getInstance().setExperienceGainsGlobalMultiplier(newRate); - if (xpEvent) { - for (Player x : plugin.getServer().getOnlinePlayers()) { + if (xpEventEnabled) { + for (Player x : mcMMO.p.getServer().getOnlinePlayers()) { x.sendMessage(LocaleLoader.getString("Commands.xprate.started.0")); - x.sendMessage(LocaleLoader.getString("Commands.xprate.started.1", new Object[] {Config.getInstance().xpGainMultiplier})); + x.sendMessage(LocaleLoader.getString("Commands.xprate.started.1", new Object[] {newRate})); } } else { - sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", new Object[] {Config.getInstance().xpGainMultiplier})); + sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", new Object[] {newRate})); } } else { diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McabilityCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McabilityCommand.java index 98a698a87..51d6480c0 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McabilityCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McabilityCommand.java @@ -11,7 +11,6 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Users; public class McabilityCommand implements CommandExecutor { - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandHelper.noConsoleUsage(sender)) { diff --git a/src/main/java/com/gmail/nossr50/commands/mc/MccCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/MccCommand.java index 9611874ca..3690ba774 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/MccCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/MccCommand.java @@ -12,7 +12,6 @@ import com.gmail.nossr50.util.Permissions; //TODO: Rework this whole thing. It's ugly. Also is missing all the admin & spout commands. public class MccCommand implements CommandExecutor { - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandHelper.noConsoleUsage(sender)) { diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McgodCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McgodCommand.java index ebbed2213..e71d48475 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McgodCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McgodCommand.java @@ -11,7 +11,6 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Users; public class McgodCommand implements CommandExecutor { - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandHelper.noConsoleUsage(sender)) { diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McmmoCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McmmoCommand.java index 6058b4b00..9e1edc648 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McmmoCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McmmoCommand.java @@ -31,8 +31,7 @@ public class McmmoCommand implements CommandExecutor { } sender.sendMessage(LocaleLoader.getString("MOTD.Version", new Object[] {mcMMO.p.getDescription().getVersion()})); - Anniversary anniversary = new Anniversary(); - anniversary.anniversaryCheck(sender); + Anniversary.anniversaryCheck(sender); return true; } } diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McrankCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McrankCommand.java index f6943c23e..276e7d8dc 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McrankCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McrankCommand.java @@ -11,11 +11,10 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.runnables.McRankAsync; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Leaderboard; public class McrankCommand implements CommandExecutor { - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { //TODO: Better input handling, add usage string @@ -67,10 +66,10 @@ public class McrankCommand implements CommandExecutor { } if (rankInts[1] == 0) { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", new Object[] {Skills.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")} )); //Don't bother showing ranking for players without skills + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", new Object[] {SkillTools.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")} )); //Don't bother showing ranking for players without skills } else { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", new Object[] {Skills.localizeSkillName(skillType), String.valueOf(rankInts[0])} )); + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", new Object[] {SkillTools.localizeSkillName(skillType), String.valueOf(rankInts[0])} )); } } diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java index 687ca697d..4648240c2 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java @@ -13,12 +13,6 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Users; public class McrefreshCommand implements CommandExecutor { - private final mcMMO plugin; - - public McrefreshCommand(mcMMO instance) { - this.plugin = instance; - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { OfflinePlayer player; @@ -42,7 +36,7 @@ public class McrefreshCommand implements CommandExecutor { break; case 1: - player = plugin.getServer().getOfflinePlayer(args[0]); + player = mcMMO.p.getServer().getOfflinePlayer(args[0]); profile = Users.getProfile(player); String playerName = player.getName(); diff --git a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java index 22a59bd22..2b19d5de9 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java @@ -8,17 +8,15 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.Database; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Leaderboard; import com.gmail.nossr50.util.Misc; public class MctopCommand implements CommandExecutor { - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { String usage = LocaleLoader.getString("Commands.Usage.2", new Object[] {"mctop", "[" + LocaleLoader.getString("Commands.Usage.Skill") + "]", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]"}); @@ -34,11 +32,11 @@ public class MctopCommand implements CommandExecutor { if (Misc.isInt(args[0])) { flatfileDisplay(Integer.valueOf(args[0]), "ALL", sender); } - else if (Skills.isSkill(args[0])) { + else if (SkillTools.isSkill(args[0])) { flatfileDisplay(1, args[0].toUpperCase(), sender); } - else if (Skills.isLocalizedSkill(args[0])) { - flatfileDisplay(1, Skills.translateLocalizedSkill(args[0]).toUpperCase(), sender); + else if (SkillTools.isLocalizedSkill(args[0])) { + flatfileDisplay(1, SkillTools.translateLocalizedSkill(args[0]).toUpperCase(), sender); } else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); @@ -48,11 +46,11 @@ public class MctopCommand implements CommandExecutor { case 2: if (Misc.isInt(args[1])) { - if (Skills.isSkill(args[0])) { + if (SkillTools.isSkill(args[0])) { flatfileDisplay(Integer.valueOf(args[1]), args[0].toUpperCase(), sender); } - else if (Skills.isLocalizedSkill(args[0])) { - flatfileDisplay(Integer.valueOf(args[1]), Skills.translateLocalizedSkill(args[0]).toUpperCase(), sender); + else if (SkillTools.isLocalizedSkill(args[0])) { + flatfileDisplay(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]).toUpperCase(), sender); } else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); @@ -81,11 +79,11 @@ public class MctopCommand implements CommandExecutor { if (Misc.isInt(args[0])) { sqlDisplay(Integer.valueOf(args[0]), powerlevel, sender); } - else if (Skills.isSkill(args[0])) { + else if (SkillTools.isSkill(args[0])) { sqlDisplay(1, args[0].toLowerCase(), sender); } - else if (Skills.isLocalizedSkill(args[0])) { - sqlDisplay(1, Skills.translateLocalizedSkill(args[0]).toLowerCase(), sender); + else if (SkillTools.isLocalizedSkill(args[0])) { + sqlDisplay(1, SkillTools.translateLocalizedSkill(args[0]).toLowerCase(), sender); } else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); @@ -95,11 +93,11 @@ public class MctopCommand implements CommandExecutor { case 2: if (Misc.isInt(args[1])) { - if (Skills.isSkill(args[0])) { + if (SkillTools.isSkill(args[0])) { sqlDisplay(Integer.valueOf(args[1]), args[0].toLowerCase(), sender); } - else if (Skills.isLocalizedSkill(args[0])) { - sqlDisplay(Integer.valueOf(args[1]), Skills.translateLocalizedSkill(args[0]).toLowerCase(), sender); + else if (SkillTools.isLocalizedSkill(args[0])) { + sqlDisplay(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]).toLowerCase(), sender); } else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); @@ -151,9 +149,7 @@ public class MctopCommand implements CommandExecutor { private void sqlDisplay(int page, String query, CommandSender sender) { String tablePrefix = Config.getInstance().getMySQLTablePrefix(); - Database database = mcMMO.getPlayerDatabase(); - - HashMap> userslist = database.read("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT "+((page * 10) - 10)+",10"); + HashMap> userslist = Database.read("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT "+((page * 10) - 10)+",10"); if (query.equals("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) { sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index d69fbdd61..7021b39f3 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -7,10 +7,12 @@ public class AdvancedConfig extends ConfigLoader { super("advanced.yml"); loadKeys(); } + public static AdvancedConfig getInstance() { if (instance == null) { instance = new AdvancedConfig(); } + return instance; } diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index d408da61f..3f472c514 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -6,11 +6,9 @@ import org.bukkit.configuration.ConfigurationSection; public class Config extends ConfigLoader { private static Config instance; - public double xpGainMultiplier = 1; private Config() { super("config.yml"); - xpGainMultiplier = getExperienceGainsGlobalMultiplier(); loadKeys(); } @@ -363,6 +361,7 @@ public class Config extends ConfigLoader { public boolean getExperienceGainsMobspawnersEnabled() { return config.getBoolean("Experience.Gains.Mobspawners.Enabled", false); } public boolean getExperienceGainsPlayerVersusPlayerEnabled() { return config.getBoolean("Experience.PVP.Rewards", true); } public double getExperienceGainsGlobalMultiplier() { return config.getDouble("Experience.Gains.Multiplier.Global", 1.0); } + public void setExperienceGainsGlobalMultiplier(double value) { config.set("Experience.Gains.Multiplier.Global", value); } /* Combat XP Multipliers */ public double getPlayerVersusPlayerXP() { return config.getDouble("Experience.Gains.Multiplier.PVP", 1.0); } diff --git a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java index df416b749..51ef294bc 100644 --- a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java +++ b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java @@ -16,7 +16,7 @@ import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.datatypes.treasure.Treasure; -public class TreasuresConfig extends ConfigLoader{ +public class TreasuresConfig extends ConfigLoader { private static TreasuresConfig instance; public List excavationFromDirt = new ArrayList(); public List excavationFromGrass = new ArrayList(); diff --git a/src/main/java/com/gmail/nossr50/database/Database.java b/src/main/java/com/gmail/nossr50/database/Database.java index 90a9af18c..7d028873d 100644 --- a/src/main/java/com/gmail/nossr50/database/Database.java +++ b/src/main/java/com/gmail/nossr50/database/Database.java @@ -22,12 +22,12 @@ import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.spout.huds.SpoutHud; import com.gmail.nossr50.util.Users; -public class Database { +public final class Database { + private Database() {} - private static Config configInstance = Config.getInstance(); private static String connectionString; - private static String tablePrefix = configInstance.getMySQLTablePrefix(); + private static String tablePrefix = Config.getInstance().getMySQLTablePrefix(); private static Connection connection = null; private static mcMMO plugin = null; @@ -49,16 +49,13 @@ public class Database { // How many connection attemtps have failed private static int reconnectAttempt = 0; - public Database(mcMMO instance) { - plugin = instance; - checkConnected(); //Connect to MySQL - } - /** * Attempt to connect to the mySQL database. */ public static void connect() { + Config configInstance = Config.getInstance(); connectionString = "jdbc:mysql://" + configInstance.getMySQLServerName() + ":" + configInstance.getMySQLServerPort() + "/" + configInstance.getMySQLDatabaseName(); + try { mcMMO.p.getLogger().info("Attempting connection to MySQL..."); @@ -84,7 +81,7 @@ public class Database { /** * Attempt to create the database structure. */ - public void createStructure() { + public static void createStructure() { write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` (" + "`id` int(10) unsigned NOT NULL AUTO_INCREMENT," + "`user` varchar(40) NOT NULL," @@ -158,7 +155,7 @@ public class Database { * * @param update Type of data to check updates for */ - public void checkDatabaseStructure(DatabaseUpdate update) { + private static void checkDatabaseStructure(DatabaseUpdate update) { String sql = null; ResultSet resultSet = null; HashMap> rows = new HashMap>(); @@ -256,7 +253,7 @@ public class Database { * @param sql Query to write. * @return true if the query was successfully written, false otherwise. */ - public boolean write(String sql) { + public static boolean write(String sql) { if (checkConnected()) { PreparedStatement statement = null; try { @@ -288,7 +285,7 @@ public class Database { * @param sql SQL query to execute * @return the number of rows affected */ - public int update(String sql) { + public static int update(String sql) { int ret = 0; if (checkConnected()) { PreparedStatement statement = null; @@ -320,7 +317,7 @@ public class Database { * @param sql SQL query to execute * @return the value in the first row / first field */ - public int getInt(String sql) { + public static int getInt(String sql) { ResultSet resultSet; int result = 0; @@ -416,7 +413,7 @@ public class Database { if (connection != null && !connection.isClosed()) { // Schedule a database save if we really had an outage if (reconnectAttempt > 1) { - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SQLReconnect(plugin), 5); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SQLReconnect(), 5); } nextReconnectTimestamp = 0; reconnectAttempt = 0; @@ -441,7 +438,7 @@ public class Database { * @param sql SQL query to read * @return the rows in this SQL query */ - public HashMap> read(String sql) { + public static HashMap> read(String sql) { ResultSet resultSet; HashMap> rows = new HashMap>(); @@ -470,7 +467,7 @@ public class Database { return rows; } - public Map readSQLRank(String playerName) { + public static Map readSQLRank(String playerName) { ResultSet resultSet; Map skills = new HashMap(); if (checkConnected()) { @@ -512,7 +509,7 @@ public class Database { return skills; } - public void purgePowerlessSQL() { + public static void purgePowerlessSQL() { plugin.getLogger().info("Purging powerless users..."); HashMap> usernames = read("SELECT u.user FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE s.user_id = u.id AND (s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing) = 0"); write("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.id IN (SELECT * FROM (SELECT u.id FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE s.user_id = u.id AND (s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing) = 0) AS p)"); @@ -532,7 +529,7 @@ public class Database { plugin.getLogger().info("Purged " + purgedUsers + " users from the database."); } - public void purgeOldSQL() { + public static void purgeOldSQL() { plugin.getLogger().info("Purging old users..."); long currentTime = System.currentTimeMillis(); long purgeTime = 2630000000L * Config.getInstance().getOldUsersCutoff(); diff --git a/src/main/java/com/gmail/nossr50/database/commands/McpurgeCommand.java b/src/main/java/com/gmail/nossr50/database/commands/McpurgeCommand.java index cf381ba72..04f6500d7 100644 --- a/src/main/java/com/gmail/nossr50/database/commands/McpurgeCommand.java +++ b/src/main/java/com/gmail/nossr50/database/commands/McpurgeCommand.java @@ -4,15 +4,12 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.Database; import com.gmail.nossr50.locale.LocaleLoader; public class McpurgeCommand implements CommandExecutor{ - private Database database = mcMMO.getPlayerDatabase(); - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mcremove")) { @@ -20,10 +17,10 @@ public class McpurgeCommand implements CommandExecutor{ } if (Config.getInstance().getUseMySQL()) { - database.purgePowerlessSQL(); + Database.purgePowerlessSQL(); if (Config.getInstance().getOldUsersCutoff() != -1) { - database.purgeOldSQL(); + Database.purgeOldSQL(); } } else { diff --git a/src/main/java/com/gmail/nossr50/database/commands/McremoveCommand.java b/src/main/java/com/gmail/nossr50/database/commands/McremoveCommand.java index 32ebb8511..62a82524e 100644 --- a/src/main/java/com/gmail/nossr50/database/commands/McremoveCommand.java +++ b/src/main/java/com/gmail/nossr50/database/commands/McremoveCommand.java @@ -16,14 +16,6 @@ import com.gmail.nossr50.database.Database; import com.gmail.nossr50.locale.LocaleLoader; public class McremoveCommand implements CommandExecutor { - private final String location; - private final mcMMO plugin; - - public McremoveCommand (mcMMO plugin) { - this.plugin = plugin; - this.location = mcMMO.getUsersFile(); - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { String playerName; @@ -49,9 +41,8 @@ public class McremoveCommand implements CommandExecutor { /* MySQL */ if (Config.getInstance().getUseMySQL()) { - Database database = mcMMO.getPlayerDatabase(); int affected = 0; - affected = database.update("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.user = '" + playerName + "'"); + affected = Database.update("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.user = '" + playerName + "'"); if (affected > 0) { sender.sendMessage(success); @@ -78,9 +69,10 @@ public class McremoveCommand implements CommandExecutor { BufferedReader in = null; FileWriter out = null; + String usersFilePath = mcMMO.getUsersFilePath(); try { - FileReader file = new FileReader(location); + FileReader file = new FileReader(usersFilePath); in = new BufferedReader(file); StringBuilder writer = new StringBuilder(); String line = ""; @@ -98,11 +90,11 @@ public class McremoveCommand implements CommandExecutor { } } - out = new FileWriter(location); //Write out the new file + out = new FileWriter(usersFilePath); //Write out the new file out.write(writer.toString()); } catch (Exception e) { - plugin.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); + mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString()); } finally { if (in != null) { diff --git a/src/main/java/com/gmail/nossr50/database/commands/MmoupdateCommand.java b/src/main/java/com/gmail/nossr50/database/commands/MmoupdateCommand.java index c763a633a..492956431 100644 --- a/src/main/java/com/gmail/nossr50/database/commands/MmoupdateCommand.java +++ b/src/main/java/com/gmail/nossr50/database/commands/MmoupdateCommand.java @@ -13,12 +13,6 @@ import com.gmail.nossr50.runnables.SQLConversionTask; import com.gmail.nossr50.util.Users; public class MmoupdateCommand implements CommandExecutor { - private final mcMMO plugin; - - public MmoupdateCommand (mcMMO plugin) { - this.plugin = plugin; - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.admin")) { @@ -29,7 +23,7 @@ public class MmoupdateCommand implements CommandExecutor { Users.clearAll(); convertToMySQL(); - for (Player x : plugin.getServer().getOnlinePlayers()) { + for (Player x : mcMMO.p.getServer().getOnlinePlayers()) { Users.addUser(x); } @@ -46,6 +40,6 @@ public class MmoupdateCommand implements CommandExecutor { return; } - plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new SQLConversionTask(plugin), 1); + mcMMO.p.getServer().getScheduler().runTaskLaterAsynchronously(mcMMO.p, new SQLConversionTask(), 1); } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java index f4c5dcd54..069aa0b4f 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java @@ -28,7 +28,7 @@ public class McMMOPlayer { String playerName = player.getName(); this.player = player; this.profile = new PlayerProfile(playerName, true); - this.party = PartyManager.getInstance().getPlayerParty(playerName); + this.party = PartyManager.getPlayerParty(playerName); } /** @@ -112,7 +112,7 @@ public class McMMOPlayer { * @param newValue The amount of XP to add */ public void addXPOverrideBonus(SkillType skillType, int xp) { - int modifiedXp = (int)Math.floor(xp * Config.getInstance().xpGainMultiplier); + int modifiedXp = (int)Math.floor(xp * Config.getInstance().getExperienceGainsGlobalMultiplier()); addXPOverride(skillType, modifiedXp); } @@ -138,7 +138,7 @@ public class McMMOPlayer { bonusModifier = calculatePartyXPModifier(skillType); } - int xp = (int)Math.floor((newValue / skillType.getXpModifier()) * Config.getInstance().xpGainMultiplier); + int xp = (int)Math.floor((newValue / skillType.getXpModifier()) * Config.getInstance().getExperienceGainsGlobalMultiplier()); if (bonusModifier > 0) { if (bonusModifier >= 2) { diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index 3961480d7..98898431c 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -59,11 +59,11 @@ public class PlayerProfile { HashMap skillsDATS = new HashMap(); HashMap toolATS = new HashMap(); - private final static String location = mcMMO.getUsersFile(); + private final static String location = mcMMO.getUsersFilePath(); public PlayerProfile(String playerName, boolean addNew) { this.playerName = playerName; - party = PartyManager.getInstance().getPlayerParty(playerName); + party = PartyManager.getPlayerParty(playerName); for (AbilityType abilityType : AbilityType.values()) { skillsDATS.put(abilityType, 0); @@ -93,19 +93,18 @@ public class PlayerProfile { } public boolean loadMySQL() { - Database database = mcMMO.getPlayerDatabase(); String tablePrefix = Config.getInstance().getMySQLTablePrefix(); - userId = database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'"); + userId = Database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'"); if (userId == 0) { return false; } - HashMap> huds = database.read("SELECT hudtype FROM " + tablePrefix + "huds WHERE user_id = " + userId); + HashMap> huds = Database.read("SELECT hudtype FROM " + tablePrefix + "huds WHERE user_id = " + userId); if (huds.get(1) == null) { - database.write("INSERT INTO " + tablePrefix + "huds (user_id) VALUES (" + userId + ")"); + Database.write("INSERT INTO " + tablePrefix + "huds (user_id) VALUES (" + userId + ")"); } else { for (HudType type : HudType.values()) { @@ -119,11 +118,11 @@ public class PlayerProfile { * I'm still learning MySQL, this is a fix for adding a new table * its not pretty but it works */ - HashMap> cooldowns = database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + tablePrefix + "cooldowns WHERE user_id = " + userId); + HashMap> cooldowns = Database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + tablePrefix + "cooldowns WHERE user_id = " + userId); ArrayList cooldownValues = cooldowns.get(1); if (cooldownValues == null) { - database.write("INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")"); + Database.write("INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")"); mcMMO.p.getLogger().warning(playerName + "does not exist in the cooldown table. Their cooldowns will be reset."); } else { @@ -137,11 +136,11 @@ public class PlayerProfile { skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldownValues.get(7))); } - HashMap> stats = database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "skills WHERE user_id = " + userId); + HashMap> stats = Database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "skills WHERE user_id = " + userId); ArrayList statValues = stats.get(1); if (statValues == null) { - database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")"); + Database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")"); mcMMO.p.getLogger().warning(playerName + "does not exist in the skills table. Their stats will be reset."); } else { @@ -159,11 +158,11 @@ public class PlayerProfile { skills.put(SkillType.FISHING, Integer.valueOf(statValues.get(11))); } - HashMap> experience = database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "experience WHERE user_id = " + userId); + HashMap> experience = Database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "experience WHERE user_id = " + userId); ArrayList experienceValues = experience.get(1); if (experienceValues == null) { - database.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")"); + Database.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")"); mcMMO.p.getLogger().warning(playerName + "does not exist in the experience table. Their experience will be reset."); } else { @@ -186,14 +185,13 @@ public class PlayerProfile { } public void addMySQLPlayer() { - Database database = mcMMO.getPlayerDatabase(); String tablePrefix = Config.getInstance().getMySQLTablePrefix(); - database.write("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR + ")"); - userId = database.getInt("SELECT id FROM "+tablePrefix + "users WHERE user = '" + playerName + "'"); - database.write("INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")"); - database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")"); - database.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")"); + Database.write("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR + ")"); + userId = Database.getInt("SELECT id FROM "+tablePrefix + "users WHERE user = '" + playerName + "'"); + Database.write("INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")"); + Database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")"); + Database.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")"); } public boolean load() { @@ -307,12 +305,11 @@ public class PlayerProfile { // if we are using mysql save to database if (Config.getInstance().getUseMySQL()) { - Database database = mcMMO.getPlayerDatabase(); String tablePrefix = Config.getInstance().getMySQLTablePrefix(); - database.write("UPDATE " + tablePrefix + "huds SET hudtype = '" + hudType.toString() + "' WHERE user_id = " + userId); - database.write("UPDATE " + tablePrefix + "users SET lastlogin = " + ((int) (timestamp / Misc.TIME_CONVERSION_FACTOR)) + " WHERE id = " + userId); - database.write("UPDATE " + tablePrefix + "cooldowns SET " + Database.write("UPDATE " + tablePrefix + "huds SET hudtype = '" + hudType.toString() + "' WHERE user_id = " + userId); + Database.write("UPDATE " + tablePrefix + "users SET lastlogin = " + ((int) (timestamp / Misc.TIME_CONVERSION_FACTOR)) + " WHERE id = " + userId); + Database.write("UPDATE " + tablePrefix + "cooldowns SET " + " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER) + ", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER) + ", unarmed = " + skillsDATS.get(AbilityType.BERSERK) @@ -322,7 +319,7 @@ public class PlayerProfile { + ", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER) + ", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING) + " WHERE user_id = " + userId); - database.write("UPDATE " + tablePrefix + "skills SET " + Database.write("UPDATE " + tablePrefix + "skills SET " + " taming = " + skills.get(SkillType.TAMING) + ", mining = " + skills.get(SkillType.MINING) + ", repair = " + skills.get(SkillType.REPAIR) @@ -336,7 +333,7 @@ public class PlayerProfile { + ", acrobatics = " + skills.get(SkillType.ACROBATICS) + ", fishing = " + skills.get(SkillType.FISHING) + " WHERE user_id = " + userId); - database.write("UPDATE " + tablePrefix + "experience SET " + Database.write("UPDATE " + tablePrefix + "experience SET " + " taming = " + skillsXp.get(SkillType.TAMING) + ", mining = " + skillsXp.get(SkillType.MINING) + ", repair = " + skillsXp.get(SkillType.REPAIR) diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerStat.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerStat.java index 948521e79..4c7caac45 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerStat.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerStat.java @@ -4,8 +4,6 @@ public class PlayerStat { public String name; public int statVal = 0; - public PlayerStat() {}; - public PlayerStat(String name, int value) { this.name = name; this.statVal = value; diff --git a/src/main/java/com/gmail/nossr50/datatypes/treasure/ExcavationTreasure.java b/src/main/java/com/gmail/nossr50/datatypes/treasure/ExcavationTreasure.java index 093d79769..7483b0473 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/treasure/ExcavationTreasure.java +++ b/src/main/java/com/gmail/nossr50/datatypes/treasure/ExcavationTreasure.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.datatypes.treasure; import org.bukkit.inventory.ItemStack; public class ExcavationTreasure extends Treasure { - // dirt | grass | sand | gravel | clay | mycel | soulsand // 00000001 - dirt 1 // 00000010 - grass 2 diff --git a/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java b/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java index 4625a761c..a48d2dac9 100644 --- a/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java +++ b/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java @@ -3,8 +3,7 @@ package com.gmail.nossr50.events.chat; /** * Called when a chat is sent to the admin chat channel */ -public class McMMOAdminChatEvent extends McMMOChatEvent{ - +public class McMMOAdminChatEvent extends McMMOChatEvent { public McMMOAdminChatEvent(String sender, String message) { super(sender, message); } diff --git a/src/main/java/com/gmail/nossr50/events/chat/McMMOChatEvent.java b/src/main/java/com/gmail/nossr50/events/chat/McMMOChatEvent.java index fafa6da9f..d7d79ec7f 100644 --- a/src/main/java/com/gmail/nossr50/events/chat/McMMOChatEvent.java +++ b/src/main/java/com/gmail/nossr50/events/chat/McMMOChatEvent.java @@ -4,12 +4,12 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class McMMOChatEvent extends Event implements Cancellable{ +public class McMMOChatEvent extends Event implements Cancellable { private boolean cancelled; private String sender; private String message; - public McMMOChatEvent(String sender, String message) { + protected McMMOChatEvent(String sender, String message) { this.sender = sender; this.message = message; } diff --git a/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java b/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java index 112dd24cd..6dde6fe88 100644 --- a/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java +++ b/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java @@ -3,7 +3,7 @@ package com.gmail.nossr50.events.chat; /** * Called when a chat is sent to a party channel */ -public class McMMOPartyChatEvent extends McMMOChatEvent{ +public class McMMOPartyChatEvent extends McMMOChatEvent { private String party; public McMMOPartyChatEvent(String sender, String party, String message) { diff --git a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java index a627e21b4..9b177b2bd 100644 --- a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java +++ b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java @@ -9,11 +9,11 @@ import com.gmail.nossr50.skills.SkillType; /** * Generic event for mcMMO experience events. */ -public class McMMOPlayerExperienceEvent extends PlayerEvent { +public abstract class McMMOPlayerExperienceEvent extends PlayerEvent { protected SkillType skill; protected int skillLevel; - public McMMOPlayerExperienceEvent(Player player, SkillType skill) { + protected McMMOPlayerExperienceEvent(Player player, SkillType skill) { super(player); this.skill = skill; this.skillLevel = skill.getSkillLevel(player); diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java index 0a81eab92..14d7f09b3 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java @@ -8,7 +8,6 @@ import org.bukkit.event.block.BlockBreakEvent; * Called when mcMMO breaks a block due to a special ability. */ public class FakeBlockBreakEvent extends BlockBreakEvent { - public FakeBlockBreakEvent(Block theBlock, Player player) { super(theBlock, player); } diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeBlockDamageEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeBlockDamageEvent.java index 037cfa50d..82b2f947d 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeBlockDamageEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeBlockDamageEvent.java @@ -9,7 +9,6 @@ import org.bukkit.inventory.ItemStack; * Called when mcMMO damages a block due to a special ability. */ public class FakeBlockDamageEvent extends BlockDamageEvent { - public FakeBlockDamageEvent(Player player, Block block, ItemStack itemInHand, boolean instaBreak) { super(player, block, itemInHand, instaBreak); } diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java index 377436b5d..a2ad48842 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java @@ -7,7 +7,6 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; * Called when mcMMO applies damage from an entity due to special abilities. */ public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent { - public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) { super(damager, damagee, cause, damage); } diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java index df531adac..3ae6b1aed 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java @@ -7,7 +7,6 @@ import org.bukkit.event.entity.EntityDamageEvent; * Called when mcMMO applies damage due to special abilities. */ public class FakeEntityDamageEvent extends EntityDamageEvent { - public FakeEntityDamageEvent(Entity damagee, DamageCause cause, int damage) { super(damagee, cause, damage); } diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java index 1d884a7bc..d338fbb6d 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java @@ -7,7 +7,6 @@ import org.bukkit.event.player.PlayerAnimationEvent; * Called when handling extra drops to avoid issues with NoCheat. */ public class FakePlayerAnimationEvent extends PlayerAnimationEvent { - public FakePlayerAnimationEvent(Player player) { super(player); } diff --git a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyChangeEvent.java b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyChangeEvent.java index 2248176ec..a5af26ba0 100644 --- a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyChangeEvent.java +++ b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyChangeEvent.java @@ -8,12 +8,11 @@ import org.bukkit.event.player.PlayerEvent; /** * Called when a player attempts to join, leave, or change parties. */ -public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{ - - protected String oldParty; - protected String newParty; - protected EventReason reason; - protected boolean cancelled; +public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable { + private String oldParty; + private String newParty; + private EventReason reason; + private boolean cancelled; public McMMOPartyChangeEvent(Player player, String oldParty, String newParty, EventReason reason) { super(player); diff --git a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java index 35d647102..54254ee4d 100644 --- a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java +++ b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java @@ -7,7 +7,7 @@ import org.bukkit.event.player.PlayerTeleportEvent; /** * Called just before a player teleports using the /ptp command. */ -public class McMMOPartyTeleportEvent extends PlayerTeleportEvent{ +public class McMMOPartyTeleportEvent extends PlayerTeleportEvent { private String party; private Player target; diff --git a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java index db530bef0..0c4f6d7c4 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java +++ b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java @@ -9,11 +9,11 @@ import com.gmail.nossr50.skills.SkillType; /** * Generic event for mcMMO skill handling. */ -public class McMMOPlayerSkillEvent extends PlayerEvent { +public abstract class McMMOPlayerSkillEvent extends PlayerEvent { protected SkillType skill; protected int skillLevel; - public McMMOPlayerSkillEvent(Player player, SkillType skill) { + protected McMMOPlayerSkillEvent(Player player, SkillType skill) { super(player); this.skill = skill; this.skillLevel = skill.getSkillLevel(player); diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 5154a0d3f..aa6dd9a33 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -27,7 +27,7 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.runnables.StickyPistonTracker; import com.gmail.nossr50.skills.AbilityType; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.skills.ToolType; import com.gmail.nossr50.skills.excavation.Excavation; import com.gmail.nossr50.skills.herbalism.Herbalism; @@ -149,7 +149,7 @@ public class BlockListener implements Listener { if (BlockChecks.canBeGreenTerra(block)) { /* Green Terra */ if (profile.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(player)) { - Skills.abilityCheck(player, SkillType.HERBALISM); + SkillTools.abilityCheck(player, SkillType.HERBALISM); } /* @@ -272,19 +272,19 @@ public class BlockListener implements Listener { ItemStack heldItem = player.getItemInHand(); if (profile.getToolPreparationMode(ToolType.HOE) && ItemChecks.isHoe(heldItem) && (BlockChecks.canBeGreenTerra(block) || BlockChecks.canMakeMossy(block)) && Permissions.greenTerra(player)) { - Skills.abilityCheck(player, SkillType.HERBALISM); + SkillTools.abilityCheck(player, SkillType.HERBALISM); } else if (profile.getToolPreparationMode(ToolType.AXE) && ItemChecks.isAxe(heldItem) && BlockChecks.isLog(block) && Permissions.treeFeller(player)) { - Skills.abilityCheck(player, SkillType.WOODCUTTING); + SkillTools.abilityCheck(player, SkillType.WOODCUTTING); } else if (profile.getToolPreparationMode(ToolType.PICKAXE) && ItemChecks.isPickaxe(heldItem) && BlockChecks.canBeSuperBroken(block) && Permissions.superBreaker(player)) { - Skills.abilityCheck(player, SkillType.MINING); + SkillTools.abilityCheck(player, SkillType.MINING); } else if (profile.getToolPreparationMode(ToolType.SHOVEL) && ItemChecks.isShovel(heldItem) && BlockChecks.canBeGigaDrillBroken(block) && Permissions.gigaDrillBreaker(player)) { - Skills.abilityCheck(player, SkillType.EXCAVATION); + SkillTools.abilityCheck(player, SkillType.EXCAVATION); } else if (profile.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockChecks.canBeGigaDrillBroken(block) || block.getType().equals(Material.SNOW)) && Permissions.berserk(player)) { - Skills.abilityCheck(player, SkillType.UNARMED); + SkillTools.abilityCheck(player, SkillType.UNARMED); } } @@ -327,7 +327,7 @@ public class BlockListener implements Listener { if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canMakeMossy(block)) { Herbalism.greenTerra(player, block); } - else if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && Skills.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) { + else if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && SkillTools.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) { if (Excavation.requiresTool) { if (ItemChecks.isShovel(heldItem)) { event.setInstaBreak(true); @@ -339,7 +339,7 @@ public class BlockListener implements Listener { Excavation.gigaDrillBreaker(player, block); } } - else if (profile.getAbilityMode(AbilityType.BERSERK) && Skills.triggerCheck(player, block, AbilityType.BERSERK)) { + else if (profile.getAbilityMode(AbilityType.BERSERK) && SkillTools.triggerCheck(player, block, AbilityType.BERSERK)) { if (heldItem.getType().equals(Material.AIR)) { FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); plugin.getServer().getPluginManager().callEvent(armswing); @@ -351,7 +351,7 @@ public class BlockListener implements Listener { SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); } } - else if (profile.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) { + else if (profile.getAbilityMode(AbilityType.SUPER_BREAKER) && SkillTools.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) { MiningManager miningManager = new MiningManager(player); if (Mining.requiresTool) { @@ -366,7 +366,7 @@ public class BlockListener implements Listener { } } else if ((profile.getSkillLevel(SkillType.WOODCUTTING) >= Woodcutting.LEAF_BLOWER_UNLOCK_LEVEL) && BlockChecks.isLeaves(block)) { - if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { + if (SkillTools.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { if (Woodcutting.REQUIRES_TOOL) { if (ItemChecks.isAxe(heldItem)) { event.setInstaBreak(true); diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index a36b96ff3..6eed50b3c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -110,7 +110,7 @@ public class EntityListener implements Listener { return; } - if (attacker instanceof Player && PartyManager.getInstance().inSameParty(defendingPlayer, (Player) attacker)) { + if (attacker instanceof Player && PartyManager.inSameParty(defendingPlayer, (Player) attacker)) { event.setCancelled(true); return; } diff --git a/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java b/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java index 1541c3fbd..96e3ed57f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java @@ -11,7 +11,6 @@ import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; public class HardcoreListener implements Listener { - /** * Monitor PlayerDeath events. * diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 7c7fbd46d..c93b80e4c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -17,7 +17,6 @@ import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.PluginDescriptionFile; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; @@ -26,7 +25,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.skills.fishing.Fishing; import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.mining.BlastMining; @@ -36,14 +35,13 @@ import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.ChatManager; -import com.gmail.nossr50.util.Item; -import com.gmail.nossr50.util.MOTD; +import com.gmail.nossr50.util.ChimaeraWing; +import com.gmail.nossr50.util.Motd; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class PlayerListener implements Listener { - private final mcMMO plugin; public PlayerListener(final mcMMO plugin) { @@ -154,20 +152,11 @@ public class PlayerListener implements Listener { } if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) { - PluginDescriptionFile pluginDescription = plugin.getDescription(); - MOTD motd = new MOTD(player); - - motd.displayVersion(pluginDescription.getVersion()); - motd.displayHardcoreSettings(); - motd.displayXpPerks(); - motd.displayCooldownPerks(); - motd.displayActivationPerks(); - motd.displayLuckyPerks(); - motd.displayWebsite(pluginDescription.getWebsite()); + Motd.displayAll(player); } if (plugin.isXPEventEnabled()) { - player.sendMessage(LocaleLoader.getString("XPRate.Event", new Object[] {Config.getInstance().xpGainMultiplier})); + player.sendMessage(LocaleLoader.getString("XPRate.Event", new Object[] {Config.getInstance().getExperienceGainsGlobalMultiplier()})); } } @@ -265,20 +254,20 @@ public class PlayerListener implements Listener { /* ACTIVATION & ITEM CHECKS */ if (BlockChecks.canActivateAbilities(block)) { - if (Skills.abilitiesEnabled) { + if (SkillTools.abilitiesEnabled) { if (BlockChecks.canActivateHerbalism(block)) { - Skills.activationCheck(player, SkillType.HERBALISM); + SkillTools.activationCheck(player, SkillType.HERBALISM); } - Skills.activationCheck(player, SkillType.AXES); - Skills.activationCheck(player, SkillType.EXCAVATION); - Skills.activationCheck(player, SkillType.MINING); - Skills.activationCheck(player, SkillType.SWORDS); - Skills.activationCheck(player, SkillType.UNARMED); - Skills.activationCheck(player, SkillType.WOODCUTTING); + SkillTools.activationCheck(player, SkillType.AXES); + SkillTools.activationCheck(player, SkillType.EXCAVATION); + SkillTools.activationCheck(player, SkillType.MINING); + SkillTools.activationCheck(player, SkillType.SWORDS); + SkillTools.activationCheck(player, SkillType.UNARMED); + SkillTools.activationCheck(player, SkillType.WOODCUTTING); } - Item.itemChecks(player); + ChimaeraWing.activationCheck(player); } /* GREEN THUMB CHECK */ @@ -291,18 +280,18 @@ public class PlayerListener implements Listener { case RIGHT_CLICK_AIR: /* ACTIVATION CHECKS */ - if (Skills.abilitiesEnabled) { - Skills.activationCheck(player, SkillType.AXES); - Skills.activationCheck(player, SkillType.EXCAVATION); - Skills.activationCheck(player, SkillType.HERBALISM); - Skills.activationCheck(player, SkillType.MINING); - Skills.activationCheck(player, SkillType.SWORDS); - Skills.activationCheck(player, SkillType.UNARMED); - Skills.activationCheck(player, SkillType.WOODCUTTING); + if (SkillTools.abilitiesEnabled) { + SkillTools.activationCheck(player, SkillType.AXES); + SkillTools.activationCheck(player, SkillType.EXCAVATION); + SkillTools.activationCheck(player, SkillType.HERBALISM); + SkillTools.activationCheck(player, SkillType.MINING); + SkillTools.activationCheck(player, SkillType.SWORDS); + SkillTools.activationCheck(player, SkillType.UNARMED); + SkillTools.activationCheck(player, SkillType.WOODCUTTING); } /* ITEM CHECKS */ - Item.itemChecks(player); + ChimaeraWing.activationCheck(player); break; @@ -352,13 +341,11 @@ public class PlayerListener implements Listener { return; } - ChatManager chatManager = new ChatManager(plugin, player.getName(), event.getMessage()); - chatManager.handlePartyChat(party); + ChatManager.handlePartyChat(party, player.getName(), event.getMessage()); event.setCancelled(true); } else if (profile.getAdminChatMode()) { - ChatManager chatManager = new ChatManager(plugin, player.getName(), event.getMessage()); - chatManager.handleAdminChat(); + ChatManager.handleAdminChat(player.getName(), event.getMessage()); event.setCancelled(true); } } diff --git a/src/main/java/com/gmail/nossr50/listeners/SelfListener.java b/src/main/java/com/gmail/nossr50/listeners/SelfListener.java index 0636e33cb..c1f9e7ef8 100644 --- a/src/main/java/com/gmail/nossr50/listeners/SelfListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/SelfListener.java @@ -9,7 +9,6 @@ import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent; * Listener for listening to our own events, only really useful for catching errors */ public class SelfListener implements Listener { - /** * Monitor internal XP gain events. * diff --git a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java index 512621e7b..81bf7fa24 100644 --- a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java +++ b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java @@ -9,10 +9,12 @@ import org.bukkit.ChatColor; import com.gmail.nossr50.config.Config; -public class LocaleLoader { +public final class LocaleLoader { private static final String BUNDLE_NAME = "com.gmail.nossr50.locale.locale"; private static ResourceBundle RESOURCE_BUNDLE = null; + private LocaleLoader() {}; + public static String getString(String key) { return getString(key, null); } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index e469f6e16..278236825 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -99,7 +99,6 @@ public class mcMMO extends JavaPlugin { private HashMap tntTracker = new HashMap(); private HashMap furnaceTracker = new HashMap(); - private static Database database; public static mcMMO p; public static ChunkManager placeStore; @@ -181,8 +180,8 @@ public class mcMMO extends JavaPlugin { //Setup the leader boards if (configInstance.getUseMySQL()) { - database = new Database(this); - database.createStructure(); + Database.connect(); + Database.createStructure(); } else { Leaderboard.updateLeaderboards(); @@ -199,9 +198,9 @@ public class mcMMO extends JavaPlugin { //Schedule Spout Activation 1 second after start-up scheduler.scheduleSyncDelayedTask(this, new SpoutStart(this), 20); //Periodic save timer (Saves every 10 minutes by default) - scheduler.scheduleSyncRepeatingTask(this, new SaveTimer(this), 0, configInstance.getSaveInterval() * 1200); + scheduler.scheduleSyncRepeatingTask(this, new SaveTimer(), 0, configInstance.getSaveInterval() * 1200); //Regen & Cooldown timer (Runs every second) - scheduler.scheduleSyncRepeatingTask(this, new SkillMonitor(this), 0, 20); + scheduler.scheduleSyncRepeatingTask(this, new SkillMonitor(), 0, 20); //Bleed timer (Runs every two seconds) scheduler.scheduleSyncRepeatingTask(this, new BleedTimer(), 0, 40); @@ -253,8 +252,7 @@ public class mcMMO extends JavaPlugin { new MobStoreCleaner(); // Create Anniversary files - Anniversary anniversary = new Anniversary(); - anniversary.createAnniversaryFile(); + Anniversary.createAnniversaryFile(); } /** @@ -311,7 +309,7 @@ public class mcMMO extends JavaPlugin { @Override public void onDisable() { Users.saveAll(); //Make sure to save player information if the server shuts down - PartyManager.getInstance().saveParties(); + PartyManager.saveParties(); getServer().getScheduler().cancelTasks(this); //This removes our tasks placeStore.saveAll(); //Save our metadata placeStore.cleanUp(); //Cleanup empty metadata stores @@ -323,9 +321,8 @@ public class mcMMO extends JavaPlugin { catch (IOException e) { getLogger().severe(e.toString()); } - Anniversary anniversary = new Anniversary(); - anniversary.saveAnniversaryFiles(); + Anniversary.saveAnniversaryFiles(); getLogger().info("Was disabled."); //How informative! } @@ -372,7 +369,7 @@ public class mcMMO extends JavaPlugin { getCommand("mcpurge").setExecutor(new McpurgeCommand()); } if (configInstance.getCommandMCRemoveEnabled()) { - getCommand("mcremove").setExecutor(new McremoveCommand(this)); + getCommand("mcremove").setExecutor(new McremoveCommand()); } if (configInstance.getCommandMCAbilityEnabled()) { @@ -392,7 +389,7 @@ public class mcMMO extends JavaPlugin { } if (configInstance.getCommandMCRefreshEnabled()) { - getCommand("mcrefresh").setExecutor(new McrefreshCommand(this)); + getCommand("mcrefresh").setExecutor(new McrefreshCommand()); } if (configInstance.getCommandMCTopEnabled()) { @@ -413,11 +410,11 @@ public class mcMMO extends JavaPlugin { //Party commands if (configInstance.getCommandAdminChatAEnabled()) { - getCommand("a").setExecutor(new ACommand(this)); + getCommand("a").setExecutor(new ACommand()); } if (configInstance.getCommandPartyEnabled()) { - getCommand("party").setExecutor(new PartyCommand(this)); + getCommand("party").setExecutor(new PartyCommand()); } if (configInstance.getCommandPartyChatPEnabled()) { @@ -430,11 +427,11 @@ public class mcMMO extends JavaPlugin { //Other commands if (configInstance.getCommandAddXPEnabled()) { - getCommand("addxp").setExecutor(new AddxpCommand(this)); + getCommand("addxp").setExecutor(new AddxpCommand()); } if (configInstance.getCommandAddLevelsEnabled()) { - getCommand("addlevels").setExecutor(new AddlevelsCommand(this)); + getCommand("addlevels").setExecutor(new AddlevelsCommand()); } if (configInstance.getCommandMmoeditEnabled()) { @@ -446,10 +443,10 @@ public class mcMMO extends JavaPlugin { } if (configInstance.getCommandXPRateEnabled()) { - getCommand("xprate").setExecutor(new XprateCommand(this)); + getCommand("xprate").setExecutor(new XprateCommand()); } - getCommand("mmoupdate").setExecutor(new MmoupdateCommand(this)); + getCommand("mmoupdate").setExecutor(new MmoupdateCommand()); //Spout commands if (configInstance.getCommandXPLockEnabled()) { @@ -542,7 +539,7 @@ public class mcMMO extends JavaPlugin { return flatFileDirectory; } - public static String getUsersFile() { + public static String getUsersFilePath() { return usersFile; } @@ -550,10 +547,6 @@ public class mcMMO extends JavaPlugin { return modDirectory; } - public static Database getPlayerDatabase() { - return database; - } - public boolean isXPEventEnabled() { return xpEventEnabled; } diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index c59fea659..b144a9a46 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -12,26 +12,9 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Users; -public class PartyManager { - private static String partiesFilePath; +public final class PartyManager { + private static String partiesFilePath = mcMMO.p.getDataFolder().getPath() + File.separator + "FlatFileStuff" + File.separator + "parties.yml"; private static List parties = new ArrayList(); - private static mcMMO plugin; - private static PartyManager instance; - - private PartyManager() { - plugin = mcMMO.p; - partiesFilePath = plugin.getDataFolder().getPath() + File.separator + "FlatFileStuff" + File.separator + "parties.yml"; - - loadParties(); - } - - public static PartyManager getInstance() { - if (instance == null) { - instance = new PartyManager(); - } - - return instance; - } /** * Check if two players are in the same party. @@ -40,7 +23,7 @@ public class PartyManager { * @param secondPlayer The second player * @return true if they are in the same party, false otherwise */ - public boolean inSameParty(Player firstPlayer, Player secondPlayer) { + public static boolean inSameParty(Player firstPlayer, Player secondPlayer) { PlayerProfile firstProfile = Users.getProfile(firstPlayer); PlayerProfile secondProfile = Users.getProfile(secondPlayer); @@ -64,7 +47,7 @@ public class PartyManager { * @param playerName The name of the player that joins * @param party The concerned party */ - private void informPartyMembersJoin(String playerName, Party party) { + private static void informPartyMembersJoin(String playerName, Party party) { for (Player member : party.getOnlineMembers()) { if (!member.getName().equals(playerName)) { member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", new Object[] {playerName})); @@ -78,7 +61,7 @@ public class PartyManager { * @param playerName The name of the player that quits * @param party The concerned party */ - private void informPartyMembersQuit(String playerName, Party party) { + private static void informPartyMembersQuit(String playerName, Party party) { for (Player member : party.getOnlineMembers()) { if (!member.getName().equals(playerName)) { member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", new Object[] {playerName})); @@ -92,7 +75,7 @@ public class PartyManager { * @param player The player to check * @return all the players in the player's party */ - public List getAllMembers(Player player) { + public static List getAllMembers(Player player) { Party party = Users.getProfile(player).getParty(); if (party == null) { @@ -108,7 +91,7 @@ public class PartyManager { * @param partyName The party to check * @return all online players in this party */ - public List getOnlineMembers(String partyName) { + public static List getOnlineMembers(String partyName) { Party party = getParty(partyName); if (party == null) { @@ -124,7 +107,7 @@ public class PartyManager { * @param player The player to check * @return all online players in this party */ - public List getOnlineMembers(Player player) { + public static List getOnlineMembers(Player player) { return getOnlineMembers(player.getName()); } @@ -134,7 +117,7 @@ public class PartyManager { * @param partyName The party name * @return the existing party, null otherwise */ - public Party getParty(String partyName) { + public static Party getParty(String partyName) { for (Party party : parties) { if (party.getName().equals(partyName)) { return party; @@ -150,7 +133,7 @@ public class PartyManager { * @param playerName The member name * @return the existing party, null otherwise */ - public Party getPlayerParty(String playerName) { + public static Party getPlayerParty(String playerName) { for (Party party : parties) { if (party.getMembers().contains(playerName)) { return party; @@ -164,7 +147,7 @@ public class PartyManager { * * @return the list of parties. */ - public List getParties() { + public static List getParties() { return parties; } @@ -174,7 +157,7 @@ public class PartyManager { * @param playerName The name of the player to remove * @param party The party */ - public void removeFromParty(String playerName, Party party) { + public static void removeFromParty(String playerName, Party party) { List members = party.getMembers(); members.remove(playerName); @@ -204,7 +187,7 @@ public class PartyManager { * * @param party The party to remove */ - public void disbandParty(Party party) { + public static void disbandParty(Party party) { List members = party.getMembers(); for (String member : party.getMembers()) { @@ -229,7 +212,7 @@ public class PartyManager { * @param partyName The party to add the player to * @param password the password for this party, null if there was no password */ - public void createParty(Player player, PlayerProfile playerProfile, String partyName, String password) { + public static void createParty(Player player, PlayerProfile playerProfile, String partyName, String password) { partyName = partyName.replace(".", ""); Party party = getParty(partyName); String playerName = player.getName(); @@ -264,7 +247,7 @@ public class PartyManager { * @param partyName The party to add the player to * @param password the password for this party, null if there was no password */ - public void joinParty(Player player, PlayerProfile playerProfile, String partyName, String password) { + public static void joinParty(Player player, PlayerProfile playerProfile, String partyName, String password) { partyName = partyName.replace(".", ""); Party party = getParty(partyName); String playerName = player.getName(); @@ -299,7 +282,7 @@ public class PartyManager { * @param password The password provided by the player * @return true if the player can join the party */ - public boolean checkJoinability(Player player, Party party, String password) { + public static boolean checkJoinability(Player player, Party party, String password) { //Don't care about passwords if it isn't locked if (party.isLocked()) { String partyPassword = party.getPassword(); @@ -330,7 +313,7 @@ public class PartyManager { * @param player The player to add to the party * @param playerProfile The profile of the player */ - public void joinInvitedParty(Player player, PlayerProfile playerProfile) { + public static void joinInvitedParty(Player player, PlayerProfile playerProfile) { Party invite = playerProfile.getInvite(); if (!parties.contains(invite)) { @@ -349,7 +332,7 @@ public class PartyManager { * @param playerProfile The profile of the player * @param party The party */ - public void addToParty(String playerName, PlayerProfile playerProfile, Party party) { + public static void addToParty(String playerName, PlayerProfile playerProfile, Party party) { informPartyMembersJoin(playerName, party); playerProfile.setParty(party); party.getMembers().add(playerName); @@ -361,7 +344,7 @@ public class PartyManager { * @param partyName The party name * @return the leader of the party */ - public String getPartyLeader(String partyName) { + public static String getPartyLeader(String partyName) { Party party = getParty(partyName); if (party == null) { @@ -377,7 +360,7 @@ public class PartyManager { * @param playerName The name of the player to set as leader * @param party The party */ - public void setPartyLeader(String playerName, Party party) { + public static void setPartyLeader(String playerName, Party party) { String leaderName = party.getLeader(); for (Player member : party.getOnlineMembers()) { @@ -402,7 +385,7 @@ public class PartyManager { * @param playerProfile The profile of the given player * @return true if the player can invite */ - public boolean canInvite(Player player, PlayerProfile playerProfile) { + public static boolean canInvite(Player player, PlayerProfile playerProfile) { Party party = playerProfile.getParty(); if (party == null || (party.isLocked() && !party.getLeader().equals(player.getName()))) { @@ -418,7 +401,7 @@ public class PartyManager { * @param partyName The party name to check * @return true if this is a valid party, false otherwise */ - public boolean isParty(String partyName) { + public static boolean isParty(String partyName) { for (Party party : parties) { if (party.getName().equals(partyName)) { return true; @@ -431,7 +414,7 @@ public class PartyManager { /** * Load party file. */ - private void loadParties() { + private static void loadParties() { File file = new File(partiesFilePath); if (!file.exists()) { @@ -462,7 +445,7 @@ public class PartyManager { /** * Save party file. */ - public void saveParties() { + public static void saveParties() { File file = new File(partiesFilePath); if (file.exists()) { diff --git a/src/main/java/com/gmail/nossr50/party/commands/ACommand.java b/src/main/java/com/gmail/nossr50/party/commands/ACommand.java index eea2cb566..413774f06 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/ACommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/ACommand.java @@ -14,12 +14,6 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class ACommand implements CommandExecutor { - private final mcMMO plugin; - - public ACommand (mcMMO plugin) { - this.plugin = plugin; - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { PlayerProfile profile; @@ -68,7 +62,7 @@ public class ACommand implements CommandExecutor { Player player = (Player) sender; McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(player.getName(), message); - plugin.getServer().getPluginManager().callEvent(chatEvent); + mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); if (chatEvent.isCancelled()) { return true; @@ -77,9 +71,9 @@ public class ACommand implements CommandExecutor { message = chatEvent.getMessage(); String prefix = LocaleLoader.getString("Commands.AdminChat.Prefix", new Object[] {player.getName()} ); - plugin.getLogger().info("[A]<" + player.getName() + "> " + message); + mcMMO.p.getLogger().info("[A]<" + player.getName() + "> " + message); - for (Player otherPlayer : plugin.getServer().getOnlinePlayers()) { + for (Player otherPlayer : mcMMO.p.getServer().getOnlinePlayers()) { if (Permissions.adminChat(otherPlayer) || otherPlayer.isOp()) { otherPlayer.sendMessage(prefix + message); } @@ -87,7 +81,7 @@ public class ACommand implements CommandExecutor { } else { McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent("Console", message); - plugin.getServer().getPluginManager().callEvent(chatEvent); + mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); if (chatEvent.isCancelled()) { return true; @@ -96,9 +90,9 @@ public class ACommand implements CommandExecutor { message = chatEvent.getMessage(); String prefix = LocaleLoader.getString("Commands.AdminChat.Prefix", new Object[] {LocaleLoader.getString("Commands.Chat.Console")} ); - plugin.getLogger().info("[A]<*Console*> " + message); + mcMMO.p.getLogger().info("[A]<*Console*> " + message); - for (Player player : plugin.getServer().getOnlinePlayers()) { + for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { if (Permissions.adminChat(player) || player.isOp()) { player.sendMessage(prefix + message); } diff --git a/src/main/java/com/gmail/nossr50/party/commands/PCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PCommand.java index c77ef0bc4..dcf68f19f 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PCommand.java @@ -96,7 +96,7 @@ public class PCommand implements CommandExecutor { return true; } - if (!PartyManager.getInstance().isParty(args[0])) { + if (!PartyManager.isParty(args[0])) { sender.sendMessage(LocaleLoader.getString("Party.InvalidName")); return true; } @@ -123,7 +123,7 @@ public class PCommand implements CommandExecutor { plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + message); - for (Player member : PartyManager.getInstance().getOnlineMembers(args[0])) { + for (Player member : PartyManager.getOnlineMembers(args[0])) { member.sendMessage(prefix + message); } } diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java index e4bf94a19..4094e1f79 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -19,12 +19,6 @@ import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.util.Users; public class PartyCommand implements CommandExecutor { - private final mcMMO plugin; - - public PartyCommand (mcMMO plugin) { - this.plugin = plugin; - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandHelper.noConsoleUsage(sender)) { @@ -38,51 +32,71 @@ public class PartyCommand implements CommandExecutor { Player player = (Player) sender; PlayerProfile playerProfile = Users.getProfile(player); - if(args.length < 1) + if (args.length < 1) { return party(sender); + } - if(args[0].equalsIgnoreCase("join")) + if (args[0].equalsIgnoreCase("join")) { return join(sender, args); - else if(args[0].equalsIgnoreCase("accept")) + } + else if (args[0].equalsIgnoreCase("accept")) { return accept(sender, args); - else if(args[0].equalsIgnoreCase("create")) + } + else if (args[0].equalsIgnoreCase("create")) { return create(sender, args); - else if(args[0].equalsIgnoreCase("info")) + } + else if (args[0].equalsIgnoreCase("info")) { return party(sender); - else if(args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) - return help(sender, args); + } + else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) { + return printHelp(sender, args); + } + if (playerProfile.inParty()) { - if(args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) + if(args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) { return quit(sender, args); - else if(args[0].equalsIgnoreCase("expshare")) - return expshare(sender, args); - else if(args[0].equalsIgnoreCase("itemshare")) - return itemshare(sender, args); - else if(args[0].equalsIgnoreCase("invite")) + } + else if(args[0].equalsIgnoreCase("expshare")) { + return shareExp(sender, args); + } + else if(args[0].equalsIgnoreCase("itemshare")) { + return shareItem(sender, args); + } + else if(args[0].equalsIgnoreCase("invite")) { return invite(sender, args); - else if(args[0].equalsIgnoreCase("kick")) + } + else if(args[0].equalsIgnoreCase("kick")) { return kick(sender, args); - else if(args[0].equalsIgnoreCase("disband")) + } + else if(args[0].equalsIgnoreCase("disband")) { return disband(sender, args); - else if(args[0].equalsIgnoreCase("owner")) - return owner(sender, args); - else if(args[0].equalsIgnoreCase("lock")) + } + else if(args[0].equalsIgnoreCase("owner")) { + return changeOwner(sender, args); + } + else if(args[0].equalsIgnoreCase("lock")) { return lock(sender, args); - else if(args[0].equalsIgnoreCase("unlock")) + } + else if(args[0].equalsIgnoreCase("unlock")) { return unlock(sender, args); - else if(args[0].equalsIgnoreCase("password")) - return password(sender, args); - else if(args[0].equalsIgnoreCase("rename")) + } + else if(args[0].equalsIgnoreCase("password")) { + return changePassword(sender, args); + } + else if(args[0].equalsIgnoreCase("rename")) { return rename(sender, args); - else - return usage(sender); - } else { + } + else { + return printUsage(sender); + } + } + else { player.sendMessage(LocaleLoader.getString("Commands.Party.None")); - return usage(sender); + return printUsage(sender); } } - private boolean usage(CommandSender sender) { + private boolean printUsage(CommandSender sender) { Player player = (Player) sender; player.sendMessage(LocaleLoader.getString("Party.Help.0")); player.sendMessage(LocaleLoader.getString("Party.Help.1")); @@ -97,7 +111,7 @@ public class PartyCommand implements CommandExecutor { if (playerProfile.inParty()) { Party party = playerProfile.getParty(); - Server server = plugin.getServer(); + Server server = mcMMO.p.getServer(); String leader = party.getLeader(); StringBuffer tempList = new StringBuffer(); @@ -123,127 +137,137 @@ public class PartyCommand implements CommandExecutor { // player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode", new Object[] { "NONE", "NONE" })); Party share modes will get implemented later player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header")); player.sendMessage(LocaleLoader.getString("Commands.Party.Members", new Object[] {tempList})); - } else { - return usage(sender); + } + else { + return printUsage(sender); } return true; } private boolean join(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.join")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.join")) { return true; + } + Player player = (Player) sender; String playerName = player.getName(); PlayerProfile playerProfile = Users.getProfile(player); - - PartyManager partyManagerInstance = PartyManager.getInstance(); Party party = playerProfile.getParty(); - if(args.length < 2) { + if (args.length < 2) { player.sendMessage(LocaleLoader.getString("Party.Help.0")); return true; - } else { + } + else { Player target = Bukkit.getServer().getPlayer(args[1]); + if (target == null) { player.sendMessage(LocaleLoader.getString("Party.NotOnline", new Object[] {args[1]})); return false; } + if (!Users.getProfile(target).inParty()) { player.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", new Object[] {args[1]})); return false; } - String password = null; - if(args.length > 2) password = args[2]; - String partyTarget = partyManagerInstance.getPlayerParty(target.getName()).getName(); - Party newParty = partyManagerInstance.getParty(args[0]); + String password = null; + + if(args.length > 2) { + password = args[2]; + } + + String partyTarget = PartyManager.getPlayerParty(target.getName()).getName(); + Party newParty = PartyManager.getParty(args[0]); // Check to see if the party exists, and if it does, can the player join it? - if (newParty != null && !partyManagerInstance.checkJoinability(player, newParty, null)) { + if (newParty != null && !PartyManager.checkJoinability(player, newParty, null)) { return true; // End before any event is fired. } if (party != null) { McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), partyTarget, EventReason.CHANGED_PARTIES); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } - partyManagerInstance.removeFromParty(playerName, party); + + PartyManager.removeFromParty(playerName, party); } else { McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyTarget, EventReason.JOINED_PARTY); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } } - partyManagerInstance.joinParty(player, playerProfile, partyTarget, password); + PartyManager.joinParty(player, playerProfile, partyTarget, password); return true; } } private boolean accept(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.accept")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.accept")) { return true; + } Player player = (Player) sender; PlayerProfile playerProfile = Users.getProfile(player); if (playerProfile.hasPartyInvite()) { - PartyManager partyManagerInstance = PartyManager.getInstance(); - if (playerProfile.inParty()) { Party party = playerProfile.getParty(); McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), playerProfile.getInvite().getName(), EventReason.CHANGED_PARTIES); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } - partyManagerInstance.removeFromParty(player.getName(), party); + PartyManager.removeFromParty(player.getName(), party); } else { McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, playerProfile.getInvite().getName(), EventReason.JOINED_PARTY); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } } - partyManagerInstance.joinInvitedParty(player, playerProfile); + + PartyManager.joinInvitedParty(player, playerProfile); } else { player.sendMessage(LocaleLoader.getString("mcMMO.NoInvites")); } + return true; } private boolean create(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.create")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.create")) { return true; + } Player player = (Player) sender; String playerName = player.getName(); PlayerProfile playerProfile = Users.getProfile(player); - - PartyManager partyManagerInstance = PartyManager.getInstance(); Party party = playerProfile.getParty(); if(args.length < 2) { player.sendMessage(LocaleLoader.getString("Party.Help.1")); return true; - } else { + } + else { String partyname = args[1]; String password = null; if(args.length > 2) password = args[2]; - Party newParty = partyManagerInstance.getParty(partyname); + Party newParty = PartyManager.getParty(partyname); // Check to see if the party exists, and if it does cancel creating a new party if (newParty != null) { player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", new Object[] {partyname})); @@ -253,68 +277,67 @@ public class PartyCommand implements CommandExecutor { if (playerProfile.inParty()) { String oldPartyName = party.getName(); McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, partyname, EventReason.CHANGED_PARTIES); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } - partyManagerInstance.removeFromParty(playerName, party); - partyManagerInstance.createParty(player, playerProfile, partyname, password); - } else { + PartyManager.removeFromParty(playerName, party); + PartyManager.createParty(player, playerProfile, partyname, password); + } + else { McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyname, EventReason.JOINED_PARTY); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } - partyManagerInstance.createParty(player, playerProfile, partyname, password); + PartyManager.createParty(player, playerProfile, partyname, password); return true; } } + return true; } private boolean quit(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.quit")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.quit")) { return true; + } Player player = (Player) sender; String playerName = player.getName(); PlayerProfile playerProfile = Users.getProfile(player); - - PartyManager partyManagerInstance = PartyManager.getInstance(); Party party = playerProfile.getParty(); if (party != null) { McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), null, EventReason.LEFT_PARTY); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } - partyManagerInstance.removeFromParty(playerName, party); + PartyManager.removeFromParty(playerName, party); player.sendMessage(LocaleLoader.getString("Commands.Party.Leave")); } - else + else { player.sendMessage(LocaleLoader.getString("Commands.Party.None")); + } + return false; } - private boolean expshare(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.expshare")) - return true; - return true; + private boolean shareExp(CommandSender sender, String[] args) { + return (!CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.expshare")); } - private boolean itemshare(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.itemshare")) - return true; - return true; + private boolean shareItem(CommandSender sender, String[] args) { + return (!CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.itemshare")); } - private boolean help(CommandSender sender, String[] args) { + private boolean printHelp(CommandSender sender, String[] args) { Player player = (Player) sender; player.sendMessage(LocaleLoader.getString("Party.Help.3")); player.sendMessage(LocaleLoader.getString("Party.Help.1")); @@ -327,8 +350,9 @@ public class PartyCommand implements CommandExecutor { } private boolean invite(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.invite")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.invite")) { return true; + } switch (args.length) { case 2: @@ -340,14 +364,14 @@ public class PartyCommand implements CommandExecutor { return true; } - Player target = plugin.getServer().getPlayer(args[1]); + Player target = mcMMO.p.getServer().getPlayer(args[1]); if (target != null) { - if (PartyManager.getInstance().inSameParty(player, target)) { + if (PartyManager.inSameParty(player, target)) { player.sendMessage(LocaleLoader.getString("Party.Player.InSameParty")); return true; } - if (PartyManager.getInstance().canInvite(player, playerProfile)) { + if (PartyManager.canInvite(player, playerProfile)) { Party party = playerProfile.getParty(); Users.getProfile(target).setInvite(party); @@ -360,6 +384,7 @@ public class PartyCommand implements CommandExecutor { player.sendMessage(LocaleLoader.getString("Party.Locked")); return true; } + player.sendMessage(LocaleLoader.getString("Party.Player.Invalid")); return true; @@ -373,13 +398,13 @@ public class PartyCommand implements CommandExecutor { * Kick a party member */ private boolean kick(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.kick")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.kick")) { return true; + } + Player player = (Player) sender; String playerName = player.getName(); PlayerProfile playerProfile = Users.getProfile(player); - - PartyManager partyManagerInstance = PartyManager.getInstance(); Party party = playerProfile.getParty(); if (party.getLeader().equals(playerName)) { @@ -388,22 +413,27 @@ public class PartyCommand implements CommandExecutor { return true; } - Player target = plugin.getServer().getOfflinePlayer(args[1]).getPlayer(); + Player target = mcMMO.p.getServer().getOfflinePlayer(args[1]).getPlayer(); + if (target != null) { String partyName = party.getName(); McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(target, partyName, null, EventReason.KICKED_FROM_PARTY); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } + target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", new Object[] {partyName})); } - partyManagerInstance.removeFromParty(args[1], party); + + PartyManager.removeFromParty(args[1], party); } - else + else { player.sendMessage(LocaleLoader.getString("Party.NotOwner")); + } + return true; } @@ -411,59 +441,63 @@ public class PartyCommand implements CommandExecutor { * Disband the current party, kicks out all party members. */ private boolean disband(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.disband")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.disband")) { return true; + } Player player = (Player) sender; String playerName = player.getName(); PlayerProfile playerProfile = Users.getProfile(player); - - PartyManager partyManagerInstance = PartyManager.getInstance(); Party party = playerProfile.getParty(); if (party.getLeader().equals(playerName)) { for (Player onlineMembers : party.getOnlineMembers()) { McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), null, EventReason.KICKED_FROM_PARTY); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } + onlineMembers.sendMessage(LocaleLoader.getString("Party.Disband")); } - partyManagerInstance.disbandParty(party); + + PartyManager.disbandParty(party); } - else + else { player.sendMessage(LocaleLoader.getString("Party.NotOwner")); + } + return true; } /** * Change the owner of the current party */ - private boolean owner(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.owner")) + private boolean changeOwner(CommandSender sender, String[] args) { + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.owner")) { return true; + } Player player = (Player) sender; String playerName = player.getName(); PlayerProfile playerProfile = Users.getProfile(player); - - PartyManager partyManagerInstance = PartyManager.getInstance(); Party party = playerProfile.getParty(); - if(args.length < 2) { player.sendMessage("Usage: /party owner [player]"); return true; } + if (party.getLeader().equals(playerName)) { if (!party.getMembers().contains(args[1])) { player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {args[1]})); return true; } - partyManagerInstance.setPartyLeader(args[1], party); + + PartyManager.setPartyLeader(args[1], party); } + return true; } @@ -471,8 +505,9 @@ public class PartyCommand implements CommandExecutor { * Lock the current party */ private boolean lock(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.lock")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.lock")) { return true; + } Player player = (Player) sender; String playerName = player.getName(); @@ -489,11 +524,14 @@ public class PartyCommand implements CommandExecutor { player.sendMessage(LocaleLoader.getString("Party.Locked")); } } - else + else { player.sendMessage(LocaleLoader.getString("Party.NotOwner")); + } } - else + else { player.sendMessage("Commands.Party.None"); + } + return true; } @@ -501,8 +539,9 @@ public class PartyCommand implements CommandExecutor { * Unlock the current party */ private boolean unlock(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.unlock")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.unlock")) { return true; + } Player player = (Player) sender; String playerName = player.getName(); @@ -519,24 +558,28 @@ public class PartyCommand implements CommandExecutor { player.sendMessage(LocaleLoader.getString("Party.Unlocked")); } } - else + else { player.sendMessage(LocaleLoader.getString("Party.NotOwner")); + } } - else + else { player.sendMessage("Commands.Party.None"); + } + return true; } - private boolean password(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.password")) + private boolean changePassword(CommandSender sender, String[] args) { + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.password")) { return true; + } Player player = (Player) sender; String playerName = player.getName(); PlayerProfile playerProfile = Users.getProfile(player); Party party = playerProfile.getParty(); - if(args.length < 2) { + if (args.length < 2) { player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "password", "<" + LocaleLoader.getString("Commands.Usage.Password") + ">"})); return true; } @@ -546,8 +589,10 @@ public class PartyCommand implements CommandExecutor { party.setPassword(args[1]); player.sendMessage(LocaleLoader.getString("Party.PasswordSet", new Object[] {args[1]})); } - else + else { player.sendMessage(LocaleLoader.getString("Party.NotOwner")); + } + return true; } @@ -555,25 +600,28 @@ public class PartyCommand implements CommandExecutor { * Rename the current party */ private boolean rename(CommandSender sender, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.rename")) + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.rename")) { return true; + } Player player = (Player) sender; String playerName = player.getName(); PlayerProfile playerProfile = Users.getProfile(player); - - PartyManager partyManagerInstance = PartyManager.getInstance(); Party party = playerProfile.getParty(); String leader = party.getLeader(); if (party.getLeader().equals(playerName)) { - if(args.length < 2) { + if (args.length < 2) { player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"})); return true; - } else { + } + else { String newPartyName = args[1]; - if (!party.getName().equals(newPartyName)) {//This is to prevent party leaders from spamming other players with the rename message - Party newParty = partyManagerInstance.getParty(newPartyName); + + // This is to prevent party leaders from spamming other players with the rename message + if (!party.getName().equals(newPartyName)) { + Party newParty = PartyManager.getParty(newPartyName); + // Check to see if the party exists, and if it does cancel renaming the party if (newParty != null) { player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", new Object[] {newPartyName})); @@ -582,7 +630,7 @@ public class PartyCommand implements CommandExecutor { for (Player onlineMembers : party.getOnlineMembers()) { McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), newPartyName, EventReason.CHANGED_PARTIES); - plugin.getServer().getPluginManager().callEvent(event); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; @@ -592,13 +640,17 @@ public class PartyCommand implements CommandExecutor { onlineMembers.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", new Object[] {leader, newPartyName})); } } + party.setName(newPartyName); } + player.sendMessage(LocaleLoader.getString("Commands.Party.Rename", new Object[] {newPartyName})); } } - else + else { player.sendMessage(LocaleLoader.getString("Party.NotOwner")); + } + return true; } } diff --git a/src/main/java/com/gmail/nossr50/party/commands/PtpCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PtpCommand.java index c3442daad..663e10310 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PtpCommand.java @@ -61,7 +61,7 @@ public class PtpCommand implements CommandExecutor { return true; } - if (PartyManager.getInstance().inSameParty(player, target)) { + if (PartyManager.inSameParty(player, target)) { McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, profile.getParty().getName()); plugin.getServer().getPluginManager().callEvent(event); diff --git a/src/main/java/com/gmail/nossr50/runnables/BleedTimer.java b/src/main/java/com/gmail/nossr50/runnables/BleedTimer.java index eba81e0e2..3b2c9068f 100644 --- a/src/main/java/com/gmail/nossr50/runnables/BleedTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/BleedTimer.java @@ -15,11 +15,9 @@ import com.gmail.nossr50.skills.Combat; public class BleedTimer implements Runnable { private final static int MAX_BLEED_TICKS = 10; - private static Map bleedList = new HashMap(); private static Map bleedAddList = new HashMap(); private static List bleedRemoveList = new ArrayList(); - private static boolean lock = false; @Override diff --git a/src/main/java/com/gmail/nossr50/runnables/GainXp.java b/src/main/java/com/gmail/nossr50/runnables/GainXp.java index ff736013d..14ba53012 100644 --- a/src/main/java/com/gmail/nossr50/runnables/GainXp.java +++ b/src/main/java/com/gmail/nossr50/runnables/GainXp.java @@ -5,15 +5,15 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; public class GainXp implements Runnable { - private Player player = null; - private PlayerProfile profile = null; - private double baseXp = 0; - private SkillType skillType = null; - private LivingEntity target = null; - private int baseHealth = 0; + private Player player; + private PlayerProfile profile; + private double baseXp; + private SkillType skillType; + private LivingEntity target; + private int baseHealth; public GainXp(Player player, PlayerProfile profile, SkillType skillType, double baseXp, LivingEntity target) { this.player = player; @@ -39,6 +39,6 @@ public class GainXp implements Runnable { damage += health; } - Skills.xpProcessing(player, profile, skillType, (int) (damage * baseXp)); + SkillTools.xpProcessing(player, profile, skillType, (int) (damage * baseXp)); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/GreenThumbTimer.java b/src/main/java/com/gmail/nossr50/runnables/GreenThumbTimer.java index a138e4a04..178c72acc 100644 --- a/src/main/java/com/gmail/nossr50/runnables/GreenThumbTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/GreenThumbTimer.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.skills.AbilityType; import com.gmail.nossr50.skills.SkillType; public class GreenThumbTimer implements Runnable { - AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); private Block block; private PlayerProfile profile; private Material type; @@ -23,15 +22,16 @@ public class GreenThumbTimer implements Runnable { @Override public void run() { - if (this.block.getType() != this.type) + if (this.block.getType() != this.type) { this.block.setType(this.type); + } int skillLevel = this.profile.getSkillLevel(SkillType.HERBALISM); + int greenThumbStage = (int) ((double) skillLevel / (double) AdvancedConfig.getInstance().getGreenThumbStageChange()); - final int STAGE_CHANGE = advancedConfig.getGreenThumbStageChange(); - - int greenThumbStage = (int) ((double) skillLevel / (double) STAGE_CHANGE); - if (greenThumbStage > 4) greenThumbStage = 4; + if (greenThumbStage > 4) { + greenThumbStage = 4; + } switch(this.type) { case CROPS: diff --git a/src/main/java/com/gmail/nossr50/runnables/McRankAsync.java b/src/main/java/com/gmail/nossr50/runnables/McRankAsync.java index 1f878f3de..d5ecb284d 100644 --- a/src/main/java/com/gmail/nossr50/runnables/McRankAsync.java +++ b/src/main/java/com/gmail/nossr50/runnables/McRankAsync.java @@ -5,14 +5,12 @@ import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.database.Database; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; public class McRankAsync implements Runnable { - private Database database = mcMMO.getPlayerDatabase(); private final String playerName; private final CommandSender sender; @@ -23,23 +21,26 @@ public class McRankAsync implements Runnable { @Override public void run() { - final Map skills = database.readSQLRank(playerName); + final Map skills = Database.readSQLRank(playerName); Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("mcMMO"), new Runnable() { - @Override public void run() { sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading")); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", new Object[] {playerName})); + for (SkillType skillType : SkillType.values()) { - if (skillType.isChildSkill()) continue; + if (skillType.isChildSkill()) { + continue; + } + if (skillType.equals(SkillType.ALL)) continue; // We want the overall ranking to be at the bottom if (skills.get(skillType.name()) == null) { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", new Object[] {Skills.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")} )); + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", new Object[] {SkillTools.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")} )); } else { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", new Object[] {Skills.localizeSkillName(skillType), skills.get(skillType.name())} )); + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", new Object[] {SkillTools.localizeSkillName(skillType), skills.get(skillType.name())} )); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/MobStoreCleaner.java b/src/main/java/com/gmail/nossr50/runnables/MobStoreCleaner.java index 7696864c2..4261f1d5d 100755 --- a/src/main/java/com/gmail/nossr50/runnables/MobStoreCleaner.java +++ b/src/main/java/com/gmail/nossr50/runnables/MobStoreCleaner.java @@ -5,37 +5,34 @@ import org.bukkit.scheduler.BukkitScheduler; import com.gmail.nossr50.mcMMO; -public class MobStoreCleaner implements Runnable -{ +public class MobStoreCleaner implements Runnable { private int taskID; - public MobStoreCleaner() - { + public MobStoreCleaner() { taskID = -1; start(); } - public void start() - { - if (taskID >= 0) + public void start() { + if (taskID >= 0) { return; + } BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); taskID = scheduler.scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000); } - public void stop() - { - if(taskID < 0) + public void stop() { + if (taskID < 0) { return; + } Bukkit.getServer().getScheduler().cancelTask(taskID); taskID = -1; } @Override - public void run() - { + public void run() { mcMMO.placeStore.cleanMobLists(); } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java b/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java index b32a4bbac..1798918c6 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java @@ -9,17 +9,11 @@ import com.gmail.nossr50.database.Database; import com.gmail.nossr50.util.Misc; public class SQLConversionTask implements Runnable { - private final mcMMO plugin; private String tablePrefix = Config.getInstance().getMySQLTablePrefix(); - public SQLConversionTask(mcMMO plugin) { - this.plugin = plugin; - } - @Override public void run() { - Database database = mcMMO.getPlayerDatabase(); - String location = mcMMO.getUsersFile(); + String location = mcMMO.getUsersFilePath(); try { FileReader file = new FileReader(location); @@ -166,7 +160,7 @@ public class SQLConversionTask implements Runnable { } //Check to see if the user is in the DB - id = database.getInt("SELECT id FROM " + id = Database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'"); @@ -174,11 +168,11 @@ public class SQLConversionTask implements Runnable { theCount++; //Update the skill values - database.write("UPDATE " + Database.write("UPDATE " + tablePrefix + "users SET lastlogin = " + 0 + " WHERE id = " + id); - database.write("UPDATE " + Database.write("UPDATE " + tablePrefix + "skills SET " + " taming = taming+" + Misc.getInt(taming) @@ -194,7 +188,7 @@ public class SQLConversionTask implements Runnable { + ", acrobatics = acrobatics+" + Misc.getInt(acrobatics) + ", fishing = fishing+" + Misc.getInt(fishing) + " WHERE user_id = " + id); - database.write("UPDATE " + Database.write("UPDATE " + tablePrefix + "experience SET " + " taming = " + Misc.getInt(tamingXP) @@ -215,32 +209,32 @@ public class SQLConversionTask implements Runnable { theCount++; //Create the user in the DB - database.write("INSERT INTO " + Database.write("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR + ")"); - id = database.getInt("SELECT id FROM " + id = Database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'"); - database.write("INSERT INTO " + Database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + id + ")"); - database.write("INSERT INTO " + Database.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + id + ")"); //Update the skill values - database.write("UPDATE " + Database.write("UPDATE " + tablePrefix + "users SET lastlogin = " + 0 + " WHERE id = " + id); - database.write("UPDATE " + Database.write("UPDATE " + tablePrefix + "users SET party = '" + party + "' WHERE id = " + id); - database.write("UPDATE " + Database.write("UPDATE " + tablePrefix + "skills SET " + " taming = taming+" + Misc.getInt(taming) @@ -256,7 +250,7 @@ public class SQLConversionTask implements Runnable { + ", acrobatics = acrobatics+" + Misc.getInt(acrobatics) + ", fishing = fishing+" + Misc.getInt(fishing) + " WHERE user_id = " + id); - database.write("UPDATE " + Database.write("UPDATE " + tablePrefix + "experience SET " + " taming = " + Misc.getInt(tamingXP) @@ -279,7 +273,7 @@ public class SQLConversionTask implements Runnable { in.close(); } catch (Exception e) { - plugin.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); + mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); } } } diff --git a/src/main/java/com/gmail/nossr50/runnables/SQLReconnect.java b/src/main/java/com/gmail/nossr50/runnables/SQLReconnect.java index 6a5b9e1bb..df7d6e959 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SQLReconnect.java +++ b/src/main/java/com/gmail/nossr50/runnables/SQLReconnect.java @@ -7,19 +7,13 @@ import com.gmail.nossr50.database.Database; import com.gmail.nossr50.util.Users; public class SQLReconnect implements Runnable { - private final mcMMO plugin; - - public SQLReconnect(mcMMO plugin) { - this.plugin = plugin; - } - @Override public void run() { if (Database.checkConnected()) { Users.saveAll(); //Save all profiles Users.clearAll(); //Clear the profiles - for (Player player : plugin.getServer().getOnlinePlayers()) { + for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { Users.addUser(player); //Add in new profiles, forcing them to 'load' again from MySQL } } diff --git a/src/main/java/com/gmail/nossr50/runnables/SaveTimer.java b/src/main/java/com/gmail/nossr50/runnables/SaveTimer.java index 0eabf6f44..5929b2ed1 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SaveTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/SaveTimer.java @@ -8,23 +8,17 @@ import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.util.Users; public class SaveTimer implements Runnable { - private final mcMMO plugin; - - public SaveTimer(final mcMMO plugin) { - this.plugin = plugin; - } - @Override public void run() { //All player data will be saved periodically through this int count = 1; - BukkitScheduler bukkitScheduler = plugin.getServer().getScheduler(); + BukkitScheduler bukkitScheduler = mcMMO.p.getServer().getScheduler(); for (McMMOPlayer mcMMOPlayer : Users.getPlayers().values()) { - bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(mcMMOPlayer), count); + bukkitScheduler.scheduleSyncDelayedTask(mcMMO.p, new ProfileSaveTask(mcMMOPlayer), count); count++; } - PartyManager.getInstance().saveParties(); + PartyManager.saveParties(); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/SkillMonitor.java b/src/main/java/com/gmail/nossr50/runnables/SkillMonitor.java index eaa605347..4f9d443f1 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SkillMonitor.java +++ b/src/main/java/com/gmail/nossr50/runnables/SkillMonitor.java @@ -6,22 +6,15 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.skills.AbilityType; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Users; public class SkillMonitor implements Runnable { - private final mcMMO plugin; - - public SkillMonitor(final mcMMO plugin) { - this.plugin = plugin; - } - @Override public void run() { long curTime = System.currentTimeMillis(); - for (Player player : plugin.getServer().getOnlinePlayers()) { - + for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { PlayerProfile profile = Users.getProfile(player); /* @@ -29,7 +22,7 @@ public class SkillMonitor implements Runnable { */ for (SkillType skill : SkillType.values()) { if (skill.getTool() != null && skill.getAbility() != null) { - Skills.monitorSkill(player, profile, curTime, skill); + SkillTools.monitorSkill(player, profile, curTime, skill); } } @@ -37,8 +30,8 @@ public class SkillMonitor implements Runnable { * COOLDOWN MONITORING */ for (AbilityType ability : AbilityType.values()) { - if (ability.getCooldown() > 0 ) { - Skills.watchCooldown(player, profile, ability); + if (ability.getCooldown() > 0) { + SkillTools.watchCooldown(player, profile, ability); } } } diff --git a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java index a7996d743..c2d325505 100644 --- a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java +++ b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java @@ -18,11 +18,13 @@ public class StickyPistonTracker implements Runnable { Block newBlock = event.getBlock().getRelative(event.getDirection()); Block originalBlock = newBlock.getRelative(event.getDirection()); - if (originalBlock.getType() != Material.AIR) + if (originalBlock.getType() != Material.AIR) { return; + } - if (!mcMMO.placeStore.isTrue(originalBlock)) + if (!mcMMO.placeStore.isTrue(originalBlock)) { return; + } mcMMO.placeStore.setFalse(originalBlock); mcMMO.placeStore.setTrue(newBlock); diff --git a/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java b/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java index 4fdb81b01..fb4755a75 100644 --- a/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java @@ -1,23 +1,16 @@ package com.gmail.nossr50.runnables; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.Database; public class UserPurgeTask implements Runnable { - private Database database = mcMMO.getPlayerDatabase(); - - public UserPurgeTask() { - - } - @Override public void run() { if (Config.getInstance().getUseMySQL()) { - database.purgePowerlessSQL(); + Database.purgePowerlessSQL(); if (Config.getInstance().getOldUsersCutoff() != -1) { - database.purgeOldSQL(); + Database.purgeOldSQL(); } } else { diff --git a/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionMain.java b/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionMain.java index d00b2ca4c..d8c82efc6 100755 --- a/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionMain.java +++ b/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionMain.java @@ -53,8 +53,9 @@ public class BlockStoreConversionMain implements Runnable { this.xDirs = this.dataDir.listFiles(); for (this.i = 0; (this.i < HiddenConfig.getInstance().getConversionRate()) && (this.i < this.xDirs.length); this.i++) { - if (this.converters[this.i] == null) + if (this.converters[this.i] == null) { this.converters[this.i] = new BlockStoreConversionXDirectory(); + } this.converters[this.i].start(this.world, this.xDirs[this.i]); } @@ -63,8 +64,9 @@ public class BlockStoreConversionMain implements Runnable { } public void stop() { - if (this.taskID < 0) + if (this.taskID < 0) { return; + } this.scheduler.cancelTask(this.taskID); this.taskID = -1; diff --git a/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionXDirectory.java b/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionXDirectory.java index d3e21603d..dfe1cf06a 100755 --- a/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionXDirectory.java +++ b/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionXDirectory.java @@ -25,8 +25,9 @@ public class BlockStoreConversionXDirectory implements Runnable { this.converters = new BlockStoreConversionZDirectory[HiddenConfig.getInstance().getConversionRate()]; this.dataDir = dataDir; - if (this.taskID >= 0) + if (this.taskID >= 0) { return; + } this.taskID = this.scheduler.scheduleSyncDelayedTask(mcMMO.p, this, 1); return; @@ -54,8 +55,9 @@ public class BlockStoreConversionXDirectory implements Runnable { this.zDirs = this.dataDir.listFiles(); for (this.i = 0; (this.i < HiddenConfig.getInstance().getConversionRate()) && (this.i < this.zDirs.length); this.i++) { - if (this.converters[this.i] == null) + if (this.converters[this.i] == null) { this.converters[this.i] = new BlockStoreConversionZDirectory(); + } this.converters[this.i].start(this.world, this.dataDir, this.zDirs[this.i]); } @@ -64,8 +66,9 @@ public class BlockStoreConversionXDirectory implements Runnable { } public void stop() { - if (this.taskID < 0) + if (this.taskID < 0) { return; + } this.scheduler.cancelTask(this.taskID); this.taskID = -1; diff --git a/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionZDirectory.java b/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionZDirectory.java index 706522621..12f281745 100755 --- a/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionZDirectory.java +++ b/src/main/java/com/gmail/nossr50/runnables/blockstoreconversion/BlockStoreConversionZDirectory.java @@ -38,8 +38,9 @@ public class BlockStoreConversionZDirectory implements Runnable { this.dataDir = dataDir; this.xDir = xDir; - if (this.taskID >= 0) + if (this.taskID >= 0) { return; + } this.taskID = this.scheduler.scheduleSyncDelayedTask(mcMMO.p, this, 1); return; @@ -110,8 +111,9 @@ public class BlockStoreConversionZDirectory implements Runnable { for (this.y2 = (64 * this.y); this.y2 < (64 * this.y + 64); this.y2++) { try { - if (!this.manager.isTrue(this.cxPos, this.y2, this.czPos, this.world)) + if (!this.manager.isTrue(this.cxPos, this.y2, this.czPos, this.world)) { continue; + } this.newManager.setTrue(this.cxPos, this.y2, this.czPos, this.world); } @@ -119,6 +121,7 @@ public class BlockStoreConversionZDirectory implements Runnable { } } } + continue; } @@ -128,17 +131,26 @@ public class BlockStoreConversionZDirectory implements Runnable { for (this.x = 0; this.x < 16; this.x++) { for (this.z = 0; this.z < 16; this.z++) { - if (this.primitiveChunklet != null) + if (this.primitiveChunklet != null) { this.oldArray = this.primitiveChunklet.store[x][z]; - if (this.primitiveExChunklet != null) + } + + if (this.primitiveExChunklet != null) { this.oldArray = this.primitiveExChunklet.store[x][z]; - else + } + else { return; + } + this.newArray = this.currentChunk.store[x][z]; - if (this.oldArray.length < 64) + + if (this.oldArray.length < 64) { return; - else if (this.newArray.length < ((this.y * 64) + 64)) + } + else if (this.newArray.length < ((this.y * 64) + 64)) { return; + } + System.arraycopy(this.oldArray, 0, this.newArray, (this.y * 64), 64); } } @@ -148,8 +160,9 @@ public class BlockStoreConversionZDirectory implements Runnable { this.newManager.unloadChunk(this.cx, this.cz, this.world); for (File yFile : dataDir.listFiles()) { - if (!yFile.exists()) + if (!yFile.exists()) { continue; + } yFile.delete(); } diff --git a/src/main/java/com/gmail/nossr50/skills/Combat.java b/src/main/java/com/gmail/nossr50/skills/Combat.java index 0a66c6819..e35d44498 100644 --- a/src/main/java/com/gmail/nossr50/skills/Combat.java +++ b/src/main/java/com/gmail/nossr50/skills/Combat.java @@ -45,9 +45,11 @@ import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; -public class Combat { +public final class Combat { private static Config configInstance = Config.getInstance(); + private Combat() {}; + /** * Apply combat modifiers and process and XP gain. * @@ -83,7 +85,7 @@ public class Combat { boolean canSerratedStrike = Permissions.serratedStrikes(player); //So we don't have to check the same permission twice if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) { - Skills.abilityCheck(player, SkillType.SWORDS); + SkillTools.abilityCheck(player, SkillType.SWORDS); } if (Permissions.swordsBleed(player) && shouldBeAffected(player, target)) { @@ -112,7 +114,7 @@ public class Combat { PlayerProfile profile = axeManager.getProfile(); boolean canSkullSplit = Permissions.skullSplitter(player); //So we don't have to check the same permission twice if (profile.getToolPreparationMode(ToolType.AXE) && canSkullSplit) { - Skills.abilityCheck(player, SkillType.AXES); + SkillTools.abilityCheck(player, SkillType.AXES); } if (Permissions.axeBonus(player)) { @@ -150,7 +152,7 @@ public class Combat { boolean canBerserk = Permissions.berserk(player); //So we don't have to check the same permission twice if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) { - Skills.abilityCheck(player, SkillType.UNARMED); + SkillTools.abilityCheck(player, SkillType.UNARMED); } if (Permissions.unarmedBonus(player)) { @@ -558,7 +560,7 @@ public class Combat { if (entity instanceof Player) { Player defender = (Player) entity; - if (!defender.getWorld().getPVP() || defender == player || PartyManager.getInstance().inSameParty(player, defender) || Users.getProfile(defender).getGodMode()) { + if (!defender.getWorld().getPVP() || defender == player || PartyManager.inSameParty(player, defender) || Users.getProfile(defender).getGodMode()) { return false; } diff --git a/src/main/java/com/gmail/nossr50/skills/Page.java b/src/main/java/com/gmail/nossr50/skills/Page.java index 132681971..c2734cbdf 100644 --- a/src/main/java/com/gmail/nossr50/skills/Page.java +++ b/src/main/java/com/gmail/nossr50/skills/Page.java @@ -7,24 +7,24 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Misc; -public class Page { +public final class Page { + private Page() {} - public static int getTotalPageNumber(String address) - { + public static int getTotalPageNumber(String address) { String[] addressSplit = LocaleLoader.getString(address).split("\n"); - if (addressSplit.length <= 8) + + if (addressSplit.length <= 8) { return 1; + } return (addressSplit.length/8)+1; } - public static ArrayList grabPageContents(String header, String address, int pagenum) - { + public static ArrayList grabPageContents(String header, String address, int pagenum) { int pageIndexStart = 0; //Determine what string to start at - if (pagenum > 1) - { + if (pagenum > 1) { pageIndexStart = 8*(pagenum-1); } @@ -34,23 +34,21 @@ public class Page { allStrings.add(LocaleLoader.getString("Guides.Header", new Object[] {header} )); //Add targeted strings - - while (allStrings.size() < 9) - { - if (pageIndexStart+allStrings.size() > split.length) + while (allStrings.size() < 9) { + if (pageIndexStart+allStrings.size() > split.length) { allStrings.add(""); - else + } + else { allStrings.add(split[pageIndexStart+allStrings.size()-1]); + } } allStrings.add("Page "+pagenum+" of "+getTotalPageNumber(address)); return allStrings; } - public static void clearChat(Player player) - { - for (int x = 0; x < 20; x++) - { + public static void clearChat(Player player) { + for (int x = 0; x < 20; x++) { player.sendMessage(""); } } @@ -58,36 +56,39 @@ public class Page { public static void grabGuidePageForSkill(SkillType skilltype, Player player, String[] args) { String skillName = skilltype.toString(); String capitalized = Misc.getCapitalized(skillName); - String localized = Skills.localizeSkillName(skilltype); + String localized = SkillTools.localizeSkillName(skilltype); player.sendMessage(LocaleLoader.getString("Guides.Available", new Object[] {localized, localized.toLowerCase()} )); - if (args.length >= 1) { - if (args[0].equals("?")) { - String address = "Guides."+capitalized; - int totalPages = Page.getTotalPageNumber(address); + if (args.length >= 1 && args[0].equals("?")) { + String address = "Guides." + capitalized; + int totalPages = Page.getTotalPageNumber(address); - if (args.length > 1 && Misc.isInt(args[1]) && Misc.getInt(args[1]) <= totalPages) { + if (args.length == 1) { + Page.clearChat(player); + + for (String target : Page.grabPageContents(localized, address, 1)) { + player.sendMessage(target); + } + } + else { + if (!Misc.isInt(args[1])) { + player.sendMessage(LocaleLoader.getString("Guides.Page.Invalid")); + } + + if (Misc.getInt(args[1]) <= totalPages) { Page.clearChat(player); + for (String target : Page.grabPageContents(localized, address, Misc.getInt(args[1]))) { player.sendMessage(target); } } - else if (args.length == 1) { - Page.clearChat(player); - for (String target : Page.grabPageContents(localized, address, 1)) { - player.sendMessage(target); - } - } - else if (args.length > 1 && Misc.getInt(args[1]) > totalPages) { + else { player.sendMessage(LocaleLoader.getString("Guides.Page.OutOfRange", new Object[] {totalPages} )); } - else if (args.length > 1 && !Misc.isInt(args[1])) { - player.sendMessage(LocaleLoader.getString("Guides.Page.Invalid")); - } - } - else { - player.sendMessage(LocaleLoader.getString("Guides.Usage", new Object[] {localized.toLowerCase()} )); } } + else { + player.sendMessage(LocaleLoader.getString("Guides.Usage", new Object[] {localized.toLowerCase()} )); + } } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/skills/SkillCommand.java b/src/main/java/com/gmail/nossr50/skills/SkillCommand.java index 226aeafa2..049446107 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillCommand.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillCommand.java @@ -159,7 +159,7 @@ public abstract class SkillCommand implements CommandExecutor { protected void luckyEffectsDisplay() { if (isLucky) { String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", new Object[] { Skills.localizeSkillName(skill) }) })); + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", new Object[] { SkillTools.localizeSkillName(skill) }) })); } } diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/SkillTools.java similarity index 97% rename from src/main/java/com/gmail/nossr50/skills/Skills.java rename to src/main/java/com/gmail/nossr50/skills/SkillTools.java index 00e71ed83..b2d63dcbf 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillTools.java @@ -21,7 +21,7 @@ import com.gmail.nossr50.util.ModChecks; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; -public class Skills { +public class SkillTools { static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength(); public static boolean abilitiesEnabled = Config.getInstance().getAbilitiesEnabled(); diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java index 6a3ee80cf..d032e5726 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java @@ -5,7 +5,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; public class DodgeEventHandler extends AcrobaticsEventHandler { @@ -47,7 +47,7 @@ public class DodgeEventHandler extends AcrobaticsEventHandler { PlayerProfile profile = manager.getProfile(); if (System.currentTimeMillis() >= profile.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) { - Skills.xpProcessing(player, profile, SkillType.ACROBATICS, xp); + SkillTools.xpProcessing(player, profile, SkillType.ACROBATICS, xp); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java index bfd92e20e..f01e713c8 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java @@ -4,7 +4,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -67,7 +67,7 @@ public class RollEventHandler extends AcrobaticsEventHandler { @Override protected void processXPGain(int xpGain) { - Skills.xpProcessing(player, manager.getProfile(), SkillType.ACROBATICS, xpGain); + SkillTools.xpProcessing(player, manager.getProfile(), SkillType.ACROBATICS, xpGain); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java index a0c9155cb..c883c8add 100644 --- a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java @@ -19,7 +19,7 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModChecks; @@ -112,7 +112,7 @@ public class Excavation { } } - Skills.xpProcessing(player, profile, SkillType.EXCAVATION, xp); + SkillTools.xpProcessing(player, profile, SkillType.EXCAVATION, xp); } /** @@ -125,7 +125,7 @@ public class Excavation { if (player == null) return; - Skills.abilityDurabilityLoss(player.getItemInHand(), Misc.toolDurabilityLoss); + SkillTools.abilityDurabilityLoss(player.getItemInHand(), Misc.toolDurabilityLoss); if (!mcMMO.placeStore.isTrue(block) && Misc.blockBreakSimulate(block, player, true)) { FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java index 90d8b7ef2..d08922b96 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java @@ -31,7 +31,7 @@ import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.Combat; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.ItemChecks; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -62,7 +62,7 @@ public class Fishing { return; } - Skills.handleFoodSkills(player, SkillType.FISHING, event, fishermansDietRankLevel1, fishermansDietMaxLevel, rankChange); + SkillTools.handleFoodSkills(player, SkillType.FISHING, event, fishermansDietRankLevel1, fishermansDietMaxLevel, rankChange); } /** @@ -141,7 +141,7 @@ public class Fishing { } } - Skills.xpProcessing(player, profile, SkillType.FISHING, Config.getInstance().getFishingBaseXP()); + SkillTools.xpProcessing(player, profile, SkillType.FISHING, Config.getInstance().getFishingBaseXP()); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index 0dba8f585..449ede27d 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -24,7 +24,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.runnables.GreenThumbTimer; import com.gmail.nossr50.skills.AbilityType; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModChecks; import com.gmail.nossr50.util.Permissions; @@ -58,7 +58,7 @@ public class Herbalism { return; } - Skills.handleFoodSkills(player, SkillType.HERBALISM, event, farmersDietRankLevel1, farmersDietMaxLevel, rankChange); + SkillTools.handleFoodSkills(player, SkillType.HERBALISM, event, farmersDietRankLevel1, farmersDietMaxLevel, rankChange); } /** @@ -437,7 +437,7 @@ public class Herbalism { if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) return; - Skills.xpProcessing(player, profile, SkillType.HERBALISM, xp); + SkillTools.xpProcessing(player, profile, SkillType.HERBALISM, xp); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index fe2ad2610..c66d50d5b 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -14,7 +14,7 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModChecks; @@ -106,7 +106,7 @@ public class Mining { break; } - Skills.xpProcessing(player, profile, SkillType.MINING, xp); + SkillTools.xpProcessing(player, profile, SkillType.MINING, xp); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/mining/RemoteDetonationEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/RemoteDetonationEventHandler.java index 67d2233dd..237ab1524 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/RemoteDetonationEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/RemoteDetonationEventHandler.java @@ -12,7 +12,7 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.AbilityType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; public class RemoteDetonationEventHandler { @@ -43,8 +43,8 @@ public class RemoteDetonationEventHandler { } protected boolean cooldownOver() { - if (!Skills.cooldownOver(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)) { - player.sendMessage(LocaleLoader.getString("Skills.TooTired", new Object[] { Skills.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player) })); + if (!SkillTools.cooldownOver(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)) { + player.sendMessage(LocaleLoader.getString("SkillTools.TooTired", new Object[] { SkillTools.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player) })); return false; } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/SuperBreakerEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/SuperBreakerEventHandler.java index 894fa11ff..42152304f 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/SuperBreakerEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/SuperBreakerEventHandler.java @@ -8,7 +8,7 @@ import org.getspout.spoutapi.sound.SoundEffect; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModChecks; @@ -48,7 +48,7 @@ public class SuperBreakerEventHandler { } protected void processDurabilityLoss() { - Skills.abilityDurabilityLoss(heldItem, durabilityLoss); + SkillTools.abilityDurabilityLoss(heldItem, durabilityLoss); } protected void processDropsAndXP() { diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java index 10cc6c96c..819c1a850 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -16,7 +16,7 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -52,7 +52,7 @@ public class Repair { dif = (short) (dif * modify); - Skills.xpProcessing(player, profile, SkillType.REPAIR, dif * 10); + SkillTools.xpProcessing(player, profile, SkillType.REPAIR, dif * 10); //CLANG CLANG if (mcMMO.spoutEnabled) { @@ -248,7 +248,7 @@ public class Repair { int activationChance = Misc.calculateActivationChance(Permissions.luckyRepair(player)); if (chance > Misc.getRandom().nextInt(activationChance) && Permissions.repairBonus(player)) { - player.sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy")); + player.sendMessage(LocaleLoader.getString("Repair.SkillTools.FeltEasy")); return true; } return false; diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltResourceEventHandler.java b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltResourceEventHandler.java index 75363bb3e..69328f901 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltResourceEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltResourceEventHandler.java @@ -8,7 +8,7 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -68,11 +68,11 @@ public class SmeltResourceEventHandler { } if (Permissions.mining(player)) { - Skills.xpProcessing(player, profile, SkillType.MINING, xp / 2); + SkillTools.xpProcessing(player, profile, SkillType.MINING, xp / 2); } if (Permissions.repair(player)) { - Skills.xpProcessing(player, profile, SkillType.REPAIR, xp / 2); + SkillTools.xpProcessing(player, profile, SkillType.REPAIR, xp / 2); } } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 57e2e4e99..bbdebd048 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -13,7 +13,7 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -37,11 +37,11 @@ public class TamingManager extends SkillManager { switch (event.getEntityType()) { case WOLF: - Skills.xpProcessing(player, profile, SkillType.TAMING, Taming.wolfXP); + SkillTools.xpProcessing(player, profile, SkillType.TAMING, Taming.wolfXP); break; case OCELOT: - Skills.xpProcessing(player, profile, SkillType.TAMING, Taming.ocelotXP); + SkillTools.xpProcessing(player, profile, SkillType.TAMING, Taming.ocelotXP); break; default: diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java index 597148ad4..7599df268 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java @@ -17,7 +17,7 @@ import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.Combat; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModChecks; @@ -42,13 +42,13 @@ public abstract class TreeFeller { if (treeFellerReachedThreshold) { treeFellerReachedThreshold = false; - player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold")); + player.sendMessage(LocaleLoader.getString("Woodcutting.SkillTools.TreeFellerThreshold")); return; } // If the tool can't sustain the durability loss if (!handleDurabilityLoss(treeFellerBlocks, player)) { - player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter")); + player.sendMessage(LocaleLoader.getString("Woodcutting.SkillTools.TreeFeller.Splinter")); int health = player.getHealth(); @@ -223,7 +223,7 @@ public abstract class TreeFeller { // Do we really have to check the permission here? if (Permissions.woodcutting(player)) { - Skills.xpProcessing(player, Users.getProfile(player), SkillType.WOODCUTTING, xp); + SkillTools.xpProcessing(player, Users.getProfile(player), SkillType.WOODCUTTING, xp); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java index 83845fc7a..0e9ec9807 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java @@ -15,14 +15,14 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModChecks; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; -public abstract class Woodcutting { +public final class Woodcutting { public static final int DOUBLE_DROP_MAX_LEVEL = AdvancedConfig.getInstance().getMiningDoubleDropMaxLevel(); public static final double DOUBLE_DROP_CHANCE = AdvancedConfig.getInstance().getMiningDoubleDropChance(); public static final int LEAF_BLOWER_UNLOCK_LEVEL = AdvancedConfig.getInstance().getLeafBlowUnlockLevel(); @@ -30,6 +30,8 @@ public abstract class Woodcutting { public static final int TREE_FELLER_THRESHOLD = Config.getInstance().getTreeFellerThreshold(); public static final boolean REQUIRES_TOOL = Config.getInstance().getWoodcuttingRequiresTool(); + private Woodcutting() {} + /** * Begins the Tree Feller ability * @@ -75,7 +77,7 @@ public abstract class Woodcutting { } checkDoubleDrop(player, block); - Skills.xpProcessing(player, Users.getProfile(player), SkillType.WOODCUTTING, xp); + SkillTools.xpProcessing(player, Users.getProfile(player), SkillType.WOODCUTTING, xp); } /** diff --git a/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java b/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java index 67ac9e2ac..a5dfbe957 100644 --- a/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java +++ b/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java @@ -23,7 +23,7 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Users; @@ -549,7 +549,7 @@ public class SpoutStuff { break; } - spoutPlayer.sendNotification(LocaleLoader.getString("Spout.LevelUp.1"), LocaleLoader.getString("Spout.LevelUp.2", new Object[] {Skills.localizeSkillName(skillType), profile.getSkillLevel(skillType)} ), mat); + spoutPlayer.sendNotification(LocaleLoader.getString("Spout.LevelUp.1"), LocaleLoader.getString("Spout.LevelUp.2", new Object[] {SkillTools.localizeSkillName(skillType), profile.getSkillLevel(skillType)} ), mat); SpoutSounds.playLevelUpNoise(spoutPlayer, plugin); } diff --git a/src/main/java/com/gmail/nossr50/spout/commands/XplockCommand.java b/src/main/java/com/gmail/nossr50/spout/commands/XplockCommand.java index 421500ecb..0e8b1287c 100644 --- a/src/main/java/com/gmail/nossr50/spout/commands/XplockCommand.java +++ b/src/main/java/com/gmail/nossr50/spout/commands/XplockCommand.java @@ -11,7 +11,7 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; import com.gmail.nossr50.spout.SpoutConfig; import com.gmail.nossr50.spout.huds.SpoutHud; import com.gmail.nossr50.util.Misc; @@ -63,10 +63,10 @@ public class XplockCommand implements CommandExecutor { return true; case 1: - if (Skills.isSkill(args[0])) { + if (SkillTools.isSkill(args[0])) { if (Permissions.hasPermission(player, "mcmmo.skills." + args[0].toLowerCase())) { spoutHud.setXpBarLocked(true); - spoutHud.setSkillLock(Skills.getSkillType(args[0])); + spoutHud.setSkillLock(SkillTools.getSkillType(args[0])); spoutHud.updateXpBar(); player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(args[0]) })); diff --git a/src/main/java/com/gmail/nossr50/spout/huds/SpoutHud.java b/src/main/java/com/gmail/nossr50/spout/huds/SpoutHud.java index 41c98a200..395dea1c6 100644 --- a/src/main/java/com/gmail/nossr50/spout/huds/SpoutHud.java +++ b/src/main/java/com/gmail/nossr50/spout/huds/SpoutHud.java @@ -14,11 +14,9 @@ import com.gmail.nossr50.spout.popups.XpBar; public class SpoutHud { private Player player; private PlayerProfile profile; - private SkillType lastGained; private SkillType skillLock; private boolean xpBarLocked; - private Menu menu; private XpBar xpBar; diff --git a/src/main/java/com/gmail/nossr50/spout/popups/XpBar.java b/src/main/java/com/gmail/nossr50/spout/popups/XpBar.java index 926685553..b986a9b7a 100644 --- a/src/main/java/com/gmail/nossr50/spout/popups/XpBar.java +++ b/src/main/java/com/gmail/nossr50/spout/popups/XpBar.java @@ -17,7 +17,6 @@ import com.gmail.nossr50.util.Misc; public class XpBar { private SpoutPlayer spoutPlayer; - private Widget xpBar; private GenericGradient xpFill; private GenericGradient xpBackground; diff --git a/src/main/java/com/gmail/nossr50/util/Anniversary.java b/src/main/java/com/gmail/nossr50/util/Anniversary.java index 0bf019366..ea05b4ece 100644 --- a/src/main/java/com/gmail/nossr50/util/Anniversary.java +++ b/src/main/java/com/gmail/nossr50/util/Anniversary.java @@ -11,7 +11,6 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; -import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -26,14 +25,13 @@ import org.bukkit.inventory.meta.FireworkMeta; import com.gmail.nossr50.mcMMO; -public class Anniversary { - - private Random random = new Random(); - +public final class Anniversary { public static ArrayList hasCelebrated; + private Anniversary() {} + //This gets called onEnable - public void createAnniversaryFile() { + public static void createAnniversaryFile() { File anniversaryFile = new File(mcMMO.p.getDataFolder().getAbsolutePath() + File.separator + "anniversary"); if (!anniversaryFile.exists()) { @@ -62,7 +60,7 @@ public class Anniversary { } //This gets called onDisable - public void saveAnniversaryFiles() { + public static void saveAnniversaryFiles() { try { BufferedWriter writer = new BufferedWriter(new FileWriter(mcMMO.p.getDataFolder().getAbsolutePath() + File.separator + "anniversary")); for (String player : hasCelebrated) { @@ -77,7 +75,7 @@ public class Anniversary { } //This gets called from /mcmmo command - public void anniversaryCheck(final CommandSender sender) { + public static void anniversaryCheck(final CommandSender sender) { if (sender instanceof Player) { GregorianCalendar anniversaryStart = new GregorianCalendar(2013, Calendar.FEBRUARY, 3); GregorianCalendar anniversaryEnd = new GregorianCalendar(2013, Calendar.FEBRUARY, 6); @@ -105,11 +103,11 @@ public class Anniversary { } } - private boolean getDateRange(Date date, Date start, Date end) { + private static boolean getDateRange(Date date, Date start, Date end) { return !(date.before(start) || date.after(end)); } - private void spawnFireworks(Player player) { + private static void spawnFireworks(Player player) { int power = (int) (Math.random() * 3) + 1; int type = (int) (Math.random() * 5) + 1; @@ -122,16 +120,16 @@ public class Anniversary { Firework fireworks = (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK); FireworkMeta fireworkmeta = fireworks.getFireworkMeta(); - FireworkEffect effect = FireworkEffect.builder().flicker(random.nextBoolean()).withColor(colorchoose()).withFade(colorchoose()).with(typen).trail(random.nextBoolean()).build(); + FireworkEffect effect = FireworkEffect.builder().flicker(Misc.getRandom().nextBoolean()).withColor(colorchoose()).withFade(colorchoose()).with(typen).trail(Misc.getRandom().nextBoolean()).build(); fireworkmeta.addEffect(effect); fireworkmeta.setPower(power); fireworks.setFireworkMeta(fireworkmeta); } - private List colorchoose() { + private static List colorchoose() { // Thanks Zomis and Tejpbit for the help with this function! - int numberofcolors = random.nextInt(17) + 1; + int numberofcolors = Misc.getRandom().nextInt(17) + 1; List allcolors = new ArrayList(); allcolors.add(Color.AQUA); @@ -155,7 +153,7 @@ public class Anniversary { List choosencolors = new ArrayList(); for (int i = 0; i < numberofcolors; i++) { - choosencolors.add(allcolors.remove(random.nextInt(allcolors.size()))); + choosencolors.add(allcolors.remove(Misc.getRandom().nextInt(allcolors.size()))); } return choosencolors; } diff --git a/src/main/java/com/gmail/nossr50/util/BlockChecks.java b/src/main/java/com/gmail/nossr50/util/BlockChecks.java index 281ed0705..83f27458f 100644 --- a/src/main/java/com/gmail/nossr50/util/BlockChecks.java +++ b/src/main/java/com/gmail/nossr50/util/BlockChecks.java @@ -9,9 +9,10 @@ import org.bukkit.material.MaterialData; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.mods.CustomBlocksConfig; -public class BlockChecks { +public final class BlockChecks { private static Config configInstance = Config.getInstance(); - private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled(); + + private BlockChecks() {} /** * Checks to see if a block type awards XP. @@ -62,7 +63,7 @@ public class BlockChecks { default: ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); - if (customBlocksEnabled && CustomBlocksConfig.getInstance().customItems.contains(item)) { + if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customItems.contains(item)) { return true; } @@ -79,7 +80,7 @@ public class BlockChecks { public static boolean canActivateAbilities(Block block) { ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); - if (customBlocksEnabled && CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) { + if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) { return false; } @@ -137,7 +138,7 @@ public class BlockChecks { return true; default: - if (customBlocksEnabled && ModChecks.isCustomOreBlock(block)) { + if (configInstance.getBlockModsEnabled() && ModChecks.isCustomOreBlock(block)) { return true; } @@ -201,7 +202,7 @@ public class BlockChecks { default: ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); - if (customBlocksEnabled && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) { + if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) { return true; } @@ -237,7 +238,7 @@ public class BlockChecks { default: ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); - if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) { + if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) { return true; } @@ -265,7 +266,7 @@ public class BlockChecks { default: ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); - if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) { + if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) { return true; } @@ -288,7 +289,7 @@ public class BlockChecks { default: ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); - if (customBlocksEnabled && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) { + if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) { return true; } @@ -297,7 +298,7 @@ public class BlockChecks { } public static boolean isLog(Block block) { - if (block.getType().equals(Material.LOG) || (customBlocksEnabled && ModChecks.isCustomLogBlock(block))) { + if (block.getType().equals(Material.LOG) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block))) { return true; } diff --git a/src/main/java/com/gmail/nossr50/util/ChatManager.java b/src/main/java/com/gmail/nossr50/util/ChatManager.java index 322518287..415d0f2e8 100644 --- a/src/main/java/com/gmail/nossr50/util/ChatManager.java +++ b/src/main/java/com/gmail/nossr50/util/ChatManager.java @@ -8,20 +8,12 @@ import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.Party; -public class ChatManager { - private mcMMO plugin; - private String playerName; - private String message; +public final class ChatManager { + public ChatManager () {} - public ChatManager (mcMMO plugin, String playerName, String message) { - this.plugin = plugin; - this.playerName = playerName; - this.message = message; - } - - public void handleAdminChat() { + public static void handleAdminChat(String playerName, String message) { McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(playerName, message); - plugin.getServer().getPluginManager().callEvent(chatEvent); + mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); if (chatEvent.isCancelled()) { return; @@ -29,20 +21,20 @@ public class ChatManager { String adminMessage = chatEvent.getMessage(); - plugin.getLogger().info("[A]<" + playerName + "> " + adminMessage); + mcMMO.p.getLogger().info("[A]<" + playerName + "> " + adminMessage); - for (Player otherPlayer : plugin.getServer().getOnlinePlayers()) { + for (Player otherPlayer : mcMMO.p.getServer().getOnlinePlayers()) { if (Permissions.adminChat(otherPlayer) || otherPlayer.isOp()) { otherPlayer.sendMessage(LocaleLoader.getString("Commands.AdminChat.Prefix", new Object[] {playerName}) + adminMessage); } } } - public void handlePartyChat(Party party) { + public static void handlePartyChat(Party party, String playerName, String message) { String partyName = party.getName(); McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(playerName, partyName, message); - plugin.getServer().getPluginManager().callEvent(chatEvent); + mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); if (chatEvent.isCancelled()) { return; @@ -50,7 +42,7 @@ public class ChatManager { String partyMessage = chatEvent.getMessage(); - plugin.getLogger().info("[P](" + partyName + ")" + "<" + playerName + "> " + partyMessage); + mcMMO.p.getLogger().info("[P](" + partyName + ")" + "<" + playerName + "> " + partyMessage); for (Player member : party.getOnlineMembers()) { member.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Prefix", new Object[] {playerName}) + partyMessage); diff --git a/src/main/java/com/gmail/nossr50/util/Item.java b/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java similarity index 72% rename from src/main/java/com/gmail/nossr50/util/Item.java rename to src/main/java/com/gmail/nossr50/util/ChimaeraWing.java index 43c430fdc..c377467e4 100644 --- a/src/main/java/com/gmail/nossr50/util/Item.java +++ b/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java @@ -8,32 +8,30 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.SkillTools; -public class Item { +public final class ChimaeraWing { + private ChimaeraWing() {} /** * Check for item usage. * * @param player Player whose item usage to check */ - public static void itemChecks(Player player) { + public static void activationCheck(Player player) { ItemStack inHand = player.getItemInHand(); - if (Config.getInstance().getChimaeraEnabled() && inHand.getTypeId() == Config.getInstance().getChimaeraItemId()) { - chimaeraWing(player); + if (!Config.getInstance().getChimaeraEnabled() || inHand.getTypeId() != Config.getInstance().getChimaeraItemId()) { + return; } - } - private static void chimaeraWing(Player player) { PlayerProfile profile = Users.getProfile(player); - ItemStack inHand = player.getItemInHand(); Block block = player.getLocation().getBlock(); int amount = inHand.getAmount(); long recentlyHurt = profile.getRecentlyHurt(); if (Permissions.chimaeraWing(player) && inHand.getTypeId() == Config.getInstance().getChimaeraItemId()) { - if (Skills.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) { + if (SkillTools.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) { player.setItemInHand(new ItemStack(Config.getInstance().getChimaeraItemId(), amount - Config.getInstance().getChimaeraCost())); for (int y = 1; block.getY() + y < player.getWorld().getMaxHeight(); y++) { @@ -53,11 +51,11 @@ public class Item { player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass")); } - else if (!Skills.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) { - player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", new Object[] {Skills.calculateTimeLeft(recentlyHurt, 60, player)})); + else if (!SkillTools.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) { + player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", new Object[] {SkillTools.calculateTimeLeft(recentlyHurt, 60, player)})); } else if (amount <= Config.getInstance().getChimaeraCost()) { - player.sendMessage(LocaleLoader.getString("Skills.NeedMore", new Object[] { Misc.prettyItemString(Config.getInstance().getChimaeraItemId()) })); + player.sendMessage(LocaleLoader.getString("SkillTools.NeedMore", new Object[] { Misc.prettyItemString(Config.getInstance().getChimaeraItemId()) })); } } } diff --git a/src/main/java/com/gmail/nossr50/util/Hardcore.java b/src/main/java/com/gmail/nossr50/util/Hardcore.java index 3f43479cf..0d114d7d5 100644 --- a/src/main/java/com/gmail/nossr50/util/Hardcore.java +++ b/src/main/java/com/gmail/nossr50/util/Hardcore.java @@ -7,13 +7,14 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -public abstract class Hardcore { +public final class Hardcore { public static double statLossPercentage = Config.getInstance().getHardcoreDeathStatPenaltyPercentage(); public static double vampirismStatLeechPercentage = Config.getInstance().getHardcoreVampirismStatLeechPercentage(); - public static boolean statLossEnabled = Config.getInstance().getHardcoreEnabled(); public static boolean vampirismEnabled = Config.getInstance().getHardcoreVampirismEnabled(); + private Hardcore() {} + public static void invokeStatPenalty(Player player) { if (statLossPercentage <= 0 || statLossPercentage > 100) { return; diff --git a/src/main/java/com/gmail/nossr50/util/Leaderboard.java b/src/main/java/com/gmail/nossr50/util/Leaderboard.java index dfffb1268..d4bc5afea 100644 --- a/src/main/java/com/gmail/nossr50/util/Leaderboard.java +++ b/src/main/java/com/gmail/nossr50/util/Leaderboard.java @@ -12,12 +12,12 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.PlayerStat; import com.gmail.nossr50.skills.SkillType; -public class Leaderboard { - private static mcMMO plugin = mcMMO.p; - private final static String location = mcMMO.getUsersFile(); +public final class Leaderboard { private static HashMap> playerStatHash = new HashMap>(); private static long lastUpdate = 0; + private Leaderboard() {} + /** * Update the leader boards. */ @@ -47,7 +47,7 @@ public class Leaderboard { //Read from the FlatFile database and fill our arrays with information try { - FileReader file = new FileReader(location); + FileReader file = new FileReader(mcMMO.getUsersFilePath()); BufferedReader in = new BufferedReader(file); String line = ""; ArrayList players = new ArrayList(); @@ -130,7 +130,7 @@ public class Leaderboard { in.close(); } catch (Exception e) { - plugin.getLogger().severe(("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString())); + mcMMO.p.getLogger().severe(("Exception while reading " + mcMMO.getUsersFilePath() + " (Are you sure you formatted it correctly?)" + e.toString())); } SkillComparator c = new SkillComparator(); diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index efd1d2b09..36ef1d3b0 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -25,19 +25,19 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; import com.gmail.nossr50.party.PartyManager; -public class Misc { +public final class Misc { private static Random random = new Random(); - public static int toolDurabilityLoss = Config.getInstance().getAbilityToolDamage(); public static int abilityLengthIncreaseLevel = AdvancedConfig.getInstance().getAbilityLength(); public static boolean isSpawnerXPEnabled = Config.getInstance().getExperienceGainsMobspawnersEnabled(); - public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5; public static final int TIME_CONVERSION_FACTOR = 1000; public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0; public static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100; public static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75; + private Misc() {}; + /** * Calculate activation chance for a skill. * @@ -75,7 +75,7 @@ public class Misc { if (tamer instanceof Player) { Player owner = (Player) tamer; - if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) { + if (owner == attacker || PartyManager.inSameParty(attacker, owner)) { return true; } } diff --git a/src/main/java/com/gmail/nossr50/util/ModChecks.java b/src/main/java/com/gmail/nossr50/util/ModChecks.java index 955a57db2..2373853eb 100644 --- a/src/main/java/com/gmail/nossr50/util/ModChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ModChecks.java @@ -12,16 +12,17 @@ import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.datatypes.mods.CustomItem; import com.gmail.nossr50.datatypes.mods.CustomTool; -public class ModChecks { +public final class ModChecks { private static Config configInstance = Config.getInstance(); private static boolean customToolsEnabled = configInstance.getToolModsEnabled(); private static boolean customArmorEnabled = configInstance.getArmorModsEnabled(); private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled(); - private static CustomToolsConfig toolInstance = CustomToolsConfig.getInstance(); private static CustomArmorConfig armorInstance = CustomArmorConfig.getInstance(); private static CustomBlocksConfig blocksInstance = CustomBlocksConfig.getInstance(); + private ModChecks() {} + /** * Get the custom armor associated with an item. * diff --git a/src/main/java/com/gmail/nossr50/util/MOTD.java b/src/main/java/com/gmail/nossr50/util/Motd.java similarity index 75% rename from src/main/java/com/gmail/nossr50/util/MOTD.java rename to src/main/java/com/gmail/nossr50/util/Motd.java index bd3bacbbf..9e23d91b2 100644 --- a/src/main/java/com/gmail/nossr50/util/MOTD.java +++ b/src/main/java/com/gmail/nossr50/util/Motd.java @@ -1,30 +1,42 @@ package com.gmail.nossr50.util; import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginDescriptionFile; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; -public class MOTD { - private Player player; - private String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); +public final class Motd { + private static final String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); + private static final PluginDescriptionFile pluginDescription = mcMMO.p.getDescription(); - public MOTD(Player player) { - this.player = player; + private Motd() {} + + public static void displayAll(Player player) { + displayVersion(player, pluginDescription.getVersion()); + displayHardcoreSettings(player); + displayXpPerks(player); + displayCooldownPerks(player); + displayActivationPerks(player); + displayLuckyPerks(player); + displayWebsite(player, pluginDescription.getWebsite()); } /** * Display version info. - * @param version The plugin version + * @param player Target player + * @param version Plugin version */ - public void displayVersion(String version) { + public static void displayVersion(Player player, String version) { player.sendMessage(LocaleLoader.getString("MOTD.Version", new Object[] {version})); } /** * Display Hardcore Mode settings. + * @param player Target player */ - public void displayHardcoreSettings() { + public static void displayHardcoreSettings(Player player) { if (Hardcore.statLossEnabled) { if (Hardcore.vampirismEnabled) { player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn")); @@ -40,8 +52,9 @@ public class MOTD { /** * Display XP perks. + * @param player Target player */ - public void displayXpPerks() { + public static void displayXpPerks(Player player) { if (Permissions.xpQuadruple(player)) { player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 4 }) })); } @@ -61,8 +74,9 @@ public class MOTD { /** * Display cooldown perks. + * @param player Target player */ - public void displayCooldownPerks() { + public static void displayCooldownPerks(Player player) { if (Permissions.cooldownsHalved(player)) { player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", new Object[] { "1/2" }) })); } @@ -76,8 +90,9 @@ public class MOTD { /** * Display activiation perks. + * @param player Target player */ - public void displayActivationPerks() { + public static void displayActivationPerks(Player player) { if (Permissions.activationTwelve(player)) { player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", new Object[] { 12 }) })); } @@ -91,8 +106,9 @@ public class MOTD { /** * Display "lucky" perks. + * @param player Target player */ - public void displayLuckyPerks() { + public static void displayLuckyPerks(Player player) { for (SkillType skill : SkillType.values()) { if (Permissions.lucky(player, skill)) { player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc.login") })); @@ -103,9 +119,10 @@ public class MOTD { /** * Display website info. - * @param website The plugin website + * @param player Target player + * @param website Plugin website */ - public void displayWebsite(String website) { + public static void displayWebsite(Player player, String website) { player.sendMessage(LocaleLoader.getString("MOTD.Website", new Object[] {website})); } } diff --git a/src/main/java/com/gmail/nossr50/util/Permissions.java b/src/main/java/com/gmail/nossr50/util/Permissions.java index 5ec2ed565..05bec60f1 100644 --- a/src/main/java/com/gmail/nossr50/util/Permissions.java +++ b/src/main/java/com/gmail/nossr50/util/Permissions.java @@ -5,21 +5,11 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.skills.SkillType; -public class Permissions { - public static boolean hasPermission(CommandSender sender, String perm) - { - if (sender.hasPermission(perm)) - return true; +public final class Permissions { + private Permissions() {} - return false; - } - - public static boolean hasPermission(Player sender, String perm) - { - if (sender.hasPermission(perm)) - return true; - - return false; + public static boolean hasPermission(CommandSender sender, String perm) { + return (sender.hasPermission(perm)); } /* diff --git a/src/main/java/com/gmail/nossr50/util/Users.java b/src/main/java/com/gmail/nossr50/util/Users.java index c4df4bdf5..2bd1f997b 100644 --- a/src/main/java/com/gmail/nossr50/util/Users.java +++ b/src/main/java/com/gmail/nossr50/util/Users.java @@ -12,9 +12,11 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.PlayerProfile; -public class Users { +public final class Users { private static Map players = new HashMap(); + private Users() {}; + /** * Load users. */ @@ -22,7 +24,7 @@ public class Users { new File(mcMMO.getFlatFileDirectory()).mkdir(); try { - new File(mcMMO.getUsersFile()).createNewFile(); + new File(mcMMO.getUsersFilePath()).createNewFile(); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/net/shatteredlands/shatt/backup/ZipLibrary.java b/src/main/java/net/shatteredlands/shatt/backup/ZipLibrary.java index ea967f2e7..c069a8f1e 100644 --- a/src/main/java/net/shatteredlands/shatt/backup/ZipLibrary.java +++ b/src/main/java/net/shatteredlands/shatt/backup/ZipLibrary.java @@ -20,7 +20,7 @@ public class ZipLibrary { private static File BackupDir = new File(BackupDirectory); private static File FlatFileDirectory = new File(mcMMO.getFlatFileDirectory()); private static File ModFileDirectory = new File(mcMMO.getModDirectory()); - private static File UsersFile = new File(mcMMO.getUsersFile()); + private static File UsersFile = new File(mcMMO.getUsersFilePath()); private static File ConfigFile = new File(mcMMO.getMainDirectory() + "config.yml"); private static File TreasuresFile = new File(mcMMO.getMainDirectory() + "treasures.yml");