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
*.wav binary

82
.gitignore vendored
View File

@ -1,42 +1,42 @@
# Eclipse stuff
/.classpath
/.project
/.settings
# netbeans
/nbproject
# we use maven!
/build.xml
# maven
/target
# vim
.*.sw[a-p]
# various other potential build files
/build
/bin
/dist
/manifest.mf
/world
# Mac filesystem dust
*.DS_Store
# intellij
*.iml
*.ipr
*.iws
.idea/
# Project Stuff
/src/main/resources/mcMMO
# Other Libraries
*.jar
# Atlassian Stuff
# Eclipse stuff
/.classpath
/.project
/.settings
# netbeans
/nbproject
# we use maven!
/build.xml
# maven
/target
# vim
.*.sw[a-p]
# various other potential build files
/build
/bin
/dist
/manifest.mf
/world
# Mac filesystem dust
*.DS_Store
# intellij
*.iml
*.ipr
*.iws
.idea/
# Project Stuff
/src/main/resources/mcMMO
# Other Libraries
*.jar
# Atlassian Stuff
/atlassian-ide-plugin.xml

View File

@ -7,8 +7,48 @@ Key:
! Change
- 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 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
+ Added API to get the skill and power level caps.

View File

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

View File

@ -1,14 +1,14 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>${project.build.directory}/${artifactId}.jar</source>
<outputDirectory>/</outputDirectory>
<destName>mcMMO.jar</destName>
</file>
</files>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>${project.build.directory}/${artifactId}.jar</source>
<outputDirectory>/</outputDirectory>
<destName>mcMMO.jar</destName>
</file>
</files>
</assembly>

View File

@ -39,22 +39,6 @@ public final class ChatAPI {
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
* </br>
@ -82,21 +66,6 @@ public final class ChatAPI {
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.
*

View File

@ -1,30 +1,18 @@
package com.gmail.nossr50.api;
import java.util.Set;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
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.skills.SkillUtils;
public final class 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.
* </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>
* 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 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 addMultipliedXP(Player player, SkillType skillType, int XP) {
UserManager.getPlayer(player).applyXpGain(skillType, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
public static void addRawXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, skillType, XP);
}
/**
@ -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>
* 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 #addXP(Player, String, int)} instead
*/
@Deprecated
public static void addXP(Player player, SkillType skillType, int XP) {
UserManager.getPlayer(player).beginXpGain(skillType, XP);
public static void addModifiedXP(Player player, String skillType, int XP) {
SkillType skill = SkillType.getSkill(skillType);
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);
}
/**
* 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.
* </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>
* This function is designed for API usage.
*
* @param player The player to get the XP amount for
* @param skillType The skill to get the XP amount for
* @return the amount of XP left before leveling up a specifc skill
* @deprecated Use {@link #getXPToNextLevel(Player, String)} instead
* @param playerName The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static int getXPToNextLevel(Player player, SkillType skillType) {
return UserManager.getPlayer(player).getProfile().getXpToLevel(skillType);
public static int getOfflineXP(String playerName, String skillType) {
return getOfflineProfile(playerName).getSkillXpLevel(SkillType.getSkill(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>
* 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
* @param notify Unused argument
* @deprecated Use addLevel(Player, SKillType, int) instead
* @param playerName The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static void addLevel(Player player, SkillType skillType, int levels, boolean notify) {
UserManager.getProfile(player).addLevels(skillType, levels);
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);
public static int getOfflineXPToNextLevel(String playerName, String skillType) {
return getOfflineProfile(playerName).getXpToLevel(SkillType.getSkill(skillType));
}
/**
@ -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>
* This function is designed for API usage.
*
* @param player The player to get the level for
* @param skillType The skill to get the level for
* @return the level of a given skill
* @deprecated Use {@link #getLevel(Player, String)} instead
* @param playerName The player to add levels to
* @param skillType Type of skill to add levels to
* @param levels Number of levels to add
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static int getLevel(Player player, SkillType skillType) {
return UserManager.getPlayer(player).getProfile().getSkillLevel(skillType);
public static void addLevelOffline(String playerName, String skillType, int levels) {
PlayerProfile profile = getOfflineProfile(playerName);
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));
}
/**
* 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.
* </br>
@ -237,6 +249,30 @@ public final class ExperienceAPI {
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.
* </br>
@ -260,21 +296,6 @@ public final class ExperienceAPI {
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.
* </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>
* This function is designed for API usage.
*
* @param player The player to set the XP of
* @param skillType The skill to set the XP for
* @param newValue The value to set the XP to
* @deprecated Use {@link #setXP(Player, String, int)} instead
* @param playerName 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
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static void setXP(Player player, SkillType skillType, int newValue) {
UserManager.getPlayer(player).getProfile().setSkillXpLevel(skillType, newValue);
public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
getOfflineProfile(playerName).modifySkill(SkillType.getSkill(skillType), skillLevel);
}
/**
@ -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>
* This function is designed for API usage.
*
* @param player The player to change the XP of
* @param skillType The skill to change the XP for
* @param xp The amount of XP to remove
* @deprecated Use {@link #removeXP(Player, String, int)} instead
* @param playerName The player to set the XP of
* @param skillType The skill to set the XP for
* @param newValue The value to set the XP to
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static void removeXP(Player player, SkillType skillType, int xp) {
UserManager.getPlayer(player).getProfile().removeXp(skillType, xp);
public static void setXPOffline(String playerName, String skillType, int newValue) {
getOfflineProfile(playerName).setSkillXpLevel(SkillType.getSkill(skillType), newValue);
}
/**
@ -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 skillType The skill to check
* @deprecated Calling this function is no longer needed and should be avoided
* @param playerName The player to change the XP of
* @param skillType The skill to change the XP for
* @param xp The amount of XP to remove
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
private static void checkXP(Player player, SkillType skillType) {
SkillUtils.xpCheckSkill(skillType, player, UserManager.getProfile(player));
public static void removeXPOffline(String playerName, String skillType, int xp) {
getOfflineProfile(playerName).removeXp(SkillType.getSkill(skillType), xp);
}
/**
* 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;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.OfflinePlayer;
@ -19,9 +18,13 @@ public final class PartyAPI {
* This function is designed for API usage.
*
* @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) {
if (!inParty(player)) {
return null;
}
return UserManager.getPlayer(player).getParty().getName();
}
@ -116,26 +119,6 @@ public final class PartyAPI {
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.
* </br>

View File

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

View File

@ -6,35 +6,32 @@ 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.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public class McrefreshCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
switch (args.length) {
case 0:
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.mcrefresh(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!(sender instanceof Player)) {
return false;
}
mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
mcMMOPlayer.setRecentlyHurt(0);
mcMMOPlayer.getProfile().resetCooldowns();
mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode();
sender.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
refreshPlayer();
return true;
case 1:
@ -45,31 +42,17 @@ public class McrefreshCommand implements CommandExecutor {
mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) {
PlayerProfile playerProfile = new PlayerProfile(args[0], false);
if (!playerProfile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
if (CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) {
return true;
}
Player player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
if (CommandUtils.isOffline(sender, player)) {
return true;
}
mcMMOPlayer.setRecentlyHurt(0);
mcMMOPlayer.getProfile().resetCooldowns();
mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
refreshPlayer();
sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", args[0]));
return true;
@ -77,4 +60,13 @@ public class McrefreshCommand implements CommandExecutor {
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.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils;
public class XprateCommand implements CommandExecutor {
private static double originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
private double originalRate;
public XprateCommand() {
originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -35,8 +39,8 @@ public class XprateCommand implements CommandExecutor {
return true;
case 2:
if (!StringUtils.isInt(args[0])) {
return false;
if (CommandUtils.isInvalidInteger(sender, args[0])) {
return true;
}
if (!Permissions.xprateSet(sender)) {
@ -44,11 +48,16 @@ public class XprateCommand implements CommandExecutor {
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;
}
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
int newXpRate = Integer.parseInt(args[0]);
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.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.chat.ChatMode;
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;
public abstract class ChatCommand implements CommandExecutor {
protected McMMOPlayer mcMMOPlayer;
protected ChatMode chatMode;
private McMMOPlayer mcMMOPlayer;
public ChatCommand(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) {
switch (args.length) {
case 0:
if (!(sender instanceof Player)) {
return false;
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
mcMMOPlayer = UserManager.getPlayer((Player) sender);
mcMMOPlayer = UserManager.getPlayer(sender.getName());
if (chatMode.isEnabled(mcMMOPlayer)) {
disableChatMode(sender);
@ -37,20 +38,24 @@ public abstract class ChatCommand implements CommandExecutor {
return true;
case 1:
if (args[0].equalsIgnoreCase("on")) {
if (!(sender instanceof Player)) {
return false;
if (CommandUtils.shouldEnableToggle(args[0])) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
mcMMOPlayer = UserManager.getPlayer(sender.getName());
enableChatMode(sender);
return true;
}
if (args[0].equalsIgnoreCase("off")) {
if (!(sender instanceof Player)) {
return false;
if (CommandUtils.shouldDisableToggle(args[0])) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
mcMMOPlayer = UserManager.getPlayer(sender.getName());
disableChatMode(sender);
return true;
}
@ -78,11 +83,21 @@ public abstract class ChatCommand implements CommandExecutor {
protected abstract void handleChatSending(CommandSender sender, String[] args);
private void enableChatMode(CommandSender sender) {
if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return;
}
chatMode.enable(mcMMOPlayer);
sender.sendMessage(chatMode.getEnabledMessage());
}
private void disableChatMode(CommandSender sender) {
if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return;
}
chatMode.disable(mcMMOPlayer);
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.LeaderboardManager;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class McremoveCommand implements CommandExecutor {
@ -25,7 +26,7 @@ public class McremoveCommand implements CommandExecutor {
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
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]));
}
else {
@ -34,7 +35,7 @@ public class McremoveCommand implements CommandExecutor {
}
else {
if (LeaderboardManager.removeFlatFileUser(args[0])) {
DatabaseManager.profileCleanup(args[0]);
Misc.profileCleanup(args[0]);
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
}
else {

View File

@ -46,6 +46,6 @@ public class MmoupdateCommand implements CommandExecutor {
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;
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.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public class AddlevelsCommand implements CommandExecutor {
public class AddlevelsCommand extends ExperienceCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
int levels;
boolean allSkills = false;
SkillType skill = null;
protected boolean permissionsCheckSelf(CommandSender sender) {
return Permissions.addlevels(sender);
}
switch (args.length) {
case 2:
if (!Permissions.addlevels(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
@Override
protected boolean permissionsCheckOthers(CommandSender sender) {
return Permissions.addlevelsOthers(sender);
}
if (!(sender instanceof Player)) {
return false;
}
@Override
protected void handleCommand(SkillType skill) {
profile.addLevels(skill, value);
}
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
@Override
protected void handlePlayerMessageAll() {
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", value));
}
if (!StringUtils.isInt(args[1])) {
return false;
}
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;
}
@Override
protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, SkillUtils.getSkillName(skill)));
}
}

View File

@ -1,152 +1,40 @@
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.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public class AddxpCommand implements CommandExecutor {
public class AddxpCommand extends ExperienceCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
int xp;
McMMOPlayer mcMMOPlayer;
PlayerProfile profile;
boolean allSkills = false;
SkillType skill = null;
protected boolean permissionsCheckSelf(CommandSender sender) {
return Permissions.addxp(sender);
}
switch (args.length) {
case 2:
if (!Permissions.addxp(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
@Override
protected boolean permissionsCheckOthers(CommandSender sender) {
return Permissions.addxpOthers(sender);
}
if (!(sender instanceof Player)) {
return false;
}
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
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 handleCommand(SkillType skill) {
if (player != null) {
mcMMOPlayer.applyXpGain(skill, value);
}
else {
profile.setSkillXpLevel(skill, value);
}
}
@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;
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.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public class MmoeditCommand implements CommandExecutor {
public class MmoeditCommand extends ExperienceCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
int newValue;
boolean allSkills = false;
SkillType skill = null;
protected boolean permissionsCheckSelf(CommandSender sender) {
return Permissions.mmoedit(sender);
}
switch (args.length) {
case 2:
if (!Permissions.mmoedit(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
@Override
protected boolean permissionsCheckOthers(CommandSender sender) {
return Permissions.mmoeditOthers(sender);
}
if (!(sender instanceof Player)) {
return false;
}
@Override
protected void handleCommand(SkillType skill) {
profile.modifySkill(skill, value);
}
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
@Override
protected void handlePlayerMessageAll() {
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", value));
}
if (!StringUtils.isInt(args[1])) {
return false;
}
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;
}
@Override
protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", SkillUtils.getSkillName(skill), value));
}
}

View File

@ -1,76 +1,47 @@
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.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
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
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
boolean allSkills = false;
SkillType skill = null;
String skillName = "";
this.command = command;
this.sender = sender;
argsLength = args.length;
switch (args.length) {
case 1:
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.skillreset(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!(sender instanceof Player)) {
return false;
}
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
if (isInvalidSkill(sender, args[0])) {
return true;
}
profile = UserManager.getPlayer((Player) sender).getProfile();
if (allSkills) {
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));
}
mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
profile = mcMMOPlayer.getProfile();
editValues();
return true;
case 2:
@ -79,91 +50,67 @@ public class SkillresetCommand implements CommandExecutor {
return true;
}
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
if (isInvalidSkill(sender, args[1])) {
return true;
}
if (!allSkills) {
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]);
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"));
if (CommandUtils.unloadedProfile(sender, profile)) {
return true;
}
if (allSkills) {
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);
}
editValues();
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
player = mcMMOPlayer.getPlayer();
if (allSkills) {
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]));
editValues();
}
handleSenderMessage(sender, args[0]);
return true;
default:
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;
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.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
public class HardcoreCommand implements CommandExecutor {
public class HardcoreCommand extends HardcoreModeCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
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() {
protected void disable() {
Config.getInstance().setHardcoreEnabled(false);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Disabled"));
}
private void enableHardcore() {
@Override
protected void enable() {
Config.getInstance().setHardcoreEnabled(true);
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;
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.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
public class VampirismCommand implements CommandExecutor {
public class VampirismCommand extends HardcoreModeCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Config.getInstance().getHardcoreEnabled()) {
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;
}
protected boolean checkTogglePermissions() {
return Permissions.vampirismToggle(sender);
}
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);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Disabled"));
}
private void enableVampirism() {
Config.getInstance().setHardcoreVampirismEnabled(true);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Enabled"));
@Override
protected void modify() {
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;
public class PartyAcceptCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer();
if (!mcMMOPlayer.hasPartyInvite()) {
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.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
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) {
switch (args.length) {
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]))) {
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.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager;
public class PartyChangePasswordCommand implements CommandExecutor {
private Party playerParty;
@Override
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) {
case 1:
unprotectParty(sender, playerParty);
unprotectParty(sender);
return true;
case 2:
if (args[1].equalsIgnoreCase("clear") || args[1].equalsIgnoreCase("reset")) {
unprotectParty(sender, playerParty);
unprotectParty(sender);
return true;
}
protectParty(sender, playerParty, args[1]);
protectParty(sender, args[1]);
return true;
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.setPassword(null);
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.setPassword(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.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.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
@ -31,8 +31,8 @@ public class PartyCommand implements CommandExecutor {
private CommandExecutor partyRenameCommand = new PartyRenameCommand();
private CommandExecutor partyInfoCommand = new PartyInfoCommand();
private CommandExecutor partyHelpCommand = new PartyHelpCommand();
private CommandExecutor partyTeleportCommand = new PtpCommand();
private CommandExecutor partyChatCommand = new PartyChatCommand();
private CommandExecutor partyTeleportCommand = mcMMO.p.getCommand("ptp").getExecutor();
private CommandExecutor partyChatCommand = mcMMO.p.getCommand("partychat").getExecutor();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -45,8 +45,8 @@ public class PartyCommand implements CommandExecutor {
return true;
}
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
if (args.length < 1) {
if (!mcMMOPlayer.inParty()) {
@ -104,7 +104,7 @@ public class PartyCommand implements CommandExecutor {
}
// Party leader commands
if (!mcMMOPlayer.getParty().getLeader().equals(player.getName())) {
if (!mcMMOPlayer.getParty().getLeader().equalsIgnoreCase(player.getName())) {
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true;
}
@ -121,7 +121,6 @@ public class PartyCommand implements CommandExecutor {
case OWNER:
return partyChangeOwnerCommand.onCommand(sender, command, label, args);
case LOCK:
// Fallthrough
case UNLOCK:
return partyLockCommand.onCommand(sender, command, label, args);
case PASSWORD:

View File

@ -12,26 +12,21 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
public class PartyCreateCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
// Fallthrough
case 3:
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
if (newParty != null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", args[1]));
if (PartyManager.checkPartyExistence(player, newParty, args[1])) {
return true;
}
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
// Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), args[1])) {
return true;

View File

@ -16,10 +16,11 @@ public class PartyDisbandCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
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()) {
if (!PartyManager.handlePartyChangeEvent(member, playerParty.getName(), null, EventReason.KICKED_FROM_PARTY)) {
if (!PartyManager.handlePartyChangeEvent(member, partyName, null, EventReason.KICKED_FROM_PARTY)) {
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.ShareMode;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public class PartyExpShareCommand implements CommandExecutor {
@ -25,12 +26,12 @@ public class PartyExpShareCommand implements CommandExecutor {
switch (args.length) {
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);
}
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);
}
else {
@ -48,8 +49,10 @@ public class PartyExpShareCommand implements CommandExecutor {
private void handleChangingShareMode(ShareHandler.ShareMode 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()) {
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;
}
}
}

View File

@ -21,8 +21,8 @@ public class PartyInfoCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
playerParty = mcMMOPlayer.getParty();
displayPartyHeader();
@ -35,15 +35,19 @@ public class PartyInfoCommand implements CommandExecutor {
StringBuilder memberList = new StringBuilder();
for (OfflinePlayer member : playerParty.getMembers()) {
if (playerParty.getLeader().equals(member.getName())) {
memberList.append(ChatColor.GOLD).append(member.getName()).append(" ");
String memberName = member.getName();
if (playerParty.getLeader().equalsIgnoreCase(memberName)) {
memberList.append(ChatColor.GOLD);
}
else if (member.isOnline()) {
memberList.append(ChatColor.WHITE).append(member.getName()).append(" ");
memberList.append(ChatColor.WHITE);
}
else {
memberList.append(ChatColor.GRAY).append(member.getName()).append(" ");
memberList.append(ChatColor.GRAY);
}
memberList.append(memberName).append(" ");
}
return memberList.toString();
@ -52,7 +56,7 @@ public class PartyInfoCommand implements CommandExecutor {
private void displayShareModeInfo() {
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
boolean itemSharingActive = playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE;
boolean itemSharingActive = (playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE);
if (!xpShareEnabled && !itemShareEnabled) {
return;
@ -97,6 +101,6 @@ public class PartyInfoCommand implements CommandExecutor {
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
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.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public class PartyInviteCommand implements CommandExecutor {
private McMMOPlayer mcMMOTarget;
private Player target;
private McMMOPlayer mcMMOPlayer;
private Player player;
private Party playerParty;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
if (!mcMMO.p.getServer().getOfflinePlayer(args[1]).isOnline()) {
sender.sendMessage(LocaleLoader.getString("Party.NotOnline", args[1]));
McMMOPlayer mcMMOTarget = UserManager.getPlayer(args[1]);
if (CommandUtils.checkPlayerExistence(sender, args[1], mcMMOTarget)) {
return true;
}
mcMMOTarget = UserManager.getPlayer(args[1]);
if (mcMMOTarget == null) {
sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
return true;
}
target = mcMMOTarget.getPlayer();
mcMMOPlayer = UserManager.getPlayer((Player) sender);
player = mcMMOPlayer.getPlayer();
Player target = mcMMOTarget.getPlayer();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer();
if (player.equals(target)) {
sender.sendMessage(LocaleLoader.getString("Party.Invite.Self"));
@ -50,7 +37,7 @@ public class PartyInviteCommand implements CommandExecutor {
return true;
}
playerParty = mcMMOPlayer.getParty();
Party playerParty = mcMMOPlayer.getParty();
if (!PartyManager.canInvite(player, playerParty)) {
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.ShareMode;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public class PartyItemShareCommand implements CommandExecutor {
@ -25,9 +26,9 @@ public class PartyItemShareCommand implements CommandExecutor {
switch (args.length) {
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);
}
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
@ -43,15 +44,19 @@ public class PartyItemShareCommand implements CommandExecutor {
return true;
case 3:
playerParty = UserManager.getPlayer((Player) sender).getParty();
playerParty = UserManager.getPlayer(sender.getName()).getParty();
boolean toggle = false;
if (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("on") || args[2].equalsIgnoreCase("enabled")) {
if (CommandUtils.shouldEnableToggle(args[2])) {
toggle = true;
}
else if (args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("off") || args[2].equalsIgnoreCase("disabled")) {
else if (CommandUtils.shouldDisableToggle(args[2])) {
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")) {
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>"));
}
notifyToggleItemShareCategory(args, toggle);
notifyToggleItemShareCategory(args[1], toggle);
return true;
default:
@ -82,20 +87,20 @@ public class PartyItemShareCommand implements CommandExecutor {
private void handleChangingShareMode(ShareHandler.ShareMode 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()) {
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) {
String state = "disabled";
private void notifyToggleItemShareCategory(String category, boolean toggle) {
String state = toggle ? "enabled" : "disabled";
if (toggle) {
state = "enabled";
}
String toggleMessage = LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(category), state);
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.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
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) {
switch (args.length) {
case 2:
// Fallthrough
case 3:
// Verify target exists and is in a different party than the player
if (!canJoinParty(sender, args[1])) {
@ -62,16 +61,10 @@ public class PartyJoinCommand implements CommandExecutor {
}
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);
if (mcMMOTarget == null) {
sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
return false;
if (CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return true;
}
target = mcMMOTarget.getPlayer();
@ -81,8 +74,9 @@ public class PartyJoinCommand implements CommandExecutor {
return false;
}
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
playerParty = mcMMOPlayer.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) {
switch (args.length) {
case 2:
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]);
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.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public class PartyLockCommand implements CommandExecutor {
@ -15,15 +15,15 @@ public class PartyLockCommand implements CommandExecutor {
@Override
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) {
case 1:
if (args[0].equalsIgnoreCase("lock")) {
lockParty(sender, command);
lockParty(sender, command.getPermissionMessage());
}
else if (args[0].equalsIgnoreCase("unlock")) {
unlockParty(sender, command);
unlockParty(sender, command.getPermissionMessage());
}
return true;
@ -34,11 +34,11 @@ public class PartyLockCommand implements CommandExecutor {
return true;
}
if (args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) {
lockParty(sender, command);
if (CommandUtils.shouldEnableToggle(args[1])) {
lockParty(sender, command.getPermissionMessage());
}
else if (args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) {
unlockParty(sender, command);
else if (CommandUtils.shouldDisableToggle(args[1])) {
unlockParty(sender, command.getPermissionMessage());
}
else {
sendUsageStrings(sender);
@ -55,9 +55,9 @@ public class PartyLockCommand implements CommandExecutor {
/**
* Handle locking a party.
*/
private void lockParty(CommandSender sender, Command command) {
private void lockParty(CommandSender sender, String permissionMessage) {
if (!Permissions.partySubcommand(sender, PartySubcommandType.LOCK)) {
sender.sendMessage(command.getPermissionMessage());
sender.sendMessage(permissionMessage);
return;
}
@ -75,9 +75,9 @@ public class PartyLockCommand implements CommandExecutor {
*
* @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)) {
sender.sendMessage(command.getPermissionMessage());
sender.sendMessage(permissionMessage);
return;
}

View File

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

View File

@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
@ -14,33 +15,36 @@ import com.gmail.nossr50.util.player.UserManager;
public class PartyRenameCommand implements CommandExecutor {
@Override
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) {
case 2:
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Party playerParty = mcMMOPlayer.getParty();
String oldPartyName = playerParty.getName();
String newPartyName = args[1];
// 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"));
return true;
}
Player player = mcMMOPlayer.getPlayer();
Party newParty = PartyManager.getParty(newPartyName);
// Check to see if the party exists, and if it does cancel renaming the party
if (newParty != null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", newPartyName));
if (PartyManager.checkPartyExistence(player, newParty, newPartyName)) {
return true;
}
String leaderName = playerParty.getLeader();
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;
}
if (!member.getName().equals(leaderName)) {
if (!member.getName().equalsIgnoreCase(leaderName)) {
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.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
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;
@ -17,64 +16,49 @@ import com.gmail.nossr50.util.player.UserManager;
public class InspectCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
switch (args.length) {
case 1:
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); // Temporary Profile
PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile
if (!profile.isLoaded()) {
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"));
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
return true;
}
sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", args[0]));
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)));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Fishing.Listener"), profile.getSkillLevel(SkillType.FISHING), profile.getSkillXpLevel(SkillType.FISHING), profile.getXpToLevel(SkillType.FISHING)));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Herbalism.Listener"), profile.getSkillLevel(SkillType.HERBALISM), profile.getSkillXpLevel(SkillType.HERBALISM), profile.getXpToLevel(SkillType.HERBALISM)));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Mining.Listener"), profile.getSkillLevel(SkillType.MINING), profile.getSkillXpLevel(SkillType.MINING), profile.getXpToLevel(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.EXCAVATION);
CommandUtils.displaySkill(sender, profile, SkillType.FISHING);
CommandUtils.displaySkill(sender, profile, SkillType.HERBALISM);
CommandUtils.displaySkill(sender, profile, SkillType.MINING);
CommandUtils.displaySkill(sender, profile, SkillType.WOODCUTTING);
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)));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Archery.Listener"), profile.getSkillLevel(SkillType.ARCHERY), profile.getSkillXpLevel(SkillType.ARCHERY), profile.getXpToLevel(SkillType.ARCHERY)));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Swords.Listener"), profile.getSkillLevel(SkillType.SWORDS), profile.getSkillXpLevel(SkillType.SWORDS), profile.getXpToLevel(SkillType.SWORDS)));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Taming.Listener"), profile.getSkillLevel(SkillType.TAMING), profile.getSkillXpLevel(SkillType.TAMING), profile.getXpToLevel(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.AXES);
CommandUtils.displaySkill(sender, profile, SkillType.ARCHERY);
CommandUtils.displaySkill(sender, profile, SkillType.SWORDS);
CommandUtils.displaySkill(sender, profile, SkillType.TAMING);
CommandUtils.displaySkill(sender, profile, SkillType.UNARMED);
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)));
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.ACROBATICS);
CommandUtils.displaySkill(sender, profile, SkillType.REPAIR);
}
else {
Player target = mcMMOPlayer.getPlayer();
if (sender instanceof Player) {
Player inspector = (Player) sender;
if (!Misc.isNear(inspector.getLocation(), target.getLocation(), 5.0) && !Permissions.inspectFar(inspector)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}
if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
return true;
}
profile = mcMMOPlayer.getProfile();
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName()));
CommandUtils.printGatheringSkills(target, profile, sender);
CommandUtils.printCombatSkills(target, profile, sender);
CommandUtils.printMiscSkills(target, profile, sender);
CommandUtils.printGatheringSkills(target, sender);
CommandUtils.printCombatSkills(target, sender);
CommandUtils.printMiscSkills(target, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel()));
}

View File

@ -1,10 +1,8 @@
package com.gmail.nossr50.commands.player;
import org.bukkit.Bukkit;
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;
@ -14,8 +12,8 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
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;
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) {
switch (args.length) {
case 0:
if (!Permissions.mcrank(sender)) {
sender.sendMessage(command.getPermissionMessage());
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!(sender instanceof Player)) {
return false;
if (!Permissions.mcrank(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, sender.getName());
}
else {
LeaderboardManager.updateLeaderboards(); // Make sure the information is up to date
flatfileDisplay(sender, sender.getName());
}
@ -52,32 +49,18 @@ public class McrankCommand implements CommandExecutor {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) {
PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (sender instanceof Player && !Permissions.mcrankOffline(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
if (CommandUtils.inspectOffline(sender, new PlayerProfile(args[0], false), Permissions.mcrankOffline(sender))) {
return true;
}
}
else {
Player target = mcMMOPlayer.getPlayer();
if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !Permissions.mcrankFar(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}
else if (CommandUtils.tooFar(sender, mcMMOPlayer.getPlayer(), Permissions.mcrankFar(sender))) {
return true;
}
if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, args[0]);
}
else {
LeaderboardManager.updateLeaderboards(); // Make sure the information is up to date
flatfileDisplay(sender, args[0]);
}
@ -89,13 +72,15 @@ public class McrankCommand implements CommandExecutor {
}
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.Player", playerName));
for (SkillType skillType : SkillType.values()) {
int[] rankInts = LeaderboardManager.getPlayerRank(playerName, skillType);
if (skillType.isChildSkill()) {
if (!Permissions.skillEnabled(sender, skillType) || skillType.isChildSkill()) {
continue;
}
@ -119,6 +104,6 @@ public class McrankCommand implements CommandExecutor {
}
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.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
@ -21,24 +20,23 @@ public class McstatsCommand implements CommandExecutor {
switch (args.length) {
case 0:
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer();
player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
CommandUtils.printGatheringSkills(player, profile);
CommandUtils.printCombatSkills(player, profile);
CommandUtils.printMiscSkills(player, profile);
CommandUtils.printGatheringSkills(player);
CommandUtils.printCombatSkills(player);
CommandUtils.printMiscSkills(player);
int powerLevelCap = Config.getInstance().getPowerLevelCap();
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 {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel()));
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", UserManager.getPlayer(player).getPowerLevel()));
}
return true;

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.commands.player;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
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.util.Permissions;
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 {
private SkillType skill;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
boolean useMySQL = Config.getInstance().getUseMySQL();
switch (args.length) {
case 0:
display(1, "ALL", sender, useMySQL, command);
@ -29,42 +31,26 @@ public class MctopCommand implements CommandExecutor {
case 1:
if (StringUtils.isInt(args[0])) {
display(Integer.parseInt(args[0]), "ALL", sender, useMySQL, command);
}
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"));
return true;
}
if (!extractSkill(sender, args[0])) {
return true;
}
display(1, skill.toString(), sender, useMySQL, command);
return true;
case 2:
if (!StringUtils.isInt(args[1])) {
return false;
if (CommandUtils.isInvalidInteger(sender, args[1])) {
return true;
}
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(Integer.parseInt(args[1]), skill.toString(), sender, useMySQL, command);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
if (!extractSkill(sender, args[0])) {
return true;
}
display(Integer.parseInt(args[1]), skill.toString(), sender, useMySQL, command);
return true;
default:
@ -73,28 +59,26 @@ public class MctopCommand implements CommandExecutor {
}
private void display(int page, String skill, CommandSender sender, boolean sql, Command command) {
if (sql) {
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))) {
if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, this.skill)) {
sender.sendMessage(command.getPermissionMessage());
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")) {
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)));
}
int n = (page * 10) - 9; // Position
for (String x : info) {
if (x != null) {
String digit = String.valueOf(n);
int position = (page * 10) - 9;
if (n < 10) {
digit = "0" + digit;
}
String[] splitx = x.split(":");
// Format: 1. Playername - skill value
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitx[1] + " - " + ChatColor.WHITE + splitx[0]);
n++;
for (String playerStat : LeaderboardManager.retrieveInfo(skill, page)) {
if (playerStat == null) {
continue;
}
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"));
}
private void sqlDisplay(int page, String query, CommandSender sender, Command command) {
Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new MctopCommandAsyncTask(page, query, sender, command));
private void sqlDisplay(int page, String query, CommandSender sender) {
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
protected void dataCalculations() {
// DODGE
String[] dodgeStrings = calculateAbilityDisplayValues(Acrobatics.dodgeMaxBonusLevel, Acrobatics.dodgeMaxChance);
dodgeChance = dodgeStrings[0];
dodgeChanceLucky = dodgeStrings[1];
if (canDodge) {
String[] dodgeStrings = calculateAbilityDisplayValues(Acrobatics.dodgeMaxBonusLevel, Acrobatics.dodgeMaxChance);
dodgeChance = dodgeStrings[0];
dodgeChanceLucky = dodgeStrings[1];
}
// ROLL
String[] rollStrings = calculateAbilityDisplayValues(Acrobatics.rollMaxBonusLevel, Acrobatics.rollMaxChance);
rollChance = rollStrings[0];
rollChanceLucky = rollStrings[1];
if (canRoll) {
String[] rollStrings = calculateAbilityDisplayValues(Acrobatics.rollMaxBonusLevel, Acrobatics.rollMaxChance);
rollChance = rollStrings[0];
rollChanceLucky = rollStrings[1];
}
// GRACEFUL ROLL
String[] gracefulRollStrings = calculateAbilityDisplayValues(Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollMaxChance);
gracefulRollChance = gracefulRollStrings[0];
gracefulRollChanceLucky = gracefulRollStrings[1];
if (canGracefulRoll) {
String[] gracefulRollStrings = calculateAbilityDisplayValues(Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollMaxChance);
gracefulRollChance = gracefulRollStrings[0];
gracefulRollChanceLucky = gracefulRollStrings[1];
}
}
@Override
@ -76,30 +82,15 @@ public class AcrobaticsCommand extends SkillCommand {
@Override
protected void statsDisplay() {
if (canRoll) {
if (isLucky) {
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 }));
}
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", rollChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", rollChanceLucky) : ""));
}
if (canGracefulRoll) {
if (isLucky) {
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 }));
}
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", gracefulRollChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", gracefulRollChanceLucky) : ""));
}
if (canDodge) {
if (isLucky) {
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 }));
}
player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", dodgeChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", dodgeChanceLucky) : ""));
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -12,8 +12,8 @@ public class HerbalismCommand extends SkillCommand {
private String greenTerraLengthEndurance;
private String greenThumbChance;
private String greenThumbChanceLucky;
private String greenThumbStage;
private String farmersDietRank;
private int greenThumbStage;
private int farmersDietRank;
private String doubleDropChance;
private String doubleDropChanceLucky;
private String hylianLuckChance;
@ -23,12 +23,11 @@ public class HerbalismCommand extends SkillCommand {
private boolean hasHylianLuck;
private boolean canGreenTerra;
private boolean canGreenThumbWheat;
private boolean canGreenThumbPlants;
private boolean canGreenThumbBlocks;
private boolean canFarmersDiet;
private boolean canDoubleDrop;
private boolean canShroomThumb;
private boolean doubleDropsDisabled;
public HerbalismCommand() {
super(SkillType.HERBALISM);
@ -37,51 +36,62 @@ public class HerbalismCommand extends SkillCommand {
@Override
protected void dataCalculations() {
// GREEN TERRA
String[] greenTerraStrings = calculateLengthDisplayValues();
greenTerraLength = greenTerraStrings[0];
greenTerraLengthEndurance = greenTerraStrings[1];
if (canGreenTerra) {
String[] greenTerraStrings = calculateLengthDisplayValues();
greenTerraLength = greenTerraStrings[0];
greenTerraLengthEndurance = greenTerraStrings[1];
}
// FARMERS DIET
farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1);
if (canFarmersDiet) {
farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1);
}
// GREEN THUMB
greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageChangeLevel);
if (canGreenThumbBlocks || canGreenThumbPlants) {
greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageChangeLevel);
String[] greenThumbStrings = calculateAbilityDisplayValues(Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance);
greenThumbChance = greenThumbStrings[0];
greenThumbChanceLucky = greenThumbStrings[1];
String[] greenThumbStrings = calculateAbilityDisplayValues(Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance);
greenThumbChance = greenThumbStrings[0];
greenThumbChanceLucky = greenThumbStrings[1];
}
// DOUBLE DROPS
String[] doubleDropStrings = calculateAbilityDisplayValues(Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance);
doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
if (canDoubleDrop) {
String[] doubleDropStrings = calculateAbilityDisplayValues(Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance);
doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
}
// HYLIAN LUCK
String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance);
hylianLuckChance = hylianLuckStrings[0];
hylianLuckChanceLucky = hylianLuckStrings[1];
if (hasHylianLuck) {
String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance);
hylianLuckChance = hylianLuckStrings[0];
hylianLuckChanceLucky = hylianLuckStrings[1];
}
// SHROOM THUMB
String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance);
shroomThumbChance = shroomThumbStrings[0];
shroomThumbChanceLucky = shroomThumbStrings[1];
if (canShroomThumb) {
String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance);
shroomThumbChance = shroomThumbStrings[0];
shroomThumbChanceLucky = shroomThumbStrings[1];
}
}
@Override
protected void permissionsCheck() {
hasHylianLuck = Permissions.hylianLuck(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.
canGreenThumbBlocks = (Permissions.greenThumbBlock(player, Material.DIRT) || Permissions.greenThumbBlock(player, Material.COBBLESTONE) || Permissions.greenThumbBlock(player, Material.COBBLE_WALL) || Permissions.greenThumbBlock(player, Material.SMOOTH_BRICK));
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);
canFarmersDiet = Permissions.farmersDiet(player);
canDoubleDrop = Permissions.doubleDrops(player, skill);
doubleDropsDisabled = skill.getDoubleDropsDisabled();
canDoubleDrop = Permissions.doubleDrops(player, skill) && !skill.getDoubleDropsDisabled();
canShroomThumb = Permissions.shroomThumb(player);
}
@Override
protected boolean effectsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb;
return canGreenTerra || canDoubleDrop || canFarmersDiet || canGreenThumbBlocks || canGreenThumbPlants || canShroomThumb;
}
@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")));
}
if (canGreenThumbWheat) {
if (canGreenThumbPlants) {
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")));
}
if (canDoubleDrop && !doubleDropsDisabled) {
if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb;
return canGreenTerra || canDoubleDrop || canFarmersDiet || canGreenThumbBlocks || canGreenThumbPlants || canShroomThumb;
}
@Override
protected void statsDisplay() {
if (canGreenTerra) {
if (hasEndurance) {
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));
}
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", greenTerraLengthEndurance) : ""));
}
if (canGreenThumbBlocks || canGreenThumbWheat) {
if (isLucky) {
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 (canGreenThumbBlocks || canGreenThumbPlants) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", greenThumbChanceLucky) : ""));
}
if (canGreenThumbWheat) {
if (canGreenThumbPlants) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Stage", greenThumbStage));
}
@ -151,30 +151,15 @@ public class HerbalismCommand extends SkillCommand {
}
if (hasHylianLuck) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance) + LocaleLoader.getString("Perks.lucky.bonus", hylianLuckChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance));
}
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", hylianLuckChanceLucky) : ""));
}
if (canShroomThumb) {
if (isLucky) {
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));
}
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", shroomThumbChanceLucky) : ""));
}
if (canDoubleDrop && !doubleDropsDisabled) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance));
}
if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky) : ""));
}
}
}

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.MiningManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class MiningCommand extends SkillCommand {
private String doubleDropChance;
@ -26,7 +25,6 @@ public class MiningCommand extends SkillCommand {
private boolean canBlast;
private boolean canBiggerBombs;
private boolean canDemoExpert;
private boolean doubleDropsDisabled;
public MiningCommand() {
super(SkillType.MINING);
@ -35,23 +33,30 @@ public class MiningCommand extends SkillCommand {
@Override
protected void dataCalculations() {
// SUPER BREAKER
String[] superBreakerStrings = calculateLengthDisplayValues();
superBreakerLength = superBreakerStrings[0];
superBreakerLengthEndurance = superBreakerStrings[1];
if (canSuperBreaker) {
String[] superBreakerStrings = calculateLengthDisplayValues();
superBreakerLength = superBreakerStrings[0];
superBreakerLengthEndurance = superBreakerStrings[1];
}
// DOUBLE DROPS
String[] doubleDropStrings = calculateAbilityDisplayValues(Mining.doubleDropsMaxLevel, Mining.doubleDropsMaxChance);
doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
if (canDoubleDrop) {
String[] doubleDropStrings = calculateAbilityDisplayValues(Mining.doubleDropsMaxLevel, Mining.doubleDropsMaxChance);
doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
}
// BLAST MINING
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
blastMiningRank = miningManager.getBlastMiningTier();
bonusTNTDrops = miningManager.getDropMultiplier();
oreBonus = percent.format(miningManager.getOreBonus() / 30.0D); // Base received in TNT is 30%
debrisReduction = percent.format(miningManager.getDebrisReduction() / 30.0D); // Base received in TNT is 30%
blastDamageDecrease = percent.format(miningManager.getBlastDamageModifier() / 100.0D);
blastRadiusIncrease = miningManager.getBlastRadiusModifier();
if (canBlast || canDemoExpert || canBiggerBombs) {
MiningManager miningManager = mcMMOPlayer.getMiningManager();
blastMiningRank = miningManager.getBlastMiningTier();
bonusTNTDrops = miningManager.getDropMultiplier();
oreBonus = percent.format(miningManager.getOreBonus() / 30.0D); // Base received in TNT is 30%
debrisReduction = percent.format(miningManager.getDebrisReduction() / 30.0D); // Base received in TNT is 30%
blastDamageDecrease = percent.format(miningManager.getBlastDamageModifier() / 100.0D);
blastRadiusIncrease = miningManager.getBlastRadiusModifier();
}
}
@Override
@ -59,14 +64,13 @@ public class MiningCommand extends SkillCommand {
canBiggerBombs = Permissions.biggerBombs(player);
canBlast = Permissions.remoteDetonation(player);
canDemoExpert = Permissions.demolitionsExpertise(player);
canDoubleDrop = Permissions.doubleDrops(player, skill);
canDoubleDrop = Permissions.doubleDrops(player, skill) && !skill.getDoubleDropsDisabled();
canSuperBreaker = Permissions.superBreaker(player);
doubleDropsDisabled = skill.getDoubleDropsDisabled();
}
@Override
protected boolean effectsHeaderPermissions() {
return canBiggerBombs || canBlast || canDemoExpert || (canDoubleDrop && !doubleDropsDisabled) || canSuperBreaker;
return canBiggerBombs || canBlast || canDemoExpert || canDoubleDrop || canSuperBreaker;
}
@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")));
}
if (canDoubleDrop && !doubleDropsDisabled) {
if (canDoubleDrop) {
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
protected boolean statsHeaderPermissions() {
return canBiggerBombs || canBlast || canDemoExpert || (canDoubleDrop && !doubleDropsDisabled) || canSuperBreaker;
return canBiggerBombs || canBlast || canDemoExpert || canDoubleDrop || canSuperBreaker;
}
@Override
protected void statsDisplay() {
if (canDoubleDrop && !doubleDropsDisabled) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance));
}
if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky) : ""));
}
if (canSuperBreaker) {
if (hasEndurance) {
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + LocaleLoader.getString("Perks.activationtime.bonus", superBreakerLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength));
}
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", superBreakerLengthEndurance) : ""));
}
if (canBlast) {
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank1()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", AdvancedConfig.getInstance().getBlastMiningRank1())));
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank1();
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", unlockLevel)));
}
else {
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 (skillValue < AdvancedConfig.getInstance().getBlastMiningRank2()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", AdvancedConfig.getInstance().getBlastMiningRank2())));
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank2();
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", unlockLevel)));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease));
@ -138,8 +136,10 @@ public class MiningCommand extends SkillCommand {
}
if (canDemoExpert) {
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank4()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", AdvancedConfig.getInstance().getBlastMiningRank4())));
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank4();
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", unlockLevel)));
}
else {
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.datatypes.skills.SkillType;
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.RepairManager;
import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.util.Permissions;
public class RepairCommand extends SkillCommand {
private int arcaneForgingRank;
private String repairMasteryBonus;
private String superRepairChance;
private String superRepairChanceLucky;
@ -41,10 +41,10 @@ public class RepairCommand extends SkillCommand {
@Override
protected void dataCalculations() {
// We're using pickaxes here, not the best but it works
Repairable diamondRepairable = mcMMO.repairManager.getRepairable(Material.DIAMOND_PICKAXE.getId());
Repairable goldRepairable = mcMMO.repairManager.getRepairable(Material.GOLD_PICKAXE.getId());
Repairable ironRepairable = mcMMO.repairManager.getRepairable(Material.IRON_PICKAXE.getId());
Repairable stoneRepairable = mcMMO.repairManager.getRepairable(Material.STONE_PICKAXE.getId());
Repairable diamondRepairable = mcMMO.repairableManager.getRepairable(Material.DIAMOND_PICKAXE.getId());
Repairable goldRepairable = mcMMO.repairableManager.getRepairable(Material.GOLD_PICKAXE.getId());
Repairable ironRepairable = mcMMO.repairableManager.getRepairable(Material.IRON_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
diamondLevel = (diamondRepairable == null) ? 0 : diamondRepairable.getMinimumLevel();
@ -53,20 +53,16 @@ public class RepairCommand extends SkillCommand {
stoneLevel = (stoneRepairable == null) ? 0 : stoneRepairable.getMinimumLevel();
// REPAIR MASTERY
if (skillValue >= Repair.repairMasteryMaxBonusLevel) {
repairMasteryBonus = percent.format(Repair.repairMasteryMaxBonus / 100D);
}
else {
repairMasteryBonus = percent.format(((Repair.repairMasteryMaxBonus / Repair.repairMasteryMaxBonusLevel) * skillValue) / 100D);
if (canMasterRepair) {
repairMasteryBonus = percent.format(Math.min(((Repair.repairMasteryMaxBonus / Repair.repairMasteryMaxBonusLevel) * skillValue), Repair.repairMasteryMaxBonus) / 100D);
}
// SUPER REPAIR
String[] superRepairStrings = calculateAbilityDisplayValues(Repair.superRepairMaxBonusLevel, Repair.superRepairMaxChance);
superRepairChance = superRepairStrings[0];
superRepairChanceLucky = superRepairStrings[1];
// ARCANE FORGING
arcaneForgingRank = Repair.getArcaneForgingRank(profile);
if (canSuperRepair) {
String[] superRepairStrings = calculateAbilityDisplayValues(Repair.superRepairMaxBonusLevel, Repair.superRepairMaxChance);
superRepairChance = superRepairStrings[0];
superRepairChanceLucky = superRepairStrings[1];
}
}
@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")));
}
if (canSalvage && Salvage.salvageUnlockLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Salvage.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17")));
if (canSalvage && Repair.salvageUnlockLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Repair.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17")));
}
if (canArcaneForge) {
@ -143,23 +139,20 @@ public class RepairCommand extends SkillCommand {
}
if (canSuperRepair) {
if (isLucky) {
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));
}
player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", superRepairChanceLucky) : ""));
}
if (canArcaneForge) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Rank", arcaneForgingRank));
RepairManager repairManager = mcMMOPlayer.getRepairManager();
if (Repair.arcaneForgingEnchantLoss) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : Repair.getEnchantChance(arcaneForgingRank))));
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Rank", repairManager.getArcaneForgingRank()));
if (ArcaneForging.arcaneForgingEnchantLoss) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : repairManager.getKeepEnchantChance())));
}
if (Repair.arcaneForgingDowngrades) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Downgrade", (arcaneBypass ? 0 : Repair.getDowngradeChance(arcaneForgingRank))));
if (ArcaneForging.arcaneForgingDowngrades) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Downgrade", (arcaneBypass ? 0 : repairManager.getDowngradeEnchantChance())));
}
}
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.skills;
import java.text.DecimalFormat;
import java.util.Set;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -8,9 +9,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.child.FamilyTree;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils;
@ -20,10 +23,12 @@ import com.gmail.nossr50.util.skills.SkillUtils;
public abstract class SkillCommand implements CommandExecutor {
protected SkillType skill;
private String skillString;
protected String skillName;
protected Player player;
protected PlayerProfile profile;
protected McMMOPlayer mcMMOPlayer;
protected float skillValue;
protected boolean isLucky;
protected boolean hasEndurance;
@ -31,9 +36,12 @@ public abstract class SkillCommand implements CommandExecutor {
protected DecimalFormat percent = new DecimalFormat("##0.00%");
protected DecimalFormat decimal = new DecimalFormat("##0.00");
private CommandExecutor skillGuideCommand;
public SkillCommand(SkillType skill) {
this.skill = skill;
this.skillString = StringUtils.getCapitalized(skill.toString());
skillName = SkillUtils.getSkillName(skill);
skillGuideCommand = new SkillGuideCommand(skill);
}
@Override
@ -42,86 +50,73 @@ public abstract class SkillCommand implements CommandExecutor {
return true;
}
player = (Player) sender;
profile = UserManager.getPlayer(player).getProfile();
mcMMOPlayer = UserManager.getPlayer(sender.getName());
player = mcMMOPlayer.getPlayer();
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
switch (args.length) {
case 0:
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) {
if (skillValue >= maxLevel) {
return String.valueOf(maxLevel / rankChangeLevel);
}
return String.valueOf((int) (skillValue / rankChangeLevel));
protected int calculateRank(int maxLevel, int rankChangeLevel) {
return Math.min((int) skillValue, maxLevel) / rankChangeLevel;
}
protected String[] calculateAbilityDisplayValues(double chance) {
if (isLucky) {
double luckyChance = chance * 1.3333D;
String[] displayValues = new String[2];
if (luckyChance >= 100D) {
return new String[] { percent.format(chance / 100.0D), percent.format(1.0D) };
}
displayValues[0] = percent.format(Math.min(chance, 100.0D) / 100.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 new String[] { percent.format(chance / 100.0D), null };
return displayValues;
}
protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) {
double abilityChance;
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 };
return calculateAbilityDisplayValues((maxChance / maxBonusLevel) * Math.min(skillValue, maxBonusLevel));
}
protected String[] calculateLengthDisplayValues() {
@ -130,9 +125,7 @@ public abstract class SkillCommand implements CommandExecutor {
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
if (maxLength != 0) {
if (length > maxLength) {
length = maxLength;
}
length = Math.min(length, maxLength);
}
return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
@ -141,7 +134,7 @@ public abstract class SkillCommand implements CommandExecutor {
protected void luckyEffectsDisplay() {
if (isLucky) {
String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", 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 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.locale.LocaleLoader;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public final class SkillGuideCommand {
private SkillGuideCommand() {}
public class SkillGuideCommand implements CommandExecutor {
private String header;
private String[] guide;
public static int getTotalPageNumber(String address) {
String[] addressSplit = LocaleLoader.getString(address).split("\n");
private String invalidPage;
if (addressSplit.length <= 8) {
return 1;
}
public SkillGuideCommand(SkillType skillType) {
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) {
int pageIndexStart = 0;
// 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;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
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:
if (!args[0].equals("?")) {
return false;
}
SkillGuideCommand.clearChat(player);
for (String target : SkillGuideCommand.grabPageContents(localized, address, 1)) {
player.sendMessage(target);
}
sendGuide(sender, 1);
return true;
case 2:
int totalPages = SkillGuideCommand.getTotalPageNumber(address);
int totalPages = getTotalPageNumber();
if (!StringUtils.isInt(args[1])) {
player.sendMessage(LocaleLoader.getString("Guides.Page.Invalid"));
sender.sendMessage(invalidPage);
return true;
}
if (Integer.parseInt(args[1]) > totalPages) {
player.sendMessage(LocaleLoader.getString("Guides.Page.OutOfRange", totalPages));
int pageNumber = Integer.parseInt(args[1]);
if (pageNumber > totalPages || pageNumber <= 0) {
sender.sendMessage(LocaleLoader.getString("Guides.Page.OutOfRange", totalPages));
return true;
}
SkillGuideCommand.clearChat(player);
for (String target : SkillGuideCommand.grabPageContents(localized, address, Integer.parseInt(args[1]))) {
player.sendMessage(target);
}
sendGuide(sender, pageNumber);
return true;
default:
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.skills.smelting.Smelting;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class SmeltingCommand extends SkillCommand {
private String burnTimeModifier;
@ -14,8 +13,6 @@ public class SmeltingCommand extends SkillCommand {
private String fluxMiningChance;
private String fluxMiningChanceLucky;
private int vanillaXPModifier;
private boolean canFuelEfficiency;
private boolean canSecondSmelt;
private boolean canFluxMine;
@ -28,20 +25,23 @@ public class SmeltingCommand extends SkillCommand {
@Override
protected void dataCalculations() {
// FUEL EFFICIENCY
burnTimeModifier = decimal.format(1 + ((skillValue / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier));
if (canFuelEfficiency) {
burnTimeModifier = decimal.format(1 + ((skillValue / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier));
}
// SECOND SMELT
String[] secondSmeltStrings = calculateAbilityDisplayValues(Smelting.secondSmeltMaxLevel, Smelting.secondSmeltMaxChance);
secondSmeltChance = secondSmeltStrings[0];
secondSmeltChanceLucky = secondSmeltStrings[1];
if (canSecondSmelt) {
String[] secondSmeltStrings = calculateAbilityDisplayValues(Smelting.secondSmeltMaxLevel, Smelting.secondSmeltMaxChance);
secondSmeltChance = secondSmeltStrings[0];
secondSmeltChanceLucky = secondSmeltStrings[1];
}
// FLUX MINING
String[] fluxMiningStrings = calculateAbilityDisplayValues(Smelting.fluxMiningChance);
fluxMiningChance = fluxMiningStrings[0];
fluxMiningChanceLucky = fluxMiningStrings[1];
// VANILLA XP BOOST
vanillaXPModifier = UserManager.getPlayer(player).getSmeltingManager().getVanillaXpMultiplier();
if (canFluxMine) {
String[] fluxMiningStrings = calculateAbilityDisplayValues(Smelting.fluxMiningChance);
fluxMiningChance = fluxMiningStrings[0];
fluxMiningChanceLucky = fluxMiningStrings[1];
}
}
@Override
@ -90,20 +90,17 @@ public class SmeltingCommand extends SkillCommand {
}
if (canSecondSmelt) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance) + LocaleLoader.getString("Perks.lucky.bonus", secondSmeltChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance));
}
player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", secondSmeltChanceLucky) : ""));
}
if (canVanillaXPBoost) {
if (skillValue < AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level())));
int unlockLevel = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level();
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", unlockLevel)));
}
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) {
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 {
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 {
private String counterAttackChance;
private String counterAttackChanceLucky;
private String bleedLength;
private int bleedLength;
private String bleedChance;
private String bleedChanceLucky;
private String serratedStrikesLength;
@ -25,26 +25,27 @@ public class SwordsCommand extends SkillCommand {
@Override
protected void dataCalculations() {
// SERRATED STRIKES
String[] serratedStrikesStrings = calculateLengthDisplayValues();
serratedStrikesLength = serratedStrikesStrings[0];
serratedStrikesLengthEndurance = serratedStrikesStrings[1];
if (canSerratedStrike) {
String[] serratedStrikesStrings = calculateLengthDisplayValues();
serratedStrikesLength = serratedStrikesStrings[0];
serratedStrikesLengthEndurance = serratedStrikesStrings[1];
}
// BLEED
if (skillValue >= Swords.bleedMaxBonusLevel) {
bleedLength = String.valueOf(Swords.bleedMaxTicks);
}
else {
bleedLength = String.valueOf(Swords.bleedBaseTicks);
}
if (canBleed) {
bleedLength = (skillValue >= Swords.bleedMaxBonusLevel) ? Swords.bleedMaxTicks : Swords.bleedBaseTicks;
String[] bleedStrings = calculateAbilityDisplayValues(Swords.bleedMaxBonusLevel, Swords.bleedMaxChance);
bleedChance = bleedStrings[0];
bleedChanceLucky = bleedStrings[1];
String[] bleedStrings = calculateAbilityDisplayValues(Swords.bleedMaxBonusLevel, Swords.bleedMaxChance);
bleedChance = bleedStrings[0];
bleedChanceLucky = bleedStrings[1];
}
// COUNTER ATTACK
String[] counterAttackStrings = calculateAbilityDisplayValues(Swords.counterAttackMaxBonusLevel, Swords.counterAttackMaxChance);
counterAttackChance = counterAttackStrings[0];
counterAttackChanceLucky = counterAttackStrings[1];
if (canCounter) {
String[] counterAttackStrings = calculateAbilityDisplayValues(Swords.counterAttackMaxBonusLevel, Swords.counterAttackMaxChance);
counterAttackChance = counterAttackStrings[0];
counterAttackChanceLucky = counterAttackStrings[1];
}
}
@Override
@ -85,33 +86,17 @@ public class SwordsCommand extends SkillCommand {
@Override
protected void statsDisplay() {
if (canCounter) {
if (isLucky) {
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));
}
player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", counterAttackChanceLucky) : ""));
}
if (canBleed) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Length", bleedLength));
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Note"));
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));
}
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", bleedChanceLucky) : ""));
}
if (canSerratedStrike) {
if (hasEndurance) {
player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength) + LocaleLoader.getString("Perks.activationtime.bonus", serratedStrikesLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength));
}
player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", serratedStrikesLengthEndurance) : ""));
}
}
}

View File

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

View File

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

View File

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

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.spout;
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.spout.SpoutConfig;
@ -28,7 +27,7 @@ public abstract class SpoutCommand implements CommandExecutor {
return true;
}
playerProfile = UserManager.getPlayer((Player) sender).getProfile();
playerProfile = UserManager.getPlayer(sender.getName()).getProfile();
spoutHud = playerProfile.getSpoutHud();
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.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class XplockCommand extends SpoutCommand {
@ -22,25 +23,23 @@ public class XplockCommand extends SpoutCommand {
@Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
if (args[0].equalsIgnoreCase("on")) {
if (CommandUtils.shouldEnableToggle(args[0])) {
lockXpBar(sender, spoutHud.getLastGained());
return true;
}
if (args[0].equalsIgnoreCase("off")) {
if (CommandUtils.shouldDisableToggle(args[0])) {
unlockXpBar(sender);
return true;
}
if (!SkillUtils.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
if (CommandUtils.isInvalidSkill(sender, args[0])) {
return true;
}
SkillType skill = SkillType.getSkill(args[0]);
if (skill.isChildSkill()) {
sender.sendMessage("Child skills are not yet supported by this command."); // TODO: Localize this
if (CommandUtils.isChildSkill(sender, skill)) {
return true;
}

View File

@ -20,6 +20,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
/* GENERAL */
public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); }
public int getEnchantBuff() { return config.getInt("Skills.General.Ability_EnchantBuff", 5); }
/* ACROBATICS */
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 double getSuperRepairChanceMax() { return config.getDouble("Skills.Repair.SuperRepair_ChanceMax", 100.0D); }
public int getSuperRepairMaxLevel() { return config.getInt("Skills.Repair.SuperRepair_MaxBonusLevel", 1000); }
public int getSalvageUnlockLevel() { return config.getInt("Skills.Repair.Salvage_UnlockLevel", 600); }
/* Arcane Forging */
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); }
/* 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 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 */
public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }
@ -183,9 +186,7 @@ public class Config extends AutoUpdateConfigLoader {
/* Repair */
public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); }
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 getSalvageUnlockLevel() { return config.getInt("Skills.Repair.Salvage_UnlockLevel", 600); }
public boolean getSalvageTools() { return config.getBoolean("Skills.Repair.Salvage_tools", 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); }
/* Woodcutting */
public boolean getWoodcuttingRequiresTool() { return config.getBoolean("Skills.Woodcutting.Requires_Axe", true); }
public int getWoodcuttingXPOak() { return config.getInt("Experience.Woodcutting.Oak", 70); }
public int getWoodcuttingXPBirch() { return config.getInt("Experience.Woodcutting.Birch", 90); }
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.Properties;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
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.spout.huds.McMMOHud;
import com.gmail.nossr50.runnables.database.SQLReconnectTask;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.spout.SpoutUtils;
import com.gmail.nossr50.util.Misc;
public final class DatabaseManager {
private static String connectionString;
@ -340,7 +336,7 @@ public final class DatabaseManager {
if (connection != null && !connection.isClosed()) {
// Schedule a database save if we really had an outage
if (reconnectAttempt > 1) {
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new SQLReconnectTask(), 5);
new SQLReconnectTask().runTaskLater(mcMMO.p, 5);
}
nextReconnectTimestamp = 0;
reconnectAttempt = 0;
@ -502,7 +498,7 @@ public final class DatabaseManager {
continue;
}
profileCleanup(playerName);
Misc.profileCleanup(playerName);
purgedUsers++;
}
@ -524,36 +520,13 @@ public final class DatabaseManager {
continue;
}
profileCleanup(playerName);
Misc.profileCleanup(playerName);
purgedUsers++;
}
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.
*

View File

@ -60,79 +60,79 @@ public final class LeaderboardManager {
ArrayList<String> players = new ArrayList<String>();
while ((line = in.readLine()) != null) {
String[] character = line.split(":");
String[] data = line.split(":");
String p = character[0];
String playerName = data[0];
int powerLevel = 0;
// 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;
}
players.add(p);
players.add(playerName);
if (character.length > 1 && StringUtils.isInt(character[1])) {
mining.add(new PlayerStat(p, Integer.parseInt(character[1])));
powerLevel += Integer.parseInt(character[1]);
if (data.length > 1 && StringUtils.isInt(data[1])) {
mining.add(new PlayerStat(playerName, Integer.parseInt(data[1])));
powerLevel += Integer.parseInt(data[1]);
}
if (character.length > 5 && StringUtils.isInt(character[5])) {
woodcutting.add(new PlayerStat(p, Integer.parseInt(character[5])));
powerLevel += Integer.parseInt(character[5]);
if (data.length > 5 && StringUtils.isInt(data[5])) {
woodcutting.add(new PlayerStat(playerName, Integer.parseInt(data[5])));
powerLevel += Integer.parseInt(data[5]);
}
if (character.length > 7 && StringUtils.isInt(character[7])) {
repair.add(new PlayerStat(p, Integer.parseInt(character[7])));
powerLevel += Integer.parseInt(character[7]);
if (data.length > 7 && StringUtils.isInt(data[7])) {
repair.add(new PlayerStat(playerName, Integer.parseInt(data[7])));
powerLevel += Integer.parseInt(data[7]);
}
if (character.length > 8 && StringUtils.isInt(character[8])) {
unarmed.add(new PlayerStat(p, Integer.parseInt(character[8])));
powerLevel += Integer.parseInt(character[8]);
if (data.length > 8 && StringUtils.isInt(data[8])) {
unarmed.add(new PlayerStat(playerName, Integer.parseInt(data[8])));
powerLevel += Integer.parseInt(data[8]);
}
if (character.length > 9 && StringUtils.isInt(character[9])) {
herbalism.add(new PlayerStat(p, Integer.parseInt(character[9])));
powerLevel += Integer.parseInt(character[9]);
if (data.length > 9 && StringUtils.isInt(data[9])) {
herbalism.add(new PlayerStat(playerName, Integer.parseInt(data[9])));
powerLevel += Integer.parseInt(data[9]);
}
if (character.length > 10 && StringUtils.isInt(character[10])) {
excavation.add(new PlayerStat(p, Integer.parseInt(character[10])));
powerLevel += Integer.parseInt(character[10]);
if (data.length > 10 && StringUtils.isInt(data[10])) {
excavation.add(new PlayerStat(playerName, Integer.parseInt(data[10])));
powerLevel += Integer.parseInt(data[10]);
}
if (character.length > 11 && StringUtils.isInt(character[11])) {
archery.add(new PlayerStat(p, Integer.parseInt(character[11])));
powerLevel += Integer.parseInt(character[11]);
if (data.length > 11 && StringUtils.isInt(data[11])) {
archery.add(new PlayerStat(playerName, Integer.parseInt(data[11])));
powerLevel += Integer.parseInt(data[11]);
}
if (character.length > 12 && StringUtils.isInt(character[12])) {
swords.add(new PlayerStat(p, Integer.parseInt(character[12])));
powerLevel += Integer.parseInt(character[12]);
if (data.length > 12 && StringUtils.isInt(data[12])) {
swords.add(new PlayerStat(playerName, Integer.parseInt(data[12])));
powerLevel += Integer.parseInt(data[12]);
}
if (character.length > 13 && StringUtils.isInt(character[13])) {
axes.add(new PlayerStat(p, Integer.parseInt(character[13])));
powerLevel += Integer.parseInt(character[13]);
if (data.length > 13 && StringUtils.isInt(data[13])) {
axes.add(new PlayerStat(playerName, Integer.parseInt(data[13])));
powerLevel += Integer.parseInt(data[13]);
}
if (character.length > 14 && StringUtils.isInt(character[14])) {
acrobatics.add(new PlayerStat(p, Integer.parseInt(character[14])));
powerLevel += Integer.parseInt(character[14]);
if (data.length > 14 && StringUtils.isInt(data[14])) {
acrobatics.add(new PlayerStat(playerName, Integer.parseInt(data[14])));
powerLevel += Integer.parseInt(data[14]);
}
if (character.length > 24 && StringUtils.isInt(character[24])) {
taming.add(new PlayerStat(p, Integer.parseInt(character[24])));
powerLevel += Integer.parseInt(character[24]);
if (data.length > 24 && StringUtils.isInt(data[24])) {
taming.add(new PlayerStat(playerName, Integer.parseInt(data[24])));
powerLevel += Integer.parseInt(data[24]);
}
if (character.length > 34 && StringUtils.isInt(character[34])) {
fishing.add(new PlayerStat(p, Integer.parseInt(character[34])));
powerLevel += Integer.parseInt(character[34]);
if (data.length > 34 && StringUtils.isInt(data[34])) {
fishing.add(new PlayerStat(playerName, Integer.parseInt(data[34])));
powerLevel += Integer.parseInt(data[34]);
}
powerLevels.add(new PlayerStat(p, powerLevel));
powerLevels.add(new PlayerStat(playerName, powerLevel));
}
in.close();
}
@ -188,72 +188,22 @@ public final class LeaderboardManager {
statsList = playerStatHash.get(SkillType.getSkill(skillType));
}
int destination;
int destination = (pageNumber - 1) * 10;
// How many lines to skip through
if (pageNumber == 1) {
destination = 0;
}
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++;
for (int i = 0; i < 10; i++) {
PlayerStat ps = statsList.get(destination + i);
info[i] = ps.name + ":" + ps.statVal;
}
return info;
}
public static int[] getPlayerRank(String playerName) {
int currentPos = 1;
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};
return getPlayerRank(playerName, powerLevels);
}
public static int[] getPlayerRank(String playerName, SkillType skillType) {
int currentPos = 1;
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};
return getPlayerRank(playerName, playerStatHash.get(skillType));
}
public static boolean removeFlatFileUser(String playerName) {
@ -315,8 +265,9 @@ public final class LeaderboardManager {
mcMMO.p.getLogger().info("Purging powerless users...");
int purgedUsers = 0;
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++;
}
}
@ -394,6 +345,24 @@ public final class LeaderboardManager {
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> {
@Override
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.herbalism.HerbalismManager;
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.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager;
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.ModUtils;
import com.gmail.nossr50.util.Permissions;
@ -65,7 +68,7 @@ public class McMMOPlayer {
private boolean displaySkillNotifications = true;
private boolean abilityUse = true;
private boolean placedAnvil;
private boolean placedRepairAnvil;
private boolean placedSalvageAnvil;
private boolean godMode;
@ -76,6 +79,7 @@ public class McMMOPlayer {
private Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
private int recentlyHurt;
private int chimaeraWing;
private int respawnATS;
public McMMOPlayer(Player player) {
@ -92,12 +96,7 @@ public class McMMOPlayer {
*/
try {
for (SkillType skillType : SkillType.values()) {
Class<? extends SkillManager> skillManagerClass = skillType.getManagerClass();
// 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));
}
skillManagers.put(skillType, skillType.getManagerClass().getConstructor(McMMOPlayer.class).newInstance(this));
}
}
catch (Exception e) {
@ -144,6 +143,10 @@ public class McMMOPlayer {
return (MiningManager) skillManagers.get(SkillType.MINING);
}
public RepairManager getRepairManager() {
return (RepairManager) skillManagers.get(SkillType.REPAIR);
}
public SmeltingManager getSmeltingManager() {
return (SmeltingManager) skillManagers.get(SkillType.SMELTING);
}
@ -160,6 +163,10 @@ public class McMMOPlayer {
return (UnarmedManager) skillManagers.get(SkillType.UNARMED);
}
public WoodcuttingManager getWoodcuttingManager() {
return (WoodcuttingManager) skillManagers.get(SkillType.WOODCUTTING);
}
/*
* Abilities
*/
@ -292,6 +299,23 @@ public class McMMOPlayer {
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
*/
@ -308,24 +332,26 @@ public class McMMOPlayer {
* Repair Anvil Placement
*/
public void togglePlacedAnvil() {
placedAnvil = !placedAnvil;
public boolean getPlacedAnvil(int anvilId) {
if (anvilId == Repair.repairAnvilId) {
return placedRepairAnvil;
}
if (anvilId == Repair.salvageAnvilId) {
return placedSalvageAnvil;
}
return true;
}
public Boolean getPlacedAnvil() {
return placedAnvil;
}
public void togglePlacedAnvil(int anvilId) {
if (anvilId == Repair.repairAnvilId) {
placedRepairAnvil = !placedRepairAnvil;
}
/*
* Salvage Anvil Placement
*/
public void togglePlacedSalvageAnvil() {
placedSalvageAnvil = !placedSalvageAnvil;
}
public Boolean getPlacedSalvageAnvil() {
return placedSalvageAnvil;
if (anvilId == Repair.salvageAnvilId) {
placedSalvageAnvil = !placedSalvageAnvil;
}
}
/*
@ -423,6 +449,19 @@ public class McMMOPlayer {
* @param xp Experience amount to add
*/
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);
mcMMO.p.getServer().getPluginManager().callEvent(event);

View File

@ -92,7 +92,7 @@ public class PlayerProfile {
}
else {
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;
}
}
@ -186,7 +186,7 @@ public class PlayerProfile {
// Find if the line contains the player we want.
String[] character = line.split(":");
if (!character[0].equals(playerName)) {
if (!character[0].equalsIgnoreCase(playerName)) {
continue;
}
@ -400,7 +400,7 @@ public class PlayerProfile {
// While not at the end of the file
while ((line = in.readLine()) != null) {
// 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");
}
else {
@ -611,6 +611,10 @@ public class PlayerProfile {
}
public void setSkillXpLevel(SkillType skillType, int newValue) {
if (skillType.isChildSkill()) {
return;
}
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.herbalism.HerbalismManager;
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.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.StringUtils;
public enum SkillType {
@ -25,12 +27,12 @@ public enum SkillType {
FISHING(FishingManager.class),
HERBALISM(HerbalismManager.class, AbilityType.GREEN_TERRA, ToolType.HOE),
MINING(MiningManager.class, AbilityType.SUPER_BREAKER, ToolType.PICKAXE),
REPAIR(null), // TODO: Create a proper RepairManager class
REPAIR(RepairManager.class),
SMELTING(SmeltingManager.class),
SWORDS(SwordsManager.class, AbilityType.SERRATED_STRIKES, ToolType.SWORD),
TAMING(TamingManager.class),
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 AbilityType ability;

View File

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

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.listeners;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace;
import org.bukkit.entity.HumanEntity;
@ -16,6 +17,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType;
@ -49,11 +51,12 @@ public class InventoryListener implements Listener {
if (furnace == null) {
return;
}
if (furnace.getBurnTime() == 0) {
Block furnaceBlock = furnace.getBlock();
BlockState furnaceBlock = furnace.getBlock().getState();
if (furnace.getBurnTime() == 0 && !plugin.furnaceIsTracked(furnaceBlock)) {
plugin.addToOpenFurnaceTracker(furnaceBlock, player.getName());
if (!furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, new FixedMetadataValue(plugin, player.getName()));
}
}
}
}
@ -75,23 +78,27 @@ public class InventoryListener implements Listener {
return;
}
BlockState furnaceBlock = furnace.getBlock().getState();
if (furnace.getBurnTime() == 0) {
Block furnaceBlock = furnace.getBlock();
if (furnace.getBurnTime() == 0 && plugin.furnaceIsTracked(furnaceBlock)) {
plugin.removeFromFurnaceTracker(furnaceBlock);
if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
furnaceBlock.removeMetadata(mcMMO.furnaceMetadataKey, plugin);
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
BlockState furnaceBlock = event.getBlock().getState();
Block furnaceBlock = event.getBlock();
BlockState furnaceState = furnaceBlock.getState();
if (furnaceBlock instanceof Furnace) {
ItemStack smelting = ((Furnace) furnaceBlock).getInventory().getSmelting();
if (furnaceState instanceof Furnace) {
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemUtils.isSmeltable(smelting)) {
Player player = plugin.getFurnacePlayer(furnaceBlock);
if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey) && smelting != null && ItemUtils.isSmeltable(smelting)) {
// 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)) {
return;
@ -104,13 +111,15 @@ public class InventoryListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
BlockState furnaceBlock = event.getBlock().getState();
Block furnaceBlock = event.getBlock();
BlockState furnaceState = furnaceBlock.getState();
if (furnaceBlock instanceof Furnace) {
ItemStack smelting = ((Furnace) furnaceBlock).getInventory().getSmelting();
if (furnaceState instanceof Furnace) {
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemUtils.isSmeltable(smelting)) {
Player player = plugin.getFurnacePlayer(furnaceBlock);
if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey) && smelting != null && ItemUtils.isSmeltable(smelting)) {
// 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)) {
return;
@ -123,13 +132,19 @@ public class InventoryListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
BlockState furnaceBlock = event.getBlock().getState();
Block furnaceBlock = event.getBlock();
BlockState furnaceState = furnaceBlock.getState();
if (furnaceBlock instanceof Furnace) {
ItemStack result = ((Furnace) furnaceBlock).getInventory().getResult();
if (furnaceState instanceof Furnace) {
ItemStack result = ((Furnace) furnaceState).getInventory().getResult();
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemUtils.isSmelted(result)) {
Player player = event.getPlayer();
if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey) && result != null && ItemUtils.isSmelted(result)) {
// 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();

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

View File

@ -8,15 +8,11 @@ import java.util.List;
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.event.HandlerList;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import com.gmail.nossr50.config.AdvancedConfig;
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.database.DatabaseManager;
import com.gmail.nossr50.database.LeaderboardManager;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.listeners.BlockListener;
import com.gmail.nossr50.listeners.EntityListener;
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.SkillMonitorTask;
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.RepairableManager;
import com.gmail.nossr50.skills.repair.RepairableManagerFactory;
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.Permissions;
import com.gmail.nossr50.util.UpdateChecker;
@ -66,12 +62,11 @@ public class mcMMO extends JavaPlugin {
private final WorldListener worldListener = new WorldListener();
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
private HashMap<BlockState, String> furnaceTracker = new HashMap<BlockState, String>();
public static mcMMO p;
public static ChunkManager placeStore;
public static RepairManager repairManager;
public static RepairableManager repairableManager;
// Jar Stuff
public static File mcmmo;
@ -95,6 +90,7 @@ public class mcMMO extends JavaPlugin {
public static FixedMetadataValue metadataValue;
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
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.
@ -115,6 +111,7 @@ public class mcMMO extends JavaPlugin {
}
registerEvents();
registerCustomRecipes();
// Setup the leader boards
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.");
}
Bukkit.getPluginManager().disablePlugin(this);
getServer().getPluginManager().disablePlugin(this);
}
}
@ -197,43 +194,6 @@ public class mcMMO extends JavaPlugin {
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.
*
@ -273,22 +233,6 @@ public class mcMMO extends JavaPlugin {
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() {
return mainDirectory;
}
@ -377,8 +321,8 @@ public class mcMMO extends JavaPlugin {
// Load repair configs, make manager, and register them at this time
RepairConfigManager rManager = new RepairConfigManager(this);
repairables.addAll(rManager.getLoadedRepairables());
repairManager = RepairManagerFactory.getRepairManager(repairables.size());
repairManager.registerRepairables(repairables);
repairableManager = RepairableManagerFactory.getRepairManager(repairables.size());
repairableManager.registerRepairables(repairables);
// Check if Repair Anvil and Salvage Anvil have different itemID's
if (configInstance.getSalvageAnvilId() == configInstance.getRepairAnvilId()) {
@ -450,43 +394,51 @@ public class mcMMO extends JavaPlugin {
CommandRegistrationManager.registerMchudCommand();
}
private void scheduleTasks() {
BukkitScheduler scheduler = getServer().getScheduler();
private void registerCustomRecipes() {
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
scheduler.scheduleSyncDelayedTask(this, new PartyLoaderTask(), 0);
new PartyLoaderTask().runTaskLater(this, 0);
// Periodic save timer (Saves every 10 minutes by default)
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)
scheduler.scheduleSyncRepeatingTask(this, new SkillMonitorTask(), 20, 20);
new SkillMonitorTask().runTaskTimer(this, 20, 20);
// Bleed timer (Runs every two seconds)
scheduler.scheduleSyncRepeatingTask(this, new BleedTimerTask(), 40, 40);
new BleedTimerTask().runTaskTimer(this, 40, 40);
// Old & Powerless User remover
int purgeInterval = Config.getInstance().getPurgeInterval();
UserPurgeTask userPurgeTask = new UserPurgeTask();
if (purgeInterval == 0) {
scheduler.scheduleSyncDelayedTask(this, new UserPurgeTask(), 40); // Start 2 seconds after startup.
userPurgeTask.runTaskLater(this, 40);
}
else if (purgeInterval > 0) {
long purgeIntervalTicks = purgeInterval * 60 * 60 * 20;
scheduler.scheduleSyncRepeatingTask(this, new UserPurgeTask(), purgeIntervalTicks, purgeIntervalTicks);
userPurgeTask.runTaskTimer(this, purgeIntervalTicks, purgeIntervalTicks);
}
// Automatically remove old members from parties
long kickInterval = Config.getInstance().getAutoPartyKickInterval();
PartyAutoKickTask partyAutoKickTask = new PartyAutoKickTask();
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) {
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() {}
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) {
if (mcMMOPlayer.inParty()) {
if (!handlePartyChangeEvent(player, oldParty.getName(), newPartyName, EventReason.CHANGED_PARTIES)) {
@ -75,7 +84,7 @@ public final class PartyManager {
List<Player> nearMembers = new ArrayList<Player>();
if (party != null) {
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);
}
}
@ -122,7 +131,13 @@ public final class PartyManager {
* @return all online players in this party
*/
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) {
for (Party party : parties) {
for (OfflinePlayer member : party.getMembers()) {
if (member.getName().equals(playerName)) {
if (member.getName().equalsIgnoreCase(playerName)) {
return party;
}
}
@ -184,7 +199,7 @@ public final class PartyManager {
}
else {
// 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();
party.setLeader(newLeader);
}
@ -374,10 +389,10 @@ public final class PartyManager {
String leaderName = party.getLeader();
for (Player member : party.getOnlineMembers()) {
if (member.getName().equals(playerName)) {
if (member.getName().equalsIgnoreCase(playerName)) {
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"));
}
else {
@ -396,7 +411,7 @@ public final class PartyManager {
* @return true if the player can invite
*/
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;
}
@ -488,13 +503,13 @@ public final class PartyManager {
}
partiesFile.set(partyName + ".Members", memberNames);
}
try {
partiesFile.save(new File(partiesFilePath));
}
catch (Exception e) {
e.printStackTrace();
}
try {
partiesFile.save(new File(partiesFilePath));
}
catch (Exception e) {
e.printStackTrace();
}
}

View File

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

View File

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

View File

@ -2,16 +2,13 @@ package com.gmail.nossr50.runnables.commands;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
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 CommandSender sender;
@ -22,35 +19,8 @@ public class McrankCommandAsyncTask implements Runnable {
@Override
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() {
@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);
new McrankCommandDisplayTask(skills, sender, playerName).runTaskLater(mcMMO.p, 1);
}
}

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.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
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 String query;
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.query = query;
this.sender = sender;
this.command = command;
}
@Override
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();
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;
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);
new MctopCommandDisplayTask(userslist, page, tablePrefix, sender).runTaskLater(mcMMO.p, 1);
}
}

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.FileReader;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils;
public class SQLConversionTask implements Runnable {
public class SQLConversionTask extends BukkitRunnable {
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
@Override
@ -55,7 +57,7 @@ public class SQLConversionTask implements Runnable {
playerName = character[0];
// 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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,12 +7,13 @@ import java.util.Map.Entry;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.skills.CombatUtils;
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 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;
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.skills.AbilityType;
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.skills.SkillUtils;
public class SkillMonitorTask implements Runnable {
public class SkillMonitorTask extends BukkitRunnable {
@Override
public void run() {
long curTime = System.currentTimeMillis();
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
if (Misc.isNPCEntity(player)) {
continue;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers().values()) {
/*
* 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 targetLocation = target.getLocation();
if (!shooterLocation.getWorld().equals(targetLocation.getWorld())) {
if (shooterLocation.getWorld() != targetLocation.getWorld()) {
return;
}

View File

@ -3,29 +3,27 @@ package com.gmail.nossr50.skills.archery;
import java.util.UUID;
import org.bukkit.entity.LivingEntity;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
public class TrackedEntity implements Runnable {
public class TrackedEntity extends BukkitRunnable {
private LivingEntity livingEntity;
private UUID id;
private int arrowCount;
private int taskId;
private BukkitScheduler scheduler;
protected TrackedEntity(LivingEntity livingEntity) {
this.livingEntity = livingEntity;
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
public void run() {
if (!livingEntity.isValid()) {
Archery.removeFromTracker(this);
scheduler.cancelTask(taskId);
this.cancel();
}
}

View File

@ -189,7 +189,7 @@ public class FishingManager extends SkillManager {
}
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()));
ItemStack treasureDrop = treasure.getDrop();
if (!SkillUtils.treasureDropSuccessful(treasure.getDropChance(), skillLevel)) {
if (!SkillUtils.treasureDropSuccessful(treasure.getDropChance(), activationChance)) {
return null;
}

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