Merge pull request #2 from mcMMO-Dev/master

updating fork...
This commit is contained in:
Mike Pulli 2013-03-21 12:16:47 -07:00
commit c366d4cfe8
148 changed files with 3881 additions and 3872 deletions

2
.gitattributes vendored
View File

@ -1,4 +1,4 @@
* text * text=auto
*.png binary *.png binary
*.wav binary *.wav binary

View File

@ -7,8 +7,48 @@ Key:
! Change ! Change
- Removal - Removal
Version 1.4.03-dev Version 1.4.04-dev
+ Added functions to ExperienceAPI for use with offline players
+ Added Nether Quartz Ore to Mining
+ Added Dropper, Hopper, and Trapped Chest to blocks that shouldn't activate abilities
= Fixed bug where trying to activate a Chimaera Wing would require one item too much
= Fixed bug where Treefeller would try to cut too many leaves and reach the threshold when it shouldn't
= Fixed bug where Mining wasn't awarding double drops
= Fixed bug where Shake wouldn't damage mobs whose max health was less than 4
= Fixed bug where the API would fail if the name of a player's current party is requested when the player isn't in one (Thanks @dualspiral!)
= Fixed bug with retrieving a player's party members
! Updated localization files
- Removed deprecated functions from API classes.
- Removed functions for getting the PlayerProfile - using API classes is preferred, but if not the McMMOPlayer should be used instead
Version 1.4.03
+ Added option to advanced.yml to determine the # of enchant levels used when buffing Super Breaker & Giga Drill Breaker
+ Improved stats display for child skills
+ Added cooldown between using Chimaera Wings
= Fixed bug with '/party chat (on|off)' and '/partychat (on|off)' not working
= Fixed bug with Repair not decreasing enchanting levels properly
= Fixed bug with Smelting not properly tracking furnaces
= Fixed bug with Blast Mining not dropping blocks correctly
= Fixed bug with custom blocks not working
= Fixed bug with Blast Mining increasing TNT damage.
= Fixed bug where Blast Mining was awarding too much XP
= Fixed bug where triple drops would award twice the amount of experience in Herbalism and Mining
= Fixed bug where Green Thumb would consume wheat instead of seeds
= Fixed bug where Green Terra would consume twice the amount of seed when used on crops
= Fixed bug where experience would be awarded in Herbalism for some player-placed blocks
= Fixed bug where players were unable to salvage leather armor = Fixed bug where players were unable to salvage leather armor
= Fixed bug with repairing using materials with byte metadata
= Fixed bug where Fishing was becoming less successful at higher levels
= Fixed bug with using Salvage on stacked items.
= Fixed bug where the 'mcmmo.commands.ptp.world.all' was registered twice
= Fixed bug where Beast Lore wouldn't work on friendly pets
= Fixed bug where Deflect was calculated based on the attacker, not the defender. (We really did this time!)
= Fixed bug where Treefeller would not deal durability damage when the axe "splinters into dozens of pieces"
! Moved the Salvage unlock level from config.yml to advanced.yml
! Changed how Chimaera Wings are acquired, you need to craft them now. (By default, use 5 feathers in a shapeless recipe)
! Changed how Chimaera Wings teleport players to the spawnpoint, will now check if the location is safe
- Removed option to disable Salvage via the config file. This should be handled via permissions instead.
- Removed the option to use Woodcutting without an axe from the config file.
Version 1.4.02 Version 1.4.02
+ Added API to get the skill and power level caps. + Added API to get the skill and power level caps.

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId> <groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId> <artifactId>mcMMO</artifactId>
<version>1.4.03-dev1</version> <version>1.4.04-dev1</version>
<name>mcMMO</name> <name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url> <url>https://github.com/mcMMO-Dev/mcMMO</url>
<issueManagement> <issueManagement>

View File

@ -39,22 +39,6 @@ public final class ChatAPI {
ChatManager.handlePartyChat(plugin, PartyManager.getParty(party), sender, sender, message); ChatManager.handlePartyChat(plugin, PartyManager.getParty(party), sender, sender, message);
} }
/**
* Send a message to all members of a party
* </br>
* This function is designed for API usage.
*
* @deprecated Replaced by sendPartyChat(Plugin, String, String, String)
*
* @param sender The name of the sender to display in the chat
* @param party The name of the party to send to
* @param message The message to send
*/
@Deprecated
public static void sendPartyChat(String sender, String party, String message) {
sendPartyChat(null, party, sender, sender, message);
}
/** /**
* Send a message to administrators * Send a message to administrators
* </br> * </br>
@ -82,21 +66,6 @@ public final class ChatAPI {
ChatManager.handleAdminChat(plugin, sender, sender, message); ChatManager.handleAdminChat(plugin, sender, sender, message);
} }
/**
* Send a message to administrators
* </br>
* This function is designed for API usage.
*
* @deprecated Replaced by sendAdminChat(Plugin, String, String)
*
* @param sender The name of the sender to display in the chat
* @param message The message to send
*/
@Deprecated
public static void sendAdminChat(String sender, String message) {
sendAdminChat(null, sender, sender, message);
}
/** /**
* Check if a player is currently talking in party chat. * Check if a player is currently talking in party chat.
* *

View File

@ -1,30 +1,18 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import java.util.Set;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.child.FamilyTree;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public final class ExperienceAPI { public final class ExperienceAPI {
private ExperienceAPI() {} private ExperienceAPI() {}
/**
* Adds raw XP to the player.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @deprecated Use {@link #addRawXP(Player, String, int)} instead
*/
@Deprecated
public static void addRawXP(Player player, SkillType skillType, int XP) {
UserManager.getPlayer(player).applyXpGain(skillType, XP);
}
/** /**
* Adds raw XP to the player. * Adds raw XP to the player.
* </br> * </br>
@ -39,18 +27,18 @@ public final class ExperienceAPI {
} }
/** /**
* Adds XP to the player, calculates for XP Rate only. * Adds raw XP to an offline player.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to add XP to * @param playerName The player to add XP to
* @param skillType The skill to add XP to * @param skillType The skill to add XP to
* @param XP The amount of XP to add * @param XP The amount of XP to add
* @deprecated Use {@link #addMultipliedXP(Player, String, int)} instead *
* @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated public static void addRawXPOffline(String playerName, String skillType, int XP) {
public static void addMultipliedXP(Player player, SkillType skillType, int XP) { addOfflineXP(playerName, skillType, XP);
UserManager.getPlayer(player).applyXpGain(skillType, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
} }
/** /**
@ -67,18 +55,48 @@ public final class ExperienceAPI {
} }
/** /**
* Adds XP to the player, calculates for XP Rate, skill modifiers and perks. May be shared with the party. * Adds XP to an offline player, calculates for XP Rate only.
* </br>
* This function is designed for API usage.
*
* @param playerName The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, skillType, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
}
/**
* Adds XP to the player, calculates for XP Rate and skill modifier.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to add XP to * @param player The player to add XP to
* @param skillType The skill to add XP to * @param skillType The skill to add XP to
* @param XP The amount of XP to add * @param XP The amount of XP to add
* @deprecated Use {@link #addXP(Player, String, int)} instead
*/ */
@Deprecated public static void addModifiedXP(Player player, String skillType, int XP) {
public static void addXP(Player player, SkillType skillType, int XP) { SkillType skill = SkillType.getSkill(skillType);
UserManager.getPlayer(player).beginXpGain(skillType, XP);
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
}
/**
* Adds XP to an offline player, calculates for XP Rate and skill modifier.
* </br>
* This function is designed for API usage.
*
* @param playerName The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, skillType, (int) (XP / SkillType.getSkill(skillType).getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
} }
/** /**
@ -94,21 +112,6 @@ public final class ExperienceAPI {
UserManager.getPlayer(player).beginXpGain(SkillType.getSkill(skillType), XP); UserManager.getPlayer(player).beginXpGain(SkillType.getSkill(skillType), XP);
} }
/**
* Get the amount of XP a player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param player The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
* @deprecated Use {@link #getXP(Player, String)} instead
*/
@Deprecated
public static int getXP(Player player, SkillType skillType) {
return UserManager.getPlayer(player).getProfile().getSkillXpLevel(skillType);
}
/** /**
* Get the amount of XP a player has in a specific skill. * Get the amount of XP a player has in a specific skill.
* </br> * </br>
@ -123,18 +126,17 @@ public final class ExperienceAPI {
} }
/** /**
* Get the amount of XP left before leveling up. * Get the amount of XP an offline player has in a specific skill.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to get the XP amount for * @param playerName The player to get XP for
* @param skillType The skill to get the XP amount for * @param skillType The skill to get XP for
* @return the amount of XP left before leveling up a specifc skill * @return the amount of XP in a given skill
* @deprecated Use {@link #getXPToNextLevel(Player, String)} instead * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated public static int getOfflineXP(String playerName, String skillType) {
public static int getXPToNextLevel(Player player, SkillType skillType) { return getOfflineProfile(playerName).getSkillXpLevel(SkillType.getSkill(skillType));
return UserManager.getPlayer(player).getProfile().getXpToLevel(skillType);
} }
/** /**
@ -151,37 +153,17 @@ public final class ExperienceAPI {
} }
/** /**
* Add levels to a skill. * Get the amount of XP an offline player has left before leveling up.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to add levels to * @param playerName The player to get XP for
* @param skillType Type of skill to add levels to * @param skillType The skill to get XP for
* @param levels Number of levels to add * @return the amount of XP in a given skill
* @param notify Unused argument * @throws InvalidPlayerException if the given player does not exist in the database
* @deprecated Use addLevel(Player, SKillType, int) instead
*/ */
public static void addLevel(Player player, SkillType skillType, int levels, boolean notify) { public static int getOfflineXPToNextLevel(String playerName, String skillType) {
UserManager.getProfile(player).addLevels(skillType, levels); return getOfflineProfile(playerName).getXpToLevel(SkillType.getSkill(skillType));
if (notify) {
checkXP(player, skillType);
}
}
/**
* Add levels to a skill.
* </br>
* 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
* @deprecated Use {@link #addLevel(Player, String, int)} instead
*/
@Deprecated
public static void addLevel(Player player, SkillType skillType, int levels) {
UserManager.getPlayer(player).getProfile().addLevels(skillType, levels);
} }
/** /**
@ -198,18 +180,34 @@ public final class ExperienceAPI {
} }
/** /**
* Get the level a player has in a specific skill. * Add levels to a skill for an offline player.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to get the level for * @param playerName The player to add levels to
* @param skillType The skill to get the level for * @param skillType Type of skill to add levels to
* @return the level of a given skill * @param levels Number of levels to add
* @deprecated Use {@link #getLevel(Player, String)} instead *
* @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated public static void addLevelOffline(String playerName, String skillType, int levels) {
public static int getLevel(Player player, SkillType skillType) { PlayerProfile profile = getOfflineProfile(playerName);
return UserManager.getPlayer(player).getProfile().getSkillLevel(skillType);
SkillType skill = SkillType.getSkill(skillType);
if (skill.isChildSkill()) {
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
for (SkillType parentSkill : parentSkills) {
profile.addLevels(parentSkill, (levels / parentSkills.size()));
}
profile.save();
return;
}
profile.addLevels(skill, levels);
profile.save();
} }
/** /**
@ -225,6 +223,20 @@ public final class ExperienceAPI {
return UserManager.getPlayer(player).getProfile().getSkillLevel(SkillType.getSkill(skillType)); return UserManager.getPlayer(player).getProfile().getSkillLevel(SkillType.getSkill(skillType));
} }
/**
* Get the level an offline player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param playerName The player to get the level for
* @param skillType The skill to get the level for
* @return the level of a given skill
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static int getLevelOffline(String playerName, String skillType) {
return getOfflineProfile(playerName).getSkillLevel(SkillType.getSkill(skillType));
}
/** /**
* Gets the power level of a player. * Gets the power level of a player.
* </br> * </br>
@ -237,6 +249,30 @@ public final class ExperienceAPI {
return UserManager.getPlayer(player).getPowerLevel(); return UserManager.getPlayer(player).getPowerLevel();
} }
/**
* Gets the power level of an offline player.
* </br>
* This function is designed for API usage.
*
* @param playerName The player to get the power level for
* @return the power level of the player
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static int getPowerLevelOffline(String playerName) {
int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(playerName);
for (SkillType type : SkillType.values()) {
if (type.isChildSkill()) {
continue;
}
powerLevel += profile.getSkillLevel(type);
}
return powerLevel;
}
/** /**
* Get the level cap of a specific skill. * Get the level cap of a specific skill.
* </br> * </br>
@ -260,21 +296,6 @@ public final class ExperienceAPI {
return Config.getInstance().getPowerLevelCap(); return Config.getInstance().getPowerLevelCap();
} }
/**
* Sets the level of a player in a specific skill type.
* </br>
* This function is designed for API usage.
*
* @param player The player to set the level of
* @param skillType The skill to set the level for
* @param skillLevel The value to set the level to
* @deprecated Use {@link #setLevel(Player, String, int)} instead
*/
@Deprecated
public static void setLevel(Player player, SkillType skillType, int skillLevel) {
UserManager.getPlayer(player).getProfile().modifySkill(skillType, skillLevel);
}
/** /**
* Sets the level of a player in a specific skill type. * Sets the level of a player in a specific skill type.
* </br> * </br>
@ -289,18 +310,18 @@ public final class ExperienceAPI {
} }
/** /**
* Sets the XP of a player in a specific skill type. * Sets the level of an offline player in a specific skill type.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to set the XP of * @param playerName The player to set the level of
* @param skillType The skill to set the XP for * @param skillType The skill to set the level for
* @param newValue The value to set the XP to * @param skillLevel The value to set the level to
* @deprecated Use {@link #setXP(Player, String, int)} instead *
* @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
public static void setXP(Player player, SkillType skillType, int newValue) { getOfflineProfile(playerName).modifySkill(SkillType.getSkill(skillType), skillLevel);
UserManager.getPlayer(player).getProfile().setSkillXpLevel(skillType, newValue);
} }
/** /**
@ -317,18 +338,18 @@ public final class ExperienceAPI {
} }
/** /**
* Removes XP from a player in a specific skill type. * Sets the XP of an offline player in a specific skill type.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to change the XP of * @param playerName The player to set the XP of
* @param skillType The skill to change the XP for * @param skillType The skill to set the XP for
* @param xp The amount of XP to remove * @param newValue The value to set the XP to
* @deprecated Use {@link #removeXP(Player, String, int)} instead *
* @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated public static void setXPOffline(String playerName, String skillType, int newValue) {
public static void removeXP(Player player, SkillType skillType, int xp) { getOfflineProfile(playerName).setSkillXpLevel(SkillType.getSkill(skillType), newValue);
UserManager.getPlayer(player).getProfile().removeXp(skillType, xp);
} }
/** /**
@ -345,14 +366,54 @@ public final class ExperienceAPI {
} }
/** /**
* Check the XP of a player. This should be called after giving XP to process level-ups. * Removes XP from an offline player in a specific skill type.
* </br>
* This function is designed for API usage.
* *
* @param player The player to check * @param playerName The player to change the XP of
* @param skillType The skill to check * @param skillType The skill to change the XP for
* @deprecated Calling this function is no longer needed and should be avoided * @param xp The amount of XP to remove
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated public static void removeXPOffline(String playerName, String skillType, int xp) {
private static void checkXP(Player player, SkillType skillType) { getOfflineProfile(playerName).removeXp(SkillType.getSkill(skillType), xp);
SkillUtils.xpCheckSkill(skillType, player, UserManager.getProfile(player)); }
/**
* Add XP to an offline player.
*
* @param playerName The player to check
* @param skillType The skill to check
* @param XP The amount of XP to award.
*/
private static void addOfflineXP(String playerName, String skillType, int XP) {
PlayerProfile profile = getOfflineProfile(playerName);
SkillType skill = SkillType.getSkill(skillType);
if (skill.isChildSkill()) {
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
for (SkillType parentSkill : parentSkills) {
profile.setSkillXpLevel(parentSkill, profile.getSkillLevel(parentSkill) + (XP / parentSkills.size()));
}
profile.save();
return;
}
profile.setSkillXpLevel(skill, profile.getSkillXpLevel(skill) + XP);
profile.save();
}
private static PlayerProfile getOfflineProfile(String playerName) {
PlayerProfile profile = new PlayerProfile(playerName, false);
if (!profile.isLoaded()) {
throw new InvalidPlayerException();
}
return profile;
} }
} }

View File

@ -0,0 +1,9 @@
package com.gmail.nossr50.api;
public class InvalidPlayerException extends RuntimeException {
private static final long serialVersionUID = 907213002618581385L;
public InvalidPlayerException() {
super("That player does not exist in the database.");
}
}

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -19,9 +18,13 @@ public final class PartyAPI {
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to check the party name of * @param player The player to check the party name of
* @return the name of the player's party * @return the name of the player's party, or null if not in a party
*/ */
public static String getPartyName(Player player) { public static String getPartyName(Player player) {
if (!inParty(player)) {
return null;
}
return UserManager.getPlayer(player).getParty().getName(); return UserManager.getPlayer(player).getParty().getName();
} }
@ -116,26 +119,6 @@ public final class PartyAPI {
PartyManager.setPartyLeader(player, PartyManager.getParty(partyName)); PartyManager.setPartyLeader(player, PartyManager.getParty(partyName));
} }
/**
* Get a list of all players in this player's party.
* </br>
* This function is designed for API usage.
*
* @param player The player to check
* @return all the players in the player's party
* @deprecated
*/
@Deprecated
public static List<String> getAllMembers(Player player) {
List<String> memberNames = new ArrayList<String>();
for (OfflinePlayer member : PartyManager.getAllMembers(player)) {
memberNames.add(member.getName());
}
return memberNames;
}
/** /**
* Get a list of all players in this player's party. * Get a list of all players in this player's party.
* </br> * </br>

View File

@ -6,33 +6,32 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class McabilityCommand implements CommandExecutor { public class McabilityCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
switch (args.length) { switch (args.length) {
case 0: case 0:
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.mcability(sender)) { if (!Permissions.mcability(sender)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
mcMMOPlayer = UserManager.getPlayer((Player) sender); mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
if (mcMMOPlayer.getAbilityUse()) { toggleAbilityUse();
sender.sendMessage(LocaleLoader.getString("Commands.Ability.Off"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.On"));
}
mcMMOPlayer.toggleAbilityUse();
return true; return true;
case 1: case 1:
@ -43,37 +42,33 @@ public class McabilityCommand implements CommandExecutor {
mcMMOPlayer = UserManager.getPlayer(args[0]); mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) { if (CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) {
PlayerProfile playerProfile = new PlayerProfile(args[0], false);
if (!playerProfile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true; return true;
} }
Player player = mcMMOPlayer.getPlayer(); player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) { if (CommandUtils.isOffline(sender, player)) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true; return true;
} }
if (mcMMOPlayer.getAbilityUse()) { toggleAbilityUse();
player.sendMessage(LocaleLoader.getString("Commands.Ability.Off")); sender.sendMessage("Ability use has been toggled for" + args[0]); // TODO: Localize
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Ability.On"));
}
mcMMOPlayer.toggleAbilityUse();
return true; return true;
default: default:
return false; return false;
} }
} }
private void toggleAbilityUse() {
if (mcMMOPlayer.getAbilityUse()) {
player.sendMessage(LocaleLoader.getString("Commands.Ability.Off"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Ability.On"));
}
mcMMOPlayer.toggleAbilityUse();
}
} }

View File

@ -6,42 +6,32 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class McgodCommand implements CommandExecutor { public class McgodCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
switch (args.length) { switch (args.length) {
case 0: case 0:
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.mcgod(sender)) { if (!Permissions.mcgod(sender)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
if (!(sender instanceof Player)) { mcMMOPlayer = UserManager.getPlayer(sender.getName());
return false; player = mcMMOPlayer.getPlayer();
}
mcMMOPlayer = UserManager.getPlayer((Player) sender); toggleGodMode();
if (mcMMOPlayer == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (mcMMOPlayer.getGodMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
}
mcMMOPlayer.toggleGodMode();
return true; return true;
case 1: case 1:
@ -52,37 +42,33 @@ public class McgodCommand implements CommandExecutor {
mcMMOPlayer = UserManager.getPlayer(args[0]); mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) { if (CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) {
PlayerProfile playerProfile = new PlayerProfile(args[0], false);
if (!playerProfile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true; return true;
} }
Player player = mcMMOPlayer.getPlayer(); player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) { if (CommandUtils.isOffline(sender, player)) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true; return true;
} }
if (mcMMOPlayer.getGodMode()) { toggleGodMode();
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled")); sender.sendMessage("God mode has been toggled for" + args[0]); // TODO: Localize
}
else {
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
}
mcMMOPlayer.toggleGodMode();
return true; return true;
default: default:
return false; return false;
} }
} }
private void toggleGodMode() {
if (mcMMOPlayer.getGodMode()) {
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
}
mcMMOPlayer.toggleGodMode();
}
} }

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.commands;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@ -14,7 +13,7 @@ public class McnotifyCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 0: case 0:
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
if (mcMMOPlayer.useChatNotifications()) { if (mcMMOPlayer.useChatNotifications()) {
sender.sendMessage(LocaleLoader.getString("Commands.Notifications.Off")); sender.sendMessage(LocaleLoader.getString("Commands.Notifications.Off"));

View File

@ -6,35 +6,32 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class McrefreshCommand implements CommandExecutor { public class McrefreshCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
switch (args.length) { switch (args.length) {
case 0: case 0:
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.mcrefresh(sender)) { if (!Permissions.mcrefresh(sender)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
if (!(sender instanceof Player)) {
return false;
}
mcMMOPlayer = UserManager.getPlayer(sender.getName()); mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
mcMMOPlayer.setRecentlyHurt(0); refreshPlayer();
mcMMOPlayer.getProfile().resetCooldowns();
mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode();
sender.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
return true; return true;
case 1: case 1:
@ -45,31 +42,17 @@ public class McrefreshCommand implements CommandExecutor {
mcMMOPlayer = UserManager.getPlayer(args[0]); mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) { if (CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) {
PlayerProfile playerProfile = new PlayerProfile(args[0], false);
if (!playerProfile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true; return true;
} }
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) { if (CommandUtils.isOffline(sender, player)) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true; return true;
} }
mcMMOPlayer.setRecentlyHurt(0); refreshPlayer();
mcMMOPlayer.getProfile().resetCooldowns();
mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", args[0])); sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", args[0]));
return true; return true;
@ -77,4 +60,13 @@ public class McrefreshCommand implements CommandExecutor {
return false; return false;
} }
} }
private void refreshPlayer() {
mcMMOPlayer.setRecentlyHurt(0);
mcMMOPlayer.getProfile().resetCooldowns();
mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
}
} }

View File

@ -8,10 +8,14 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.commands.CommandUtils;
public class XprateCommand implements CommandExecutor { public class XprateCommand implements CommandExecutor {
private static double originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier(); private double originalRate;
public XprateCommand() {
originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -35,8 +39,8 @@ public class XprateCommand implements CommandExecutor {
return true; return true;
case 2: case 2:
if (!StringUtils.isInt(args[0])) { if (CommandUtils.isInvalidInteger(sender, args[0])) {
return false; return true;
} }
if (!Permissions.xprateSet(sender)) { if (!Permissions.xprateSet(sender)) {
@ -44,11 +48,16 @@ public class XprateCommand implements CommandExecutor {
return true; return true;
} }
if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) { if (CommandUtils.shouldDisableToggle(args[1])) {
mcMMO.p.setXPEventEnabled(false);
}
else if (CommandUtils.shouldEnableToggle(args[1])) {
mcMMO.p.setXPEventEnabled(true);
}
else {
return false; return false;
} }
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
int newXpRate = Integer.parseInt(args[0]); int newXpRate = Integer.parseInt(args[0]);
Config.getInstance().setExperienceGainsGlobalMultiplier(newXpRate); Config.getInstance().setExperienceGainsGlobalMultiplier(newXpRate);

View File

@ -3,15 +3,16 @@ package com.gmail.nossr50.commands.chat;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.chat.ChatMode; import com.gmail.nossr50.chat.ChatMode;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public abstract class ChatCommand implements CommandExecutor { public abstract class ChatCommand implements CommandExecutor {
protected McMMOPlayer mcMMOPlayer;
protected ChatMode chatMode; protected ChatMode chatMode;
private McMMOPlayer mcMMOPlayer;
public ChatCommand(ChatMode chatMode) { public ChatCommand(ChatMode chatMode) {
this.chatMode = chatMode; this.chatMode = chatMode;
@ -21,11 +22,11 @@ public abstract class ChatCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 0: case 0:
if (!(sender instanceof Player)) { if (CommandUtils.noConsoleUsage(sender)) {
return false; return true;
} }
mcMMOPlayer = UserManager.getPlayer((Player) sender); mcMMOPlayer = UserManager.getPlayer(sender.getName());
if (chatMode.isEnabled(mcMMOPlayer)) { if (chatMode.isEnabled(mcMMOPlayer)) {
disableChatMode(sender); disableChatMode(sender);
@ -37,20 +38,24 @@ public abstract class ChatCommand implements CommandExecutor {
return true; return true;
case 1: case 1:
if (args[0].equalsIgnoreCase("on")) { if (CommandUtils.shouldEnableToggle(args[0])) {
if (!(sender instanceof Player)) { if (CommandUtils.noConsoleUsage(sender)) {
return false; return true;
} }
mcMMOPlayer = UserManager.getPlayer(sender.getName());
enableChatMode(sender); enableChatMode(sender);
return true; return true;
} }
if (args[0].equalsIgnoreCase("off")) { if (CommandUtils.shouldDisableToggle(args[0])) {
if (!(sender instanceof Player)) { if (CommandUtils.noConsoleUsage(sender)) {
return false; return true;
} }
mcMMOPlayer = UserManager.getPlayer(sender.getName());
disableChatMode(sender); disableChatMode(sender);
return true; return true;
} }
@ -78,11 +83,21 @@ public abstract class ChatCommand implements CommandExecutor {
protected abstract void handleChatSending(CommandSender sender, String[] args); protected abstract void handleChatSending(CommandSender sender, String[] args);
private void enableChatMode(CommandSender sender) { private void enableChatMode(CommandSender sender) {
if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return;
}
chatMode.enable(mcMMOPlayer); chatMode.enable(mcMMOPlayer);
sender.sendMessage(chatMode.getEnabledMessage()); sender.sendMessage(chatMode.getEnabledMessage());
} }
private void disableChatMode(CommandSender sender) { private void disableChatMode(CommandSender sender) {
if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return;
}
chatMode.disable(mcMMOPlayer); chatMode.disable(mcMMOPlayer);
sender.sendMessage(chatMode.getDisabledMessage()); sender.sendMessage(chatMode.getDisabledMessage());
} }

View File

@ -8,6 +8,7 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.database.LeaderboardManager; import com.gmail.nossr50.database.LeaderboardManager;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class McremoveCommand implements CommandExecutor { public class McremoveCommand implements CommandExecutor {
@ -25,7 +26,7 @@ public class McremoveCommand implements CommandExecutor {
String tablePrefix = Config.getInstance().getMySQLTablePrefix(); String tablePrefix = Config.getInstance().getMySQLTablePrefix();
if (DatabaseManager.update("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.user = '" + args[0] + "'") != 0) { if (DatabaseManager.update("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.user = '" + args[0] + "'") != 0) {
DatabaseManager.profileCleanup(args[0]); Misc.profileCleanup(args[0]);
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0])); sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
} }
else { else {
@ -34,7 +35,7 @@ public class McremoveCommand implements CommandExecutor {
} }
else { else {
if (LeaderboardManager.removeFlatFileUser(args[0])) { if (LeaderboardManager.removeFlatFileUser(args[0])) {
DatabaseManager.profileCleanup(args[0]); Misc.profileCleanup(args[0]);
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0])); sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
} }
else { else {

View File

@ -46,6 +46,6 @@ public class MmoupdateCommand implements CommandExecutor {
return; return;
} }
mcMMO.p.getServer().getScheduler().runTaskLaterAsynchronously(mcMMO.p, new SQLConversionTask(), 1); new SQLConversionTask().runTaskLaterAsynchronously(mcMMO.p, 1);
} }
} }

View File

@ -1,154 +1,36 @@
package com.gmail.nossr50.commands.experience; package com.gmail.nossr50.commands.experience;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
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.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; 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; import com.gmail.nossr50.util.skills.SkillUtils;
public class AddlevelsCommand implements CommandExecutor { public class AddlevelsCommand extends ExperienceCommand {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { protected boolean permissionsCheckSelf(CommandSender sender) {
PlayerProfile profile; return Permissions.addlevels(sender);
int levels; }
boolean allSkills = false;
SkillType skill = null;
switch (args.length) { @Override
case 2: protected boolean permissionsCheckOthers(CommandSender sender) {
if (!Permissions.addlevels(sender)) { return Permissions.addlevelsOthers(sender);
sender.sendMessage(command.getPermissionMessage()); }
return true;
}
if (!(sender instanceof Player)) { @Override
return false; protected void handleCommand(SkillType skill) {
} profile.addLevels(skill, value);
}
if (args[0].equalsIgnoreCase("all")) { @Override
allSkills = true; protected void handlePlayerMessageAll() {
} player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", value));
else if (!SkillUtils.isSkill(args[0])) { }
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!StringUtils.isInt(args[1])) { @Override
return false; protected void handlePlayerMessageSkill() {
} player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, SkillUtils.getSkillName(skill)));
levels = Integer.parseInt(args[1]);
profile = UserManager.getPlayer((Player) sender).getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.addLevels(skillType, levels);
}
}
else {
skill = SkillType.getSkill(args[0]);
profile.addLevels(skill, levels);
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", levels));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, SkillUtils.getSkillName(skill)));
}
return true;
case 3:
if (!Permissions.addlevelsOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!StringUtils.isInt(args[2])) {
return false;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
levels = Integer.parseInt(args[2]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.addLevels(skillType, levels);
}
}
else {
skill = SkillType.getSkill(args[1]);
profile.addLevels(skill, levels);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.addLevels(skillType, levels);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", levels));
}
else {
skill = SkillType.getSkill(args[1]);
profile.addLevels(skill, levels);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, SkillUtils.getSkillName(skill)));
}
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", SkillUtils.getSkillName(skill), args[0]));
}
return true;
default:
return false;
}
} }
} }

View File

@ -1,152 +1,40 @@
package com.gmail.nossr50.commands.experience; package com.gmail.nossr50.commands.experience;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
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.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; 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; import com.gmail.nossr50.util.skills.SkillUtils;
public class AddxpCommand implements CommandExecutor { public class AddxpCommand extends ExperienceCommand {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { protected boolean permissionsCheckSelf(CommandSender sender) {
int xp; return Permissions.addxp(sender);
McMMOPlayer mcMMOPlayer; }
PlayerProfile profile;
boolean allSkills = false;
SkillType skill = null;
switch (args.length) { @Override
case 2: protected boolean permissionsCheckOthers(CommandSender sender) {
if (!Permissions.addxp(sender)) { return Permissions.addxpOthers(sender);
sender.sendMessage(command.getPermissionMessage()); }
return true;
}
if (!(sender instanceof Player)) { @Override
return false; protected void handleCommand(SkillType skill) {
} if (player != null) {
mcMMOPlayer.applyXpGain(skill, value);
if (args[0].equalsIgnoreCase("all")) { }
allSkills = true; else {
} profile.setSkillXpLevel(skill, value);
else if (!SkillUtils.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!StringUtils.isInt(args[1])) {
return false;
}
xp = Integer.parseInt(args[1]);
mcMMOPlayer = UserManager.getPlayer((Player) sender);
profile = mcMMOPlayer.getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
mcMMOPlayer.applyXpGain(skillType, xp);
}
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
}
else {
skill = SkillType.getSkill(args[0]);
mcMMOPlayer.applyXpGain(skill, xp);
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, SkillUtils.getSkillName(skill)));
}
return true;
case 3:
if (!Permissions.addxpOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!StringUtils.isInt(args[2])) {
return false;
}
mcMMOPlayer = UserManager.getPlayer(args[0]);
xp = Integer.parseInt(args[2]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
// TODO: Currently the offline player doesn't level up automatically
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.setSkillXpLevel(skillType, xp);
}
}
else {
skill = SkillType.getSkill(args[1]);
profile.setSkillXpLevel(skill, xp);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
mcMMOPlayer.applyXpGain(skillType, xp);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
}
else {
skill = SkillType.getSkill(args[1]);
mcMMOPlayer.applyXpGain(skill, xp);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, SkillUtils.getSkillName(skill)));
}
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", SkillUtils.getSkillName(skill), args[0]));
}
return true;
default:
return false;
} }
} }
@Override
protected void handlePlayerMessageAll() {
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", value));
}
@Override
protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", value, SkillUtils.getSkillName(skill)));
}
} }

View File

@ -0,0 +1,149 @@
package com.gmail.nossr50.commands.experience;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
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.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public abstract class ExperienceCommand implements CommandExecutor {
protected McMMOPlayer mcMMOPlayer;
protected Player player;
protected PlayerProfile profile;
protected boolean allSkills;
protected SkillType skill;
protected int value;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!permissionsCheckSelf(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!validateArguments(sender, args[0], args[1])) {
return true;
}
mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
profile = mcMMOPlayer.getProfile();
editValues();
return true;
case 3:
if (!permissionsCheckOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!validateArguments(sender, args[1], args[2])) {
return true;
}
mcMMOPlayer = UserManager.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (CommandUtils.unloadedProfile(sender, profile)) {
return true;
}
editValues();
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
editValues();
}
handleSenderMessage(sender, args[0]);
return true;
default:
return false;
}
}
protected abstract boolean permissionsCheckSelf(CommandSender sender);
protected abstract boolean permissionsCheckOthers(CommandSender sender);
protected abstract void handleCommand(SkillType skill);
protected abstract void handlePlayerMessageAll();
protected abstract void handlePlayerMessageSkill();
private boolean validateArguments(CommandSender sender, String skillName, String value) {
if (isInvalidInteger(sender, value) || isInvalidSkill(sender, skillName)) {
return false;
}
return true;
}
private boolean isInvalidInteger(CommandSender sender, String value) {
if (CommandUtils.isInvalidInteger(sender, value)) {
return true;
}
this.value = Integer.parseInt(value);
return false;
}
protected boolean isInvalidSkill(CommandSender sender, String skillName) {
if (skillName.equalsIgnoreCase("all")) {
allSkills = true;
return false;
}
else if (CommandUtils.isInvalidSkill(sender, skillName)) {
return true;
}
skill = SkillType.getSkill(skillName);
return false;
}
protected void handleSenderMessage(CommandSender sender, String playerName) {
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", SkillUtils.getSkillName(skill), playerName));
}
}
protected void editValues() {
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
handleCommand(skillType);
}
if (player != null) {
handlePlayerMessageAll();
}
}
else {
handleCommand(skill);
if (player != null) {
handlePlayerMessageSkill();
}
}
}
}

View File

@ -1,150 +1,35 @@
package com.gmail.nossr50.commands.experience; package com.gmail.nossr50.commands.experience;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
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.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; 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; import com.gmail.nossr50.util.skills.SkillUtils;
public class MmoeditCommand implements CommandExecutor { public class MmoeditCommand extends ExperienceCommand {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { protected boolean permissionsCheckSelf(CommandSender sender) {
PlayerProfile profile; return Permissions.mmoedit(sender);
int newValue; }
boolean allSkills = false;
SkillType skill = null;
switch (args.length) { @Override
case 2: protected boolean permissionsCheckOthers(CommandSender sender) {
if (!Permissions.mmoedit(sender)) { return Permissions.mmoeditOthers(sender);
sender.sendMessage(command.getPermissionMessage()); }
return true;
}
if (!(sender instanceof Player)) { @Override
return false; protected void handleCommand(SkillType skill) {
} profile.modifySkill(skill, value);
}
if (args[0].equalsIgnoreCase("all")) { @Override
allSkills = true; protected void handlePlayerMessageAll() {
} player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", value));
else if (!SkillUtils.isSkill(args[0])) { }
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!StringUtils.isInt(args[1])) { @Override
return false; protected void handlePlayerMessageSkill() {
} player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", SkillUtils.getSkillName(skill), value));
newValue = Integer.parseInt(args[1]);
profile = UserManager.getPlayer((Player) sender).getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.modifySkill(skillType, newValue);
}
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
skill = SkillType.getSkill(args[0]);
profile.modifySkill(skill, newValue);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", SkillUtils.getSkillName(skill), newValue));
}
return true;
case 3:
if (!Permissions.mmoeditOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!StringUtils.isInt(args[2])) {
return false;
}
newValue = Integer.parseInt(args[2]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.modifySkill(skillType, newValue);
}
}
else {
skill = SkillType.getSkill(args[1]);
profile.modifySkill(skill, newValue);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.modifySkill(skillType, newValue);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
skill = SkillType.getSkill(args[1]);
profile.modifySkill(skill, newValue);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", SkillUtils.getSkillName(skill), newValue));
}
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", SkillUtils.getSkillName(skill), args[0]));
}
return true;
default:
return false;
}
} }
} }

View File

@ -1,76 +1,47 @@
package com.gmail.nossr50.commands.experience; package com.gmail.nossr50.commands.experience;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class SkillresetCommand implements CommandExecutor { public class SkillresetCommand extends ExperienceCommand {
private CommandSender sender;
private Command command;
private int argsLength;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile; this.command = command;
boolean allSkills = false; this.sender = sender;
SkillType skill = null; argsLength = args.length;
String skillName = "";
switch (args.length) { switch (args.length) {
case 1: case 1:
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.skillreset(sender)) { if (!Permissions.skillreset(sender)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
if (!(sender instanceof Player)) { if (isInvalidSkill(sender, args[0])) {
return false;
}
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true; return true;
} }
profile = UserManager.getPlayer((Player) sender).getProfile(); mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
if (allSkills) { profile = mcMMOPlayer.getProfile();
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillreset(sender, skillType)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
skill = SkillType.getSkill(args[0]);
skillName = SkillUtils.getSkillName(skill);
if (!Permissions.skillreset(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
profile.modifySkill(skill, 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", skillName));
}
editValues();
return true; return true;
case 2: case 2:
@ -79,91 +50,67 @@ public class SkillresetCommand implements CommandExecutor {
return true; return true;
} }
if (args[1].equalsIgnoreCase("all")) { if (isInvalidSkill(sender, args[1])) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true; return true;
} }
if (!allSkills) { mcMMOPlayer = UserManager.getPlayer(args[0]);
skill = SkillType.getSkill(args[1]);
skillName = SkillUtils.getSkillName(skill);
if (!Permissions.skillresetOthers(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process. // If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false); profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) { if (CommandUtils.unloadedProfile(sender, profile)) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true; return true;
} }
if (allSkills) { editValues();
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillresetOthers(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
}
else {
profile.modifySkill(skill, 0);
}
profile.save(); // Since this is a temporary profile, we save it here. profile.save(); // Since this is a temporary profile, we save it here.
} }
else { else {
profile = mcMMOPlayer.getProfile(); profile = mcMMOPlayer.getProfile();
player = mcMMOPlayer.getPlayer();
if (allSkills) { editValues();
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillresetOthers(sender, skillType)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
profile.modifySkill(skill, 0);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", skillName));
}
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", skillName, args[0]));
} }
handleSenderMessage(sender, args[0]);
return true; return true;
default: default:
return false; return false;
} }
} }
@Override
protected boolean permissionsCheckSelf(CommandSender sender) {
// TODO Auto-generated method stub
return false;
}
@Override
protected boolean permissionsCheckOthers(CommandSender sender) {
// TODO Auto-generated method stub
return false;
}
@Override
protected void handleCommand(SkillType skill) {
if (argsLength == 1 && !Permissions.skillreset(sender, skill) || (argsLength == 2 && !Permissions.skillresetOthers(sender, skill))) {
sender.sendMessage(command.getPermissionMessage());
return;
}
profile.modifySkill(skill, 0);
}
@Override
protected void handlePlayerMessageAll() {
player.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
@Override
protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", SkillUtils.getSkillName(skill)));
}
} }

View File

@ -1,85 +1,41 @@
package com.gmail.nossr50.commands.hardcore; package com.gmail.nossr50.commands.hardcore;
import java.text.DecimalFormat;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
public class HardcoreCommand implements CommandExecutor { public class HardcoreCommand extends HardcoreModeCommand {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { protected void disable() {
switch (args.length) {
case 0:
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (Config.getInstance().getHardcoreEnabled()) {
disableHardcore();
}
else {
enableHardcore();
}
return true;
case 1:
if (args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("enabled")) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enableHardcore();
return true;
}
if (args[0].equalsIgnoreCase("off") || args[0].equalsIgnoreCase("false") || args[0].equalsIgnoreCase("disabled")) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
disableHardcore();
return true;
}
if (!StringUtils.isDouble(args[0])) {
return false;
}
if (!Permissions.hardcoreModify(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
DecimalFormat percent = new DecimalFormat("##0.00%");
double newPercent = Double.parseDouble(args[0]);
Config.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercent);
sender.sendMessage(LocaleLoader.getString("Hardcore.PercentageChanged", percent.format(newPercent / 100D)));
return true;
default:
return false;
}
}
private void disableHardcore() {
Config.getInstance().setHardcoreEnabled(false); Config.getInstance().setHardcoreEnabled(false);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Disabled")); mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Disabled"));
} }
private void enableHardcore() { @Override
protected void enable() {
Config.getInstance().setHardcoreEnabled(true); Config.getInstance().setHardcoreEnabled(true);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Enabled")); mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Enabled"));
} }
@Override
protected boolean checkTogglePermissions() {
return Permissions.hardcoreToggle(sender);
}
@Override
protected boolean checkModifyPermissions() {
return Permissions.hardcoreModify(sender);
}
@Override
protected boolean checkEnabled() {
return Config.getInstance().getHardcoreEnabled();
}
@Override
protected void modify() {
Config.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercent);
sender.sendMessage(LocaleLoader.getString("Hardcore.PercentageChanged", percent.format(newPercent / 100D)));
}
} }

View File

@ -0,0 +1,94 @@
package com.gmail.nossr50.commands.hardcore;
import java.text.DecimalFormat;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
public abstract class HardcoreModeCommand implements CommandExecutor {
protected CommandSender sender;
protected double newPercent;
protected DecimalFormat percent;
public HardcoreModeCommand() {
percent = new DecimalFormat("##0.00%");
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 0:
this.sender = sender;
if (!checkTogglePermissions()) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (checkEnabled()) {
disable();
}
else {
enable();
}
return true;
case 1:
if (CommandUtils.shouldEnableToggle(args[0])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enable();
return true;
}
if (CommandUtils.shouldDisableToggle(args[0])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
disable();
return true;
}
if (isInvalidPercentage(sender, args[0])) {
return true;
}
if (!Permissions.hardcoreModify(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
modify();
return true;
default:
return false;
}
}
protected abstract boolean checkTogglePermissions();
protected abstract boolean checkModifyPermissions();
protected abstract boolean checkEnabled();
protected abstract void enable();
protected abstract void disable();
protected abstract void modify();
private boolean isInvalidPercentage(CommandSender sender, String value) {
if (CommandUtils.isInvalidDouble(sender, value)) {
return true;
}
newPercent = Double.parseDouble(value);
return false;
}
}

View File

@ -1,90 +1,41 @@
package com.gmail.nossr50.commands.hardcore; package com.gmail.nossr50.commands.hardcore;
import java.text.DecimalFormat;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
public class VampirismCommand implements CommandExecutor { public class VampirismCommand extends HardcoreModeCommand {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { protected boolean checkTogglePermissions() {
if (!Config.getInstance().getHardcoreEnabled()) { return Permissions.vampirismToggle(sender);
sender.sendMessage(LocaleLoader.getString("Hardcore.Disabled"));
return true;
}
switch (args.length) {
case 0:
if (!Permissions.vampirismToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (Config.getInstance().getHardcoreVampirismEnabled()) {
disableVampirism();
}
else {
enableVampirism();
}
return true;
case 1:
if (args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("enabled")) {
if (!Permissions.vampirismToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enableVampirism();
return true;
}
if (args[0].equalsIgnoreCase("off") || args[0].equalsIgnoreCase("false") || args[0].equalsIgnoreCase("disabled")) {
if (!Permissions.vampirismToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
disableVampirism();
return true;
}
if (!StringUtils.isDouble(args[0])) {
return false;
}
if (!Permissions.vampirismModify(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
DecimalFormat percent = new DecimalFormat("##0.00%");
double newPercent = Double.parseDouble(args[0]);
Config.getInstance().setHardcoreVampirismStatLeechPercentage(newPercent);
sender.sendMessage(LocaleLoader.getString("Vampirism.PercentageChanged", percent.format(newPercent / 100D)));
return true;
default:
return false;
}
} }
private void disableVampirism() { @Override
protected boolean checkModifyPermissions() {
return Permissions.vampirismModify(sender);
}
@Override
protected boolean checkEnabled() {
return Config.getInstance().getHardcoreVampirismEnabled();
}
@Override
protected void enable() {
Config.getInstance().setHardcoreVampirismEnabled(true);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Enabled"));
}
@Override
protected void disable() {
Config.getInstance().setHardcoreVampirismEnabled(false); Config.getInstance().setHardcoreVampirismEnabled(false);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Disabled")); mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Disabled"));
} }
private void enableVampirism() { @Override
Config.getInstance().setHardcoreVampirismEnabled(true); protected void modify() {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Enabled")); Config.getInstance().setHardcoreVampirismStatLeechPercentage(newPercent);
sender.sendMessage(LocaleLoader.getString("Vampirism.PercentageChanged", percent.format(newPercent / 100D)));
} }
} }

View File

@ -11,15 +11,12 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyAcceptCommand implements CommandExecutor { public class PartyAcceptCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 1: case 1:
player = (Player) sender; McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
mcMMOPlayer = UserManager.getPlayer(player); Player player = mcMMOPlayer.getPlayer();
if (!mcMMOPlayer.hasPartyInvite()) { if (!mcMMOPlayer.hasPartyInvite()) {
sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites")); sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
@ -16,7 +15,7 @@ public class PartyChangeOwnerCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
Party playerParty = UserManager.getPlayer((Player) sender).getParty(); Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
if (!playerParty.getMembers().contains(mcMMO.p.getServer().getOfflinePlayer(args[1]))) { if (!playerParty.getMembers().contains(mcMMO.p.getServer().getOfflinePlayer(args[1]))) {
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1])); sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));

View File

@ -3,29 +3,30 @@ package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyChangePasswordCommand implements CommandExecutor { public class PartyChangePasswordCommand implements CommandExecutor {
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Party playerParty = UserManager.getPlayer((Player) sender).getParty(); playerParty = UserManager.getPlayer(sender.getName()).getParty();
switch (args.length) { switch (args.length) {
case 1: case 1:
unprotectParty(sender, playerParty); unprotectParty(sender);
return true; return true;
case 2: case 2:
if (args[1].equalsIgnoreCase("clear") || args[1].equalsIgnoreCase("reset")) { if (args[1].equalsIgnoreCase("clear") || args[1].equalsIgnoreCase("reset")) {
unprotectParty(sender, playerParty); unprotectParty(sender);
return true; return true;
} }
protectParty(sender, playerParty, args[1]); protectParty(sender, args[1]);
return true; return true;
default: default:
@ -35,13 +36,13 @@ public class PartyChangePasswordCommand implements CommandExecutor {
} }
} }
private void unprotectParty(CommandSender sender, Party playerParty) { private void unprotectParty(CommandSender sender) {
playerParty.setLocked(true); playerParty.setLocked(true);
playerParty.setPassword(null); playerParty.setPassword(null);
sender.sendMessage(LocaleLoader.getString("Party.Password.Removed")); sender.sendMessage(LocaleLoader.getString("Party.Password.Removed"));
} }
private void protectParty(CommandSender sender, Party playerParty, String password) { private void protectParty(CommandSender sender, String password) {
playerParty.setLocked(true); playerParty.setLocked(true);
playerParty.setPassword(password); playerParty.setPassword(password);
sender.sendMessage(LocaleLoader.getString("Party.Password.Set", password)); sender.sendMessage(LocaleLoader.getString("Party.Password.Set", password));

View File

@ -5,7 +5,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.chat.PartyChatCommand; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -31,8 +31,8 @@ public class PartyCommand implements CommandExecutor {
private CommandExecutor partyRenameCommand = new PartyRenameCommand(); private CommandExecutor partyRenameCommand = new PartyRenameCommand();
private CommandExecutor partyInfoCommand = new PartyInfoCommand(); private CommandExecutor partyInfoCommand = new PartyInfoCommand();
private CommandExecutor partyHelpCommand = new PartyHelpCommand(); private CommandExecutor partyHelpCommand = new PartyHelpCommand();
private CommandExecutor partyTeleportCommand = new PtpCommand(); private CommandExecutor partyTeleportCommand = mcMMO.p.getCommand("ptp").getExecutor();
private CommandExecutor partyChatCommand = new PartyChatCommand(); private CommandExecutor partyChatCommand = mcMMO.p.getCommand("partychat").getExecutor();
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -45,8 +45,8 @@ public class PartyCommand implements CommandExecutor {
return true; return true;
} }
player = (Player) sender; mcMMOPlayer = UserManager.getPlayer(sender.getName());
mcMMOPlayer = UserManager.getPlayer(player); player = mcMMOPlayer.getPlayer();
if (args.length < 1) { if (args.length < 1) {
if (!mcMMOPlayer.inParty()) { if (!mcMMOPlayer.inParty()) {
@ -104,7 +104,7 @@ public class PartyCommand implements CommandExecutor {
} }
// Party leader commands // Party leader commands
if (!mcMMOPlayer.getParty().getLeader().equals(player.getName())) { if (!mcMMOPlayer.getParty().getLeader().equalsIgnoreCase(player.getName())) {
sender.sendMessage(LocaleLoader.getString("Party.NotOwner")); sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true; return true;
} }
@ -121,7 +121,6 @@ public class PartyCommand implements CommandExecutor {
case OWNER: case OWNER:
return partyChangeOwnerCommand.onCommand(sender, command, label, args); return partyChangeOwnerCommand.onCommand(sender, command, label, args);
case LOCK: case LOCK:
// Fallthrough
case UNLOCK: case UNLOCK:
return partyLockCommand.onCommand(sender, command, label, args); return partyLockCommand.onCommand(sender, command, label, args);
case PASSWORD: case PASSWORD:

View File

@ -12,26 +12,21 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyCreateCommand implements CommandExecutor { public class PartyCreateCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
// Fallthrough
case 3: case 3:
Party newParty = PartyManager.getParty(args[1]); Party newParty = PartyManager.getParty(args[1]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer();
// Check to see if the party exists, and if it does cancel creating a new party // Check to see if the party exists, and if it does cancel creating a new party
if (newParty != null) { if (PartyManager.checkPartyExistence(player, newParty, args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", args[1]));
return true; return true;
} }
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
// Changing parties // Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), args[1])) { if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), args[1])) {
return true; return true;

View File

@ -16,10 +16,11 @@ public class PartyDisbandCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 1: case 1:
Party playerParty = UserManager.getPlayer((Player) sender).getParty(); Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
String partyName = playerParty.getName();
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
if (!PartyManager.handlePartyChangeEvent(member, playerParty.getName(), null, EventReason.KICKED_FROM_PARTY)) { if (!PartyManager.handlePartyChangeEvent(member, partyName, null, EventReason.KICKED_FROM_PARTY)) {
return true; return true;
} }

View File

@ -11,6 +11,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.party.ShareHandler.ShareMode; import com.gmail.nossr50.party.ShareHandler.ShareMode;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyExpShareCommand implements CommandExecutor { public class PartyExpShareCommand implements CommandExecutor {
@ -25,12 +26,12 @@ public class PartyExpShareCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 2: case 2:
playerParty = UserManager.getPlayer((Player) sender).getParty(); playerParty = UserManager.getPlayer(sender.getName()).getParty();
if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) { if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) {
handleChangingShareMode(ShareMode.NONE); handleChangingShareMode(ShareMode.NONE);
} }
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) { else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even") || CommandUtils.shouldEnableToggle(args[1])) {
handleChangingShareMode(ShareMode.EQUAL); handleChangingShareMode(ShareMode.EQUAL);
} }
else { else {
@ -48,8 +49,10 @@ public class PartyExpShareCommand implements CommandExecutor {
private void handleChangingShareMode(ShareHandler.ShareMode mode) { private void handleChangingShareMode(ShareHandler.ShareMode mode) {
playerParty.setXpShareMode(mode); playerParty.setXpShareMode(mode);
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())))); member.sendMessage(changeModeMessage);
} }
} }
} }

View File

@ -26,5 +26,4 @@ public class PartyHelpCommand implements CommandExecutor {
return true; return true;
} }
} }
} }

View File

@ -21,8 +21,8 @@ public class PartyInfoCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
player = (Player) sender; McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); player = mcMMOPlayer.getPlayer();
playerParty = mcMMOPlayer.getParty(); playerParty = mcMMOPlayer.getParty();
displayPartyHeader(); displayPartyHeader();
@ -35,15 +35,19 @@ public class PartyInfoCommand implements CommandExecutor {
StringBuilder memberList = new StringBuilder(); StringBuilder memberList = new StringBuilder();
for (OfflinePlayer member : playerParty.getMembers()) { for (OfflinePlayer member : playerParty.getMembers()) {
if (playerParty.getLeader().equals(member.getName())) { String memberName = member.getName();
memberList.append(ChatColor.GOLD).append(member.getName()).append(" ");
if (playerParty.getLeader().equalsIgnoreCase(memberName)) {
memberList.append(ChatColor.GOLD);
} }
else if (member.isOnline()) { else if (member.isOnline()) {
memberList.append(ChatColor.WHITE).append(member.getName()).append(" "); memberList.append(ChatColor.WHITE);
} }
else { else {
memberList.append(ChatColor.GRAY).append(member.getName()).append(" "); memberList.append(ChatColor.GRAY);
} }
memberList.append(memberName).append(" ");
} }
return memberList.toString(); return memberList.toString();
@ -52,7 +56,7 @@ public class PartyInfoCommand implements CommandExecutor {
private void displayShareModeInfo() { private void displayShareModeInfo() {
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled(); boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled(); boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
boolean itemSharingActive = playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE; boolean itemSharingActive = (playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE);
if (!xpShareEnabled && !itemShareEnabled) { if (!xpShareEnabled && !itemShareEnabled) {
return; return;
@ -97,6 +101,6 @@ public class PartyInfoCommand implements CommandExecutor {
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header")); player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline)); player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline));
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", createMembersList())); player.sendMessage(createMembersList());
} }
} }

View File

@ -5,40 +5,27 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyInviteCommand implements CommandExecutor { public class PartyInviteCommand implements CommandExecutor {
private McMMOPlayer mcMMOTarget;
private Player target;
private McMMOPlayer mcMMOPlayer;
private Player player;
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
if (!mcMMO.p.getServer().getOfflinePlayer(args[1]).isOnline()) { McMMOPlayer mcMMOTarget = UserManager.getPlayer(args[1]);
sender.sendMessage(LocaleLoader.getString("Party.NotOnline", args[1]));
if (CommandUtils.checkPlayerExistence(sender, args[1], mcMMOTarget)) {
return true; return true;
} }
mcMMOTarget = UserManager.getPlayer(args[1]); Player target = mcMMOTarget.getPlayer();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
if (mcMMOTarget == null) { Player player = mcMMOPlayer.getPlayer();
sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
return true;
}
target = mcMMOTarget.getPlayer();
mcMMOPlayer = UserManager.getPlayer((Player) sender);
player = mcMMOPlayer.getPlayer();
if (player.equals(target)) { if (player.equals(target)) {
sender.sendMessage(LocaleLoader.getString("Party.Invite.Self")); sender.sendMessage(LocaleLoader.getString("Party.Invite.Self"));
@ -50,7 +37,7 @@ public class PartyInviteCommand implements CommandExecutor {
return true; return true;
} }
playerParty = mcMMOPlayer.getParty(); Party playerParty = mcMMOPlayer.getParty();
if (!PartyManager.canInvite(player, playerParty)) { if (!PartyManager.canInvite(player, playerParty)) {
player.sendMessage(LocaleLoader.getString("Party.Locked")); player.sendMessage(LocaleLoader.getString("Party.Locked"));

View File

@ -11,6 +11,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.party.ShareHandler.ShareMode; import com.gmail.nossr50.party.ShareHandler.ShareMode;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyItemShareCommand implements CommandExecutor { public class PartyItemShareCommand implements CommandExecutor {
@ -25,9 +26,9 @@ public class PartyItemShareCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 2: case 2:
playerParty = UserManager.getPlayer((Player) sender).getParty(); playerParty = UserManager.getPlayer(sender.getName()).getParty();
if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) { if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) {
handleChangingShareMode(ShareMode.NONE); handleChangingShareMode(ShareMode.NONE);
} }
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) { else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
@ -43,15 +44,19 @@ public class PartyItemShareCommand implements CommandExecutor {
return true; return true;
case 3: case 3:
playerParty = UserManager.getPlayer((Player) sender).getParty(); playerParty = UserManager.getPlayer(sender.getName()).getParty();
boolean toggle = false; boolean toggle = false;
if (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("on") || args[2].equalsIgnoreCase("enabled")) { if (CommandUtils.shouldEnableToggle(args[2])) {
toggle = true; toggle = true;
} }
else if (args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("off") || args[2].equalsIgnoreCase("disabled")) { else if (CommandUtils.shouldDisableToggle(args[2])) {
toggle = false; toggle = false;
} }
else {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>"));
return true;
}
if (args[1].equalsIgnoreCase("loot")) { if (args[1].equalsIgnoreCase("loot")) {
playerParty.setSharingLootDrops(toggle); playerParty.setSharingLootDrops(toggle);
@ -69,7 +74,7 @@ public class PartyItemShareCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>")); sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>"));
} }
notifyToggleItemShareCategory(args, toggle); notifyToggleItemShareCategory(args[1], toggle);
return true; return true;
default: default:
@ -82,20 +87,20 @@ public class PartyItemShareCommand implements CommandExecutor {
private void handleChangingShareMode(ShareHandler.ShareMode mode) { private void handleChangingShareMode(ShareHandler.ShareMode mode) {
playerParty.setItemShareMode(mode); playerParty.setItemShareMode(mode);
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())))); member.sendMessage(changeModeMessage);
} }
} }
private void notifyToggleItemShareCategory(String[] args, boolean toggle) { private void notifyToggleItemShareCategory(String category, boolean toggle) {
String state = "disabled"; String state = toggle ? "enabled" : "disabled";
if (toggle) { String toggleMessage = LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(category), state);
state = "enabled";
}
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(args[1]), state)); member.sendMessage(toggleMessage);
} }
} }
} }

View File

@ -5,11 +5,11 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyJoinCommand implements CommandExecutor { public class PartyJoinCommand implements CommandExecutor {
@ -25,7 +25,6 @@ public class PartyJoinCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
// Fallthrough
case 3: case 3:
// Verify target exists and is in a different party than the player // Verify target exists and is in a different party than the player
if (!canJoinParty(sender, args[1])) { if (!canJoinParty(sender, args[1])) {
@ -62,16 +61,10 @@ public class PartyJoinCommand implements CommandExecutor {
} }
private boolean canJoinParty(CommandSender sender, String targetName) { private boolean canJoinParty(CommandSender sender, String targetName) {
if (!mcMMO.p.getServer().getOfflinePlayer(targetName).isOnline()) {
sender.sendMessage(LocaleLoader.getString("Party.NotOnline", targetName));
return false;
}
mcMMOTarget = UserManager.getPlayer(targetName); mcMMOTarget = UserManager.getPlayer(targetName);
if (mcMMOTarget == null) { if (CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid")); return true;
return false;
} }
target = mcMMOTarget.getPlayer(); target = mcMMOTarget.getPlayer();
@ -81,8 +74,9 @@ public class PartyJoinCommand implements CommandExecutor {
return false; return false;
} }
player = (Player) sender; mcMMOPlayer = UserManager.getPlayer(sender.getName());
mcMMOPlayer = UserManager.getPlayer(player); player = mcMMOPlayer.getPlayer();
playerParty = mcMMOPlayer.getParty(); playerParty = mcMMOPlayer.getParty();
targetParty = mcMMOTarget.getParty(); targetParty = mcMMOTarget.getParty();

View File

@ -18,8 +18,7 @@ public class PartyKickCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
Party playerParty = UserManager.getPlayer((Player) sender).getParty(); Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]); OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]);
if (!playerParty.getMembers().contains(target)) { if (!playerParty.getMembers().contains(target)) {

View File

@ -3,11 +3,11 @@ package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyLockCommand implements CommandExecutor { public class PartyLockCommand implements CommandExecutor {
@ -15,15 +15,15 @@ public class PartyLockCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
playerParty = UserManager.getPlayer((Player) sender).getParty(); playerParty = UserManager.getPlayer(sender.getName()).getParty();
switch (args.length) { switch (args.length) {
case 1: case 1:
if (args[0].equalsIgnoreCase("lock")) { if (args[0].equalsIgnoreCase("lock")) {
lockParty(sender, command); lockParty(sender, command.getPermissionMessage());
} }
else if (args[0].equalsIgnoreCase("unlock")) { else if (args[0].equalsIgnoreCase("unlock")) {
unlockParty(sender, command); unlockParty(sender, command.getPermissionMessage());
} }
return true; return true;
@ -34,11 +34,11 @@ public class PartyLockCommand implements CommandExecutor {
return true; return true;
} }
if (args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) { if (CommandUtils.shouldEnableToggle(args[1])) {
lockParty(sender, command); lockParty(sender, command.getPermissionMessage());
} }
else if (args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) { else if (CommandUtils.shouldDisableToggle(args[1])) {
unlockParty(sender, command); unlockParty(sender, command.getPermissionMessage());
} }
else { else {
sendUsageStrings(sender); sendUsageStrings(sender);
@ -55,9 +55,9 @@ public class PartyLockCommand implements CommandExecutor {
/** /**
* Handle locking a party. * Handle locking a party.
*/ */
private void lockParty(CommandSender sender, Command command) { private void lockParty(CommandSender sender, String permissionMessage) {
if (!Permissions.partySubcommand(sender, PartySubcommandType.LOCK)) { if (!Permissions.partySubcommand(sender, PartySubcommandType.LOCK)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(permissionMessage);
return; return;
} }
@ -75,9 +75,9 @@ public class PartyLockCommand implements CommandExecutor {
* *
* @return true if party is successfully unlocked, false otherwise. * @return true if party is successfully unlocked, false otherwise.
*/ */
private void unlockParty(CommandSender sender, Command command) { private void unlockParty(CommandSender sender, String permissionMessage) {
if (!Permissions.partySubcommand(sender, PartySubcommandType.UNLOCK)) { if (!Permissions.partySubcommand(sender, PartySubcommandType.UNLOCK)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(permissionMessage);
return; return;
} }

View File

@ -12,15 +12,12 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyQuitCommand implements CommandExecutor { public class PartyQuitCommand implements CommandExecutor {
private Player player;
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 1: case 1:
player = (Player) sender; Player player = (Player) sender;
playerParty = UserManager.getPlayer(player).getParty(); Party playerParty = UserManager.getPlayer(player).getParty();
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) { if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) {
return true; return true;
@ -31,7 +28,7 @@ public class PartyQuitCommand implements CommandExecutor {
return true; return true;
default: default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "[quit|q|leave]")); sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "quit"));
return true; return true;
} }
} }

View File

@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
@ -14,33 +15,36 @@ import com.gmail.nossr50.util.player.UserManager;
public class PartyRenameCommand implements CommandExecutor { public class PartyRenameCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
String leaderName = playerParty.getLeader();
switch (args.length) { switch (args.length) {
case 2: case 2:
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Party playerParty = mcMMOPlayer.getParty();
String oldPartyName = playerParty.getName();
String newPartyName = args[1]; String newPartyName = args[1];
// This is to prevent party leaders from spamming other players with the rename message // This is to prevent party leaders from spamming other players with the rename message
if (playerParty.getName().equalsIgnoreCase(newPartyName)) { if (oldPartyName.equalsIgnoreCase(newPartyName)) {
sender.sendMessage(LocaleLoader.getString("Party.Rename.Same")); sender.sendMessage(LocaleLoader.getString("Party.Rename.Same"));
return true; return true;
} }
Player player = mcMMOPlayer.getPlayer();
Party newParty = PartyManager.getParty(newPartyName); Party newParty = PartyManager.getParty(newPartyName);
// Check to see if the party exists, and if it does cancel renaming the party // Check to see if the party exists, and if it does cancel renaming the party
if (newParty != null) { if (PartyManager.checkPartyExistence(player, newParty, newPartyName)) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", newPartyName));
return true; return true;
} }
String leaderName = playerParty.getLeader();
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
if (!PartyManager.handlePartyChangeEvent(member, playerParty.getName(), newPartyName, EventReason.CHANGED_PARTIES)) { if (!PartyManager.handlePartyChangeEvent(member, oldPartyName, newPartyName, EventReason.CHANGED_PARTIES)) {
return true; return true;
} }
if (!member.getName().equals(leaderName)) { if (!member.getName().equalsIgnoreCase(leaderName)) {
member.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", leaderName, newPartyName)); member.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", leaderName, newPartyName));
} }
} }

View File

@ -1,218 +0,0 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
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.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public class PtpCommand implements CommandExecutor {
private Player player;
private McMMOPlayer mcMMOPlayer;
private Player target;
private McMMOPlayer mcMMOTarget;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
switch (args.length) {
case 1:
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
if (args[0].equalsIgnoreCase("toggle")) {
if (!Permissions.partyTeleportToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
return togglePartyTeleportation();
}
if (args[0].equalsIgnoreCase("acceptany") || args[0].equalsIgnoreCase("acceptall")) {
if (!Permissions.partyTeleportAcceptAll(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
return acceptAnyTeleportRequest();
}
int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
long recentlyHurt = UserManager.getPlayer(player).getRecentlyHurt();
if ((recentlyHurt * Misc.TIME_CONVERSION_FACTOR + ptpCooldown * Misc.TIME_CONVERSION_FACTOR) > System.currentTimeMillis()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", ptpCooldown));
return true;
}
if (args[0].equalsIgnoreCase("accept")) {
if (!Permissions.partyTeleportAccept(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
return acceptTeleportRequest();
}
return sendTeleportRequest(args[0]);
default:
return false;
}
}
private boolean sendTeleportRequest(String targetName) {
if (!canTeleport(targetName)) {
return true;
}
if (!mcMMOTarget.getPtpConfirmRequired()) {
return handlePartyTeleportEvent(player, target);
}
mcMMOTarget.setPtpRequest(player);
mcMMOTarget.actualizePtpTimeout();
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;
}
private boolean acceptTeleportRequest() {
if (!mcMMOPlayer.hasPtpRequest()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
return true;
}
int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout();
if ((mcMMOPlayer.getPtpTimeout() + ptpRequestExpire) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
mcMMOPlayer.removePtpRequest();
player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired"));
return true;
}
target = mcMMOPlayer.getPtpRequest();
mcMMOPlayer.removePtpRequest();
if (!canTeleport(target.getName())) {
return true;
}
if (Config.getInstance().getPTPCommandWorldPermissions()) {
World targetWorld = target.getWorld();
World playerWorld = player.getWorld();
if (!Permissions.partyTeleportAllWorlds(target)) {
if (!Permissions.partyTeleportWorld(target, targetWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", targetWorld.getName()));
return true;
}
else if (targetWorld != playerWorld && !Permissions.partyTeleportWorld(target, playerWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", playerWorld.getName()));
return true;
}
}
}
return handlePartyTeleportEvent(target, player);
}
private boolean acceptAnyTeleportRequest() {
if (mcMMOPlayer.getPtpConfirmRequired()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled"));
}
mcMMOPlayer.togglePtpConfirmRequired();
return true;
}
private boolean togglePartyTeleportation() {
if (mcMMOPlayer.getPtpEnabled()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
}
mcMMOPlayer.togglePtpUse();
return true;
}
private boolean canTeleport(String targetName) {
if (!mcMMO.p.getServer().getOfflinePlayer(targetName).isOnline()) {
player.sendMessage(LocaleLoader.getString("Party.NotOnline", targetName));
return false;
}
mcMMOTarget = UserManager.getPlayer(targetName);
if (mcMMOTarget == null) {
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
return false;
}
target = mcMMOTarget.getPlayer();
if (player.equals(target)) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
return false;
}
if (!PartyManager.inSameParty(player, target)) {
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName));
return false;
}
if (!mcMMOTarget.getPtpEnabled()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", target.getName()));
return false;
}
if (target.isDead()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Dead"));
return false;
}
return true;
}
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()) {
return true;
}
player.teleport(target);
player.sendMessage(LocaleLoader.getString("Party.Teleport.Player", target.getName()));
target.sendMessage(LocaleLoader.getString("Party.Teleport.Target", player.getName()));
mcMMOPlayer.actualizeRecentlyHurt();
return true;
}
}

View File

@ -0,0 +1,34 @@
package com.gmail.nossr50.commands.party.teleport;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class PtpAcceptAnyCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.partyTeleportAcceptAll(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer();
if (mcMMOPlayer.getPtpConfirmRequired()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled"));
}
mcMMOPlayer.togglePtpConfirmRequired();
return true;
}
}

View File

@ -0,0 +1,64 @@
package com.gmail.nossr50.commands.party.teleport;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class PtpAcceptCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.partyTeleportAccept(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer();
if (!mcMMOPlayer.hasPtpRequest()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
return true;
}
if ((mcMMOPlayer.getPtpTimeout() + Config.getInstance().getPTPCommandTimeout()) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
mcMMOPlayer.removePtpRequest();
player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired"));
return true;
}
Player target = mcMMOPlayer.getPtpRequest();
mcMMOPlayer.removePtpRequest();
if (!PtpCommand.canTeleport(sender, player, target.getName())) {
return true;
}
if (Config.getInstance().getPTPCommandWorldPermissions()) {
World targetWorld = target.getWorld();
World playerWorld = player.getWorld();
if (!Permissions.partyTeleportAllWorlds(target)) {
if (!Permissions.partyTeleportWorld(target, targetWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", targetWorld.getName()));
return true;
}
else if (targetWorld != playerWorld && !Permissions.partyTeleportWorld(target, playerWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", playerWorld.getName()));
return true;
}
}
}
PtpCommand.handlePartyTeleportEvent(target, player);
return true;
}
}

View File

@ -0,0 +1,133 @@
package com.gmail.nossr50.commands.party.teleport;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
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.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public class PtpCommand implements CommandExecutor {
private static Player target;
private static McMMOPlayer mcMMOTarget;
private CommandExecutor ptpToggleCommand = new PtpToggleCommand();
private CommandExecutor ptpAcceptAnyCommand = new PtpAcceptAnyCommand();
private CommandExecutor ptpAcceptCommand = new PtpAcceptCommand();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
switch (args.length) {
case 1:
if (args[0].equalsIgnoreCase("toggle")) {
return ptpToggleCommand.onCommand(sender, command, label, args);
}
if (args[0].equalsIgnoreCase("acceptany") || args[0].equalsIgnoreCase("acceptall")) {
return ptpAcceptAnyCommand.onCommand(sender, command, label, args);
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer();
int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
if (((recentlyHurt * Misc.TIME_CONVERSION_FACTOR) + (ptpCooldown * Misc.TIME_CONVERSION_FACTOR)) > System.currentTimeMillis()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", ptpCooldown));
return true;
}
if (args[0].equalsIgnoreCase("accept")) {
return ptpAcceptCommand.onCommand(sender, command, label, args);
}
sendTeleportRequest(sender, player, args[0]);
return true;
default:
return false;
}
}
private void sendTeleportRequest(CommandSender sender, Player player, String targetName) {
if (!canTeleport(sender, player, targetName)) {
return;
}
if (!mcMMOTarget.getPtpConfirmRequired()) {
handlePartyTeleportEvent(player, target);
return;
}
mcMMOTarget.setPtpRequest(player);
mcMMOTarget.actualizePtpTimeout();
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request1", player.getName()));
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request2", Config.getInstance().getPTPCommandTimeout()));
}
protected static boolean canTeleport(CommandSender sender, Player player, String targetName) {
mcMMOTarget = UserManager.getPlayer(targetName);
if (CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return false;
}
target = mcMMOTarget.getPlayer();
if (player.equals(target)) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
return false;
}
if (!PartyManager.inSameParty(player, target)) {
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName));
return false;
}
if (!mcMMOTarget.getPtpEnabled()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", targetName));
return false;
}
if (!target.isValid()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Dead"));
return false;
}
return true;
}
protected static void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(teleportingPlayer, targetPlayer, mcMMOPlayer.getParty().getName());
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
teleportingPlayer.teleport(targetPlayer);
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Player", targetPlayer.getName()));
targetPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Target", teleportingPlayer.getName()));
mcMMOPlayer.actualizeRecentlyHurt();
}
}

View File

@ -0,0 +1,34 @@
package com.gmail.nossr50.commands.party.teleport;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class PtpToggleCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.partyTeleportToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer();
if (mcMMOPlayer.getPtpEnabled()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
}
mcMMOPlayer.togglePtpUse();
return true;
}
}

View File

@ -9,7 +9,6 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@ -17,64 +16,49 @@ import com.gmail.nossr50.util.player.UserManager;
public class InspectCommand implements CommandExecutor { public class InspectCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
switch (args.length) { switch (args.length) {
case 1: case 1:
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process. // If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false); // Temporary Profile PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile
if (!profile.isLoaded()) { if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
// TODO: Why do we care if this is a player?
if (sender instanceof Player && !Permissions.inspectOffline(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true; return true;
} }
sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", args[0])); sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", args[0]));
sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering")); sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Excavation.Listener"), profile.getSkillLevel(SkillType.EXCAVATION), profile.getSkillXpLevel(SkillType.EXCAVATION), profile.getXpToLevel(SkillType.EXCAVATION))); CommandUtils.displaySkill(sender, profile, SkillType.EXCAVATION);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Fishing.Listener"), profile.getSkillLevel(SkillType.FISHING), profile.getSkillXpLevel(SkillType.FISHING), profile.getXpToLevel(SkillType.FISHING))); CommandUtils.displaySkill(sender, profile, SkillType.FISHING);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Herbalism.Listener"), profile.getSkillLevel(SkillType.HERBALISM), profile.getSkillXpLevel(SkillType.HERBALISM), profile.getXpToLevel(SkillType.HERBALISM))); CommandUtils.displaySkill(sender, profile, SkillType.HERBALISM);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Mining.Listener"), profile.getSkillLevel(SkillType.MINING), profile.getSkillXpLevel(SkillType.MINING), profile.getXpToLevel(SkillType.MINING))); CommandUtils.displaySkill(sender, profile, SkillType.MINING);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Woodcutting.Listener"), profile.getSkillLevel(SkillType.WOODCUTTING), profile.getSkillXpLevel(SkillType.WOODCUTTING), profile.getXpToLevel(SkillType.WOODCUTTING))); CommandUtils.displaySkill(sender, profile, SkillType.WOODCUTTING);
sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat")); sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat"));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Axes.Listener"), profile.getSkillLevel(SkillType.AXES), profile.getSkillXpLevel(SkillType.AXES), profile.getXpToLevel(SkillType.AXES))); CommandUtils.displaySkill(sender, profile, SkillType.AXES);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Archery.Listener"), profile.getSkillLevel(SkillType.ARCHERY), profile.getSkillXpLevel(SkillType.ARCHERY), profile.getXpToLevel(SkillType.ARCHERY))); CommandUtils.displaySkill(sender, profile, SkillType.ARCHERY);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Swords.Listener"), profile.getSkillLevel(SkillType.SWORDS), profile.getSkillXpLevel(SkillType.SWORDS), profile.getXpToLevel(SkillType.SWORDS))); CommandUtils.displaySkill(sender, profile, SkillType.SWORDS);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Taming.Listener"), profile.getSkillLevel(SkillType.TAMING), profile.getSkillXpLevel(SkillType.TAMING), profile.getXpToLevel(SkillType.TAMING))); CommandUtils.displaySkill(sender, profile, SkillType.TAMING);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Unarmed.Listener"), profile.getSkillLevel(SkillType.UNARMED), profile.getSkillXpLevel(SkillType.UNARMED), profile.getXpToLevel(SkillType.UNARMED))); CommandUtils.displaySkill(sender, profile, SkillType.UNARMED);
sender.sendMessage(LocaleLoader.getString("Stats.Header.Misc")); sender.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Acrobatics.Listener"), profile.getSkillLevel(SkillType.ACROBATICS), profile.getSkillXpLevel(SkillType.ACROBATICS), profile.getXpToLevel(SkillType.ACROBATICS))); CommandUtils.displaySkill(sender, profile, SkillType.ACROBATICS);
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Repair.Listener"), profile.getSkillLevel(SkillType.REPAIR), profile.getSkillXpLevel(SkillType.REPAIR), profile.getXpToLevel(SkillType.REPAIR))); CommandUtils.displaySkill(sender, profile, SkillType.REPAIR);
} }
else { else {
Player target = mcMMOPlayer.getPlayer(); Player target = mcMMOPlayer.getPlayer();
if (sender instanceof Player) { if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
Player inspector = (Player) sender; return true;
if (!Misc.isNear(inspector.getLocation(), target.getLocation(), 5.0) && !Permissions.inspectFar(inspector)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}
} }
profile = mcMMOPlayer.getProfile();
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName())); sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName()));
CommandUtils.printGatheringSkills(target, profile, sender); CommandUtils.printGatheringSkills(target, sender);
CommandUtils.printCombatSkills(target, profile, sender); CommandUtils.printCombatSkills(target, sender);
CommandUtils.printMiscSkills(target, profile, sender); CommandUtils.printMiscSkills(target, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel())); sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel()));
} }

View File

@ -1,10 +1,8 @@
package com.gmail.nossr50.commands.player; package com.gmail.nossr50.commands.player;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@ -14,8 +12,8 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask; import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
@ -24,20 +22,19 @@ public class McrankCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 0: case 0:
if (!Permissions.mcrank(sender)) { if (CommandUtils.noConsoleUsage(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
if (!(sender instanceof Player)) { if (!Permissions.mcrank(sender)) {
return false; sender.sendMessage(command.getPermissionMessage());
return true;
} }
if (Config.getInstance().getUseMySQL()) { if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, sender.getName()); sqlDisplay(sender, sender.getName());
} }
else { else {
LeaderboardManager.updateLeaderboards(); // Make sure the information is up to date
flatfileDisplay(sender, sender.getName()); flatfileDisplay(sender, sender.getName());
} }
@ -52,32 +49,18 @@ public class McrankCommand implements CommandExecutor {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile if (CommandUtils.inspectOffline(sender, new PlayerProfile(args[0], false), Permissions.mcrankOffline(sender))) {
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (sender instanceof Player && !Permissions.mcrankOffline(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true; return true;
} }
} }
else { else if (CommandUtils.tooFar(sender, mcMMOPlayer.getPlayer(), Permissions.mcrankFar(sender))) {
Player target = mcMMOPlayer.getPlayer(); return true;
if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !Permissions.mcrankFar(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}
} }
if (Config.getInstance().getUseMySQL()) { if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, args[0]); sqlDisplay(sender, args[0]);
} }
else { else {
LeaderboardManager.updateLeaderboards(); // Make sure the information is up to date
flatfileDisplay(sender, args[0]); flatfileDisplay(sender, args[0]);
} }
@ -89,13 +72,15 @@ public class McrankCommand implements CommandExecutor {
} }
private void flatfileDisplay(CommandSender sender, String playerName) { private void flatfileDisplay(CommandSender sender, String playerName) {
LeaderboardManager.updateLeaderboards(); // Make sure the information is up to date
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading")); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.values()) {
int[] rankInts = LeaderboardManager.getPlayerRank(playerName, skillType); int[] rankInts = LeaderboardManager.getPlayerRank(playerName, skillType);
if (skillType.isChildSkill()) { if (!Permissions.skillEnabled(sender, skillType) || skillType.isChildSkill()) {
continue; continue;
} }
@ -119,6 +104,6 @@ public class McrankCommand implements CommandExecutor {
} }
private void sqlDisplay(CommandSender sender, String playerName) { private void sqlDisplay(CommandSender sender, String playerName) {
Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new McrankCommandAsyncTask(playerName, sender)); new McrankCommandAsyncTask(playerName, sender).runTaskAsynchronously(mcMMO.p);
} }
} }

View File

@ -7,7 +7,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@ -21,24 +20,23 @@ public class McstatsCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 0: case 0:
Player player = (Player) sender; McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); Player player = mcMMOPlayer.getPlayer();
PlayerProfile profile = mcMMOPlayer.getProfile();
player.sendMessage(LocaleLoader.getString("Stats.Own.Stats")); player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote")); player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
CommandUtils.printGatheringSkills(player, profile); CommandUtils.printGatheringSkills(player);
CommandUtils.printCombatSkills(player, profile); CommandUtils.printCombatSkills(player);
CommandUtils.printMiscSkills(player, profile); CommandUtils.printMiscSkills(player);
int powerLevelCap = Config.getInstance().getPowerLevelCap(); int powerLevelCap = Config.getInstance().getPowerLevelCap();
if (powerLevelCap != Integer.MAX_VALUE) { if (powerLevelCap != Integer.MAX_VALUE) {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Capped", mcMMOPlayer.getPowerLevel(), powerLevelCap)); player.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Capped", UserManager.getPlayer(player).getPowerLevel(), powerLevelCap));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel())); player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", UserManager.getPlayer(player).getPowerLevel()));
} }
return true; return true;

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.commands.player; package com.gmail.nossr50.commands.player;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -14,13 +13,16 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask; import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.commands.CommandUtils;
public class MctopCommand implements CommandExecutor { public class MctopCommand implements CommandExecutor {
private SkillType skill;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
boolean useMySQL = Config.getInstance().getUseMySQL(); boolean useMySQL = Config.getInstance().getUseMySQL();
switch (args.length) { switch (args.length) {
case 0: case 0:
display(1, "ALL", sender, useMySQL, command); display(1, "ALL", sender, useMySQL, command);
@ -29,42 +31,26 @@ public class MctopCommand implements CommandExecutor {
case 1: case 1:
if (StringUtils.isInt(args[0])) { if (StringUtils.isInt(args[0])) {
display(Integer.parseInt(args[0]), "ALL", sender, useMySQL, command); display(Integer.parseInt(args[0]), "ALL", sender, useMySQL, command);
} return true;
else if (SkillUtils.isSkill(args[0])) {
SkillType skill = SkillType.getSkill(args[0]);
if (skill.isChildSkill()) {
sender.sendMessage("Child skills are not yet supported by this command."); // TODO: Localize this
return true;
}
display(1, skill.toString(), sender, useMySQL, command);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
} }
if (!extractSkill(sender, args[0])) {
return true;
}
display(1, skill.toString(), sender, useMySQL, command);
return true; return true;
case 2: case 2:
if (!StringUtils.isInt(args[1])) { if (CommandUtils.isInvalidInteger(sender, args[1])) {
return false; return true;
} }
if (SkillUtils.isSkill(args[0])) { if (!extractSkill(sender, args[0])) {
SkillType skill = SkillType.getSkill(args[0]); return true;
if (skill.isChildSkill()) {
sender.sendMessage("Child skills are not yet supported by this command."); // TODO: Localize this
return true;
}
display(Integer.parseInt(args[1]), skill.toString(), sender, useMySQL, command);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
} }
display(Integer.parseInt(args[1]), skill.toString(), sender, useMySQL, command);
return true; return true;
default: default:
@ -73,28 +59,26 @@ public class MctopCommand implements CommandExecutor {
} }
private void display(int page, String skill, CommandSender sender, boolean sql, Command command) { private void display(int page, String skill, CommandSender sender, boolean sql, Command command) {
if (sql) { if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, this.skill)) {
if (skill.equalsIgnoreCase("all")) {
sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender, command);
}
else {
sqlDisplay(page, skill, sender, command);
}
}
else {
flatfileDisplay(page, skill, sender, command);
}
}
private void flatfileDisplay(int page, String skill, CommandSender sender, Command command) {
if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, SkillType.getSkill(skill))) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return; return;
} }
LeaderboardManager.updateLeaderboards(); // Make sure we have the latest information if (sql) {
if (skill.equalsIgnoreCase("all")) {
sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender);
}
else {
sqlDisplay(page, skill, sender);
}
}
else {
flatfileDisplay(page, skill, sender);
}
}
String[] info = LeaderboardManager.retrieveInfo(skill, page); private void flatfileDisplay(int page, String skill, CommandSender sender) {
LeaderboardManager.updateLeaderboards(); // Make sure we have the latest information
if (skill.equalsIgnoreCase("all")) { if (skill.equalsIgnoreCase("all")) {
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
@ -103,27 +87,44 @@ public class MctopCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill))); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
} }
int n = (page * 10) - 9; // Position int position = (page * 10) - 9;
for (String x : info) {
if (x != null) {
String digit = String.valueOf(n);
if (n < 10) { for (String playerStat : LeaderboardManager.retrieveInfo(skill, page)) {
digit = "0" + digit; if (playerStat == null) {
} continue;
String[] splitx = x.split(":");
// Format: 1. Playername - skill value
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitx[1] + " - " + ChatColor.WHITE + splitx[0]);
n++;
} }
String digit = String.valueOf(position);
if (position < 10) {
digit = "0" + digit;
}
String[] splitStat = playerStat.split(":");
// Format: 1. Playername - skill value
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitStat[1] + " - " + ChatColor.WHITE + splitStat[0]);
position++;
} }
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip")); sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
} }
private void sqlDisplay(int page, String query, CommandSender sender, Command command) { private void sqlDisplay(int page, String query, CommandSender sender) {
Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new MctopCommandAsyncTask(page, query, sender, command)); new MctopCommandAsyncTask(page, query, sender).runTaskAsynchronously(mcMMO.p);
}
private boolean extractSkill(CommandSender sender, String skillName) {
if (CommandUtils.isInvalidSkill(sender, skillName)) {
return false;
}
skill = SkillType.getSkill(skillName);
if (CommandUtils.isChildSkill(sender, skill)) {
return true;
}
return true;
} }
} }

View File

@ -24,19 +24,25 @@ public class AcrobaticsCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// DODGE // DODGE
String[] dodgeStrings = calculateAbilityDisplayValues(Acrobatics.dodgeMaxBonusLevel, Acrobatics.dodgeMaxChance); if (canDodge) {
dodgeChance = dodgeStrings[0]; String[] dodgeStrings = calculateAbilityDisplayValues(Acrobatics.dodgeMaxBonusLevel, Acrobatics.dodgeMaxChance);
dodgeChanceLucky = dodgeStrings[1]; dodgeChance = dodgeStrings[0];
dodgeChanceLucky = dodgeStrings[1];
}
// ROLL // ROLL
String[] rollStrings = calculateAbilityDisplayValues(Acrobatics.rollMaxBonusLevel, Acrobatics.rollMaxChance); if (canRoll) {
rollChance = rollStrings[0]; String[] rollStrings = calculateAbilityDisplayValues(Acrobatics.rollMaxBonusLevel, Acrobatics.rollMaxChance);
rollChanceLucky = rollStrings[1]; rollChance = rollStrings[0];
rollChanceLucky = rollStrings[1];
}
// GRACEFUL ROLL // GRACEFUL ROLL
String[] gracefulRollStrings = calculateAbilityDisplayValues(Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollMaxChance); if (canGracefulRoll) {
gracefulRollChance = gracefulRollStrings[0]; String[] gracefulRollStrings = calculateAbilityDisplayValues(Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollMaxChance);
gracefulRollChanceLucky = gracefulRollStrings[1]; gracefulRollChance = gracefulRollStrings[0];
gracefulRollChanceLucky = gracefulRollStrings[1];
}
} }
@Override @Override
@ -76,30 +82,15 @@ public class AcrobaticsCommand extends SkillCommand {
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canRoll) { if (canRoll) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", rollChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", rollChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", new Object[] { rollChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { rollChanceLucky }));
}
else {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", new Object[] { rollChance }));
}
} }
if (canGracefulRoll) { if (canGracefulRoll) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", gracefulRollChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", gracefulRollChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", new Object[] { gracefulRollChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { gracefulRollChanceLucky }));
}
else {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", new Object[] { gracefulRollChance }));
}
} }
if (canDodge) { if (canDodge) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", dodgeChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", dodgeChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", new Object[] { dodgeChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { dodgeChanceLucky }));
}
else {
player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", new Object[] { dodgeChance }));
}
} }
} }
} }

View File

@ -23,24 +23,24 @@ public class ArcheryCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// SKILL SHOT // SKILL SHOT
double bonus = (skillValue / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage; if (canSkillShot) {
double bonus = (skillValue / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage;
if (bonus > Archery.skillShotMaxBonusPercentage) { skillShotBonus = percent.format(Math.min(bonus, Archery.skillShotMaxBonusPercentage));
skillShotBonus = percent.format(Archery.skillShotMaxBonusPercentage);
}
else {
skillShotBonus = percent.format(bonus);
} }
// DAZE // DAZE
String[] dazeStrings = calculateAbilityDisplayValues(Archery.dazeMaxBonusLevel, Archery.dazeMaxBonus); if (canDaze) {
dazeChance = dazeStrings[0]; String[] dazeStrings = calculateAbilityDisplayValues(Archery.dazeMaxBonusLevel, Archery.dazeMaxBonus);
dazeChanceLucky = dazeStrings[1]; dazeChance = dazeStrings[0];
dazeChanceLucky = dazeStrings[1];
}
// RETRIEVE // RETRIEVE
String[] retrieveStrings = calculateAbilityDisplayValues(Archery.retrieveMaxBonusLevel, Archery.retrieveMaxChance); if (canRetrieve) {
retrieveChance = retrieveStrings[0]; String[] retrieveStrings = calculateAbilityDisplayValues(Archery.retrieveMaxBonusLevel, Archery.retrieveMaxChance);
retrieveChanceLucky = retrieveStrings[1]; retrieveChance = retrieveStrings[0];
retrieveChanceLucky = retrieveStrings[1];
}
} }
@Override @Override
@ -84,21 +84,11 @@ public class ArcheryCommand extends SkillCommand {
} }
if (canDaze) { if (canDaze) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", dazeChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance) + LocaleLoader.getString("Perks.lucky.bonus", dazeChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance));
}
} }
if (canRetrieve) { if (canRetrieve) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", retrieveChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance) + LocaleLoader.getString("Perks.lucky.bonus", retrieveChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance));
}
} }
} }
} }

View File

@ -8,9 +8,8 @@ import com.gmail.nossr50.util.Permissions;
public class AxesCommand extends SkillCommand { public class AxesCommand extends SkillCommand {
private String critChance; private String critChance;
private String critChanceLucky; private String critChanceLucky;
private String bonusDamage; private float bonusDamage;
private String impactDamage; private float impactDamage;
private String greaterImpactDamage;
private String skullSplitterLength; private String skullSplitterLength;
private String skullSplitterLengthEndurance; private String skullSplitterLengthEndurance;
@ -27,25 +26,27 @@ public class AxesCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// IMPACT // IMPACT
impactDamage = String.valueOf(1 + (skillValue / Axes.impactIncreaseLevel)); if (canImpact) {
greaterImpactDamage = String.valueOf(Axes.greaterImpactBonusDamage); impactDamage = 1 + (skillValue / Axes.impactIncreaseLevel);
}
// SKULL SPLITTER // SKULL SPLITTER
String[] skullSplitterStrings = calculateLengthDisplayValues(); if (canSkullSplitter) {
skullSplitterLength = skullSplitterStrings[0]; String[] skullSplitterStrings = calculateLengthDisplayValues();
skullSplitterLengthEndurance = skullSplitterStrings[1]; skullSplitterLength = skullSplitterStrings[0];
skullSplitterLengthEndurance = skullSplitterStrings[1];
}
// CRITICAL STRIKES // CRITICAL STRIKES
String[] criticalStrikeStrings = calculateAbilityDisplayValues(Axes.criticalHitMaxBonusLevel, Axes.criticalHitMaxChance); if (canCritical) {
critChance = criticalStrikeStrings[0]; String[] criticalStrikeStrings = calculateAbilityDisplayValues(Axes.criticalHitMaxBonusLevel, Axes.criticalHitMaxChance);
critChanceLucky = criticalStrikeStrings[1]; critChance = criticalStrikeStrings[0];
critChanceLucky = criticalStrikeStrings[1];
}
// AXE MASTERY // AXE MASTERY
if (skillValue >= Axes.bonusDamageMaxBonusLevel) { if (canBonusDamage) {
bonusDamage = String.valueOf(Axes.bonusDamageMaxBonus); bonusDamage = Math.min(skillValue / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus);
}
else {
bonusDamage = String.valueOf(skillValue / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus));
} }
} }
@ -104,25 +105,15 @@ public class AxesCommand extends SkillCommand {
} }
if (canGreaterImpact) { if (canGreaterImpact) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.4"), LocaleLoader.getString("Axes.Ability.Bonus.5", greaterImpactDamage))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.4"), LocaleLoader.getString("Axes.Ability.Bonus.5", Axes.greaterImpactBonusDamage)));
} }
if (canCritical) { if (canCritical) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Axes.Combat.CritChance", critChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", critChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Axes.Combat.CritChance", critChance) + LocaleLoader.getString("Perks.lucky.bonus", critChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Axes.Combat.CritChance", critChance));
}
} }
if (canSkullSplitter) { if (canSkullSplitter) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", skullSplitterLengthEndurance) : ""));
player.sendMessage(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength) + LocaleLoader.getString("Perks.activationtime.bonus", skullSplitterLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength));
}
} }
} }
} }

View File

@ -18,9 +18,11 @@ public class ExcavationCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// GIGA DRILL BREAKER // GIGA DRILL BREAKER
String gigaDrillStrings[] = calculateLengthDisplayValues(); if (canGigaDrill) {
gigaDrillBreakerLength = gigaDrillStrings[0]; String gigaDrillStrings[] = calculateLengthDisplayValues();
gigaDrillBreakerLengthEndurance = gigaDrillStrings[1]; gigaDrillBreakerLength = gigaDrillStrings[0];
gigaDrillBreakerLengthEndurance = gigaDrillStrings[1];
}
} }
@Override @Override
@ -55,12 +57,7 @@ public class ExcavationCommand extends SkillCommand {
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canGigaDrill) { if (canGigaDrill) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", gigaDrillBreakerLengthEndurance) : ""));
player.sendMessage(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength) + LocaleLoader.getString("Perks.activationtime.bonus", gigaDrillBreakerLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength));
}
} }
} }
} }

View File

@ -14,7 +14,7 @@ public class FishingCommand extends SkillCommand {
private String chanceRaining = ""; private String chanceRaining = "";
private String shakeChance; private String shakeChance;
private String shakeChanceLucky; private String shakeChanceLucky;
private String fishermansDietRank; private int fishermansDietRank;
private boolean canTreasureHunt; private boolean canTreasureHunt;
private boolean canMagicHunt; private boolean canMagicHunt;
@ -27,27 +27,32 @@ public class FishingCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
lootTier = UserManager.getPlayer(player).getFishingManager().getLootTier();
// TREASURE HUNTER // TREASURE HUNTER
double enchantChance = lootTier * AdvancedConfig.getInstance().getFishingMagicMultiplier(); if (canTreasureHunt) {
lootTier = mcMMOPlayer.getFishingManager().getLootTier();
double enchantChance = lootTier * AdvancedConfig.getInstance().getFishingMagicMultiplier();
if (player.getWorld().hasStorm()) { if (player.getWorld().hasStorm()) {
chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining"); chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining");
enchantChance = enchantChance * 1.1D; enchantChance *= 1.1D;
}
String[] treasureHunterStrings = calculateAbilityDisplayValues(enchantChance);
magicChance = treasureHunterStrings[0];
magicChanceLucky = treasureHunterStrings[1];
} }
String[] treasureHunterStrings = calculateAbilityDisplayValues(enchantChance);
magicChance = treasureHunterStrings[0];
magicChanceLucky = treasureHunterStrings[1];
// SHAKE // SHAKE
String[] shakeStrings = calculateAbilityDisplayValues(UserManager.getPlayer(player).getFishingManager().getShakeProbability()); if (canShake) {
shakeChance = shakeStrings[0]; String[] shakeStrings = calculateAbilityDisplayValues(UserManager.getPlayer(player).getFishingManager().getShakeProbability());
shakeChanceLucky = shakeStrings[1]; shakeChance = shakeStrings[0];
shakeChanceLucky = shakeStrings[1];
}
// FISHERMAN'S DIET // FISHERMAN'S DIET
fishermansDietRank = calculateRank(Fishing.fishermansDietMaxLevel, Fishing.fishermansDietRankLevel1); if (canFishermansDiet) {
fishermansDietRank = calculateRank(Fishing.fishermansDietMaxLevel, Fishing.fishermansDietRankLevel1);
}
} }
@Override @Override
@ -96,25 +101,17 @@ public class FishingCommand extends SkillCommand {
} }
if (canMagicHunt) { if (canMagicHunt) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", magicChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining + LocaleLoader.getString("Perks.lucky.bonus", magicChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining);
}
} }
if (canShake) { if (canShake) {
if (skillValue < AdvancedConfig.getInstance().getShakeUnlockLevel()) { int unlockLevel = AdvancedConfig.getInstance().getShakeUnlockLevel();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.0", AdvancedConfig.getInstance().getShakeUnlockLevel())));
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.0", unlockLevel)));
} }
else { else {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", shakeChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance) + LocaleLoader.getString("Perks.lucky.bonus", shakeChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance));
}
} }
} }

View File

@ -12,8 +12,8 @@ public class HerbalismCommand extends SkillCommand {
private String greenTerraLengthEndurance; private String greenTerraLengthEndurance;
private String greenThumbChance; private String greenThumbChance;
private String greenThumbChanceLucky; private String greenThumbChanceLucky;
private String greenThumbStage; private int greenThumbStage;
private String farmersDietRank; private int farmersDietRank;
private String doubleDropChance; private String doubleDropChance;
private String doubleDropChanceLucky; private String doubleDropChanceLucky;
private String hylianLuckChance; private String hylianLuckChance;
@ -23,12 +23,11 @@ public class HerbalismCommand extends SkillCommand {
private boolean hasHylianLuck; private boolean hasHylianLuck;
private boolean canGreenTerra; private boolean canGreenTerra;
private boolean canGreenThumbWheat; private boolean canGreenThumbPlants;
private boolean canGreenThumbBlocks; private boolean canGreenThumbBlocks;
private boolean canFarmersDiet; private boolean canFarmersDiet;
private boolean canDoubleDrop; private boolean canDoubleDrop;
private boolean canShroomThumb; private boolean canShroomThumb;
private boolean doubleDropsDisabled;
public HerbalismCommand() { public HerbalismCommand() {
super(SkillType.HERBALISM); super(SkillType.HERBALISM);
@ -37,51 +36,62 @@ public class HerbalismCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// GREEN TERRA // GREEN TERRA
String[] greenTerraStrings = calculateLengthDisplayValues(); if (canGreenTerra) {
greenTerraLength = greenTerraStrings[0]; String[] greenTerraStrings = calculateLengthDisplayValues();
greenTerraLengthEndurance = greenTerraStrings[1]; greenTerraLength = greenTerraStrings[0];
greenTerraLengthEndurance = greenTerraStrings[1];
}
// FARMERS DIET // FARMERS DIET
farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1); if (canFarmersDiet) {
farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1);
}
// GREEN THUMB // GREEN THUMB
greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageChangeLevel); if (canGreenThumbBlocks || canGreenThumbPlants) {
greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageChangeLevel);
String[] greenThumbStrings = calculateAbilityDisplayValues(Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance); String[] greenThumbStrings = calculateAbilityDisplayValues(Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance);
greenThumbChance = greenThumbStrings[0]; greenThumbChance = greenThumbStrings[0];
greenThumbChanceLucky = greenThumbStrings[1]; greenThumbChanceLucky = greenThumbStrings[1];
}
// DOUBLE DROPS // DOUBLE DROPS
String[] doubleDropStrings = calculateAbilityDisplayValues(Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance); if (canDoubleDrop) {
doubleDropChance = doubleDropStrings[0]; String[] doubleDropStrings = calculateAbilityDisplayValues(Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance);
doubleDropChanceLucky = doubleDropStrings[1]; doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
}
// HYLIAN LUCK // HYLIAN LUCK
String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance); if (hasHylianLuck) {
hylianLuckChance = hylianLuckStrings[0]; String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance);
hylianLuckChanceLucky = hylianLuckStrings[1]; hylianLuckChance = hylianLuckStrings[0];
hylianLuckChanceLucky = hylianLuckStrings[1];
}
// SHROOM THUMB // SHROOM THUMB
String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance); if (canShroomThumb) {
shroomThumbChance = shroomThumbStrings[0]; String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance);
shroomThumbChanceLucky = shroomThumbStrings[1]; shroomThumbChance = shroomThumbStrings[0];
shroomThumbChanceLucky = shroomThumbStrings[1];
}
} }
@Override @Override
protected void permissionsCheck() { protected void permissionsCheck() {
hasHylianLuck = Permissions.hylianLuck(player); hasHylianLuck = Permissions.hylianLuck(player);
canGreenTerra = Permissions.greenTerra(player); canGreenTerra = Permissions.greenTerra(player);
canGreenThumbWheat = Permissions.greenThumbPlant(player, Material.CROPS); // TODO: This isn't really accurate - they could have perms for other crops but not wheat. canGreenThumbPlants = Permissions.greenThumbPlant(player, Material.CROPS) || Permissions.greenThumbPlant(player, Material.CARROT) || Permissions.greenThumbPlant(player, Material.POTATO) || Permissions.greenThumbPlant(player, Material.NETHER_WARTS) || Permissions.greenThumbPlant(player, Material.COCOA);
canGreenThumbBlocks = (Permissions.greenThumbBlock(player, Material.DIRT) || Permissions.greenThumbBlock(player, Material.COBBLESTONE) || Permissions.greenThumbBlock(player, Material.COBBLE_WALL) || Permissions.greenThumbBlock(player, Material.SMOOTH_BRICK)); canGreenThumbBlocks = Permissions.greenThumbBlock(player, Material.DIRT) || Permissions.greenThumbBlock(player, Material.COBBLESTONE) || Permissions.greenThumbBlock(player, Material.COBBLE_WALL) || Permissions.greenThumbBlock(player, Material.SMOOTH_BRICK);
canFarmersDiet = Permissions.farmersDiet(player); canFarmersDiet = Permissions.farmersDiet(player);
canDoubleDrop = Permissions.doubleDrops(player, skill); canDoubleDrop = Permissions.doubleDrops(player, skill) && !skill.getDoubleDropsDisabled();
doubleDropsDisabled = skill.getDoubleDropsDisabled();
canShroomThumb = Permissions.shroomThumb(player); canShroomThumb = Permissions.shroomThumb(player);
} }
@Override @Override
protected boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb; return canGreenTerra || canDoubleDrop || canFarmersDiet || canGreenThumbBlocks || canGreenThumbPlants || canShroomThumb;
} }
@Override @Override
@ -92,7 +102,7 @@ public class HerbalismCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.0"), LocaleLoader.getString("Herbalism.Effect.1"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.0"), LocaleLoader.getString("Herbalism.Effect.1")));
} }
if (canGreenThumbWheat) { if (canGreenThumbPlants) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.2"), LocaleLoader.getString("Herbalism.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.2"), LocaleLoader.getString("Herbalism.Effect.3")));
} }
@ -112,37 +122,27 @@ public class HerbalismCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.12"), LocaleLoader.getString("Herbalism.Effect.13"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.12"), LocaleLoader.getString("Herbalism.Effect.13")));
} }
if (canDoubleDrop && !doubleDropsDisabled) { if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9")));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb; return canGreenTerra || canDoubleDrop || canFarmersDiet || canGreenThumbBlocks || canGreenThumbPlants || canShroomThumb;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canGreenTerra) { if (canGreenTerra) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", greenTerraLengthEndurance) : ""));
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength) + LocaleLoader.getString("Perks.activationtime.bonus", greenTerraLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength));
}
} }
if (canGreenThumbBlocks || canGreenThumbWheat) { if (canGreenThumbBlocks || canGreenThumbPlants) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", greenThumbChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance) + LocaleLoader.getString("Perks.lucky.bonus", greenThumbChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance));
}
} }
if (canGreenThumbWheat) { if (canGreenThumbPlants) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Stage", greenThumbStage)); player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Stage", greenThumbStage));
} }
@ -151,30 +151,15 @@ public class HerbalismCommand extends SkillCommand {
} }
if (hasHylianLuck) { if (hasHylianLuck) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", hylianLuckChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance) + LocaleLoader.getString("Perks.lucky.bonus", hylianLuckChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance));
}
} }
if (canShroomThumb) { if (canShroomThumb) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", shroomThumbChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + LocaleLoader.getString("Perks.lucky.bonus", shroomThumbChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance));
}
} }
if (canDoubleDrop && !doubleDropsDisabled) { if (canDoubleDrop) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance));
}
} }
} }
} }

View File

@ -6,7 +6,6 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.mining.Mining; import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class MiningCommand extends SkillCommand { public class MiningCommand extends SkillCommand {
private String doubleDropChance; private String doubleDropChance;
@ -26,7 +25,6 @@ public class MiningCommand extends SkillCommand {
private boolean canBlast; private boolean canBlast;
private boolean canBiggerBombs; private boolean canBiggerBombs;
private boolean canDemoExpert; private boolean canDemoExpert;
private boolean doubleDropsDisabled;
public MiningCommand() { public MiningCommand() {
super(SkillType.MINING); super(SkillType.MINING);
@ -35,23 +33,30 @@ public class MiningCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// SUPER BREAKER // SUPER BREAKER
String[] superBreakerStrings = calculateLengthDisplayValues(); if (canSuperBreaker) {
superBreakerLength = superBreakerStrings[0]; String[] superBreakerStrings = calculateLengthDisplayValues();
superBreakerLengthEndurance = superBreakerStrings[1]; superBreakerLength = superBreakerStrings[0];
superBreakerLengthEndurance = superBreakerStrings[1];
}
// DOUBLE DROPS // DOUBLE DROPS
String[] doubleDropStrings = calculateAbilityDisplayValues(Mining.doubleDropsMaxLevel, Mining.doubleDropsMaxChance); if (canDoubleDrop) {
doubleDropChance = doubleDropStrings[0]; String[] doubleDropStrings = calculateAbilityDisplayValues(Mining.doubleDropsMaxLevel, Mining.doubleDropsMaxChance);
doubleDropChanceLucky = doubleDropStrings[1]; doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
}
// BLAST MINING // BLAST MINING
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); if (canBlast || canDemoExpert || canBiggerBombs) {
blastMiningRank = miningManager.getBlastMiningTier(); MiningManager miningManager = mcMMOPlayer.getMiningManager();
bonusTNTDrops = miningManager.getDropMultiplier();
oreBonus = percent.format(miningManager.getOreBonus() / 30.0D); // Base received in TNT is 30% blastMiningRank = miningManager.getBlastMiningTier();
debrisReduction = percent.format(miningManager.getDebrisReduction() / 30.0D); // Base received in TNT is 30% bonusTNTDrops = miningManager.getDropMultiplier();
blastDamageDecrease = percent.format(miningManager.getBlastDamageModifier() / 100.0D); oreBonus = percent.format(miningManager.getOreBonus() / 30.0D); // Base received in TNT is 30%
blastRadiusIncrease = miningManager.getBlastRadiusModifier(); debrisReduction = percent.format(miningManager.getDebrisReduction() / 30.0D); // Base received in TNT is 30%
blastDamageDecrease = percent.format(miningManager.getBlastDamageModifier() / 100.0D);
blastRadiusIncrease = miningManager.getBlastRadiusModifier();
}
} }
@Override @Override
@ -59,14 +64,13 @@ public class MiningCommand extends SkillCommand {
canBiggerBombs = Permissions.biggerBombs(player); canBiggerBombs = Permissions.biggerBombs(player);
canBlast = Permissions.remoteDetonation(player); canBlast = Permissions.remoteDetonation(player);
canDemoExpert = Permissions.demolitionsExpertise(player); canDemoExpert = Permissions.demolitionsExpertise(player);
canDoubleDrop = Permissions.doubleDrops(player, skill); canDoubleDrop = Permissions.doubleDrops(player, skill) && !skill.getDoubleDropsDisabled();
canSuperBreaker = Permissions.superBreaker(player); canSuperBreaker = Permissions.superBreaker(player);
doubleDropsDisabled = skill.getDoubleDropsDisabled();
} }
@Override @Override
protected boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canBiggerBombs || canBlast || canDemoExpert || (canDoubleDrop && !doubleDropsDisabled) || canSuperBreaker; return canBiggerBombs || canBlast || canDemoExpert || canDoubleDrop || canSuperBreaker;
} }
@Override @Override
@ -77,7 +81,7 @@ public class MiningCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.0"), LocaleLoader.getString("Mining.Effect.1"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.0"), LocaleLoader.getString("Mining.Effect.1")));
} }
if (canDoubleDrop && !doubleDropsDisabled) { if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.2"), LocaleLoader.getString("Mining.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.2"), LocaleLoader.getString("Mining.Effect.3")));
} }
@ -96,32 +100,24 @@ public class MiningCommand extends SkillCommand {
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return canBiggerBombs || canBlast || canDemoExpert || (canDoubleDrop && !doubleDropsDisabled) || canSuperBreaker; return canBiggerBombs || canBlast || canDemoExpert || canDoubleDrop || canSuperBreaker;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canDoubleDrop && !doubleDropsDisabled) { if (canDoubleDrop) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance));
}
} }
if (canSuperBreaker) { if (canSuperBreaker) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", superBreakerLengthEndurance) : ""));
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + LocaleLoader.getString("Perks.activationtime.bonus", superBreakerLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength));
}
} }
if (canBlast) { if (canBlast) {
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank1()) { int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank1();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", AdvancedConfig.getInstance().getBlastMiningRank1())));
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", unlockLevel)));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, LocaleLoader.getString("Mining.Blast.Effect", oreBonus, debrisReduction, bonusTNTDrops))); player.sendMessage(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, LocaleLoader.getString("Mining.Blast.Effect", oreBonus, debrisReduction, bonusTNTDrops)));
@ -129,8 +125,10 @@ public class MiningCommand extends SkillCommand {
} }
if (canBiggerBombs) { if (canBiggerBombs) {
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank2()) { int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank2();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", AdvancedConfig.getInstance().getBlastMiningRank2())));
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", unlockLevel)));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease)); player.sendMessage(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease));
@ -138,8 +136,10 @@ public class MiningCommand extends SkillCommand {
} }
if (canDemoExpert) { if (canDemoExpert) {
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank4()) { int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank4();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", AdvancedConfig.getInstance().getBlastMiningRank4())));
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", unlockLevel)));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Mining.Effect.Decrease", blastDamageDecrease)); player.sendMessage(LocaleLoader.getString("Mining.Effect.Decrease", blastDamageDecrease));

View File

@ -5,13 +5,13 @@ import org.bukkit.Material;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.repair.ArcaneForging;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.repair.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class RepairCommand extends SkillCommand { public class RepairCommand extends SkillCommand {
private int arcaneForgingRank;
private String repairMasteryBonus; private String repairMasteryBonus;
private String superRepairChance; private String superRepairChance;
private String superRepairChanceLucky; private String superRepairChanceLucky;
@ -41,10 +41,10 @@ public class RepairCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// We're using pickaxes here, not the best but it works // We're using pickaxes here, not the best but it works
Repairable diamondRepairable = mcMMO.repairManager.getRepairable(Material.DIAMOND_PICKAXE.getId()); Repairable diamondRepairable = mcMMO.repairableManager.getRepairable(Material.DIAMOND_PICKAXE.getId());
Repairable goldRepairable = mcMMO.repairManager.getRepairable(Material.GOLD_PICKAXE.getId()); Repairable goldRepairable = mcMMO.repairableManager.getRepairable(Material.GOLD_PICKAXE.getId());
Repairable ironRepairable = mcMMO.repairManager.getRepairable(Material.IRON_PICKAXE.getId()); Repairable ironRepairable = mcMMO.repairableManager.getRepairable(Material.IRON_PICKAXE.getId());
Repairable stoneRepairable = mcMMO.repairManager.getRepairable(Material.STONE_PICKAXE.getId()); Repairable stoneRepairable = mcMMO.repairableManager.getRepairable(Material.STONE_PICKAXE.getId());
// TODO: This isn't really accurate - if they don't have pickaxes loaded it doesn't always mean the repair level is 0 // TODO: This isn't really accurate - if they don't have pickaxes loaded it doesn't always mean the repair level is 0
diamondLevel = (diamondRepairable == null) ? 0 : diamondRepairable.getMinimumLevel(); diamondLevel = (diamondRepairable == null) ? 0 : diamondRepairable.getMinimumLevel();
@ -53,20 +53,16 @@ public class RepairCommand extends SkillCommand {
stoneLevel = (stoneRepairable == null) ? 0 : stoneRepairable.getMinimumLevel(); stoneLevel = (stoneRepairable == null) ? 0 : stoneRepairable.getMinimumLevel();
// REPAIR MASTERY // REPAIR MASTERY
if (skillValue >= Repair.repairMasteryMaxBonusLevel) { if (canMasterRepair) {
repairMasteryBonus = percent.format(Repair.repairMasteryMaxBonus / 100D); repairMasteryBonus = percent.format(Math.min(((Repair.repairMasteryMaxBonus / Repair.repairMasteryMaxBonusLevel) * skillValue), Repair.repairMasteryMaxBonus) / 100D);
}
else {
repairMasteryBonus = percent.format(((Repair.repairMasteryMaxBonus / Repair.repairMasteryMaxBonusLevel) * skillValue) / 100D);
} }
// SUPER REPAIR // SUPER REPAIR
String[] superRepairStrings = calculateAbilityDisplayValues(Repair.superRepairMaxBonusLevel, Repair.superRepairMaxChance); if (canSuperRepair) {
superRepairChance = superRepairStrings[0]; String[] superRepairStrings = calculateAbilityDisplayValues(Repair.superRepairMaxBonusLevel, Repair.superRepairMaxChance);
superRepairChanceLucky = superRepairStrings[1]; superRepairChance = superRepairStrings[0];
superRepairChanceLucky = superRepairStrings[1];
// ARCANE FORGING }
arcaneForgingRank = Repair.getArcaneForgingRank(profile);
} }
@Override @Override
@ -122,8 +118,8 @@ public class RepairCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.6", diamondLevel), LocaleLoader.getString("Repair.Effect.7"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.6", diamondLevel), LocaleLoader.getString("Repair.Effect.7")));
} }
if (canSalvage && Salvage.salvageUnlockLevel > 0) { if (canSalvage && Repair.salvageUnlockLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Salvage.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Repair.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17")));
} }
if (canArcaneForge) { if (canArcaneForge) {
@ -143,23 +139,20 @@ public class RepairCommand extends SkillCommand {
} }
if (canSuperRepair) { if (canSuperRepair) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", superRepairChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance) + LocaleLoader.getString("Perks.lucky.bonus", superRepairChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance));
}
} }
if (canArcaneForge) { if (canArcaneForge) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Rank", arcaneForgingRank)); RepairManager repairManager = mcMMOPlayer.getRepairManager();
if (Repair.arcaneForgingEnchantLoss) { player.sendMessage(LocaleLoader.getString("Repair.Arcane.Rank", repairManager.getArcaneForgingRank()));
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : Repair.getEnchantChance(arcaneForgingRank))));
if (ArcaneForging.arcaneForgingEnchantLoss) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : repairManager.getKeepEnchantChance())));
} }
if (Repair.arcaneForgingDowngrades) { if (ArcaneForging.arcaneForgingDowngrades) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Downgrade", (arcaneBypass ? 0 : Repair.getDowngradeChance(arcaneForgingRank)))); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Downgrade", (arcaneBypass ? 0 : repairManager.getDowngradeEnchantChance())));
} }
} }
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Set;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -8,9 +9,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.child.FamilyTree;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
@ -20,10 +23,12 @@ import com.gmail.nossr50.util.skills.SkillUtils;
public abstract class SkillCommand implements CommandExecutor { public abstract class SkillCommand implements CommandExecutor {
protected SkillType skill; protected SkillType skill;
private String skillString; protected String skillName;
protected Player player; protected Player player;
protected PlayerProfile profile; protected PlayerProfile profile;
protected McMMOPlayer mcMMOPlayer;
protected float skillValue; protected float skillValue;
protected boolean isLucky; protected boolean isLucky;
protected boolean hasEndurance; protected boolean hasEndurance;
@ -31,9 +36,12 @@ public abstract class SkillCommand implements CommandExecutor {
protected DecimalFormat percent = new DecimalFormat("##0.00%"); protected DecimalFormat percent = new DecimalFormat("##0.00%");
protected DecimalFormat decimal = new DecimalFormat("##0.00"); protected DecimalFormat decimal = new DecimalFormat("##0.00");
private CommandExecutor skillGuideCommand;
public SkillCommand(SkillType skill) { public SkillCommand(SkillType skill) {
this.skill = skill; this.skill = skill;
this.skillString = StringUtils.getCapitalized(skill.toString()); skillName = SkillUtils.getSkillName(skill);
skillGuideCommand = new SkillGuideCommand(skill);
} }
@Override @Override
@ -42,86 +50,73 @@ public abstract class SkillCommand implements CommandExecutor {
return true; return true;
} }
player = (Player) sender; mcMMOPlayer = UserManager.getPlayer(sender.getName());
profile = UserManager.getPlayer(player).getProfile(); player = mcMMOPlayer.getPlayer();
if (profile == null) { switch (args.length) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); case 0:
return true; profile = mcMMOPlayer.getProfile();
skillValue = profile.getSkillLevel(skill);
isLucky = Permissions.lucky(sender, skill);
hasEndurance = (PerksUtils.handleActivationPerks(player, 0, 0) != 0);
permissionsCheck();
dataCalculations();
if (!skill.isChildSkill()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", skillName));
player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain." + StringUtils.getCapitalized(skill.toString()))));
player.sendMessage(LocaleLoader.getString("Effects.Level", (int) skillValue, profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)));
}
else {
player.sendMessage(LocaleLoader.getString("Skills.Header", skillName + " " + LocaleLoader.getString("Skills.Child")));
player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain.Child")));
player.sendMessage(LocaleLoader.getString("Effects.Child", (int) skillValue));
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Skills.Parents")));
Set<SkillType> parents = FamilyTree.getParents(skill);
for (SkillType parent : parents) {
player.sendMessage(SkillUtils.getSkillName(parent) + " - " + LocaleLoader.getString("Effects.Level", profile.getSkillLevel(parent), profile.getSkillXpLevel(parent), profile.getXpToLevel(parent)));
}
}
if (effectsHeaderPermissions()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));
}
effectsDisplay();
if (statsHeaderPermissions()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));
}
statsDisplay();
player.sendMessage(LocaleLoader.getString("Guides.Available", skillName, skillName.toLowerCase()));
return true;
default:
return skillGuideCommand.onCommand(sender, command, label, args);
} }
skillValue = profile.getSkillLevel(skill);
isLucky = Permissions.lucky(sender, skill);
hasEndurance = (Permissions.twelveSecondActivationBoost(sender) || Permissions.eightSecondActivationBoost(sender) || Permissions.fourSecondActivationBoost(sender));
dataCalculations();
permissionsCheck();
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString(skillString + ".SkillName")));
if (!skill.isChildSkill()) {
player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain." + skillString)));
player.sendMessage(LocaleLoader.getString("Effects.Level", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)));
}
if (effectsHeaderPermissions()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));
}
effectsDisplay();
if (statsHeaderPermissions()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));
}
statsDisplay();
return SkillGuideCommand.grabGuidePageForSkill(skill, player, args);
} }
protected String calculateRank(int maxLevel, int rankChangeLevel) { protected int calculateRank(int maxLevel, int rankChangeLevel) {
if (skillValue >= maxLevel) { return Math.min((int) skillValue, maxLevel) / rankChangeLevel;
return String.valueOf(maxLevel / rankChangeLevel);
}
return String.valueOf((int) (skillValue / rankChangeLevel));
} }
protected String[] calculateAbilityDisplayValues(double chance) { protected String[] calculateAbilityDisplayValues(double chance) {
if (isLucky) { String[] displayValues = new String[2];
double luckyChance = chance * 1.3333D;
if (luckyChance >= 100D) { displayValues[0] = percent.format(Math.min(chance, 100.0D) / 100.0D);
return new String[] { percent.format(chance / 100.0D), percent.format(1.0D) }; displayValues[1] = isLucky ? percent.format(Math.min(chance * 1.3333D, 100.0D) / 100.0D) : null;
}
return new String[] { percent.format(chance / 100.0D), percent.format(luckyChance / 100.0D) }; return displayValues;
}
return new String[] { percent.format(chance / 100.0D), null };
} }
protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) { protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) {
double abilityChance; return calculateAbilityDisplayValues((maxChance / maxBonusLevel) * Math.min(skillValue, maxBonusLevel));
if (skillValue >= maxBonusLevel) {
abilityChance = maxChance;
}
else {
abilityChance = (maxChance / maxBonusLevel) * skillValue;
}
if (isLucky) {
double luckyChance = abilityChance * 1.3333D;
if (luckyChance >= 100D) {
return new String[] { percent.format(abilityChance / 100.0D), percent.format(1.0D) };
}
return new String[] { percent.format(abilityChance / 100.0D), percent.format(luckyChance / 100.0D) };
}
return new String[] { percent.format(abilityChance / 100.0D), null };
} }
protected String[] calculateLengthDisplayValues() { protected String[] calculateLengthDisplayValues() {
@ -130,9 +125,7 @@ public abstract class SkillCommand implements CommandExecutor {
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength); int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
if (maxLength != 0) { if (maxLength != 0) {
if (length > maxLength) { length = Math.min(length, maxLength);
length = maxLength;
}
} }
return new String[] { String.valueOf(length), String.valueOf(enduranceLength) }; return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
@ -141,7 +134,7 @@ public abstract class SkillCommand implements CommandExecutor {
protected void luckyEffectsDisplay() { protected void luckyEffectsDisplay() {
if (isLucky) { if (isLucky) {
String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", SkillUtils.getSkillName(skill)))); player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", skillName)));
} }
} }

View File

@ -2,106 +2,89 @@ package com.gmail.nossr50.commands.skills;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.entity.Player; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public final class SkillGuideCommand { public class SkillGuideCommand implements CommandExecutor {
private SkillGuideCommand() {} private String header;
private String[] guide;
public static int getTotalPageNumber(String address) { private String invalidPage;
String[] addressSplit = LocaleLoader.getString(address).split("\n");
if (addressSplit.length <= 8) { public SkillGuideCommand(SkillType skillType) {
return 1; header = LocaleLoader.getString("Guides.Header", SkillUtils.getSkillName(skillType));
} guide = LocaleLoader.getString("Guides." + StringUtils.getCapitalized(skillType.toString())).split("\n");
return (addressSplit.length / 8) + 1; invalidPage = LocaleLoader.getString("Guides.Page.Invalid");
} }
public static ArrayList<String> grabPageContents(String header, String address, int pagenum) { @Override
int pageIndexStart = 0; public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Determine what string to start at
if (pagenum > 1) {
pageIndexStart = 8 * (pagenum - 1);
}
ArrayList<String> allStrings = new ArrayList<String>();
String split[] = LocaleLoader.getString(address).split("\n");
allStrings.add(LocaleLoader.getString("Guides.Header", header));
// Add targeted strings
while (allStrings.size() < 9) {
if (pageIndexStart + allStrings.size() > split.length) {
allStrings.add("");
}
else {
allStrings.add(split[pageIndexStart + allStrings.size() - 1]);
}
}
allStrings.add("Page " + pagenum + " of " + getTotalPageNumber(address));
return allStrings;
}
public static void clearChat(Player player) {
player.sendMessage("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); // Dear god why?
}
public static boolean grabGuidePageForSkill(SkillType skilltype, Player player, String[] args) {
String skillName = skilltype.toString();
String capitalized = StringUtils.getCapitalized(skillName);
String localized = SkillUtils.getSkillName(skilltype);
player.sendMessage(LocaleLoader.getString("Guides.Available", localized, localized.toLowerCase()));
String address = "Guides." + capitalized;
switch (args.length) { switch (args.length) {
case 0:
// We have to specify this, otherwise we get the usage string every time we call /skillname...
return true;
case 1: case 1:
if (!args[0].equals("?")) { if (!args[0].equals("?")) {
return false; return false;
} }
SkillGuideCommand.clearChat(player); sendGuide(sender, 1);
for (String target : SkillGuideCommand.grabPageContents(localized, address, 1)) {
player.sendMessage(target);
}
return true; return true;
case 2: case 2:
int totalPages = SkillGuideCommand.getTotalPageNumber(address); int totalPages = getTotalPageNumber();
if (!StringUtils.isInt(args[1])) { if (!StringUtils.isInt(args[1])) {
player.sendMessage(LocaleLoader.getString("Guides.Page.Invalid")); sender.sendMessage(invalidPage);
return true; return true;
} }
if (Integer.parseInt(args[1]) > totalPages) { int pageNumber = Integer.parseInt(args[1]);
player.sendMessage(LocaleLoader.getString("Guides.Page.OutOfRange", totalPages));
if (pageNumber > totalPages || pageNumber <= 0) {
sender.sendMessage(LocaleLoader.getString("Guides.Page.OutOfRange", totalPages));
return true; return true;
} }
SkillGuideCommand.clearChat(player); sendGuide(sender, pageNumber);
for (String target : SkillGuideCommand.grabPageContents(localized, address, Integer.parseInt(args[1]))) {
player.sendMessage(target);
}
return true; return true;
default: default:
return false; return false;
} }
} }
private int getTotalPageNumber() {
return (int) Math.ceil(guide.length / 8.0);
}
private void sendGuide(CommandSender sender, int pageNumber) {
for (String target : grabPageContents(pageNumber)) {
sender.sendMessage(target);
}
}
private ArrayList<String> grabPageContents(int pagenum) {
int pageIndexStart = 8 * (pagenum - 1); // Determine what string to start at
ArrayList<String> allStrings = new ArrayList<String>();
allStrings.add(header);
// Add targeted strings
while (allStrings.size() < 9) {
if (pageIndexStart + allStrings.size() > guide.length) {
allStrings.add("");
}
else {
allStrings.add(guide[pageIndexStart + (allStrings.size() - 1)]);
}
}
allStrings.add("Page " + pagenum + " of " + getTotalPageNumber());
return allStrings;
}
} }

View File

@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.smelting.Smelting; import com.gmail.nossr50.skills.smelting.Smelting;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class SmeltingCommand extends SkillCommand { public class SmeltingCommand extends SkillCommand {
private String burnTimeModifier; private String burnTimeModifier;
@ -14,8 +13,6 @@ public class SmeltingCommand extends SkillCommand {
private String fluxMiningChance; private String fluxMiningChance;
private String fluxMiningChanceLucky; private String fluxMiningChanceLucky;
private int vanillaXPModifier;
private boolean canFuelEfficiency; private boolean canFuelEfficiency;
private boolean canSecondSmelt; private boolean canSecondSmelt;
private boolean canFluxMine; private boolean canFluxMine;
@ -28,20 +25,23 @@ public class SmeltingCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// FUEL EFFICIENCY // FUEL EFFICIENCY
burnTimeModifier = decimal.format(1 + ((skillValue / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier)); if (canFuelEfficiency) {
burnTimeModifier = decimal.format(1 + ((skillValue / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier));
}
// SECOND SMELT // SECOND SMELT
String[] secondSmeltStrings = calculateAbilityDisplayValues(Smelting.secondSmeltMaxLevel, Smelting.secondSmeltMaxChance); if (canSecondSmelt) {
secondSmeltChance = secondSmeltStrings[0]; String[] secondSmeltStrings = calculateAbilityDisplayValues(Smelting.secondSmeltMaxLevel, Smelting.secondSmeltMaxChance);
secondSmeltChanceLucky = secondSmeltStrings[1]; secondSmeltChance = secondSmeltStrings[0];
secondSmeltChanceLucky = secondSmeltStrings[1];
}
// FLUX MINING // FLUX MINING
String[] fluxMiningStrings = calculateAbilityDisplayValues(Smelting.fluxMiningChance); if (canFluxMine) {
fluxMiningChance = fluxMiningStrings[0]; String[] fluxMiningStrings = calculateAbilityDisplayValues(Smelting.fluxMiningChance);
fluxMiningChanceLucky = fluxMiningStrings[1]; fluxMiningChance = fluxMiningStrings[0];
fluxMiningChanceLucky = fluxMiningStrings[1];
// VANILLA XP BOOST }
vanillaXPModifier = UserManager.getPlayer(player).getSmeltingManager().getVanillaXpMultiplier();
} }
@Override @Override
@ -90,20 +90,17 @@ public class SmeltingCommand extends SkillCommand {
} }
if (canSecondSmelt) { if (canSecondSmelt) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", secondSmeltChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance) + LocaleLoader.getString("Perks.lucky.bonus", secondSmeltChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance));
}
} }
if (canVanillaXPBoost) { if (canVanillaXPBoost) {
if (skillValue < AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level()) { int unlockLevel = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level())));
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", unlockLevel)));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.VanillaXPBoost", vanillaXPModifier)); player.sendMessage(LocaleLoader.getString("Smelting.Ability.VanillaXPBoost", mcMMOPlayer.getSmeltingManager().getVanillaXpMultiplier()));
} }
} }
@ -111,11 +108,8 @@ public class SmeltingCommand extends SkillCommand {
if (skillValue < Smelting.fluxMiningUnlockLevel) { if (skillValue < Smelting.fluxMiningUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.1", Smelting.fluxMiningUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.1", Smelting.fluxMiningUnlockLevel)));
} }
else if (isLucky) {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance) + LocaleLoader.getString("Perks.lucky.bonus", fluxMiningChanceLucky));
}
else { else {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance)); player.sendMessage(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", fluxMiningChanceLucky) : ""));
} }
} }
} }

View File

@ -8,7 +8,7 @@ import com.gmail.nossr50.util.Permissions;
public class SwordsCommand extends SkillCommand { public class SwordsCommand extends SkillCommand {
private String counterAttackChance; private String counterAttackChance;
private String counterAttackChanceLucky; private String counterAttackChanceLucky;
private String bleedLength; private int bleedLength;
private String bleedChance; private String bleedChance;
private String bleedChanceLucky; private String bleedChanceLucky;
private String serratedStrikesLength; private String serratedStrikesLength;
@ -25,26 +25,27 @@ public class SwordsCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// SERRATED STRIKES // SERRATED STRIKES
String[] serratedStrikesStrings = calculateLengthDisplayValues(); if (canSerratedStrike) {
serratedStrikesLength = serratedStrikesStrings[0]; String[] serratedStrikesStrings = calculateLengthDisplayValues();
serratedStrikesLengthEndurance = serratedStrikesStrings[1]; serratedStrikesLength = serratedStrikesStrings[0];
serratedStrikesLengthEndurance = serratedStrikesStrings[1];
}
// BLEED // BLEED
if (skillValue >= Swords.bleedMaxBonusLevel) { if (canBleed) {
bleedLength = String.valueOf(Swords.bleedMaxTicks); bleedLength = (skillValue >= Swords.bleedMaxBonusLevel) ? Swords.bleedMaxTicks : Swords.bleedBaseTicks;
}
else {
bleedLength = String.valueOf(Swords.bleedBaseTicks);
}
String[] bleedStrings = calculateAbilityDisplayValues(Swords.bleedMaxBonusLevel, Swords.bleedMaxChance); String[] bleedStrings = calculateAbilityDisplayValues(Swords.bleedMaxBonusLevel, Swords.bleedMaxChance);
bleedChance = bleedStrings[0]; bleedChance = bleedStrings[0];
bleedChanceLucky = bleedStrings[1]; bleedChanceLucky = bleedStrings[1];
}
// COUNTER ATTACK // COUNTER ATTACK
String[] counterAttackStrings = calculateAbilityDisplayValues(Swords.counterAttackMaxBonusLevel, Swords.counterAttackMaxChance); if (canCounter) {
counterAttackChance = counterAttackStrings[0]; String[] counterAttackStrings = calculateAbilityDisplayValues(Swords.counterAttackMaxBonusLevel, Swords.counterAttackMaxChance);
counterAttackChanceLucky = counterAttackStrings[1]; counterAttackChance = counterAttackStrings[0];
counterAttackChanceLucky = counterAttackStrings[1];
}
} }
@Override @Override
@ -85,33 +86,17 @@ public class SwordsCommand extends SkillCommand {
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canCounter) { if (canCounter) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", counterAttackChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance) + LocaleLoader.getString("Perks.lucky.bonus", counterAttackChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance));
}
} }
if (canBleed) { if (canBleed) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Length", bleedLength)); player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Length", bleedLength));
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Note")); player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Note"));
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", bleedChanceLucky) : ""));
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance) + LocaleLoader.getString("Perks.lucky.bonus", bleedChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance));
}
} }
if (canSerratedStrike) { if (canSerratedStrike) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", serratedStrikesLengthEndurance) : ""));
player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength) + LocaleLoader.getString("Perks.activationtime.bonus", serratedStrikesLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength));
}
} }
} }
} }

View File

@ -26,9 +26,11 @@ public class TamingCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
String[] goreStrings = calculateAbilityDisplayValues(Taming.goreMaxBonusLevel, Taming.goreMaxChance); if (canGore) {
goreChance = goreStrings[0]; String[] goreStrings = calculateAbilityDisplayValues(Taming.goreMaxBonusLevel, Taming.goreMaxChance);
goreChanceLucky = goreStrings[1]; goreChance = goreStrings[0];
goreChanceLucky = goreStrings[1];
}
} }
@Override @Override
@ -154,12 +156,7 @@ public class TamingCommand extends SkillCommand {
} }
if (canGore) { if (canGore) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", goreChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance) + LocaleLoader.getString("Perks.lucky.bonus", goreChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance));
}
} }
} }
} }

View File

@ -14,7 +14,7 @@ public class UnarmedCommand extends SkillCommand {
private String disarmChanceLucky; private String disarmChanceLucky;
private String ironGripChance; private String ironGripChance;
private String ironGripChanceLucky; private String ironGripChanceLucky;
private String ironArmBonus; private int ironArmBonus;
private boolean canBerserk; private boolean canBerserk;
private boolean canDisarm; private boolean canDisarm;
@ -29,32 +29,37 @@ public class UnarmedCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// BERSERK // BERSERK
String[] berserkStrings = calculateLengthDisplayValues(); if (canBerserk) {
berserkLength = berserkStrings[0]; String[] berserkStrings = calculateLengthDisplayValues();
berserkLengthEndurance = berserkStrings[1]; berserkLength = berserkStrings[0];
berserkLengthEndurance = berserkStrings[1];
}
// DISARM // DISARM
String[] disarmStrings = calculateAbilityDisplayValues(Unarmed.disarmMaxBonusLevel, Unarmed.disarmMaxChance); if (canDisarm) {
disarmChance = disarmStrings[0]; String[] disarmStrings = calculateAbilityDisplayValues(Unarmed.disarmMaxBonusLevel, Unarmed.disarmMaxChance);
disarmChanceLucky = disarmStrings[1]; disarmChance = disarmStrings[0];
disarmChanceLucky = disarmStrings[1];
}
// DEFLECT // DEFLECT
String[] deflectStrings = calculateAbilityDisplayValues(Unarmed.deflectMaxBonusLevel, Unarmed.deflectMaxChance); if (canDeflect) {
deflectChance = deflectStrings[0]; String[] deflectStrings = calculateAbilityDisplayValues(Unarmed.deflectMaxBonusLevel, Unarmed.deflectMaxChance);
deflectChanceLucky = deflectStrings[1]; deflectChance = deflectStrings[0];
deflectChanceLucky = deflectStrings[1];
}
// IRON ARM // IRON ARM
if (skillValue >= ((Unarmed.ironArmMaxBonusDamage - 3) * Unarmed.ironArmIncreaseLevel)) { if (canBonusDamage) {
ironArmBonus = String.valueOf(Unarmed.ironArmMaxBonusDamage); ironArmBonus = Math.min(3 + ((int) skillValue / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
}
else {
ironArmBonus = String.valueOf(3 + (skillValue / Unarmed.ironArmIncreaseLevel));
} }
// IRON GRIP // IRON GRIP
String[] ironGripStrings = calculateAbilityDisplayValues(Unarmed.ironGripMaxBonusLevel, Unarmed.ironGripMaxChance); if (canIronGrip) {
ironGripChance = ironGripStrings[0]; String[] ironGripStrings = calculateAbilityDisplayValues(Unarmed.ironGripMaxBonusLevel, Unarmed.ironGripMaxChance);
ironGripChanceLucky = ironGripStrings[1]; ironGripChance = ironGripStrings[0];
ironGripChanceLucky = ironGripStrings[1];
}
} }
@Override @Override
@ -108,39 +113,19 @@ public class UnarmedCommand extends SkillCommand {
} }
if (canDeflect) { if (canDeflect) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", deflectChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance) + LocaleLoader.getString("Perks.lucky.bonus", deflectChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance));
}
} }
if (canDisarm) { if (canDisarm) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", disarmChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance) + LocaleLoader.getString("Perks.lucky.bonus", disarmChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance));
}
} }
if (canIronGrip) { if (canIronGrip) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", ironGripChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance) + LocaleLoader.getString("Perks.lucky.bonus", ironGripChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance));
}
} }
if (canBerserk) { if (canBerserk) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", berserkLengthEndurance) : ""));
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength) + LocaleLoader.getString("Perks.activationtime.bonus", berserkLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength));
}
} }
} }
} }

View File

@ -15,7 +15,6 @@ public class WoodcuttingCommand extends SkillCommand {
private boolean canTreeFell; private boolean canTreeFell;
private boolean canLeafBlow; private boolean canLeafBlow;
private boolean canDoubleDrop; private boolean canDoubleDrop;
private boolean doubleDropsDisabled;
public WoodcuttingCommand() { public WoodcuttingCommand() {
super(SkillType.WOODCUTTING); super(SkillType.WOODCUTTING);
@ -24,27 +23,30 @@ public class WoodcuttingCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
// TREE FELLER // TREE FELLER
String[] treeFellerStrings = calculateLengthDisplayValues(); if (canTreeFell) {
treeFellerLength = treeFellerStrings[0]; String[] treeFellerStrings = calculateLengthDisplayValues();
treeFellerLengthEndurance = treeFellerStrings[1]; treeFellerLength = treeFellerStrings[0];
treeFellerLengthEndurance = treeFellerStrings[1];
}
// DOUBLE DROPS // DOUBLE DROPS
String[] doubleDropStrings = calculateAbilityDisplayValues(Woodcutting.doubleDropsMaxLevel, Woodcutting.doubleDropsMaxChance); if (canDoubleDrop) {
doubleDropChance = doubleDropStrings[0]; String[] doubleDropStrings = calculateAbilityDisplayValues(Woodcutting.doubleDropsMaxLevel, Woodcutting.doubleDropsMaxChance);
doubleDropChanceLucky = doubleDropStrings[1]; doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
}
} }
@Override @Override
protected void permissionsCheck() { protected void permissionsCheck() {
canTreeFell = Permissions.treeFeller(player); canTreeFell = Permissions.treeFeller(player);
canDoubleDrop = Permissions.doubleDrops(player, skill); canDoubleDrop = Permissions.doubleDrops(player, skill) && !skill.getDoubleDropsDisabled();
canLeafBlow = Permissions.leafBlower(player); canLeafBlow = Permissions.leafBlower(player);
doubleDropsDisabled = skill.getDoubleDropsDisabled();
} }
@Override @Override
protected boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return (canDoubleDrop && !doubleDropsDisabled) || canLeafBlow || canTreeFell; return canDoubleDrop || canLeafBlow || canTreeFell;
} }
@Override @Override
@ -59,14 +61,14 @@ public class WoodcuttingCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3")));
} }
if (canDoubleDrop && !doubleDropsDisabled) { if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5")));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return (canDoubleDrop && !doubleDropsDisabled) || canLeafBlow || canTreeFell; return canDoubleDrop || canLeafBlow || canTreeFell;
} }
@Override @Override
@ -82,22 +84,12 @@ public class WoodcuttingCommand extends SkillCommand {
} }
} }
if (canDoubleDrop && !doubleDropsDisabled) { if (canDoubleDrop) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky) : ""));
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance));
}
} }
if (canTreeFell) { if (canTreeFell) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", treeFellerLengthEndurance) : ""));
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength) + LocaleLoader.getString("Perks.activationtime.bonus", treeFellerLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength));
}
} }
} }
} }

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.spout;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.spout.SpoutConfig; import com.gmail.nossr50.config.spout.SpoutConfig;
@ -28,7 +27,7 @@ public abstract class SpoutCommand implements CommandExecutor {
return true; return true;
} }
playerProfile = UserManager.getPlayer((Player) sender).getProfile(); playerProfile = UserManager.getPlayer(sender.getName()).getProfile();
spoutHud = playerProfile.getSpoutHud(); spoutHud = playerProfile.getSpoutHud();
if (spoutHud == null) { if (spoutHud == null) {

View File

@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class XplockCommand extends SpoutCommand { public class XplockCommand extends SpoutCommand {
@ -22,25 +23,23 @@ public class XplockCommand extends SpoutCommand {
@Override @Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) { protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
if (args[0].equalsIgnoreCase("on")) { if (CommandUtils.shouldEnableToggle(args[0])) {
lockXpBar(sender, spoutHud.getLastGained()); lockXpBar(sender, spoutHud.getLastGained());
return true; return true;
} }
if (args[0].equalsIgnoreCase("off")) { if (CommandUtils.shouldDisableToggle(args[0])) {
unlockXpBar(sender); unlockXpBar(sender);
return true; return true;
} }
if (!SkillUtils.isSkill(args[0])) { if (CommandUtils.isInvalidSkill(sender, args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true; return true;
} }
SkillType skill = SkillType.getSkill(args[0]); SkillType skill = SkillType.getSkill(args[0]);
if (skill.isChildSkill()) { if (CommandUtils.isChildSkill(sender, skill)) {
sender.sendMessage("Child skills are not yet supported by this command."); // TODO: Localize this
return true; return true;
} }

View File

@ -20,6 +20,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
/* GENERAL */ /* GENERAL */
public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); } public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); }
public int getEnchantBuff() { return config.getInt("Skills.General.Ability_EnchantBuff", 5); }
/* ACROBATICS */ /* ACROBATICS */
public double getDodgeChanceMax() { return config.getDouble("Skills.Acrobatics.Dodge_ChanceMax", 20.0D); } public double getDodgeChanceMax() { return config.getDouble("Skills.Acrobatics.Dodge_ChanceMax", 20.0D); }
@ -178,6 +179,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
public int getRepairMasteryMaxLevel() { return config.getInt("Skills.Repair.RepairMastery_MaxBonusLevel", 1000); } public int getRepairMasteryMaxLevel() { return config.getInt("Skills.Repair.RepairMastery_MaxBonusLevel", 1000); }
public double getSuperRepairChanceMax() { return config.getDouble("Skills.Repair.SuperRepair_ChanceMax", 100.0D); } public double getSuperRepairChanceMax() { return config.getDouble("Skills.Repair.SuperRepair_ChanceMax", 100.0D); }
public int getSuperRepairMaxLevel() { return config.getInt("Skills.Repair.SuperRepair_MaxBonusLevel", 1000); } public int getSuperRepairMaxLevel() { return config.getInt("Skills.Repair.SuperRepair_MaxBonusLevel", 1000); }
public int getSalvageUnlockLevel() { return config.getInt("Skills.Repair.Salvage_UnlockLevel", 600); }
/* Arcane Forging */ /* Arcane Forging */
public boolean getArcaneForgingDowngradeEnabled() { return config.getBoolean("Skills.Repair.Arcane_Forging.Downgrades.Enabled", true); } public boolean getArcaneForgingDowngradeEnabled() { return config.getBoolean("Skills.Repair.Arcane_Forging.Downgrades.Enabled", true); }

View File

@ -101,9 +101,12 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getEntityModsEnabled() { return config.getBoolean("Mods.Entity_Mods_Enabled", false); } public boolean getEntityModsEnabled() { return config.getBoolean("Mods.Entity_Mods_Enabled", false); }
/* Items */ /* Items */
public int getChimaeraCost() { return config.getInt("Items.Chimaera_Wing.Feather_Cost", 10); } public int getChimaeraUseCost() { return config.getInt("Items.Chimaera_Wing.Use_Cost", 1); }
public int getChimaeraRecipeCost() { return config.getInt("Items.Chimaera_Wing.Recipe_Cost", 5); }
public int getChimaeraItemId() { return config.getInt("Items.Chimaera_Wing.Item_ID", 288); } public int getChimaeraItemId() { return config.getInt("Items.Chimaera_Wing.Item_ID", 288); }
public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); } public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); }
public boolean getChimaeraPreventUseUnderground() { return config.getBoolean("Items.Chimaera_Wing.Prevent_Use_Underground", true); }
public int getChimaeraCooldown() { return config.getInt("Items.Chimaera_Wing.Cooldown", 240); }
/* Particles */ /* Particles */
public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); } public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }
@ -183,9 +186,7 @@ public class Config extends AutoUpdateConfigLoader {
/* Repair */ /* Repair */
public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); } public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); }
public int getRepairAnvilId() { return config.getInt("Skills.Repair.Anvil_ID", 42); } public int getRepairAnvilId() { return config.getInt("Skills.Repair.Anvil_ID", 42); }
public boolean getSalvageEnabled() { return config.getBoolean("Skills.Repair.Salvage_enabled", true); }
public int getSalvageAnvilId() { return config.getInt("Skills.Repair.Salvage_Anvil_ID", 41); } public int getSalvageAnvilId() { return config.getInt("Skills.Repair.Salvage_Anvil_ID", 41); }
public int getSalvageUnlockLevel() { return config.getInt("Skills.Repair.Salvage_UnlockLevel", 600); }
public boolean getSalvageTools() { return config.getBoolean("Skills.Repair.Salvage_tools", true); } public boolean getSalvageTools() { return config.getBoolean("Skills.Repair.Salvage_tools", true); }
public boolean getSalvageArmor() { return config.getBoolean("Skills.Repair.Salvage_armor", true); } public boolean getSalvageArmor() { return config.getBoolean("Skills.Repair.Salvage_armor", true); }
@ -199,8 +200,6 @@ public class Config extends AutoUpdateConfigLoader {
public int getTamingCOTWOcelotCost() { return config.getInt("Skills.Taming.Call_Of_The_Wild.Fish_Required", 10); } public int getTamingCOTWOcelotCost() { return config.getInt("Skills.Taming.Call_Of_The_Wild.Fish_Required", 10); }
/* Woodcutting */ /* Woodcutting */
public boolean getWoodcuttingRequiresTool() { return config.getBoolean("Skills.Woodcutting.Requires_Axe", true); }
public int getWoodcuttingXPOak() { return config.getInt("Experience.Woodcutting.Oak", 70); } public int getWoodcuttingXPOak() { return config.getInt("Experience.Woodcutting.Oak", 70); }
public int getWoodcuttingXPBirch() { return config.getInt("Experience.Woodcutting.Birch", 90); } public int getWoodcuttingXPBirch() { return config.getInt("Experience.Woodcutting.Birch", 90); }
public int getWoodcuttingXPSpruce() { return config.getInt("Experience.Woodcutting.Spruce", 80); } public int getWoodcuttingXPSpruce() { return config.getInt("Experience.Woodcutting.Spruce", 80); }

View File

@ -10,17 +10,13 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.database.DatabaseUpdateType; import com.gmail.nossr50.datatypes.database.DatabaseUpdateType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.spout.huds.McMMOHud;
import com.gmail.nossr50.runnables.database.SQLReconnectTask; import com.gmail.nossr50.runnables.database.SQLReconnectTask;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.spout.SpoutUtils;
public final class DatabaseManager { public final class DatabaseManager {
private static String connectionString; private static String connectionString;
@ -340,7 +336,7 @@ public final class DatabaseManager {
if (connection != null && !connection.isClosed()) { if (connection != null && !connection.isClosed()) {
// Schedule a database save if we really had an outage // Schedule a database save if we really had an outage
if (reconnectAttempt > 1) { if (reconnectAttempt > 1) {
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new SQLReconnectTask(), 5); new SQLReconnectTask().runTaskLater(mcMMO.p, 5);
} }
nextReconnectTimestamp = 0; nextReconnectTimestamp = 0;
reconnectAttempt = 0; reconnectAttempt = 0;
@ -502,7 +498,7 @@ public final class DatabaseManager {
continue; continue;
} }
profileCleanup(playerName); Misc.profileCleanup(playerName);
purgedUsers++; purgedUsers++;
} }
@ -524,36 +520,13 @@ public final class DatabaseManager {
continue; continue;
} }
profileCleanup(playerName); Misc.profileCleanup(playerName);
purgedUsers++; purgedUsers++;
} }
mcMMO.p.getLogger().info("Purged " + purgedUsers + " users from the database."); mcMMO.p.getLogger().info("Purged " + purgedUsers + " users from the database.");
} }
public static void profileCleanup(String playerName) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
if (mcMMOPlayer != null) {
Player player = mcMMOPlayer.getPlayer();
McMMOHud spoutHud = mcMMOPlayer.getProfile().getSpoutHud();
if (spoutHud != null) {
spoutHud.removeWidgets();
}
UserManager.remove(playerName);
if (player.isOnline()) {
UserManager.addUser(player);
if (mcMMO.spoutEnabled) {
SpoutUtils.reloadSpoutPlayer(player);
}
}
}
}
/** /**
* Check database structure for missing values. * Check database structure for missing values.
* *

View File

@ -60,79 +60,79 @@ public final class LeaderboardManager {
ArrayList<String> players = new ArrayList<String>(); ArrayList<String> players = new ArrayList<String>();
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
String[] character = line.split(":"); String[] data = line.split(":");
String p = character[0]; String playerName = data[0];
int powerLevel = 0; int powerLevel = 0;
// Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...) // Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...)
if (players.contains(p)) { if (players.contains(playerName)) {
continue; continue;
} }
players.add(p); players.add(playerName);
if (character.length > 1 && StringUtils.isInt(character[1])) { if (data.length > 1 && StringUtils.isInt(data[1])) {
mining.add(new PlayerStat(p, Integer.parseInt(character[1]))); mining.add(new PlayerStat(playerName, Integer.parseInt(data[1])));
powerLevel += Integer.parseInt(character[1]); powerLevel += Integer.parseInt(data[1]);
} }
if (character.length > 5 && StringUtils.isInt(character[5])) { if (data.length > 5 && StringUtils.isInt(data[5])) {
woodcutting.add(new PlayerStat(p, Integer.parseInt(character[5]))); woodcutting.add(new PlayerStat(playerName, Integer.parseInt(data[5])));
powerLevel += Integer.parseInt(character[5]); powerLevel += Integer.parseInt(data[5]);
} }
if (character.length > 7 && StringUtils.isInt(character[7])) { if (data.length > 7 && StringUtils.isInt(data[7])) {
repair.add(new PlayerStat(p, Integer.parseInt(character[7]))); repair.add(new PlayerStat(playerName, Integer.parseInt(data[7])));
powerLevel += Integer.parseInt(character[7]); powerLevel += Integer.parseInt(data[7]);
} }
if (character.length > 8 && StringUtils.isInt(character[8])) { if (data.length > 8 && StringUtils.isInt(data[8])) {
unarmed.add(new PlayerStat(p, Integer.parseInt(character[8]))); unarmed.add(new PlayerStat(playerName, Integer.parseInt(data[8])));
powerLevel += Integer.parseInt(character[8]); powerLevel += Integer.parseInt(data[8]);
} }
if (character.length > 9 && StringUtils.isInt(character[9])) { if (data.length > 9 && StringUtils.isInt(data[9])) {
herbalism.add(new PlayerStat(p, Integer.parseInt(character[9]))); herbalism.add(new PlayerStat(playerName, Integer.parseInt(data[9])));
powerLevel += Integer.parseInt(character[9]); powerLevel += Integer.parseInt(data[9]);
} }
if (character.length > 10 && StringUtils.isInt(character[10])) { if (data.length > 10 && StringUtils.isInt(data[10])) {
excavation.add(new PlayerStat(p, Integer.parseInt(character[10]))); excavation.add(new PlayerStat(playerName, Integer.parseInt(data[10])));
powerLevel += Integer.parseInt(character[10]); powerLevel += Integer.parseInt(data[10]);
} }
if (character.length > 11 && StringUtils.isInt(character[11])) { if (data.length > 11 && StringUtils.isInt(data[11])) {
archery.add(new PlayerStat(p, Integer.parseInt(character[11]))); archery.add(new PlayerStat(playerName, Integer.parseInt(data[11])));
powerLevel += Integer.parseInt(character[11]); powerLevel += Integer.parseInt(data[11]);
} }
if (character.length > 12 && StringUtils.isInt(character[12])) { if (data.length > 12 && StringUtils.isInt(data[12])) {
swords.add(new PlayerStat(p, Integer.parseInt(character[12]))); swords.add(new PlayerStat(playerName, Integer.parseInt(data[12])));
powerLevel += Integer.parseInt(character[12]); powerLevel += Integer.parseInt(data[12]);
} }
if (character.length > 13 && StringUtils.isInt(character[13])) { if (data.length > 13 && StringUtils.isInt(data[13])) {
axes.add(new PlayerStat(p, Integer.parseInt(character[13]))); axes.add(new PlayerStat(playerName, Integer.parseInt(data[13])));
powerLevel += Integer.parseInt(character[13]); powerLevel += Integer.parseInt(data[13]);
} }
if (character.length > 14 && StringUtils.isInt(character[14])) { if (data.length > 14 && StringUtils.isInt(data[14])) {
acrobatics.add(new PlayerStat(p, Integer.parseInt(character[14]))); acrobatics.add(new PlayerStat(playerName, Integer.parseInt(data[14])));
powerLevel += Integer.parseInt(character[14]); powerLevel += Integer.parseInt(data[14]);
} }
if (character.length > 24 && StringUtils.isInt(character[24])) { if (data.length > 24 && StringUtils.isInt(data[24])) {
taming.add(new PlayerStat(p, Integer.parseInt(character[24]))); taming.add(new PlayerStat(playerName, Integer.parseInt(data[24])));
powerLevel += Integer.parseInt(character[24]); powerLevel += Integer.parseInt(data[24]);
} }
if (character.length > 34 && StringUtils.isInt(character[34])) { if (data.length > 34 && StringUtils.isInt(data[34])) {
fishing.add(new PlayerStat(p, Integer.parseInt(character[34]))); fishing.add(new PlayerStat(playerName, Integer.parseInt(data[34])));
powerLevel += Integer.parseInt(character[34]); powerLevel += Integer.parseInt(data[34]);
} }
powerLevels.add(new PlayerStat(p, powerLevel)); powerLevels.add(new PlayerStat(playerName, powerLevel));
} }
in.close(); in.close();
} }
@ -188,72 +188,22 @@ public final class LeaderboardManager {
statsList = playerStatHash.get(SkillType.getSkill(skillType)); statsList = playerStatHash.get(SkillType.getSkill(skillType));
} }
int destination; int destination = (pageNumber - 1) * 10;
// How many lines to skip through for (int i = 0; i < 10; i++) {
if (pageNumber == 1) { PlayerStat ps = statsList.get(destination + i);
destination = 0; info[i] = ps.name + ":" + ps.statVal;
}
else {
destination = (pageNumber * 10) - 9;
}
int currentPos = 0;
for (PlayerStat ps : statsList) {
if (currentPos == 10) {
break;
}
if (destination > 1) {
destination--;
continue;
}
info[currentPos] = ps.name + ":" + ps.statVal;
currentPos++;
} }
return info; return info;
} }
public static int[] getPlayerRank(String playerName) { public static int[] getPlayerRank(String playerName) {
int currentPos = 1; return getPlayerRank(playerName, powerLevels);
if (powerLevels != null) {
for (PlayerStat stat : powerLevels) {
if (stat.name.equalsIgnoreCase(playerName)) {
return new int[] {currentPos, stat.statVal};
}
currentPos++;
continue;
}
return new int[] {0, 0};
}
return new int[] {0, 0};
} }
public static int[] getPlayerRank(String playerName, SkillType skillType) { public static int[] getPlayerRank(String playerName, SkillType skillType) {
int currentPos = 1; return getPlayerRank(playerName, playerStatHash.get(skillType));
List<PlayerStat> statsList = playerStatHash.get(skillType);
if (statsList != null) {
for (PlayerStat stat : statsList) {
if (stat.name.equalsIgnoreCase(playerName)) {
return new int[] {currentPos, stat.statVal};
}
currentPos++;
continue;
}
return new int[] {0, 0};
}
return new int[] {0, 0};
} }
public static boolean removeFlatFileUser(String playerName) { public static boolean removeFlatFileUser(String playerName) {
@ -315,8 +265,9 @@ public final class LeaderboardManager {
mcMMO.p.getLogger().info("Purging powerless users..."); mcMMO.p.getLogger().info("Purging powerless users...");
int purgedUsers = 0; int purgedUsers = 0;
for (PlayerStat stat : powerLevels) { for (PlayerStat stat : powerLevels) {
if (stat.statVal == 0 && removeFlatFileUser(stat.name) && !mcMMO.p.getServer().getOfflinePlayer(stat.name).isOnline()) { if (stat.statVal == 0 && !mcMMO.p.getServer().getOfflinePlayer(stat.name).isOnline() && removeFlatFileUser(stat.name)) {
purgedUsers++; purgedUsers++;
} }
} }
@ -394,6 +345,24 @@ public final class LeaderboardManager {
return removedPlayers; return removedPlayers;
} }
private static int[] getPlayerRank(String playerName, List<PlayerStat> statsList) {
int currentPos = 1;
if (statsList == null) {
return new int[] {0, 0};
}
for (PlayerStat stat : statsList) {
if (stat.name.equalsIgnoreCase(playerName)) {
return new int[] {currentPos, stat.statVal};
}
currentPos++;
}
return new int[] {0, 0};
}
private static class SkillComparator implements Comparator<PlayerStat> { private static class SkillComparator implements Comparator<PlayerStat> {
@Override @Override
public int compare(PlayerStat o1, PlayerStat o2) { public int compare(PlayerStat o1, PlayerStat o2) {

View File

@ -28,10 +28,13 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.skills.fishing.FishingManager; import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils; import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -65,7 +68,7 @@ public class McMMOPlayer {
private boolean displaySkillNotifications = true; private boolean displaySkillNotifications = true;
private boolean abilityUse = true; private boolean abilityUse = true;
private boolean placedAnvil; private boolean placedRepairAnvil;
private boolean placedSalvageAnvil; private boolean placedSalvageAnvil;
private boolean godMode; private boolean godMode;
@ -76,6 +79,7 @@ public class McMMOPlayer {
private Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>(); private Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
private int recentlyHurt; private int recentlyHurt;
private int chimaeraWing;
private int respawnATS; private int respawnATS;
public McMMOPlayer(Player player) { public McMMOPlayer(Player player) {
@ -92,12 +96,7 @@ public class McMMOPlayer {
*/ */
try { try {
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.values()) {
Class<? extends SkillManager> skillManagerClass = skillType.getManagerClass(); skillManagers.put(skillType, skillType.getManagerClass().getConstructor(McMMOPlayer.class).newInstance(this));
// TODO: The null check is needed only because currently some SkillType doesn't have a valid skillManagerClass
if (skillManagerClass != null) {
skillManagers.put(skillType, skillManagerClass.getConstructor(McMMOPlayer.class).newInstance(this));
}
} }
} }
catch (Exception e) { catch (Exception e) {
@ -144,6 +143,10 @@ public class McMMOPlayer {
return (MiningManager) skillManagers.get(SkillType.MINING); return (MiningManager) skillManagers.get(SkillType.MINING);
} }
public RepairManager getRepairManager() {
return (RepairManager) skillManagers.get(SkillType.REPAIR);
}
public SmeltingManager getSmeltingManager() { public SmeltingManager getSmeltingManager() {
return (SmeltingManager) skillManagers.get(SkillType.SMELTING); return (SmeltingManager) skillManagers.get(SkillType.SMELTING);
} }
@ -160,6 +163,10 @@ public class McMMOPlayer {
return (UnarmedManager) skillManagers.get(SkillType.UNARMED); return (UnarmedManager) skillManagers.get(SkillType.UNARMED);
} }
public WoodcuttingManager getWoodcuttingManager() {
return (WoodcuttingManager) skillManagers.get(SkillType.WOODCUTTING);
}
/* /*
* Abilities * Abilities
*/ */
@ -292,6 +299,23 @@ public class McMMOPlayer {
recentlyHurt = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); recentlyHurt = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
} }
/*
* Chimaera Wing
*/
public int getLastChimaeraTeleport() {
return chimaeraWing;
}
public void setLastChimaeraTeleport(int value) {
chimaeraWing = value;
}
public void actualizeLastChimaeraTeleport() {
chimaeraWing = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
}
/* /*
* Exploit Prevention * Exploit Prevention
*/ */
@ -308,24 +332,26 @@ public class McMMOPlayer {
* Repair Anvil Placement * Repair Anvil Placement
*/ */
public void togglePlacedAnvil() { public boolean getPlacedAnvil(int anvilId) {
placedAnvil = !placedAnvil; if (anvilId == Repair.repairAnvilId) {
return placedRepairAnvil;
}
if (anvilId == Repair.salvageAnvilId) {
return placedSalvageAnvil;
}
return true;
} }
public Boolean getPlacedAnvil() { public void togglePlacedAnvil(int anvilId) {
return placedAnvil; if (anvilId == Repair.repairAnvilId) {
} placedRepairAnvil = !placedRepairAnvil;
}
/* if (anvilId == Repair.salvageAnvilId) {
* Salvage Anvil Placement placedSalvageAnvil = !placedSalvageAnvil;
*/ }
public void togglePlacedSalvageAnvil() {
placedSalvageAnvil = !placedSalvageAnvil;
}
public Boolean getPlacedSalvageAnvil() {
return placedSalvageAnvil;
} }
/* /*
@ -423,6 +449,19 @@ public class McMMOPlayer {
* @param xp Experience amount to add * @param xp Experience amount to add
*/ */
public void applyXpGain(SkillType skillType, int xp) { public void applyXpGain(SkillType skillType, int xp) {
if (skillType.isChildSkill()) {
Set<SkillType> parentSkills = FamilyTree.getParents(skillType);
for (SkillType parentSkill : parentSkills) {
if (Permissions.skillEnabled(player, parentSkill)) {
applyXpGain(parentSkill, xp / parentSkills.size());
}
}
return;
}
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skillType, xp); McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skillType, xp);
mcMMO.p.getServer().getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);

View File

@ -92,7 +92,7 @@ public class PlayerProfile {
} }
else { else {
for (HudType type : HudType.values()) { for (HudType type : HudType.values()) {
if (type.toString().equals(huds.get(1).get(0))) { if (type.toString().equalsIgnoreCase(huds.get(1).get(0))) {
hudType = type; hudType = type;
} }
} }
@ -186,7 +186,7 @@ public class PlayerProfile {
// Find if the line contains the player we want. // Find if the line contains the player we want.
String[] character = line.split(":"); String[] character = line.split(":");
if (!character[0].equals(playerName)) { if (!character[0].equalsIgnoreCase(playerName)) {
continue; continue;
} }
@ -400,7 +400,7 @@ public class PlayerProfile {
// While not at the end of the file // While not at the end of the file
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
// Read the line in and copy it to the output it's not the player we want to edit // Read the line in and copy it to the output it's not the player we want to edit
if (!line.split(":")[0].equals(playerName)) { if (!line.split(":")[0].equalsIgnoreCase(playerName)) {
writer.append(line).append("\r\n"); writer.append(line).append("\r\n");
} }
else { else {
@ -611,6 +611,10 @@ public class PlayerProfile {
} }
public void setSkillXpLevel(SkillType skillType, int newValue) { public void setSkillXpLevel(SkillType skillType, int newValue) {
if (skillType.isChildSkill()) {
return;
}
skillsXp.put(skillType, newValue); skillsXp.put(skillType, newValue);
} }

View File

@ -11,10 +11,12 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.skills.fishing.FishingManager; import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
public enum SkillType { public enum SkillType {
@ -25,12 +27,12 @@ public enum SkillType {
FISHING(FishingManager.class), FISHING(FishingManager.class),
HERBALISM(HerbalismManager.class, AbilityType.GREEN_TERRA, ToolType.HOE), HERBALISM(HerbalismManager.class, AbilityType.GREEN_TERRA, ToolType.HOE),
MINING(MiningManager.class, AbilityType.SUPER_BREAKER, ToolType.PICKAXE), MINING(MiningManager.class, AbilityType.SUPER_BREAKER, ToolType.PICKAXE),
REPAIR(null), // TODO: Create a proper RepairManager class REPAIR(RepairManager.class),
SMELTING(SmeltingManager.class), SMELTING(SmeltingManager.class),
SWORDS(SwordsManager.class, AbilityType.SERRATED_STRIKES, ToolType.SWORD), SWORDS(SwordsManager.class, AbilityType.SERRATED_STRIKES, ToolType.SWORD),
TAMING(TamingManager.class), TAMING(TamingManager.class),
UNARMED(UnarmedManager.class, AbilityType.BERSERK, ToolType.FISTS), UNARMED(UnarmedManager.class, AbilityType.BERSERK, ToolType.FISTS),
WOODCUTTING(null, AbilityType.TREE_FELLER, ToolType.AXE); // TODO: Create a proper WoodcuttingManager class WOODCUTTING(WoodcuttingManager.class, AbilityType.TREE_FELLER, ToolType.AXE);
private Class<? extends SkillManager> managerClass; private Class<? extends SkillManager> managerClass;
private AbilityType ability; private AbilityType ability;

View File

@ -20,8 +20,6 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
@ -35,10 +33,9 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.skills.unarmed.Unarmed; import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.Woodcutting; import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -91,7 +88,7 @@ public class BlockListener implements Listener {
public void onBlockPistonRetract(BlockPistonRetractEvent event) { public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if (event.isSticky()) { if (event.isSticky()) {
// Needed only because under some circumstances Minecraft doesn't move the block // Needed only because under some circumstances Minecraft doesn't move the block
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StickyPistonTrackerTask(event), 2); new StickyPistonTrackerTask(event).runTaskLater(plugin, 2);
} }
} }
@ -109,21 +106,15 @@ public class BlockListener implements Listener {
} }
BlockState blockState = event.getBlock().getState(); BlockState blockState = event.getBlock().getState();
int blockId = blockState.getTypeId();
/* Check if the blocks placed should be monitored so they do not give out XP in the future */ /* Check if the blocks placed should be monitored so they do not give out XP in the future */
if (BlockUtils.shouldBeWatched(blockState)) { if (BlockUtils.shouldBeWatched(blockState)) {
mcMMO.placeStore.setTrue(blockState); mcMMO.placeStore.setTrue(blockState);
} }
if (Repair.anvilMessagesEnabled) { if (Repair.anvilMessagesEnabled && (blockId == Repair.repairAnvilId || blockId == Repair.salvageAnvilId)) {
int blockID = blockState.getTypeId(); UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockId);
if (blockID == Repair.anvilID) {
Repair.placedAnvilCheck(player, blockID);
}
else if (blockID == Salvage.anvilID) {
Salvage.placedAnvilCheck(player, blockID);
}
} }
} }
@ -146,12 +137,11 @@ public class BlockListener implements Listener {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
BlockState blockState = event.getBlock().getState(); BlockState blockState = event.getBlock().getState();
ItemStack heldItem = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
/* HERBALISM */ /* HERBALISM */
if (BlockUtils.affectedByGreenTerra(blockState)) { if (BlockUtils.affectedByGreenTerra(blockState)) {
HerbalismManager herbalismManager = UserManager.getPlayer(player).getHerbalismManager(); HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
/* Green Terra */ /* Green Terra */
if (herbalismManager.canActivateAbility()) { if (herbalismManager.canActivateAbility()) {
@ -163,47 +153,31 @@ public class BlockListener implements Listener {
* Instead, we check it inside the drops handler. * Instead, we check it inside the drops handler.
*/ */
if (Permissions.skillEnabled(player, SkillType.HERBALISM)) { if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
// Double drops
herbalismManager.herbalismBlockCheck(blockState); herbalismManager.herbalismBlockCheck(blockState);
// Triple drops
if (herbalismManager.canGreenTerraPlant()) {
herbalismManager.herbalismBlockCheck(blockState);
}
} }
} }
/* MINING */ /* MINING */
else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(blockState)) { else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(blockState)) {
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); MiningManager miningManager = mcMMOPlayer.getMiningManager();
miningManager.miningBlockCheck(blockState); miningManager.miningBlockCheck(blockState);
if (mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) {
miningManager.miningBlockCheck(blockState);
}
} }
/* WOOD CUTTING */ /* WOOD CUTTING */
else if (BlockUtils.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(blockState)) { else if (BlockUtils.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(blockState)) {
if (mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemUtils.isAxe(heldItem)) { WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager();
Woodcutting.beginTreeFeller(blockState, player);
if (woodcuttingManager.canUseTreeFeller(heldItem)) {
woodcuttingManager.processTreeFeller(blockState);
} }
else { else {
if (Config.getInstance().getWoodcuttingRequiresTool()) { woodcuttingManager.woodcuttingBlockCheck(blockState);
if (ItemUtils.isAxe(heldItem)) {
Woodcutting.beginWoodcutting(player, blockState);
}
}
else {
Woodcutting.beginWoodcutting(player, blockState);
}
} }
} }
/* EXCAVATION */ /* EXCAVATION */
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) { else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) {
ExcavationManager excavationManager = UserManager.getPlayer(player).getExcavationManager(); ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager();
excavationManager.excavationBlockCheck(blockState); excavationManager.excavationBlockCheck(blockState);
if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
@ -368,24 +342,18 @@ public class BlockListener implements Listener {
} }
} }
// Another perm check for the cracked blocks activation // Another perm check for the cracked blocks activation
else if (BlockUtils.affectedByBlockCracker(blockState) && Permissions.blockCracker(player)) { else if (BlockUtils.affectedByBlockCracker(blockState)) {
if (Unarmed.blockCracker(player, blockState)) { UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
if (unarmedManager.canUseBlockCracker() && SkillUtils.blockBreakSimulate(block, player, false) && unarmedManager.blockCrackerCheck(blockState)) {
blockState.update(); blockState.update();
} }
} }
} }
else if ((mcMMOPlayer.getProfile().getSkillLevel(SkillType.WOODCUTTING) >= AdvancedConfig.getInstance().getLeafBlowUnlockLevel()) && BlockUtils.isLeaves(blockState)) { else if (BlockUtils.isLeaves(blockState)) {
if (SkillUtils.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && SkillUtils.blockBreakSimulate(block, player, true)) {
if (Config.getInstance().getWoodcuttingRequiresTool()) { event.setInstaBreak(true);
if (ItemUtils.isAxe(heldItem)) { player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
event.setInstaBreak(true);
Woodcutting.beginLeafBlower(player, blockState);
}
}
else if (!(heldItem.getType() == Material.SHEARS)) {
event.setInstaBreak(true);
Woodcutting.beginLeafBlower(player, blockState);
}
} }
} }
} }

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace; import org.bukkit.block.Furnace;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
@ -16,6 +17,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.FurnaceInventory; import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
@ -49,11 +51,12 @@ public class InventoryListener implements Listener {
if (furnace == null) { if (furnace == null) {
return; return;
} }
if (furnace.getBurnTime() == 0) {
Block furnaceBlock = furnace.getBlock();
BlockState furnaceBlock = furnace.getBlock().getState(); if (!furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, new FixedMetadataValue(plugin, player.getName()));
if (furnace.getBurnTime() == 0 && !plugin.furnaceIsTracked(furnaceBlock)) { }
plugin.addToOpenFurnaceTracker(furnaceBlock, player.getName());
} }
} }
} }
@ -75,23 +78,27 @@ public class InventoryListener implements Listener {
return; return;
} }
BlockState furnaceBlock = furnace.getBlock().getState(); if (furnace.getBurnTime() == 0) {
Block furnaceBlock = furnace.getBlock();
if (furnace.getBurnTime() == 0 && plugin.furnaceIsTracked(furnaceBlock)) { if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
plugin.removeFromFurnaceTracker(furnaceBlock); furnaceBlock.removeMetadata(mcMMO.furnaceMetadataKey, plugin);
}
} }
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceBurnEvent(FurnaceBurnEvent event) { public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
BlockState furnaceBlock = event.getBlock().getState(); Block furnaceBlock = event.getBlock();
BlockState furnaceState = furnaceBlock.getState();
if (furnaceBlock instanceof Furnace) { if (furnaceState instanceof Furnace) {
ItemStack smelting = ((Furnace) furnaceBlock).getInventory().getSmelting(); ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemUtils.isSmeltable(smelting)) { if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey) && smelting != null && ItemUtils.isSmeltable(smelting)) {
Player player = plugin.getFurnacePlayer(furnaceBlock); // We can make this assumption because we (should) be the only ones using this exact metadata
Player player = plugin.getServer().getPlayer(furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey).get(0).asString());
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) { if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
return; return;
@ -104,13 +111,15 @@ public class InventoryListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) { public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
BlockState furnaceBlock = event.getBlock().getState(); Block furnaceBlock = event.getBlock();
BlockState furnaceState = furnaceBlock.getState();
if (furnaceBlock instanceof Furnace) { if (furnaceState instanceof Furnace) {
ItemStack smelting = ((Furnace) furnaceBlock).getInventory().getSmelting(); ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemUtils.isSmeltable(smelting)) { if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey) && smelting != null && ItemUtils.isSmeltable(smelting)) {
Player player = plugin.getFurnacePlayer(furnaceBlock); // We can make this assumption because we (should) be the only ones using this exact metadata
Player player = plugin.getServer().getPlayer(furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey).get(0).asString());
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) { if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) {
return; return;
@ -123,13 +132,19 @@ public class InventoryListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceExtractEvent(FurnaceExtractEvent event) { public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
BlockState furnaceBlock = event.getBlock().getState(); Block furnaceBlock = event.getBlock();
BlockState furnaceState = furnaceBlock.getState();
if (furnaceBlock instanceof Furnace) { if (furnaceState instanceof Furnace) {
ItemStack result = ((Furnace) furnaceBlock).getInventory().getResult(); ItemStack result = ((Furnace) furnaceState).getInventory().getResult();
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemUtils.isSmelted(result)) { if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey) && result != null && ItemUtils.isSmelted(result)) {
Player player = event.getPlayer(); // We can make this assumption because we (should) be the only ones using this exact metadata
Player player = plugin.getServer().getPlayer(furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey).get(0).asString());
if (Misc.isNPCEntity(player)) {
return;
}
SmeltingManager smeltingManager = UserManager.getPlayer(player).getSmeltingManager(); SmeltingManager smeltingManager = UserManager.getPlayer(player).getSmeltingManager();

View File

@ -39,7 +39,6 @@ import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.ChimaeraWing; import com.gmail.nossr50.util.ChimaeraWing;
@ -285,14 +284,14 @@ public class PlayerListener implements Listener {
int blockID = block.getTypeId(); int blockID = block.getTypeId();
/* REPAIR CHECKS */ /* REPAIR CHECKS */
if (blockID == Repair.anvilID && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.repairManager.isRepairable(heldItem)) { if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.repairableManager.isRepairable(heldItem)) {
mcMMO.repairManager.handleRepair(mcMMOPlayer, heldItem); UserManager.getPlayer(player).getRepairManager().handleRepair(heldItem);
event.setCancelled(true); event.setCancelled(true);
player.updateInventory(); player.updateInventory();
} }
/* SALVAGE CHECKS */ /* SALVAGE CHECKS */
else if (blockID == Salvage.anvilID && Permissions.salvage(player) && Salvage.isSalvageable(heldItem)) { else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
Salvage.handleSalvage(player, block.getLocation(), heldItem); UserManager.getPlayer(player).getRepairManager().handleSalvage(block.getLocation(), heldItem);
event.setCancelled(true); event.setCancelled(true);
player.updateInventory(); player.updateInventory();
} }

View File

@ -8,15 +8,11 @@ import java.util.List;
import net.shatteredlands.shatt.backup.ZipLibrary; import net.shatteredlands.shatt.backup.ZipLibrary;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@ -29,7 +25,6 @@ import com.gmail.nossr50.config.spout.SpoutConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.database.LeaderboardManager; import com.gmail.nossr50.database.LeaderboardManager;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.listeners.BlockListener; import com.gmail.nossr50.listeners.BlockListener;
import com.gmail.nossr50.listeners.EntityListener; import com.gmail.nossr50.listeners.EntityListener;
import com.gmail.nossr50.listeners.InventoryListener; import com.gmail.nossr50.listeners.InventoryListener;
@ -45,10 +40,11 @@ import com.gmail.nossr50.runnables.party.PartyLoaderTask;
import com.gmail.nossr50.runnables.skills.BleedTimerTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.runnables.skills.SkillMonitorTask; import com.gmail.nossr50.runnables.skills.SkillMonitorTask;
import com.gmail.nossr50.skills.child.ChildConfig; import com.gmail.nossr50.skills.child.ChildConfig;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.repair.RepairManagerFactory;
import com.gmail.nossr50.skills.repair.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableManager;
import com.gmail.nossr50.skills.repair.RepairableManagerFactory;
import com.gmail.nossr50.skills.repair.config.RepairConfigManager; import com.gmail.nossr50.skills.repair.config.RepairConfigManager;
import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.LogFilter; import com.gmail.nossr50.util.LogFilter;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.UpdateChecker; import com.gmail.nossr50.util.UpdateChecker;
@ -66,12 +62,11 @@ public class mcMMO extends JavaPlugin {
private final WorldListener worldListener = new WorldListener(); private final WorldListener worldListener = new WorldListener();
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>(); private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
private HashMap<BlockState, String> furnaceTracker = new HashMap<BlockState, String>();
public static mcMMO p; public static mcMMO p;
public static ChunkManager placeStore; public static ChunkManager placeStore;
public static RepairManager repairManager; public static RepairableManager repairableManager;
// Jar Stuff // Jar Stuff
public static File mcmmo; public static File mcmmo;
@ -95,6 +90,7 @@ public class mcMMO extends JavaPlugin {
public static FixedMetadataValue metadataValue; public static FixedMetadataValue metadataValue;
public final static String entityMetadataKey = "mcMMO: Spawned Entity"; public final static String entityMetadataKey = "mcMMO: Spawned Entity";
public final static String blockMetadataKey = "mcMMO: Piston Tracking"; public final static String blockMetadataKey = "mcMMO: Piston Tracking";
public final static String furnaceMetadataKey = "mcMMO: Tracked Furnace";
/** /**
* Things to be run when the plugin is enabled. * Things to be run when the plugin is enabled.
@ -115,6 +111,7 @@ public class mcMMO extends JavaPlugin {
} }
registerEvents(); registerEvents();
registerCustomRecipes();
// Setup the leader boards // Setup the leader boards
if (Config.getInstance().getUseMySQL()) { if (Config.getInstance().getUseMySQL()) {
@ -155,7 +152,7 @@ public class mcMMO extends JavaPlugin {
getLogger().info("Please do not replace the mcMMO jar while the server is running."); getLogger().info("Please do not replace the mcMMO jar while the server is running.");
} }
Bukkit.getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
} }
} }
@ -197,43 +194,6 @@ public class mcMMO extends JavaPlugin {
getLogger().info("Was disabled."); // How informative! getLogger().info("Was disabled."); // How informative!
} }
/**
* Get profile of the player by name.
* </br>
* This function is designed for API usage.
*
* @param playerName Name of player whose profile to get
* @return the PlayerProfile object
*/
public PlayerProfile getPlayerProfile(String playerName) {
return UserManager.getPlayer(playerName).getProfile();
}
/**
* Get profile of the player.
* </br>
* This function is designed for API usage.
*
* @param player player whose profile to get
* @return the PlayerProfile object
*/
public PlayerProfile getPlayerProfile(OfflinePlayer player) {
return UserManager.getPlayer(player.getName()).getProfile();
}
/**
* Get profile of the player.
* </br>
* This function is designed for API usage.
*
* @param player player whose profile to get
* @return the PlayerProfile object
*/
@Deprecated
public PlayerProfile getPlayerProfile(Player player) {
return UserManager.getProfile(player);
}
/** /**
* Add a set of values to the TNT tracker. * Add a set of values to the TNT tracker.
* *
@ -273,22 +233,6 @@ public class mcMMO extends JavaPlugin {
tntTracker.remove(tntID); tntTracker.remove(tntID);
} }
public void addToOpenFurnaceTracker(BlockState furnace, String playerName) {
furnaceTracker.put(furnace, playerName);
}
public boolean furnaceIsTracked(BlockState furnace) {
return furnaceTracker.containsKey(furnace);
}
public void removeFromFurnaceTracker(BlockState furnace) {
furnaceTracker.remove(furnace);
}
public Player getFurnacePlayer(BlockState furnace) {
return getServer().getPlayer(furnaceTracker.get(furnace));
}
public static String getMainDirectory() { public static String getMainDirectory() {
return mainDirectory; return mainDirectory;
} }
@ -377,8 +321,8 @@ public class mcMMO extends JavaPlugin {
// Load repair configs, make manager, and register them at this time // Load repair configs, make manager, and register them at this time
RepairConfigManager rManager = new RepairConfigManager(this); RepairConfigManager rManager = new RepairConfigManager(this);
repairables.addAll(rManager.getLoadedRepairables()); repairables.addAll(rManager.getLoadedRepairables());
repairManager = RepairManagerFactory.getRepairManager(repairables.size()); repairableManager = RepairableManagerFactory.getRepairManager(repairables.size());
repairManager.registerRepairables(repairables); repairableManager.registerRepairables(repairables);
// Check if Repair Anvil and Salvage Anvil have different itemID's // Check if Repair Anvil and Salvage Anvil have different itemID's
if (configInstance.getSalvageAnvilId() == configInstance.getRepairAnvilId()) { if (configInstance.getSalvageAnvilId() == configInstance.getRepairAnvilId()) {
@ -450,43 +394,51 @@ public class mcMMO extends JavaPlugin {
CommandRegistrationManager.registerMchudCommand(); CommandRegistrationManager.registerMchudCommand();
} }
private void scheduleTasks() { private void registerCustomRecipes() {
BukkitScheduler scheduler = getServer().getScheduler(); if (Config.getInstance().getChimaeraEnabled()) {
getServer().addRecipe(ChimaeraWing.getChimaeraWingRecipe());
}
}
private void scheduleTasks() {
// Parties are loaded at the end of first server tick otherwise Server.getOfflinePlayer throws an IndexOutOfBoundsException // Parties are loaded at the end of first server tick otherwise Server.getOfflinePlayer throws an IndexOutOfBoundsException
scheduler.scheduleSyncDelayedTask(this, new PartyLoaderTask(), 0); new PartyLoaderTask().runTaskLater(this, 0);
// Periodic save timer (Saves every 10 minutes by default) // Periodic save timer (Saves every 10 minutes by default)
long saveIntervalTicks = Config.getInstance().getSaveInterval() * 1200; long saveIntervalTicks = Config.getInstance().getSaveInterval() * 1200;
scheduler.scheduleSyncRepeatingTask(this, new SaveTimerTask(), saveIntervalTicks, saveIntervalTicks); new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
// Regen & Cooldown timer (Runs every second) // Regen & Cooldown timer (Runs every second)
scheduler.scheduleSyncRepeatingTask(this, new SkillMonitorTask(), 20, 20); new SkillMonitorTask().runTaskTimer(this, 20, 20);
// Bleed timer (Runs every two seconds) // Bleed timer (Runs every two seconds)
scheduler.scheduleSyncRepeatingTask(this, new BleedTimerTask(), 40, 40); new BleedTimerTask().runTaskTimer(this, 40, 40);
// Old & Powerless User remover // Old & Powerless User remover
int purgeInterval = Config.getInstance().getPurgeInterval(); int purgeInterval = Config.getInstance().getPurgeInterval();
UserPurgeTask userPurgeTask = new UserPurgeTask();
if (purgeInterval == 0) { if (purgeInterval == 0) {
scheduler.scheduleSyncDelayedTask(this, new UserPurgeTask(), 40); // Start 2 seconds after startup. userPurgeTask.runTaskLater(this, 40);
} }
else if (purgeInterval > 0) { else if (purgeInterval > 0) {
long purgeIntervalTicks = purgeInterval * 60 * 60 * 20; long purgeIntervalTicks = purgeInterval * 60 * 60 * 20;
scheduler.scheduleSyncRepeatingTask(this, new UserPurgeTask(), purgeIntervalTicks, purgeIntervalTicks); userPurgeTask.runTaskTimer(this, purgeIntervalTicks, purgeIntervalTicks);
} }
// Automatically remove old members from parties // Automatically remove old members from parties
long kickInterval = Config.getInstance().getAutoPartyKickInterval(); long kickInterval = Config.getInstance().getAutoPartyKickInterval();
PartyAutoKickTask partyAutoKickTask = new PartyAutoKickTask();
if (kickInterval == 0) { if (kickInterval == 0) {
scheduler.scheduleSyncDelayedTask(this, new PartyAutoKickTask(), 40); // Start 2 seconds after startup. partyAutoKickTask.runTaskLater(this, 40); // Start 2 seconds after startup.
} }
else if (kickInterval > 0) { else if (kickInterval > 0) {
long kickIntervalTicks = kickInterval * 60 * 60 * 20; long kickIntervalTicks = kickInterval * 60 * 60 * 20;
scheduler.scheduleSyncRepeatingTask(this, new PartyAutoKickTask(), kickIntervalTicks, kickIntervalTicks); partyAutoKickTask.runTaskTimer(this, kickIntervalTicks, kickIntervalTicks);
} }
} }
} }

View File

@ -24,6 +24,15 @@ public final class PartyManager {
private PartyManager() {} private PartyManager() {}
public static boolean checkPartyExistence(Player player, Party party, String partyName) {
if (party == null) {
return false;
}
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", partyName));
return true;
}
public static boolean changeOrJoinParty(McMMOPlayer mcMMOPlayer, Player player, Party oldParty, String newPartyName) { public static boolean changeOrJoinParty(McMMOPlayer mcMMOPlayer, Player player, Party oldParty, String newPartyName) {
if (mcMMOPlayer.inParty()) { if (mcMMOPlayer.inParty()) {
if (!handlePartyChangeEvent(player, oldParty.getName(), newPartyName, EventReason.CHANGED_PARTIES)) { if (!handlePartyChangeEvent(player, oldParty.getName(), newPartyName, EventReason.CHANGED_PARTIES)) {
@ -75,7 +84,7 @@ public final class PartyManager {
List<Player> nearMembers = new ArrayList<Player>(); List<Player> nearMembers = new ArrayList<Player>();
if (party != null) { if (party != null) {
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
if (!player.getName().equals(member.getName()) && Misc.isNear(player.getLocation(), member.getLocation(), range)) { if (!player.getName().equalsIgnoreCase(member.getName()) && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
nearMembers.add(member); nearMembers.add(member);
} }
} }
@ -122,7 +131,13 @@ public final class PartyManager {
* @return all online players in this party * @return all online players in this party
*/ */
public static List<Player> getOnlineMembers(Player player) { public static List<Player> getOnlineMembers(Player player) {
return getOnlineMembers(player.getName()); Party party = getPlayerParty(player.getName());
if (party == null) {
return null;
}
return getOnlineMembers(party.getName());
} }
/** /**
@ -150,7 +165,7 @@ public final class PartyManager {
public static Party getPlayerParty(String playerName) { public static Party getPlayerParty(String playerName) {
for (Party party : parties) { for (Party party : parties) {
for (OfflinePlayer member : party.getMembers()) { for (OfflinePlayer member : party.getMembers()) {
if (member.getName().equals(playerName)) { if (member.getName().equalsIgnoreCase(playerName)) {
return party; return party;
} }
} }
@ -184,7 +199,7 @@ public final class PartyManager {
} }
else { else {
// If the leaving player was the party leader, appoint a new leader from the party members // If the leaving player was the party leader, appoint a new leader from the party members
if (party.getLeader().equals(player.getName())) { if (party.getLeader().equalsIgnoreCase(player.getName())) {
String newLeader = members.get(0).getName(); String newLeader = members.get(0).getName();
party.setLeader(newLeader); party.setLeader(newLeader);
} }
@ -374,10 +389,10 @@ public final class PartyManager {
String leaderName = party.getLeader(); String leaderName = party.getLeader();
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
if (member.getName().equals(playerName)) { if (member.getName().equalsIgnoreCase(playerName)) {
member.sendMessage(LocaleLoader.getString("Party.Owner.Player")); member.sendMessage(LocaleLoader.getString("Party.Owner.Player"));
} }
else if (member.getName().equals(leaderName)) { else if (member.getName().equalsIgnoreCase(leaderName)) {
member.sendMessage(LocaleLoader.getString("Party.Owner.NotLeader")); member.sendMessage(LocaleLoader.getString("Party.Owner.NotLeader"));
} }
else { else {
@ -396,7 +411,7 @@ public final class PartyManager {
* @return true if the player can invite * @return true if the player can invite
*/ */
public static boolean canInvite(Player player, Party party) { public static boolean canInvite(Player player, Party party) {
if (party.isLocked() && !party.getLeader().equals(player.getName())) { if (party.isLocked() && !party.getLeader().equalsIgnoreCase(player.getName())) {
return false; return false;
} }
@ -488,13 +503,13 @@ public final class PartyManager {
} }
partiesFile.set(partyName + ".Members", memberNames); partiesFile.set(partyName + ".Members", memberNames);
}
try { try {
partiesFile.save(new File(partiesFilePath)); partiesFile.save(new File(partiesFilePath));
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}
} }
} }

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.runnables; package com.gmail.nossr50.runnables;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -8,15 +8,14 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask; import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class SaveTimerTask implements Runnable { public class SaveTimerTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
// All player data will be saved periodically through this // All player data will be saved periodically through this
int count = 1; int count = 1;
BukkitScheduler bukkitScheduler = mcMMO.p.getServer().getScheduler();
for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers().values()) { for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers().values()) {
bukkitScheduler.scheduleSyncDelayedTask(mcMMO.p, new PlayerProfileSaveTask(mcMMOPlayer), count); new PlayerProfileSaveTask(mcMMOPlayer).runTaskLater(mcMMO.p, count);
count++; count++;
} }

View File

@ -3,10 +3,11 @@ package com.gmail.nossr50.runnables;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
public class StickyPistonTrackerTask implements Runnable { public class StickyPistonTrackerTask extends BukkitRunnable {
BlockPistonRetractEvent event; BlockPistonRetractEvent event;
public StickyPistonTrackerTask(BlockPistonRetractEvent event) { public StickyPistonTrackerTask(BlockPistonRetractEvent event) {

View File

@ -2,16 +2,13 @@ package com.gmail.nossr50.runnables.commands;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.skills.SkillUtils;
public class McrankCommandAsyncTask implements Runnable { public class McrankCommandAsyncTask extends BukkitRunnable {
private final String playerName; private final String playerName;
private final CommandSender sender; private final CommandSender sender;
@ -22,35 +19,8 @@ public class McrankCommandAsyncTask implements Runnable {
@Override @Override
public void run() { public void run() {
final Map<String, Integer> skills = DatabaseManager.readSQLRank(playerName); Map<String, Integer> skills = DatabaseManager.readSQLRank(playerName);
Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, new Runnable() { new McrankCommandDisplayTask(skills, sender, playerName).runTaskLater(mcMMO.p, 1);
@Override
public void run() {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (skills.get(skillType.name()) == null) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), skills.get(skillType.name())));
}
}
if (skills.get("ALL") == null) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", LocaleLoader.getString("Commands.mcrank.Unranked")));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", skills.get("ALL")));
}
}
}, 1L);
} }
} }

View File

@ -0,0 +1,50 @@
package com.gmail.nossr50.runnables.commands;
import java.util.Map;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillUtils;
public class McrankCommandDisplayTask extends BukkitRunnable {
private final Map<String, Integer> skills;
private final CommandSender sender;
private final String playerName;
public McrankCommandDisplayTask(Map<String, Integer> skills, CommandSender sender, String playerName) {
this.skills = skills;
this.sender = sender;
this.playerName = playerName;
}
@Override
public void run() {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (SkillType skillType : SkillType.values()) {
if ((sender instanceof Player && !Permissions.skillEnabled(sender, skillType)) || skillType.isChildSkill()) {
continue;
}
if (skills.get(skillType.name()) == null) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), skills.get(skillType.name())));
}
}
if (skills.get("ALL") == null) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", LocaleLoader.getString("Commands.mcrank.Unranked")));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", skills.get("ALL")));
}
}
}

View File

@ -3,67 +3,31 @@ package com.gmail.nossr50.runnables.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
public class MctopCommandAsyncTask implements Runnable { public class MctopCommandAsyncTask extends BukkitRunnable {
private CommandSender sender; private CommandSender sender;
private String query; private String query;
private int page; private int page;
private Command command;
public MctopCommandAsyncTask(int page, String query, CommandSender sender, Command command) { public MctopCommandAsyncTask(int page, String query, CommandSender sender) {
this.page = page; this.page = page;
this.query = query; this.query = query;
this.sender = sender; this.sender = sender;
this.command = command;
} }
@Override @Override
public void run() { public void run() {
if (!query.equalsIgnoreCase("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) {
if (!Permissions.mctop(sender, SkillType.getSkill(query))) {
sender.sendMessage(command.getPermissionMessage());
return;
}
}
String tablePrefix = Config.getInstance().getMySQLTablePrefix(); String tablePrefix = Config.getInstance().getMySQLTablePrefix();
final HashMap<Integer, ArrayList<String>> userslist = DatabaseManager.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"); final HashMap<Integer, ArrayList<String>> userslist = DatabaseManager.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");
Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, new Runnable() {
@Override
public void run() {
if (query.equals("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) {
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(query)));
}
int place = (page * 10) - 9; new MctopCommandDisplayTask(userslist, page, tablePrefix, sender).runTaskLater(mcMMO.p, 1);
for (int i = 1; i <= 10; i++) {
if (userslist.get(i) == null) {
break;
}
// Format: 1. Playername - skill value
sender.sendMessage(place + ". " + ChatColor.GREEN + userslist.get(i).get(1) + " - " + ChatColor.WHITE + userslist.get(i).get(0));
place++;
}
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
}
}, 1L);
} }
} }

View File

@ -0,0 +1,48 @@
package com.gmail.nossr50.runnables.commands;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.StringUtils;
public class MctopCommandDisplayTask extends BukkitRunnable {
private HashMap<Integer, ArrayList<String>> userslist;
private CommandSender sender;
private String query;
private int page;
public MctopCommandDisplayTask(HashMap<Integer, ArrayList<String>> userslist, int page, String query, CommandSender sender) {
this.userslist = userslist;
this.page = page;
this.query = query;
this.sender = sender;
}
@Override
public void run() {
if (query.equalsIgnoreCase("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) {
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(query)));
}
int place = (page * 10) - 9;
for (int i = 1; i <= 10; i++) {
if (userslist.get(i) == null) {
break;
}
// Format: 1. Playername - skill value
sender.sendMessage(place + ". " + ChatColor.GREEN + userslist.get(i).get(1) + " - " + ChatColor.WHITE + userslist.get(i).get(0));
place++;
}
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
}
}

View File

@ -3,13 +3,15 @@ package com.gmail.nossr50.runnables.database;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
public class SQLConversionTask implements Runnable { public class SQLConversionTask extends BukkitRunnable {
private String tablePrefix = Config.getInstance().getMySQLTablePrefix(); private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
@Override @Override
@ -55,7 +57,7 @@ public class SQLConversionTask implements Runnable {
playerName = character[0]; playerName = character[0];
// Check for things we don't want put in the DB // Check for things we don't want put in the DB
if (playerName == null || playerName.equals("null") || playerName.equals("#Storage place for user information")) { if (playerName == null || playerName.equalsIgnoreCase("null") || playerName.equalsIgnoreCase("#Storage place for user information")) {
continue; continue;
} }

View File

@ -1,12 +1,13 @@
package com.gmail.nossr50.runnables.database; package com.gmail.nossr50.runnables.database;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class SQLReconnectTask implements Runnable { public class SQLReconnectTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
if (DatabaseManager.checkConnected()) { if (DatabaseManager.checkConnected()) {

View File

@ -1,10 +1,12 @@
package com.gmail.nossr50.runnables.database; package com.gmail.nossr50.runnables.database;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.database.LeaderboardManager; import com.gmail.nossr50.database.LeaderboardManager;
public class UserPurgeTask implements Runnable { public class UserPurgeTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
if (Config.getInstance().getUseMySQL()) { if (Config.getInstance().getUseMySQL()) {

View File

@ -3,12 +3,13 @@ package com.gmail.nossr50.runnables.party;
import java.util.Iterator; import java.util.Iterator;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
public class PartyAutoKickTask implements Runnable { public class PartyAutoKickTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
updatePartyMembers(); updatePartyMembers();

View File

@ -1,8 +1,10 @@
package com.gmail.nossr50.runnables.party; package com.gmail.nossr50.runnables.party;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
public class PartyLoaderTask implements Runnable { public class PartyLoaderTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
PartyManager.loadParties(); PartyManager.loadParties();

View File

@ -1,10 +1,12 @@
package com.gmail.nossr50.runnables.player; package com.gmail.nossr50.runnables.player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PlayerProfileSaveTask implements Runnable { public class PlayerProfileSaveTask extends BukkitRunnable {
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
private PlayerProfile playerProfile; private PlayerProfile playerProfile;

View File

@ -1,11 +1,12 @@
package com.gmail.nossr50.runnables.skills; package com.gmail.nossr50.runnables.skills;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
public class AwardCombatXpTask implements Runnable { public class AwardCombatXpTask extends BukkitRunnable {
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
private double baseXp; private double baseXp;
private SkillType skillType; private SkillType skillType;

View File

@ -7,12 +7,13 @@ import java.util.Map.Entry;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.ParticleEffectUtils; import com.gmail.nossr50.util.skills.ParticleEffectUtils;
public class BleedTimerTask implements Runnable { public class BleedTimerTask extends BukkitRunnable {
private final static int MAX_BLEED_TICKS = 10; private final static int MAX_BLEED_TICKS = 10;
private static Map<LivingEntity, Integer> bleedList = new HashMap<LivingEntity, Integer>(); private static Map<LivingEntity, Integer> bleedList = new HashMap<LivingEntity, Integer>();

View File

@ -0,0 +1,17 @@
package com.gmail.nossr50.runnables.skills;
import org.bukkit.block.BlockState;
import org.bukkit.scheduler.BukkitRunnable;
public class HerbalismBlockUpdaterTask extends BukkitRunnable {
private BlockState blockState;
public HerbalismBlockUpdaterTask(BlockState blockState) {
this.blockState = blockState;
}
@Override
public void run() {
blockState.update(true);
}
}

View File

@ -1,27 +1,19 @@
package com.gmail.nossr50.runnables.skills; package com.gmail.nossr50.runnables.skills;
import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class SkillMonitorTask implements Runnable { public class SkillMonitorTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
long curTime = System.currentTimeMillis(); long curTime = System.currentTimeMillis();
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers().values()) {
if (Misc.isNPCEntity(player)) {
continue;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
/* /*
* MONITOR SKILLS * MONITOR SKILLS
*/ */

View File

@ -1,46 +0,0 @@
package com.gmail.nossr50.runnables.skills.herbalism;
import org.bukkit.CropState;
import org.bukkit.block.BlockState;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
public class GreenTerraTimerTask implements Runnable {
private BlockState blockState;
/**
* Convert plants affected by the Green Terra ability.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public GreenTerraTimerTask(BlockState blockState) {
this.blockState = blockState;
}
@Override
public void run() {
switch (blockState.getType()) {
case CROPS:
case CARROT:
case POTATO:
blockState.setRawData(CropState.MEDIUM.getData());
blockState.update(true);
return;
case NETHER_WARTS:
blockState.setRawData((byte) 0x2);
blockState.update(true);
return;
case COCOA:
CocoaPlant plant = (CocoaPlant) blockState.getData();
plant.setSize(CocoaPlantSize.MEDIUM);
blockState.setData(plant);
blockState.update(true);
return;
default:
return;
}
}
}

View File

@ -1,66 +0,0 @@
package com.gmail.nossr50.runnables.skills.herbalism;
import org.bukkit.block.BlockState;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import com.gmail.nossr50.skills.herbalism.Herbalism;
public class GreenThumbTimerTask implements Runnable {
private BlockState blockState;
private int skillLevel;
/**
* Convert plants affected by the Green Thumb ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @param skillLevel The player's Herbalism skill level
*/
public GreenThumbTimerTask(BlockState blockState, int skillLevel) {
this.blockState = blockState;
this.skillLevel = skillLevel;
}
@Override
public void run() {
int greenThumbStage = Math.min(Math.min(skillLevel, Herbalism.greenThumbStageMaxLevel) / Herbalism.greenThumbStageChangeLevel, 4);
switch (blockState.getType()) {
case CROPS:
case CARROT:
case POTATO:
blockState.setRawData((byte) greenThumbStage);
blockState.update(true);
return;
case NETHER_WARTS:
if (greenThumbStage > 2) {
blockState.setRawData((byte) 0x2);
}
else if (greenThumbStage == 2) {
blockState.setRawData((byte) 0x1);
}
else {
blockState.setRawData((byte) 0x0);
}
blockState.update(true);
return;
case COCOA:
CocoaPlant plant = (CocoaPlant) blockState.getData();
if (greenThumbStage > 1) {
plant.setSize(CocoaPlantSize.MEDIUM);
}
else {
plant.setSize(CocoaPlantSize.SMALL);
}
blockState.setData(plant);
blockState.update(true);
return;
default:
return;
}
}
}

View File

@ -45,7 +45,7 @@ public class ArcheryManager extends SkillManager {
Location shooterLocation = player.getLocation(); Location shooterLocation = player.getLocation();
Location targetLocation = target.getLocation(); Location targetLocation = target.getLocation();
if (!shooterLocation.getWorld().equals(targetLocation.getWorld())) { if (shooterLocation.getWorld() != targetLocation.getWorld()) {
return; return;
} }

View File

@ -3,29 +3,27 @@ package com.gmail.nossr50.skills.archery;
import java.util.UUID; import java.util.UUID;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
public class TrackedEntity implements Runnable { public class TrackedEntity extends BukkitRunnable {
private LivingEntity livingEntity; private LivingEntity livingEntity;
private UUID id; private UUID id;
private int arrowCount; private int arrowCount;
private int taskId;
private BukkitScheduler scheduler;
protected TrackedEntity(LivingEntity livingEntity) { protected TrackedEntity(LivingEntity livingEntity) {
this.livingEntity = livingEntity; this.livingEntity = livingEntity;
this.id = livingEntity.getUniqueId(); this.id = livingEntity.getUniqueId();
this.scheduler = mcMMO.p.getServer().getScheduler();
this.taskId = scheduler.scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000); this.runTaskTimer(mcMMO.p, 12000, 12000);
} }
@Override @Override
public void run() { public void run() {
if (!livingEntity.isValid()) { if (!livingEntity.isValid()) {
Archery.removeFromTracker(this); Archery.removeFromTracker(this);
scheduler.cancelTask(taskId); this.cancel();
} }
} }

View File

@ -189,7 +189,7 @@ public class FishingManager extends SkillManager {
} }
Misc.dropItem(target.getLocation(), drop); Misc.dropItem(target.getLocation(), drop);
CombatUtils.dealDamage(target, target.getMaxHealth() / 4); // Make it so you can shake a mob no more than 4 times. CombatUtils.dealDamage(target, Math.max(target.getMaxHealth() / 4, 1)); // Make it so you can shake a mob no more than 4 times.
} }
} }
@ -217,7 +217,7 @@ public class FishingManager extends SkillManager {
FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size())); FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
ItemStack treasureDrop = treasure.getDrop(); ItemStack treasureDrop = treasure.getDrop();
if (!SkillUtils.treasureDropSuccessful(treasure.getDropChance(), skillLevel)) { if (!SkillUtils.treasureDropSuccessful(treasure.getDropChance(), activationChance)) {
return null; return null;
} }

View File

@ -63,24 +63,20 @@ public class Herbalism {
protected static int calculateCatciAndSugarDrops(BlockState blockState) { protected static int calculateCatciAndSugarDrops(BlockState blockState) {
Block block = blockState.getBlock(); Block block = blockState.getBlock();
Material blockType = blockState.getType(); Material blockType = blockState.getType();
int dropAmount = 0; int dropAmount = mcMMO.placeStore.isTrue(block) ? 0 : 1;
// Handle the original block
if (!mcMMO.placeStore.isTrue(blockState)) {
dropAmount++;
}
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally // Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
for (int y = 1; y < 3; y++) { for (int y = 1; y < 3; y++) {
Block relativeBlock = block.getRelative(BlockFace.UP, y); Block relativeBlock = block.getRelative(BlockFace.UP, y);
Material relativeBlockType = relativeBlock.getType();
// If the first one is air, so is the next one if (relativeBlock.getType() != blockType) {
if (relativeBlockType == Material.AIR) {
break; break;
} }
if (relativeBlockType == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) { if (mcMMO.placeStore.isTrue(relativeBlock)) {
mcMMO.placeStore.setFalse(relativeBlock);
}
else {
dropAmount++; dropAmount++;
} }
} }

View File

@ -3,12 +3,14 @@ package com.gmail.nossr50.skills.herbalism;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Location; import org.bukkit.CropState;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@ -20,8 +22,7 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.herbalism.GreenTerraTimerTask; import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
import com.gmail.nossr50.runnables.skills.herbalism.GreenThumbTimerTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -76,7 +77,7 @@ public class HerbalismManager extends SkillManager {
* @return the modified change in hunger for the event * @return the modified change in hunger for the event
*/ */
public int farmersDiet(int rankChange, int eventFoodLevel) { public int farmersDiet(int rankChange, int eventFoodLevel) {
return SkillUtils.handleFoodSkills(getPlayer(), SkillType.HERBALISM, eventFoodLevel, Herbalism.farmersDietRankLevel1, Herbalism.farmersDietMaxLevel, rankChange); return SkillUtils.handleFoodSkills(getPlayer(), skill, eventFoodLevel, Herbalism.farmersDietRankLevel1, Herbalism.farmersDietMaxLevel, rankChange);
} }
/** /**
@ -107,65 +108,63 @@ public class HerbalismManager extends SkillManager {
} }
/** /**
* Process double drops & XP gain for Herbalism. *
* *
* @param blockState The {@link BlockState} to check ability activation for * @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/ */
public void herbalismBlockCheck(BlockState blockState) { public void herbalismBlockCheck(BlockState blockState) {
Player player = getPlayer(); Material material = blockState.getType();
Material blockType = blockState.getType(); boolean oneBlockPlant = (material == Material.CACTUS || material == Material.SUGAR_CANE_BLOCK) ? false : true;
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType); if (oneBlockPlant && mcMMO.placeStore.isTrue(blockState)) {
CustomBlock customBlock = null; return;
}
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(material);
ItemStack drop = null;
int amount = 1;
int xp = 0; int xp = 0;
int dropAmount = 1; boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility());
ItemStack dropItem = null;
if (herbalismBlock != null) { if (herbalismBlock != null) {
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) { if (herbalismBlock.hasGreenThumbPermission(getPlayer())) {
dropItem = herbalismBlock.getDropItem(); processGreenThumbPlants(blockState, greenTerra);
dropAmount = Herbalism.calculateCatciAndSugarDrops(blockState);
xp = herbalismBlock.getXpGain() * dropAmount;
} }
else if (herbalismBlock.hasGreenThumbPermission(player)) {
dropItem = herbalismBlock.getDropItem(); xp = herbalismBlock.getXpGain();
xp = herbalismBlock.getXpGain();
processGreenThumbPlants(blockState); if (herbalismBlock.canDoubleDrop() && Permissions.doubleDrops(getPlayer(), skill)) {
drop = herbalismBlock.getDropItem();
} }
else {
if (!mcMMO.placeStore.isTrue(blockState)) { if (!oneBlockPlant) {
dropItem = herbalismBlock.getDropItem(); amount = Herbalism.calculateCatciAndSugarDrops(blockState);
xp = herbalismBlock.getXpGain(); xp *= amount;
}
} }
} }
else { else {
customBlock = ModUtils.getCustomBlock(blockState); CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
dropItem = customBlock.getItemDrop();
xp = customBlock.getXpGain(); xp = customBlock.getXpGain();
}
if (Permissions.doubleDrops(player, skill) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.doubleDropsMaxChance, Herbalism.doubleDropsMaxLevel)) { if (Permissions.doubleDrops(getPlayer(), skill)) {
Location location = blockState.getLocation();
if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
Misc.dropItems(location, dropItem, dropAmount);
}
else if (customBlock != null) {
int minimumDropAmount = customBlock.getMinimumDropAmount(); int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount(); int maximumDropAmount = customBlock.getMaximumDropAmount();
drop = customBlock.getItemDrop();
if (minimumDropAmount != maximumDropAmount) { amount = Misc.getRandom().nextInt(maximumDropAmount - minimumDropAmount + 1) + minimumDropAmount;
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
}
Misc.dropItems(location, dropItem, minimumDropAmount);
} }
} }
applyXpGain(xp); applyXpGain(xp);
if (drop == null) {
return;
}
for (int i = greenTerra ? 2 : 1; i != 0; i--) {
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.doubleDropsMaxChance, Herbalism.doubleDropsMaxLevel)) {
Misc.dropItems(blockState.getLocation(), drop, amount);
}
}
} }
/** /**
@ -269,29 +268,82 @@ public class HerbalismManager extends SkillManager {
* Process the Green Thumb ability for plants. * Process the Green Thumb ability for plants.
* *
* @param blockState The {@link BlockState} to check ability activation for * @param blockState The {@link BlockState} to check ability activation for
* @param greenTerra
*/ */
private void processGreenThumbPlants(BlockState blockState) { private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) {
Player player = getPlayer(); Player player = getPlayer();
PlayerInventory playerInventory = player.getInventory(); PlayerInventory playerInventory = player.getInventory();
ItemStack seed = HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem(); ItemStack seed = (blockState.getType() == Material.CROPS) ? new ItemStack(Material.SEEDS) : HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
if (!playerInventory.containsAtLeast(seed, 1)) { if (!playerInventory.containsAtLeast(seed, 1)) {
return; return;
} }
if (mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA)) { if (!greenTerra && !SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GreenTerraTimerTask(blockState), 0);
return; return;
} }
else if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GreenThumbTimerTask(blockState, getSkillLevel()), 0); if (!handleBlockState(blockState, greenTerra)) {
return; return;
} }
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available
new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
}
private boolean handleBlockState(BlockState blockState, boolean greenTerra) {
switch (blockState.getType()) {
case CROPS:
case CARROT:
case POTATO:
if (greenTerra) {
blockState.setRawData(CropState.MEDIUM.getData()); // 2
}
else {
blockState.setRawData(getGreenThumbStage());
}
return true;
case NETHER_WARTS:
if (greenTerra) {
blockState.setRawData((byte) 2);
}
else {
int greenThumbStage = getGreenThumbStage();
if (greenThumbStage > 2) {
blockState.setRawData((byte) 2);
}
else if (greenThumbStage == 2) {
blockState.setRawData((byte) 1);
}
else {
blockState.setRawData((byte) 0);
}
}
return true;
case COCOA:
CocoaPlant plant = (CocoaPlant) blockState.getData();
if (greenTerra || getGreenThumbStage() > 1) {
plant.setSize(CocoaPlantSize.MEDIUM);
}
else {
plant.setSize(CocoaPlantSize.SMALL);
}
return true;
default:
return false;
}
}
private byte getGreenThumbStage() {
return (byte) Math.min(Math.min(getProfile().getSkillLevel(skill), Herbalism.greenThumbStageMaxLevel) / Herbalism.greenThumbStageChangeLevel, 4);
} }
} }

Some files were not shown because too many files have changed in this diff Show More