From 8bbee7fe060661ff57dc421e2b3dcc521b1ea971 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 29 Mar 2012 16:13:43 -0400 Subject: [PATCH] Moved some stuff around, added a few functions to PartyAPI --- .../com/gmail/nossr50/api/ExperienceAPI.java | 13 +++++++++++ .../java/com/gmail/nossr50/api/PartyAPI.java | 22 +++++++++++++----- .../commands/general/InspectCommand.java | 2 +- .../commands/general/McstatsCommand.java | 3 +-- .../nossr50/datatypes/PlayerProfile.java | 18 +++++++++++++++ .../nossr50/listeners/mcSpoutListener.java | 7 +++--- src/main/java/com/gmail/nossr50/m.java | 23 +------------------ .../java/com/gmail/nossr50/skills/Skills.java | 2 +- 8 files changed, 55 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index 7be4b88e6..ced341728 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -96,6 +96,7 @@ public class ExperienceAPI { *
* This function is designed for API usage. * + * @param player The player to add levels to * @param skillType Type of skill to add levels to * @param levels Number of levels to add */ @@ -115,4 +116,16 @@ public class ExperienceAPI { public static int getLevel(Player player, SkillType skillType) { return Users.getProfile(player).getSkillLevel(skillType); } + + /** + * Gets the power level of a player. + *
+ * This function is designed for API usage. + * + * @param player The player to get the power level for + * @return the power level of the player + */ + public static int getPowerLevel(Player player) { + return Users.getProfile(player).getPowerLevel(); + } } diff --git a/src/main/java/com/gmail/nossr50/api/PartyAPI.java b/src/main/java/com/gmail/nossr50/api/PartyAPI.java index 79aae0134..d5d3e9de5 100644 --- a/src/main/java/com/gmail/nossr50/api/PartyAPI.java +++ b/src/main/java/com/gmail/nossr50/api/PartyAPI.java @@ -8,6 +8,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import com.gmail.nossr50.Users; +import com.gmail.nossr50.party.Party; public class PartyAPI { @@ -45,12 +46,7 @@ public class PartyAPI { * @return true if the two players are in the same party, false otherwise */ public static boolean inSameParty(Player playera, Player playerb) { - if (inParty(playera) && inParty(playerb) && getPartyName(playera).equals(getPartyName(playerb))) { - return true; - } - else { - return false; - } + return Party.getInstance().inSameParty(playera, playerb); } /** @@ -91,4 +87,18 @@ public class PartyAPI { } return parties; } + + /** + * Get a list of all players in this player's party. + *
+ * This function is designed for API usage. + * + * @param player The player to check + * @return all the players in the player's party + */ + public static ArrayList getPartyMembers(Player player) { + return Party.getInstance().getPartyMembers(player); + } + + } diff --git a/src/main/java/com/gmail/nossr50/commands/general/InspectCommand.java b/src/main/java/com/gmail/nossr50/commands/general/InspectCommand.java index 3a80bcef4..df448236b 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/InspectCommand.java @@ -84,7 +84,7 @@ public class InspectCommand implements CommandExecutor { if (mcPermissions.getInstance().repair(target)) sender.sendMessage(Skills.getSkillStats(mcLocale.getString("mcPlayerListener.RepairSkill"), PPt.getSkillLevel(SkillType.REPAIR), PPt.getSkillXpLevel(SkillType.REPAIR), PPt.getXpToLevel(SkillType.REPAIR))); - sender.sendMessage(mcLocale.getString("mcPlayerListener.PowerLevel") + ChatColor.GREEN + (m.getPowerLevel(target, PPt))); + sender.sendMessage(mcLocale.getString("mcPlayerListener.PowerLevel") + ChatColor.GREEN + (PPt.getPowerLevel())); } else { if(sender instanceof Player && !player.isOp()) { 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 ccfe5cd82..db8b7fa32 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java @@ -7,7 +7,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gmail.nossr50.Users; -import com.gmail.nossr50.m; import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; @@ -71,7 +70,7 @@ public class McstatsCommand implements CommandExecutor { if (mcPermissions.getInstance().repair(player)) player.sendMessage(Skills.getSkillStats(mcLocale.getString("mcPlayerListener.RepairSkill"), PP.getSkillLevel(SkillType.REPAIR), PP.getSkillXpLevel(SkillType.REPAIR), PP.getXpToLevel(SkillType.REPAIR))); } - player.sendMessage(mcLocale.getString("mcPlayerListener.PowerLevel") + ChatColor.GREEN + (m.getPowerLevel(player, PP))); + player.sendMessage(mcLocale.getString("mcPlayerListener.PowerLevel") + ChatColor.GREEN + (PP.getPowerLevel())); return true; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index 95f724ebd..0e1b9576c 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -1131,6 +1131,24 @@ public class PlayerProfile { return (int) (1020 + (skills.get(skillType) * 20)); //Do we REALLY need to cast to int here? } + /** + * Gets the power level of a player. + * + * @return the power level of the player + */ + public int getPowerLevel() { + Player player = Bukkit.getPlayer(playerName); + int powerLevel = 0; + + for (SkillType type : SkillType.values()) { + if (type.getPermissions(player)) { + powerLevel += getSkillLevel(type); + } + } + + return powerLevel; + } + /** * Calculate the party XP modifier. * diff --git a/src/main/java/com/gmail/nossr50/listeners/mcSpoutListener.java b/src/main/java/com/gmail/nossr50/listeners/mcSpoutListener.java index f53ffa5ec..eb37a64a8 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcSpoutListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcSpoutListener.java @@ -6,9 +6,9 @@ import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent; import org.getspout.spoutapi.player.SpoutPlayer; import com.gmail.nossr50.Users; -import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.HUDmmo; +import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.spout.SpoutStuff; public class mcSpoutListener implements Listener { @@ -30,8 +30,9 @@ public class mcSpoutListener implements Listener { if (sPlayer.isSpoutCraftEnabled()) { SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer)); //Setup Party HUD stuff - Users.getProfile(sPlayer).toggleSpoutEnabled(); - sPlayer.setTitle(String.valueOf(m.getPowerLevel(sPlayer, Users.getProfile(sPlayer)))); + PlayerProfile PPs = Users.getProfile(sPlayer); + PPs.toggleSpoutEnabled(); + sPlayer.setTitle(String.valueOf(PPs.getPowerLevel())); } } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index 42483312a..1779cbb25 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -11,8 +11,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; -import com.gmail.nossr50.datatypes.PlayerProfile; -import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; @@ -96,25 +94,6 @@ public class m { } } - /** - * Gets the power level of a player. - * - * @param player The player to get the power level of - * @param PP The profile of the player - * @return the power level of the player - */ - public static int getPowerLevel(Player player, PlayerProfile PP) { - int powerLevel = 0; - - for (SkillType type : SkillType.values()) { - if (type.getPermissions(player)) { - powerLevel += PP.getSkillLevel(type); - } - } - - return powerLevel; - } - /** * Simulate a block break event. * @@ -148,7 +127,7 @@ public class m { * @param inHand The item to check the tier of * @return the tier of the item */ - public static Integer getTier(ItemStack inHand) { + public static int getTier(ItemStack inHand) { int tier = 0; if (ItemChecks.isWoodTool(inHand)) { diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index a35755739..278d7bf86 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -175,7 +175,7 @@ public class Skills { ps.statVal = PP.getSkillLevel(skillType); } else { - ps.statVal = m.getPowerLevel(player, PP); + ps.statVal = PP.getPowerLevel(); } ps.name = player.getName();