1
0
mirror of https://github.com/mcMMO-Dev/mcMMO.git synced 2026-02-18 09:43:00 +01:00

Compare commits

..

1 Commits

Author SHA1 Message Date
t00thpick1
63ae7e97e1 Ranks config idea 2013-10-04 17:52:47 -04:00
170 changed files with 5046 additions and 6290 deletions

View File

@@ -7,14 +7,7 @@ Key:
! Change ! Change
- Removal - Removal
Version 1.4.08-dev Version 1.4.07-dev
+ Added the possibility to gain experience when using Fishing "Shake"
= Fixed IllegalArgumentException caused by an empty Fishing treasure category
Version 1.4.07
+ Added XP boost to Acrobatics when wearing Boots of Feather Falling
+ Added SQL Database can now recover from a dropped connection without losing data. (Thanks Riking!)
+ Added more tiers to Fishing, Repair and Smelting!
+ Added Carrot on a Stick and Flint & Steel to repair.vanilla.yml + Added Carrot on a Stick and Flint & Steel to repair.vanilla.yml
+ Added horses to the "Shake" ability + Added horses to the "Shake" ability
+ Added ability to summon horses via "Call of the Wild" using apples + Added ability to summon horses via "Call of the Wild" using apples
@@ -34,12 +27,6 @@ Version 1.4.07
+ Added ability to give custom names to items in treasures.yml - use the key "Custom_Name" to set, expects a string. + Added ability to give custom names to items in treasures.yml - use the key "Custom_Name" to set, expects a string.
+ Added ability to give lore to items in treasures.yml - use the key "Lore" to set, expects a list of strings. + Added ability to give lore to items in treasures.yml - use the key "Lore" to set, expects a list of strings.
+ Added Quartz and Name Tags to the default Excavation treasures + Added Quartz and Name Tags to the default Excavation treasures
+ Added a warning message if the server is running NoCheatPlus without CompatNoCheatPlus
+ Added cooldown to commands with heavy database access to prevent denial of service
+ Added /mcscoreboard keep, to keep the scoreboard up forever
+ Added Rainbow Mode to scoreboards
+ Added new /mccooldowns command to show all ability cooldowns
+ Commands may now both print text and display a scoreboard
+ Killing a custom entity will automatically add it to the custom entity config file with default values. + Killing a custom entity will automatically add it to the custom entity config file with default values.
= Fixed bug which allowed players to bypass fishing's exploit prevention = Fixed bug which allowed players to bypass fishing's exploit prevention
= Fixed bug where FakeEntityDamageByEntityEvent wasn't being fired = Fixed bug where FakeEntityDamageByEntityEvent wasn't being fired
@@ -53,18 +40,12 @@ Version 1.4.07
= Fixed a bug where squid were not awarding XP. = Fixed a bug where squid were not awarding XP.
= Fixed a bug where Combat XP was granted within 5 seconds for respawned players = Fixed a bug where Combat XP was granted within 5 seconds for respawned players
= Fixed a bug where wrong feedback messages were being send when using a command on an offline player = Fixed a bug where wrong feedback messages were being send when using a command on an offline player
= Fixed a bug where players were able to gain Herbalism XP in mine carts, even though Prevent_AFK_Leveling was enabled
= Fixed a bug where players would get hit by fireworks if they leveled up while in a boat
! Changed Fishing "Treasure Hunter" and "Magic Hunter" drop percentages
! Changed format of mod config files. (blocks.yml, tools.yml, armor.yml and entities.yml) **YOU WILL NEED TO UPDATE YOUR FILE TO THE NEW FORMAT** ! Changed format of mod config files. (blocks.yml, tools.yml, armor.yml and entities.yml) **YOU WILL NEED TO UPDATE YOUR FILE TO THE NEW FORMAT**
! Changed format of treasures.yml. **YOU WILL NEED TO UPDATE YOUR FILE TO THE NEW FORMAT** ! Changed format of treasures.yml. **YOU WILL NEED TO UPDATE YOUR FILE TO THE NEW FORMAT**
! Changed format of repair.vanilla.yml. **YOU WILL NEED TO UPDATE YOUR FILE TO THE NEW FORMAT** ! Changed format of repair.vanilla.yml. **YOU WILL NEED TO UPDATE YOUR FILE TO THE NEW FORMAT**
! Changed default XP multiplier for repairing shears ! Changed default XP multiplier for repairing shears
! Changed "Shake" drops for Witches. They no longer drop water bottles, since they no longer drop them in Vanilla. ! Changed "Shake" drops for Witches. They no longer drop water bottles, since they no longer drop them in Vanilla.
! Changed fishing exploit prevention, by default it will no longer send global sounds, effects and messages.
! Changed Hardcore modes, they will also subtract experience
! Changed various values to double in advanced.yml for the sake of consistency. ! Changed various values to double in advanced.yml for the sake of consistency.
! Nerfed Fishing "Master Angler" (removed skill level based bonus) and also made the modifiers configurable
! Nerfed Archery damage to eliminate constant one-hit kills. ! Nerfed Archery damage to eliminate constant one-hit kills.
! Changed the way Repair hands out XP, also added config options to control Repair XP ! Changed the way Repair hands out XP, also added config options to control Repair XP
! Changed Swords "Counter Attack" ability from passive to active. Blocking is required to activate. ! Changed Swords "Counter Attack" ability from passive to active. Blocking is required to activate.
@@ -72,8 +53,6 @@ Version 1.4.07
! Vampirism can now be enabled without having Skill Death Penalty enabled ! Vampirism can now be enabled without having Skill Death Penalty enabled
! Admin and Party chat prefixes are now customizable ! Admin and Party chat prefixes are now customizable
! Changed the color of party leader names in Party chat ! Changed the color of party leader names in Party chat
! Improved "Tree Feller" algorithm (Thanks Riking!)
! Improved AFK Acrobatics prevention mechanism
! Improved profile saving ! Improved profile saving
! Improved partial name matcher ! Improved partial name matcher
! Improved update checker ! Improved update checker
@@ -81,11 +60,8 @@ Version 1.4.07
! Party item share category states are now saved when the server shuts down. ! Party item share category states are now saved when the server shuts down.
! When using "Super Breaker" or "Giga Driller" abilities extra tool durability is used (again) ! When using "Super Breaker" or "Giga Driller" abilities extra tool durability is used (again)
! Mob healthbars are automatically disabled when the plugin "HealthBar" is found ! Mob healthbars are automatically disabled when the plugin "HealthBar" is found
! Massively improved scoreboard handling
! Reworked scoreboard configuration (config.yml) - **you will need to update**
- The /mmoupdate command has been removed. It is replaced by /mcconvert database - The /mmoupdate command has been removed. It is replaced by /mcconvert database
- Removed Abilities.Tools.Durability_Loss_Enabled, set Abilities.Tools.Durability_Loss to 0 to disable instead. - Removed Abilities.Tools.Durability_Loss_Enabled, set Abilities.Tools.Durability_Loss to 0 to disable instead.
- Removed Skills.Fishing.Shake_UnlockLevel from advanced.yml, now using Skills.Fishing.Rank_Levels.Rank_1 instead.
- Removed SpoutPlugin support - Removed SpoutPlugin support
Version 1.4.06 Version 1.4.06

View File

@@ -2,7 +2,7 @@
## The RPG lovers mod ## The RPG lovers mod
### Dev builds ### Dev builds
Our latest development builds are available ~~[here](http://ci.mcmmo.info)~~. Unfortunately, the mcMMO site is down; a temporary dev build location is hosted [here](http://ci.ecocitycraft.com/job/mcMMO/). Our latest development builds are available [here](http://ci.mcmmo.info).
### Brief Description ### Brief Description
The goal of mcMMO is to take core Minecraft game mechanics and expand them into add an extensive and quality RPG experience. Everything in mcMMO has been carefully thought out and is constantly being improved upon. Currently, mcMMO adds thirteen unique skills to train and level in. Each of these skills is highly customizable through our configuration files, allowing server admins to tweak mcMMO to best suit the needs of his or her server. Know that the mcMMO team is dedicated to providing an ever-evolving experience, and that we carefully read all feedback and bug reports in order to evaluate and balance the mechanics of mcMMO in every update. The goal of mcMMO is to take core Minecraft game mechanics and expand them into add an extensive and quality RPG experience. Everything in mcMMO has been carefully thought out and is constantly being improved upon. Currently, mcMMO adds thirteen unique skills to train and level in. Each of these skills is highly customizable through our configuration files, allowing server admins to tweak mcMMO to best suit the needs of his or her server. Know that the mcMMO team is dedicated to providing an ever-evolving experience, and that we carefully read all feedback and bug reports in order to evaluate and balance the mechanics of mcMMO in every update.
@@ -29,8 +29,6 @@ mcMMO is currently developed by a team of individuals from all over the world.
(https://github.com/TfT-02) (https://github.com/TfT-02)
[![t00thpick1](http://www.gravatar.com/avatar/ee23c7794a0c40120c3474287c7bce06.png)] [![t00thpick1](http://www.gravatar.com/avatar/ee23c7794a0c40120c3474287c7bce06.png)]
(https://github.com/t00thpick1) (https://github.com/t00thpick1)
[![riking](https://1.gravatar.com/avatar/aca9f37e569ac3a63929920035a91ba4.png)]
(https://github.com/riking)
## Compiling ## Compiling

14
pom.xml
View File

@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId> <groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId> <artifactId>mcMMO</artifactId>
<version>1.4.08-dev1</version> <version>1.4.07-dev2</version>
<name>mcMMO</name> <name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url> <url>https://github.com/mcMMO-Dev/mcMMO</url>
<issueManagement> <issueManagement>
@@ -30,14 +30,6 @@
<include>locale*.properties</include> <include>locale*.properties</include>
</includes> </includes>
</resource> </resource>
<resource>
<targetPath>mods</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/mods</directory>
<includes>
<include>*.yml</include>
</includes>
</resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
@@ -143,7 +135,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<ciManagement> <ciManagement>
<system>Jenkins</system> <system>Jenkins</system>
<url>http://ci.ecocitycraft.com/job/mcMMO</url> <url>ci.mcmmo.org</url>
</ciManagement> </ciManagement>
</project> </project>

View File

@@ -414,7 +414,7 @@ public final class ExperienceAPI {
int powerLevel = 0; int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
for (SkillType type : SkillType.NON_CHILD_SKILLS) { for (SkillType type : SkillType.nonChildSkills()) {
powerLevel += profile.getSkillLevel(type); powerLevel += profile.getSkillLevel(type);
} }
@@ -461,7 +461,7 @@ public final class ExperienceAPI {
* @return the position on the leaderboard * @return the position on the leaderboard
*/ */
public static int getPlayerRankSkill(String playerName, String skillType) { public static int getPlayerRankSkill(String playerName, String skillType) {
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(getNonChildSkillType(skillType)); return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(getNonChildSkillType(skillType).toString());
} }
@@ -477,7 +477,7 @@ public final class ExperienceAPI {
* @return the position on the power level leaderboard * @return the position on the power level leaderboard
*/ */
public static int getPlayerRankOverall(String playerName) { public static int getPlayerRankOverall(String playerName) {
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(null); return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get("ALL");
} }
/** /**

View File

@@ -27,7 +27,7 @@ public class PartyChatManager extends ChatManager {
@Override @Override
protected void sendMessage() { protected void sendMessage() {
if (Config.getInstance().getPartyChatColorLeaderName() && senderName.equalsIgnoreCase(party.getLeader())) { if (Config.getInstance().getPartyChatColorLeaderName() && senderName.equalsIgnoreCase(party.getLeader())) {
message = message.replaceFirst(displayName, ChatColor.GOLD + displayName + ChatColor.RESET); message = message.replaceAll(displayName, ChatColor.GOLD + displayName + ChatColor.RESET);
} }
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {

View File

@@ -11,10 +11,11 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class KrakenCommand implements TabExecutor { public class KrakenCommand implements TabExecutor {
@@ -40,10 +41,10 @@ public class KrakenCommand implements TabExecutor {
return true; return true;
} }
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0], true); String playerName = Misc.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
if (mcMMOPlayer == null) { if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true; return true;
} }

View File

@@ -24,6 +24,6 @@ public class McabilityCommand extends ToggleCommand {
@Override @Override
protected void sendSuccessMessage(CommandSender sender) { protected void sendSuccessMessage(CommandSender sender) {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.Toggle")); sender.sendMessage("Ability use has been toggled for " + player.getName()); // TODO: Localize
} }
} }

View File

@@ -24,6 +24,6 @@ public class McgodCommand extends ToggleCommand {
@Override @Override
protected void sendSuccessMessage(CommandSender sender) { protected void sendSuccessMessage(CommandSender sender) {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Success")); sender.sendMessage("God mode has been toggled for " + player.getName()); // TODO: Localize
} }
} }

View File

@@ -2,19 +2,25 @@ package com.gmail.nossr50.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class McscoreboardCommand implements TabExecutor { public class McscoreboardCommand implements TabExecutor {
private static final List<String> FIRST_ARGS = ImmutableList.of("keep", "time", "clear"); private static final List<String> SCOREBOARD_TYPES = ImmutableList.of("clear", "rank", "stats", "top");
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@@ -22,49 +28,94 @@ public class McscoreboardCommand implements TabExecutor {
return true; return true;
} }
Player player = (Player) sender;
switch (args.length) { switch (args.length) {
case 0:
clearScoreboard(player);
return true;
case 1: case 1:
if (args[0].equalsIgnoreCase("clear") || args[0].equalsIgnoreCase("reset")) { if (args[0].equalsIgnoreCase("clear")) {
ScoreboardManager.clearBoard(sender.getName()); clearScoreboard(player);
sender.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Clear"));
return true;
} }
else if (args[0].equalsIgnoreCase("rank")) {
if (args[0].equalsIgnoreCase("keep")) { if (!Config.getInstance().getMcrankScoreboardEnabled()) {
if (!Config.getInstance().getAllowKeepBoard()) { sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true; return true;
} }
if (!ScoreboardManager.isBoardShown(sender.getName())) { ScoreboardManager.setupPlayerScoreboard(player.getName());
sender.sendMessage(LocaleLoader.getString("Commands.Scoreboard.NoBoard")); ScoreboardManager.enablePlayerRankScoreboard(player);
}
else if (args[0].equalsIgnoreCase("stats")) {
if (!Config.getInstance().getMcstatsScoreboardsEnabled()) {
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
return true; return true;
} }
ScoreboardManager.keepBoard(sender.getName()); ScoreboardManager.setupPlayerScoreboard(player.getName());
sender.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Keep")); ScoreboardManager.enablePlayerStatsScoreboard(UserManager.getPlayer(player));
return true; }
else if (args[0].equalsIgnoreCase("top")) {
if (!Config.getInstance().getMctopScoreboardEnabled()) {
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
return true;
}
ScoreboardManager.enableGlobalStatsScoreboard(player, "all", 1);
}
else {
return false;
} }
return help(sender); return true;
case 2: case 2:
if (args[0].equalsIgnoreCase("time") || args[0].equalsIgnoreCase("timer")) { if (!args[0].equalsIgnoreCase("top")) {
if (CommandUtils.isInvalidInteger(sender, args[1])) { return false;
return true; }
}
int time = Math.abs(Integer.parseInt(args[1])); if (!Config.getInstance().getMctopScoreboardEnabled()) {
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
ScoreboardManager.setRevertTimer(sender.getName(), time);
sender.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Timer", time));
return true; return true;
} }
return help(sender); if (StringUtils.isInt(args[1])) {
ScoreboardManager.enableGlobalStatsScoreboard(player, "all", Math.abs(Integer.parseInt(args[1])));
return true;
}
if (CommandUtils.isInvalidSkill(sender, args[1])) {
return true;
}
ScoreboardManager.enableGlobalStatsScoreboard(player, args[1], 1);
return true;
case 3:
if (!args[0].equalsIgnoreCase("top")) {
return false;
}
if (!Config.getInstance().getMctopScoreboardEnabled()) {
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
return true;
}
if (CommandUtils.isInvalidSkill(sender, args[1])) {
return true;
}
if (CommandUtils.isInvalidInteger(sender, args[2])) {
return true;
}
ScoreboardManager.enableGlobalStatsScoreboard(player, args[1], Math.abs(Integer.parseInt(args[2])));
return true;
default: default:
return help(sender); return false;
} }
} }
@@ -72,17 +123,20 @@ public class McscoreboardCommand implements TabExecutor {
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
switch (args.length) { switch (args.length) {
case 1: case 1:
return StringUtil.copyPartialMatches(args[0], FIRST_ARGS, new ArrayList<String>(FIRST_ARGS.size())); return StringUtil.copyPartialMatches(args[0], SCOREBOARD_TYPES, new ArrayList<String>(SCOREBOARD_TYPES.size()));
case 2:
if (args[0].equalsIgnoreCase("top")) {
return StringUtil.copyPartialMatches(args[1], SkillType.SKILL_NAMES, new ArrayList<String>(SkillType.SKILL_NAMES.size()));
}
// Fallthrough
default: default:
return ImmutableList.of(); return ImmutableList.of();
} }
} }
private boolean help(CommandSender sender) { private void clearScoreboard(Player player) {
sender.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Help.0")); player.setScoreboard(mcMMO.p.getServer().getScoreboardManager().getMainScoreboard());
sender.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Help.1")); player.sendMessage("Your scoreboard has been cleared!"); //TODO: Locale
sender.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Help.2"));
sender.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Help.3"));
return true;
} }
} }

View File

@@ -12,9 +12,9 @@ import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.MobHealthbarType; import com.gmail.nossr50.datatypes.MobHealthbarType;
import com.gmail.nossr50.datatypes.player.PlayerProfile; 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.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class MobhealthCommand implements TabExecutor { public class MobhealthCommand implements TabExecutor {
@@ -44,11 +44,11 @@ public class MobhealthCommand implements TabExecutor {
try { try {
MobHealthbarType type = MobHealthbarType.valueOf(args[0].toUpperCase().trim()); MobHealthbarType type = MobHealthbarType.valueOf(args[0].toUpperCase().trim());
playerProfile.setMobHealthbarType(type); playerProfile.setMobHealthbarType(type);
sender.sendMessage(LocaleLoader.getString("Commands.Healthbars.Changed." + type.name())); sender.sendMessage("Display type changed to: " + type); //TODO: Localize
return true; return true;
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
sender.sendMessage(LocaleLoader.getString("Commands.Healthbars.Invalid")); sender.sendMessage("Invalid type!"); //TODO: Localize
return true; return true;
} }

View File

@@ -11,9 +11,10 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public abstract class ToggleCommand implements TabExecutor { public abstract class ToggleCommand implements TabExecutor {
@@ -45,15 +46,19 @@ public abstract class ToggleCommand implements TabExecutor {
return true; return true;
} }
mcMMOPlayer = UserManager.getPlayer(args[0], true); String playerName = Misc.getMatchedPlayerName(args[0]);
mcMMOPlayer = UserManager.getPlayer(playerName);
if (mcMMOPlayer == null) { if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) {
player.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true; return true;
} }
player = mcMMOPlayer.getPlayer(); player = mcMMOPlayer.getPlayer();
if (CommandUtils.isOffline(sender, player)) {
return true;
}
applyCommandAction(); applyCommandAction();
sendSuccessMessage(sender); sendSuccessMessage(sender);
return true; return true;

View File

@@ -22,7 +22,7 @@ public class ConvertDatabaseCommand implements CommandExecutor {
DatabaseType previousType = DatabaseType.getDatabaseType(args[1]); DatabaseType previousType = DatabaseType.getDatabaseType(args[1]);
DatabaseType newType = mcMMO.getDatabaseManager().getDatabaseType(); DatabaseType newType = mcMMO.getDatabaseManager().getDatabaseType();
if (previousType == newType || (newType == DatabaseType.CUSTOM && DatabaseManagerFactory.getCustomDatabaseManagerClass().getSimpleName().equalsIgnoreCase(args[1]))) { if ((newType == DatabaseType.CUSTOM && DatabaseManagerFactory.getCustomDatabaseManagerClass().getSimpleName().equalsIgnoreCase(args[1])) || previousType == newType) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.Same", newType.toString())); sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.Same", newType.toString()));
return true; return true;
} }
@@ -39,12 +39,17 @@ public class ConvertDatabaseCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.InvalidType", args[1])); sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.InvalidType", args[1]));
return true; return true;
} }
}
catch (Exception e) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.InvalidType", args[1]));
return true;
}
try {
oldDatabase = DatabaseManagerFactory.createCustomDatabaseManager((Class<? extends DatabaseManager>) clazz); oldDatabase = DatabaseManagerFactory.createCustomDatabaseManager((Class<? extends DatabaseManager>) clazz);
} }
catch (Throwable e) { catch (Throwable t) {
e.printStackTrace(); sender.sendMessage("An error occurred during the conversion process."); // TODO: Localize
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.InvalidType", args[1]));
return true; return true;
} }
} }

View File

@@ -45,7 +45,7 @@ public class McconvertCommand implements TabExecutor {
} }
// Custom stuff // Custom stuff
databaseTypes.remove(DatabaseType.CUSTOM.toString()); databaseTypes.remove(DatabaseType.CUSTOM);
if (mcMMO.getDatabaseManager().getDatabaseType() == DatabaseType.CUSTOM) { if (mcMMO.getDatabaseManager().getDatabaseType() == DatabaseType.CUSTOM) {
databaseTypes.add(DatabaseManagerFactory.getCustomDatabaseManagerClass().getName()); databaseTypes.add(DatabaseManagerFactory.getCustomDatabaseManagerClass().getName());

View File

@@ -2,10 +2,12 @@ package com.gmail.nossr50.commands.experience;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillUtils;
public class AddlevelsCommand extends ExperienceCommand { public class AddlevelsCommand extends ExperienceCommand {
@Override @Override
@@ -20,14 +22,11 @@ public class AddlevelsCommand extends ExperienceCommand {
@Override @Override
protected void handleCommand(SkillType skill) { protected void handleCommand(SkillType skill) {
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.addLevels(skill, value); profile.addLevels(skill, value);
if (player == null) { if (player != null) {
return; mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value));
} }
EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, true);
} }
@Override @Override
@@ -37,6 +36,6 @@ public class AddlevelsCommand extends ExperienceCommand {
@Override @Override
protected void handlePlayerMessageSkill() { protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, skill.getName())); player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, SkillUtils.getSkillName(skill)));
} }
} }

View File

@@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillUtils;
public class AddxpCommand extends ExperienceCommand { public class AddxpCommand extends ExperienceCommand {
@Override @Override
@@ -34,6 +35,6 @@ public class AddxpCommand extends ExperienceCommand {
@Override @Override
protected void handlePlayerMessageSkill() { protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", value, skill.getName())); player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", value, SkillUtils.getSkillName(skill)));
} }
} }

View File

@@ -18,6 +18,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@@ -148,7 +149,7 @@ public abstract class ExperienceCommand implements TabExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName));
} }
else { else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", skill.getName(), playerName)); sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", SkillUtils.getSkillName(skill), playerName));
} }
} }

View File

@@ -2,10 +2,13 @@ package com.gmail.nossr50.commands.experience;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillUtils;
public class MmoeditCommand extends ExperienceCommand { public class MmoeditCommand extends ExperienceCommand {
@Override @Override
@@ -20,16 +23,20 @@ public class MmoeditCommand extends ExperienceCommand {
@Override @Override
protected void handleCommand(SkillType skill) { protected void handleCommand(SkillType skill) {
int skillLevel = profile.getSkillLevel(skill);
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.modifySkill(skill, value); profile.modifySkill(skill, value);
if (player == null || value == skillLevel) { if (player == null) {
return; return;
} }
EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, value > skillLevel); int skillLevel = profile.getSkillLevel(skill);
if (value > skillLevel) {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value - skillLevel));
}
else if (value < skillLevel) {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelDownEvent(player, skill, skillLevel - value));
}
} }
@Override @Override
@@ -39,6 +46,6 @@ public class MmoeditCommand extends ExperienceCommand {
@Override @Override
protected void handlePlayerMessageSkill() { protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", skill.getName(), value)); player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", SkillUtils.getSkillName(skill), value));
} }
} }

View File

@@ -6,12 +6,13 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public class SkillresetCommand extends ExperienceCommand { public class SkillresetCommand extends ExperienceCommand {
private CommandSender sender; private CommandSender sender;
@@ -102,16 +103,11 @@ public class SkillresetCommand extends ExperienceCommand {
return; return;
} }
int levelsRemoved = profile.getSkillLevel(skill);
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.modifySkill(skill, 0); profile.modifySkill(skill, 0);
if (player == null) { if (player != null) {
return; mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelDownEvent(player, skill, profile.getSkillLevel(skill)));
} }
EventUtils.handleLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false);
} }
@Override @Override
@@ -121,6 +117,6 @@ public class SkillresetCommand extends ExperienceCommand {
@Override @Override
protected void handlePlayerMessageSkill() { protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", skill.getName())); player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", SkillUtils.getSkillName(skill)));
} }
} }

View File

@@ -50,12 +50,12 @@ public class HardcoreCommand extends HardcoreModeCommand {
private void toggle(boolean enable) { private void toggle(boolean enable) {
if (skill.equalsIgnoreCase("ALL")) { if (skill.equalsIgnoreCase("ALL")) {
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) { for (SkillType skillType : SkillType.nonChildSkills()) {
skillType.setHardcoreStatLossEnabled(enable); Config.getInstance().setHardcoreStatLossEnabled(skillType, enable);
} }
} }
else { else {
SkillType.getSkill(skill).setHardcoreStatLossEnabled(enable); Config.getInstance().setHardcoreStatLossEnabled(SkillType.getSkill(skill), enable);
} }
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), skill)); mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), skill));

View File

@@ -48,16 +48,16 @@ public class VampirismCommand extends HardcoreModeCommand {
sender.sendMessage(LocaleLoader.getString("Hardcore.Vampirism.PercentageChanged", percent.format(newPercent / 100D))); sender.sendMessage(LocaleLoader.getString("Hardcore.Vampirism.PercentageChanged", percent.format(newPercent / 100D)));
} }
private void toggle(boolean enable) { private void toggle(boolean enabled) {
if (skill.equalsIgnoreCase("ALL")) { if (skill.equalsIgnoreCase("ALL")) {
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) { for (SkillType skillType : SkillType.nonChildSkills()) {
skillType.setHardcoreVampirismEnabled(enable); Config.getInstance().setHardcoreVampirismEnabled(skillType, enabled);
} }
} }
else { else {
SkillType.getSkill(skill).setHardcoreVampirismEnabled(enable); Config.getInstance().setHardcoreVampirismEnabled(SkillType.getSkill(skill), enabled);
} }
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.Vampirism.Name"), skill)); mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enabled ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.Vampirism.Name"), skill));
} }
} }

View File

@@ -9,23 +9,34 @@ import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyInviteCommand implements CommandExecutor { public class PartyInviteCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return false;
}
switch (args.length) { switch (args.length) {
case 2: case 2:
String targetName = Misc.getMatchedPlayerName(args[1]);
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName, true);
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return false;
}
Player target = mcMMOTarget.getPlayer();
Player player = (Player) sender; Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
String playerName = player.getName(); String playerName = player.getName();
if (playerName.equalsIgnoreCase(args[1])) { if (player.equals(target)) {
player.sendMessage(LocaleLoader.getString("Party.Invite.Self")); sender.sendMessage(LocaleLoader.getString("Party.Invite.Self"));
return true;
}
if (PartyManager.inSameParty(player, target)) {
sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", targetName));
return true; return true;
} }
@@ -34,20 +45,6 @@ public class PartyInviteCommand implements CommandExecutor {
return true; return true;
} }
McMMOPlayer mcMMOTarget = UserManager.getPlayer(args[1], true);
if (mcMMOTarget == null) {
player.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
Player target = mcMMOTarget.getPlayer();
if (PartyManager.inSameParty(player, target)) {
sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", target.getName()));
return true;
}
Party playerParty = mcMMOPlayer.getParty(); Party playerParty = mcMMOPlayer.getParty();
mcMMOTarget.setPartyInvite(playerParty); mcMMOTarget.setPartyInvite(playerParty);

View File

@@ -9,26 +9,31 @@ import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyJoinCommand implements CommandExecutor { public class PartyJoinCommand implements CommandExecutor {
private McMMOPlayer mcMMOTarget;
private Player target;
private Party targetParty;
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
private Player player; private Player player;
private Party targetParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
case 3: case 3:
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
// Verify target exists and is in a different party than the player // Verify target exists and is in a different party than the player
if (!canJoinParty(sender, args[1])) { if (!canJoinParty(sender, args[1])) {
return true; return true;
} }
mcMMOPlayer = UserManager.getPlayer((Player) sender);
player = mcMMOPlayer.getPlayer();
String password = getPassword(args); String password = getPassword(args);
// Make sure party passwords match // Make sure party passwords match
@@ -62,21 +67,25 @@ public class PartyJoinCommand implements CommandExecutor {
} }
private boolean canJoinParty(CommandSender sender, String targetName) { private boolean canJoinParty(CommandSender sender, String targetName) {
// Short-circuit for joining your own party targetName = Misc.getMatchedPlayerName(targetName);
if (sender.getName().equalsIgnoreCase(targetName)) { mcMMOTarget = UserManager.getPlayer(targetName);
sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return false; return false;
} }
targetParty = PartyManager.getPlayerParty(targetName); target = mcMMOTarget.getPlayer();
if (targetParty == null) { if (!mcMMOTarget.inParty()) {
sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName)); sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName));
return false; return false;
} }
// Can't join your own party player = (Player) sender;
if (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty)) { mcMMOPlayer = UserManager.getPlayer(player);
targetParty = mcMMOTarget.getParty();
if (player.equals(target) || (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty))) {
sender.sendMessage(LocaleLoader.getString("Party.Join.Self")); sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
return false; return false;
} }

View File

@@ -38,7 +38,7 @@ public class PtpAcceptCommand implements CommandExecutor {
Player target = mcMMOPlayer.getPtpRequest(); Player target = mcMMOPlayer.getPtpRequest();
mcMMOPlayer.removePtpRequest(); mcMMOPlayer.removePtpRequest();
if (!PtpCommand.canTeleport(player, target.getName())) { if (!PtpCommand.canTeleport(sender, player, target.getName())) {
return true; return true;
} }

View File

@@ -14,10 +14,10 @@ import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.items.TeleportationWarmup; import com.gmail.nossr50.runnables.items.TeleportationWarmup;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
@@ -88,7 +88,7 @@ public class PtpCommand implements TabExecutor {
} }
} }
sendTeleportRequest(player, Misc.getMatchedPlayerName(args[0])); sendTeleportRequest(sender, player, Misc.getMatchedPlayerName(args[0]));
return true; return true;
default: default:
@@ -113,8 +113,8 @@ public class PtpCommand implements TabExecutor {
} }
} }
private void sendTeleportRequest(Player player, String targetName) { private void sendTeleportRequest(CommandSender sender, Player player, String targetName) {
if (!canTeleport(player, targetName)) { if (!canTeleport(sender, player, targetName)) {
return; return;
} }
@@ -132,21 +132,20 @@ public class PtpCommand implements TabExecutor {
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request2", Config.getInstance().getPTPCommandTimeout())); target.sendMessage(LocaleLoader.getString("Commands.ptp.Request2", Config.getInstance().getPTPCommandTimeout()));
} }
protected static boolean canTeleport(Player player, String targetName) { protected static boolean canTeleport(CommandSender sender, Player player, String targetName) {
target = mcMMO.p.getServer().getPlayerExact(targetName); mcMMOTarget = UserManager.getPlayer(targetName);
if (target == null) { if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
player.sendMessage(LocaleLoader.getString("Commands.Offline"));
return false; return false;
} }
target = mcMMOTarget.getPlayer();
if (player.equals(target)) { if (player.equals(target)) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self")); player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
return false; return false;
} }
mcMMOTarget = UserManager.getPlayer(target);
if (!PartyManager.inSameParty(player, target)) { if (!PartyManager.inSameParty(player, target)) {
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName)); player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName));
return false; return false;
@@ -178,7 +177,25 @@ public class PtpCommand implements TabExecutor {
new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(mcMMO.p, 20 * warmup); new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(mcMMO.p, 20 * warmup);
} }
else { else {
EventUtils.handlePartyTeleportEvent(teleportingPlayer, targetPlayer); handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
} }
} }
public 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.actualizePtpLastUse();
}
} }

View File

@@ -29,6 +29,10 @@ public class InspectCommand implements TabExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 1: case 1:
if (sender instanceof Player && Config.getInstance().getInspectScoreboardEnabled()) {
ScoreboardManager.setupPlayerScoreboard(sender.getName());
}
String playerName = Misc.getMatchedPlayerName(args[0]); String playerName = Misc.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);
@@ -40,31 +44,30 @@ public class InspectCommand implements TabExecutor {
return true; return true;
} }
if (sender instanceof Player && Config.getInstance().getInspectUseBoard()) { if (sender instanceof Player && Config.getInstance().getInspectScoreboardEnabled()) {
ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, profile); ScoreboardManager.enablePlayerInspectScoreboardOffline((Player) sender, profile);
return true;
if (!Config.getInstance().getInspectUseChat()) {
return true;
}
} }
sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", playerName)); sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", playerName));
sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering")); sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
for (SkillType skill : SkillType.GATHERING_SKILLS) { CommandUtils.displaySkill(sender, profile, SkillType.EXCAVATION);
sender.sendMessage(CommandUtils.displaySkill(profile, skill)); 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("Stats.Header.Combat"));
for (SkillType skill : SkillType.COMBAT_SKILLS) { CommandUtils.displaySkill(sender, profile, SkillType.AXES);
sender.sendMessage(CommandUtils.displaySkill(profile, skill)); 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("Stats.Header.Misc"));
for (SkillType skill : SkillType.MISC_SKILLS) { CommandUtils.displaySkill(sender, profile, SkillType.ACROBATICS);
sender.sendMessage(CommandUtils.displaySkill(profile, skill)); CommandUtils.displaySkill(sender, profile, SkillType.REPAIR);
}
} }
else { else {
Player target = mcMMOPlayer.getPlayer(); Player target = mcMMOPlayer.getPlayer();
@@ -79,12 +82,9 @@ public class InspectCommand implements TabExecutor {
return true; return true;
} }
if (sender instanceof Player && Config.getInstance().getInspectUseBoard()) { if (sender instanceof Player && Config.getInstance().getInspectScoreboardEnabled()) {
ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, mcMMOPlayer.getProfile()); ScoreboardManager.enablePlayerInspectScoreboardOnline((Player) sender, mcMMOPlayer);
return true;
if (!Config.getInstance().getInspectUseChat()) {
return true;
}
} }
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName())); sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName()));

View File

@@ -1,69 +0,0 @@
package com.gmail.nossr50.commands.player;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
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.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList;
public class MccooldownCommand implements TabExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
switch (args.length) {
case 0:
Player player = (Player) sender;
if (Config.getInstance().getCooldownUseBoard()) {
ScoreboardManager.enablePlayerCooldownScoreboard(player);
if (!Config.getInstance().getCooldownUseChat()) {
return true;
}
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Header"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
for (AbilityType ability : AbilityType.NORMAL_ABILITIES) {
if (!ability.getPermissions(player)) {
continue;
}
int seconds = mcMMOPlayer.calculateTimeRemaining(ability);
if (seconds <= 0) {
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Row.Y", ability.getName()));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Row.N", ability.getName(), seconds));
}
}
return true;
default:
return false;
}
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return ImmutableList.of();
}
}

View File

@@ -13,12 +13,13 @@ import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask; import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class McrankCommand implements TabExecutor { public class McrankCommand implements TabExecutor {
@@ -35,7 +36,13 @@ public class McrankCommand implements TabExecutor {
return true; return true;
} }
display(sender, sender.getName()); if (Config.getInstance().getMcrankScoreboardEnabled()) {
ScoreboardManager.setupPlayerScoreboard(sender.getName());
ScoreboardManager.enablePlayerRankScoreboard((Player) sender);
}
else {
display(sender, sender.getName());
}
return true; return true;
@@ -49,10 +56,9 @@ public class McrankCommand implements TabExecutor {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);
if (mcMMOPlayer != null) { if (mcMMOPlayer != null) {
Player player = mcMMOPlayer.getPlayer(); playerName = mcMMOPlayer.getPlayer().getName();
playerName = player.getName();
if (CommandUtils.tooFar(sender, player, Permissions.mcrankFar(sender))) { if (CommandUtils.tooFar(sender, mcMMOPlayer.getPlayer(), Permissions.mcrankFar(sender))) {
return true; return true;
} }
} }
@@ -60,7 +66,13 @@ public class McrankCommand implements TabExecutor {
return true; return true;
} }
display(sender, playerName); if (sender instanceof Player && Config.getInstance().getMcrankScoreboardEnabled()) {
ScoreboardManager.setupPlayerScoreboard(sender.getName());
ScoreboardManager.enablePlayerRankScoreboardOthers((Player) sender, playerName);
}
else {
display(sender, playerName);
}
return true; return true;
default: default:
@@ -80,20 +92,6 @@ public class McrankCommand implements TabExecutor {
} }
private void display(CommandSender sender, String playerName) { private void display(CommandSender sender, String playerName) {
if (sender instanceof Player) { new McrankCommandAsyncTask(playerName, sender).runTaskAsynchronously(mcMMO.p);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
if (mcMMOPlayer.getDatabaseATS() + Misc.PLAYER_DATABASE_COOLDOWN_MILLIS > System.currentTimeMillis()) {
sender.sendMessage(LocaleLoader.getString("Commands.Database.Cooldown"));
return;
}
mcMMOPlayer.actualizeDatabaseATS();
}
boolean useBoard = (sender instanceof Player) && (Config.getInstance().getRankUseBoard());
boolean useChat = useBoard ? Config.getInstance().getRankUseChat() : true;
new McrankCommandAsyncTask(playerName, sender, useBoard, useChat).runTaskAsynchronously(mcMMO.p);
} }
} }

View File

@@ -8,6 +8,7 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@@ -25,29 +26,28 @@ public class McstatsCommand implements TabExecutor {
switch (args.length) { switch (args.length) {
case 0: case 0:
Player player = (Player) sender; Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (Config.getInstance().getStatsUseBoard()) { if (Config.getInstance().getMcstatsScoreboardsEnabled()) {
ScoreboardManager.enablePlayerStatsScoreboard(player); ScoreboardManager.setupPlayerScoreboard(player.getName());
ScoreboardManager.enablePlayerStatsScoreboard(mcMMOPlayer);
if (!Config.getInstance().getStatsUseChat()) {
return true;
}
}
player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
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", UserManager.getPlayer(player).getPowerLevel(), powerLevelCap));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", UserManager.getPlayer(player).getPowerLevel())); player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
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", UserManager.getPlayer(player).getPowerLevel(), powerLevelCap));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", UserManager.getPlayer(player).getPowerLevel()));
}
} }
return true; return true;

View File

@@ -11,40 +11,36 @@ import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask; import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class MctopCommand implements TabExecutor { public class MctopCommand implements TabExecutor {
private SkillType skill;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
SkillType skill = null;
switch (args.length) { switch (args.length) {
case 0: case 0:
display(1, skill, sender, command); display(1, "ALL", sender, command);
return true; return true;
case 1: case 1:
if (StringUtils.isInt(args[0])) { if (StringUtils.isInt(args[0])) {
display(Math.abs(Integer.parseInt(args[0])), skill, sender, command); display(Math.abs(Integer.parseInt(args[0])), "ALL", sender, command);
return true; return true;
} }
skill = extractSkill(sender, args[0]); if (!extractSkill(sender, args[0])) {
if (skill == null) {
return true; return true;
} }
display(1, skill, sender, command); display(1, skill.toString(), sender, command);
return true; return true;
case 2: case 2:
@@ -52,13 +48,11 @@ public class MctopCommand implements TabExecutor {
return true; return true;
} }
skill = extractSkill(sender, args[0]); if (!extractSkill(sender, args[0])) {
if (skill == null) {
return true; return true;
} }
display(Math.abs(Integer.parseInt(args[1])), skill, sender, command); display(Math.abs(Integer.parseInt(args[1])), skill.toString(), sender, command);
return true; return true;
default: default:
@@ -76,44 +70,35 @@ public class MctopCommand implements TabExecutor {
} }
} }
private void display(int page, SkillType skill, CommandSender sender, Command command) { private void display(int page, String skill, CommandSender sender, Command command) {
if (skill != null && !Permissions.mctop(sender, skill)) { if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, this.skill)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return; return;
} }
if (sender instanceof Player) { if (sender instanceof Player && Config.getInstance().getMctopScoreboardEnabled()) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName()); ScoreboardManager.enableGlobalStatsScoreboard((Player) sender, skill, page);
}
if (mcMMOPlayer.getDatabaseATS() + Misc.PLAYER_DATABASE_COOLDOWN_MILLIS > System.currentTimeMillis()) { else {
sender.sendMessage(LocaleLoader.getString("Commands.Database.Cooldown")); display(page, skill, sender);
return;
}
mcMMOPlayer.actualizeDatabaseATS();
} }
display(page, skill, sender);
} }
private void display(int page, SkillType skill, CommandSender sender) { private void display(int page, String query, CommandSender sender) {
boolean useBoard = (sender instanceof Player) && (Config.getInstance().getTopUseBoard()); new MctopCommandAsyncTask(page, query, sender).runTaskAsynchronously(mcMMO.p);
boolean useChat = useBoard ? Config.getInstance().getTopUseChat() : true;
new MctopCommandAsyncTask(page, skill, sender, useBoard, useChat).runTaskAsynchronously(mcMMO.p);
} }
private SkillType extractSkill(CommandSender sender, String skillName) { private boolean extractSkill(CommandSender sender, String skillName) {
if (CommandUtils.isInvalidSkill(sender, skillName)) { if (CommandUtils.isInvalidSkill(sender, skillName)) {
return null; return false;
} }
SkillType skill = SkillType.getSkill(skillName); skill = SkillType.getSkill(skillName);
if (CommandUtils.isChildSkill(sender, skill)) { if (CommandUtils.isChildSkill(sender, skill)) {
return null; return false;
} }
return skill; return true;
} }
} }

View File

@@ -1,36 +1,25 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import org.bukkit.Location;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.treasure.Rarity;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.fishing.Fishing; import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.fishing.Fishing.Tier;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class FishingCommand extends SkillCommand { public class FishingCommand extends SkillCommand {
private int lootTier; private int lootTier;
private String magicChance;
private String magicChanceLucky;
private String chanceRaining = "";
private String shakeChance; private String shakeChance;
private String shakeChanceLucky; private String shakeChanceLucky;
private int fishermansDietRank; private int fishermansDietRank;
private String biteChance; private String biteChance;
private String trapTreasure;
private String commonTreasure;
private String uncommonTreasure;
private String rareTreasure;
private String epicTreasure;
private String legendaryTreasure;
private String recordTreasure;
private String magicChance;
private boolean canTreasureHunt; private boolean canTreasureHunt;
private boolean canMagicHunt; private boolean canMagicHunt;
private boolean canShake; private boolean canShake;
@@ -49,24 +38,16 @@ public class FishingCommand extends SkillCommand {
// TREASURE HUNTER // TREASURE HUNTER
if (canTreasureHunt) { if (canTreasureHunt) {
lootTier = mcMMOPlayer.getFishingManager().getLootTier(); lootTier = mcMMOPlayer.getFishingManager().getLootTier();
double enchantChance = lootTier * AdvancedConfig.getInstance().getFishingMagicMultiplier();
// Item drop rates if (isStorming) {
trapTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.TRAP))[0]; chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining");
commonTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.COMMON))[0]; enchantChance *= 1.1D;
uncommonTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.UNCOMMON))[0]; }
rareTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RARE))[0];
epicTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.EPIC))[0];
legendaryTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.LEGENDARY))[0];
recordTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RECORD))[0];
// Magic hunter drop rates String[] treasureHunterStrings = calculateAbilityDisplayValues(enchantChance);
double commonEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.COMMON); magicChance = treasureHunterStrings[0];
double uncommonEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.UNCOMMON); magicChanceLucky = treasureHunterStrings[1];
double rareEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.RARE);
double epicEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.EPIC);
double legendaryEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.LEGENDARY);
magicChance = calculateAbilityDisplayValues(commonEnchantment + uncommonEnchantment + rareEnchantment + epicEnchantment + legendaryEnchantment)[0];
} }
// SHAKE // SHAKE
@@ -83,17 +64,15 @@ public class FishingCommand extends SkillCommand {
// MASTER ANGLER // MASTER ANGLER
if (canMasterAngler) { if (canMasterAngler) {
double rawBiteChance = 1.0 / (isStorming ? 300 : 500); double rawBiteChance = ((Math.max((skillValue / 200.0), 1.0)) / (isStorming ? 300 : 500));
Location location = (mcMMOPlayer.getHookLocation() != null) ? mcMMOPlayer.getHookLocation() : player.getLocation(); Biome biome = player.getLocation().getBlock().getBiome();
Biome biome = location.getBlock().getBiome();
if (biome == Biome.RIVER || biome == Biome.OCEAN) { if (biome == Biome.RIVER || biome == Biome.OCEAN) {
rawBiteChance = rawBiteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier(); rawBiteChance = rawBiteChance * 2.0;
} }
if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) { if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) {
rawBiteChance = rawBiteChance * AdvancedConfig.getInstance().getMasterAnglerBoatModifier(); rawBiteChance = rawBiteChance * 2.0;
} }
biteChance = calculateAbilityDisplayValues(rawBiteChance * 100.0)[0]; biteChance = calculateAbilityDisplayValues(rawBiteChance * 100.0)[0];
@@ -127,14 +106,6 @@ public class FishingCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.2"), LocaleLoader.getString("Fishing.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.2"), LocaleLoader.getString("Fishing.Effect.3")));
} }
if (canIceFish) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.10"), LocaleLoader.getString("Fishing.Effect.11")));
}
if (canMasterAngler) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.8"), LocaleLoader.getString("Fishing.Effect.9")));
}
if (canShake) { if (canShake) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.4"), LocaleLoader.getString("Fishing.Effect.5"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.4"), LocaleLoader.getString("Fishing.Effect.5")));
} }
@@ -142,6 +113,14 @@ public class FishingCommand extends SkillCommand {
if (canFishermansDiet) { if (canFishermansDiet) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.6"), LocaleLoader.getString("Fishing.Effect.7"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.6"), LocaleLoader.getString("Fishing.Effect.7")));
} }
if (canMasterAngler) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.8"), LocaleLoader.getString("Fishing.Effect.9")));
}
if (canIceFish) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.10"), LocaleLoader.getString("Fishing.Effect.11")));
}
} }
@Override @Override
@@ -151,39 +130,20 @@ public class FishingCommand extends SkillCommand {
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canMasterAngler) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Chance", biteChance));
}
if (canTreasureHunt) { if (canTreasureHunt) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Rank", lootTier, Tier.EIGHT.toNumerical())); player.sendMessage(LocaleLoader.getString("Fishing.Ability.Rank", lootTier));
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.DropRate", trapTreasure, commonTreasure, uncommonTreasure, rareTreasure, epicTreasure, legendaryTreasure, recordTreasure));
} }
if (canMagicHunt) { if (canMagicHunt) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.MagicRate", magicChance)); player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", magicChanceLucky) : ""));
}
if (canIceFish) {
int unlockLevel = AdvancedConfig.getInstance().getIceFishingUnlockLevel();
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.1", unlockLevel)));
}
else {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.IceFishing"));
}
}
if (canMasterAngler) {
int unlockLevel = AdvancedConfig.getInstance().getMasterAnglerUnlockLevel();
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.2", unlockLevel)));
}
else {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Chance", biteChance));
}
} }
if (canShake) { if (canShake) {
int unlockLevel = AdvancedConfig.getInstance().getFishingTierLevel(Tier.ONE); int unlockLevel = AdvancedConfig.getInstance().getShakeUnlockLevel();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.0", unlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.0", unlockLevel)));
@@ -196,5 +156,16 @@ public class FishingCommand extends SkillCommand {
if (canFishermansDiet) { if (canFishermansDiet) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.FD", fishermansDietRank)); player.sendMessage(LocaleLoader.getString("Fishing.Ability.FD", fishermansDietRank));
} }
if (canIceFish) {
int unlockLevel = AdvancedConfig.getInstance().getIceFishingUnlockLevel();
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.1", unlockLevel)));
}
else {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.IceFishing"));
}
}
} }
} }

View File

@@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.mining.BlastMining.Tier;
import com.gmail.nossr50.skills.mining.Mining; import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@@ -115,18 +114,18 @@ public class MiningCommand extends SkillCommand {
} }
if (canBlast) { if (canBlast) {
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRankLevel(Tier.ONE); int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank1();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", unlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", unlockLevel)));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, Tier.EIGHT.toNumerical(), LocaleLoader.getString("Mining.Blast.Effect", oreBonus, debrisReduction, bonusTNTDrops))); player.sendMessage(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, LocaleLoader.getString("Mining.Blast.Effect", oreBonus, debrisReduction, bonusTNTDrops)));
} }
} }
if (canBiggerBombs) { if (canBiggerBombs) {
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRankLevel(Tier.TWO); int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank2();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", unlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", unlockLevel)));
@@ -137,7 +136,7 @@ public class MiningCommand extends SkillCommand {
} }
if (canDemoExpert) { if (canDemoExpert) {
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRankLevel(Tier.FOUR); int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank4();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", unlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", unlockLevel)));

View File

@@ -6,10 +6,9 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.repair.ArcaneForging; import com.gmail.nossr50.skills.repair.ArcaneForging;
import com.gmail.nossr50.skills.repair.ArcaneForging.Tier;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.RepairManager; import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class RepairCommand extends SkillCommand { public class RepairCommand extends SkillCommand {
@@ -146,7 +145,7 @@ public class RepairCommand extends SkillCommand {
if (canArcaneForge) { if (canArcaneForge) {
RepairManager repairManager = mcMMOPlayer.getRepairManager(); RepairManager repairManager = mcMMOPlayer.getRepairManager();
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Rank", repairManager.getArcaneForgingRank(), Tier.EIGHT.toNumerical())); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Rank", repairManager.getArcaneForgingRank()));
if (ArcaneForging.arcaneForgingEnchantLoss) { if (ArcaneForging.arcaneForgingEnchantLoss) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : repairManager.getKeepEnchantChance()))); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : repairManager.getKeepEnchantChance())));

View File

@@ -23,6 +23,7 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.skills.PerksUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@@ -45,7 +46,7 @@ public abstract class SkillCommand implements TabExecutor {
public SkillCommand(SkillType skill) { public SkillCommand(SkillType skill) {
this.skill = skill; this.skill = skill;
skillName = skill.getName(); skillName = SkillUtils.getSkillName(skill);
skillGuideCommand = new SkillGuideCommand(skill); skillGuideCommand = new SkillGuideCommand(skill);
} }
@@ -69,14 +70,17 @@ public abstract class SkillCommand implements TabExecutor {
permissionsCheck(); permissionsCheck();
dataCalculations(); dataCalculations();
if (Config.getInstance().getSkillUseBoard()) {
ScoreboardManager.enablePlayerSkillScoreboard(player, skill);
}
if (!skill.isChildSkill()) { if (!skill.isChildSkill()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", skillName)); 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("Commands.XPGain", LocaleLoader.getString("Commands.XPGain." + StringUtils.getCapitalized(skill.toString()))));
player.sendMessage(LocaleLoader.getString("Effects.Level", (int) skillValue, profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)));
if (Config.getInstance().getSkillScoreboardEnabled()) {
ScoreboardManager.setupPlayerScoreboard(player.getName());
ScoreboardManager.enablePlayerSkillScoreboard(mcMMOPlayer, skill);
}
else {
player.sendMessage(LocaleLoader.getString("Effects.Level", (int) skillValue, profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)));
}
} }
else { else {
player.sendMessage(LocaleLoader.getString("Skills.Header", skillName + " " + LocaleLoader.getString("Skills.Child"))); player.sendMessage(LocaleLoader.getString("Skills.Header", skillName + " " + LocaleLoader.getString("Skills.Child")));
@@ -87,7 +91,7 @@ public abstract class SkillCommand implements TabExecutor {
Set<SkillType> parents = FamilyTree.getParents(skill); Set<SkillType> parents = FamilyTree.getParents(skill);
for (SkillType parent : parents) { for (SkillType parent : parents) {
player.sendMessage(parent.getName() + " - " + LocaleLoader.getString("Effects.Level", profile.getSkillLevel(parent), profile.getSkillXpLevel(parent), profile.getXpToLevel(parent))); player.sendMessage(SkillUtils.getSkillName(parent) + " - " + LocaleLoader.getString("Effects.Level", profile.getSkillLevel(parent), profile.getSkillXpLevel(parent), profile.getXpToLevel(parent)));
} }
} }

View File

@@ -1,7 +1,6 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@@ -10,16 +9,17 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class SkillGuideCommand implements CommandExecutor { public class SkillGuideCommand implements CommandExecutor {
private String header; private String header;
private ArrayList<String> guide; private String[] guide;
private String invalidPage; private String invalidPage;
public SkillGuideCommand(SkillType skillType) { public SkillGuideCommand(SkillType skillType) {
header = LocaleLoader.getString("Guides.Header", skillType.getName()); header = LocaleLoader.getString("Guides.Header", SkillUtils.getSkillName(skillType));
guide = getGuide(skillType); guide = LocaleLoader.getString("Guides." + StringUtils.getCapitalized(skillType.toString())).split("\n");
invalidPage = LocaleLoader.getString("Guides.Page.Invalid"); invalidPage = LocaleLoader.getString("Guides.Page.Invalid");
} }
@@ -59,7 +59,7 @@ public class SkillGuideCommand implements CommandExecutor {
} }
private int getTotalPageNumber() { private int getTotalPageNumber() {
return (int) Math.ceil(guide.size() / 8.0); return (int) Math.ceil(guide.length / 8.0);
} }
private void sendGuide(CommandSender sender, int pageNumber) { private void sendGuide(CommandSender sender, int pageNumber) {
@@ -76,38 +76,15 @@ public class SkillGuideCommand implements CommandExecutor {
// Add targeted strings // Add targeted strings
while (allStrings.size() < 9) { while (allStrings.size() < 9) {
if (pageIndexStart + allStrings.size() > guide.size()) { if (pageIndexStart + allStrings.size() > guide.length) {
allStrings.add(""); allStrings.add("");
} }
else { else {
allStrings.add(guide.get(pageIndexStart + (allStrings.size() - 1))); allStrings.add(guide[pageIndexStart + (allStrings.size() - 1)]);
} }
} }
allStrings.add("Page " + pagenum + " of " + getTotalPageNumber()); allStrings.add("Page " + pagenum + " of " + getTotalPageNumber());
return allStrings; return allStrings;
} }
private ArrayList<String> getGuide(SkillType skillType) {
ArrayList<String> guide = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
String[] section = LocaleLoader.getString("Guides." + StringUtils.getCapitalized(skillType.toString()) + ".Section." + i).split("\n");
if (section[0].startsWith("!")) {
break;
}
guide.addAll(Arrays.asList(section));
if (section.length < 8) {
for (int blankLine = 8 - section.length; blankLine > 0; blankLine--) {
guide.add("");
}
}
}
return guide;
}
} }

View File

@@ -4,7 +4,6 @@ import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.smelting.Smelting; import com.gmail.nossr50.skills.smelting.Smelting;
import com.gmail.nossr50.skills.smelting.Smelting.Tier;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class SmeltingCommand extends SkillCommand { public class SmeltingCommand extends SkillCommand {
@@ -95,7 +94,7 @@ public class SmeltingCommand extends SkillCommand {
} }
if (canVanillaXPBoost) { if (canVanillaXPBoost) {
int unlockLevel = AdvancedConfig.getInstance().getSmeltingRankLevel(Tier.ONE); int unlockLevel = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", unlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", unlockLevel)));

File diff suppressed because it is too large Load Diff

View File

@@ -45,44 +45,24 @@ public class Config extends AutoUpdateConfigLoader {
} }
/* Scoreboards */ /* Scoreboards */
if (getRankScoreboardTime() != -1 && getRankScoreboardTime() <= 0) { if (getMcrankScoreboardTime() != -1 && getMcrankScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Rank.Display_Time should be greater than 0, or -1!"); reason.add("Scoreboards.Mcrank.Display_Time should be greater than 0 or -1!");
} }
if (getStatsScoreboardTime() != -1 && getStatsScoreboardTime() <= 0) { if (getMcstatsScoreboardTime() != -1 && getMcstatsScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Stats.Display_Time should be greater than 0, or -1!"); reason.add("Scoreboards.Mcstats.Display_Time should be greater than 0 or -1!");
} }
if (getTopScoreboardTime() != -1 && getTopScoreboardTime() <= 0) { if (getMctopScoreboardTime() != -1 && getMctopScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Top.Display_Time should be greater than 0, or -1!"); reason.add("Scoreboards.Mctop.Display_Time should be greater than 0 or -1!");
} }
if (getInspectScoreboardTime() != -1 && getInspectScoreboardTime() <= 0) { if (getInspectScoreboardTime() != -1 && getInspectScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Inspect.Display_Time should be greater than 0, or -1!"); reason.add("Scoreboards.Inspect.Display_Time should be greater than 0 or -1!");
} }
if (getSkillScoreboardTime() != -1 && getSkillScoreboardTime() <= 0) { if (getSkillScoreboardTime() != -1 && getSkillScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Skill.Display_Time should be greater than 0, or -1!"); reason.add("Scoreboards.Skillname.Display_Time should be greater than 0 or -1!");
}
if (getSkillLevelUpTime() != -1 && getSkillScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Skill.Display_Time should be greater than 0, or -1!");
}
if (!(getRankUseChat() || getRankUseBoard())) {
reason.add("Either Board or Print in Scoreboard.Types.Rank must be true!");
}
if (!(getTopUseChat() || getTopUseBoard())) {
reason.add("Either Board or Print in Scoreboard.Types.Top must be true!");
}
if (!(getStatsUseChat() || getStatsUseBoard())) {
reason.add("Either Board or Print in Scoreboard.Types.Stats must be true!");
}
if (!(getInspectUseChat() || getInspectUseBoard())) {
reason.add("Either Board or Print in Scoreboard.Types.Inspect must be true!");
} }
/* Database Purging */ /* Database Purging */
@@ -232,35 +212,22 @@ public class Config extends AutoUpdateConfigLoader {
public int getMobHealthbarTime() { return config.getInt("Mob_Healthbar.Display_Time", 3); } public int getMobHealthbarTime() { return config.getInt("Mob_Healthbar.Display_Time", 3); }
/* Scoreboards */ /* Scoreboards */
public boolean getRankUseChat() { return config.getBoolean("Scoreboard.Types.Rank.Print", false); } public boolean getMcrankScoreboardEnabled() { return config.getBoolean("Scoreboards.Mcrank.Use", true); }
public boolean getRankUseBoard() { return config.getBoolean("Scoreboard.Types.Rank.Board", true); } public int getMcrankScoreboardTime() { return config.getInt("Scoreboards.Mcrank.Display_Time", 10); }
public int getRankScoreboardTime() { return config.getInt("Scoreboard.Types.Rank.Display_Time", 10); }
public boolean getTopUseChat() { return config.getBoolean("Scoreboard.Types.Top.Print", true); } public boolean getMcstatsScoreboardsEnabled() { return config.getBoolean("Scoreboards.Mcstats.Use", true); }
public boolean getTopUseBoard() { return config.getBoolean("Scoreboard.Types.Top.Board", true); } public int getMcstatsScoreboardTime() { return config.getInt("Scoreboards.Mcstats.Display_Time", 10); }
public int getTopScoreboardTime() { return config.getInt("Scoreboard.Types.Top.Display_Time", 15); }
public boolean getStatsUseChat() { return config.getBoolean("Scoreboard.Types.Stats.Print", true); } public boolean getMctopScoreboardEnabled() { return config.getBoolean("Scoreboards.Mctop.Use", true); }
public boolean getStatsUseBoard() { return config.getBoolean("Scoreboard.Types.Stats.Board", true); } public int getMctopScoreboardTime() { return config.getInt("Scoreboards.Mctop.Display_Time", 10); }
public int getStatsScoreboardTime() { return config.getInt("Scoreboard.Types.Stats.Display_Time", 10); }
public boolean getInspectUseChat() { return config.getBoolean("Scoreboard.Types.Inspect.Print", true); } public boolean getInspectScoreboardEnabled() { return config.getBoolean("Scoreboards.Inspect.Use", true); }
public boolean getInspectUseBoard() { return config.getBoolean("Scoreboard.Types.Inspect.Board", true); } public int getInspectScoreboardTime() { return config.getInt("Scoreboards.Inspect.Display_Time", 10); }
public int getInspectScoreboardTime() { return config.getInt("Scoreboard.Types.Inspect.Display_Time", 25); }
public boolean getCooldownUseChat() { return config.getBoolean("Scoreboard.Types.Cooldown.Print", false); } public boolean getSkillScoreboardEnabled() { return config.getBoolean("Scoreboards.Skillname.Use", true); }
public boolean getCooldownUseBoard() { return config.getBoolean("Scoreboard.Types.Cooldown.Board", true); } public int getSkillScoreboardTime() { return config.getInt("Scoreboards.Skillname.Display_Time", 10); }
public int getCooldownScoreboardTime() { return config.getInt("Scoreboard.Types.Cooldown.Display_Time", 41); }
public boolean getSkillUseBoard() { return config.getBoolean("Scoreboard.Types.Skill.Board", true); } public boolean getPowerLevelsEnabled() { return config.getBoolean("Scoreboards.Power_Level.Use", false); }
public int getSkillScoreboardTime() { return config.getInt("Scoreboard.Types.Skill.Display_Time", 30); }
public boolean getSkillLevelUpBoard() { return config.getBoolean("Scoreboard.Types.Skill.LevelUp_Board", true); }
public int getSkillLevelUpTime() { return config.getInt("Scoreboard.Types.Skill.LevelUp_Time", 5); }
public boolean getPowerLevelTagsEnabled() { return config.getBoolean("Scoreboard.Power_Level_Tags", false); }
public boolean getAllowKeepBoard() { return config.getBoolean("Scoreboard.Allow_Keep", true); }
public boolean getScoreboardRainbows() { return config.getBoolean("Scoreboard.Rainbows", false); }
/* Database Purging */ /* Database Purging */
public int getPurgeInterval() { return config.getInt("Database_Purging.Purge_Interval", -1); } public int getPurgeInterval() { return config.getInt("Database_Purging.Purge_Interval", -1); }
@@ -303,7 +270,7 @@ public class Config extends AutoUpdateConfigLoader {
/* SMP Mods */ /* SMP Mods */
public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); } public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); }
public boolean getArmorModsEnabled() { return config.getBoolean("Mods.Armor_Mods_Enabled", false); } public boolean getArmorModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); }
public boolean getBlockModsEnabled() { return config.getBoolean("Mods.Block_Mods_Enabled", false); } public boolean getBlockModsEnabled() { return config.getBoolean("Mods.Block_Mods_Enabled", false); }
public boolean getEntityModsEnabled() { return config.getBoolean("Mods.Entity_Mods_Enabled", false); } public boolean getEntityModsEnabled() { return config.getBoolean("Mods.Entity_Mods_Enabled", false); }
@@ -361,7 +328,7 @@ public class Config extends AutoUpdateConfigLoader {
public int getMaxLength(AbilityType ability) { return config.getInt("Abilities.Max_Seconds." + ability.toString()); } public int getMaxLength(AbilityType ability) { return config.getInt("Abilities.Max_Seconds." + ability.toString()); }
/* Durability Settings */ /* Durability Settings */
public int getAbilityToolDamage() { return config.getInt("Abilities.Tools.Durability_Loss", 1); } public int getAbilityToolDamage() { return config.getInt("Abilities.Tools.Durability_Loss", 2); }
/* Thresholds */ /* Thresholds */
public int getTreeFellerThreshold() { return config.getInt("Abilities.Limits.Tree_Feller_Threshold", 500); } public int getTreeFellerThreshold() { return config.getInt("Abilities.Limits.Tree_Feller_Threshold", 500); }
@@ -422,9 +389,8 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getJungleDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Jungle", true); } public boolean getJungleDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Jungle", true); }
/* AFK Leveling */ /* AFK Leveling */
public boolean getAcrobaticsPreventAFK() { return config.getBoolean("Skills.Acrobatics.Prevent_AFK_Leveling", true); } public boolean getAcrobaticsAFKDisabled() { return config.getBoolean("Skills.Acrobatics.Prevent_AFK_Leveling", true); }
public int getAcrobaticsAFKMaxTries() { return config.getInt("Skills.Acrobatics.Max_Tries_At_Same_Location", 3); } public boolean getHerbalismAFKDisabled() { return config.getBoolean("Skills.Herbalism.Prevent_AFK_Leveling", true); }
public boolean getHerbalismPreventAFK() { return config.getBoolean("Skills.Herbalism.Prevent_AFK_Leveling", true); }
/* Level Caps */ /* Level Caps */
public int getPowerLevelCap() { public int getPowerLevelCap() {

View File

@@ -1,6 +1,11 @@
package com.gmail.nossr50.config; package com.gmail.nossr50.config;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List; import java.util.List;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@@ -11,7 +16,7 @@ import com.gmail.nossr50.mcMMO;
public abstract class ConfigLoader { public abstract class ConfigLoader {
protected static final mcMMO plugin = mcMMO.p; protected static final mcMMO plugin = mcMMO.p;
protected String fileName; protected String fileName;
private File configFile; protected File configFile;
protected FileConfiguration config; protected FileConfiguration config;
public ConfigLoader(String relativePath, String fileName) { public ConfigLoader(String relativePath, String fileName) {
@@ -29,13 +34,7 @@ public abstract class ConfigLoader {
protected void loadFile() { protected void loadFile() {
if (!configFile.exists()) { if (!configFile.exists()) {
plugin.debug("Creating mcMMO " + fileName + " File..."); plugin.debug("Creating mcMMO " + fileName + " File...");
createFile();
try {
plugin.saveResource(fileName, false); // Normal files
}
catch (IllegalArgumentException ex) {
plugin.saveResource(configFile.getParentFile().getName() + File.separator + fileName, false); // Mod files
}
} }
else { else {
plugin.debug("Loading mcMMO " + fileName + " File..."); plugin.debug("Loading mcMMO " + fileName + " File...");
@@ -46,6 +45,53 @@ public abstract class ConfigLoader {
protected abstract void loadKeys(); protected abstract void loadKeys();
protected void createFile() {
configFile.getParentFile().mkdirs();
InputStream inputStream = plugin.getResource(fileName);
if (inputStream == null) {
plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors");
return;
}
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(configFile);
int read;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if (outputStream != null) {
try {
outputStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
try {
inputStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
protected boolean validateKeys() { protected boolean validateKeys() {
return true; return true;
} }
@@ -72,19 +118,4 @@ public abstract class ConfigLoader {
public File getFile() { public File getFile() {
return configFile; return configFile;
} }
public void backup() {
plugin.getLogger().warning("You are using an old version of the " + fileName + " file.");
plugin.getLogger().warning("Your old file has been renamed to " + fileName + ".old and has been replaced by an updated version.");
configFile.renameTo(new File(configFile.getPath() + ".old"));
if (plugin.getResource(fileName) != null) {
plugin.saveResource(fileName, true);
}
plugin.getLogger().warning("Reloading " + fileName + " with new values...");
loadFile();
loadKeys();
}
} }

View File

@@ -9,7 +9,7 @@ import org.bukkit.entity.EntityType;
import com.gmail.nossr50.config.AutoUpdateConfigLoader; import com.gmail.nossr50.config.AutoUpdateConfigLoader;
import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.repair.repairables.RepairMaterialType; import com.gmail.nossr50.skills.repair.RepairMaterialType;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
public class ExperienceConfig extends AutoUpdateConfigLoader { public class ExperienceConfig extends AutoUpdateConfigLoader {
@@ -85,27 +85,11 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
reason.add("Experience.Combat.Multiplier.Wither_Skeleton should be at least 0!"); reason.add("Experience.Combat.Multiplier.Wither_Skeleton should be at least 0!");
} }
if (getDodgeXPModifier() < 0) {
reason.add("Skills.Acrobatics.Dodge_XP_Modifier should be at least 0!");
}
if (getRollXPModifier() < 0) {
reason.add("Skills.Acrobatics.Roll_XP_Modifier should be at least 0!");
}
if (getFallXPModifier() < 0) {
reason.add("Skills.Acrobatics.Fall_XP_Modifier should be at least 0!");
}
/* Fishing */ /* Fishing */
if (getFishingBaseXP() <= 0) { if (getFishingBaseXP() <= 0) {
reason.add("Experience.Fishing.Base should be greater than 0!"); reason.add("Experience.Fishing.Base should be greater than 0!");
} }
if (getFishingShakeXP() <= 0) {
reason.add("Experience.Fishing.Shake should be greater than 0!");
}
/* Repair */ /* Repair */
if (getRepairXPBase() <= 0) { if (getRepairXPBase() <= 0) {
reason.add("Experience.Repair.Base should be greater than 0!"); reason.add("Experience.Repair.Base should be greater than 0!");
@@ -192,16 +176,8 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
/* Materials */ /* Materials */
public int getXp(SkillType skill, Material material) { return config.getInt("Experience." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_")); } public int getXp(SkillType skill, Material material) { return config.getInt("Experience." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_")); }
/* Acrobatics */
public int getDodgeXPModifier() { return config.getInt("Experience.Acrobatics.Dodge", 120); }
public int getRollXPModifier() { return config.getInt("Experience.Acrobatics.Roll", 80); }
public int getFallXPModifier() { return config.getInt("Experience.Acrobatics.Fall", 120); }
public double getFeatherFallXPModifier() { return config.getDouble("Experience.Acrobatics.FeatherFall_Multiplier", 2.0); }
/* Fishing */ /* Fishing */
public int getFishingBaseXP() { return config.getInt("Experience.Fishing.Base", 800); } public int getFishingBaseXP() { return config.getInt("Experience.Fishing.Base", 800); }
public int getFishingShakeXP() { return config.getInt("Experience.Fishing.Shake", 50); }
/* Repair */ /* Repair */
public double getRepairXPBase() { return config.getDouble("Experience.Repair.Base", 1000.0); } public double getRepairXPBase() { return config.getDouble("Experience.Repair.Base", 1000.0); }

View File

@@ -10,16 +10,14 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.repairables.RepairItemType; import com.gmail.nossr50.skills.repair.RepairItemType;
import com.gmail.nossr50.skills.repair.repairables.RepairMaterialType; import com.gmail.nossr50.skills.repair.RepairMaterialType;
import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairableFactory; import com.gmail.nossr50.skills.repair.RepairableFactory;
public class CustomArmorConfig extends ConfigLoader { public class CustomArmorConfig extends ConfigLoader {
private static CustomArmorConfig instance; private static CustomArmorConfig instance;
private boolean needsUpdate = false;
private List<Repairable> repairables; private List<Repairable> repairables;
private List<Material> customBoots = new ArrayList<Material>(); private List<Material> customBoots = new ArrayList<Material>();
@@ -28,7 +26,7 @@ public class CustomArmorConfig extends ConfigLoader {
private List<Material> customLeggings = new ArrayList<Material>(); private List<Material> customLeggings = new ArrayList<Material>();
public CustomArmorConfig() { public CustomArmorConfig() {
super("mods", "armor.yml"); super("ModConfigs", "armor.yml");
loadKeys(); loadKeys();
} }
@@ -56,18 +54,9 @@ public class CustomArmorConfig extends ConfigLoader {
loadArmor("Chestplates", customChestplates); loadArmor("Chestplates", customChestplates);
loadArmor("Helmets", customHelmets); loadArmor("Helmets", customHelmets);
loadArmor("Leggings", customLeggings); loadArmor("Leggings", customLeggings);
if (needsUpdate) {
needsUpdate = false;
backup();
}
} }
private void loadArmor(String armorType, List<Material> materialList) { private void loadArmor(String armorType, List<Material> materialList) {
if (needsUpdate) {
return;
}
ConfigurationSection armorSection = config.getConfigurationSection(armorType); ConfigurationSection armorSection = config.getConfigurationSection(armorType);
if (armorSection == null) { if (armorSection == null) {
@@ -77,15 +66,10 @@ public class CustomArmorConfig extends ConfigLoader {
Set<String> armorConfigSet = armorSection.getKeys(false); Set<String> armorConfigSet = armorSection.getKeys(false);
for (String armorName : armorConfigSet) { for (String armorName : armorConfigSet) {
if (config.contains(armorType + "." + armorName + "." + ".ID")) {
needsUpdate = true;
return;
}
Material armorMaterial = Material.matchMaterial(armorName); Material armorMaterial = Material.matchMaterial(armorName);
if (armorMaterial == null) { if (armorMaterial == null) {
plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + armorName); plugin.getLogger().warning("Invalid material name. This item will be skipped.");
continue; continue;
} }
@@ -93,7 +77,7 @@ public class CustomArmorConfig extends ConfigLoader {
Material repairMaterial = Material.matchMaterial(config.getString(armorType + "." + armorName + ".Repair_Material", "")); Material repairMaterial = Material.matchMaterial(config.getString(armorType + "." + armorName + ".Repair_Material", ""));
if (repairMaterial == null) { if (repairMaterial == null) {
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable. - " + armorName); plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
repairable = false; repairable = false;
} }

View File

@@ -7,6 +7,7 @@ import java.util.Set;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
@@ -15,8 +16,6 @@ import com.gmail.nossr50.datatypes.mods.CustomBlock;
public class CustomBlockConfig extends ConfigLoader { public class CustomBlockConfig extends ConfigLoader {
private static CustomBlockConfig instance; private static CustomBlockConfig instance;
private boolean needsUpdate = false;
private List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>(); private List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>(); private List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customMiningBlocks = new ArrayList<MaterialData>(); private List<MaterialData> customMiningBlocks = new ArrayList<MaterialData>();
@@ -29,7 +28,7 @@ public class CustomBlockConfig extends ConfigLoader {
private HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>(); private HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>();
public CustomBlockConfig() { public CustomBlockConfig() {
super("mods", "blocks.yml"); super("ModConfigs", "blocks.yml");
loadKeys(); loadKeys();
} }
@@ -48,18 +47,9 @@ public class CustomBlockConfig extends ConfigLoader {
loadBlocks("Mining", customMiningBlocks); loadBlocks("Mining", customMiningBlocks);
loadBlocks("Woodcutting", customWoodcuttingBlocks); loadBlocks("Woodcutting", customWoodcuttingBlocks);
loadBlocks("Ability_Blocks", customAbilityBlocks); loadBlocks("Ability_Blocks", customAbilityBlocks);
if (needsUpdate) {
needsUpdate = false;
backup();
}
} }
private void loadBlocks(String skillType, List<MaterialData> blockList) { private void loadBlocks(String skillType, List<MaterialData> blockList) {
if (needsUpdate) {
return;
}
ConfigurationSection skillSection = config.getConfigurationSection(skillType); ConfigurationSection skillSection = config.getConfigurationSection(skillType);
if (skillSection == null) { if (skillSection == null) {
@@ -69,11 +59,6 @@ public class CustomBlockConfig extends ConfigLoader {
Set<String> skillConfigSet = skillSection.getKeys(false); Set<String> skillConfigSet = skillSection.getKeys(false);
for (String blockName : skillConfigSet) { for (String blockName : skillConfigSet) {
if (config.contains(skillType + "." + blockName + "." + ".Drop_Item")) {
needsUpdate = true;
return;
}
String[] blockInfo = blockName.split("[|]"); String[] blockInfo = blockName.split("[|]");
Material blockMaterial = Material.matchMaterial(blockInfo[0]); Material blockMaterial = Material.matchMaterial(blockInfo[0]);
@@ -93,6 +78,27 @@ public class CustomBlockConfig extends ConfigLoader {
int xp = config.getInt(skillType + "." + blockName + ".XP_Gain"); int xp = config.getInt(skillType + "." + blockName + ".XP_Gain");
boolean shouldDropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item");
Material dropMaterial = Material.matchMaterial(config.getString(skillType + "." + blockName + ".Drop_Item_Name"));
if (shouldDropItem && dropMaterial == null) {
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself. - " + blockInfo[0]);
shouldDropItem = false;
}
ItemStack itemDrop;
if (shouldDropItem) {
byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value");
itemDrop = (new MaterialData(dropMaterial, dropData)).toItemStack(1);
}
else {
itemDrop = blockMaterialData.toItemStack(1);
}
int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) { if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) {
customOres.add(blockMaterialData); customOres.add(blockMaterialData);
} }
@@ -106,7 +112,7 @@ public class CustomBlockConfig extends ConfigLoader {
} }
} }
customBlockMap.put(blockMaterialData, new CustomBlock(xp, config.getBoolean(skillType + "." + blockName + ".Double_Drops_Enabled"))); customBlockMap.put(blockMaterialData, new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, xp));
} }
} }

View File

@@ -18,7 +18,7 @@ public class CustomEntityConfig extends ConfigLoader {
private HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<String, CustomEntity>(); private HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<String, CustomEntity>();
public CustomEntityConfig() { public CustomEntityConfig() {
super("mods", "entities.yml"); super("ModConfigs", "entities.yml");
loadKeys(); loadKeys();
} }
@@ -32,11 +32,6 @@ public class CustomEntityConfig extends ConfigLoader {
@Override @Override
protected void loadKeys() { protected void loadKeys() {
if (config.getConfigurationSection("Hostile") != null) {
backup();
return;
}
for (String entityName : config.getKeys(false)) { for (String entityName : config.getKeys(false)) {
Class<?> clazz = null; Class<?> clazz = null;
String className = config.getString(entityName + ".Class", ""); String className = config.getString(entityName + ".Class", "");

View File

@@ -12,16 +12,13 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomTool; import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.repairables.RepairItemType; import com.gmail.nossr50.skills.repair.RepairItemType;
import com.gmail.nossr50.skills.repair.repairables.RepairMaterialType; import com.gmail.nossr50.skills.repair.RepairMaterialType;
import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairableFactory; import com.gmail.nossr50.skills.repair.RepairableFactory;
public class CustomToolConfig extends ConfigLoader { public class CustomToolConfig extends ConfigLoader {
private static CustomToolConfig instance; private static CustomToolConfig instance;
private boolean needsUpdate = false;
private List<Repairable> repairables; private List<Repairable> repairables;
private List<Material> customAxes = new ArrayList<Material>(); private List<Material> customAxes = new ArrayList<Material>();
@@ -34,7 +31,7 @@ public class CustomToolConfig extends ConfigLoader {
private HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>(); private HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
private CustomToolConfig() { private CustomToolConfig() {
super("mods", "tools.yml"); super("ModConfigs", "tools.yml");
loadKeys(); loadKeys();
} }
@@ -64,18 +61,9 @@ public class CustomToolConfig extends ConfigLoader {
loadTool("Pickaxes", customPickaxes); loadTool("Pickaxes", customPickaxes);
loadTool("Shovels", customShovels); loadTool("Shovels", customShovels);
loadTool("Swords", customSwords); loadTool("Swords", customSwords);
if (needsUpdate) {
needsUpdate = false;
backup();
}
} }
private void loadTool(String toolType, List<Material> materialList) { private void loadTool(String toolType, List<Material> materialList) {
if (needsUpdate) {
return;
}
ConfigurationSection toolSection = config.getConfigurationSection(toolType); ConfigurationSection toolSection = config.getConfigurationSection(toolType);
if (toolSection == null) { if (toolSection == null) {
@@ -85,11 +73,6 @@ public class CustomToolConfig extends ConfigLoader {
Set<String> toolConfigSet = toolSection.getKeys(false); Set<String> toolConfigSet = toolSection.getKeys(false);
for (String toolName : toolConfigSet) { for (String toolName : toolConfigSet) {
if (config.contains(toolType + "." + toolName + "." + ".ID")) {
needsUpdate = true;
return;
}
Material toolMaterial = Material.matchMaterial(toolName); Material toolMaterial = Material.matchMaterial(toolName);
if (toolMaterial == null) { if (toolMaterial == null) {

View File

@@ -0,0 +1,45 @@
package com.gmail.nossr50.config.tiers;
import org.bukkit.configuration.ConfigurationSection;
public class BlastMiningRank extends Rank {
private double blastDamageDecrease;
private double oreBonus;
private double debrisReduction;
private int dropMultiplier;
private double blastRadiusModifier;
public BlastMiningRank(int level, double blastDamageDecrease, double oreBonus, double debrisReduction, int dropMultiplier, double blastRadiusModifier) {
super(level);
this.blastDamageDecrease = blastDamageDecrease;
this.oreBonus = oreBonus;
this.debrisReduction = debrisReduction;
this.dropMultiplier = dropMultiplier;
this.blastRadiusModifier = blastRadiusModifier;
}
public BlastMiningRank(ConfigurationSection section) {
this(section.getInt("Level"), section.getDouble("BlastDamageDecrease"), section.getDouble("OreBonus"), section.getDouble("DebrisReduction"), section.getInt("DropMultiplier"), section.getDouble("BlastRadiusModifier"));
}
public double getBlastDamageDecrease() {
return blastDamageDecrease;
}
public double getOreBonus() {
return oreBonus;
}
public double getDebrisReduction() {
return debrisReduction;
}
public int getDropMultiplier() {
return dropMultiplier;
}
public double getBlastRadiusModifier() {
return blastRadiusModifier;
}
}

View File

@@ -0,0 +1,27 @@
package com.gmail.nossr50.config.tiers;
import org.bukkit.configuration.ConfigurationSection;
public class FishingRank extends Rank {
private double shakeChance;
private int xpBoost;
private FishingRank(int level, double shakeChance, int xpBoost) {
super(level);
this.shakeChance = shakeChance;
this.xpBoost = xpBoost;
}
public FishingRank(ConfigurationSection section) {
this(section.getInt("Level"), section.getDouble("ShakeChance"), section.getInt("VanillaXPBoost"));
}
public double getShakeChance() {
return shakeChance;
}
public int getXpBoost() {
return xpBoost;
}
}

View File

@@ -0,0 +1,13 @@
package com.gmail.nossr50.config.tiers;
public abstract class Rank {
private int level;
public Rank(int level) {
this.level = level;
}
public int getLevel() {
return level;
}
}

View File

@@ -0,0 +1,117 @@
package com.gmail.nossr50.config.tiers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.config.ConfigLoader;
public class RankLoader extends ConfigLoader {
private List<FishingRank> fishingRanks;
private List<SmeltingRank> smeltingRanks;
private List<BlastMiningRank> blastMiningRanks;
private List<RepairRank> repairRanks;
private static RankLoader instance;
private RankLoader() {
super("ranks.yml");
fishingRanks = new ArrayList<FishingRank>();
smeltingRanks = new ArrayList<SmeltingRank>();
blastMiningRanks = new ArrayList<BlastMiningRank>();
repairRanks = new ArrayList<RepairRank>();
loadKeys();
}
public static RankLoader getInstance() {
if (instance == null) {
instance = new RankLoader();
}
return instance;
}
@Override
protected void loadKeys() {
ConfigurationSection section = config.getConfigurationSection("Ranks.Fishing");
RankComparator rankComparator = new RankComparator();
for (String rank : section.getKeys(false)) {
fishingRanks.add(new FishingRank(section.getConfigurationSection(rank)));
}
Collections.sort(fishingRanks, rankComparator);
section = config.getConfigurationSection("Ranks.BlastMining");
for (String rank : section.getKeys(false)) {
blastMiningRanks.add(new BlastMiningRank(section.getConfigurationSection(rank)));
}
Collections.sort(blastMiningRanks, rankComparator);
section = config.getConfigurationSection("Ranks.Repair");
for (String rank : section.getKeys(false)) {
repairRanks.add(new RepairRank(section.getConfigurationSection(rank)));
}
Collections.sort(repairRanks, rankComparator);
section = config.getConfigurationSection("Ranks.Smelting");
for (String rank : section.getKeys(false)) {
smeltingRanks.add(new SmeltingRank(section.getConfigurationSection(rank)));
}
Collections.sort(smeltingRanks, rankComparator);
}
public FishingRank getFishingRank(int level) {
Iterator<FishingRank> it = fishingRanks.iterator();
while (it.hasNext()) {
FishingRank rank = it.next();
if (rank.getLevel() > level) {
return rank;
}
}
return null;
}
public RepairRank getRepairRank(int level) {
Iterator<RepairRank> it = repairRanks.iterator();
while (it.hasNext()) {
RepairRank rank = it.next();
if (rank.getLevel() > level) {
return rank;
}
}
return null;
}
public SmeltingRank getSmeltingRank(int level) {
Iterator<SmeltingRank> it = smeltingRanks.iterator();
while (it.hasNext()) {
SmeltingRank rank = it.next();
if (rank.getLevel() > level) {
return rank;
}
}
return null;
}
public BlastMiningRank getBlastMiningRank(int level) {
Iterator<BlastMiningRank> it = blastMiningRanks.iterator();
while (it.hasNext()) {
BlastMiningRank rank = it.next();
if (rank.getLevel() > level) {
return rank;
}
}
return null;
}
private class RankComparator implements Comparator<Rank> {
@Override
public int compare(Rank o1, Rank o2) {
return Integer.valueOf(o1.getLevel()).compareTo(Integer.valueOf(o2.getLevel()));
}
}
}

View File

@@ -0,0 +1,27 @@
package com.gmail.nossr50.config.tiers;
import org.bukkit.configuration.ConfigurationSection;
public class RepairRank extends Rank {
private double downgradeChance;
private double keepEnchantsChance;
public RepairRank(int level, double downgradeChance, double keepEnchantsChance) {
super(level);
this.downgradeChance = downgradeChance;
this.keepEnchantsChance = keepEnchantsChance;
}
public RepairRank(ConfigurationSection section) {
this(section.getInt("Level"), section.getDouble("DowngradeChance"), section.getDouble("KeepEnchantsChance"));
}
public double getDowngradeChance() {
return downgradeChance;
}
public double getKeepEnchantsChance() {
return keepEnchantsChance;
}
}

View File

@@ -0,0 +1,21 @@
package com.gmail.nossr50.config.tiers;
import org.bukkit.configuration.ConfigurationSection;
public class SmeltingRank extends Rank {
private int xpMultiplier;
public SmeltingRank(int level, int xpMultiplier) {
super(level);
this.xpMultiplier = xpMultiplier;
}
public SmeltingRank(ConfigurationSection section) {
this(section.getInt("Level"), section.getInt("VanillaXPMultiplier"));
}
public int getXpMultiplier() {
return xpMultiplier;
}
}

View File

@@ -1,13 +1,11 @@
package com.gmail.nossr50.config.treasure; package com.gmail.nossr50.config.treasure;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@@ -16,13 +14,10 @@ import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.datatypes.treasure.Rarity;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure; import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.util.EnchantmentUtils;
public class TreasureConfig extends ConfigLoader { public class TreasureConfig extends ConfigLoader {
private static TreasureConfig instance; private static TreasureConfig instance;
@@ -62,8 +57,7 @@ public class TreasureConfig extends ConfigLoader {
public List<ShakeTreasure> shakeFromWitch = new ArrayList<ShakeTreasure>(); public List<ShakeTreasure> shakeFromWitch = new ArrayList<ShakeTreasure>();
public List<ShakeTreasure> shakeFromZombie = new ArrayList<ShakeTreasure>(); public List<ShakeTreasure> shakeFromZombie = new ArrayList<ShakeTreasure>();
public HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<Rarity, List<FishingTreasure>>(); public List<FishingTreasure> fishingRewards = new ArrayList<FishingTreasure>();
public HashMap<Rarity, List<EnchantmentTreasure>> fishingEnchantments = new HashMap<Rarity, List<EnchantmentTreasure>>();
private TreasureConfig() { private TreasureConfig() {
super("treasures.yml"); super("treasures.yml");
@@ -81,14 +75,15 @@ public class TreasureConfig extends ConfigLoader {
@Override @Override
protected void loadKeys() { protected void loadKeys() {
if (config.getConfigurationSection("Treasures") != null) { if (config.getConfigurationSection("Treasures") != null) {
backup(); plugin.getLogger().warning("You are using an old version of the treasures.yml file.");
plugin.getLogger().warning("You should delete your current file and allow a new one to generate.");
plugin.getLogger().warning("Shake, Hylian Luck, Fishing, and Excavation will not work properly until you do.");
return; return;
} }
loadTreaures("Fishing"); loadTreaures("Fishing");
loadTreaures("Excavation"); loadTreaures("Excavation");
loadTreaures("Hylian_Luck"); loadTreaures("Hylian_Luck");
loadEnchantments();
for (EntityType entity : EntityType.values()) { for (EntityType entity : EntityType.values()) {
if (entity.isAlive()) { if (entity.isAlive()) {
@@ -109,13 +104,6 @@ public class TreasureConfig extends ConfigLoader {
return; return;
} }
// Initialize fishing HashMap
for (Rarity rarity : Rarity.values()) {
if (!fishingRewards.containsKey(rarity)) {
fishingRewards.put(rarity, (new ArrayList<FishingTreasure>()));
}
}
for (String treasureName : treasureSection.getKeys(false)) { for (String treasureName : treasureSection.getKeys(false)) {
// Validate all the things! // Validate all the things!
List<String> reason = new ArrayList<String>(); List<String> reason = new ArrayList<String>();
@@ -142,12 +130,12 @@ public class TreasureConfig extends ConfigLoader {
reason.add("Invalid material: " + treasureName); reason.add("Invalid material: " + treasureName);
} }
if (amount <= 0) { if (amount < 1) {
reason.add("Amount of " + treasureName + " must be greater than 0! " + amount); reason.add("Invalid amount: " + amount);
} }
if (material != null && material.isBlock() && (data > 127 || data < -128)) { if (material != null && material.isBlock() && (data > 127 || data < -128)) {
reason.add("Data of " + treasureName + " is invalid! " + data); reason.add("Invalid data: " + data);
} }
/* /*
@@ -159,27 +147,31 @@ public class TreasureConfig extends ConfigLoader {
int dropLevel = config.getInt(type + "." + treasureName + ".Drop_Level"); int dropLevel = config.getInt(type + "." + treasureName + ".Drop_Level");
if (xp < 0) { if (xp < 0) {
reason.add(treasureName + " has an invalid XP value: " + xp); reason.add("Invalid xp: " + xp);
} }
if (dropChance < 0.0D) { if (dropChance < 0.0D) {
reason.add(treasureName + " has an invalid Drop_Chance: " + dropChance); reason.add("Invalid Drop_Chance: " + dropChance);
} }
if (dropLevel < 0) { if (dropLevel < 0) {
reason.add(treasureName + " has an invalid Drop_Level: " + dropLevel); reason.add("Invalid Drop_Level: " + dropLevel);
} }
/* /*
* Specific Types * Specific Types
*/ */
Rarity rarity = null; int maxLevel = 0;
if (isFishing) { if (isFishing) {
rarity = Rarity.getRarity(config.getString(type + "." + treasureName + ".Rarity")); maxLevel = config.getInt(type + "." + treasureName + ".Max_Level");
if (rarity == null) { if (maxLevel < -1) {
reason.add("Invalid Rarity for item: " + treasureName); reason.add("Invalid Max_Level: " + maxLevel);
}
if (maxLevel != -1 && maxLevel < dropLevel) {
reason.add("Max_Level must be -1 or greater than Drop_Level!");
} }
} }
@@ -229,7 +221,7 @@ public class TreasureConfig extends ConfigLoader {
if (noErrorsInConfig(reason)) { if (noErrorsInConfig(reason)) {
if (isFishing) { if (isFishing) {
fishingRewards.get(rarity).add(new FishingTreasure(item, xp)); fishingRewards.add(new FishingTreasure(item, xp, dropChance, dropLevel, maxLevel));
} }
else if (isShake) { else if (isShake) {
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel); ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
@@ -353,37 +345,4 @@ public class TreasureConfig extends ConfigLoader {
} }
} }
} }
}
private void loadEnchantments() {
for (Rarity rarity : Rarity.values()) {
if (rarity == Rarity.TRAP || rarity == Rarity.RECORD) {
continue;
}
if (!fishingEnchantments.containsKey(rarity)) {
fishingEnchantments.put(rarity, (new ArrayList<EnchantmentTreasure>()));
}
ConfigurationSection enchantmentSection = config.getConfigurationSection("Enchantments_Rarity." + rarity.toString());
if (enchantmentSection == null) {
return;
}
for (String enchantmentName : enchantmentSection.getKeys(false)) {
int level = config.getInt("Enchantments_Rarity." + rarity.toString() + "." + enchantmentName);
Enchantment enchantment = EnchantmentUtils.getByName(enchantmentName);
if (enchantment == null) {
plugin.getLogger().warning("Skipping invalid enchantment in treasures.yml: " + enchantmentName);
continue;
}
fishingEnchantments.get(rarity).add(new EnchantmentTreasure(enchantment, level));
}
}
}
public double getItemDropRate(int tier, Rarity rarity) { return config.getDouble("Item_Drop_Rates.Tier_" + tier + "." + rarity.toString()); }
public double getEnchantmentDropRate(int tier, Rarity rarity) { return config.getDouble("Enchantment_Drop_Rates.Tier_" + tier + "." + rarity.toString()); }
}

View File

@@ -7,13 +7,10 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.database.DatabaseType; import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType;
public interface DatabaseManager { public interface DatabaseManager {
// One month in milliseconds // One month in milliseconds
public final long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff(); public final long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
// During convertUsers, how often to output a status
public final int progressInterval = 200;
/** /**
* Purge users with 0 power level from the database. * Purge users with 0 power level from the database.
@@ -37,9 +34,8 @@ public interface DatabaseManager {
* Save a user to the database. * Save a user to the database.
* *
* @param profile The profile of the player to save * @param profile The profile of the player to save
* @return true if successful, false on failure
*/ */
public boolean saveUser(PlayerProfile profile); public void saveUser(PlayerProfile profile);
/** /**
* Retrieve leaderboard info. * Retrieve leaderboard info.
@@ -49,18 +45,15 @@ public interface DatabaseManager {
* @param statsPerPage The number of stats per page * @param statsPerPage The number of stats per page
* @return the requested leaderboard information * @return the requested leaderboard information
*/ */
public List<PlayerStat> readLeaderboard(SkillType skill, int pageNumber, int statsPerPage); public List<PlayerStat> readLeaderboard(String skillName, int pageNumber, int statsPerPage);
/** /**
* Retrieve rank info into a HashMap from SkillType to the rank. * Retrieve rank info.
* <p>
* The special value <code>null</code> is used to represent the Power
* Level rank (the combination of all skill levels).
* *
* @param playerName The name of the user to retrieve the rankings for * @param playerName The name of the user to retrieve the rankings for
* @return the requested rank information * @return the requested rank information
*/ */
public Map<SkillType, Integer> readRank(String playerName); public Map<String, Integer> readRank(String playerName);
/** /**
* Add a new user to the database. * Add a new user to the database.

View File

@@ -10,7 +10,7 @@ public class DatabaseManagerFactory {
public static DatabaseManager getDatabaseManager() { public static DatabaseManager getDatabaseManager() {
if (customManager != null) { if (customManager != null) {
try { try {
return createDefaultCustomDatabaseManager(); return createCustomDatabaseManager(customManager);
} }
catch (Exception e) { catch (Exception e) {
mcMMO.p.debug("Could not create custom database manager"); mcMMO.p.debug("Could not create custom database manager");
@@ -29,18 +29,17 @@ public class DatabaseManagerFactory {
/** /**
* Sets the custom DatabaseManager class for mcMMO to use. This should be * Sets the custom DatabaseManager class for mcMMO to use. This should be
* called prior to mcMMO enabling. * called prior to mcMMO enabling.
* <p/> * <p>
* The provided class must have an empty constructor, which is the one * The provided class must have an empty constructor, which is the one
* that will be used. * that will be used.
* <p/> * <p>
* This method is intended for API use, but it should not be considered * This method is intended for API use, but it should not be considered
* stable. This method is subject to change and/or removal in future * stable. This method is subject to change and/or removal in future
* versions. * versions.
* *
* @param clazz the DatabaseManager class to use * @param clazz the DatabaseManager class to use
*
* @throws IllegalArgumentException if the provided class does not have * @throws IllegalArgumentException if the provided class does not have
* an empty constructor * an empty constructor
*/ */
public static void setCustomDatabaseManagerClass(Class<? extends DatabaseManager> clazz) { public static void setCustomDatabaseManagerClass(Class<? extends DatabaseManager> clazz) {
try { try {
@@ -64,24 +63,13 @@ public class DatabaseManagerFactory {
case SQL: case SQL:
return new SQLDatabaseManager(); return new SQLDatabaseManager();
case CUSTOM:
try {
return createDefaultCustomDatabaseManager();
}
catch (Throwable e) {
e.printStackTrace();
}
default: default:
return null; return null;
} }
} }
public static DatabaseManager createDefaultCustomDatabaseManager() throws Throwable { //TODO: Why is clazz never used here?
return customManager.getConstructor((Class<?>) null).newInstance((Object[]) null);
}
public static DatabaseManager createCustomDatabaseManager(Class<? extends DatabaseManager> clazz) throws Throwable { public static DatabaseManager createCustomDatabaseManager(Class<? extends DatabaseManager> clazz) throws Throwable {
return clazz.getConstructor((Class<?>) null).newInstance((Object[]) null); return customManager.getConstructor((Class<?>) clazz).newInstance((Object[]) null);
} }
} }

View File

@@ -15,6 +15,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
@@ -121,10 +122,9 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
try { try {
lastPlayed = Long.parseLong(character[37]) * Misc.TIME_CONVERSION_FACTOR; lastPlayed = Long.parseLong(character[37]) * Misc.TIME_CONVERSION_FACTOR;
} }
catch (NumberFormatException e) { catch (NumberFormatException e) {}
}
if (lastPlayed == 0) { if (lastPlayed == 0) {
OfflinePlayer player = mcMMO.p.getServer().getOfflinePlayer(name); OfflinePlayer player = Bukkit.getOfflinePlayer(name);
lastPlayed = player.getLastPlayed(); lastPlayed = player.getLastPlayed();
rewrite = true; rewrite = true;
} }
@@ -203,7 +203,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
return worked; return worked;
} }
public boolean saveUser(PlayerProfile profile) { public void saveUser(PlayerProfile profile) {
String playerName = profile.getPlayerName(); String playerName = profile.getPlayerName();
BufferedReader in = null; BufferedReader in = null;
@@ -272,11 +272,9 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
// Write the new file // Write the new file
out = new FileWriter(usersFilePath); out = new FileWriter(usersFilePath);
out.write(writer.toString()); out.write(writer.toString());
return true;
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false;
} }
finally { finally {
tryClose(in); tryClose(in);
@@ -285,24 +283,24 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
} }
} }
public List<PlayerStat> readLeaderboard(SkillType skill, int pageNumber, int statsPerPage) { public List<PlayerStat> readLeaderboard(String skillName, int pageNumber, int statsPerPage) {
updateLeaderboards(); updateLeaderboards();
List<PlayerStat> statsList = skill == null ? powerLevels : playerStatHash.get(skill); List<PlayerStat> statsList = skillName.equalsIgnoreCase("all") ? powerLevels : playerStatHash.get(SkillType.getSkill(skillName));
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage; int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size())); return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size()));
} }
public Map<SkillType, Integer> readRank(String playerName) { public Map<String, Integer> readRank(String playerName) {
updateLeaderboards(); updateLeaderboards();
Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); Map<String, Integer> skills = new HashMap<String, Integer>();
for (SkillType skill : SkillType.NON_CHILD_SKILLS) { for (SkillType skill : SkillType.nonChildSkills()) {
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill))); skills.put(skill.name(), getPlayerRank(playerName, playerStatHash.get(skill)));
} }
skills.put(null, getPlayerRank(playerName, powerLevels)); skills.put("ALL", getPlayerRank(playerName, powerLevels));
return skills; return skills;
} }
@@ -387,41 +385,28 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
} }
PlayerProfile p = loadFromLine(character); PlayerProfile p = loadFromLine(character);
in.close();
return p; return p;
} }
// Didn't find the player, create a new one
if (create) {
newUser(playerName);
return new PlayerProfile(playerName, true);
}
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
finally { finally {
// I have no idea why it's necessary to inline tryClose() here, but it removes tryClose(in);
// a resource leak warning, and I'm trusting the compiler on this one.
if (in != null) {
try {
in.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
} }
} }
// Return unloaded profile if (create) {
newUser(playerName);
return new PlayerProfile(playerName, true);
}
return new PlayerProfile(playerName); return new PlayerProfile(playerName);
} }
public void convertUsers(DatabaseManager destination) { public void convertUsers(DatabaseManager destination) {
BufferedReader in = null; BufferedReader in = null;
String usersFilePath = mcMMO.getUsersFilePath(); String usersFilePath = mcMMO.getUsersFilePath();
int convertedUsers = 0;
long startMillis = System.currentTimeMillis();
synchronized (fileWritingLock) { synchronized (fileWritingLock) {
try { try {
@@ -438,8 +423,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
convertedUsers++;
Misc.printProgress(convertedUsers, progressInterval, startMillis);
} }
} }
catch (Exception e) { catch (Exception e) {
@@ -451,6 +434,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
} }
} }
public boolean checkConnected() {
// Not implemented
return true;
}
public List<String> getStoredUsers() { public List<String> getStoredUsers() {
ArrayList<String> users = new ArrayList<String>(); ArrayList<String> users = new ArrayList<String>();
BufferedReader in = null; BufferedReader in = null;
@@ -505,7 +493,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
List<PlayerStat> fishing = new ArrayList<PlayerStat>(); List<PlayerStat> fishing = new ArrayList<PlayerStat>();
BufferedReader in = null; BufferedReader in = null;
String playerName = null;
// Read from the FlatFile database and fill our arrays with information // Read from the FlatFile database and fill our arrays with information
synchronized (fileWritingLock) { synchronized (fileWritingLock) {
try { try {
@@ -514,7 +501,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
String[] data = line.split(":"); String[] data = line.split(":");
playerName = data[0]; String playerName = data[0];
int powerLevel = 0; int powerLevel = 0;
Map<SkillType, Integer> skills = getSkillMapFromLine(data); Map<SkillType, Integer> skills = getSkillMapFromLine(data);
@@ -536,7 +523,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
} }
} }
catch (Exception e) { catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " during user " + playerName + " (Are you sure you formatted it correctly?) " + e.toString()); mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
} }
finally { finally {
tryClose(in); tryClose(in);

View File

@@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@@ -22,7 +23,6 @@ import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.runnables.database.SQLDatabaseKeepaliveTask;
import com.gmail.nossr50.runnables.database.SQLReconnectTask; import com.gmail.nossr50.runnables.database.SQLReconnectTask;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@@ -51,8 +51,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
protected SQLDatabaseManager() { protected SQLDatabaseManager() {
checkStructure(); checkStructure();
new SQLDatabaseKeepaliveTask(this).runTaskTimerAsynchronously(mcMMO.p, 10, 60L * 60 * Misc.TICK_CONVERSION_FACTOR);
} }
public void purgePowerlessUsers() { public void purgePowerlessUsers() {
@@ -94,7 +92,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
"WHERE ((" + currentTime + " - lastlogin * " + Misc.TIME_CONVERSION_FACTOR + ") > " + PURGE_TIME + ")"); "WHERE ((" + currentTime + " - lastlogin * " + Misc.TIME_CONVERSION_FACTOR + ") > " + PURGE_TIME + ")");
processPurge(usernames); processPurge(usernames);
mcMMO.p.getLogger().info("Purged " + usernames.size() + " users from the database."); mcMMO.p.getLogger().info("Purged " + usernames.size() + " users from the database.");;
} }
public boolean removeUser(String playerName) { public boolean removeUser(String playerName) {
@@ -115,9 +113,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
return success; return success;
} }
public boolean saveUser(PlayerProfile profile) { public void saveUser(PlayerProfile profile) {
if (!checkConnected()) { if (!checkConnected()) {
return false; return;
} }
int userId = readId(profile.getPlayerName()); int userId = readId(profile.getPlayerName());
@@ -125,15 +123,15 @@ public final class SQLDatabaseManager implements DatabaseManager {
newUser(profile.getPlayerName()); newUser(profile.getPlayerName());
userId = readId(profile.getPlayerName()); userId = readId(profile.getPlayerName());
if (userId == -1) { if (userId == -1) {
return false; mcMMO.p.getLogger().log(Level.WARNING, "Failed to save user " + profile.getPlayerName());
return;
} }
} }
boolean success = true;
MobHealthbarType mobHealthbarType = profile.getMobHealthbarType(); MobHealthbarType mobHealthbarType = profile.getMobHealthbarType();
success &= saveLogin(userId, ((int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR))); saveLogin(userId, ((int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)));
success &= saveHuds(userId, (mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString())); saveHuds(userId, (mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()));
success &= saveLongs( saveLongs(
"UPDATE " + tablePrefix + "cooldowns SET " "UPDATE " + tablePrefix + "cooldowns SET "
+ " mining = ?, woodcutting = ?, unarmed = ?" + " mining = ?, woodcutting = ?, unarmed = ?"
+ ", herbalism = ?, excavation = ?, swords = ?" + ", herbalism = ?, excavation = ?, swords = ?"
@@ -147,7 +145,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
profile.getSkillDATS(AbilityType.SERRATED_STRIKES), profile.getSkillDATS(AbilityType.SERRATED_STRIKES),
profile.getSkillDATS(AbilityType.SKULL_SPLITTER), profile.getSkillDATS(AbilityType.SKULL_SPLITTER),
profile.getSkillDATS(AbilityType.BLAST_MINING)); profile.getSkillDATS(AbilityType.BLAST_MINING));
success &= saveIntegers( saveIntegers(
"UPDATE " + tablePrefix + "skills SET " "UPDATE " + tablePrefix + "skills SET "
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?" + " taming = ?, mining = ?, repair = ?, woodcutting = ?"
+ ", unarmed = ?, herbalism = ?, excavation = ?" + ", unarmed = ?, herbalism = ?, excavation = ?"
@@ -166,7 +164,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
profile.getSkillLevel(SkillType.ACROBATICS), profile.getSkillLevel(SkillType.ACROBATICS),
profile.getSkillLevel(SkillType.FISHING), profile.getSkillLevel(SkillType.FISHING),
userId); userId);
success &= saveIntegers( saveIntegers(
"UPDATE " + tablePrefix + "experience SET " "UPDATE " + tablePrefix + "experience SET "
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?" + " taming = ?, mining = ?, repair = ?, woodcutting = ?"
+ ", unarmed = ?, herbalism = ?, excavation = ?" + ", unarmed = ?, herbalism = ?, excavation = ?"
@@ -185,14 +183,13 @@ public final class SQLDatabaseManager implements DatabaseManager {
profile.getSkillXpLevel(SkillType.ACROBATICS), profile.getSkillXpLevel(SkillType.ACROBATICS),
profile.getSkillXpLevel(SkillType.FISHING), profile.getSkillXpLevel(SkillType.FISHING),
userId); userId);
return success;
} }
public List<PlayerStat> readLeaderboard(SkillType skill, int pageNumber, int statsPerPage) { public List<PlayerStat> readLeaderboard(String skillName, int pageNumber, int statsPerPage) {
List<PlayerStat> stats = new ArrayList<PlayerStat>(); List<PlayerStat> stats = new ArrayList<PlayerStat>();
if (checkConnected()) { if (checkConnected()) {
String query = skill == null ? "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing" : skill.name().toLowerCase(); String query = skillName.equalsIgnoreCase("ALL") ? "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing" : skillName;
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement statement = null; PreparedStatement statement = null;
@@ -230,14 +227,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
return stats; return stats;
} }
public Map<SkillType, Integer> readRank(String playerName) { public Map<String, Integer> readRank(String playerName) {
Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); Map<String, Integer> skills = new HashMap<String, Integer>();
if (checkConnected()) { if (checkConnected()) {
ResultSet resultSet; ResultSet resultSet;
try { try {
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) { for (SkillType skillType : SkillType.nonChildSkills()) {
String skillName = skillType.name().toLowerCase(); String skillName = skillType.name().toLowerCase();
String sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " + String sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " +
"AND " + skillName + " > (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " + "AND " + skillName + " > (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +
@@ -262,7 +259,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
while (resultSet.next()) { while (resultSet.next()) {
if (resultSet.getString("user").equalsIgnoreCase(playerName)) { if (resultSet.getString("user").equalsIgnoreCase(playerName)) {
skills.put(skillType, rank + resultSet.getRow()); skills.put(skillType.name(), rank + resultSet.getRow());
break; break;
} }
} }
@@ -299,7 +296,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
while (resultSet.next()) { while (resultSet.next()) {
if (resultSet.getString("user").equalsIgnoreCase(playerName)) { if (resultSet.getString("user").equalsIgnoreCase(playerName)) {
skills.put(null, rank + resultSet.getRow()); skills.put("ALL", rank + resultSet.getRow());
break; break;
} }
} }
@@ -346,10 +343,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
public PlayerProfile loadPlayerProfile(String playerName, boolean create) { public PlayerProfile loadPlayerProfile(String playerName, boolean create) {
return loadPlayerProfile(playerName, create, true);
}
private PlayerProfile loadPlayerProfile(String playerName, boolean create, boolean retry) {
if (!checkConnected()) { if (!checkConnected()) {
return new PlayerProfile(playerName, false); // return fake profile if not connected return new PlayerProfile(playerName, false); // return fake profile if not connected
} }
@@ -379,8 +372,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
result.close(); result.close();
return ret; return ret;
} }
catch (SQLException e) { catch (SQLException e) {}
}
} }
result.close(); result.close();
} }
@@ -400,11 +392,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
// Problem, nothing was returned // Problem, nothing was returned
// Quit if this is second time around
if (!retry) {
return new PlayerProfile(playerName, false);
}
// First, read User Id - this is to check for orphans // First, read User Id - this is to check for orphans
int id = readId(playerName); int id = readId(playerName);
@@ -413,16 +400,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
// There is no such user // There is no such user
if (create) { if (create) {
newUser(playerName); newUser(playerName);
return loadPlayerProfile(playerName, false, false);
} }
// Return unloaded profile if can't create return new PlayerProfile(playerName, create);
return new PlayerProfile(playerName, false);
} }
// There is such a user // There is such a user
writeMissingRows(id); writeMissingRows(id);
// Retry, and abort on re-failure // Retry, and abort on re-failure
return loadPlayerProfile(playerName, create, false); return loadPlayerProfile(playerName, false);
} }
public void convertUsers(DatabaseManager destination) { public void convertUsers(DatabaseManager destination) {
@@ -447,8 +432,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
+ "WHERE u.user = ?"); + "WHERE u.user = ?");
List<String> usernames = getStoredUsers(); List<String> usernames = getStoredUsers();
ResultSet result = null; ResultSet result = null;
int convertedUsers = 0;
long startMillis = System.currentTimeMillis();
for (String playerName : usernames) { for (String playerName : usernames) {
statement.setString(1, playerName); statement.setString(1, playerName);
try { try {
@@ -460,8 +443,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
catch (SQLException e) { catch (SQLException e) {
// Ignore // Ignore
} }
convertedUsers++;
Misc.printProgress(convertedUsers, progressInterval, startMillis);
} }
} }
catch (SQLException e) { catch (SQLException e) {
@@ -471,15 +452,13 @@ public final class SQLDatabaseManager implements DatabaseManager {
if (statement != null) { if (statement != null) {
try { try {
statement.close(); statement.close();
} } catch (SQLException e) {
catch (SQLException e) {
// Ignore // Ignore
} }
} }
} }
} }
/** /**
* Check connection status and re-establish if dead or stale. * Check connection status and re-establish if dead or stale.
* *
@@ -590,8 +569,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
if (stmt != null) { if (stmt != null) {
try { try {
stmt.close(); stmt.close();
} } catch (SQLException e) {
catch (SQLException e) {
// Ignore // Ignore
} }
} }
@@ -1042,7 +1020,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
private boolean saveIntegers(String sql, int... args) { private void saveIntegers(String sql, int... args) {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
@@ -1054,11 +1032,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
statement.execute(); statement.execute();
return true;
} }
catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
return false;
} }
finally { finally {
if (statement != null) { if (statement != null) {
@@ -1072,7 +1048,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
private boolean saveLongs(String sql, int id, long... args) { private void saveLongs(String sql, int id, long... args) {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
@@ -1085,11 +1061,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
statement.setInt(i++, id); statement.setInt(i++, id);
statement.execute(); statement.execute();
return true;
} }
catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
return false;
} }
finally { finally {
if (statement != null) { if (statement != null) {
@@ -1124,7 +1098,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
return id; return id;
} }
private boolean saveLogin(int id, long login) { private void saveLogin(int id, long login) {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
@@ -1132,11 +1106,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
statement.setLong(1, login); statement.setLong(1, login);
statement.setInt(2, id); statement.setInt(2, id);
statement.execute(); statement.execute();
return true;
} }
catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
return false;
} }
finally { finally {
if (statement != null) { if (statement != null) {
@@ -1150,7 +1122,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
private boolean saveHuds(int userId, String mobHealthBar) { private void saveHuds(int userId, String mobHealthBar) {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
@@ -1158,11 +1130,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
statement.setString(1, mobHealthBar); statement.setString(1, mobHealthBar);
statement.setInt(2, userId); statement.setInt(2, userId);
statement.execute(); statement.execute();
return true;
} }
catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
return false;
} }
finally { finally {
if (statement != null) { if (statement != null) {

View File

@@ -1,19 +1,33 @@
package com.gmail.nossr50.datatypes.mods; package com.gmail.nossr50.datatypes.mods;
import org.bukkit.inventory.ItemStack;
public class CustomBlock { public class CustomBlock {
private int xpGain; private int xpGain;
private boolean canDoubleDrop; private ItemStack itemDrop;
private int minimumDropAmount;
private int maximumDropAmount;
public CustomBlock(int xpGain, boolean canDoubleDrop) { public CustomBlock(int minimumDropAmount, int maximumDropAmount, ItemStack itemDrop, int xpGain) {
this.xpGain = xpGain; this.xpGain = xpGain;
this.canDoubleDrop = canDoubleDrop; this.itemDrop = itemDrop;
this.minimumDropAmount = minimumDropAmount;
this.maximumDropAmount = maximumDropAmount;
} }
public int getXpGain() { public int getXpGain() {
return xpGain; return xpGain;
} }
public boolean isDoubleDropEnabled() { public ItemStack getItemDrop() {
return canDoubleDrop; return itemDrop;
}
public int getMinimumDropAmount() {
return minimumDropAmount;
}
public int getMaximumDropAmount() {
return maximumDropAmount;
} }
} }

View File

@@ -7,14 +7,9 @@ import java.util.Set;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.mods.CustomTool; import com.gmail.nossr50.datatypes.mods.CustomTool;
@@ -22,11 +17,11 @@ import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.runnables.skills.AbilityDisableTask; import com.gmail.nossr50.runnables.skills.AbilityDisableTask;
import com.gmail.nossr50.runnables.skills.ToolLowerTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.ArcheryManager; import com.gmail.nossr50.skills.archery.ArcheryManager;
@@ -43,12 +38,9 @@ import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager; import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils; import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.skills.PerksUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
@@ -86,8 +78,6 @@ public class McMMOPlayer {
private int lastSalvageClick; private int lastSalvageClick;
private boolean godMode; private boolean godMode;
private Location hookLocation;
private final Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>(); private final Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
private final Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>(); private final Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>();
@@ -97,7 +87,6 @@ public class McMMOPlayer {
private int recentlyHurt; private int recentlyHurt;
private int respawnATS; private int respawnATS;
private int teleportATS; private int teleportATS;
private long databaseATS;
private int chimeraWingLastUse; private int chimeraWingLastUse;
private Location teleportCommence; private Location teleportCommence;
@@ -134,69 +123,6 @@ public class McMMOPlayer {
toolMode.put(toolType, false); toolMode.put(toolType, false);
toolATS.put(toolType, 0); toolATS.put(toolType, 0);
} }
if (!profile.isLoaded()) {
mcMMO.p.getLogger().warning("Unable to load the PlayerProfile for " + playerName + ". Will retry over the next several seconds.");
new RetryProfileLoadingTask().runTaskTimerAsynchronously(mcMMO.p, 11L, 31L);
}
}
private class RetryProfileLoadingTask extends BukkitRunnable {
private static final int MAX_TRIES = 5;
private final String playerName = McMMOPlayer.this.player.getName();
private int attempt = 0;
// WARNING: ASYNC TASK
// DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE
@Override
public void run() {
// Quit if they logged out
if (!player.isOnline()) {
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + playerName + " - player logged out");
this.cancel();
return;
}
// Send the message that we're doing the recovery
if (attempt == 0) {
player.sendMessage(LocaleLoader.getString("Recovery.Notice"));
}
// Increment attempt counter and try
attempt++;
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, true);
// If successful, schedule the apply
if (profile.isLoaded()) {
new ApplySuccessfulProfile(profile).runTask(mcMMO.p);
player.sendMessage(LocaleLoader.getString("Recovery.Success"));
this.cancel();
return;
}
// If we've failed five times, give up
if (attempt >= MAX_TRIES) {
mcMMO.p.getLogger().severe("Giving up on attempting to load the PlayerProfile for " + playerName);
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Recovery.AdminFailureNotice", playerName), Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
player.sendMessage(LocaleLoader.getString("Recovery.Failure").split("\n"));
this.cancel();
return;
}
}
}
private class ApplySuccessfulProfile extends BukkitRunnable {
private final PlayerProfile profile;
private ApplySuccessfulProfile(PlayerProfile profile) {
this.profile = profile;
}
// Synchronized task
// No database access permitted
@Override
public void run() {
McMMOPlayer.this.profile = profile;
}
} }
public AcrobaticsManager getAcrobaticsManager() { public AcrobaticsManager getAcrobaticsManager() {
@@ -428,14 +354,6 @@ public class McMMOPlayer {
teleportATS = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); teleportATS = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
} }
public long getDatabaseATS() {
return databaseATS;
}
public void actualizeDatabaseATS() {
databaseATS = System.currentTimeMillis();
}
/* /*
* Repair Anvil Placement * Repair Anvil Placement
*/ */
@@ -510,18 +428,6 @@ public class McMMOPlayer {
godMode = !godMode; godMode = !godMode;
} }
/*
* Fishing: Master Angler
*/
public Location getHookLocation() {
return hookLocation;
}
public void setHookLocation(Location hookLocation) {
this.hookLocation = hookLocation;
}
/* /*
* Skill notifications * Skill notifications
*/ */
@@ -542,8 +448,8 @@ public class McMMOPlayer {
public int getPowerLevel() { public int getPowerLevel() {
int powerLevel = 0; int powerLevel = 0;
for (SkillType type : SkillType.NON_CHILD_SKILLS) { for (SkillType type : SkillType.nonChildSkills()) {
if (type.getPermissions(player)) { if (Permissions.skillEnabled(player, type)) {
powerLevel += profile.getSkillLevel(type); powerLevel += profile.getSkillLevel(type);
} }
} }
@@ -566,7 +472,7 @@ public class McMMOPlayer {
Set<SkillType> parentSkills = FamilyTree.getParents(skillType); Set<SkillType> parentSkills = FamilyTree.getParents(skillType);
for (SkillType parentSkill : parentSkills) { for (SkillType parentSkill : parentSkills) {
if (parentSkill.getPermissions(player)) { if (Permissions.skillEnabled(player, parentSkill)) {
beginXpGain(parentSkill, xp / parentSkills.size()); beginXpGain(parentSkill, xp / parentSkills.size());
} }
} }
@@ -601,7 +507,7 @@ public class McMMOPlayer {
* @param xp Experience amount to add * @param xp Experience amount to add
*/ */
public void applyXpGain(SkillType skillType, float xp) { public void applyXpGain(SkillType skillType, float xp) {
if (!skillType.getPermissions(player)) { if (!Permissions.skillEnabled(player, skillType)) {
return; return;
} }
@@ -615,45 +521,17 @@ public class McMMOPlayer {
return; return;
} }
if (!EventUtils.handleXpGainEvent(player, skillType, xp)) { McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skillType, xp);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return; return;
} }
profile.setSkillXpLevel(skillType, profile.getSkillXpLevelRaw(skillType) + event.getRawXpGained());
isUsingUnarmed = (skillType == SkillType.UNARMED); isUsingUnarmed = (skillType == SkillType.UNARMED);
checkXp(skillType); SkillUtils.xpCheckSkill(skillType, player, profile);
}
/**
* Check the XP of a skill.
*
* @param skillType The skill to check
*/
private void checkXp(SkillType skillType) {
int levelsGained = 0;
float xpRemoved = 0;
if (profile.getSkillXpLevelRaw(skillType) >= profile.getXpToLevel(skillType)) {
while (profile.getSkillXpLevelRaw(skillType) >= profile.getXpToLevel(skillType)) {
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Config.getInstance().getPowerLevelCap() >= getPowerLevel() + 1)) {
int xp = profile.getXpToLevel(skillType);
xpRemoved += xp;
profile.removeXp(skillType, xp);
levelsGained++;
profile.skillUp(skillType, 1);
}
else {
profile.addLevels(skillType, 0); // This seems kinda pointless... why do we have this again?
}
}
if (!EventUtils.handleLevelChangeEvent(player, skillType, levelsGained, xpRemoved, true)) {
return;
}
player.playSound(player.getLocation(), Sound.LEVEL_UP, Misc.LEVELUP_VOLUME, Misc.LEVELUP_PITCH);
player.sendMessage(LocaleLoader.getString(StringUtils.getCapitalized(skillType.toString()) + ".Skillup", levelsGained, profile.getSkillLevel(skillType)));
}
} }
/* /*
@@ -838,119 +716,4 @@ public class McMMOPlayer {
player.sendMessage(LocaleLoader.getString("Party.Forbidden")); player.sendMessage(LocaleLoader.getString("Party.Forbidden"));
} }
} }
/**
* Check to see if an ability can be activated.
*
* @param skill The skill the ability is based on
*/
public void checkAbilityActivation(SkillType skill) {
ToolType tool = skill.getTool();
AbilityType ability = skill.getAbility();
setToolPreparationMode(tool, false);
if (getAbilityMode(ability)) {
return;
}
int timeRemaining = calculateTimeRemaining(ability);
if (timeRemaining > 0) {
/*
* Axes and Woodcutting are odd because they share the same tool.
* We show them the too tired message when they take action.
*/
if (skill == SkillType.WOODCUTTING || skill == SkillType.AXES) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
}
return;
}
if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) {
return;
}
int ticks = PerksUtils.handleActivationPerks(player, 2 + (profile.getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxLength());
// Notify people that ability has been activated
ParticleEffectUtils.playAbilityEnabledEffect(player);
if (useChatNotifications()) {
player.sendMessage(ability.getAbilityOn());
}
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player));
// Enable the ability
profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
setAbilityMode(ability, true);
if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
SkillUtils.handleAbilitySpeedIncrease(player);
}
new AbilityDisableTask(this, ability).runTaskLater(mcMMO.p, ticks * Misc.TICK_CONVERSION_FACTOR);
}
public void processAbilityActivation(SkillType skill) {
if (Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && !player.isSneaking()) {
return;
}
ItemStack inHand = player.getItemInHand();
if (ModUtils.isCustomTool(inHand) && !ModUtils.getToolFromItemStack(inHand).isAbilityEnabled()) {
return;
}
if (!getAbilityUse()) {
return;
}
for (AbilityType abilityType : AbilityType.values()) {
if (getAbilityMode(abilityType)) {
return;
}
}
AbilityType ability = skill.getAbility();
ToolType tool = skill.getTool();
/*
* Woodcutting & Axes need to be treated differently.
* Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action
*/
if (ability.getPermissions(player) && tool.inHand(inHand) && !getToolPreparationMode(tool)) {
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
int timeRemaining = calculateTimeRemaining(ability);
if (!getAbilityMode(ability) && timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
return;
}
}
if (Config.getInstance().getAbilityMessagesEnabled()) {
player.sendMessage(tool.getRaiseTool());
}
setToolPreparationATS(tool, System.currentTimeMillis());
setToolPreparationMode(tool, true);
new ToolLowerTask(this, tool).runTaskLaterAsynchronously(mcMMO.p, 4 * Misc.TICK_CONVERSION_FACTOR);
}
}
/**
* Calculate the time remaining until the ability's cooldown expires.
*
* @param ability AbilityType whose cooldown to check
*
* @return the number of seconds remaining before the cooldown expires
*/
public int calculateTimeRemaining(AbilityType ability) {
long deactivatedTimestamp = profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR;
return (int) (((deactivatedTimestamp + (PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
}
} }

View File

@@ -39,7 +39,7 @@ public class PlayerProfile {
skillsDATS.put(abilityType, 0); skillsDATS.put(abilityType, 0);
} }
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) { for (SkillType skillType : SkillType.nonChildSkills()) {
skills.put(skillType, 0); skills.put(skillType, 0);
skillsXp.put(skillType, 0F); skillsXp.put(skillType, 0F);
} }
@@ -54,7 +54,7 @@ public class PlayerProfile {
* Calling this constructor is considered loading the profile. * Calling this constructor is considered loading the profile.
*/ */
public PlayerProfile(String playerName, Map<SkillType, Integer> argSkills, Map<SkillType, Float> argSkillsXp, Map<AbilityType, Integer> argSkillsDats, MobHealthbarType mobHealthbarType) { public PlayerProfile(String playerName, Map<SkillType, Integer> argSkills, Map<SkillType, Float> argSkillsXp, Map<AbilityType, Integer> argSkillsDats, MobHealthbarType mobHealthbarType) {
this(playerName); this(playerName, true);
this.mobHealthbarType = mobHealthbarType; this.mobHealthbarType = mobHealthbarType;
@@ -66,14 +66,12 @@ public class PlayerProfile {
} }
public void save() { public void save() {
if (!changed || !loaded) { if (!changed) {
return; return;
} }
changed = !mcMMO.getDatabaseManager().saveUser(this); mcMMO.getDatabaseManager().saveUser(this);
if (changed) { changed = false;
mcMMO.p.getLogger().warning("PlayerProfile for " + playerName + " failed to save");
}
} }
public String getPlayerName() { public String getPlayerName() {
@@ -152,7 +150,11 @@ public class PlayerProfile {
*/ */
public int getSkillLevel(SkillType skillType) { public int getSkillLevel(SkillType skillType) {
return skillType.isChildSkill() ? getChildSkillLevel(skillType) : skills.get(skillType); if (skillType.isChildSkill()) {
return getChildSkillLevel(skillType);
}
return skills.get(skillType);
} }
public float getSkillXpLevelRaw(SkillType skillType) { public float getSkillXpLevelRaw(SkillType skillType) {

View File

@@ -1,19 +1,14 @@
package com.gmail.nossr50.datatypes.skills; package com.gmail.nossr50.datatypes.skills;
import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.google.common.collect.ImmutableList;
public enum AbilityType { public enum AbilityType {
BERSERK( BERSERK(
@@ -65,9 +60,6 @@ public enum AbilityType {
"Swords.Skills.SS.Refresh", "Swords.Skills.SS.Refresh",
"Swords.Skills.SS.Other.Off"), "Swords.Skills.SS.Other.Off"),
/**
* Has cooldown - but has to share a skill with Super Breaker, so needs special treatment
*/
BLAST_MINING( BLAST_MINING(
null, null,
null, null,
@@ -75,15 +67,19 @@ public enum AbilityType {
"Mining.Blast.Refresh", "Mining.Blast.Refresh",
null), null),
/** LEAF_BLOWER(
* No cooldown - always active null,
*/ null,
LEAF_BLOWER, null,
null,
null),
/** BLOCK_CRACKER(
* Not a first-class Ability - part of Berserk null,
*/ null,
BLOCK_CRACKER; null,
null,
null);
private String abilityOn; private String abilityOn;
private String abilityOff; private String abilityOff;
@@ -91,20 +87,6 @@ public enum AbilityType {
private String abilityRefresh; private String abilityRefresh;
private String abilityPlayerOff; private String abilityPlayerOff;
/**
* Those abilities that have a cooldown saved to the database.
*/
public static final List<AbilityType> NORMAL_ABILITIES = ImmutableList.of(BERSERK, BLAST_MINING, GIGA_DRILL_BREAKER, GREEN_TERRA, SERRATED_STRIKES, SKULL_SPLITTER, SUPER_BREAKER, TREE_FELLER);
/**
* Those abilities that do not have a cooldown saved to the database.
*/
public static final List<AbilityType> NON_NORMAL_ABILITIES = ImmutableList.of(BLOCK_CRACKER, LEAF_BLOWER);
private AbilityType() {
this(null, null, null, null, null);
}
private AbilityType(String abilityOn, String abilityOff, String abilityPlayer, String abilityRefresh, String abilityPlayerOff) { private AbilityType(String abilityOn, String abilityOff, String abilityPlayer, String abilityRefresh, String abilityPlayerOff) {
this.abilityOn = abilityOn; this.abilityOn = abilityOn;
this.abilityOff = abilityOff; this.abilityOff = abilityOff;
@@ -141,10 +123,6 @@ public enum AbilityType {
return LocaleLoader.getString(this.abilityRefresh); return LocaleLoader.getString(this.abilityRefresh);
} }
public String getName() {
return StringUtils.getPrettyAbilityString(this);
}
@Override @Override
public String toString() { public String toString() {
String baseString = name(); String baseString = name();
@@ -242,23 +220,4 @@ public enum AbilityType {
return false; return false;
} }
} }
/**
* Check to see if ability should be triggered.
*
* @param player The player using the ability
* @param block The block modified by the ability
* @return true if the ability should activate, false otherwise
*/
public boolean triggerCheck(Player player, Block block) {
switch (this) {
case BERSERK:
case BLOCK_CRACKER:
case LEAF_BLOWER:
return blockCheck(block.getState()) && EventUtils.simulateBlockBreak(block, player, true);
default:
return false;
}
}
} }

View File

@@ -5,7 +5,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@@ -25,8 +24,8 @@ import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager; import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@@ -52,34 +51,15 @@ public enum SkillType {
public static final List<String> SKILL_NAMES; public static final List<String> SKILL_NAMES;
public static final List<SkillType> CHILD_SKILLS;
public static final List<SkillType> NON_CHILD_SKILLS;
public static final List<SkillType> COMBAT_SKILLS = ImmutableList.of(ARCHERY, AXES, SWORDS, TAMING, UNARMED);
public static final List<SkillType> GATHERING_SKILLS = ImmutableList.of(EXCAVATION, FISHING, HERBALISM, MINING, WOODCUTTING);
public static final List<SkillType> MISC_SKILLS = ImmutableList.of(ACROBATICS, REPAIR, SMELTING);
static { static {
List<SkillType> childSkills = new ArrayList<SkillType>();
List<SkillType> nonChildSkills = new ArrayList<SkillType>();
ArrayList<String> names = new ArrayList<String>(); ArrayList<String> names = new ArrayList<String>();
for (SkillType skill : values()) { for (SkillType skill : values()) {
if (skill.isChildSkill()) { names.add(SkillUtils.getSkillName(skill));
childSkills.add(skill);
}
else {
nonChildSkills.add(skill);
}
names.add(skill.getName());
} }
Collections.sort(names); Collections.sort(names);
SKILL_NAMES = ImmutableList.copyOf(names); SKILL_NAMES = ImmutableList.copyOf(names);
CHILD_SKILLS = ImmutableList.copyOf(childSkills);
NON_CHILD_SKILLS = ImmutableList.copyOf(nonChildSkills);
} }
private SkillType(Class<? extends SkillManager> managerClass, Color runescapeColor) { private SkillType(Class<? extends SkillManager> managerClass, Color runescapeColor) {
@@ -129,18 +109,10 @@ public enum SkillType {
return Config.getInstance().getHardcoreStatLossEnabled(this); return Config.getInstance().getHardcoreStatLossEnabled(this);
} }
public void setHardcoreStatLossEnabled(boolean enable) {
Config.getInstance().setHardcoreStatLossEnabled(this, enable);
}
public boolean getHardcoreVampirismEnabled() { public boolean getHardcoreVampirismEnabled() {
return Config.getInstance().getHardcoreVampirismEnabled(this); return Config.getInstance().getHardcoreVampirismEnabled(this);
} }
public void setHardcoreVampirismEnabled(boolean enable) {
Config.getInstance().setHardcoreVampirismEnabled(this, enable);
}
public ToolType getTool() { public ToolType getTool() {
return tool; return tool;
} }
@@ -171,14 +143,33 @@ public enum SkillType {
// TODO: This is a little "hacky", we probably need to add something to distinguish child skills in the enum, or to use another enum for them // TODO: This is a little "hacky", we probably need to add something to distinguish child skills in the enum, or to use another enum for them
public boolean isChildSkill() { public boolean isChildSkill() {
switch (this) { switch (this) {
case SMELTING: case SMELTING:
return true; return true;
default: default:
return false; return false;
} }
} }
public static SkillType[] nonChildSkills() {
return new SkillType[] {SkillType.ACROBATICS,
SkillType.ARCHERY,
SkillType.AXES,
SkillType.EXCAVATION,
SkillType.FISHING,
SkillType.HERBALISM,
SkillType.MINING,
SkillType.REPAIR,
SkillType.SWORDS,
SkillType.TAMING,
SkillType.UNARMED,
SkillType.WOODCUTTING };
}
public static SkillType[] childSkills() {
return new SkillType[] { SkillType.SMELTING };
}
public Color getRunescapeModeColor() { public Color getRunescapeModeColor() {
return runescapeColor; return runescapeColor;
} }
@@ -192,12 +183,4 @@ public enum SkillType {
return null; return null;
} }
public String getName() {
return Config.getInstance().getLocale().equalsIgnoreCase("en_US") ? StringUtils.getCapitalized(this.toString()) : StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(this.toString()) + ".SkillName"));
}
public boolean getPermissions(Player player) {
return Permissions.skillEnabled(player, this);
}
} }

View File

@@ -1,29 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.enchantments.Enchantment;
public class EnchantmentTreasure {
private Enchantment enchantment;
private int level;
public EnchantmentTreasure(Enchantment enchantment, int level) {
this.setEnchantment(enchantment);
this.setLevel(level);
}
public Enchantment getEnchantment() {
return enchantment;
}
public void setEnchantment(Enchantment enchantment) {
this.enchantment = enchantment;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}

View File

@@ -3,8 +3,18 @@ package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class FishingTreasure extends Treasure { public class FishingTreasure extends Treasure {
private int maxLevel;
public FishingTreasure(ItemStack drop, int xp) { public FishingTreasure(ItemStack drop, int xp, Double dropChance, int dropLevel, int maxLevel) {
super(drop, xp, 0, 0); super(drop, xp, dropChance, dropLevel);
this.setMaxLevel(maxLevel);
}
public int getMaxLevel() {
return maxLevel;
}
public void setMaxLevel(int maxLevel) {
this.maxLevel = maxLevel;
} }
} }

View File

@@ -1,20 +0,0 @@
package com.gmail.nossr50.datatypes.treasure;
public enum Rarity {
RECORD,
LEGENDARY,
EPIC,
RARE,
UNCOMMON,
COMMON,
TRAP;
public static Rarity getRarity(String string) {
try {
return valueOf(string);
}
catch (IllegalArgumentException ex) {
return COMMON;
}
}
};

View File

@@ -3,16 +3,28 @@ package com.gmail.nossr50.events.skills.abilities;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerAbilityActivateEvent extends McMMOPlayerAbilityEvent implements Cancellable { public class McMMOPlayerAbilityActivateEvent extends McMMOPlayerSkillEvent implements Cancellable {
private AbilityType abilityType;
private boolean cancelled; private boolean cancelled;
public McMMOPlayerAbilityActivateEvent(Player player, SkillType skill) { public McMMOPlayerAbilityActivateEvent(Player player, SkillType skill) {
super(player, skill); super(player, skill);
abilityType = skill.getAbility();
cancelled = false; cancelled = false;
} }
/**
* @return The ability type involved in this event
*/
public AbilityType getAbilityType() {
return abilityType;
}
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }

View File

@@ -2,10 +2,21 @@ package com.gmail.nossr50.events.skills.abilities;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerAbilityDeactivateEvent extends McMMOPlayerSkillEvent {
private AbilityType ability;
public class McMMOPlayerAbilityDeactivateEvent extends McMMOPlayerAbilityEvent {
public McMMOPlayerAbilityDeactivateEvent(Player player, SkillType skill) { public McMMOPlayerAbilityDeactivateEvent(Player player, SkillType skill) {
super(player, skill); super(player, skill);
this.ability = skill.getAbility();
} }
public AbilityType getAbility() {
return ability;
}
} }

View File

@@ -1,20 +0,0 @@
package com.gmail.nossr50.events.skills.abilities;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerAbilityEvent extends McMMOPlayerSkillEvent {
private AbilityType ability;
protected McMMOPlayerAbilityEvent(Player player, SkillType skill) {
super(player, skill);
ability = skill.getAbility();
}
public AbilityType getAbility() {
return ability;
}
}

View File

@@ -1,24 +0,0 @@
package com.gmail.nossr50.events.skills.fishing;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerFishingEvent extends McMMOPlayerSkillEvent implements Cancellable {
private boolean cancelled;
protected McMMOPlayerFishingEvent(Player player) {
super(player, SkillType.FISHING);
cancelled = false;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean newValue) {
this.cancelled = newValue;
}
}

View File

@@ -1,14 +1,20 @@
package com.gmail.nossr50.events.skills.fishing; package com.gmail.nossr50.events.skills.fishing;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class McMMOPlayerFishingTreasureEvent extends McMMOPlayerFishingEvent { import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerFishingTreasureEvent extends McMMOPlayerSkillEvent implements Cancellable {
private boolean cancelled = false;
private ItemStack treasure; private ItemStack treasure;
private int xp; private int xp;
public McMMOPlayerFishingTreasureEvent(Player player, ItemStack treasure, int xp) { public McMMOPlayerFishingTreasureEvent(Player player, ItemStack treasure, int xp) {
super(player); super(player, SkillType.FISHING);
this.treasure = treasure; this.treasure = treasure;
this.xp = xp; this.xp = xp;
} }
@@ -21,6 +27,14 @@ public class McMMOPlayerFishingTreasureEvent extends McMMOPlayerFishingEvent {
this.treasure = item; this.treasure = item;
} }
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean newValue) {
this.cancelled = newValue;
}
public int getXp() { public int getXp() {
return xp; return xp;
} }

View File

@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class McMMOPlayerMagicHunterEvent extends McMMOPlayerFishingTreasureEvent { public class McMMOPlayerMagicHunterEvent extends McMMOPlayerFishingTreasureEvent {
private Map<Enchantment, Integer> enchants; private Map<Enchantment, Integer> enchants;
public McMMOPlayerMagicHunterEvent(Player player, ItemStack treasure, int xp, Map<Enchantment, Integer> enchants) { public McMMOPlayerMagicHunterEvent(Player player, ItemStack treasure, int xp, Map<Enchantment, Integer> enchants) {

View File

@@ -1,16 +1,30 @@
package com.gmail.nossr50.events.skills.fishing; package com.gmail.nossr50.events.skills.fishing;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class McMMOPlayerShakeEvent extends McMMOPlayerFishingEvent { import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerShakeEvent extends McMMOPlayerSkillEvent implements Cancellable {
private boolean cancelled = false;
private ItemStack drop; private ItemStack drop;
public McMMOPlayerShakeEvent(Player player, ItemStack drop) { public McMMOPlayerShakeEvent(Player player, ItemStack drop) {
super(player); super(player, SkillType.FISHING);
this.drop = drop; this.drop = drop;
} }
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean newValue) {
this.cancelled = newValue;
}
public ItemStack getDrop() { public ItemStack getDrop() {
return drop; return drop;
} }
@@ -18,4 +32,5 @@ public class McMMOPlayerShakeEvent extends McMMOPlayerFishingEvent {
public void setDrop(ItemStack drop) { public void setDrop(ItemStack drop) {
this.drop = drop; this.drop = drop;
} }
} }

View File

@@ -54,7 +54,7 @@ public class BlockListener implements Listener {
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockPistonExtend(BlockPistonExtendEvent event) { public void onBlockPistonExtend(BlockPistonExtendEvent event) {
List<Block> blocks = event.getBlocks(); List<Block> blocks = event.getBlocks();
BlockFace direction = event.getDirection(); BlockFace direction = event.getDirection();
@@ -84,7 +84,7 @@ public class BlockListener implements Listener {
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockPistonRetract(BlockPistonRetractEvent event) { public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if (event.isSticky()) { if (event.isSticky()) {
// Needed only because under some circumstances Minecraft doesn't move the block // Needed only because under some circumstances Minecraft doesn't move the block
@@ -149,26 +149,26 @@ public class BlockListener implements Listener {
/* Green Terra */ /* Green Terra */
if (herbalismManager.canActivateAbility()) { if (herbalismManager.canActivateAbility()) {
mcMMOPlayer.checkAbilityActivation(SkillType.HERBALISM); SkillUtils.abilityCheck(mcMMOPlayer, SkillType.HERBALISM);
} }
/* /*
* We don't check the block store here because herbalism has too many unusual edge cases. * We don't check the block store here because herbalism has too many unusual edge cases.
* Instead, we check it inside the drops handler. * Instead, we check it inside the drops handler.
*/ */
if (SkillType.HERBALISM.getPermissions(player)) { if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
herbalismManager.herbalismBlockCheck(blockState); herbalismManager.herbalismBlockCheck(blockState);
} }
} }
/* MINING */ /* MINING */
else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && SkillType.MINING.getPermissions(player) && !mcMMO.getPlaceStore().isTrue(blockState)) { else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.getPlaceStore().isTrue(blockState)) {
MiningManager miningManager = mcMMOPlayer.getMiningManager(); MiningManager miningManager = mcMMOPlayer.getMiningManager();
miningManager.miningBlockCheck(blockState); miningManager.miningBlockCheck(blockState);
} }
/* WOOD CUTTING */ /* WOOD CUTTING */
else if (BlockUtils.isLog(blockState) && SkillType.WOODCUTTING.getPermissions(player) && !mcMMO.getPlaceStore().isTrue(blockState)) { else if (BlockUtils.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.getPlaceStore().isTrue(blockState)) {
WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager(); WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager();
if (woodcuttingManager.canUseTreeFeller(heldItem)) { if (woodcuttingManager.canUseTreeFeller(heldItem)) {
@@ -180,7 +180,7 @@ public class BlockListener implements Listener {
} }
/* EXCAVATION */ /* EXCAVATION */
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && SkillType.EXCAVATION.getPermissions(player) && !mcMMO.getPlaceStore().isTrue(blockState)) { else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.getPlaceStore().isTrue(blockState)) {
ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager(); ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager();
excavationManager.excavationBlockCheck(blockState); excavationManager.excavationBlockCheck(blockState);
@@ -280,19 +280,19 @@ public class BlockListener implements Listener {
} }
if (mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) { if (mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) {
mcMMOPlayer.checkAbilityActivation(SkillType.HERBALISM); SkillUtils.abilityCheck(mcMMOPlayer, SkillType.HERBALISM);
} }
else if (mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) { else if (mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) {
mcMMOPlayer.checkAbilityActivation(SkillType.WOODCUTTING); SkillUtils.abilityCheck(mcMMOPlayer, SkillType.WOODCUTTING);
} }
else if (mcMMOPlayer.getToolPreparationMode(ToolType.PICKAXE) && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) { else if (mcMMOPlayer.getToolPreparationMode(ToolType.PICKAXE) && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) {
mcMMOPlayer.checkAbilityActivation(SkillType.MINING); SkillUtils.abilityCheck(mcMMOPlayer, SkillType.MINING);
} }
else if (mcMMOPlayer.getToolPreparationMode(ToolType.SHOVEL) && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) { else if (mcMMOPlayer.getToolPreparationMode(ToolType.SHOVEL) && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) {
mcMMOPlayer.checkAbilityActivation(SkillType.EXCAVATION); SkillUtils.abilityCheck(mcMMOPlayer, SkillType.EXCAVATION);
} }
else if (mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) { else if (mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) {
mcMMOPlayer.checkAbilityActivation(SkillType.UNARMED); SkillUtils.abilityCheck(mcMMOPlayer, SkillType.UNARMED);
} }
} }
@@ -339,17 +339,17 @@ public class BlockListener implements Listener {
} }
} }
else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && heldItem.getType() == Material.AIR) { else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && heldItem.getType() == Material.AIR) {
if (AbilityType.BERSERK.triggerCheck(player, block)) { if (SkillUtils.triggerCheck(player, block, AbilityType.BERSERK)) {
event.setInstaBreak(true); event.setInstaBreak(true);
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch()); player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
} }
else if (mcMMOPlayer.getUnarmedManager().canUseBlockCracker() && AbilityType.BLOCK_CRACKER.triggerCheck(player, block)) { else if (mcMMOPlayer.getUnarmedManager().canUseBlockCracker() && SkillUtils.triggerCheck(player, block, AbilityType.BLOCK_CRACKER)) {
if (mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) { if (mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) {
blockState.update(); blockState.update();
} }
} }
} }
else if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && AbilityType.LEAF_BLOWER.triggerCheck(player, block)) { else if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && SkillUtils.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
event.setInstaBreak(true); event.setInstaBreak(true);
player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch()); player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
} }

View File

@@ -459,22 +459,6 @@ public class EntityListener implements Listener {
} }
} }
/**
* Handle EntityExplode events that involve modifying the event.
*
* @param event The event to modify
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityExplodeMonitor(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntsafeMetadataKey)) {
return;
}
event.blockList().clear();
}
/** /**
* Handle FoodLevelChange events that involve modifying the event. * Handle FoodLevelChange events that involve modifying the event.
* *

View File

@@ -91,7 +91,7 @@ public class InventoryListener implements Listener {
Player player = Misc.getPlayerFromFurnace(furnaceBlock); Player player = Misc.getPlayerFromFurnace(furnaceBlock);
if (Misc.isNPCEntity(player) || !SkillType.SMELTING.getPermissions(player)) { if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) {
return; return;
} }

View File

@@ -49,7 +49,6 @@ import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.Unarmed; import com.gmail.nossr50.skills.unarmed.Unarmed;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.ChimaeraWing; import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.HardcoreManager; import com.gmail.nossr50.util.HardcoreManager;
import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@@ -57,6 +56,7 @@ import com.gmail.nossr50.util.MobHealthbarUtils;
import com.gmail.nossr50.util.Motd; import com.gmail.nossr50.util.Motd;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
@@ -204,7 +204,7 @@ public class PlayerListener implements Listener {
public void onPlayerFishHighest(PlayerFishEvent event) { public void onPlayerFishHighest(PlayerFishEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (Misc.isNPCEntity(player) || !SkillType.FISHING.getPermissions(player)) { if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.FISHING)) {
return; return;
} }
@@ -249,7 +249,7 @@ public class PlayerListener implements Listener {
public void onPlayerFishMonitor(PlayerFishEvent event) { public void onPlayerFishMonitor(PlayerFishEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (Misc.isNPCEntity(player) || !SkillType.FISHING.getPermissions(player)) { if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.FISHING)) {
return; return;
} }
@@ -362,6 +362,7 @@ public class PlayerListener implements Listener {
} }
UserManager.addUser(player).actualizeRespawnATS(); UserManager.addUser(player).actualizeRespawnATS();
ScoreboardManager.enablePowerLevelDisplay(player);
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) { if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
Motd.displayAll(player); Motd.displayAll(player);
@@ -421,7 +422,7 @@ public class PlayerListener implements Listener {
if (!Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) { if (!Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) {
/* REPAIR CHECKS */ /* REPAIR CHECKS */
if (type == Repair.repairAnvilMaterial && SkillType.REPAIR.getPermissions(player) && mcMMO.getRepairableManager().isRepairable(heldItem)) { if (type == Repair.repairAnvilMaterial && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
RepairManager repairManager = mcMMOPlayer.getRepairManager(); RepairManager repairManager = mcMMOPlayer.getRepairManager();
event.setCancelled(true); event.setCancelled(true);
@@ -460,7 +461,7 @@ public class PlayerListener implements Listener {
if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) { if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) {
/* REPAIR CHECKS */ /* REPAIR CHECKS */
if (type == Repair.repairAnvilMaterial && SkillType.REPAIR.getPermissions(player) && mcMMO.getRepairableManager().isRepairable(heldItem)) { if (type == Repair.repairAnvilMaterial && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
RepairManager repairManager = mcMMOPlayer.getRepairManager(); RepairManager repairManager = mcMMOPlayer.getRepairManager();
// Cancel repairing an enchanted item // Cancel repairing an enchanted item
@@ -513,15 +514,15 @@ public class PlayerListener implements Listener {
if (BlockUtils.canActivateAbilities(blockState)) { if (BlockUtils.canActivateAbilities(blockState)) {
if (Config.getInstance().getAbilitiesEnabled()) { if (Config.getInstance().getAbilitiesEnabled()) {
if (BlockUtils.canActivateHerbalism(blockState)) { if (BlockUtils.canActivateHerbalism(blockState)) {
mcMMOPlayer.processAbilityActivation(SkillType.HERBALISM); SkillUtils.activationCheck(player, SkillType.HERBALISM);
} }
mcMMOPlayer.processAbilityActivation(SkillType.AXES); SkillUtils.activationCheck(player, SkillType.AXES);
mcMMOPlayer.processAbilityActivation(SkillType.EXCAVATION); SkillUtils.activationCheck(player, SkillType.EXCAVATION);
mcMMOPlayer.processAbilityActivation(SkillType.MINING); SkillUtils.activationCheck(player, SkillType.MINING);
mcMMOPlayer.processAbilityActivation(SkillType.SWORDS); SkillUtils.activationCheck(player, SkillType.SWORDS);
mcMMOPlayer.processAbilityActivation(SkillType.UNARMED); SkillUtils.activationCheck(player, SkillType.UNARMED);
mcMMOPlayer.processAbilityActivation(SkillType.WOODCUTTING); SkillUtils.activationCheck(player, SkillType.WOODCUTTING);
} }
ChimaeraWing.activationCheck(player); ChimaeraWing.activationCheck(player);
@@ -533,14 +534,14 @@ public class PlayerListener implements Listener {
if (herbalismManager.canGreenThumbBlock(blockState)) { if (herbalismManager.canGreenThumbBlock(blockState)) {
player.setItemInHand(new ItemStack(Material.SEEDS, heldItem.getAmount() - 1)); player.setItemInHand(new ItemStack(Material.SEEDS, heldItem.getAmount() - 1));
if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) { if (herbalismManager.processGreenThumbBlocks(blockState) && SkillUtils.blockBreakSimulate(block, player, false)) {
blockState.update(true); blockState.update(true);
} }
} }
/* SHROOM THUMB CHECK */ /* SHROOM THUMB CHECK */
else if (herbalismManager.canUseShroomThumb(blockState)) { else if (herbalismManager.canUseShroomThumb(blockState)) {
if (herbalismManager.processShroomThumb(blockState) && EventUtils.simulateBlockBreak(block, player, false)) { if (herbalismManager.processShroomThumb(blockState) && SkillUtils.blockBreakSimulate(block, player, false)) {
blockState.update(true); blockState.update(true);
} }
} }
@@ -550,13 +551,13 @@ public class PlayerListener implements Listener {
/* ACTIVATION CHECKS */ /* ACTIVATION CHECKS */
if (Config.getInstance().getAbilitiesEnabled()) { if (Config.getInstance().getAbilitiesEnabled()) {
mcMMOPlayer.processAbilityActivation(SkillType.AXES); SkillUtils.activationCheck(player, SkillType.AXES);
mcMMOPlayer.processAbilityActivation(SkillType.EXCAVATION); SkillUtils.activationCheck(player, SkillType.EXCAVATION);
mcMMOPlayer.processAbilityActivation(SkillType.HERBALISM); SkillUtils.activationCheck(player, SkillType.HERBALISM);
mcMMOPlayer.processAbilityActivation(SkillType.MINING); SkillUtils.activationCheck(player, SkillType.MINING);
mcMMOPlayer.processAbilityActivation(SkillType.SWORDS); SkillUtils.activationCheck(player, SkillType.SWORDS);
mcMMOPlayer.processAbilityActivation(SkillType.UNARMED); SkillUtils.activationCheck(player, SkillType.UNARMED);
mcMMOPlayer.processAbilityActivation(SkillType.WOODCUTTING); SkillUtils.activationCheck(player, SkillType.WOODCUTTING);
} }
/* ITEM CHECKS */ /* ITEM CHECKS */
@@ -658,7 +659,7 @@ public class PlayerListener implements Listener {
// Do these ACTUALLY have to be lower case to work properly? // Do these ACTUALLY have to be lower case to work properly?
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.values()) {
String skillName = skill.toString().toLowerCase(); String skillName = skill.toString().toLowerCase();
String localizedName = skill.getName().toLowerCase(); String localizedName = SkillUtils.getSkillName(skill).toLowerCase();
if (lowerCaseCommand.equals(localizedName)) { if (lowerCaseCommand.equals(localizedName)) {
event.setMessage(message.replace(command, skillName)); event.setMessage(message.replace(command, skillName));

View File

@@ -1,39 +0,0 @@
package com.gmail.nossr50.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
public class ScoreboardsListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
ScoreboardManager.setupPlayer(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
ScoreboardManager.teardownPlayer(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLevelUp(McMMOPlayerLevelUpEvent event) {
ScoreboardManager.handleLevelUp(event.getPlayer(), event.getSkill());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerXp(McMMOPlayerXpGainEvent event) {
ScoreboardManager.handleXp(event.getPlayer(), event.getSkill());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onAbility(McMMOPlayerAbilityActivateEvent event) {
ScoreboardManager.cooldownUpdate(event.getPlayer(), event.getSkill());
}
}

View File

@@ -7,7 +7,6 @@ import java.util.ResourceBundle;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
public final class LocaleLoader { public final class LocaleLoader {
@@ -41,17 +40,13 @@ public final class LocaleLoader {
return getString(key, enBundle, messageArguments); return getString(key, enBundle, messageArguments);
} }
catch (MissingResourceException ex2) { catch (MissingResourceException ex2) {
if (!key.contains("Guides")) {
mcMMO.p.getLogger().warning("Could not find locale string: " + key);
}
return '!' + key + '!'; return '!' + key + '!';
} }
} }
} }
private static String getString(String key, ResourceBundle bundle, Object... messageArguments) throws MissingResourceException { private static String getString(String key, ResourceBundle bundle, Object... messageArguments) throws MissingResourceException {
return formatString(bundle.getString(key), messageArguments); return formatString(bundle.getString(key).replace("\'", "''"), messageArguments);
} }
public static String formatString(String string, Object... messageArguments) { public static String formatString(String string, Object... messageArguments) {
@@ -61,7 +56,6 @@ public final class LocaleLoader {
string = formatter.format(messageArguments); string = formatter.format(messageArguments);
} }
string.replaceAll("\'", "''");
string = addColors(string); string = addColors(string);
return string; return string;

View File

@@ -25,7 +25,6 @@ import com.gmail.nossr50.listeners.BlockListener;
import com.gmail.nossr50.listeners.EntityListener; import com.gmail.nossr50.listeners.EntityListener;
import com.gmail.nossr50.listeners.InventoryListener; import com.gmail.nossr50.listeners.InventoryListener;
import com.gmail.nossr50.listeners.PlayerListener; import com.gmail.nossr50.listeners.PlayerListener;
import com.gmail.nossr50.listeners.ScoreboardsListener;
import com.gmail.nossr50.listeners.SelfListener; import com.gmail.nossr50.listeners.SelfListener;
import com.gmail.nossr50.listeners.WorldListener; import com.gmail.nossr50.listeners.WorldListener;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@@ -34,13 +33,12 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.SaveTimerTask; import com.gmail.nossr50.runnables.SaveTimerTask;
import com.gmail.nossr50.runnables.database.UserPurgeTask; import com.gmail.nossr50.runnables.database.UserPurgeTask;
import com.gmail.nossr50.runnables.party.PartyAutoKickTask; import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
import com.gmail.nossr50.runnables.player.PowerLevelUpdatingTask;
import com.gmail.nossr50.runnables.skills.BleedTimerTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.skills.child.ChildConfig; import com.gmail.nossr50.skills.child.ChildConfig;
import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableManager;
import com.gmail.nossr50.skills.repair.RepairableManagerFactory;
import com.gmail.nossr50.skills.repair.config.RepairConfigManager; import com.gmail.nossr50.skills.repair.config.RepairConfigManager;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairableManager;
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairableManager;
import com.gmail.nossr50.util.ChimaeraWing; import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.LogFilter; import com.gmail.nossr50.util.LogFilter;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@@ -50,11 +48,10 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
import com.gmail.nossr50.util.commands.CommandRegistrationManager; import com.gmail.nossr50.util.commands.CommandRegistrationManager;
import com.gmail.nossr50.util.experience.FormulaManager; import com.gmail.nossr50.util.experience.FormulaManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import net.gravitydevelopment.updater.mcmmo.Updater; import net.h31ix.updater.mcmmo.Updater;
import net.gravitydevelopment.updater.mcmmo.Updater.UpdateResult; import net.h31ix.updater.mcmmo.Updater.UpdateResult;
import net.gravitydevelopment.updater.mcmmo.Updater.UpdateType; import net.h31ix.updater.mcmmo.Updater.UpdateType;
import net.shatteredlands.shatt.backup.ZipLibrary; import net.shatteredlands.shatt.backup.ZipLibrary;
public class mcMMO extends JavaPlugin { public class mcMMO extends JavaPlugin {
@@ -81,8 +78,6 @@ public class mcMMO extends JavaPlugin {
/* Plugin Checks */ /* Plugin Checks */
private static boolean combatTagEnabled; private static boolean combatTagEnabled;
private static boolean healthBarPluginEnabled; private static boolean healthBarPluginEnabled;
private static boolean noCheatPlusPluginEnabled;
private static boolean compatNoCheatPlusPluginEnabled;
private static boolean mcpcEnabled; private static boolean mcpcEnabled;
// Config Validation Check // Config Validation Check
@@ -96,7 +91,6 @@ public class mcMMO extends JavaPlugin {
public final static String blockMetadataKey = "mcMMO: Piston Tracking"; public final static String blockMetadataKey = "mcMMO: Piston Tracking";
public final static String furnaceMetadataKey = "mcMMO: Tracked Furnace"; public final static String furnaceMetadataKey = "mcMMO: Tracked Furnace";
public final static String tntMetadataKey = "mcMMO: Tracked TNT"; public final static String tntMetadataKey = "mcMMO: Tracked TNT";
public final static String tntsafeMetadataKey = "mcMMO: Safe TNT";
public final static String customNameKey = "mcMMO: Custom Name"; public final static String customNameKey = "mcMMO: Custom Name";
public final static String customVisibleKey = "mcMMO: Name Visibility"; public final static String customVisibleKey = "mcMMO: Name Visibility";
public final static String droppedItemKey = "mcMMO: Tracked Item"; public final static String droppedItemKey = "mcMMO: Tracked Item";
@@ -125,11 +119,9 @@ public class mcMMO extends JavaPlugin {
return; return;
} }
mcpcEnabled = getServer().getName().equals("MCPC+");
combatTagEnabled = getServer().getPluginManager().getPlugin("CombatTag") != null; combatTagEnabled = getServer().getPluginManager().getPlugin("CombatTag") != null;
healthBarPluginEnabled = getServer().getPluginManager().getPlugin("HealthBar") != null; healthBarPluginEnabled = getServer().getPluginManager().getPlugin("HealthBar") != null;
noCheatPlusPluginEnabled = getServer().getPluginManager().getPlugin("NoCheatPlus") != null; mcpcEnabled = getServer().getName().equals("MCPC+");
compatNoCheatPlusPluginEnabled = getServer().getPluginManager().getPlugin("CompatNoCheatPlus") != null;
if (mcpcEnabled) { if (mcpcEnabled) {
checkModConfigs(); checkModConfigs();
@@ -139,11 +131,6 @@ public class mcMMO extends JavaPlugin {
getLogger().info("HealthBar plugin found, mcMMO's healthbars are automatically disabled."); getLogger().info("HealthBar plugin found, mcMMO's healthbars are automatically disabled.");
} }
if (noCheatPlusPluginEnabled && !compatNoCheatPlusPluginEnabled) {
getLogger().warning("NoCheatPlus plugin found, but CompatNoCheatPlus was not found!");
getLogger().warning("mcMMO will not work properly alongside NoCheatPlus without CompatNoCheatPlus");
}
databaseManager = DatabaseManagerFactory.getDatabaseManager(); databaseManager = DatabaseManagerFactory.getDatabaseManager();
registerEvents(); registerEvents();
@@ -155,7 +142,6 @@ public class mcMMO extends JavaPlugin {
for (Player player : getServer().getOnlinePlayers()) { for (Player player : getServer().getOnlinePlayers()) {
UserManager.addUser(player); // In case of reload add all users back into UserManager UserManager.addUser(player); // In case of reload add all users back into UserManager
ScoreboardManager.setupPlayer(player);
} }
debug("Version " + getDescription().getVersion() + " is enabled!"); debug("Version " + getDescription().getVersion() + " is enabled!");
@@ -195,7 +181,6 @@ public class mcMMO extends JavaPlugin {
try { try {
UserManager.saveAll(); // Make sure to save player information if the server shuts down UserManager.saveAll(); // Make sure to save player information if the server shuts down
PartyManager.saveParties(); // Save our parties PartyManager.saveParties(); // Save our parties
ScoreboardManager.teardownAll();
formulaManager.saveFormula(); formulaManager.saveFormula();
placeStore.saveAll(); // Save our metadata placeStore.saveAll(); // Save our metadata
placeStore.cleanUp(); // Cleanup empty metadata stores placeStore.cleanUp(); // Cleanup empty metadata stores
@@ -302,23 +287,9 @@ public class mcMMO extends JavaPlugin {
private void setupFilePaths() { private void setupFilePaths() {
mcmmo = getFile(); mcmmo = getFile();
mainDirectory = getDataFolder().getPath() + File.separator; mainDirectory = getDataFolder().getPath() + File.separator;
flatFileDirectory = mainDirectory + "flatfile" + File.separator; flatFileDirectory = mainDirectory + "FlatFileStuff" + File.separator;
usersFile = flatFileDirectory + "mcmmo.users"; usersFile = flatFileDirectory + "mcmmo.users";
modDirectory = mainDirectory + "mods" + File.separator; modDirectory = mainDirectory + "ModConfigs" + File.separator;
fixFilePaths();
}
private void fixFilePaths() {
File oldFlatfilePath = new File(mainDirectory + "FlatFileStuff" + File.separator);
File oldModPath = new File(mainDirectory + "ModConfigs" + File.separator);
if (oldFlatfilePath.exists()) {
oldFlatfilePath.renameTo(new File(flatFileDirectory));
}
if (oldModPath.exists()) {
oldModPath.renameTo(new File(modDirectory));
}
} }
private void checkForUpdates() { private void checkForUpdates() {
@@ -326,14 +297,14 @@ public class mcMMO extends JavaPlugin {
return; return;
} }
Updater updater = new Updater(this, 31030, mcmmo, UpdateType.NO_DOWNLOAD, false); Updater updater = new Updater(this, "mcmmo", mcmmo, UpdateType.NO_DOWNLOAD, false);
if (updater.getResult() != UpdateResult.UPDATE_AVAILABLE) { if (updater.getResult() != UpdateResult.UPDATE_AVAILABLE) {
this.updateAvailable = false; this.updateAvailable = false;
return; return;
} }
if (updater.getLatestType().equals("beta") && !Config.getInstance().getPreferBeta()) { if (updater.getLatestVersionString().contains("-beta") && !Config.getInstance().getPreferBeta()) {
this.updateAvailable = false; this.updateAvailable = false;
return; return;
} }
@@ -371,7 +342,7 @@ public class mcMMO extends JavaPlugin {
// Load repair configs, make manager, and register them at this time // Load repair configs, make manager, and register them at this time
RepairConfigManager rManager = new RepairConfigManager(this); RepairConfigManager rManager = new RepairConfigManager(this);
repairables.addAll(rManager.getLoadedRepairables()); repairables.addAll(rManager.getLoadedRepairables());
repairableManager = new SimpleRepairableManager(repairables.size()); repairableManager = RepairableManagerFactory.getRepairManager(repairables.size());
repairableManager.registerRepairables(repairables); repairableManager.registerRepairables(repairables);
} }
@@ -384,7 +355,6 @@ public class mcMMO extends JavaPlugin {
pluginManager.registerEvents(new EntityListener(this), this); pluginManager.registerEvents(new EntityListener(this), this);
pluginManager.registerEvents(new InventoryListener(this), this); pluginManager.registerEvents(new InventoryListener(this), this);
pluginManager.registerEvents(new SelfListener(), this); pluginManager.registerEvents(new SelfListener(), this);
pluginManager.registerEvents(new ScoreboardsListener(), this);
pluginManager.registerEvents(new WorldListener(this), this); pluginManager.registerEvents(new WorldListener(this), this);
} }
@@ -421,9 +391,6 @@ public class mcMMO extends JavaPlugin {
else if (kickIntervalTicks > 0) { else if (kickIntervalTicks > 0) {
new PartyAutoKickTask().runTaskTimer(this, kickIntervalTicks, kickIntervalTicks); new PartyAutoKickTask().runTaskTimer(this, kickIntervalTicks, kickIntervalTicks);
} }
// Update power level tag scoreboards
new PowerLevelUpdatingTask().runTaskTimer(this, 2 * Misc.TICK_CONVERSION_FACTOR, 2 * Misc.TICK_CONVERSION_FACTOR);
} }
private void checkModConfigs() { private void checkModConfigs() {

View File

@@ -189,7 +189,11 @@ public final class PartyManager {
public static Party getParty(Player player) { public static Party getParty(Player player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
return mcMMOPlayer.getParty(); if (mcMMOPlayer != null) {
return mcMMOPlayer.getParty();
}
return getPlayerParty(player.getName());
} }
/** /**

View File

@@ -2,38 +2,25 @@ package com.gmail.nossr50.runnables.commands;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.Validate;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType;
public class McrankCommandAsyncTask extends BukkitRunnable { public class McrankCommandAsyncTask extends BukkitRunnable {
private final String playerName; private final String playerName;
private final CommandSender sender; private final CommandSender sender;
private final boolean useBoard, useChat;
public McrankCommandAsyncTask(String playerName, CommandSender sender, boolean useBoard, boolean useChat) {
Validate.isTrue(useBoard || useChat, "Attempted to start a rank retrieval with both board and chat off");
Validate.notNull(sender, "Attempted to start a rank retrieval with no recipient");
if (useBoard) {
Validate.isTrue(sender instanceof Player, "Attempted to start a rank retrieval displaying scoreboard to a non-player");
}
public McrankCommandAsyncTask(String playerName, CommandSender sender) {
this.playerName = playerName; this.playerName = playerName;
this.sender = sender; this.sender = sender;
this.useBoard = useBoard;
this.useChat = useChat;
} }
@Override @Override
public void run() { public void run() {
Map<SkillType, Integer> skills = mcMMO.getDatabaseManager().readRank(playerName); Map<String, Integer> skills = mcMMO.getDatabaseManager().readRank(playerName);
new McrankCommandDisplayTask(skills, sender, playerName, useBoard, useChat).runTaskLater(mcMMO.p, 1); new McrankCommandDisplayTask(skills, sender, playerName).runTaskLater(mcMMO.p, 1);
} }
} }

View File

@@ -9,62 +9,38 @@ import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillUtils;
/**
* Display the results of McrankCommandAsyncTask to the sender.
*/
public class McrankCommandDisplayTask extends BukkitRunnable { public class McrankCommandDisplayTask extends BukkitRunnable {
private final Map<SkillType, Integer> skills; private final Map<String, Integer> skills;
private final CommandSender sender; private final CommandSender sender;
private final String playerName; private final String playerName;
private final boolean useBoard, useChat;
McrankCommandDisplayTask(Map<SkillType, Integer> skills, CommandSender sender, String playerName, boolean useBoard, boolean useChat) { public McrankCommandDisplayTask(Map<String, Integer> skills, CommandSender sender, String playerName) {
this.skills = skills; this.skills = skills;
this.sender = sender; this.sender = sender;
this.playerName = playerName; this.playerName = playerName;
this.useBoard = useBoard;
this.useChat = useChat;
} }
@Override @Override
public void run() { public void run() {
if (useBoard) {
displayBoard();
}
if (useChat){
displayChat();
}
}
private void displayChat() {
Player player = mcMMO.p.getServer().getPlayerExact(playerName); Player player = mcMMO.p.getServer().getPlayerExact(playerName);
Integer rank; Integer rank;
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading")); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (SkillType skill : SkillType.NON_CHILD_SKILLS) { for (SkillType skill : SkillType.nonChildSkills()) {
if (!skill.getPermissions(player)) { if (player != null && !Permissions.skillEnabled(player, skill)) {
continue; continue;
} }
rank = skills.get(skill); rank = skills.get(skill.name());
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", skill.getName(), (rank == null ? LocaleLoader.getString("Commands.mcrank.Unranked") : rank))); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skill), (rank == null ? LocaleLoader.getString("Commands.mcrank.Unranked") : rank)));
} }
rank = skills.get(null); rank = skills.get("ALL");
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", (rank == null ? LocaleLoader.getString("Commands.mcrank.Unranked") : rank))); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", (rank == null ? LocaleLoader.getString("Commands.mcrank.Unranked") : rank)));
} }
public void displayBoard() {
if (sender.getName().equalsIgnoreCase(playerName)) {
ScoreboardManager.showPlayerRankScoreboard((Player) sender, skills);
}
else {
ScoreboardManager.showPlayerRankScoreboardOthers((Player) sender, playerName, skills);
}
}
} }

View File

@@ -2,40 +2,27 @@ package com.gmail.nossr50.runnables.commands;
import java.util.List; import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.skills.SkillType;
public class MctopCommandAsyncTask extends BukkitRunnable { public class MctopCommandAsyncTask extends BukkitRunnable {
private final CommandSender sender; private CommandSender sender;
private final SkillType skill; private String skill;
private final int page; private int page;
private final boolean useBoard, useChat;
public MctopCommandAsyncTask(int page, SkillType skill, CommandSender sender, boolean useBoard, boolean useChat) {
Validate.isTrue(useBoard || useChat, "Attempted to start a rank retrieval with both board and chat off");
Validate.notNull(sender, "Attempted to start a rank retrieval with no recipient");
if (useBoard) {
Validate.isTrue(sender instanceof Player, "Attempted to start a rank retrieval displaying scoreboard to a non-player");
}
public MctopCommandAsyncTask(int page, String skill, CommandSender sender) {
this.page = page; this.page = page;
this.skill = skill; this.skill = skill;
this.sender = sender; this.sender = sender;
this.useBoard = useBoard;
this.useChat = useChat;
} }
@Override @Override
public void run() { public void run() {
final List<PlayerStat> userStats = mcMMO.getDatabaseManager().readLeaderboard(skill, page, 10); final List<PlayerStat> userStats = mcMMO.getDatabaseManager().readLeaderboard(skill, page, 10);
new MctopCommandDisplayTask(userStats, page, skill, sender, useBoard, useChat).runTaskLater(mcMMO.p, 1); new MctopCommandDisplayTask(userStats, page, skill, sender).runTaskLater(mcMMO.p, 1);
} }
} }

View File

@@ -4,71 +4,44 @@ import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.StringUtils;
/**
* Display the results of {@link MctopCommandAsyncTask} to the sender.
*/
public class MctopCommandDisplayTask extends BukkitRunnable { public class MctopCommandDisplayTask extends BukkitRunnable {
private final List<PlayerStat> userStats; private List<PlayerStat> userStats;
private final CommandSender sender; private CommandSender sender;
private final SkillType skill; private String skill;
private final int page; private int page;
private final boolean useBoard, useChat;
MctopCommandDisplayTask(List<PlayerStat> userStats, int page, SkillType skill, CommandSender sender, boolean useBoard, boolean useChat) { public MctopCommandDisplayTask(List<PlayerStat> userStats, int page, String skill, CommandSender sender) {
this.userStats = userStats; this.userStats = userStats;
this.page = page; this.page = page;
this.skill = skill; this.skill = skill;
this.sender = sender; this.sender = sender;
this.useBoard = useBoard;
this.useChat = useChat;
} }
@Override @Override
public void run() { public void run() {
if (useBoard) { if (skill.equalsIgnoreCase("all")) {
displayBoard();
}
if (useChat) {
displayChat();
}
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
}
private void displayChat() {
if (skill == null) {
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
} }
else { else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
} }
int place = (page * 10) - 9; int place = (page * 10) - 9;
for (PlayerStat stat : userStats) { for (PlayerStat stat : userStats) {
// Format: String digit = ((place < 10) ? "0" : "") + String.valueOf(place);
// 01. Playername - skill value
// 12. Playername - skill value // Format: 1. Playername - skill value
sender.sendMessage(String.format("%2d. %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal)); sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.name + " - " + ChatColor.WHITE + stat.statVal);
place++; place++;
} }
}
private void displayBoard() { sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
if (skill == null) {
ScoreboardManager.showTopPowerScoreboard((Player) sender, page, userStats);
}
else {
ScoreboardManager.showTopScoreboard((Player) sender, skill, page, userStats);
}
} }
} }

View File

@@ -5,13 +5,11 @@ import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class FormulaConversionTask extends BukkitRunnable { public class FormulaConversionTask extends BukkitRunnable {
@@ -25,8 +23,6 @@ public class FormulaConversionTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
int convertedUsers = 0;
long startMillis = System.currentTimeMillis();
for (String playerName : mcMMO.getDatabaseManager().getStoredUsers()) { for (String playerName : mcMMO.getDatabaseManager().getStoredUsers()) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);
PlayerProfile profile; PlayerProfile profile;
@@ -47,8 +43,6 @@ public class FormulaConversionTask extends BukkitRunnable {
profile = mcMMOPlayer.getProfile(); profile = mcMMOPlayer.getProfile();
editValues(profile); editValues(profile);
} }
convertedUsers++;
Misc.printProgress(convertedUsers, DatabaseManager.progressInterval, startMillis);
} }
mcMMO.getFormulaManager().setPreviousFormulaType(formulaType); mcMMO.getFormulaManager().setPreviousFormulaType(formulaType);
@@ -58,7 +52,7 @@ public class FormulaConversionTask extends BukkitRunnable {
private void editValues(PlayerProfile profile) { private void editValues(PlayerProfile profile) {
mcMMO.p.debug("========================================================================"); mcMMO.p.debug("========================================================================");
mcMMO.p.debug("Conversion report for " + profile.getPlayerName() + ":"); mcMMO.p.debug("Conversion report for " + profile.getPlayerName() + ":");
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) { for (SkillType skillType : SkillType.nonChildSkills()) {
int oldLevel = profile.getSkillLevel(skillType); int oldLevel = profile.getSkillLevel(skillType);
int oldXPLevel = profile.getSkillXpLevel(skillType); int oldXPLevel = profile.getSkillXpLevel(skillType);
int totalOldXP = mcMMO.getFormulaManager().calculateTotalExperience(oldLevel, oldXPLevel); int totalOldXP = mcMMO.getFormulaManager().calculateTotalExperience(oldLevel, oldXPLevel);

View File

@@ -1,39 +0,0 @@
package com.gmail.nossr50.runnables.database;
import java.lang.ref.WeakReference;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.database.SQLDatabaseManager;
/**
* This task is in charge of sending a MySQL ping over the MySQL connection
* every hour to prevent the connection from timing out and losing players'
* data when they join.
* <p/>
* A WeakReference is used to keep the database instance, because
* {@link com.gmail.nossr50.commands.database.ConvertDatabaseCommand database
* conversion} may create a SQLDatabaseManager that will be thrown out. If a
* normal reference was used, the conversion would cause a combined data and
* resource leak through this task.
*/
public class SQLDatabaseKeepaliveTask extends BukkitRunnable {
WeakReference<SQLDatabaseManager> databaseInstance;
public SQLDatabaseKeepaliveTask(SQLDatabaseManager dbman) {
databaseInstance = new WeakReference<SQLDatabaseManager>(dbman);
}
public void run() {
SQLDatabaseManager dbman = databaseInstance.get();
if (dbman != null) {
dbman.checkConnected();
}
else {
// This happens when the database was started for a conversion,
// or discarded by its creator for any other reason. If this code
// was not present, we would leak the connection resources.
this.cancel();
}
}
}

View File

@@ -4,11 +4,11 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.commands.party.teleport.PtpCommand;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
@@ -58,6 +58,6 @@ public class TeleportationWarmup extends BukkitRunnable {
} }
} }
EventUtils.handlePartyTeleportEvent(teleportingPlayer, targetPlayer); PtpCommand.handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
} }
} }

View File

@@ -1,14 +0,0 @@
package com.gmail.nossr50.runnables.player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
public class PowerLevelUpdatingTask extends BukkitRunnable {
@Override
public void run() {
if (!ScoreboardManager.powerLevelHeartbeat()) {
this.cancel();
}
}
}

View File

@@ -0,0 +1,27 @@
package com.gmail.nossr50.runnables.scoreboards;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Scoreboard;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
public class ScoreboardChangeTask extends BukkitRunnable {
private Player player;
private Scoreboard oldScoreboard;
public ScoreboardChangeTask(Player player, Scoreboard oldScoreboard) {
this.player = player;
this.oldScoreboard = oldScoreboard;
}
@Override
public void run() {
if (player.isOnline()) {
player.setScoreboard(oldScoreboard);
ScoreboardManager.enablePowerLevelDisplay(player);
}
ScoreboardManager.clearPendingTask(player.getName());
}
}

View File

@@ -7,7 +7,8 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.ParticleEffectUtils; import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.skills.PerksUtils;
@@ -46,7 +47,8 @@ public class AbilityDisableTask extends BukkitRunnable {
break; break;
} }
EventUtils.callAbilityDeactivateEvent(player, ability); McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, SkillType.byAbility(ability));
mcMMO.p.getServer().getPluginManager().callEvent(event);
mcMMOPlayer.setAbilityMode(ability, false); mcMMOPlayer.setAbilityMode(ability, false);
mcMMOPlayer.setAbilityInformed(ability, false); mcMMOPlayer.setAbilityInformed(ability, false);

View File

@@ -14,7 +14,7 @@ public class KrakenAttackTask extends BukkitRunnable {
private Creature kraken; private Creature kraken;
private Player player; private Player player;
private Location location; private Location location;
private final boolean GLOBAL_EFFECTS = AdvancedConfig.getInstance().getKrakenGlobalEffectsEnabled(); private final boolean GLOBAL_SOUNDS = AdvancedConfig.getInstance().getKrakenGlobalSoundsEnabled();
private final String DEFEAT_MESSAGE = AdvancedConfig.getInstance().getPlayerDefeatMessage(); private final String DEFEAT_MESSAGE = AdvancedConfig.getInstance().getPlayerDefeatMessage();
private final String ESCAPE_MESSAGE = AdvancedConfig.getInstance().getPlayerEscapeMessage(); private final String ESCAPE_MESSAGE = AdvancedConfig.getInstance().getPlayerEscapeMessage();
@@ -37,7 +37,16 @@ public class KrakenAttackTask extends BukkitRunnable {
if (player.isValid() && playerLocation.getBlock().isLiquid()) { if (player.isValid() && playerLocation.getBlock().isLiquid()) {
World world = player.getWorld(); World world = player.getWorld();
krakenAttack(playerLocation, world); player.damage(AdvancedConfig.getInstance().getKrakenAttackDamage(), kraken);
if (GLOBAL_SOUNDS) {
world.playSound(playerLocation, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
}
else {
player.playSound(playerLocation, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
}
world.strikeLightningEffect(playerLocation);
} }
else { else {
player.sendMessage(AdvancedConfig.getInstance().getPlayerEscapeMessage()); player.sendMessage(AdvancedConfig.getInstance().getPlayerEscapeMessage());
@@ -74,24 +83,20 @@ public class KrakenAttackTask extends BukkitRunnable {
World world = player.getWorld(); World world = player.getWorld();
kraken.teleport(player); kraken.teleport(player);
krakenAttack(location, world); player.damage(AdvancedConfig.getInstance().getKrakenAttackDamage(), kraken);
if (GLOBAL_SOUNDS) {
world.playSound(location, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
}
else {
player.playSound(location, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
}
world.strikeLightningEffect(location);
} }
else { else {
kraken.remove(); kraken.remove();
cancel(); cancel();
} }
} }
private void krakenAttack(Location playerLocation, World world) {
player.damage(AdvancedConfig.getInstance().getKrakenAttackDamage(), kraken);
if (GLOBAL_EFFECTS) {
world.playSound(playerLocation, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
world.strikeLightningEffect(playerLocation);
}
else {
player.playSound(playerLocation, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
world.createExplosion(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ(), 0F, false, false);
}
}
} }

View File

@@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.acrobatics;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
public final class Acrobatics { public final class Acrobatics {
public static int dodgeMaxBonusLevel = AdvancedConfig.getInstance().getDodgeMaxBonusLevel(); public static int dodgeMaxBonusLevel = AdvancedConfig.getInstance().getDodgeMaxBonusLevel();
@@ -17,12 +16,11 @@ public final class Acrobatics {
public static double gracefulRollThreshold = AdvancedConfig.getInstance().getGracefulRollDamageThreshold(); public static double gracefulRollThreshold = AdvancedConfig.getInstance().getGracefulRollDamageThreshold();
public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax(); public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax();
public static int dodgeXpModifier = ExperienceConfig.getInstance().getDodgeXPModifier(); public static int dodgeXpModifier = AdvancedConfig.getInstance().getDodgeXPModifier();
public static int rollXpModifier = ExperienceConfig.getInstance().getRollXPModifier(); public static int rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier();
public static int fallXpModifier = ExperienceConfig.getInstance().getFallXPModifier(); public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier();
public static double featherFallXPModifier = ExperienceConfig.getInstance().getFeatherFallXPModifier();
public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled();
public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled(); public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled();
private Acrobatics() {}; private Acrobatics() {};

View File

@@ -1,14 +1,10 @@
package com.gmail.nossr50.skills.acrobatics; package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LightningStrike; import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@@ -20,15 +16,14 @@ import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class AcrobaticsManager extends SkillManager { public class AcrobaticsManager extends SkillManager {
private int fallTries = 0;
Location lastFallLocation;
public AcrobaticsManager(McMMOPlayer mcMMOPlayer) { public AcrobaticsManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.ACROBATICS); super(mcMMOPlayer, SkillType.ACROBATICS);
} }
public boolean canRoll() { public boolean canRoll() {
return !exploitPrevention() && Permissions.roll(getPlayer()); Player player = getPlayer();
return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player);
} }
public boolean canDodge(Entity damager) { public boolean canDodge(Entity damager) {
@@ -88,16 +83,14 @@ public class AcrobaticsManager extends SkillManager {
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.rollMaxChance, Acrobatics.rollMaxBonusLevel)) { if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.rollMaxChance, Acrobatics.rollMaxBonusLevel)) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text")); player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
applyXpGain(calculateRollXP(damage, true)); applyXpGain((float) (damage * Acrobatics.rollXpModifier));
return modifiedDamage; return modifiedDamage;
} }
else if (!isFatal(damage)) { else if (!isFatal(damage)) {
applyXpGain(calculateRollXP(damage, false)); applyXpGain((float) (damage * Acrobatics.fallXpModifier));
} }
lastFallLocation = player.getLocation();
return damage; return damage;
} }
@@ -112,44 +105,17 @@ public class AcrobaticsManager extends SkillManager {
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.gracefulRollMaxChance, Acrobatics.gracefulRollMaxBonusLevel)) { if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.gracefulRollMaxChance, Acrobatics.gracefulRollMaxBonusLevel)) {
getPlayer().sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc")); getPlayer().sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
applyXpGain(calculateRollXP(damage, true)); applyXpGain((float) (damage * Acrobatics.rollXpModifier));
return modifiedDamage; return modifiedDamage;
} }
else if (!isFatal(damage)) { else if (!isFatal(damage)) {
applyXpGain(calculateRollXP(damage, false)); applyXpGain((float) (damage * Acrobatics.fallXpModifier));
} }
return damage; return damage;
} }
/**
* Check if the player is "farming" Acrobatics XP using
* exploits in the game.
*
* @return true if exploits are detected, false otherwise
*/
public boolean exploitPrevention() {
if (!Config.getInstance().getAcrobaticsPreventAFK()) {
return false;
}
Player player = getPlayer();
if (player.getItemInHand().getType() == Material.ENDER_PEARL || player.isInsideVehicle()) {
return true;
}
Location fallLocation = player.getLocation();
boolean sameLocation = (lastFallLocation != null && Misc.isNear(lastFallLocation, fallLocation, 2));
fallTries = sameLocation ? fallTries + 1 : Math.max(fallTries - 1, 0);
lastFallLocation = fallLocation;
return fallTries > Config.getInstance().getAcrobaticsAFKMaxTries();
}
private boolean isSuccessfulRoll(double maxChance, int maxLevel) { private boolean isSuccessfulRoll(double maxChance, int maxLevel) {
return (maxChance / maxLevel) * Math.min(getSkillLevel(), maxLevel) > Misc.getRandom().nextInt(activationChance); return (maxChance / maxLevel) * Math.min(getSkillLevel(), maxLevel) > Misc.getRandom().nextInt(activationChance);
} }
@@ -157,15 +123,4 @@ public class AcrobaticsManager extends SkillManager {
private boolean isFatal(double damage) { private boolean isFatal(double damage) {
return getPlayer().getHealth() - damage < 1; return getPlayer().getHealth() - damage < 1;
} }
private float calculateRollXP(double damage, boolean isRoll) {
ItemStack boots = getPlayer().getInventory().getBoots();
float xp = (float) (damage * (isRoll ? Acrobatics.rollXpModifier : Acrobatics.fallXpModifier));
if (boots != null && boots.containsEnchantment(Enchantment.PROTECTION_FALL)) {
xp *= Acrobatics.featherFallXPModifier;
}
return xp;
}
} }

View File

@@ -104,7 +104,7 @@ public class AxesManager extends SkillManager {
short maxDurability = mcMMO.getRepairableManager().isRepairable(armorType) ? mcMMO.getRepairableManager().getRepairable(armorType).getMaximumDurability() : armorType.getMaxDurability(); short maxDurability = mcMMO.getRepairableManager().isRepairable(armorType) ? mcMMO.getRepairableManager().getRepairable(armorType).getMaximumDurability() : armorType.getMaxDurability();
double maxDurabilityDamage = maxDurability * Axes.impactMaxDurabilityModifier; double maxDurabilityDamage = maxDurability * Axes.impactMaxDurabilityModifier;
SkillUtils.handleDurabilityChange(armor, (int) Math.min(modifiedDurabilityDamage, maxDurabilityDamage)); armor.setDurability((short) (Math.min(modifiedDurabilityDamage, maxDurabilityDamage) + armor.getDurability()));
} }
} }
} }

View File

@@ -20,7 +20,7 @@ public class ChildConfig extends AutoUpdateConfigLoader {
FamilyTree.clearRegistrations(); // when reloading, need to clear statics FamilyTree.clearRegistrations(); // when reloading, need to clear statics
for (SkillType skill : SkillType.CHILD_SKILLS) { for (SkillType skill : SkillType.childSkills()) {
plugin.debug("Finding parents of " + skill.name()); plugin.debug("Finding parents of " + skill.name());
EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class); EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class);

View File

@@ -15,15 +15,27 @@ import com.gmail.nossr50.util.Misc;
public final class Fishing { public final class Fishing {
// The order of the values is extremely important, a few methods depend on it to work properly // The order of the values is extremely important, a few methods depend on it to work properly
public enum Tier { protected enum Tier {
EIGHT(8), FIVE(5) {
SEVEN(7), @Override public int getLevel() { return AdvancedConfig.getInstance().getFishingTierLevelsTier5(); }
SIX(6), @Override public double getShakeChance() { return AdvancedConfig.getInstance().getShakeChanceRank5(); }
FIVE(5), @Override public int getVanillaXPBoostModifier() { return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank5(); }},
FOUR(4), FOUR(4) {
THREE(3), @Override public int getLevel() { return AdvancedConfig.getInstance().getFishingTierLevelsTier4(); }
TWO(2), @Override public double getShakeChance() { return AdvancedConfig.getInstance().getShakeChanceRank4(); }
ONE(1); @Override public int getVanillaXPBoostModifier() { return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank4(); }},
THREE(3) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getFishingTierLevelsTier3(); }
@Override public double getShakeChance() { return AdvancedConfig.getInstance().getShakeChanceRank3(); }
@Override public int getVanillaXPBoostModifier() { return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank3(); }},
TWO(2) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getFishingTierLevelsTier2(); }
@Override public double getShakeChance() { return AdvancedConfig.getInstance().getShakeChanceRank2(); }
@Override public int getVanillaXPBoostModifier() { return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank2(); }},
ONE(1) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getFishingTierLevelsTier1(); }
@Override public double getShakeChance() { return AdvancedConfig.getInstance().getShakeChanceRank1(); }
@Override public int getVanillaXPBoostModifier() { return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank1(); }};
int numerical; int numerical;
@@ -35,17 +47,9 @@ public final class Fishing {
return numerical; return numerical;
} }
protected int getLevel() { abstract protected int getLevel();
return AdvancedConfig.getInstance().getFishingTierLevel(this); abstract protected double getShakeChance();
} abstract protected int getVanillaXPBoostModifier();
protected double getShakeChance() {
return AdvancedConfig.getInstance().getShakeChance(this);
}
protected int getVanillaXPBoostModifier() {
return AdvancedConfig.getInstance().getFishingVanillaXPModifier(this);
}
} }
protected static final HashMap<Material, List<Enchantment>> ENCHANTABLE_CACHE = new HashMap<Material, List<Enchantment>>(); protected static final HashMap<Material, List<Enchantment>> ENCHANTABLE_CACHE = new HashMap<Material, List<Enchantment>>();

View File

@@ -26,14 +26,10 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep; import org.bukkit.entity.Sheep;
import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.TNTPrimed; import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Wool; import org.bukkit.material.Wool;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType;
import org.bukkit.util.Vector;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
@@ -42,18 +38,18 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Rarity;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure; import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakePlayerFishEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.KrakenAttackTask; import com.gmail.nossr50.runnables.skills.KrakenAttackTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.fishing.Fishing.Tier; import com.gmail.nossr50.skills.fishing.Fishing.Tier;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@@ -66,18 +62,17 @@ public class FishingManager extends SkillManager {
private int fishingTries = 0; private int fishingTries = 0;
private long fishingTimestamp = 0L; private long fishingTimestamp = 0L;
private Location fishingTarget; private Location fishingTarget;
private Item fishingCatch;
public FishingManager(McMMOPlayer mcMMOPlayer) { public FishingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.FISHING); super(mcMMOPlayer, SkillType.FISHING);
} }
public boolean canShake(Entity target) { public boolean canShake(Entity target) {
return target instanceof LivingEntity && getSkillLevel() >= Tier.ONE.getLevel() && Permissions.shake(getPlayer()); return target instanceof LivingEntity && getSkillLevel() >= AdvancedConfig.getInstance().getShakeUnlockLevel() && Permissions.shake(getPlayer());
} }
public boolean canMasterAngler() { public boolean canMasterAngler() {
return getSkillLevel() >= AdvancedConfig.getInstance().getMasterAnglerUnlockLevel() && Permissions.masterAngler(getPlayer()); return Permissions.masterAngler(getPlayer());
} }
public boolean unleashTheKraken() { public boolean unleashTheKraken() {
@@ -103,31 +98,31 @@ public class FishingManager extends SkillManager {
player.teleport(player.getTargetBlock(null, 100).getLocation(), TeleportCause.PLUGIN); player.teleport(player.getTargetBlock(null, 100).getLocation(), TeleportCause.PLUGIN);
Location location = player.getLocation();
world.strikeLightningEffect(location);
world.strikeLightningEffect(location);
world.strikeLightningEffect(location);
String unleashMessage = AdvancedConfig.getInstance().getPlayerUnleashMessage(); String unleashMessage = AdvancedConfig.getInstance().getPlayerUnleashMessage();
if (!unleashMessage.isEmpty()) { if (!unleashMessage.isEmpty()) {
player.sendMessage(unleashMessage); player.sendMessage(unleashMessage);
} }
Location location = player.getLocation(); if (AdvancedConfig.getInstance().getKrakenGlobalSoundsEnabled()) {
boolean globalEffectsEnabled = AdvancedConfig.getInstance().getKrakenGlobalEffectsEnabled();
if (globalEffectsEnabled) {
world.strikeLightningEffect(location);
world.strikeLightningEffect(location);
world.strikeLightningEffect(location);
world.playSound(location, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch()); world.playSound(location, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
mcMMO.p.getServer().broadcastMessage(ChatColor.RED + AdvancedConfig.getInstance().getServerUnleashMessage().replace("(PLAYER)", player.getDisplayName()));
} }
else { else {
world.createExplosion(location.getX(), location.getY(), location.getZ(), 0F, false, false);
world.createExplosion(location.getX(), location.getY(), location.getZ(), 0F, false, false);
world.createExplosion(location.getX(), location.getY(), location.getZ(), 0F, false, false);
player.playSound(location, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch()); player.playSound(location, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
} }
String globalMessage = AdvancedConfig.getInstance().getServerUnleashMessage();
if (!globalMessage.isEmpty()) {
mcMMO.p.getServer().broadcastMessage(ChatColor.RED + AdvancedConfig.getInstance().getServerUnleashMessage().replace("(PLAYER)", player.getDisplayName()));
}
if (player.getItemInHand().getType() == Material.FISHING_ROD) { if (player.getItemInHand().getType() == Material.FISHING_ROD) {
player.setItemInHand(null); player.setItemInHand(null);
} }
@@ -208,7 +203,10 @@ public class FishingManager extends SkillManager {
return false; return false;
} }
return EventUtils.simulateBlockBreak(block, player, false); FakeBlockBreakEvent blockBreakEvent = new FakeBlockBreakEvent(block, player);
mcMMO.p.getServer().getPluginManager().callEvent(blockBreakEvent);
return !blockBreakEvent.isCancelled();
} }
/** /**
@@ -248,9 +246,8 @@ public class FishingManager extends SkillManager {
/** /**
* Handle the Fisherman's Diet ability * Handle the Fisherman's Diet ability
* *
* @param rankChange The # of levels to change rank for the food * @param rankChange The # of levels to change rank for the food
* @param eventFoodLevel The initial change in hunger from the event * @param eventFoodLevel The initial change in hunger from the event
*
* @return the modified change in hunger for the event * @return the modified change in hunger for the event
*/ */
public int handleFishermanDiet(int rankChange, int eventFoodLevel) { public int handleFishermanDiet(int rankChange, int eventFoodLevel) {
@@ -272,23 +269,20 @@ public class FishingManager extends SkillManager {
} }
// Recast in the new spot // Recast in the new spot
EventUtils.callFakeFishEvent(getPlayer(), hook); mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerFishEvent(getPlayer(), null, hook, PlayerFishEvent.State.FISHING));
} }
public void masterAngler(Fish hook) { public void masterAngler(Fish hook) {
Player player = getPlayer(); Player player = getPlayer();
Location location = hook.getLocation(); Biome biome = player.getLocation().getBlock().getBiome();
Biome biome = location.getBlock().getBiome(); double biteChance = Math.min(hook.getBiteChance() * Math.max((getSkillLevel() / 200.0), 1.0), 1.0);
double biteChance = hook.getBiteChance();
mcMMOPlayer.setHookLocation(location);
if (biome == Biome.RIVER || biome == Biome.OCEAN) { if (biome == Biome.RIVER || biome == Biome.OCEAN) {
biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier(); biteChance = biteChance * 2.0;
} }
if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) { if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) {
biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBoatModifier(); biteChance = biteChance * 2.0;
} }
hook.setBiteChance(biteChance); hook.setBiteChance(biteChance);
@@ -300,33 +294,37 @@ public class FishingManager extends SkillManager {
* @param fishingCatch The {@link Item} initially caught * @param fishingCatch The {@link Item} initially caught
*/ */
public void handleFishing(Item fishingCatch) { public void handleFishing(Item fishingCatch) {
this.fishingCatch = fishingCatch;
int treasureXp = 0; int treasureXp = 0;
Player player = getPlayer(); Player player = getPlayer();
FishingTreasure treasure = null; FishingTreasure treasure = null;
if (Config.getInstance().getFishingDropsEnabled() && Permissions.fishingTreasureHunter(player)) { if (Config.getInstance().getFishingDropsEnabled() && Permissions.fishingTreasureHunter(player)) {
treasure = getFishingTreasure(); treasure = getFishingTreasure();
this.fishingCatch = null;
} }
if (treasure != null) { if (treasure != null) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.ItemFound")); player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
treasureXp = treasure.getXp();
ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay? ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
McMMOPlayerFishingTreasureEvent event;
Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>(); Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>();
if (Permissions.magicHunter(player) && ItemUtils.isEnchantable(treasureDrop)) { if (Permissions.magicHunter(player) && ItemUtils.isEnchantable(treasureDrop)) {
enchants = handleMagicHunter(treasureDrop); enchants = handleMagicHunter(treasureDrop);
} event = new McMMOPlayerMagicHunterEvent(player, treasureDrop, treasureXp, enchants);
McMMOPlayerFishingTreasureEvent event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
if (!event.isCancelled()) {
treasureDrop = event.getTreasure();
treasureXp = event.getXp();
} }
else { else {
event = new McMMOPlayerFishingTreasureEvent(player, treasureDrop, treasureXp);
}
mcMMO.p.getServer().getPluginManager().callEvent(event);
treasureDrop = event.getTreasure();
treasureXp = event.getXp();
if (event.isCancelled()) {
treasureDrop = null; treasureDrop = null;
treasureXp = 0; treasureXp = 0;
} }
@@ -341,9 +339,10 @@ public class FishingManager extends SkillManager {
} }
if (enchanted) { if (enchanted) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.MagicFound")); player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
} }
Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
fishingCatch.setItemStack(treasureDrop); fishingCatch.setItemStack(treasureDrop);
} }
} }
@@ -355,7 +354,6 @@ public class FishingManager extends SkillManager {
* Handle the vanilla XP boost for Fishing * Handle the vanilla XP boost for Fishing
* *
* @param experience The amount of experience initially awarded by the event * @param experience The amount of experience initially awarded by the event
*
* @return the modified event damage * @return the modified event damage
*/ */
public int handleVanillaXpBoost(int experience) { public int handleVanillaXpBoost(int experience) {
@@ -432,7 +430,6 @@ public class FishingManager extends SkillManager {
Misc.dropItem(target.getLocation(), drop); Misc.dropItem(target.getLocation(), drop);
CombatUtils.dealDamage(target, Math.max(target.getMaxHealth() / 4, 1)); // 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.
applyXpGain(ExperienceConfig.getInstance().getFishingShakeXP());
} }
} }
@@ -442,36 +439,28 @@ public class FishingManager extends SkillManager {
* @return The {@link FishingTreasure} found, or null if no treasure was found. * @return The {@link FishingTreasure} found, or null if no treasure was found.
*/ */
private FishingTreasure getFishingTreasure() { private FishingTreasure getFishingTreasure() {
double diceRoll = Misc.getRandom().nextDouble() * 100; List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
FishingTreasure treasure = null; int skillLevel = getSkillLevel();
for (Rarity rarity : Rarity.values()) { for (FishingTreasure treasure : TreasureConfig.getInstance().fishingRewards) {
double dropRate = TreasureConfig.getInstance().getItemDropRate(getLootTier(), rarity); int maxLevel = treasure.getMaxLevel();
if (diceRoll <= dropRate) { if (treasure.getDropLevel() <= skillLevel && (maxLevel >= skillLevel || maxLevel <= 0)) {
if (rarity == Rarity.TRAP) { rewards.add(treasure);
handleTraps();
break;
}
List<FishingTreasure> fishingTreasures = TreasureConfig.getInstance().fishingRewards.get(rarity);
if (fishingTreasures.isEmpty()) {
return null;
}
treasure = fishingTreasures.get(Misc.getRandom().nextInt(fishingTreasures.size()));
break;
} }
diceRoll -= dropRate;
} }
if (treasure == null) { if (rewards.isEmpty()) {
return null; return null;
} }
FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
ItemStack treasureDrop = treasure.getDrop(); ItemStack treasureDrop = treasure.getDrop();
if (!SkillUtils.treasureDropSuccessful(treasure.getDropChance(), activationChance)) {
return null;
}
short maxDurability = treasureDrop.getType().getMaxDurability(); short maxDurability = treasureDrop.getType().getMaxDurability();
if (maxDurability > 0) { if (maxDurability > 0) {
@@ -481,92 +470,41 @@ public class FishingManager extends SkillManager {
return treasure; return treasure;
} }
private void handleTraps() {
Player player = getPlayer();
if (Misc.getRandom().nextBoolean()) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Boom"));
TNTPrimed tnt = (TNTPrimed) player.getWorld().spawnEntity(fishingCatch.getLocation(), EntityType.PRIMED_TNT);
fishingCatch.setPassenger(tnt);
Vector velocity = fishingCatch.getVelocity();
double magnitude = velocity.length();
fishingCatch.setVelocity(velocity.multiply((magnitude + 1) / magnitude));
tnt.setMetadata(mcMMO.tntsafeMetadataKey, mcMMO.metadataValue);
tnt.setFuseTicks(3 * Misc.TICK_CONVERSION_FACTOR);
}
else {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Poison"));
ThrownPotion thrownPotion = player.getWorld().spawn(fishingCatch.getLocation(), ThrownPotion.class);
thrownPotion.setItem(new Potion(PotionType.POISON).splash().toItemStack(1));
fishingCatch.setPassenger(thrownPotion);
}
}
/** /**
* Process the Magic Hunter ability * Process the Magic Hunter ability
* *
* @param treasureDrop The {@link ItemStack} to enchant * @param treasureDrop The {@link ItemStack} to enchant
*
* @return true if the item has been enchanted * @return true if the item has been enchanted
*/ */
private Map<Enchantment, Integer> handleMagicHunter(ItemStack treasureDrop) { private Map<Enchantment, Integer> handleMagicHunter(ItemStack treasureDrop) {
Player player = getPlayer();
int activationChance = this.activationChance;
if (player.getWorld().hasStorm()) {
activationChance *= Fishing.STORM_MODIFIER;
}
Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>(); Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>();
List<EnchantmentTreasure> fishingEnchantments = null;
double diceRoll = Misc.getRandom().nextDouble() * 100; if (Misc.getRandom().nextInt(activationChance) > getLootTier() * AdvancedConfig.getInstance().getFishingMagicMultiplier()) {
for (Rarity rarity : Rarity.values()) {
if (rarity == Rarity.TRAP || rarity == Rarity.RECORD) {
continue;
}
double dropRate = TreasureConfig.getInstance().getEnchantmentDropRate(getLootTier(), rarity);
if (diceRoll <= dropRate) {
fishingEnchantments = TreasureConfig.getInstance().fishingEnchantments.get(rarity);
break;
}
diceRoll -= dropRate;
}
if (fishingEnchantments == null) {
return enchants; return enchants;
} }
List<Enchantment> validEnchantments = getPossibleEnchantments(treasureDrop); List<Enchantment> possibleEnchantments = getPossibleEnchantments(treasureDrop);
List<EnchantmentTreasure> possibleEnchants = new ArrayList<EnchantmentTreasure>();
for (EnchantmentTreasure enchantmentTreasure : fishingEnchantments) {
if (validEnchantments.contains(enchantmentTreasure.getEnchantment())) {
possibleEnchants.add(enchantmentTreasure);
}
}
if (possibleEnchants.isEmpty()) {
return enchants;
}
// This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant // This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant
Collections.shuffle(possibleEnchants, Misc.getRandom()); Collections.shuffle(possibleEnchantments, Misc.getRandom());
int specificChance = 1; int specificChance = 1;
for (EnchantmentTreasure enchantmentTreasure : possibleEnchants) { for (Enchantment possibleEnchantment : possibleEnchantments) {
Enchantment possibleEnchantment = enchantmentTreasure.getEnchantment();
if (treasureDrop.getItemMeta().hasConflictingEnchant(possibleEnchantment) || Misc.getRandom().nextInt(specificChance) != 0) { if (treasureDrop.getItemMeta().hasConflictingEnchant(possibleEnchantment) || Misc.getRandom().nextInt(specificChance) != 0) {
continue; continue;
} }
enchants.put(possibleEnchantment, enchantmentTreasure.getLevel()); enchants.put(possibleEnchantment, Math.max(Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1, possibleEnchantment.getStartLevel()));
specificChance *= 2; specificChance++;
} }
return enchants; return enchants;

View File

@@ -0,0 +1,77 @@
package com.gmail.nossr50.skills.herbalism;
import java.util.Map;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.Permissions;
import com.google.common.collect.Maps;
public enum HerbalismBlock {
BROWN_MUSHROOM(Material.BROWN_MUSHROOM),
CACTUS(Material.CACTUS),
CARROT(Material.CARROT, Material.CARROT_ITEM),
COCOA(Material.COCOA, new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData())),
CROPS(Material.CROPS, Material.WHEAT),
MELON_BLOCK(Material.MELON_BLOCK, Material.MELON),
NETHER_WARTS(Material.NETHER_WARTS, Material.NETHER_STALK),
POTATO(Material.POTATO, Material.POTATO_ITEM),
PUMPKIN(Material.PUMPKIN),
RED_MUSHROOM(Material.RED_MUSHROOM),
RED_ROSE(Material.RED_ROSE),
SUGAR_CANE_BLOCK(Material.SUGAR_CANE_BLOCK, Material.SUGAR_CANE),
VINE(Material.VINE),
WATER_LILY(Material.WATER_LILY),
YELLOW_FLOWER(Material.YELLOW_FLOWER);
private Material blockType;
private ItemStack dropItem;
private final static Map<Material, HerbalismBlock> BY_MATERIAL = Maps.newHashMap();
private HerbalismBlock(Material blockType) {
this(blockType, new ItemStack(blockType));
}
private HerbalismBlock(Material blockType, Material dropType) {
this(blockType, new ItemStack(dropType));
}
private HerbalismBlock(Material blockType, ItemStack dropItem) {
this.blockType = blockType;
this.dropItem = dropItem;
}
static {
for (HerbalismBlock herbalismBlock : values()) {
BY_MATERIAL.put(herbalismBlock.blockType, herbalismBlock);
}
}
public ItemStack getDropItem() {
return dropItem;
}
public int getXpGain() {
return ExperienceConfig.getInstance().getXp(SkillType.HERBALISM, blockType);
}
public boolean canDoubleDrop() {
return Config.getInstance().getDoubleDropsEnabled(SkillType.HERBALISM, blockType);
}
public boolean hasGreenThumbPermission(Player player) {
return Permissions.greenThumbPlant(player, blockType);
}
public static HerbalismBlock getHerbalismBlock(Material blockType) {
return BY_MATERIAL.get(blockType);
}
}

View File

@@ -1,7 +1,6 @@
package com.gmail.nossr50.skills.herbalism; package com.gmail.nossr50.skills.herbalism;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.bukkit.CropState; import org.bukkit.CropState;
@@ -18,7 +17,6 @@ import org.bukkit.material.NetherWarts;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@@ -30,7 +28,6 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask; import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils; import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@@ -43,7 +40,7 @@ public class HerbalismManager extends SkillManager {
} }
public boolean canBlockCheck() { public boolean canBlockCheck() {
return !(Config.getInstance().getHerbalismPreventAFK() && getPlayer().isInsideVehicle()); return !(Config.getInstance().getHerbalismAFKDisabled() && getPlayer().isInsideVehicle());
} }
public boolean canGreenThumbBlock(BlockState blockState) { public boolean canGreenThumbBlock(BlockState blockState) {
@@ -119,7 +116,6 @@ public class HerbalismManager extends SkillManager {
* @param blockState The {@link BlockState} to check ability activation for * @param blockState The {@link BlockState} to check ability activation for
*/ */
public void herbalismBlockCheck(BlockState blockState) { public void herbalismBlockCheck(BlockState blockState) {
Player player = getPlayer();
Material material = blockState.getType(); Material material = blockState.getType();
boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.SUGAR_CANE_BLOCK); boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.SUGAR_CANE_BLOCK);
@@ -127,32 +123,21 @@ public class HerbalismManager extends SkillManager {
return; return;
} }
if (!canBlockCheck()) { HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(material);
return; ItemStack drop = null;
}
Collection<ItemStack> drops = null;
int amount = 1; int amount = 1;
int xp = 0; int xp = 0;
boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility()); boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility());
if (ModUtils.isCustomHerbalismBlock(blockState)) { if (herbalismBlock != null) {
CustomBlock customBlock = ModUtils.getCustomBlock(blockState); if (herbalismBlock.hasGreenThumbPermission(getPlayer())) {
xp = customBlock.getXpGain();
if (Permissions.doubleDrops(player, skill) && customBlock.isDoubleDropEnabled()) {
drops = blockState.getBlock().getDrops();
}
}
else {
if (Permissions.greenThumbPlant(player, material)) {
processGreenThumbPlants(blockState, greenTerra); processGreenThumbPlants(blockState, greenTerra);
} }
xp = ExperienceConfig.getInstance().getXp(skill, material); xp = herbalismBlock.getXpGain();
if (Config.getInstance().getDoubleDropsEnabled(skill, material) && Permissions.doubleDrops(player, skill)) { if (herbalismBlock.canDoubleDrop() && Permissions.doubleDrops(getPlayer(), skill)) {
drops = blockState.getBlock().getDrops(); drop = herbalismBlock.getDropItem();
} }
if (!oneBlockPlant) { if (!oneBlockPlant) {
@@ -160,18 +145,27 @@ public class HerbalismManager extends SkillManager {
xp *= amount; xp *= amount;
} }
} }
else {
CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
xp = customBlock.getXpGain();
if (Permissions.doubleDrops(getPlayer(), skill)) {
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
drop = customBlock.getItemDrop();
amount = Misc.getRandom().nextInt(maximumDropAmount - minimumDropAmount + 1) + minimumDropAmount;
}
}
applyXpGain(xp); applyXpGain(xp);
if (drops == null) { if (drop == null) {
return; return;
} }
for (int i = greenTerra ? 2 : 1; i != 0; i--) { for (int i = greenTerra ? 2 : 1; i != 0; i--) {
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.doubleDropsMaxChance, Herbalism.doubleDropsMaxLevel)) { if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.doubleDropsMaxChance, Herbalism.doubleDropsMaxLevel)) {
for (ItemStack item : drops) { Misc.dropItems(blockState.getLocation(), drop, amount);
Misc.dropItems(blockState.getLocation(), item, amount);
}
} }
} }
} }
@@ -229,16 +223,14 @@ public class HerbalismManager extends SkillManager {
return false; return false;
} }
Player player = getPlayer(); if (treasures.isEmpty()) {
if (treasures.isEmpty() || EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) {
return false; return false;
} }
blockState.setType(Material.AIR); blockState.setType(Material.AIR);
Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop()); Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck")); getPlayer().sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
return true; return true;
} }
@@ -283,28 +275,7 @@ public class HerbalismManager extends SkillManager {
private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) { private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) {
Player player = getPlayer(); Player player = getPlayer();
PlayerInventory playerInventory = player.getInventory(); PlayerInventory playerInventory = player.getInventory();
ItemStack seed = null; ItemStack seed = (blockState.getType() == Material.CROPS) ? new ItemStack(Material.SEEDS) : HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
switch (blockState.getType()) {
case CARROT:
seed = new ItemStack(Material.CARROT_ITEM);
break;
case CROPS:
seed = new ItemStack(Material.SEEDS);
break;
case NETHER_WARTS:
seed = new ItemStack(Material.NETHER_STALK);
break;
case POTATO:
seed = new ItemStack(Material.POTATO_ITEM);
break;
default:
break;
}
if (!playerInventory.containsAtLeast(seed, 1)) { if (!playerInventory.containsAtLeast(seed, 1)) {
return; return;

View File

@@ -7,15 +7,63 @@ import com.gmail.nossr50.config.Config;
public class BlastMining { public class BlastMining {
// The order of the values is extremely important, a few methods depend on it to work properly // The order of the values is extremely important, a few methods depend on it to work properly
public enum Tier { protected enum Tier {
EIGHT(8), EIGHT(8) {
SEVEN(7), @Override public int getLevel() { return AdvancedConfig.getInstance().getBlastMiningRank8(); }
SIX(6), @Override public double getBlastRadiusModifier() { return AdvancedConfig.getInstance().getBlastRadiusModifierRank8(); }
FIVE(5), @Override public double getOreBonus() { return AdvancedConfig.getInstance().getOreBonusRank8(); }
FOUR(4), @Override public double getDebrisReduction() { return AdvancedConfig.getInstance().getDebrisReductionRank8(); }
THREE(3), @Override public double getBlastDamageDecrease() { return AdvancedConfig.getInstance().getBlastDamageDecreaseRank8(); }
TWO(2), @Override public int getDropMultiplier() { return AdvancedConfig.getInstance().getDropMultiplierRank8(); }},
ONE(1); SEVEN(7) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getBlastMiningRank7(); }
@Override public double getBlastRadiusModifier() { return AdvancedConfig.getInstance().getBlastRadiusModifierRank7(); }
@Override public double getOreBonus() { return AdvancedConfig.getInstance().getOreBonusRank7(); }
@Override public double getDebrisReduction() { return AdvancedConfig.getInstance().getDebrisReductionRank7(); }
@Override public double getBlastDamageDecrease() { return AdvancedConfig.getInstance().getBlastDamageDecreaseRank7(); }
@Override public int getDropMultiplier() { return AdvancedConfig.getInstance().getDropMultiplierRank7(); }},
SIX(6) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getBlastMiningRank6(); }
@Override public double getBlastRadiusModifier() { return AdvancedConfig.getInstance().getBlastRadiusModifierRank6(); }
@Override public double getOreBonus() { return AdvancedConfig.getInstance().getOreBonusRank6(); }
@Override public double getDebrisReduction() { return AdvancedConfig.getInstance().getDebrisReductionRank6(); }
@Override public double getBlastDamageDecrease() { return AdvancedConfig.getInstance().getBlastDamageDecreaseRank6(); }
@Override public int getDropMultiplier() { return AdvancedConfig.getInstance().getDropMultiplierRank6(); }},
FIVE(5) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getBlastMiningRank5(); }
@Override public double getBlastRadiusModifier() { return AdvancedConfig.getInstance().getBlastRadiusModifierRank5(); }
@Override public double getOreBonus() { return AdvancedConfig.getInstance().getOreBonusRank5(); }
@Override public double getDebrisReduction() { return AdvancedConfig.getInstance().getDebrisReductionRank5(); }
@Override public double getBlastDamageDecrease() { return AdvancedConfig.getInstance().getBlastDamageDecreaseRank5(); }
@Override public int getDropMultiplier() { return AdvancedConfig.getInstance().getDropMultiplierRank5(); }},
FOUR(4) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getBlastMiningRank4(); }
@Override public double getBlastRadiusModifier() { return AdvancedConfig.getInstance().getBlastRadiusModifierRank4(); }
@Override public double getOreBonus() { return AdvancedConfig.getInstance().getOreBonusRank4(); }
@Override public double getDebrisReduction() { return AdvancedConfig.getInstance().getDebrisReductionRank4(); }
@Override public double getBlastDamageDecrease() { return AdvancedConfig.getInstance().getBlastDamageDecreaseRank4(); }
@Override public int getDropMultiplier() { return AdvancedConfig.getInstance().getDropMultiplierRank4(); }},
THREE(3) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getBlastMiningRank3(); }
@Override public double getBlastRadiusModifier() { return AdvancedConfig.getInstance().getBlastRadiusModifierRank3(); }
@Override public double getOreBonus() { return AdvancedConfig.getInstance().getOreBonusRank3(); }
@Override public double getDebrisReduction() { return AdvancedConfig.getInstance().getDebrisReductionRank3(); }
@Override public double getBlastDamageDecrease() { return AdvancedConfig.getInstance().getBlastDamageDecreaseRank3(); }
@Override public int getDropMultiplier() { return AdvancedConfig.getInstance().getDropMultiplierRank3(); }},
TWO(2) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getBlastMiningRank2(); }
@Override public double getBlastRadiusModifier() { return AdvancedConfig.getInstance().getBlastRadiusModifierRank2(); }
@Override public double getOreBonus() { return AdvancedConfig.getInstance().getOreBonusRank2(); }
@Override public double getDebrisReduction() { return AdvancedConfig.getInstance().getDebrisReductionRank2(); }
@Override public double getBlastDamageDecrease() { return AdvancedConfig.getInstance().getBlastDamageDecreaseRank2(); }
@Override public int getDropMultiplier() { return AdvancedConfig.getInstance().getDropMultiplierRank2(); }},
ONE(1) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getBlastMiningRank1(); }
@Override public double getBlastRadiusModifier() { return AdvancedConfig.getInstance().getBlastRadiusModifierRank1(); }
@Override public double getOreBonus() { return AdvancedConfig.getInstance().getOreBonusRank1(); }
@Override public double getDebrisReduction() { return AdvancedConfig.getInstance().getDebrisReductionRank1(); }
@Override public double getBlastDamageDecrease() { return AdvancedConfig.getInstance().getBlastDamageDecreaseRank1(); }
@Override public int getDropMultiplier() { return AdvancedConfig.getInstance().getDropMultiplierRank1(); }};
int numerical; int numerical;
@@ -27,29 +75,12 @@ public class BlastMining {
return numerical; return numerical;
} }
protected int getLevel() { abstract protected int getLevel();
return AdvancedConfig.getInstance().getBlastMiningRankLevel(this); abstract protected double getBlastRadiusModifier();
} abstract protected double getOreBonus();
abstract protected double getDebrisReduction();
protected double getBlastRadiusModifier() { abstract protected double getBlastDamageDecrease();
return AdvancedConfig.getInstance().getBlastRadiusModifier(this); abstract protected int getDropMultiplier();
}
protected double getOreBonus() {
return AdvancedConfig.getInstance().getOreBonus(this);
}
protected double getDebrisReduction() {
return AdvancedConfig.getInstance().getDebrisReduction(this);
}
protected double getBlastDamageDecrease() {
return AdvancedConfig.getInstance().getBlastDamageDecrease(this);
}
protected int getDropMultiplier() {
return AdvancedConfig.getInstance().getDropMultiplier(this);
}
} }
public static Material detonator = Config.getInstance().getDetonatorItem(); public static Material detonator = Config.getInstance().getDetonatorItem();

View File

@@ -1,5 +1,6 @@
package com.gmail.nossr50.skills.mining; package com.gmail.nossr50.skills.mining;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -7,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils; import com.gmail.nossr50.util.ModUtils;
@@ -24,13 +26,11 @@ public class Mining {
Material blockType = blockState.getType(); Material blockType = blockState.getType();
int xp = ExperienceConfig.getInstance().getXp(SkillType.MINING, blockType); int xp = ExperienceConfig.getInstance().getXp(SkillType.MINING, blockType);
if (xp == 0) { if (blockType == Material.GLOWING_REDSTONE_ORE) {
if (blockType == Material.GLOWING_REDSTONE_ORE) { xp = ExperienceConfig.getInstance().getXp(SkillType.MINING, Material.REDSTONE_ORE);
xp = ExperienceConfig.getInstance().getXp(SkillType.MINING, Material.REDSTONE_ORE); }
} else if (xp == 0 && ModUtils.isCustomMiningBlock(blockState)) {
else if (ModUtils.isCustomMiningBlock(blockState)) { xp = ModUtils.getCustomBlock(blockState).getXpGain();
xp = ModUtils.getCustomBlock(blockState).getXpGain();
}
} }
return xp; return xp;
@@ -86,7 +86,10 @@ public class Mining {
* @param blockState The {@link BlockState} to check ability activation for * @param blockState The {@link BlockState} to check ability activation for
*/ */
protected static void handleMiningDrops(BlockState blockState) { protected static void handleMiningDrops(BlockState blockState) {
switch (blockState.getType()) { Material blockType = blockState.getType();
Location location = blockState.getLocation();
switch (blockType) {
case COAL_ORE: case COAL_ORE:
case DIAMOND_ORE: case DIAMOND_ORE:
case EMERALD_ORE: case EMERALD_ORE:
@@ -99,21 +102,36 @@ public class Mining {
case MOSSY_COBBLESTONE: case MOSSY_COBBLESTONE:
case NETHERRACK: case NETHERRACK:
case OBSIDIAN: case OBSIDIAN:
case REDSTONE_ORE:
case SANDSTONE: case SANDSTONE:
case QUARTZ_ORE: case QUARTZ_ORE:
Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops()); for (ItemStack drop : blockState.getBlock().getDrops()) {
return; Misc.dropItem(location, drop);
case GLOWING_REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops());
} }
return; return;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
for (ItemStack drop : blockState.getBlock().getDrops()) {
Misc.dropItem(location, drop);
}
}
return;
default: default:
if (ModUtils.isCustomMiningBlock(blockState)) { if (ModUtils.isCustomMiningBlock(blockState)) {
Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops()); CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
ItemStack dropItem = customBlock.getItemDrop();
if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(location, dropItem, minimumDropAmount);
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
}
else {
Misc.dropItems(location, dropItem, minimumDropAmount);
}
} }
return; return;
} }

View File

@@ -14,6 +14,7 @@ import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@@ -21,9 +22,7 @@ import com.gmail.nossr50.runnables.skills.AbilityCooldownTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.mining.BlastMining.Tier; import com.gmail.nossr50.skills.mining.BlastMining.Tier;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
@@ -70,7 +69,7 @@ public class MiningManager extends SkillManager {
SkillUtils.handleDurabilityChange(getPlayer().getItemInHand(), Config.getInstance().getAbilityToolDamage()); SkillUtils.handleDurabilityChange(getPlayer().getItemInHand(), Config.getInstance().getAbilityToolDamage());
} }
if ((ModUtils.isCustomMiningBlock(blockState) && !ModUtils.getCustomBlock(blockState).isDoubleDropEnabled()) || material != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(skill, material)) { if (material != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(skill, material)) {
return; return;
} }
@@ -95,7 +94,7 @@ public class MiningManager extends SkillManager {
Player player = getPlayer(); Player player = getPlayer();
Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE); Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
if (targetBlock.getType() != Material.TNT || !EventUtils.simulateBlockBreak(targetBlock, player, true) || !blastMiningCooldownOver()) { if (targetBlock.getType() != Material.TNT || !SkillUtils.blockBreakSimulate(targetBlock, player, true) || !blastMiningCooldownOver()) {
return; return;
} }
@@ -285,10 +284,12 @@ public class MiningManager extends SkillManager {
} }
private boolean blastMiningCooldownOver() { private boolean blastMiningCooldownOver() {
int timeRemaining = mcMMOPlayer.calculateTimeRemaining(AbilityType.BLAST_MINING); Player player = getPlayer();
PlayerProfile profile = getProfile();
int timeRemaining = SkillUtils.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player);
if (timeRemaining > 0) { if (timeRemaining > 0) {
getPlayer().sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining)); player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
return false; return false;
} }

View File

@@ -4,15 +4,23 @@ import com.gmail.nossr50.config.AdvancedConfig;
public class ArcaneForging { public class ArcaneForging {
// The order of the values is extremely important, a few methods depend on it to work properly // The order of the values is extremely important, a few methods depend on it to work properly
public enum Tier { protected enum Tier {
EIGHT(8), FOUR(4) {
SEVEN(7), @Override public int getLevel() { return AdvancedConfig.getInstance().getArcaneForgingRankLevels4(); }
SIX(6), @Override public double getKeepEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChanceRank4(); }
FIVE(5), @Override public double getDowngradeEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingDowngradeChanceRank4(); }},
FOUR(4), THREE(3) {
THREE(3), @Override public int getLevel() { return AdvancedConfig.getInstance().getArcaneForgingRankLevels3(); }
TWO(2), @Override public double getKeepEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChanceRank3(); }
ONE(1); @Override public double getDowngradeEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingDowngradeChanceRank3(); }},
TWO(2) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getArcaneForgingRankLevels2(); }
@Override public double getKeepEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChanceRank2(); }
@Override public double getDowngradeEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingDowngradeChanceRank2(); }},
ONE(1) {
@Override public int getLevel() { return AdvancedConfig.getInstance().getArcaneForgingRankLevels1(); }
@Override public double getKeepEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChanceRank1(); }
@Override public double getDowngradeEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingDowngradeChanceRank1(); }};
int numerical; int numerical;
@@ -24,17 +32,9 @@ public class ArcaneForging {
return numerical; return numerical;
} }
protected int getLevel() { abstract protected int getLevel();
return AdvancedConfig.getInstance().getArcaneForgingRankLevel(this); abstract protected double getKeepEnchantChance();
} abstract protected double getDowngradeEnchantChance();
protected double getKeepEnchantChance() {
return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChance(this);
}
protected double getDowngradeEnchantChance() {
return AdvancedConfig.getInstance().getArcaneForgingDowngradeChance(this);
}
} }
public static boolean arcaneForgingDowngrades = AdvancedConfig.getInstance().getArcaneForgingDowngradeEnabled(); public static boolean arcaneForgingDowngrades = AdvancedConfig.getInstance().getArcaneForgingDowngradeEnabled();

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