From c0b7f8a32370d1ac9f3bd7d7fec54fcd3f24aaab Mon Sep 17 00:00:00 2001 From: bm01 Date: Sun, 3 Mar 2013 17:06:05 +0100 Subject: [PATCH] Moved everything that could be moved from PlayerProfile to McMMOPlayer PlayerProfile now only store stored (flatfile or MySQL) data --- .../com/gmail/nossr50/api/AbilityAPI.java | 20 +- .../nossr50/commands/McabilityCommand.java | 19 +- .../gmail/nossr50/commands/McgodCommand.java | 21 +- .../nossr50/commands/McnotifyCommand.java | 8 +- .../nossr50/commands/McrefreshCommand.java | 28 +- .../nossr50/commands/party/PtpCommand.java | 14 +- .../nossr50/datatypes/player/McMMOPlayer.java | 235 +++++++++- .../datatypes/player/PlayerProfile.java | 406 +----------------- .../nossr50/listeners/BlockListener.java | 43 +- .../nossr50/listeners/EntityListener.java | 6 +- .../nossr50/listeners/PlayerListener.java | 14 +- .../runnables/skills/SkillMonitorTask.java | 8 +- .../skills/acrobatics/AcrobaticsManager.java | 7 +- .../skills/archery/ArcheryManager.java | 4 +- .../nossr50/skills/axes/AxesManager.java | 8 +- .../skills/herbalism/HerbalismManager.java | 12 +- .../nossr50/skills/mining/MiningManager.java | 5 +- .../gmail/nossr50/skills/repair/Repair.java | 6 +- .../gmail/nossr50/skills/repair/Salvage.java | 8 +- .../nossr50/skills/swords/SwordsManager.java | 4 +- .../nossr50/skills/taming/TamingManager.java | 6 +- .../com/gmail/nossr50/util/ChimaeraWing.java | 4 +- .../nossr50/util/skills/CombatUtils.java | 22 +- .../gmail/nossr50/util/skills/SkillUtils.java | 100 +++-- 24 files changed, 405 insertions(+), 603 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java index 515bf14f3..52743f42e 100644 --- a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java +++ b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java @@ -2,7 +2,7 @@ package com.gmail.nossr50.api; import org.bukkit.entity.Player; -import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.util.player.UserManager; @@ -10,38 +10,38 @@ public final class AbilityAPI { private AbilityAPI() {} public static boolean berserkEnabled(Player player) { - return UserManager.getPlayer(player).getProfile().getAbilityMode(AbilityType.BERSERK); + return UserManager.getPlayer(player).getAbilityMode(AbilityType.BERSERK); } public static boolean gigaDrillBreakerEnabled(Player player) { - return UserManager.getPlayer(player).getProfile().getAbilityMode(AbilityType.GIGA_DRILL_BREAKER); + return UserManager.getPlayer(player).getAbilityMode(AbilityType.GIGA_DRILL_BREAKER); } public static boolean greenTerraEnabled(Player player) { - return UserManager.getPlayer(player).getProfile().getAbilityMode(AbilityType.GREEN_TERRA); + return UserManager.getPlayer(player).getAbilityMode(AbilityType.GREEN_TERRA); } public static boolean serratedStrikesEnabled(Player player) { - return UserManager.getPlayer(player).getProfile().getAbilityMode(AbilityType.SERRATED_STRIKES); + return UserManager.getPlayer(player).getAbilityMode(AbilityType.SERRATED_STRIKES); } public static boolean skullSplitterEnabled(Player player) { - return UserManager.getPlayer(player).getProfile().getAbilityMode(AbilityType.SKULL_SPLITTER); + return UserManager.getPlayer(player).getAbilityMode(AbilityType.SKULL_SPLITTER); } public static boolean superBreakerEnabled(Player player) { - return UserManager.getPlayer(player).getProfile().getAbilityMode(AbilityType.SUPER_BREAKER); + return UserManager.getPlayer(player).getAbilityMode(AbilityType.SUPER_BREAKER); } public static boolean treeFellerEnabled(Player player) { - return UserManager.getPlayer(player).getProfile().getAbilityMode(AbilityType.TREE_FELLER); + return UserManager.getPlayer(player).getAbilityMode(AbilityType.TREE_FELLER); } public static boolean isAnyAbilityEnabled(Player player) { - PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); for (AbilityType ability : AbilityType.values()) { - if (profile.getAbilityMode(ability)) { + if (mcMMOPlayer.getAbilityMode(ability)) { return true; } } diff --git a/src/main/java/com/gmail/nossr50/commands/McabilityCommand.java b/src/main/java/com/gmail/nossr50/commands/McabilityCommand.java index 69016d96a..aeaf06e9a 100644 --- a/src/main/java/com/gmail/nossr50/commands/McabilityCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McabilityCommand.java @@ -14,7 +14,7 @@ import com.gmail.nossr50.util.player.UserManager; public class McabilityCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - PlayerProfile profile; + McMMOPlayer mcMMOPlayer; switch (args.length) { case 0: @@ -23,16 +23,16 @@ public class McabilityCommand implements CommandExecutor { return true; } - profile = UserManager.getPlayer((Player) sender).getProfile(); + mcMMOPlayer = UserManager.getPlayer((Player) sender); - if (profile.getAbilityUse()) { + if (mcMMOPlayer.getAbilityUse()) { sender.sendMessage(LocaleLoader.getString("Commands.Ability.Off")); } else { sender.sendMessage(LocaleLoader.getString("Commands.Ability.On")); } - profile.toggleAbilityUse(); + mcMMOPlayer.toggleAbilityUse(); return true; case 1: @@ -41,12 +41,12 @@ public class McabilityCommand implements CommandExecutor { return true; } - McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]); + mcMMOPlayer = UserManager.getPlayer(args[0]); if (mcMMOPlayer == null) { - profile = new PlayerProfile(args[0], false); + PlayerProfile playerProfile = new PlayerProfile(args[0], false); - if (!profile.isLoaded()) { + if (!playerProfile.isLoaded()) { sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); return true; } @@ -56,21 +56,20 @@ public class McabilityCommand implements CommandExecutor { } Player player = mcMMOPlayer.getPlayer(); - profile = mcMMOPlayer.getProfile(); if (!player.isOnline()) { sender.sendMessage(LocaleLoader.getString("Commands.Offline")); return true; } - if (profile.getAbilityUse()) { + if (mcMMOPlayer.getAbilityUse()) { player.sendMessage(LocaleLoader.getString("Commands.Ability.Off")); } else { player.sendMessage(LocaleLoader.getString("Commands.Ability.On")); } - profile.toggleAbilityUse(); + mcMMOPlayer.toggleAbilityUse(); return true; default: diff --git a/src/main/java/com/gmail/nossr50/commands/McgodCommand.java b/src/main/java/com/gmail/nossr50/commands/McgodCommand.java index 10ea58a24..b89b15b70 100644 --- a/src/main/java/com/gmail/nossr50/commands/McgodCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McgodCommand.java @@ -14,7 +14,7 @@ import com.gmail.nossr50.util.player.UserManager; public class McgodCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - PlayerProfile profile; + McMMOPlayer mcMMOPlayer; switch (args.length) { case 0: @@ -27,21 +27,21 @@ public class McgodCommand implements CommandExecutor { return false; } - profile = UserManager.getPlayer((Player) sender).getProfile(); + mcMMOPlayer = UserManager.getPlayer((Player) sender); - if (profile == null) { + if (mcMMOPlayer == null) { sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); return true; } - if (profile.getGodMode()) { + if (mcMMOPlayer.getGodMode()) { sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled")); } else { sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled")); } - profile.toggleGodMode(); + mcMMOPlayer.toggleGodMode(); return true; case 1: @@ -50,12 +50,12 @@ public class McgodCommand implements CommandExecutor { return true; } - McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]); + mcMMOPlayer = UserManager.getPlayer(args[0]); if (mcMMOPlayer == null) { - profile = new PlayerProfile(args[0], false); + PlayerProfile playerProfile = new PlayerProfile(args[0], false); - if (!profile.isLoaded()) { + if (!playerProfile.isLoaded()) { sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); return true; } @@ -64,7 +64,6 @@ public class McgodCommand implements CommandExecutor { return true; } - profile = mcMMOPlayer.getProfile(); Player player = mcMMOPlayer.getPlayer(); if (!player.isOnline()) { @@ -72,14 +71,14 @@ public class McgodCommand implements CommandExecutor { return true; } - if (profile.getGodMode()) { + if (mcMMOPlayer.getGodMode()) { player.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled")); } else { player.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled")); } - profile.toggleGodMode(); + mcMMOPlayer.toggleGodMode(); return true; default: diff --git a/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java b/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java index da3a42dcd..11a664cb4 100644 --- a/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java @@ -5,7 +5,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.player.UserManager; @@ -14,16 +14,16 @@ public class McnotifyCommand implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { switch (args.length) { case 0: - PlayerProfile profile = UserManager.getPlayer((Player) sender).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender); - if (profile.useChatNotifications()) { + if (mcMMOPlayer.useChatNotifications()) { sender.sendMessage(LocaleLoader.getString("Commands.Notifications.Off")); } else { sender.sendMessage(LocaleLoader.getString("Commands.Notifications.On")); } - profile.toggleChatNotifications(); + mcMMOPlayer.toggleChatNotifications(); return true; default: diff --git a/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java b/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java index 2ca351d4e..b6bf8b8b2 100644 --- a/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java @@ -14,7 +14,7 @@ import com.gmail.nossr50.util.player.UserManager; public class McrefreshCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - PlayerProfile profile; + McMMOPlayer mcMMOPlayer; switch (args.length) { case 0: @@ -27,12 +27,12 @@ public class McrefreshCommand implements CommandExecutor { return false; } - profile = UserManager.getPlayer(sender.getName()).getProfile(); + mcMMOPlayer = UserManager.getPlayer(sender.getName()); - profile.setRecentlyHurt(0); - profile.resetCooldowns(); - profile.resetToolPrepMode(); - profile.resetAbilityMode(); + mcMMOPlayer.setRecentlyHurt(0); + mcMMOPlayer.getProfile().resetCooldowns(); + mcMMOPlayer.resetToolPrepMode(); + mcMMOPlayer.resetAbilityMode(); sender.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh")); return true; @@ -43,12 +43,12 @@ public class McrefreshCommand implements CommandExecutor { return true; } - McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]); + mcMMOPlayer = UserManager.getPlayer(args[0]); if (mcMMOPlayer == null) { - profile = new PlayerProfile(args[0], false); + PlayerProfile playerProfile = new PlayerProfile(args[0], false); - if (!profile.isLoaded()) { + if (!playerProfile.isLoaded()) { sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); return true; } @@ -56,7 +56,7 @@ public class McrefreshCommand implements CommandExecutor { sender.sendMessage(LocaleLoader.getString("Commands.Offline")); return true; } - profile = mcMMOPlayer.getProfile(); + Player player = mcMMOPlayer.getPlayer(); if (!player.isOnline()) { @@ -64,10 +64,10 @@ public class McrefreshCommand implements CommandExecutor { return true; } - profile.setRecentlyHurt(0); - profile.resetCooldowns(); - profile.resetToolPrepMode(); - profile.resetAbilityMode(); + mcMMOPlayer.setRecentlyHurt(0); + mcMMOPlayer.getProfile().resetCooldowns(); + mcMMOPlayer.resetToolPrepMode(); + mcMMOPlayer.resetAbilityMode(); player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh")); sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", args[0])); diff --git a/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java index eb87959a3..4d446d39f 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.PartyManager; @@ -21,7 +20,6 @@ import com.gmail.nossr50.util.player.UserManager; public class PtpCommand implements CommandExecutor { private Player player; private McMMOPlayer mcMMOPlayer; - private PlayerProfile playerProfile; private Player target; private McMMOPlayer mcMMOTarget; @@ -34,10 +32,6 @@ public class PtpCommand implements CommandExecutor { switch (args.length) { case 1: - player = (Player) sender; - mcMMOPlayer = UserManager.getPlayer(player); - playerProfile = mcMMOPlayer.getProfile(); - if (args[0].equalsIgnoreCase("toggle")) { if (!Permissions.partyTeleportToggle(sender)) { sender.sendMessage(command.getPermissionMessage()); @@ -56,8 +50,9 @@ public class PtpCommand implements CommandExecutor { return acceptAnyTeleportRequest(); } + player = (Player) sender; int ptpCooldown = Config.getInstance().getPTPCommandCooldown(); - long recentlyHurt = playerProfile.getRecentlyHurt() * Misc.TIME_CONVERSION_FACTOR; + long recentlyHurt = UserManager.getPlayer(player).getRecentlyHurt() * Misc.TIME_CONVERSION_FACTOR; if (System.currentTimeMillis() - recentlyHurt >= (ptpCooldown * Misc.TIME_CONVERSION_FACTOR)) { player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", ptpCooldown)); @@ -94,6 +89,7 @@ public class PtpCommand implements CommandExecutor { player.sendMessage(LocaleLoader.getString("Commands.Invite.Success")); int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout(); + target.sendMessage(LocaleLoader.getString("Commands.ptp.Request1", player.getName())); target.sendMessage(LocaleLoader.getString("Commands.ptp.Request2", ptpRequestExpire)); return true; @@ -203,8 +199,8 @@ public class PtpCommand implements CommandExecutor { private boolean handlePartyTeleportEvent(Player player, Player target) { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); - McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, mcMMOPlayer.getParty().getName()); + mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -214,7 +210,7 @@ public class PtpCommand implements CommandExecutor { player.teleport(target); player.sendMessage(LocaleLoader.getString("Party.Teleport.Player", target.getName())); target.sendMessage(LocaleLoader.getString("Party.Teleport.Target", player.getName())); - mcMMOPlayer.getProfile().actualizeRecentlyHurt(); + mcMMOPlayer.actualizeRecentlyHurt(); return true; } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 6d436fc52..f1d4d4c90 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -12,7 +12,9 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.mods.CustomTool; import com.gmail.nossr50.datatypes.party.Party; +import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.spout.huds.McMMOHud; import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent; import com.gmail.nossr50.party.PartyManager; @@ -49,8 +51,9 @@ public class McMMOPlayer { */ private Map skillManagers = new HashMap(); - private Party party; - private Party invite; + private Party party; + private Party invite; + private int itemShareModifier; private Player ptpRequest; private boolean ptpEnabled = true; @@ -59,8 +62,20 @@ public class McMMOPlayer { private boolean partyChatMode; private boolean adminChatMode; + private boolean displaySkillNotifications = true; - private int itemShareModifier; + private boolean abilityUse = true; + private boolean placedAnvil; + private boolean placedSalvageAnvil; + private boolean godMode; + + private Map abilityMode = new HashMap(); + private Map abilityInformed = new HashMap(); + private Map toolPreparationMode = new HashMap(); + private Map toolATS = new HashMap(); + + private int recentlyHurt; + private int respawnATS; public McMMOPlayer(Player player) { String playerName = player.getName(); @@ -88,6 +103,16 @@ public class McMMOPlayer { e.printStackTrace(); mcMMO.p.getPluginLoader().disablePlugin(mcMMO.p); } + + for (AbilityType abilityType : AbilityType.values()) { + abilityMode.put(abilityType, false); + abilityInformed.put(abilityType, true); // This is intended + } + + for (ToolType toolType : ToolType.values()) { + toolPreparationMode.put(toolType, false); + toolATS.put(toolType, 0); + } } public AcrobaticsManager getAcrobaticsManager() { @@ -134,6 +159,198 @@ public class McMMOPlayer { return (UnarmedManager) skillManagers.get(SkillType.UNARMED); } + /* + * Abilities + */ + + /** + * Reset the mode of all abilities. + */ + public void resetAbilityMode() { + for (AbilityType ability : AbilityType.values()) { + setAbilityMode(ability, false); + } + } + + /** + * Get the mode of an ability. + * + * @param ability The ability to check + * @return true if the ability is enabled, false otherwise + */ + public boolean getAbilityMode(AbilityType ability) { + return abilityMode.get(ability); + } + + /** + * Set the mode of an ability. + * + * @param ability The ability to check + * @param bool True if the ability is active, false otherwise + */ + public void setAbilityMode(AbilityType ability, boolean bool) { + abilityMode.put(ability, bool); + } + + /** + * Get the informed state of an ability + * + * @param ability The ability to check + * @return true if the ability is informed, false otherwise + */ + public boolean getAbilityInformed(AbilityType ability) { + return abilityInformed.get(ability); + } + + /** + * Set the informed state of an ability. + * + * @param ability The ability to check + * @param bool True if the ability is informed, false otherwise + */ + public void setAbilityInformed(AbilityType ability, boolean bool) { + abilityInformed.put(ability, bool); + } + + /** + * Get the current prep mode of a tool. + * + * @param tool Tool to get the mode for + * @return true if the tool is prepped, false otherwise + */ + public boolean getToolPreparationMode(ToolType tool) { + return toolPreparationMode.get(tool); + } + + public boolean getAbilityUse() { + return abilityUse; + } + + public void toggleAbilityUse() { + abilityUse = !abilityUse; + } + + /* + * Tools + */ + + /** + * Reset the prep modes of all tools. + */ + public void resetToolPrepMode() { + for (ToolType tool : ToolType.values()) { + setToolPreparationMode(tool, false); + } + } + + /** + * Set the current prep mode of a tool. + * + * @param tool Tool to set the mode for + * @param bool true if the tool should be prepped, false otherwise + */ + public void setToolPreparationMode(ToolType tool, boolean bool) { + toolPreparationMode.put(tool, bool); + } + + /** + * Get the current prep ATS of a tool. + * + * @param tool Tool to get the ATS for + * @return the ATS for the tool + */ + public long getToolPreparationATS(ToolType tool) { + return toolATS.get(tool); + } + + /** + * Set the current prep ATS of a tool. + * + * @param tool Tool to set the ATS for + * @param ATS the ATS of the tool + */ + public void setToolPreparationATS(ToolType tool, long ATS) { + int startTime = (int) (ATS / Misc.TIME_CONVERSION_FACTOR); + + toolATS.put(tool, startTime); + } + + /* + * Recently Hurt + */ + + public int getRecentlyHurt() { + return recentlyHurt; + } + + public void setRecentlyHurt(int value) { + recentlyHurt = value; + } + + public void actualizeRecentlyHurt() { + recentlyHurt = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); + } + + /* + * Exploit Prevention + */ + + public int getRespawnATS() { + return respawnATS; + } + + public void actualizeRespawnATS() { + respawnATS = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); + } + + /* + * Repair Anvil Placement + */ + + public void togglePlacedAnvil() { + placedAnvil = !placedAnvil; + } + + public Boolean getPlacedAnvil() { + return placedAnvil; + } + + /* + * Salvage Anvil Placement + */ + + public void togglePlacedSalvageAnvil() { + placedSalvageAnvil = !placedSalvageAnvil; + } + + public Boolean getPlacedSalvageAnvil() { + return placedSalvageAnvil; + } + + /* + * God Mode + */ + + public boolean getGodMode() { + return godMode; + } + + public void toggleGodMode() { + godMode = !godMode; + } + + /* + * Skill notifications + */ + + public boolean useChatNotifications() { + return displaySkillNotifications; + } + + public void toggleChatNotifications() { + displaySkillNotifications = !displaySkillNotifications; + } + /** * Gets the power level of this player. * @@ -223,7 +440,9 @@ public class McMMOPlayer { SkillUtils.xpCheckSkill(skillType, player, profile); } - // Players & Profiles + /* + * Players & Profiles + */ public Player getPlayer() { return player; @@ -237,7 +456,9 @@ public class McMMOPlayer { return profile; } - // Party Stuff + /* + * Party Stuff + */ public void setPartyInvite(Party invite) { this.invite = invite; @@ -339,6 +560,10 @@ public class McMMOPlayer { itemShareModifier = modifier; } + /* + * Chat modes + */ + public boolean getAdminChatMode() { return adminChatMode; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java index 3c7a91179..8b36d2cf0 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java @@ -6,6 +6,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.util.ArrayList; import java.util.HashMap; +import java.util.Map; import java.util.Set; import com.gmail.nossr50.mcMMO; @@ -14,7 +15,6 @@ import com.gmail.nossr50.config.spout.SpoutConfig; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; -import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.spout.huds.HudType; import com.gmail.nossr50.datatypes.spout.huds.McMMOHud; import com.gmail.nossr50.skills.child.FamilyTree; @@ -28,51 +28,14 @@ public class PlayerProfile { private McMMOHud spoutHud; private HudType hudType; - // Toggles - private boolean loaded; - private boolean godMode; - - private boolean placedAnvil; - private boolean placedSalvageAnvil; - - private boolean hoePreparationMode; - private boolean shovelPreparationMode; - private boolean swordsPreparationMode; - private boolean fistsPreparationMode; - private boolean pickaxePreparationMode; - private boolean axePreparationMode; - - private boolean greenTerraMode; - private boolean treeFellerMode; - private boolean superBreakerMode; - private boolean gigaDrillBreakerMode; - private boolean serratedStrikesMode; - private boolean skullSplitterMode; - private boolean berserkMode; - - private boolean greenTerraInformed = true; - private boolean berserkInformed = true; - private boolean skullSplitterInformed = true; - private boolean gigaDrillBreakerInformed = true; - private boolean superBreakerInformed = true; - private boolean blastMiningInformed = true; - private boolean serratedStrikesInformed = true; - private boolean treeFellerInformed = true; - - private boolean abilityUse = true; - private boolean displaySkillNotifications = true; - - // Timestamps - private int recentlyHurt; - private int respawnATS; - // mySQL Stuff private int userId; - private HashMap skills = new HashMap(); // Skills and Levels - private HashMap skillsXp = new HashMap(); // Skills and Xp - private HashMap skillsDATS = new HashMap(); - private HashMap toolATS = new HashMap(); + private boolean loaded; + + private Map skills = new HashMap(); // Skills and Levels + private Map skillsXp = new HashMap(); // Skills and Xp + private Map skillsDATS = new HashMap(); private final static String location = mcMMO.getUsersFilePath(); @@ -565,42 +528,6 @@ public class PlayerProfile { return loaded; } - /* - * God Mode - */ - - public boolean getGodMode() { - return godMode; - } - - public void toggleGodMode() { - godMode = !godMode; - } - - /* - * Repair Anvil Placement - */ - - public void togglePlacedAnvil() { - placedAnvil = !placedAnvil; - } - - public Boolean getPlacedAnvil() { - return placedAnvil; - } - - /* - * Salvage Anvil Placement - */ - - public void togglePlacedSalvageAnvil() { - placedSalvageAnvil = !placedSalvageAnvil; - } - - public Boolean getPlacedSalvageAnvil() { - return placedSalvageAnvil; - } - /* * HUD Stuff */ @@ -621,315 +548,6 @@ public class PlayerProfile { this.hudType = hudType; } - /* - * Tools - */ - - /** - * Reset the prep modes of all tools. - */ - public void resetToolPrepMode() { - for (ToolType tool : ToolType.values()) { - setToolPreparationMode(tool, false); - } - } - - /** - * Get the current prep mode of a tool. - * - * @param tool Tool to get the mode for - * @return true if the tool is prepped, false otherwise - */ - public boolean getToolPreparationMode(ToolType tool) { - switch (tool) { - case AXE: - return axePreparationMode; - - case FISTS: - return fistsPreparationMode; - - case HOE: - return hoePreparationMode; - - case PICKAXE: - return pickaxePreparationMode; - - case SHOVEL: - return shovelPreparationMode; - - case SWORD: - return swordsPreparationMode; - - default: - return false; - } - } - - /** - * Set the current prep mode of a tool. - * - * @param tool Tool to set the mode for - * @param bool true if the tool should be prepped, false otherwise - */ - public void setToolPreparationMode(ToolType tool, boolean bool) { - switch (tool) { - case AXE: - axePreparationMode = bool; - break; - - case FISTS: - fistsPreparationMode = bool; - break; - - case HOE: - hoePreparationMode = bool; - break; - - case PICKAXE: - pickaxePreparationMode = bool; - break; - - case SHOVEL: - shovelPreparationMode = bool; - break; - - case SWORD: - swordsPreparationMode = bool; - break; - - default: - break; - } - } - - /** - * Get the current prep ATS of a tool. - * - * @param tool Tool to get the ATS for - * @return the ATS for the tool - */ - public long getToolPreparationATS(ToolType tool) { - return toolATS.get(tool); - } - - /** - * Set the current prep ATS of a tool. - * - * @param tool Tool to set the ATS for - * @param ATS the ATS of the tool - */ - public void setToolPreparationATS(ToolType tool, long ATS) { - int startTime = (int) (ATS / Misc.TIME_CONVERSION_FACTOR); - - toolATS.put(tool, startTime); - } - - /* - * Abilities - */ - - /** - * Reset the prep modes of all tools. - */ - public void resetAbilityMode() { - for (AbilityType ability : AbilityType.values()) { - setAbilityMode(ability, false); - } - } - - /** - * Get the mode of an ability. - * - * @param ability The ability to check - * @return true if the ability is enabled, false otherwise - */ - public boolean getAbilityMode(AbilityType ability) { - switch (ability) { - case BERSERK: - return berserkMode; - - case SUPER_BREAKER: - return superBreakerMode; - - case GIGA_DRILL_BREAKER: - return gigaDrillBreakerMode; - - case GREEN_TERRA: - return greenTerraMode; - - case SKULL_SPLITTER: - return skullSplitterMode; - - case TREE_FELLER: - return treeFellerMode; - - case SERRATED_STRIKES: - return serratedStrikesMode; - - default: - return false; - } - } - - /** - * Set the mode of an ability. - * - * @param ability The ability to check - * @param bool True if the ability is active, false otherwise - */ - public void setAbilityMode(AbilityType ability, boolean bool) { - switch (ability) { - case BERSERK: - berserkMode = bool; - break; - - case SUPER_BREAKER: - superBreakerMode = bool; - break; - - case GIGA_DRILL_BREAKER: - gigaDrillBreakerMode = bool; - break; - - case GREEN_TERRA: - greenTerraMode = bool; - break; - - case SKULL_SPLITTER: - skullSplitterMode = bool; - break; - - case TREE_FELLER: - treeFellerMode = bool; - break; - - case SERRATED_STRIKES: - serratedStrikesMode = bool; - break; - - default: - break; - } - } - - /** - * Get the informed state of an ability - * - * @param ability The ability to check - * @return true if the ability is informed, false otherwise - */ - public boolean getAbilityInformed(AbilityType ability) { - switch (ability) { - case BERSERK: - return berserkInformed; - - case BLAST_MINING: - return blastMiningInformed; - - case SUPER_BREAKER: - return superBreakerInformed; - - case GIGA_DRILL_BREAKER: - return gigaDrillBreakerInformed; - - case GREEN_TERRA: - return greenTerraInformed; - - case SKULL_SPLITTER: - return skullSplitterInformed; - - case TREE_FELLER: - return treeFellerInformed; - - case SERRATED_STRIKES: - return serratedStrikesInformed; - - default: - return false; - } - } - - /** - * Set the informed state of an ability. - * - * @param ability The ability to check - * @param bool True if the ability is informed, false otherwise - */ - public void setAbilityInformed(AbilityType ability, boolean bool) { - switch (ability) { - case BERSERK: - berserkInformed = bool; - break; - - case BLAST_MINING: - blastMiningInformed = bool; - break; - - case SUPER_BREAKER: - superBreakerInformed = bool; - break; - - case GIGA_DRILL_BREAKER: - gigaDrillBreakerInformed = bool; - break; - - case GREEN_TERRA: - greenTerraInformed = bool; - break; - - case SKULL_SPLITTER: - skullSplitterInformed = bool; - break; - - case TREE_FELLER: - treeFellerInformed = bool; - break; - - case SERRATED_STRIKES: - serratedStrikesInformed = bool; - break; - - default: - break; - } - } - - public boolean getAbilityUse() { - return abilityUse; - } - - public void toggleAbilityUse() { - abilityUse = !abilityUse; - } - - /* - * Recently Hurt - */ - - public int getRecentlyHurt() { - return recentlyHurt; - } - - public void setRecentlyHurt(int value) { - recentlyHurt = value; - } - - public void actualizeRecentlyHurt() { - recentlyHurt = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); - } - - /* - * Ability Notifications - */ - - public boolean useChatNotifications() { - return displaySkillNotifications; - } - - public void toggleChatNotifications() { - displaySkillNotifications = !displaySkillNotifications; - } - /* * Cooldowns */ @@ -965,18 +583,6 @@ public class PlayerProfile { } } - /* - * Exploit Prevention - */ - - public int getRespawnATS() { - return respawnATS; - } - - public void actualizeRespawnATS() { - respawnATS = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); - } - /* * Xp Functions */ diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 39f15e147..5274d8ca0 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -23,7 +23,6 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.ToolType; @@ -145,7 +144,6 @@ public class BlockListener implements Listener { } McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); - PlayerProfile profile = mcMMOPlayer.getProfile(); BlockState blockState = event.getBlock().getState(); ItemStack heldItem = player.getItemInHand(); @@ -156,7 +154,7 @@ public class BlockListener implements Listener { /* Green Terra */ if (herbalismManager.canActivateAbility()) { - SkillUtils.abilityCheck(player, SkillType.HERBALISM); + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.HERBALISM); } /* @@ -180,14 +178,14 @@ public class BlockListener implements Listener { MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); miningManager.miningBlockCheck(blockState); - if (profile.getAbilityMode(AbilityType.SUPER_BREAKER)) { + if (mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) { miningManager.miningBlockCheck(blockState); } } /* WOOD CUTTING */ else if (BlockUtils.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(blockState)) { - if (profile.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemUtils.isAxe(heldItem)) { + if (mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemUtils.isAxe(heldItem)) { Woodcutting.beginTreeFeller(blockState, player); } else { @@ -207,7 +205,7 @@ public class BlockListener implements Listener { ExcavationManager excavationManager = UserManager.getPlayer(player).getExcavationManager(); excavationManager.excavationBlockCheck(blockState); - if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { + if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { excavationManager.gigaDrillBreaker(blockState); } } @@ -271,7 +269,7 @@ public class BlockListener implements Listener { return; } - PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); BlockState blockState = event.getBlock().getState(); /* @@ -283,30 +281,30 @@ public class BlockListener implements Listener { ItemStack heldItem = player.getItemInHand(); if (HiddenConfig.getInstance().useEnchantmentBuffs()) { - if ((ItemUtils.isPickaxe(heldItem) && !profile.getAbilityMode(AbilityType.SUPER_BREAKER)) || (ItemUtils.isShovel(heldItem) && !profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER))) { + if ((ItemUtils.isPickaxe(heldItem) && !mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) || (ItemUtils.isShovel(heldItem) && !mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER))) { SkillUtils.removeAbilityBuff(heldItem); } } else { - if ((profile.getAbilityMode(AbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) { + if ((mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) { SkillUtils.handleAbilitySpeedDecrease(player); } } - if (profile.getToolPreparationMode(ToolType.HOE) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) { - SkillUtils.abilityCheck(player, SkillType.HERBALISM); + if (mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) { + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.HERBALISM); } - else if (profile.getToolPreparationMode(ToolType.AXE) && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) { - SkillUtils.abilityCheck(player, SkillType.WOODCUTTING); + else if (mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) { + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.WOODCUTTING); } - else if (profile.getToolPreparationMode(ToolType.PICKAXE) && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) { - SkillUtils.abilityCheck(player, SkillType.MINING); + else if (mcMMOPlayer.getToolPreparationMode(ToolType.PICKAXE) && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) { + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.MINING); } - else if (profile.getToolPreparationMode(ToolType.SHOVEL) && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) { - SkillUtils.abilityCheck(player, SkillType.EXCAVATION); + else if (mcMMOPlayer.getToolPreparationMode(ToolType.SHOVEL) && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) { + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.EXCAVATION); } - else if (profile.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) { - SkillUtils.abilityCheck(player, SkillType.UNARMED); + else if (mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) { + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.UNARMED); } } @@ -315,7 +313,7 @@ public class BlockListener implements Listener { * * We don't need to check permissions here because they've already been checked for the ability to even activate. */ - if (profile.getAbilityMode(AbilityType.TREE_FELLER) && BlockUtils.isLog(blockState)) { + if (mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && BlockUtils.isLog(blockState)) { player.playSound(blockState.getLocation(), Sound.FIZZ, Misc.FIZZ_VOLUME, Misc.FIZZ_PITCH); } } @@ -338,7 +336,6 @@ public class BlockListener implements Listener { } McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); - PlayerProfile profile = mcMMOPlayer.getProfile(); ItemStack heldItem = player.getItemInHand(); Block block = event.getBlock(); BlockState blockState = block.getState(); @@ -354,7 +351,7 @@ public class BlockListener implements Listener { blockState.update(true); } } - else if (profile.getAbilityMode(AbilityType.BERSERK)) { + else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK)) { if (SkillUtils.triggerCheck(player, block, AbilityType.BERSERK)) { if (heldItem.getType() == Material.AIR) { plugin.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player)); @@ -370,7 +367,7 @@ public class BlockListener implements Listener { } } } - else if ((profile.getSkillLevel(SkillType.WOODCUTTING) >= AdvancedConfig.getInstance().getLeafBlowUnlockLevel()) && BlockUtils.isLeaves(blockState)) { + else if ((mcMMOPlayer.getProfile().getSkillLevel(SkillType.WOODCUTTING) >= AdvancedConfig.getInstance().getLeafBlowUnlockLevel()) && BlockUtils.isLeaves(blockState)) { if (SkillUtils.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { if (Config.getInstance().getWoodcuttingRequiresTool()) { if (ItemUtils.isAxe(heldItem)) { diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index b9b29071f..0448977b9 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -28,7 +28,6 @@ import org.bukkit.event.entity.FoodLevelChangeEvent; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.party.PartyManager; @@ -161,10 +160,9 @@ public class EntityListener implements Listener { } McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); - PlayerProfile profile = mcMMOPlayer.getProfile(); /* Check for invincibility */ - if (profile.getGodMode()) { + if (mcMMOPlayer.getGodMode()) { event.setCancelled(true); return; } @@ -201,7 +199,7 @@ public class EntityListener implements Listener { } if (event.getDamage() >= 1) { - profile.actualizeRecentlyHurt(); + mcMMOPlayer.actualizeRecentlyHurt(); } } else if (livingEntity instanceof Tameable) { diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 0de27e591..8af4d21f5 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -30,7 +30,6 @@ import com.gmail.nossr50.chat.ChatManager; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.locale.LocaleLoader; @@ -101,10 +100,9 @@ public class PlayerListener implements Listener { } McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); - PlayerProfile profile = mcMMOPlayer.getProfile(); - if (profile.getGodMode() && !Permissions.mcgod(player)) { - profile.toggleGodMode(); + if (mcMMOPlayer.getGodMode() && !Permissions.mcgod(player)) { + mcMMOPlayer.toggleGodMode(); player.sendMessage(LocaleLoader.getString("Commands.GodMode.Forbidden")); } @@ -128,7 +126,7 @@ public class PlayerListener implements Listener { return; } - UserManager.addUser(player).getProfile().actualizeRespawnATS(); + UserManager.addUser(player).actualizeRespawnATS(); } } @@ -140,9 +138,9 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerDropItemEvent(PlayerDropItemEvent event) { Player player = event.getPlayer(); - PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); - if (playerProfile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) || playerProfile.getAbilityMode(AbilityType.SUPER_BREAKER)) { + if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) || mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) { event.setCancelled(true); return; } @@ -261,7 +259,7 @@ public class PlayerListener implements Listener { return; } - UserManager.getPlayer(player).getProfile().actualizeRespawnATS(); + UserManager.getPlayer(player).actualizeRespawnATS(); } /** diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java index 5d8c9f137..dffbba9ca 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java @@ -3,7 +3,7 @@ package com.gmail.nossr50.runnables.skills; import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.util.Misc; @@ -20,14 +20,14 @@ public class SkillMonitorTask implements Runnable { continue; } - PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); /* * MONITOR SKILLS */ for (SkillType skill : SkillType.values()) { if (skill.getTool() != null && skill.getAbility() != null) { - SkillUtils.monitorSkill(player, profile, curTime, skill); + SkillUtils.monitorSkill(mcMMOPlayer, curTime, skill); } } @@ -36,7 +36,7 @@ public class SkillMonitorTask implements Runnable { */ for (AbilityType ability : AbilityType.values()) { if (ability.getCooldown() > 0) { - SkillUtils.watchCooldown(player, profile, ability); + SkillUtils.watchCooldown(mcMMOPlayer, ability); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java index 93350b314..c9df41cd9 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -6,7 +6,6 @@ import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillManager; @@ -52,14 +51,12 @@ public class AcrobaticsManager extends SkillManager { if (!isFatal(modifiedDamage) && SkillUtils.activationSuccessful(player, skill, Acrobatics.dodgeMaxChance, Acrobatics.dodgeMaxBonusLevel)) { ParticleEffectUtils.playDodgeEffect(player); - PlayerProfile playerProfile = getProfile(); - - if (playerProfile.useChatNotifications()) { + if (mcMMOPlayer.useChatNotifications()) { player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc")); } // Why do we check respawn cooldown here? - if (System.currentTimeMillis() >= playerProfile.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) { + if (System.currentTimeMillis() >= mcMMOPlayer.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) { applyXpGain(damage * Acrobatics.dodgeXpModifier); } diff --git a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java index 3d6e610bb..15d5053a6 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java @@ -86,11 +86,11 @@ public class ArcheryManager extends SkillManager { defender.teleport(dazedLocation); defender.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 10)); - if (UserManager.getPlayer(defender).getProfile().useChatNotifications()) { + if (UserManager.getPlayer(defender).useChatNotifications()) { defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy")); } - if (getProfile().useChatNotifications()) { + if (mcMMOPlayer.useChatNotifications()) { attacker.sendMessage(LocaleLoader.getString("Combat.TargetDazed")); } diff --git a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java index b322947fe..f579307a7 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java @@ -41,11 +41,11 @@ public class AxesManager extends SkillManager { } public boolean canUseSkullSplitter(LivingEntity target) { - return target.isValid() && getProfile().getAbilityMode(AbilityType.SKULL_SPLITTER) && Permissions.skullSplitter(getPlayer()); + return target.isValid() && mcMMOPlayer.getAbilityMode(AbilityType.SKULL_SPLITTER) && Permissions.skullSplitter(getPlayer()); } public boolean canActivateAbility() { - return getProfile().getToolPreparationMode(ToolType.AXE) && Permissions.skullSplitter(getPlayer()); + return mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && Permissions.skullSplitter(getPlayer()); } /** @@ -118,14 +118,14 @@ public class AxesManager extends SkillManager { ParticleEffectUtils.playGreaterImpactEffect(target); target.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier)); - if (getProfile().useChatNotifications()) { + if (mcMMOPlayer.useChatNotifications()) { player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc")); } if (target instanceof Player) { Player defender = (Player) target; - if (UserManager.getPlayer(defender).getProfile().useChatNotifications()) { + if (UserManager.getPlayer(defender).useChatNotifications()) { defender.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck")); } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 5919d5bc4..4f6171589 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -15,7 +15,6 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.ToolType; @@ -30,7 +29,6 @@ import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModUtils; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.StringUtils; -import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; public class HerbalismManager extends SkillManager { @@ -62,15 +60,15 @@ public class HerbalismManager extends SkillManager { } public boolean canGreenTerraBlock(BlockState blockState) { - return getProfile().getAbilityMode(AbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState); + return mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState); } public boolean canActivateAbility() { - return getProfile().getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer()); + return mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer()); } public boolean canGreenTerraPlant() { - return getProfile().getAbilityMode(AbilityType.GREEN_TERRA); + return mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA); } /** @@ -288,9 +286,7 @@ public class HerbalismManager extends SkillManager { return; } - PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile(); - - if (playerProfile.getAbilityMode(AbilityType.GREEN_TERRA)) { + if (mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA)) { playerInventory.removeItem(seed); player.updateInventory(); // Needed until replacement available diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index a5a1f8116..80b51025f 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -86,7 +86,6 @@ public class MiningManager extends SkillManager{ return; } - PlayerProfile profile = getProfile(); TNTPrimed tnt = player.getWorld().spawn(targetBlock.getLocation(), TNTPrimed.class); SkillUtils.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player)); @@ -97,8 +96,8 @@ public class MiningManager extends SkillManager{ targetBlock.setData((byte) 0x0); targetBlock.setType(Material.AIR); - profile.setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis()); - profile.setAbilityInformed(AbilityType.BLAST_MINING, false); + getProfile().setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis()); + mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false); } /** 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 64607d624..b8e658c93 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -204,9 +204,9 @@ public class Repair { * @param anvilID The item ID of the anvil block */ public static void placedAnvilCheck(Player player, int anvilID) { - PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); - if (!profile.getPlacedAnvil()) { + if (!mcMMOPlayer.getPlacedAnvil()) { if (mcMMO.spoutEnabled) { SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); @@ -219,7 +219,7 @@ public class Repair { } player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); - profile.togglePlacedAnvil(); + mcMMOPlayer.togglePlacedAnvil(); } } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Salvage.java b/src/main/java/com/gmail/nossr50/skills/repair/Salvage.java index fabd1146c..912abf387 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Salvage.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Salvage.java @@ -11,7 +11,7 @@ import org.getspout.spoutapi.player.SpoutPlayer; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.ItemUtils; @@ -59,9 +59,9 @@ public class Salvage { * @param anvilID The item ID of the anvil block */ public static void placedAnvilCheck(final Player player, final int anvilID) { - final PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); - if (!profile.getPlacedSalvageAnvil()) { + if (!mcMMOPlayer.getPlacedSalvageAnvil()) { if (mcMMO.spoutEnabled) { final SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); @@ -74,7 +74,7 @@ public class Salvage { } player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); - profile.togglePlacedSalvageAnvil(); + mcMMOPlayer.togglePlacedSalvageAnvil(); } } diff --git a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java index 51e359895..6f181ad2b 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java @@ -34,14 +34,14 @@ public class SwordsManager extends SkillManager { BleedTimerTask.add(target, Swords.bleedBaseTicks); } - if (getProfile().useChatNotifications()) { + if (mcMMOPlayer.useChatNotifications()) { player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding")); } if (target instanceof Player) { Player defender = (Player) target; - if (UserManager.getPlayer(defender).getProfile().useChatNotifications()) { + if (UserManager.getPlayer(defender).useChatNotifications()) { defender.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding.Started")); } } 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 b907b5bdb..b09f392b8 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -108,7 +108,7 @@ public class TamingManager extends SkillManager { * @param livingEntity The entity to examine */ public void beastLore(LivingEntity livingEntity) { - BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(mcMMOPlayer.getPlayer(), livingEntity); + BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(getPlayer(), livingEntity); eventHandler.sendInspectMessage(); } @@ -119,11 +119,11 @@ public class TamingManager extends SkillManager { * @param summonAmount The amount of material needed to summon the entity */ private void callOfTheWild(EntityType type, int summonAmount) { - if (!Permissions.callOfTheWild(mcMMOPlayer.getPlayer())) { + if (!Permissions.callOfTheWild(getPlayer())) { return; } - CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(mcMMOPlayer.getPlayer(), type, summonAmount); + CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(getPlayer(), type, summonAmount); ItemStack inHand = eventHandler.inHand; int inHandAmount = inHand.getAmount(); diff --git a/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java b/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java index f3b861466..db05ac465 100644 --- a/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java +++ b/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java @@ -6,7 +6,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.metrics.MetricsManager; import com.gmail.nossr50.util.player.UserManager; @@ -27,10 +26,9 @@ public final class ChimaeraWing { return; } - PlayerProfile profile = UserManager.getPlayer(player).getProfile(); Block block = player.getLocation().getBlock(); int amount = inHand.getAmount(); - long recentlyHurt = profile.getRecentlyHurt() * Misc.TIME_CONVERSION_FACTOR; + long recentlyHurt = UserManager.getPlayer(player).getRecentlyHurt() * Misc.TIME_CONVERSION_FACTOR; if (Permissions.chimaeraWing(player) && inHand.getTypeId() == Config.getInstance().getChimaeraItemId()) { if (SkillUtils.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) { diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index c10caf468..293fc7f65 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -21,7 +21,6 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.ToolType; @@ -90,11 +89,10 @@ public final class CombatUtils { } if (Permissions.skillEnabled(player, SkillType.SWORDS)) { - PlayerProfile profile = mcMMOPlayer.getProfile(); boolean canSerratedStrike = Permissions.serratedStrikes(player); // So we don't have to check the same permission twice - if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) { - SkillUtils.abilityCheck(player, SkillType.SWORDS); + if (mcMMOPlayer.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) { + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.SWORDS); } SwordsManager swordsManager = mcMMOPlayer.getSwordsManager(); @@ -103,7 +101,7 @@ public final class CombatUtils { swordsManager.bleedCheck(target); } - if (profile.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) { + if (mcMMOPlayer.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) { swordsManager.serratedStrikes(target, event.getDamage()); } @@ -119,7 +117,7 @@ public final class CombatUtils { AxesManager axesManager = mcMMOPlayer.getAxesManager(); if (axesManager.canActivateAbility()) { - SkillUtils.abilityCheck(player, SkillType.AXES); + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.AXES); } if (axesManager.canUseAxeMastery()) { @@ -155,12 +153,10 @@ public final class CombatUtils { } if (Permissions.skillEnabled(player, SkillType.UNARMED)) { - PlayerProfile profile = mcMMOPlayer.getProfile(); - boolean canBerserk = Permissions.berserk(player); // So we don't have to check the same permission twice - if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) { - SkillUtils.abilityCheck(player, SkillType.UNARMED); + if (mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && canBerserk) { + SkillUtils.abilityCheck(mcMMOPlayer, SkillType.UNARMED); } UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager(); @@ -169,7 +165,7 @@ public final class CombatUtils { event.setDamage(unarmedManager.ironArmCheck(event.getDamage())); } - if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) { + if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && canBerserk) { event.setDamage(unarmedManager.berserkDamage(event.getDamage())); } @@ -450,7 +446,7 @@ public final class CombatUtils { Player defender = (Player) target; - if (System.currentTimeMillis() >= UserManager.getPlayer(defender).getProfile().getRespawnATS() + 5) { + if (System.currentTimeMillis() >= UserManager.getPlayer(defender).getRespawnATS() + 5) { baseXP = 20 * Config.getInstance().getPlayerVersusPlayerXP(); } } @@ -538,7 +534,7 @@ public final class CombatUtils { if (entity instanceof Player) { Player defender = (Player) entity; - if (!defender.getWorld().getPVP() || defender == player || UserManager.getPlayer(defender).getProfile().getGodMode()) { + if (!defender.getWorld().getPVP() || defender == player || UserManager.getPlayer(defender).getGodMode()) { return false; } diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java index 5c313d246..251b7574a 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java @@ -21,6 +21,7 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.spout.SpoutConfig; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; @@ -87,17 +88,18 @@ public class SkillUtils { /** * Sends a message to the player when the cooldown expires. * - * @param player The player to send a message to - * @param profile The profile of the player + * @param mcMMOPlayer The player to send a message to * @param ability The ability to watch cooldowns for */ - public static void watchCooldown(Player player, PlayerProfile profile, AbilityType ability) { - if (player == null || profile == null || ability == null) { + public static void watchCooldown(McMMOPlayer mcMMOPlayer, AbilityType ability) { + if (mcMMOPlayer == null || ability == null) { return; } - if (!profile.getAbilityInformed(ability) && cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { - profile.setAbilityInformed(ability, true); + Player player = mcMMOPlayer.getPlayer(); + + if (!mcMMOPlayer.getAbilityInformed(ability) && cooldownOver(mcMMOPlayer.getProfile().getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { + mcMMOPlayer.setAbilityInformed(ability, true); player.sendMessage(ability.getAbilityRefresh()); } } @@ -113,7 +115,7 @@ public class SkillUtils { return; } - PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); AbilityType ability = skill.getAbility(); ToolType tool = skill.getTool(); ItemStack inHand = player.getItemInHand(); @@ -122,29 +124,26 @@ public class SkillUtils { return; } - /* Check if any abilities are active */ - if (profile == null) { + if (!mcMMOPlayer.getAbilityUse()) { return; } - if (!profile.getAbilityUse()) { - return; - } - - for (AbilityType x : AbilityType.values()) { - if (profile.getAbilityMode(x)) { + for (AbilityType abilityType : AbilityType.values()) { + if (mcMMOPlayer.getAbilityMode(abilityType)) { return; } } + PlayerProfile playerProfile = mcMMOPlayer.getProfile(); + /* * Woodcutting & Axes need to be treated differently. * Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action */ - if (ability.getPermissions(player) && tool.inHand(inHand) && !profile.getToolPreparationMode(tool)) { + if (ability.getPermissions(player) && tool.inHand(inHand) && !mcMMOPlayer.getToolPreparationMode(tool)) { if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) { - if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { - player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player))); + if (!mcMMOPlayer.getAbilityMode(ability) && !cooldownOver(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { + player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player))); return; } } @@ -153,39 +152,36 @@ public class SkillUtils { player.sendMessage(tool.getRaiseTool()); } - profile.setToolPreparationATS(tool, System.currentTimeMillis()); - profile.setToolPreparationMode(tool, true); + mcMMOPlayer.setToolPreparationATS(tool, System.currentTimeMillis()); + mcMMOPlayer.setToolPreparationMode(tool, true); } } /** * Monitors various things relating to skill abilities. * - * @param player The player using the skill + * @param mcMMOPlayer The player using the skill * @param profile The profile of the player * @param curTime The current system time * @param skill The skill being monitored */ - public static void monitorSkill(Player player, PlayerProfile profile, long curTime, SkillType skill) { + public static void monitorSkill(McMMOPlayer mcMMOPlayer, long curTime, SkillType skill) { final int FOUR_SECONDS = 4000; - ToolType tool = skill.getTool(); - AbilityType ability = skill.getAbility(); - if (profile == null) { - return; - } - - if (profile.getToolPreparationMode(tool) && curTime - (profile.getToolPreparationATS(tool) * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) { - profile.setToolPreparationMode(tool, false); + if (mcMMOPlayer.getToolPreparationMode(tool) && curTime - (mcMMOPlayer.getToolPreparationATS(tool) * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) { + mcMMOPlayer.setToolPreparationMode(tool, false); if (Config.getInstance().getAbilityMessagesEnabled()) { - player.sendMessage(tool.getLowerTool()); + mcMMOPlayer.getPlayer().sendMessage(tool.getLowerTool()); } } + AbilityType ability = skill.getAbility(); + Player player = mcMMOPlayer.getPlayer(); + if (ability.getPermissions(player)) { - if (profile.getAbilityMode(ability) && (profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) { + if (mcMMOPlayer.getAbilityMode(ability) && (mcMMOPlayer.getProfile().getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) { if (ability == AbilityType.BERSERK) { player.setCanPickupItems(true); } @@ -193,12 +189,12 @@ public class SkillUtils { handleAbilitySpeedDecrease(player); } - profile.setAbilityMode(ability, false); - profile.setAbilityInformed(ability, false); + mcMMOPlayer.setAbilityMode(ability, false); + mcMMOPlayer.setAbilityInformed(ability, false); ParticleEffectUtils.playAbilityDisabledEffect(player); - if (profile.useChatNotifications()) { + if (mcMMOPlayer.useChatNotifications()) { player.sendMessage(ability.getAbilityOff()); } @@ -368,40 +364,42 @@ public class SkillUtils { /** * Check to see if an ability can be activated. * - * @param player The player activating the ability + * @param mcMMOPlayer The player activating the ability * @param type The skill the ability is based on */ - public static void abilityCheck(Player player, SkillType type) { - PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + public static void abilityCheck(McMMOPlayer mcMMOPlayer, SkillType type) { ToolType tool = type.getTool(); AbilityType ability = type.getAbility(); - profile.setToolPreparationMode(tool, false); + mcMMOPlayer.setToolPreparationMode(tool, false); + + Player player = mcMMOPlayer.getPlayer(); + PlayerProfile playerProfile = mcMMOPlayer.getProfile(); /* * Axes and Woodcutting are odd because they share the same tool. * We show them the too tired message when they take action. */ if (type == SkillType.WOODCUTTING || type == SkillType.AXES) { - if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { - player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player))); + if (!mcMMOPlayer.getAbilityMode(ability) && !cooldownOver(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { + player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player))); return; } } - if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) { - int ticks = PerksUtils.handleActivationPerks(player, 2 + (profile.getSkillLevel(type) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxTicks()); + if (!mcMMOPlayer.getAbilityMode(ability) && cooldownOver(playerProfile.getSkillDATS(ability), ability.getCooldown(), player)) { + int ticks = PerksUtils.handleActivationPerks(player, 2 + (playerProfile.getSkillLevel(type) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxTicks()); ParticleEffectUtils.playAbilityEnabledEffect(player); - if (profile.useChatNotifications()) { + if (mcMMOPlayer.useChatNotifications()) { player.sendMessage(ability.getAbilityOn()); } SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player)); - profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR)); - profile.setAbilityMode(ability, true); + playerProfile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR)); + mcMMOPlayer.setAbilityMode(ability, true); if (ability == AbilityType.BERSERK) { player.setCanPickupItems(false); @@ -514,14 +512,14 @@ public class SkillUtils { } } - PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); int ticks = 0; - if (profile.getAbilityMode(AbilityType.SUPER_BREAKER)) { - ticks = ((int) (profile.getSkillDATS(AbilityType.SUPER_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR; + if (mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) { + ticks = ((int) (mcMMOPlayer.getProfile().getSkillDATS(AbilityType.SUPER_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR; } - else if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { - ticks = ((int) (profile.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR; + else if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { + ticks = ((int) (mcMMOPlayer.getProfile().getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR; } PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);